Merge pull request #247 from phkb/equipment_display_color

Adds a "display_color" property to equipment items, used on equip ship screen
This commit is contained in:
AnotherCommander 2017-07-28 11:08:54 +02:00 committed by GitHub
commit 8e192e052f
6 changed files with 57 additions and 19 deletions

View File

@ -989,7 +989,7 @@ typedef enum
- (void) docked;
- (void) setGuiToStatusScreen;
- (NSArray *) equipmentList; // Each entry is an array with a string followed by a boolean indicating availability (NO = damaged).
- (NSArray *) equipmentList; // Each entry is an array with a string followed by a boolean indicating availability (NO = damaged), then a color (or nil for default color).
- (BOOL) setPrimedEquipment:(NSString *)eqKey showMessage:(BOOL)showMsg;
- (NSString *) primedEquipmentName:(NSInteger)offset;
- (NSUInteger) primedEquipmentCount;

View File

@ -7801,14 +7801,14 @@ NSComparisonResult marketSorterByMassUnit(id a, id b, void *market);
// only one installed display normally
if (count == 1)
{
[quip2 addObject:[NSArray arrayWithObjects:[eqType name], [NSNumber numberWithBool:YES], nil]];
[quip2 addObject:[NSArray arrayWithObjects:[eqType name], [NSNumber numberWithBool:YES], [eqType displayColor], nil]];
}
// display plural form
else
{
NSString *equipmentName = [eqType name];
alldesc = OOExpandKey(@"equipment-plural", count, equipmentName);
[quip2 addObject:[NSArray arrayWithObjects:alldesc, [NSNumber numberWithBool:YES], nil]];
[quip2 addObject:[NSArray arrayWithObjects:alldesc, [NSNumber numberWithBool:YES], [eqType displayColor], nil]];
}
}
// all broken, only one installed
@ -7817,11 +7817,11 @@ NSComparisonResult marketSorterByMassUnit(id a, id b, void *market);
desc = [NSString stringWithFormat:DESC(@"equipment-@-not-available"), [eqType name]];
if (prioritiseDamaged)
{
[quip1 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:NO], nil]];
[quip1 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:NO], [eqType displayColor], nil]];
}
else
{
[quip2 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:NO], nil]];
[quip2 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:NO], [eqType displayColor], nil]];
}
}
// some broken, multiple installed
@ -7831,17 +7831,17 @@ NSComparisonResult marketSorterByMassUnit(id a, id b, void *market);
alldesc = OOExpandKey(@"equipment-plural-some-na", okcount, count, equipmentName);
if (prioritiseDamaged)
{
[quip1 addObject:[NSArray arrayWithObjects:alldesc, [NSNumber numberWithBool:NO], nil]];
[quip1 addObject:[NSArray arrayWithObjects:alldesc, [NSNumber numberWithBool:NO], [eqType displayColor], nil]];
}
else
{
[quip2 addObject:[NSArray arrayWithObjects:alldesc, [NSNumber numberWithBool:NO], nil]];
[quip2 addObject:[NSArray arrayWithObjects:alldesc, [NSNumber numberWithBool:NO], [eqType displayColor], nil]];
}
}
}
else if ([self hasEquipmentItem:[eqType identifier]])
{
[quip2 addObject:[NSArray arrayWithObjects:[eqType name], [NSNumber numberWithBool:YES], nil]];
[quip2 addObject:[NSArray arrayWithObjects:[eqType name], [NSNumber numberWithBool:YES], [eqType displayColor], nil]];
}
else
{
@ -7852,12 +7852,12 @@ NSComparisonResult marketSorterByMassUnit(id a, id b, void *market);
if (prioritiseDamaged)
{
[quip1 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:NO], nil]];
[quip1 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:NO], [eqType displayColor], nil]];
}
else
{
// just add in to the normal array
[quip2 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:NO], nil]];
[quip2 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:NO], [eqType displayColor], nil]];
}
}
}
@ -7867,28 +7867,28 @@ NSComparisonResult marketSorterByMassUnit(id a, id b, void *market);
if (max_passengers > 0)
{
desc = [NSString stringWithFormat:DESC_PLURAL(@"equipment-pass-berth-@", max_passengers), max_passengers];
[quip2 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:YES], nil]];
[quip2 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:YES], [[OOEquipmentType equipmentTypeWithIdentifier:@"EQ_PASSENGER_BERTH"] displayColor], nil]];
}
if (!isWeaponNone(forward_weapon_type))
{
desc = [NSString stringWithFormat:DESC(@"equipment-fwd-weapon-@"),[forward_weapon_type name]];
[quip2 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:YES], nil]];
[quip2 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:YES], [forward_weapon_type displayColor], nil]];
}
if (!isWeaponNone(aft_weapon_type))
{
desc = [NSString stringWithFormat:DESC(@"equipment-aft-weapon-@"),[aft_weapon_type name]];
[quip2 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:YES], nil]];
[quip2 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:YES], [aft_weapon_type displayColor], nil]];
}
if (!isWeaponNone(port_weapon_type))
{
desc = [NSString stringWithFormat:DESC(@"equipment-port-weapon-@"),[port_weapon_type name]];
[quip2 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:YES], nil]];
[quip2 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:YES], [port_weapon_type displayColor], nil]];
}
if (!isWeaponNone(starboard_weapon_type))
{
desc = [NSString stringWithFormat:DESC(@"equipment-stb-weapon-@"),[starboard_weapon_type name]];
[quip2 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:YES], nil]];
[quip2 addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:YES], [starboard_weapon_type displayColor], nil]];
}
// list damaged first, then working
@ -9107,7 +9107,9 @@ static NSString *last_outfitting_key=nil;
NSString *eq_key_damaged = [eqInfo damagedIdentifier];
double price;
[gui setColor:[gui colorFromSetting:kGuiEquipmentOptionColor defaultValue:nil] forRow:row];
OOColor *dispCol = [eqInfo displayColor];
if (dispCol == nil) dispCol = [gui colorFromSetting:kGuiEquipmentOptionColor defaultValue:nil];
[gui setColor:dispCol forRow:row];
if ([eqKey isEqual:@"EQ_FUEL"])
{

View File

@ -1293,10 +1293,11 @@ static OOTextureSprite *NewTextureSpriteWithDescriptor(NSDictionary *descriptor)
// Damaged items show up orange.
[self setGLColorFromSetting:@"status_equipment_damaged_color" defaultValue:[OOColor orangeColor] alpha:1.0];
}
else
else /// add color selection here
{
OOColor *dispCol = [info oo_objectAtIndex:2];
// Normal items in default colour
[self setGLColorFromSetting:@"status_equipment_ok_color" defaultValue:nil alpha:1.0];
[self setGLColorFromSetting:@"status_equipment_ok_color" defaultValue:dispCol alpha:1.0];
}
if (i - start < itemsPerColumn)

