- mac menu part II, only show Screenshots & OXP directories (& previous log) if we have got anything to show. Reworked the AddOns directory preference, as agreed.

- 3284 redux: Kilos/grams handled properly when carrying specialCargo, simpler code.
- some minor cleanup.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3286 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Marc 2010-05-05 00:33:16 +00:00
parent 5af9d5adcd
commit b4f537f4b5
7 changed files with 106 additions and 61 deletions

View File

@ -3,7 +3,7 @@
MyOpenGLView.m
Oolite
Copyright (C) 2004-2008 Giles C Williams and contributors
Copyright (C) 2004-2010 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -32,6 +32,7 @@ MA 02110-1301, USA.
#import "GuiDisplayGen.h"
#import <Carbon/Carbon.h>
#import "JoystickHandler.h"
#import "NSFileManagerOOExtensions.h"
#ifndef NDEBUG
#import <Foundation/NSDebug.h>
@ -251,21 +252,25 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown";
w = w + 4 - (w & 3);
long nPixels = w * h + 1;
unsigned char *red = (unsigned char *) malloc( nPixels);
unsigned char *green = (unsigned char *) malloc( nPixels);
unsigned char *blue = (unsigned char *) malloc( nPixels);
NSString *filepath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent]; // also in gameController showSnapshotsAction
// backup the previous directory
NSString* originalDirectory = [[NSFileManager defaultManager] currentDirectoryPath];
// use the snapshots directory
[[NSFileManager defaultManager] chdirToSnapshotPath];
int imageNo = 0;
NSString *pathToPic = nil;
do
{
imageNo++;
pathToPic = [filepath stringByAppendingPathComponent:[NSString stringWithFormat:@"oolite-%03d.png",imageNo]];
pathToPic = [NSString stringWithFormat:@"oolite-%03d.png",imageNo];
} while ([[NSFileManager defaultManager] fileExistsAtPath:pathToPic]);
OOLog(@"snapshot", @">>>>> Snapshot %d x %d file path chosen = %@", w, h, pathToPic);
NSBitmapImageRep* bitmapRep =
@ -281,13 +286,13 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown";
bytesPerRow: 3*w // can no longer let the class figure it out
bitsPerPixel: 24 // can no longer let the class figure it out
];
unsigned char *pixels = [bitmapRep bitmapData];
glReadPixels(0,0, w,h, GL_RED, GL_UNSIGNED_BYTE, red);
glReadPixels(0,0, w,h, GL_GREEN, GL_UNSIGNED_BYTE, green);
glReadPixels(0,0, w,h, GL_BLUE, GL_UNSIGNED_BYTE, blue);
int x,y;
for (y = 0; y < h; y++)
{
@ -309,6 +314,8 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown";
free(green);
free(blue);
// return to the previous directory
[[NSFileManager defaultManager] changeCurrentDirectoryPath:originalDirectory];
}

View File

@ -3,7 +3,7 @@
GameController.m
Oolite
Copyright (C) 2004-2009 Giles C Williams and contributors
Copyright (C) 2004-2010 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -793,14 +793,40 @@ static NSComparisonResult CompareDisplayModes(id arg1, id arg2, void *context)
- (IBAction) showSnapshotsAction:sender
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath: [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent]]]; // also in myOpenGLView snapShot
[[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@SNAPSHOTDIR]]]; // also in myOpenGLView snapShot
}
- (IBAction) showAddOnsAction:sender
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath: [[[[NSBundle mainBundle] bundlePath]
stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"AddOns"]]];
// show the preferred AddOns folder (index 0 is Resources)
[[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:(NSString *)[[ResourceManager paths] objectAtIndex:1]]];
}
- (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem
{
if ([menuItem action] == @selector(showLogAction:))
{
// the first path is always Resources
return ([[NSFileManager defaultManager] fileExistsAtPath:[OOLogHandlerGetLogBasePath() stringByAppendingPathComponent:@"Previous.log"]]);
}
if ([menuItem action] == @selector(showAddOnsAction:))
{
// the first path is Resources, only enable item if we've got a second path.
return ([[ResourceManager paths] count] > 1);
}
if ([menuItem action] == @selector(showSnapshotsAction:))
{
BOOL pathIsDirectory;
if(![[NSFileManager defaultManager] fileExistsAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@SNAPSHOTDIR] isDirectory:&pathIsDirectory]) return NO;
return pathIsDirectory;
}
// default
return YES;
}

View File

