[Scummvm-cvs-logs] SF.net SVN: scummvm:[40191] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Wed Apr 29 07:30:59 CEST 2009


Revision: 40191
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40191&view=rev
Author:   peres001
Date:     2009-04-29 05:30:58 +0000 (Wed, 29 Apr 2009)

Log Message:
-----------
* 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.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/gui_br.cpp
    scummvm/trunk/engines/parallaction/saveload.cpp
    scummvm/trunk/engines/parallaction/saveload.h

Modified: scummvm/trunk/engines/parallaction/gui_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/gui_br.cpp	2009-04-28 22:56:44 UTC (rev 40190)
+++ scummvm/trunk/engines/parallaction/gui_br.cpp	2009-04-29 05:30:58 UTC (rev 40191)
@@ -155,6 +155,9 @@
 	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 @@
 		}
 	}
 
-	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 @@
     }
 
 	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);
+		switch (_options[_selection]) {
+		case kMenuQuit: {
+			_vm->quitGame();
+			break;
+		}
 
-		if ((p.x > MENUITEMS_X) && (p.x < (MENUITEMS_X+MENUITEM_WIDTH)) && (p.y > MENUITEMS_Y)) {
-			_selection = (p.y - MENUITEMS_Y) / MENUITEM_HEIGHT;
+		case kMenuLoadGame:
+			warning("loadgame not yet implemented");
+			if (!_vm->_saveLoad->loadGame()) {
+				return this;
+			}
+			break;
 
-			if (!(_selection < _availItems))
-				_selection = -1;
-		} else
-			_selection = -1;
-
-		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 @@
 		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 @@
 			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 @@
 				_mscStatus = _vm->getMusicStatus();
 				_vm->_gfx->setItemFrame(_mscMenuObjId, frameFromStatus(_mscStatus));
 			}
-			return this;
+			break;
 
 		case 1:	// toggle sfx
 			if (_sfxStatus != -1) {
@@ -405,23 +412,29 @@
 				_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() {

Modified: scummvm/trunk/engines/parallaction/saveload.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/saveload.cpp	2009-04-28 22:56:44 UTC (rev 40190)
+++ scummvm/trunk/engines/parallaction/saveload.cpp	2009-04-29 05:30:58 UTC (rev 40191)
@@ -53,14 +53,8 @@
 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 @@
 
 
 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 @@
 	_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 @@
 }
 
 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::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::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::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() {
+	// 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 @@
 }
 
 
-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) {

Modified: scummvm/trunk/engines/parallaction/saveload.h
===================================================================
--- scummvm/trunk/engines/parallaction/saveload.h	2009-04-28 22:56:44 UTC (rev 40190)
+++ scummvm/trunk/engines/parallaction/saveload.h	2009-04-29 05:30:58 UTC (rev 40191)
@@ -41,13 +41,18 @@
 	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 @@
 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 @@
 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);
 };


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list