[Scummvm-cvs-logs] CVS: scummvm/saga input.cpp,1.44,1.45 interface.cpp,1.98,1.99 interface.h,1.54,1.55 saga.h,1.97,1.98 saveload.cpp,1.11,1.12

Andrew Kurushin h00ligan at users.sourceforge.net
Tue May 31 13:10:13 CEST 2005


Update of /cvsroot/scummvm/scummvm/saga
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9963

Modified Files:
	input.cpp interface.cpp interface.h saga.h saveload.cpp 
Log Message:
multiple files save-load implementation

Index: input.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/input.cpp,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- input.cpp	29 May 2005 20:57:45 -0000	1.44
+++ input.cpp	31 May 2005 20:08:44 -0000	1.45
@@ -86,10 +86,8 @@
 				_render->toggleFlag(RF_ACTOR_PATH_TEST);
 				break;
 			case 288: // F7
-				save();
 				break;
 			case 289: // F8
-				load();
 				break;
 			case 9: // Tab
 				_script->SThreadDebugStep();

Index: interface.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/interface.cpp,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- interface.cpp	31 May 2005 01:03:13 -0000	1.98
+++ interface.cpp	31 May 2005 20:08:44 -0000	1.99
@@ -303,10 +303,8 @@
 			break;
 		case(kPanelSave):
 			_savePanel.currentButton = NULL;
-			_textInputMaxWidth = _saveEdit->width - 9;
+			_textInputMaxWidth = _saveEdit->width - 10;
 			_textInput = true;
-			_textInputString[0] = 0;
-			strcpy(_textInputString, "test1");
 			_textInputStringLength = strlen(_textInputString);
 			_textInputPos = _textInputStringLength + 1;
 			_textInputRepeatPhase = 0;
