mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-01 00:12:59 +00:00
* 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
This commit is contained in:
parent
ed914d6740
commit
9a78f6ef41
@ -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,45 +172,7 @@ class MainMenuInputState_BR : public MenuInputState {
|
||||
}
|
||||
}
|
||||
|
||||
void performChoice(int selectedItem) {
|
||||
switch (selectedItem) {
|
||||
case kMenuQuit: {
|
||||
_vm->quitGame();
|
||||
break;
|
||||
}
|
||||
|
||||
case kMenuLoadGame:
|
||||
warning("loadgame not yet implemented");
|
||||
break;
|
||||
|
||||
default:
|
||||
_vm->scheduleLocationSwitch(_firstLocation[selectedItem]);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
MainMenuInputState_BR(Parallaction_br *vm, MenuInputHelper *helper) : MenuInputState("mainmenu", helper), _vm(vm) {
|
||||
memset(_lines, 0, sizeof(_lines));
|
||||
}
|
||||
|
||||
~MainMenuInputState_BR() {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void redrawMenu() {
|
||||
Common::Point p;
|
||||
_vm->_input->getCursorPos(p);
|
||||
|
||||
@ -222,9 +187,45 @@ public:
|
||||
for (int i = 0; i < _availItems; i++) {
|
||||
_vm->_gfx->setItemFrame(i, _selection == i ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
MainMenuInputState_BR(Parallaction_br *vm, MenuInputHelper *helper) : MenuInputState("mainmenu", helper), _vm(vm) {
|
||||
memset(_lines, 0, sizeof(_lines));
|
||||
}
|
||||
|
||||
return this;
|
||||
~MainMenuInputState_BR() {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
virtual MenuInputState* run() {
|
||||
int event = _vm->_input->getLastButtonEvent();
|
||||
if (!((event == kMouseLeftUp) && _selection >= 0)) {
|
||||
redrawMenu();
|
||||
return this;
|
||||
}
|
||||
|
||||
switch (_options[_selection]) {
|
||||
case kMenuQuit: {
|
||||
_vm->quitGame();
|
||||
break;
|
||||
}
|
||||
|
||||
case kMenuLoadGame:
|
||||
warning("loadgame not yet implemented");
|
||||
if (!_vm->_saveLoad->loadGame()) {
|
||||
return this;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
_vm->scheduleLocationSwitch(_firstLocation[_options[_selection]]);
|
||||
}
|
||||
|
||||
_vm->_system->showMouse(false);
|
||||
cleanup();
|
||||
|
||||
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() {
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user