JS support for setting MFDs
PS.setMultiFunctionText(key, string) PS.setMultiFunctionDisplay(index,key) PS.multiFunctionDisplays // count Second function may end up as debug-only.
This commit is contained in:
parent
ff60370d3f
commit
8bb6636e0c
@ -659,6 +659,8 @@ typedef enum
|
||||
- (void) resetHud;
|
||||
|
||||
- (NSString *) multiFunctionText:(NSUInteger) index;
|
||||
- (void) setMultiFunctionText:(NSString *)text forKey:(NSString *)key;
|
||||
- (BOOL) setMultiFunctionDisplay:(NSUInteger) index toKey:(NSString *)key;
|
||||
|
||||
- (void) setShowDemoShips:(BOOL) value;
|
||||
- (BOOL) showDemoShips;
|
||||
|
@ -3359,7 +3359,8 @@ static GLfloat sBaseMass = 0.0;
|
||||
BOOL wasHidden = NO;
|
||||
BOOL wasCompassActive = YES;
|
||||
double scannerZoom = 1.0;
|
||||
|
||||
int i;
|
||||
|
||||
if (!hudFileName) return NO;
|
||||
|
||||
// is the HUD in the process of being rendered? If yes, set it to defer state and abort the switching now
|
||||
@ -3397,6 +3398,11 @@ static GLfloat sBaseMass = 0.0;
|
||||
[hud setCompassActive:wasCompassActive];
|
||||
[hud setHidden:wasHidden];
|
||||
activeMFD = 0;
|
||||
[multiFunctionDisplaySettings removeAllObjects];
|
||||
for (i = [hud mfdCount]-1 ; i >= 0 ; i--)
|
||||
{
|
||||
[multiFunctionDisplaySettings addObject:[NSNull null]];
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
@ -4137,8 +4143,6 @@ static GLfloat sBaseMass = 0.0;
|
||||
|
||||
- (NSString *) multiFunctionText:(NSUInteger)i
|
||||
{
|
||||
return @"This is a test\nof the MFD code\nTo see if it\nworks.";
|
||||
#ifdef FINISHED_OTHER_BITS_OF_MFDS
|
||||
NSString *key = [multiFunctionDisplaySettings oo_stringAtIndex:i defaultValue:nil];
|
||||
if (key == nil)
|
||||
{
|
||||
@ -4146,7 +4150,40 @@ static GLfloat sBaseMass = 0.0;
|
||||
}
|
||||
NSString *text = [multiFunctionDisplayText oo_stringForKey:key defaultValue:nil];
|
||||
return text;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
- (void) setMultiFunctionText:(NSString *)text forKey:(NSString *)key
|
||||
{
|
||||
if (text != nil)
|
||||
{
|
||||
[multiFunctionDisplayText setObject:text forKey:key];
|
||||
}
|
||||
else
|
||||
{
|
||||
[multiFunctionDisplayText removeObjectForKey:key];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) setMultiFunctionDisplay:(NSUInteger)index toKey:(NSString *)key
|
||||
{
|
||||
if (index < [hud mfdCount])
|
||||
{
|
||||
if (key == nil)
|
||||
{
|
||||
[multiFunctionDisplaySettings replaceObjectAtIndex:index withObject:[NSNull null]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[multiFunctionDisplaySettings replaceObjectAtIndex:index withObject:key];
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -290,6 +290,8 @@ MA 02110-1301, USA.
|
||||
- (void) addDial:(NSDictionary *)info;
|
||||
- (void) addMFD:(NSDictionary *)info;
|
||||
|
||||
- (NSUInteger) mfdCount;
|
||||
|
||||
- (void) renderHUD;
|
||||
|
||||
- (void) refreshLastTransmitter;
|
||||
|
@ -640,6 +640,12 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
|
||||
[mfdArray addObject:[NSArray arrayWithObjects:info, [NSValue valueWithBytes:&cache objCType:@encode(struct CachedInfo)],nil]];
|
||||
}
|
||||
|
||||
|
||||
- (NSUInteger) mfdCount
|
||||
{
|
||||
return [mfdArray count];
|
||||
}
|
||||
|
||||
/*
|
||||
SLOW_CODE
|
||||
As of 2012-09-13 (r5320), HUD rendering is taking 25%-30% of rendering time,
|
||||
|
@ -134,14 +134,14 @@ static JSFunctionSpec sPlayerMethods[] =
|
||||
{ "commsMessage", PlayerCommsMessage, 1 },
|
||||
{ "consoleMessage", PlayerConsoleMessage, 1 },
|
||||
{ "decreaseContractReputation", PlayerDecreaseContractReputation, 0 },
|
||||
{ "decreaseParcelReputation", PlayerDecreaseParcelReputation, 0 },
|
||||
{ "decreaseParcelReputation", PlayerDecreaseParcelReputation, 0 },
|
||||
{ "decreasePassengerReputation", PlayerDecreasePassengerReputation, 0 },
|
||||
{ "increaseContractReputation", PlayerIncreaseContractReputation, 0 },
|
||||
{ "increaseParcelReputation", PlayerIncreaseParcelReputation, 0 },
|
||||
{ "increaseParcelReputation", PlayerIncreaseParcelReputation, 0 },
|
||||
{ "increasePassengerReputation", PlayerIncreasePassengerReputation, 0 },
|
||||
{ "replaceShip", PlayerReplaceShip, 1 },
|
||||
{ "setEscapePodDestination", PlayerSetEscapePodDestination, 1 }, // null destination must be set explicitly
|
||||
{ "setPlayerRole", PlayerSetPlayerRole, 1 },
|
||||
{ "setPlayerRole", PlayerSetPlayerRole, 1 },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
@ -626,7 +626,7 @@ static JSBool PlayerSetPlayerRole(JSContext *context, uintN argc, jsval *vp)
|
||||
if (argc > 0) role = OOStringFromJSValue(context, OOJS_ARGV[0]);
|
||||
if (role == nil)
|
||||
{
|
||||
OOJSReportBadArguments(context, @"Player", @"setPlayerRole", MIN(argc, 1U), OOJS_ARGV, nil, @"string (role) [, number (index)");
|
||||
OOJSReportBadArguments(context, @"Player", @"setPlayerRole", MIN(argc, 1U), OOJS_ARGV, nil, @"string (role) [, number (index)]");
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,8 @@ static JSBool PlayerShipResetCustomView(JSContext *context, uintN argc, jsval *v
|
||||
static JSBool PlayerShipTakeInternalDamage(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool PlayerShipBeginHyperspaceCountdown(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool PlayerShipCancelHyperspaceCountdown(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool PlayerShipSetMultiFunctionDisplay(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool PlayerShipSetMultiFunctionText(JSContext *context, uintN argc, jsval *vp);
|
||||
|
||||
|
||||
static BOOL ValidateContracts(JSContext *context, uintN argc, jsval *vp, BOOL isCargo, OOSystemID *start, OOSystemID *destination, double *eta, double *fee, double *premium, NSString *functionName, unsigned *risk);
|
||||
@ -118,6 +120,7 @@ enum
|
||||
kPlayerShip_hyperspaceSpinTime, // hyperspace spin time, read only
|
||||
kPlayerShip_maxAftShield, // maximum aft shield charge level, positive float, read-only
|
||||
kPlayerShip_maxForwardShield, // maximum forward shield charge level, positive float, read-only
|
||||
kPlayerShip_multiFunctionDisplays, // mfd count, positive int, read-only
|
||||
kPlayerShip_missilesOnline, // bool (false for ident mode, true for missile mode)
|
||||
kPlayerShip_pitch, // pitch (overrules Ship)
|
||||
kPlayerShip_price, // idealised trade-in value decicredits, positive int, read-only
|
||||
@ -165,6 +168,7 @@ static JSPropertySpec sPlayerShipProperties[] =
|
||||
{ "maxAftShield", kPlayerShip_maxAftShield, OOJS_PROP_READONLY_CB },
|
||||
{ "maxForwardShield", kPlayerShip_maxForwardShield, OOJS_PROP_READONLY_CB },
|
||||
{ "missilesOnline", kPlayerShip_missilesOnline, OOJS_PROP_READONLY_CB },
|
||||
{ "multiFunctionDisplays", kPlayerShip_multiFunctionDisplays, OOJS_PROP_READONLY_CB },
|
||||
{ "price", kPlayerShip_price, OOJS_PROP_READONLY_CB },
|
||||
{ "pitch", kPlayerShip_pitch, OOJS_PROP_READONLY_CB },
|
||||
{ "reticleTargetSensitive", kPlayerShip_reticleTargetSensitive, OOJS_PROP_READWRITE_CB },
|
||||
@ -191,17 +195,19 @@ static JSFunctionSpec sPlayerShipMethods[] =
|
||||
{ "addPassenger", PlayerShipAddPassenger, 0 },
|
||||
{ "awardContract", PlayerShipAwardContract, 0 },
|
||||
{ "awardEquipmentToCurrentPylon", PlayerShipAwardEquipmentToCurrentPylon, 1 },
|
||||
{ "beginHyperspaceCountdown", PlayerShipBeginHyperspaceCountdown, 0 },
|
||||
{ "cancelHyperspaceCountdown", PlayerShipCancelHyperspaceCountdown, 0 },
|
||||
{ "beginHyperspaceCountdown", PlayerShipBeginHyperspaceCountdown, 0 },
|
||||
{ "cancelHyperspaceCountdown", PlayerShipCancelHyperspaceCountdown, 0 },
|
||||
{ "disengageAutopilot", PlayerShipDisengageAutopilot, 0 },
|
||||
{ "engageAutopilotToStation", PlayerShipEngageAutopilotToStation, 1 },
|
||||
{ "launch", PlayerShipLaunch, 0 },
|
||||
{ "removeAllCargo", PlayerShipRemoveAllCargo, 0 },
|
||||
{ "removeContract", PlayerShipRemoveContract, 2 },
|
||||
{ "removeParcel", PlayerShipRemoveParcel, 1 },
|
||||
{ "removeParcel", PlayerShipRemoveParcel, 1 },
|
||||
{ "removePassenger", PlayerShipRemovePassenger, 1 },
|
||||
{ "resetCustomView", PlayerShipResetCustomView, 0 },
|
||||
{ "setCustomView", PlayerShipSetCustomView, 2 },
|
||||
{ "setMultiFunctionDisplay", PlayerShipSetMultiFunctionDisplay, 1 },
|
||||
{ "setMultiFunctionText", PlayerShipSetMultiFunctionText, 1 },
|
||||
{ "takeInternalDamage", PlayerShipTakeInternalDamage, 0 },
|
||||
{ "useSpecialCargo", PlayerShipUseSpecialCargo, 1 },
|
||||
{ 0 }
|
||||
@ -343,6 +349,9 @@ static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsid pro
|
||||
// No distinction made internally
|
||||
return JS_NewNumberValue(context, [player shieldRechargeRate], value);
|
||||
|
||||
case kPlayerShip_multiFunctionDisplays:
|
||||
return JS_NewNumberValue(context, [[player hud] mfdCount], value);
|
||||
|
||||
case kPlayerShip_missilesOnline:
|
||||
*value = OOJSValueFromBOOL(![player dialIdentEngaged]);
|
||||
return YES;
|
||||
@ -1111,6 +1120,71 @@ static JSBool PlayerShipCancelHyperspaceCountdown(JSContext *context, uintN argc
|
||||
}
|
||||
|
||||
|
||||
// setMultiFunctionDisplay(index,key)
|
||||
static JSBool PlayerShipSetMultiFunctionDisplay(JSContext *context, uintN argc, jsval *vp)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
NSString *key = nil;
|
||||
uint32 index = 0;
|
||||
PlayerEntity *player = OOPlayerForScripting();
|
||||
BOOL OK = YES;
|
||||
|
||||
if (argc > 0)
|
||||
{
|
||||
if (!JS_ValueToECMAUint32(context,OOJS_ARGV[0],&index))
|
||||
{
|
||||
OOJSReportBadArguments(context, @"PlayerShip", @"setMultiFunctionDisplay", MIN(argc, 1U), OOJS_ARGV, nil, @"number (index) [, string (key)]");
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
key = OOStringFromJSValue(context, OOJS_ARGV[1]);
|
||||
}
|
||||
|
||||
OK = [player setMultiFunctionDisplay:index toKey:key];
|
||||
|
||||
OOJS_RETURN_BOOL(OK);
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
|
||||
// setMultiFunctionText(key,value)
|
||||
static JSBool PlayerShipSetMultiFunctionText(JSContext *context, uintN argc, jsval *vp)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
NSString *key = nil;
|
||||
NSString *value = nil;
|
||||
PlayerEntity *player = OOPlayerForScripting();
|
||||
|
||||
if (argc > 0)
|
||||
{
|
||||
key = OOStringFromJSValue(context, OOJS_ARGV[0]);
|
||||
}
|
||||
if (key == nil)
|
||||
{
|
||||
OOJSReportBadArguments(context, @"PlayerShip", @"setMultiFunctionText", MIN(argc, 1U), OOJS_ARGV, nil, @"string (key) [, string (text)]");
|
||||
return NO;
|
||||
}
|
||||
if (argc > 1)
|
||||
{
|
||||
value = OOStringFromJSValue(context, OOJS_ARGV[1]);
|
||||
}
|
||||
|
||||
[player setMultiFunctionText:value forKey:key];
|
||||
|
||||
OOJS_RETURN_VOID;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static BOOL ValidateContracts(JSContext *context, uintN argc, jsval *vp, BOOL isCargo, OOSystemID *start, OOSystemID *destination, double *eta, double *fee, double *premium, NSString *functionName, unsigned *risk)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user