Use ActorPreviewWidget for the color pickers.

This commit is contained in:
Paul Chote
2015-02-09 23:48:42 +00:00
parent aa9db669e7
commit 8d51fb0e66
18 changed files with 63 additions and 100 deletions

View File

@@ -218,7 +218,6 @@
<Compile Include="Traits\World\ActorMap.cs" /> <Compile Include="Traits\World\ActorMap.cs" />
<Compile Include="Widgets\HotkeyEntryWidget.cs" /> <Compile Include="Widgets\HotkeyEntryWidget.cs" />
<Compile Include="Widgets\SpriteWidget.cs" /> <Compile Include="Widgets\SpriteWidget.cs" />
<Compile Include="Widgets\SpriteSequenceWidget.cs" />
<Compile Include="Widgets\RGBASpriteWidget.cs" /> <Compile Include="Widgets\RGBASpriteWidget.cs" />
<Compile Include="Scripting\ScriptContext.cs" /> <Compile Include="Scripting\ScriptContext.cs" />
<Compile Include="Scripting\ScriptActorInterface.cs" /> <Compile Include="Scripting\ScriptActorInterface.cs" />

View File

@@ -1,65 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 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. For more information,
* see COPYING.
*/
#endregion
using System;
using OpenRA.Graphics;
namespace OpenRA.Widgets
{
public class SpriteSequenceWidget : SpriteWidget
{
public string Unit = null;
public string Sequence = null;
public int Frame = 0;
public int Facing = 0;
public Func<Animation> GetAnimation;
public Func<int> GetFacing;
[ObjectCreator.UseCtor]
public SpriteSequenceWidget(WorldRenderer worldRenderer)
: base(worldRenderer)
{
GetAnimation = () => null;
}
public override void Initialize(WidgetArgs args)
{
base.Initialize(args);
if (Unit != null && Sequence != null)
{
var anim = new Animation(WorldRenderer.World, Unit, () => Facing);
anim.PlayFetchIndex(Sequence, () => Frame);
GetAnimation = () => anim;
}
GetSprite = () =>
{
var anim = GetAnimation();
return anim != null ? anim.Image : null;
};
}
protected SpriteSequenceWidget(SpriteSequenceWidget other)
: base(other)
{
Unit = other.Unit;
Sequence = other.Sequence;
Frame = other.Frame;
Facing = other.Facing;
GetAnimation = other.GetAnimation;
GetFacing = other.GetFacing;
}
public override Widget Clone() { return new SpriteSequenceWidget(this); }
}
}

View File

@@ -10,6 +10,7 @@
using System; using System;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Widgets; using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic namespace OpenRA.Mods.Common.Widgets.Logic
@@ -17,16 +18,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public class ColorPickerLogic public class ColorPickerLogic
{ {
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public ColorPickerLogic(Widget widget, HSLColor initialColor, Action<HSLColor> onChange, WorldRenderer worldRenderer) public ColorPickerLogic(Widget widget, World world, HSLColor initialColor, Action<HSLColor> onChange, WorldRenderer worldRenderer)
{ {
var ticker = widget.GetOrNull<LogicTickerWidget>("ANIMATE_PREVIEW"); string actorType;
if (ticker != null) if (!ChromeMetrics.TryGet<string>("ColorPickerActorType", out actorType))
{ actorType = "mcv";
var preview = widget.Get<SpriteSequenceWidget>("PREVIEW");
var anim = preview.GetAnimation(); var preview = widget.GetOrNull<ActorPreviewWidget>("PREVIEW");
anim.PlayRepeating(anim.CurrentSequence.Name); var actor = world.Map.Rules.Actors[actorType];
ticker.OnTick = anim.Tick; preview.SetPreview(actor, world.WorldActor.Owner, new TypeDictionary());
}
var hueSlider = widget.Get<SliderWidget>("HUE"); var hueSlider = widget.Get<SliderWidget>("HUE");
var mixer = widget.Get<ColorMixerWidget>("MIXER"); var mixer = widget.Get<ColorMixerWidget>("MIXER");

View File

@@ -32,6 +32,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly OrderManager orderManager; readonly OrderManager orderManager;
readonly bool skirmishMode; readonly bool skirmishMode;
readonly Ruleset modRules; readonly Ruleset modRules;
readonly World shellmapWorld;
enum PanelType { Players, Options, Kick, ForceStart } enum PanelType { Players, Options, Kick, ForceStart }
PanelType panel = PanelType.Players; PanelType panel = PanelType.Players;
@@ -108,6 +109,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
this.onExit = onExit; this.onExit = onExit;
this.skirmishMode = skirmishMode; this.skirmishMode = skirmishMode;
this.modRules = modRules; this.modRules = modRules;
shellmapWorld = worldRenderer.World;
orderManager.AddChatLine += AddChatLine; orderManager.AddChatLine += AddChatLine;
Game.LobbyInfoChanged += UpdateCurrentMap; Game.LobbyInfoChanged += UpdateCurrentMap;
@@ -699,7 +701,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
else else
LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager); LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager);
LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, colorPreview); LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, shellmapWorld, colorPreview);
LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, countries); LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, countries);
LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, Map); LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, Map);
LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, Map); LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, Map);

