[dasher: 37/43] MacOS: Add Game Mode toggle - mutually exclusive with direct mode.



commit b6e9647a57afe2437ef2554333ec9718aa8e3dda
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Mon May 23 21:22:12 2011 +0100

    MacOS: Add Game Mode toggle - mutually exclusive with direct mode.

 Src/MacOSX/COSXDasherControl.h                     |    1 +
 Src/MacOSX/COSXDasherControl.mm                    |    6 +
 Src/MacOSX/DasherApp.h                             |    1 +
 Src/MacOSX/DasherApp.mm                            |   23 +++++
 .../English.lproj/MainMenu.nib/designable.nib      |  104 +++++++++++++++++++-
 .../English.lproj/MainMenu.nib/keyedobjects.nib    |  Bin 32759 -> 33605 bytes
 6 files changed, 133 insertions(+), 2 deletions(-)
---
diff --git a/Src/MacOSX/COSXDasherControl.h b/Src/MacOSX/COSXDasherControl.h
index 91c734f..7c6313b 100644
--- a/Src/MacOSX/COSXDasherControl.h
+++ b/Src/MacOSX/COSXDasherControl.h
@@ -54,6 +54,7 @@ public:
   void ClearAllContext();
   std::string GetContext(unsigned int iOffset, unsigned int iLength);
   virtual int GetFileSize(const std::string &strFileName);
+  void HandleEvent(int iParameter);
   void SetEdit(id<DasherEdit> pEdit);
 private:
   virtual void ScanAlphabetFiles(std::vector<std::string> &vFileList);
diff --git a/Src/MacOSX/COSXDasherControl.mm b/Src/MacOSX/COSXDasherControl.mm
index 075e66e..a2483b3 100644
--- a/Src/MacOSX/COSXDasherControl.mm
+++ b/Src/MacOSX/COSXDasherControl.mm
@@ -135,6 +135,12 @@ void COSXDasherControl::TimerFired(NSPoint p) {
   [[dasherApp dasherView] redisplay];
 }  
  
+void COSXDasherControl::HandleEvent(int iParameter) {
+  CDashIntfScreenMsgs::HandleEvent(iParameter);
+  if (iParameter == BP_GAME_MODE)
+    [dasherApp setGameModeOn:(GetBoolParameter(BP_GAME_MODE) ? NSOnState : NSOffState)];
+}
+
 void COSXDasherControl::SetEdit(id<DasherEdit> _dasherEdit) {
   //These both produce warnings, as release/retain are not defined in the DasherEdit protocol...(??)
   [dasherEdit release];
diff --git a/Src/MacOSX/DasherApp.h b/Src/MacOSX/DasherApp.h
index e366e30..cc6e873 100644
--- a/Src/MacOSX/DasherApp.h
+++ b/Src/MacOSX/DasherApp.h
@@ -36,6 +36,7 @@
   NSString *filename;
   BOOL modified;
 }
+ property BOOL gameModeOn;
 @property BOOL directMode;
 @property (readonly,retain) NSString *filename;
 @property BOOL modified;
diff --git a/Src/MacOSX/DasherApp.mm b/Src/MacOSX/DasherApp.mm
index 2003e53..26754e4 100644
--- a/Src/MacOSX/DasherApp.mm
+++ b/Src/MacOSX/DasherApp.mm
@@ -139,8 +139,31 @@ static NSString *FilenameToUntitledName = @"NilToUntitled";
   [[PreferencesController preferencesController] makeKeyAndOrderFront:sender];
 }
 
+-(BOOL)gameModeOn {
+  return aquaDasherControl->GetBoolParameter(BP_GAME_MODE);
+}
+
+-(void)setGameModeOn:(BOOL)bVal {
+  //called from the main event loop when game mode menu item is clicked.
+  //If we try to set BP_GAME_MODE now, and we can't find any game sentences,
+  // we'll clear BP_GAME_MODE before the first call to SetBoolParam returns.
+  //Then, later in the same event handling code for the first menu click,
+  // the game mode menu item will be checked - even tho game mode is not on.
+  //Hence, let the event handler for the menu finish first:
+  [self performSelectorOnMainThread:@selector(doSetGameMode:) withObject:(bVal ? self : nil) waitUntilDone:NO];
+}
+
+-(void)doSetGameMode:(id)obj {
+  //we can now try and startup game mode in the core;
+  // with no automatic checking of the menuitem pending, any changes we make
+  // to the gameModeOn property will be correctly reflected in the menu... 
+  if (obj && directMode) self.directMode=false; //turn off direct mode first _if_necessary_ (properties do not check for no-change)
+  aquaDasherControl->SetBoolParameter(BP_GAME_MODE, obj!=nil);
+}
+
 -(void)setDirectMode:(BOOL)bVal {
   //hidden-ness of textview / appwatcher controls are automatically linked to property changes
+  if (bVal) self.gameModeOn=false; //exit game mode
   aquaDasherControl->SetEdit(bVal ? [[[DirectEdit alloc] initWithIntf:aquaDasherControl AppWatcher:appWatcher] autorelease] : textView);
   self->directMode = bVal;
 }
