2 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // File: PreferenceController.m
6 // Created: Wed Sep 24 2003
8 // Copyright: 2003 Chaz McGarvey. All rights reserved.
9 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 #import "PreferenceController.h"
14 @implementation PreferenceController
17 - (id)initWithDelegate
:(id)del
19 if ( self = [super initWithWindowNibName
:@
"Preferences"] )
21 [self setWindowFrameAutosaveName
:@
"TCPreferencWindowPosition"];
31 [self initialInterfaceSetup
];
35 - (void)initialInterfaceSetup
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
];
45 [self interfaceUpdate
];
48 - (void)interfaceUpdate
50 if ( [allowRemoteButton state
] )
52 [listenPortTextField setEnabled
:YES
];
53 [broadcastNameTextField setEnabled
:YES
];
57 [listenPortTextField setEnabled
:NO
];
58 [broadcastNameTextField setEnabled
:NO
];
63 - (IBAction)playSoundsButton:(id)sender
65 if ( [playSoundsButton state] == NSOnState )
67 TCGlobalPlaySounds = YES;
68 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:TCPlaySoundsPref];
72 TCGlobalPlaySounds = NO;
73 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:TCPlaySoundsPref];
77 - (IBAction)windowsOnTopButton:(id)sender
79 if ( [windowsOnTopButton state] == NSOnState )
81 TCGlobalWindowsOnTop = YES;
82 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:TCWindowsOnTopPref];
86 TCGlobalWindowsOnTop = NO;
87 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:TCWindowsOnTopPref];
90 [[NSNotificationCenter defaultCenter] postNotificationName:@"TCWindowsOnTopChanged" object:nil];
93 - (IBAction)updateAutomaticallyButton:(id)sender
95 if ( [updateAutomaticallyButton state] == NSOnState )
97 TCGlobalUpdateCheck = YES;
98 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:TCUpdateCheckPref];
102 TCGlobalUpdateCheck = NO;
103 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:TCUpdateCheckPref];
107 - (IBAction)allowRemoteButton:(id)sender
109 if ( [allowRemoteButton state] == NSOnState )
111 TCGlobalAllowRemote = YES;
112 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:TCAllowRemotePref];
116 TCGlobalAllowRemote = NO;
117 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:TCAllowRemotePref];
120 [self interfaceUpdate];
122 [delegate preferenceAllowRemoteChanged:TCGlobalAllowRemote];
125 - (IBAction)listenPortTextField:(id)sender
127 TCGlobalListenPort = [listenPortTextField intValue];
129 [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:TCGlobalListenPort] forKey:TCListenPortPref];
131 [delegate preferenceListenPortChanged:TCGlobalListenPort];
134 - (IBAction)broadcastNameTextField:(id)sender
136 NSString *name = [broadcastNameTextField stringValue];
138 [[NSUserDefaults standardUserDefaults] setObject:name forKey:TCBroadcastNamePref];
140 [delegate preferenceBroadcastNameChanged:name];
143 - (IBAction)hitsDisplayedTextField:(id)sender
145 TCGlobalHitsDisplayed = [hitsDisplayedTextField intValue];
147 [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:TCGlobalHitsDisplayed] forKey:TCHitsDisplayedPref];
152 - (IBAction
)change
:(id)sender
154 [self interfaceUpdate
];
158 - (IBAction
)revert
:(id)sender
160 [self initialInterfaceSetup
];
163 - (IBAction
)cancel
:(id)sender
165 [self initialInterfaceSetup
];
169 - (IBAction
)save
:(id)sender
171 TCGlobalPlaySounds
= [playSoundsButton state
];
172 [[NSUserDefaults standardUserDefaults
] setBool
:TCGlobalPlaySounds forKey
:TCPlaySoundsPref
];
174 // send window information to the delegate so the necessary adjustments can be made
175 [delegate preferenceSetWindowsOnTop
:[windowsOnTopButton state
]];
177 TCGlobalWindowsOnTop
= [windowsOnTopButton state
];
178 [[NSUserDefaults standardUserDefaults
] setBool
:TCGlobalWindowsOnTop forKey
:TCWindowsOnTopPref
];
180 TCGlobalUpdateCheck
= [updateAutomaticallyButton state
];
181 [[NSUserDefaults standardUserDefaults
] setBool
:TCGlobalUpdateCheck forKey
:TCUpdateCheckPref
];
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
]];
186 TCGlobalAllowRemote
= [allowRemoteButton state
];
187 [[NSUserDefaults standardUserDefaults
] setBool
:TCGlobalAllowRemote forKey
:TCAllowRemotePref
];
189 TCGlobalListenPort
= [listenPortTextField intValue
];
190 [[NSUserDefaults standardUserDefaults
] setObject
:[NSNumber numberWithInt
:TCGlobalListenPort
] forKey
:TCListenPortPref
];
192 [[NSUserDefaults standardUserDefaults
] setObject
:[broadcastNameTextField stringValue
] forKey
:TCBroadcastNamePref
];
194 TCGlobalHitsDisplayed
= [hitsDisplayedTextField intValue
];
195 [[NSUserDefaults standardUserDefaults
] setObject
:[NSNumber numberWithInt
:TCGlobalHitsDisplayed
] forKey
:TCHitsDisplayedPref
];