Implement the 'new player' player on the welcome screen
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10364 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -127,15 +127,20 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
|
||||
}
|
||||
|
||||
UserConfigParams::m_all_players.push_back( new PlayerProfile(playerName) );
|
||||
|
||||
if (m_listener != NULL) m_listener->onNewPlayerWithName( playerName );
|
||||
|
||||
// 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
|
||||
INewPlayerListener* listener = m_listener;
|
||||
|
||||
ModalDialog::dismiss();
|
||||
|
||||
if (listener != NULL) listener->onNewPlayerWithName( playerName );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#include "challenges/unlock_manager.hpp"
|
||||
#include "guiengine/widgets/list_widget.hpp"
|
||||
#include "states_screens/dialogs/story_mode_new.hpp"
|
||||
#include "states_screens/dialogs/enter_player_name_dialog.hpp"
|
||||
#include "states_screens/main_menu_screen.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
|
||||
@@ -82,7 +82,7 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, const std::string& name
|
||||
}
|
||||
else if (name == "creategame")
|
||||
{
|
||||
new StoryModeNewDialog(0.8f, 0.8f);
|
||||
new EnterPlayerNameDialog(this, 0.5f, 0.4f);
|
||||
}
|
||||
else if (name == "gameslots")
|
||||
{
|
||||
@@ -119,3 +119,30 @@ void StoryModeLobbyScreen::unloaded()
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void StoryModeLobbyScreen::onNewPlayerWithName(const stringw& newName)
|
||||
{
|
||||
|
||||
bool slot_found = false;
|
||||
|
||||
PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players;
|
||||
for (int n=0; n<players.size(); n++)
|
||||
{
|
||||
if (players[n].getName() == newName)
|
||||
{
|
||||
unlock_manager->setCurrentSlot(n);
|
||||
slot_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!slot_found)
|
||||
{
|
||||
fprintf(stderr, "[StoryModeLobbyScreen] ERROR: cannot find player corresponding to slot '%s'\n",
|
||||
core::stringc(newName.c_str()).c_str());
|
||||
}
|
||||
|
||||
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "guiengine/screen.hpp"
|
||||
#include "states_screens/dialogs/enter_player_name_dialog.hpp"
|
||||
|
||||
namespace GUIEngine { class Widget; }
|
||||
|
||||
@@ -30,7 +31,8 @@ namespace GUIEngine { class Widget; }
|
||||
* \brief Audio options screen
|
||||
* \ingroup states_screens
|
||||
*/
|
||||
class StoryModeLobbyScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<StoryModeLobbyScreen>
|
||||
class StoryModeLobbyScreen : public GUIEngine::Screen, public EnterPlayerNameDialog::INewPlayerListener,
|
||||
public GUIEngine::ScreenSingleton<StoryModeLobbyScreen>
|
||||
{
|
||||
StoryModeLobbyScreen();
|
||||
|
||||
@@ -51,6 +53,9 @@ public:
|
||||
|
||||
/** \brief implement optional callback from parent class GUIEngine::Screen */
|
||||
virtual void unloaded();
|
||||
|
||||
/** \brief implement callback from EnterPlayerNameDialog::INewPlayerListener */
|
||||
virtual void onNewPlayerWithName(const irr::core::stringw& newName);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user