mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-09-07 22:40:43 +02:00
Right click menu to go to history and user info for save buttons
This commit is contained in:
@@ -52,6 +52,7 @@ void ContextMenu::Show(ui::Point position)
|
|||||||
void ContextMenu::ActionCallback(ui::Button *sender, int item)
|
void ContextMenu::ActionCallback(ui::Button *sender, int item)
|
||||||
{
|
{
|
||||||
ui::Engine::Ref().CloseWindow();
|
ui::Engine::Ref().CloseWindow();
|
||||||
|
Halt();
|
||||||
source->OnContextMenuAction(item);
|
source->OnContextMenuAction(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +62,18 @@ void ContextMenu::OnMouseDown(int x, int y, unsigned button)
|
|||||||
ui::Engine::Ref().CloseWindow();
|
ui::Engine::Ref().CloseWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ContextMenu::SetItem(int id, std::string text)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < items.size(); i++)
|
||||||
|
{
|
||||||
|
if(items[i].ID == id)
|
||||||
|
{
|
||||||
|
items[i].Text = text;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ContextMenu::RemoveItem(int id)
|
void ContextMenu::RemoveItem(int id)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < items.size(); i++)
|
for(int i = 0; i < items.size(); i++)
|
||||||
|
@@ -29,6 +29,7 @@ public:
|
|||||||
virtual void ActionCallback(ui::Button *sender, int item);
|
virtual void ActionCallback(ui::Button *sender, int item);
|
||||||
virtual void AddItem(ContextMenuItem item);
|
virtual void AddItem(ContextMenuItem item);
|
||||||
virtual void RemoveItem(int id);
|
virtual void RemoveItem(int id);
|
||||||
|
virtual void SetItem(int id, std::string text);
|
||||||
virtual void Show(ui::Point position);
|
virtual void Show(ui::Point position);
|
||||||
virtual void OnDraw();
|
virtual void OnDraw();
|
||||||
virtual void OnMouseDown(int x, int y, unsigned button);
|
virtual void OnMouseDown(int x, int y, unsigned button);
|
||||||
|
@@ -7,6 +7,9 @@
|
|||||||
#include "Engine.h"
|
#include "Engine.h"
|
||||||
#include "client/ThumbnailBroker.h"
|
#include "client/ThumbnailBroker.h"
|
||||||
#include "simulation/SaveRenderer.h"
|
#include "simulation/SaveRenderer.h"
|
||||||
|
#include "Format.h"
|
||||||
|
#include "ContextMenu.h"
|
||||||
|
#include "Keys.h"
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
@@ -23,7 +26,7 @@ SaveButton::SaveButton(Point position, Point size, SaveInfo * save):
|
|||||||
selected(false),
|
selected(false),
|
||||||
waitingForThumb(false),
|
waitingForThumb(false),
|
||||||
isMouseInsideAuthor(false),
|
isMouseInsideAuthor(false),
|
||||||
MouseInsideHistory(false),
|
isMouseInsideHistory(false),
|
||||||
showVotes(false)
|
showVotes(false)
|
||||||
{
|
{
|
||||||
if(save)
|
if(save)
|
||||||
@@ -44,6 +47,12 @@ SaveButton::SaveButton(Point position, Point size, SaveInfo * save):
|
|||||||
voteColour.Green = voteRatio*255;
|
voteColour.Green = voteRatio*255;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
menu = new ContextMenu(this);
|
||||||
|
menu->AddItem(ContextMenuItem("Open", 0, true));
|
||||||
|
menu->AddItem(ContextMenuItem("Select", 1, true));
|
||||||
|
menu->AddItem(ContextMenuItem("View History", 2, true));
|
||||||
|
menu->AddItem(ContextMenuItem("More by this user", 3, true));
|
||||||
|
|
||||||
if(save)
|
if(save)
|
||||||
{
|
{
|
||||||
name = save->name;
|
name = save->name;
|
||||||
@@ -53,6 +62,29 @@ SaveButton::SaveButton(Point position, Point size, SaveInfo * save):
|
|||||||
name = name.erase(position, name.length()-position);
|
name = name.erase(position, name.length()-position);
|
||||||
name += "...";
|
name += "...";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string votes, icon;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
votes = format::NumberToString<int>(save->GetVotesUp()-save->GetVotesDown());
|
||||||
|
icon += 0xBB;
|
||||||
|
for (int j = 1; j < votes.length(); j++)
|
||||||
|
icon += 0xBC;
|
||||||
|
icon += 0xB9;
|
||||||
|
icon += 0xBA;
|
||||||
|
|
||||||
|
votesBackground = icon;
|
||||||
|
|
||||||
|
for (std::string::iterator iter = icon.begin(), end = icon.end(); iter != end; ++iter)
|
||||||
|
*iter -= 14;
|
||||||
|
|
||||||
|
votesBackground2 = icon;
|
||||||
|
|
||||||
|
for (std::string::iterator iter = votes.begin(), end = votes.end(); iter != end; ++iter)
|
||||||
|
if(*iter != '-')
|
||||||
|
*iter += 127;
|
||||||
|
|
||||||
|
votesString = votes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +102,7 @@ SaveButton::SaveButton(Point position, Point size, SaveFile * file):
|
|||||||
wantsDraw(false),
|
wantsDraw(false),
|
||||||
waitingForThumb(false),
|
waitingForThumb(false),
|
||||||
isMouseInsideAuthor(false),
|
isMouseInsideAuthor(false),
|
||||||
MouseInsideHistory(false),
|
isMouseInsideHistory(false),
|
||||||
showVotes(false)
|
showVotes(false)
|
||||||
{
|
{
|
||||||
if(file)
|
if(file)
|
||||||
@@ -198,32 +230,18 @@ 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, 100, 130, 160, 255);
|
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 (showVotes)// && !isMouseInside)
|
if (showVotes)// && !isMouseInside)
|
||||||
{
|
{
|
||||||
char icon[64], votestring[64];
|
int x = screenPos.X-7+(Size.X-thumbBoxSize.X)/2+thumbBoxSize.X-Graphics::textwidth(votesBackground.c_str());
|
||||||
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;
|
int y = screenPos.Y-23+(Size.Y-thumbBoxSize.Y)/2+thumbBoxSize.Y;
|
||||||
g->drawtext(x, y, icon, 16, 72, 16, 255);
|
g->drawtext(x, y, votesBackground, 16, 72, 16, 255);
|
||||||
for (j=0; icon[j]; j++)
|
g->drawtext(x, y, votesBackground2, 192, 192, 192, 255);
|
||||||
icon[j] -= 14;
|
g->drawtext(x+3, y, votesString, 255, 255, 255, 255);
|
||||||
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)
|
if (isMouseInsideHistory && showVotes)
|
||||||
{
|
{
|
||||||
int x = screenPos.X;
|
int x = screenPos.X;
|
||||||
int y = screenPos.Y-15+(Size.Y-thumbBoxSize.Y)/2+thumbBoxSize.Y;
|
int y = screenPos.Y-15+(Size.Y-thumbBoxSize.Y)/2+thumbBoxSize.Y;
|
||||||
g->fillrect(x+1, y+1, 7, 8, 255, 255, 255, 255);
|
g->fillrect(x+1, y+1, 7, 8, 255, 255, 255, 255);
|
||||||
if (MouseInsideHistory) {
|
if (isMouseInsideHistory) {
|
||||||
g->drawtext(x, y, "\xA6", 200, 100, 80, 255);
|
g->drawtext(x, y, "\xA6", 200, 100, 80, 255);
|
||||||
} else {
|
} else {
|
||||||
g->drawtext(x, y, "\xA6", 160, 70, 50, 255);
|
g->drawtext(x, y, "\xA6", 160, 70, 50, 255);
|
||||||
@@ -275,40 +293,63 @@ void SaveButton::OnMouseUnclick(int x, int y, unsigned int button)
|
|||||||
isButtonDown = false;
|
isButtonDown = false;
|
||||||
if(isMouseInsideAuthor)
|
if(isMouseInsideAuthor)
|
||||||
DoAuthorAction();
|
DoAuthorAction();
|
||||||
else if (MouseInsideHistory)
|
else if(isMouseInsideHistory)
|
||||||
DoHistoryAction();
|
DoHistoryAction();
|
||||||
else
|
else
|
||||||
DoAction();
|
DoAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveButton::OnMouseClick(int x, int y, unsigned int button)
|
void SaveButton::OnContextMenuAction(int item)
|
||||||
{
|
{
|
||||||
if(button !=1 && selectable)
|
switch(item)
|
||||||
{
|
{
|
||||||
|
case 0:
|
||||||
|
DoAction();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
selected = !selected;
|
selected = !selected;
|
||||||
DoSelection();
|
DoSelection();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
DoHistoryAction();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
DoAuthorAction();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if(button != 1) return; //left click only!
|
}
|
||||||
|
|
||||||
isButtonDown = true;
|
void SaveButton::OnMouseClick(int x, int y, unsigned int button)
|
||||||
|
{
|
||||||
|
if(button == BUTTON_RIGHT)
|
||||||
|
{
|
||||||
|
if(menu)
|
||||||
|
menu->Show(GetScreenPos() + ui::Point(x, y));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isButtonDown = true;
|
||||||
|
if(button !=1 && selectable)
|
||||||
|
{
|
||||||
|
selected = !selected;
|
||||||
|
DoSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveButton::OnMouseMovedInside(int x, int y, int dx, int dy)
|
void SaveButton::OnMouseMovedInside(int x, int y, int dx, int dy)
|
||||||
{
|
{
|
||||||
if(y > Size.Y-11)
|
if(y > Size.Y-11)
|
||||||
{
|
|
||||||
isMouseInsideAuthor = true;
|
isMouseInsideAuthor = true;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
isMouseInsideAuthor = false;
|
isMouseInsideAuthor = false;
|
||||||
|
|
||||||
if(showVotes && y > Size.Y-29 && y < Size.Y - 18 && x > 0 && x < 9)
|
if(showVotes && y > Size.Y-29 && y < Size.Y - 18 && x > 0 && x < 9)
|
||||||
{
|
isMouseInsideHistory = true;
|
||||||
MouseInsideHistory = true;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
MouseInsideHistory = false;
|
isMouseInsideHistory = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveButton::OnMouseEnter(int x, int y)
|
void SaveButton::OnMouseEnter(int x, int y)
|
||||||
@@ -320,7 +361,7 @@ void SaveButton::OnMouseLeave(int x, int y)
|
|||||||
{
|
{
|
||||||
isMouseInside = false;
|
isMouseInside = false;
|
||||||
isMouseInsideAuthor = false;
|
isMouseInsideAuthor = false;
|
||||||
MouseInsideHistory = false;
|
isMouseInsideHistory = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveButton::DoHistoryAction()
|
void SaveButton::DoHistoryAction()
|
||||||
@@ -343,7 +384,14 @@ void SaveButton::DoAction()
|
|||||||
|
|
||||||
void SaveButton::DoSelection()
|
void SaveButton::DoSelection()
|
||||||
{
|
{
|
||||||
if(selectable)
|
if(menu)
|
||||||
|
{
|
||||||
|
if(selected)
|
||||||
|
menu->SetItem(1, "Deselect");
|
||||||
|
else
|
||||||
|
menu->SetItem(1, "Select");
|
||||||
|
}
|
||||||
|
if(selectable && actionCallback)
|
||||||
actionCallback->SelectedCallback(this);
|
actionCallback->SelectedCallback(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,10 +30,13 @@ class SaveButton : public Component, public ThumbnailListener
|
|||||||
SaveInfo * save;
|
SaveInfo * save;
|
||||||
Thumbnail * thumbnail;
|
Thumbnail * thumbnail;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
std::string votesString;
|
||||||
|
std::string votesBackground;
|
||||||
|
std::string votesBackground2;
|
||||||
bool wantsDraw;
|
bool wantsDraw;
|
||||||
bool waitingForThumb;
|
bool waitingForThumb;
|
||||||
bool isMouseInsideAuthor;
|
bool isMouseInsideAuthor;
|
||||||
bool MouseInsideHistory;
|
bool isMouseInsideHistory;
|
||||||
bool showVotes;
|
bool showVotes;
|
||||||
public:
|
public:
|
||||||
SaveButton(Point position, Point size, SaveInfo * save);
|
SaveButton(Point position, Point size, SaveInfo * save);
|
||||||
@@ -48,6 +51,8 @@ public:
|
|||||||
|
|
||||||
virtual void OnMouseMovedInside(int x, int y, int dx, int dy);
|
virtual void OnMouseMovedInside(int x, int y, int dx, int dy);
|
||||||
|
|
||||||
|
virtual void OnContextMenuAction(int item);
|
||||||
|
|
||||||
virtual void Draw(const Point& screenPos);
|
virtual void Draw(const Point& screenPos);
|
||||||
virtual void Tick(float dt);
|
virtual void Tick(float dt);
|
||||||
|
|
||||||
|
@@ -14,6 +14,7 @@ Window::Window(Point _position, Point _size):
|
|||||||
AllowExclusiveDrawing(true),
|
AllowExclusiveDrawing(true),
|
||||||
halt(false),
|
halt(false),
|
||||||
destruct(false),
|
destruct(false),
|
||||||
|
stop(false),
|
||||||
cancelButton(NULL),
|
cancelButton(NULL),
|
||||||
okayButton(NULL)
|
okayButton(NULL)
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@@ -232,6 +233,7 @@ void Window::DoTick(float dt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
halt = false;
|
halt = false;
|
||||||
|
stop = false;
|
||||||
|
|
||||||
OnTick(dt);
|
OnTick(dt);
|
||||||
|
|
||||||
@@ -292,7 +294,8 @@ void Window::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool a
|
|||||||
focusedComponent_->OnKeyPress(key, character, shift, ctrl, alt);
|
focusedComponent_->OnKeyPress(key, character, shift, ctrl, alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnKeyPress(key, character, shift, ctrl, alt);
|
if(!stop)
|
||||||
|
OnKeyPress(key, character, shift, ctrl, alt);
|
||||||
|
|
||||||
if(key == KEY_ESCAPE)
|
if(key == KEY_ESCAPE)
|
||||||
OnTryExit(Escape);
|
OnTryExit(Escape);
|
||||||
@@ -317,7 +320,8 @@ void Window::DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool
|
|||||||
focusedComponent_->OnKeyRelease(key, character, shift, ctrl, alt);
|
focusedComponent_->OnKeyRelease(key, character, shift, ctrl, alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnKeyRelease(key, character, shift, ctrl, alt);
|
if(!stop)
|
||||||
|
OnKeyRelease(key, character, shift, ctrl, alt);
|
||||||
if(destruct)
|
if(destruct)
|
||||||
finalise();
|
finalise();
|
||||||
}
|
}
|
||||||
@@ -360,7 +364,8 @@ void Window::DoMouseDown(int x_, int y_, unsigned button)
|
|||||||
Components[i]->OnMouseDown(x, y, button);
|
Components[i]->OnMouseDown(x, y, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnMouseDown(x_, y_, button);
|
if(!stop)
|
||||||
|
OnMouseDown(x_, y_, button);
|
||||||
|
|
||||||
if(x_ < Position.X || y_ < Position.Y || x_ > Position.X+Size.X || y_ > Position.Y+Size.Y)
|
if(x_ < Position.X || y_ < Position.Y || x_ > Position.X+Size.X || y_ > Position.Y+Size.Y)
|
||||||
OnTryExit(MouseOutside);
|
OnTryExit(MouseOutside);
|
||||||
@@ -419,7 +424,8 @@ void Window::DoMouseMove(int x_, int y_, int dx, int dy)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OnMouseMove(x_, y_, dx, dy);
|
if(!stop)
|
||||||
|
OnMouseMove(x_, y_, dx, dy);
|
||||||
if(destruct)
|
if(destruct)
|
||||||
finalise();
|
finalise();
|
||||||
}
|
}
|
||||||
@@ -452,7 +458,8 @@ void Window::DoMouseUp(int x_, int y_, unsigned button)
|
|||||||
Components[i]->OnMouseUp(x, y, button);
|
Components[i]->OnMouseUp(x, y, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnMouseUp(x_, y_, button);
|
if(!stop)
|
||||||
|
OnMouseUp(x_, y_, button);
|
||||||
if(destruct)
|
if(destruct)
|
||||||
finalise();
|
finalise();
|
||||||
}
|
}
|
||||||
@@ -483,7 +490,8 @@ void Window::DoMouseWheel(int x_, int y_, int d)
|
|||||||
Components[i]->OnMouseWheel(x - Components[i]->Position.X, y - Components[i]->Position.Y, d);
|
Components[i]->OnMouseWheel(x - Components[i]->Position.X, y - Components[i]->Position.Y, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnMouseWheel(x_, y_, d);
|
if(!stop)
|
||||||
|
OnMouseWheel(x_, y_, d);
|
||||||
|
|
||||||
if(destruct)
|
if(destruct)
|
||||||
finalise();
|
finalise();
|
||||||
@@ -498,5 +506,12 @@ void Window::SelfDestruct()
|
|||||||
{
|
{
|
||||||
destruct = true;
|
destruct = true;
|
||||||
halt = true;
|
halt = true;
|
||||||
|
stop = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::Halt()
|
||||||
|
{
|
||||||
|
stop = true;
|
||||||
|
halt = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -68,6 +68,7 @@ enum ChromeStyle
|
|||||||
|
|
||||||
//Sets halt and destroy, this causes the Windows to stop sending events and remove itself.
|
//Sets halt and destroy, this causes the Windows to stop sending events and remove itself.
|
||||||
void SelfDestruct();
|
void SelfDestruct();
|
||||||
|
void Halt();
|
||||||
|
|
||||||
bool IsFocused(const Component* c) const;
|
bool IsFocused(const Component* c) const;
|
||||||
void FocusComponent(Component* c);
|
void FocusComponent(Component* c);
|
||||||
@@ -105,6 +106,7 @@ enum ChromeStyle
|
|||||||
void finalise();
|
void finalise();
|
||||||
bool halt;
|
bool halt;
|
||||||
bool destruct;
|
bool destruct;
|
||||||
|
bool stop;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
bool debugMode;
|
bool debugMode;
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user