Even more conversions to NSString

This commit is contained in:
Bill Currie 2010-10-09 10:02:05 +09:00
parent 12d79ba28d
commit c2644699a4
2 changed files with 33 additions and 76 deletions

View file

@ -49,7 +49,7 @@ extern float lightaxis[3];
// //
// validate and set methods called by UI or defaults // validate and set methods called by UI or defaults
// //
- (id) setProjectPath: (const char *)path; - (id) setProjectPath: (NSString *)path;
- (id) setBspSoundPath: (NSString *)path; // set the path of the soundfile - (id) setBspSoundPath: (NSString *)path; // set the path of the soundfile
- (id) setShowBSP: (int)state; // set the state of ShowBSP - (id) setShowBSP: (int)state; // set the state of ShowBSP
- (id) setBrushOffset: (int)state; // set the state of BrushOffset - (id) setBrushOffset: (int)state; // set the state of BrushOffset

View file

@ -17,18 +17,15 @@ float lightaxis[3] = {1, 0.6, 0.75};
@implementation Preferences @implementation Preferences
void void
WriteStringDefault (id prefs, const char *name, const char *value) WriteStringDefault (id prefs, NSString *name, NSString *value)
{ {
NSString *key = [NSString stringWithCString: name]; [prefs setObject: name forKey: value];
NSString *val = [NSString stringWithCString: value];
[prefs setObject: val forKey: key];
} }
void void
WriteNumericDefault (id prefs, const char *name, float value) WriteNumericDefault (id prefs, NSString *name, float value)
{ {
WriteStringDefault (prefs, name, va ("%f", value)); WriteStringDefault (prefs, name, [NSString stringWithFormat: @"%f", value]);
} }
- (id) init - (id) init
@ -38,86 +35,46 @@ WriteNumericDefault (id prefs, const char *name, float value)
NSMutableDictionary *defaults = [NSMutableDictionary dictionary]; NSMutableDictionary *defaults = [NSMutableDictionary dictionary];
WriteStringDefault (defaults, "ProjectPath", ""); WriteStringDefault (defaults, @"ProjectPath", @"");
WriteStringDefault (defaults, "BspSoundPath", ""); WriteStringDefault (defaults, @"BspSoundPath", @"");
WriteNumericDefault (defaults, "ShowBSPOutput", NO); WriteNumericDefault (defaults, @"ShowBSPOutput", NO);
WriteNumericDefault (defaults, "OffsetBrushCopy", NO); WriteNumericDefault (defaults, @"OffsetBrushCopy", NO);
WriteNumericDefault (defaults, "StartWad", 0); WriteNumericDefault (defaults, @"StartWad", 0);
WriteNumericDefault (defaults, "Xlight", 0); WriteNumericDefault (defaults, @"Xlight", 0);
WriteNumericDefault (defaults, "Ylight", 0); WriteNumericDefault (defaults, @"Ylight", 0);
WriteNumericDefault (defaults, "Zlight", 0); WriteNumericDefault (defaults, @"Zlight", 0);
prefs = [[NSUserDefaults standardUserDefaults] retain]; prefs = [[NSUserDefaults standardUserDefaults] retain];
[prefs registerDefaults: defaults]; [prefs registerDefaults: defaults];
return self; return self;
} }
int
_atoi (const char *c)
{
if (!c)
return 0;
return atoi (c);
}
int
_atof (const char *c)
{
if (!c)
return 0;
return atof (c);
}
// //
// Read in at start of program // Read in at start of program
// //
- (id) readDefaults - (id) readDefaults
{ {
const char *string; [self setProjectPath: [prefs stringForKey: @"ProjectPath"]];
float value = 0;
string = [[prefs stringForKey: @"ProjectPath"] cString];
[self setProjectPath: string];
[self setBspSoundPath: [prefs stringForKey: @"BspSoundPath"]]; [self setBspSoundPath: [prefs stringForKey: @"BspSoundPath"]];
string = [[prefs stringForKey: @"ShowBSPOutput"] cString]; [self setShowBSP: [[prefs stringForKey: @"ShowBSPOutput"] intValue]];
value = _atoi (string); [self setBrushOffset: [[prefs stringForKey: @"OffsetBrushCopy"] intValue]];
[self setShowBSP: value]; [self setStartWad: [[prefs stringForKey: @"StartWad"] intValue]];
string = [[prefs stringForKey: @"OffsetBrushCopy"] cString]; [self setXlight: [[prefs stringForKey: @"Xlight"] floatValue]];
value = _atoi (string); [self setYlight: [[prefs stringForKey: @"Ylight"] floatValue]];
[self setBrushOffset: value]; [self setZlight: [[prefs stringForKey: @"Zlight"] floatValue]];
string = [[prefs stringForKey: @"StartWad"] cString];
value = _atoi (string);
[self setStartWad: value];
string = [[prefs stringForKey: @"Xlight"] cString];
value = _atof (string);
[self setXlight: value];
string = [[prefs stringForKey: @"Ylight"] cString];
value = _atof (string);
[self setYlight: value];
string = [[prefs stringForKey: @"Zlight"] cString];
value = _atof (string);
[self setZlight: value];
return self; return self;
} }
- (id) setProjectPath: (const char *)path - (id) setProjectPath: (NSString *)path
{ {
if (!path) [path retain];
path = ""; [projectpath release];
projectpath = path;
projectpath = [NSString stringWithCString: path];
[startproject_i setStringValue: projectpath]; [startproject_i setStringValue: projectpath];
WriteStringDefault (prefs, "ProjectPath", path); WriteStringDefault (prefs, @"ProjectPath", projectpath);
return self; return self;
} }
@ -199,7 +156,7 @@ _atof (const char *c)
[bspSoundField_i setStringValue: bspSound]; [bspSoundField_i setStringValue: bspSound];
WriteStringDefault (prefs, "BspSoundPath", [bspSound cString]); WriteStringDefault (prefs, @"BspSoundPath", bspSound);
return self; return self;
} }
@ -215,7 +172,7 @@ _atof (const char *c)
{ {
showBSP = state; showBSP = state;
[showBSP_i setIntValue: state]; [showBSP_i setIntValue: state];
WriteNumericDefault (prefs, "ShowBSPOutput", showBSP); WriteNumericDefault (prefs, @"ShowBSPOutput", showBSP);
return self; return self;
} }
@ -239,7 +196,7 @@ _atof (const char *c)
{ {
brushOffset = state; brushOffset = state;
[brushOffset_i setIntValue: state]; [brushOffset_i setIntValue: state];
WriteNumericDefault (prefs, "OffsetBrushCopy", state); WriteNumericDefault (prefs, @"OffsetBrushCopy", state);
return self; return self;
} }
@ -263,7 +220,7 @@ _atof (const char *c)
[startwad_i selectCellAtRow: startwad column: 0]; [startwad_i selectCellAtRow: startwad column: 0];
WriteNumericDefault (prefs, "StartWad", value); WriteNumericDefault (prefs, @"StartWad", value);
return self; return self;
} }
@ -285,7 +242,7 @@ _atof (const char *c)
xlight = 0.6; xlight = 0.6;
lightaxis[1] = xlight; lightaxis[1] = xlight;
[xlight_i setFloatValue: xlight]; [xlight_i setFloatValue: xlight];
WriteNumericDefault (prefs, "Xlight", xlight); WriteNumericDefault (prefs, @"Xlight", xlight);
return self; return self;
} }
@ -296,7 +253,7 @@ _atof (const char *c)
ylight = 0.75; ylight = 0.75;
lightaxis[2] = ylight; lightaxis[2] = ylight;
[ylight_i setFloatValue: ylight]; [ylight_i setFloatValue: ylight];
WriteNumericDefault (prefs, "Ylight", ylight); WriteNumericDefault (prefs, @"Ylight", ylight);
return self; return self;
} }
@ -307,7 +264,7 @@ _atof (const char *c)
zlight = 1; zlight = 1;
lightaxis[0] = zlight; lightaxis[0] = zlight;
[zlight_i setFloatValue: zlight]; [zlight_i setFloatValue: zlight];
WriteNumericDefault (prefs, "Zlight", zlight); WriteNumericDefault (prefs, @"Zlight", zlight);
return self; return self;
} }
@ -340,7 +297,7 @@ Grab all the current UI state
{ {
Sys_Printf ("defaults updated\n"); Sys_Printf ("defaults updated\n");
[self setProjectPath: [[startproject_i stringValue] cString]]; [self setProjectPath: [startproject_i stringValue]];
[self setBspSoundPath: [bspSoundField_i stringValue]]; [self setBspSoundPath: [bspSoundField_i stringValue]];
[self setShowBSP: [showBSP_i intValue]]; [self setShowBSP: [showBSP_i intValue]];
[self setBrushOffset: [brushOffset_i intValue]]; [self setBrushOffset: [brushOffset_i intValue]];