From 4f306f2b3b11d642f1f2f8863491faf10d68dc12 Mon Sep 17 00:00:00 2001 From: Jens Ayton Date: Wed, 26 May 2010 21:42:14 +0000 Subject: [PATCH] Moved JS setScreenBackground() and setScreenForeground() into global object. oolite object is for info about application. git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3415 127b21dd-08f5-0310-b4b7-95ae10353056 --- src/Core/Scripting/OOJSGlobal.m | 38 +++++++++++++++++++++++++++++++++ src/Core/Scripting/OOJSOolite.m | 36 ------------------------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/Core/Scripting/OOJSGlobal.m b/src/Core/Scripting/OOJSGlobal.m index 93d0de61..879c6728 100644 --- a/src/Core/Scripting/OOJSGlobal.m +++ b/src/Core/Scripting/OOJSGlobal.m @@ -31,6 +31,8 @@ MA 02110-1301, USA. #import "OOStringParsing.h" #import "OOConstToString.h" #import "OOCollectionExtractors.h" +#import "OOTexture.h" +#import "GuiDisplayGen.h" #if OOJSENGINE_MONITOR_SUPPORT @@ -58,6 +60,8 @@ static JSBool GlobalExpandMissionText(JSContext *context, JSObject *this, uintN static JSBool GlobalDisplayNameForCommodity(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult); static JSBool GlobalRandomName(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult); static JSBool GlobalRandomInhabitantsDescription(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult); +static JSBool GlobalSetScreenBackground(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult); +static JSBool GlobalSetScreenOverlay(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult); static JSClass sGlobalClass = @@ -104,6 +108,8 @@ static JSFunctionSpec sGlobalMethods[] = { "displayNameForCommodity", GlobalDisplayNameForCommodity, 1 }, { "randomName", GlobalRandomName, 0 }, { "randomInhabitantsDescription", GlobalRandomInhabitantsDescription, 1 }, + { "setScreenBackground", GlobalSetScreenBackground, 1 }, + { "setScreenOverlay", GlobalSetScreenOverlay, 1 }, { 0 } }; @@ -314,3 +320,35 @@ static JSBool GlobalRandomInhabitantsDescription(JSContext *context, JSObject *t return YES; } + + +// setScreenBackground(name : String) : Boolean +static JSBool GlobalSetScreenBackground(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult) +{ + *outResult = JSVAL_FALSE; + NSString *value = JSValToNSString(context, argv[0]); + PlayerEntity *player = OOPlayerForScripting(); + + if ([UNIVERSE viewDirection] == VIEW_GUI_DISPLAY) + { + *outResult = BOOLEAN_TO_JSVAL([[UNIVERSE gui] setBackgroundTexture:[OOTexture textureWithName:value inFolder:@"Images"]]); + // add some permanence to the override if we're in the equip ship screen + if (*outResult == JSVAL_TRUE && [player guiScreen] == GUI_SCREEN_EQUIP_SHIP) [player setTempBackground:value]; + } + + return YES; +} + + +// setScreenOverlay(name : String) : Boolean +static JSBool GlobalSetScreenOverlay(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult) +{ + *outResult = JSVAL_FALSE; + + if ([UNIVERSE viewDirection] == VIEW_GUI_DISPLAY) + { + *outResult = BOOLEAN_TO_JSVAL([[UNIVERSE gui] setForegroundTexture:[OOTexture textureWithName:JSValToNSString(context, argv[0]) inFolder:@"Images"]]); + } + + return YES; +} diff --git a/src/Core/Scripting/OOJSOolite.m b/src/Core/Scripting/OOJSOolite.m index d468b17f..0a4d74b3 100644 --- a/src/Core/Scripting/OOJSOolite.m +++ b/src/Core/Scripting/OOJSOolite.m @@ -28,8 +28,6 @@ MA 02110-1301, USA. #import "OOJSOolite.h" #import "OOJavaScriptEngine.h" #import "OOStringParsing.h" -#import "OOTexture.h" -#import "GuiDisplayGen.h" #import "OOJSPlayer.h" @@ -39,8 +37,6 @@ static NSString *VersionString(void); static NSArray *VersionComponents(void); static JSBool OoliteCompareVersion(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult); -static JSBool OoliteScreenBackground(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult); -static JSBool OoliteScreenOverlay(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult); static JSClass sOoliteClass = @@ -86,8 +82,6 @@ static JSFunctionSpec sOoliteMethods[] = { // JS name Function min args { "compareVersion", OoliteCompareVersion, 1 }, - { "setScreenBackground", OoliteScreenBackground, 1 }, - { "setScreenOverlay", OoliteScreenOverlay, 1 }, { 0 } }; @@ -192,33 +186,3 @@ static JSBool OoliteCompareVersion(JSContext *context, JSObject *this, uintN arg return YES; } - - -static JSBool OoliteScreenBackground(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult) -{ - *outResult = JSVAL_FALSE; - NSString *value = JSValToNSString(context, argv[0]); - PlayerEntity *player = OOPlayerForScripting(); - - if ([UNIVERSE viewDirection] == VIEW_GUI_DISPLAY) - { - *outResult = BOOLEAN_TO_JSVAL([[UNIVERSE gui] setBackgroundTexture:[OOTexture textureWithName:value inFolder:@"Images"]]); - // add some permanence to the override if we're in the equip ship screen - if (*outResult == JSVAL_TRUE && [player guiScreen] == GUI_SCREEN_EQUIP_SHIP) [player setTempBackground:value]; - } - - return YES; -} - - -static JSBool OoliteScreenOverlay(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult) -{ - *outResult = JSVAL_FALSE; - - if ([UNIVERSE viewDirection] == VIEW_GUI_DISPLAY) - { - *outResult = BOOLEAN_TO_JSVAL([[UNIVERSE gui] setForegroundTexture:[OOTexture textureWithName:JSValToNSString(context, argv[0]) inFolder:@"Images"]]); - } - - return YES; -}