From ba2704291a1589338db0e06c85d6b660e1b68906 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 25 Apr 2013 12:07:30 +1200 Subject: [PATCH 1/6] Implement new spawn tooltips in RA and d2k. --- OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj | 1 - OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 1 + .../Logic/SpawnSelectorTooltipLogic.cs | 17 +++++++++----- mods/cnc/chrome/lobby.yaml | 2 +- mods/cnc/chrome/tooltips.yaml | 8 +++++-- mods/d2k/chrome/lobby.yaml | 4 +++- mods/d2k/chrome/tooltips.yaml | 23 +++++++++++++++++++ mods/d2k/mod.yaml | 1 + mods/ra/chrome/lobby.yaml | 4 +++- mods/ra/chrome/tooltips.yaml | 23 +++++++++++++++++++ mods/ra/mod.yaml | 1 + 11 files changed, 73 insertions(+), 12 deletions(-) rename {OpenRA.Mods.Cnc => OpenRA.Mods.RA}/Widgets/Logic/SpawnSelectorTooltipLogic.cs (79%) create mode 100644 mods/d2k/chrome/tooltips.yaml create mode 100644 mods/ra/chrome/tooltips.yaml diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index c7d8551f80..dddbb9e9b7 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -113,7 +113,6 @@ - diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index df0d79d224..328a098d0b 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -430,6 +430,7 @@ + diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/SpawnSelectorTooltipLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/SpawnSelectorTooltipLogic.cs similarity index 79% rename from OpenRA.Mods.Cnc/Widgets/Logic/SpawnSelectorTooltipLogic.cs rename to OpenRA.Mods.RA/Widgets/Logic/SpawnSelectorTooltipLogic.cs index 6ad7f65538..3745ae98e4 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/SpawnSelectorTooltipLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/SpawnSelectorTooltipLogic.cs @@ -14,7 +14,7 @@ using System.Linq; using OpenRA.Widgets; using OpenRA.Network; -namespace OpenRA.Mods.Cnc.Widgets.Logic +namespace OpenRA.Mods.RA.Widgets.Logic { public class SpawnSelectorTooltipLogic { @@ -25,9 +25,14 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var label = widget.Get("LABEL"); var flag = widget.Get("FLAG"); var team = widget.Get("TEAM"); - + var singleHeight = widget.Get("SINGLE_HEIGHT").Bounds.Height; + var doubleHeight = widget.Get("DOUBLE_HEIGHT").Bounds.Height; var ownerFont = Game.Renderer.Fonts[label.Font]; var teamFont = Game.Renderer.Fonts[team.Font]; + + // Width specified in YAML is used as the margin between flag / label and label / border + var labelMargin = widget.Bounds.Width; + var cachedWidth = 0; var labelText = ""; string playerCountry = null; @@ -43,18 +48,18 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic labelText = "Available spawn"; playerCountry = null; playerTeam = 0; - widget.Bounds.Height = 25; + widget.Bounds.Height = singleHeight; } else { labelText = client.Name; playerCountry = client.Country; playerTeam = client.Team; - widget.Bounds.Height = playerTeam > 0 ? 40 : 25; + widget.Bounds.Height = playerTeam > 0 ? doubleHeight : singleHeight; teamWidth = teamFont.Measure(team.GetText()).X; } - label.Bounds.X = playerCountry != null ? flag.Bounds.Right + 5 : 5; + label.Bounds.X = playerCountry != null ? flag.Bounds.Right + labelMargin : labelMargin; var textWidth = ownerFont.Measure(labelText).X; if (textWidth != cachedWidth) @@ -63,7 +68,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic widget.Bounds.Width = 2*label.Bounds.X + textWidth; } - widget.Bounds.Width = Math.Max(teamWidth + 10, label.Bounds.Right + 5); + widget.Bounds.Width = Math.Max(teamWidth + 2*labelMargin, label.Bounds.Right + labelMargin); team.Bounds.Width = widget.Bounds.Width; }; diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index b5f325c6e0..28907a96df 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -480,7 +480,6 @@ Container@SERVER_LOBBY: Height:25 Align:Right Text:Chat: - TooltipContainer@TOOLTIP_CONTAINER: Button@DISCONNECT_BUTTON: X:0 Y:499 @@ -505,3 +504,4 @@ Container@SERVER_LOBBY: Width:140 Height:35 Text:Start Game + TooltipContainer@TOOLTIP_CONTAINER: \ No newline at end of file diff --git a/mods/cnc/chrome/tooltips.yaml b/mods/cnc/chrome/tooltips.yaml index ed35e8ddb3..49644b4746 100644 --- a/mods/cnc/chrome/tooltips.yaml +++ b/mods/cnc/chrome/tooltips.yaml @@ -103,8 +103,12 @@ Background@SUPPORT_POWER_TOOLTIP: Background@SPAWN_TOOLTIP: Logic:SpawnSelectorTooltipLogic Background:panel-black - Width:141 + Width:5 Children: + Container@SINGLE_HEIGHT: + Height:26 + Container@DOUBLE_HEIGHT: + Height:40 Label@LABEL: X:5 Height:23 @@ -118,4 +122,4 @@ Background@SPAWN_TOOLTIP: Y:21 Height:15 Font:TinyBold - Align:center \ No newline at end of file + Align:center diff --git a/mods/d2k/chrome/lobby.yaml b/mods/d2k/chrome/lobby.yaml index e000aadfec..6abb365c69 100644 --- a/mods/d2k/chrome/lobby.yaml +++ b/mods/d2k/chrome/lobby.yaml @@ -34,6 +34,7 @@ Background@SERVER_LOBBY: Y:4 Width:244 Height:244 + TooltipContainer:TOOLTIP_CONTAINER ScrollPanel@PLAYERS: X:20 Y:67 @@ -493,4 +494,5 @@ Background@SERVER_LOBBY: Width:120 Height:25 Text:Start Game - Font:Bold \ No newline at end of file + Font:Bold + TooltipContainer@TOOLTIP_CONTAINER: \ No newline at end of file diff --git a/mods/d2k/chrome/tooltips.yaml b/mods/d2k/chrome/tooltips.yaml new file mode 100644 index 0000000000..c8b88119c5 --- /dev/null +++ b/mods/d2k/chrome/tooltips.yaml @@ -0,0 +1,23 @@ +Background@SPAWN_TOOLTIP: + Logic:SpawnSelectorTooltipLogic + Background:dialog3 + Width:7 + Children: + Container@SINGLE_HEIGHT: + Height:31 + Container@DOUBLE_HEIGHT: + Height:47 + Label@LABEL: + Y:3 + Height:23 + Font:Bold + Image@FLAG: + X:5 + Y:5 + Width:23 + Height:23 + Label@TEAM: + Y:28 + Height:15 + Font:TinyBold + Align:center \ No newline at end of file diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index 477dd592b6..0999f09c7c 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -60,6 +60,7 @@ ChromeLayout: mods/ra/chrome/dropdowns.yaml mods/ra/chrome/modchooser.yaml mods/ra/chrome/cheats.yaml + mods/d2k/chrome/tooltips.yaml Weapons: mods/d2k/weapons/defaults.yaml diff --git a/mods/ra/chrome/lobby.yaml b/mods/ra/chrome/lobby.yaml index 39de30bbac..d087512504 100644 --- a/mods/ra/chrome/lobby.yaml +++ b/mods/ra/chrome/lobby.yaml @@ -34,6 +34,7 @@ Background@SERVER_LOBBY: Y:4 Width:244 Height:244 + TooltipContainer:TOOLTIP_CONTAINER ScrollPanel@PLAYERS: X:20 Y:67 @@ -499,4 +500,5 @@ Background@SERVER_LOBBY: Width:120 Height:25 Text:Start Game - Font:Bold \ No newline at end of file + Font:Bold + TooltipContainer@TOOLTIP_CONTAINER: \ No newline at end of file diff --git a/mods/ra/chrome/tooltips.yaml b/mods/ra/chrome/tooltips.yaml new file mode 100644 index 0000000000..03904d5d69 --- /dev/null +++ b/mods/ra/chrome/tooltips.yaml @@ -0,0 +1,23 @@ +Background@SPAWN_TOOLTIP: + Logic:SpawnSelectorTooltipLogic + Background:dialog4 + Width:7 + Children: + Container@SINGLE_HEIGHT: + Height:29 + Container@DOUBLE_HEIGHT: + Height:44 + Label@LABEL: + Y:2 + Height:23 + Font:Bold + Image@FLAG: + X:7 + Y:7 + Width:32 + Height:16 + Label@TEAM: + Y:23 + Height:15 + Font:TinyBold + Align:center \ No newline at end of file diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index ae392c4e35..d5f84e3c1b 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -70,6 +70,7 @@ ChromeLayout: mods/ra/chrome/modchooser.yaml mods/ra/chrome/cheats.yaml mods/ra/chrome/objectives.yaml + mods/ra/chrome/tooltips.yaml Weapons: mods/ra/weapons.yaml From a1d2229a585666076a9c8f502c32e368d44a59e1 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 25 Apr 2013 12:13:31 +1200 Subject: [PATCH 2/6] Remove legacy tooltip code. --- OpenRA.Game/Widgets/MapPreviewWidget.cs | 7 ------- OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs | 1 - OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs | 9 --------- 3 files changed, 17 deletions(-) diff --git a/OpenRA.Game/Widgets/MapPreviewWidget.cs b/OpenRA.Game/Widgets/MapPreviewWidget.cs index 18ce33f525..3da666e6dc 100644 --- a/OpenRA.Game/Widgets/MapPreviewWidget.cs +++ b/OpenRA.Game/Widgets/MapPreviewWidget.cs @@ -24,7 +24,6 @@ namespace OpenRA.Widgets public Func Map = () => null; public Func> SpawnClients = () => new Dictionary(); public Action OnMouseDown = _ => {}; - public Action OnTooltip = (_, __) => { }; public bool IgnoreMouseInput = false; public bool ShowSpawnPoints = true; @@ -147,13 +146,7 @@ namespace OpenRA.Widgets Game.Renderer.RgbaSpriteRenderer.DrawSprite(sprite, pos + offset); if ((pos - Viewport.LastMousePos).LengthSquared < 64) - { TooltipSpawnIndex = spawnPoints.IndexOf(p) + 1; - - // Legacy tooltip behavior - if (TooltipContainer == null) - OnTooltip(TooltipSpawnIndex, pos); - } } } } diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index e1604531f8..44d80257eb 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -112,7 +112,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic mapPreview.IsVisible = () => Map != null; mapPreview.Map = () => Map; mapPreview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint( orderManager, mapPreview, Map, mi ); - mapPreview.OnTooltip = (spawnPoint, pos) => LobbyUtils.ShowSpawnPointTooltip(orderManager, spawnPoint, pos); mapPreview.SpawnClients = () => LobbyUtils.GetSpawnClients(orderManager, Map); var mapTitle = lobby.GetOrNull("MAP_TITLE"); diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs index 8cbf698add..09ba31f0a8 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs @@ -158,15 +158,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic } } - public static void ShowSpawnPointTooltip(OrderManager orderManager, int spawnPoint, int2 position) - { - var client = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == spawnPoint); - if (client != null) - { - Game.Renderer.Fonts["Bold"].DrawTextWithContrast(client.Name, position + new int2(5, 5), Color.White, Color.Black, 1); - } - } - static Color GetPingColor(Session.Client c) { if (c.Ping < 0) // Ping unknown From fd58461d4328ae391ca2ed266794546373f0814b Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 25 Apr 2013 13:43:05 +1200 Subject: [PATCH 3/6] Rename Ping -> Latency. --- OpenRA.Game/Network/Session.cs | 6 +++--- OpenRA.Game/Server/Server.cs | 8 ++++---- OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs | 6 +++--- OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs | 14 +++++++------- mods/cnc/chrome/lobby.yaml | 16 ++++++++-------- mods/d2k/chrome/lobby.yaml | 16 ++++++++-------- mods/ra/chrome/lobby.yaml | 16 ++++++++-------- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/OpenRA.Game/Network/Session.cs b/OpenRA.Game/Network/Session.cs index 98301611b3..7f7835cb56 100644 --- a/OpenRA.Game/Network/Session.cs +++ b/OpenRA.Game/Network/Session.cs @@ -61,9 +61,9 @@ namespace OpenRA.Network public bool IsAdmin; public bool IsReady { get { return State == ClientState.Ready; } } public bool IsObserver { get { return Slot == null; } } - public int Ping = -1; - public int PingJitter = -1; - public int[] PingHistory = {}; + public int Latency = -1; + public int LatencyJitter = -1; + public int[] LatencyHistory = {}; } public class Slot diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index b962608669..3f3e4af03e 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -469,16 +469,16 @@ namespace OpenRA.Server break; } - var history = fromClient.PingHistory.ToList(); + var history = fromClient.LatencyHistory.ToList(); history.Add(Environment.TickCount - pingSent); // Cap ping history at 5 values (25 seconds) if (history.Count > 5) history.RemoveRange(0, history.Count - 5); - fromClient.Ping = history.Sum() / history.Count; - fromClient.PingJitter = (history.Max() - history.Min())/2; - fromClient.PingHistory = history.ToArray(); + fromClient.Latency = history.Sum() / history.Count; + fromClient.LatencyJitter = (history.Max() - history.Min())/2; + fromClient.LatencyHistory = history.ToArray(); if (State == ServerState.WaitingPlayers) SyncLobbyInfo(); diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index 44d80257eb..e57c09181e 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -388,7 +388,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic if (template == null || template.Id != EditablePlayerTemplate.Id) template = EditablePlayerTemplate.Clone(); - LobbyUtils.SetupAdminPingWidget(template, slot, client, orderManager, client.Bot == null); + LobbyUtils.SetupClientWidget(template, slot, client, orderManager, client.Bot == null); if (client.Bot != null) LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager); @@ -408,7 +408,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic if (template == null || template.Id != NonEditablePlayerTemplate.Id) template = NonEditablePlayerTemplate.Clone(); - LobbyUtils.SetupAdminPingWidget(template, slot, client, orderManager, client.Bot == null); + LobbyUtils.SetupClientWidget(template, slot, client, orderManager, client.Bot == null); LobbyUtils.SetupNameWidget(template, slot, client); LobbyUtils.SetupKickWidget(template, slot, client, orderManager); LobbyUtils.SetupColorWidget(template, slot, client); @@ -459,7 +459,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic LobbyUtils.SetupReadyWidget(template, null, client); } - LobbyUtils.SetupAdminPingWidget(template, null, c, orderManager, true); + LobbyUtils.SetupClientWidget(template, null, c, orderManager, true); template.IsVisible = () => true; if (idx >= Players.Children.Count) diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs index 09ba31f0a8..3fc94ad7f3 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs @@ -158,26 +158,26 @@ namespace OpenRA.Mods.RA.Widgets.Logic } } - static Color GetPingColor(Session.Client c) + static Color GetLatencyColor(Session.Client c) { - if (c.Ping < 0) // Ping unknown + if (c.Latency < 0) // Ping unknown return Color.Gray; - if (c.Ping > 720) // OrderLag > 6 + if (c.Latency > 720) // OrderLag > 6 return Color.Red; - if (c.Ping > 360) // OrderLag > 3 + if (c.Latency > 360) // OrderLag > 3 return Color.Orange; return Color.LimeGreen; } - public static void SetupAdminPingWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, bool visible) + public static void SetupClientWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, bool visible) { parent.Get("ADMIN_INDICATOR").IsVisible = () => c.IsAdmin; - var block = parent.Get("PING_BLOCK"); + var block = parent.Get("LATENCY"); block.IsVisible = () => visible; if (visible) - block.Get("PING_COLOR").GetColor = () => GetPingColor(c); + block.Get("LATENCY_COLOR").GetColor = () => GetLatencyColor(c); } public static void SetupEditableNameWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager) diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index 28907a96df..bf1e029182 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -73,7 +73,7 @@ Container@SERVER_LOBBY: ImageName:admin X:2 Visible:false - Background@PING_BLOCK: + Background@LATENCY: Background:button X:0 Y:6 @@ -81,7 +81,7 @@ Container@SERVER_LOBBY: Height:14 Visible:false Children: - ColorBlock@PING_COLOR: + ColorBlock@LATENCY_COLOR: X:2 Y:2 Width:PARENT_RIGHT-4 @@ -161,7 +161,7 @@ Container@SERVER_LOBBY: ImageName:admin X:2 Visible:false - Background@PING_BLOCK: + Background@LATENCY: Background:button X:0 Y:6 @@ -169,7 +169,7 @@ Container@SERVER_LOBBY: Height:14 Visible:false Children: - ColorBlock@PING_COLOR: + ColorBlock@LATENCY_COLOR: X:2 Y:2 Width:PARENT_RIGHT-4 @@ -263,7 +263,7 @@ Container@SERVER_LOBBY: ImageName:admin X:2 Visible:false - Background@PING_BLOCK: + Background@LATENCY: Background:button X:0 Y:6 @@ -271,7 +271,7 @@ Container@SERVER_LOBBY: Height:14 Visible:false Children: - ColorBlock@PING_COLOR: + ColorBlock@LATENCY_COLOR: X:2 Y:2 Width:PARENT_RIGHT-4 @@ -319,7 +319,7 @@ Container@SERVER_LOBBY: ImageName:admin X:2 Visible:false - Background@PING_BLOCK: + Background@LATENCY: Background:button X:0 Y:6 @@ -327,7 +327,7 @@ Container@SERVER_LOBBY: Height:14 Visible:false Children: - ColorBlock@PING_COLOR: + ColorBlock@LATENCY_COLOR: X:2 Y:2 Width:PARENT_RIGHT-4 diff --git a/mods/d2k/chrome/lobby.yaml b/mods/d2k/chrome/lobby.yaml index 6abb365c69..d5645d4a28 100644 --- a/mods/d2k/chrome/lobby.yaml +++ b/mods/d2k/chrome/lobby.yaml @@ -54,14 +54,14 @@ Background@SERVER_LOBBY: ImageName:admin X:2 Visible:false - Container@PING_BLOCK: + Container@LATENCY: X:0 Y:6 Width:11 Height:14 Visible:false Children: - ColorBlock@PING_COLOR: + ColorBlock@LATENCY_COLOR: X:2 Y:2 Width:PARENT_RIGHT-4 @@ -140,14 +140,14 @@ Background@SERVER_LOBBY: ImageName:admin X:2 Visible:false - Container@PING_BLOCK: + Container@LATENCY: X:0 Y:6 Width:11 Height:14 Visible:false Children: - ColorBlock@PING_COLOR: + ColorBlock@LATENCY_COLOR: X:2 Y:2 Width:PARENT_RIGHT-4 @@ -240,14 +240,14 @@ Background@SERVER_LOBBY: ImageName:admin X:2 Visible:false - Container@PING_BLOCK: + Container@LATENCY: X:0 Y:6 Width:11 Height:14 Visible:false Children: - ColorBlock@PING_COLOR: + ColorBlock@LATENCY_COLOR: X:2 Y:2 Width:PARENT_RIGHT-4 @@ -302,14 +302,14 @@ Background@SERVER_LOBBY: ImageName:admin X:2 Visible:false - Container@PING_BLOCK: + Container@LATENCY: X:0 Y:6 Width:11 Height:14 Visible:false Children: - ColorBlock@PING_COLOR: + ColorBlock@LATENCY_COLOR: X:2 Y:2 Width:PARENT_RIGHT-4 diff --git a/mods/ra/chrome/lobby.yaml b/mods/ra/chrome/lobby.yaml index d087512504..f67699e16b 100644 --- a/mods/ra/chrome/lobby.yaml +++ b/mods/ra/chrome/lobby.yaml @@ -54,14 +54,14 @@ Background@SERVER_LOBBY: ImageName:admin X:2 Visible:false - Container@PING_BLOCK: + Container@LATENCY: X:0 Y:6 Width:11 Height:14 Visible:false Children: - ColorBlock@PING_COLOR: + ColorBlock@LATENCY_COLOR: X:2 Y:2 Width:PARENT_RIGHT-4 @@ -140,14 +140,14 @@ Background@SERVER_LOBBY: ImageName:admin X:2 Visible:false - Container@PING_BLOCK: + Container@LATENCY: X:0 Y:6 Width:11 Height:14 Visible:false Children: - ColorBlock@PING_COLOR: + ColorBlock@LATENCY_COLOR: X:2 Y:2 Width:PARENT_RIGHT-4 @@ -240,14 +240,14 @@ Background@SERVER_LOBBY: ImageName:admin X:2 Visible:false - Container@PING_BLOCK: + Container@LATENCY: X:0 Y:6 Width:11 Height:14 Visible:false Children: - ColorBlock@PING_COLOR: + ColorBlock@LATENCY_COLOR: X:2 Y:2 Width:PARENT_RIGHT-4 @@ -302,14 +302,14 @@ Background@SERVER_LOBBY: ImageName:admin X:2 Visible:false - Container@PING_BLOCK: + Container@LATENCY: X:0 Y:6 Width:11 Height:14 Visible:false Children: - ColorBlock@PING_COLOR: + ColorBlock@LATENCY_COLOR: X:2 Y:2 Width:PARENT_RIGHT-4 From d21875d353039b13052bf92efc5cbc85517ed9d0 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 25 Apr 2013 13:48:55 +1200 Subject: [PATCH 4/6] Adjust latency thresholds and add text description. --- OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs | 26 ++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs index 3fc94ad7f3..922a0df210 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs @@ -158,16 +158,28 @@ namespace OpenRA.Mods.RA.Widgets.Logic } } - static Color GetLatencyColor(Session.Client c) + static Color LatencyColor(int latency) { - if (c.Latency < 0) // Ping unknown + // Levels set relative to the default order lag of 3 net ticks (360ms) + // TODO: Adjust this once dynamic lag is implemented + if (latency < 0) return Color.Gray; - if (c.Latency > 720) // OrderLag > 6 - return Color.Red; - if (c.Latency > 360) // OrderLag > 3 + if (latency < 300) + return Color.LimeGreen; + if (latency < 600) return Color.Orange; + return Color.Red; + } - return Color.LimeGreen; + static string LatencyDescription(int latency) + { + if (latency < 0) + return "Unknown"; + if (latency < 300) + return "Good"; + if (latency < 600) + return "Moderate"; + return "Poor"; } public static void SetupClientWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, bool visible) @@ -177,7 +189,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic block.IsVisible = () => visible; if (visible) - block.Get("LATENCY_COLOR").GetColor = () => GetLatencyColor(c); + block.Get("LATENCY_COLOR").GetColor = () => LatencyColor(c.Latency); } public static void SetupEditableNameWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager) From 91115d5ba30942a858f6cdf313b4e99f2a080f09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Tue, 12 Mar 2013 08:13:44 +0100 Subject: [PATCH 5/6] save client IpAddress for later --- OpenRA.Game/Network/Session.cs | 1 + OpenRA.Game/Server/Server.cs | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Network/Session.cs b/OpenRA.Game/Network/Session.cs index 7f7835cb56..7896ced537 100644 --- a/OpenRA.Game/Network/Session.cs +++ b/OpenRA.Game/Network/Session.cs @@ -53,6 +53,7 @@ namespace OpenRA.Network public string Country; public int SpawnPoint; public string Name; + public string IpAddress; public ClientState State; public int Team; public string Slot; // slot ID, or null for observer diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index 3f3e4af03e..70176592d6 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -263,11 +263,13 @@ namespace OpenRA.Server return; } + client.IpAddress = ((IPEndPoint)newConn.socket.RemoteEndPoint).Address.ToString(); + // Check if IP is banned if (lobbyInfo.GlobalSettings.Ban != null) { - var remote_addr = ((IPEndPoint)newConn.socket.RemoteEndPoint).Address.ToString(); - if (lobbyInfo.GlobalSettings.Ban.Contains(remote_addr)) + + if (lobbyInfo.GlobalSettings.Ban.Contains(client.IpAddress)) { Console.WriteLine("Rejected connection from "+client.Name+"("+newConn.socket.RemoteEndPoint+"); Banned."); Log.Write("server", "Rejected connection from {0}; Banned.", From 45ff0645babfe1921ec1a90b9cf5521393d6eaaa Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 25 Apr 2013 13:34:18 +1200 Subject: [PATCH 6/6] Add client tooltips showing Admin/IP/Latency. --- OpenRA.Game/OpenRA.Game.csproj | 1 + .../Widgets/ClientTooltipRegionWidget.cs | 67 +++++++++++++++++++ OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 1 + .../Widgets/Logic/ClientTooltipLogic.cs | 64 ++++++++++++++++++ OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs | 8 ++- mods/cnc/chrome/lobby.yaml | 20 ++++++ mods/cnc/chrome/tooltips.yaml | 24 +++++++ mods/d2k/chrome/lobby.yaml | 20 ++++++ mods/d2k/chrome/tooltips.yaml | 26 ++++++- mods/ra/chrome/lobby.yaml | 20 ++++++ mods/ra/chrome/tooltips.yaml | 26 ++++++- 11 files changed, 273 insertions(+), 4 deletions(-) create mode 100644 OpenRA.Game/Widgets/ClientTooltipRegionWidget.cs create mode 100644 OpenRA.Mods.RA/Widgets/Logic/ClientTooltipLogic.cs diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 6cf977a09a..a6f99c8a59 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -223,6 +223,7 @@ + diff --git a/OpenRA.Game/Widgets/ClientTooltipRegionWidget.cs b/OpenRA.Game/Widgets/ClientTooltipRegionWidget.cs new file mode 100644 index 0000000000..d487ea51ae --- /dev/null +++ b/OpenRA.Game/Widgets/ClientTooltipRegionWidget.cs @@ -0,0 +1,67 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Threading; +using OpenRA.FileFormats; +using OpenRA.Graphics; +using OpenRA.Network; + +namespace OpenRA.Widgets +{ + public class ClientTooltipRegionWidget : Widget + { + public readonly string Template; + public readonly string TooltipContainer; + Lazy tooltipContainer; + OrderManager orderManager; + int clientIndex; + + public ClientTooltipRegionWidget() : base() + { + tooltipContainer = Lazy.New(() => Ui.Root.Get(TooltipContainer)); + } + + protected ClientTooltipRegionWidget(ClientTooltipRegionWidget other) + : base(other) + { + Template = other.Template; + TooltipContainer = other.TooltipContainer; + tooltipContainer = Lazy.New(() => Ui.Root.Get(TooltipContainer)); + orderManager = other.orderManager; + clientIndex = other.clientIndex; + } + + public override Widget Clone() { return new ClientTooltipRegionWidget(this); } + + public void Bind(OrderManager orderManager, int clientIndex) + { + this.orderManager = orderManager; + this.clientIndex = clientIndex; + } + + public override void MouseEntered() + { + if (TooltipContainer == null) + return; + tooltipContainer.Value.SetTooltip(Template, new WidgetArgs() {{"orderManager", orderManager}, {"clientIndex", clientIndex}}); + } + + public override void MouseExited() + { + if (TooltipContainer == null) + return; + tooltipContainer.Value.RemoveTooltip(); + } + } +} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 328a098d0b..d19315ef96 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -431,6 +431,7 @@ + diff --git a/OpenRA.Mods.RA/Widgets/Logic/ClientTooltipLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ClientTooltipLogic.cs new file mode 100644 index 0000000000..847704bf92 --- /dev/null +++ b/OpenRA.Mods.RA/Widgets/Logic/ClientTooltipLogic.cs @@ -0,0 +1,64 @@ +#region Copyright & License Information +/* + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Drawing; +using System.Linq; +using OpenRA.Widgets; +using OpenRA.Network; + +namespace OpenRA.Mods.RA.Widgets.Logic +{ + public class ClientTooltipLogic + { + [ObjectCreator.UseCtor] + public ClientTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, OrderManager orderManager, int clientIndex) + { + var admin = widget.Get("ADMIN"); + var adminFont = Game.Renderer.Fonts[admin.Font]; + + var latency = widget.Get("LATENCY"); + var latencyFont = Game.Renderer.Fonts[latency.Font]; + + var ip = widget.Get("IP"); + var ipFont = Game.Renderer.Fonts[ip.Font]; + + var ipOffset = ip.Bounds.Y; + var latencyOffset = latency.Bounds.Y; + var tooltipHeight = widget.Bounds.Height; + + var margin = widget.Bounds.Width; + tooltipContainer.BeforeRender = () => + { + var width = Math.Max(adminFont.Measure(admin.GetText()).X, Math.Max(ipFont.Measure(ip.GetText()).X, latencyFont.Measure(latency.GetText()).X)); + widget.Bounds.Width = width + 2*margin; + latency.Bounds.Width = widget.Bounds.Width; + ip.Bounds.Width = widget.Bounds.Width; + admin.Bounds.Width = widget.Bounds.Width; + + ip.Bounds.Y = ipOffset; + latency.Bounds.Y = latencyOffset; + widget.Bounds.Height = tooltipHeight; + + if (admin.IsVisible()) + { + ip.Bounds.Y += admin.Bounds.Height; + latency.Bounds.Y += admin.Bounds.Height; + widget.Bounds.Height += admin.Bounds.Height; + } + }; + + admin.IsVisible = () => orderManager.LobbyInfo.ClientWithIndex(clientIndex).IsAdmin; + latency.GetText = () => "Latency: {0}".F(LobbyUtils.LatencyDescription(orderManager.LobbyInfo.ClientWithIndex(clientIndex).Latency)); + ip.GetText = () => orderManager.LobbyInfo.ClientWithIndex(clientIndex).IpAddress; + } + } +} + diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs index 922a0df210..09659d261e 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs @@ -158,7 +158,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic } } - static Color LatencyColor(int latency) + public static Color LatencyColor(int latency) { // Levels set relative to the default order lag of 3 net ticks (360ms) // TODO: Adjust this once dynamic lag is implemented @@ -171,7 +171,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic return Color.Red; } - static string LatencyDescription(int latency) + public static string LatencyDescription(int latency) { if (latency < 0) return "Unknown"; @@ -190,6 +190,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic if (visible) block.Get("LATENCY_COLOR").GetColor = () => LatencyColor(c.Latency); + + var tooltip = parent.Get("CLIENT_REGION"); + tooltip.IsVisible = () => visible; + tooltip.Bind(orderManager, c.Index); } public static void SetupEditableNameWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager) diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index bf1e029182..6c64204219 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -86,6 +86,11 @@ Container@SERVER_LOBBY: Y:2 Width:PARENT_RIGHT-4 Height:PARENT_BOTTOM-4 + ClientTooltipRegion@CLIENT_REGION: + TooltipContainer:TOOLTIP_CONTAINER + Template:CLIENT_TOOLTIP + Width:11 + Height:25 TextField@NAME: Text:Name X:15 @@ -174,6 +179,11 @@ Container@SERVER_LOBBY: Y:2 Width:PARENT_RIGHT-4 Height:PARENT_BOTTOM-4 + ClientTooltipRegion@CLIENT_REGION: + TooltipContainer:TOOLTIP_CONTAINER + Template:CLIENT_TOOLTIP + Width:11 + Height:25 Label@NAME: Text:Name Width:185 @@ -276,6 +286,11 @@ Container@SERVER_LOBBY: Y:2 Width:PARENT_RIGHT-4 Height:PARENT_BOTTOM-4 + ClientTooltipRegion@CLIENT_REGION: + TooltipContainer:TOOLTIP_CONTAINER + Template:CLIENT_TOOLTIP + Width:11 + Height:25 TextField@NAME: Text:Name X:15 @@ -332,6 +347,11 @@ Container@SERVER_LOBBY: Y:2 Width:PARENT_RIGHT-4 Height:PARENT_BOTTOM-4 + ClientTooltipRegion@CLIENT_REGION: + TooltipContainer:TOOLTIP_CONTAINER + Template:CLIENT_TOOLTIP + Width:11 + Height:25 Label@NAME: Text:Name Width:185 diff --git a/mods/cnc/chrome/tooltips.yaml b/mods/cnc/chrome/tooltips.yaml index 49644b4746..7393067200 100644 --- a/mods/cnc/chrome/tooltips.yaml +++ b/mods/cnc/chrome/tooltips.yaml @@ -123,3 +123,27 @@ Background@SPAWN_TOOLTIP: Height:15 Font:TinyBold Align:center + +Background@CLIENT_TOOLTIP: + Logic:ClientTooltipLogic + Background:panel-black + Height:35 + Width:5 + Children: + Label@ADMIN: + Y:2 + Height:18 + Font:Bold + Text:Game Admin + Align:Center + Label@IP: + Y:5 + Width:5 + Height:10 + Font:TinyBold + Align:Center + Label@LATENCY: + Y:17 + Height:10 + Font:TinyBold + Align:Center diff --git a/mods/d2k/chrome/lobby.yaml b/mods/d2k/chrome/lobby.yaml index d5645d4a28..352a73a78f 100644 --- a/mods/d2k/chrome/lobby.yaml +++ b/mods/d2k/chrome/lobby.yaml @@ -66,6 +66,11 @@ Background@SERVER_LOBBY: Y:2 Width:PARENT_RIGHT-4 Height:PARENT_BOTTOM-4 + ClientTooltipRegion@CLIENT_REGION: + TooltipContainer:TOOLTIP_CONTAINER + Template:CLIENT_TOOLTIP + Width:11 + Height:25 TextField@NAME: Text:Name X:15 @@ -152,6 +157,11 @@ Background@SERVER_LOBBY: Y:2 Width:PARENT_RIGHT-4 Height:PARENT_BOTTOM-4 + ClientTooltipRegion@CLIENT_REGION: + TooltipContainer:TOOLTIP_CONTAINER + Template:CLIENT_TOOLTIP + Width:11 + Height:25 Label@NAME: Text:Name Width:130 @@ -252,6 +262,11 @@ Background@SERVER_LOBBY: Y:2 Width:PARENT_RIGHT-4 Height:PARENT_BOTTOM-4 + ClientTooltipRegion@CLIENT_REGION: + TooltipContainer:TOOLTIP_CONTAINER + Template:CLIENT_TOOLTIP + Width:11 + Height:25 TextField@NAME: Text:Name X:15 @@ -314,6 +329,11 @@ Background@SERVER_LOBBY: Y:2 Width:PARENT_RIGHT-4 Height:PARENT_BOTTOM-4 + ClientTooltipRegion@CLIENT_REGION: + TooltipContainer:TOOLTIP_CONTAINER + Template:CLIENT_TOOLTIP + Width:11 + Height:25 Label@NAME: Text:Name Width:130 diff --git a/mods/d2k/chrome/tooltips.yaml b/mods/d2k/chrome/tooltips.yaml index c8b88119c5..25ee4544b7 100644 --- a/mods/d2k/chrome/tooltips.yaml +++ b/mods/d2k/chrome/tooltips.yaml @@ -20,4 +20,28 @@ Background@SPAWN_TOOLTIP: Y:28 Height:15 Font:TinyBold - Align:center \ No newline at end of file + Align:center + +Background@CLIENT_TOOLTIP: + Logic:ClientTooltipLogic + Background:dialog3 + Height:39 + Width:7 + Children: + Label@ADMIN: + Y:4 + Height:18 + Font:Bold + Text:Game Admin + Align:Center + Label@IP: + Y:7 + Width:5 + Height:10 + Font:TinyBold + Align:Center + Label@LATENCY: + Y:19 + Height:10 + Font:TinyBold + Align:Center diff --git a/mods/ra/chrome/lobby.yaml b/mods/ra/chrome/lobby.yaml index f67699e16b..22115f69b3 100644 --- a/mods/ra/chrome/lobby.yaml +++ b/mods/ra/chrome/lobby.yaml @@ -66,6 +66,11 @@ Background@SERVER_LOBBY: Y:2 Width:PARENT_RIGHT-4 Height:PARENT_BOTTOM-4 + ClientTooltipRegion@CLIENT_REGION: + TooltipContainer:TOOLTIP_CONTAINER + Template:CLIENT_TOOLTIP + Width:11 + Height:25 TextField@NAME: Text:Name X:15 @@ -152,6 +157,11 @@ Background@SERVER_LOBBY: Y:2 Width:PARENT_RIGHT-4 Height:PARENT_BOTTOM-4 + ClientTooltipRegion@CLIENT_REGION: + TooltipContainer:TOOLTIP_CONTAINER + Template:CLIENT_TOOLTIP + Width:11 + Height:25 Label@NAME: Text:Name Width:130 @@ -252,6 +262,11 @@ Background@SERVER_LOBBY: Y:2 Width:PARENT_RIGHT-4 Height:PARENT_BOTTOM-4 + ClientTooltipRegion@CLIENT_REGION: + TooltipContainer:TOOLTIP_CONTAINER + Template:CLIENT_TOOLTIP + Width:11 + Height:25 TextField@NAME: Text:Name X:15 @@ -314,6 +329,11 @@ Background@SERVER_LOBBY: Y:2 Width:PARENT_RIGHT-4 Height:PARENT_BOTTOM-4 + ClientTooltipRegion@CLIENT_REGION: + TooltipContainer:TOOLTIP_CONTAINER + Template:CLIENT_TOOLTIP + Width:11 + Height:25 Label@NAME: Text:Name Width:130 diff --git a/mods/ra/chrome/tooltips.yaml b/mods/ra/chrome/tooltips.yaml index 03904d5d69..2d948ffef7 100644 --- a/mods/ra/chrome/tooltips.yaml +++ b/mods/ra/chrome/tooltips.yaml @@ -20,4 +20,28 @@ Background@SPAWN_TOOLTIP: Y:23 Height:15 Font:TinyBold - Align:center \ No newline at end of file + Align:center + +Background@CLIENT_TOOLTIP: + Logic:ClientTooltipLogic + Background:dialog4 + Height:39 + Width:7 + Children: + Label@ADMIN: + Y:4 + Height:18 + Font:Bold + Text:Game Admin + Align:Center + Label@IP: + Y:7 + Width:5 + Height:10 + Font:TinyBold + Align:Center + Label@LATENCY: + Y:19 + Height:10 + Font:TinyBold + Align:Center