ColorBlockWidget instead of ColorButton + refactoring
This commit is contained in:
@@ -309,7 +309,7 @@
|
||||
<Compile Include="Widgets\BuildPaletteWidget.cs" />
|
||||
<Compile Include="Traits\World\BridgeLayer.cs" />
|
||||
<Compile Include="Widgets\Delegates\LobbyDelegate.cs" />
|
||||
<Compile Include="Widgets\ColorButtonWidget.cs" />
|
||||
<Compile Include="Widgets\ColorBlockWidget.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
45
OpenRA.Game/Widgets/ColorBlockWidget.cs
Normal file
45
OpenRA.Game/Widgets/ColorBlockWidget.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
class ColorBlockWidget : Widget
|
||||
{
|
||||
public int PaletteIndex = 0;
|
||||
public Func<int> GetPaletteIndex;
|
||||
|
||||
public ColorBlockWidget()
|
||||
: base()
|
||||
{
|
||||
GetPaletteIndex = () => { return PaletteIndex; };
|
||||
}
|
||||
|
||||
public ColorBlockWidget(Widget widget)
|
||||
:base(widget)
|
||||
{
|
||||
PaletteIndex = (widget as ColorBlockWidget).PaletteIndex;
|
||||
GetPaletteIndex = (widget as ColorBlockWidget).GetPaletteIndex;
|
||||
}
|
||||
|
||||
public override Widget Clone()
|
||||
{
|
||||
return new ColorBlockWidget(this);
|
||||
}
|
||||
|
||||
public override void Draw(World world)
|
||||
{
|
||||
if (!IsVisible())
|
||||
{
|
||||
base.Draw(world);
|
||||
return;
|
||||
}
|
||||
|
||||
var pos = DrawPosition();
|
||||
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);
|
||||
|
||||
base.Draw(world);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ namespace OpenRA.Widgets.Delegates
|
||||
Bold = true,
|
||||
Bounds = new Rectangle(margin + labelWidth + 10, y, labelWidth, 25),
|
||||
Text = "Their Stance",
|
||||
Align = "Left",
|
||||
Align = LabelWidget.TextAlign.Left,
|
||||
};
|
||||
|
||||
bg.AddChild(ts);
|
||||
@@ -50,7 +50,7 @@ namespace OpenRA.Widgets.Delegates
|
||||
Bold = true,
|
||||
Bounds = new Rectangle(margin + 2 * labelWidth + 20, y, labelWidth, 25),
|
||||
Text = "My Stance",
|
||||
Align = "Left",
|
||||
Align = LabelWidget.TextAlign.Left,
|
||||
};
|
||||
|
||||
bg.AddChild(ms);
|
||||
@@ -66,7 +66,7 @@ namespace OpenRA.Widgets.Delegates
|
||||
Bounds = new Rectangle(margin, y, labelWidth, 25),
|
||||
Id = "DIPLOMACY_PLAYER_LABEL_{0}".F(p.Index),
|
||||
Text = p.PlayerName,
|
||||
Align = "Left",
|
||||
Align = LabelWidget.TextAlign.Left,
|
||||
Bold = true,
|
||||
};
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace OpenRA.Widgets.Delegates
|
||||
Bounds = new Rectangle( margin + labelWidth + 10, y, labelWidth, 25),
|
||||
Id = "DIPLOMACY_PLAYER_LABEL_THEIR_{0}".F(p.Index),
|
||||
Text = p.PlayerName,
|
||||
Align = "Left",
|
||||
Align = LabelWidget.TextAlign.Left,
|
||||
Bold = false,
|
||||
|
||||
GetText = () => pp.Stances[ Game.world.LocalPlayer ].ToString(),
|
||||
|
||||
@@ -47,10 +47,11 @@ namespace OpenRA.Widgets.Delegates
|
||||
|
||||
if(client.Index == Game.LocalClient.Index)
|
||||
{
|
||||
//TODO: Real Color Button
|
||||
var color = template.GetWidget<ColorButtonWidget>("COLOR");
|
||||
var color = template.GetWidget<ButtonWidget>("COLOR");
|
||||
color.OnMouseUp = CyclePalette;
|
||||
color.GetPaletteIndex = () => c.PaletteIndex;
|
||||
|
||||
var colorBlock = color.GetWidget<ColorBlockWidget>("COLORBLOCK");
|
||||
colorBlock.GetPaletteIndex = () => c.PaletteIndex;
|
||||
|
||||
var faction = template.GetWidget<ButtonWidget>("FACTION");
|
||||
faction.OnMouseUp = CycleRace;
|
||||
@@ -70,9 +71,8 @@ namespace OpenRA.Widgets.Delegates
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO: Real Color Label
|
||||
var color = template.GetWidget<LabelWidget>("COLOR");
|
||||
color.GetText = () => c.PaletteIndex.ToString();
|
||||
var color = template.GetWidget<ColorBlockWidget>("COLOR");
|
||||
color.GetPaletteIndex = () => c.PaletteIndex;
|
||||
|
||||
var faction = template.GetWidget<LabelWidget>("FACTION");
|
||||
faction.GetText = () => c.Country;
|
||||
|
||||
@@ -25,8 +25,15 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
class LabelWidget : Widget
|
||||
{
|
||||
public enum TextAlign
|
||||
{
|
||||
Left,
|
||||
Center,
|
||||
Right
|
||||
}
|
||||
|
||||
public string Text = "";
|
||||
public string Align = "Left";
|
||||
public TextAlign Align = TextAlign.Left;
|
||||
public bool Bold = true;
|
||||
public Func<string> GetText;
|
||||
|
||||
@@ -58,9 +65,8 @@ namespace OpenRA.Widgets
|
||||
int2 textSize = font.Measure(text);
|
||||
int2 position = DrawPosition();
|
||||
|
||||
if (Align == "Center")
|
||||
position = new int2(position.X +Bounds.Width/2, position.Y + Bounds.Height/2)
|
||||
- new int2(textSize.X / 2, textSize.Y/2);
|
||||
if (Align == TextAlign.Center)
|
||||
position += new int2((Bounds.Width - textSize.X)/2, 0);
|
||||
|
||||
font.DrawText(text, position, Color.White);
|
||||
base.Draw(world);
|
||||
|
||||
@@ -312,11 +312,18 @@ Container:
|
||||
Y:5
|
||||
Button@COLOR:
|
||||
Id:COLOR
|
||||
Text:Color
|
||||
Width:65
|
||||
Height:25
|
||||
X:100
|
||||
Y:0
|
||||
Children:
|
||||
ColorBlock@COLORBLOCK:
|
||||
Id:COLORBLOCK
|
||||
X:5
|
||||
Y:7
|
||||
Width:PARENT_RIGHT-10
|
||||
Height:PARENT_BOTTOM-12
|
||||
PaletteIndex:0
|
||||
Button@FACTION:
|
||||
Id:FACTION
|
||||
Text:Faction
|
||||
@@ -341,7 +348,7 @@ Container:
|
||||
Checkbox@STATUS:
|
||||
Id:STATUS
|
||||
X:455
|
||||
Y:0
|
||||
Y:1
|
||||
Width:20
|
||||
Height:20
|
||||
Container@TEMPLATE_REMOTE
|
||||
@@ -359,14 +366,13 @@ Container:
|
||||
Height:25
|
||||
X:0
|
||||
Y:5
|
||||
Label@COLOR:
|
||||
ColorBlock@COLOR:
|
||||
Id:COLOR
|
||||
Text:Color
|
||||
Width:65
|
||||
Height:25
|
||||
X:100
|
||||
Y:0
|
||||
Align:Center
|
||||
X:105
|
||||
Y:7
|
||||
Width:55
|
||||
Height:13
|
||||
PaletteIndex:0
|
||||
Label@FACTION:
|
||||
Id:FACTION
|
||||
Text:Faction
|
||||
@@ -394,9 +400,60 @@ Container:
|
||||
Checkbox@STATUS:
|
||||
Id:STATUS
|
||||
X:455
|
||||
Y:1
|
||||
Width:20
|
||||
Height:20
|
||||
Container@LABEL_CONTAINER:
|
||||
X:30
|
||||
Y:50
|
||||
Children:
|
||||
Label@LABEL_LOBBY_NAME:
|
||||
Id:LABEL_LOBBY_NAME
|
||||
Width:95
|
||||
Height:25
|
||||
X:0
|
||||
Y:0
|
||||
Text:Name
|
||||
Label@LABEL_LOBBY_COLOR:
|
||||
Id:LABEL_LOBBY_COLOR
|
||||
Width:65
|
||||
Height:25
|
||||
X:100
|
||||
Y:0
|
||||
Text:Color
|
||||
Align:Center
|
||||
Label@LABEL_LOBBY_FACTION
|
||||
Id:LABEL_LOBBY_FACTION
|
||||
Width:90
|
||||
Height:25
|
||||
X:180
|
||||
Y:0
|
||||
Text:Faction
|
||||
Align:Center
|
||||
Label@LABEL_LOBBY_SPAWN
|
||||
Id:LABEL_LOBBY_SPAWN
|
||||
Width:70
|
||||
Height:25
|
||||
X:275
|
||||
Y:0
|
||||
Text:Spawn
|
||||
Align:Center
|
||||
Label@LABEL_LOBBY_TEAM
|
||||
Id:LABEL_LOBBY_TEAM
|
||||
Width:70
|
||||
Height:25
|
||||
X:355
|
||||
Y:0
|
||||
Text:Team
|
||||
Align:Center
|
||||
Label@LABEL_LOBBY_STATUS
|
||||
Id:LABEL_LOBBY_STATUS
|
||||
X:455
|
||||
Y:0
|
||||
Width:20
|
||||
Height:20
|
||||
Text:Ready
|
||||
Align:Center
|
||||
Button@CHANGEMAP_BUTTON:
|
||||
Id:CHANGEMAP_BUTTON
|
||||
Visible:true
|
||||
@@ -405,48 +462,6 @@ Container:
|
||||
Width:120
|
||||
Height:25
|
||||
Text:Change Map
|
||||
Label@LABEL_LOBBY_NAME:
|
||||
Id:LABEL_LOBBY_NAME
|
||||
X:40
|
||||
Y:50
|
||||
Width:250
|
||||
Height:25
|
||||
Text:Name
|
||||
Label@LABEL_LOBBY_COLOR:
|
||||
Id:LABEL_LOBBY_COLOR
|
||||
X:140
|
||||
Y:50
|
||||
Width:250
|
||||
Height:25
|
||||
Text:Color
|
||||
Label@LABEL_LOBBY_FACTION
|
||||
Id:LABEL_LOBBY_FACTION
|
||||
X:220
|
||||
Y:50
|
||||
Width:250
|
||||
Height:25
|
||||
Text:Faction
|
||||
Label@LABEL_LOBBY_SPAWN
|
||||
Id:LABEL_LOBBY_SPAWN
|
||||
X:315
|
||||
Y:50
|
||||
Width:250
|
||||
Height:25
|
||||
Text:Spawn
|
||||
Label@LABEL_LOBBY_TEAM
|
||||
Id:LABEL_LOBBY_TEAM
|
||||
X:395
|
||||
Y:50
|
||||
Width:250
|
||||
Height:25
|
||||
Text:Team
|
||||
Label@LABEL_LOBBY_STATUS
|
||||
Id:LABEL_LOBBY_STATUS
|
||||
X:475
|
||||
Y:50
|
||||
Width:250
|
||||
Height:25
|
||||
Text:Ready
|
||||
Background@MAP_CHOOSER:
|
||||
Id:MAP_CHOOSER
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
|
||||
@@ -310,12 +310,19 @@ Container:
|
||||
Height:25
|
||||
X:0
|
||||
Y:5
|
||||
ColorButton@COLOR:
|
||||
Button@COLOR:
|
||||
Id:COLOR
|
||||
Width:65
|
||||
Height:25
|
||||
X:100
|
||||
Y:0
|
||||
Children:
|
||||
ColorBlock@COLORBLOCK:
|
||||
Id:COLORBLOCK
|
||||
X:5
|
||||
Y:7
|
||||
Width:PARENT_RIGHT-10
|
||||
Height:PARENT_BOTTOM-12
|
||||
PaletteIndex:0
|
||||
Button@FACTION:
|
||||
Id:FACTION
|
||||
@@ -341,7 +348,7 @@ Container:
|
||||
Checkbox@STATUS:
|
||||
Id:STATUS
|
||||
X:455
|
||||
Y:0
|
||||
Y:1
|
||||
Width:20
|
||||
Height:20
|
||||
Container@TEMPLATE_REMOTE
|
||||
@@ -359,14 +366,13 @@ Container:
|
||||
Height:25
|
||||
X:0
|
||||
Y:5
|
||||
Label@COLOR:
|
||||
ColorBlock@COLOR:
|
||||
Id:COLOR
|
||||
Text:Color
|
||||
Width:65
|
||||
Height:25
|
||||
X:100
|
||||
Y:0
|
||||
Align:Center
|
||||
X:105
|
||||
Y:7
|
||||
Width:55
|
||||
Height:13
|
||||
PaletteIndex:0
|
||||
Label@FACTION:
|
||||
Id:FACTION
|
||||
Text:Faction
|
||||
@@ -394,9 +400,60 @@ Container:
|
||||
Checkbox@STATUS:
|
||||
Id:STATUS
|
||||
X:455
|
||||
Y:1
|
||||
Width:20
|
||||
Height:20
|
||||
Container@LABEL_CONTAINER:
|
||||
X:30
|
||||
Y:50
|
||||
Children:
|
||||
Label@LABEL_LOBBY_NAME:
|
||||
Id:LABEL_LOBBY_NAME
|
||||
Width:95
|
||||
Height:25
|
||||
X:0
|
||||
Y:0
|
||||
Text:Name
|
||||
Label@LABEL_LOBBY_COLOR:
|
||||
Id:LABEL_LOBBY_COLOR
|
||||
Width:65
|
||||
Height:25
|
||||
X:100
|
||||
Y:0
|
||||
Text:Color
|
||||
Align:Center
|
||||
Label@LABEL_LOBBY_FACTION
|
||||
Id:LABEL_LOBBY_FACTION
|
||||
Width:90
|
||||
Height:25
|
||||
X:180
|
||||
Y:0
|
||||
Text:Faction
|
||||
Align:Center
|
||||
Label@LABEL_LOBBY_SPAWN
|
||||
Id:LABEL_LOBBY_SPAWN
|
||||
Width:70
|
||||
Height:25
|
||||
X:275
|
||||
Y:0
|
||||
Text:Spawn
|
||||
Align:Center
|
||||
Label@LABEL_LOBBY_TEAM
|
||||
Id:LABEL_LOBBY_TEAM
|
||||
Width:70
|
||||
Height:25
|
||||
X:355
|
||||
Y:0
|
||||
Text:Team
|
||||
Align:Center
|
||||
Label@LABEL_LOBBY_STATUS
|
||||
Id:LABEL_LOBBY_STATUS
|
||||
X:455
|
||||
Y:0
|
||||
Width:20
|
||||
Height:20
|
||||
Text:Ready
|
||||
Align:Center
|
||||
Button@CHANGEMAP_BUTTON:
|
||||
Id:CHANGEMAP_BUTTON
|
||||
Visible:true
|
||||
@@ -405,48 +462,6 @@ Container:
|
||||
Width:120
|
||||
Height:25
|
||||
Text:Change Map
|
||||
Label@LABEL_LOBBY_NAME:
|
||||
Id:LABEL_LOBBY_NAME
|
||||
X:40
|
||||
Y:50
|
||||
Width:250
|
||||
Height:25
|
||||
Text:Name
|
||||
Label@LABEL_LOBBY_COLOR:
|
||||
Id:LABEL_LOBBY_COLOR
|
||||
X:140
|
||||
Y:50
|
||||
Width:250
|
||||
Height:25
|
||||
Text:Color
|
||||
Label@LABEL_LOBBY_FACTION
|
||||
Id:LABEL_LOBBY_FACTION
|
||||
X:220
|
||||
Y:50
|
||||
Width:250
|
||||
Height:25
|
||||
Text:Faction
|
||||
Label@LABEL_LOBBY_SPAWN
|
||||
Id:LABEL_LOBBY_SPAWN
|
||||
X:315
|
||||
Y:50
|
||||
Width:250
|
||||
Height:25
|
||||
Text:Spawn
|
||||
Label@LABEL_LOBBY_TEAM
|
||||
Id:LABEL_LOBBY_TEAM
|
||||
X:395
|
||||
Y:50
|
||||
Width:250
|
||||
Height:25
|
||||
Text:Team
|
||||
Label@LABEL_LOBBY_STATUS
|
||||
Id:LABEL_LOBBY_STATUS
|
||||
X:475
|
||||
Y:50
|
||||
Width:250
|
||||
Height:25
|
||||
Text:Ready
|
||||
Background@MAP_CHOOSER:
|
||||
Id:MAP_CHOOSER
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
|
||||
Reference in New Issue
Block a user