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 @@
|
||||
# Modify this file to change the last-modified date when you add/remove a file.
|
||||
# This will then trigger a new cmake run automatically.
|
||||
# This will then trigger a new cmake run automatically.
|
||||
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
|
||||
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
|
||||
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")
|
||||
|
@ -1,5 +1,5 @@
|
||||
// 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
|
||||
// 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
|
||||
// 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/widgets/button_widget.hpp"
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
#include "guiengine/widgets/text_box_widget.hpp"
|
||||
#include "scriptengine/script_engine.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
#include <IGUIEnvironment.h>
|
||||
|
||||
|
||||
using namespace GUIEngine;
|
||||
using namespace irr::core;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
ScriptingConsole::ScriptingConsole() :
|
||||
ModalDialog(0.95f, 0.2f, GUIEngine::MODAL_DIALOG_LOCATION_BOTTOM)
|
||||
GeneralDebugDialog::GeneralDebugDialog(const wchar_t* title, Callback cb) :
|
||||
ModalDialog(0.95f, 0.4f, GUIEngine::MODAL_DIALOG_LOCATION_BOTTOM),
|
||||
m_callback(cb)
|
||||
{
|
||||
m_fade_background = false;
|
||||
loadFromFile("scripting_console.stkgui");
|
||||
loadFromFile("general_debug_dialog.stkgui");
|
||||
|
||||
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
|
||||
assert(textCtrl != NULL);
|
||||
textCtrl->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
}
|
||||
TextBoxWidget* text_field = getWidget<TextBoxWidget>("textfield");
|
||||
assert(text_field != NULL);
|
||||
text_field->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
LabelWidget* label = getWidget<LabelWidget>("title");
|
||||
assert(label != NULL);
|
||||
label->setText(title, false/*expandAsNeeded*/);
|
||||
} // GeneralDebugDialog
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
ScriptingConsole::~ScriptingConsole()
|
||||
GeneralDebugDialog::~GeneralDebugDialog()
|
||||
{
|
||||
// FIXME: what is this code for?
|
||||
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
|
||||
textCtrl->getIrrlichtElement()->remove();
|
||||
textCtrl->clearListeners();
|
||||
}
|
||||
TextBoxWidget* text_field = getWidget<TextBoxWidget>("textfield");
|
||||
text_field->getIrrlichtElement()->remove();
|
||||
text_field->clearListeners();
|
||||
} // ~GeneralDebugDialog
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
GUIEngine::EventPropagation ScriptingConsole::processEvent(const std::string& eventSource)
|
||||
GUIEngine::EventPropagation GeneralDebugDialog::processEvent(const std::string& eventSource)
|
||||
{
|
||||
if (eventSource == "close")
|
||||
{
|
||||
dismiss();
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
else if (eventSource == "run")
|
||||
else if (eventSource == "ok")
|
||||
{
|
||||
runScript();
|
||||
run();
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
return GUIEngine::EVENT_LET;
|
||||
}
|
||||
} // processEvent
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void ScriptingConsole::runScript()
|
||||
void GeneralDebugDialog::run()
|
||||
{
|
||||
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
|
||||
core::stringw script = textCtrl->getText();
|
||||
textCtrl->setText(L"");
|
||||
TextBoxWidget* text_field = getWidget<TextBoxWidget>("textfield");
|
||||
std::string text = StringUtils::wideToUtf8(text_field->getText());
|
||||
m_callback(text);
|
||||
text_field->setText(L"");
|
||||
|
||||
Scripting::ScriptEngine::getInstance()
|
||||
->evalScript(core::stringc(script.c_str()).c_str());
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
} // run
|
@ -1,5 +1,5 @@
|
||||
// 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
|
||||
// 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
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
#ifndef HEADER_SCRIPTING_CONSOLE_DIALOG_HPP
|
||||
#define HEADER_SCRIPTING_CONSOLE_DIALOG_HPP
|
||||
#ifndef HEADER_GENERAL_DEBUG_DIALOG_HPP
|
||||
#define HEADER_GENERAL_DEBUG_DIALOG_HPP
|
||||
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
#include "utils/cpp2011.hpp"
|
||||
|
||||
#include <irrString.h>
|
||||
|
||||
|
||||
namespace GUIEngine
|
||||
{
|
||||
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
|
||||
*/
|
||||
class ScriptingConsole : public GUIEngine::ModalDialog
|
||||
class GeneralDebugDialog : public GUIEngine::ModalDialog
|
||||
{
|
||||
private:
|
||||
typedef void (*Callback)(const std::string& text);
|
||||
|
||||
Callback m_callback;
|
||||
|
||||
void run();
|
||||
|
||||
public:
|
||||
|
||||
ScriptingConsole();
|
||||
~ScriptingConsole();
|
||||
|
||||
virtual void onEnterPressedInternal() OVERRIDE{ runScript(); }
|
||||
void runScript();
|
||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource) OVERRIDE;
|
||||
GeneralDebugDialog(const wchar_t* title, Callback cb);
|
||||
// ------------------------------------------------------------------------
|
||||
~GeneralDebugDialog();
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void onEnterPressedInternal() OVERRIDE { run(); }
|
||||
// ------------------------------------------------------------------------
|
||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource)
|
||||
OVERRIDE;
|
||||
};
|
||||
|
||||
#endif
|
@ -40,8 +40,9 @@
|
||||
#include "race/history.hpp"
|
||||
#include "main_loop.hpp"
|
||||
#include "replay/replay_recorder.hpp"
|
||||
#include "scriptengine/script_engine.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/log.hpp"
|
||||
#include "utils/profiler.hpp"
|
||||
@ -54,6 +55,14 @@
|
||||
using namespace irr;
|
||||
using namespace gui;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Callback for each general debug dialog
|
||||
static void scripting(const std::string& text)
|
||||
{
|
||||
Scripting::ScriptEngine::getInstance()->evalScript(text);
|
||||
} // scripting
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace Debug {
|
||||
|
||||
/** This is to let mouse input events go through when the debug menu is
|
||||
@ -630,7 +639,7 @@ bool handleContextMenuAction(s32 cmd_id)
|
||||
break;
|
||||
}
|
||||
case DEBUG_SCRIPT_CONSOLE:
|
||||
new ScriptingConsole();
|
||||
new GeneralDebugDialog(L"Run Script", scripting);
|
||||
break;
|
||||
} // switch
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user