diff --git a/data/gui/story_mode_lobby.stkgui b/data/gui/story_mode_lobby.stkgui
index b84f035a0..5d8c4bf69 100644
--- a/data/gui/story_mode_lobby.stkgui
+++ b/data/gui/story_mode_lobby.stkgui
@@ -6,14 +6,14 @@
-
-
+
+
+
player_nodes;
- m_player_data->getNodes("player", player_nodes);
+ if(m_player_data)
+ m_player_data->getNodes("player", player_nodes);
for (unsigned int i = 0; iisGuestAccount())
{
Log::info("PlayerManager", "Enfocring current player '%s'.",
- player->getName().c_str());
+ player->getName().c_str());
m_current_player = player;
return;
}
diff --git a/src/config/player_profile.cpp b/src/config/player_profile.cpp
index 0e761aed5..9cebfedb1 100644
--- a/src/config/player_profile.cpp
+++ b/src/config/player_profile.cpp
@@ -49,8 +49,13 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest)
m_saved_token = "";
m_saved_user_id = 0;
m_last_online_name = "";
- m_achievements_status = NULL;
- m_story_mode_status = NULL;
+ if (unlock_manager && AchievementsManager::get())
+ initRemainingData();
+ else
+ {
+ m_achievements_status = NULL;
+ m_story_mode_status = NULL;
+ }
} // PlayerProfile
//------------------------------------------------------------------------------
diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp
index fe46ce4bf..a3451a457 100644
--- a/src/states_screens/story_mode_lobby.cpp
+++ b/src/states_screens/story_mode_lobby.cpp
@@ -56,7 +56,9 @@ void StoryModeLobbyScreen::init()
assert(m_username_tb);
m_password_tb = getWidget("password");
assert(m_password_tb);
- //m_password_tb->setPasswordBox(true, L'*');
+ m_password_tb->setPasswordBox(true, L'*');
+ m_players = getWidget("players");
+ assert(m_players);
Screen::init();
PlayerProfile *player = PlayerManager::getCurrentPlayer();
@@ -66,20 +68,23 @@ void StoryModeLobbyScreen::init()
//return;
}
- DynamicRibbonWidget* local = getWidget("local");
- assert( local != NULL );
-
+ m_players->clearItems();
for (unsigned int n=0; ngetNumPlayers(); n++)
{
const PlayerProfile *player = PlayerManager::get()->getPlayer(n);
if (player->isGuestAccount()) continue;
std::string s = StringUtils::toString(n);
- local->addItem(player->getName(), s, "/karts/nolok/nolokicon.png", 0,
+ m_players->addItem(player->getName(), s, "/karts/nolok/nolokicon.png", 0,
IconButtonWidget::ICON_PATH_TYPE_RELATIVE);
}
- local->updateItemDisplay();
- update();
+ m_players->updateItemDisplay();
+
+ // Select the first user (the list of users is sorted by usage, so it
+ // is the most frequently used user).
+ if (PlayerManager::get()->getNumPlayers()>0)
+ selectUser(0);
+
} // init
@@ -91,9 +96,47 @@ void StoryModeLobbyScreen::tearDown()
} // tearDown
// ----------------------------------------------------------------------------
-void StoryModeLobbyScreen::update()
+/** Called when a user is selected. It updates the online checkbox and
+ * entrye fields.
+ */
+void StoryModeLobbyScreen::selectUser(int index)
+{
+ PlayerProfile *profile = PlayerManager::get()->getPlayer(index);
+ assert(profile);
+ getWidget("username")->setText(profile
+ ->getLastOnlineName());
+ m_players->setSelection(StringUtils::toString(index), 0, /*focusIt*/true);
+
+ // Last game was not online, so make the offline settings the default
+ // (i.e. unckeck online checkbox, and make entry fields invisible).
+ if (profile->getLastOnlineName() == "")
+ {
+ m_online_cb->setState(false);
+ makeEntryFieldsVisible(false);
+ return;
+ }
+
+ // Now last use was with online --> Display the saved data
+ makeEntryFieldsVisible(true);
+ m_username_tb->setText(profile->getLastOnlineName());
+
+ // And make the password invisible if the session is saved (i.e
+ // the user does not need to enter a password).
+ if (profile->hasSavedSession())
+ {
+ m_password_tb->setVisible(false);
+ getWidget("label_password")->setVisible(false);
+ }
+
+} // selectUser
+
+// ----------------------------------------------------------------------------
+/** Make the entry fields either visible or invisible.
+ * \param online Online state, which dicates if the entry fields are
+ * visible (true) or not.
+ */
+void StoryModeLobbyScreen::makeEntryFieldsVisible(bool online)
{
- bool online = m_online_cb->getState();
getWidget("label_username")->setVisible(online);
m_username_tb->setVisible(online);
getWidget("label_password")->setVisible(online);
@@ -101,33 +144,27 @@ void StoryModeLobbyScreen::update()
} // update
// ----------------------------------------------------------------------------
+/** Called when the user selects anything on the screen.
+ */
void StoryModeLobbyScreen::eventCallback(Widget* widget,
const std::string& name,
const int player_id)
{
- if (name == "local")
+ if (name == "players")
{
// Clicked on a name --> Find the corresponding online data
// and display them
- const std::string &s_index = getWidget("local")
- ->getSelectionIDString(player_id);
+ const std::string &s_index = getWidget("players")
+ ->getSelectionIDString(player_id);
if (s_index == "") return; // can happen if the list is empty
unsigned int id;
- StringUtils::fromString(s_index, id);
- PlayerProfile *profile = PlayerManager::get()->getPlayer(id);
- assert(profile);
- getWidget("username")->setText(profile
- ->getLastOnlineName());
- // In case of a saved session, remove the password field,
- // since it is not necessary to display it.
- getWidget("password")->setVisible(profile
- ->hasSavedSession());
-
+ if (StringUtils::fromString(s_index, id))
+ selectUser(id);
}
else if (name == "online")
{
- update(); // This will make the fields (in)visible
+ makeEntryFieldsVisible(m_online_cb->getState());
}
else if (name == "options")
{
@@ -135,13 +172,14 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget,
getWidget("options")->getSelectionIDString(player_id);
if (button == "ok" || button == "ok_and_save")
{
- DynamicRibbonWidget *local = getWidget("local");
- const std::string &name = local->getSelectionIDString(player_id);
- if (name == "local_new")
+ if (m_online_cb->getState() && m_password_tb->getText() == "")
{
- // create new local player
+ getWidget("message")->setText("Enter password",true);
return;
}
+
+ const std::string &name = m_players->getSelectionIDString(player_id);
+
unsigned int id;
StringUtils::fromString(name, id);
PlayerProfile *profile = PlayerManager::get()->getPlayer(id);
@@ -149,9 +187,12 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget,
StateManager::get()->pushScreen(MainMenuScreen::getInstance());
return;
} // button==ok || ok_and_save
+ else if (button == "new_user")
+ {
+ new EnterPlayerNameDialog(this, 0.5f, 0.4f);
+ }
} // options
- update();
return;
@@ -159,10 +200,6 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget,
{
StateManager::get()->escapePressed();
}
- else if (name == "creategame")
- {
- new EnterPlayerNameDialog(this, 0.5f, 0.4f);
- }
else if (name == "gameslots")
{
ListWidget* list = getWidget("gameslots");
@@ -206,30 +243,15 @@ void StoryModeLobbyScreen::unloaded()
} // unloaded
// ----------------------------------------------------------------------------
-
-void StoryModeLobbyScreen::onNewPlayerWithName(const core::stringw& newName)
+/** This is a callback from the new user dialog.
+ */
+void StoryModeLobbyScreen::onNewPlayerWithName(const core::stringw& new_name)
{
- bool slot_found = false;
-
- for (unsigned int n=0; ngetNumPlayers(); n++)
- {
- PlayerProfile *player = PlayerManager::get()->getPlayer(n);
- if (player->getName() == newName)
- {
- PlayerManager::get()->setCurrentPlayer(player, false);
- slot_found = true;
- break;
- }
- }
-
- if (!slot_found)
- {
- Log::error("StoryModeLobbyScreen",
- "Cannot find player corresponding to slot '%s'.",
- core::stringc(newName.c_str()).c_str());
- }
-
- StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
+ init();
+ // Select the newly added player
+ selectUser(PlayerManager::get()->getNumPlayers() - 1);
+
+ return;
} // onNewPlayerWithName
// -----------------------------------------------------------------------------
diff --git a/src/states_screens/story_mode_lobby.hpp b/src/states_screens/story_mode_lobby.hpp
index dcd647925..ce506f97f 100644
--- a/src/states_screens/story_mode_lobby.hpp
+++ b/src/states_screens/story_mode_lobby.hpp
@@ -52,7 +52,11 @@ private:
/** Password widget. */
GUIEngine::TextBoxWidget *m_password_tb;
- void update();
+ /** The dynamic ribbon containing all players. */
+ GUIEngine::DynamicRibbonWidget* m_players;
+
+ void selectUser(int index);
+ void makeEntryFieldsVisible(bool online);
public:
friend class GUIEngine::ScreenSingleton;