]> Dogcows Code - chaz/thecheat/blob - PreferenceController.m
The Cheat 1.1.1
[chaz/thecheat] / PreferenceController.m
1
2 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 // Project: The Cheat
4 //
5 // File: PreferenceController.m
6 // Created: Wed Sep 24 2003
7 //
8 // Copyright: 2003 Chaz McGarvey. All rights reserved.
9 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10
11 #import "PreferenceController.h"
12
13
14 @implementation PreferenceController
15
16
17 - (id)initWithDelegate:(id)del
18 {
19 if ( self = [super initWithWindowNibName:@"Preferences"] )
20 {
21 [self setWindowFrameAutosaveName:@"TCPreferencWindowPosition"];
22
23 delegate = del;
24 }
25
26 return self;
27 }
28
29 - (void)windowDidLoad
30 {
31 [self initialInterfaceSetup];
32 }
33
34
35 - (void)initialInterfaceSetup
36 {
37 [playSoundsButton setState:(TCGlobalPlaySounds)? NSOnState:NSOffState];
38 [windowsOnTopButton setState:(TCGlobalWindowsOnTop)? NSOnState:NSOffState];
39 [updateAutomaticallyButton setState:(TCGlobalUpdateCheck)? NSOnState:NSOffState];
40 [allowRemoteButton setState:(TCGlobalAllowRemote)? NSOnState:NSOffState];
41 [listenPortTextField setIntValue:TCGlobalListenPort];
42 [broadcastNameTextField setStringValue:[[NSUserDefaults standardUserDefaults] objectForKey:TCBroadcastNamePref]];
43 [hitsDisplayedTextField setIntValue:TCGlobalHitsDisplayed];
44
45 [self interfaceUpdate];
46 }
47
48 - (void)interfaceUpdate
49 {
50 if ( [allowRemoteButton state] )
51 {
52 [listenPortTextField setEnabled:YES];
53 [broadcastNameTextField setEnabled:YES];
54 }
55 else
56 {
57 [listenPortTextField setEnabled:NO];
58 [broadcastNameTextField setEnabled:NO];
59 }
60 }
61
62
63 - (IBAction)change:(id)sender
64 {
65 [self interfaceUpdate];
66 }
67
68
69 - (IBAction)revert:(id)sender
70 {
71 [self initialInterfaceSetup];
72 }
73
74 - (IBAction)apply:(id)sender
75 {
76 TCGlobalPlaySounds = [playSoundsButton state];
77 [[NSUserDefaults standardUserDefaults] setBool:TCGlobalPlaySounds forKey:TCPlaySoundsPref];
78
79 // send window information to the delegate so the necessary adjustments can be made
80 [delegate preferenceSetWindowsOnTop:[windowsOnTopButton state]];
81
82 TCGlobalWindowsOnTop = [windowsOnTopButton state];
83 [[NSUserDefaults standardUserDefaults] setBool:TCGlobalWindowsOnTop forKey:TCWindowsOnTopPref];
84
85 TCGlobalUpdateCheck = [updateAutomaticallyButton state];
86 [[NSUserDefaults standardUserDefaults] setBool:TCGlobalUpdateCheck forKey:TCUpdateCheckPref];
87
88 // send server information to the delegate so the server can be updated accordingly
89 [delegate preferenceSetAllowRemote:[allowRemoteButton state] listenPort:[listenPortTextField intValue] broadcastName:[broadcastNameTextField stringValue]];
90
91 TCGlobalAllowRemote = [allowRemoteButton state];
92 [[NSUserDefaults standardUserDefaults] setBool:TCGlobalAllowRemote forKey:TCAllowRemotePref];
93
94 TCGlobalListenPort = [listenPortTextField intValue];
95 [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:TCGlobalListenPort] forKey:TCListenPortPref];
96
97 [[NSUserDefaults standardUserDefaults] setObject:[broadcastNameTextField stringValue] forKey:TCBroadcastNamePref];
98
99 TCGlobalHitsDisplayed = [hitsDisplayedTextField intValue];
100 [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:TCGlobalHitsDisplayed] forKey:TCHitsDisplayedPref];
101 }
102
103
104 - (IBAction)cancel:(id)sender
105 {
106 [self initialInterfaceSetup];
107 [self close];
108 }
109
110 - (IBAction)save:(id)sender
111 {
112 [self apply:self];
113 [self close];
114 }
115
116
117 @end
This page took 0.035122 seconds and 4 git commands to generate.