View File

@@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
} }
public static void ShowColorDropDown(DropDownButtonWidget color, Session.Client client, public static void ShowColorDropDown(DropDownButtonWidget color, Session.Client client,
OrderManager orderManager, ColorPreviewManagerWidget preview) OrderManager orderManager, World world, ColorPreviewManagerWidget preview)
{ {
Action onExit = () => Action onExit = () =>
{ {
@@ -143,7 +143,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Action<HSLColor> onChange = c => preview.Color = c; Action<HSLColor> onChange = c => preview.Color = c;
var colorChooser = Game.LoadWidget(orderManager.World, "COLOR_CHOOSER", null, new WidgetArgs() var colorChooser = Game.LoadWidget(world, "COLOR_CHOOSER", null, new WidgetArgs()
{ {
{ "onChange", onChange }, { "onChange", onChange },
{ "initialColor", client.Color } { "initialColor", client.Color }
@@ -377,11 +377,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}; };
} }
public static void SetupEditableColorWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, ColorPreviewManagerWidget colorPreview) public static void SetupEditableColorWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, World world, ColorPreviewManagerWidget colorPreview)
{ {
var color = parent.Get<DropDownButtonWidget>("COLOR"); var color = parent.Get<DropDownButtonWidget>("COLOR");
color.IsDisabled = () => (s != null && s.LockColor) || orderManager.LocalClient.IsReady; color.IsDisabled = () => (s != null && s.LockColor) || orderManager.LocalClient.IsReady;
color.OnMouseDown = _ => ShowColorDropDown(color, c, orderManager, colorPreview); color.OnMouseDown = _ => ShowColorDropDown(color, c, orderManager, world, colorPreview);
SetupColorWidget(color, s, c); SetupColorWidget(color, s, c);
} }

View File

@@ -30,14 +30,12 @@ Background@COLOR_CHOOSER:
Y: 2 Y: 2
Width: 144 Width: 144
Height: 72 Height: 72
SpriteSequence@PREVIEW: ActorPreview@PREVIEW:
X: 153 X: 153
Y: 1 Y: 1
Width: 80 Width: 80
Height: 73 Height: 73
Palette: colorpicker Animate: true
Unit: fact
Sequence: idle
Button@RANDOM_BUTTON: Button@RANDOM_BUTTON:
Key: tab Key: tab
X: 158 X: 158

View File

@@ -20,6 +20,7 @@ Metrics:
TextContrast: false TextContrast: false
TextContrastColor: 0,0,0 TextContrastColor: 0,0,0
ColorPickerRemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190 ColorPickerRemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190
ColorPickerActorType: ^fact.colorpicker
SpawnFont: TinyBold SpawnFont: TinyBold
SpawnColor: 255,255,255 SpawnColor: 255,255,255
SpawnContrastColor: 0,0,0 SpawnContrastColor: 0,0,0

View File

@@ -42,6 +42,12 @@ waypoint:
RenderEditorOnly: RenderEditorOnly:
BodyOrientation: BodyOrientation:
^fact.colorpicker:
Inherits: FACT
RenderBuilding:
Image: fact
Palette: colorpicker
CAMERA: CAMERA:
Immobile: Immobile:
OccupiesSpace: false OccupiesSpace: false

View File

@@ -29,15 +29,11 @@ Background@COLOR_CHOOSER:
Y: 2 Y: 2
Width: 144 Width: 144
Height: 72 Height: 72
SpriteSequence@FACT: ActorPreview@PREVIEW:
X: 153 X: 153
Y: 1 Y: 1
Width: 80 Width: 80
Height: 73 Height: 73
Palette: colorpicker
Unit: carryall
Sequence: idle
Facing: 104
Button@RANDOM_BUTTON: Button@RANDOM_BUTTON:
Key: tab Key: tab
X: 158 X: 158

View File

@@ -20,6 +20,7 @@ Metrics:
TextContrast: false TextContrast: false
TextContrastColor: 0,0,0 TextContrastColor: 0,0,0
ColorPickerRemapIndices: 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240 ColorPickerRemapIndices: 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240
ColorPickerActorType: ^carryall.colorpicker
SpawnFont: TinyBold SpawnFont: TinyBold
SpawnColor: 255,255,255 SpawnColor: 255,255,255
SpawnContrastColor: 0,0,0 SpawnContrastColor: 0,0,0

View File

@@ -140,6 +140,14 @@ waypoint:
RenderEditorOnly: RenderEditorOnly:
BodyOrientation: BodyOrientation:
^carryall.colorpicker:
Inherits: ^CARRYALL
RenderUnit:
Image: carryall
Palette: colorpicker
Helicopter:
InitialFacing: 104
CAMERA: CAMERA:
Immobile: Immobile:
OccupiesSpace: false OccupiesSpace: false

View File

@@ -29,14 +29,11 @@ Background@COLOR_CHOOSER:
Y: 2 Y: 2
Width: 144 Width: 144
Height: 72 Height: 72
SpriteSequence@FACT: ActorPreview@PREVIEW:
X: 153 X: 153
Y: 1 Y: 1
Width: 80 Width: 80
Height: 73 Height: 73
Palette: colorpicker
Unit: fact
Sequence: idle
Button@RANDOM_BUTTON: Button@RANDOM_BUTTON:
Key: tab Key: tab
X: 158 X: 158

View File

@@ -20,6 +20,7 @@ Metrics:
TextContrast: false TextContrast: false
TextContrastColor: 0,0,0 TextContrastColor: 0,0,0
ColorPickerRemapIndices: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 ColorPickerRemapIndices: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95
ColorPickerActorType: ^fact.colorpicker
SpawnFont: TinyBold SpawnFont: TinyBold
SpawnColor: 255,255,255 SpawnColor: 255,255,255
SpawnContrastColor: 0,0,0 SpawnContrastColor: 0,0,0

View File

@@ -368,6 +368,12 @@ waypoint:
RenderEditorOnly: RenderEditorOnly:
BodyOrientation: BodyOrientation:
^fact.colorpicker:
Inherits: FACT
RenderBuilding:
Image: fact
Palette: colorpicker
CTFLAG: CTFLAG:
Inherits: ^TechBuilding Inherits: ^TechBuilding
Building: Building:

View File

@@ -29,14 +29,11 @@ Background@COLOR_CHOOSER:
Y: 2 Y: 2
Width: 144 Width: 144
Height: 72 Height: 72
SpriteSequence@PREVIEW: ActorPreview@PREVIEW:
X: 153 X: 163
Y: 1-40
Width: 80 Width: 80
Height: 73 Height: 74
Palette: colorpicker Animate: true
Unit: gacnst
Sequence: make
Button@RANDOM_BUTTON: Button@RANDOM_BUTTON:
Key: tab Key: tab
X: 158 X: 158

View File

@@ -20,6 +20,7 @@ Metrics:
TextContrast: false TextContrast: false
TextContrastColor: 0,0,0 TextContrastColor: 0,0,0
ColorPickerRemapIndices: 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 ColorPickerRemapIndices: 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
ColorPickerActorType: ^mmch.colorpicker
SpawnFont: TinyBold SpawnFont: TinyBold
SpawnColor: 255,255,255 SpawnColor: 255,255,255
SpawnContrastColor: 0,0,0 SpawnContrastColor: 0,0,0

View File

@@ -10,6 +10,20 @@ waypoint:
RenderEditorOnly: RenderEditorOnly:
BodyOrientation: BodyOrientation:
^mmch.colorpicker:
Inherits: MMCH
Mobile:
InitialFacing: 160
Turreted:
InitialFacing: 160
RenderInfantry:
Image: mmch
StandAnimations: run
Palette: colorpicker
RenderVoxels:
Image: mmch
Palette: colorpicker
CAMERA: CAMERA:
Immobile: Immobile:
OccupiesSpace: false OccupiesSpace: false

View File

@@ -37,6 +37,7 @@ World:
Name: colorpicker Name: colorpicker
Filename: unittem.pal Filename: unittem.pal
AllowModifiers: false AllowModifiers: false
ShadowIndex: 1
PaletteFromRGBA@shadow: PaletteFromRGBA@shadow:
Name: shadow Name: shadow
R: 0 R: 0