]> Dogcows Code - chaz/thecheat/blob - PreferenceController.m
4b603622eca9dab99750b6d35a3845657485e64e
[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)playSoundsButton:(id)sender
64 {
65 if ( [playSoundsButton state] == NSOnState )
66 {
67 TCGlobalPlaySounds = YES;
68 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:TCPlaySoundsPref];
69 }
70 else
71 {
72 TCGlobalPlaySounds = NO;
73 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:TCPlaySoundsPref];
74 }
75 }
76
77 - (IBAction)windowsOnTopButton:(id)sender
78 {
79 if ( [windowsOnTopButton state] == NSOnState )
80 {
81 TCGlobalWindowsOnTop = YES;
82 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:TCWindowsOnTopPref];
83 }
84 else
85 {
86 TCGlobalWindowsOnTop = NO;
87 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:TCWindowsOnTopPref];
88 }
89
90 [[NSNotificationCenter defaultCenter] postNotificationName:@"TCWindowsOnTopChanged" object:nil];
91 }
92
93 - (IBAction)updateAutomaticallyButton:(id)sender
94 {
95 if ( [updateAutomaticallyButton state] == NSOnState )
96 {
97 TCGlobalUpdateCheck = YES;
98 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:TCUpdateCheckPref];
99 }
100 else
101 {
102 TCGlobalUpdateCheck = NO;
103 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:TCUpdateCheckPref];
104 }
105 }
106
107 - (IBAction)allowRemoteButton:(id)sender
108 {
109 if ( [allowRemoteButton state] == NSOnState )
110 {
111 TCGlobalAllowRemote = YES;
112 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:TCAllowRemotePref];
113 }
114 else
115 {
116 TCGlobalAllowRemote = NO;
117 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:TCAllowRemotePref];
118 }
119
120 [self interfaceUpdate];
121
122 [delegate preferenceAllowRemoteChanged:TCGlobalAllowRemote];
123 }
124
125 - (IBAction)listenPortTextField:(id)sender
126 {
127 TCGlobalListenPort = [listenPortTextField intValue];
128
129 [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:TCGlobalListenPort] forKey:TCListenPortPref];
130
131 [delegate preferenceListenPortChanged:TCGlobalListenPort];
132 }
133
134 - (IBAction)broadcastNameTextField:(id)sender
135 {
136 NSString *name = [broadcastNameTextField stringValue];
137
138 [[NSUserDefaults standardUserDefaults] setObject:name forKey:TCBroadcastNamePref];
139
140 [delegate preferenceBroadcastNameChanged:name];
141 }
142
143 - (IBAction)hitsDisplayedTextField:(id)sender
144 {
145 TCGlobalHitsDisplayed = [hitsDisplayedTextField intValue];
146
147 [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:TCGlobalHitsDisplayed] forKey:TCHitsDisplayedPref];
148 }
149 */
150
151
152 - (IBAction)change:(id)sender
153 {
154 [self interfaceUpdate];
155 }
156
157
158 - (IBAction)revert:(id)sender
159 {
160 [self initialInterfaceSetup];
161 }
162
163 - (IBAction)cancel:(id)sender
164 {
165 [self initialInterfaceSetup];
166 [self close];
167 }
168
169 - (IBAction)save:(id)sender
170 {
171 TCGlobalPlaySounds = [playSoundsButton state];
172 [[NSUserDefaults standardUserDefaults] setBool:TCGlobalPlaySounds forKey:TCPlaySoundsPref];
173
174 // send window information to the delegate so the necessary adjustments can be made
175 [delegate preferenceSetWindowsOnTop:[windowsOnTopButton state]];
176
177 TCGlobalWindowsOnTop = [windowsOnTopButton state];
178 [[NSUserDefaults standardUserDefaults] setBool:TCGlobalWindowsOnTop forKey:TCWindowsOnTopPref];
179
180 TCGlobalUpdateCheck = [updateAutomaticallyButton state];
181 [[NSUserDefaults standardUserDefaults] setBool:TCGlobalUpdateCheck forKey:TCUpdateCheckPref];
182
183 // send server information to the delegate so the server can be updated accordingly
184 [delegate preferenceSetAllowRemote:[allowRemoteButton state] listenPort:[listenPortTextField intValue] broadcastName:[broadcastNameTextField stringValue]];
185
186 TCGlobalAllowRemote = [allowRemoteButton state];
187 [[NSUserDefaults standardUserDefaults] setBool:TCGlobalAllowRemote forKey:TCAllowRemotePref];
188
189 TCGlobalListenPort = [listenPortTextField intValue];
190 [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:TCGlobalListenPort] forKey:TCListenPortPref];
191
192 [[NSUserDefaults standardUserDefaults] setObject:[broadcastNameTextField stringValue] forKey:TCBroadcastNamePref];
193
194 TCGlobalHitsDisplayed = [hitsDisplayedTextField intValue];
195 [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:TCGlobalHitsDisplayed] forKey:TCHitsDisplayedPref];
196
197 [self close];
198 }
199
200
201 @end
This page took 0.036082 seconds and 3 git commands to generate.