Add a general debug dialog
To be used later
This commit is contained in:
parent
6a142e8d2e
commit
3c9174d278
15
data/gui/general_debug_dialog.stkgui
Normal file
15
data/gui/general_debug_dialog.stkgui
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<stkgui>
|
||||||
|
<div x="2%" y="10%" width="96%" height="80%" layout="vertical-row" >
|
||||||
|
<label id="title" raw_text="Text" proportion="1"/>
|
||||||
|
|
||||||
|
<spacer height="25" width="10" />
|
||||||
|
<textbox id="textfield" width="75%" align="center"/>
|
||||||
|
|
||||||
|
<spacer height="20" width="20" />
|
||||||
|
<button id="ok" raw_text="OK" align="center" proportion="1"/>
|
||||||
|
|
||||||
|
<spacer height="15" width="20" />
|
||||||
|
<button id="close" raw_text="Close" align="center" proportion="1"/>
|
||||||
|
</div>
|
||||||
|
</stkgui>
|
@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<stkgui>
|
|
||||||
<div x="2%" y="10%" width="96%" height="80%" layout="vertical-row" >
|
|
||||||
|
|
||||||
<label raw_text="Run script"/>
|
|
||||||
|
|
||||||
<textbox id="textfield" width="75%" I18N="In the 'add new grand prix' dialog" align="center"/>
|
|
||||||
|
|
||||||
<spacer height="20" width="20" />
|
|
||||||
|
|
||||||
<div align="center" height="fit" width="100%" layout="horizontal-row">
|
|
||||||
<button id="run" raw_text="Run" align="center" proportion="1"/>
|
|
||||||
<spacer height="20" width="20" />
|
|
||||||
<button id="close" raw_text="Close" align="center" proportion="1"/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</stkgui>
|
|
@ -1,5 +1,5 @@
|
|||||||
// SuperTuxKart - a fun racing game with go-kart
|
// SuperTuxKart - a fun racing game with go-kart
|
||||||
// Copyright (C) 2014-2015 Marc Coll
|
// Copyright (C) 2016 SuperTuxKart-Team
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or
|
// This program is free software; you can redistribute it and/or
|
||||||
// modify it under the terms of the GNU General Public License
|
// modify it under the terms of the GNU General Public License
|
||||||
@ -15,72 +15,67 @@
|
|||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "states_screens/dialogs/scripting_console.hpp"
|
#include "states_screens/dialogs/general_debug_dialog.hpp"
|
||||||
|
|
||||||
#include "guiengine/engine.hpp"
|
#include "guiengine/engine.hpp"
|
||||||
#include "guiengine/widgets/button_widget.hpp"
|
#include "guiengine/widgets/button_widget.hpp"
|
||||||
#include "guiengine/widgets/label_widget.hpp"
|
#include "guiengine/widgets/label_widget.hpp"
|
||||||
#include "guiengine/widgets/text_box_widget.hpp"
|
#include "guiengine/widgets/text_box_widget.hpp"
|
||||||
#include "scriptengine/script_engine.hpp"
|
|
||||||
#include "states_screens/state_manager.hpp"
|
#include "states_screens/state_manager.hpp"
|
||||||
#include "utils/translation.hpp"
|
#include "utils/string_utils.hpp"
|
||||||
|
|
||||||
#include <IGUIEnvironment.h>
|
#include <IGUIEnvironment.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace GUIEngine;
|
using namespace GUIEngine;
|
||||||
using namespace irr::core;
|
using namespace irr::core;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
GeneralDebugDialog::GeneralDebugDialog(const wchar_t* title, Callback cb) :
|
||||||
ScriptingConsole::ScriptingConsole() :
|
ModalDialog(0.95f, 0.4f, GUIEngine::MODAL_DIALOG_LOCATION_BOTTOM),
|
||||||
ModalDialog(0.95f, 0.2f, GUIEngine::MODAL_DIALOG_LOCATION_BOTTOM)
|
m_callback(cb)
|
||||||
{
|
{
|
||||||
m_fade_background = false;
|
m_fade_background = false;
|
||||||
loadFromFile("scripting_console.stkgui");
|
loadFromFile("general_debug_dialog.stkgui");
|
||||||
|
|
||||||
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
|
TextBoxWidget* text_field = getWidget<TextBoxWidget>("textfield");
|
||||||
assert(textCtrl != NULL);
|
assert(text_field != NULL);
|
||||||
textCtrl->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
text_field->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||||
}
|
|
||||||
|
LabelWidget* label = getWidget<LabelWidget>("title");
|
||||||
|
assert(label != NULL);
|
||||||
|
label->setText(title, false/*expandAsNeeded*/);
|
||||||
|
} // GeneralDebugDialog
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
GeneralDebugDialog::~GeneralDebugDialog()
|
||||||
ScriptingConsole::~ScriptingConsole()
|
|
||||||
{
|
{
|
||||||
// FIXME: what is this code for?
|
TextBoxWidget* text_field = getWidget<TextBoxWidget>("textfield");
|
||||||
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
|
text_field->getIrrlichtElement()->remove();
|
||||||
textCtrl->getIrrlichtElement()->remove();
|
text_field->clearListeners();
|
||||||
textCtrl->clearListeners();
|
} // ~GeneralDebugDialog
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
GUIEngine::EventPropagation GeneralDebugDialog::processEvent(const std::string& eventSource)
|
||||||
GUIEngine::EventPropagation ScriptingConsole::processEvent(const std::string& eventSource)
|
|
||||||
{
|
{
|
||||||
if (eventSource == "close")
|
if (eventSource == "close")
|
||||||
{
|
{
|
||||||
dismiss();
|
dismiss();
|
||||||
return GUIEngine::EVENT_BLOCK;
|
return GUIEngine::EVENT_BLOCK;
|
||||||
}
|
}
|
||||||
else if (eventSource == "run")
|
else if (eventSource == "ok")
|
||||||
{
|
{
|
||||||
runScript();
|
run();
|
||||||
return GUIEngine::EVENT_BLOCK;
|
return GUIEngine::EVENT_BLOCK;
|
||||||
}
|
}
|
||||||
return GUIEngine::EVENT_LET;
|
return GUIEngine::EVENT_LET;
|
||||||
}
|
} // processEvent
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
void GeneralDebugDialog::run()
|
||||||
void ScriptingConsole::runScript()
|
|
||||||
{
|
{
|
||||||
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
|
TextBoxWidget* text_field = getWidget<TextBoxWidget>("textfield");
|
||||||
core::stringw script = textCtrl->getText();
|
std::string text = StringUtils::wideToUtf8(text_field->getText());
|
||||||
textCtrl->setText(L"");
|
m_callback(text);
|
||||||
|
text_field->setText(L"");
|
||||||
|
|
||||||
Scripting::ScriptEngine::getInstance()
|
} // run
|
||||||
->evalScript(core::stringc(script.c_str()).c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
@ -1,5 +1,5 @@
|
|||||||
// SuperTuxKart - a fun racing game with go-kart
|
// SuperTuxKart - a fun racing game with go-kart
|
||||||
// Copyright (C) 2014-2015 Marc Coll
|
// Copyright (C) 2016 SuperTuxKart-Team
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or
|
// This program is free software; you can redistribute it and/or
|
||||||
// modify it under the terms of the GNU General Public License
|
// modify it under the terms of the GNU General Public License
|
||||||
@ -15,16 +15,12 @@
|
|||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
#ifndef HEADER_GENERAL_DEBUG_DIALOG_HPP
|
||||||
#ifndef HEADER_SCRIPTING_CONSOLE_DIALOG_HPP
|
#define HEADER_GENERAL_DEBUG_DIALOG_HPP
|
||||||
#define HEADER_SCRIPTING_CONSOLE_DIALOG_HPP
|
|
||||||
|
|
||||||
#include "guiengine/modaldialog.hpp"
|
#include "guiengine/modaldialog.hpp"
|
||||||
#include "utils/cpp2011.hpp"
|
#include "utils/cpp2011.hpp"
|
||||||
|
|
||||||
#include <irrString.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace GUIEngine
|
namespace GUIEngine
|
||||||
{
|
{
|
||||||
class TextBoxWidget;
|
class TextBoxWidget;
|
||||||
@ -33,19 +29,27 @@ namespace GUIEngine
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Dialog that allows the player to enter the name for a new grand prix
|
* \brief A general debug dialog to run stuff based on captured text.
|
||||||
* \ingroup states_screens
|
* \ingroup states_screens
|
||||||
*/
|
*/
|
||||||
class ScriptingConsole : public GUIEngine::ModalDialog
|
class GeneralDebugDialog : public GUIEngine::ModalDialog
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
typedef void (*Callback)(const std::string& text);
|
||||||
|
|
||||||
|
Callback m_callback;
|
||||||
|
|
||||||
|
void run();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
GeneralDebugDialog(const wchar_t* title, Callback cb);
|
||||||
ScriptingConsole();
|
// ------------------------------------------------------------------------
|
||||||
~ScriptingConsole();
|
~GeneralDebugDialog();
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
virtual void onEnterPressedInternal() OVERRIDE{ runScript(); }
|
virtual void onEnterPressedInternal() OVERRIDE { run(); }
|
||||||
void runScript();
|
// ------------------------------------------------------------------------
|
||||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource) OVERRIDE;
|
GUIEngine::EventPropagation processEvent(const std::string& eventSource)
|
||||||
|
OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -40,8 +40,9 @@
|
|||||||
#include "race/history.hpp"
|
#include "race/history.hpp"
|
||||||
#include "main_loop.hpp"
|
#include "main_loop.hpp"
|
||||||
#include "replay/replay_recorder.hpp"
|
#include "replay/replay_recorder.hpp"
|
||||||
|
#include "scriptengine/script_engine.hpp"
|
||||||
#include "states_screens/dialogs/debug_slider.hpp"
|
#include "states_screens/dialogs/debug_slider.hpp"
|
||||||
#include "states_screens/dialogs/scripting_console.hpp"
|
#include "states_screens/dialogs/general_debug_dialog.hpp"
|
||||||
#include "utils/constants.hpp"
|
#include "utils/constants.hpp"
|
||||||
#include "utils/log.hpp"
|
#include "utils/log.hpp"
|
||||||
#include "utils/profiler.hpp"
|
#include "utils/profiler.hpp"
|
||||||
@ -54,6 +55,14 @@
|
|||||||
using namespace irr;
|
using namespace irr;
|
||||||
using namespace gui;
|
using namespace gui;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Callback for each general debug dialog
|
||||||
|
static void scripting(const std::string& text)
|
||||||
|
{
|
||||||
|
Scripting::ScriptEngine::getInstance()->evalScript(text);
|
||||||
|
} // scripting
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace Debug {
|
namespace Debug {
|
||||||
|
|
||||||
/** This is to let mouse input events go through when the debug menu is
|
/** This is to let mouse input events go through when the debug menu is
|
||||||
@ -630,7 +639,7 @@ bool handleContextMenuAction(s32 cmd_id)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DEBUG_SCRIPT_CONSOLE:
|
case DEBUG_SCRIPT_CONSOLE:
|
||||||
new ScriptingConsole();
|
new GeneralDebugDialog(L"Run Script", scripting);
|
||||||
break;
|
break;
|
||||||
} // switch
|
} // switch
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user