Skip to content

Commit

Permalink
add ctrl+q shortcut to exit the game from anywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Mar 10, 2018
1 parent ab4cdf2 commit f2ac8a9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
5 changes: 4 additions & 1 deletion src/PowderToySDL.cpp
Expand Up @@ -646,7 +646,10 @@ void EventProcess(SDL_Event event)
engine->Exit();
break;
case SDL_KEYDOWN:
engine->onKeyPress(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod&KMOD_SHIFT, event.key.keysym.mod&KMOD_CTRL, event.key.keysym.mod&KMOD_ALT);
if (event.key.keysym.sym == 'q' && (event.key.keysym.mod&KMOD_CTRL))
engine->ConfirmExit();
else
engine->onKeyPress(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod&KMOD_SHIFT, event.key.keysym.mod&KMOD_CTRL, event.key.keysym.mod&KMOD_ALT);
break;
case SDL_KEYUP:
engine->onKeyRelease(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod&KMOD_SHIFT, event.key.keysym.mod&KMOD_CTRL, event.key.keysym.mod&KMOD_ALT);
Expand Down
18 changes: 1 addition & 17 deletions src/gui/game/GameView.cpp
Expand Up @@ -1327,22 +1327,6 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
UpdateDrawMode();
}

void GameView::ExitPrompt()
{
class ExitConfirmation: public ConfirmDialogueCallback {
public:
ExitConfirmation() {}
virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) {
if (result == ConfirmPrompt::ResultOkay)
{
ui::Engine::Ref().Exit();
}
}
virtual ~ExitConfirmation() { }
};
new ConfirmPrompt("You are about to quit", "Are you sure you want to exit the game?", new ExitConfirmation());
}

void GameView::ToolTip(ui::Point senderPosition, std::string toolTip)
{
// buttom button tooltips
Expand Down Expand Up @@ -1579,7 +1563,7 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
break;
case SDLK_ESCAPE:
case 'q':
ExitPrompt();
ui::Engine::Ref().ConfirmExit();
break;
case 'u':
c->ToggleAHeat();
Expand Down
1 change: 0 additions & 1 deletion src/gui/game/GameView.h
Expand Up @@ -146,7 +146,6 @@ class GameView: public ui::Window
bool CtrlBehaviour(){ return ctrlBehaviour; }
bool ShiftBehaviour(){ return shiftBehaviour; }
bool AltBehaviour(){ return altBehaviour; }
void ExitPrompt();
SelectMode GetSelectMode() { return selectMode; }
void BeginStampSelection();
ui::Point GetPlaceSaveOffset() { return placeSaveOffset; }
Expand Down
17 changes: 17 additions & 0 deletions src/gui/interface/Engine.cpp
Expand Up @@ -7,6 +7,7 @@
#include "Platform.h"
#include "gui/interface/Window.h"
#include "gui/interface/Engine.h"
#include "gui/dialogues/ConfirmPrompt.h"
#include "graphics/Graphics.h"

using namespace ui;
Expand Down Expand Up @@ -73,6 +74,22 @@ void Engine::Exit()
running_ = false;
}

void Engine::ConfirmExit()
{
class ExitConfirmation: public ConfirmDialogueCallback {
public:
ExitConfirmation() {}
virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) {
if (result == ConfirmPrompt::ResultOkay)
{
ui::Engine::Ref().Exit();
}
}
virtual ~ExitConfirmation() { }
};
new ConfirmPrompt("You are about to quit", "Are you sure you want to exit the game?", new ExitConfirmation());
}

void Engine::ShowWindow(Window * window)
{
windowOpenState = 0;
Expand Down
1 change: 1 addition & 0 deletions src/gui/interface/Engine.h
Expand Up @@ -39,6 +39,7 @@ namespace ui
inline long unsigned int LastTick() { return lastTick; }
inline void LastTick(long unsigned int tick) { lastTick = tick; }
void Exit();
void ConfirmExit();
void Break();
void UnBreak();

Expand Down

0 comments on commit f2ac8a9

Please sign in to comment.