always use a ScrollPanel in the profile viewer

also fix Textbox autosize. TODO: add a bunch more info to the profile viewer
This commit is contained in:
jacob1 2015-07-09 14:25:01 -04:00
parent e9d6519800
commit c786640c74
6 changed files with 97 additions and 84 deletions

View File

@ -1271,8 +1271,8 @@ RequestBroker::Request * Client::SaveUserInfoAsync(UserInfo info)
virtual ~StatusParser() { } virtual ~StatusParser() { }
}; };
std::map<std::string, std::string> postData; std::map<std::string, std::string> postData;
postData.insert(std::pair<std::string, std::string>("Location", info.Location)); postData.insert(std::pair<std::string, std::string>("Location", info.location));
postData.insert(std::pair<std::string, std::string>("Biography", info.Biography)); postData.insert(std::pair<std::string, std::string>("Biography", info.biography));
return new APIRequest("http://" SERVER "/Profile.json", postData, new StatusParser()); 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::Object objDocument;
json::Reader::Read(objDocument, dataStream); json::Reader::Read(objDocument, dataStream);
json::Object tempUser = objDocument["User"]; 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( return new UserInfo(static_cast<json::Number>(tempUser["ID"]),
userIDTemp.Value(), static_cast<json::Number>(tempUser["Age"]),
ageTemp.Value(), static_cast<json::String>(tempUser["Username"]),
usernameTemp.Value(), static_cast<json::String>(tempUser["Biography"]),
bioTemp.Value(), static_cast<json::String>(tempUser["Location"]),
locationTemp.Value()); static_cast<json::String>(tempUser["Website"]),
static_cast<json::Number>(tempUser["Saves"]["Count"]),
static_cast<json::Number>(tempUser["Saves"]["AverageScore"]),
static_cast<json::Number>(tempUser["Saves"]["HighestScore"]),
static_cast<json::Number>(tempUser["Forum"]["Topics"]),
static_cast<json::Number>(tempUser["Forum"]["Replies"]),
static_cast<json::Number>(tempUser["Forum"]["Reputation"]));
} }
catch (json::Exception &e) catch (json::Exception &e)
{ {

View File

@ -7,16 +7,33 @@ class UserInfo
{ {
public: public:
int ID; int ID;
int Age; int age;
std::string Username; std::string username;
std::string Biography; std::string biography;
std::string Location; std::string location;
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;
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), ID(id),
Age(age), age(age),
Username(username), username(username),
Biography(biography), biography(biography),
Location(location) location(location),
website(website),
saveCount(saveCount),
averageScore(averageScore),
highestScore(highestScore),
topicCount(topicCount),
topicReplies(topicReplies),
reputation(reputation)
{ } { }
UserInfo() {} UserInfo() {}
}; };

View File

@ -123,7 +123,7 @@ void Label::updateMultiline()
} }
if (autoHeight) if (autoHeight)
{ {
Size.Y = lines*12; Size.Y = lines*12+3;
} }
textLines = std::string(rawText); textLines = std::string(rawText);
delete[] rawText; delete[] rawText;
@ -164,7 +164,7 @@ void Label::updateMultiline()
{ {
if (autoHeight) if (autoHeight)
{ {
Size.Y = 12; Size.Y = 15;
} }
textLines = std::string(""); textLines = std::string("");
} }

View File

@ -228,7 +228,7 @@ void PreviewView::commentBoxAutoHeight()
int oldSize = addCommentBox->Size.Y; int oldSize = addCommentBox->Size.Y;
addCommentBox->AutoHeight(); addCommentBox->AutoHeight();
int newSize = addCommentBox->Size.Y+5; int newSize = addCommentBox->Size.Y+2;
addCommentBox->Size.Y = oldSize; addCommentBox->Size.Y = oldSize;
commentBoxHeight = newSize+22; commentBoxHeight = newSize+22;
@ -245,7 +245,7 @@ void PreviewView::commentBoxAutoHeight()
commentBoxPositionX = (XRES/2)+4; commentBoxPositionX = (XRES/2)+4;
commentBoxPositionY = Size.Y-19; commentBoxPositionY = Size.Y-19;
commentBoxSizeX = Size.X-(XRES/2)-48; commentBoxSizeX = Size.X-(XRES/2)-48;
commentBoxSizeY = 17; commentBoxSizeY = 16;
} }
commentsPanel->Size.Y = Size.Y-commentBoxHeight; commentsPanel->Size.Y = Size.Y-commentBoxHeight;
} }

View File

