diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 17b0f70ff7..a63aa03037 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -68,8 +68,7 @@ namespace OpenRA if (!world.GameHasStarted) return; if (world.LocalPlayer == null) return; - if (worldTooltipTicks < worldTooltipDelay) - ++worldTooltipTicks; + ++ticksSinceLastMove; rootWidget.Tick(world); } @@ -82,37 +81,6 @@ namespace OpenRA var typingArea = new Rectangle(240, Game.viewport.Height - 30, Game.viewport.Width - 420, 30); var chatLogArea = new Rectangle(240, Game.viewport.Height - 500, Game.viewport.Width - 420, 500 - 40); DrawChat(typingArea, chatLogArea); - - DrawWorldTooltip(world); - } - - void DrawWorldTooltip(World world) - { - if (worldTooltipTicks < worldTooltipDelay || world == null || world.LocalPlayer == null) - return; - - var actor = world.FindUnitsAtMouse(lastMousePos).FirstOrDefault(); - if (actor == null) return; - - var text = actor.Info.Traits.Contains() ? actor.Info.Traits.Get().Description : actor.Info.Name; - var text2 = (actor.Owner == world.LocalPlayer) - ? "" : (actor.Owner == world.NeutralPlayer ? "{0}" : "{0} ({1})").F(actor.Owner.PlayerName, world.LocalPlayer.Stances[actor.Owner]); - - var sz = renderer.BoldFont.Measure(text); - var sz2 = renderer.RegularFont.Measure(text2); - - sz.X = Math.Max(sz.X, sz2.X); - - if (text2 != "") sz.Y += sz2.Y + 2; - - sz.X += 20; - sz.Y += 24; - - WidgetUtils.DrawPanel("dialog4", Rectangle.FromLTRB( - lastMousePos.X + 20, lastMousePos.Y + 20, lastMousePos.X + sz.X + 20, lastMousePos.Y + sz.Y + 20)); - - renderer.BoldFont.DrawText(text, new float2(lastMousePos.X + 30, lastMousePos.Y + 30), Color.White); - renderer.RegularFont.DrawText(text2, new float2(lastMousePos.X + 30, lastMousePos.Y + 50), Color.White); } void AddUiButton(int2 pos, string text, Action a) @@ -385,9 +353,7 @@ namespace OpenRA renderer.RegularFont.DrawText(line.c, p + new int2(size.X + 10, 0), Color.White); } - const int worldTooltipDelay = 10; /* ticks */ - - public int worldTooltipTicks = 0; + public int ticksSinceLastMove = 0; public int2 lastMousePos; public bool HandleInput(World world, MouseInput mi) { @@ -400,7 +366,7 @@ namespace OpenRA if (mi.Event == MouseInputEvent.Move) { lastMousePos = mi.Location; - worldTooltipTicks = 0; + ticksSinceLastMove = 0; } var action = buttons.Where(a => a.First.Contains(mi.Location.ToPoint())) diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index e9cee78f9c..acaebe1312 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -277,6 +277,7 @@ + diff --git a/OpenRA.Game/Widgets/WorldTooltipWidget.cs b/OpenRA.Game/Widgets/WorldTooltipWidget.cs new file mode 100644 index 0000000000..bbfdbd9e9a --- /dev/null +++ b/OpenRA.Game/Widgets/WorldTooltipWidget.cs @@ -0,0 +1,50 @@ +using System; +using System.Drawing; +using System.Linq; +using OpenRA.Traits; + +namespace OpenRA.Widgets +{ + public class WorldTooltipWidget : Widget + { + const int worldTooltipDelay = 10; /* ticks */ + + public override void Draw(World world) + { + if (Game.chrome.ticksSinceLastMove < worldTooltipDelay || world == null || world.LocalPlayer == null) + return; + + var actor = world.FindUnitsAtMouse(Game.chrome.lastMousePos).FirstOrDefault(); + if (actor == null) return; + + var text = actor.Info.Traits.Contains() + ? actor.Info.Traits.Get().Description + : actor.Info.Name; + var text2 = (actor.Owner == world.LocalPlayer) + ? "" : (actor.Owner == world.NeutralPlayer ? "{0}" : "{0} ({1})").F(actor.Owner.PlayerName, world.LocalPlayer.Stances[actor.Owner]); + + var renderer = Game.chrome.renderer; + + var sz = renderer.BoldFont.Measure(text); + var sz2 = renderer.RegularFont.Measure(text2); + + sz.X = Math.Max(sz.X, sz2.X); + + if (text2 != "") sz.Y += sz2.Y + 2; + + sz.X += 20; + sz.Y += 24; + + WidgetUtils.DrawPanel("dialog4", Rectangle.FromLTRB( + Game.chrome.lastMousePos.X + 20, Game.chrome.lastMousePos.Y + 20, + Game.chrome.lastMousePos.X + sz.X + 20, Game.chrome.lastMousePos.Y + sz.Y + 20)); + + renderer.BoldFont.DrawText(text, + new float2(Game.chrome.lastMousePos.X + 30, Game.chrome.lastMousePos.Y + 30), Color.White); + renderer.RegularFont.DrawText(text2, + new float2(Game.chrome.lastMousePos.X + 30, Game.chrome.lastMousePos.Y + 50), Color.White); + + renderer.RgbaSpriteRenderer.Flush(); + } + } +} diff --git a/mods/cnc/menus.yaml b/mods/cnc/menus.yaml index 98ba320107..ad3a8caaea 100644 --- a/mods/cnc/menus.yaml +++ b/mods/cnc/menus.yaml @@ -343,10 +343,10 @@ Container: Width:160 Height:25 Text:Diplomacy + WorldTooltip@INGAME_WORLD_TOOLTIP: + Id:INGAME_WORLD_TOOLTIP RadarBin@INGAME_RADAR_BIN: Id:INGAME_RADAR_BIN - X:WINDOW_RIGHT - WIDTH - Y:0 MoneyBin@INGAME_MONEY_BIN: Id:INGAME_MONEY_BIN X:WINDOW_RIGHT - WIDTH diff --git a/mods/ra/menus.yaml b/mods/ra/menus.yaml index 98ba320107..ad3a8caaea 100644 --- a/mods/ra/menus.yaml +++ b/mods/ra/menus.yaml @@ -343,10 +343,10 @@ Container: Width:160 Height:25 Text:Diplomacy + WorldTooltip@INGAME_WORLD_TOOLTIP: + Id:INGAME_WORLD_TOOLTIP RadarBin@INGAME_RADAR_BIN: Id:INGAME_RADAR_BIN - X:WINDOW_RIGHT - WIDTH - Y:0 MoneyBin@INGAME_MONEY_BIN: Id:INGAME_MONEY_BIN X:WINDOW_RIGHT - WIDTH