@ -1,13 +1,13 @@
/*
NSFileManagerOOExtensions.m
NSFileManagerOOExtensions.h
This extends NSFileManager and adds some methods to insulate the
main oolite code from the gory details of creating/chdiring to the
commander save directory.
Oolite
Copyright (C) 2004-2008 Giles C Williams and contributors
Copyright (C) 2004-2010 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -29,7 +29,13 @@ MA 02110-1301, USA.
#import <Foundation/Foundation.h>
#define SAVEDIR "oolite-saves"
#define SNAPSHOTDIR "snapshots"
#if OOLITE_MAC_OS_X
#define SNAPSHOTDIR "Desktop/Oolite Screen Shots"
#else
#define SNAPSHOTDIR "snapshots"
#endif
@interface NSFileManager (OOExtensions)

View File

@ -7,7 +7,7 @@ main oolite code from the gory details of creating/chdiring to the
commander save directory.
Oolite
Copyright (C) 2004-2008 Giles C Williams and contributors
Copyright (C) 2004-2010 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -116,10 +116,15 @@ MA 02110-1301, USA.
}
- (BOOL)chdirToSnapshotPath
- (BOOL) chdirToSnapshotPath
{
// default path for snapshots is oolite.app/oolite-saves/snapshots
#if OOLITE_MAC_OS_X
// Macs: the default path for snapshots is ~/Desktop/Oolite Snap Shots
NSString *savedir = [NSHomeDirectory() stringByAppendingPathComponent:@SNAPSHOTDIR];
#else
// SDL: the default path for snapshots is oolite.app/oolite-saves/snapshots
NSString *savedir = [[NSHomeDirectory() stringByAppendingPathComponent:@SAVEDIR] stringByAppendingPathComponent:@SNAPSHOTDIR];
#endif
if (![self changeCurrentDirectoryPath: savedir])
{
// it probably doesn't exist.

View File

@ -3,7 +3,7 @@
ResourceManager.m
Oolite
Copyright (C) 2004-2008 Giles C Williams and contributors
Copyright (C) 2004-2010 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -114,33 +114,33 @@ static NSMutableDictionary *sStringCache;
if (sRootPaths == nil)
{
// the paths are now in order of preference as per yesterday's talk. -- Kaks 2010-05-05
sRootPaths = [[NSArray alloc] initWithObjects:[self builtInPath],
#if OOLITE_MAC_OS_X
NSString *app_addon_path = [[[[NSBundle mainBundle] bundlePath]
stringByDeletingLastPathComponent]
stringByAppendingPathComponent:@"AddOns"];
NSString *appsupport_path = [[[[NSHomeDirectory()
stringByAppendingPathComponent:@"Library"]
stringByAppendingPathComponent:@"Application Support"]
stringByAppendingPathComponent:@"Oolite"]
stringByAppendingPathComponent:@"AddOns"];
/* 1st mac path */ [[[[NSHomeDirectory() stringByAppendingPathComponent:@"Library"]
stringByAppendingPathComponent:@"Application Support"]
stringByAppendingPathComponent:@"Oolite"]
stringByAppendingPathComponent:@"AddOns"],
/* 2nd mac path */ [[[[NSBundle mainBundle] bundlePath]
stringByDeletingLastPathComponent]
stringByAppendingPathComponent:@"AddOns"],
#elif OOLITE_WINDOWS
NSString *app_addon_path = @"../AddOns";
NSString *appsupport_path = nil;
#else
NSString *app_addon_path = @"AddOns";
NSString *appsupport_path = nil;
/* windows path */ @"../AddOns",
#else
/* 1st *nix path */ @"AddOns",
#endif
NSString *nix_path = nil;
#if !OOLITE_WINDOWS
/* Enabling this path in Windows causes a log message, and it's not
actually useful.
*/
nix_path = [[NSHomeDirectory()
stringByAppendingPathComponent:@".Oolite"]
stringByAppendingPathComponent:@"AddOns"];
/* 2nd *nix path, 3rd mac path */
[[NSHomeDirectory()
stringByAppendingPathComponent:@".Oolite"]
stringByAppendingPathComponent:@"AddOns"],
#endif
sRootPaths = [[NSArray alloc] initWithObjects:[self builtInPath], app_addon_path, nix_path, appsupport_path, nil];
nil];
}
return sRootPaths;

View File

