From 94df65c1629b812264999b3a2982df55065f6494 Mon Sep 17 00:00:00 2001 From: alzeih Date: Sat, 24 Apr 2010 21:42:50 +1200 Subject: [PATCH] ColorBlockWidget instead of ColorButton + refactoring --- OpenRA.Game/OpenRA.Game.csproj | 2 +- OpenRA.Game/Widgets/ColorBlockWidget.cs | 45 +++++++ OpenRA.Game/Widgets/ColorButtonWidget.cs | 54 -------- .../Widgets/Delegates/DiplomacyDelegate.cs | 8 +- .../Widgets/Delegates/LobbyDelegate.cs | 12 +- OpenRA.Game/Widgets/LabelWidget.cs | 14 +- mods/cnc/menus.yaml | 119 +++++++++-------- mods/ra/menus.yaml | 121 ++++++++++-------- 8 files changed, 201 insertions(+), 174 deletions(-) create mode 100644 OpenRA.Game/Widgets/ColorBlockWidget.cs delete mode 100644 OpenRA.Game/Widgets/ColorButtonWidget.cs diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 5463bcdaf5..8b9bc44db9 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -309,7 +309,7 @@ - + diff --git a/OpenRA.Game/Widgets/ColorBlockWidget.cs b/OpenRA.Game/Widgets/ColorBlockWidget.cs new file mode 100644 index 0000000000..79f8db0baf --- /dev/null +++ b/OpenRA.Game/Widgets/ColorBlockWidget.cs @@ -0,0 +1,45 @@ + +using System; +using System.Drawing; + +namespace OpenRA.Widgets +{ + class ColorBlockWidget : Widget + { + public int PaletteIndex = 0; + public Func 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); + } + } +} diff --git a/OpenRA.Game/Widgets/ColorButtonWidget.cs b/OpenRA.Game/Widgets/ColorButtonWidget.cs deleted file mode 100644 index bf22279aba..0000000000 --- a/OpenRA.Game/Widgets/ColorButtonWidget.cs +++ /dev/null @@ -1,54 +0,0 @@ - -using System; -using System.Drawing; - -namespace OpenRA.Widgets -{ - class ColorButtonWidget : ButtonWidget - { - public int PaletteIndex = 0; - public Func 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); - } - } -} diff --git a/OpenRA.Game/Widgets/Delegates/DiplomacyDelegate.cs b/OpenRA.Game/Widgets/Delegates/DiplomacyDelegate.cs index 7ab9784f18..a69d56fe32 100644 --- a/OpenRA.Game/Widgets/Delegates/DiplomacyDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/DiplomacyDelegate.cs @@ -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(), diff --git a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs index 81d319b2e1..914a50ec70 100644 --- a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs @@ -47,10 +47,11 @@ namespace OpenRA.Widgets.Delegates if(client.Index == Game.LocalClient.Index) { - //TODO: Real Color Button - var color = template.GetWidget("COLOR"); + var color = template.GetWidget("COLOR"); color.OnMouseUp = CyclePalette; - color.GetPaletteIndex = () => c.PaletteIndex; + + var colorBlock = color.GetWidget("COLORBLOCK"); + colorBlock.GetPaletteIndex = () => c.PaletteIndex; var faction = template.GetWidget("FACTION"); faction.OnMouseUp = CycleRace; @@ -70,9 +71,8 @@ namespace OpenRA.Widgets.Delegates } else { - //TODO: Real Color Label - var color = template.GetWidget("COLOR"); - color.GetText = () => c.PaletteIndex.ToString(); + var color = template.GetWidget("COLOR"); + color.GetPaletteIndex = () => c.PaletteIndex; var faction = template.GetWidget("FACTION"); faction.GetText = () => c.Country; diff --git a/OpenRA.Game/Widgets/LabelWidget.cs b/OpenRA.Game/Widgets/LabelWidget.cs index 15b11ea638..7796aa4be9 100644 --- a/OpenRA.Game/Widgets/LabelWidget.cs +++ b/OpenRA.Game/Widgets/LabelWidget.cs @@ -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 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); diff --git a/mods/cnc/menus.yaml b/mods/cnc/menus.yaml index 7024e7f6fa..edd403af17 100644 --- a/mods/cnc/menus.yaml +++ b/mods/cnc/menus.yaml @@ -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:0 + 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 diff --git a/mods/ra/menus.yaml b/mods/ra/menus.yaml index 601bb34913..edd403af17 100644 --- a/mods/ra/menus.yaml +++ b/mods/ra/menus.yaml @@ -310,13 +310,20 @@ Container: Height:25 X:0 Y:5 - ColorButton@COLOR: + Button@COLOR: Id:COLOR Width:65 Height:25 X:100 Y:0 - PaletteIndex: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:0 + 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