Try to combine all text field dialogs
This commit is contained in:
parent
3c9174d278
commit
ebef08c3d8
@ -1,20 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<stkgui>
|
|
||||||
<div x="2%" y="10%" width="96%" height="80%" layout="vertical-row" >
|
|
||||||
|
|
||||||
<label id="title" width="100%" text_align="center" word_wrap="true"
|
|
||||||
I18N="In the 'add new grand prix' dialog"
|
|
||||||
text="Please enter the name of the grand prix" proportion="1" />
|
|
||||||
|
|
||||||
<spacer height="25" width="10" />
|
|
||||||
|
|
||||||
<textbox id="textfield" width="75%" I18N="In the 'add new grand prix' dialog" align="center"/>
|
|
||||||
|
|
||||||
<spacer height="20" width="20" />
|
|
||||||
|
|
||||||
<button id="accept" I18N="In the 'add new grand prix' dialog" text="OK" align="center" proportion="1"/>
|
|
||||||
<spacer height="15" width="20" />
|
|
||||||
<button id="cancel" I18N="In the 'add new grand prix' dialog" text="Cancel" align="center" proportion="1"/>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</stkgui>
|
|
@ -7,9 +7,9 @@
|
|||||||
<textbox id="textfield" width="75%" align="center"/>
|
<textbox id="textfield" width="75%" align="center"/>
|
||||||
|
|
||||||
<spacer height="20" width="20" />
|
<spacer height="20" width="20" />
|
||||||
<button id="ok" raw_text="OK" align="center" proportion="1"/>
|
<button id="ok" I18N="In the general textfield dialog" text="OK" align="center" proportion="1"/>
|
||||||
|
|
||||||
<spacer height="15" width="20" />
|
<spacer height="15" width="20" />
|
||||||
<button id="close" raw_text="Close" align="center" proportion="1"/>
|
<button id="cancel" I18N="In the general textfield dialog" text="Cancel" align="center" proportion="1"/>
|
||||||
</div>
|
</div>
|
||||||
</stkgui>
|
</stkgui>
|
@ -1,5 +1,5 @@
|
|||||||
# Modify this file to change the last-modified date when you add/remove a file.
|
# 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_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
|
||||||
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
|
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
|
||||||
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")
|
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")
|
||||||
|
@ -1,147 +0,0 @@
|
|||||||
// SuperTuxKart - a fun racing game with go-kart
|
|
||||||
// Copyright (C) 2014-2015 Marc Coll
|
|
||||||
//
|
|
||||||
// This program is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public License
|
|
||||||
// as published by the Free Software Foundation; either version 3
|
|
||||||
// of the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// 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/enter_gp_name_dialog.hpp"
|
|
||||||
|
|
||||||
#include "audio/sfx_manager.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 "race/grand_prix_manager.hpp"
|
|
||||||
#include "states_screens/state_manager.hpp"
|
|
||||||
#include "utils/translation.hpp"
|
|
||||||
|
|
||||||
#include <IGUIEnvironment.h>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace GUIEngine;
|
|
||||||
using namespace irr::core;
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
EnterGPNameDialog::EnterGPNameDialog(INewGPListener* listener,
|
|
||||||
const float w, const float h)
|
|
||||||
: ModalDialog(w, h), m_listener(listener), m_self_destroy(false)
|
|
||||||
{
|
|
||||||
assert(listener != NULL);
|
|
||||||
loadFromFile("enter_gp_name_dialog.stkgui");
|
|
||||||
|
|
||||||
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
|
|
||||||
assert(textCtrl != NULL);
|
|
||||||
textCtrl->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
EnterGPNameDialog::~EnterGPNameDialog()
|
|
||||||
{
|
|
||||||
// FIXME: what is this code for?
|
|
||||||
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
|
|
||||||
textCtrl->getIrrlichtElement()->remove();
|
|
||||||
textCtrl->clearListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
GUIEngine::EventPropagation EnterGPNameDialog::processEvent(const std::string& eventSource)
|
|
||||||
{
|
|
||||||
if (eventSource == "cancel")
|
|
||||||
{
|
|
||||||
dismiss();
|
|
||||||
return GUIEngine::EVENT_BLOCK;
|
|
||||||
}
|
|
||||||
else if (eventSource == "accept")
|
|
||||||
{
|
|
||||||
validateName();
|
|
||||||
}
|
|
||||||
return GUIEngine::EVENT_LET;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
void EnterGPNameDialog::onEnterPressedInternal()
|
|
||||||
{
|
|
||||||
//Cancel button pressed
|
|
||||||
ButtonWidget* cancelButton = getWidget<ButtonWidget>("cancel");
|
|
||||||
if (GUIEngine::isFocusedForPlayer(cancelButton, PLAYER_ID_GAME_MASTER))
|
|
||||||
{
|
|
||||||
std::string fakeEvent = "cancel";
|
|
||||||
processEvent(fakeEvent);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Otherwise, see if we can accept the new name and create the grand prix
|
|
||||||
validateName();
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
void EnterGPNameDialog::onUpdate(float dt)
|
|
||||||
{
|
|
||||||
// It's unsafe to delete from inside the event handler so we do it here
|
|
||||||
if (m_self_destroy)
|
|
||||||
{
|
|
||||||
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
|
|
||||||
stringw name = textCtrl->getText().trim();
|
|
||||||
|
|
||||||
// irrLicht is too stupid to remove focus from deleted widgets
|
|
||||||
// so do it by hand
|
|
||||||
GUIEngine::getGUIEnv()->removeFocus( textCtrl->getIrrlichtElement() );
|
|
||||||
GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
|
|
||||||
|
|
||||||
// we will destroy the dialog before notifying the listener to be safer.
|
|
||||||
// but in order not to crash we must make a local copy of the listern
|
|
||||||
// otherwise we will crash
|
|
||||||
INewGPListener* listener = m_listener;
|
|
||||||
|
|
||||||
ModalDialog::dismiss();
|
|
||||||
|
|
||||||
if (listener != NULL)
|
|
||||||
listener->onNewGPWithName(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
void EnterGPNameDialog::validateName()
|
|
||||||
{
|
|
||||||
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
|
|
||||||
assert(textCtrl != NULL);
|
|
||||||
LabelWidget* label = getWidget<LabelWidget>("title");
|
|
||||||
assert(label != NULL);
|
|
||||||
|
|
||||||
stringw name = textCtrl->getText().trim();
|
|
||||||
if (name.size() == 0)
|
|
||||||
{
|
|
||||||
label->setText(_("Name is empty."), false);
|
|
||||||
SFXManager::get()->quickSound("anvil");
|
|
||||||
}
|
|
||||||
else if (grand_prix_manager->existsName(name) ||
|
|
||||||
name == GrandPrixData::getRandomGPName())
|
|
||||||
{
|
|
||||||
// check for duplicate names
|
|
||||||
label->setText(_("Another grand prix with this name already exists."), false);
|
|
||||||
SFXManager::get()->quickSound("anvil");
|
|
||||||
}
|
|
||||||
else if (name.size() > 30)
|
|
||||||
{
|
|
||||||
label->setText(_("Name is too long."), false);
|
|
||||||
SFXManager::get()->quickSound("anvil");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// It's unsafe to delete from inside the event handler so we do it
|
|
||||||
// in onUpdate (which checks for m_self_destroy)
|
|
||||||
m_self_destroy = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
// SuperTuxKart - a fun racing game with go-kart
|
|
||||||
// Copyright (C) 2014-2015 Marc Coll
|
|
||||||
//
|
|
||||||
// This program is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public License
|
|
||||||
// as published by the Free Software Foundation; either version 3
|
|
||||||
// of the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// 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_ENTER_GP_NAME_DIALOG_HPP
|
|
||||||
#define HEADER_ENTER_GP_NAME_DIALOG_HPP
|
|
||||||
|
|
||||||
#include "guiengine/modaldialog.hpp"
|
|
||||||
|
|
||||||
#include <irrString.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace GUIEngine
|
|
||||||
{
|
|
||||||
class TextBoxWidget;
|
|
||||||
class ButtonWidget;
|
|
||||||
class LabelWidget;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Dialog that allows the player to enter the name for a new grand prix
|
|
||||||
* \ingroup states_screens
|
|
||||||
*/
|
|
||||||
class EnterGPNameDialog : public GUIEngine::ModalDialog
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
class INewGPListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual void onNewGPWithName(const irr::core::stringw& newName) = 0;
|
|
||||||
virtual ~INewGPListener(){}
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
INewGPListener* m_listener;
|
|
||||||
bool m_self_destroy;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a modal dialog with given percentage of screen width and height
|
|
||||||
*/
|
|
||||||
EnterGPNameDialog(INewGPListener* listener, const float percentWidth,
|
|
||||||
const float percentHeight);
|
|
||||||
~EnterGPNameDialog();
|
|
||||||
|
|
||||||
void onEnterPressedInternal();
|
|
||||||
void validateName();
|
|
||||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
|
|
||||||
virtual void onUpdate(float dt);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,81 +0,0 @@
|
|||||||
// SuperTuxKart - a fun racing game with go-kart
|
|
||||||
// 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
|
|
||||||
// as published by the Free Software Foundation; either version 3
|
|
||||||
// of the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// 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/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 "states_screens/state_manager.hpp"
|
|
||||||
#include "utils/string_utils.hpp"
|
|
||||||
|
|
||||||
#include <IGUIEnvironment.h>
|
|
||||||
|
|
||||||
using namespace GUIEngine;
|
|
||||||
using namespace irr::core;
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
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("general_debug_dialog.stkgui");
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
GeneralDebugDialog::~GeneralDebugDialog()
|
|
||||||
{
|
|
||||||
TextBoxWidget* text_field = getWidget<TextBoxWidget>("textfield");
|
|
||||||
text_field->getIrrlichtElement()->remove();
|
|
||||||
text_field->clearListeners();
|
|
||||||
} // ~GeneralDebugDialog
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
GUIEngine::EventPropagation GeneralDebugDialog::processEvent(const std::string& eventSource)
|
|
||||||
{
|
|
||||||
if (eventSource == "close")
|
|
||||||
{
|
|
||||||
dismiss();
|
|
||||||
return GUIEngine::EVENT_BLOCK;
|
|
||||||
}
|
|
||||||
else if (eventSource == "ok")
|
|
||||||
{
|
|
||||||
run();
|
|
||||||
return GUIEngine::EVENT_BLOCK;
|
|
||||||
}
|
|
||||||
return GUIEngine::EVENT_LET;
|
|
||||||
} // processEvent
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
void GeneralDebugDialog::run()
|
|
||||||
{
|
|
||||||
TextBoxWidget* text_field = getWidget<TextBoxWidget>("textfield");
|
|
||||||
std::string text = StringUtils::wideToUtf8(text_field->getText());
|
|
||||||
m_callback(text);
|
|
||||||
text_field->setText(L"");
|
|
||||||
|
|
||||||
} // run
|
|
119
src/states_screens/dialogs/general_text_field_dialog.cpp
Normal file
119
src/states_screens/dialogs/general_text_field_dialog.cpp
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
// SuperTuxKart - a fun racing game with go-kart
|
||||||
|
// 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
|
||||||
|
// as published by the Free Software Foundation; either version 3
|
||||||
|
// of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// 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/general_text_field_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 "states_screens/state_manager.hpp"
|
||||||
|
#include "utils/string_utils.hpp"
|
||||||
|
|
||||||
|
#include <IGUIEnvironment.h>
|
||||||
|
|
||||||
|
using namespace GUIEngine;
|
||||||
|
using namespace irr::core;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
GeneralTextFieldDialog::GeneralTextFieldDialog(const wchar_t* title,
|
||||||
|
DismissCallback dm_cb,
|
||||||
|
ValidationCallback val_cb)
|
||||||
|
: ModalDialog(0.95f, 0.4f,
|
||||||
|
GUIEngine::MODAL_DIALOG_LOCATION_BOTTOM),
|
||||||
|
m_dm_cb(dm_cb), m_val_cb(val_cb)
|
||||||
|
{
|
||||||
|
m_fade_background = false;
|
||||||
|
m_self_destroy = false;
|
||||||
|
loadFromFile("general_textfield_dialog.stkgui");
|
||||||
|
|
||||||
|
m_text_field = getWidget<TextBoxWidget>("textfield");
|
||||||
|
assert(m_text_field != NULL);
|
||||||
|
m_text_field->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||||
|
|
||||||
|
m_title = getWidget<LabelWidget>("title");
|
||||||
|
assert(m_title != NULL);
|
||||||
|
m_title->setText(title, false/*expandAsNeeded*/);
|
||||||
|
} // GeneralTextFieldDialog
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
GeneralTextFieldDialog::~GeneralTextFieldDialog()
|
||||||
|
{
|
||||||
|
m_text_field->getIrrlichtElement()->remove();
|
||||||
|
m_text_field->clearListeners();
|
||||||
|
} // ~GeneralTextFieldDialog
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
GUIEngine::EventPropagation GeneralTextFieldDialog::processEvent(const std::string& eventSource)
|
||||||
|
{
|
||||||
|
if (eventSource == "cancel")
|
||||||
|
{
|
||||||
|
dismiss();
|
||||||
|
return GUIEngine::EVENT_BLOCK;
|
||||||
|
}
|
||||||
|
else if (eventSource == "ok")
|
||||||
|
{
|
||||||
|
// If validation callback return true, dismiss the dialog
|
||||||
|
if (m_val_cb(m_title, m_text_field))
|
||||||
|
m_self_destroy = true;
|
||||||
|
return GUIEngine::EVENT_BLOCK;
|
||||||
|
}
|
||||||
|
return GUIEngine::EVENT_LET;
|
||||||
|
} // processEvent
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
void GeneralTextFieldDialog::onEnterPressedInternal()
|
||||||
|
{
|
||||||
|
// Cancel button pressed
|
||||||
|
ButtonWidget* cancel_button = getWidget<ButtonWidget>("cancel");
|
||||||
|
if (GUIEngine::isFocusedForPlayer(cancel_button, PLAYER_ID_GAME_MASTER))
|
||||||
|
{
|
||||||
|
std::string fake_event = "cancel";
|
||||||
|
processEvent(fake_event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_val_cb(m_title, m_text_field))
|
||||||
|
m_self_destroy = true;
|
||||||
|
|
||||||
|
} // onEnterPressedInternal
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
void GeneralTextFieldDialog::onUpdate(float dt)
|
||||||
|
{
|
||||||
|
// It's unsafe to delete from inside the event handler so we do it here
|
||||||
|
if (m_self_destroy)
|
||||||
|
{
|
||||||
|
stringw name = m_text_field->getText().trim();
|
||||||
|
|
||||||
|
// irrLicht is too stupid to remove focus from deleted widgets
|
||||||
|
// so do it by hand
|
||||||
|
GUIEngine::getGUIEnv()
|
||||||
|
->removeFocus(m_text_field->getIrrlichtElement());
|
||||||
|
GUIEngine::getGUIEnv()->removeFocus(m_irrlicht_window);
|
||||||
|
|
||||||
|
// We will destroy the dialog before notifying the callback is run,
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
} // onUpdate
|
@ -15,12 +15,14 @@
|
|||||||
// 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_GENERAL_TEXT_FIELD_DIALOG_HPP
|
||||||
#define HEADER_GENERAL_DEBUG_DIALOG_HPP
|
#define HEADER_GENERAL_TEXT_FIELD_DIALOG_HPP
|
||||||
|
|
||||||
#include "guiengine/modaldialog.hpp"
|
#include "guiengine/modaldialog.hpp"
|
||||||
#include "utils/cpp2011.hpp"
|
#include "utils/cpp2011.hpp"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace GUIEngine
|
namespace GUIEngine
|
||||||
{
|
{
|
||||||
class TextBoxWidget;
|
class TextBoxWidget;
|
||||||
@ -29,24 +31,43 @@ namespace GUIEngine
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief A general debug dialog to run stuff based on captured text.
|
* \brief A general textfield dialog to do anything based on captured text
|
||||||
|
* using callbacks.
|
||||||
* \ingroup states_screens
|
* \ingroup states_screens
|
||||||
*/
|
*/
|
||||||
class GeneralDebugDialog : public GUIEngine::ModalDialog
|
class GeneralTextFieldDialog : public GUIEngine::ModalDialog
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef void (*Callback)(const std::string& text);
|
typedef std::function<void(const irr::core::stringw&)> DismissCallback;
|
||||||
|
|
||||||
Callback m_callback;
|
typedef
|
||||||
|
std::function<bool(GUIEngine::LabelWidget*, GUIEngine::TextBoxWidget*)>
|
||||||
|
ValidationCallback;
|
||||||
|
|
||||||
void run();
|
GUIEngine::LabelWidget* m_title;
|
||||||
|
|
||||||
|
GUIEngine::TextBoxWidget* m_text_field;
|
||||||
|
|
||||||
|
DismissCallback m_dm_cb;
|
||||||
|
|
||||||
|
ValidationCallback m_val_cb;
|
||||||
|
|
||||||
|
bool m_self_destroy;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GeneralDebugDialog(const wchar_t* title, Callback cb);
|
GeneralTextFieldDialog(const wchar_t* title, DismissCallback dm_cb,
|
||||||
|
ValidationCallback val_cb = [=]
|
||||||
|
(GUIEngine::LabelWidget* lw, GUIEngine::TextBoxWidget* tb)->bool
|
||||||
|
{
|
||||||
|
// No validation if not specify, always go to dismiss callback
|
||||||
|
return true;
|
||||||
|
});
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
~GeneralDebugDialog();
|
~GeneralTextFieldDialog();
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
virtual void onEnterPressedInternal() OVERRIDE { run(); }
|
virtual void onEnterPressedInternal() OVERRIDE;
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
virtual void onUpdate(float dt) OVERRIDE;
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource)
|
GUIEngine::EventPropagation processEvent(const std::string& eventSource)
|
||||||
OVERRIDE;
|
OVERRIDE;
|
@ -22,6 +22,8 @@
|
|||||||
#include "race/grand_prix_manager.hpp"
|
#include "race/grand_prix_manager.hpp"
|
||||||
#include "race/race_manager.hpp"
|
#include "race/race_manager.hpp"
|
||||||
#include "states_screens/grand_prix_cutscene.hpp"
|
#include "states_screens/grand_prix_cutscene.hpp"
|
||||||
|
#include "states_screens/grand_prix_editor_screen.hpp"
|
||||||
|
#include "states_screens/dialogs/general_text_field_dialog.hpp"
|
||||||
#include "tracks/track_manager.hpp"
|
#include "tracks/track_manager.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -42,7 +44,7 @@ void GrandPrixCutscene::saveGPButton()
|
|||||||
* The GP that the race_manager provides can't be used because we need some
|
* The GP that the race_manager provides can't be used because we need some
|
||||||
* functions and settings that the GP manager only gives us through
|
* functions and settings that the GP manager only gives us through
|
||||||
* createNewGP(). */
|
* createNewGP(). */
|
||||||
void GrandPrixCutscene::onNewGPWithName(const irr::core::stringw& name)
|
void GrandPrixCutscene::setNewGPWithName(const irr::core::stringw& name)
|
||||||
{
|
{
|
||||||
// create a new GP with the correct filename and a unique id
|
// create a new GP with the correct filename and a unique id
|
||||||
GrandPrixData* gp = grand_prix_manager->createNewGP(name);
|
GrandPrixData* gp = grand_prix_manager->createNewGP(name);
|
||||||
@ -56,7 +58,7 @@ void GrandPrixCutscene::onNewGPWithName(const irr::core::stringw& name)
|
|||||||
|
|
||||||
// Avoid double-save which can have bad side-effects
|
// Avoid double-save which can have bad side-effects
|
||||||
getWidget<Button>("save")->setVisible(false);
|
getWidget<Button>("save")->setVisible(false);
|
||||||
} // onNewGPWithName
|
} // setNewGPWithName
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -70,7 +72,9 @@ void GrandPrixCutscene::eventCallback(GUIEngine::Widget* widget,
|
|||||||
}
|
}
|
||||||
else if (name == "save")
|
else if (name == "save")
|
||||||
{
|
{
|
||||||
new EnterGPNameDialog(this, 0.5f, 0.4f);
|
new GeneralTextFieldDialog(_("Please enter the name of the grand prix"),
|
||||||
|
std::bind(&GrandPrixCutscene::setNewGPWithName, this,
|
||||||
|
std::placeholders::_1), GrandPrixEditorScreen::validateName);
|
||||||
}
|
}
|
||||||
} // eventCallback
|
} // eventCallback
|
||||||
|
|
||||||
|
@ -21,12 +21,10 @@
|
|||||||
#include "guiengine/screen.hpp"
|
#include "guiengine/screen.hpp"
|
||||||
#include "guiengine/widgets/button_widget.hpp"
|
#include "guiengine/widgets/button_widget.hpp"
|
||||||
#include "race/race_manager.hpp"
|
#include "race/race_manager.hpp"
|
||||||
#include "states_screens/dialogs/enter_gp_name_dialog.hpp"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class GrandPrixCutscene: public GUIEngine::CutsceneScreen,
|
class GrandPrixCutscene: public GUIEngine::CutsceneScreen
|
||||||
public EnterGPNameDialog::INewGPListener
|
|
||||||
{
|
{
|
||||||
friend class GUIEngine::ScreenSingleton<GrandPrixCutscene>;
|
friend class GUIEngine::ScreenSingleton<GrandPrixCutscene>;
|
||||||
public:
|
public:
|
||||||
@ -34,8 +32,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void saveGPButton();
|
void saveGPButton();
|
||||||
|
|
||||||
/** implement callback from INewGPListener */
|
void setNewGPWithName(const irr::core::stringw& name);
|
||||||
void onNewGPWithName(const irr::core::stringw& name) OVERRIDE;
|
|
||||||
|
|
||||||
// implement callbacks from parent class GUIEngine::Screen
|
// implement callbacks from parent class GUIEngine::Screen
|
||||||
void eventCallback(GUIEngine::Widget* widget,
|
void eventCallback(GUIEngine::Widget* widget,
|
||||||
|
@ -17,21 +17,22 @@
|
|||||||
|
|
||||||
#include "states_screens/grand_prix_editor_screen.hpp"
|
#include "states_screens/grand_prix_editor_screen.hpp"
|
||||||
|
|
||||||
|
#include "audio/sfx_manager.hpp"
|
||||||
#include "graphics/irr_driver.hpp"
|
#include "graphics/irr_driver.hpp"
|
||||||
#include "guiengine/widget.hpp"
|
#include "guiengine/widget.hpp"
|
||||||
#include "guiengine/widgets/label_widget.hpp"
|
#include "guiengine/widgets/label_widget.hpp"
|
||||||
|
#include "guiengine/widgets/text_box_widget.hpp"
|
||||||
#include "guiengine/widgets/dynamic_ribbon_widget.hpp"
|
#include "guiengine/widgets/dynamic_ribbon_widget.hpp"
|
||||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "race/grand_prix_manager.hpp"
|
#include "race/grand_prix_manager.hpp"
|
||||||
#include "states_screens/state_manager.hpp"
|
#include "states_screens/state_manager.hpp"
|
||||||
#include "states_screens/edit_gp_screen.hpp"
|
#include "states_screens/edit_gp_screen.hpp"
|
||||||
#include "states_screens/dialogs/enter_gp_name_dialog.hpp"
|
#include "states_screens/dialogs/general_text_field_dialog.hpp"
|
||||||
#include "tracks/track.hpp"
|
#include "tracks/track.hpp"
|
||||||
#include "tracks/track_manager.hpp"
|
#include "tracks/track_manager.hpp"
|
||||||
#include "utils/translation.hpp"
|
#include "utils/translation.hpp"
|
||||||
|
|
||||||
|
|
||||||
using namespace GUIEngine;
|
using namespace GUIEngine;
|
||||||
using namespace irr::core;
|
using namespace irr::core;
|
||||||
|
|
||||||
@ -97,7 +98,9 @@ void GrandPrixEditorScreen::eventCallback(Widget* widget, const std::string& nam
|
|||||||
|
|
||||||
if (m_action == "new" || m_action == "copy")
|
if (m_action == "new" || m_action == "copy")
|
||||||
{
|
{
|
||||||
new EnterGPNameDialog(this, 0.5f, 0.4f);
|
new GeneralTextFieldDialog(_("Please enter the name of the grand prix"),
|
||||||
|
std::bind(&GrandPrixEditorScreen::setNewGPWithName,
|
||||||
|
this, std::placeholders::_1), validateName);
|
||||||
}
|
}
|
||||||
else if (m_action == "edit" && m_selection != NULL)
|
else if (m_action == "edit" && m_selection != NULL)
|
||||||
{
|
{
|
||||||
@ -112,7 +115,9 @@ void GrandPrixEditorScreen::eventCallback(Widget* widget, const std::string& nam
|
|||||||
}
|
}
|
||||||
else if (m_action == "rename" && m_selection != NULL)
|
else if (m_action == "rename" && m_selection != NULL)
|
||||||
{
|
{
|
||||||
new EnterGPNameDialog(this, 0.5f, 0.4f);
|
new GeneralTextFieldDialog(_("Please enter the name of the grand prix"),
|
||||||
|
std::bind(&GrandPrixEditorScreen::setNewGPWithName,
|
||||||
|
this, std::placeholders::_1), validateName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (name == "gpgroups")
|
else if (name == "gpgroups")
|
||||||
@ -281,7 +286,7 @@ void GrandPrixEditorScreen::enableButtons()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
void GrandPrixEditorScreen::onNewGPWithName(const stringw& newName)
|
void GrandPrixEditorScreen::setNewGPWithName(const stringw& newName)
|
||||||
{
|
{
|
||||||
if (m_action == "copy" && m_selection != NULL)
|
if (m_action == "copy" && m_selection != NULL)
|
||||||
{
|
{
|
||||||
@ -328,3 +333,34 @@ const core::stringw GrandPrixEditorScreen::getGroupName(enum GrandPrixData::GPGr
|
|||||||
default: return L"???";
|
default: return L"???";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
bool GrandPrixEditorScreen::validateName(LabelWidget* label,
|
||||||
|
TextBoxWidget* text)
|
||||||
|
{
|
||||||
|
stringw name = text->getText().trim();
|
||||||
|
if (name.size() == 0)
|
||||||
|
{
|
||||||
|
label->setText(_("Name is empty."), false);
|
||||||
|
SFXManager::get()->quickSound("anvil");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (grand_prix_manager->existsName(name) ||
|
||||||
|
name == GrandPrixData::getRandomGPName())
|
||||||
|
{
|
||||||
|
// check for duplicate names
|
||||||
|
label->setText(_("Another grand prix with this name already exists."), false);
|
||||||
|
SFXManager::get()->quickSound("anvil");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (name.size() > 30)
|
||||||
|
{
|
||||||
|
label->setText(_("Name is too long."), false);
|
||||||
|
SFXManager::get()->quickSound("anvil");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -20,11 +20,10 @@
|
|||||||
|
|
||||||
#include "guiengine/screen.hpp"
|
#include "guiengine/screen.hpp"
|
||||||
#include "race/grand_prix_data.hpp"
|
#include "race/grand_prix_data.hpp"
|
||||||
#include "states_screens/dialogs/enter_gp_name_dialog.hpp"
|
|
||||||
#include "states_screens/dialogs/message_dialog.hpp"
|
#include "states_screens/dialogs/message_dialog.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace GUIEngine { class Widget; }
|
namespace GUIEngine { class Widget; class LabelWidget; }
|
||||||
|
|
||||||
class GrandPrixData;
|
class GrandPrixData;
|
||||||
|
|
||||||
@ -35,7 +34,6 @@ class GrandPrixData;
|
|||||||
class GrandPrixEditorScreen :
|
class GrandPrixEditorScreen :
|
||||||
public GUIEngine::Screen,
|
public GUIEngine::Screen,
|
||||||
public GUIEngine::ScreenSingleton<GrandPrixEditorScreen>,
|
public GUIEngine::ScreenSingleton<GrandPrixEditorScreen>,
|
||||||
public EnterGPNameDialog::INewGPListener,
|
|
||||||
public MessageDialog::IConfirmDialogListener
|
public MessageDialog::IConfirmDialogListener
|
||||||
{
|
{
|
||||||
friend class GUIEngine::ScreenSingleton<GrandPrixEditorScreen>;
|
friend class GUIEngine::ScreenSingleton<GrandPrixEditorScreen>;
|
||||||
@ -48,7 +46,7 @@ class GrandPrixEditorScreen :
|
|||||||
void showEditScreen(GrandPrixData* gp);
|
void showEditScreen(GrandPrixData* gp);
|
||||||
void enableButtons();
|
void enableButtons();
|
||||||
|
|
||||||
void onNewGPWithName(const irr::core::stringw& newName) OVERRIDE;
|
void setNewGPWithName(const irr::core::stringw& newName);
|
||||||
void onConfirm() OVERRIDE;
|
void onConfirm() OVERRIDE;
|
||||||
|
|
||||||
static const core::stringw getGroupName(enum GrandPrixData::GPGroupType group);
|
static const core::stringw getGroupName(enum GrandPrixData::GPGroupType group);
|
||||||
@ -71,6 +69,9 @@ public:
|
|||||||
|
|
||||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||||
virtual void init() OVERRIDE;
|
virtual void init() OVERRIDE;
|
||||||
|
|
||||||
|
/** \brief Global function to validate grand prix names. */
|
||||||
|
static bool validateName(GUIEngine::LabelWidget*, GUIEngine::TextBoxWidget*);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
#include "replay/replay_recorder.hpp"
|
#include "replay/replay_recorder.hpp"
|
||||||
#include "scriptengine/script_engine.hpp"
|
#include "scriptengine/script_engine.hpp"
|
||||||
#include "states_screens/dialogs/debug_slider.hpp"
|
#include "states_screens/dialogs/debug_slider.hpp"
|
||||||
#include "states_screens/dialogs/general_debug_dialog.hpp"
|
#include "states_screens/dialogs/general_text_field_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"
|
||||||
@ -55,14 +55,6 @@
|
|||||||
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
|
||||||
@ -639,7 +631,12 @@ bool handleContextMenuAction(s32 cmd_id)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DEBUG_SCRIPT_CONSOLE:
|
case DEBUG_SCRIPT_CONSOLE:
|
||||||
new GeneralDebugDialog(L"Run Script", scripting);
|
new GeneralTextFieldDialog(L"Run Script", [=]
|
||||||
|
(const irr::core::stringw& text)
|
||||||
|
{
|
||||||
|
Scripting::ScriptEngine::getInstance()
|
||||||
|
->evalScript(StringUtils::wideToUtf8(text));
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
} // switch
|
} // switch
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user