diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bundle.h | 11 | ||||
-rw-r--r-- | src/bundle.mm | 36 | ||||
-rw-r--r-- | src/client.cpp | 59 | ||||
-rw-r--r-- | src/game.cpp | 6 | ||||
-rw-r--r-- | src/gui/truetypefont.h | 2 | ||||
-rw-r--r-- | src/log.cpp | 8 | ||||
-rw-r--r-- | src/resources/music.h | 2 | ||||
-rw-r--r-- | src/resources/soundeffect.h | 2 | ||||
-rw-r--r-- | src/resources/wallpaper.cpp | 2 | ||||
-rw-r--r-- | src/sound.h | 2 | ||||
-rw-r--r-- | src/window.h | 10 | ||||
-rw-r--r-- | src/window.mm | 26 |
12 files changed, 126 insertions, 40 deletions
diff --git a/src/bundle.h b/src/bundle.h new file mode 100644 index 00000000..3231988c --- /dev/null +++ b/src/bundle.h @@ -0,0 +1,11 @@ +// +// bundle.h +// themanaworld +// +// Created by David Athay on 1/27/11. +// Copyright 2011 __MyCompanyName__. All rights reserved. +// + +#include <string> + +std::string getBundleResourcesPath(); diff --git a/src/bundle.mm b/src/bundle.mm new file mode 100644 index 00000000..424e35f8 --- /dev/null +++ b/src/bundle.mm @@ -0,0 +1,36 @@ +// +// bundle.m +// themanaworld +// +// Created by David Athay on 1/27/11. +// Copyright 2011 __MyCompanyName__. All rights reserved. +// + +#import "bundle.h" +#import <Cocoa/Cocoa.h> + +std::string getBundleResourcesPath() +{ + std::string resPath; + NSBundle *mainBundle; + + // Get the main bundle for the app. + mainBundle = [NSBundle mainBundle]; + + NSString *bundlePath = [mainBundle bundlePath]; + NSArray *bundlePathArray = [[NSFileManager defaultManager] directoryContentsAtPath:bundlePath]; + // check it contains the right directories + if ((nil != bundlePathArray) && ([bundlePathArray containsObject:@"Contents"])) + { + NSString *contentsPath = [bundlePath stringByAppendingPathComponent:@"Contents"]; + NSArray *contentsPathArray = [[NSFileManager defaultManager] directoryContentsAtPath:contentsPath]; + if ((nil != contentsPath) && ([contentsPathArray containsObject:@"MacOS"]) && ([contentsPathArray containsObject:@"Resources"])) + { + // get the final path of the resources + NSString *finalResourcesPath = [contentsPath stringByAppendingPathComponent:@"Resources"]; + resPath = [finalResourcesPath UTF8String]; + } + } + + return resPath; +}
\ No newline at end of file diff --git a/src/client.cpp b/src/client.cpp index f63fc5f7..e955a75c 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -77,7 +77,8 @@ #include "utils/stringutils.h" #ifdef __APPLE__ -#include <CoreFoundation/CFBundle.h> +#include "window.h" +#include "bundle.h" #endif #include <physfs.h> @@ -211,16 +212,35 @@ Client::Client(const Options &options): mInstance = this; logger = new Logger; + + ResourceManager *resman = ResourceManager::getInstance(); + +#if defined __APPLE__ + std::string path; + path = getBundleResourcesPath(); + path.append("/data"); + resman->addToSearchPath(path.c_str(), false); + mPackageDir = path; +#else + resman->addToSearchPath(PKG_DATADIR "data", false); + mPackageDir = PKG_DATADIR "data"; +#endif // Load branding information if (!options.brandingPath.empty()) { - branding.init(options.brandingPath); + branding.init(options.brandingPath, true); } - + initRootDir(); initHomeDir(); initConfiguration(); + + if (!resman->setWriteDir(mLocalDataDir)) + { + logger->error(strprintf("%s couldn't be set as home directory! " + "Exiting.", mLocalDataDir.c_str())); + } // Configure logger logger->setLogFile(mLocalDataDir + std::string("/mana.log")); @@ -245,34 +265,8 @@ Client::Client(const Options &options): SDL_WM_SetCaption(branding.getValue("appName", "Mana").c_str(), NULL); - ResourceManager *resman = ResourceManager::getInstance(); - - if (!resman->setWriteDir(mLocalDataDir)) - { - logger->error(strprintf("%s couldn't be set as home directory! " - "Exiting.", mLocalDataDir.c_str())); - } - Image::SDLsetEnableAlphaCache(config.getValue("alphaCache", true)); -#if defined __APPLE__ - CFBundleRef mainBundle = CFBundleGetMainBundle(); - CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); - char path[PATH_MAX]; - if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, - PATH_MAX)) - { - fprintf(stderr, "Can't find Resources directory\n"); - } - CFRelease(resourcesURL); - strncat(path, "/data", PATH_MAX - 1); - resman->addToSearchPath(path, false); - mPackageDir = path; -#else - resman->addToSearchPath(PKG_DATADIR "data", false); - mPackageDir = PKG_DATADIR "data"; -#endif - resman->addToSearchPath("data", false); // Add branding/data to PhysFS search path @@ -302,10 +296,15 @@ Client::Client(const Options &options): std::string iconFile = branding.getValue("appIcon", "icons/mana"); #ifdef WIN32 iconFile += ".ico"; +#elif defined (__APPLE__) + // MacOSX expects just the filename without extension + iconFile = iconFile.substr(iconFile.find_last_of("/")+1); #else iconFile += ".png"; #endif +#ifndef __APPLE__ iconFile = resman->getPath(iconFile); +#endif logger->log("Loading icon from file: %s", iconFile.c_str()); #ifdef WIN32 static SDL_SysWMinfo pInfo; @@ -320,6 +319,8 @@ Client::Client(const Options &options): if (icon) SetClassLong(pInfo.window, GCL_HICON, (LONG) icon); +#elif defined(__APPLE__) + setIcon(iconFile.c_str()); #else mIcon = IMG_Load(iconFile.c_str()); if (mIcon) diff --git a/src/game.cpp b/src/game.cpp index 512b8b5f..cd36dcdd 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -779,6 +779,9 @@ void Game::handleInput() return; } + const Vector &pos = player_node->getPosition(); + const Uint16 x = (int) pos.x / 32; + const Uint16 y = (int) pos.y / 32; unsigned char direction = 0; // Translate pressed keys to movement and direction @@ -896,9 +899,6 @@ void Game::handleInput() { if (joystick->buttonPressed(1)) { - const int x = player_node->getTileX(); - const int y = player_node->getTileY(); - FloorItem *item = floorItemManager->findByCoordinates(x, y); if (item) diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h index 689f45bf..e62ad20d 100644 --- a/src/gui/truetypefont.h +++ b/src/gui/truetypefont.h @@ -26,7 +26,7 @@ #include <guichan/font.hpp> #ifdef __APPLE__ -#include <SDL_ttf/SDL_ttf.h> +#include <SDL/SDL_ttf.h> #else #ifdef __WIN32__ #include <SDL/SDL_ttf.h> diff --git a/src/log.cpp b/src/log.cpp index 4ce1cd83..9fc6aa55 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -26,7 +26,8 @@ #ifdef WIN32 #include <windows.h> #elif __APPLE__ -#include <Carbon/Carbon.h> +//#include <Carbon/Carbon.h> +#include "window.h" #endif #include <sys/time.h> @@ -115,7 +116,7 @@ void Logger::error(const std::string &error_text) #ifdef WIN32 MessageBox(NULL, error_text.c_str(), "Error", MB_ICONERROR | MB_OK); #elif defined __APPLE__ - Str255 msg; + /*Str255 msg; CFStringRef error; error = CFStringCreateWithCString(NULL, error_text.c_str(), @@ -123,7 +124,8 @@ void Logger::error(const std::string &error_text) CFStringGetPascalString(error, msg, 255, kCFStringEncodingMacRoman); StandardAlert(kAlertStopAlert, "\pError", - (ConstStr255Param) msg, NULL, NULL); + (ConstStr255Param) msg, NULL, NULL);*/ + windowAlert(error_text.c_str()); #elif defined __linux__ || __linux std::cerr << "Error: " << error_text << std::endl; std::string msg="xmessage \"" + error_text + "\""; diff --git a/src/resources/music.h b/src/resources/music.h index c0cf5abe..9d0a32af 100644 --- a/src/resources/music.h +++ b/src/resources/music.h @@ -25,7 +25,7 @@ #include "resources/resource.h" #ifdef __APPLE__ -#include <SDL_mixer/SDL_mixer.h> +#include <SDL/SDL_mixer.h> #else #include <SDL_mixer.h> #endif diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h index e7c832f4..fd4f50bd 100644 --- a/src/resources/soundeffect.h +++ b/src/resources/soundeffect.h @@ -25,7 +25,7 @@ #include "resources/resource.h" #ifdef __APPLE__ -#include <SDL_mixer/SDL_mixer.h> +#include <SDL/SDL_mixer.h> #else #include <SDL_mixer.h> #endif diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp index c8857745..f9fc69ee 100644 --- a/src/resources/wallpaper.cpp +++ b/src/resources/wallpaper.cpp @@ -103,7 +103,7 @@ void Wallpaper::loadWallpapers() // First, get the base filename of the image: std::string filename = *i; - unsigned int separator = filename.rfind("_"); + int separator = filename.rfind("_"); filename = filename.substr(0, separator); // Check that the base filename doesn't have any '%' markers. diff --git a/src/sound.h b/src/sound.h index bf5dc3f6..9400c2a5 100644 --- a/src/sound.h +++ b/src/sound.h @@ -23,7 +23,7 @@ #define SOUND_H #ifdef __APPLE__ -#include <SDL_mixer/SDL_mixer.h> +#include <SDL/SDL_mixer.h> #else #include <SDL_mixer.h> #endif diff --git a/src/window.h b/src/window.h new file mode 100644 index 00000000..482f65ee --- /dev/null +++ b/src/window.h @@ -0,0 +1,10 @@ +// +// window.h +// themanaworld +// +// Created by David Athay on 1/27/11. +// Copyright 2011 __MyCompanyName__. All rights reserved. +// + +void setIcon(const char *icon); +void windowAlert(const char *msg);
\ No newline at end of file diff --git a/src/window.mm b/src/window.mm new file mode 100644 index 00000000..f631f17d --- /dev/null +++ b/src/window.mm @@ -0,0 +1,26 @@ +// +// window.m +// themanaworld +// +// Created by David Athay on 1/27/11. +// Copyright 2011 __MyCompanyName__. All rights reserved. +// + +#import "window.h" +#import <Cocoa/Cocoa.h> + +void setIcon(const char *icon) +{ + NSString *path = [NSString stringWithCString:icon + encoding:[NSString defaultCStringEncoding]]; + NSString *imageName = [[NSBundle mainBundle] pathForResource:path ofType:@"icns" inDirectory:@"data/icons"]; + NSImage *iconImage = [[NSImage alloc] initWithContentsOfFile:imageName]; + [NSApp setApplicationIconImage: iconImage]; +} + +void windowAlert(const char *msg) +{ + NSString *alertText = [NSString stringWithCString:msg + encoding:[NSString defaultCStringEncoding]]; + NSRunAlertPanel(nil, alertText , @"OK", nil, nil); +}
\ No newline at end of file |