profile viewer now shows age, website, and save stats
Also, add Multiline type textboxes (allows pressing enter) and fix some other bugs
This commit is contained in:
parent
c786640c74
commit
906b4a973f
@ -1288,7 +1288,6 @@ RequestBroker::Request * Client::GetUserInfoAsync(std::string username)
|
||||
json::Object objDocument;
|
||||
json::Reader::Read(objDocument, dataStream);
|
||||
json::Object tempUser = objDocument["User"];
|
||||
|
||||
return new UserInfo(static_cast<json::Number>(tempUser["ID"]),
|
||||
static_cast<json::Number>(tempUser["Age"]),
|
||||
static_cast<json::String>(tempUser["Username"]),
|
||||
|
@ -60,7 +60,7 @@ void ScrollPanel::Draw(const Point& screenPos)
|
||||
}
|
||||
|
||||
g->fillrect(screenPos.X+(Size.X-scrollBarWidth), screenPos.Y, scrollBarWidth, Size.Y, 125, 125, 125, 100);
|
||||
g->fillrect(screenPos.X+(Size.X-scrollBarWidth), screenPos.Y+scrollPos, scrollBarWidth, scrollHeight, 255, 255, 255, 255);
|
||||
g->fillrect(screenPos.X+(Size.X-scrollBarWidth), screenPos.Y+scrollPos, scrollBarWidth, scrollHeight+1, 255, 255, 255, 255);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,8 +159,6 @@ void Textbox::cutSelection()
|
||||
{
|
||||
text = backingText;
|
||||
}
|
||||
if(actionCallback)
|
||||
actionCallback->TextChangedCallback(this);
|
||||
|
||||
if(multiline)
|
||||
updateMultiline();
|
||||
@ -175,6 +173,8 @@ void Textbox::cutSelection()
|
||||
{
|
||||
cursorPositionY = cursorPositionX = 0;
|
||||
}
|
||||
if(actionCallback)
|
||||
actionCallback->TextChangedCallback(this);
|
||||
}
|
||||
|
||||
void Textbox::selectAll()
|
||||
@ -187,18 +187,18 @@ void Textbox::selectAll()
|
||||
void Textbox::pasteIntoSelection()
|
||||
{
|
||||
std::string newText = ClipboardPull();
|
||||
if(HasSelection())
|
||||
if (HasSelection())
|
||||
{
|
||||
if(getLowerSelectionBound() < 0 || getHigherSelectionBound() > (int)backingText.length())
|
||||
if (getLowerSelectionBound() < 0 || getHigherSelectionBound() > (int)backingText.length())
|
||||
return;
|
||||
backingText.erase(backingText.begin()+getLowerSelectionBound(), backingText.begin()+getHigherSelectionBound());
|
||||
cursor = getLowerSelectionBound();
|
||||
}
|
||||
for(std::string::iterator iter = newText.begin(), end = newText.end(); iter != end; ++iter)
|
||||
for (std::string::iterator iter = newText.begin(), end = newText.end(); iter != end; ++iter)
|
||||
{
|
||||
if(!CharacterValid(*iter))
|
||||
if (!CharacterValid(*iter))
|
||||
{
|
||||
if(inputType == All)
|
||||
if (inputType == All || inputType == Multiline)
|
||||
{
|
||||
if(*iter == '\n' || *iter == '\r')
|
||||
*iter = ' ';
|
||||
@ -248,8 +248,6 @@ void Textbox::pasteIntoSelection()
|
||||
{
|
||||
text = backingText;
|
||||
}
|
||||
if(actionCallback)
|
||||
actionCallback->TextChangedCallback(this);
|
||||
|
||||
if(multiline)
|
||||
updateMultiline();
|
||||
@ -267,6 +265,8 @@ void Textbox::pasteIntoSelection()
|
||||
{
|
||||
cursorPositionY = cursorPositionX = 0;
|
||||
}
|
||||
if(actionCallback)
|
||||
actionCallback->TextChangedCallback(this);
|
||||
}
|
||||
|
||||
bool Textbox::CharacterValid(Uint16 character)
|
||||
@ -276,6 +276,9 @@ bool Textbox::CharacterValid(Uint16 character)
|
||||
case Number:
|
||||
case Numeric:
|
||||
return (character >= '0' && character <= '9');
|
||||
case Multiline:
|
||||
if (character == '\n')
|
||||
return true;
|
||||
case All:
|
||||
default:
|
||||
return (character >= ' ' && character < 127);
|
||||
@ -406,6 +409,8 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
||||
}
|
||||
ClearSelection();
|
||||
break;
|
||||
case KEY_RETURN:
|
||||
character = '\n';
|
||||
default:
|
||||
if (CharacterValid(character) && !ReadOnly)
|
||||
{
|
||||
@ -418,7 +423,7 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
||||
}
|
||||
|
||||
int regionWidth = Size.X;
|
||||
if( Appearance.icon)
|
||||
if (Appearance.icon)
|
||||
regionWidth -= 13;
|
||||
regionWidth -= Appearance.Margin.Left;
|
||||
regionWidth -= Appearance.Margin.Right;
|
||||
@ -465,8 +470,6 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
||||
{
|
||||
text = backingText;
|
||||
}
|
||||
if(actionCallback)
|
||||
actionCallback->TextChangedCallback(this);
|
||||
}
|
||||
|
||||
if(multiline)
|
||||
@ -485,6 +488,8 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
||||
{
|
||||
cursorPositionY = cursorPositionX = 0;
|
||||
}
|
||||
if (changed && actionCallback)
|
||||
actionCallback->TextChangedCallback(this);
|
||||
}
|
||||
|
||||
void Textbox::OnMouseClick(int x, int y, unsigned button)
|
||||
|
@ -21,7 +21,7 @@ class Textbox : public Label
|
||||
friend class TextboxAction;
|
||||
public:
|
||||
bool ReadOnly;
|
||||
enum ValidInput { All, Numeric, Number };
|
||||
enum ValidInput { All, Multiline, Numeric, Number }; // Numeric doesn't delete trailing 0's
|
||||
Textbox(Point position, Point size, std::string textboxText = "", std::string textboxPlaceholder = "");
|
||||
virtual ~Textbox();
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "client/Client.h"
|
||||
#include "client/UserInfo.h"
|
||||
#include "client/requestbroker/RequestListener.h"
|
||||
#include "Format.h"
|
||||
|
||||
ProfileActivity::ProfileActivity(std::string username) :
|
||||
WindowActivity(ui::Point(-1, -1), ui::Point(236, 300)),
|
||||
@ -86,72 +87,142 @@ void ProfileActivity::setUserInfo(UserInfo newInfo)
|
||||
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.website.length())
|
||||
info.website = "\bgNot Provided";
|
||||
|
||||
|
||||
ui::ScrollPanel * scrollPanel = new ui::ScrollPanel(ui::Point(1, 1), ui::Point(Size.X-2, Size.Y-16));
|
||||
// everything is on a large scroll panel
|
||||
scrollPanel = new ui::ScrollPanel(ui::Point(1, 1), ui::Point(Size.X-2, Size.Y-16));
|
||||
AddComponent(scrollPanel);
|
||||
int currentY = 5;
|
||||
|
||||
// username label
|
||||
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;
|
||||
scrollPanel->AddChild(title);
|
||||
|
||||
ui::AvatarButton * avatar = new ui::AvatarButton(ui::Point((Size.X-40)-8, 8), ui::Point(40, 40), info.username);
|
||||
// avatar
|
||||
ui::AvatarButton * avatar = new ui::AvatarButton(ui::Point((Size.X-40)-8, 5), ui::Point(40, 40), info.username);
|
||||
scrollPanel->AddChild(avatar);
|
||||
|
||||
int currentY = 5;
|
||||
// edit avatar button
|
||||
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));
|
||||
scrollPanel->AddChild(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;
|
||||
scrollPanel->AddChild(title);
|
||||
currentY += 20;
|
||||
currentY += 23;
|
||||
|
||||
// age
|
||||
ui::Label * ageTitle = new ui::Label(ui::Point(4, currentY), ui::Point(18, 15), "Age:");
|
||||
ageTitle->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
ageTitle->SetTextColour(ui::Colour(180, 180, 180));
|
||||
scrollPanel->AddChild(ageTitle);
|
||||
|
||||
ui::Label * locationTitle = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8-(40+8), 15), "Location");
|
||||
// can't figure out how to tell a null from a 0 in the json library we use
|
||||
ui::Label *age = new ui::Label(ui::Point(8+ageTitle->Size.X, currentY), ui::Point(40, 15), info.age ? format::NumberToString<int>(info.age) : "\bgNot Provided");
|
||||
age->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
scrollPanel->AddChild(age);
|
||||
currentY += 2+age->Size.Y;
|
||||
|
||||
// location
|
||||
ui::Label * locationTitle = new ui::Label(ui::Point(4, currentY), ui::Point(45, 15), "Location:");
|
||||
locationTitle->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
locationTitle->SetTextColour(ui::Colour(180, 180, 180));
|
||||
scrollPanel->AddChild(locationTitle);
|
||||
currentY += 17;
|
||||
|
||||
if (editable)
|
||||
{
|
||||
location = new ui::Textbox(ui::Point(4, currentY), ui::Point(Size.X-8-(40+8), 17), info.location);
|
||||
}
|
||||
location = new ui::Textbox(ui::Point(8+locationTitle->Size.X, currentY), ui::Point(Size.X-locationTitle->Size.X-16, 17), info.location);
|
||||
else
|
||||
{
|
||||
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));
|
||||
}
|
||||
location = new ui::Label(ui::Point(4+locationTitle->Size.X, currentY), ui::Point(Size.X-locationTitle->Size.X-14, 17), info.location);
|
||||
location->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
scrollPanel->AddChild(location);
|
||||
this->location = location;
|
||||
currentY += 10+location->Size.Y;
|
||||
currentY += 2+location->Size.Y;
|
||||
|
||||
ui::Label * bioTitle = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8, 15), "Biography");
|
||||
// website
|
||||
ui::Label * websiteTitle = new ui::Label(ui::Point(4, currentY), ui::Point(38, 15), "Website:");
|
||||
websiteTitle->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
websiteTitle->SetTextColour(ui::Colour(180, 180, 180));
|
||||
scrollPanel->AddChild(websiteTitle);
|
||||
|
||||
ui::Label *website = new ui::Label(ui::Point(8+websiteTitle->Size.X, currentY), ui::Point(Size.X-websiteTitle->Size.X-16, 15), info.website);
|
||||
website->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
scrollPanel->AddChild(website);
|
||||
currentY += 2+website->Size.Y;
|
||||
|
||||
// saves
|
||||
ui::Label * savesTitle = new ui::Label(ui::Point(4, currentY), ui::Point(35, 15), "Saves:");
|
||||
savesTitle->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
savesTitle->SetTextColour(ui::Colour(180, 180, 180));
|
||||
scrollPanel->AddChild(savesTitle);
|
||||
currentY += savesTitle->Size.Y;
|
||||
|
||||
// saves count
|
||||
ui::Label * saveCountTitle = new ui::Label(ui::Point(12, currentY), ui::Point(30, 15), "Count:");
|
||||
saveCountTitle->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
saveCountTitle->SetTextColour(ui::Colour(180, 180, 180));
|
||||
scrollPanel->AddChild(saveCountTitle);
|
||||
|
||||
ui::Label *savesCount = new ui::Label(ui::Point(12+saveCountTitle->Size.X, currentY), ui::Point(Size.X-saveCountTitle->Size.X-16, 15), format::NumberToString<int>(info.saveCount));
|
||||
savesCount->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
scrollPanel->AddChild(savesCount);
|
||||
currentY += savesCount->Size.Y;
|
||||
|
||||
// average score
|
||||
ui::Label * averageScoreTitle = new ui::Label(ui::Point(12, currentY), ui::Point(70, 15), "Average Score:");
|
||||
averageScoreTitle->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
averageScoreTitle->SetTextColour(ui::Colour(180, 180, 180));
|
||||
scrollPanel->AddChild(averageScoreTitle);
|
||||
|
||||
ui::Label *averageScore = new ui::Label(ui::Point(12+averageScoreTitle->Size.X, currentY), ui::Point(Size.X-averageScoreTitle->Size.X-16, 15), format::NumberToString<float>(info.averageScore));
|
||||
averageScore->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
scrollPanel->AddChild(averageScore);
|
||||
currentY += averageScore->Size.Y;
|
||||
|
||||
// highest score
|
||||
ui::Label * highestScoreTitle = new ui::Label(ui::Point(12, currentY), ui::Point(69, 15), "Highest Score:");
|
||||
highestScoreTitle->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
highestScoreTitle->SetTextColour(ui::Colour(180, 180, 180));
|
||||
scrollPanel->AddChild(highestScoreTitle);
|
||||
|
||||
ui::Label *highestScore = new ui::Label(ui::Point(12+highestScoreTitle->Size.X, currentY), ui::Point(Size.X-highestScoreTitle->Size.X-16, 15), format::NumberToString<int>(info.highestScore));
|
||||
highestScore->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
scrollPanel->AddChild(highestScore);
|
||||
currentY += 2+highestScore->Size.Y;
|
||||
|
||||
// biograhy
|
||||
ui::Label * bioTitle = new ui::Label(ui::Point(4, currentY), ui::Point(50, 15), "Biography:");
|
||||
bioTitle->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
bioTitle->SetTextColour(ui::Colour(180, 180, 180));
|
||||
scrollPanel->AddChild(bioTitle);
|
||||
currentY += 17;
|
||||
|
||||
class BioChangedAction: public ui::TextboxAction
|
||||
{
|
||||
public:
|
||||
ProfileActivity * profileActivity;
|
||||
BioChangedAction(ProfileActivity * profileActivity_) { profileActivity = profileActivity_; }
|
||||
virtual void TextChangedCallback(ui::Textbox * sender)
|
||||
{
|
||||
profileActivity->ResizeArea();
|
||||
}
|
||||
};
|
||||
|
||||
if (editable)
|
||||
{
|
||||
bio = new ui::Textbox(ui::Point(8, currentY), ui::Point(Size.X-16, -1), info.biography);
|
||||
bio = new ui::Textbox(ui::Point(4, currentY), ui::Point(Size.X-12, -1), info.biography);
|
||||
((ui::Textbox*)bio)->SetInputType(ui::Textbox::Multiline);
|
||||
((ui::Textbox*)bio)->SetActionCallback(new BioChangedAction(this));
|
||||
}
|
||||
else
|
||||
{
|
||||
bio = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-8, -1), info.biography);
|
||||
bio->SetTextColour(ui::Colour(180, 180, 180));
|
||||
}
|
||||
bio = new ui::Label(ui::Point(4, currentY), ui::Point(Size.X-12, -1), info.biography);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -181,6 +252,11 @@ void ProfileActivity::OnTryExit(ExitMethod method)
|
||||
Exit();
|
||||
}
|
||||
|
||||
void ProfileActivity::ResizeArea()
|
||||
{
|
||||
scrollPanel->InnerSize = ui::Point(Size.X, bio->Position.Y + bio->Size.Y + 10);
|
||||
}
|
||||
|
||||
ProfileActivity::~ProfileActivity()
|
||||
{
|
||||
RequestBroker::Ref().DetachRequestListener(this);
|
||||
|
@ -6,11 +6,16 @@
|
||||
#include "client/requestbroker/RequestListener.h"
|
||||
#include "client/UserInfo.h"
|
||||
#include "gui/interface/Window.h"
|
||||
#include "gui/interface/Label.h"
|
||||
|
||||
namespace ui
|
||||
{
|
||||
class Label;
|
||||
class ScrollPanel;
|
||||
}
|
||||
class ProfileActivity: public WindowActivity, public RequestListener {
|
||||
ui::Label * location;
|
||||
ui::Label * bio;
|
||||
ui::ScrollPanel *scrollPanel;
|
||||
ui::Label *location;
|
||||
ui::Label *bio;
|
||||
UserInfo info;
|
||||
bool editable;
|
||||
bool loading;
|
||||
@ -22,6 +27,8 @@ public:
|
||||
virtual void OnResponseReady(void * userDataPtr, int identifier);
|
||||
virtual void OnDraw();
|
||||
virtual void OnTryExit(ExitMethod method);
|
||||
|
||||
void ResizeArea();
|
||||
};
|
||||
|
||||
#endif /* PROFILEACTIVITY_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user