diff --git a/data/gui/online/user_info_dialog.stkgui b/data/gui/online/user_info_dialog.stkgui index fc45c4b32..ba78d0bda 100644 --- a/data/gui/online/user_info_dialog.stkgui +++ b/data/gui/online/user_info_dialog.stkgui @@ -30,7 +30,7 @@ + I18N="User info dialog" text="Close" label_location="bottom"/> diff --git a/src/guiengine/dialog_queue.cpp b/src/guiengine/dialog_queue.cpp index 89b5c8979..ae79e584c 100644 --- a/src/guiengine/dialog_queue.cpp +++ b/src/guiengine/dialog_queue.cpp @@ -63,7 +63,7 @@ namespace GUIEngine if(entry->closes() || !ModalDialog::isADialogActive()) { ModalDialog::dismiss(); - entry->get()->doInit(); + entry->get()->load(); m_queue.pop(); delete entry; } diff --git a/src/guiengine/modaldialog.cpp b/src/guiengine/modaldialog.cpp index e2a065258..83f386bf2 100644 --- a/src/guiengine/modaldialog.cpp +++ b/src/guiengine/modaldialog.cpp @@ -47,20 +47,19 @@ using namespace GUIEngine; // ---------------------------------------------------------------------------- -ModalDialog::ModalDialog(const float percentWidth, const float percentHeight, bool do_init, ModalDialogLocation location) +ModalDialog::ModalDialog(const float percentWidth, const float percentHeight, ModalDialogLocation location) { m_dialog_location = location; m_init = false; m_percent_width = percentWidth; m_percent_height = percentHeight; - if(do_init) - doInit(); } // ---------------------------------------------------------------------------- void ModalDialog::loadFromFile(const char* xmlFile) { + doInit(); IXMLReader* xml = file_manager->createXMLReader( (file_manager->getGUIDir() + xmlFile).c_str() ); if (xml == NULL) { diff --git a/src/guiengine/modaldialog.hpp b/src/guiengine/modaldialog.hpp index 47c628ce8..da3f966a5 100644 --- a/src/guiengine/modaldialog.hpp +++ b/src/guiengine/modaldialog.hpp @@ -71,7 +71,7 @@ namespace GUIEngine /** * \brief Creates a modal dialog with given percentage of screen width and height */ - ModalDialog(const float percentWidth, const float percentHeight, bool do_init = true, + ModalDialog(const float percentWidth, const float percentHeight, ModalDialogLocation location = MODAL_DIALOG_LOCATION_CENTER); /** \brief Load a XML file to create the dialog from @@ -86,12 +86,13 @@ namespace GUIEngine * that takes a XML file as argument is used) */ virtual void loadedFromFile() {} + void doInit(); public: LEAK_CHECK() /** Because C++ doesn't support constructor delegation... */ - void doInit(); + bool isInited() {return m_init;} virtual ~ModalDialog(); @@ -120,6 +121,7 @@ namespace GUIEngine * init(), which is invoked afer widgets were added) */ virtual void beforeAddingWidgets() {} + virtual void load() {} /** \brief Optional callback invoked after widgets have been add()ed */ virtual void init() {} diff --git a/src/online/current_user.cpp b/src/online/current_user.cpp index c892033cf..2bcad8804 100644 --- a/src/online/current_user.cpp +++ b/src/online/current_user.cpp @@ -28,6 +28,7 @@ #include "addons/addon.hpp" #include "guiengine/dialog_queue.hpp" #include "states_screens/dialogs/user_info_dialog.hpp" +#include "states_screens/online_profile_friends.hpp" #include #include @@ -390,7 +391,10 @@ namespace Online{ irr::core::stringw info_text(""); if(m_success) { - ProfileManager::get()->removePersistent(id); + CurrentUser::get()->getProfile()->removeFriend(id); + ProfileManager::get()->moveToCache(id); + ProfileManager::get()->getProfileByID(id)->deleteRelationalInfo(); + OnlineProfileFriends::getInstance()->refreshFriendsList(); info_text = _("Friend request declined!"); } else diff --git a/src/online/profile.cpp b/src/online/profile.cpp index 6ca8f99b4..f07329e1c 100644 --- a/src/online/profile.cpp +++ b/src/online/profile.cpp @@ -161,6 +161,32 @@ namespace Online{ // ============================================================================ + void Profile::removeFriend( const uint32_t id) + { + assert (m_has_fetched_friends); + std::vector::iterator iter; + for (iter = m_friends.begin(); iter != m_friends.end();) + { + if (*iter == id) + { + m_friends.erase(iter++); + break; + } + else + ++iter; + } + } + + // ============================================================================ + + void Profile::deleteRelationalInfo() + { + delete m_relation_info; + m_relation_info = NULL; + } + + // ============================================================================ + const std::vector & Profile::getFriends() { assert (m_has_fetched_friends && m_state == S_READY); diff --git a/src/online/profile.hpp b/src/online/profile.hpp index 55813ece8..3190e1d11 100644 --- a/src/online/profile.hpp +++ b/src/online/profile.hpp @@ -107,6 +107,8 @@ namespace Online{ bool isCurrentUser() const { return m_is_current_user; } bool isFriend() const { return m_is_friend; } void setFriend() { m_is_friend = true; } + void removeFriend(const uint32_t id); + void deleteRelationalInfo(); RelationInfo * getRelationInfo() { return m_relation_info; } void setRelationInfo(RelationInfo * r){ delete m_relation_info; m_relation_info = r;} diff --git a/src/online/profile_manager.cpp b/src/online/profile_manager.cpp index 023caa518..437283e41 100644 --- a/src/online/profile_manager.cpp +++ b/src/online/profile_manager.cpp @@ -117,23 +117,47 @@ namespace Online{ void ProfileManager::addPersistent(Profile * profile) { - assert (!inPersistent(profile->getID())); - m_profiles_persistent[profile->getID()] = profile; + if(inPersistent(profile->getID())) + { + delete m_profiles_persistent[profile->getID()]; + m_profiles_persistent[profile->getID()] = profile; + } + else + { + m_profiles_persistent[profile->getID()] = profile; + } } // ============================================================================ - void ProfileManager::removePersistent(const uint32_t id) + void ProfileManager::deleteFromPersistent(const uint32_t id) { - assert (inPersistent(id)); - delete m_profiles_persistent[id]; - m_profiles_persistent.erase(id); + if (inPersistent(id)) + { + delete m_profiles_persistent[id]; + m_profiles_persistent.erase(id); + } + else + Log::warn("ProfileManager::removePersistent", "Tried to remove profile with id %d from persistent while not present", id); + } + + // ============================================================================ + + void ProfileManager::moveToCache(const uint32_t id) + { + if (inPersistent(id)) + { + Profile * profile = getProfileByID(id); + m_profiles_persistent.erase(id); + addToCache(profile); + } + else + Log::warn("ProfileManager::removePersistent", "Tried to move profile with id %d from persistent to cache while not present", id); } // ============================================================================ void ProfileManager::addToCache(Profile * profile) { - if(inPersistent(profile->getID())) { //FIXME should do updating of values @@ -147,6 +171,8 @@ namespace Online{ { directToCache(profile); } + Log::info("persistent size","%d", m_profiles_persistent.size()); + Log::info("cache size","%d", m_profiles_cache.size()); } // ============================================================================ @@ -182,6 +208,7 @@ namespace Online{ Profile * ProfileManager::getProfileByID(const uint32_t id) { + if(inPersistent(id)) return m_profiles_persistent[id]; if(cacheHit(id)) diff --git a/src/online/profile_manager.hpp b/src/online/profile_manager.hpp index 13bedb77a..4aeac4e14 100644 --- a/src/online/profile_manager.hpp +++ b/src/online/profile_manager.hpp @@ -59,7 +59,8 @@ namespace Online{ void addToCache(Profile * profile); void addPersistent(Profile * profile); - void removePersistent(const uint32_t id); + void deleteFromPersistent(const uint32_t id); + void moveToCache(const uint32_t id); void setVisiting(const uint32_t id); bool cacheHit(const uint32_t id); bool inPersistent(const uint32_t id); diff --git a/src/states_screens/dialogs/user_info_dialog.cpp b/src/states_screens/dialogs/user_info_dialog.cpp index 1362578f8..38ef2e833 100644 --- a/src/states_screens/dialogs/user_info_dialog.cpp +++ b/src/states_screens/dialogs/user_info_dialog.cpp @@ -35,29 +35,32 @@ using namespace Online; // ----------------------------------------------------------------------------- UserInfoDialog::UserInfoDialog(uint32_t showing_id, const core::stringw info, bool error, bool from_queue) - : ModalDialog(0.8f,0.8f, !from_queue), m_showing_id(showing_id) + : ModalDialog(0.8f,0.8f), m_showing_id(showing_id) { - m_profile = ProfileManager::get()->getProfileByID(showing_id); - if(m_profile->isCurrentUser()) - ModalDialog::dismiss(); - m_self_destroy = false; - m_enter_profile = false; - m_processing = false; m_error = error; m_info = info; + if(!from_queue) load(); +} + +void UserInfoDialog::load() +{ + loadFromFile("online/user_info_dialog.stkgui"); } void UserInfoDialog::beforeAddingWidgets() { - loadFromFile("online/user_info_dialog.stkgui"); - if(m_error) - m_info_widget->setErrorColor(); - m_info_widget->setText(m_info, false); + m_profile = ProfileManager::get()->getProfileByID(m_showing_id); + m_self_destroy = false; + m_enter_profile = false; + m_processing = false; m_name_widget = getWidget("name"); assert(m_name_widget != NULL); m_name_widget->setText(m_profile->getUserName(),false); m_info_widget = getWidget("info"); assert(m_info_widget != NULL); + if(m_error) + m_info_widget->setErrorColor(); + m_info_widget->setText(m_info, false); m_options_widget = getWidget("options"); assert(m_options_widget != NULL); m_friend_widget = getWidget("friend"); @@ -72,18 +75,22 @@ void UserInfoDialog::beforeAddingWidgets() assert(m_cancel_widget != NULL); m_options_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); - Profile::RelationInfo * relation_info = m_profile->getRelationInfo(); - - if(relation_info == NULL || !relation_info->isPending() || !relation_info->isAsker()) - { - m_accept_widget->setVisible(false); - m_decline_widget->setVisible(false); - if (relation_info == NULL) return; - } - - if(m_profile->isFriend() || relation_info->isPending()) - { + m_accept_widget->setVisible(false); + m_decline_widget->setVisible(false); + if(m_profile->isFriend() || m_profile->isCurrentUser()) m_friend_widget->setVisible(false); + + Profile::RelationInfo * relation_info = m_profile->getRelationInfo(); + if(relation_info != NULL) + { + if(relation_info->isPending() && relation_info->isAsker()) + { + m_accept_widget->setVisible(true); + m_decline_widget->setVisible(true); + } + + if(relation_info->isPending()) + m_friend_widget->setVisible(false); } } diff --git a/src/states_screens/dialogs/user_info_dialog.hpp b/src/states_screens/dialogs/user_info_dialog.hpp index 6cb66cfae..5b64be329 100644 --- a/src/states_screens/dialogs/user_info_dialog.hpp +++ b/src/states_screens/dialogs/user_info_dialog.hpp @@ -66,6 +66,7 @@ public: ~UserInfoDialog(); virtual void beforeAddingWidgets(); + virtual void load(); void onEnterPressedInternal(); GUIEngine::EventPropagation processEvent(const std::string& eventSource); diff --git a/src/states_screens/online_profile_friends.hpp b/src/states_screens/online_profile_friends.hpp index c73f184f3..222e46f8b 100644 --- a/src/states_screens/online_profile_friends.hpp +++ b/src/states_screens/online_profile_friends.hpp @@ -47,6 +47,7 @@ private: int m_selected_friend_index; bool m_waiting_for_friends; bool m_own_profile; + bool m_refresh_screen; public: friend class GUIEngine::ScreenSingleton; @@ -63,6 +64,8 @@ public: virtual void onUpdate(float delta, irr::video::IVideoDriver* driver) OVERRIDE; virtual void beforeAddingWidget() OVERRIDE; + + virtual void refreshFriendsList() {m_waiting_for_friends = true; } }; #endif