Fix uglyness with how Favorites menu was done
This commit is contained in:
parent
fe4653c30e
commit
ae247a2d2b
@ -1,26 +1,44 @@
|
||||
#include "Favorite.h"
|
||||
#include "json/json.h"
|
||||
#include "client/Client.h"
|
||||
#include <algorithm>
|
||||
|
||||
std::vector<std::string> *favoritesList;
|
||||
|
||||
Favorite::Favorite()
|
||||
{
|
||||
favoritesList = new std::vector<std::string>();
|
||||
}
|
||||
Favorite::Favorite():
|
||||
favoritesList(std::vector<std::string>())
|
||||
{}
|
||||
|
||||
|
||||
std::vector<std::string> *Favorite::GetFavoritesList()
|
||||
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();
|
||||
return std::find(favoritesList.begin(), favoritesList.end(), identifier) != favoritesList.end();
|
||||
}
|
||||
|
||||
bool Favorite::AnyFavorites()
|
||||
{
|
||||
return favoritesList.size() == 0;
|
||||
}
|
||||
|
||||
void Favorite::AddFavorite(std::string identifier)
|
||||
{
|
||||
favoritesList.push_back(identifier);
|
||||
}
|
||||
|
||||
void Favorite::RemoveFavorite(std::string identifier)
|
||||
{
|
||||
favoritesList.erase(std::remove(favoritesList.begin(), favoritesList.end(), identifier), favoritesList.end());
|
||||
}
|
||||
|
||||
void Favorite::SaveFavoritesToPrefs()
|
||||
{
|
||||
Client::Ref().SetPref("Favorites", std::vector<Json::Value>(favoritesList.begin(), favoritesList.end()));
|
||||
}
|
||||
|
||||
void Favorite::LoadFavoritesFromPrefs()
|
||||
{
|
||||
favoritesList = Client::Ref().GetPrefStringArray("Favorites");
|
||||
}
|
||||
|
@ -6,11 +6,20 @@
|
||||
|
||||
#include "common/Singleton.h"
|
||||
|
||||
class Favorite : public Singleton<Favorite> {
|
||||
class Favorite : public Singleton<Favorite>
|
||||
{
|
||||
std::vector<std::string> favoritesList;
|
||||
public:
|
||||
Favorite();
|
||||
std::vector<std::string> * GetFavoritesList();
|
||||
void SetFavoritesList(std::vector<std::string> favoritesList);
|
||||
|
||||
std::vector<std::string> GetFavoritesList();
|
||||
bool IsFavorite(std::string identifier);
|
||||
bool AnyFavorites();
|
||||
|
||||
void AddFavorite(std::string identifier);
|
||||
void RemoveFavorite(std::string identifier);
|
||||
|
||||
void SaveFavoritesToPrefs();
|
||||
void LoadFavoritesFromPrefs();
|
||||
};
|
||||
#endif //FAVORITE_H
|
||||
|
@ -82,10 +82,7 @@ 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);
|
||||
Favorite::Ref().LoadFavoritesFromPrefs();
|
||||
|
||||
//Load last user
|
||||
if(Client::Ref().GetAuthUser().ID)
|
||||
@ -162,7 +159,7 @@ 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()));
|
||||
Favorite::Ref().SaveFavoritesToPrefs();
|
||||
|
||||
for (size_t i = 0; i < menuList.size(); i++)
|
||||
{
|
||||
@ -374,7 +371,7 @@ void GameModel::BuildFavoritesMenu()
|
||||
{
|
||||
menuList[SC_FAVORITES]->ClearTools();
|
||||
|
||||
for (size_t i = 0; i < menuList.size(); i++)
|
||||
/*for (size_t i = 0; i < menuList.size(); i++)
|
||||
{
|
||||
if (i == SC_FAVORITES)
|
||||
continue;
|
||||
@ -387,6 +384,21 @@ void GameModel::BuildFavoritesMenu()
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < extraElementTools.size(); i++)
|
||||
{
|
||||
if (Favorite::Ref().IsFavorite(extraElementTools[i]->GetIdentifier()))
|
||||
{
|
||||
menuList[SC_FAVORITES]->AddTool(extraElementTools[i]);
|
||||
}
|
||||
}*/
|
||||
|
||||
std::vector<std::string> favList = Favorite::Ref().GetFavoritesList();
|
||||
for (size_t i = 0; i < favList.size(); i++)
|
||||
{
|
||||
Tool *tool = GetToolFromIdentifier(favList[i]);
|
||||
if (tool)
|
||||
menuList[SC_FAVORITES]->AddTool(tool);
|
||||
}
|
||||
|
||||
if (activeMenu == SC_FAVORITES)
|
||||
toolList = menuList[SC_FAVORITES]->GetToolList();
|
||||
|
@ -542,12 +542,9 @@ public:
|
||||
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());
|
||||
}
|
||||
Favorite::Ref().RemoveFavorite(tool->GetIdentifier());
|
||||
else if (sender->GetSelectionState() == 0)
|
||||
Favorite::Ref().GetFavoritesList()->push_back(tool->GetIdentifier());
|
||||
Favorite::Ref().AddFavorite(tool->GetIdentifier());
|
||||
else if (sender->GetSelectionState() == 2)
|
||||
v->c->SetActiveMenu(SC_FAVORITES);
|
||||
|
||||
@ -613,7 +610,7 @@ void GameView::NotifyMenuListChanged(GameModel * sender)
|
||||
std::string tempString = "";
|
||||
tempString += menuList[i]->GetIcon();
|
||||
std::string description = menuList[i]->GetDescription();
|
||||
if (i == SC_FAVORITES && Favorite::Ref().GetFavoritesList()->size() == 0)
|
||||
if (i == SC_FAVORITES && Favorite::Ref().AnyFavorites())
|
||||
description += " (Use ctrl+shift+click to favorite an element)";
|
||||
ui::Button * tempButton = new ui::Button(ui::Point(WINDOWW-16, currentY), ui::Point(15, 15), tempString, description);
|
||||
tempButton->Appearance.Margin = ui::Border(0, 2, 3, 2);
|
||||
|
Reference in New Issue
Block a user