quakeforge/tools/Forge/Bundles/MapEdit/Preferences.m

316 lines
6.3 KiB
Mathematica
Raw Normal View History

#include <unistd.h>
2010-09-11 23:43:55 +00:00
#include "QF/sys.h"
#include "QF/va.h"
#include "Preferences.h"
#include "Map.h"
#include "QuakeEd.h"
#include "Project.h"
id preferences_i;
#define DEFOWNER "QuakeEd2"
float lightaxis[3] = {1, 0.6, 0.75};
@implementation Preferences
2010-09-11 12:08:21 +00:00
void
2010-10-09 01:02:05 +00:00
WriteStringDefault (id prefs, NSString *name, NSString *value)
2010-09-11 12:08:21 +00:00
{
2010-10-09 06:04:40 +00:00
[prefs setObject: value forKey: name];
2010-09-11 12:08:21 +00:00
}
void
2010-10-09 01:02:05 +00:00
WriteNumericDefault (id prefs, NSString *name, float value)
2010-09-11 12:08:21 +00:00
{
2010-10-09 01:02:05 +00:00
WriteStringDefault (prefs, name, [NSString stringWithFormat: @"%f", value]);
2010-09-11 12:08:21 +00:00
}
- (id) init
{
[super init];
preferences_i = self;
2010-09-11 12:08:21 +00:00
NSMutableDictionary *defaults = [NSMutableDictionary dictionary];
2010-09-11 12:08:21 +00:00
2010-10-09 01:02:05 +00:00
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);
2010-09-11 12:08:21 +00:00
prefs = [[NSUserDefaults standardUserDefaults] retain];
[prefs registerDefaults: defaults];
return self;
}
//
// Read in at start of program
//
- (id) readDefaults
{
2010-10-09 01:02:05 +00:00
[self setProjectPath: [prefs stringForKey: @"ProjectPath"]];
2010-10-09 00:49:35 +00:00
[self setBspSoundPath: [prefs stringForKey: @"BspSoundPath"]];
2010-10-09 01:02:05 +00:00
[self setShowBSP: [[prefs stringForKey: @"ShowBSPOutput"] intValue]];
[self setBrushOffset: [[prefs stringForKey: @"OffsetBrushCopy"] intValue]];
[self setStartWad: [[prefs stringForKey: @"StartWad"] intValue]];
2010-10-09 01:02:05 +00:00
[self setXlight: [[prefs stringForKey: @"Xlight"] floatValue]];
[self setYlight: [[prefs stringForKey: @"Ylight"] floatValue]];
[self setZlight: [[prefs stringForKey: @"Zlight"] floatValue]];
return self;
}
2010-10-09 01:02:05 +00:00
- (id) setProjectPath: (NSString *)path
{
2010-10-09 01:02:05 +00:00
[path retain];
[projectpath release];
projectpath = path;
2010-10-09 00:49:35 +00:00
[startproject_i setStringValue: projectpath];
2010-10-09 01:02:05 +00:00
WriteStringDefault (prefs, @"ProjectPath", projectpath);
return self;
}
- (id) setCurrentProject: sender
{
2010-10-05 14:48:56 +00:00
[startproject_i setStringValue: [project_i currentProjectFile]];
[self UIChanged: self];
return self;
}
2010-10-09 00:49:35 +00:00
- (NSString *) getProjectPath
{
return projectpath;
}
//
// ===============================================
// BSP sound stuff
// ===============================================
//
// Set the BSP sound using an OpenPanel
//
- (id) setBspSound: sender
{
id panel;
NSString *types[] = {@"snd"};
int rtn;
NSArray *filenames;
2010-10-09 00:49:35 +00:00
NSString *path, *file;
2010-09-11 12:08:21 +00:00
panel = [NSOpenPanel new];
2010-10-09 00:49:35 +00:00
path = [bspSound stringByDeletingLastPathComponent];
file = [bspSound lastPathComponent];
2010-10-09 00:49:35 +00:00
rtn = [panel runModalForDirectory: path file: file
types: [NSArray arrayWithObjects: types
count: 1]
];
if (rtn) {
filenames = [panel filenames];
2010-10-09 00:49:35 +00:00
[self setBspSoundPath: [filenames objectAtIndex: 0]];
[self playBspSound];
}
return self;
}
//
// Play the BSP sound
//
- (id) playBspSound
{
[bspSound_i play];
return self;
}
//
// Set the bspSound path
//
2010-10-09 00:49:35 +00:00
- (id) setBspSoundPath: (NSString *)path
{
2010-10-09 00:49:35 +00:00
[path retain];
[bspSound release];
bspSound = path;
if (bspSound_i) {
[bspSound_i release];
bspSound_i = nil;
}
2010-10-09 00:49:35 +00:00
if (access ([path cString], R_OK)) {
bspSound_i = [[NSSound alloc] initWithContentsOfFile: bspSound
byReference: YES];
}
if (!bspSound_i)
return self;
2010-10-09 00:49:35 +00:00
[bspSoundField_i setStringValue: bspSound];
2010-10-09 01:02:05 +00:00
WriteStringDefault (prefs, @"BspSoundPath", bspSound);
return self;
}
// ===============================================
// Show BSP Output management
// ===============================================
//
// Set the state
//
- (id) setShowBSP: (int)state
{
showBSP = state;
[showBSP_i setIntValue: state];
2010-10-09 01:02:05 +00:00
WriteNumericDefault (prefs, @"ShowBSPOutput", showBSP);
return self;
}
//
// Get the state
//
- (int) getShowBSP
{
return showBSP;
}
// ===============================================
// "Offset Brush ..." management
// ===============================================
//
// Set the state
//
- (id) setBrushOffset: (int)state
{
brushOffset = state;
[brushOffset_i setIntValue: state];
2010-10-09 01:02:05 +00:00
WriteNumericDefault (prefs, @"OffsetBrushCopy", state);
return self;
}
//
// Get the state
//
- (int) getBrushOffset
{
return brushOffset;
}
// ===============================================
// StartWad
// ===============================================
- (id) setStartWad: (int)value // set start wad (0-2)
{
startwad = value;
if (startwad < 0 || startwad > 2)
startwad = 0;
[startwad_i selectCellAtRow: startwad column: 0];
2010-10-09 01:02:05 +00:00
WriteNumericDefault (prefs, @"StartWad", value);
return self;
}
- (int) getStartWad
{
return startwad;
}
// ===============================================
// X,Y,Z light values
// ===============================================
//
// Set the state
//
- (id) setXlight: (float)value
{
xlight = value;
if (xlight < 0.25 || xlight > 1)
xlight = 0.6;
lightaxis[1] = xlight;
[xlight_i setFloatValue: xlight];
2010-10-09 01:02:05 +00:00
WriteNumericDefault (prefs, @"Xlight", xlight);
return self;
}
- (id) setYlight: (float)value
{
ylight = value;
if (ylight < 0.25 || ylight > 1)
ylight = 0.75;
lightaxis[2] = ylight;
[ylight_i setFloatValue: ylight];
2010-10-09 01:02:05 +00:00
WriteNumericDefault (prefs, @"Ylight", ylight);
return self;
}
- (id) setZlight: (float)value
{
zlight = value;
if (zlight < 0.25 || zlight > 1)
zlight = 1;
lightaxis[0] = zlight;
[zlight_i setFloatValue: zlight];
2010-10-09 01:02:05 +00:00
WriteNumericDefault (prefs, @"Zlight", zlight);
return self;
}
//
// Get the state
//
- (float) getXlight
{
return [xlight_i floatValue];
}
- (float) getYlight
{
return [ylight_i floatValue];
}
- (float) getZlight
{
return [zlight_i floatValue];
}
/*
============
UIChanged
Grab all the current UI state
============
*/
- (id) UIChanged: sender
{
2010-09-12 02:13:35 +00:00
Sys_Printf ("defaults updated\n");
2010-10-09 01:02:05 +00:00
[self setProjectPath: [startproject_i stringValue]];
2010-10-09 00:49:35 +00:00
[self setBspSoundPath: [bspSoundField_i stringValue]];
[self setShowBSP: [showBSP_i intValue]];
[self setBrushOffset: [brushOffset_i intValue]];
[self setStartWad: [startwad_i selectedRow]];
[self setXlight: [xlight_i floatValue]];
[self setYlight: [ylight_i floatValue]];
[self setZlight: [zlight_i floatValue]];
[map_i makeGlobalPerform: @selector (flushTextures)];
[quakeed_i updateAll];
return self;
}
@end