aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicola Mettifogo2009-04-29 05:30:58 +0000
committerNicola Mettifogo2009-04-29 05:30:58 +0000
commit9a78f6ef41b30e28973551ebc9c19bbc1ac1d8dd (patch)
treeaf7ba141114807512e726c7613cbb34f6e635f55
parented914d6740fda4ea057c23ef8d2ae51dc93df033 (diff)
downloadscummvm-rg350-9a78f6ef41b30e28973551ebc9c19bbc1ac1d8dd.tar.gz
scummvm-rg350-9a78f6ef41b30e28973551ebc9c19bbc1ac1d8dd.tar.bz2
scummvm-rg350-9a78f6ef41b30e28973551ebc9c19bbc1ac1d8dd.zip
* Refactored existing save/load code to ease extension
* Added load/save dialogs using ScummVM's overlay for the moment (no actual saving is performed yet) * Plugged the main menu so that it displays the load dialog when needed. svn-id: r40191
-rw-r--r--engines/parallaction/gui_br.cpp103
-rw-r--r--engines/parallaction/saveload.cpp89
-rw-r--r--engines/parallaction/saveload.h23
3 files changed, 105 insertions, 110 deletions
diff --git a/engines/parallaction/gui_br.cpp b/engines/parallaction/gui_br.cpp
index fd882d4b93..79d4e74395 100644
--- a/engines/parallaction/gui_br.cpp
+++ b/engines/parallaction/gui_br.cpp
@@ -155,6 +155,9 @@ class MainMenuInputState_BR : public MenuInputState {
static const MenuOptions _optionsAmiga[NUM_MENULINES];
static const MenuOptions _optionsPC[NUM_MENULINES];
+ const char **_menuStrings;
+ const MenuOptions *_options;
+
static const char *_firstLocation[];
int _availItems;
@@ -169,19 +172,20 @@ class MainMenuInputState_BR : public MenuInputState {
}
}
- void performChoice(int selectedItem) {
- switch (selectedItem) {
- case kMenuQuit: {
- _vm->quitGame();
- break;
- }
+ void redrawMenu() {
+ Common::Point p;
+ _vm->_input->getCursorPos(p);
- case kMenuLoadGame:
- warning("loadgame not yet implemented");
- break;
+ if ((p.x > MENUITEMS_X) && (p.x < (MENUITEMS_X+MENUITEM_WIDTH)) && (p.y > MENUITEMS_Y)) {
+ _selection = (p.y - MENUITEMS_Y) / MENUITEM_HEIGHT;
- default:
- _vm->scheduleLocationSwitch(_firstLocation[selectedItem]);
+ if (!(_selection < _availItems))
+ _selection = -1;
+ } else
+ _selection = -1;
+
+ for (int i = 0; i < _availItems; i++) {
+ _vm->_gfx->setItemFrame(i, _selection == i ? 1 : 0);
}
}
@@ -195,36 +199,33 @@ public:
}
virtual MenuInputState* run() {
-
int event = _vm->_input->getLastButtonEvent();
- if ((event == kMouseLeftUp) && _selection >= 0) {
- _vm->_system->showMouse(false);
- cleanup();
- if (_vm->getPlatform() == Common::kPlatformAmiga) {
- performChoice(_optionsAmiga[_selection]);
- } else {
- performChoice(_optionsPC[_selection]);
- }
- return 0;
+ if (!((event == kMouseLeftUp) && _selection >= 0)) {
+ redrawMenu();
+ return this;
}
- Common::Point p;
- _vm->_input->getCursorPos(p);
-
- if ((p.x > MENUITEMS_X) && (p.x < (MENUITEMS_X+MENUITEM_WIDTH)) && (p.y > MENUITEMS_Y)) {
- _selection = (p.y - MENUITEMS_Y) / MENUITEM_HEIGHT;
+ switch (_options[_selection]) {
+ case kMenuQuit: {
+ _vm->quitGame();
+ break;
+ }
- if (!(_selection < _availItems))
- _selection = -1;
- } else
- _selection = -1;
+ case kMenuLoadGame:
+ warning("loadgame not yet implemented");
+ if (!_vm->_saveLoad->loadGame()) {
+ return this;
+ }
+ break;
- for (int i = 0; i < _availItems; i++) {
- _vm->_gfx->setItemFrame(i, _selection == i ? 1 : 0);
+ default:
+ _vm->scheduleLocationSwitch(_firstLocation[_options[_selection]]);
}
+ _vm->_system->showMouse(false);
+ cleanup();
- return this;
+ return 0;
}
virtual void enter() {
@@ -243,12 +244,16 @@ public:
for (i = 0; i < 3 && complete[i]; i++, _availItems++) ;
// TODO: keep track of and destroy menu item frames/surfaces
+ if (_vm->getPlatform() == Common::kPlatformAmiga) {
+ _menuStrings = _menuStringsAmiga;
+ _options = _optionsAmiga;
+ } else {
+ _menuStrings = _menuStringsPC;
+ _options = _optionsPC;
+ }
+
for (i = 0; i < _availItems; i++) {
- if (_vm->getPlatform() == Common::kPlatformAmiga) {
- _lines[i] = new GfxObj(0, renderMenuItem(_menuStringsAmiga[i]), "MenuItem");
- } else {
- _lines[i] = new GfxObj(0, renderMenuItem(_menuStringsPC[i]), "MenuItem");
- }
+ _lines[i] = new GfxObj(0, renderMenuItem(_menuStrings[i]), "MenuItem");
_vm->_gfx->setItem(_lines[i], MENUITEMS_X, MENUITEMS_Y + MENUITEM_HEIGHT * i, 0xFF);
}
_selection = -1;
@@ -385,11 +390,13 @@ public:
cell = (p.x - _menuRect.left) / _cellW + 3 * ((p.y - _menuRect.top) / _cellH);
}
+ bool close = false;
+
switch (cell) {
case 4: // resume
case -1: // invalid cell
- _vm->_gfx->freeDialogueObjects();
- return 0;
+ close = true;
+ break;
case 0: // toggle music
if (_mscStatus != -1) {
@@ -397,7 +404,7 @@ public:
_mscStatus = _vm->getMusicStatus();
_vm->_gfx->setItemFrame(_mscMenuObjId, frameFromStatus(_mscStatus));
}
- return this;
+ break;
case 1: // toggle sfx
if (_sfxStatus != -1) {
@@ -405,23 +412,29 @@ public:
_sfxStatus = _vm->getSfxStatus();
_vm->_gfx->setItemFrame(_sfxMenuObjId, frameFromStatus(_sfxStatus));
}
- return this;
+ break;
case 2: // save
warning("Saving is not supported yet!");
- _vm->_gfx->freeDialogueObjects();
+ _vm->_saveLoad->saveGame();
break;
case 3: // load
warning("Loading is not supported yet!");
- _vm->_gfx->freeDialogueObjects();
+ close = _vm->_saveLoad->loadGame();
break;
case 5: // quit
return _helper->getState("quitdialog");
}
- return 0;
+ if (close) {
+ _vm->_gfx->freeDialogueObjects();
+ return 0;
+ }
+
+ _vm->_input->setArrowCursor();
+ return this;
}
void enter() {
diff --git a/engines/parallaction/saveload.cpp b/engines/parallaction/saveload.cpp
index 70da931fbb..784fc8ac8a 100644
--- a/engines/parallaction/saveload.cpp
+++ b/engines/parallaction/saveload.cpp
@@ -53,14 +53,8 @@ class SaveLoadChooser : public GUI::Dialog {
protected:
GUI::ListWidget *_list;
GUI::ButtonWidget *_chooseButton;
- GUI::GraphicsWidget *_gfxWidget;
- GUI::StaticTextWidget *_date;
- GUI::StaticTextWidget *_time;
- GUI::StaticTextWidget *_playtime;
GUI::ContainerWidget *_container;
- uint8 _fillR, _fillG, _fillB;
-
public:
SaveLoadChooser(const String &title, const String &buttonLabel);
~SaveLoadChooser();
@@ -240,7 +234,7 @@ enum {
SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel)
- : Dialog("ScummSaveLoad"), _list(0), _chooseButton(0), _gfxWidget(0) {
+ : Dialog("ScummSaveLoad"), _list(0), _chooseButton(0) {
// _drawingHints |= GUI::THEME_HINT_SPECIAL_COLOR;
_backgroundType = GUI::ThemeEngine::kDialogBackgroundSpecial;
@@ -252,19 +246,10 @@ SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel)
_list->setEditable(true);
_list->setNumberingMode(GUI::kListNumberingOne);
- _gfxWidget = new GUI::GraphicsWidget(this, 0, 0, 10, 10);
-
- _date = new GUI::StaticTextWidget(this, 0, 0, 10, 10, "No date saved", Graphics::kTextAlignCenter);
- _time = new GUI::StaticTextWidget(this, 0, 0, 10, 10, "No time saved", Graphics::kTextAlignCenter);
- _playtime = new GUI::StaticTextWidget(this, 0, 0, 10, 10, "No playtime saved", Graphics::kTextAlignCenter);
-
// Buttons
new GUI::ButtonWidget(this, "ScummSaveLoad.Cancel", "Cancel", GUI::kCloseCmd, 0);
_chooseButton = new GUI::ButtonWidget(this, "ScummSaveLoad.Choose", buttonLabel, kChooseCmd, 0);
_chooseButton->setEnabled(false);
-
- _container = new GUI::ContainerWidget(this, 0, 0, 10, 10);
-// _container->setHints(GUI::THEME_HINT_USE_SHADOW);
}
SaveLoadChooser::~SaveLoadChooser() {
@@ -279,10 +264,7 @@ void SaveLoadChooser::setList(const StringList& list) {
}
int SaveLoadChooser::runModal() {
- if (_gfxWidget)
- _gfxWidget->setGfx(0);
- int ret = GUI::Dialog::runModal();
- return ret;
+ return GUI::Dialog::runModal();
}
void SaveLoadChooser::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
@@ -319,16 +301,11 @@ void SaveLoadChooser::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint
}
void SaveLoadChooser::reflowLayout() {
- _container->setVisible(false);
- _gfxWidget->setVisible(false);
- _date->setVisible(false);
- _time->setVisible(false);
- _playtime->setVisible(false);
-
Dialog::reflowLayout();
}
-int SaveLoad_ns::buildSaveFileList(Common::StringList& l) {
+
+int SaveLoad::buildSaveFileList(Common::StringList& l) {
Common::String pattern = _saveFilePrefix + ".???";
Common::StringList filenames = _saveFileMan->listSavefiles(pattern.c_str());
@@ -353,30 +330,28 @@ int SaveLoad_ns::buildSaveFileList(Common::StringList& l) {
}
-int SaveLoad_ns::selectSaveFile(uint16 arg_0, const char* caption, const char* button) {
+int SaveLoad::selectSaveFile(Common::String &selectedName, const Common::String &caption, const Common::String &button) {
+ Common::StringList list;
+ buildSaveFileList(list);
- SaveLoadChooser* slc = new SaveLoadChooser(caption, button);
+ SaveLoadChooser slc(caption, button);
+ slc.setList(list);
- Common::StringList l;
+ selectedName.clear();
- /*int count = */ buildSaveFileList(l);
- slc->setList(l);
-
- int idx = slc->runModal();
- if (idx >= 0) {
- _saveFileName = slc->getResultString();
+ int slot = slc.runModal();
+ if (slot >= 0) {
+ selectedName = slc.getResultString();
}
- delete slc;
-
- return idx;
+ return slot;
}
-bool SaveLoad_ns::loadGame() {
-
- int _di = selectSaveFile( 0, "Load file", "Load" );
+bool SaveLoad::loadGame() {
+ Common::String null;
+ int _di = selectSaveFile(null, "Load file", "Load");
if (_di == -1) {
return false;
}
@@ -392,18 +367,14 @@ bool SaveLoad_ns::loadGame() {
}
-bool SaveLoad_ns::saveGame() {
-
- if (!scumm_stricmp(_vm->_location._name, "caveau")) {
- return false;
- }
-
- int slot = selectSaveFile( 1, "Save file", "Save" );
+bool SaveLoad::saveGame() {
+ Common::String saveName;
+ int slot = selectSaveFile(saveName, "Save file", "Save");
if (slot == -1) {
return false;
}
- doSaveGame(slot, _saveFileName.c_str());
+ doSaveGame(slot, saveName.c_str());
GUI::TimedMessageDialog dialog("Saving game...", 1500);
dialog.runModal();
@@ -412,6 +383,16 @@ bool SaveLoad_ns::saveGame() {
}
+bool SaveLoad_ns::saveGame() {
+ // NOTE: shouldn't this check be done before, so that the
+ // user can't even select 'save'?
+ if (!scumm_stricmp(_vm->_location._name, "caveau")) {
+ return false;
+ }
+
+ return SaveLoad::saveGame();
+}
+
void SaveLoad_ns::setPartComplete(const char *part) {
Common::String s;
bool alreadyPresent = false;
@@ -512,14 +493,14 @@ void SaveLoad_ns::renameOldSavefiles() {
}
-bool SaveLoad_br::loadGame() {
+void SaveLoad_br::doLoadGame(uint16 slot) {
// TODO: implement loadgame
- return false;
+ return;
}
-bool SaveLoad_br::saveGame() {
+void SaveLoad_br::doSaveGame(uint16 slot, const char* name) {
// TODO: implement savegame
- return false;
+ return;
}
void SaveLoad_br::getGamePartProgress(bool *complete, int size) {
diff --git a/engines/parallaction/saveload.h b/engines/parallaction/saveload.h
index 10bb8aafc2..2b2a7ab6a5 100644
--- a/engines/parallaction/saveload.h
+++ b/engines/parallaction/saveload.h
@@ -41,13 +41,18 @@ protected:
Common::String genSaveFileName(uint slot);
Common::InSaveFile *getInSaveFile(uint slot);
Common::OutSaveFile *getOutSaveFile(uint slot);
+ int selectSaveFile(Common::String &selectedName, const Common::String &caption, const Common::String &button);
+ int buildSaveFileList(Common::StringList& l);
+ virtual void doLoadGame(uint16 slot) = 0;
+ virtual void doSaveGame(uint16 slot, const char* name) = 0;
public:
SaveLoad(Common::SaveFileManager* saveFileMan, const char *prefix) : _saveFileMan(saveFileMan), _saveFilePrefix(prefix) { }
virtual ~SaveLoad() { }
- virtual bool loadGame() = 0;
- virtual bool saveGame() = 0;
+ virtual bool loadGame();
+ virtual bool saveGame();
+
virtual void getGamePartProgress(bool *complete, int size) = 0;
virtual void setPartComplete(const char *part) = 0;
@@ -57,22 +62,18 @@ public:
class SaveLoad_ns : public SaveLoad {
Parallaction_ns *_vm;
-
- Common::String _saveFileName;
Common::String genOldSaveFileName(uint slot);
protected:
void renameOldSavefiles();
- void doLoadGame(uint16 slot);
- void doSaveGame(uint16 slot, const char* name);
- int buildSaveFileList(Common::StringList& l);
- int selectSaveFile(uint16 arg_0, const char* caption, const char* button);
+ virtual void doLoadGame(uint16 slot);
+ virtual void doSaveGame(uint16 slot, const char* name);
public:
SaveLoad_ns(Parallaction_ns *vm, Common::SaveFileManager *saveFileMan) : SaveLoad(saveFileMan, "nippon"), _vm(vm) { }
- virtual bool loadGame();
virtual bool saveGame();
+
virtual void getGamePartProgress(bool *complete, int size);
virtual void setPartComplete(const char *part);
};
@@ -80,12 +81,12 @@ public:
class SaveLoad_br : public SaveLoad {
Parallaction_br *_vm;
+ virtual void doLoadGame(uint16 slot);
+ virtual void doSaveGame(uint16 slot, const char* name);
public:
SaveLoad_br(Parallaction_br *vm, Common::SaveFileManager *saveFileMan) : SaveLoad(saveFileMan, "bra"), _vm(vm) { }
- virtual bool loadGame();
- virtual bool saveGame();
virtual void getGamePartProgress(bool *complete, int size);
virtual void setPartComplete(const char *part);
};