summaryrefslogtreecommitdiff
path: root/src/profile/ProfileActivity.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/profile/ProfileActivity.cpp')
-rw-r--r--src/profile/ProfileActivity.cpp112
1 files changed, 109 insertions, 3 deletions
diff --git a/src/profile/ProfileActivity.cpp b/src/profile/ProfileActivity.cpp
index 1b3a1f8..ed10df9 100644
--- a/src/profile/ProfileActivity.cpp
+++ b/src/profile/ProfileActivity.cpp
@@ -3,15 +3,20 @@
#include "interface/Button.h"
#include "interface/Textbox.h"
#include "interface/Label.h"
+#include "interface/AvatarButton.h"
+#include "interface/ScrollPanel.h"
#include "interface/Keys.h"
#include "Style.h"
#include "client/Client.h"
+#include "client/UserInfo.h"
#include "client/requestbroker/RequestListener.h"
ProfileActivity::ProfileActivity(std::string username) :
- WindowActivity(ui::Point(-1, -1), ui::Point(236, 302))
+ WindowActivity(ui::Point(-1, -1), ui::Point(236, 200)),
+ loading(false),
+ saving(false)
{
- bool editable = Client::Ref().GetAuthUser().ID && Client::Ref().GetAuthUser().Username == username;
+ editable = Client::Ref().GetAuthUser().ID && Client::Ref().GetAuthUser().Username == username;
class CloseAction: public ui::ButtonAction
@@ -32,6 +37,15 @@ ProfileActivity::ProfileActivity(std::string username) :
SaveAction(ProfileActivity * a) : a(a) { }
void ActionCallback(ui::Button * sender_)
{
+ if(!a->loading && !a->saving && a->editable)
+ {
+ sender_->Enabled = false;
+ sender_->SetText("Saving...");
+ a->saving = true;
+ a->info.Location = ((ui::Textbox*)a->location)->GetText();
+ a->info.Biography = ((ui::Textbox*)a->bio)->GetText();
+ RequestBroker::Ref().Start(Client::Ref().SaveUserInfoAsync(a->info), a);
+ }
}
};
@@ -47,12 +61,104 @@ ProfileActivity::ProfileActivity(std::string username) :
AddComponent(closeButton);
+ loading = true;
RequestBroker::Ref().Start(Client::Ref().GetUserInfoAsync(username), this);
}
+void ProfileActivity::setUserInfo(UserInfo newInfo)
+{
+ info = newInfo;
+
+ if(!info.Biography.length() && !editable)
+ info.Biography = "\bg(no bio)";
+
+ if(!info.Location.length() && !editable)
+ info.Location = "\bg(no location)";
+
+ ui::AvatarButton * avatar = new ui::AvatarButton(ui::Point((Size.X-40)-8, 8), ui::Point(40, 40), info.Username);
+ 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);
+ 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);
+ currentY += 17;
+
+ if(editable)
+ {
+ ui::Textbox * location = new ui::Textbox(ui::Point(8, currentY), ui::Point(Size.X-16-(40+8), 17), info.Location);
+ location->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
+ AddComponent(location);
+ this->location = location;
+ currentY += 10+location->Size.Y;
+ }
+ else
+ {
+ ui::Label * location = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8-(40+8), 12), info.Location);
+ location->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
+ location->SetTextColour(ui::Colour(180, 180, 180));
+ AddComponent(location);
+ this->location = location;
+ currentY += 10+location->Size.Y;
+ }
+
+ ui::Label * bioTitle = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8, 15), "Biography");
+ bioTitle->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
+ AddComponent(bioTitle);
+ currentY += 17;
+
+ if(editable)
+ {
+ ui::Textbox * bio = new ui::Textbox(ui::Point(8, currentY), ui::Point(Size.X-16, Size.Y-30-currentY), info.Biography);
+ bio->SetMultiline(true);
+ bio->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
+ bio->Appearance.VerticalAlign = ui::Appearance::AlignTop;
+ AddComponent(bio);
+ currentY += 10+bio->Size.Y;
+ this->bio = bio;
+ }
+ else
+ {
+ ui::Label * bio = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8, -1), info.Biography);
+ bio->SetMultiline(true);
+ bio->SetTextColour(ui::Colour(180, 180, 180));
+ bio->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
+ currentY += 10+bio->Size.Y;
+ if(currentY > Size.Y - 20)
+ {
+ ui::ScrollPanel * scrollPanel = new ui::ScrollPanel(bio->Position, ui::Point(Size.X, Size.Y-30-bio->Position.Y));
+ AddComponent(scrollPanel);
+ bio->Position = ui::Point(4, 4);
+ scrollPanel->AddChild(bio);
+ scrollPanel->InnerSize = ui::Point(Size.X, bio->Size.Y+8);
+ }
+ else
+ {
+ AddComponent(bio);
+ }
+ this->bio = bio;
+ }
+
+ //exit(0);
+}
+
void ProfileActivity::OnResponseReady(void * userDataPtr)
{
- exit(0);
+ if(loading)
+ {
+ loading = false;
+ setUserInfo(*(UserInfo*)userDataPtr);
+ delete (UserInfo*)userDataPtr;
+ }
+ else if(saving)
+ {
+ Exit();
+ }
}
void ProfileActivity::OnDraw()