mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-28 10:20:04 +02:00
@@ -129,9 +129,9 @@ void ElementSearchActivity::searchTools(std::string query)
|
|||||||
ToolButton * tempButton;
|
ToolButton * tempButton;
|
||||||
|
|
||||||
if(tempTexture)
|
if(tempTexture)
|
||||||
tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), "", tool->GetDescription());
|
tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), "", tool->GetIdentifier(), tool->GetDescription());
|
||||||
else
|
else
|
||||||
tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), tool->GetName(), tool->GetDescription());
|
tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), tool->GetName(), tool->GetIdentifier(), tool->GetDescription());
|
||||||
|
|
||||||
tempButton->Appearance.SetTexture(tempTexture);
|
tempButton->Appearance.SetTexture(tempTexture);
|
||||||
tempButton->Appearance.BackgroundInactive = ui::Colour(tool->colRed, tool->colGreen, tool->colBlue);
|
tempButton->Appearance.BackgroundInactive = ui::Colour(tool->colRed, tool->colGreen, tool->colBlue);
|
||||||
|
26
src/gui/game/Favorite.cpp
Normal file
26
src/gui/game/Favorite.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "Favorite.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
std::vector<std::string> *favoritesList;
|
||||||
|
|
||||||
|
Favorite::Favorite()
|
||||||
|
{
|
||||||
|
favoritesList = new std::vector<std::string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<std::string> *Favorite::GetFavoritesList()
|
||||||
|
{
|
||||||
|
return favoritesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Favorite::SetFavoritesList(std::vector<std::string> newFavoritesList)
|
||||||
|
{
|
||||||
|
*favoritesList = newFavoritesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Favorite::IsFavorite(std::string identifier)
|
||||||
|
{
|
||||||
|
std::vector<std::string> tempFavoritsList = *favoritesList;
|
||||||
|
return std::find(tempFavoritsList.begin(), tempFavoritsList.end(), identifier) != tempFavoritsList.end();
|
||||||
|
}
|
16
src/gui/game/Favorite.h
Normal file
16
src/gui/game/Favorite.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef FAVORITE_H
|
||||||
|
#define FAVORITE_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "common/Singleton.h"
|
||||||
|
|
||||||
|
class Favorite : public Singleton<Favorite> {
|
||||||
|
public:
|
||||||
|
Favorite();
|
||||||
|
std::vector<std::string> * GetFavoritesList();
|
||||||
|
void SetFavoritesList(std::vector<std::string> favoritesList);
|
||||||
|
bool IsFavorite(std::string identifier);
|
||||||
|
};
|
||||||
|
#endif //FAVORITE_H
|
@@ -1045,6 +1045,11 @@ std::vector<Menu*> GameController::GetMenuList()
|
|||||||
return gameModel->GetMenuList();
|
return gameModel->GetMenuList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameController::RebuildFavoritesMenu()
|
||||||
|
{
|
||||||
|
gameModel->BuildFavoritesMenu();
|
||||||
|
}
|
||||||
|
|
||||||
void GameController::ActiveToolChanged(int toolSelection, Tool *tool)
|
void GameController::ActiveToolChanged(int toolSelection, Tool *tool)
|
||||||
{
|
{
|
||||||
commandInterface->OnActiveToolChanged(toolSelection, tool);
|
commandInterface->OnActiveToolChanged(toolSelection, tool);
|
||||||
|
@@ -103,6 +103,7 @@ public:
|
|||||||
void SetDebugFlags(unsigned int flags) { debugFlags = flags; }
|
void SetDebugFlags(unsigned int flags) { debugFlags = flags; }
|
||||||
void SetActiveMenu(int menuID);
|
void SetActiveMenu(int menuID);
|
||||||
std::vector<Menu*> GetMenuList();
|
std::vector<Menu*> GetMenuList();
|
||||||
|
void RebuildFavoritesMenu();
|
||||||
Tool * GetActiveTool(int selection);
|
Tool * GetActiveTool(int selection);
|
||||||
void SetActiveTool(int toolSelection, Tool * tool);
|
void SetActiveTool(int toolSelection, Tool * tool);
|
||||||
void SetLastTool(Tool * tool);
|
void SetLastTool(Tool * tool);
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#include "QuickOptions.h"
|
#include "QuickOptions.h"
|
||||||
#include "GameModelException.h"
|
#include "GameModelException.h"
|
||||||
#include "Format.h"
|
#include "Format.h"
|
||||||
|
#include "Favorite.h"
|
||||||
|
|
||||||
GameModel::GameModel():
|
GameModel::GameModel():
|
||||||
clipboard(NULL),
|
clipboard(NULL),
|
||||||
@@ -81,6 +82,11 @@ GameModel::GameModel():
|
|||||||
sim->aheat_enable = Client::Ref().GetPrefInteger("Simulation.AmbientHeat", 0);
|
sim->aheat_enable = Client::Ref().GetPrefInteger("Simulation.AmbientHeat", 0);
|
||||||
sim->pretty_powder = Client::Ref().GetPrefInteger("Simulation.PrettyPowder", 0);
|
sim->pretty_powder = Client::Ref().GetPrefInteger("Simulation.PrettyPowder", 0);
|
||||||
|
|
||||||
|
//Load favorites
|
||||||
|
std::vector<std::string> favoritesList = Client::Ref().GetPrefStringArray("Favorites");
|
||||||
|
|
||||||
|
Favorite::Ref().SetFavoritesList(favoritesList);
|
||||||
|
|
||||||
//Load last user
|
//Load last user
|
||||||
if(Client::Ref().GetAuthUser().ID)
|
if(Client::Ref().GetAuthUser().ID)
|
||||||
{
|
{
|
||||||
@@ -156,6 +162,8 @@ GameModel::~GameModel()
|
|||||||
Client::Ref().SetPref("Decoration.Blue", (int)colour.Blue);
|
Client::Ref().SetPref("Decoration.Blue", (int)colour.Blue);
|
||||||
Client::Ref().SetPref("Decoration.Alpha", (int)colour.Alpha);
|
Client::Ref().SetPref("Decoration.Alpha", (int)colour.Alpha);
|
||||||
|
|
||||||
|
Client::Ref().SetPref("Favorites", std::vector<Json::Value>(Favorite::Ref().GetFavoritesList()->begin(), Favorite::Ref().GetFavoritesList()->end()));
|
||||||
|
|
||||||
for (size_t i = 0; i < menuList.size(); i++)
|
for (size_t i = 0; i < menuList.size(); i++)
|
||||||
{
|
{
|
||||||
delete menuList[i];
|
delete menuList[i];
|
||||||
@@ -353,6 +361,36 @@ void GameModel::BuildMenus()
|
|||||||
notifyToolListChanged();
|
notifyToolListChanged();
|
||||||
notifyActiveToolsChanged();
|
notifyActiveToolsChanged();
|
||||||
notifyLastToolChanged();
|
notifyLastToolChanged();
|
||||||
|
|
||||||
|
//Build menu for favorites
|
||||||
|
BuildFavoritesMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameModel::BuildFavoritesMenu()
|
||||||
|
{
|
||||||
|
menuList[SC_FAVORITES]->ClearTools();
|
||||||
|
|
||||||
|
for (int i = 0; i < menuList.size(); i++)
|
||||||
|
{
|
||||||
|
if (i == SC_FAVORITES)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (int j = 0; j < menuList[i]->GetToolList().size(); j++)
|
||||||
|
{
|
||||||
|
if (Favorite::Ref().IsFavorite(menuList[i]->GetToolList()[j]->GetIdentifier()))
|
||||||
|
{
|
||||||
|
menuList[SC_FAVORITES]->AddTool(menuList[i]->GetToolList()[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activeMenu == SC_FAVORITES)
|
||||||
|
toolList = menuList[SC_FAVORITES]->GetToolList();
|
||||||
|
|
||||||
|
notifyMenuListChanged();
|
||||||
|
notifyToolListChanged();
|
||||||
|
notifyActiveToolsChanged();
|
||||||
|
notifyLastToolChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
Tool * GameModel::GetToolFromIdentifier(std::string identifier)
|
Tool * GameModel::GetToolFromIdentifier(std::string identifier)
|
||||||
|
@@ -125,6 +125,7 @@ public:
|
|||||||
std::string GetInfoTip();
|
std::string GetInfoTip();
|
||||||
|
|
||||||
void BuildMenus();
|
void BuildMenus();
|
||||||
|
void BuildFavoritesMenu();
|
||||||
void BuildQuickOptionMenu(GameController * controller);
|
void BuildQuickOptionMenu(GameController * controller);
|
||||||
|
|
||||||
std::deque<Snapshot*> GetHistory();
|
std::deque<Snapshot*> GetHistory();
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "gui/Style.h"
|
#include "gui/Style.h"
|
||||||
@@ -19,6 +20,7 @@
|
|||||||
#include "QuickOptions.h"
|
#include "QuickOptions.h"
|
||||||
#include "IntroText.h"
|
#include "IntroText.h"
|
||||||
#include "DecorationTool.h"
|
#include "DecorationTool.h"
|
||||||
|
#include "Favorite.h"
|
||||||
|
|
||||||
|
|
||||||
class SplitButton;
|
class SplitButton;
|
||||||
@@ -536,12 +538,28 @@ public:
|
|||||||
void ActionCallback(ui::Button * sender_)
|
void ActionCallback(ui::Button * sender_)
|
||||||
{
|
{
|
||||||
ToolButton *sender = (ToolButton*)sender_;
|
ToolButton *sender = (ToolButton*)sender_;
|
||||||
|
if (v->ShiftBehaviour() && !v->CtrlBehaviour() && !v->AltBehaviour())
|
||||||
|
{
|
||||||
|
if (Favorite::Ref().IsFavorite(tool->GetIdentifier()) && sender->GetSelectionState() == 1)
|
||||||
|
Favorite::Ref().GetFavoritesList()->erase(std::remove(Favorite::Ref().GetFavoritesList()->begin(), Favorite::Ref().GetFavoritesList()->end(),
|
||||||
|
tool->GetIdentifier()), Favorite::Ref().GetFavoritesList()->end());
|
||||||
|
else if (sender->GetSelectionState() == 0)
|
||||||
|
Favorite::Ref().GetFavoritesList()->push_back(tool->GetIdentifier());
|
||||||
|
else if (sender->GetSelectionState() == 2)
|
||||||
|
v->c->SetActiveMenu(SC_FAVORITES);
|
||||||
|
|
||||||
|
v->c->RebuildFavoritesMenu();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (v->CtrlBehaviour() && v->AltBehaviour() && !v->ShiftBehaviour())
|
if (v->CtrlBehaviour() && v->AltBehaviour() && !v->ShiftBehaviour())
|
||||||
if (tool->GetIdentifier().find("DEFAULT_PT_") != tool->GetIdentifier().npos)
|
if (tool->GetIdentifier().find("DEFAULT_PT_") != tool->GetIdentifier().npos)
|
||||||
sender->SetSelectionState(3);
|
sender->SetSelectionState(3);
|
||||||
if(sender->GetSelectionState() >= 0 && sender->GetSelectionState() <= 3)
|
|
||||||
|
if (sender->GetSelectionState() >= 0 && sender->GetSelectionState() <= 3)
|
||||||
v->c->SetActiveTool(sender->GetSelectionState(), tool);
|
v->c->SetActiveTool(sender->GetSelectionState(), tool);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void GameView::NotifyQuickOptionsChanged(GameModel * sender)
|
void GameView::NotifyQuickOptionsChanged(GameModel * sender)
|
||||||
@@ -740,9 +758,9 @@ void GameView::NotifyToolListChanged(GameModel * sender)
|
|||||||
tempTexture = ((DecorationTool*)toolList[i])->GetIcon(toolList[i]->GetToolID(), 26, 14);
|
tempTexture = ((DecorationTool*)toolList[i])->GetIcon(toolList[i]->GetToolID(), 26, 14);
|
||||||
|
|
||||||
if(tempTexture)
|
if(tempTexture)
|
||||||
tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), "", toolList[i]->GetDescription());
|
tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), "", toolList[i]->GetIdentifier(), toolList[i]->GetDescription());
|
||||||
else
|
else
|
||||||
tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), toolList[i]->GetName(), toolList[i]->GetDescription());
|
tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), toolList[i]->GetName(), toolList[i]->GetIdentifier(), toolList[i]->GetDescription());
|
||||||
|
|
||||||
//currentY -= 17;
|
//currentY -= 17;
|
||||||
currentX -= 31;
|
currentX -= 31;
|
||||||
@@ -832,7 +850,7 @@ void GameView::NotifyColourPresetsChanged(GameModel * sender)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for(std::vector<ui::Colour>::iterator iter = colours.begin(), end = colours.end(); iter != end; ++iter)
|
for(std::vector<ui::Colour>::iterator iter = colours.begin(), end = colours.end(); iter != end; ++iter)
|
||||||
{
|
{
|
||||||
ToolButton * tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), "", "Decoration Presets.");
|
ToolButton * tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), "", "", "Decoration Presets.");
|
||||||
tempButton->Appearance.BackgroundInactive = *iter;
|
tempButton->Appearance.BackgroundInactive = *iter;
|
||||||
tempButton->SetActionCallback(new ColourPresetAction(this, i));
|
tempButton->SetActionCallback(new ColourPresetAction(this, i));
|
||||||
|
|
||||||
|
@@ -45,6 +45,11 @@ public:
|
|||||||
{
|
{
|
||||||
tools.push_back(tool_);
|
tools.push_back(tool_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClearTools()
|
||||||
|
{
|
||||||
|
tools.clear();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,11 +1,14 @@
|
|||||||
#include "ToolButton.h"
|
#include "ToolButton.h"
|
||||||
#include "gui/interface/Keys.h"
|
#include "gui/interface/Keys.h"
|
||||||
|
#include "Favorite.h"
|
||||||
|
|
||||||
ToolButton::ToolButton(ui::Point position, ui::Point size, std::string text_, std::string toolTip):
|
ToolButton::ToolButton(ui::Point position, ui::Point size, std::string text_, std::string toolIdentifier, std::string toolTip):
|
||||||
ui::Button(position, size, text_, toolTip)
|
ui::Button(position, size, text_, toolTip),
|
||||||
|
toolIdentifier(toolIdentifier)
|
||||||
{
|
{
|
||||||
SetSelectionState(-1);
|
SetSelectionState(-1);
|
||||||
Appearance.BorderActive = ui::Colour(255, 0, 0);
|
Appearance.BorderActive = ui::Colour(255, 0, 0);
|
||||||
|
Appearance.BorderFavorite = ui::Colour(255, 255, 0);
|
||||||
|
|
||||||
//don't use "..." on elements that have long names
|
//don't use "..." on elements that have long names
|
||||||
buttonDisplayText = ButtonText.substr(0, 7);
|
buttonDisplayText = ButtonText.substr(0, 7);
|
||||||
@@ -56,6 +59,10 @@ void ToolButton::Draw(const ui::Point& screenPos)
|
|||||||
{
|
{
|
||||||
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, Appearance.BorderActive.Red, Appearance.BorderActive.Green, Appearance.BorderActive.Blue, Appearance.BorderActive.Alpha);
|
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, Appearance.BorderActive.Red, Appearance.BorderActive.Green, Appearance.BorderActive.Blue, Appearance.BorderActive.Alpha);
|
||||||
}
|
}
|
||||||
|
else if (Favorite::Ref().IsFavorite(toolIdentifier) && currentSelection == -1)
|
||||||
|
{
|
||||||
|
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, Appearance.BorderFavorite.Red, Appearance.BorderFavorite.Green, Appearance.BorderFavorite.Blue, Appearance.BorderFavorite.Alpha);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, Appearance.BorderInactive.Red, Appearance.BorderInactive.Green, Appearance.BorderInactive.Blue, Appearance.BorderInactive.Alpha);
|
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, Appearance.BorderInactive.Red, Appearance.BorderInactive.Green, Appearance.BorderInactive.Blue, Appearance.BorderInactive.Alpha);
|
||||||
|
@@ -6,8 +6,9 @@
|
|||||||
class ToolButton: public ui::Button
|
class ToolButton: public ui::Button
|
||||||
{
|
{
|
||||||
int currentSelection;
|
int currentSelection;
|
||||||
|
std::string toolIdentifier;
|
||||||
public:
|
public:
|
||||||
ToolButton(ui::Point position, ui::Point size, std::string text_, std::string toolTip = "");
|
ToolButton(ui::Point position, ui::Point size, std::string text_, std::string toolIdentifier, std::string toolTip = "");
|
||||||
virtual void OnMouseUnclick(int x, int y, unsigned int button);
|
virtual void OnMouseUnclick(int x, int y, unsigned int button);
|
||||||
virtual void OnMouseUp(int x, int y, unsigned int button);
|
virtual void OnMouseUp(int x, int y, unsigned int button);
|
||||||
virtual void OnMouseClick(int x, int y, unsigned int button);
|
virtual void OnMouseClick(int x, int y, unsigned int button);
|
||||||
|
@@ -38,6 +38,7 @@ namespace ui
|
|||||||
ui::Colour BorderHover;
|
ui::Colour BorderHover;
|
||||||
ui::Colour BorderInactive;
|
ui::Colour BorderInactive;
|
||||||
ui::Colour BorderActive;
|
ui::Colour BorderActive;
|
||||||
|
ui::Colour BorderFavorite;
|
||||||
ui::Colour BorderDisabled;
|
ui::Colour BorderDisabled;
|
||||||
|
|
||||||
ui::Border Margin;
|
ui::Border Margin;
|
||||||
|
@@ -158,6 +158,7 @@ menu_section * LoadMenus(int & menuCount)
|
|||||||
{"\xD2", "Game Of Life", 0, 1},
|
{"\xD2", "Game Of Life", 0, 1},
|
||||||
{"\xD7", "Tools", 0, 1},
|
{"\xD7", "Tools", 0, 1},
|
||||||
{"\xE4", "Decoration tools", 0, 1},
|
{"\xE4", "Decoration tools", 0, 1},
|
||||||
|
{"\xCC", "Favorites", 0, 1},
|
||||||
{"\xC8", "Cracker", 0, 0},
|
{"\xC8", "Cracker", 0, 0},
|
||||||
{"\xC8", "Cracker!", 0, 0},
|
{"\xC8", "Cracker!", 0, 0},
|
||||||
};
|
};
|
||||||
|
@@ -15,9 +15,10 @@
|
|||||||
#define SC_LIFE 12
|
#define SC_LIFE 12
|
||||||
#define SC_TOOL 13
|
#define SC_TOOL 13
|
||||||
#define SC_DECO 14
|
#define SC_DECO 14
|
||||||
#define SC_CRACKER 15
|
#define SC_FAVORITES 15
|
||||||
#define SC_CRACKER2 16
|
#define SC_CRACKER 16
|
||||||
#define SC_TOTAL 15
|
#define SC_CRACKER2 17
|
||||||
|
#define SC_TOTAL 16
|
||||||
|
|
||||||
#define O_WL_WALLELEC 122
|
#define O_WL_WALLELEC 122
|
||||||
#define O_WL_EWALL 123
|
#define O_WL_EWALL 123
|
||||||
|
Reference in New Issue
Block a user