From 18941738526113c9153e05d455926b357cdfa7d3 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Sat, 6 Jun 2009 16:47:21 +0000 Subject: Adding a pause mode svn-id: r41228 --- engines/gob/gob.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ engines/gob/gob.h | 20 ++++++++++++++++++++ engines/gob/util.cpp | 2 ++ 3 files changed, 66 insertions(+) (limited to 'engines') diff --git a/engines/gob/gob.cpp b/engines/gob/gob.cpp index 436a1bf1f3..71d89912ba 100644 --- a/engines/gob/gob.cpp +++ b/engines/gob/gob.cpp @@ -31,6 +31,9 @@ #include "common/md5.h" #include "sound/mididrv.h" +#include "gui/GuiManager.h" +#include "gui/widget.h" + #include "gob/gob.h" #include "gob/global.h" #include "gob/util.h" @@ -67,6 +70,37 @@ const Common::Language GobEngine::_gobToScummVMLang[] = { Common::JA_JPN }; + +PauseDialog::PauseDialog() : GUI::Dialog("PauseDialog") { + _backgroundType = GUI::ThemeEngine::kDialogBackgroundSpecial; + + _message = "Game paused. Press Ctrl+p again to continue."; + _text = new GUI::StaticTextWidget(this, 4, 0, 10, 10, + _message, Graphics::kTextAlignCenter); +} + +void PauseDialog::reflowLayout() { + const int screenW = g_system->getOverlayWidth(); + const int screenH = g_system->getOverlayHeight(); + + int width = g_gui.getStringWidth(_message) + 16; + int height = g_gui.getFontHeight() + 8; + + _w = width; + _h = height; + _x = (screenW - width) / 2; + _y = (screenH - height) / 2; + + _text->setSize(_w - 8, _h); +} + +void PauseDialog::handleKeyDown(Common::KeyState state) { + // Close on CTRL+p + if ((state.flags == Common::KBD_CTRL) && (state.keycode == Common::KEYCODE_p)) + close(); +} + + GobEngine::GobEngine(OSystem *syst) : Engine(syst) { _sound = 0; _mult = 0; _game = 0; _global = 0; _dataIO = 0; _goblin = 0; @@ -277,6 +311,16 @@ void GobEngine::pauseEngineIntern(bool pause) { _mixer->pauseAll(pause); } +void GobEngine::pauseGame() { + pauseEngineIntern(true); + + PauseDialog pauseDialog; + + pauseDialog.runModal(); + + pauseEngineIntern(false); +} + bool GobEngine::initGameParts() { _noMusic = MidiDriver::parseMusicDriver(ConfMan.get("music_driver")) == MD_NULL; diff --git a/engines/gob/gob.h b/engines/gob/gob.h index 65d6ffeced..43e2270354 100644 --- a/engines/gob/gob.h +++ b/engines/gob/gob.h @@ -29,8 +29,14 @@ #include "common/system.h" #include "common/savefile.h" +#include "gui/dialog.h" + #include "engines/engine.h" +namespace GUI { + class StaticTextWidget; +} + namespace Gob { class Game; @@ -134,6 +140,18 @@ enum { struct GOBGameDescription; +class PauseDialog : public GUI::Dialog { +public: + PauseDialog(); + + virtual void reflowLayout(); + virtual void handleKeyDown(Common::KeyState state); + +private: + Common::String _message; + GUI::StaticTextWidget *_text; +}; + class GobEngine : public Engine { private: GameType _gameType; @@ -189,6 +207,8 @@ public: void validateLanguage(); void validateVideoMode(int16 videoMode); + void pauseGame(); + Endianness getEndianness() const; Common::Platform getPlatform() const; GameType getGameType() const; diff --git a/engines/gob/util.cpp b/engines/gob/util.cpp index 2916caa340..d89368b898 100644 --- a/engines/gob/util.cpp +++ b/engines/gob/util.cpp @@ -120,6 +120,8 @@ void Util::processInput(bool scroll) { _fastMode ^= 1; else if (event.kbd.keycode == Common::KEYCODE_g) _fastMode ^= 2; + else if (event.kbd.keycode == Common::KEYCODE_p) + _vm->pauseGame(); break; } addKeyToBuffer(event.kbd); -- cgit v1.2.3