From 53865f974ef7a23b876e4557bf8687e79f5abd0c Mon Sep 17 00:00:00 2001 From: alzeih Date: Sat, 24 Apr 2010 19:38:58 +1200 Subject: [PATCH] Lobby player listing working with widgets --- OpenRA.Game/Chrome.cs | 62 ------- OpenRA.Game/Widgets/ButtonWidget.cs | 10 +- .../Widgets/Delegates/LobbyDelegate.cs | 84 +++++---- OpenRA.Game/Widgets/LabelWidget.cs | 14 ++ mods/cnc/menus.yaml | 163 ++++++++++++++++++ mods/ra/menus.yaml | 68 +++++++- 6 files changed, 291 insertions(+), 110 deletions(-) diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index e688f415ec..650221316c 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -110,9 +110,7 @@ namespace OpenRA Chrome.rootWidget.CloseWindow(); }); - var mapBackground = new Rectangle(r.Right - 284, r.Top + 26, 264, 264); var mapContainer = new Rectangle(r.Right - 280, r.Top + 30, 256, 256); - var mapRect = currentMap.PreviewBounds(new Rectangle(mapContainer.X,mapContainer.Y,mapContainer.Width,mapContainer.Height)); var y = r.Top + 50; @@ -171,61 +169,6 @@ namespace OpenRA var w = 800; var h = 600; var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h ); - var f = renderer.BoldFont; - - rgbaRenderer.Flush(); - - var y = r.Top + 80; - foreach (var client in Game.LobbyInfo.Clients) - { - var isLocalPlayer = client.Index == Game.orderManager.Connection.LocalClientId; - var paletteRect = new Rectangle(r.Left + 130, y - 2, 65, 22); - /* - if (isLocalPlayer) - { - // todo: name editing - var nameRect = new Rectangle(r.Left + 30, y - 2, 95, 22); - DrawDialogBackground(nameRect, "dialog3"); - - DrawDialogBackground(paletteRect, "dialog3"); - AddButton(paletteRect, CyclePalette); - - var factionRect = new Rectangle(r.Left + 210, y - 2, 90, 22); - DrawDialogBackground(factionRect, "dialog3"); - AddButton(factionRect, CycleRace); - - var spawnPointRect = new Rectangle(r.Left + 305, y - 2, 70, 22); - DrawDialogBackground(spawnPointRect, "dialog3"); - AddButton(spawnPointRect, CycleSpawnPoint); - - var teamRect = new Rectangle(r.Left + 385, y - 2, 70, 22); - DrawDialogBackground(teamRect, "dialog3"); - AddButton(teamRect, CycleTeam); - - var readyRect = new Rectangle(r.Left + 465, y - 2, 50, 22); - DrawDialogBackground(readyRect, "dialog3"); - AddButton(readyRect, CycleReady); - } - */ - shpRenderer.Flush(); - /* - f = renderer.RegularFont; - f.DrawText(client.Name, new int2(r.Left + 40, y), Color.White); - 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)[client.PaletteIndex % Player.PlayerColors(Game.world).Count()].c); - lineRenderer.Flush(); - f.DrawText(client.Country, new int2(r.Left + 220, y), Color.White); - f.DrawText((client.SpawnPoint == 0) ? "-" : client.SpawnPoint.ToString(), new int2(r.Left + 315 + 20, y), Color.White); - f.DrawText((client.Team == 0)? "-" : client.Team.ToString(), new int2(r.Left + 395 + 20, y), Color.White); - f.DrawText(client.State.ToString(), new int2(r.Left + 475, y), Color.White); - y += 30; - */ - rgbaRenderer.Flush(); - - } var typingBox = new Rectangle(r.Left + 20, r.Bottom - 47, r.Width - 40, 27); var chatBox = new Rectangle(r.Left + 20, r.Bottom - 269, r.Width - 40, 220); @@ -234,11 +177,6 @@ namespace OpenRA DrawDialogBackground(chatBox, "dialog3"); DrawChat(typingBox, chatBox); - - // block clicks `through` the dialog - AddButton(r, _ => { }); - - } void AddButton(RectangleF r, Action b) { buttons.Add(Pair.New(r, b)); } diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs index 50afd45ab9..808282ee49 100644 --- a/OpenRA.Game/Widgets/ButtonWidget.cs +++ b/OpenRA.Game/Widgets/ButtonWidget.cs @@ -36,13 +36,13 @@ namespace OpenRA.Widgets GetText = () => { return Text; }; } - public ButtonWidget(ButtonWidget widget) + public ButtonWidget(Widget widget) :base(widget) { - Text = widget.Text; - Depressed = widget.Depressed; - VisualHeight = widget.VisualHeight; - GetText = widget.GetText; + Text = (widget as ButtonWidget).Text; + Depressed = (widget as ButtonWidget).Depressed; + VisualHeight = (widget as ButtonWidget).VisualHeight; + GetText = (widget as ButtonWidget).GetText; } public override bool HandleInput(MouseInput mi) diff --git a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs index 809a7267aa..e12d3f227f 100644 --- a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs @@ -9,15 +9,15 @@ namespace OpenRA.Widgets.Delegates { public class LobbyDelegate : IWidgetDelegate { - Widget PlayerTemplate; - Widget Players; + Widget Players, LocalPlayerTemplate, RemotePlayerTemplate; public LobbyDelegate () { var r = Chrome.rootWidget; var lobby = r.GetWidget("SERVER_LOBBY"); Players = Chrome.rootWidget.GetWidget("SERVER_LOBBY").GetWidget("PLAYERS"); - PlayerTemplate = Players.GetWidget("TEMPLATE"); + LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL"); + RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE"); var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON"); @@ -26,11 +26,9 @@ namespace OpenRA.Widgets.Delegates return true; }; - mapButton.IsVisible = () => {return (mapButton.Visible && Game.IsHost);}; + mapButton.IsVisible = () => mapButton.Visible && Game.IsHost; - Game.LobbyInfoChanged += () => UpdatePlayerList(); - - UpdatePlayerList(); + Game.LobbyInfoChanged += UpdatePlayerList; } void UpdatePlayerList() @@ -41,37 +39,53 @@ namespace OpenRA.Widgets.Delegates foreach(var client in Game.LobbyInfo.Clients) { var c = client; - - Log.Write("Client {0}",c.Name); - var template = PlayerTemplate.Clone(); - var pos = template.DrawPosition(); + var template = (client.Index == Game.LocalClient.Index)? LocalPlayerTemplate.Clone() : RemotePlayerTemplate.Clone(); template.Id = "PLAYER_{0}".F(c.Index); - template.Parent = Players; + template.Parent = Players; + template.GetWidget("NAME").GetText = () => c.Name; - template.GetWidget("NAME").GetText = () => c.Name; - - //TODO: Real Color Button - var color = template.GetWidget("COLOR"); - color.OnMouseUp = mi => CyclePalette(mi); - color.GetText = () => c.PaletteIndex.ToString(); - - var faction = template.GetWidget("FACTION"); - faction.OnMouseUp = mi => CycleRace(mi); - faction.GetText = () => c.Country; - - var spawn = template.GetWidget("SPAWN"); - spawn.OnMouseUp = mi => CycleSpawnPoint(mi); - spawn.GetText = () => { return (c.SpawnPoint == 0) ? "-" : c.SpawnPoint.ToString(); }; - - var team = template.GetWidget("TEAM"); - team.OnMouseUp = mi => CycleTeam(mi); - team.GetText = () => { return (c.Team == 0) ? "-" : c.Team.ToString(); }; - - //It fails here - var status = template.GetWidget("STATUS"); - status.Checked = () => { return (c.State == Session.ClientState.Ready) ? true : false; }; - status.OnMouseDown = mi => CycleReady(mi); + if(client.Index == Game.LocalClient.Index) + { + //TODO: Real Color Button + var color = template.GetWidget("COLOR"); + color.OnMouseUp = CyclePalette; + color.GetText = () => c.PaletteIndex.ToString(); + + var faction = template.GetWidget("FACTION"); + faction.OnMouseUp = CycleRace; + faction.GetText = () => c.Country; + + var spawn = template.GetWidget("SPAWN"); + spawn.OnMouseUp = CycleSpawnPoint; + spawn.GetText = () => (c.SpawnPoint == 0) ? "-" : c.SpawnPoint.ToString(); + + var team = template.GetWidget("TEAM"); + team.OnMouseUp = CycleTeam; + team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString(); + + var status = template.GetWidget("STATUS"); + status.Checked = () => c.State == Session.ClientState.Ready; + status.OnMouseDown = CycleReady; + } + else + { + //TODO: Real Color Label + var color = template.GetWidget("COLOR"); + color.GetText = () => c.PaletteIndex.ToString(); + + var faction = template.GetWidget("FACTION"); + faction.GetText = () => c.Country; + + var spawn = template.GetWidget("SPAWN"); + spawn.GetText = () => (c.SpawnPoint == 0) ? "-" : c.SpawnPoint.ToString(); + + var team = template.GetWidget("TEAM"); + team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString(); + + var status = template.GetWidget("STATUS"); + status.Checked = () => c.State == Session.ClientState.Ready; + } template.Bounds = new Rectangle(0, offset, template.Bounds.Width, template.Bounds.Height); template.IsVisible = () => true; diff --git a/OpenRA.Game/Widgets/LabelWidget.cs b/OpenRA.Game/Widgets/LabelWidget.cs index 3578c2bbac..15b11ea638 100644 --- a/OpenRA.Game/Widgets/LabelWidget.cs +++ b/OpenRA.Game/Widgets/LabelWidget.cs @@ -36,6 +36,15 @@ namespace OpenRA.Widgets GetText = () => { return Text; }; } + public LabelWidget(Widget other) + : base(other) + { + Text = (other as LabelWidget).Text; + Align = (other as LabelWidget).Align; + Bold = (other as LabelWidget).Bold; + GetText = (other as LabelWidget).GetText; + } + public override void Draw(World world) { if (!IsVisible()) @@ -56,5 +65,10 @@ namespace OpenRA.Widgets font.DrawText(text, position, Color.White); base.Draw(world); } + + public override Widget Clone() + { + return new LabelWidget(this); + } } } \ No newline at end of file diff --git a/mods/cnc/menus.yaml b/mods/cnc/menus.yaml index ad3a8caaea..2df088d29f 100644 --- a/mods/cnc/menus.yaml +++ b/mods/cnc/menus.yaml @@ -262,6 +262,7 @@ Container: Text:Abort Background@SERVER_LOBBY: Id:SERVER_LOBBY + Delegate:LobbyDelegate X:(WINDOW_RIGHT - WIDTH)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2 Width:800 @@ -287,6 +288,165 @@ Container: Y:4 Width:244 Height:244 + Container@PLAYERS + Id:PLAYERS + X:30 + Y:75 + Width:500 + Height:200 + Children: + Container@TEMPLATE_LOCAL + Id:TEMPLATE_LOCAL + X:0 + Y:0 + Width:500 + Height:30 + Visible:false + Children: + Label@NAME: + Id:NAME + Text:Name + Width:95 + Height:25 + X:0 + Y:0 + Button@COLOR: + Id:COLOR + Text:Color + Width:65 + Height:25 + X:100 + Y:0 + Button@FACTION: + Id:FACTION + Text:Faction + Width:90 + Height:25 + X:180 + Y:0 + Button@SPAWN: + Id:SPAWN + Text:Spawn + Width:70 + Height:25 + X:275 + Y:0 + Button@TEAM: + Id:TEAM + Text:Team + Width:70 + Height:25 + X:355 + Y:0 + Checkbox@STATUS: + Id:STATUS + X:455 + Y:0 + Width:20 + Height:20 + Container@TEMPLATE_REMOTE + Id:TEMPLATE_REMOTE + X:0 + Y:0 + Width:500 + Height:30 + Visible:false + Children: + Label@NAME: + Id:NAME + Text:Name + Width:95 + Height:25 + X:0 + Y:0 + Label@COLOR: + Id:COLOR + Text:Color + Width:65 + Height:25 + X:100 + Y:0 + Align:Center + Label@FACTION: + Id:FACTION + Text:Faction + Width:90 + Height:25 + X:180 + Y:0 + Align:Center + Label@SPAWN: + Id:SPAWN + Text:Spawn + Width:70 + Height:25 + X:275 + Y:0 + Align:Center + Label@TEAM: + Id:TEAM + Text:Team + Width:70 + Height:25 + X:355 + Y:0 + Align:Center + Checkbox@STATUS: + Id:STATUS + X:455 + Y:0 + Width:20 + Height:20 + Button@CHANGEMAP_BUTTON: + Id:CHANGEMAP_BUTTON + Visible:true + X:PARENT_RIGHT-140 + Y:300 + 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:Status Background@MAP_CHOOSER: Id:MAP_CHOOSER X:(WINDOW_RIGHT - WIDTH)/2 @@ -463,3 +623,6 @@ Container: Width:25 Height:25 Text:[] + + + diff --git a/mods/ra/menus.yaml b/mods/ra/menus.yaml index 8b58f15f11..2df088d29f 100644 --- a/mods/ra/menus.yaml +++ b/mods/ra/menus.yaml @@ -292,18 +292,18 @@ Container: Id:PLAYERS X:30 Y:75 - Width:455 + Width:500 Height:200 Children: - Container@TEMPLATE - Id:TEMPLATE + Container@TEMPLATE_LOCAL + Id:TEMPLATE_LOCAL X:0 Y:0 - Width:455 + Width:500 Height:30 Visible:false Children: - Button@NAME: + Label@NAME: Id:NAME Text:Name Width:95 @@ -340,11 +340,63 @@ Container: Y:0 Checkbox@STATUS: Id:STATUS - X:430 + X:455 Y:0 - Width:300 + Width:20 + Height:20 + Container@TEMPLATE_REMOTE + Id:TEMPLATE_REMOTE + X:0 + Y:0 + Width:500 + Height:30 + Visible:false + Children: + Label@NAME: + Id:NAME + Text:Name + Width:95 + Height:25 + X:0 + Y:0 + Label@COLOR: + Id:COLOR + Text:Color + Width:65 + Height:25 + X:100 + Y:0 + Align:Center + Label@FACTION: + Id:FACTION + Text:Faction + Width:90 + Height:25 + X:180 + Y:0 + Align:Center + Label@SPAWN: + Id:SPAWN + Text:Spawn + Width:70 + Height:25 + X:275 + Y:0 + Align:Center + Label@TEAM: + Id:TEAM + Text:Team + Width:70 + Height:25 + X:355 + Y:0 + Align:Center + Checkbox@STATUS: + Id:STATUS + X:455 + Y:0 + Width:20 Height:20 - Text:Show Spatial Index Debug Button@CHANGEMAP_BUTTON: Id:CHANGEMAP_BUTTON Visible:true