From 8efe8853defa84525bde5d03febc4034a0a69157 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sun, 24 Jul 2016 22:31:31 -0400 Subject: [PATCH] allow favoriting / ctrl+alt selecting elements in element search ui --- .../elementsearch/ElementSearchActivity.cpp | 54 +++++++++++++++++-- src/gui/elementsearch/ElementSearchActivity.h | 9 +++- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/gui/elementsearch/ElementSearchActivity.cpp b/src/gui/elementsearch/ElementSearchActivity.cpp index 1179f88e8..4d463a638 100644 --- a/src/gui/elementsearch/ElementSearchActivity.cpp +++ b/src/gui/elementsearch/ElementSearchActivity.cpp @@ -5,6 +5,7 @@ #include "gui/interface/Keys.h" #include "gui/game/Tool.h" #include "gui/Style.h" +#include "gui/game/Favorite.h" #include "gui/game/GameController.h" class ElementSearchActivity::ToolAction: public ui::ButtonAction @@ -26,6 +27,9 @@ ElementSearchActivity::ElementSearchActivity(GameController * gameController, st firstResult(NULL), gameController(gameController), tools(tools), + shiftPressed(false), + ctrlPressed(false), + altPressed(false), exit(false) { ui::Label * title = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 15), "Element Search"); @@ -167,7 +171,18 @@ void ElementSearchActivity::searchTools(std::string query) void ElementSearchActivity::SetActiveTool(int selectionState, Tool * tool) { - gameController->SetActiveTool(selectionState, tool); + if (ctrlPressed && shiftPressed && !altPressed) + { + Favorite::Ref().AddFavorite(tool->GetIdentifier()); + gameController->RebuildFavoritesMenu(); + } + else if (ctrlPressed && altPressed && !shiftPressed && + tool->GetIdentifier().find("DEFAULT_PT_") != tool->GetIdentifier().npos) + { + gameController->SetActiveTool(3, tool); + } + else + gameController->SetActiveTool(selectionState, tool); exit = true; } @@ -188,15 +203,46 @@ void ElementSearchActivity::OnTick(float dt) void ElementSearchActivity::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) { - if (key == SDLK_KP_ENTER || key == SDLK_RETURN) + switch (key) { + case SDLK_KP_ENTER: + case SDLK_RETURN: if(firstResult) gameController->SetActiveTool(0, firstResult); + case SDLK_ESCAPE: exit = true; + break; + case SDLK_LSHIFT: + case SDLK_RSHIFT: + shiftPressed = true; + break; + case SDLK_LCTRL: + case SDLK_RCTRL: + ctrlPressed = true; + break; + case SDLK_LALT: + case SDLK_RALT: + altPressed = true; + break; } - if (key == SDLK_ESCAPE) +} + +void ElementSearchActivity::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) +{ + switch (key) { - exit = true; + case SDLK_LSHIFT: + case SDLK_RSHIFT: + shiftPressed = false; + break; + case SDLK_LCTRL: + case SDLK_RCTRL: + ctrlPressed = false; + break; + case SDLK_LALT: + case SDLK_RALT: + altPressed = false; + break; } } diff --git a/src/gui/elementsearch/ElementSearchActivity.h b/src/gui/elementsearch/ElementSearchActivity.h index 76f81ec60..6f852c5bc 100644 --- a/src/gui/elementsearch/ElementSearchActivity.h +++ b/src/gui/elementsearch/ElementSearchActivity.h @@ -9,16 +9,20 @@ #include "gui/game/ToolButton.h" class Tool; - class GameController; -class ElementSearchActivity: public WindowActivity { +class ElementSearchActivity: public WindowActivity +{ Tool * firstResult; GameController * gameController; std::vector tools; ui::Textbox * searchField; std::vector toolButtons; + bool shiftPressed; + bool ctrlPressed; + bool altPressed; void searchTools(std::string query); + public: class ToolAction; bool exit; @@ -29,6 +33,7 @@ public: virtual void OnDraw(); virtual void OnTick(float dt); virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); + virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); }; #endif /* ELEMENTSEARCHACTIVITY_H_ */