View File

@ -58,6 +58,7 @@ SOFTWARE.
_fastAffinityA: 1,
_fastAffinityB: 1,
_canCarryMultiple: 1;
OOColor *_displayColor;
NSUInteger _installTime;
NSUInteger _repairTime;
GLfloat _damageProbability;
@ -110,6 +111,8 @@ SOFTWARE.
- (GLfloat) damageProbability;
- (BOOL) canBeDamaged;
- (BOOL) isVisible; // Visible in UI?
- (OOColor *) displayColor;
- (void) setDisplayColor:(OOColor *)newColor;
- (BOOL) isAvailableToPlayer;
- (BOOL) isAvailableToNPCs;

View File

@ -233,6 +233,9 @@ static NSDictionary *sMissilesRegistry = nil;
_repairTime = [extra oo_unsignedIntForKey:@"repair_time" defaultValue:0];
_provides = [[extra oo_arrayForKey:@"provides" defaultValue:[NSArray array]] retain];
id dispColor = [extra oo_objectForKey:@"display_color" defaultValue:nil];
_displayColor = [[OOColor colorWithDescription:dispColor] retain];
_weaponInfo = [[extra oo_dictionaryForKey:@"weapon_info" defaultValue:[NSDictionary dictionary]] retain];
_damageProbability = [extra oo_floatForKey:@"damage_probability" defaultValue:(_isMissileOrMine?0.0:1.0)];
@ -324,6 +327,7 @@ static NSDictionary *sMissilesRegistry = nil;
DESTROY(_name);
DESTROY(_identifier);
DESTROY(_description);
DESTROY(_displayColor);
DESTROY(_requiresEquipment);
DESTROY(_requiresAnyEquipment);
DESTROY(_incompatibleEquipment);
@ -533,6 +537,19 @@ static NSDictionary *sMissilesRegistry = nil;
}
- (OOColor *) displayColor
{
return _displayColor;
}
- (void) setDisplayColor:(OOColor *)color
{
[_displayColor release];
_displayColor = [color retain];
}
- (NSArray *) conditions
{
return _conditions;

View File

@ -49,6 +49,7 @@ enum
kEquipmentInfo_canCarryMultiple,
kEquipmentInfo_damageProbability,
kEquipmentInfo_description,
kEquipmentInfo_displayColor,
kEquipmentInfo_effectiveTechLevel,
kEquipmentInfo_equipmentKey,
kEquipmentInfo_fastAffinityDefensive,
@ -86,6 +87,7 @@ static JSPropertySpec sEquipmentInfoProperties[] =
{ "canCarryMultiple", kEquipmentInfo_canCarryMultiple, OOJS_PROP_READONLY_CB },
{ "damageProbability", kEquipmentInfo_damageProbability, OOJS_PROP_READONLY_CB },
{ "description", kEquipmentInfo_description, OOJS_PROP_READONLY_CB },
{ "displayColor", kEquipmentInfo_displayColor, OOJS_PROP_READWRITE_CB },
{ "effectiveTechLevel", kEquipmentInfo_effectiveTechLevel, OOJS_PROP_READWRITE_CB },
{ "equipmentKey", kEquipmentInfo_equipmentKey, OOJS_PROP_READONLY_CB },
{ "fastAffinityDefensive", kEquipmentInfo_fastAffinityDefensive, OOJS_PROP_READONLY_CB },
@ -268,6 +270,10 @@ static JSBool EquipmentInfoGetProperty(JSContext *context, JSObject *this, jsid
case kEquipmentInfo_damageProbability:
return JS_NewNumberValue(context, [eqType damageProbability], value);
case kEquipmentInfo_displayColor:
result = [[eqType displayColor] normalizedArray];
break;
case kEquipmentInfo_fastAffinityDefensive:
*value = OOJSValueFromBOOL([eqType fastAffinityDefensive]);
return YES;
@ -389,11 +395,20 @@ static JSBool EquipmentInfoSetProperty(JSContext *context, JSObject *this, jsid
OOEquipmentType *eqType = nil;
int32 iValue;
OOColor *colorForScript = nil;
if (EXPECT_NOT(!JSEquipmentInfoGetEquipmentType(context, this, &eqType))) return NO;
switch (JSID_TO_INT(propID))
{
case kEquipmentInfo_displayColor:
colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
if (colorForScript != nil || JSVAL_IS_NULL(*value))
{
[eqType setDisplayColor:colorForScript];
return YES;
}
break;
case kEquipmentInfo_effectiveTechLevel:
OOStandardsDeprecated([NSString stringWithFormat:@"TL99 for variable tech level is deprecated for %@",[eqType identifier]]);
if (!OOEnforceStandards() && [eqType techLevel] == kOOVariableTechLevel)