BuildPalette tooltips show build time (+ in red if in low power)

This commit is contained in:
alzeih
2010-06-14 00:18:36 +12:00
parent fbeadb9869
commit 3ac0ca6a65
4 changed files with 32 additions and 16 deletions

View File

@@ -65,10 +65,7 @@ namespace OpenRA.Traits
{ {
var unit = Rules.Info[order.TargetString]; var unit = Rules.Info[order.TargetString];
var ui = unit.Traits.Get<BuildableInfo>(); var ui = unit.Traits.Get<BuildableInfo>();
var time = ui.Cost var time = GetBuildTime(self, order.TargetString);
* self.Owner.PlayerActor.Info.Traits.Get<ProductionQueueInfo>().BuildSpeed /* todo: country-specific build speed bonus */
* (25 * 60) /* frames per min */ /* todo: build acceleration, if we do that */
/ 1000;
if (!Rules.TechTree.BuildableItems(order.Player, unit.Category).Contains(order.TargetString)) if (!Rules.TechTree.BuildableItems(order.Player, unit.Category).Contains(order.TargetString))
return; /* you can't build that!! */ return; /* you can't build that!! */
@@ -108,6 +105,20 @@ namespace OpenRA.Traits
} }
} }
public static int GetBuildTime(Actor self, String unitString)
{
var unit = Rules.Info[unitString];
if (unit == null || ! unit.Traits.Contains<BuildableInfo>())
return 0;
var ui = unit.Traits.Get<BuildableInfo>();
var time = ui.Cost
* self.Owner.PlayerActor.Info.Traits.Get<ProductionQueueInfo>().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. // Key: Production category.
// TODO: sync this // TODO: sync this
readonly Cache<string, List<ProductionItem>> production readonly Cache<string, List<ProductionItem>> production

View File

@@ -473,7 +473,7 @@ namespace OpenRA.Widgets
var longDescSize = Game.chrome.renderer.RegularFont.Measure(buildable.LongDesc.Replace("\\n", "\n")).Y; var longDescSize = Game.chrome.renderer.RegularFont.Measure(buildable.LongDesc.Replace("\\n", "\n")).Y;
if (!canBuildThis) longDescSize += 8; 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( Game.chrome.renderer.BoldFont.DrawText(
buildable.Description + ((buildable.Hotkey != null)? " ({0})".F(buildable.Hotkey.ToUpper()) : ""), buildable.Description + ((buildable.Hotkey != null)? " ({0})".F(buildable.Hotkey.ToUpper()) : ""),
@@ -482,13 +482,18 @@ namespace OpenRA.Widgets
DrawRightAligned("${0}".F(buildable.Cost), pos + new int2(-5, 5), DrawRightAligned("${0}".F(buildable.Cost), pos + new int2(-5, 5),
(world.LocalPlayer.PlayerActor.traits.Get<PlayerResources>().DisplayCash >= buildable.Cost)? Color.White: Color.Red); (world.LocalPlayer.PlayerActor.traits.Get<PlayerResources>().DisplayCash >= buildable.Cost)? Color.White: Color.Red);
var lowpower = world.LocalPlayer.PlayerActor.traits.Get<PlayerResources>().GetPowerState() != PowerState.Normal;
var time = ProductionQueue.GetBuildTime(world.LocalPlayer.PlayerActor, info.Name)
* ((lowpower)? world.LocalPlayer.PlayerActor.Info.Traits.Get<ProductionQueueInfo>().LowPowerSlowdown : 1);
DrawRightAligned(WorldUtils.FormatTime(time), pos + new int2(-5, 35), (lowpower)? Color.Red: Color.White);
var bi = info.Traits.GetOrDefault<BuildingInfo>(); var bi = info.Traits.GetOrDefault<BuildingInfo>();
var playerres = world.LocalPlayer.PlayerActor.traits.Get<PlayerResources>(); var playerres = world.LocalPlayer.PlayerActor.traits.Get<PlayerResources>();
if (bi != null) if (bi != null)
DrawRightAligned("{1}{0}".F(bi.Power, bi.Power > 0 ? "+" : ""), pos + new int2(-5, 20), 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); ((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) if (!canBuildThis)
{ {
var prereqs = buildable.Prerequisites var prereqs = buildable.Prerequisites

View File

@@ -134,8 +134,8 @@ namespace OpenRA.Widgets
Game.chrome.renderer.BoldFont.DrawText(sp.Info.Description, pos, Color.White); Game.chrome.renderer.BoldFont.DrawText(sp.Info.Description, pos, Color.White);
pos += new int2(0,20); pos += new int2(0,20);
Game.chrome.renderer.BoldFont.DrawText(FormatTime(sp.RemainingTime).ToString(), pos, Color.White); Game.chrome.renderer.BoldFont.DrawText(WorldUtils.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("/ {0}".F(WorldUtils.FormatTime(sp.TotalTime)), pos + new int2(45,0), Color.White);
if (sp.Info.LongDesc != null) if (sp.Info.LongDesc != null)
{ {
@@ -171,13 +171,5 @@ namespace OpenRA.Widgets
{ {
return mi => { if (mi.Button == MouseButton.Left) sp.Activate(); }; 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);
}
} }
} }

View File

@@ -241,5 +241,13 @@ namespace OpenRA
{ {
return world.WorldActor.Info.Traits.WithInterface<PlayerColorPaletteInfo>().ToList(); return world.WorldActor.Info.Traits.WithInterface<PlayerColorPaletteInfo>().ToList();
} }
public static string FormatTime(int ticks)
{
var seconds = ticks / 25;
var minutes = seconds / 60;
return "{0:D2}:{1:D2}".F(minutes, seconds % 60);
}
} }
} }