Permalink
Browse files

add ctrl+q shortcut to exit the game from anywhere

  • Loading branch information...
jacob1 committed Mar 10, 2018
1 parent ab4cdf2 commit f2ac8a951c57f076a7e381eac590ddf43f8e95eb
Showing with 23 additions and 19 deletions.
  1. +4 −1 src/PowderToySDL.cpp
  2. +1 −17 src/gui/game/GameView.cpp
  3. +0 −1 src/gui/game/GameView.h
  4. +17 −0 src/gui/interface/Engine.cpp
  5. +1 −0 src/gui/interface/Engine.h
@@ -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);
@@ -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
@@ -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();
@@ -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; }
@@ -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;
@@ -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;
@@ -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();

0 comments on commit f2ac8a9

Please sign in to comment.