diff --git a/data/gui/general_debug_dialog.stkgui b/data/gui/general_debug_dialog.stkgui
new file mode 100644
index 000000000..514fce91f
--- /dev/null
+++ b/data/gui/general_debug_dialog.stkgui
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/data/gui/scripting_console.stkgui b/data/gui/scripting_console.stkgui
deleted file mode 100644
index f900753a9..000000000
--- a/data/gui/scripting_console.stkgui
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/sources.cmake b/sources.cmake
index d4f28ae4d..ba4868d71 100644
--- a/sources.cmake
+++ b/sources.cmake
@@ -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/*")
diff --git a/src/states_screens/dialogs/scripting_console.cpp b/src/states_screens/dialogs/general_debug_dialog.cpp
similarity index 55%
rename from src/states_screens/dialogs/scripting_console.cpp
rename to src/states_screens/dialogs/general_debug_dialog.cpp
index 3e0770e58..6afd2992f 100644
--- a/src/states_screens/dialogs/scripting_console.cpp
+++ b/src/states_screens/dialogs/general_debug_dialog.cpp
@@ -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
-
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("textfield");
- assert(textCtrl != NULL);
- textCtrl->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
-}
+ TextBoxWidget* text_field = getWidget("textfield");
+ assert(text_field != NULL);
+ text_field->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
+
+ LabelWidget* label = getWidget("title");
+ assert(label != NULL);
+ label->setText(title, false/*expandAsNeeded*/);
+} // GeneralDebugDialog
// -----------------------------------------------------------------------------
-
-ScriptingConsole::~ScriptingConsole()
+GeneralDebugDialog::~GeneralDebugDialog()
{
- // FIXME: what is this code for?
- TextBoxWidget* textCtrl = getWidget("textfield");
- textCtrl->getIrrlichtElement()->remove();
- textCtrl->clearListeners();
-}
+ TextBoxWidget* text_field = getWidget("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("textfield");
- core::stringw script = textCtrl->getText();
- textCtrl->setText(L"");
+ TextBoxWidget* text_field = getWidget("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
diff --git a/src/states_screens/dialogs/scripting_console.hpp b/src/states_screens/dialogs/general_debug_dialog.hpp
similarity index 57%
rename from src/states_screens/dialogs/scripting_console.hpp
rename to src/states_screens/dialogs/general_debug_dialog.hpp
index c248a008c..0b30e0f13 100644
--- a/src/states_screens/dialogs/scripting_console.hpp
+++ b/src/states_screens/dialogs/general_debug_dialog.hpp
@@ -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
-
-
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
diff --git a/src/utils/debug.cpp b/src/utils/debug.cpp
index 6b4468ef1..27aa7c720 100644
--- a/src/utils/debug.cpp
+++ b/src/utils/debug.cpp
@@ -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;