Move color picker actor type from metrics to ColorPickerManager.

This commit is contained in:
Paul Chote
2021-05-09 15:09:20 +01:00
committed by teinarss
parent f65de2dd43
commit 9d62ce214c
10 changed files with 41 additions and 19 deletions

View File

@@ -31,6 +31,15 @@ namespace OpenRA.Mods.Common.Traits
[PaletteReference] [PaletteReference]
public readonly string PaletteName = "colorpicker"; public readonly string PaletteName = "colorpicker";
[ActorReference]
[Desc("Actor type to show in the color picker. This can be overriden for specific factions with FactionPreviewActors.")]
public readonly string PreviewActor = null;
[SequenceReference(dictionaryReference: LintDictionaryReference.Values)]
[Desc("Actor type to show in the color picker for specific factions. Overrides PreviewActor.",
"A dictionary of [faction name]: [actor name].")]
public readonly Dictionary<string, string> FactionPreviewActors = new Dictionary<string, string>();
public readonly int[] RemapIndices = { }; public readonly int[] RemapIndices = { };
public readonly float Ramp = 0.05f; public readonly float Ramp = 0.05f;
public Color Color { get; private set; } public Color Color { get; private set; }

View File

@@ -28,21 +28,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public ColorPickerLogic(Widget widget, ModData modData, World world, Color initialColor, string initialFaction, Action<Color> onChange, public ColorPickerLogic(Widget widget, ModData modData, World world, Color initialColor, string initialFaction, Action<Color> onChange,
Dictionary<string, MiniYaml> logicArgs) Dictionary<string, MiniYaml> logicArgs)
{ {
if (initialFaction == null || !ChromeMetrics.TryGet("ColorPickerActorType-" + initialFaction, out string actorType))
actorType = ChromeMetrics.Get<string>("ColorPickerActorType");
var preview = widget.GetOrNull<ActorPreviewWidget>("PREVIEW");
var actor = world.Map.Rules.Actors[actorType];
var td = new TypeDictionary();
td.Add(new OwnerInit(world.WorldActor.Owner));
td.Add(new FactionInit(world.WorldActor.Owner.PlayerReference.Faction));
foreach (var api in actor.TraitInfos<IActorPreviewInitInfo>())
foreach (var o in api.ActorPreviewInits(actor, ActorPreviewType.ColorPicker))
td.Add(o);
preview?.SetPreview(actor, td);
var hueSlider = widget.Get<SliderWidget>("HUE"); var hueSlider = widget.Get<SliderWidget>("HUE");
var mixer = widget.Get<ColorMixerWidget>("MIXER"); var mixer = widget.Get<ColorMixerWidget>("MIXER");
var randomButton = widget.GetOrNull<ButtonWidget>("RANDOM_BUTTON"); var randomButton = widget.GetOrNull<ButtonWidget>("RANDOM_BUTTON");
@@ -71,6 +56,34 @@ namespace OpenRA.Mods.Common.Widgets.Logic
mixer.Set(initialColor); mixer.Set(initialColor);
hueSlider.Value = HueFromColor(initialColor); hueSlider.Value = HueFromColor(initialColor);
if (initialFaction == null || !colorManager.FactionPreviewActors.TryGetValue(initialFaction, out var actorType))
actorType = colorManager.PreviewActor;
if (actorType == null)
{
var message = "ColorPickerManager does not define a preview actor";
if (initialFaction != null)
message += " for faction " + initialFaction;
message += "!";
throw new YamlException(message);
}
var preview = widget.GetOrNull<ActorPreviewWidget>("PREVIEW");
var actor = world.Map.Rules.Actors[actorType];
var td = new TypeDictionary
{
new OwnerInit(world.WorldActor.Owner),
new FactionInit(world.WorldActor.Owner.PlayerReference.Faction)
};
foreach (var api in actor.TraitInfos<IActorPreviewInitInfo>())
foreach (var o in api.ActorPreviewInits(actor, ActorPreviewType.ColorPicker))
td.Add(o);
preview?.SetPreview(actor, td);
// HACK: the value returned from the color mixer will generally not // HACK: the value returned from the color mixer will generally not
// be equal to the given initialColor due to its internal RGB -> HSL -> RGB // be equal to the given initialColor due to its internal RGB -> HSL -> RGB
// conversion. This conversion can sometimes convert a valid initial value // conversion. This conversion can sometimes convert a valid initial value

View File

@@ -4,5 +4,4 @@ Metrics:
ButtonDepth: 0 ButtonDepth: 0
ButtonFont: Bold ButtonFont: Bold
CheckboxPressedState: true CheckboxPressedState: true
ColorPickerActorType: fact.colorpicker
TextfieldColorHighlight: 800000 TextfieldColorHighlight: 800000

View File

@@ -255,6 +255,7 @@ World:
ScriptTriggers: ScriptTriggers:
TimeLimitManager: TimeLimitManager:
ColorPickerManager: ColorPickerManager:
PreviewActor: fact.colorpicker
RemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190 RemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190
TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 502048, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 502048, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d

View File

@@ -1,6 +1,5 @@
# General dumping-ground for UI element sizes, etc. # General dumping-ground for UI element sizes, etc.
Metrics: Metrics:
ColorPickerActorType: carryall.colorpicker
FactionSuffix-fremen: atreides FactionSuffix-fremen: atreides
FactionSuffix-corrino: harkonnen FactionSuffix-corrino: harkonnen
FactionSuffix-smuggler: ordos FactionSuffix-smuggler: ordos

View File

@@ -236,6 +236,7 @@ World:
StartGameNotification: StartGameNotification:
TimeLimitManager: TimeLimitManager:
ColorPickerManager: ColorPickerManager:
PreviewActor: carryall.colorpicker
RemapIndices: 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240 RemapIndices: 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240
TeamColorPresets: 9023cd, f53333, ffae00, fff830, 87f506, f872ad, da06f3, ddb8ff, def7b2, 39c46f, 200738, 280df6, 2f86f2, 76d2f8, 498221, 392929 TeamColorPresets: 9023cd, f53333, ffae00, fff830, 87f506, f872ad, da06f3, ddb8ff, def7b2, 39c46f, 200738, 280df6, 2f86f2, 76d2f8, 498221, 392929

View File

@@ -1,7 +1,6 @@
# General dumping-ground for UI element sizes, etc. # General dumping-ground for UI element sizes, etc.
Metrics: Metrics:
ColorPickerActorType: fact.colorpicker
FactionSuffix-allies: allies FactionSuffix-allies: allies
FactionSuffix-england: allies FactionSuffix-england: allies
FactionSuffix-france: allies FactionSuffix-france: allies

View File

@@ -281,6 +281,7 @@ World:
2: WarningTwoMinutesRemaining 2: WarningTwoMinutesRemaining
1: WarningOneMinuteRemaining 1: WarningOneMinuteRemaining
ColorPickerManager: ColorPickerManager:
PreviewActor: fact.colorpicker
RemapIndices: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 RemapIndices: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95
TeamColorPresets: f7b3b3, f50606, 98331f, f57606, f7bb06, f861a4, da06f3, ddb8ff, 06f739, cef7b2, 200738, 280df6, 2f86f2, 76d2f8, 34ba93, 391d1d TeamColorPresets: f7b3b3, f50606, 98331f, f57606, f7bb06, f861a4, da06f3, ddb8ff, 06f739, cef7b2, 200738, 280df6, 2f86f2, 76d2f8, 34ba93, 391d1d

View File

@@ -1,4 +1,3 @@
# General dumping-ground for UI element sizes, etc. # General dumping-ground for UI element sizes, etc.
Metrics: Metrics:
ColorPickerActorType: mmch.colorpicker
TextfieldColorHighlight: 1a1a1a TextfieldColorHighlight: 1a1a1a

View File

@@ -381,6 +381,7 @@ World:
ScriptTriggers: ScriptTriggers:
TimeLimitManager: TimeLimitManager:
ColorPickerManager: ColorPickerManager:
PreviewActor: mmch.colorpicker
RemapIndices: 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 RemapIndices: 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 4A1948, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 4A1948, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d