From c786640c745b4c4a7959afaa6ab3a3a0541175aa Mon Sep 17 00:00:00 2001 From: jacob1 Date: Thu, 9 Jul 2015 14:25:01 -0400 Subject: [PATCH] always use a ScrollPanel in the profile viewer also fix Textbox autosize. TODO: add a bunch more info to the profile viewer --- src/client/Client.cpp | 28 ++++---- src/client/UserInfo.h | 35 ++++++--- src/gui/interface/Label.cpp | 4 +- src/gui/preview/PreviewView.cpp | 4 +- src/gui/profile/ProfileActivity.cpp | 106 +++++++++++++--------------- src/gui/profile/ProfileActivity.h | 6 +- 6 files changed, 98 insertions(+), 85 deletions(-) diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 5f587704d4..9ddd75084e 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -1271,8 +1271,8 @@ RequestBroker::Request * Client::SaveUserInfoAsync(UserInfo info) virtual ~StatusParser() { } }; std::map postData; - postData.insert(std::pair("Location", info.Location)); - postData.insert(std::pair("Biography", info.Biography)); + postData.insert(std::pair("Location", info.location)); + postData.insert(std::pair("Biography", info.biography)); return new APIRequest("http://" SERVER "/Profile.json", postData, new StatusParser()); } @@ -1288,19 +1288,19 @@ RequestBroker::Request * Client::GetUserInfoAsync(std::string username) json::Object objDocument; json::Reader::Read(objDocument, dataStream); json::Object tempUser = objDocument["User"]; - - json::Number userIDTemp = tempUser["ID"]; - json::String usernameTemp = tempUser["Username"]; - json::String bioTemp = tempUser["Biography"]; - json::String locationTemp = tempUser["Location"]; - json::Number ageTemp = tempUser["Age"]; - return new UserInfo( - userIDTemp.Value(), - ageTemp.Value(), - usernameTemp.Value(), - bioTemp.Value(), - locationTemp.Value()); + return new UserInfo(static_cast(tempUser["ID"]), + static_cast(tempUser["Age"]), + static_cast(tempUser["Username"]), + static_cast(tempUser["Biography"]), + static_cast(tempUser["Location"]), + static_cast(tempUser["Website"]), + static_cast(tempUser["Saves"]["Count"]), + static_cast(tempUser["Saves"]["AverageScore"]), + static_cast(tempUser["Saves"]["HighestScore"]), + static_cast(tempUser["Forum"]["Topics"]), + static_cast(tempUser["Forum"]["Replies"]), + static_cast(tempUser["Forum"]["Reputation"])); } catch (json::Exception &e) { diff --git a/src/client/UserInfo.h b/src/client/UserInfo.h index 2df00159fc..034c18e9ba 100644 --- a/src/client/UserInfo.h +++ b/src/client/UserInfo.h @@ -7,16 +7,33 @@ class UserInfo { public: int ID; - int Age; - std::string Username; - std::string Biography; - std::string Location; - UserInfo(int id, int age, std::string username, std::string biography, std::string location): + int age; + std::string username; + std::string biography; + std::string location; + std::string website; + + int saveCount; + float averageScore; + int highestScore; + + int topicCount; + int topicReplies; + int reputation; + + UserInfo(int id, int age, std::string username, std::string biography, std::string location, std::string website, int saveCount, float averageScore, int highestScore, int topicCount, int topicReplies, int reputation): ID(id), - Age(age), - Username(username), - Biography(biography), - Location(location) + age(age), + username(username), + biography(biography), + location(location), + website(website), + saveCount(saveCount), + averageScore(averageScore), + highestScore(highestScore), + topicCount(topicCount), + topicReplies(topicReplies), + reputation(reputation) { } UserInfo() {} }; diff --git a/src/gui/interface/Label.cpp b/src/gui/interface/Label.cpp index 3728f6e2cd..78a3b20a9b 100644 --- a/src/gui/interface/Label.cpp +++ b/src/gui/interface/Label.cpp @@ -123,7 +123,7 @@ void Label::updateMultiline() } if (autoHeight) { - Size.Y = lines*12; + Size.Y = lines*12+3; } textLines = std::string(rawText); delete[] rawText; @@ -164,7 +164,7 @@ void Label::updateMultiline() { if (autoHeight) { - Size.Y = 12; + Size.Y = 15; } textLines = std::string(""); } diff --git a/src/gui/preview/PreviewView.cpp b/src/gui/preview/PreviewView.cpp index 1880208f23..263c674d85 100644 --- a/src/gui/preview/PreviewView.cpp +++ b/src/gui/preview/PreviewView.cpp @@ -228,7 +228,7 @@ void PreviewView::commentBoxAutoHeight() int oldSize = addCommentBox->Size.Y; addCommentBox->AutoHeight(); - int newSize = addCommentBox->Size.Y+5; + int newSize = addCommentBox->Size.Y+2; addCommentBox->Size.Y = oldSize; commentBoxHeight = newSize+22; @@ -245,7 +245,7 @@ void PreviewView::commentBoxAutoHeight() commentBoxPositionX = (XRES/2)+4; commentBoxPositionY = Size.Y-19; commentBoxSizeX = Size.X-(XRES/2)-48; - commentBoxSizeY = 17; + commentBoxSizeY = 16; } commentsPanel->Size.Y = Size.Y-commentBoxHeight; } diff --git a/src/gui/profile/ProfileActivity.cpp b/src/gui/profile/ProfileActivity.cpp index 6c667a436e..378c5a14bf 100644 --- a/src/gui/profile/ProfileActivity.cpp +++ b/src/gui/profile/ProfileActivity.cpp @@ -37,13 +37,13 @@ ProfileActivity::ProfileActivity(std::string username) : SaveAction(ProfileActivity * a) : a(a) { } void ActionCallback(ui::Button * sender_) { - if(!a->loading && !a->saving && a->editable) + 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(); + 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); } } @@ -82,100 +82,88 @@ void ProfileActivity::setUserInfo(UserInfo newInfo) info = newInfo; - if(!info.Biography.length() && !editable) - info.Biography = "\bg(no bio)"; + if (!info.biography.length() && !editable) + info.biography = "\bgNot Provided"; + if (!info.location.length() && !editable) + info.location = "\bgNot Provided"; + if (!info.website.length() && !editable) + info.location = "\bgNot Provided"; + //if (!info.age.length() && !editable) + // info.age = "\bgNot Provided"; - 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); + ui::ScrollPanel * scrollPanel = new ui::ScrollPanel(ui::Point(1, 1), ui::Point(Size.X-2, Size.Y-16)); + AddComponent(scrollPanel); + + + ui::AvatarButton * avatar = new ui::AvatarButton(ui::Point((Size.X-40)-8, 8), ui::Point(40, 40), info.username); + scrollPanel->AddChild(avatar); int currentY = 5; - if(editable) + 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); + scrollPanel->AddChild(editAvatar); } - ui::Label * title = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8-(40+8+75), 15), info.Username); + 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); + scrollPanel->AddChild(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); + scrollPanel->AddChild(locationTitle); currentY += 17; - if(editable) + 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; + location = new ui::Textbox(ui::Point(4, currentY), ui::Point(Size.X-8-(40+8), 17), info.location); } 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 = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8-(40+8), 12), info.location); location->SetTextColour(ui::Colour(180, 180, 180)); - AddComponent(location); - this->location = location; - currentY += 10+location->Size.Y; } + location->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; + scrollPanel->AddChild(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); + scrollPanel->AddChild(bioTitle); currentY += 17; - if(editable) + 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; + bio = new ui::Textbox(ui::Point(8, currentY), ui::Point(Size.X-16, -1), info.biography); } else { - ui::Label * bio = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8, -1), info.Biography); - bio->SetMultiline(true); + bio = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8, -1), info.biography); 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(ui::Point(1, bio->Position.Y), ui::Point(Size.X-2, 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); + bio->SetMultiline(true); + bio->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; + bio->Appearance.VerticalAlign = ui::Appearance::AlignTop; + bio->AutoHeight(); + scrollPanel->AddChild(bio); + currentY += 10+bio->Size.Y; + + scrollPanel->InnerSize = ui::Point(Size.X, currentY); } void ProfileActivity::OnResponseReady(void * userDataPtr, int identifier) { - if(loading) + if (loading) { loading = false; setUserInfo(*(UserInfo*)userDataPtr); delete (UserInfo*)userDataPtr; } - else if(saving) + else if (saving) { Exit(); } @@ -188,7 +176,13 @@ void ProfileActivity::OnDraw() g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255); } -ProfileActivity::~ProfileActivity() { +void ProfileActivity::OnTryExit(ExitMethod method) +{ + Exit(); +} + +ProfileActivity::~ProfileActivity() +{ RequestBroker::Ref().DetachRequestListener(this); } diff --git a/src/gui/profile/ProfileActivity.h b/src/gui/profile/ProfileActivity.h index 53966e37bc..f660e2a994 100644 --- a/src/gui/profile/ProfileActivity.h +++ b/src/gui/profile/ProfileActivity.h @@ -6,10 +6,11 @@ #include "client/requestbroker/RequestListener.h" #include "client/UserInfo.h" #include "gui/interface/Window.h" +#include "gui/interface/Label.h" class ProfileActivity: public WindowActivity, public RequestListener { - ui::Component * location; - ui::Component * bio; + ui::Label * location; + ui::Label * bio; UserInfo info; bool editable; bool loading; @@ -20,6 +21,7 @@ class ProfileActivity: public WindowActivity, public RequestListener { virtual ~ProfileActivity(); virtual void OnResponseReady(void * userDataPtr, int identifier); virtual void OnDraw(); + virtual void OnTryExit(ExitMethod method); }; #endif /* PROFILEACTIVITY_H_ */