Fix UI rendering of offset sprites.

This commit is contained in:
Paul Chote
2013-11-30 22:13:53 +13:00
parent 21f2e88d83
commit 6881dcc710
13 changed files with 72 additions and 38 deletions

View File

@@ -203,6 +203,7 @@ namespace OpenRA.Mods.RA.Widgets
string paletteCollection = "palette-" + world.LocalPlayer.Country.Race;
float2 origin = new float2(paletteOrigin.X + 9, paletteOrigin.Y + 9);
var iconOffset = 0.5f * new float2(IconWidth, IconHeight);
var x = 0;
var y = 0;
@@ -233,7 +234,7 @@ namespace OpenRA.Mods.RA.Widgets
var drawPos = new float2(rect.Location);
var icon = new Animation(RenderSimple.GetImage(item));
icon.Play(item.Traits.Get<TooltipInfo>().Icon);
WidgetUtils.DrawSHP(icon.Image, drawPos, worldRenderer);
WidgetUtils.DrawSHPCentered(icon.Image, drawPos + iconOffset, worldRenderer);
var firstOfThis = queue.AllQueued().FirstOrDefault(a => a.Item == item.Name);
@@ -248,7 +249,7 @@ namespace OpenRA.Mods.RA.Widgets
() => (firstOfThis.TotalTime - firstOfThis.RemainingTime)
* (clock.CurrentSequence.Length - 1) / firstOfThis.TotalTime);
clock.Tick();
WidgetUtils.DrawSHP(clock.Image, drawPos, worldRenderer);
WidgetUtils.DrawSHPCentered(clock.Image, drawPos + iconOffset, worldRenderer);
if (queue.CurrentItem() == firstOfThis)
textBits.Add(Pair.New(overlayPos, GetOverlayForItem(firstOfThis)));
@@ -269,7 +270,7 @@ namespace OpenRA.Mods.RA.Widgets
if (x != 0) y++;
foreach (var ob in overlayBits)
WidgetUtils.DrawSHP(ob.First, ob.Second, worldRenderer);
WidgetUtils.DrawSHPCentered(ob.First, ob.Second + iconOffset, worldRenderer);
var font = Game.Renderer.Fonts["TinyBold"];
foreach (var tb in textBits)

View File

@@ -25,6 +25,10 @@ namespace OpenRA.Mods.RA.Widgets
WorldRenderer worldRenderer;
Dictionary<ProductionQueue, Animation> clocks;
public int IconWidth = 32;
public int IconHeight = 24;
public int IconSpacing = 8;
[ObjectCreator.UseCtor]
public ObserverProductionIconsWidget(World world, WorldRenderer worldRenderer)
{
@@ -59,6 +63,8 @@ namespace OpenRA.Mods.RA.Widgets
clocks.Add(queue.Trait, new Animation("clock"));
}
}
var iconSize = new float2(IconWidth, IconHeight);
foreach (var queue in queues)
{
var current = queue.Trait.CurrentItem();
@@ -71,16 +77,15 @@ namespace OpenRA.Mods.RA.Widgets
var icon = new Animation(RenderSimple.GetImage(actor));
icon.Play(actor.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(icon.Image, location, worldRenderer, size);
var location = new float2(RenderBounds.Location) + new float2(queue.i * (IconWidth + IconSpacing), 0);
WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer, 0.5f);
var clock = clocks[queue.Trait];
clock.PlayFetchIndex("idle",
() => current.TotalTime == 0 ? 0 : ((current.TotalTime - current.RemainingTime)
* (clock.CurrentSequence.Length - 1) / current.TotalTime));
clock.Tick();
WidgetUtils.DrawSHP(clock.Image, location, worldRenderer, size);
WidgetUtils.DrawSHPCentered(clock.Image, location + 0.5f * iconSize, worldRenderer, 0.5f);
var tiny = Game.Renderer.Fonts["Tiny"];
var text = GetOverlayForItem(current);

View File

@@ -25,6 +25,10 @@ namespace OpenRA.Mods.RA.Widgets
WorldRenderer worldRenderer;
Dictionary<string, Animation> clocks;
public int IconWidth = 32;
public int IconHeight = 24;
public int IconSpacing = 8;
[ObjectCreator.UseCtor]
public ObserverSupportPowerIconsWidget(World world, WorldRenderer worldRenderer)
{
@@ -61,22 +65,24 @@ namespace OpenRA.Mods.RA.Widgets
clocks.Add(power.a.Key, new Animation("clock"));
}
}
var iconSize = new float2(IconWidth, IconHeight);
foreach (var power in powers)
{
var item = power.a.Value;
if (item == null || item.Info == null || item.Info.Icon == null)
continue;
icon.Play(item.Info.Icon);
var size = icon.Image.size / new float2(2, 2);
var location = new float2(RenderBounds.Location) + new float2(power.i * (int)size.Length, 0);
WidgetUtils.DrawSHP(icon.Image, location, worldRenderer, size);
var location = new float2(RenderBounds.Location) + new float2(power.i * (IconWidth + IconSpacing), 0);
WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer, 0.5f);
var clock = clocks[power.a.Key];
clock.PlayFetchIndex("idle",
() => item.TotalTime == 0 ? 0 : ((item.TotalTime - item.RemainingTime)
* (clock.CurrentSequence.Length - 1) / item.TotalTime));
clock.Tick();
WidgetUtils.DrawSHP(clock.Image, location, worldRenderer, size);
WidgetUtils.DrawSHPCentered(clock.Image, location + 0.5f * iconSize, worldRenderer, 0.5f);
var tiny = Game.Renderer.Fonts["Tiny"];
var text = GetOverlayForItem(item);

View File

@@ -23,6 +23,9 @@ namespace OpenRA.Mods.RA.Widgets
[Translate] public string ReadyText = "";
[Translate] public string HoldText = "";
public int IconWidth = 64;
public int IconHeight = 48;
Animation icon;
Animation clock;
readonly List<Pair<Rectangle, Action<MouseInput>>> buttons = new List<Pair<Rectangle,Action<MouseInput>>>();
@@ -84,10 +87,11 @@ namespace OpenRA.Mods.RA.Widgets
WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-bottom"), new float2(rectBounds.X, rectBounds.Y + numPowers * 51));
// HACK: Hack Hack Hack
rectBounds.Width = 69;
rectBounds.Height = 10 + numPowers * 51 + 21;
rectBounds.Width = IconWidth + 5;
rectBounds.Height = 31 + numPowers * (IconHeight + 3);
var y = rectBounds.Y + 10;
var iconSize = new float2(IconWidth, IconHeight);
foreach (var kv in powers)
{
var sp = kv.Value;
@@ -137,14 +141,14 @@ namespace OpenRA.Mods.RA.Widgets
}
}
WidgetUtils.DrawSHP(icon.Image, drawPos, worldRenderer);
WidgetUtils.DrawSHPCentered(icon.Image, drawPos + 0.5f * iconSize, worldRenderer);
clock.PlayFetchIndex("idle",
() => sp.TotalTime == 0 ? clock.CurrentSequence.Length - 1 : (sp.TotalTime - sp.RemainingTime)
* (clock.CurrentSequence.Length - 1) / sp.TotalTime);
clock.Tick();
WidgetUtils.DrawSHP(clock.Image, drawPos, worldRenderer);
WidgetUtils.DrawSHPCentered(clock.Image, drawPos + 0.5f * iconSize, worldRenderer);
var overlay = sp.Ready ? ReadyText : sp.Active ? null : HoldText;
var font = Game.Renderer.Fonts["TinyBold"];