Permalink
Browse files

Added a favorites menu. (#298)

Added a favorites menu.
  • Loading branch information...
me4502 authored and jacob1 committed Jun 25, 2016
1 parent 9a18338 commit 083d4885660919585408a509cd8234e8565c000a
@@ -129,9 +129,9 @@ void ElementSearchActivity::searchTools(std::string query)
ToolButton * tempButton;
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
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.BackgroundInactive = ui::Colour(tool->colRed, tool->colGreen, tool->colBlue);
@@ -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();
}
@@ -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();
}
void GameController::RebuildFavoritesMenu()
{
gameModel->BuildFavoritesMenu();
}
void GameController::ActiveToolChanged(int toolSelection, Tool *tool)
{
commandInterface->OnActiveToolChanged(toolSelection, tool);
@@ -103,6 +103,7 @@ class GameController: public ClientListener
void SetDebugFlags(unsigned int flags) { debugFlags = flags; }
void SetActiveMenu(int menuID);
std::vector<Menu*> GetMenuList();
void RebuildFavoritesMenu();
Tool * GetActiveTool(int selection);
void SetActiveTool(int toolSelection, Tool * tool);
void SetLastTool(Tool * tool);
@@ -17,6 +17,7 @@
#include "QuickOptions.h"
#include "GameModelException.h"
#include "Format.h"
#include "Favorite.h"
GameModel::GameModel():
clipboard(NULL),
@@ -81,6 +82,11 @@ GameModel::GameModel():
sim->aheat_enable = Client::Ref().GetPrefInteger("Simulation.AmbientHeat", 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
if(Client::Ref().GetAuthUser().ID)
{
@@ -156,6 +162,8 @@ GameModel::~GameModel()
Client::Ref().SetPref("Decoration.Blue", (int)colour.Blue);
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++)
{
delete menuList[i];
@@ -353,6 +361,36 @@ void GameModel::BuildMenus()
notifyToolListChanged();
notifyActiveToolsChanged();
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)
@@ -125,6 +125,7 @@ class GameModel
std::string GetInfoTip();
void BuildMenus();
void BuildFavoritesMenu();
void BuildQuickOptionMenu(GameController * controller);
std::deque<Snapshot*> GetHistory();
@@ -1,5 +1,6 @@
#include <sstream>
#include <iomanip>
#include <algorithm>
#include "Config.h"
#include "gui/Style.h"
@@ -19,6 +20,7 @@
#include "QuickOptions.h"
#include "IntroText.h"
#include "DecorationTool.h"
#include "Favorite.h"
class SplitButton;
@@ -536,11 +538,27 @@ class GameView::ToolAction: public ui::ButtonAction
void ActionCallback(ui::Button * sender_)
{
ToolButton *sender = (ToolButton*)sender_;
if (v->CtrlBehaviour() && v->AltBehaviour() && !v->ShiftBehaviour())
if (tool->GetIdentifier().find("DEFAULT_PT_") != tool->GetIdentifier().npos)
sender->SetSelectionState(3);
if(sender->GetSelectionState() >= 0 && sender->GetSelectionState() <= 3)
v->c->SetActiveTool(sender->GetSelectionState(), tool);
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 (tool->GetIdentifier().find("DEFAULT_PT_") != tool->GetIdentifier().npos)
sender->SetSelectionState(3);
if (sender->GetSelectionState() >= 0 && sender->GetSelectionState() <= 3)
v->c->SetActiveTool(sender->GetSelectionState(), tool);
}
}
};
@@ -740,9 +758,9 @@ void GameView::NotifyToolListChanged(GameModel * sender)
tempTexture = ((DecorationTool*)toolList[i])->GetIcon(toolList[i]->GetToolID(), 26, 14);
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
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;
currentX -= 31;
@@ -832,7 +850,7 @@ void GameView::NotifyColourPresetsChanged(GameModel * sender)
int i = 0;
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->SetActionCallback(new ColourPresetAction(this, i));
@@ -45,6 +45,11 @@ class Menu
{
tools.push_back(tool_);
}
void ClearTools()
{
tools.clear();
}
};
@@ -1,11 +1,14 @@
#include "ToolButton.h"
#include "gui/interface/Keys.h"
#include "Favorite.h"
ToolButton::ToolButton(ui::Point position, ui::Point size, std::string text_, std::string toolTip):
ui::Button(position, size, text_, toolTip)
ToolButton::ToolButton(ui::Point position, ui::Point size, std::string text_, std::string toolIdentifier, std::string toolTip):
ui::Button(position, size, text_, toolTip),
toolIdentifier(toolIdentifier)
{
SetSelectionState(-1);
Appearance.BorderActive = ui::Colour(255, 0, 0);
Appearance.BorderFavorite = ui::Colour(255, 255, 0);
//don't use "..." on elements that have long names
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);
}
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
{
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
{
int currentSelection;
std::string toolIdentifier;
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 OnMouseUp(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 BorderInactive;
ui::Colour BorderActive;
ui::Colour BorderFavorite;
ui::Colour BorderDisabled;
ui::Border Margin;
@@ -158,6 +158,7 @@ menu_section * LoadMenus(int & menuCount)
{"\xD2", "Game Of Life", 0, 1},
{"\xD7", "Tools", 0, 1},
{"\xE4", "Decoration tools", 0, 1},
{"\xCC", "Favorites", 0, 1},
{"\xC8", "Cracker", 0, 0},
{"\xC8", "Cracker!", 0, 0},
};
@@ -15,9 +15,10 @@
#define SC_LIFE 12
#define SC_TOOL 13
#define SC_DECO 14
#define SC_CRACKER 15
#define SC_CRACKER2 16
#define SC_TOTAL 15
#define SC_FAVORITES 15
#define SC_CRACKER 16
#define SC_CRACKER2 17
#define SC_TOTAL 16
#define O_WL_WALLELEC 122
#define O_WL_EWALL 123

0 comments on commit 083d488

Please sign in to comment.