Moved getUserState from CurrentUser to PlayerManager::getCurrentOnlineState().
This commit is contained in:
@@ -46,7 +46,7 @@ void PlayerManager::create()
|
||||
|
||||
} // create
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Adds the login credential to a http request. It sets the name of
|
||||
* the script to invokce, token, and user id.
|
||||
* \param request The http request.
|
||||
@@ -59,14 +59,14 @@ void PlayerManager::setUserDetails(Online::HTTPRequest *request,
|
||||
get()->getCurrentUser()->setUserDetails(request, action, php_name);
|
||||
} // setUserDetails
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns whether a user is signed in or not. */
|
||||
bool PlayerManager::isCurrentLoggedIn()
|
||||
{
|
||||
return getCurrentUser()->isRegisteredUser();
|
||||
} // isCurrentLoggedIn
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns the online id of the current player.
|
||||
* \pre User logged in (which is asserted in getID()).
|
||||
*/
|
||||
@@ -75,6 +75,15 @@ unsigned int PlayerManager::getCurrentOnlineId()
|
||||
return getCurrentUser()->getID();
|
||||
} // getCurrentOnlineId
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns the online state of the current player. It can be logged out,
|
||||
* logging in, logged in, logging out, logged out, or guest.
|
||||
*/
|
||||
PlayerManager::OnlineState PlayerManager::getCurrentOnlineState()
|
||||
{
|
||||
return (OnlineState)getCurrentUser()->getUserState();
|
||||
} // getCurrentOnlineState
|
||||
|
||||
// ============================================================================
|
||||
/** Constructor.
|
||||
*/
|
||||
|
||||
@@ -99,6 +99,19 @@ public:
|
||||
const std::string &php_name = "");
|
||||
static unsigned int getCurrentOnlineId();
|
||||
static bool isCurrentLoggedIn();
|
||||
|
||||
/** The online state a player can be in. */
|
||||
enum OnlineState
|
||||
{
|
||||
OS_SIGNED_OUT = 0,
|
||||
OS_SIGNED_IN,
|
||||
OS_GUEST,
|
||||
OS_SIGNING_IN,
|
||||
OS_SIGNING_OUT
|
||||
};
|
||||
|
||||
static OnlineState getCurrentOnlineState();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the current player. */
|
||||
static PlayerProfile* getCurrentPlayer()
|
||||
|
||||
@@ -51,15 +51,6 @@ namespace Online
|
||||
private:
|
||||
LEAK_CHECK()
|
||||
public:
|
||||
enum UserState
|
||||
{
|
||||
US_SIGNED_OUT = 0,
|
||||
US_SIGNED_IN,
|
||||
US_GUEST,
|
||||
US_SIGNING_IN,
|
||||
US_SIGNING_OUT
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
class SignInRequest : public XMLRequest
|
||||
{
|
||||
@@ -87,7 +78,6 @@ namespace Online
|
||||
private:
|
||||
std::string m_token;
|
||||
bool m_save_session;
|
||||
UserState m_state;
|
||||
OnlineProfile *m_profile;
|
||||
|
||||
bool saveSession() const { return m_save_session; }
|
||||
@@ -105,6 +95,18 @@ namespace Online
|
||||
const std::string &action,
|
||||
const std::string &php_script = "");
|
||||
bool isRegisteredUser() const { return m_state == US_SIGNED_IN; }
|
||||
/** Returns the user state. */
|
||||
enum UserState
|
||||
{
|
||||
US_SIGNED_OUT = 0,
|
||||
US_SIGNED_IN,
|
||||
US_GUEST,
|
||||
US_SIGNING_IN,
|
||||
US_SIGNING_OUT
|
||||
};
|
||||
UserState m_state;
|
||||
const UserState getUserState() const { return m_state; }
|
||||
|
||||
|
||||
public:
|
||||
CurrentUser();
|
||||
@@ -121,8 +123,6 @@ namespace Online
|
||||
|
||||
irr::core::stringw getUserName() const;
|
||||
// ----------------------------------------------------------------
|
||||
/** Returns the user state. */
|
||||
const UserState getUserState() const { return m_state; }
|
||||
// ----------------------------------------------------------------
|
||||
/** Returns the session token of the signed in user. */
|
||||
const std::string& getToken() const { return m_token; }
|
||||
|
||||
@@ -146,13 +146,13 @@ void MainMenuScreen::init()
|
||||
void MainMenuScreen::onUpdate(float delta)
|
||||
|
||||
{
|
||||
if(PlayerManager::getCurrentUser()->getUserState() == CurrentUser::US_GUEST ||
|
||||
PlayerManager::getCurrentUser()->getUserState() == CurrentUser::US_SIGNED_IN)
|
||||
if(PlayerManager::getCurrentOnlineState() == PlayerManager::OS_GUEST ||
|
||||
PlayerManager::getCurrentOnlineState() == PlayerManager::OS_SIGNED_IN)
|
||||
{
|
||||
m_online->setActivated();
|
||||
m_online->setLabel( _("Online"));
|
||||
}
|
||||
else if (PlayerManager::getCurrentUser()->getUserState() == CurrentUser::US_SIGNED_OUT)
|
||||
else if (PlayerManager::getCurrentOnlineState() == PlayerManager::OS_SIGNED_OUT)
|
||||
{
|
||||
m_online->setActivated();
|
||||
m_online->setLabel( _("Login" ));
|
||||
|
||||
@@ -56,7 +56,7 @@ DEFINE_SCREEN_SINGLETON( OnlineScreen );
|
||||
|
||||
OnlineScreen::OnlineScreen() : Screen("online/main.stkgui")
|
||||
{
|
||||
m_recorded_state = CurrentUser::US_SIGNED_OUT;
|
||||
m_recorded_state = PlayerManager::OS_SIGNED_OUT;
|
||||
} // OnlineScreen
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -98,8 +98,8 @@ void OnlineScreen::loadedFromFile()
|
||||
*/
|
||||
bool OnlineScreen::hasStateChanged()
|
||||
{
|
||||
CurrentUser::UserState previous_state = m_recorded_state;
|
||||
m_recorded_state = PlayerManager::getCurrentUser()->getUserState();
|
||||
PlayerManager::OnlineState previous_state = m_recorded_state;
|
||||
m_recorded_state = PlayerManager::getCurrentOnlineState();
|
||||
if (previous_state != m_recorded_state)
|
||||
return true;
|
||||
return false;
|
||||
@@ -112,9 +112,9 @@ void OnlineScreen::beforeAddingWidget()
|
||||
m_bottom_menu_widget->setVisible(true);
|
||||
m_top_menu_widget->setVisible(true);
|
||||
hasStateChanged();
|
||||
if (m_recorded_state == CurrentUser::US_SIGNED_OUT ||
|
||||
m_recorded_state == CurrentUser::US_SIGNING_IN ||
|
||||
m_recorded_state == CurrentUser::US_SIGNING_OUT )
|
||||
if (m_recorded_state == PlayerManager::OS_SIGNED_OUT ||
|
||||
m_recorded_state == PlayerManager::OS_SIGNING_IN ||
|
||||
m_recorded_state == PlayerManager::OS_SIGNING_OUT)
|
||||
{
|
||||
m_quick_play_widget->setDeactivated();
|
||||
m_find_server_widget->setDeactivated();
|
||||
@@ -122,7 +122,7 @@ void OnlineScreen::beforeAddingWidget()
|
||||
m_sign_out_widget->setVisible(false);
|
||||
m_profile_widget->setVisible(false);
|
||||
}
|
||||
else if (m_recorded_state == CurrentUser::US_GUEST)
|
||||
else if (m_recorded_state == PlayerManager::OS_GUEST)
|
||||
{
|
||||
m_find_server_widget->setDeactivated();
|
||||
m_create_server_widget->setDeactivated();
|
||||
@@ -151,11 +151,11 @@ void OnlineScreen::onUpdate(float delta)
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_recorded_state == CurrentUser::US_SIGNING_IN)
|
||||
if (m_recorded_state == PlayerManager::OS_SIGNING_IN)
|
||||
{
|
||||
m_online_status_widget->setText(Messages::signingIn(), false);
|
||||
}
|
||||
else if (m_recorded_state == CurrentUser::US_SIGNING_OUT)
|
||||
else if (m_recorded_state == PlayerManager::OS_SIGNING_OUT)
|
||||
{
|
||||
m_online_status_widget->setText(Messages::signingOut(), false);
|
||||
}
|
||||
@@ -259,7 +259,7 @@ void OnlineScreen::tearDown()
|
||||
*/
|
||||
void OnlineScreen::setInitialFocus()
|
||||
{
|
||||
if(m_recorded_state == CurrentUser::US_SIGNED_IN)
|
||||
if (m_recorded_state == PlayerManager::OS_SIGNED_IN)
|
||||
m_top_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
else
|
||||
m_bottom_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
#ifndef HEADER_ONLINE_SCREEN_HPP
|
||||
#define HEADER_ONLINE_SCREEN_HPP
|
||||
|
||||
#include "config/player_manager.hpp"
|
||||
#include "guiengine/screen.hpp"
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
#include "online/current_user.hpp"
|
||||
#include "utils/ptr_vector.hpp"
|
||||
|
||||
namespace GUIEngine { class Widget; class ListWidget; }
|
||||
@@ -54,7 +54,7 @@ private:
|
||||
GUIEngine::IconButtonWidget * m_profile_widget;
|
||||
GUIEngine::IconButtonWidget * m_sign_out_widget;
|
||||
|
||||
Online::CurrentUser::UserState m_recorded_state;
|
||||
PlayerManager::OnlineState m_recorded_state;
|
||||
|
||||
bool hasStateChanged();
|
||||
void setInitialFocus();
|
||||
|
||||
Reference in New Issue
Block a user