mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-28 15:12:36 +00:00
Possibly get preferences working.
This commit is contained in:
parent
40e39ca77b
commit
8cf5dc2737
2 changed files with 63 additions and 40 deletions
|
@ -39,6 +39,8 @@ extern float lightaxis[3];
|
||||||
id xlight_i; // X-side lighting
|
id xlight_i; // X-side lighting
|
||||||
id ylight_i; // Y-side lighting
|
id ylight_i; // Y-side lighting
|
||||||
id zlight_i; // Z-side lighting
|
id zlight_i; // Z-side lighting
|
||||||
|
|
||||||
|
NSUserDefaults *prefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
-readDefaults;
|
-readDefaults;
|
||||||
|
@ -46,8 +48,8 @@ extern float lightaxis[3];
|
||||||
//
|
//
|
||||||
// validate and set methods called by UI or defaults
|
// validate and set methods called by UI or defaults
|
||||||
//
|
//
|
||||||
-setProjectPath:(char *) path;
|
-setProjectPath:(const char *) path;
|
||||||
-setBspSoundPath:(char *) path; // set the path of the soundfile
|
-setBspSoundPath:(const char *) path; // set the path of the soundfile
|
||||||
// externally
|
// externally
|
||||||
-setShowBSP:(int) state; // set the state of ShowBSP
|
-setShowBSP:(int) state; // set the state of ShowBSP
|
||||||
-setBrushOffset:(int) state; // set the state of BrushOffset
|
-setBrushOffset:(int) state; // set the state of BrushOffset
|
||||||
|
|
|
@ -12,15 +12,46 @@ float lightaxis[3] = { 1, 0.6, 0.75 };
|
||||||
|
|
||||||
@implementation Preferences
|
@implementation Preferences
|
||||||
|
|
||||||
|
void
|
||||||
|
WriteStringDefault (id prefs, const char *name, const char *value)
|
||||||
|
{
|
||||||
|
NSString *key = [NSString stringWithCString: name];
|
||||||
|
NSString *val = [NSString stringWithCString: value];
|
||||||
|
[prefs setObject:val forKey:key];
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
WriteNumericDefault (id prefs, const char *name, float value)
|
||||||
|
{
|
||||||
|
char str[128];
|
||||||
|
|
||||||
|
sprintf (str, "%f", value);
|
||||||
|
WriteStringDefault (prefs, name, str);
|
||||||
|
}
|
||||||
|
|
||||||
-init
|
-init
|
||||||
{
|
{
|
||||||
[super init];
|
[super init];
|
||||||
preferences_i = self;
|
preferences_i = self;
|
||||||
|
|
||||||
|
NSMutableDictionary *defaults = [NSMutableDictionary dictionary];
|
||||||
|
|
||||||
|
WriteStringDefault (defaults, "ProjectPath", "");
|
||||||
|
WriteStringDefault (defaults, "BspSoundPath", "");
|
||||||
|
WriteNumericDefault (defaults, "ShowBSPOutput", NO);
|
||||||
|
WriteNumericDefault (defaults, "OffsetBrushCopy", NO);
|
||||||
|
WriteNumericDefault (defaults, "StartWad", 0);
|
||||||
|
WriteNumericDefault (defaults, "Xlight", 0);
|
||||||
|
WriteNumericDefault (defaults, "Ylight", 0);
|
||||||
|
WriteNumericDefault (defaults, "Zlight", 0);
|
||||||
|
|
||||||
|
prefs = [[NSUserDefaults standardUserDefaults] retain];
|
||||||
|
[prefs registerDefaults:defaults];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
_atoi (char *c)
|
_atoi (const char *c)
|
||||||
{
|
{
|
||||||
if (!c)
|
if (!c)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -28,72 +59,62 @@ _atoi (char *c)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
_atof (char *c)
|
_atof (const char *c)
|
||||||
{
|
{
|
||||||
if (!c)
|
if (!c)
|
||||||
return 0;
|
return 0;
|
||||||
return atof (c);
|
return atof (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
WriteNumericDefault (char *name, float value)
|
|
||||||
{
|
|
||||||
char str[128];
|
|
||||||
|
|
||||||
sprintf (str, "%f", value);
|
|
||||||
// XXX NSWriteDefault (DEFOWNER, name, str);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
WriteStringDefault (char *name, char *value)
|
|
||||||
{
|
|
||||||
// XXX NSWriteDefault (DEFOWNER, name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Read in at start of program
|
// Read in at start of program
|
||||||
//
|
//
|
||||||
-readDefaults
|
-readDefaults
|
||||||
{
|
{
|
||||||
char *string = "";
|
const char *string;
|
||||||
float value = 0;
|
float value = 0;
|
||||||
|
|
||||||
// XXX string = (char *)NSGetDefaultValue(DEFOWNER,"ProjectPath");
|
string = [[prefs stringForKey: @"ProjectPath"] cString];
|
||||||
[self setProjectPath:string];
|
[self setProjectPath:string];
|
||||||
|
|
||||||
// XXX string = (char *)NSGetDefaultValue(DEFOWNER,"BspSoundPath");
|
string = [[prefs stringForKey: @"BspSoundPath"] cString];
|
||||||
[self setBspSoundPath:string];
|
[self setBspSoundPath:string];
|
||||||
|
|
||||||
// XXX value = _atoi((char *)NSGetDefaultValue(DEFOWNER,"ShowBSPOutput"));
|
string = [[prefs stringForKey: @"ShowBSPOutput"] cString];
|
||||||
|
value = _atoi (string);
|
||||||
[self setShowBSP:value];
|
[self setShowBSP:value];
|
||||||
|
|
||||||
// XXX value = _atoi((char
|
string = [[prefs stringForKey: @"OffsetBrushCopy"] cString];
|
||||||
// *)NSGetDefaultValue(DEFOWNER,"OffsetBrushCopy"));
|
value = _atoi (string);
|
||||||
[self setBrushOffset:value];
|
[self setBrushOffset:value];
|
||||||
|
|
||||||
// XXX value = _atoi((char *)NSGetDefaultValue(DEFOWNER,"StartWad"));
|
string = [[prefs stringForKey: @"StartWad"] cString];
|
||||||
|
value = _atoi (string);
|
||||||
[self setStartWad:value];
|
[self setStartWad:value];
|
||||||
|
|
||||||
// XXX value = _atof((char *)NSGetDefaultValue(DEFOWNER,"Xlight"));
|
string = [[prefs stringForKey: @"Xlight"] cString];
|
||||||
|
value = _atof (string);
|
||||||
[self setXlight:value];
|
[self setXlight:value];
|
||||||
|
|
||||||
// XXX value = _atof((char *)NSGetDefaultValue(DEFOWNER,"Ylight"));
|
string = [[prefs stringForKey: @"Ylight"] cString];
|
||||||
|
value = _atof (string);
|
||||||
[self setYlight:value];
|
[self setYlight:value];
|
||||||
|
|
||||||
// XXX value = _atof((char *)NSGetDefaultValue(DEFOWNER,"Zlight"));
|
string = [[prefs stringForKey: @"Zlight"] cString];
|
||||||
|
value = _atof (string);
|
||||||
[self setZlight:value];
|
[self setZlight:value];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
-setProjectPath:(char *) path
|
-setProjectPath:(const char *) path
|
||||||
{
|
{
|
||||||
if (!path)
|
if (!path)
|
||||||
path = "";
|
path = "";
|
||||||
strcpy (projectpath, path);
|
strcpy (projectpath, path);
|
||||||
[startproject_i setStringValue: [NSString stringWithCString:path]];
|
[startproject_i setStringValue: [NSString stringWithCString:path]];
|
||||||
WriteStringDefault ("ProjectPath", path);
|
WriteStringDefault (prefs, "ProjectPath", path);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +182,7 @@ WriteStringDefault (char *name, char *value)
|
||||||
//
|
//
|
||||||
// Set the bspSound path
|
// Set the bspSound path
|
||||||
//
|
//
|
||||||
-setBspSoundPath:(char *) path
|
-setBspSoundPath:(const char *) path
|
||||||
{
|
{
|
||||||
if (!path)
|
if (!path)
|
||||||
path = "";
|
path = "";
|
||||||
|
@ -177,7 +198,7 @@ WriteStringDefault (char *name, char *value)
|
||||||
|
|
||||||
[bspSoundField_i setStringValue: [NSString stringWithCString:bspSound]];
|
[bspSoundField_i setStringValue: [NSString stringWithCString:bspSound]];
|
||||||
|
|
||||||
WriteStringDefault ("BspSoundPath", bspSound);
|
WriteStringDefault (prefs, "BspSoundPath", bspSound);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -193,7 +214,7 @@ WriteStringDefault (char *name, char *value)
|
||||||
{
|
{
|
||||||
showBSP = state;
|
showBSP = state;
|
||||||
[showBSP_i setIntValue:state];
|
[showBSP_i setIntValue:state];
|
||||||
WriteNumericDefault ("ShowBSPOutput", showBSP);
|
WriteNumericDefault (prefs, "ShowBSPOutput", showBSP);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -218,7 +239,7 @@ WriteStringDefault (char *name, char *value)
|
||||||
{
|
{
|
||||||
brushOffset = state;
|
brushOffset = state;
|
||||||
[brushOffset_i setIntValue:state];
|
[brushOffset_i setIntValue:state];
|
||||||
WriteNumericDefault ("OffsetBrushCopy", state);
|
WriteNumericDefault (prefs, "OffsetBrushCopy", state);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +263,7 @@ WriteStringDefault (char *name, char *value)
|
||||||
|
|
||||||
[startwad_i selectCellAtRow: startwad column:0];
|
[startwad_i selectCellAtRow: startwad column:0];
|
||||||
|
|
||||||
WriteNumericDefault ("StartWad", value);
|
WriteNumericDefault (prefs, "StartWad", value);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +286,7 @@ WriteStringDefault (char *name, char *value)
|
||||||
xlight = 0.6;
|
xlight = 0.6;
|
||||||
lightaxis[1] = xlight;
|
lightaxis[1] = xlight;
|
||||||
[xlight_i setFloatValue:xlight];
|
[xlight_i setFloatValue:xlight];
|
||||||
WriteNumericDefault ("Xlight", xlight);
|
WriteNumericDefault (prefs, "Xlight", xlight);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +297,7 @@ WriteStringDefault (char *name, char *value)
|
||||||
ylight = 0.75;
|
ylight = 0.75;
|
||||||
lightaxis[2] = ylight;
|
lightaxis[2] = ylight;
|
||||||
[ylight_i setFloatValue:ylight];
|
[ylight_i setFloatValue:ylight];
|
||||||
WriteNumericDefault ("Ylight", ylight);
|
WriteNumericDefault (prefs, "Ylight", ylight);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +308,7 @@ WriteStringDefault (char *name, char *value)
|
||||||
zlight = 1;
|
zlight = 1;
|
||||||
lightaxis[0] = zlight;
|
lightaxis[0] = zlight;
|
||||||
[zlight_i setFloatValue:zlight];
|
[zlight_i setFloatValue:zlight];
|
||||||
WriteNumericDefault ("Zlight", zlight);
|
WriteNumericDefault (prefs, "Zlight", zlight);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue