Skip to content

Commit

Permalink
Added player.ship.chartHighlightMode property, and chartHighlightMode…
Browse files Browse the repository at this point in the history
…Changed event (#288)
  • Loading branch information
phkb authored and AnotherCommander committed Feb 17, 2018
1 parent c3406ef commit 835770b
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 14 deletions.
8 changes: 0 additions & 8 deletions src/Core/Entities/PlayerEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,6 @@ typedef enum
} OOSpeechSettings;


typedef enum
{
OOLRC_MODE_NORMAL = 0,
OOLRC_MODE_ECONOMY = 1,
OOLRC_MODE_GOVERNMENT = 2,
OOLRC_MODE_TECHLEVEL = 3
} OOLongRangeChartMode;

// When fully zoomed in, chart shows area of galaxy that's 64x64 galaxy units.
#define CHART_WIDTH_AT_MAX_ZOOM 64.0
#define CHART_HEIGHT_AT_MAX_ZOOM 64.0
Expand Down
6 changes: 3 additions & 3 deletions src/Core/Entities/PlayerEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -1248,8 +1248,8 @@ - (BOOL)setCommanderDataFromDictionary:(NSDictionary *) dict
target_chart_zoom = chart_zoom;
saved_chart_zoom = chart_zoom;
ANA_mode = [dict oo_intForKey:@"chart_ana_mode" defaultValue:OPTIMIZED_BY_NONE];
longRangeChartMode = [dict oo_intForKey:@"chart_colour_mode" defaultValue:OOLRC_MODE_NORMAL];

longRangeChartMode = [dict oo_intForKey:@"chart_colour_mode" defaultValue:OOLRC_MODE_SUNCOLOR];
if (longRangeChartMode == OOLRC_MODE_UNKNOWN) longRangeChartMode = OOLRC_MODE_SUNCOLOR;

target_system_id = [dict oo_intForKey:@"target_id" defaultValue:system_id];
info_system_id = target_system_id;
Expand Down Expand Up @@ -1954,7 +1954,7 @@ - (BOOL) setUpAndConfirmOK:(BOOL)stopOnError saveGame:(BOOL)saveGame

[self switchHudTo:@"hud.plist"];
scanner_zoom_rate = 0.0f;
longRangeChartMode = OOLRC_MODE_NORMAL;
longRangeChartMode = OOLRC_MODE_SUNCOLOR;

[mission_variables release];
mission_variables = [[NSMutableDictionary alloc] init];
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Entities/PlayerEntityControls.m
Original file line number Diff line number Diff line change
Expand Up @@ -1754,8 +1754,9 @@ - (void) pollGuiArrowKeyControls:(double) delta_t
}
else
{
[self setLongRangeChartMode:OOLRC_MODE_NORMAL];
[self setLongRangeChartMode:OOLRC_MODE_SUNCOLOR];
}
[self doScriptEvent:OOJSID("chartHighlightModeChanged") withArgument:OOStringFromLongRangeChartMode([self longRangeChartMode])];
}
queryPressed = YES;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Core/GuiDisplayGen.m
Original file line number Diff line number Diff line change
Expand Up @@ -2052,7 +2052,8 @@ - (void) drawStarChart:(GLfloat)x :(GLfloat)y :(GLfloat)z :(GLfloat) alpha :(BOO
}
OOGL(glColor4f(r, g, b, alpha));
break;
case OOLRC_MODE_NORMAL:
case OOLRC_MODE_UNKNOWN:
case OOLRC_MODE_SUNCOLOR:
if (EXPECT(noNova))
{
r = g = b = 1.0;
Expand Down
4 changes: 4 additions & 0 deletions src/Core/OOConstToString.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ NSString *DisplayStringForMassUnitForCommodity(OOCommodityType commodity);
NSString *OOStringFromCompassMode(OOCompassMode mode);
OOCompassMode OOCompassModeFromString(NSString *string);

NSString *OOStringFromLongRangeChartMode(OOLongRangeChartMode chartMode);
OOLongRangeChartMode OOLongRangeChartModeFromString(NSString *string);

NSString *OOStringFromLegalStatusReason(OOLegalStatusReason reason);

NSString *RouteTypeToString(OORouteType routeType);
Expand All @@ -113,3 +116,4 @@ NSString *DockingClearanceStatusToString(OODockingClearanceStatus dockingClearan

NSString *OOStringFromGraphicsDetail(OOGraphicsDetail detail);
OOGraphicsDetail OOGraphicsDetailFromString(NSString *string);

16 changes: 16 additions & 0 deletions src/Core/OOConstToString.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@
return @"UNDEFINED";
}

NSString *OOStringFromLongRangeChartMode(OOLongRangeChartMode value)
{
switch (value)
{
#include "OOLongRangeChartMode.tbl"
}

return @"UNDEFINED";
}

NSString *OOStringFromGalacticHyperspaceBehaviour(OOGalacticHyperspaceBehaviour value)
{
Expand Down Expand Up @@ -178,6 +187,13 @@ OOScanClass OOScanClassFromString(NSString *string)
return kOOScanClassDefault;
}

OOLongRangeChartMode OOLongRangeChartModeFromString(NSString *string)
{
#include "OOLongRangeChartMode.tbl"

return kOOLongRangeChartModeDefault;
}

#undef ENTRY
#undef GALACTIC_HYPERSPACE_ENTRY

Expand Down
7 changes: 7 additions & 0 deletions src/Core/OOTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ typedef enum
kOOViewIDDefault = VIEW_NONE
} OOViewID;

