Skip to content

Commit

Permalink
fix crash when selecting PROP from element search, fixes #209
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Aug 11, 2014
1 parent fb49a49 commit 7740980
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/gui/elementsearch/ElementSearchActivity.cpp
Expand Up @@ -25,7 +25,8 @@ ElementSearchActivity::ElementSearchActivity(GameController * gameController, st
WindowActivity(ui::Point(-1, -1), ui::Point(236, 302)),
gameController(gameController),
tools(tools),
firstResult(NULL)
firstResult(NULL),
exit(false)
{
ui::Label * title = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 15), "Element Search");
title->SetTextColour(style::Colour::InformationTitle);
Expand Down Expand Up @@ -56,7 +57,7 @@ ElementSearchActivity::ElementSearchActivity(GameController * gameController, st
CloseAction(ElementSearchActivity * a) : a(a) { }
void ActionCallback(ui::Button * sender_)
{
a->Exit();
a->exit = true;
}
};

Expand Down Expand Up @@ -167,7 +168,7 @@ void ElementSearchActivity::searchTools(std::string query)
void ElementSearchActivity::SetActiveTool(int selectionState, Tool * tool)
{
gameController->SetActiveTool(selectionState, tool);
Exit();
exit = true;
}

void ElementSearchActivity::OnDraw()
Expand All @@ -179,17 +180,23 @@ void ElementSearchActivity::OnDraw()
g->drawrect(Position.X+searchField->Position.X, Position.Y+searchField->Position.Y+searchField->Size.Y+8, searchField->Size.X, Size.Y-(searchField->Position.Y+searchField->Size.Y+8)-23, 255, 255, 255, 180);
}

void ElementSearchActivity::OnTick(float dt)
{
if (exit)
Exit();
}

void ElementSearchActivity::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
if(key == KEY_ENTER || key == KEY_RETURN)
{
if(firstResult)
gameController->SetActiveTool(0, firstResult);
Exit();
exit = true;
}
if(key == KEY_ESCAPE)
{
Exit();
exit = true;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/gui/elementsearch/ElementSearchActivity.h
Expand Up @@ -21,11 +21,13 @@ class ElementSearchActivity: public WindowActivity {
void searchTools(std::string query);
public:
class ToolAction;
bool exit;
Tool * GetFirstResult() { return firstResult; }
ElementSearchActivity(GameController * gameController, std::vector<Tool*> tools);
void SetActiveTool(int selectionState, Tool * tool);
virtual ~ElementSearchActivity();
virtual void OnDraw();
virtual void OnTick(float dt);
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
};

Expand Down

0 comments on commit 7740980

Please sign in to comment.