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]
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 float Ramp = 0.05f;
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,
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 mixer = widget.Get<ColorMixerWidget>("MIXER");
var randomButton = widget.GetOrNull<ButtonWidget>("RANDOM_BUTTON");
@@ -71,6 +56,34 @@ namespace OpenRA.Mods.Common.Widgets.Logic
mixer.Set(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
// be equal to the given initialColor due to its internal RGB -> HSL -> RGB
// conversion. This conversion can sometimes convert a valid initial value