Fixed start with no players (including aborting the create user screen),
added 'lastWasOnline' flag to enable saving of a login token even when the account is used offline in between.
This commit is contained in:
parent
cf297c67b4
commit
1946df97be
@ -47,6 +47,7 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest)
|
|||||||
m_saved_token = "";
|
m_saved_token = "";
|
||||||
m_saved_user_id = 0;
|
m_saved_user_id = 0;
|
||||||
m_last_online_name = "";
|
m_last_online_name = "";
|
||||||
|
m_last_was_online = false;
|
||||||
initRemainingData();
|
initRemainingData();
|
||||||
} // PlayerProfile
|
} // PlayerProfile
|
||||||
|
|
||||||
@ -71,6 +72,7 @@ PlayerProfile::PlayerProfile(const XMLNode* node)
|
|||||||
m_saved_token = "";
|
m_saved_token = "";
|
||||||
m_saved_user_id = 0;
|
m_saved_user_id = 0;
|
||||||
m_last_online_name = "";
|
m_last_online_name = "";
|
||||||
|
m_last_was_online = false;
|
||||||
m_story_mode_status = NULL;
|
m_story_mode_status = NULL;
|
||||||
m_achievements_status = NULL;
|
m_achievements_status = NULL;
|
||||||
|
|
||||||
@ -82,6 +84,7 @@ PlayerProfile::PlayerProfile(const XMLNode* node)
|
|||||||
node->get("saved-user", &m_saved_user_id );
|
node->get("saved-user", &m_saved_user_id );
|
||||||
node->get("saved-token", &m_saved_token );
|
node->get("saved-token", &m_saved_token );
|
||||||
node->get("last-online-name", &m_last_online_name);
|
node->get("last-online-name", &m_last_online_name);
|
||||||
|
node->get("last-was-online", &m_last_was_online );
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
m_magic_number = 0xABCD1234;
|
m_magic_number = 0xABCD1234;
|
||||||
@ -138,7 +141,8 @@ void PlayerProfile::save(UTFWriter &out)
|
|||||||
|
|
||||||
out << L" saved-user=\"" << m_saved_user_id
|
out << L" saved-user=\"" << m_saved_user_id
|
||||||
<< L"\" saved-token=\"" << m_saved_token << L"\"\n";
|
<< L"\" saved-token=\"" << m_saved_token << L"\"\n";
|
||||||
out << L" last-online-name=\"" << m_last_online_name<< L"\">\n";
|
out << L" last-online-name=\"" << m_last_online_name
|
||||||
|
<< L"\" last-was-online=\"" << m_last_was_online<< L"\">\n";
|
||||||
{
|
{
|
||||||
if(m_story_mode_status)
|
if(m_story_mode_status)
|
||||||
m_story_mode_status->save(out);
|
m_story_mode_status->save(out);
|
||||||
|
@ -95,6 +95,9 @@ private:
|
|||||||
/** The online user name used last (empty if not used online). */
|
/** The online user name used last (empty if not used online). */
|
||||||
core::stringw m_last_online_name;
|
core::stringw m_last_online_name;
|
||||||
|
|
||||||
|
/** True if the last time this player was used as online. */
|
||||||
|
bool m_last_was_online;
|
||||||
|
|
||||||
/** The complete challenge state. */
|
/** The complete challenge state. */
|
||||||
StoryModeStatus *m_story_mode_status;
|
StoryModeStatus *m_story_mode_status;
|
||||||
|
|
||||||
@ -256,6 +259,13 @@ public:
|
|||||||
return m_saved_token;
|
return m_saved_token;
|
||||||
} // getSavedToken
|
} // getSavedToken
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
/** Returns if the last time this player was used it was used online or
|
||||||
|
* offline. */
|
||||||
|
bool wasOnlineLastTime() const { return m_last_was_online; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
/** Sets if this player was logged in last time it was used. */
|
||||||
|
void setWasOnlineLastTime(bool b) { m_last_was_online = b; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
}; // class PlayerProfile
|
}; // class PlayerProfile
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -189,6 +189,7 @@
|
|||||||
#include "replay/replay_play.hpp"
|
#include "replay/replay_play.hpp"
|
||||||
#include "replay/replay_recorder.hpp"
|
#include "replay/replay_recorder.hpp"
|
||||||
#include "states_screens/main_menu_screen.hpp"
|
#include "states_screens/main_menu_screen.hpp"
|
||||||
|
#include "states_screens/register_screen.hpp"
|
||||||
#include "states_screens/state_manager.hpp"
|
#include "states_screens/state_manager.hpp"
|
||||||
#include "states_screens/user_screen.hpp"
|
#include "states_screens/user_screen.hpp"
|
||||||
#include "states_screens/dialogs/message_dialog.hpp"
|
#include "states_screens/dialogs/message_dialog.hpp"
|
||||||
@ -1293,7 +1294,14 @@ int main(int argc, char *argv[] )
|
|||||||
if(PlayerManager::getCurrentPlayer())
|
if(PlayerManager::getCurrentPlayer())
|
||||||
StateManager::get()->pushScreen(MainMenuScreen::getInstance());
|
StateManager::get()->pushScreen(MainMenuScreen::getInstance());
|
||||||
else
|
else
|
||||||
|
{
|
||||||
StateManager::get()->pushScreen(UserScreen::getInstance());
|
StateManager::get()->pushScreen(UserScreen::getInstance());
|
||||||
|
// If there is no player, push the RegisterScreen on top of
|
||||||
|
// the login screen. This way on first start players are
|
||||||
|
// forced to create a player.
|
||||||
|
if(PlayerManager::get()->getNumPlayers()==0)
|
||||||
|
StateManager::get()->pushScreen(RegisterScreen::getInstance());
|
||||||
|
}
|
||||||
#ifdef ENABLE_WIIUSE
|
#ifdef ENABLE_WIIUSE
|
||||||
// Show a dialog to allow connection of wiimotes. */
|
// Show a dialog to allow connection of wiimotes. */
|
||||||
if(WiimoteManager::isEnabled())
|
if(WiimoteManager::isEnabled())
|
||||||
|
@ -94,7 +94,7 @@ namespace Online
|
|||||||
void OnlinePlayerProfile::requestSavedSession()
|
void OnlinePlayerProfile::requestSavedSession()
|
||||||
{
|
{
|
||||||
SignInRequest * request = NULL;
|
SignInRequest * request = NULL;
|
||||||
if (m_online_state == OS_SIGNED_OUT && hasSavedSession() )
|
if (m_online_state == OS_SIGNED_OUT && hasSavedSession())
|
||||||
{
|
{
|
||||||
request = new SignInRequest(true);
|
request = new SignInRequest(true);
|
||||||
request->setServerURL("client-user.php");
|
request->setServerURL("client-user.php");
|
||||||
|
@ -97,7 +97,7 @@ void RegisterScreen::makeEntryFieldsVisible(bool online)
|
|||||||
getWidget<LabelWidget >("label_email")->setVisible(online);
|
getWidget<LabelWidget >("label_email")->setVisible(online);
|
||||||
getWidget<TextBoxWidget>("email_confirm")->setVisible(online);
|
getWidget<TextBoxWidget>("email_confirm")->setVisible(online);
|
||||||
getWidget<LabelWidget >("label_email_confirm")->setVisible(online);
|
getWidget<LabelWidget >("label_email_confirm")->setVisible(online);
|
||||||
} // makeEntryFieldvisible
|
} // makeEntryFieldsVisible
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
/** If necessary creates the local user.
|
/** If necessary creates the local user.
|
||||||
@ -268,7 +268,12 @@ void RegisterScreen::eventCallback(Widget* widget, const std::string& name,
|
|||||||
doRegister();
|
doRegister();
|
||||||
}
|
}
|
||||||
else if(button=="cancel")
|
else if(button=="cancel")
|
||||||
StateManager::get()->escapePressed();
|
{
|
||||||
|
// We poop this menu, onEscapePress will handle the special case
|
||||||
|
// of e.g. a fresh start of stk that is aborted.
|
||||||
|
StateManager::get()->popMenu();
|
||||||
|
onEscapePressed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (name == "back")
|
else if (name == "back")
|
||||||
{
|
{
|
||||||
@ -278,3 +283,18 @@ void RegisterScreen::eventCallback(Widget* widget, const std::string& name,
|
|||||||
} // eventCallback
|
} // eventCallback
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
bool RegisterScreen::onEscapePressed()
|
||||||
|
{
|
||||||
|
if (PlayerManager::get()->getNumPlayers() == 0)
|
||||||
|
{
|
||||||
|
// Must be first time start, and player cancelled player creation
|
||||||
|
// so quit stk. At this stage there are two menus on the stack:
|
||||||
|
// 1) The UserScreen, 2) RegisterStreen
|
||||||
|
// Popping them both will trigger STK to close.
|
||||||
|
StateManager::get()->popMenu();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
StateManager::get()->escapePressed();
|
||||||
|
return true;
|
||||||
|
} // onEscapePressed
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ public:
|
|||||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||||
virtual void loadedFromFile() OVERRIDE {};
|
virtual void loadedFromFile() OVERRIDE {};
|
||||||
virtual void onUpdate(float dt) OVERRIDE;
|
virtual void onUpdate(float dt) OVERRIDE;
|
||||||
|
virtual bool onEscapePressed() OVERRIDE;
|
||||||
|
|
||||||
void acceptTerms();
|
void acceptTerms();
|
||||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||||
|
@ -103,11 +103,13 @@ void BaseUserScreen::init()
|
|||||||
{
|
{
|
||||||
m_players->setSelection(current_player_index, PLAYER_ID_GAME_MASTER,
|
m_players->setSelection(current_player_index, PLAYER_ID_GAME_MASTER,
|
||||||
/*focus*/ true);
|
/*focus*/ true);
|
||||||
const stringw &online_name = PlayerManager::getCurrentPlayer()
|
PlayerProfile *player = PlayerManager::getCurrentPlayer();
|
||||||
->getLastOnlineName();
|
const stringw &online_name = player->getLastOnlineName();
|
||||||
m_online_cb->setState(online_name.size()>0);
|
|
||||||
m_username_tb->setText(online_name);
|
m_username_tb->setText(online_name);
|
||||||
makeEntryFieldsVisible(online_name.size()>0);
|
// Select 'online
|
||||||
|
m_online_cb->setState(player->wasOnlineLastTime() ||
|
||||||
|
player->isLoggedIn() );
|
||||||
|
makeEntryFieldsVisible();
|
||||||
}
|
}
|
||||||
else // no current player found
|
else // no current player found
|
||||||
{
|
{
|
||||||
@ -154,16 +156,17 @@ void BaseUserScreen::selectUser(int index)
|
|||||||
|
|
||||||
// Last game was not online, so make the offline settings the default
|
// Last game was not online, so make the offline settings the default
|
||||||
// (i.e. unckeck online checkbox, and make entry fields invisible).
|
// (i.e. unckeck online checkbox, and make entry fields invisible).
|
||||||
if (profile->getLastOnlineName() == "")
|
|
||||||
|
if (!profile->wasOnlineLastTime() || profile->getLastOnlineName() == "")
|
||||||
{
|
{
|
||||||
m_online_cb->setState(false);
|
m_online_cb->setState(false);
|
||||||
makeEntryFieldsVisible(false);
|
makeEntryFieldsVisible();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now last use was with online --> Display the saved data
|
// Now last use was with online --> Display the saved data
|
||||||
m_online_cb->setState(true);
|
m_online_cb->setState(true);
|
||||||
makeEntryFieldsVisible(true);
|
makeEntryFieldsVisible();
|
||||||
m_username_tb->setText(profile->getLastOnlineName());
|
m_username_tb->setText(profile->getLastOnlineName());
|
||||||
|
|
||||||
// And make the password invisible if the session is saved (i.e
|
// And make the password invisible if the session is saved (i.e
|
||||||
@ -181,26 +184,19 @@ void BaseUserScreen::selectUser(int index)
|
|||||||
* \param online Online state, which dicates if the entry fields are
|
* \param online Online state, which dicates if the entry fields are
|
||||||
* visible (true) or not.
|
* visible (true) or not.
|
||||||
*/
|
*/
|
||||||
void BaseUserScreen::makeEntryFieldsVisible(bool online)
|
void BaseUserScreen::makeEntryFieldsVisible()
|
||||||
{
|
{
|
||||||
#ifdef GUEST_ACCOUNTS_ENABLED
|
#ifdef GUEST_ACCOUNTS_ENABLED
|
||||||
getWidget<LabelWidget>("label_guest")->setVisible(online);
|
getWidget<LabelWidget>("label_guest")->setVisible(online);
|
||||||
getWidget<CheckBoxWidget>("guest")->setVisible(online);
|
getWidget<CheckBoxWidget>("guest")->setVisible(online);
|
||||||
#endif
|
#endif
|
||||||
|
bool online = m_online_cb->getState();
|
||||||
getWidget<LabelWidget>("label_username")->setVisible(online);
|
getWidget<LabelWidget>("label_username")->setVisible(online);
|
||||||
m_username_tb->setVisible(online);
|
m_username_tb->setVisible(online);
|
||||||
getWidget<LabelWidget>("label_password")->setVisible(online);
|
getWidget<LabelWidget>("label_password")->setVisible(online);
|
||||||
m_password_tb->setVisible(online);
|
m_password_tb->setVisible(online);
|
||||||
} // makeEntryFieldsVisible
|
} // makeEntryFieldsVisible
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
/** Make sure that a current player is defined when escape is pressed.
|
|
||||||
*/
|
|
||||||
bool BaseUserScreen::onEscapePressed()
|
|
||||||
{
|
|
||||||
return Screen::onEscapePressed();
|
|
||||||
} // onEscapePressed
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** Called when the user selects anything on the screen.
|
/** Called when the user selects anything on the screen.
|
||||||
*/
|
*/
|
||||||
@ -237,7 +233,7 @@ void BaseUserScreen::eventCallback(Widget* widget,
|
|||||||
sfx_manager->quickSound( "anvil" );
|
sfx_manager->quickSound( "anvil" );
|
||||||
m_online_cb->setState(false);
|
m_online_cb->setState(false);
|
||||||
}
|
}
|
||||||
makeEntryFieldsVisible(m_online_cb->getState());
|
makeEntryFieldsVisible();
|
||||||
}
|
}
|
||||||
else if (name == "options")
|
else if (name == "options")
|
||||||
{
|
{
|
||||||
@ -253,10 +249,8 @@ void BaseUserScreen::eventCallback(Widget* widget,
|
|||||||
}
|
}
|
||||||
else if (button == "cancel")
|
else if (button == "cancel")
|
||||||
{
|
{
|
||||||
PlayerProfile *cp = PlayerManager::getCurrentPlayer();
|
|
||||||
if(cp && cp->isLoggedIn())
|
|
||||||
cp->requestSignOut();
|
|
||||||
StateManager::get()->popMenu();
|
StateManager::get()->popMenu();
|
||||||
|
onEscapePressed();
|
||||||
}
|
}
|
||||||
else if (button == "rename")
|
else if (button == "rename")
|
||||||
{
|
{
|
||||||
@ -296,27 +290,30 @@ void BaseUserScreen::login()
|
|||||||
// problem will activate the widget again.
|
// problem will activate the widget again.
|
||||||
m_options_widget->setDeactivated();
|
m_options_widget->setDeactivated();
|
||||||
|
|
||||||
PlayerProfile *profile = getSelectedPlayer();
|
PlayerProfile *player = getSelectedPlayer();
|
||||||
PlayerManager::get()->setCurrentPlayer(profile);
|
PlayerManager::get()->setCurrentPlayer(player);
|
||||||
assert(profile);
|
assert(player);
|
||||||
|
|
||||||
// If no online login requested, go straight to the main menu screen.
|
// If no online login requested, go straight to the main menu screen.
|
||||||
if(!m_online_cb->getState())
|
if(!m_online_cb->getState())
|
||||||
{
|
{
|
||||||
if(profile->isLoggedIn())
|
if(player->isLoggedIn())
|
||||||
{
|
{
|
||||||
// The player is logged in, but online is now disabled,
|
// The player is logged in, but online is now disabled,
|
||||||
// so log the player out. There is no error handling of
|
// so log the player out. There is no error handling of
|
||||||
// a failed logout request
|
// a failed logout request
|
||||||
profile->requestSignOut();
|
player->requestSignOut();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player->setWasOnlineLastTime(false);
|
||||||
closeScreen();
|
closeScreen();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Player wants to be online, and is already online - nothing to do
|
// Player wants to be online, and is already online - nothing to do
|
||||||
if(profile->isLoggedIn())
|
if(player->isLoggedIn())
|
||||||
{
|
{
|
||||||
|
player->setWasOnlineLastTime(true);
|
||||||
closeScreen();
|
closeScreen();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -325,10 +322,10 @@ void BaseUserScreen::login()
|
|||||||
// This implies that this screen will wait till the server responds, so
|
// This implies that this screen will wait till the server responds, so
|
||||||
// that error messages ('invalid password') can be shown, and the user
|
// that error messages ('invalid password') can be shown, and the user
|
||||||
// can decide what to do about them.
|
// can decide what to do about them.
|
||||||
if (profile->hasSavedSession())
|
if (player->hasSavedSession())
|
||||||
{
|
{
|
||||||
// Online login with saved token
|
// Online login with saved token
|
||||||
profile->requestSavedSession();
|
player->requestSavedSession();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -340,7 +337,7 @@ void BaseUserScreen::login()
|
|||||||
m_options_widget->setActivated();
|
m_options_widget->setActivated();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
profile->requestSignIn(m_username_tb->getText(),
|
player->requestSignIn(m_username_tb->getText(),
|
||||||
m_password_tb->getText());
|
m_password_tb->getText());
|
||||||
} // !hasSavedSession
|
} // !hasSavedSession
|
||||||
|
|
||||||
@ -362,6 +359,8 @@ void BaseUserScreen::onUpdate(float dt)
|
|||||||
*/
|
*/
|
||||||
void BaseUserScreen::loginSuccessful()
|
void BaseUserScreen::loginSuccessful()
|
||||||
{
|
{
|
||||||
|
PlayerProfile *player = getSelectedPlayer();
|
||||||
|
player->setWasOnlineLastTime(true);
|
||||||
m_options_widget->setActivated();
|
m_options_widget->setActivated();
|
||||||
// Clean any error message still shown
|
// Clean any error message still shown
|
||||||
m_info_widget->setText("", true);
|
m_info_widget->setText("", true);
|
||||||
@ -448,6 +447,7 @@ void BaseUserScreen::unloaded()
|
|||||||
*/
|
*/
|
||||||
void BaseUserScreen::onDialogClose()
|
void BaseUserScreen::onDialogClose()
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
// To allow players to exit the game without creating a player, we count
|
// To allow players to exit the game without creating a player, we count
|
||||||
// how often this function was called. The first time is after the
|
// how often this function was called. The first time is after the
|
||||||
// internet allowed dialog, the 2nd time
|
// internet allowed dialog, the 2nd time
|
||||||
|
@ -70,7 +70,7 @@ private:
|
|||||||
GUIEngine::DynamicRibbonWidget* m_players;
|
GUIEngine::DynamicRibbonWidget* m_players;
|
||||||
|
|
||||||
void selectUser(int index);
|
void selectUser(int index);
|
||||||
void makeEntryFieldsVisible(bool online);
|
void makeEntryFieldsVisible();
|
||||||
void login();
|
void login();
|
||||||
void closeScreen();
|
void closeScreen();
|
||||||
void deletePlayer();
|
void deletePlayer();
|
||||||
@ -95,7 +95,6 @@ public:
|
|||||||
|
|
||||||
/** \brief implement optional callback from parent class GUIEngine::Screen */
|
/** \brief implement optional callback from parent class GUIEngine::Screen */
|
||||||
virtual void unloaded();
|
virtual void unloaded();
|
||||||
virtual bool onEscapePressed();
|
|
||||||
|
|
||||||
void loginSuccessful();
|
void loginSuccessful();
|
||||||
void loginError(const irr::core::stringw &error_message);
|
void loginError(const irr::core::stringw &error_message);
|
||||||
|
Loading…
Reference in New Issue
Block a user