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
This commit is contained in:
Jens Ayton 2010-05-26 21:42:14 +00:00
parent 9ee645891d
commit 4f306f2b3b
2 changed files with 38 additions and 36 deletions

View File

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

View File

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