From 8f58c61c69eaac8655d8894efd30433cc0f2a653 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Mon, 10 Sep 2012 20:09:22 -0400 Subject: [PATCH] Show number of votes and the history button on your own saves --- src/interface/SaveButton.cpp | 57 ++++++++++++++++++++++++++++++++++-- src/interface/SaveButton.h | 5 ++++ src/search/SearchView.cpp | 8 +++++ 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/interface/SaveButton.cpp b/src/interface/SaveButton.cpp index 35be432a2..d8ad43005 100644 --- a/src/interface/SaveButton.cpp +++ b/src/interface/SaveButton.cpp @@ -22,7 +22,9 @@ SaveButton::SaveButton(Point position, Point size, SaveInfo * save): selectable(false), selected(false), waitingForThumb(false), - isMouseInsideAuthor(false) + isMouseInsideAuthor(false), + MouseInsideHistory(false), + showVotes(false) { if(save) { @@ -67,7 +69,9 @@ SaveButton::SaveButton(Point position, Point size, SaveFile * file): selected(false), wantsDraw(false), waitingForThumb(false), - isMouseInsideAuthor(false) + isMouseInsideAuthor(false), + MouseInsideHistory(false), + showVotes(false) { if(file) { @@ -187,6 +191,39 @@ void SaveButton::Draw(const Point& screenPos) g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save->userName.c_str()))/2, screenPos.Y+Size.Y - 10, save->userName, 200, 230, 255, 255); else g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save->userName.c_str()))/2, screenPos.Y+Size.Y - 10, save->userName, 100, 130, 160, 255); + if (!isMouseInside && showVotes) + { + char icon[64], votestring[64]; + int j; + sprintf(votestring, "%d", save->GetVotesUp()-save->GetVotesDown()); + icon[0] = 0xBB; + for (j = 1; j <= strlen(votestring); j++) + icon[j] = 0xBC; + icon[j-1] = 0xB9; + icon[j] = 0xBA; + icon[j+1] = 0; + int x = screenPos.X-7+(Size.X-thumbBoxSize.X)/2+thumbBoxSize.X-Graphics::textwidth(icon); + int y = screenPos.Y-23+(Size.Y-thumbBoxSize.Y)/2+thumbBoxSize.Y; + g->drawtext(x, y, icon, 16, 72, 16, 255); + for (j=0; icon[j]; j++) + icon[j] -= 14; + g->drawtext(x, y, icon, 192, 192, 192, 255); + for (j=0; votestring[j]; j++) + if (votestring[j] != '-') + votestring[j] += 127; + g->drawtext(x+3, y, votestring, 255, 255, 255, 255); + } + if (MouseInsideHistory && showVotes) + { + int x = screenPos.X; + int y = screenPos.Y-15+(Size.Y-thumbBoxSize.Y)/2+thumbBoxSize.Y; + g->fillrect(x+1, y+1, 7, 8, 255, 255, 255, 255); + if (MouseInsideHistory) { + g->drawtext(x, y, "\xA6", 200, 100, 80, 255); + } else { + g->drawtext(x, y, "\xA6", 160, 70, 50, 255); + } + } } if(file) { @@ -233,6 +270,8 @@ void SaveButton::OnMouseUnclick(int x, int y, unsigned int button) isButtonDown = false; if(isMouseInsideAuthor) DoAuthorAction(); + else if (MouseInsideHistory) + DoHistoryAction(); else DoAction(); } @@ -258,6 +297,13 @@ void SaveButton::OnMouseMovedInside(int x, int y, int dx, int dy) } else isMouseInsideAuthor = false; + + if(showVotes && y > Size.Y-29 && y < Size.Y - 18 && x > 0 && x < 9) + { + MouseInsideHistory = true; + } + else + MouseInsideHistory = false; } void SaveButton::OnMouseEnter(int x, int y) @@ -269,6 +315,13 @@ void SaveButton::OnMouseLeave(int x, int y) { isMouseInside = false; isMouseInsideAuthor = false; + MouseInsideHistory = false; +} + +void SaveButton::DoHistoryAction() +{ + if(actionCallback) + actionCallback->HistoryActionCallback(this); } void SaveButton::DoAuthorAction() diff --git a/src/interface/SaveButton.h b/src/interface/SaveButton.h index d1ae05a11..9e9bef567 100644 --- a/src/interface/SaveButton.h +++ b/src/interface/SaveButton.h @@ -19,6 +19,7 @@ class SaveButtonAction public: virtual void ActionCallback(ui::SaveButton * sender) {} virtual void AuthorActionCallback(ui::SaveButton * sender) {} + virtual void HistoryActionCallback(ui::SaveButton * sender) {} virtual void SelectedCallback(ui::SaveButton * sender) {} virtual ~SaveButtonAction() {} }; @@ -32,6 +33,8 @@ class SaveButton : public Component, public ThumbnailListener bool wantsDraw; bool waitingForThumb; bool isMouseInsideAuthor; + bool MouseInsideHistory; + bool showVotes; public: SaveButton(Point position, Point size, SaveInfo * save); SaveButton(Point position, Point size, SaveFile * file); @@ -54,12 +57,14 @@ public: bool GetSelected() { return selected; } void SetSelectable(bool selectable_) { selectable = selectable_; } bool GetSelectable() { return selectable; } + void SetShowVotes(bool showVotes_) { showVotes = showVotes_; } SaveInfo * GetSave() { return save; } SaveFile * GetSaveFile() { return file; } inline bool GetState() { return state; } virtual void DoAction(); virtual void DoAuthorAction(); + virtual void DoHistoryAction(); virtual void DoSelection(); void SetActionCallback(SaveButtonAction * action); protected: diff --git a/src/search/SearchView.cpp b/src/search/SearchView.cpp index 256ef90ff..08258888f 100644 --- a/src/search/SearchView.cpp +++ b/src/search/SearchView.cpp @@ -596,6 +596,12 @@ void SearchView::NotifySaveListChanged(SearchModel * sender) { v->Search("user:"+sender->GetSave()->GetUserName()); } + virtual void HistoryActionCallback(ui::SaveButton * sender) + { + stringstream search; + search << "history:" << sender->GetSave()->GetID(); + v->Search(search.str()); + } }; for(i = 0; i < saves.size(); i++) { @@ -617,6 +623,8 @@ void SearchView::NotifySaveListChanged(SearchModel * sender) saveButton->SetActionCallback(new SaveOpenAction(this)); if(Client::Ref().GetAuthUser().ID) saveButton->SetSelectable(true); + if (saves[i]->GetUserName() == Client::Ref().GetAuthUser().Username || sender->GetShowOwn() || Client::Ref().GetAuthUser().UserElevation == User::ElevationAdmin || Client::Ref().GetAuthUser().UserElevation == User::ElevationModerator) + saveButton->SetShowVotes(true); saveButtons.push_back(saveButton); AddComponent(saveButton); saveX++;