diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 8e9f4ca3c8..9a36f2d501 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -127,6 +127,9 @@ namespace OpenRA { if (!world.GameHasStarted) return; if (world.LocalPlayer == null) return; + + if (worldTooltipTicks < worldTooltipDelay) + ++worldTooltipTicks; TickPaletteAnimation(); TickRadarAnimation(); @@ -163,6 +166,32 @@ namespace OpenRA int paletteHeight = DrawBuildPalette(world, currentTab); DrawBuildTabs(world, paletteHeight); DrawChat(); + + if (worldTooltipTicks >= worldTooltipDelay && world != null && world.LocalPlayer != null) + { + 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); + } } public void DrawDialog(string text) @@ -986,6 +1015,9 @@ namespace OpenRA } } + const int worldTooltipDelay = 10; /* ticks */ + + public int worldTooltipTicks = 0; public int2 lastMousePos; public bool HandleInput(World world, MouseInput mi) { @@ -994,9 +1026,12 @@ namespace OpenRA if (rootWidget.HandleInput(mi)) return true; - + if (mi.Event == MouseInputEvent.Move) + { lastMousePos = mi.Location; + worldTooltipTicks = 0; + } var action = buttons.Where(a => a.First.Contains(mi.Location.ToPoint())) .Select(a => a.Second).FirstOrDefault();