Rewrite prefs loading/saving to use Cocoa
This commit is contained in:
@@ -497,6 +497,7 @@
|
||||
91E5C7B80F9F619D00C21460 /* talking.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91E5C7B70F9F619D00C21460 /* talking.cpp */; };
|
||||
91E5C7B90F9F619D00C21460 /* talking.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91E5C7B70F9F619D00C21460 /* talking.cpp */; };
|
||||
91E5C7BA0F9F619D00C21460 /* talking.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91E5C7B70F9F619D00C21460 /* talking.cpp */; };
|
||||
91EC483B18FBAD8000BB1E86 /* prefs.mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 91EC481018FBABB100BB1E86 /* prefs.mac.mm */; };
|
||||
91F6F8E318F87F3700E3EA15 /* sfml-audio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 91F6F8DD18F87F3700E3EA15 /* sfml-audio.framework */; };
|
||||
91F6F8E418F87F3700E3EA15 /* sfml-audio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 91F6F8DD18F87F3700E3EA15 /* sfml-audio.framework */; };
|
||||
91F6F8E518F87F3700E3EA15 /* sfml-audio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 91F6F8DD18F87F3700E3EA15 /* sfml-audio.framework */; };
|
||||
@@ -1481,6 +1482,8 @@
|
||||
91E5C7A60F9F615400C21460 /* fileio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fileio.cpp; sourceTree = "<group>"; };
|
||||
91E5C7B60F9F619D00C21460 /* talking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = talking.h; sourceTree = "<group>"; };
|
||||
91E5C7B70F9F619D00C21460 /* talking.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = talking.cpp; sourceTree = "<group>"; };
|
||||
91EC480E18FBAA8700BB1E86 /* prefs.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = prefs.hpp; sourceTree = "<group>"; };
|
||||
91EC481018FBABB100BB1E86 /* prefs.mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = prefs.mac.mm; sourceTree = "<group>"; };
|
||||
91F6F8DD18F87F3700E3EA15 /* sfml-audio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = "sfml-audio.framework"; path = "../../../../../../Library/Frameworks/sfml-audio.framework"; sourceTree = "<group>"; };
|
||||
91F6F8DE18F87F3700E3EA15 /* sfml-graphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = "sfml-graphics.framework"; path = "../../../../../../Library/Frameworks/sfml-graphics.framework"; sourceTree = "<group>"; };
|
||||
91F6F8DF18F87F3700E3EA15 /* sfml-network.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = "sfml-network.framework"; path = "../../../../../../Library/Frameworks/sfml-network.framework"; sourceTree = "<group>"; };
|
||||
@@ -1930,6 +1933,7 @@
|
||||
91B3F10F0F9779D000BF5B67 /* soundtool.cpp */,
|
||||
912283C80FD0E16C00B21642 /* undo.cpp */,
|
||||
919145FF18E63B70005CF3A4 /* winutil.mac.mm */,
|
||||
91EC481018FBABB100BB1E86 /* prefs.mac.mm */,
|
||||
);
|
||||
name = src;
|
||||
sourceTree = "<group>";
|
||||
@@ -1945,6 +1949,7 @@
|
||||
91B3F10E0F9779D000BF5B67 /* soundtool.h */,
|
||||
917B573F100B956C0096C978 /* undo.h */,
|
||||
919145FE18E63B41005CF3A4 /* winutil.h */,
|
||||
91EC480E18FBAA8700BB1E86 /* prefs.hpp */,
|
||||
);
|
||||
name = headers;
|
||||
sourceTree = "<group>";
|
||||
@@ -2577,6 +2582,7 @@
|
||||
914B2AC618E7E6EB007B6799 /* winutil.mac.mm in Sources */,
|
||||
9107074C18F1D18400F7BD7F /* scrollbar.cpp in Sources */,
|
||||
91F6F8F618F8DE6300E3EA15 /* qdpict.cpp in Sources */,
|
||||
91EC483B18FBAD8000BB1E86 /* prefs.mac.mm in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@@ -33,10 +33,8 @@
|
||||
#include "button.h"
|
||||
#include "pict.h"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include "prefs.hpp"
|
||||
#define NUM_HINTS 30
|
||||
// TODO: This is used for plist preferences; maybe that should be changed
|
||||
#include <CoreFoundation/CFPreferences.h>
|
||||
#include <CoreFoundation/CFNumber.h>
|
||||
|
||||
//extern big_tr_type t_d;
|
||||
extern short stat_window;
|
||||
@@ -1082,258 +1080,28 @@ void do_sign(short town_num, short which_sign, short sign_type,location sign_loc
|
||||
}
|
||||
|
||||
void load_prefs(){
|
||||
Boolean b, valid;
|
||||
CFIndex x;
|
||||
b = CFPreferencesGetAppBooleanValue(CFSTR("GiveIntroHint"), CFSTR("com.spidweb.bladesofexile"), &valid);
|
||||
if(valid) give_intro_hint = b;
|
||||
x = CFPreferencesGetAppIntegerValue(CFSTR("DisplayMode"), CFSTR("com.spidweb.bladesofexile"), &valid);
|
||||
if(valid) display_mode = x;
|
||||
b = CFPreferencesGetAppBooleanValue(CFSTR("PlaySounds"), CFSTR("com.spidweb.bladesofexile"), &valid);
|
||||
if(valid) play_sounds = b;
|
||||
b = CFPreferencesGetAppBooleanValue(CFSTR("ShowStartupSplash"), CFSTR("com.spidweb.bladesofexile"), &valid);
|
||||
if(valid) show_startup_splash = b;
|
||||
b = CFPreferencesGetAppBooleanValue(CFSTR("GameRunBefore"), CFSTR("com.spidweb.bladesofexile"), &valid);
|
||||
if(valid) game_run_before = b;
|
||||
b = CFPreferencesGetAppBooleanValue(CFSTR("SkipBoomDelay"), CFSTR("com.spidweb.bladesofexile"), &valid);
|
||||
if(valid) skip_boom_delay = b;
|
||||
give_intro_hint = get_bool_pref("GiveIntroHint");
|
||||
display_mode = get_int_pref("DisplayMode");
|
||||
play_sounds = get_bool_pref("PlaySounds");
|
||||
show_startup_splash = get_bool_pref("ShowStartupSplash");
|
||||
game_run_before = get_bool_pref("GameRunBefore");
|
||||
skip_boom_delay = get_bool_pref("SkipBoomDelay");
|
||||
}
|
||||
|
||||
//void check_pref_file() {
|
||||
// short num_tries = 0;
|
||||
//
|
||||
// while ((num_tries < 300) && (open_pref_file() == -100))
|
||||
// num_tries++;
|
||||
//
|
||||
// if (num_tries == 300) {
|
||||
// Alert(983,NULL);
|
||||
// ExitToShell();
|
||||
// }
|
||||
// }
|
||||
|
||||
//long open_pref_file()
|
||||
//{
|
||||
// char pref_name[256];
|
||||
// short vol_ref = 0;
|
||||
// long dir_ID = 0,stored_key;
|
||||
// FSSpec pref;
|
||||
// short file_ref_num;
|
||||
// PrefHandle data_handle;
|
||||
//
|
||||
// GetIndString(pref_name,5,19);
|
||||
// FindFolder(kOnSystemDisk,kPreferencesFolderType,
|
||||
// kDontCreateFolder,&vol_ref,&dir_ID);
|
||||
// FSMakeFSSpec(vol_ref,dir_ID,pref_name,&pref);
|
||||
// file_ref_num = FSpOpenResFile(&pref,fsCurPerm);
|
||||
// if (file_ref_num == -1) {
|
||||
// game_run_before = false;
|
||||
// save_prefs();
|
||||
// //make_pref_file(pref);
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// UseResFile(file_ref_num);
|
||||
// data_handle = (PrefHandle) Get1Resource('PRFN',128);
|
||||
//
|
||||
// if ((**data_handle).l[1] != 0)
|
||||
// ask_to_change_color = true;
|
||||
// else ask_to_change_color = false;
|
||||
// if ((**data_handle).l[2] != 0)
|
||||
// give_intro_hint = true;
|
||||
// else give_intro_hint = false;
|
||||
// display_mode = (short) ((**data_handle).l[3]);
|
||||
// play_sounds = (short) ((**data_handle).l[4]);
|
||||
// register_flag = (long) (800000) - (**data_handle).l[5];
|
||||
// stored_key = (long) (700000) - (**data_handle).l[7];
|
||||
// ed_flag = (long) (800000) - (**data_handle).l[6];
|
||||
// ed_key = (long) (700000) - (**data_handle).l[8];
|
||||
//
|
||||
// if ((registered == true) && (stored_key != init_data(register_flag))) {
|
||||
// display_mode = 0;
|
||||
// CloseResFile(file_ref_num);
|
||||
// save_prefs();
|
||||
// return -100;
|
||||
// }
|
||||
// if ((stored_key != init_data(register_flag)) && ((register_flag < 10000) || (register_flag > 30000)
|
||||
// || (display_mode < 0) || (display_mode > 5) || (ed_flag < 0) || (ed_flag > 10000)) ) {
|
||||
// registered = false;
|
||||
// if ((register_flag < 10000) || (register_flag > 30000))
|
||||
// register_flag = get_ran(1,10000,30000);
|
||||
// if ((ed_flag < 0) || (ed_flag > 10000))
|
||||
// ed_flag = 10000;
|
||||
//
|
||||
// stored_key = 0;
|
||||
// display_mode = 0;
|
||||
// CloseResFile(file_ref_num);
|
||||
// save_prefs();
|
||||
// return -100;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// CloseResFile(file_ref_num);
|
||||
//
|
||||
// return stored_key;
|
||||
//
|
||||
//}
|
||||
|
||||
//void make_pref_file(FSSpec pref)
|
||||
//{
|
||||
// short file_ref_num;
|
||||
// Handle app_handle;
|
||||
// short res_ID;
|
||||
// ResType res_type;
|
||||
// char res_name[256] = "xxx";
|
||||
// short res_attributes;
|
||||
//
|
||||
//
|
||||
//// rf = CurResFile();
|
||||
//// UseResFile(rf);
|
||||
//// app_handle = Get1Resource('PRFN',128);
|
||||
//
|
||||
//// for (i = 0; i < 10; i++)
|
||||
//// (**(PrefHandle)app_handle).l[i] = (long) (get_ran(1,-20000,20000)) * (i + 2);
|
||||
//// (**(PrefHandle)app_handle).l[2] = (long) (give_intro_hint);
|
||||
//// (**(PrefHandle)app_handle).l[3] = (long) (display_mode);
|
||||
//// (**(PrefHandle)app_handle).l[4] = (long) (play_sounds);
|
||||
//
|
||||
//// if (register_flag == 0) {
|
||||
//// register_flag = (long) get_ran(1,10000,20000);
|
||||
//// ed_flag = get_ran(1,5000,9999);
|
||||
//// }
|
||||
//
|
||||
// // Amputating this code, cause it's broken, while save prefs code works OK
|
||||
//
|
||||
//// (**(PrefHandle)app_handle).l[5] = (long) (800000) - register_flag;
|
||||
//// if (registered == true)
|
||||
//// (**(PrefHandle)app_handle).l[7] = (long) (700000) - init_data(register_flag);
|
||||
//
|
||||
//// (**(PrefHandle)app_handle).l[6] = (long) (800000) - ed_flag;
|
||||
//// if (ed_reg == true)
|
||||
//// (**(PrefHandle)app_handle).l[8] = (long) (700000) - init_data(ed_flag);
|
||||
//
|
||||
//// GetResInfo((Handle) app_handle,&res_ID,&res_type,res_name);
|
||||
//// res_attributes = GetResAttrs(app_handle);
|
||||
//// DetachResource(app_handle);
|
||||
// FSpCreateResFile(&pref,'blx!','BLPR',smSystemScript);
|
||||
//// save_prefs();
|
||||
// return;
|
||||
//
|
||||
//// FSpCreateResFile(&pref,'RSED','rsrc',smSystemScript);
|
||||
// file_ref_num = FSpOpenResFile(&pref,fsCurPerm);
|
||||
//
|
||||
// UseResFile(file_ref_num);
|
||||
// AddResource(app_handle,res_type,res_ID,res_name);
|
||||
// SetResAttrs(app_handle,res_attributes);
|
||||
// ChangedResource(app_handle);
|
||||
// WriteResource(app_handle);
|
||||
// ReleaseResource(app_handle);
|
||||
// CloseResFile(file_ref_num);
|
||||
//
|
||||
//}
|
||||
|
||||
void save_prefs(){
|
||||
CFPreferencesSetAppValue(
|
||||
CFSTR("GiveIntroHint"),
|
||||
give_intro_hint ? kCFBooleanTrue : kCFBooleanFalse,
|
||||
CFSTR("com.spidweb.bladesofexile")
|
||||
);
|
||||
CFPreferencesSetAppValue(
|
||||
CFSTR("DisplayMode"),
|
||||
CFNumberCreate(NULL, kCFNumberShortType, &display_mode),
|
||||
CFSTR("com.spidweb.bladesofexile")
|
||||
);
|
||||
CFPreferencesSetAppValue(
|
||||
CFSTR("PlaySounds"),
|
||||
play_sounds ? kCFBooleanTrue : kCFBooleanFalse,
|
||||
CFSTR("com.spidweb.bladesofexile")
|
||||
);
|
||||
CFPreferencesSetAppValue(
|
||||
CFSTR("ShowStartupSplash"),
|
||||
show_startup_splash ? kCFBooleanTrue : kCFBooleanFalse,
|
||||
CFSTR("com.spidweb.bladesofexile")
|
||||
);
|
||||
CFPreferencesSetAppValue(
|
||||
CFSTR("GameRunBefore"),
|
||||
game_run_before ? kCFBooleanTrue : kCFBooleanFalse,
|
||||
CFSTR("com.spidweb.bladesofexile")
|
||||
);
|
||||
CFPreferencesSetAppValue(
|
||||
CFSTR("SkipBoomDelay"),
|
||||
skip_boom_delay ? kCFBooleanTrue : kCFBooleanFalse,
|
||||
CFSTR("com.spidweb.bladesofexile")
|
||||
);
|
||||
set_pref("GiveIntroHint", give_intro_hint);
|
||||
set_pref("DisplayMode", display_mode);
|
||||
set_pref("PlaySounds", play_sounds);
|
||||
set_pref("ShowStartupSplash", show_startup_splash);
|
||||
set_pref("GameRunBefore", game_run_before);
|
||||
set_pref("SkipBoomDelay", skip_boom_delay);
|
||||
|
||||
bool success = CFPreferencesAppSynchronize (CFSTR("com.spidweb.bladesofexile"));
|
||||
bool success = sync_prefs();
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
//void save_prefs()
|
||||
//{
|
||||
// short file_ref_num;
|
||||
// Handle old_handle,data_handle;
|
||||
// short vol_ref,i;
|
||||
// short res_ID;
|
||||
// long dir_ID;
|
||||
// ResType res_type = 'PRFN';
|
||||
// char res_name[256];
|
||||
// short res_attributes;
|
||||
// FSSpec pref;
|
||||
// short app_res_num;
|
||||
// char pref_name[256];
|
||||
//
|
||||
// app_res_num = CurResFile();
|
||||
//
|
||||
// GetIndString(pref_name,5,19);
|
||||
// if (sys_7_avail == true)
|
||||
// FindFolder(kOnSystemDisk,kPreferencesFolderType,
|
||||
// kDontCreateFolder,&vol_ref,&dir_ID);
|
||||
// FSMakeFSSpec(vol_ref,dir_ID,pref_name,&pref);
|
||||
// file_ref_num = FSpOpenResFile(&pref,fsCurPerm);
|
||||
// if (file_ref_num == -1) {
|
||||
// make_pref_file(pref);
|
||||
// file_ref_num = FSpOpenResFile(&pref,fsCurPerm);
|
||||
//// return;
|
||||
// }
|
||||
//
|
||||
// UseResFile(file_ref_num);
|
||||
//
|
||||
// data_handle = NewHandleClear(sizeof(PrefRecord));
|
||||
// HLock(data_handle);
|
||||
//
|
||||
// for (i = 0; i < 10; i++)
|
||||
// (**(PrefHandle)data_handle).l[i] = (long) (get_ran(1,-20000,20000)) * (i + 2);
|
||||
// (**(PrefHandle)data_handle).l[1] = (long) (ask_to_change_color);
|
||||
// (**(PrefHandle)data_handle).l[2] = (long) (give_intro_hint);
|
||||
// (**(PrefHandle)data_handle).l[3] = (long) (display_mode);
|
||||
// (**(PrefHandle)data_handle).l[4] = (long) (play_sounds);
|
||||
//
|
||||
//
|
||||
// if (register_flag == 0) {
|
||||
// register_flag = (long) get_ran(1,10000,20000);
|
||||
// ed_flag = get_ran(1,5000,9999);
|
||||
// }
|
||||
// (**(PrefHandle)data_handle).l[5] = (long) (800000) - register_flag;
|
||||
// (**(PrefHandle)data_handle).l[6] = (long) (800000) - ed_flag;
|
||||
// if (registered == true)
|
||||
// (**(PrefHandle)data_handle).l[7] = (long) (700000) - init_data(register_flag);
|
||||
// if (ed_reg == true)
|
||||
// (**(PrefHandle)data_handle).l[8] = (long) (700000) - init_data(ed_flag);
|
||||
//
|
||||
// old_handle = Get1Resource('PRFN',128);
|
||||
// GetResInfo(old_handle,&res_ID,&res_type,res_name);
|
||||
// res_attributes = GetResAttrs(old_handle);
|
||||
// RemoveResource(old_handle);
|
||||
//
|
||||
// AddResource(data_handle,'PRFN',128,res_name);
|
||||
// WriteResource(data_handle);
|
||||
// HUnlock(data_handle);
|
||||
// ReleaseResource(data_handle);
|
||||
//
|
||||
// CloseResFile(file_ref_num);
|
||||
// UseResFile(app_res_num);
|
||||
//}
|
||||
|
||||
bool prefs_event_filter (cDialog& me, std::string id, eKeyMod mods)
|
||||
{
|
||||
// TODO: I should no longer need done_yet as this now only handles the okay and cancel buttons; the LEDs are now handled automatically by the cLed class (and the cLedGroup class, for LED groups).
|
||||
|
27
osx/tools/prefs.hpp
Normal file
27
osx/tools/prefs.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// prefs.hpp
|
||||
// BoE
|
||||
//
|
||||
// Created by Celtic Minstrel on 14-04-14.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef BoE_prefs_hpp
|
||||
#define BoE_prefs_hpp
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void set_pref(std::string keypath, bool value);
|
||||
bool get_bool_pref(std::string keypath);
|
||||
|
||||
void set_pref(std::string keypath, int value);
|
||||
int get_int_pref(std::string keypath);
|
||||
|
||||
void append_iarray_pref(std::string keypath, int value);
|
||||
std::vector<int> get_iarray_pref(std::string keypath);
|
||||
|
||||
void clear_pref(std::string keypath);
|
||||
bool sync_prefs();
|
||||
|
||||
#endif
|
61
osx/tools/prefs.mac.mm
Normal file
61
osx/tools/prefs.mac.mm
Normal file
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// prefs.mac.mm
|
||||
// BoE
|
||||
//
|
||||
// Created by Celtic Minstrel on 14-04-14.
|
||||
//
|
||||
//
|
||||
|
||||
#include "prefs.hpp"
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <unordered_map>
|
||||
|
||||
//static const CFStringRef prefsID = CFSTR("com.spidweb.bladesofexile");
|
||||
|
||||
NSString* convertKey(std::string keypath) {
|
||||
NSString* key = [NSString stringWithCString: keypath.c_str() encoding: NSASCIIStringEncoding];
|
||||
return [key autorelease];
|
||||
}
|
||||
|
||||
void set_pref(std::string keypath, bool value) {
|
||||
[[NSUserDefaults standardUserDefaults] setBool: value forKey: convertKey(keypath)];
|
||||
}
|
||||
|
||||
bool get_bool_pref(std::string keypath) {
|
||||
return [[NSUserDefaults standardUserDefaults] boolForKey: convertKey(keypath)];
|
||||
}
|
||||
|
||||
void set_pref(std::string keypath, int value) {
|
||||
[[NSUserDefaults standardUserDefaults] setInteger: value forKey: convertKey(keypath)];
|
||||
}
|
||||
|
||||
int get_int_pref(std::string keypath) {
|
||||
return [[NSUserDefaults standardUserDefaults] integerForKey: convertKey(keypath)];
|
||||
}
|
||||
|
||||
void append_iarray_pref(std::string keypath, int value) {
|
||||
NSString* key = convertKey(keypath);
|
||||
NSArray* list = [[NSUserDefaults standardUserDefaults] arrayForKey: key];
|
||||
NSNumber* num = [NSNumber numberWithInt: value];
|
||||
if(list == nil)
|
||||
[[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObject: num] forKey: key] ;
|
||||
else [[NSUserDefaults standardUserDefaults] setObject: [list arrayByAddingObject: num] forKey: key];
|
||||
}
|
||||
|
||||
std::vector<int> get_iarray_pref(std::string keypath) {
|
||||
NSArray* list = [[NSUserDefaults standardUserDefaults] arrayForKey: convertKey(keypath)];
|
||||
if(list == nil) return {};
|
||||
std::vector<int> result;
|
||||
for(size_t i = 0; i < [list count]; i++)
|
||||
result.push_back([[list objectAtIndex: i] intValue]);
|
||||
return result;
|
||||
}
|
||||
|
||||
void clear_pref(std::string keypath) {
|
||||
[[NSUserDefaults standardUserDefaults] setNilValueForKey: convertKey(keypath)];
|
||||
}
|
||||
|
||||
bool sync_prefs() {
|
||||
return [[NSUserDefaults standardUserDefaults] synchronize];
|
||||
}
|
||||
|
Reference in New Issue
Block a user