Fix #1620 (Player's achievements can only be seen when logged in).

This commit is contained in:
hiker 2014-11-25 17:12:47 +11:00
parent 49474a5370
commit ea3a433147
8 changed files with 131 additions and 56 deletions

View File

@ -57,6 +57,8 @@
I18N="In the main screen" text="Help" label_location="hover"/>
<icon-button id="startTutorial" width="64" height="64" icon="gui/tutorial.png" extend_label="150"
I18N="In the main screen" text="Tutorial" label_location="hover"/>
<icon-button id="achievements" width="64" height="64" icon="gui/gp_copy.png" extend_label="150"
I18N="In the main screen" text="Achievements" label_location="hover"/>
<icon-button id="gpEditor" width="64" height="64" icon="gui/gpeditor.png" extend_label="150"
I18N="In the main screen" text="Grand Prix Editor" label_location="hover"/>
<icon-button id="about" width="64" height="64" icon="gui/main_about.png" extend_label="50"

View File

@ -8,13 +8,6 @@
<spacer height="25" width="10"/>
<tabs id="profile_tabs" height="10%" max_height="110" x="2%" width="98%" align="center">
<icon-button id="tab_achievements" width="128" height="128" icon="gui/options_players.png"
I18N="Section in the profile screen" text="Achievements"/>
<icon-button id="tab_friends" width="128" height="128" icon="gui/options_players.png"/>
<icon-button id="tab_settings" width="128" height="128" icon="gui/main_options.png"/>
</tabs>
<box proportion="1" width="100%" layout="vertical-row" padding="6">
<list id="achievements_list" x="0" y="0" width="100%" height="100%"/>
</box>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<stkgui>
<icon-button id="back" x="0" y="0" height="8%" icon="gui/back.png"/>
<div x="1%" y="1%" width="98%" height="98%" layout="vertical-row" >
<header id="title" text_align="center" width="80%" align="center" text="..."/>
<spacer height="25" width="10"/>
<tabs id="profile_tabs" height="10%" max_height="110" x="2%" width="98%" align="center">
<icon-button id="tab_achievements" width="128" height="128" icon="gui/options_players.png"
I18N="Section in the profile screen" text="Achievements"/>
<icon-button id="tab_friends" width="128" height="128" icon="gui/options_players.png"/>
<icon-button id="tab_settings" width="128" height="128" icon="gui/main_options.png"/>
</tabs>
<box proportion="1" width="100%" layout="vertical-row" padding="6">
<list id="achievements_list" x="0" y="0" width="100%" height="100%"/>
</box>
</div>
</stkgui>

View File

@ -496,7 +496,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
// For 0.8.2 disable the server menu, instead go to online profile
//OnlineScreen::getInstance()->push();
ProfileManager::get()->setVisiting(PlayerManager::getCurrentOnlineId());
OnlineProfileAchievements::getInstance()->push();
TabOnlineProfileAchievements::getInstance()->push();
}
else
{
@ -522,6 +522,10 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
{
GrandPrixEditorScreen::getInstance()->push();
}
else if (selection == "achievements")
{
OnlineProfileAchievements::getInstance()->push();
}
} // eventCallback
// ----------------------------------------------------------------------------

View File

