From 810b73e1f07d38bd321413988da0dde722f6ebc3 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 17 Nov 2010 11:03:57 +1300 Subject: [PATCH] Fix encoding issue with OpenRA.Utility. Refactor SidebarEntry. Add launcher pages to all mods. --- OpenRA.Launcher.Mac/Controller.m | 19 ++++++++++------ OpenRA.Launcher.Mac/GameInstall.h | 1 + OpenRA.Launcher.Mac/GameInstall.m | 12 ++++++++-- OpenRA.Launcher.Mac/JSBridge.m | 2 +- OpenRA.Launcher.Mac/SidebarEntry.h | 8 +++---- OpenRA.Launcher.Mac/SidebarEntry.m | 35 +++++++++++------------------- mods/cnc/mod.html | 10 +++++++++ mods/d2k/mod.html | 6 +++++ mods/default/mod.html | 6 +++++ mods/example/mod.html | 7 ++++++ mods/ra/mod.html | 6 +++++ mods/ra_perf/mod.html | 7 ++++++ 12 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 mods/d2k/mod.html create mode 100644 mods/default/mod.html create mode 100644 mods/example/mod.html create mode 100644 mods/ra/mod.html create mode 100644 mods/ra_perf/mod.html diff --git a/OpenRA.Launcher.Mac/Controller.m b/OpenRA.Launcher.Mac/Controller.m index 58bb8427a0..30e4942692 100644 --- a/OpenRA.Launcher.Mac/Controller.m +++ b/OpenRA.Launcher.Mac/Controller.m @@ -18,15 +18,20 @@ - (void) awakeFromNib { game = [[GameInstall alloc] initWithURL:[NSURL URLWithString:@"/Users/paul/src/OpenRA"]]; - sidebarItems = [[SidebarEntry headerWithTitle:@""] retain]; - [sidebarItems addChild:[self sidebarModsTree]]; - [sidebarItems addChild:[self sidebarOtherTree]]; NSTableColumn *col = [outlineView tableColumnWithIdentifier:@"mods"]; ImageAndTextCell *imageAndTextCell = [[[ImageAndTextCell alloc] init] autorelease]; [col setDataCell:imageAndTextCell]; + sidebarItems = [[SidebarEntry headerWithTitle:@""] retain]; + id modsRoot = [self sidebarModsTree]; + [sidebarItems addChild:modsRoot]; + id otherRoot = [self sidebarOtherTree]; + [sidebarItems addChild:otherRoot]; + + [outlineView reloadData]; - [outlineView expandItem:[outlineView itemAtRow:0] expandChildren:YES]; + [outlineView expandItem:modsRoot expandChildren:YES]; + [outlineView expandItem:otherRoot expandChildren:YES]; [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO]; jsbridge = [[JSBridge alloc] initWithController:self]; @@ -44,7 +49,7 @@ { if ([aMod standalone]) { - id child = [SidebarEntry entryWithMod:aMod allMods:allMods]; + id child = [SidebarEntry entryWithMod:aMod allMods:allMods baseURL:[[game gameURL] URLByAppendingPathComponent:@"mods"]]; [rootItem addChild:child]; } } @@ -55,8 +60,8 @@ - (SidebarEntry *)sidebarOtherTree { SidebarEntry *rootItem = [SidebarEntry headerWithTitle:@"OTHER"]; - [rootItem addChild:[SidebarEntry entryWithTitle:@"Support" object:nil icon:nil]]; - [rootItem addChild:[SidebarEntry entryWithTitle:@"Credits" object:nil icon:nil]]; + [rootItem addChild:[SidebarEntry entryWithTitle:@"Support" url:nil icon:nil]]; + [rootItem addChild:[SidebarEntry entryWithTitle:@"Credits" url:nil icon:nil]]; return rootItem; } diff --git a/OpenRA.Launcher.Mac/GameInstall.h b/OpenRA.Launcher.Mac/GameInstall.h index 588b08b403..52b0e6721a 100644 --- a/OpenRA.Launcher.Mac/GameInstall.h +++ b/OpenRA.Launcher.Mac/GameInstall.h @@ -12,6 +12,7 @@ @interface GameInstall : NSObject { NSURL *gameURL; } +@property(readonly) NSURL *gameURL; -(id)initWithURL:(NSURL *)path; -(void)launchGame; diff --git a/OpenRA.Launcher.Mac/GameInstall.m b/OpenRA.Launcher.Mac/GameInstall.m index fc4e33ca1b..61d520bfb9 100644 --- a/OpenRA.Launcher.Mac/GameInstall.m +++ b/OpenRA.Launcher.Mac/GameInstall.m @@ -10,6 +10,7 @@ #import "Mod.h" @implementation GameInstall +@synthesize gameURL; -(id)initWithURL:(NSURL *)url { @@ -78,6 +79,12 @@ [fields setObject:[value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] forKey:key]; } + if (current != nil) + { + id url = [gameURL URLByAppendingPathComponent:[NSString stringWithFormat:@"mods/%@",current]]; + [ret addObject:[Mod modWithId:current fields:fields baseURL:url]]; + } + return ret; } @@ -110,11 +117,11 @@ - (NSString *)runUtilityQuery:(NSString *)arg { - NSTask *task = [[NSTask alloc] init]; NSPipe *outPipe = [NSPipe pipe]; NSMutableArray *taskArgs = [NSMutableArray arrayWithObject:@"OpenRA.Utility.exe"]; [taskArgs addObject:arg]; + NSTask *task = [[NSTask alloc] init]; [task setCurrentDirectoryPath:[gameURL absoluteString]]; [task setLaunchPath:@"/Library/Frameworks/Mono.framework/Commands/mono"]; [task setArguments:taskArgs]; @@ -124,7 +131,8 @@ NSData *data = [[outPipe fileHandleForReading] readDataToEndOfFile]; [task waitUntilExit]; [task release]; - return [NSString stringWithUTF8String:[data bytes]]; + + return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease]; } diff --git a/OpenRA.Launcher.Mac/JSBridge.m b/OpenRA.Launcher.Mac/JSBridge.m index bde28e580a..4c03cb5224 100644 --- a/OpenRA.Launcher.Mac/JSBridge.m +++ b/OpenRA.Launcher.Mac/JSBridge.m @@ -20,13 +20,13 @@ } return self; } + - (void) dealloc { [controller release]; controller = nil; [super dealloc]; } - - (void)launchCurrentMod { NSLog(@"launchcurrent"); diff --git a/OpenRA.Launcher.Mac/SidebarEntry.h b/OpenRA.Launcher.Mac/SidebarEntry.h index 16a1ed25ef..ba83f1a6f9 100644 --- a/OpenRA.Launcher.Mac/SidebarEntry.h +++ b/OpenRA.Launcher.Mac/SidebarEntry.h @@ -14,7 +14,7 @@ BOOL isHeader; NSString *title; NSImage *icon; - id object; + NSURL *url; NSMutableArray *children; } @@ -24,9 +24,9 @@ @property (readonly) NSImage* icon; + (id)headerWithTitle:(NSString *)aTitle; -+ (id)entryWithTitle:(NSString *)aTitle object:(id)anObject icon:(id)anIcon; -+ (id)entryWithMod:(Mod *)baseMod allMods:(NSArray *)allMods; -- (id)initWithTitle:(NSString *)aTitle object:(id)anObject icon:(id)anIcon isHeader:(BOOL)aHeader; ++ (id)entryWithTitle:(NSString *)aTitle url:(NSURL *)aURL icon:(id)anIcon; ++ (id)entryWithMod:(Mod *)baseMod allMods:(NSArray *)allMods baseURL:(NSURL *)aURL; +- (id)initWithTitle:(NSString *)aTitle url:(NSURL *)aURL icon:(id)anIcon isHeader:(BOOL)aHeader; - (void)addChild:(id)child; - (NSURL *)url; @end diff --git a/OpenRA.Launcher.Mac/SidebarEntry.m b/OpenRA.Launcher.Mac/SidebarEntry.m index 32e42c1ee4..2310149576 100644 --- a/OpenRA.Launcher.Mac/SidebarEntry.m +++ b/OpenRA.Launcher.Mac/SidebarEntry.m @@ -17,45 +17,48 @@ + (id)headerWithTitle:(NSString *)aTitle; { - id newObject = [[self alloc] initWithTitle:aTitle object:nil icon:nil isHeader:YES]; + id newObject = [[self alloc] initWithTitle:aTitle url:nil icon:nil isHeader:YES]; [newObject autorelease]; return newObject; } -+ (id)entryWithTitle:(NSString *)aTitle object:(id)anObject icon:(id)anIcon ++ (id)entryWithTitle:(NSString *)aTitle url:(NSURL *)aURL icon:(id)anIcon { - id newObject = [[self alloc] initWithTitle:aTitle object:anObject icon:anIcon isHeader:NO]; + id newObject = [[self alloc] initWithTitle:aTitle url:aURL icon:anIcon isHeader:NO]; [newObject autorelease]; return newObject; } -+ (id)entryWithMod:(Mod *)baseMod allMods:(NSArray *)allMods ++ (id)entryWithMod:(Mod *)baseMod allMods:(NSArray *)allMods baseURL:(NSURL *)baseURL { // TODO: Get the mod icon from the Mod // Temporary hack until mods define an icon NSString* imageName = [[NSBundle mainBundle] pathForResource:@"OpenRA" ofType:@"icns"]; id icon = [[[NSImage alloc] initWithContentsOfFile:imageName] autorelease]; - id ret = [SidebarEntry entryWithTitle:[baseMod title] object:baseMod icon:icon]; + id url = [[baseURL URLByAppendingPathComponent:[baseMod mod]] + URLByAppendingPathComponent:@"mod.html"]; + + id ret = [SidebarEntry entryWithTitle:[baseMod title] url:url icon:icon]; for (id aMod in allMods) { if (![[aMod requires] isEqualToString:[baseMod mod]]) continue; - id child = [SidebarEntry entryWithMod:aMod allMods:allMods]; + id child = [SidebarEntry entryWithMod:aMod allMods:allMods baseURL:baseURL]; [ret addChild:child]; } return ret; } -- (id)initWithTitle:(NSString *)aTitle object:(id)anObject icon:(id)anIcon isHeader:(BOOL)isaHeader +- (id)initWithTitle:(NSString *)aTitle url:(NSURL *)aURL icon:(id)anIcon isHeader:(BOOL)isaHeader { self = [super init]; if (self) { isHeader = isaHeader; title = [aTitle retain]; - object = [anObject retain]; + url = [aURL retain]; icon = [anIcon retain]; children = [[NSMutableArray alloc] init]; } @@ -64,30 +67,18 @@ - (void)addChild:(Mod *)child { - NSLog(@"Adding sidebar child %@ to %@",[child title], title); [children addObject:child]; } -- (BOOL)shouldSelect -{ - return [object shouldSelect]; -} - - (NSURL *)url { - if (object == nil) - { - NSLog(@"object is nil"); - return nil; - } - - return [object pageURL]; + return url; } - (void) dealloc { [title release]; title = nil; - [object release]; object = nil; + [url release]; url = nil; [icon release]; icon = nil; [super dealloc]; } diff --git a/mods/cnc/mod.html b/mods/cnc/mod.html index c9abff0985..a9177d70ef 100644 --- a/mods/cnc/mod.html +++ b/mods/cnc/mod.html @@ -63,6 +63,16 @@ font-size:1em; background-color: #272d2c; } + + .button:active + { + background-color:#fff; + } + + .button:hover + { + background-color: #333; + } diff --git a/mods/d2k/mod.html b/mods/d2k/mod.html new file mode 100644 index 0000000000..f838912df8 --- /dev/null +++ b/mods/d2k/mod.html @@ -0,0 +1,6 @@ + + +

Dune 2000

+ + + diff --git a/mods/default/mod.html b/mods/default/mod.html new file mode 100644 index 0000000000..143ce7d04e --- /dev/null +++ b/mods/default/mod.html @@ -0,0 +1,6 @@ + + +

Default Mod

+ + + diff --git a/mods/example/mod.html b/mods/example/mod.html new file mode 100644 index 0000000000..cd00c6bc33 --- /dev/null +++ b/mods/example/mod.html @@ -0,0 +1,7 @@ + + +

Example Mod

+

Demonstrates how to add a new unit by adding a soviet supply truck.

+ + + diff --git a/mods/ra/mod.html b/mods/ra/mod.html new file mode 100644 index 0000000000..e44446f9a9 --- /dev/null +++ b/mods/ra/mod.html @@ -0,0 +1,6 @@ + + +

Red Alert

+ + + diff --git a/mods/ra_perf/mod.html b/mods/ra_perf/mod.html new file mode 100644 index 0000000000..0c95bf1dc9 --- /dev/null +++ b/mods/ra_perf/mod.html @@ -0,0 +1,7 @@ + + +

RA Performance Tests

+

Adds special performance test maps to ra.

+ + +