@ -84,18 +84,18 @@ enum
kManifest_firearms, // commodity quantity, integer, read/write
kManifest_furs, // commodity quantity, integer, read/write
kManifest_minerals, // commodity quantity, integer, read/write
kManifest_alienitems, // commodity quantity, integer, read/write
kManifest_gold, // commodity quantity, integer, read/write
kManifest_platinum, // commodity quantity, integer, read/write
kManifest_gemstones, // commodity quantity, integer, read/write
kManifest_alienitems, // commodity quantity, integer, read/write
// Up to kManifest_alienitems, these properties are case insensitive.
// Up to kManifest_gemstones, these properties are case insensitive.
// FIXME: there must be a better way of doing this.
kManifest_liquor_wines, // standardised identifier commodity quantity, integer, read/write
kManifest_liquorWines, // js style alias to previous commodity quantity, integer, read/write
kManifest_gem_stones, // standardised identifier commodity quantity, integer, read/write
kManifest_gemStones, // js style alias to previous commodity quantity, integer, read/write
kManifest_liquor_wines, // standardised identifier commodity quantity, integer, read/write
kManifest_liquorWines, // js style alias to previous commodity quantity, integer, read/write
kManifest_alien_items, // standardised identifier commodity quantity, integer, read/write
kManifest_alienItems, // js style alias to previous commodity quantity, integer, read/write
@ -119,19 +119,19 @@ static JSPropertySpec sManifestProperties[] =
{ "firearms", kManifest_firearms, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ "furs", kManifest_furs, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ "minerals", kManifest_minerals, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ "alien items", kManifest_alienitems, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ "gold", kManifest_gold, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ "platinum", kManifest_platinum, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ "gem-stones", kManifest_gemstones, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ "alien items", kManifest_alienitems, JSPROP_PERMANENT | JSPROP_ENUMERATE },
// There are 3 possible ways of accessing two-words commodities at the moment.
// We can either use the case insensitive original names - as above,
// or use one of the case insensitive variants below.
// or use one of the case sensitive variants below.
{ "liquor_wines", kManifest_liquor_wines, JSPROP_PERMANENT | JSPROP_ENUMERATE }, // normalised
{ "liquorWines", kManifest_liquorWines, JSPROP_PERMANENT | JSPROP_ENUMERATE }, // camelCase
{ "gem_stones", kManifest_gem_stones, JSPROP_PERMANENT | JSPROP_ENUMERATE }, // normalised
{ "gemStones", kManifest_gemStones, JSPROP_PERMANENT | JSPROP_ENUMERATE }, // camelCase
{ "liquor_wines", kManifest_liquor_wines, JSPROP_PERMANENT | JSPROP_ENUMERATE }, // normalised
{ "liquorWines", kManifest_liquorWines, JSPROP_PERMANENT | JSPROP_ENUMERATE }, // camelCase
{ "alien_items", kManifest_alien_items, JSPROP_PERMANENT | JSPROP_ENUMERATE }, // normalised
{ "alienItems", kManifest_alienItems, JSPROP_PERMANENT | JSPROP_ENUMERATE }, // camelCase
@ -369,9 +369,10 @@ static JSBool ManifestSetProperty(JSContext *context, JSObject *this, jsval name
//if (EXPECT_NOT(!JSShipGetShipEntity(context, this, &entity))) return NO;
commodity = JSVAL_TO_INT(name);
if ([entity specialCargo] && !(commodity >= kManifest_gold && commodity <= kManifest_gemstones) && commodity != kManifest_gem_stones && commodity != kManifest_gemStones)
// we can always change gold, platinum & gem-stones quantities, even with special cargo
if ([entity specialCargo] && (commodity < kManifest_gold || commodity > kManifest_gemStones))
{
OOReportJSWarning(context, @"PlayerShip.manifest['foo'] - cannot modify cargo when Special Cargo is in use.");
OOReportJSWarning(context, @"PlayerShip.manifest['foo'] - cannot modify cargo tonnage when Special Cargo is in use.");
return YES;
}

View File

@ -3,7 +3,7 @@
MyOpenGLView.m
Oolite
Copyright (C) 2004-2009 Giles C Williams and contributors
Copyright (C) 2004-2010 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -772,30 +772,30 @@ MA 02110-1301, USA.
SDL_Surface* tmpSurface;
int w = viewSize.width;
int h = viewSize.height;
if (w & 3)
w = w + 4 - (w & 3);
// backup the savegame directory.
// backup the previous directory
NSString* originalDirectory = [[NSFileManager defaultManager] currentDirectoryPath];
// use the snapshots directory
[[NSFileManager defaultManager] chdirToSnapshotPath];
int imageNo = 0;
NSString *pathToPic = nil;
do
{
imageNo++;
pathToPic = [NSString stringWithFormat:@"oolite-%03d.bmp",imageNo];
} while ([[NSFileManager defaultManager] fileExistsAtPath:pathToPic]);
OOLog(@"snapshot", @">>>>> Snapshot %d x %d file chosen = %@", w, h, pathToPic);
unsigned char *pixls = malloc(surface->w * surface->h * 3);
// SDL_Surface *screen;
glReadPixels(0,0,surface->w,surface->h,GL_RGB,GL_UNSIGNED_BYTE,pixls);
int pitch = surface->w * 3;
unsigned char *aux = malloc( pitch );
short h2=surface->h/2;
@ -810,13 +810,13 @@ MA 02110-1301, USA.
p2-=pitch;
}
free(aux);
tmpSurface=SDL_CreateRGBSurfaceFrom(pixls,surface->w,surface->h,24,surface->w*3,0xFF,0xFF00,0xFF0000,0x0);
SDL_SaveBMP(tmpSurface, [pathToPic UTF8String]);
SDL_FreeSurface(tmpSurface);
free(pixls);
// restore the savegame directory name.
// return to the previous directory
[[NSFileManager defaultManager] changeCurrentDirectoryPath:originalDirectory];
}