diff --git a/OpenRA.Game/Widgets/ScrollPanelWidget.cs b/OpenRA.Game/Widgets/ScrollPanelWidget.cs index aeafcb250c..5f8adab3ad 100644 --- a/OpenRA.Game/Widgets/ScrollPanelWidget.cs +++ b/OpenRA.Game/Widgets/ScrollPanelWidget.cs @@ -19,6 +19,7 @@ namespace OpenRA.Widgets public readonly string Background = "dialog3"; public readonly int ScrollbarWidth = 24; public readonly float ScrollVelocity = 4f; + public readonly int ItemSpacing = 2; public int ContentHeight = 0; float ListOffset = 0; @@ -35,16 +36,24 @@ namespace OpenRA.Widgets protected ScrollPanelWidget(ScrollPanelWidget other) : base(other) { - Background = other.Background; - upButtonRect = other.upButtonRect; - downButtonRect = other.downButtonRect; - scrollbarRect = other.scrollbarRect; - backgroundRect = other.backgroundRect; - thumbRect = other.thumbRect; + throw new NotImplementedException(); + } + + public void ClearChildren() + { + Children.Clear(); + ContentHeight = 0; + } + + public override void AddChild(Widget child) + { + // Initial setup of margins/height + if (Children.Count == 0) + ContentHeight = ItemSpacing; - UpPressed = other.UpPressed; - DownPressed = other.DownPressed; - ThumbPressed = other.ThumbPressed; + child.Bounds.Y += ContentHeight; + ContentHeight += child.Bounds.Height + ItemSpacing; + base.AddChild(child); } public override void DrawInner( WorldRenderer wr ) {} diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 8a14aa0361..a858d4a3d5 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -287,7 +287,7 @@ namespace OpenRA.Widgets child.Tick(); } - public void AddChild(Widget child) + public virtual void AddChild(Widget child) { child.Parent = this; Children.Add( child ); diff --git a/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs index 6185dab7fb..439989a966 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs @@ -293,10 +293,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates { // This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them) // Todo: handle this nicer - Players.Children.Clear(); - Players.ContentHeight = 0; + Players.ClearChildren(); - int offset = 0; foreach (var slot in orderManager.LobbyInfo.Slots) { var s = slot; @@ -446,19 +444,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates } template.Id = "SLOT_{0}".F(s.Index); - template.Parent = Players; - - template.Bounds = new Rectangle(template.Bounds.X, template.Bounds.Y + offset, template.Bounds.Width, template.Bounds.Height); template.IsVisible = () => true; Players.AddChild(template); - - offset += template.Bounds.Height; - - // Hack to ensure correct ContentHeight - if (Players.ContentHeight == 0) - Players.ContentHeight += template.Bounds.Y; - - Players.ContentHeight += template.Bounds.Height; } } diff --git a/OpenRA.Mods.RA/Widgets/Delegates/MapChooserDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/MapChooserDelegate.cs index fce6ff1788..fa0bbdfac3 100644 --- a/OpenRA.Mods.RA/Widgets/Delegates/MapChooserDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/MapChooserDelegate.cs @@ -55,7 +55,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates }; var itemTemplate = ml.GetWidget("MAP_TEMPLATE"); - int offset = itemTemplate.Bounds.Y; foreach (var kv in Game.modData.AvailableMaps.OrderBy(kv => kv.Value.Title)) { var map = kv.Value; @@ -66,19 +65,10 @@ namespace OpenRA.Mods.RA.Widgets.Delegates template.Id = "MAP_{0}".F(map.Uid); template.GetBackground = () => ((Map == map) ? "dialog2" : null); template.OnMouseDown = mi => { Map = map; return true; }; - template.Parent = ml; - template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height); template.IsVisible = () => true; template.GetWidget("TITLE").GetText = () => " " + map.Title; template.GetWidget("TYPE").GetText = () => map.Type + " "; ml.AddChild(template); - - offset += template.Bounds.Height; - - // Padding hack - if (ml.ContentHeight == 0) - ml.ContentHeight += 2*template.Bounds.Y; - ml.ContentHeight += template.Bounds.Height; } } } diff --git a/OpenRA.Mods.RA/Widgets/Delegates/MusicPlayerDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/MusicPlayerDelegate.cs index 03fb19f0b8..1809c8e186 100644 --- a/OpenRA.Mods.RA/Widgets/Delegates/MusicPlayerDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/MusicPlayerDelegate.cs @@ -98,7 +98,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates var ml = bg.GetWidget("MUSIC_LIST"); var itemTemplate = ml.GetWidget("MUSIC_TEMPLATE"); - int offset = itemTemplate.Bounds.Y; if (!Rules.Music.Where(m => m.Value.Exists).Any()) { @@ -122,24 +121,12 @@ namespace OpenRA.Mods.RA.Widgets.Delegates bg.GetWidget("BUTTON_PLAY").OnMouseUp(mi); return true; }; - template.Parent = ml; - template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height); - template.IsVisible = () => true; - + template.IsVisible = () => true; template.GetWidget("TITLE").GetText = () => " " + Rules.Music[song].Title; template.GetWidget("LENGTH").GetText = () => "{0:D1}:{1:D2}".F(Rules.Music[song].Length / 60, Rules.Music[song].Length % 60); ml.AddChild(template); - - offset += template.Bounds.Height; - - // Padding hack - if (ml.ContentHeight == 0) - ml.ContentHeight += 2*template.Bounds.Y; - - ml.ContentHeight += template.Bounds.Height; - } } diff --git a/OpenRA.Mods.RA/Widgets/Delegates/ReplayBrowserDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/ReplayBrowserDelegate.cs index c76c8ee125..b8584bdc53 100644 --- a/OpenRA.Mods.RA/Widgets/Delegates/ReplayBrowserDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/ReplayBrowserDelegate.cs @@ -40,11 +40,9 @@ namespace OpenRA.Mods.RA.Widgets.Delegates var template = widget.GetWidget("REPLAY_TEMPLATE"); CurrentReplay = null; - rl.Children.Clear(); - rl.ContentHeight = 0; - var offset = template.Bounds.Y; + rl.ClearChildren(); foreach (var replayFile in Directory.GetFiles(replayDir, "*.rep").Reverse()) - AddReplay(rl, replayFile, template, ref offset); + AddReplay(rl, replayFile, template); widget.GetWidget("WATCH_BUTTON").OnMouseUp = mi => { @@ -100,27 +98,15 @@ namespace OpenRA.Mods.RA.Widgets.Delegates } } - void AddReplay(ScrollPanelWidget list, string filename, LabelWidget template, ref int offset) + void AddReplay(ScrollPanelWidget list, string filename, LabelWidget template) { var entry = template.Clone() as LabelWidget; entry.Id = "REPLAY_"; entry.GetText = () => " {0}".F(Path.GetFileName(filename)); entry.GetBackground = () => (CurrentReplay == filename) ? "dialog2" : null; entry.OnMouseDown = mi => { CurrentReplay = filename; return true; }; - entry.Parent = list; - entry.Bounds = new Rectangle(entry.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height); entry.IsVisible = () => true; list.AddChild(entry); - - if (offset == template.Bounds.Y) - CurrentReplay = filename; - - offset += template.Bounds.Height; - // Padding hack - if (list.ContentHeight == 0) - list.ContentHeight += 2*template.Bounds.Y; - - list.ContentHeight += template.Bounds.Height; } } diff --git a/OpenRA.Mods.RA/Widgets/Delegates/ServerBrowserDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/ServerBrowserDelegate.cs index 3cd2b10292..1c3d546886 100644 --- a/OpenRA.Mods.RA/Widgets/Delegates/ServerBrowserDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/ServerBrowserDelegate.cs @@ -139,7 +139,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates var sl = bg.GetWidget("SERVER_LIST"); - sl.Children.Clear(); + sl.ClearChildren(); currentServer = null; if (games == null) @@ -161,8 +161,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = false; - sl.ContentHeight = 0; - int offset = ServerTemplate.Bounds.Y; int i = 0; foreach (var loop in gamesWaiting) { @@ -174,20 +172,10 @@ namespace OpenRA.Mods.RA.Widgets.Delegates game.Address); template.GetBackground = () => (currentServer == game) ? "dialog2" : null; template.OnMouseDown = mi => { currentServer = game; return true; }; - template.Parent = sl; - - template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height); template.IsVisible = () => true; sl.AddChild(template); if (i == 0) currentServer = game; - - offset += template.Bounds.Height; - // Padding hack - if (sl.ContentHeight == 0) - sl.ContentHeight += 2*template.Bounds.Y; - - sl.ContentHeight += template.Bounds.Height; i++; } } diff --git a/OpenRA.Mods.RA/Widgets/Delegates/VideoPlayerDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/VideoPlayerDelegate.cs index 204ed51829..503d6fba47 100644 --- a/OpenRA.Mods.RA/Widgets/Delegates/VideoPlayerDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/VideoPlayerDelegate.cs @@ -57,7 +57,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates var vl = bg.GetWidget("VIDEO_LIST"); var itemTemplate = vl.GetWidget("VIDEO_TEMPLATE"); - int offset = itemTemplate.Bounds.Y; foreach (var kv in Rules.Movies) { @@ -79,14 +78,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates player.Load(video); return true; }; - template.Parent = vl; - - template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height); template.IsVisible = () => true; vl.AddChild(template); - - offset += template.Bounds.Height; - vl.ContentHeight += template.Bounds.Height; } } } diff --git a/mods/cnc/chrome/gamelobby.yaml b/mods/cnc/chrome/gamelobby.yaml index e3a7591e8d..8561d65bea 100644 --- a/mods/cnc/chrome/gamelobby.yaml +++ b/mods/cnc/chrome/gamelobby.yaml @@ -32,15 +32,16 @@ Background@SERVER_LOBBY: Id:PLAYERS X:20 Y:67 + ItemSpacing:5 Width:504 Height:235 Children: Container@TEMPLATE_LOCAL: Id:TEMPLATE_LOCAL X:5 - Y:5 + Y:0 Width:475 - Height:30 + Height:25 Visible:false Children: TextField@NAME: @@ -109,9 +110,9 @@ Background@SERVER_LOBBY: Container@TEMPLATE_REMOTE: Id:TEMPLATE_REMOTE X:5 - Y:5 + Y:0 Width:475 - Height:30 + Height:25 Visible:false Children: Label@NAME: @@ -181,9 +182,9 @@ Background@SERVER_LOBBY: Container@TEMPLATE_EMPTY: Id:TEMPLATE_EMPTY X:5 - Y:5 + Y:0 Width:475 - Height:30 + Height:25 Visible:false Children: Label@NAME: @@ -212,9 +213,9 @@ Background@SERVER_LOBBY: Container@TEMPLATE_EMPTY_HOST: Id:TEMPLATE_EMPTY_HOST X:5 - Y:5 + Y:0 Width:400 - Height:30 + Height:25 Visible:false Children: DropDownButton@NAME: @@ -448,7 +449,7 @@ Background@MAP_CHOOSER: Height:25 ClickThrough:false X:2 - Y:2 + Y:0 Visible:false Children: Label@TITLE: diff --git a/mods/cnc/chrome/mainmenu.yaml b/mods/cnc/chrome/mainmenu.yaml index 011ab2a716..7013d9b680 100644 --- a/mods/cnc/chrome/mainmenu.yaml +++ b/mods/cnc/chrome/mainmenu.yaml @@ -220,7 +220,7 @@ Background@MUSIC_MENU: Height:25 ClickThrough:false X:2 - Y:2 + Y:0 Visible:false Children: Label@TITLE: diff --git a/mods/cnc/chrome/replaybrowser.yaml b/mods/cnc/chrome/replaybrowser.yaml index 07ba33fed9..72baeba2c3 100644 --- a/mods/cnc/chrome/replaybrowser.yaml +++ b/mods/cnc/chrome/replaybrowser.yaml @@ -28,7 +28,7 @@ Background@REPLAYBROWSER_BG: Height:25 ClickThrough:false X:2 - Y:2 + Y:0 Visible:false Container@REPLAY_INFO: Id:REPLAY_INFO diff --git a/mods/cnc/chrome/serverbrowser.yaml b/mods/cnc/chrome/serverbrowser.yaml index 6e3bc8033a..17f6229265 100644 --- a/mods/cnc/chrome/serverbrowser.yaml +++ b/mods/cnc/chrome/serverbrowser.yaml @@ -122,7 +122,7 @@ Background@JOINSERVER_BG: Height:25 ClickThrough:false X:2 - Y:2 + Y:0 Visible:false Label@JOINSERVER_PROGRESS_TITLE: Id:JOINSERVER_PROGRESS_TITLE diff --git a/mods/cnc/chrome/videoplayer.yaml b/mods/cnc/chrome/videoplayer.yaml index 7e2e596f5f..38eeff162a 100644 --- a/mods/cnc/chrome/videoplayer.yaml +++ b/mods/cnc/chrome/videoplayer.yaml @@ -33,7 +33,7 @@ Background@VIDEOPLAYER_MENU: Height:25 ClickThrough:false X:2 - Y:2 + Y:0 Visible:false Button@BUTTON_PLAYPAUSE: Id:BUTTON_PLAYPAUSE diff --git a/mods/d2k/chrome/gamelobby.yaml b/mods/d2k/chrome/gamelobby.yaml index 80731b8b8b..c63d53c9d7 100644 --- a/mods/d2k/chrome/gamelobby.yaml +++ b/mods/d2k/chrome/gamelobby.yaml @@ -419,7 +419,7 @@ Background@MAP_CHOOSER: Height:25 ClickThrough:false X:2 - Y:2 + Y:0 Visible:false Background@MAPCHOOSER_MAP_BG: X:PARENT_RIGHT-268 diff --git a/mods/d2k/chrome/mainmenu.yaml b/mods/d2k/chrome/mainmenu.yaml index eb318e6d7a..b02efcb949 100644 --- a/mods/d2k/chrome/mainmenu.yaml +++ b/mods/d2k/chrome/mainmenu.yaml @@ -222,7 +222,7 @@ Background@MUSIC_MENU: Height:25 ClickThrough:false X:2 - Y:2 + Y:0 Visible:false Children: Label@TITLE: diff --git a/mods/d2k/chrome/serverbrowser.yaml b/mods/d2k/chrome/serverbrowser.yaml index 1856e6ac8b..ce68c4b4c6 100644 --- a/mods/d2k/chrome/serverbrowser.yaml +++ b/mods/d2k/chrome/serverbrowser.yaml @@ -124,7 +124,7 @@ Background@JOINSERVER_BG: Height:25 ClickThrough:false X:2 - Y:2 + Y:0 Visible:false Label@JOINSERVER_PROGRESS_TITLE: Id:JOINSERVER_PROGRESS_TITLE diff --git a/mods/d2k/chrome/videoplayer.yaml b/mods/d2k/chrome/videoplayer.yaml index b01a9e1834..08448de714 100644 --- a/mods/d2k/chrome/videoplayer.yaml +++ b/mods/d2k/chrome/videoplayer.yaml @@ -34,7 +34,7 @@ Background@VIDEOPLAYER_MENU: Height:25 ClickThrough:false X:2 - Y:2 + Y:0 Visible:false Button@BUTTON_PLAYPAUSE: Id:BUTTON_PLAYPAUSE diff --git a/mods/ra/chrome/gamelobby.yaml b/mods/ra/chrome/gamelobby.yaml index 5edee77359..d111daac6f 100644 --- a/mods/ra/chrome/gamelobby.yaml +++ b/mods/ra/chrome/gamelobby.yaml @@ -32,15 +32,16 @@ Background@SERVER_LOBBY: Id:PLAYERS X:20 Y:67 + ItemSpacing:5 Width:504 Height:235 Children: Container@TEMPLATE_LOCAL: Id:TEMPLATE_LOCAL X:5 - Y:5 + Y:0 Width:475 - Height:30 + Height:25 Visible:false Children: TextField@NAME: @@ -109,9 +110,9 @@ Background@SERVER_LOBBY: Container@TEMPLATE_REMOTE: Id:TEMPLATE_REMOTE X:5 - Y:5 + Y:0 Width:475 - Height:30 + Height:25 Visible:false Children: Label@NAME: @@ -181,9 +182,9 @@ Background@SERVER_LOBBY: Container@TEMPLATE_EMPTY: Id:TEMPLATE_EMPTY X:5 - Y:5 + Y:0 Width:475 - Height:30 + Height:25 Visible:false Children: Label@NAME: @@ -212,9 +213,9 @@ Background@SERVER_LOBBY: Container@TEMPLATE_EMPTY_HOST: Id:TEMPLATE_EMPTY_HOST X:5 - Y:5 + Y:0 Width:400 - Height:30 + Height:25 Visible:false Children: DropDownButton@NAME: @@ -448,7 +449,7 @@ Background@MAP_CHOOSER: Height:25 ClickThrough:false X:2 - Y:2 + Y:0 Visible:false Children: Label@TITLE: diff --git a/mods/ra/chrome/mainmenu.yaml b/mods/ra/chrome/mainmenu.yaml index 8ce32e576b..713eff510c 100644 --- a/mods/ra/chrome/mainmenu.yaml +++ b/mods/ra/chrome/mainmenu.yaml @@ -221,7 +221,7 @@ Background@MUSIC_MENU: Height:25 ClickThrough:false X:2 - Y:2 + Y:0 Visible:false Children: Label@TITLE: diff --git a/mods/ra/chrome/replaybrowser.yaml b/mods/ra/chrome/replaybrowser.yaml index 07ba33fed9..72baeba2c3 100644 --- a/mods/ra/chrome/replaybrowser.yaml +++ b/mods/ra/chrome/replaybrowser.yaml @@ -28,7 +28,7 @@ Background@REPLAYBROWSER_BG: Height:25 ClickThrough:false X:2 - Y:2 + Y:0 Visible:false Container@REPLAY_INFO: Id:REPLAY_INFO diff --git a/mods/ra/chrome/serverbrowser.yaml b/mods/ra/chrome/serverbrowser.yaml index 6e3bc8033a..17f6229265 100644 --- a/mods/ra/chrome/serverbrowser.yaml +++ b/mods/ra/chrome/serverbrowser.yaml @@ -122,7 +122,7 @@ Background@JOINSERVER_BG: Height:25 ClickThrough:false X:2 - Y:2 + Y:0 Visible:false Label@JOINSERVER_PROGRESS_TITLE: Id:JOINSERVER_PROGRESS_TITLE diff --git a/mods/ra/chrome/videoplayer.yaml b/mods/ra/chrome/videoplayer.yaml index 7e2e596f5f..38eeff162a 100644 --- a/mods/ra/chrome/videoplayer.yaml +++ b/mods/ra/chrome/videoplayer.yaml @@ -33,7 +33,7 @@ Background@VIDEOPLAYER_MENU: Height:25 ClickThrough:false X:2 - Y:2 + Y:0 Visible:false Button@BUTTON_PLAYPAUSE: Id:BUTTON_PLAYPAUSE