From 3ac0ca6a656b224c024ddf54b7eb7723b5c443d0 Mon Sep 17 00:00:00 2001 From: alzeih Date: Mon, 14 Jun 2010 00:18:36 +1200 Subject: [PATCH] BuildPalette tooltips show build time (+ in red if in low power) --- OpenRA.Game/Traits/Player/ProductionQueue.cs | 19 +++++++++++++++---- OpenRA.Game/Widgets/BuildPaletteWidget.cs | 9 +++++++-- OpenRA.Game/Widgets/SpecialPowerBinWidget.cs | 12 ++---------- OpenRA.Game/WorldUtils.cs | 8 ++++++++ 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/OpenRA.Game/Traits/Player/ProductionQueue.cs b/OpenRA.Game/Traits/Player/ProductionQueue.cs index 2456b9b7ab..e3874ac654 100644 --- a/OpenRA.Game/Traits/Player/ProductionQueue.cs +++ b/OpenRA.Game/Traits/Player/ProductionQueue.cs @@ -65,10 +65,7 @@ namespace OpenRA.Traits { var unit = Rules.Info[order.TargetString]; var ui = unit.Traits.Get(); - var time = ui.Cost - * self.Owner.PlayerActor.Info.Traits.Get().BuildSpeed /* todo: country-specific build speed bonus */ - * (25 * 60) /* frames per min */ /* todo: build acceleration, if we do that */ - / 1000; + var time = GetBuildTime(self, order.TargetString); if (!Rules.TechTree.BuildableItems(order.Player, unit.Category).Contains(order.TargetString)) return; /* you can't build that!! */ @@ -107,6 +104,20 @@ namespace OpenRA.Traits } } } + + public static int GetBuildTime(Actor self, String unitString) + { + var unit = Rules.Info[unitString]; + if (unit == null || ! unit.Traits.Contains()) + return 0; + + var ui = unit.Traits.Get(); + var time = ui.Cost + * self.Owner.PlayerActor.Info.Traits.Get().BuildSpeed /* todo: country-specific build speed bonus */ + * (25 * 60) /* frames per min */ /* todo: build acceleration, if we do that */ + / 1000; + return (int) time; + } // Key: Production category. // TODO: sync this diff --git a/OpenRA.Game/Widgets/BuildPaletteWidget.cs b/OpenRA.Game/Widgets/BuildPaletteWidget.cs index 7c0d12d77a..ff92712470 100644 --- a/OpenRA.Game/Widgets/BuildPaletteWidget.cs +++ b/OpenRA.Game/Widgets/BuildPaletteWidget.cs @@ -473,7 +473,7 @@ namespace OpenRA.Widgets var longDescSize = Game.chrome.renderer.RegularFont.Measure(buildable.LongDesc.Replace("\\n", "\n")).Y; if (!canBuildThis) longDescSize += 8; - WidgetUtils.DrawPanel("dialog4", new Rectangle(Game.viewport.Width - 300, pos.Y, 300, longDescSize + 50)); + WidgetUtils.DrawPanel("dialog4", new Rectangle(Game.viewport.Width - 300, pos.Y, 300, longDescSize + 65)); Game.chrome.renderer.BoldFont.DrawText( buildable.Description + ((buildable.Hotkey != null)? " ({0})".F(buildable.Hotkey.ToUpper()) : ""), @@ -481,6 +481,11 @@ namespace OpenRA.Widgets DrawRightAligned("${0}".F(buildable.Cost), pos + new int2(-5, 5), (world.LocalPlayer.PlayerActor.traits.Get().DisplayCash >= buildable.Cost)? Color.White: Color.Red); + + var lowpower = world.LocalPlayer.PlayerActor.traits.Get().GetPowerState() != PowerState.Normal; + var time = ProductionQueue.GetBuildTime(world.LocalPlayer.PlayerActor, info.Name) + * ((lowpower)? world.LocalPlayer.PlayerActor.Info.Traits.Get().LowPowerSlowdown : 1); + DrawRightAligned(WorldUtils.FormatTime(time), pos + new int2(-5, 35), (lowpower)? Color.Red: Color.White); var bi = info.Traits.GetOrDefault(); var playerres = world.LocalPlayer.PlayerActor.traits.Get(); @@ -488,7 +493,7 @@ namespace OpenRA.Widgets DrawRightAligned("{1}{0}".F(bi.Power, bi.Power > 0 ? "+" : ""), pos + new int2(-5, 20), ((playerres.PowerProvided - playerres.PowerDrained) >= -bi.Power || bi.Power > 0)? Color.White: Color.Red); - p += new int2(5, 20); + p += new int2(5, 35); if (!canBuildThis) { var prereqs = buildable.Prerequisites diff --git a/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs b/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs index 5f3c39e682..0be86ecd94 100644 --- a/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs +++ b/OpenRA.Game/Widgets/SpecialPowerBinWidget.cs @@ -134,8 +134,8 @@ namespace OpenRA.Widgets Game.chrome.renderer.BoldFont.DrawText(sp.Info.Description, pos, Color.White); pos += new int2(0,20); - Game.chrome.renderer.BoldFont.DrawText(FormatTime(sp.RemainingTime).ToString(), pos, Color.White); - Game.chrome.renderer.BoldFont.DrawText("/ {0}".F(FormatTime(sp.TotalTime)), pos + new int2(45,0), Color.White); + Game.chrome.renderer.BoldFont.DrawText(WorldUtils.FormatTime(sp.RemainingTime).ToString(), pos, Color.White); + Game.chrome.renderer.BoldFont.DrawText("/ {0}".F(WorldUtils.FormatTime(sp.TotalTime)), pos + new int2(45,0), Color.White); if (sp.Info.LongDesc != null) { @@ -171,13 +171,5 @@ namespace OpenRA.Widgets { return mi => { if (mi.Button == MouseButton.Left) sp.Activate(); }; } - - string FormatTime(int ticks) - { - var seconds = ticks / 25; - var minutes = seconds / 60; - - return "{0:D2}:{1:D2}".F(minutes, seconds % 60); - } } } \ No newline at end of file diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index b1228af99c..40a5aecd44 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -241,5 +241,13 @@ namespace OpenRA { return world.WorldActor.Info.Traits.WithInterface().ToList(); } + + public static string FormatTime(int ticks) + { + var seconds = ticks / 25; + var minutes = seconds / 60; + + return "{0:D2}:{1:D2}".F(minutes, seconds % 60); + } } }