aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra
diff options
context:
space:
mode:
Diffstat (limited to 'engines/kyra')
-rw-r--r--engines/kyra/gui.cpp15
-rw-r--r--engines/kyra/gui.h3
-rw-r--r--engines/kyra/gui_v1.cpp12
-rw-r--r--engines/kyra/gui_v2.cpp18
4 files changed, 39 insertions, 9 deletions
diff --git a/engines/kyra/gui.cpp b/engines/kyra/gui.cpp
index f851bcf066..d0151f0ed5 100644
--- a/engines/kyra/gui.cpp
+++ b/engines/kyra/gui.cpp
@@ -298,6 +298,21 @@ int GUI::redrawShadedButtonCallback(Button *button) {
return 0;
}
+void GUI::updateSaveList() {
+ Common::String pattern = _vm->_targetName + ".???";
+ Common::StringList saveFileList = _vm->_saveFileMan->listSavefiles(pattern.c_str());
+ Common::sort(saveFileList.begin(), saveFileList.end());
+ _saveSlots.clear();
+
+ for (Common::StringList::const_iterator i = saveFileList.begin(); i != saveFileList.end(); ++i) {
+ char s1 = 0, s2 = 0, s3 = 0;
+ s1 = (*i)[i->size()-3] - '0';
+ s2 = (*i)[i->size()-2] - '0';
+ s3 = (*i)[i->size()-1] - '0';
+ _saveSlots.push_back(s1*100+s2*10+s3);
+ }
+}
+
int GUI::getNextSavegameSlot() {
Common::InSaveFile *in;
diff --git a/engines/kyra/gui.h b/engines/kyra/gui.h
index ae0ec2014a..17f13469e9 100644
--- a/engines/kyra/gui.h
+++ b/engines/kyra/gui.h
@@ -30,6 +30,7 @@
#include "kyra/kyra.h"
#include "common/ptr.h"
+#include "common/array.h"
namespace Kyra {
@@ -185,6 +186,8 @@ protected:
void redrawText(const Menu &menu);
void redrawHighlight(const Menu &menu);
+ Common::Array<int> _saveSlots;
+ void updateSaveList();
int getNextSavegameSlot();
};
diff --git a/engines/kyra/gui_v1.cpp b/engines/kyra/gui_v1.cpp
index 96449e31b4..711ecba214 100644
--- a/engines/kyra/gui_v1.cpp
+++ b/engines/kyra/gui_v1.cpp
@@ -613,12 +613,12 @@ void GUI_v1::setupSavegames(Menu &menu, int num) {
}
KyraEngine::SaveHeader header;
- for (int i = startSlot; i < num; i++) {
- if ((in = _vm->openSaveForReading(_vm->getSavegameFilename(i + _savegameOffset), header))) {
+ for (int i = startSlot; i < num && uint(_savegameOffset + i) < _saveSlots.size(); i++) {
+ if ((in = _vm->openSaveForReading(_vm->getSavegameFilename(_saveSlots[i + _savegameOffset]), header))) {
strncpy(savenames[i], header.description.c_str(), 31);
menu.item[i].itemString = savenames[i];
menu.item[i].enabled = 1;
- menu.item[i].saveSlot = i + _savegameOffset;
+ menu.item[i].saveSlot = _saveSlots[i + _savegameOffset];
delete in;
} else {
menu.item[i].enabled = 0;
@@ -630,6 +630,8 @@ void GUI_v1::setupSavegames(Menu &menu, int num) {
int GUI_v1::saveGameMenu(Button *button) {
debugC(9, kDebugLevelGUI, "GUI_v1::saveGameMenu()");
+ updateSaveList();
+
updateMenuButton(button);
_menu[2].item[5].enabled = true;
@@ -671,6 +673,8 @@ int GUI_v1::saveGameMenu(Button *button) {
int GUI_v1::loadGameMenu(Button *button) {
debugC(9, kDebugLevelGUI, "GUI_v1::loadGameMenu()");
+ updateSaveList();
+
if (_vm->_menuDirectlyToLoad) {
_menu[2].item[5].enabled = false;
} else {
@@ -1101,6 +1105,8 @@ int GUI_v1::scrollDown(Button *button) {
updateMenuButton(button);
_savegameOffset++;
+ if (uint(_savegameOffset + 5) >= _saveSlots.size())
+ _savegameOffset = MAX<int>(_saveSlots.size() - 5, 0);
setupSavegames(_menu[2], 5);
initMenu(_menu[2]);
diff --git a/engines/kyra/gui_v2.cpp b/engines/kyra/gui_v2.cpp
index e87c149a21..78705fdfb5 100644
--- a/engines/kyra/gui_v2.cpp
+++ b/engines/kyra/gui_v2.cpp
@@ -1396,10 +1396,10 @@ void GUI_v2::setupSavegameNames(Menu &menu, int num) {
KyraEngine::SaveHeader header;
Common::InSaveFile *in;
- for (int i = startSlot; i < num; ++i) {
- if ((in = _vm->openSaveForReading(_vm->getSavegameFilename(i + _savegameOffset), header)) != 0) {
+ for (int i = startSlot; i < num && uint(_savegameOffset + i) < _saveSlots.size(); ++i) {
+ if ((in = _vm->openSaveForReading(_vm->getSavegameFilename(_saveSlots[i + _savegameOffset]), header)) != 0) {
strncpy(_vm->getTableString(menu.item[i].itemId, _vm->_optionsBuffer, 0), header.description.c_str(), 80);
- menu.item[i].saveSlot = i + _savegameOffset;
+ menu.item[i].saveSlot = _saveSlots[i + _savegameOffset];
menu.item[i].enabled = true;
delete in;
}
@@ -1421,10 +1421,9 @@ void GUI_v2::setupSavegameNames(Menu &menu, int num) {
}
int GUI_v2::scrollUpButton(Button *button) {
- int startSlot = _isSaveMenu ? 1 : 0;
updateMenuButton(button);
- if (_savegameOffset <= startSlot)
+ if (_savegameOffset == 0)
return 0;
--_savegameOffset;
@@ -1444,6 +1443,10 @@ int GUI_v2::scrollUpButton(Button *button) {
int GUI_v2::scrollDownButton(Button *button) {
updateMenuButton(button);
++_savegameOffset;
+
+ if (uint(_savegameOffset + 5) >= _saveSlots.size())
+ _savegameOffset = MAX<int>(_saveSlots.size() - 5, 0);
+
if (_isLoadMenu) {
setupSavegameNames(_loadMenu, 5);
// original calls something different here...
@@ -1737,6 +1740,8 @@ void GUI_v2::drawSliderBar(int slider, const uint8 *shape) {
}
int GUI_v2::loadMenu(Button *caller) {
+ updateSaveList();
+
if (!_vm->_menuDirectlyToLoad) {
updateMenuButton(caller);
restorePage1(_vm->_screenBuffer);
@@ -1803,7 +1808,8 @@ int GUI_v2::cancelLoadMenu(Button *caller) {
}
int GUI_v2::saveMenu(Button *caller) {
- //XXX
+ updateSaveList();
+
updateMenuButton(caller);
restorePage1(_vm->_screenBuffer);