From b4fb55f86e9add3248166278bb566f210dacf636 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sun, 7 Apr 2013 14:40:00 +0100 Subject: [PATCH] Allow signing out and editing profile from the old login button, add a button to edit avatar (directs to the website at the moment) Allow viewing profiles by clicking avatars --- src/gui/game/GameController.cpp | 6 ++++++ src/gui/game/GameController.h | 1 + src/gui/game/GameView.cpp | 17 +++++++++++++---- src/gui/preview/PreviewView.cpp | 17 +++++++++++++++++ src/gui/preview/PreviewView.h | 1 + src/gui/profile/ProfileActivity.cpp | 26 +++++++++++++++++++++++--- 6 files changed, 61 insertions(+), 7 deletions(-) diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 8df50366e..5f7239896 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -1067,6 +1067,12 @@ void GameController::OpenLocalBrowse() } void GameController::OpenLogin() +{ + loginWindow = new LoginController(); + ui::Engine::Ref().ShowWindow(loginWindow->GetView()); +} + +void GameController::OpenProfile() { if(Client::Ref().GetAuthUser().ID) { diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index 644d25c02..c34d44a3c 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -108,6 +108,7 @@ public: void LoadSave(SaveInfo * save); void OpenSearch(); void OpenLogin(); + void OpenProfile(); void OpenTags(); void OpenSavePreview(int saveID, int saveDate); void OpenSavePreview(); diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index c11a59d0a..676eec897 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -46,6 +46,7 @@ public: { } + void SetRightToolTip(std::string tooltip) { toolTip2 = tooltip; } bool GetShowSplit() { return showSplit; } void SetShowSplit(bool split) { showSplit = split; } SplitButtonAction * GetSplitActionCallback() { return splitActionCallback; } @@ -335,20 +336,24 @@ GameView::GameView(): clearSimButton->SetActionCallback(new ClearSimAction(this)); AddComponent(clearSimButton); - class LoginAction : public ui::ButtonAction + class LoginAction : public SplitButtonAction { GameView * v; public: LoginAction(GameView * _v) { v = _v; } - void ActionCallback(ui::Button * sender) + void ActionCallbackLeft(ui::Button * sender) { v->c->OpenLogin(); } + void ActionCallbackRight(ui::Button * sender) + { + v->c->OpenProfile(); + } }; - loginButton = new ui::Button(ui::Point(Size.X-141, Size.Y-16), ui::Point(92, 15), "[sign in]", "Sign into simulation server"); + loginButton = new SplitButton(ui::Point(Size.X-141, Size.Y-16), ui::Point(92, 15), "[sign in]", "Sign into simulation server", "Edit Profile", 19); loginButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; loginButton->SetIcon(IconLogin); - loginButton->SetActionCallback(new LoginAction(this)); + ((SplitButton*)loginButton)->SetSplitActionCallback(new LoginAction(this)); AddComponent(loginButton); class SimulationOptionAction : public ui::ButtonAction @@ -802,10 +807,14 @@ void GameView::NotifyUserChanged(GameModel * sender) if(!sender->GetUser().ID) { loginButton->SetText("[sign in]"); + ((SplitButton*)loginButton)->SetShowSplit(false); + ((SplitButton*)loginButton)->SetRightToolTip("Sign in to simulation server"); } else { loginButton->SetText(sender->GetUser().Username); + ((SplitButton*)loginButton)->SetShowSplit(true); + ((SplitButton*)loginButton)->SetRightToolTip("Edit profile"); } NotifySaveChanged(sender); } diff --git a/src/gui/preview/PreviewView.cpp b/src/gui/preview/PreviewView.cpp index 42117322f..27584c91d 100644 --- a/src/gui/preview/PreviewView.cpp +++ b/src/gui/preview/PreviewView.cpp @@ -10,6 +10,7 @@ #include "gui/Style.h" #include "Format.h" #include "gui/search/Thumbnail.h" +#include "gui/profile/ProfileActivity.h" #include "client/Client.h" #include "gui/interface/ScrollPanel.h" #include "gui/interface/AvatarButton.h" @@ -47,6 +48,20 @@ public: } }; +class PreviewView::AvatarAction: public ui::AvatarButtonAction +{ + PreviewView * v; +public: + AvatarAction(PreviewView * v_){ v = v_; } + virtual void ActionCallback(ui::AvatarButton * sender) + { + if(sender->GetUsername().size() > 0) + { + new ProfileActivity(sender->GetUsername()); + } + } +}; + PreviewView::PreviewView(): ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+210, (YRES/2)+150)), savePreview(NULL), @@ -166,6 +181,7 @@ PreviewView::PreviewView(): if(showAvatars) { avatarButton = new ui::AvatarButton(ui::Point(4, (YRES/2)+4), ui::Point(34, 34), ""); + avatarButton->SetActionCallback(new AvatarAction(this)); AddComponent(avatarButton); } @@ -546,6 +562,7 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender) if(showAvatars) { tempAvatar = new ui::AvatarButton(ui::Point(2, currentY+7), ui::Point(26, 26), comments->at(i)->authorName); + tempAvatar->SetActionCallback(new AvatarAction(this)); commentComponents.push_back(tempAvatar); commentsPanel->AddChild(tempAvatar); } diff --git a/src/gui/preview/PreviewView.h b/src/gui/preview/PreviewView.h index 2fef5acc4..c01644c6e 100644 --- a/src/gui/preview/PreviewView.h +++ b/src/gui/preview/PreviewView.h @@ -23,6 +23,7 @@ class PreviewView: public ui::Window { class SubmitCommentAction; class LoginAction; class AutoCommentSizeAction; + class AvatarAction; PreviewController * c; VideoBuffer * savePreview; ui::Button * openButton; diff --git a/src/gui/profile/ProfileActivity.cpp b/src/gui/profile/ProfileActivity.cpp index 54da81e4b..fe6ab8085 100644 --- a/src/gui/profile/ProfileActivity.cpp +++ b/src/gui/profile/ProfileActivity.cpp @@ -49,11 +49,13 @@ ProfileActivity::ProfileActivity(std::string username) : } }; - ui::Button * closeButton = new ui::Button(ui::Point(0, Size.Y-15), ui::Point((Size.X/2)+1, 15), "Close"); - closeButton->SetActionCallback(new CloseAction(this)); + ui::Button * closeButton = new ui::Button(ui::Point(0, Size.Y-15), ui::Point(Size.X, 15), "Close"); + closeButton->SetActionCallback(new CloseAction(this)); if(editable) { + closeButton->Size.X = (Size.X/2)+1; + ui::Button * saveButton = new ui::Button(ui::Point(Size.X/2, Size.Y-15), ui::Point(Size.X/2, 15), "Save"); saveButton->SetActionCallback(new SaveAction(this)); AddComponent(saveButton); @@ -67,6 +69,17 @@ ProfileActivity::ProfileActivity(std::string username) : void ProfileActivity::setUserInfo(UserInfo newInfo) { + class EditAvatarAction: public ui::ButtonAction + { + ProfileActivity * a; + public: + EditAvatarAction(ProfileActivity * a) : a(a) { } + void ActionCallback(ui::Button * sender_) + { + OpenURI("http://" SERVER "/Profile/Avatar.html"); + } + }; + info = newInfo; if(!info.Biography.length() && !editable) @@ -79,11 +92,18 @@ void ProfileActivity::setUserInfo(UserInfo newInfo) AddComponent(avatar); int currentY = 5; - ui::Label * title = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8-(40+8), 15), info.Username); + if(editable) + { + ui::Button * editAvatar = new ui::Button(ui::Point(Size.X - (40 + 16 + 75), currentY), ui::Point(75, 15), "Edit Avatar"); + editAvatar->SetActionCallback(new EditAvatarAction(this)); + AddComponent(editAvatar); + } + ui::Label * title = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8-(40+8+75), 15), info.Username); title->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; AddComponent(title); currentY += 20; + ui::Label * locationTitle = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8-(40+8), 15), "Location"); locationTitle->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; AddComponent(locationTitle);