Permalink
Browse files

allow favoriting / ctrl+alt selecting elements in element search ui

  • Loading branch information...
jacob1 committed Jul 25, 2016
1 parent ae247a2 commit 8efe8853defa84525bde5d03febc4034a0a69157
Showing with 57 additions and 6 deletions.
  1. +50 −4 src/gui/elementsearch/ElementSearchActivity.cpp
  2. +7 −2 src/gui/elementsearch/ElementSearchActivity.h
@@ -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;
}
}
@@ -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<Tool*> tools;
ui::Textbox * searchField;
std::vector<ToolButton*> toolButtons;
bool shiftPressed;
bool ctrlPressed;
bool altPressed;
void searchTools(std::string query);
public:
class ToolAction;
bool exit;
@@ -29,6 +33,7 @@ class ElementSearchActivity: public WindowActivity {
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_ */

0 comments on commit 8efe885

Please sign in to comment.