Related to previous commit. Changes to the modal dialog core. (Not 100% sure if every dialog still works.) Some core changes to profile, profile manager, and the related callbacks for friending.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13520 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
445706793e
commit
8e6495139e
@ -30,7 +30,7 @@
|
||||
<icon-button id="enter" width="64" height="64" icon="gui/difficulty_medium.png"
|
||||
I18N="User info dialog" text="View" label_location="bottom"/>
|
||||
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
|
||||
I18N="User info dialog" text="Cancel" label_location="bottom"/>
|
||||
I18N="User info dialog" text="Close" label_location="bottom"/>
|
||||
</buttonbar>
|
||||
|
||||
|
||||
|
@ -63,7 +63,7 @@ namespace GUIEngine
|
||||
if(entry->closes() || !ModalDialog::isADialogActive())
|
||||
{
|
||||
ModalDialog::dismiss();
|
||||
entry->get()->doInit();
|
||||
entry->get()->load();
|
||||
m_queue.pop();
|
||||
delete entry;
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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() {}
|
||||
|
@ -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 <sstream>
|
||||
#include <stdlib.h>
|
||||
@ -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
|
||||
|
@ -161,6 +161,32 @@ namespace Online{
|
||||
|
||||
// ============================================================================
|
||||
|
||||
void Profile::removeFriend( const uint32_t id)
|
||||
{
|
||||
assert (m_has_fetched_friends);
|
||||
std::vector<uint32_t>::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<uint32_t> & Profile::getFriends()
|
||||
{
|
||||
assert (m_has_fetched_friends && m_state == S_READY);
|
||||
|
@ -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;}
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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);
|
||||
|
@ -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<LabelWidget>("name");
|
||||
assert(m_name_widget != NULL);
|
||||
m_name_widget->setText(m_profile->getUserName(),false);
|
||||
m_info_widget = getWidget<LabelWidget>("info");
|
||||
assert(m_info_widget != NULL);
|
||||
if(m_error)
|
||||
m_info_widget->setErrorColor();
|
||||
m_info_widget->setText(m_info, false);
|
||||
m_options_widget = getWidget<RibbonWidget>("options");
|
||||
assert(m_options_widget != NULL);
|
||||
m_friend_widget = getWidget<IconButtonWidget>("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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ public:
|
||||
~UserInfoDialog();
|
||||
|
||||
virtual void beforeAddingWidgets();
|
||||
virtual void load();
|
||||
|
||||
void onEnterPressedInternal();
|
||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
|
||||
|
@ -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<OnlineProfileFriends>;
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user