From 471a5c29c84c6ab24ccbdcb0bc41aa3f25ac4a60 Mon Sep 17 00:00:00 2001 From: alzeih Date: Sat, 24 Apr 2010 17:33:43 +1200 Subject: [PATCH] refactored a bit - something is still failing --- OpenRA.Game/Widgets/BackgroundWidget.cs | 3 ++- OpenRA.Game/Widgets/ButtonWidget.cs | 5 +++-- OpenRA.Game/Widgets/CheckboxWidget.cs | 5 +++-- OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs | 6 +++++- OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs | 2 +- OpenRA.Game/Widgets/LabelWidget.cs | 4 ++-- OpenRA.Game/Widgets/MapPreviewWidget.cs | 5 +++-- OpenRA.Game/Widgets/MoneyBinWidget.cs | 2 +- OpenRA.Game/Widgets/PerfGraphWidget.cs | 3 ++- OpenRA.Game/Widgets/SpecialPowerBinWidget.cs | 3 ++- OpenRA.Game/Widgets/Widget.cs | 10 ++++++---- mods/ra/menus.yaml | 2 ++ 12 files changed, 32 insertions(+), 18 deletions(-) diff --git a/OpenRA.Game/Widgets/BackgroundWidget.cs b/OpenRA.Game/Widgets/BackgroundWidget.cs index 160905fafc..aca11260ca 100644 --- a/OpenRA.Game/Widgets/BackgroundWidget.cs +++ b/OpenRA.Game/Widgets/BackgroundWidget.cs @@ -31,7 +31,8 @@ namespace OpenRA.Widgets base.Draw(world); return; } - var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); + var pos = DrawPosition(); + var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height); WidgetUtils.DrawPanel(Background, rect); base.Draw(world); } diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs index ae6b3e4e92..f29da05754 100644 --- a/OpenRA.Game/Widgets/ButtonWidget.cs +++ b/OpenRA.Game/Widgets/ButtonWidget.cs @@ -86,13 +86,14 @@ namespace OpenRA.Widgets base.Draw(world); return; } + var pos = DrawPosition(); var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0); - WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height ) ); + WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height ) ); var text = GetText(); Game.chrome.renderer.BoldFont.DrawText(text, - new int2( ( Bounds.X + getParentOffset().X) + Bounds.Width / 2, ( Bounds.Y + getParentOffset().Y) + Bounds.Height / 2) + new int2( pos.X + Bounds.Width / 2, pos.Y + Bounds.Height / 2) - new int2(Game.chrome.renderer.BoldFont.Measure(text).X / 2, Game.chrome.renderer.BoldFont.Measure(text).Y / 2) + stateOffset, Color.White); diff --git a/OpenRA.Game/Widgets/CheckboxWidget.cs b/OpenRA.Game/Widgets/CheckboxWidget.cs index fb02dcf8da..4eba3bd83f 100644 --- a/OpenRA.Game/Widgets/CheckboxWidget.cs +++ b/OpenRA.Game/Widgets/CheckboxWidget.cs @@ -35,9 +35,10 @@ namespace OpenRA.Widgets base.Draw(world); return; } - var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); + var pos = DrawPosition(); + var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height); WidgetUtils.DrawPanel("dialog3", new Rectangle(rect.Location, - new Size(Bounds.Height, Bounds.Height))); + new Size(Bounds.Height, Bounds.Height))); //HACK! Game.chrome.renderer.BoldFont.DrawText(Text, new float2(rect.Left + rect.Height * 2, rect.Top), Color.White); diff --git a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs index e339ccd086..cb7649b301 100644 --- a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs @@ -36,6 +36,7 @@ namespace OpenRA.Widgets.Delegates Players.Children.Clear(); int i = 0; + foreach(var client in Game.LobbyInfo.Clients) { //HACK : "the c# spec is, IMHO, broken here" @@ -43,9 +44,12 @@ namespace OpenRA.Widgets.Delegates Log.Write("Client {0}",c.Name); var template = PlayerTemplate.Clone(); + var pos = template.DrawPosition(); + template.Id = "PLAYER_{0}".F(c.Index); + template.Parent = Players; template.GetWidget("NAME").GetText = () => {return c.Name; }; - template.Bounds = new Rectangle(template.Bounds.X, template.Bounds.Y + i, template.Bounds.Width, template.Bounds.Height); + template.Bounds = new Rectangle(pos.X, pos.Y + i, template.Bounds.Width, template.Bounds.Height); template.IsVisible = () => {return true;}; Players.AddChild(template); i += 30; diff --git a/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs b/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs index c7613acd0f..d539c7bee6 100644 --- a/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs @@ -64,7 +64,7 @@ namespace OpenRA.Widgets.Delegates var g = game; var b = new ButtonWidget { - Bounds = new Rectangle(bg.Bounds.X + margin, bg.Bounds.Y + height, bg.Bounds.Width - 2 * margin, 25), + Bounds = new Rectangle(bg.DrawPosition().X + margin, bg.DrawPosition().Y + height, bg.Bounds.Width - 2 * margin, 25), Id = "JOIN_GAME_{0}".F(i), Text = "{0} ({1})".F(game.Name, game.Address), Delegate = "ServerBrowserDelegate", diff --git a/OpenRA.Game/Widgets/LabelWidget.cs b/OpenRA.Game/Widgets/LabelWidget.cs index 43ac9ebcbb..3578c2bbac 100644 --- a/OpenRA.Game/Widgets/LabelWidget.cs +++ b/OpenRA.Game/Widgets/LabelWidget.cs @@ -47,10 +47,10 @@ namespace OpenRA.Widgets var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont; var text = GetText(); int2 textSize = font.Measure(text); - int2 position = new int2(Parent.Bounds.X + Bounds.X,Parent.Bounds.Y + Bounds.Y); + int2 position = DrawPosition(); if (Align == "Center") - position = new int2(Bounds.X + Parent.Bounds.X +Bounds.Width/2, Bounds.Y + Parent.Bounds.Y + Bounds.Height/2) + position = new int2(position.X +Bounds.Width/2, position.Y + Bounds.Height/2) - new int2(textSize.X / 2, textSize.Y/2); font.DrawText(text, position, Color.White); diff --git a/OpenRA.Game/Widgets/MapPreviewWidget.cs b/OpenRA.Game/Widgets/MapPreviewWidget.cs index e213e4a06b..66a3390669 100755 --- a/OpenRA.Game/Widgets/MapPreviewWidget.cs +++ b/OpenRA.Game/Widgets/MapPreviewWidget.cs @@ -25,7 +25,8 @@ namespace OpenRA.Widgets mapPreviewDirty = true; lastMap = map; } - var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); + var pos = DrawPosition(); + var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height); var mapRect = map.PreviewBounds( new Rectangle( rect.X, rect.Y, rect.Width, rect.Height ) ); if( mapPreviewDirty ) @@ -43,7 +44,7 @@ namespace OpenRA.Widgets "chrome", new float2( mapRect.Size ) ); - DrawSpawnPoints( map, Parent.Bounds, world ); + DrawSpawnPoints( map, new Rectangle(pos.X, pos.Y, Parent.Bounds.Width, Parent.Bounds.Height ), world ); base.Draw( world ); } diff --git a/OpenRA.Game/Widgets/MoneyBinWidget.cs b/OpenRA.Game/Widgets/MoneyBinWidget.cs index e5323b3949..bfb3e8979c 100644 --- a/OpenRA.Game/Widgets/MoneyBinWidget.cs +++ b/OpenRA.Game/Widgets/MoneyBinWidget.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * This file is part of OpenRA. diff --git a/OpenRA.Game/Widgets/PerfGraphWidget.cs b/OpenRA.Game/Widgets/PerfGraphWidget.cs index 65e446c1ce..7b4d788e73 100644 --- a/OpenRA.Game/Widgets/PerfGraphWidget.cs +++ b/OpenRA.Game/Widgets/PerfGraphWidget.cs @@ -33,7 +33,8 @@ namespace OpenRA.Widgets base.Draw(world); return; } - var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); + var pos = DrawPosition(); + var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height); float2 origin = Game.viewport.Location + new float2(rect.Right,rect.Bottom); float2 basis = new float2(-rect.Width/100,-rect.Height/100); diff --git a/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs b/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs index 1e743b166a..e35532e42d 100644 --- a/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs +++ b/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs @@ -85,7 +85,8 @@ namespace OpenRA.Widgets var powers = world.LocalPlayer.PlayerActor.traits.WithInterface(); var numPowers = powers.Count(p => p.IsAvailable); if (numPowers == 0) return; - var rectBounds = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); + var position = DrawPosition(); + var rectBounds = new Rectangle(position.X, position.Y, Bounds.Width, Bounds.Height); WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-top"),new float2(rectBounds.X,rectBounds.Y)); for (var i = 1; i < numPowers; i++) WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world,"specialbin-middle"), new float2(rectBounds.X, rectBounds.Y + i * 51)); diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 9680fc6a56..fbfc60199f 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -83,9 +83,9 @@ namespace OpenRA.Widgets return new Widget(this); } - public int2 getParentOffset() + public int2 DrawPosition() { - return (Parent == null) ? int2.Zero : new int2(Parent.Bounds.Location.X, Parent.Bounds.Location.Y) ; + return new int2(Bounds.X, Bounds.Y) + ((Parent == null) ? int2.Zero : Parent.DrawPosition()); } public virtual void Initialize() @@ -127,7 +127,8 @@ namespace OpenRA.Widgets public bool HitTest(int2 xy) { if (!IsVisible()) return false; - var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); + var pos = DrawPosition(); + var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height); if (rect.Contains(xy.ToPoint()) && !ClickThrough) return true; return Children.Any(c => c.HitTest(xy)); @@ -135,7 +136,8 @@ namespace OpenRA.Widgets public Rectangle GetEventBounds() { - var rect = new Rectangle(Bounds.X + getParentOffset().X, Bounds.Y + getParentOffset().Y, Bounds.Width, Bounds.Height); + var pos = DrawPosition(); + var rect = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height); return Children .Where(c => c.Visible) .Select(c => c.GetEventBounds()) diff --git a/mods/ra/menus.yaml b/mods/ra/menus.yaml index a8dc4abd62..741835e648 100644 --- a/mods/ra/menus.yaml +++ b/mods/ra/menus.yaml @@ -295,6 +295,8 @@ Container: Children: Container@TEMPLATE Id:TEMPLATE + X:0 + Y:0 Visible:false Children: Button@NAME