ColorButtonWidget

This commit is contained in:
alzeih
2010-04-24 20:55:23 +12:00
parent 5f4a917677
commit 0be74556d0
4 changed files with 59 additions and 4 deletions

View File

@@ -309,6 +309,7 @@
<Compile Include="Widgets\BuildPaletteWidget.cs" />
<Compile Include="Traits\World\BridgeLayer.cs" />
<Compile Include="Widgets\Delegates\LobbyDelegate.cs" />
<Compile Include="Widgets\ColorButtonWidget.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -0,0 +1,54 @@
using System;
using System.Drawing;
namespace OpenRA.Widgets
{
class ColorButtonWidget : ButtonWidget
{
public int PaletteIndex = 0;
public Func<int> GetPaletteIndex;
public ColorButtonWidget()
: base()
{
GetPaletteIndex = () => { return PaletteIndex; };
}
public ColorButtonWidget(Widget widget)
:base(widget)
{
PaletteIndex = (widget as ColorButtonWidget).PaletteIndex;
GetPaletteIndex = (widget as ColorButtonWidget).GetPaletteIndex;
}
public override Widget Clone()
{
return new ColorButtonWidget(this);
}
public override void Draw(World world)
{
if (!IsVisible())
{
base.Draw(world);
return;
}
DrawColorBlock();
base.Draw(world);
}
void DrawColorBlock()
{
var pos = DrawPosition();
var paletteRect = new Rectangle(pos.X ,pos.Y + 2 , 65, 22);
Game.chrome.lineRenderer.FillRect(RectangleF.FromLTRB(paletteRect.Left + Game.viewport.Location.X + 5,
paletteRect.Top + Game.viewport.Location.Y + 5,
paletteRect.Right + Game.viewport.Location.X - 5,
paletteRect.Bottom+Game.viewport.Location.Y - 5),
Player.PlayerColors(Game.world)[GetPaletteIndex() % Player.PlayerColors(Game.world).Count].c);
}
}
}

View File

@@ -48,9 +48,9 @@ namespace OpenRA.Widgets.Delegates
if(client.Index == Game.LocalClient.Index)
{
//TODO: Real Color Button
var color = template.GetWidget<ButtonWidget>("COLOR");
var color = template.GetWidget<ColorButtonWidget>("COLOR");
color.OnMouseUp = CyclePalette;
color.GetText = () => c.PaletteIndex.ToString();
color.GetPaletteIndex = () => c.PaletteIndex;
var faction = template.GetWidget<ButtonWidget>("FACTION");
faction.OnMouseUp = CycleRace;

View File

@@ -310,13 +310,13 @@ Container:
Height:25
X:0
Y:5
Button@COLOR:
ColorButton@COLOR:
Id:COLOR
Text:Color
Width:65
Height:25
X:100
Y:0
PaletteIndex:0
Button@FACTION:
Id:FACTION
Text:Faction