From b05f1141742c7e5ed397df334b0c86fecb16c58b Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Mon, 3 Sep 2012 13:25:48 +0100 Subject: Views in save Preview and use old vote bars. Fixes #171 diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 4256f16..852dbb6 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -1411,6 +1411,7 @@ SaveInfo * Client::GetSave(int saveID, int saveDate) json::Boolean tempPublished = objDocument["Published"]; json::Boolean tempFavourite = objDocument["Favourite"]; json::Number tempComments = objDocument["Comments"]; + json::Number tempViews = objDocument["Views"]; json::Array tagsArray = objDocument["Tags"]; std::vector tempTags; @@ -1435,6 +1436,7 @@ SaveInfo * Client::GetSave(int saveID, int saveDate) ); tempSave->Comments = tempComments.Value(); tempSave->Favourite = tempFavourite.Value(); + tempSave->Views = tempViews.Value(); return tempSave; } catch (json::Exception &e) diff --git a/src/client/SaveInfo.cpp b/src/client/SaveInfo.cpp index 5bb08a8..c6cafb1 100644 --- a/src/client/SaveInfo.cpp +++ b/src/client/SaveInfo.cpp @@ -12,7 +12,7 @@ SaveInfo::SaveInfo(SaveInfo & save) : userName(save.userName), name(save.name), Description(save.Description), date( save.date), Published(save.Published), id(save.id), votesUp( - save.votesUp), votesDown(save.votesDown), gameSave(NULL), vote(save.vote), tags(save.tags), Comments(save.Comments) { + save.votesUp), votesDown(save.votesDown), gameSave(NULL), vote(save.vote), tags(save.tags), Comments(save.Comments), Views(save.Views) { if(save.gameSave) gameSave = new GameSave(*save.gameSave); } @@ -21,14 +21,14 @@ SaveInfo::SaveInfo(int _id, int _date, int _votesUp, int _votesDown, std::string std::string _name) : id(_id), votesUp(_votesUp), votesDown(_votesDown), userName(_userName), name( _name), Description(""), date(_date), Published( - true), gameSave(NULL), vote(0), tags(), Comments(0) { + true), gameSave(NULL), vote(0), tags(), Comments(0), Views(0) { } SaveInfo::SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote, std::string _userName, std::string _name, std::string description_, bool published_, std::vector tags_) : id(_id), votesUp(_votesUp), votesDown(_votesDown), userName(_userName), name( _name), Description(description_), date(date_), Published( - published_), gameSave(NULL), vote(_vote), tags(tags_), Comments(0) { + published_), gameSave(NULL), vote(_vote), tags(tags_), Views(0), Comments(0) { } SaveInfo::~SaveInfo() diff --git a/src/client/SaveInfo.h b/src/client/SaveInfo.h index 6c3a2a3..49057ac 100644 --- a/src/client/SaveInfo.h +++ b/src/client/SaveInfo.h @@ -17,6 +17,7 @@ public: int votesUp, votesDown; bool Favourite; int Comments; + int Views; GameSave * gameSave; diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index 2e3d1fa..de11abd 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -140,21 +140,25 @@ PreviewView::PreviewView(): browserOpenButton->SetActionCallback(new BrowserOpenAction(this)); AddComponent(browserOpenButton); - saveNameLabel = new ui::Label(ui::Point(5, (YRES/2)+15), ui::Point(100, 16), ""); + saveNameLabel = new ui::Label(ui::Point(5, (YRES/2)), ui::Point(100, 16), ""); saveNameLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; saveNameLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom; AddComponent(saveNameLabel); - saveDescriptionLabel = new ui::Label(ui::Point(5, (YRES/2)+15+14+17), ui::Point((XRES/2)-10, Size.Y-((YRES/2)+15+14+17)-21), ""); + saveDescriptionLabel = new ui::Label(ui::Point(5, (YRES/2)+15+17), ui::Point((XRES/2)-10, Size.Y-((YRES/2)+15+14+17)-21), ""); saveDescriptionLabel->SetMultiline(true); saveDescriptionLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; saveDescriptionLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop; saveDescriptionLabel->SetTextColour(ui::Colour(180, 180, 180)); AddComponent(saveDescriptionLabel); - authorDateLabel = new ui::Label(ui::Point(5, (YRES/2)+15+14), ui::Point(100, 16), ""); + authorDateLabel = new ui::Label(ui::Point(5, (YRES/2)+15), ui::Point(100, 16), ""); authorDateLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; authorDateLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom; AddComponent(authorDateLabel); + viewsLabel = new ui::Label(ui::Point((XRES/2)-103, (YRES/2)+15), ui::Point(100, 16), ""); + viewsLabel->Appearance.HorizontalAlign = ui::Appearance::AlignRight; viewsLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom; + AddComponent(viewsLabel); + pageInfo = new ui::Label(ui::Point((XRES/2) + 5, Size.Y+1), ui::Point(Size.X-((XRES/2) + 10), 15), "Page 1 of 1"); pageInfo->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; authorDateLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; @@ -269,18 +273,35 @@ void PreviewView::OnDraw() g->drawrect(Position.X, Position.Y, (XRES/2)+1, (YRES/2)+1, 255, 255, 255, 100); g->draw_line(Position.X+XRES/2, Position.Y+1, Position.X+XRES/2, Position.Y+Size.Y-2, 200, 200, 200, 255); - - g->draw_line(Position.X+1, Position.Y+12+YRES/2, Position.X-1+XRES/2, Position.Y+12+YRES/2, 100, 100, 100,255); - float factor; if(!(!votesUp && !votesDown)) { - factor = (float)(((float)(XRES/2)-2)/((float)(votesUp+votesDown))); - g->fillrect(1+Position.X, 2+Position.Y+YRES/2, (XRES/2)-2, 9, 200, 50, 50, 255); - g->fillrect(1+Position.X, 2+Position.Y+YRES/2, (int)(((float)votesUp)*factor), 9, 50, 200, 50, 255); - g->fillrect(1+Position.X, 2+Position.Y+(YRES/2), 14, 9, 0, 0, 0, 100); - g->fillrect(Position.X+(XRES/2)-15, 2+Position.Y+(YRES/2), 14, 9, 0, 0, 0, 100); - g->draw_icon(1+Position.X+2, Position.Y+(YRES/2)+4, IconVoteUp); - g->draw_icon(Position.X+(XRES/2)-12, Position.Y+(YRES/2)+1, IconVoteDown); + float ryf; + int nyu, nyd; + int lv = (votesUp>votesDown)?votesUp:votesDown; + lv = (lv>10)?lv:10; + + if (50>lv) + { + ryf = 50.0f/((float)lv); + nyu = votesUp*ryf; + nyd = votesDown*ryf; + } + else + { + ryf = ((float)lv)/50.0f; + nyu = votesUp/ryf; + nyd = votesDown/ryf; + } + nyu = nyu>50?50:nyu; + nyd = nyd>50?50:nyd; + + g->fillrect(Position.X+(XRES/2)-55, Position.Y+(YRES/2)+3, 53, 7, 0, 107, 10, 255); + g->fillrect(Position.X+(XRES/2)-55, Position.Y+(YRES/2)+9, 53, 7, 107, 10, 0, 255); + g->drawrect(Position.X+(XRES/2)-55, Position.Y+(YRES/2)+3, 53, 7, 128, 128, 128, 255); + g->drawrect(Position.X+(XRES/2)-55, Position.Y+(YRES/2)+9, 53, 7, 128, 128, 128, 255); + + g->fillrect(Position.X+(XRES/2)-4-nyu, Position.Y+(YRES/2)+5, nyu, 3, 57, 187, 57, 255); + g->fillrect(Position.X+(XRES/2)-4-nyd, Position.Y+(YRES/2)+11, nyd, 3, 187, 57, 57, 255); } } @@ -353,6 +374,7 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender) votesDown = save->votesDown; saveNameLabel->SetText(save->name); authorDateLabel->SetText("\bgAuthor:\bw " + save->userName + " \bgDate:\bw " + format::UnixtimeToDateMini(save->date)); + viewsLabel->SetText("\bgViews:\bw " + format::NumberToString(save->Views)); saveDescriptionLabel->SetText(save->Description); if(save->Favourite) favButton->Enabled = false; diff --git a/src/preview/PreviewView.h b/src/preview/PreviewView.h index 7fb9ff5..2dc667b 100644 --- a/src/preview/PreviewView.h +++ b/src/preview/PreviewView.h @@ -41,6 +41,7 @@ class PreviewView: public ui::Window { ui::Label * authorDateLabel; ui::Label * pageInfo; ui::Label * saveDescriptionLabel; + ui::Label * viewsLabel; ui::Textbox * saveIDTextbox; ui::ScrollPanel * commentsPanel; std::vector comments; -- cgit v0.9.2-21-gd62e