diff --git a/Src/MacOSX/English.lproj/MainMenu.nib/designable.nib b/Src/MacOSX/English.lproj/MainMenu.nib/designable.nib
index abdf7fb..e17dec8 100644
--- a/Src/MacOSX/English.lproj/MainMenu.nib/designable.nib
+++ b/Src/MacOSX/English.lproj/MainMenu.nib/designable.nib
@@ -377,6 +377,15 @@
 									<reference key="NSOnImage" ref="482857697"/>
 									<reference key="NSMixedImage" ref="552066134"/>
 								</object>
+								<object class="NSMenuItem" id="116803155">
+									<reference key="NSMenu" ref="449074099"/>
+									<string key="NSTitle">Game Mode</string>
+									<string key="NSKeyEquiv">g</string>
+									<int key="NSKeyEquivModMask">1048576</int>
+									<int key="NSMnemonicLoc">2147483647</int>
+									<reference key="NSOnImage" ref="482857697"/>
+									<reference key="NSMixedImage" ref="552066134"/>
+								</object>
 								<object class="NSMenuItem" id="890774057">
 									<reference key="NSMenu" ref="449074099"/>
 									<string key="NSTitle">Import Training Text...</string>
@@ -1129,6 +1138,15 @@
 						<reference key="NSOnImage" ref="482857697"/>
 						<reference key="NSMixedImage" ref="552066134"/>
 					</object>
+					<object class="NSMenuItem" id="740004343">
+						<reference key="NSMenu" ref="320235117"/>
+						<string key="NSTitle">Game Mode</string>
+						<string key="NSKeyEquiv">g</string>
+						<int key="NSKeyEquivModMask">1048576</int>
+						<int key="NSMnemonicLoc">2147483647</int>
+						<reference key="NSOnImage" ref="482857697"/>
+						<reference key="NSMixedImage" ref="552066134"/>
+					</object>
 				</object>
 			</object>
 			<object class="NSUserDefaultsController" id="516574171">
@@ -1351,6 +1369,37 @@
 				</object>
 				<object class="IBConnectionRecord">
 					<object class="IBBindingConnection" key="connection">
+						<string key="label">value: gameModeOn</string>
+						<reference key="source" ref="740004343"/>
+						<reference key="destination" ref="814937114"/>
+						<object class="NSNibBindingConnector" key="connector">
+							<reference key="NSSource" ref="740004343"/>
+							<reference key="NSDestination" ref="814937114"/>
+							<string key="NSLabel">value: gameModeOn</string>
+							<string key="NSBinding">value</string>
+							<string key="NSKeyPath">gameModeOn</string>
+							<object class="NSDictionary" key="NSOptions">
+								<bool key="EncodedWithXMLCoder">YES</bool>
+								<object class="NSArray" key="dict.sortedKeys">
+									<bool key="EncodedWithXMLCoder">YES</bool>
+									<string>NSAllowsEditingMultipleValuesSelection</string>
+									<string>NSConditionallySetsEnabled</string>
+									<string>NSValidatesImmediately</string>
+								</object>
+								<object class="NSMutableArray" key="dict.values">
+									<bool key="EncodedWithXMLCoder">YES</bool>
+									<boolean value="NO"/>
+									<boolean value="NO"/>
+									<boolean value="YES"/>
+								</object>
+							</object>
+							<int key="NSNibBindingConnectorVersion">2</int>
+						</object>
+					</object>
+					<int key="connectionID">554</int>
+				</object>
+				<object class="IBConnectionRecord">
+					<object class="IBBindingConnection" key="connection">
 						<string key="label">hidden: directMode</string>
 						<reference key="source" ref="179303831"/>
 						<reference key="destination" ref="814937114"/>
@@ -1371,6 +1420,37 @@
 				</object>
 				<object class="IBConnectionRecord">
 					<object class="IBBindingConnection" key="connection">
