Merge ColorPreviewManagerWidget into ColorPickerManager.

This commit is contained in:
Paul Chote
2021-04-11 21:55:23 +01:00
committed by teinarss
parent 7b58f03f1c
commit f65de2dd43
25 changed files with 59 additions and 103 deletions

View File

@@ -1,52 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets
{
public class ColorPreviewManagerWidget : Widget
{
public readonly string PaletteName = "colorpicker";
public readonly int[] RemapIndices = ChromeMetrics.Get<int[]>("ColorPickerRemapIndices");
public readonly float Ramp = 0.05f;
public Color Color;
Color cachedColor;
WorldRenderer worldRenderer;
IPalette preview;
[ObjectCreator.UseCtor]
public ColorPreviewManagerWidget(WorldRenderer worldRenderer)
{
this.worldRenderer = worldRenderer;
}
public override void Initialize(WidgetArgs args)
{
base.Initialize(args);
preview = worldRenderer.Palette(PaletteName).Palette;
}
public override void Tick()
{
if (cachedColor == Color)
return;
cachedColor = Color;
var newPalette = new MutablePalette(preview);
newPalette.ApplyRemap(new PlayerColorRemap(RemapIndices, Color, Ramp));
worldRenderer.ReplacePalette(PaletteName, newPalette);
}
}
}

View File

@@ -52,9 +52,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
WRot modelOrientation;
[ObjectCreator.UseCtor]
public AssetBrowserLogic(Widget widget, Action onExit, ModData modData, World world, Dictionary<string, MiniYaml> logicArgs)
public AssetBrowserLogic(Widget widget, Action onExit, ModData modData, WorldRenderer worldRenderer)
{
this.world = world;
world = worldRenderer.World;
this.modData = modData;
panel = widget;
@@ -111,16 +111,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
paletteDropDown.GetText = () => currentPalette;
}
var colorPreview = panel.GetOrNull<ColorPreviewManagerWidget>("COLOR_MANAGER");
if (colorPreview != null)
colorPreview.Color = Game.Settings.Player.Color;
var colorManager = modData.DefaultRules.Actors[SystemActors.World].TraitInfo<ColorPickerManagerInfo>();
colorManager.Update(worldRenderer, Game.Settings.Player.Color);
var colorDropdown = panel.GetOrNull<DropDownButtonWidget>("COLOR");
if (colorDropdown != null)
{
colorDropdown.IsDisabled = () => currentPalette != colorPreview.PaletteName;
colorDropdown.OnMouseDown = _ => ColorPickerLogic.ShowColorDropDown(colorDropdown, colorPreview, world);
panel.Get<ColorBlockWidget>("COLORBLOCK").GetColor = () => Game.Settings.Player.Color;
colorDropdown.IsDisabled = () => currentPalette != colorManager.PaletteName;
colorDropdown.OnMouseDown = _ => ColorPickerLogic.ShowColorDropDown(colorDropdown, colorManager, worldRenderer);
panel.Get<ColorBlockWidget>("COLORBLOCK").GetColor = () => colorManager.Color;
}
filenameInput = panel.Get<TextFieldWidget>("FILENAME_INPUT");

View File