typedef enum
{
#include "OOLongRangeChartMode.tbl"

kOOLongRangeChartModeDefault = OOLRC_MODE_SUNCOLOR
} OOLongRangeChartMode;

#undef ENTRY


Expand Down
8 changes: 7 additions & 1 deletion src/Core/Scripting/OOConstToJSString.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ Initialize table contents (with C strings, see above) from table files.
#include "OOLegalStatusReason.tbl"
};

static TableEntry sOOLongRangeChartModeTableEntries[] =
{
#include "OOLongRangeChartMode.tbl"
};

#undef ENTRY
#undef GALACTIC_HYPERSPACE_ENTRY
Expand All @@ -130,6 +134,7 @@ Initialize table contents (with C strings, see above) from table files.
ConstTable gOOViewIDConstTable = TABLE(sOOViewIDTableEntries);
ConstTable gOOShipDamageTypeConstTable = TABLE(sOOShipDamageTypeTableEntries);
ConstTable gOOLegalStatusReasonConstTable = TABLE(sOOLegalStatusReasonTableEntries);
ConstTable gOOLongRangeChartModeConstTable = TABLE(sOOLongRangeChartModeTableEntries);

static void InitTable(JSContext *context, ConstTable *table);

Expand All @@ -151,7 +156,8 @@ void OOConstToJSStringInit(JSContext *context)
InitTable(context, &gOOViewIDConstTable);
InitTable(context, &gOOShipDamageTypeConstTable);
InitTable(context, &gOOLegalStatusReasonConstTable);

InitTable(context, &gOOLongRangeChartModeConstTable);

sInited = YES;
}

Expand Down
25 changes: 25 additions & 0 deletions src/Core/Scripting/OOJSPlayerShip.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
// Property IDs
kPlayerShip_aftShield, // aft shield charge level, nonnegative float, read/write
kPlayerShip_aftShieldRechargeRate, // aft shield recharge rate, positive float, read-only
kPlayerShip_chartHightlightMode, // what type of information is being shown on the chart
kPlayerShip_compassMode, // compass mode, string, read/write
kPlayerShip_compassTarget, // object targeted by the compass, entity, read/write
kPlayerShip_compassType, // basic / advanced, string, read/write
Expand Down Expand Up @@ -171,6 +172,7 @@
// JS name ID flags
{ "aftShield", kPlayerShip_aftShield, OOJS_PROP_READWRITE_CB },
{ "aftShieldRechargeRate", kPlayerShip_aftShieldRechargeRate, OOJS_PROP_READWRITE_CB },
{ "chartHighlightMode", kPlayerShip_chartHightlightMode, OOJS_PROP_READWRITE_CB },
{ "compassMode", kPlayerShip_compassMode, OOJS_PROP_READWRITE_CB },
{ "compassTarget", kPlayerShip_compassTarget, OOJS_PROP_READWRITE_CB },
{ "compassType", kPlayerShip_compassType, OOJS_PROP_READWRITE_CB },
Expand Down Expand Up @@ -438,6 +440,10 @@ static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsid pro
*value = OOJSValueFromBOOL(![player dialIdentEngaged]);
return YES;

case kPlayerShip_chartHightlightMode:
result = OOStringFromLongRangeChartMode([player longRangeChartMode]);
break;

case kPlayerShip_galaxyCoordinates:
return NSPointToVectorJSValue(context, [player galaxy_coordinates], value);

Expand Down Expand Up @@ -644,6 +650,25 @@ static JSBool PlayerShipSetProperty(JSContext *context, JSObject *this, jsid pro
}
break;

case kPlayerShip_chartHightlightMode:
sValue = OOStringFromJSValue(context, *value);
if (sValue != nil)
{
OOLongRangeChartMode chartMode = OOLongRangeChartModeFromString(sValue);
if (chartMode > OOLRC_MODE_UNKNOWN)
{
[player setLongRangeChartMode:chartMode];
[player doScriptEvent:OOJSID("chartHighlightModeChanged") withArgument:OOStringFromLongRangeChartMode([player longRangeChartMode])];
return YES;
}
else
{
OOJSReportError(context, @"Unknown chart hightlight mode specified - must be either OOLRC_MODE_SUNCOLOR, OOLRC_MODE_ECONOMY, OOLRC_MODE_GOVERNMENT or OOLRC_MODE_TECHLEVEL.");
}
}
return NO; // not reachable if successfully set
break;

case kPlayerShip_compassMode:
sValue = OOStringFromJSValue(context, *value);
if(sValue != nil)
Expand Down
5 changes: 5 additions & 0 deletions src/Core/Tables/OOLongRangeChartMode.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ENTRY(OOLRC_MODE_UNKNOWN, -1)
ENTRY(OOLRC_MODE_SUNCOLOR, 0)
ENTRY(OOLRC_MODE_ECONOMY, 1)
ENTRY(OOLRC_MODE_GOVERNMENT, 2)
ENTRY(OOLRC_MODE_TECHLEVEL, 3)

0 comments on commit 835770b

Please sign in to comment.