more chrome
This commit is contained in:
@@ -6,6 +6,7 @@ using OpenRa.Game.Graphics;
|
||||
using OpenRa.Game.Support;
|
||||
using System.Drawing;
|
||||
using IjwFramework.Types;
|
||||
using IjwFramework.Collections;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
@@ -20,6 +21,8 @@ namespace OpenRa.Game
|
||||
readonly Animation cantBuild;
|
||||
|
||||
readonly List<Pair<Rectangle, string>> buildItems = new List<Pair<Rectangle, string>>();
|
||||
readonly Cache<string, Animation> clockAnimations;
|
||||
readonly List<Sprite> digitSprites;
|
||||
|
||||
public Chrome(Renderer r)
|
||||
{
|
||||
@@ -28,8 +31,8 @@ namespace OpenRa.Game
|
||||
chromeRenderer = new SpriteRenderer(renderer, true, renderer.RgbaSpriteShader);
|
||||
buildPaletteRenderer = new SpriteRenderer(renderer, true);
|
||||
|
||||
specialBinSprite = new Sprite(specialBin, new Rectangle(0, 0, 64, 256), TextureChannel.Alpha);
|
||||
moneyBinSprite = new Sprite(specialBin, new Rectangle(128, 0, 384, 64), TextureChannel.Alpha);
|
||||
specialBinSprite = new Sprite(specialBin, new Rectangle(0, 0, 32, 256), TextureChannel.Alpha);
|
||||
moneyBinSprite = new Sprite(specialBin, new Rectangle(512-320, 0, 320, 64), TextureChannel.Alpha);
|
||||
|
||||
sprites = groups
|
||||
.SelectMany(g => Rules.Categories[g])
|
||||
@@ -40,6 +43,16 @@ namespace OpenRa.Game
|
||||
|
||||
cantBuild = new Animation("clock");
|
||||
cantBuild.PlayFetchIndex("idle", () => 0);
|
||||
|
||||
clockAnimations = new Cache<string, Animation>(
|
||||
s => {
|
||||
var anim = new Animation("clock");
|
||||
anim.PlayFetchIndex("idle", ClockAnimFrame(s));
|
||||
return anim;
|
||||
});
|
||||
|
||||
digitSprites = Util.MakeArray(10, a => a)
|
||||
.Select(n => new Sprite(specialBin, new Rectangle(32 + 14 * n, 0, 14, 17), TextureChannel.Alpha)).ToList();
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
@@ -59,7 +72,15 @@ namespace OpenRa.Game
|
||||
PerfHistory.Render(renderer, Game.worldRenderer.lineRenderer);
|
||||
|
||||
chromeRenderer.DrawSprite(specialBinSprite, float2.Zero, 0);
|
||||
chromeRenderer.DrawSprite(moneyBinSprite, new float2( Game.viewport.Width - 384, 0 ), 0);
|
||||
chromeRenderer.DrawSprite(moneyBinSprite, new float2( Game.viewport.Width - 320, 0 ), 0);
|
||||
|
||||
var moneyDigits = Game.LocalPlayer.Cash.ToString();
|
||||
var x = Game.viewport.Width - 155;
|
||||
foreach( var d in moneyDigits.Reverse() )
|
||||
{
|
||||
chromeRenderer.DrawSprite(digitSprites[d - '0'], new float2(x,6), 0);
|
||||
x -= 14;
|
||||
}
|
||||
chromeRenderer.Flush();
|
||||
|
||||
DrawBuildPalette("Building");
|
||||
@@ -68,6 +89,17 @@ namespace OpenRa.Game
|
||||
static string[] groups = new string[] { "Building", "Defense", "Vehicle", "Ship", "Infantry", "Plane" };
|
||||
Dictionary<string, Sprite> sprites;
|
||||
|
||||
const int NumClockFrames = 54;
|
||||
Func<int> ClockAnimFrame(string group)
|
||||
{
|
||||
return () =>
|
||||
{
|
||||
var producing = Game.LocalPlayer.Producing(group);
|
||||
if (producing == null) return 0;
|
||||
return (producing.TotalTime - producing.RemainingTime) * NumClockFrames / producing.TotalTime;
|
||||
};
|
||||
}
|
||||
|
||||
void DrawBuildPalette(string queueName)
|
||||
{
|
||||
var buildItem = Game.LocalPlayer.Producing(queueName);
|
||||
@@ -76,18 +108,22 @@ namespace OpenRa.Game
|
||||
|
||||
var buildableItems = Rules.TechTree.BuildableItems(Game.LocalPlayer, queueName).ToArray();
|
||||
var allItems = Rules.TechTree.AllItems(Game.LocalPlayer, queueName)
|
||||
.Where( a => Rules.UnitInfo[a].TechLevel != -1 )
|
||||
.OrderBy( a => Rules.UnitInfo[a].TechLevel );
|
||||
|
||||
var currentItem = Game.LocalPlayer.Producing(queueName);
|
||||
|
||||
foreach (var item in allItems)
|
||||
{
|
||||
if (Rules.UnitInfo[item].TechLevel == -1) continue;
|
||||
var rect = new Rectangle(Game.viewport.Width - (3 - x) * 64 - 20, 32 + 48 * y, 64, 48);
|
||||
var rect = new Rectangle(Game.viewport.Width - (3 - x) * 64 - 10, 40 + 48 * y, 64, 48);
|
||||
buildPaletteRenderer.DrawSprite(sprites[item], Game.viewport.Location + new float2(rect.Location), 0);
|
||||
|
||||
if (!buildableItems.Contains(item))
|
||||
{
|
||||
/* don't have the necessary prereqs! */
|
||||
if (!buildableItems.Contains(item) || (currentItem != null && currentItem.Item != item))
|
||||
buildPaletteRenderer.DrawSprite(cantBuild.Image, Game.viewport.Location + new float2(rect.Location), 0);
|
||||
}
|
||||
|
||||
if (currentItem != null && currentItem.Item == item)
|
||||
buildPaletteRenderer.DrawSprite(clockAnimations[queueName].Image,
|
||||
Game.viewport.Location + new float2(rect.Location), 0);
|
||||
|
||||
buildItems.Add(Pair.New(rect, item));
|
||||
if (++x == 3) { x = 0; y++; }
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRa.Game
|
||||
Dictionary<string, Sprite> sprites = new Dictionary<string,Sprite>();
|
||||
const int spriteWidth = 64, spriteHeight = 48;
|
||||
|
||||
static string[] groups = new string[] { "Building", "Vehicle", "Ship", "Infantry", "Plane" };
|
||||
static string[] groups = new string[] { "Building", "Defense", "Vehicle", "Ship", "Infantry", "Plane" };
|
||||
|
||||
Dictionary<string, Animation> clockAnimations = new Dictionary<string,Animation>(); //group->clockAnimation
|
||||
|
||||
|
||||
BIN
specialbin.png
BIN
specialbin.png
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 22 KiB |
Reference in New Issue
Block a user