The actual fetchitng and showing of your friends in the friendslist

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13456 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-08-11 01:22:27 +00:00
parent d8734acbe6
commit c8eea98342
6 changed files with 54 additions and 1 deletions

View File

@ -70,6 +70,13 @@ namespace Online
return irr::core::stringw(_("Fetching servers")) + loadingDots();
}
// ------------------------------------------------------------------------
irr::core::stringw fetchingFriends()
{
return irr::core::stringw(_("Fetching friends")) + loadingDots();
}
// ------------------------------------------------------------------------
irr::core::stringw loadingDots(bool spaces, float interval, int max_dots)
{

View File

@ -34,6 +34,7 @@ namespace Online
irr::core::stringw joiningServer ();
irr::core::stringw creatingServer ();
irr::core::stringw fetchingServers ();
irr::core::stringw fetchingFriends ();
irr::core::stringw signedInAs (const irr::core::stringw & name);
} // namespace Messages
}// namespace Online

View File

@ -90,6 +90,8 @@ namespace Online{
const PtrVector<Online::User> & Profile::getFriends()
{
assert (m_has_fetched_friends && getState() == S_READY);
delete m_friends_list_request;
m_friends_list_request = NULL;
return m_friends;
}
// ============================================================================

View File

@ -52,7 +52,7 @@ namespace Online{
ProfilesMap m_profiles_cache;
Profile * m_currently_visiting;
const int m_max_cache_size = 5;
static const unsigned int m_max_cache_size = 5;
void iterateCache();
void addToCache(Profile * profile);

View File

@ -23,6 +23,7 @@
#include "guiengine/widget.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/translation.hpp"
#include "online/messages.hpp"
#include <IGUIButton.h>
@ -47,14 +48,30 @@ OnlineProfileFriends::OnlineProfileFriends() : OnlineProfileBase("online/profile
void OnlineProfileFriends::loadedFromFile()
{
OnlineProfileBase::loadedFromFile();
m_friends_list_widget = getWidget<GUIEngine::ListWidget>("friends_list");
assert(m_friends_list_widget != NULL);
} // loadedFromFile
// ----------------------------------------------------------------------------
void OnlineProfileFriends::beforeAddingWidget()
{
m_friends_list_widget->clearColumns();
m_friends_list_widget->addColumn( _("Username"), 3 );
}
// -----------------------------------------------------------------------------
void OnlineProfileFriends::init()
{
OnlineProfileBase::init();
m_profile_tabs->select( m_friends_tab->m_properties[PROP_ID], PLAYER_ID_GAME_MASTER );
m_visiting_profile = ProfileManager::get()->getVisitingProfile();
m_visiting_profile->fetchFriends();
m_friends_list_widget->clear();
m_friends_list_widget->addItem("spacer", L"");
m_friends_list_widget->addItem("loading", Messages::fetchingFriends());
} // init
// -----------------------------------------------------------------------------
@ -63,3 +80,20 @@ void OnlineProfileFriends::eventCallback(Widget* widget, const std::string& name
OnlineProfileBase::eventCallback( widget, name, playerID);
} // eventCallback
// ----------------------------------------------------------------------------
void OnlineProfileFriends::onUpdate(float delta, irr::video::IVideoDriver* driver)
{
if(m_visiting_profile->isReady())
{
for(int i = 0; i < m_visiting_profile->getFriends().size(); i++)
{
PtrVector<GUIEngine::ListWidget::ListCell> * row = new PtrVector<GUIEngine::ListWidget::ListCell>;
row->push_back(new GUIEngine::ListWidget::ListCell(m_visiting_profile->getFriends()[i].getUserName(),-1,3));
m_friends_list_widget->addItem("server", row);
}
}
else
{
m_friends_list_widget->renameItem("loading", Messages::fetchingFriends());
}
}

View File

@ -25,6 +25,8 @@
#include "guiengine/screen.hpp"
#include "guiengine/widgets.hpp"
#include "states_screens/online_profile_base.hpp"
#include "online/profile_manager.hpp"
namespace GUIEngine { class Widget; }
@ -38,6 +40,9 @@ class OnlineProfileFriends : public OnlineProfileBase, public GUIEngine::ScreenS
private:
OnlineProfileFriends();
GUIEngine::ListWidget * m_friends_list_widget;
Online::Profile * m_visiting_profile;
public:
friend class GUIEngine::ScreenSingleton<OnlineProfileFriends>;
@ -49,6 +54,10 @@ public:
/** \brief implement callback from parent class GUIEngine::Screen */
virtual void init() OVERRIDE;
virtual void onUpdate(float delta, irr::video::IVideoDriver* driver) OVERRIDE;
virtual void beforeAddingWidget() OVERRIDE;
};
#endif