Show remaining build time, remove unnecessary calculations from production palette
This commit is contained in:
@@ -26,6 +26,7 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
{
|
{
|
||||||
public string Name;
|
public string Name;
|
||||||
public Sprite Sprite;
|
public Sprite Sprite;
|
||||||
|
public float2 Pos;
|
||||||
public List<ProductionItem> Queued;
|
public List<ProductionItem> Queued;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +60,8 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
Rectangle eventBounds = Rectangle.Empty;
|
Rectangle eventBounds = Rectangle.Empty;
|
||||||
readonly WorldRenderer worldRenderer;
|
readonly WorldRenderer worldRenderer;
|
||||||
readonly World world;
|
readonly World world;
|
||||||
|
readonly SpriteFont overlayFont;
|
||||||
|
readonly float2 holdOffset, readyOffset, timeOffset, queuedOffset;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public ProductionPaletteWidget([ObjectCreator.Param] World world,
|
public ProductionPaletteWidget([ObjectCreator.Param] World world,
|
||||||
@@ -79,6 +82,12 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
u => u.Name,
|
u => u.Name,
|
||||||
u => Game.modData.SpriteLoader.LoadAllSprites(
|
u => Game.modData.SpriteLoader.LoadAllSprites(
|
||||||
u.Traits.Get<TooltipInfo>().Icon ?? (u.Name + "icon"))[0]);
|
u.Traits.Get<TooltipInfo>().Icon ?? (u.Name + "icon"))[0]);
|
||||||
|
|
||||||
|
overlayFont = Game.Renderer.Fonts["TinyBold"];
|
||||||
|
holdOffset = new float2(32,24) - overlayFont.Measure("On Hold") / 2;
|
||||||
|
readyOffset = new float2(32,24) - overlayFont.Measure("Ready") / 2;
|
||||||
|
timeOffset = new float2(32,24) - overlayFont.Measure(WidgetUtils.FormatTime(0)) / 2;
|
||||||
|
queuedOffset = new float2(4,2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Tick()
|
public override void Tick()
|
||||||
@@ -185,9 +194,10 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
var rect = new Rectangle(rb.X + x * 64 + 1, rb.Y + y * 48 + 1, 64, 48);
|
var rect = new Rectangle(rb.X + x * 64 + 1, rb.Y + y * 48 + 1, 64, 48);
|
||||||
var pi = new ProductionIcon()
|
var pi = new ProductionIcon()
|
||||||
{
|
{
|
||||||
|
Name = item.Name,
|
||||||
Sprite = iconSprites[item.Name],
|
Sprite = iconSprites[item.Name],
|
||||||
|
Pos = new float2(rect.Location),
|
||||||
Queued = CurrentQueue.AllQueued().Where(a => a.Item == item.Name).ToList(),
|
Queued = CurrentQueue.AllQueued().Where(a => a.Item == item.Name).ToList(),
|
||||||
Name = item.Name
|
|
||||||
};
|
};
|
||||||
Icons.Add(rect, pi);
|
Icons.Add(rect, pi);
|
||||||
i++;
|
i++;
|
||||||
@@ -204,22 +214,14 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
var isBuildingSomething = CurrentQueue.CurrentItem() != null;
|
var isBuildingSomething = CurrentQueue.CurrentItem() != null;
|
||||||
var buildableItems = CurrentQueue.BuildableItems().OrderBy(a => a.Traits.Get<BuildableInfo>().BuildPaletteOrder);
|
var buildableItems = CurrentQueue.BuildableItems().OrderBy(a => a.Traits.Get<BuildableInfo>().BuildPaletteOrder);
|
||||||
|
|
||||||
var overlayFont = Game.Renderer.Fonts["TinyBold"];
|
|
||||||
var holdOffset = new float2(32,24) - overlayFont.Measure("On Hold") / 2;
|
|
||||||
var readyOffset = new float2(32,24) - overlayFont.Measure("Ready") / 2;
|
|
||||||
var queuedOffset = new float2(4,2);
|
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
foreach (var kv in Icons)
|
foreach (var rect in Icons.Keys)
|
||||||
WidgetUtils.DrawPanel("panel-black", kv.Key.InflateBy(1,1,1,1));
|
WidgetUtils.DrawPanel("panel-black", rect.InflateBy(1,1,1,1));
|
||||||
|
|
||||||
// Icons
|
// Icons
|
||||||
foreach (var kv in Icons)
|
foreach (var icon in Icons.Values)
|
||||||
{
|
{
|
||||||
var rect = kv.Key;
|
WidgetUtils.DrawSHP(icon.Sprite, icon.Pos, worldRenderer);
|
||||||
var icon = kv.Value;
|
|
||||||
var drawPos = new float2(rect.Location);
|
|
||||||
WidgetUtils.DrawSHP(icon.Sprite, drawPos, worldRenderer);
|
|
||||||
|
|
||||||
// Build progress
|
// Build progress
|
||||||
if (icon.Queued.Count > 0)
|
if (icon.Queued.Count > 0)
|
||||||
@@ -229,32 +231,36 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
() => (first.TotalTime - first.RemainingTime)
|
() => (first.TotalTime - first.RemainingTime)
|
||||||
* (clock.CurrentSequence.Length - 1) / first.TotalTime);
|
* (clock.CurrentSequence.Length - 1) / first.TotalTime);
|
||||||
clock.Tick();
|
clock.Tick();
|
||||||
WidgetUtils.DrawSHP(clock.Image, drawPos, worldRenderer);
|
WidgetUtils.DrawSHP(clock.Image, icon.Pos, worldRenderer);
|
||||||
}
|
}
|
||||||
else if (isBuildingSomething || !buildableItems.Any(a => a.Name == icon.Name))
|
else if (isBuildingSomething || !buildableItems.Any(a => a.Name == icon.Name))
|
||||||
WidgetUtils.DrawSHP(cantBuild.Image, drawPos, worldRenderer);
|
WidgetUtils.DrawSHP(cantBuild.Image, icon.Pos, worldRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overlays
|
// Overlays
|
||||||
foreach (var kv in Icons)
|
foreach (var icon in Icons.Values)
|
||||||
{
|
{
|
||||||
var drawPos = new float2(kv.Key.Location);
|
var total = icon.Queued.Count;
|
||||||
var total = kv.Value.Queued.Count;
|
|
||||||
if (total > 0)
|
if (total > 0)
|
||||||
{
|
{
|
||||||
var first = kv.Value.Queued[0];
|
var first = icon.Queued[0];
|
||||||
|
var waiting = first != CurrentQueue.CurrentItem() && !first.Done;
|
||||||
if (first.Done)
|
if (first.Done)
|
||||||
overlayFont.DrawTextWithContrast("Ready",
|
overlayFont.DrawTextWithContrast("Ready",
|
||||||
drawPos + readyOffset,
|
icon.Pos + readyOffset,
|
||||||
Color.White, Color.Black, 1);
|
Color.White, Color.Black, 1);
|
||||||
else if (first.Paused)
|
else if (first.Paused)
|
||||||
overlayFont.DrawTextWithContrast("On Hold",
|
overlayFont.DrawTextWithContrast("On Hold",
|
||||||
drawPos + holdOffset,
|
icon.Pos + holdOffset,
|
||||||
|
Color.White, Color.Black, 1);
|
||||||
|
else if (!waiting)
|
||||||
|
overlayFont.DrawTextWithContrast(WidgetUtils.FormatTime(first.RemainingTimeActual),
|
||||||
|
icon.Pos + timeOffset,
|
||||||
Color.White, Color.Black, 1);
|
Color.White, Color.Black, 1);
|
||||||
|
|
||||||
if (total > 1 || (first != CurrentQueue.CurrentItem() && !first.Done))
|
if (total > 1 || waiting)
|
||||||
overlayFont.DrawTextWithContrast(total.ToString(),
|
overlayFont.DrawTextWithContrast(total.ToString(),
|
||||||
drawPos + queuedOffset,
|
icon.Pos + queuedOffset,
|
||||||
Color.White, Color.Black, 1);
|
Color.White, Color.Black, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,15 +164,15 @@ namespace OpenRA.Mods.RA
|
|||||||
return Produceable.ContainsKey(actor) && Produceable[actor].Buildable;
|
return Produceable.ContainsKey(actor) && Produceable[actor].Buildable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Tick( Actor self )
|
public virtual void Tick(Actor self)
|
||||||
{
|
{
|
||||||
while( Queue.Count > 0 && !BuildableItems().Any(b => b.Name == Queue[ 0 ].Item) )
|
while (Queue.Count > 0 && !BuildableItems().Any(b => b.Name == Queue[ 0 ].Item))
|
||||||
{
|
{
|
||||||
playerResources.GiveCash(Queue[0].TotalCost - Queue[0].RemainingCost); // refund what's been paid so far.
|
playerResources.GiveCash(Queue[0].TotalCost - Queue[0].RemainingCost); // refund what's been paid so far.
|
||||||
FinishProduction();
|
FinishProduction();
|
||||||
}
|
}
|
||||||
if( Queue.Count > 0 )
|
if (Queue.Count > 0)
|
||||||
Queue[ 0 ].Tick( playerResources, PlayerPower );
|
Queue[ 0 ].Tick(playerResources);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResolveOrder( Actor self, Order order )
|
public void ResolveOrder( Actor self, Order order )
|
||||||
@@ -195,7 +195,7 @@ namespace OpenRA.Mods.RA
|
|||||||
for (var n = 0; n < order.TargetLocation.X; n++) // repeat count
|
for (var n = 0; n < order.TargetLocation.X; n++) // repeat count
|
||||||
{
|
{
|
||||||
bool hasPlayedSound = false;
|
bool hasPlayedSound = false;
|
||||||
BeginProduction(new ProductionItem(this, order.TargetString, (int)time, cost,
|
BeginProduction(new ProductionItem(this, order.TargetString, (int)time, cost, PlayerPower,
|
||||||
() => self.World.AddFrameEndTask(
|
() => self.World.AddFrameEndTask(
|
||||||
_ =>
|
_ =>
|
||||||
{
|
{
|
||||||
@@ -317,16 +317,25 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
public readonly string Item;
|
public readonly string Item;
|
||||||
public readonly ProductionQueue Queue;
|
public readonly ProductionQueue Queue;
|
||||||
|
readonly PowerManager pm;
|
||||||
public readonly int TotalTime;
|
public readonly int TotalTime;
|
||||||
public readonly int TotalCost;
|
public readonly int TotalCost;
|
||||||
public int RemainingTime { get; private set; }
|
public int RemainingTime { get; private set; }
|
||||||
public int RemainingCost { get; private set; }
|
public int RemainingCost { get; private set; }
|
||||||
|
public int RemainingTimeActual
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return (pm.PowerState == PowerState.Normal) ? RemainingTime :
|
||||||
|
RemainingTime * Queue.Info.LowPowerSlowdown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool Paused = false, Done = false;
|
public bool Paused = false, Done = false;
|
||||||
public Action OnComplete;
|
public Action OnComplete;
|
||||||
public int slowdown = 0;
|
public int slowdown = 0;
|
||||||
|
|
||||||
public ProductionItem(ProductionQueue queue, string item, int time, int cost, Action onComplete)
|
public ProductionItem(ProductionQueue queue, string item, int time, int cost, PowerManager pm, Action onComplete)
|
||||||
{
|
{
|
||||||
if (time <= 0) time = 1;
|
if (time <= 0) time = 1;
|
||||||
Item = item;
|
Item = item;
|
||||||
@@ -334,11 +343,11 @@ namespace OpenRA.Mods.RA
|
|||||||
RemainingCost = TotalCost = cost;
|
RemainingCost = TotalCost = cost;
|
||||||
OnComplete = onComplete;
|
OnComplete = onComplete;
|
||||||
Queue = queue;
|
Queue = queue;
|
||||||
|
this.pm = pm;
|
||||||
//Log.Write("debug", "new ProductionItem: {0} time={1} cost={2}", item, time, cost);
|
//Log.Write("debug", "new ProductionItem: {0} time={1} cost={2}", item, time, cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(PlayerResources pr, PowerManager pm)
|
public void Tick(PlayerResources pr)
|
||||||
{
|
{
|
||||||
if (Done)
|
if (Done)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user