Allow to run cutscene(s) in artist debug menu

This commit is contained in:
Benau 2016-12-26 13:51:40 +08:00
parent ebef08c3d8
commit c2d9f91c62
3 changed files with 56 additions and 11 deletions

View File

@ -35,10 +35,9 @@ GeneralTextFieldDialog::GeneralTextFieldDialog(const wchar_t* title,
ValidationCallback val_cb)
: ModalDialog(0.95f, 0.4f,
GUIEngine::MODAL_DIALOG_LOCATION_BOTTOM),
m_dm_cb(dm_cb), m_val_cb(val_cb)
m_dm_cb(dm_cb), m_val_cb(val_cb), m_self_destroy(false)
{
m_fade_background = false;
m_self_destroy = false;
loadFromFile("general_textfield_dialog.stkgui");
m_text_field = getWidget<TextBoxWidget>("textfield");
@ -48,6 +47,8 @@ GeneralTextFieldDialog::GeneralTextFieldDialog(const wchar_t* title,
m_title = getWidget<LabelWidget>("title");
assert(m_title != NULL);
m_title->setText(title, false/*expandAsNeeded*/);
assert(m_dm_cb != NULL);
assert(m_val_cb != NULL);
} // GeneralTextFieldDialog
// -----------------------------------------------------------------------------
@ -110,10 +111,7 @@ void GeneralTextFieldDialog::onUpdate(float dt)
// but in order not to crash we must make a local copy of the callback
// otherwise we will crash
DismissCallback dm_cb = m_dm_cb;
ModalDialog::dismiss();
if (dm_cb != NULL)
dm_cb(name);
dm_cb(name);
}
} // onUpdate

View File

@ -56,7 +56,7 @@ private:
public:
GeneralTextFieldDialog(const wchar_t* title, DismissCallback dm_cb,
ValidationCallback val_cb = [=]
ValidationCallback val_cb = []
(GUIEngine::LabelWidget* lw, GUIEngine::TextBoxWidget* tb)->bool
{
// No validation if not specify, always go to dismiss callback

View File

@ -29,11 +29,13 @@
#include "graphics/irr_driver.hpp"
#include "graphics/light.hpp"
#include "graphics/shaders.hpp"
#include "guiengine/widgets/text_box_widget.hpp"
#include "items/powerup_manager.hpp"
#include "items/attachment.hpp"
#include "karts/abstract_kart.hpp"
#include "karts/kart_properties.hpp"
#include "karts/controller/controller.hpp"
#include "modes/cutscene_world.hpp"
#include "modes/world.hpp"
#include "physics/irr_debug_drawer.hpp"
#include "physics/physics.hpp"
@ -43,6 +45,7 @@
#include "scriptengine/script_engine.hpp"
#include "states_screens/dialogs/debug_slider.hpp"
#include "states_screens/dialogs/general_text_field_dialog.hpp"
#include "tracks/track_manager.hpp"
#include "utils/constants.hpp"
#include "utils/log.hpp"
#include "utils/profiler.hpp"
@ -126,7 +129,8 @@ enum DebugMenuCommand
DEBUG_VISUAL_VALUES,
DEBUG_PRINT_START_POS,
DEBUG_ADJUST_LIGHTS,
DEBUG_SCRIPT_CONSOLE
DEBUG_SCRIPT_CONSOLE,
DEBUG_RUN_CUTSCENE,
}; // DebugMenuCommand
// -----------------------------------------------------------------------------
@ -631,11 +635,53 @@ bool handleContextMenuAction(s32 cmd_id)
break;
}
case DEBUG_SCRIPT_CONSOLE:
new GeneralTextFieldDialog(L"Run Script", [=]
new GeneralTextFieldDialog(L"Run Script", []
(const irr::core::stringw& text) {},
[] (GUIEngine::LabelWidget* lw, GUIEngine::TextBoxWidget* tb)->bool
{
Scripting::ScriptEngine* engine =
Scripting::ScriptEngine::getInstance();
if (engine == NULL)
{
Log::warn("Debug", "No scripting engine loaded!");
return true;
}
engine->evalScript(StringUtils::wideToUtf8(tb->getText()));
tb->setText(L"");
// Don't close the console after each run
return false;
});
break;
case DEBUG_RUN_CUTSCENE:
new GeneralTextFieldDialog(
L"Enter the cutscene names (separate parts by space)", []
(const irr::core::stringw& text)
{
Scripting::ScriptEngine::getInstance()
->evalScript(StringUtils::wideToUtf8(text));
if (World::getWorld())
{
Log::warn("Debug", "Please run cutscene in main menu");
return;
}
if (text.empty()) return;
std::vector<std::string> parts =
StringUtils::split(StringUtils::wideToUtf8(text), ' ');
for (const std::string& track : parts)
{
Track* t = track_manager->getTrack(track);
if (t == NULL)
{
Log::warn("Debug", "Cutscene %s not found!",
track.c_str());
return;
}
}
CutsceneWorld::setUseDuration(true);
StateManager::get()->enterGameState();
race_manager->setMinorMode(RaceManager::MINOR_MODE_CUTSCENE);
race_manager->setNumKarts(0);
race_manager->setNumPlayers(0);
race_manager->startSingleRace(parts.front(), 999, false);
((CutsceneWorld*)World::getWorld())->setParts(parts);
});
break;
} // switch
@ -745,6 +791,7 @@ bool onEvent(const SEvent &event)
mnu->addItem(L"Print position", DEBUG_PRINT_START_POS);
mnu->addItem(L"Adjust Lights", DEBUG_ADJUST_LIGHTS);
mnu->addItem(L"Scripting console", DEBUG_SCRIPT_CONSOLE);
mnu->addItem(L"Run cutscene(s)", DEBUG_RUN_CUTSCENE);
g_debug_menu_visible = true;
irr_driver->showPointer();