mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-21 19:51:49 +00:00
ULTIMA8: Starting the game will now auto-load the previous used savegame
This commit is contained in:
parent
ccd043a096
commit
b2095095ed
@ -746,6 +746,26 @@ size_t String::findFirstOf(const char *chars, size_t pos) const {
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t String::findLastOf(char c, size_t pos) const {
|
||||
int start = (pos == npos) ? (int)_size - 1 : MIN((int)_size - 1, (int)pos);
|
||||
for (int idx = start; idx >= 0; --idx) {
|
||||
if ((*this)[idx] == c)
|
||||
return idx;
|
||||
}
|
||||
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t String::findLastOf(const char *chars, size_t pos) const {
|
||||
int start = (pos == npos) ? (int)_size - 1 : MIN((int)_size - 1, (int)pos);
|
||||
for (int idx = start; idx >= 0; --idx) {
|
||||
if (strchr(chars, (*this)[idx]))
|
||||
return idx;
|
||||
}
|
||||
|
||||
return npos;
|
||||
}
|
||||
|
||||
size_t String::findFirstNotOf(char c, size_t pos) const {
|
||||
for (uint idx = pos; idx < _size; ++idx) {
|
||||
if ((*this)[idx] != c)
|
||||
|
@ -332,6 +332,15 @@ public:
|
||||
return findFirstOf(chars.c_str(), pos);
|
||||
}
|
||||
|
||||
/** Find the last character in the string that's the specified character */
|
||||
size_t findLastOf(char c, size_t pos = npos) const;
|
||||
|
||||
/** Find the last character in the string that's in any of the passed characters */
|
||||
size_t findLastOf(const char *chars, size_t pos = npos) const;
|
||||
size_t findLastOf(const String &chars, size_t pos = npos) const {
|
||||
return findLastOf(chars.c_str(), pos);
|
||||
}
|
||||
|
||||
/** Find first character in the string that's not the specified character */
|
||||
size_t findFirstNotOf(char c, size_t pos = 0) const;
|
||||
|
||||
|
@ -37,6 +37,7 @@ ConfigFileManager::ConfigFileManager() {
|
||||
ConfigFileManager::~ConfigFileManager() {
|
||||
debugN(MM_INFO, "Destroying ConfigFileManager...\n");
|
||||
|
||||
ConfMan.flushToDisk();
|
||||
clear();
|
||||
_configFileManager = 0;
|
||||
}
|
||||
@ -145,38 +146,63 @@ bool ConfigFileManager::get(istring key, bool &ret) {
|
||||
}
|
||||
|
||||
void ConfigFileManager::set(istring key, string val) {
|
||||
INIFile *ini = findWriteINI(key);
|
||||
if (!ini) return;
|
||||
if (key.hasPrefix("settings/")) {
|
||||
Common::String subKey(key.c_str() + key.findLastOf('/') + 1);
|
||||
ConfMan.set(subKey, val);
|
||||
} else {
|
||||
INIFile *ini = findWriteINI(key);
|
||||
if (!ini) return;
|
||||
|
||||
ini->set(key, val);
|
||||
ini->set(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigFileManager::set(istring key, const char *val) {
|
||||
INIFile *ini = findWriteINI(key);
|
||||
if (!ini) return;
|
||||
if (key.hasPrefix("settings/")) {
|
||||
Common::String subKey(key.c_str() + key.findLastOf('/') + 1);
|
||||
ConfMan.set(subKey, val);
|
||||
} else {
|
||||
INIFile *ini = findWriteINI(key);
|
||||
if (!ini) return;
|
||||
|
||||
ini->set(key, val);
|
||||
ini->set(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigFileManager::set(istring key, int val) {
|
||||
INIFile *ini = findWriteINI(key);
|
||||
if (!ini) return;
|
||||
if (key.hasPrefix("settings/")) {
|
||||
Common::String subKey(key.c_str() + key.findLastOf('/') + 1);
|
||||
ConfMan.setInt(subKey, val);
|
||||
} else {
|
||||
INIFile *ini = findWriteINI(key);
|
||||
if (!ini) return;
|
||||
|
||||
ini->set(key, val);
|
||||
ini->set(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigFileManager::set(istring key, bool val) {
|
||||
INIFile *ini = findWriteINI(key);
|
||||
if (!ini) return;
|
||||
if (key.hasPrefix("settings/")) {
|
||||
Common::String subKey(key.c_str() + key.findLastOf('/') + 1);
|
||||
ConfMan.setBool(subKey, val);
|
||||
} else {
|
||||
INIFile *ini = findWriteINI(key);
|
||||
if (!ini) return;
|
||||
|
||||
ini->set(key, val);
|
||||
ini->set(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigFileManager::unset(istring key) {
|
||||
INIFile *ini = findWriteINI(key);
|
||||
if (!ini) return;
|
||||
if (key.hasPrefix("settings/")) {
|
||||
Common::String subKey(key.c_str() + key.findLastOf('/') + 1);
|
||||
ConfMan.set(subKey, "");
|
||||
} else {
|
||||
INIFile *ini = findWriteINI(key);
|
||||
if (!ini) return;
|
||||
|
||||
ini->unset(key);
|
||||
ini->unset(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -226,11 +226,10 @@ bool PentagramMenuGump::OnKeyDown(int key, int mod) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void PentagramMenuGump::ProcessCallback(Std::string gamename, int message) {
|
||||
void PentagramMenuGump::ProcessCallback(const Std::string &gameName, int message) {
|
||||
if (message != 0) {
|
||||
SettingManager *settingman = SettingManager::get_instance();
|
||||
settingman->set("lastSave", message != 1 ? message : -1);
|
||||
Ultima8Engine::get_instance()->changeGame(gamename);
|
||||
Ultima8Engine::get_instance()->handleAutoSave();
|
||||
Ultima8Engine::get_instance()->changeGame(gameName);
|
||||
}
|
||||
|
||||
UnhideGump();
|
||||
|
@ -100,7 +100,7 @@ private:
|
||||
Texture *_coversImage;
|
||||
Texture *_flagsImage;
|
||||
|
||||
void ProcessCallback(Std::string gamename, int message);
|
||||
void ProcessCallback(const Std::string &gameName, int message);
|
||||
};
|
||||
|
||||
} // End of namespace Ultima8
|
||||
|
@ -347,6 +347,9 @@ void Ultima8Engine::startupGame() {
|
||||
_audioMixer->openMidiOutput();
|
||||
|
||||
int saveSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1;
|
||||
if (saveSlot == -1)
|
||||
_settingMan->get("lastSave", saveSlot);
|
||||
|
||||
newGame(saveSlot);
|
||||
|
||||
pout << "-- Game Initialized --" << Std::endl << Std::endl;
|
||||
@ -1007,11 +1010,25 @@ bool Ultima8Engine::saveGame(int slot, const Std::string &desc, bool ignore_moda
|
||||
return false;
|
||||
}
|
||||
|
||||
_settingMan->set("lastSave", slot);
|
||||
|
||||
return saveGameState(slot, desc).getCode() == Common::kNoError;
|
||||
}
|
||||
|
||||
Common::Error Ultima8Engine::loadGameState(int slot) {
|
||||
Common::Error result = Shared::UltimaEngine::loadGameState(slot);
|
||||
_settingMan->set("lastSave", (result.getCode() == Common::kNoError) ? slot : -1);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Common::Error Ultima8Engine::saveGameState(int slot, const Common::String &desc, bool isAutosave) {
|
||||
Common::Error result = Shared::UltimaEngine::saveGameState(slot, desc, isAutosave);;
|
||||
|
||||
if (!isAutosave)
|
||||
_settingMan->set("lastSave", (result.getCode() == Common::kNoError) ? slot : -1);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Common::Error Ultima8Engine::saveGameStream(Common::WriteStream *stream, bool isAutosave) {
|
||||
// Hack - don't save mouse over status for gumps
|
||||
Gump *gump = _mouse->getMouseOverGump();
|
||||
@ -1191,7 +1208,8 @@ bool Ultima8Engine::newGame(int saveSlot) {
|
||||
|
||||
_game->startInitialUsecode(saveSlot);
|
||||
|
||||
_settingMan->set("lastSave", saveSlot);
|
||||
if (saveSlot == -1)
|
||||
_settingMan->set("lastSave", -1);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1212,14 +1230,12 @@ Common::Error Ultima8Engine::loadGameStream(Common::SeekableReadStream *stream)
|
||||
if (state == SavegameReader::SAVE_CORRUPT) {
|
||||
Error("Invalid or corrupt savegame", "Error Loading savegame");
|
||||
delete sg;
|
||||
_settingMan->set("lastSave", "");
|
||||
return Common::kReadingFailed;
|
||||
}
|
||||
|
||||
if (state != SavegameReader::SAVE_VALID) {
|
||||
Error("Unsupported savegame version", "Error Loading savegame");
|
||||
delete sg;
|
||||
_settingMan->set("lastSave", "");
|
||||
return Common::kReadingFailed;
|
||||
}
|
||||
|
||||
@ -1250,7 +1266,6 @@ Common::Error Ultima8Engine::loadGameStream(Common::SeekableReadStream *stream)
|
||||
}
|
||||
perr << message << Std::endl;
|
||||
#else
|
||||
_settingMan->set("lastSave", "");
|
||||
Error(message, "Error Loading savegame");
|
||||
return Common::kReadingFailed;
|
||||
#endif
|
||||
@ -1341,8 +1356,6 @@ Common::Error Ultima8Engine::loadGameStream(Common::SeekableReadStream *stream)
|
||||
|
||||
pout << "Done" << Std::endl;
|
||||
|
||||
_settingMan->set("lastSave", -1);
|
||||
|
||||
delete sg;
|
||||
return Common::kNoError;
|
||||
}
|
||||
|
@ -286,6 +286,16 @@ public:
|
||||
*/
|
||||
bool canSaveGameStateCurrently(bool isAutosave = false) override;
|
||||
|
||||
/**
|
||||
* Load a game
|
||||
*/
|
||||
Common::Error loadGameState(int slot) override;
|
||||
|
||||
/**
|
||||
* Saves the game
|
||||
*/
|
||||
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
|
||||
|
||||
/**
|
||||
* Load a game state
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user