Abstract ColorBlockWidget away from Player

This commit is contained in:
alzeih
2010-04-25 14:03:31 +12:00
parent 99b2c03534
commit e11b2a1801
2 changed files with 6 additions and 7 deletions

View File

@@ -25,18 +25,18 @@ namespace OpenRA.Widgets
{ {
class ColorBlockWidget : Widget class ColorBlockWidget : Widget
{ {
public Func<int> GetPaletteIndex; public Func<Color> GetColor;
public ColorBlockWidget() public ColorBlockWidget()
: base() : base()
{ {
GetPaletteIndex = () => 0; GetColor = () => Color.White;
} }
public ColorBlockWidget(Widget widget) public ColorBlockWidget(Widget widget)
:base(widget) :base(widget)
{ {
GetPaletteIndex = (widget as ColorBlockWidget).GetPaletteIndex; GetColor = (widget as ColorBlockWidget).GetColor;
} }
public override Widget Clone() public override Widget Clone()
@@ -54,8 +54,7 @@ namespace OpenRA.Widgets
var pos = DrawPosition(); var pos = DrawPosition();
var paletteRect = new RectangleF(pos.X + Game.viewport.Location.X, pos.Y + Game.viewport.Location.Y, Bounds.Width, Bounds.Height); var paletteRect = new RectangleF(pos.X + Game.viewport.Location.X, pos.Y + Game.viewport.Location.Y, Bounds.Width, Bounds.Height);
Game.chrome.lineRenderer.FillRect(paletteRect, Player.PlayerColors(Game.world)[GetPaletteIndex() % Player.PlayerColors(Game.world).Count].c); Game.chrome.lineRenderer.FillRect(paletteRect, GetColor());
base.Draw(world); base.Draw(world);
} }
} }

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Widgets.Delegates
color.OnMouseUp = CyclePalette; color.OnMouseUp = CyclePalette;
var colorBlock = color.GetWidget<ColorBlockWidget>("COLORBLOCK"); var colorBlock = color.GetWidget<ColorBlockWidget>("COLORBLOCK");
colorBlock.GetPaletteIndex = () => c.PaletteIndex; colorBlock.GetColor = () => Player.PlayerColors(Game.world)[c.PaletteIndex % Player.PlayerColors(Game.world).Count].c;
var faction = template.GetWidget<ButtonWidget>("FACTION"); var faction = template.GetWidget<ButtonWidget>("FACTION");
faction.OnMouseUp = CycleRace; faction.OnMouseUp = CycleRace;
@@ -91,7 +91,7 @@ namespace OpenRA.Widgets.Delegates
else else
{ {
var color = template.GetWidget<ColorBlockWidget>("COLOR"); var color = template.GetWidget<ColorBlockWidget>("COLOR");
color.GetPaletteIndex = () => c.PaletteIndex; color.GetColor = () => Player.PlayerColors(Game.world)[c.PaletteIndex % Player.PlayerColors(Game.world).Count].c;
var faction = template.GetWidget<LabelWidget>("FACTION"); var faction = template.GetWidget<LabelWidget>("FACTION");
faction.GetText = () => c.Country; faction.GetText = () => c.Country;