XEEN: Implementing control panel dialog

This commit is contained in:
Paul Gilbert 2018-01-27 20:00:24 -05:00
parent 12eacafe0e
commit 6080d63339
10 changed files with 277 additions and 13 deletions

View File

@ -71,7 +71,7 @@ bool ButtonContainer::checkEvents(XeenEngine *vm) {
Common::Point pt = events._mousePos;
for (uint i = 0; i < _buttons.size(); ++i) {
if (_buttons[i]._bounds.contains(pt)) {
if (_buttons[i]._draw && _buttons[i]._bounds.contains(pt)) {
events.debounceMouse();
_buttonValue = _buttons[i]._value;

View File

@ -21,6 +21,7 @@
*/
#include "xeen/dialogs_control_panel.h"
#include "xeen/dialogs_query.h"
#include "xeen/party.h"
#include "xeen/resources.h"
#include "xeen/xeen.h"
@ -36,7 +37,190 @@ int ControlPanel::show(XeenEngine *vm) {
}
int ControlPanel::execute() {
error("TODO: ControlPanel");
EventsManager &events = *_vm->_events;
Interface &intf = *_vm->_interface;
Map &map = *_vm->_map;
Party &party = *_vm->_party;
SavesManager &saves = *_vm->_saves;
Sound &sound = *_vm->_sound;
Windows &windows = *_vm->_windows;
Window &w = windows[23];
Window &w3 = windows[3];
loadButtons();
int result = 0, debugCtr = 0;
while (!g_vm->shouldQuit()) {
w.open();
while (!g_vm->shouldQuit()) {
Common::String btnText = getButtonText();
Common::String text = Common::String::format(Res.CONTROL_PANEL_TEXT, btnText.c_str());
drawButtons(&w);
w.writeString(text);
w.writeString("\xB""000\t000\x1");
w.update();
do {
events.updateGameCounter();
intf.draw3d(false);
w.writeString("\r");
drawButtons(&w);
w.writeString(text);
w.writeString("\v000\t000");
w.frame();
if (_debugFlag)
w.writeString(getTimeText());
w3.update();
w.update();
events.pollEventsAndWait();
checkEvents(_vm);
if (_vm->shouldQuit())
return 0;
if (!_buttonValue && !events.timeElapsed())
continue;
switch (_buttonValue) {
case Common::KEYCODE_q:
if (Confirm::show(g_vm, Res.CONFIRM_QUIT)) {
g_vm->_quitMode = QMODE_QUIT;
result = 1;
}
break;
case Common::KEYCODE_w:
if (Confirm::show(g_vm, Res.MR_WIZARD)) {
w.close();
if (!windows[2]._enabled) {
sound.playFX(51);
if (g_vm->getGameID() == GType_WorldOfXeen) {
map._loadDarkSide = false;
map.load(29);
party._mazeDirection = DIR_EAST;
} else {
map._loadDarkSide = true;
map.load(28);
party._mazeDirection = DIR_SOUTH;
}
party.moveToRunLocation();
}
party._gems = 0;
result = 2;
}
break;
case Common::KEYCODE_l:
if (_vm->_mode == MODE_COMBAT) {
ErrorScroll::show(_vm, Res.NO_LOADING_IN_COMBAT);
} else {
// Close dialog and show loading dialog
result = 3;
}
break;
case Common::KEYCODE_s:
if (_vm->_mode == MODE_COMBAT) {
ErrorScroll::show(_vm, Res.NO_SAVING_IN_COMBAT);
} else {
// Close dialog and show saving dialog
result = 4;
}
break;
case Common::KEYCODE_e:
// TODO: Toggle sound effects
break;
case Common::KEYCODE_m:
// TODO: Toggle music
break;
case Common::KEYCODE_ESCAPE:
result = 1;
break;
// Goober cheat sequence
case Common::KEYCODE_g:
debugCtr = 1;
break;
case Common::KEYCODE_o:
debugCtr = (debugCtr == 1) ? 2 : 0;
break;
case Common::KEYCODE_b:
debugCtr = (debugCtr == 2) ? 3 : 0;
case Common::KEYCODE_r:
if (debugCtr == 3)
_debugFlag = true;
else
debugCtr = 0;
break;
default:
break;
}
} while (!result);
}
}
w.close();
intf.drawParty(true);
if (result == 3) {
saves.loadGame();
} else if (result == 4) {
saves.saveGame();
}
return result;
}
void ControlPanel::loadButtons() {
_iconSprites.load("cpanel.icn");
addButton(Common::Rect(214, 56, 244, 69), Common::KEYCODE_f);
addButton(Common::Rect(214, 75, 244, 88), Common::KEYCODE_m);
addButton(Common::Rect(135, 56, 165, 69), Common::KEYCODE_l, &_iconSprites);
addButton(Common::Rect(135, 75, 165, 88), Common::KEYCODE_s);
// For ScummVM we've merged both Save and Save As into a single
// save item, so we don't need this one
addButton(Common::Rect(), 0);
_buttons.end()->_draw = false;
addButton(Common::Rect(135, 94, 165, 107), Common::KEYCODE_q);
addButton(Common::Rect(175, 113, 205, 126), Common::KEYCODE_w);
}
Common::String ControlPanel::getButtonText() {
Sound &sound = *g_vm->_sound;
_btnSoundText = sound._soundOn ? Res.ON : Res.OFF;
_btnMusicText = sound._musicOn ? Res.ON : Res.OFF;
return Common::String::format(Res.CONTROL_PANEL_BUTTONS,
_btnSoundText.c_str(), _btnMusicText.c_str());
}
Common::String ControlPanel::getTimeText() const {
TimeDate td;
g_system->getTimeAndDate(td);
Common::String timeStr = Common::String::format("%d:%.2d:%.2d%c",
td.tm_hour == 0 || td.tm_hour == 12 ? 12 : (td.tm_hour % 12),
td.tm_min, td.tm_sec, (td.tm_hour >= 12) ? 'p' : 'c');
uint32 playtime = g_vm->_events->playTime();
Common::String playtimeStr = Common::String::format("%d:%.2d:%.2d",
playtime / 3600, (playtime / 60) % 60, playtime % 60);
return Common::String::format(
"\x2\x3l\xB""000\t000\x4""160%s\x3r\xB""000\t000%s\x1",
timeStr.c_str(), playtimeStr.c_str());
}
} // End of namespace Xeen

View File

@ -29,10 +29,35 @@ namespace Xeen {
class ControlPanel : public ButtonContainer {
private:
ControlPanel(XeenEngine *vm) : ButtonContainer(vm) {}
SpriteResource _iconSprites;
Common::String _btnSoundText, _btnMusicText;
bool _debugFlag;
private:
ControlPanel(XeenEngine *vm) : ButtonContainer(vm), _debugFlag(false) {}
/**
* Inner handler for showing the dialog
*/
int execute();
/**
* Loads the buttons for the dialog
*/
void loadButtons();
/**
* Gets the text for the dialog buttons
*/
Common::String getButtonText();
/**
* Gets the current time
*/
Common::String getTimeText() const;
public:
/**
* Show the control panel
*/
static int show(XeenEngine *vm);
};

View File

@ -313,13 +313,11 @@ void Interface::perform() {
switch (_buttonValue) {
case Common::KEYCODE_TAB:
// Stop mosters doing any movement
// Show control panel
combat._moveMonsters = false;
if (ControlPanel::show(_vm) == -1) {
_vm->_quitMode = 2;
} else {
combat._moveMonsters = 1;
}
ControlPanel::show(_vm);
if (!g_vm->shouldQuit() && !g_vm->_quitMode)
combat._moveMonsters = true;
break;
case Common::KEYCODE_SPACE:

View File

@ -1672,4 +1672,25 @@ const char *const Resources::PICKS_THE_LOCK = "\x3""c\xB""010%s picks the lock!\
const char *const Resources::UNABLE_TO_PICK_LOCK = "\x3""c\v010%s was unable to pick the lock!\nPress any key.";
const char *const Resources::CONTROL_PANEL_TEXT =
"\x1\xC""00\x3""c\xB""000\t000Control Panel\x3r"
"\xB""022\t045\xC""06E\xC""dfx:\t124\xC""06S\xC""dave:"
"\xB""041\t045\xC""06M\xC""dusic:\t124S\xC""06a\xC""dve:"
"\xB""060\t045\xC""06L\xC""doad:\t124\xC""06Q\xC""duit:"
"\xB""080\t084Mr \xC""06W\xC""dizard:%s\t000";
const char *const Resources::CONTROL_PANEL_BUTTONS =
"\x3""c\xB""022\t062load\t141%s"
"\xB""041\t062save\t141%s"
"\xB""060\t062exit"
"\xB""079\t102Help\xC""d";
const char *const Resources::ON = "on";
const char *const Resources::OFF = "off";
const char *const Resources::CONFIRM_QUIT = "Are you sure you want to quit?";
const char *const Resources::MR_WIZARD =
"Are you sure you want Mr.Wizard''s Help ?";
const char *const Resources::NO_LOADING_IN_COMBAT =
"No Loading Allowed in Combat!";
const char *const Resources::NO_SAVING_IN_COMBAT =
"No Saving Allowed in Combat!";
} // End of namespace Xeen

View File

@ -353,6 +353,14 @@ public:
static const char *const WARZONE_HOW_MANY;
static const char *const PICKS_THE_LOCK;
static const char *const UNABLE_TO_PICK_LOCK;
static const char *const CONTROL_PANEL_TEXT;
static const char *const CONTROL_PANEL_BUTTONS;
static const char *const ON;
static const char *const OFF;
static const char *const CONFIRM_QUIT;
static const char *const MR_WIZARD;
static const char *const NO_LOADING_IN_COMBAT;
static const char *const NO_SAVING_IN_COMBAT;
public:
/**
* Initializes an instnace of the resources

View File

@ -221,4 +221,14 @@ Common::String SavesManager::generateSaveName(int slot) {
return Common::String::format("%s.%03d", _targetName.c_str(), slot);
}
bool SavesManager::loadGame() {
// TODO
return false;
}
bool SavesManager::saveGame() {
// TODO
return false;
}
} // End of namespace Xeen

View File

@ -81,6 +81,18 @@ public:
* Save the game
*/
Common::Error saveGameState(int slot, const Common::String &desc);
/**
* Shows the load game dialog, and lets the user load a game
* @returns True if a savegame was loaded
*/
bool loadGame();
/**
* Shows the save game dialog, and lets the user save their game
* @returns True if a savegame was saved
*/
bool saveGame();
};
} // End of namespace Xeen

View File

@ -59,7 +59,7 @@ XeenEngine::XeenEngine(OSystem *syst, const XeenGameDescription *gameDesc)
_eventData = nullptr;
_noDirectionSense = false;
_startupWindowActive = false;
_quitMode = 0;
_quitMode = QMODE_NONE;
_mode = MODE_0;
_endingScore = 0;
_loadSaveSlot = -1;
@ -160,7 +160,7 @@ void XeenEngine::playGame() {
void XeenEngine::play() {
// TODO: Init variables
_quitMode = 0;
_quitMode = QMODE_NONE;
_interface->setup();
_screen->loadBackground("back.raw");
@ -217,7 +217,7 @@ void XeenEngine::gameLoop() {
_map->cellFlagLookup(_party->_mazePosition);
if (_map->_currentIsEvent) {
_quitMode = _scripts->checkEvents();
_quitMode = (QuitMode)_scripts->checkEvents();
if (shouldQuit() || _quitMode)
return;
}

View File

@ -93,6 +93,12 @@ enum Mode {
MODE_86 = 86
};
enum QuitMode {
QMODE_NONE = 0,
QMODE_QUIT = 1,
QMODE_MENU = 2
};
struct XeenGameDescription;
#define XEEN_SAVEGAME_VERSION 1
@ -151,7 +157,7 @@ public:
Mode _mode;
GameEvent _gameEvent;
Common::SeekableReadStream *_eventData;
int _quitMode;
QuitMode _quitMode;
bool _noDirectionSense;
bool _startupWindowActive;
uint _endingScore;