read the production icons from sequences

this allows d2k to read them from DATA.R8 without trouble
This commit is contained in:
Matthias Mailänder
2013-08-16 10:03:05 +02:00
parent b73ca27a8f
commit 376a6c7a5d
46 changed files with 862 additions and 425 deletions

View File

@@ -13,6 +13,7 @@ using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets
@@ -20,7 +21,6 @@ namespace OpenRA.Mods.RA.Widgets
public class ObserverProductionIconsWidget : Widget
{
public Func<Player> GetPlayer;
Dictionary<string, Sprite> iconSprites;
World world;
WorldRenderer worldRenderer;
Dictionary<ProductionQueue, Animation> clocks;
@@ -29,10 +29,6 @@ namespace OpenRA.Mods.RA.Widgets
public ObserverProductionIconsWidget(World world, WorldRenderer worldRenderer)
: base()
{
iconSprites = Rules.Info.Values.Where(u => u.Traits.Contains<BuildableInfo>() && u.Name[0] != '^')
.ToDictionary(
u => u.Name,
u => Game.modData.SpriteLoader.LoadAllSprites(u.Traits.Get<TooltipInfo>().Icon ?? (u.Name + "icon"))[0]);
this.world = world;
this.worldRenderer = worldRenderer;
clocks = new Dictionary<ProductionQueue, Animation>();
@@ -42,7 +38,6 @@ namespace OpenRA.Mods.RA.Widgets
: base(other)
{
GetPlayer = other.GetPlayer;
iconSprites = other.iconSprites;
world = other.world;
worldRenderer = other.worldRenderer;
clocks = other.clocks;
@@ -67,25 +62,27 @@ namespace OpenRA.Mods.RA.Widgets
}
foreach (var queue in queues)
{
var item = queue.Trait.CurrentItem();
var item = queue.Trait.AllItems().FirstOrDefault();
if (item == null)
{
continue;
}
var sprite = iconSprites[item.Item];
var size = sprite.size / new float2(2, 2);
var icon = new Animation(RenderSimple.GetImage(item));
icon.Play(item.Traits.Get<TooltipInfo>().Icon);
var size = icon.Image.size / new float2(2, 2);
var location = new float2(RenderBounds.Location) + new float2(queue.i * (int)size.Length, 0);
WidgetUtils.DrawSHP(sprite, location, worldRenderer, size);
WidgetUtils.DrawSHP(icon.Image, location, worldRenderer, size);
var current = queue.Trait.CurrentItem();
if (current == null)
continue;
var clock = clocks[queue.Trait];
clock.PlayFetchIndex("idle",
() => item.TotalTime == 0 ? 0 : ((item.TotalTime - item.RemainingTime)
* (clock.CurrentSequence.Length - 1) / item.TotalTime));
() => current.TotalTime == 0 ? 0 : ((current.TotalTime - current.RemainingTime)
* (clock.CurrentSequence.Length - 1) / current.TotalTime));
clock.Tick();
WidgetUtils.DrawSHP(clock.Image, location, worldRenderer, size);
var tiny = Game.Renderer.Fonts["Tiny"];
var text = GetOverlayForItem(item);
var text = GetOverlayForItem(current);
tiny.DrawTextWithContrast(text,
location + new float2(16, 16) - new float2(tiny.Measure(text).X / 2, 0),
Color.White, Color.Black, 1);