fix tpt.selectedl not changing sometimes when using the element search or sample tool. Assume that new saves will get the auto-vote, so set that too.

This commit is contained in:
jacob1 2013-06-08 00:23:06 -04:00
parent 69961956bf
commit a1f9da2d0c
5 changed files with 24 additions and 20 deletions

View File

@ -5,7 +5,7 @@
#include "gui/interface/Keys.h" #include "gui/interface/Keys.h"
#include "gui/game/Tool.h" #include "gui/game/Tool.h"
#include "gui/Style.h" #include "gui/Style.h"
#include "gui/game/GameModel.h" #include "gui/game/GameController.h"
class ElementSearchActivity::ToolAction: public ui::ButtonAction class ElementSearchActivity::ToolAction: public ui::ButtonAction
{ {
@ -21,9 +21,9 @@ public:
} }
}; };
ElementSearchActivity::ElementSearchActivity(GameModel * gameModel, std::vector<Tool*> tools) : ElementSearchActivity::ElementSearchActivity(GameController * gameController, std::vector<Tool*> tools) :
WindowActivity(ui::Point(-1, -1), ui::Point(236, 302)), WindowActivity(ui::Point(-1, -1), ui::Point(236, 302)),
gameModel(gameModel), gameController(gameController),
tools(tools), tools(tools),
firstResult(NULL) firstResult(NULL)
{ {
@ -121,15 +121,15 @@ void ElementSearchActivity::searchTools(std::string query)
tempButton->Appearance.BackgroundInactive = ui::Colour(tool->colRed, tool->colGreen, tool->colBlue); tempButton->Appearance.BackgroundInactive = ui::Colour(tool->colRed, tool->colGreen, tool->colBlue);
tempButton->SetActionCallback(new ToolAction(this, tool)); tempButton->SetActionCallback(new ToolAction(this, tool));
if(gameModel->GetActiveTool(0) == tool) if(gameController->GetActiveTool(0) == tool)
{ {
tempButton->SetSelectionState(0); //Primary tempButton->SetSelectionState(0); //Primary
} }
else if(gameModel->GetActiveTool(1) == tool) else if(gameController->GetActiveTool(1) == tool)
{ {
tempButton->SetSelectionState(1); //Secondary tempButton->SetSelectionState(1); //Secondary
} }
else if(gameModel->GetActiveTool(2) == tool) else if(gameController->GetActiveTool(2) == tool)
{ {
tempButton->SetSelectionState(2); //Tertiary tempButton->SetSelectionState(2); //Tertiary
} }
@ -152,7 +152,7 @@ void ElementSearchActivity::searchTools(std::string query)
void ElementSearchActivity::SetActiveTool(int selectionState, Tool * tool) void ElementSearchActivity::SetActiveTool(int selectionState, Tool * tool)
{ {
gameModel->SetActiveTool(selectionState, tool); gameController->SetActiveTool(selectionState, tool);
Exit(); Exit();
} }
@ -170,7 +170,7 @@ void ElementSearchActivity::OnKeyPress(int key, Uint16 character, bool shift, bo
if(key == KEY_ENTER || key == KEY_RETURN) if(key == KEY_ENTER || key == KEY_RETURN)
{ {
if(firstResult) if(firstResult)
gameModel->SetActiveTool(0, firstResult); gameController->SetActiveTool(0, firstResult);
Exit(); Exit();
} }
if(key == KEY_ESCAPE) if(key == KEY_ESCAPE)

View File

@ -10,11 +10,11 @@
class Tool; class Tool;
class GameModel; class GameController;
class ElementSearchActivity: public WindowActivity { class ElementSearchActivity: public WindowActivity {
Tool * firstResult; Tool * firstResult;
GameModel * gameModel; GameController * gameController;
std::vector<Tool*> tools; std::vector<Tool*> tools;
ui::Textbox * searchField; ui::Textbox * searchField;
std::vector<ToolButton*> toolButtons; std::vector<ToolButton*> toolButtons;
@ -22,7 +22,7 @@ class ElementSearchActivity: public WindowActivity {
public: public:
class ToolAction; class ToolAction;
Tool * GetFirstResult() { return firstResult; } Tool * GetFirstResult() { return firstResult; }
ElementSearchActivity(GameModel * gameModel, std::vector<Tool*> tools); ElementSearchActivity(GameController * gameController, std::vector<Tool*> tools);
void SetActiveTool(int selectionState, Tool * tool); void SetActiveTool(int selectionState, Tool * tool);
virtual ~ElementSearchActivity(); virtual ~ElementSearchActivity();
virtual void OnDraw(); virtual void OnDraw();

View File

@ -965,12 +965,7 @@ void GameController::SetActiveMenu(int menuID)
if(menuID == SC_DECO) if(menuID == SC_DECO)
gameModel->SetColourSelectorVisibility(true); gameModel->SetColourSelectorVisibility(true);
else else
{
gameModel->SetColourSelectorVisibility(false); gameModel->SetColourSelectorVisibility(false);
ActiveToolChanged(0, gameModel->GetActiveTool(0));
ActiveToolChanged(1, gameModel->GetActiveTool(1));
ActiveToolChanged(2, gameModel->GetActiveTool(2));
}
} }
std::vector<Menu*> GameController::GetMenuList() std::vector<Menu*> GameController::GetMenuList()
@ -983,6 +978,11 @@ void GameController::ActiveToolChanged(int toolSelection, Tool *tool)
commandInterface->OnActiveToolChanged(toolSelection, tool); commandInterface->OnActiveToolChanged(toolSelection, tool);
} }
Tool * GameController::GetActiveTool(int selection)
{
return gameModel->GetActiveTool(selection);
}
void GameController::SetActiveTool(int toolSelection, Tool * tool) void GameController::SetActiveTool(int toolSelection, Tool * tool)
{ {
gameModel->SetActiveTool(toolSelection, tool); gameModel->SetActiveTool(toolSelection, tool);
@ -1126,7 +1126,7 @@ void GameController::OpenElementSearch()
} }
vector<Tool*> hiddenTools = gameModel->GetUnlistedTools(); vector<Tool*> hiddenTools = gameModel->GetUnlistedTools();
toolList.insert(toolList.end(), hiddenTools.begin(), hiddenTools.end()); toolList.insert(toolList.end(), hiddenTools.begin(), hiddenTools.end());
new ElementSearchActivity(gameModel, toolList); new ElementSearchActivity(this, toolList);
} }
void GameController::OpenColourPicker() void GameController::OpenColourPicker()
@ -1210,6 +1210,8 @@ void GameController::OpenSaveWindow()
virtual ~SaveUploadedCallback() {}; virtual ~SaveUploadedCallback() {};
virtual void SaveUploaded(SaveInfo save) virtual void SaveUploaded(SaveInfo save)
{ {
save.SetVote(1);
save.SetVotesUp(1);
c->LoadSave(&save); c->LoadSave(&save);
} }
}; };