@@ -585,7 +583,7 @@
 }
 
 void Interface::calcOptionSaveSlider() {
-	int totalFiles = _vm->getSaveFileNameCount();
+	int totalFiles = _vm->getSaveFilesCount();
 	int visibleFiles = _vm->getDisplayInfo().optionSaveFileVisible; 
 	int height = _optionSaveFileSlider->height;
 	int sliderHeight;
@@ -686,11 +684,11 @@
 		if (idx == _optionSaveFileTitleNumber) {
 			SWAP(bgColor, fgColor);
 		}
-		if (idx < _vm->getSaveFileNameCount()) {
+		if (idx < _vm->getSaveFilesCount()) {
 			rect2.top = rect.top + j * (fontHeight + 1);
 			rect2.bottom = rect2.top + fontHeight;
 			backBuffer->fillRect(rect2, bgColor);
-			text = _vm->getSaveFileName(idx);
+			text = _vm->getSaveFile(idx)->name;
 			_vm->_font->draw(SMALL_FONT_ID, backBuffer, text, 0,
 				 rect.left + 1, rect2.top, fgColor, 0, 0);
 		}
@@ -811,7 +809,7 @@
 void Interface::setLoad(PanelButton *panelButton) {
 	_loadPanel.currentButton = NULL;
 	switch (panelButton->id) {
-		case kTextOK:
+		case kTextOK:			
 			setMode(kPanelMain);
 			break;
 	}
@@ -827,6 +825,9 @@
 	textInputStartRepeat(ascii);
 
 	switch (ascii) {
+	case(27): // esc
+		_textInput = false;
+		break;
 	case(8): // backspace
 		if (_textInputPos <= 1) {
 			break;
@@ -947,6 +948,9 @@
 	bool releasedButton;
 
 	_savePanel.currentButton = saveHitTest(mousePoint);	
+
+	validateSaveButtons();
+
 	releasedButton = (_savePanel.currentButton != NULL) && 
 		(_savePanel.currentButton->state > 0) && (!_vm->mouseButtonPressed());
 
@@ -961,8 +965,10 @@
 
 void Interface::handleSaveClick(const Point& mousePoint) {
 	_savePanel.currentButton = saveHitTest(mousePoint);
+	
+	validateSaveButtons();
 
-	_savePanel.zeroAllButtonState();
+	_savePanel.zeroAllButtonState();	
 	
 	if (_savePanel.currentButton == NULL) {
 		_textInput = false;
@@ -976,18 +982,41 @@
 }
 
 void Interface::setSave(PanelButton *panelButton) {
-/*	_savePanel.currentButton = NULL;
+	_savePanel.currentButton = NULL;
+	uint titleNumber;
+	char *fileName;
 	switch (panelButton->id) {
-		case kTextOK:
-			setMode(kPanelMain);
+		case kTextSave:
+			if (_textInputStringLength == 0 ) {
+				break;
+			}
+			if (!_vm->isSaveListFull() && (_optionSaveFileTitleNumber == 0)) {
+				if (_vm->locateSaveFile(_textInputString, titleNumber)) {
+					fileName = _vm->calcSaveFileName(_vm->getSaveFile(titleNumber)->slotNumber);
+					_vm->save(fileName, _textInputString);
+					_optionSaveFileTitleNumber = titleNumber;
+				} else {
+					fileName = _vm->calcSaveFileName(_vm->getNewSaveSlotNumber());
+					_vm->save(fileName, _textInputString);
+					_vm->fillSaveList();
+					calcOptionSaveSlider();
+				}
+			} else {
+				fileName = _vm->calcSaveFileName(_vm->getSaveFile(_optionSaveFileTitleNumber)->slotNumber);
+				_vm->save(fileName, _textInputString);
+			}
+			setMode(kPanelOption);
 			break;
-	}*/
+		case kTextCancel:
+			setMode(kPanelOption);
+			break;
+	}
 }
 
 void Interface::handleOptionUpdate(const Point& mousePoint) {
 	int16 mouseY;
 	Rect rect;	
-	int totalFiles = _vm->getSaveFileNameCount();
+	int totalFiles = _vm->getSaveFilesCount();
 	int visibleFiles = _vm->getDisplayInfo().optionSaveFileVisible; 
 	bool releasedButton;
 	
@@ -1004,12 +1033,15 @@
 					(_optionSaveFileSlider->height - _optionSaveRectSlider.height());
 			}
 
-			_optionSaveFileTop = clamp(0, _optionSaveFileTop, _vm->getSaveFileNameCount() - _vm->getDisplayInfo().optionSaveFileVisible);
+			_optionSaveFileTop = clamp(0, _optionSaveFileTop, _vm->getSaveFilesCount() - _vm->getDisplayInfo().optionSaveFileVisible);
 			calcOptionSaveSlider();
 		}
 	}
 
 	_optionPanel.currentButton = optionHitTest(mousePoint);	
+
+	validateOptionButtons();
+
 	releasedButton = (_optionPanel.currentButton != NULL) && (_optionPanel.currentButton->state > 0) && (!_vm->mouseButtonPressed());
 
 	if (!_vm->mouseButtonPressed()) {
@@ -1026,6 +1058,8 @@
 	Rect rect;
 	_optionPanel.currentButton = optionHitTest(mousePoint);
 
+	validateOptionButtons();
+
 	_optionPanel.zeroAllButtonState();
 
 	if (_optionPanel.currentButton == NULL) {
@@ -1039,14 +1073,14 @@
 			if ((_optionSaveRectBottom.height() > 0) && (mousePoint.y >= _optionSaveRectBottom.top)) {
 				_optionSaveFileTop += _vm->getDisplayInfo().optionSaveFileVisible;
 			} else {
-				if (_vm->getDisplayInfo().optionSaveFileVisible < _vm->getSaveFileNameCount()) {
+				if (_vm->getDisplayInfo().optionSaveFileVisible < _vm->getSaveFilesCount()) {
 					_optionSaveFileMouseOff = mousePoint.y - _optionSaveRectSlider.top;
 					_optionPanel.currentButton->state = 1;
 				}
 			}
 		}
 
-		_optionSaveFileTop = clamp(0, _optionSaveFileTop, _vm->getSaveFileNameCount() - _vm->getDisplayInfo().optionSaveFileVisible);
+		_optionSaveFileTop = clamp(0, _optionSaveFileTop, _vm->getSaveFilesCount() - _vm->getDisplayInfo().optionSaveFileVisible);
 		calcOptionSaveSlider();
 	} else {
 		if (_optionPanel.currentButton == _optionSaveFilePanel) {
@@ -1057,8 +1091,8 @@
 				_optionSaveFileTitleNumber = _vm->getDisplayInfo().optionSaveFileVisible - 1;
 			}
 			_optionSaveFileTitleNumber += _optionSaveFileTop;
-			if (_optionSaveFileTitleNumber >= _vm->getSaveFileNameCount()) {
-				_optionSaveFileTitleNumber = _vm->getSaveFileNameCount() - 1;
+			if (_optionSaveFileTitleNumber >= _vm->getSaveFilesCount()) {
+				_optionSaveFileTitleNumber = _vm->getSaveFilesCount() - 1;
 			}
 		} else {
 			_optionPanel.currentButton->state = 1;
@@ -1068,21 +1102,32 @@
 
 
 void Interface::setOption(PanelButton *panelButton) {
+	char * fileName;
 	_optionPanel.currentButton = NULL;
 	switch (panelButton->id) {
 		case kTextContinuePlaying:
-				setMode(kPanelMain);
-				break;
+			setMode(kPanelMain);
+			break;
 		case kTextQuitGame:
-				setMode(kPanelQuit);
-				break;
-		case kTextLoad:
-			//todo: load
-				setMode(kPanelLoad);
-				break;
+			setMode(kPanelQuit);
+			break;
+		case kTextLoad:			
+			if (_vm->getSaveFilesCount() > 0) {
+				if (_vm->isSaveListFull() || (_optionSaveFileTitleNumber > 0)) {
+					fileName = _vm->calcSaveFileName(_vm->getSaveFile(_optionSaveFileTitleNumber)->slotNumber);
+					_vm->load(fileName);
+					setMode(kPanelLoad);
+				}
+			}
+			break;
 		case kTextSave:
-				setMode(kPanelSave);
-				break;
+			if (!_vm->isSaveListFull() && (_optionSaveFileTitleNumber == 0)) {
+				_textInputString[0] = 0;
+			} else {
+				strcpy(_textInputString, _vm->getSaveFile(_optionSaveFileTitleNumber)->name);
+			}
+			setMode(kPanelSave);
+			break;
 	}
 }
 

Index: interface.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/interface.h,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- interface.h	29 May 2005 20:57:45 -0000	1.54
+++ interface.h	31 May 2005 20:08:45 -0000	1.55
@@ -321,6 +321,22 @@
 		}
 		return _verbTypeToPanelButton[verb];
 	}
+	
+	void validateOptionButtons() {
+		if (!_vm->isSaveListFull() && (_optionSaveFileTitleNumber == 0) && (_optionPanel.currentButton != NULL)) {
+			if (_optionPanel.currentButton->id == kTextLoad) {
+				_optionPanel.currentButton = NULL;
+			}
+		}
+	}
+	void validateSaveButtons() {
+		if ((_textInputStringLength == 0) && (_savePanel.currentButton != NULL)) {
+			if (_savePanel.currentButton->id == kTextSave) {
+				_savePanel.currentButton = NULL;
+			}
+		}
+	}
+
 private:
 	SagaEngine *_vm;
 

Index: saga.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/saga.h,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -d -r1.97 -r1.98
--- saga.h	29 May 2005 21:00:45 -0000	1.97
+++ saga.h	31 May 2005 20:08:46 -0000	1.98
@@ -456,6 +456,11 @@
 	}
 };
 
+struct SaveFileData {
+	char name[SAVE_TITLE_SIZE];
+	uint slotNumber;
+};
+
 
 inline int ticksToMSec(int tick) {
 	return tick * 1000 / kScriptTimeTicksPerSecond;
@@ -503,22 +508,20 @@
 	virtual ~SagaEngine();
 	void shutDown() { _quit = true; }
 
-	void save() { //TODO: remove
-		save("iteSCUMMVM.sav", "default");
-	}
-	void load() { //TODO: remove
-		load("iteSCUMMVM.sav");
-	}
 	void save(const char *fileName, const char *saveName);
 	void load(const char *fileName);
 	void fillSaveList();
 	char *calcSaveFileName(uint slotNumber);
-	char *getSaveFileName(uint idx);
-	bool saveListFull() const {
-		return _saveFileNamesMaxCount == _saveFileNamesCount;
+	
+	SaveFileData *getSaveFile(uint idx);
+	uint getSaveSlotNumber(uint idx);
+	uint getNewSaveSlotNumber();
+	bool locateSaveFile(char *saveName, uint &titleNumber);
+	bool isSaveListFull() const {
+		return _saveFilesMaxCount == _saveFilesCount;
 	}
-	uint getSaveFileNameCount() const {
-		return saveListFull() ? _saveFileNamesCount : _saveFileNamesCount + 1;
+	uint getSaveFilesCount() const {
+		return isSaveListFull() ? _saveFilesCount : _saveFilesCount + 1;
 	}
 
 	int _soundEnabled;
@@ -595,9 +598,12 @@
 
  private:
 	Common::String _targetName;
-	uint _saveFileNamesMaxCount;
-	uint _saveFileNamesCount;
-	char _saveFileNames[MAX_SAVES][SAVE_TITLE_SIZE];
+	
+	uint _saveFilesMaxCount;
+	uint _saveFilesCount;
+	SaveFileData _saveFiles[MAX_SAVES];
+	bool _saveMarks[MAX_SAVES];
+
 	Point _mousePos;
 	bool _leftMouseButtonPressed;
 	bool _rightMouseButtonPressed;

Index: saveload.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/saveload.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- saveload.cpp	28 May 2005 11:06:55 -0000	1.11
+++ saveload.cpp	31 May 2005 20:08:46 -0000	1.12
@@ -48,7 +48,9 @@
 	char name[SAVE_TITLE_SIZE];
 };
 
-static char emptySlot[] = "[New Save Game]";
+static SaveFileData emptySlot = {
+	 "[New Save Game]", 0
+};
 
 //TODO: 
 // - delete savegame
@@ -59,42 +61,72 @@
 	return name;
 }
 
-char *SagaEngine::getSaveFileName(uint idx) {
-	if (idx >= MAX_SAVES) {
+SaveFileData *SagaEngine::getSaveFile(uint idx) {
+	if (idx >= _saveFilesMaxCount) {
 		error("getSaveFileName wrong idx");
 	}
-	if (saveListFull()) {
-		return _saveFileNames[idx];
+	if (isSaveListFull()) {
+		return &_saveFiles[_saveFilesCount - idx - 1];
 	} else {
-		return (idx == 0) ? emptySlot : _saveFileNames[idx - 1];
+		return (idx == 0) ? &emptySlot : &_saveFiles[_saveFilesCount - idx];
 	}	
 }
 
+bool SagaEngine::locateSaveFile(char *saveName, uint &titleNumber) {
+	uint i;
+	for (i = 0; i < _saveFilesCount; i++) {
+		if (strcmp(saveName, _saveFiles[i].name) == 0) {
+			if (isSaveListFull()) {
+				titleNumber = _saveFilesCount - i - 1;
+			} else {
+				titleNumber = _saveFilesCount - i;
+			}
+			return true;
+		}
+	}
+	return false;
+}
+
+uint SagaEngine::getNewSaveSlotNumber() {
+	uint i;
+	uint saveCount;
+	if (isSaveListFull()) {
+		error("getNewSaveSlotNumber save list is full");
+	}
+	i = 0;
+	saveCount = 0;
+	while (saveCount < _saveFilesCount) {
+		if (_saveMarks[i++]) {
+			saveCount++;
+		}
+	}
+	return i;
+}
 
 void SagaEngine::fillSaveList() {
 	int i;
-	bool marks[MAX_SAVES];
 	Common::InSaveFile *in;
 	SaveGameHeader header;
 	char *name;
 	
 	name = calcSaveFileName(MAX_SAVES);
 	name[strlen(name) - 2] = 0;
-	_saveFileMan->listSavefiles(name, marks, MAX_SAVES);
+	_saveFileMan->listSavefiles(name, _saveMarks, MAX_SAVES);
 
-	_saveFileNamesMaxCount = 0;
+	_saveFilesMaxCount = 0;
 	for (i = 0; i < MAX_SAVES; i++) {
-		if (marks[i]) {
-			_saveFileNamesMaxCount++;
+		if (_saveMarks[i]) {
+			_saveFilesMaxCount++;
 		}
-		_saveFileNames[i][0] = 0;
+		_saveFiles[i].name[0] = 0;
+		_saveFiles[i].slotNumber = (uint)-1;
 	}	
 	
-	_saveFileNamesCount = 0;
+	_saveFilesCount = 0;
 	
 	i = 0;
 	while (i < MAX_SAVES) {
-		if (marks[i]) {
+		if (_saveMarks[i]) {
 			name = calcSaveFileName(i);
 			if (!(in = _saveFileMan->openForLoading(name))) {
 				break;
@@ -104,19 +136,21 @@
 			if (header.type != MKID('SAGA')) {
 				error("SagaEngine::load wrong format");
 			}
-			strcpy(_saveFileNames[_saveFileNamesCount], header.name);
+			strcpy(_saveFiles[_saveFilesCount].name, header.name);
+			_saveFiles[_saveFilesCount].slotNumber = i;
 			delete in;
-			_saveFileNamesCount++;
+			_saveFilesCount++;
 		}
 		i++;
 	}
-
-	for (i = 0; i < MAX_SAVES; i++) {
-		sprintf(_saveFileNames[i], "test%i",i);
-	}	
-
-	_saveFileNamesCount = 14;
-
+/* 4debug
+	for (i = 0; i < 14; i++) {
+		sprintf(_saveFiles[i].name,"test%i", i);
+		_saveFiles[i].slotNumber = i;
+	}
+	_saveFilesCount = 14;
+	_saveFilesMaxCount = 14;
+	*/
 }
 
 
@@ -200,10 +234,6 @@
 		_scene->clearSceneQueue();
 		_scene->changeScene(insetSceneNumber, ACTOR_NO_ENTRANCE, kTransitionNoFade);
 	}
-
-	// FIXME: When save/load screen will be implemented we should
-	// call these after that screen left by user
-	_interface->draw();
 }
 
 } // End of namespace Saga





More information about the Scummvm-git-logs mailing list