From 21e597ca2da37cef481a3b35d602df51cc743f6b Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 16 Nov 2010 19:11:40 +1300 Subject: [PATCH] Hook up the "Play" button to launch the game. --- OpenRA.Launcher.Mac/Controller.h | 4 ++- OpenRA.Launcher.Mac/Controller.m | 6 +++- OpenRA.Launcher.Mac/GameInstall.m | 3 +- OpenRA.Launcher.Mac/JSBridge.h | 18 ++++++++++ OpenRA.Launcher.Mac/JSBridge.m | 36 +++++++++++++++++++ .../OpenRA.xcodeproj/project.pbxproj | 6 ++++ mods/cnc/mod.html | 2 +- 7 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 OpenRA.Launcher.Mac/JSBridge.h create mode 100644 OpenRA.Launcher.Mac/JSBridge.m diff --git a/OpenRA.Launcher.Mac/Controller.h b/OpenRA.Launcher.Mac/Controller.h index 7e4fec97cb..48b4aa37f4 100644 --- a/OpenRA.Launcher.Mac/Controller.h +++ b/OpenRA.Launcher.Mac/Controller.h @@ -11,14 +11,16 @@ @class Mod; @class SidebarEntry; @class GameInstall; +@class JSBridge; @interface Controller : NSObject { SidebarEntry *sidebarItems; GameInstall *game; + JSBridge *jsbridge; IBOutlet NSOutlineView *outlineView; IBOutlet WebView *webView; } -- (IBAction)launchGame:(id)sender; +- (void)launchGame; - (SidebarEntry *)sidebarModsTree; - (SidebarEntry *)sidebarOtherTree; diff --git a/OpenRA.Launcher.Mac/Controller.m b/OpenRA.Launcher.Mac/Controller.m index 352c70b8a8..e86df582b0 100644 --- a/OpenRA.Launcher.Mac/Controller.m +++ b/OpenRA.Launcher.Mac/Controller.m @@ -11,6 +11,7 @@ #import "SidebarEntry.h" #import "GameInstall.h" #import "ImageAndTextCell.h" +#import "JSBridge.h" @implementation Controller @@ -27,6 +28,9 @@ [outlineView reloadData]; [outlineView expandItem:[outlineView itemAtRow:0] expandChildren:YES]; [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO]; + + jsbridge = [[JSBridge alloc] initWithController:self]; + [[webView windowScriptObject] setValue:jsbridge forKey:@"Launcher"]; } - (SidebarEntry *)sidebarModsTree @@ -130,7 +134,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn } } -- (IBAction)launchGame:(id)sender +- (void)launchGame { [game launchGame]; } diff --git a/OpenRA.Launcher.Mac/GameInstall.m b/OpenRA.Launcher.Mac/GameInstall.m index 4a245e7d62..f72ed1362f 100644 --- a/OpenRA.Launcher.Mac/GameInstall.m +++ b/OpenRA.Launcher.Mac/GameInstall.m @@ -16,13 +16,14 @@ self = [super init]; if (self != nil) { - gameURL = url; + gameURL = [url retain]; } return self; } - (void)dealloc { + [gameURL release]; gameURL = nil; [super dealloc]; } diff --git a/OpenRA.Launcher.Mac/JSBridge.h b/OpenRA.Launcher.Mac/JSBridge.h new file mode 100644 index 0000000000..770756e814 --- /dev/null +++ b/OpenRA.Launcher.Mac/JSBridge.h @@ -0,0 +1,18 @@ +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ + + +#import + +@class Controller; +@interface JSBridge : NSObject { + Controller *controller; +} + +-(id)initWithController:(Controller *)aController; +@end diff --git a/OpenRA.Launcher.Mac/JSBridge.m b/OpenRA.Launcher.Mac/JSBridge.m new file mode 100644 index 0000000000..3e5802c6b2 --- /dev/null +++ b/OpenRA.Launcher.Mac/JSBridge.m @@ -0,0 +1,36 @@ +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ + +#import "JSBridge.h" +#import "Controller.h" + +@implementation JSBridge + +-(id)initWithController:(Controller *)aController +{ + self = [super init]; + if (self != nil) + { + controller = [aController retain]; + } + return self; +} +- (void) dealloc +{ + [controller release]; controller = nil; + [super dealloc]; +} + + +- (void)launchCurrentMod +{ + [controller launchGame]; +} + ++ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector { return NO; } +@end diff --git a/OpenRA.Launcher.Mac/OpenRA.xcodeproj/project.pbxproj b/OpenRA.Launcher.Mac/OpenRA.xcodeproj/project.pbxproj index 00fb047628..ea2486a9ed 100644 --- a/OpenRA.Launcher.Mac/OpenRA.xcodeproj/project.pbxproj +++ b/OpenRA.Launcher.Mac/OpenRA.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; + DA38212212925344003B0BB5 /* JSBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = DA38212112925344003B0BB5 /* JSBridge.m */; }; DA81FA821290F5C800C48F2F /* Controller.m in Sources */ = {isa = PBXBuildFile; fileRef = DA81FA811290F5C800C48F2F /* Controller.m */; }; DA81FAAA1290FA0000C48F2F /* Mod.m in Sources */ = {isa = PBXBuildFile; fileRef = DA81FAA91290FA0000C48F2F /* Mod.m */; }; DA81FB9312910A8B00C48F2F /* ImageAndTextCell.m in Sources */ = {isa = PBXBuildFile; fileRef = DA81FB9212910A8B00C48F2F /* ImageAndTextCell.m */; }; @@ -34,6 +35,8 @@ 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; 8D1107310486CEB800E47090 /* OpenRA-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "OpenRA-Info.plist"; sourceTree = ""; }; 8D1107320486CEB800E47090 /* OpenRA.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OpenRA.app; sourceTree = BUILT_PRODUCTS_DIR; }; + DA38212012925344003B0BB5 /* JSBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSBridge.h; sourceTree = ""; }; + DA38212112925344003B0BB5 /* JSBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSBridge.m; sourceTree = ""; }; DA81FA801290F5C800C48F2F /* Controller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Controller.h; sourceTree = ""; }; DA81FA811290F5C800C48F2F /* Controller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Controller.m; sourceTree = ""; }; DA81FAA81290FA0000C48F2F /* Mod.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Mod.h; sourceTree = ""; }; @@ -77,6 +80,8 @@ DA81FC3E12911E2B00C48F2F /* GameInstall.m */, DA92968E1292328200EDB02E /* SidebarEntry.h */, DA92968F1292328200EDB02E /* SidebarEntry.m */, + DA38212012925344003B0BB5 /* JSBridge.h */, + DA38212112925344003B0BB5 /* JSBridge.m */, ); name = Classes; sourceTree = ""; @@ -220,6 +225,7 @@ DA81FB9312910A8B00C48F2F /* ImageAndTextCell.m in Sources */, DA81FC3F12911E2B00C48F2F /* GameInstall.m in Sources */, DA9296901292328200EDB02E /* SidebarEntry.m in Sources */, + DA38212212925344003B0BB5 /* JSBridge.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/mods/cnc/mod.html b/mods/cnc/mod.html index ded663f982..6f408c05eb 100644 --- a/mods/cnc/mod.html +++ b/mods/cnc/mod.html @@ -84,7 +84,7 @@
- +