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