Fix some preferences having incorrect defaults and made all preferences save

- SDF preferences, which are also stored in the save file, are only saved if you're at the startup screen
- Also fixed a crash when saving prefs
This commit is contained in:
2014-04-14 03:29:38 -04:00
parent a53c16c4a0
commit 45494d0c2e
3 changed files with 36 additions and 10 deletions

View File

@@ -1080,12 +1080,22 @@ void do_sign(short town_num, short which_sign, short sign_type,location sign_loc
} }
void load_prefs(){ void load_prefs(){
give_intro_hint = get_bool_pref("GiveIntroHint"); give_intro_hint = get_bool_pref("GiveIntroHint", true);
display_mode = get_int_pref("DisplayMode"); display_mode = get_int_pref("DisplayMode");
play_sounds = get_bool_pref("PlaySounds"); play_sounds = get_bool_pref("PlaySounds", true);
show_startup_splash = get_bool_pref("ShowStartupSplash"); show_startup_splash = get_bool_pref("ShowStartupSplash", true);
game_run_before = get_bool_pref("GameRunBefore"); game_run_before = get_bool_pref("GameRunBefore");
skip_boom_delay = get_bool_pref("SkipBoomDelay"); skip_boom_delay = get_bool_pref("SkipBoomDelay");
PSD[SDF_NO_MAPS] = !get_bool_pref("SaveAutoMap", true);
PSD[SDF_NO_FRILLS] = !get_bool_pref("DrawTerrainFrills", true);
PSD[SDF_NO_INSTANT_HELP] = !get_bool_pref("ShowInstantHelp", true);
PSD[SDF_NO_TER_ANIM] = !get_bool_pref("DrawTerrainAnimation", true);
PSD[SDF_NO_SHORE_FRILLS] = !get_bool_pref("DrawTerrainShoreFrills", true);
PSD[SDF_ROOM_DESCS_AGAIN] = get_bool_pref("RepeatRoomDescriptions");
PSD[SDF_EASY_MODE] = get_bool_pref("EasyMode");
PSD[SDF_LESS_WANDER_ENC] = get_bool_pref("LessWanderingMonsters");
PSD[SDF_GAME_SPEED] = get_int_pref("GameSpeed");
} }
void save_prefs(){ void save_prefs(){
@@ -1096,6 +1106,18 @@ void save_prefs(){
set_pref("GameRunBefore", game_run_before); set_pref("GameRunBefore", game_run_before);
set_pref("SkipBoomDelay", skip_boom_delay); set_pref("SkipBoomDelay", skip_boom_delay);
if(overall_mode == MODE_STARTUP) {
set_pref("SaveAutoMap", !PSD[SDF_NO_MAPS]);
set_pref("DrawTerrainFrills", !PSD[SDF_NO_FRILLS]);
set_pref("ShowInstantHelp", !PSD[SDF_NO_INSTANT_HELP]);
set_pref("DrawTerrainAnimation", !PSD[SDF_NO_TER_ANIM]);
set_pref("DrawTerrainShoreFrills", !PSD[SDF_NO_SHORE_FRILLS]);
set_pref("RepeatRoomDescriptions", bool(PSD[SDF_ROOM_DESCS_AGAIN]));
set_pref("EasyMode", bool(PSD[SDF_EASY_MODE]));
set_pref("LessWanderingMonsters", bool(PSD[SDF_LESS_WANDER_ENC]));
set_pref("GameSpeed", PSD[SDF_GAME_SPEED]);
}
bool success = sync_prefs(); bool success = sync_prefs();
if(!success){ if(!success){
giveError("There was a problem writing to the preferences file. When the game is next run the preferences will revert to their previously set values.","Should you manage to resolve the problem without closing the program, simply open the preferences screen and click \"OK\" to try again."); giveError("There was a problem writing to the preferences file. When the game is next run the preferences will revert to their previously set values.","Should you manage to resolve the problem without closing the program, simply open the preferences screen and click \"OK\" to try again.");

View File

@@ -13,10 +13,10 @@
#include <vector> #include <vector>
void set_pref(std::string keypath, bool value); void set_pref(std::string keypath, bool value);
bool get_bool_pref(std::string keypath); bool get_bool_pref(std::string keypath, bool fallback = false);
void set_pref(std::string keypath, int value); void set_pref(std::string keypath, int value);
int get_int_pref(std::string keypath); int get_int_pref(std::string keypath, int fallback = 0);
void append_iarray_pref(std::string keypath, int value); void append_iarray_pref(std::string keypath, int value);
std::vector<int> get_iarray_pref(std::string keypath); std::vector<int> get_iarray_pref(std::string keypath);

View File

@@ -14,23 +14,27 @@
NSString* convertKey(std::string keypath) { NSString* convertKey(std::string keypath) {
NSString* key = [NSString stringWithCString: keypath.c_str() encoding: NSASCIIStringEncoding]; NSString* key = [NSString stringWithCString: keypath.c_str() encoding: NSASCIIStringEncoding];
return [key autorelease]; return key;
} }
void set_pref(std::string keypath, bool value) { void set_pref(std::string keypath, bool value) {
[[NSUserDefaults standardUserDefaults] setBool: value forKey: convertKey(keypath)]; [[NSUserDefaults standardUserDefaults] setBool: value forKey: convertKey(keypath)];
} }
bool get_bool_pref(std::string keypath) { bool get_bool_pref(std::string keypath, bool fallback) {
return [[NSUserDefaults standardUserDefaults] boolForKey: convertKey(keypath)]; id val = [[NSUserDefaults standardUserDefaults] objectForKey: convertKey(keypath)];
if([val isKindOfClass: [NSNumber class]]) return [val boolValue];
return fallback;
} }
void set_pref(std::string keypath, int value) { void set_pref(std::string keypath, int value) {
[[NSUserDefaults standardUserDefaults] setInteger: value forKey: convertKey(keypath)]; [[NSUserDefaults standardUserDefaults] setInteger: value forKey: convertKey(keypath)];
} }
int get_int_pref(std::string keypath) { int get_int_pref(std::string keypath, int fallback) {
return [[NSUserDefaults standardUserDefaults] integerForKey: convertKey(keypath)]; id val = [[NSUserDefaults standardUserDefaults] objectForKey: convertKey(keypath)];
if([val isKindOfClass: [NSNumber class]]) return [val intValue];
return fallback;
} }
void append_iarray_pref(std::string keypath, int value) { void append_iarray_pref(std::string keypath, int value) {