@ -37,13 +37,13 @@ ProfileActivity::ProfileActivity(std::string username) :
SaveAction(ProfileActivity * a) : a(a) { } SaveAction(ProfileActivity * a) : a(a) { }
void ActionCallback(ui::Button * sender_) void ActionCallback(ui::Button * sender_)
{ {
if(!a->loading && !a->saving && a->editable) if (!a->loading && !a->saving && a->editable)
{ {
sender_->Enabled = false; sender_->Enabled = false;
sender_->SetText("Saving..."); sender_->SetText("Saving...");
a->saving = true; a->saving = true;
a->info.Location = ((ui::Textbox*)a->location)->GetText(); a->info.location = ((ui::Textbox*)a->location)->GetText();
a->info.Biography = ((ui::Textbox*)a->bio)->GetText(); a->info.biography = ((ui::Textbox*)a->bio)->GetText();
RequestBroker::Ref().Start(Client::Ref().SaveUserInfoAsync(a->info), a); RequestBroker::Ref().Start(Client::Ref().SaveUserInfoAsync(a->info), a);
} }
} }
@ -82,100 +82,88 @@ void ProfileActivity::setUserInfo(UserInfo newInfo)
info = newInfo; info = newInfo;
if(!info.Biography.length() && !editable) if (!info.biography.length() && !editable)
info.Biography = "\bg(no bio)"; 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); ui::ScrollPanel * scrollPanel = new ui::ScrollPanel(ui::Point(1, 1), ui::Point(Size.X-2, Size.Y-16));
AddComponent(avatar); 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; 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"); 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)); 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; title->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
AddComponent(title); scrollPanel->AddChild(title);
currentY += 20; currentY += 20;
ui::Label * locationTitle = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8-(40+8), 15), "Location"); 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; locationTitle->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
AddComponent(locationTitle); scrollPanel->AddChild(locationTitle);
currentY += 17; 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 = new ui::Textbox(ui::Point(4, currentY), ui::Point(Size.X-8-(40+8), 17), info.location);
location->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
AddComponent(location);
this->location = location;
currentY += 10+location->Size.Y;
} }
else else
{ {
ui::Label * location = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8-(40+8), 12), info.Location); 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)); 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"); ui::Label * bioTitle = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8, 15), "Biography");
bioTitle->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; bioTitle->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
AddComponent(bioTitle); scrollPanel->AddChild(bioTitle);
currentY += 17; 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 = new ui::Textbox(ui::Point(8, currentY), ui::Point(Size.X-16, -1), 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 else
{ {
ui::Label * bio = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8, -1), info.Biography); 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->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;
} }
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;
//exit(0); scrollPanel->InnerSize = ui::Point(Size.X, currentY);
} }
void ProfileActivity::OnResponseReady(void * userDataPtr, int identifier) void ProfileActivity::OnResponseReady(void * userDataPtr, int identifier)
{ {
if(loading) if (loading)
{ {
loading = false; loading = false;
setUserInfo(*(UserInfo*)userDataPtr); setUserInfo(*(UserInfo*)userDataPtr);
delete (UserInfo*)userDataPtr; delete (UserInfo*)userDataPtr;
} }
else if(saving) else if (saving)
{ {
Exit(); Exit();
} }
@ -188,7 +176,13 @@ void ProfileActivity::OnDraw()
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255); 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); RequestBroker::Ref().DetachRequestListener(this);
} }

View File

@ -6,10 +6,11 @@
#include "client/requestbroker/RequestListener.h" #include "client/requestbroker/RequestListener.h"
#include "client/UserInfo.h" #include "client/UserInfo.h"
#include "gui/interface/Window.h" #include "gui/interface/Window.h"
#include "gui/interface/Label.h"
class ProfileActivity: public WindowActivity, public RequestListener { class ProfileActivity: public WindowActivity, public RequestListener {
ui::Component * location; ui::Label * location;
ui::Component * bio; ui::Label * bio;
UserInfo info; UserInfo info;
bool editable; bool editable;
bool loading; bool loading;
@ -20,6 +21,7 @@ public:
virtual ~ProfileActivity(); virtual ~ProfileActivity();
virtual void OnResponseReady(void * userDataPtr, int identifier); virtual void OnResponseReady(void * userDataPtr, int identifier);
virtual void OnDraw(); virtual void OnDraw();
virtual void OnTryExit(ExitMethod method);
}; };
#endif /* PROFILEACTIVITY_H_ */ #endif /* PROFILEACTIVITY_H_ */