aboutsummaryrefslogtreecommitdiff
path: root/saga
diff options
context:
space:
mode:
authorAndrew Kurushin2005-05-31 20:08:46 +0000
committerAndrew Kurushin2005-05-31 20:08:46 +0000
commitd1ffc9df2d3a907e2de871a9b9b4c81d4af3e55c (patch)
tree34c1f55cf166a14a6785ad910050514feaaa199d /saga
parent55f98f9b041c4ef2e59215e9cbc2f5190f163cbe (diff)
downloadscummvm-rg350-d1ffc9df2d3a907e2de871a9b9b4c81d4af3e55c.tar.gz
scummvm-rg350-d1ffc9df2d3a907e2de871a9b9b4c81d4af3e55c.tar.bz2
scummvm-rg350-d1ffc9df2d3a907e2de871a9b9b4c81d4af3e55c.zip
multiple files save-load implementation
svn-id: r18303
Diffstat (limited to 'saga')
-rw-r--r--saga/input.cpp2
-rw-r--r--saga/interface.cpp101
-rw-r--r--saga/interface.h16
-rw-r--r--saga/saga.h34
-rw-r--r--saga/saveload.cpp84
5 files changed, 166 insertions, 71 deletions
diff --git a/saga/input.cpp b/saga/input.cpp
index e383ca2a3f..b3dfbad697 100644
--- a/saga/input.cpp
+++ b/saga/input.cpp
@@ -86,10 +86,8 @@ int SagaEngine::processInput() {
_render->toggleFlag(RF_ACTOR_PATH_TEST);
break;
case 288: // F7
- save();
break;
case 289: // F8
- load();
break;
case 9: // Tab
_script->SThreadDebugStep();
diff --git a/saga/interface.cpp b/saga/interface.cpp
index 95117c4b53..534d48a269 100644
--- a/saga/interface.cpp
+++ b/saga/interface.cpp
@@ -303,10 +303,8 @@ void Interface::setMode(int mode, bool force) {
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::draw() {
}
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 @@ void Interface::drawOption() {
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::handleLoadClick(const Point& mousePoint) {
void Interface::setLoad(PanelButton *panelButton) {
_loadPanel.currentButton = NULL;
switch (panelButton->id) {
- case kTextOK:
+ case kTextOK:
setMode(kPanelMain);
break;
}
@@ -827,6 +825,9 @@ void Interface::processTextInput(uint16 ascii) {
textInputStartRepeat(ascii);
switch (ascii) {
+ case(27): // esc
+ _textInput = false;
+ break;
case(8): // backspace
if (_textInputPos <= 1) {
break;
@@ -947,6 +948,9 @@ void Interface::handleSaveUpdate(const Point& mousePoint) {
bool releasedButton;
_savePanel.currentButton = saveHitTest(mousePoint);
+
+ validateSaveButtons();
+
releasedButton = (_savePanel.currentButton != NULL) &&
(_savePanel.currentButton->state > 0) && (!_vm->mouseButtonPressed());
@@ -961,8 +965,10 @@ void Interface::handleSaveUpdate(const Point& mousePoint) {
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::handleSaveClick(const Point& mousePoint) {
}
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 @@ void Interface::handleOptionUpdate(const Point& mousePoint) {
(_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 @@ void Interface::handleOptionClick(const Point& mousePoint) {
Rect rect;
_optionPanel.currentButton = optionHitTest(mousePoint);
+ validateOptionButtons();
+
_optionPanel.zeroAllButtonState();
if (_optionPanel.currentButton == NULL) {
@@ -1039,14 +1073,14 @@ void Interface::handleOptionClick(const Point& mousePoint) {
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 @@ void Interface::handleOptionClick(const Point& mousePoint) {
_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::handleOptionClick(const Point& mousePoint) {
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;
}
}
diff --git a/saga/interface.h b/saga/interface.h
index 7b6330bc39..cd20655e43 100644
--- a/saga/interface.h
+++ b/saga/interface.h
@@ -321,6 +321,22 @@ private:
}
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;
diff --git a/saga/saga.h b/saga/saga.h
index 087ced8354..3d620459d2 100644
--- a/saga/saga.h
+++ b/saga/saga.h
@@ -456,6 +456,11 @@ struct GameDescription {
}
};
+struct SaveFileData {
+ char name[SAVE_TITLE_SIZE];
+ uint slotNumber;
+};
+
inline int ticksToMSec(int tick) {
return tick * 1000 / kScriptTimeTicksPerSecond;
@@ -503,22 +508,20 @@ public:
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 @@ public:
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;
diff --git a/saga/saveload.cpp b/saga/saveload.cpp
index 18ed8d0f9b..a4bea7b657 100644
--- a/saga/saveload.cpp
+++ b/saga/saveload.cpp
@@ -48,7 +48,9 @@ struct SaveGameHeader {
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 @@ char* SagaEngine::calcSaveFileName(uint slotNumber) {
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 @@ void SagaEngine::fillSaveList() {
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 @@ void SagaEngine::load(const char *fileName) {
_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