+						<string key="label">value: gameModeOn</string>
+						<reference key="source" ref="116803155"/>
+						<reference key="destination" ref="814937114"/>
+						<object class="NSNibBindingConnector" key="connector">
+							<reference key="NSSource" ref="116803155"/>
+							<reference key="NSDestination" ref="814937114"/>
+							<string key="NSLabel">value: gameModeOn</string>
+							<string key="NSBinding">value</string>
+							<string key="NSKeyPath">gameModeOn</string>
+							<object class="NSDictionary" key="NSOptions">
+								<bool key="EncodedWithXMLCoder">YES</bool>
+								<object class="NSArray" key="dict.sortedKeys">
+									<bool key="EncodedWithXMLCoder">YES</bool>
+									<string>NSAllowsEditingMultipleValuesSelection</string>
+									<string>NSConditionallySetsEnabled</string>
+									<string>NSValidatesImmediately</string>
+								</object>
+								<object class="NSMutableArray" key="dict.values">
+									<bool key="EncodedWithXMLCoder">YES</bool>
+									<boolean value="NO"/>
+									<boolean value="NO"/>
+									<boolean value="YES"/>
+								</object>
+							</object>
+							<int key="NSNibBindingConnectorVersion">2</int>
+						</object>
+					</object>
+					<int key="connectionID">565</int>
+				</object>
+				<object class="IBConnectionRecord">
+					<object class="IBBindingConnection" key="connection">
 						<string key="label">value: directMode</string>
 						<reference key="source" ref="661546643"/>
 						<reference key="destination" ref="814937114"/>
@@ -2001,6 +2081,7 @@
 							<reference ref="967558012"/>
 							<reference ref="701985345"/>
 							<reference ref="661546643"/>
+							<reference ref="116803155"/>
 							<reference ref="890774057"/>
 						</object>
 						<reference key="parent" ref="270706303"/>
@@ -2128,6 +2209,7 @@
 						<object class="NSMutableArray" key="children">
 							<bool key="EncodedWithXMLCoder">YES</bool>
 							<reference ref="257147646"/>
+							<reference ref="740004343"/>
 							<reference ref="881221781"/>
 						</object>
 						<reference key="parent" ref="0"/>
@@ -2184,6 +2266,16 @@
 						<reference key="parent" ref="0"/>
 					</object>
 					<object class="IBObjectRecord">
+						<int key="objectID">546</int>
+						<reference key="object" ref="740004343"/>
+						<reference key="parent" ref="320235117"/>
+					</object>
+					<object class="IBObjectRecord">
+						<int key="objectID">564</int>
+						<reference key="object" ref="116803155"/>
+						<reference key="parent" ref="449074099"/>
+					</object>
+					<object class="IBObjectRecord">
 						<int key="objectID">567</int>
 						<reference key="object" ref="881221781"/>
 						<reference key="parent" ref="320235117"/>
@@ -2747,8 +2839,12 @@
 					<string>527.ImportedFromIB2</string>
 					<string>536.IBPluginDependency</string>
 					<string>536.ImportedFromIB2</string>
+					<string>546.IBPluginDependency</string>
+					<string>546.ImportedFromIB2</string>
 					<string>56.IBPluginDependency</string>
 					<string>56.ImportedFromIB2</string>
+					<string>564.IBPluginDependency</string>
+					<string>564.ImportedFromIB2</string>
 					<string>567.IBPluginDependency</string>
 					<string>567.ImportedFromIB2</string>
 					<string>57.IBEditorWindowLastContentRect</string>
@@ -2904,7 +3000,11 @@
 					<boolean value="YES"/>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<boolean value="YES"/>
-					<string>{{0, 680}, {168, 43}}</string>
+					<string>{{0, 660}, {168, 63}}</string>
+					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+					<boolean value="YES"/>
+					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+					<boolean value="YES"/>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<boolean value="YES"/>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2915,7 +3015,7 @@
 					<boolean value="YES"/>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<boolean value="YES"/>
-					<string>{{110, 438}, {245, 223}}</string>
+					<string>{{110, 418}, {245, 243}}</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<boolean value="YES"/>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
diff --git a/Src/MacOSX/English.lproj/MainMenu.nib/keyedobjects.nib b/Src/MacOSX/English.lproj/MainMenu.nib/keyedobjects.nib
index 466c80d..bdf8369 100644
Binary files a/Src/MacOSX/English.lproj/MainMenu.nib/keyedobjects.nib and b/Src/MacOSX/English.lproj/MainMenu.nib/keyedobjects.nib differ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]