Added more comments, code style cleanup only.
This commit is contained in:
@@ -203,7 +203,8 @@ namespace Online
|
||||
std::string param = m_parameters;
|
||||
for (unsigned int j = 0; j < 2; j++)
|
||||
{
|
||||
std::string s = j == 0 ? "&password=" : "&token=";
|
||||
// Get the string that should be replaced.
|
||||
std::string s = (j == 0 ? "&password=" : "&token=");
|
||||
std::size_t pos = param.find(s);
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
|
||||
@@ -104,12 +104,12 @@ private:
|
||||
void storeAchievements(const XMLNode * input);
|
||||
|
||||
public:
|
||||
Profile(const uint32_t & userid,
|
||||
const irr::core::stringw & username,
|
||||
bool is_current_user = false );
|
||||
Profile(const XMLNode * xml,
|
||||
ConstructorType type = C_DEFAULT);
|
||||
~Profile();
|
||||
Profile(const uint32_t & userid,
|
||||
const irr::core::stringw & username,
|
||||
bool is_current_user = false );
|
||||
Profile(const XMLNode * xml,
|
||||
ConstructorType type = C_DEFAULT);
|
||||
~Profile();
|
||||
void fetchFriends();
|
||||
const IDList& getFriends();
|
||||
void fetchAchievements();
|
||||
@@ -117,6 +117,7 @@ public:
|
||||
void addFriend(const uint32_t id);
|
||||
void deleteRelationalInfo();
|
||||
const IDList& getAchievements();
|
||||
void merge(Profile * profile);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true if the achievements for this profile have been fetched. */
|
||||
bool hasFetchedAchievements() const { return m_has_fetched_achievements; }
|
||||
@@ -127,24 +128,34 @@ public:
|
||||
/** True if the profile is not fetching data atm. */
|
||||
bool isReady() const { return m_state == S_READY; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true if this item is the current user. */
|
||||
bool isCurrentUser() const { return m_is_current_user; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool isFriend() const { return m_is_friend; }
|
||||
bool isFriend() const { return m_is_friend; }
|
||||
// ------------------------------------------------------------------------
|
||||
void setFriend() { m_is_friend = true; }
|
||||
void setFriend() { m_is_friend = true; }
|
||||
// ------------------------------------------------------------------------
|
||||
RelationInfo* getRelationInfo() { return m_relation_info; }
|
||||
RelationInfo* getRelationInfo() { return m_relation_info; }
|
||||
// ------------------------------------------------------------------------
|
||||
void setRelationInfo(RelationInfo * r)
|
||||
{
|
||||
delete m_relation_info; m_relation_info = r;
|
||||
} // setRelationInfo
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the cache bit of this profile. Used by the cache eviction
|
||||
* algorithm. */
|
||||
void setCacheBit(bool cache_bit) { m_cache_bit = cache_bit; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the cache bit for this profile. Used by the cache eviction
|
||||
* algorithm. */
|
||||
bool getCacheBit() const { return m_cache_bit; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the online id of this profile. */
|
||||
uint32_t getID() const { return m_id; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the user name of this profile. */
|
||||
const irr::core::stringw& getUserName() const { return m_username; }
|
||||
// ------------------------------------------------------------------------
|
||||
void setRelationInfo(RelationInfo * r){ delete m_relation_info; m_relation_info = r; }
|
||||
|
||||
void setCacheBit(bool cache_bit) { m_cache_bit = cache_bit; }
|
||||
bool getCacheBit() const { return m_cache_bit; }
|
||||
|
||||
uint32_t getID() const { return m_id; }
|
||||
const irr::core::stringw & getUserName() const { return m_username; }
|
||||
|
||||
void merge(Profile * profile);
|
||||
|
||||
|
||||
}; // class Profile
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ OnlineProfileBase::OnlineProfileBase(const char* filename) : Screen(filename)
|
||||
} // OnlineProfileBase
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/** Callback when the xml file was loaded.
|
||||
*/
|
||||
void OnlineProfileBase::loadedFromFile()
|
||||
{
|
||||
m_profile_tabs = this->getWidget<RibbonWidget>("profile_tabs");
|
||||
@@ -50,18 +51,24 @@ void OnlineProfileBase::loadedFromFile()
|
||||
m_header = this->getWidget<LabelWidget>("title");
|
||||
assert(m_header != NULL);
|
||||
|
||||
m_overview_tab = (IconButtonWidget *) m_profile_tabs->findWidgetNamed("tab_overview");
|
||||
m_overview_tab =
|
||||
(IconButtonWidget *)m_profile_tabs->findWidgetNamed("tab_overview");
|
||||
assert(m_overview_tab != NULL);
|
||||
m_friends_tab = (IconButtonWidget *) m_profile_tabs->findWidgetNamed("tab_friends");
|
||||
m_friends_tab =
|
||||
(IconButtonWidget *) m_profile_tabs->findWidgetNamed("tab_friends");
|
||||
assert(m_friends_tab != NULL);
|
||||
m_achievements_tab = (IconButtonWidget *) m_profile_tabs->findWidgetNamed("tab_achievements");
|
||||
m_achievements_tab =
|
||||
(IconButtonWidget*)m_profile_tabs->findWidgetNamed("tab_achievements");
|
||||
assert(m_achievements_tab != NULL);
|
||||
m_settings_tab = (IconButtonWidget *) m_profile_tabs->findWidgetNamed("tab_settings");
|
||||
m_settings_tab =
|
||||
(IconButtonWidget *) m_profile_tabs->findWidgetNamed("tab_settings");
|
||||
assert(m_settings_tab != NULL);
|
||||
|
||||
} // loadedFromFile
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Callback before widgets are added. Clears all widgets and saves the
|
||||
* current profile.
|
||||
*/
|
||||
void OnlineProfileBase::beforeAddingWidget()
|
||||
{
|
||||
m_visiting_profile = ProfileManager::get()->getVisitingProfile();
|
||||
@@ -70,6 +77,8 @@ void OnlineProfileBase::beforeAddingWidget()
|
||||
} // beforeAddingWidget
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Called when entering this menu (before widgets are added).
|
||||
*/
|
||||
void OnlineProfileBase::init()
|
||||
{
|
||||
Screen::init();
|
||||
@@ -91,17 +100,24 @@ void OnlineProfileBase::init()
|
||||
} // init
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void OnlineProfileBase::eventCallback(Widget* widget, const std::string& name, const int playerID)
|
||||
/** Called when an event occurs (i.e. user clicks on something).
|
||||
*/
|
||||
void OnlineProfileBase::eventCallback(Widget* widget, const std::string& name,
|
||||
const int playerID)
|
||||
{
|
||||
if (name == m_profile_tabs->m_properties[PROP_ID])
|
||||
{
|
||||
std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER).c_str();
|
||||
|
||||
if (selection == m_overview_tab->m_properties[PROP_ID]) StateManager::get()->replaceTopMostScreen(OnlineProfileOverview::getInstance());
|
||||
else if (selection == m_friends_tab->m_properties[PROP_ID]) StateManager::get()->replaceTopMostScreen(OnlineProfileFriends::getInstance());
|
||||
else if (selection == m_achievements_tab->m_properties[PROP_ID]) StateManager::get()->replaceTopMostScreen(OnlineProfileAchievements::getInstance());
|
||||
else if (selection == m_settings_tab->m_properties[PROP_ID]) StateManager::get()->replaceTopMostScreen(OnlineProfileSettings::getInstance());
|
||||
std::string selection =
|
||||
((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
StateManager *sm = StateManager::get();
|
||||
if (selection == m_overview_tab->m_properties[PROP_ID])
|
||||
sm->replaceTopMostScreen(OnlineProfileOverview::getInstance());
|
||||
else if (selection == m_friends_tab->m_properties[PROP_ID])
|
||||
sm->replaceTopMostScreen(OnlineProfileFriends::getInstance());
|
||||
else if (selection == m_achievements_tab->m_properties[PROP_ID])
|
||||
sm->replaceTopMostScreen(OnlineProfileAchievements::getInstance());
|
||||
else if (selection == m_settings_tab->m_properties[PROP_ID])
|
||||
sm->replaceTopMostScreen(OnlineProfileSettings::getInstance());
|
||||
}
|
||||
else if (name == "back")
|
||||
{
|
||||
|
||||
@@ -29,14 +29,17 @@
|
||||
namespace GUIEngine { class Widget; }
|
||||
|
||||
|
||||
/**
|
||||
* \brief Online profile base screen
|
||||
* \ingroup states_screens
|
||||
*/
|
||||
/** Online profile base screen. Used for displaying friends, achievements,
|
||||
* overview, and settings. It handles the tabs which are common to each
|
||||
* of those screens, and keeps track of the profile to display.
|
||||
* \ingroup states_screens
|
||||
*/
|
||||
class OnlineProfileBase : public GUIEngine::Screen
|
||||
{
|
||||
protected:
|
||||
OnlineProfileBase(const char* filename);
|
||||
|
||||
/** Pointer to the various widgets on the screen. */
|
||||
GUIEngine::LabelWidget * m_header;
|
||||
GUIEngine::RibbonWidget* m_profile_tabs;
|
||||
GUIEngine::IconButtonWidget * m_overview_tab;
|
||||
@@ -44,7 +47,8 @@ protected:
|
||||
GUIEngine::IconButtonWidget * m_achievements_tab;
|
||||
GUIEngine::IconButtonWidget * m_settings_tab;
|
||||
|
||||
Online::Profile * m_visiting_profile;
|
||||
/** The profile that should be shown. */
|
||||
Online::Profile *m_visiting_profile;
|
||||
|
||||
public:
|
||||
|
||||
@@ -52,7 +56,9 @@ public:
|
||||
virtual void loadedFromFile() OVERRIDE;
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name, const int playerID) OVERRIDE;
|
||||
virtual void eventCallback(GUIEngine::Widget* widget,
|
||||
const std::string& name,
|
||||
const int playerID) OVERRIDE;
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void init() OVERRIDE;
|
||||
|
||||
@@ -21,17 +21,14 @@
|
||||
#include "guiengine/scalable_font.hpp"
|
||||
#include "guiengine/screen.hpp"
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/online_user_search.hpp"
|
||||
#include "states_screens/dialogs/user_info_dialog.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
#include "online/messages.hpp"
|
||||
#include "states_screens/dialogs/user_info_dialog.hpp"
|
||||
#include "states_screens/online_user_search.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
#include <IGUIButton.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace GUIEngine;
|
||||
using namespace irr::core;
|
||||
using namespace irr::gui;
|
||||
@@ -40,28 +37,31 @@ using namespace Online;
|
||||
DEFINE_SCREEN_SINGLETON( OnlineProfileFriends );
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
OnlineProfileFriends::OnlineProfileFriends() : OnlineProfileBase("online/profile_friends.stkgui")
|
||||
/** Constructor for a display of all friends.
|
||||
*/
|
||||
OnlineProfileFriends::OnlineProfileFriends()
|
||||
: OnlineProfileBase("online/profile_friends.stkgui")
|
||||
{
|
||||
m_selected_friend_index = -1;
|
||||
} // OnlineProfileFriends
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/** Callback when the xml file was loaded.
|
||||
*/
|
||||
void OnlineProfileFriends::loadedFromFile()
|
||||
{
|
||||
OnlineProfileBase::loadedFromFile();
|
||||
m_friends_list_widget = getWidget<GUIEngine::ListWidget>("friends_list");
|
||||
m_friends_list_widget = getWidget<ListWidget>("friends_list");
|
||||
assert(m_friends_list_widget != NULL);
|
||||
m_search_button_widget = getWidget<GUIEngine::ButtonWidget>("search_button");
|
||||
m_search_button_widget = getWidget<ButtonWidget>("search_button");
|
||||
assert(m_search_button_widget != NULL);
|
||||
m_search_box_widget = getWidget<GUIEngine::TextBoxWidget>("search_box");
|
||||
m_search_box_widget = getWidget<TextBoxWidget>("search_box");
|
||||
assert(m_search_box_widget != NULL);
|
||||
|
||||
} // loadedFromFile
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/** Callback before widgets are added. Clears all widgets.
|
||||
*/
|
||||
void OnlineProfileFriends::beforeAddingWidget()
|
||||
{
|
||||
OnlineProfileBase::beforeAddingWidget();
|
||||
@@ -72,23 +72,29 @@ void OnlineProfileFriends::beforeAddingWidget()
|
||||
m_friends_list_widget->addColumn( _("Since"), 1 );
|
||||
m_friends_list_widget->addColumn( _("Status"), 2 );
|
||||
}
|
||||
}
|
||||
} // beforeAddingWidget
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/** Called when entering this menu (before widgets are added).
|
||||
*/
|
||||
void OnlineProfileFriends::init()
|
||||
{
|
||||
OnlineProfileBase::init();
|
||||
m_profile_tabs->select( m_friends_tab->m_properties[PROP_ID], PLAYER_ID_GAME_MASTER );
|
||||
m_profile_tabs->select( m_friends_tab->m_properties[PROP_ID],
|
||||
PLAYER_ID_GAME_MASTER );
|
||||
assert(m_visiting_profile != NULL);
|
||||
m_visiting_profile->fetchFriends();
|
||||
m_waiting_for_friends = true;
|
||||
m_friends_list_widget->clear();
|
||||
m_friends_list_widget->addItem("loading", Messages::fetchingFriends());
|
||||
} // init
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void OnlineProfileFriends::eventCallback(Widget* widget, const std::string& name, const int playerID)
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Called when an event occurs (i.e. user clicks on something).
|
||||
*/
|
||||
void OnlineProfileFriends::eventCallback(Widget* widget,
|
||||
const std::string& name,
|
||||
const int playerID)
|
||||
{
|
||||
OnlineProfileBase::eventCallback( widget, name, playerID);
|
||||
if (name == m_search_button_widget->m_properties[GUIEngine::PROP_ID])
|
||||
@@ -100,10 +106,48 @@ void OnlineProfileFriends::eventCallback(Widget* widget, const std::string& name
|
||||
else if (name == m_friends_list_widget->m_properties[GUIEngine::PROP_ID])
|
||||
{
|
||||
m_selected_friend_index = m_friends_list_widget->getSelectionID();
|
||||
new UserInfoDialog(m_visiting_profile->getFriends()[m_selected_friend_index]);
|
||||
const Profile::IDList &friends = m_visiting_profile->getFriends();
|
||||
new UserInfoDialog(friends[m_selected_friend_index]);
|
||||
}
|
||||
} // eventCallback
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Displays the friends from a given profile.
|
||||
*/
|
||||
void OnlineProfileFriends::displayResults()
|
||||
{
|
||||
m_friends_list_widget->clear();
|
||||
const Profile::IDList &friends = m_visiting_profile->getFriends();
|
||||
for (unsigned int i = 0; i < friends.size(); i++)
|
||||
{
|
||||
std::vector<ListWidget::ListCell> row;
|
||||
Profile* friend_profile =
|
||||
ProfileManager::get()->getProfileByID(friends[i]);
|
||||
row.push_back(ListWidget::ListCell(friend_profile->getUserName(),
|
||||
-1, 2) );
|
||||
if (m_visiting_profile->isCurrentUser())
|
||||
{
|
||||
Profile::RelationInfo * relation_info =
|
||||
friend_profile->getRelationInfo();
|
||||
row.push_back(ListWidget::ListCell(relation_info->getDate(),
|
||||
-1, 1, true) );
|
||||
irr::core::stringw status("");
|
||||
if (relation_info->isPending())
|
||||
{
|
||||
status = (relation_info->isAsker() ? _("New Request")
|
||||
: _("Pending") );
|
||||
}
|
||||
else
|
||||
status = (relation_info->isOnline() ? _("Online")
|
||||
: _("Offline") );
|
||||
row.push_back(ListWidget::ListCell(status, -1, 2, true));
|
||||
}
|
||||
m_friends_list_widget->addItem("friend", row);
|
||||
}
|
||||
m_waiting_for_friends = false;
|
||||
|
||||
} // displayResults
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void OnlineProfileFriends::onUpdate(float delta)
|
||||
{
|
||||
@@ -111,32 +155,12 @@ void OnlineProfileFriends::onUpdate(float delta)
|
||||
{
|
||||
if(m_visiting_profile->isReady())
|
||||
{
|
||||
m_friends_list_widget->clear();
|
||||
for(unsigned int i = 0; i < m_visiting_profile->getFriends().size(); i++)
|
||||
{
|
||||
std::vector<GUIEngine::ListWidget::ListCell> row;
|
||||
Profile* friend_profile = ProfileManager::get()->getProfileByID(m_visiting_profile->getFriends()[i]);
|
||||
row.push_back(GUIEngine::ListWidget::ListCell(friend_profile->getUserName(),-1,2));
|
||||
if(m_visiting_profile->isCurrentUser())
|
||||
{
|
||||
Profile::RelationInfo * relation_info = friend_profile->getRelationInfo();
|
||||
row.push_back(GUIEngine::ListWidget::ListCell(relation_info->getDate(),-1,1, true));
|
||||
irr::core::stringw status("");
|
||||
if(relation_info->isPending())
|
||||
{
|
||||
status = (relation_info->isAsker() ? _("New Request") : _("Pending"));
|
||||
}
|
||||
else
|
||||
status = (relation_info->isOnline() ? _("Online") : _("Offline"));
|
||||
row.push_back(GUIEngine::ListWidget::ListCell(status,-1,2, true));
|
||||
}
|
||||
m_friends_list_widget->addItem("friend", row);
|
||||
}
|
||||
m_waiting_for_friends = false;
|
||||
displayResults();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_friends_list_widget->renameItem("loading", Messages::fetchingFriends());
|
||||
m_friends_list_widget->renameItem("loading",
|
||||
Messages::fetchingFriends());
|
||||
}
|
||||
}
|
||||
}
|
||||
} // onUpdate
|
||||
|
||||
@@ -31,22 +31,23 @@
|
||||
namespace GUIEngine { class Widget; }
|
||||
|
||||
|
||||
/**
|
||||
* \brief Online profiel overview screen
|
||||
* \ingroup states_screens
|
||||
*/
|
||||
/** Online profile overview screen.
|
||||
* \ingroup states_screens
|
||||
*/
|
||||
class OnlineProfileFriends : public OnlineProfileBase, public GUIEngine::ScreenSingleton<OnlineProfileFriends>
|
||||
{
|
||||
private:
|
||||
OnlineProfileFriends();
|
||||
|
||||
GUIEngine::ListWidget * m_friends_list_widget;
|
||||
GUIEngine::ButtonWidget * m_search_button_widget;
|
||||
GUIEngine::TextBoxWidget * m_search_box_widget;
|
||||
/** Pointer to the various widgets on the screen. */
|
||||
GUIEngine::ListWidget *m_friends_list_widget;
|
||||
GUIEngine::ButtonWidget *m_search_button_widget;
|
||||
GUIEngine::TextBoxWidget *m_search_box_widget;
|
||||
|
||||
int m_selected_friend_index;
|
||||
bool m_waiting_for_friends;
|
||||
|
||||
void displayResults();
|
||||
public:
|
||||
friend class GUIEngine::ScreenSingleton<OnlineProfileFriends>;
|
||||
|
||||
@@ -54,16 +55,19 @@ public:
|
||||
virtual void loadedFromFile() OVERRIDE;
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name, const int playerID) OVERRIDE;
|
||||
virtual void eventCallback(GUIEngine::Widget* widget,
|
||||
const std::string& name,
|
||||
const int playerID) OVERRIDE;
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void init() OVERRIDE;
|
||||
|
||||
virtual void onUpdate(float delta) OVERRIDE;
|
||||
|
||||
virtual void beforeAddingWidget() OVERRIDE;
|
||||
|
||||
virtual void refreshFriendsList() {m_waiting_for_friends = true; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Triggers a reload of the friend list next time this menu is shown. */
|
||||
void refreshFriendsList() {m_waiting_for_friends = true; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user