View File

@ -100,6 +100,7 @@ public:
bool GetDebugHUD(); bool GetDebugHUD();
void SetActiveMenu(int menuID); void SetActiveMenu(int menuID);
std::vector<Menu*> GetMenuList(); std::vector<Menu*> GetMenuList();
Tool * GetActiveTool(int selection);
void SetActiveTool(int toolSelection, Tool * tool); void SetActiveTool(int toolSelection, Tool * tool);
void ActiveToolChanged(int toolSelection, Tool *tool); void ActiveToolChanged(int toolSelection, Tool *tool);
void SetActiveColourPreset(int preset); void SetActiveColourPreset(int preset);

View File

@ -617,7 +617,6 @@ void GameView::NotifyActiveToolsChanged(GameModel * sender)
if(sender->GetActiveTool(0) == tool) if(sender->GetActiveTool(0) == tool)
{ {
toolButtons[i]->SetSelectionState(0); //Primary toolButtons[i]->SetSelectionState(0); //Primary
c->ActiveToolChanged(0, tool);
if (tool->GetIdentifier().find("DEFAULT_UI_WIND") != tool->GetIdentifier().npos) if (tool->GetIdentifier().find("DEFAULT_UI_WIND") != tool->GetIdentifier().npos)
windTool = true; windTool = true;
else else
@ -626,18 +625,20 @@ void GameView::NotifyActiveToolsChanged(GameModel * sender)
else if(sender->GetActiveTool(1) == tool) else if(sender->GetActiveTool(1) == tool)
{ {
toolButtons[i]->SetSelectionState(1); //Secondary toolButtons[i]->SetSelectionState(1); //Secondary
c->ActiveToolChanged(1, tool);
} }
else if(sender->GetActiveTool(2) == tool) else if(sender->GetActiveTool(2) == tool)
{ {
toolButtons[i]->SetSelectionState(2); //Tertiary toolButtons[i]->SetSelectionState(2); //Tertiary
c->ActiveToolChanged(2, tool);
} }
else else
{ {
toolButtons[i]->SetSelectionState(-1); toolButtons[i]->SetSelectionState(-1);
} }
} }
//need to do this for all tools every time just in case it wasn't caught if you weren't in the menu a tool was changed to
c->ActiveToolChanged(0, sender->GetActiveTool(0));
c->ActiveToolChanged(1, sender->GetActiveTool(1));
c->ActiveToolChanged(2, sender->GetActiveTool(2));
} }
void GameView::NotifyLastToolChanged(GameModel * sender) void GameView::NotifyLastToolChanged(GameModel * sender)