Fix encoding issue with OpenRA.Utility. Refactor SidebarEntry. Add launcher pages to all mods.

This commit is contained in:
Paul Chote
2010-11-17 11:03:57 +13:00
parent 82850cf4fb
commit 810b73e1f0
12 changed files with 83 additions and 36 deletions

View File

@@ -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;
}

View File

@@ -12,6 +12,7 @@
@interface GameInstall : NSObject {
NSURL *gameURL;
}
@property(readonly) NSURL *gameURL;
-(id)initWithURL:(NSURL *)path;
-(void)launchGame;

View File

@@ -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];
}

View File

@@ -20,13 +20,13 @@
}
return self;
}
- (void) dealloc
{
[controller release]; controller = nil;
[super dealloc];
}
- (void)launchCurrentMod
{
NSLog(@"launchcurrent");

View File

@@ -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

View File

@@ -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];
}

View File

@@ -63,6 +63,16 @@
font-size:1em;
background-color: #272d2c;
}
.button:active
{
background-color:#fff;
}
.button:hover
{
background-color: #333;
}
</style>
</head>

6
mods/d2k/mod.html Normal file
View File

@@ -0,0 +1,6 @@
<html>
<body>
<h1>Dune 2000</h1>
<input type="button" class="button" onclick="window.external.launchCurrentMod();" value="Play" />
</body>
</html>

6
mods/default/mod.html Normal file
View File

@@ -0,0 +1,6 @@
<html>
<body>
<h1>Default Mod</h1>
<input type="button" class="button" onclick="window.external.launchCurrentMod();" value="Play" />
</body>
</html>

7
mods/example/mod.html Normal file
View File

@@ -0,0 +1,7 @@
<html>
<body>
<h1>Example Mod</h1>
<h2>Demonstrates how to add a new unit by adding a soviet supply truck.</h2>
<input type="button" class="button" onclick="window.external.launchCurrentMod();" value="Play" />
</body>
</html>

6
mods/ra/mod.html Normal file
View File

@@ -0,0 +1,6 @@
<html>
<body>
<h1>Red Alert</h1>
<input type="button" class="button" onclick="window.external.launchCurrentMod();" value="Play" />
</body>
</html>

7
mods/ra_perf/mod.html Normal file
View File

@@ -0,0 +1,7 @@
<html>
<body>
<h1>RA Performance Tests</h1>
<h2>Adds special performance test maps to ra.</h2>
<input type="button" class="button" onclick="window.external.launchCurrentMod();" value="Play" />
</body>
</html>