@@ -12,6 +12,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Widgets;
@@ -190,22 +191,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return h;
}
public static void ShowColorDropDown(DropDownButtonWidget color, ColorPreviewManagerWidget preview, World world)
public static void ShowColorDropDown(DropDownButtonWidget color, ColorPickerManagerInfo colorManager, WorldRenderer worldRenderer, Action onExit = null)
{
Action onExit = () =>
{
Game.Settings.Player.Color = preview.Color;
Game.Settings.Save();
};
color.RemovePanel();
Action<Color> onChange = c => preview.Color = c;
Action<Color> onChange = c => colorManager.Update(worldRenderer, c);
var colorChooser = Game.LoadWidget(world, "COLOR_CHOOSER", null, new WidgetArgs()
var colorChooser = Game.LoadWidget(worldRenderer.World, "COLOR_CHOOSER", null, new WidgetArgs()
{
{ "onChange", onChange },
{ "initialColor", Game.Settings.Player.Color },
{ "initialColor", colorManager.Color },
{ "initialFaction", null }
});

View File

@@ -11,6 +11,7 @@
using System;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
@@ -63,8 +64,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return true;
};
var colorPreview = widget.Get<ColorPreviewManagerWidget>("COLOR_MANAGER");
colorPreview.Color = ps.Color;
var colorManager = modData.DefaultRules.Actors[SystemActors.World].TraitInfo<ColorPickerManagerInfo>();
colorManager.Update(worldRenderer, ps.Color);
var mouseControlDescClassic = widget.Get("MOUSE_CONTROL_DESC_CLASSIC");
mouseControlDescClassic.IsVisible = () => gs.UseClassicMouseStyle;
@@ -103,7 +104,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var colorDropdown = widget.Get<DropDownButtonWidget>("PLAYERCOLOR");
colorDropdown.IsDisabled = () => worldRenderer.World.Type != WorldType.Shellmap;
colorDropdown.OnMouseDown = _ => ColorPickerLogic.ShowColorDropDown(colorDropdown, colorPreview, worldRenderer.World);
colorDropdown.OnMouseDown = _ => ColorPickerLogic.ShowColorDropDown(colorDropdown, colorManager, worldRenderer);
colorDropdown.Get<ColorBlockWidget>("COLORBLOCK").GetColor = () => ps.Color;
var viewportSizes = modData.Manifest.Get<WorldViewportSizes>();

View File

@@ -14,6 +14,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Network;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -32,7 +33,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly WorldRenderer worldRenderer;
readonly bool skirmishMode;
readonly Ruleset modRules;
readonly World shellmapWorld;
readonly WebServices services;
enum PanelType { Players, Options, Music, Servers, Kick, ForceStart }
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly Dictionary<string, LobbyFaction> factions = new Dictionary<string, LobbyFaction>();
readonly ColorPreviewManagerWidget colorPreview;
readonly ColorPickerManagerInfo colorManager;
readonly TabCompletionLogic tabCompletion = new TabCompletionLogic();
@@ -116,7 +116,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
// TODO: This needs to be reworked to support per-map tech levels, bots, etc.
modRules = modData.DefaultRules;
shellmapWorld = worldRenderer.World;
services = modData.Manifest.Get<WebServices>();
@@ -159,8 +158,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
editableSpectatorTemplate = players.Get("TEMPLATE_EDITABLE_SPECTATOR");
nonEditableSpectatorTemplate = players.Get("TEMPLATE_NONEDITABLE_SPECTATOR");
newSpectatorTemplate = players.Get("TEMPLATE_NEW_SPECTATOR");
colorPreview = lobby.Get<ColorPreviewManagerWidget>("COLOR_MANAGER");
colorPreview.Color = Game.Settings.Player.Color;
colorManager = modRules.Actors[SystemActors.World].TraitInfo<ColorPickerManagerInfo>();
colorManager.Update(worldRenderer, Game.Settings.Player.Color);
foreach (var f in modRules.Actors[SystemActors.World].TraitInfos<FactionInfo>())
factions.Add(f.InternalName, new LobbyFaction { Selectable = f.Selectable, Name = f.Name, Side = f.Side, Description = f.Description });
@@ -601,7 +600,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
else
LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager, worldRenderer);
LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, shellmapWorld, colorPreview);
LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, worldRenderer, colorManager);
LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, factions);
LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, map);
LobbyUtils.SetupEditableHandicapWidget(template, slot, client, orderManager, map);

View File

@@ -13,6 +13,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Network;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -220,23 +221,23 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
public static void ShowColorDropDown(DropDownButtonWidget color, Session.Client client,
OrderManager orderManager, World world, ColorPreviewManagerWidget preview)
OrderManager orderManager, WorldRenderer worldRenderer, ColorPickerManagerInfo colorManager)
{
Action onExit = () =>
{
if (client.Bot == null)
if (client == orderManager.LocalClient)
{
Game.Settings.Player.Color = preview.Color;
Game.Settings.Player.Color = colorManager.Color;
Game.Settings.Save();
}
color.RemovePanel();
orderManager.IssueOrder(Order.Command($"color {client.Index} {preview.Color}"));
orderManager.IssueOrder(Order.Command($"color {client.Index} {colorManager.Color}"));
};
Action<Color> onChange = c => preview.Color = c;
Action<Color> onChange = c => colorManager.Update(worldRenderer, c);
var colorChooser = Game.LoadWidget(world, "COLOR_CHOOSER", null, new WidgetArgs()
var colorChooser = Game.LoadWidget(worldRenderer.World, "COLOR_CHOOSER", null, new WidgetArgs()
{
{ "onChange", onChange },
{ "initialColor", client.Color },
@@ -523,11 +524,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
};
}
public static void SetupEditableColorWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, World world, ColorPreviewManagerWidget colorPreview)
public static void SetupEditableColorWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, WorldRenderer worldRenderer, ColorPickerManagerInfo colorManager)
{
var color = parent.Get<DropDownButtonWidget>("COLOR");
color.IsDisabled = () => (s != null && s.LockColor) || orderManager.LocalClient.IsReady;
color.OnMouseDown = _ => ShowColorDropDown(color, c, orderManager, world, colorPreview);
color.OnMouseDown = _ => ShowColorDropDown(color, c, orderManager, worldRenderer, colorManager);
SetupColorWidget(color, s, c);
}

View File

@@ -13,6 +13,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Support;
using OpenRA.Widgets;
@@ -179,12 +180,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return true;
};
var colorPreview = panel.Get<ColorPreviewManagerWidget>("COLOR_MANAGER");
colorPreview.Color = ps.Color;
var colorManager = modData.DefaultRules.Actors[SystemActors.World].TraitInfo<ColorPickerManagerInfo>();
colorManager.Update(worldRenderer, ps.Color);
var colorDropdown = panel.Get<DropDownButtonWidget>("PLAYERCOLOR");
colorDropdown.IsDisabled = () => worldRenderer.World.Type != WorldType.Shellmap;
colorDropdown.OnMouseDown = _ => ColorPickerLogic.ShowColorDropDown(colorDropdown, colorPreview, worldRenderer.World);
colorDropdown.OnMouseDown = _ => ColorPickerLogic.ShowColorDropDown(colorDropdown, colorManager, worldRenderer, () =>
{
Game.Settings.Player.Color = colorManager.Color;
Game.Settings.Save();
});
colorDropdown.Get<ColorBlockWidget>("COLORBLOCK").GetColor = () => ps.Color;
return () =>