@ -40,21 +40,22 @@ using namespace irr::core;
using namespace irr::gui;
using namespace Online;
DEFINE_SCREEN_SINGLETON( OnlineProfileAchievements );
DEFINE_SCREEN_SINGLETON( OnlineProfileAchievements );
DEFINE_SCREEN_SINGLETON( TabOnlineProfileAchievements );
// -----------------------------------------------------------------------------
/** Constructor.
*/
OnlineProfileAchievements::OnlineProfileAchievements()
: OnlineProfileBase("online/profile_achievements.stkgui")
BaseOnlineProfileAchievements::BaseOnlineProfileAchievements(const std::string &name)
: OnlineProfileBase(name)
{
m_selected_achievement_index = -1;
} // OnlineProfileAchievements
} // BaseOnlineProfileAchievements
// -----------------------------------------------------------------------------
/** Callback when the xml file was loaded.
*/
void OnlineProfileAchievements::loadedFromFile()
void BaseOnlineProfileAchievements::loadedFromFile()
{
OnlineProfileBase::loadedFromFile();
m_achievements_list_widget = getWidget<ListWidget>("achievements_list");
@ -65,7 +66,7 @@ void OnlineProfileAchievements::loadedFromFile()
// ----------------------------------------------------------------------------
/** Callback before widgets are added. Clears all widgets.
*/
void OnlineProfileAchievements::beforeAddingWidget()
void BaseOnlineProfileAchievements::beforeAddingWidget()
{
OnlineProfileBase::beforeAddingWidget();
m_achievements_list_widget->clearColumns();
@ -82,11 +83,12 @@ void OnlineProfileAchievements::beforeAddingWidget()
// -----------------------------------------------------------------------------
/** Called when entering this menu (after widgets have been added).
*/
void OnlineProfileAchievements::init()
void BaseOnlineProfileAchievements::init()
{
OnlineProfileBase::init();
m_profile_tabs->select( m_achievements_tab->m_properties[PROP_ID],
PLAYER_ID_GAME_MASTER );
if (m_profile_tabs)
m_profile_tabs->select(m_achievements_tab->m_properties[PROP_ID],
PLAYER_ID_GAME_MASTER);
// For current user add the progrss information.
// m_visiting_profile is NULL if the user is not logged in.
@ -129,7 +131,7 @@ void OnlineProfileAchievements::init()
// -----------------------------------------------------------------------------
void OnlineProfileAchievements::eventCallback(Widget* widget,
void BaseOnlineProfileAchievements::eventCallback(Widget* widget,
const std::string& name,
const int playerID)
{
@ -155,7 +157,7 @@ void OnlineProfileAchievements::eventCallback(Widget* widget,
/** Called every frame. It will check if results from an achievement request
* have been received, and if so, display them.
*/
void OnlineProfileAchievements::onUpdate(float delta)
void BaseOnlineProfileAchievements::onUpdate(float delta)
{
if (!m_waiting_for_achievements) return;

View File

@ -35,18 +35,20 @@ namespace GUIEngine { class Widget; }
* \brief Online profiel overview screen
* \ingroup states_screens
*/
class OnlineProfileAchievements : public OnlineProfileBase, public GUIEngine::ScreenSingleton<OnlineProfileAchievements>
class BaseOnlineProfileAchievements : public OnlineProfileBase
{
private:
OnlineProfileAchievements();
GUIEngine::ListWidget * m_achievements_list_widget;
int m_selected_achievement_index;
bool m_waiting_for_achievements;
protected:
BaseOnlineProfileAchievements(const std::string &filename);
public:
friend class GUIEngine::ScreenSingleton<OnlineProfileAchievements>;
friend class GUIEngine::ScreenSingleton<BaseOnlineProfileAchievements>;
/** \brief implement callback from parent class GUIEngine::Screen */
virtual void loadedFromFile() OVERRIDE;
@ -61,7 +63,46 @@ public:
virtual void beforeAddingWidget() OVERRIDE;
virtual void refreshAchievementsList() { m_waiting_for_achievements = true; }
// ------------------------------------------------------------------------
virtual void refreshAchievementsList()
{
m_waiting_for_achievements = true;
} // refreshAchievementsList
};
// ============================================================================
/**
* \brief Online profiel overview screen
* \ingroup states_screens
*/
class TabOnlineProfileAchievements : public BaseOnlineProfileAchievements,
public GUIEngine::ScreenSingleton<TabOnlineProfileAchievements>
{
protected:
friend class GUIEngine::ScreenSingleton<TabOnlineProfileAchievements>;
TabOnlineProfileAchievements()
: BaseOnlineProfileAchievements("online/profile_achievements_tab.stkgui")
{}
}; // TabOnlineProfileAchievements
// ============================================================================
/**
* \brief Online profiel overview screen
* \ingroup states_screens
*/
class OnlineProfileAchievements : public BaseOnlineProfileAchievements,
public GUIEngine::ScreenSingleton < OnlineProfileAchievements >
{
protected:
friend class GUIEngine::ScreenSingleton<OnlineProfileAchievements>;
OnlineProfileAchievements()
: BaseOnlineProfileAchievements("online/profile_achievements.stkgui")
{}
}; // class
#endif

View File

@ -38,7 +38,8 @@ using namespace irr::gui;
using namespace Online;
OnlineProfileBase::OnlineProfileBase(const char* filename) : Screen(filename)
OnlineProfileBase::OnlineProfileBase(const std::string &filename)
: Screen(filename.c_str())
{
} // OnlineProfileBase
@ -48,19 +49,19 @@ OnlineProfileBase::OnlineProfileBase(const char* filename) : Screen(filename)
void OnlineProfileBase::loadedFromFile()
{
m_profile_tabs = getWidget<RibbonWidget>("profile_tabs");
assert(m_profile_tabs != NULL);
m_header = getWidget<LabelWidget>("title");
assert(m_header != NULL);
m_friends_tab =
m_friends_tab = !m_profile_tabs ? NULL :
(IconButtonWidget *) m_profile_tabs->findWidgetNamed("tab_friends");
assert(m_friends_tab != NULL);
m_achievements_tab =
assert(m_profile_tabs == NULL || m_friends_tab != NULL);
m_achievements_tab = !m_profile_tabs ? NULL :
(IconButtonWidget*)m_profile_tabs->findWidgetNamed("tab_achievements");
assert(m_achievements_tab != NULL);
m_settings_tab =
assert(m_profile_tabs == NULL || m_achievements_tab != NULL);
m_settings_tab = !m_profile_tabs ? NULL :
(IconButtonWidget *) m_profile_tabs->findWidgetNamed("tab_settings");
assert(m_settings_tab != NULL);
assert(m_profile_tabs == NULL || m_settings_tab != NULL);
} // loadedFromFile
// -----------------------------------------------------------------------------
@ -70,17 +71,20 @@ void OnlineProfileBase::loadedFromFile()
void OnlineProfileBase::beforeAddingWidget()
{
m_visiting_profile = ProfileManager::get()->getVisitingProfile();
if (!m_visiting_profile || !m_visiting_profile->isCurrentUser())
m_settings_tab->setVisible(false);
else
m_settings_tab->setVisible(true);
// If not logged in, don't show profile or friends
if (!m_visiting_profile)
if (m_profile_tabs)
{
m_friends_tab->setVisible(false);
m_profile_tabs->setVisible(false);
}
if (!m_visiting_profile || !m_visiting_profile->isCurrentUser())
m_settings_tab->setVisible(false);
else
m_settings_tab->setVisible(true);
// If not logged in, don't show profile or friends
if (!m_visiting_profile)
{
m_friends_tab->setVisible(false);
m_profile_tabs->setVisible(false);
}
} // if m_profile_tabhs
} // beforeAddingWidget
// -----------------------------------------------------------------------------
@ -90,20 +94,26 @@ void OnlineProfileBase::init()
{
Screen::init();
m_friends_tab->setTooltip( _("Friends") );
m_achievements_tab->setTooltip( _("Achievements") );
m_settings_tab->setTooltip( _("Account Settings") );
// If no visiting_profile is defined, use the data of the current player.
if (!m_visiting_profile || m_visiting_profile->isCurrentUser())
m_header->setText(_("Your profile"), false);
else if (m_visiting_profile)
if (m_profile_tabs)
{
m_header->setText(m_visiting_profile->getUserName() + _("'s profile"), false);
}
else
Log::error("OnlineProfileBase", "No visting profile");
m_friends_tab->setTooltip(_("Friends"));
m_achievements_tab->setTooltip(_("Achievements"));
m_settings_tab->setTooltip(_("Account Settings"));
// If no visiting_profile is defined, use the data of the current player.
if (!m_visiting_profile || m_visiting_profile->isCurrentUser())
m_header->setText(_("Your profile"), false);
else if (m_visiting_profile)
{
m_header->setText(m_visiting_profile->getUserName() + _("'s profile"), false);
}
else
Log::error("OnlineProfileBase", "No visting profile");
}
else // no tabs, so must be local player achievements:
{
m_header->setText(_("Your profile"), false);
}
} // init
// -----------------------------------------------------------------------------
@ -115,7 +125,8 @@ bool OnlineProfileBase::onEscapePressed()
//return to your profile if it's another profile
ProfileManager::get()->setVisiting(PlayerManager::getCurrentOnlineId());
StateManager::get()->replaceTopMostScreen(OnlineProfileAchievements::getInstance());
StateManager::get()->replaceTopMostScreen(
TabOnlineProfileAchievements::getInstance());
return false;
} // onEscapePressed
@ -125,7 +136,7 @@ bool OnlineProfileBase::onEscapePressed()
void OnlineProfileBase::eventCallback(Widget* widget, const std::string& name,
const int playerID)
{
if (name == m_profile_tabs->m_properties[PROP_ID])
if (m_profile_tabs && name == m_profile_tabs->m_properties[PROP_ID])
{
std::string selection =
((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);

View File

@ -37,7 +37,7 @@ namespace GUIEngine { class Widget; }
class OnlineProfileBase : public GUIEngine::Screen
{
protected:
OnlineProfileBase(const char* filename);
OnlineProfileBase(const std::string &filename);
/** Pointer to the various widgets on the screen. */
GUIEngine::LabelWidget * m_header;