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
)change
:(id)sender
65 [self interfaceUpdate
];
69 - (IBAction
)revert
:(id)sender
71 [self initialInterfaceSetup
];
74 - (IBAction
)apply
:(id)sender
76 TCGlobalPlaySounds
= [playSoundsButton state
];
77 [[NSUserDefaults standardUserDefaults
] setBool
:TCGlobalPlaySounds forKey
:TCPlaySoundsPref
];
79 // send window information to the delegate so the necessary adjustments can be made
80 [delegate preferenceSetWindowsOnTop
:[windowsOnTopButton state
]];
82 TCGlobalWindowsOnTop
= [windowsOnTopButton state
];
83 [[NSUserDefaults standardUserDefaults
] setBool
:TCGlobalWindowsOnTop forKey
:TCWindowsOnTopPref
];
85 TCGlobalUpdateCheck
= [updateAutomaticallyButton state
];
86 [[NSUserDefaults standardUserDefaults
] setBool
:TCGlobalUpdateCheck forKey
:TCUpdateCheckPref
];
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
]];
91 TCGlobalAllowRemote
= [allowRemoteButton state
];
92 [[NSUserDefaults standardUserDefaults
] setBool
:TCGlobalAllowRemote forKey
:TCAllowRemotePref
];
94 TCGlobalListenPort
= [listenPortTextField intValue
];
95 [[NSUserDefaults standardUserDefaults
] setObject
:[NSNumber numberWithInt
:TCGlobalListenPort
] forKey
:TCListenPortPref
];
97 [[NSUserDefaults standardUserDefaults
] setObject
:[broadcastNameTextField stringValue
] forKey
:TCBroadcastNamePref
];
99 TCGlobalHitsDisplayed
= [hitsDisplayedTextField intValue
];
100 [[NSUserDefaults standardUserDefaults
] setObject
:[NSNumber numberWithInt
:TCGlobalHitsDisplayed
] forKey
:TCHitsDisplayedPref
];
104 - (IBAction
)cancel
:(id)sender
106 [self initialInterfaceSetup
];
110 - (IBAction
)save
:(id)sender