added PaletteType enum

This commit is contained in:
Alli
2009-12-23 22:24:20 +13:00
parent 8fa02ea6a3
commit 9e950c84ca
16 changed files with 50 additions and 39 deletions

View File

@@ -48,7 +48,7 @@ namespace OpenRa.Game
public void AddLine(Player p, string text) public void AddLine(Player p, string text)
{ {
AddLine(paletteColors[p.Palette], p.PlayerName, text); AddLine(paletteColors[(int) p.Palette], p.PlayerName, text);
} }
public void AddLine(Color c, string from, string text) public void AddLine(Color c, string from, string text)

View File

@@ -9,6 +9,7 @@ using OpenRa.Game.Graphics;
using OpenRa.Game.Support; using OpenRa.Game.Support;
using OpenRa.Game.GameRules; using OpenRa.Game.GameRules;
namespace OpenRa.Game namespace OpenRa.Game
{ {
class Chrome : IHandleInput class Chrome : IHandleInput
@@ -110,8 +111,8 @@ namespace OpenRa.Game
PerfHistory.Render(renderer, Game.worldRenderer.lineRenderer); PerfHistory.Render(renderer, Game.worldRenderer.lineRenderer);
chromeRenderer.DrawSprite(specialBinSprite, float2.Zero, 0); chromeRenderer.DrawSprite(specialBinSprite, float2.Zero, PaletteType.Gold);
chromeRenderer.DrawSprite(moneyBinSprite, new float2(Game.viewport.Width - 320, 0), 0); chromeRenderer.DrawSprite(moneyBinSprite, new float2(Game.viewport.Width - 320, 0), PaletteType.Gold);
DrawMoney(); DrawMoney();
@@ -158,8 +159,8 @@ namespace OpenRa.Game
{ {
x = Game.viewport.Width - tabWidth; x = Game.viewport.Width - tabWidth;
} }
chromeRenderer.DrawSprite(q.Value[index], new float2(x, y), 0); chromeRenderer.DrawSprite(q.Value[index], new float2(x, y), PaletteType.Gold);
buttons.Add(Pair.New(new Rectangle(x, y, tabWidth, tabHeight), buttons.Add(Pair.New(new Rectangle(x, y, tabWidth, tabHeight),
(Action<bool>)(isLmb => currentTab = groupName))); (Action<bool>)(isLmb => currentTab = groupName)));
@@ -189,7 +190,7 @@ namespace OpenRa.Game
var x = Game.viewport.Width - 155; var x = Game.viewport.Width - 155;
foreach (var d in moneyDigits.Reverse()) foreach (var d in moneyDigits.Reverse())
{ {
chromeRenderer.DrawSprite(digitSprites[d - '0'], new float2(x, 6), 0); chromeRenderer.DrawSprite(digitSprites[d - '0'], new float2(x, 6), PaletteType.Gold);
x -= 14; x -= 14;
} }
} }
@@ -264,7 +265,7 @@ namespace OpenRa.Game
var isBuildingThis = currentItem != null && currentItem.Item == item; var isBuildingThis = currentItem != null && currentItem.Item == item;
var isBuildingSomethingElse = currentItem != null && currentItem.Item != item; var isBuildingSomethingElse = currentItem != null && currentItem.Item != item;
buildPaletteRenderer.DrawSprite(sprites[item], drawPos, HardwarePalette.Chrome); buildPaletteRenderer.DrawSprite(sprites[item], drawPos, PaletteType.Chrome);
if (rect.Contains(lastMousePos.ToPoint())) if (rect.Contains(lastMousePos.ToPoint()))
{ {
@@ -279,7 +280,7 @@ namespace OpenRa.Game
{ {
clockAnimations[queueName].Tick(); clockAnimations[queueName].Tick();
buildPaletteRenderer.DrawSprite(clockAnimations[queueName].Image, buildPaletteRenderer.DrawSprite(clockAnimations[queueName].Image,
drawPos, HardwarePalette.Chrome); drawPos, PaletteType.Chrome);
var overlayPos = drawPos + new float2((64 - ready.Image.size.X) / 2, 2); var overlayPos = drawPos + new float2((64 - ready.Image.size.X) / 2, 2);
@@ -305,26 +306,26 @@ namespace OpenRa.Game
{ {
var rect = new Rectangle(origin.X + x * 64, origin.Y + 48 * y, 64, 48); var rect = new Rectangle(origin.X + x * 64, origin.Y + 48 * y, 64, 48);
var drawPos = Game.viewport.Location + new float2(rect.Location); var drawPos = Game.viewport.Location + new float2(rect.Location);
buildPaletteRenderer.DrawSprite(blank, drawPos, HardwarePalette.Chrome); buildPaletteRenderer.DrawSprite(blank, drawPos, PaletteType.Chrome);
buttons.Add(Pair.New(rect, (Action<bool>)(_ => { }))); buttons.Add(Pair.New(rect, (Action<bool>)(_ => { })));
if (++x == columns) { x = 0; y++; } if (++x == columns) { x = 0; y++; }
} }
foreach (var ob in overlayBits) foreach (var ob in overlayBits)
buildPaletteRenderer.DrawSprite(ob.First, ob.Second, HardwarePalette.Chrome); buildPaletteRenderer.DrawSprite(ob.First, ob.Second, PaletteType.Chrome);
buildPaletteRenderer.Flush(); buildPaletteRenderer.Flush();
for (var j = 0; j < y; j++) for (var j = 0; j < y; j++)
chromeRenderer.DrawSprite(shimSprites[2], new float2(origin.X - 9, origin.Y + 48 * j), 0); chromeRenderer.DrawSprite(shimSprites[2], new float2(origin.X - 9, origin.Y + 48 * j), PaletteType.Gold);
chromeRenderer.DrawSprite(shimSprites[0], new float2(origin.X - 9, origin.Y - 9), 0); chromeRenderer.DrawSprite(shimSprites[0], new float2(origin.X - 9, origin.Y - 9), PaletteType.Gold);
chromeRenderer.DrawSprite(shimSprites[1], new float2(origin.X - 9, origin.Y - 1 + 48 * y), 0); chromeRenderer.DrawSprite(shimSprites[1], new float2(origin.X - 9, origin.Y - 1 + 48 * y), PaletteType.Gold);
for (var i = 0; i < columns; i++) for (var i = 0; i < columns; i++)
{ {
chromeRenderer.DrawSprite(shimSprites[3], new float2(origin.X + 64 * i, origin.Y - 9), 0); chromeRenderer.DrawSprite(shimSprites[3], new float2(origin.X + 64 * i, origin.Y - 9), PaletteType.Gold);
chromeRenderer.DrawSprite(shimSprites[4], new float2(origin.X + 64 * i, origin.Y - 1 + 48 * y), 0); chromeRenderer.DrawSprite(shimSprites[4], new float2(origin.X + 64 * i, origin.Y - 1 + 48 * y), PaletteType.Gold);
} }
chromeRenderer.Flush(); chromeRenderer.Flush();
@@ -414,7 +415,7 @@ namespace OpenRa.Game
void DrawProductionTooltip(string unit, int2 pos) void DrawProductionTooltip(string unit, int2 pos)
{ {
var p = pos.ToFloat2() - new float2(tooltipSprite.size.X, 0); var p = pos.ToFloat2() - new float2(tooltipSprite.size.X, 0);
chromeRenderer.DrawSprite(tooltipSprite, p, 0); chromeRenderer.DrawSprite(tooltipSprite, p, PaletteType.Gold);
chromeRenderer.Flush(); chromeRenderer.Flush();
var info = Rules.UnitInfo[unit]; var info = Rules.UnitInfo[unit];

View File

@@ -77,14 +77,14 @@ namespace OpenRa.Game.Effects
if (Projectile.High || Projectile.Arcing) if (Projectile.High || Projectile.Arcing)
{ {
if (Projectile.Shadow) if (Projectile.Shadow)
yield return new Renderable(anim.Image, pos, 8); yield return new Renderable(anim.Image, pos, PaletteType.Shadow);
var highPos = pos - new float2(0, (VisualDest - Src).Length * height * 4 * at * (1 - at)); var highPos = pos - new float2(0, (VisualDest - Src).Length * height * 4 * at * (1 - at));
yield return new Renderable(anim.Image, highPos, Owner.Palette); yield return new Renderable(anim.Image, highPos, Owner.Palette);
} }
else else
yield return new Renderable(anim.Image, pos, Projectile.UnderWater ? 8 : Owner.Palette); yield return new Renderable(anim.Image, pos, Projectile.UnderWater ? PaletteType.Shadow : Owner.Palette);
} }
} }
} }

View File

@@ -24,7 +24,7 @@ namespace OpenRa.Game.Effects
public IEnumerable<Renderable> Render() public IEnumerable<Renderable> Render()
{ {
yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, 8); yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, PaletteType.Shadow);
} }
} }
} }

View File

@@ -68,7 +68,7 @@ namespace OpenRa.Game
var name = players.ContainsKey(i) ? players[i].PlayerName : "Player {0}".F(i+1); var name = players.ContainsKey(i) ? players[i].PlayerName : "Player {0}".F(i+1);
var a = new Actor(null, new int2(int.MaxValue, int.MaxValue), null); var a = new Actor(null, new int2(int.MaxValue, int.MaxValue), null);
players[i] = new Player(a, i, i, name, race, "Multi{0}".F(i)); players[i] = new Player(a, i, (PaletteType) i, name, race, "Multi{0}".F(i));
a.Owner = players[i]; a.Owner = players[i];
a.traits.Add(new Traits.ProductionQueue(a)); a.traits.Add(new Traits.ProductionQueue(a));
Game.world.Add(a); Game.world.Add(a);

View File

@@ -5,13 +5,10 @@ namespace OpenRa.Game.Graphics
{ {
class HardwarePalette : Sheet class HardwarePalette : Sheet
{ {
public const int Shadow = 8;
public const int Invuln = 9;
public const int Chrome = 10;
const int maxEntries = 16; const int maxEntries = 16;
int allocated = 0; int allocated = 0;
//Note: addPalette calls should match the ordering in PaletteType.cs
public HardwarePalette(Renderer renderer, Map map) public HardwarePalette(Renderer renderer, Map map)
: base(renderer,new Size(256, maxEntries)) : base(renderer,new Size(256, maxEntries))
{ {

View File

@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.Graphics
{
//Note: should match the ordering in HardwarePalette.cs
enum PaletteType { Gold, Blue, Red, Orange, Teal, Salmon, Green, Gray, Shadow, Invuln, Chrome };
}

View File

@@ -54,13 +54,13 @@ namespace OpenRa.Game.Graphics
} }
} }
public void DrawSprite(Sprite s, float2 location, int palette) public void DrawSprite(Sprite s, float2 location, PaletteType palette)
{ {
if (s.sheet != currentSheet) if (s.sheet != currentSheet)
Flush(); Flush();
currentSheet = s.sheet; currentSheet = s.sheet;
Util.FastCreateQuad(vertices, indices, location, s, palette, nv, ni); Util.FastCreateQuad(vertices, indices, location, s, (int) palette, nv, ni);
nv += 4; ni += 6; nv += 4; ni += 6;
if (++sprites >= spritesPerBatch) if (++sprites >= spritesPerBatch)
Flush(); Flush();

View File

@@ -197,7 +197,7 @@ namespace OpenRa.Game.Graphics
var pipImages = new Animation("pips"); var pipImages = new Animation("pips");
pipImages.PlayFetchIndex("groups", () => (int)group); pipImages.PlayFetchIndex("groups", () => (int)group);
pipImages.Tick(); pipImages.Tick();
spriteRenderer.DrawSprite(pipImages.Image, basePosition + new float2(-8, 1), HardwarePalette.Chrome); spriteRenderer.DrawSprite(pipImages.Image, basePosition + new float2(-8, 1), PaletteType.Chrome);
} }
void DrawPips(Actor selectedUnit, float2 basePosition) void DrawPips(Actor selectedUnit, float2 basePosition)
@@ -212,7 +212,7 @@ namespace OpenRa.Game.Graphics
{ {
var pipImages = new Animation("pips"); var pipImages = new Animation("pips");
pipImages.PlayRepeating(pipStrings[(int)pip]); pipImages.PlayRepeating(pipStrings[(int)pip]);
spriteRenderer.DrawSprite(pipImages.Image, pipxyBase + pipxyOffset, HardwarePalette.Chrome); spriteRenderer.DrawSprite(pipImages.Image, pipxyBase + pipxyOffset, PaletteType.Chrome);
pipxyOffset += new float2(4, 0); pipxyOffset += new float2(4, 0);
if (pipxyOffset.X+5 > selectedUnit.SelectedSize.X) if (pipxyOffset.X+5 > selectedUnit.SelectedSize.X)
@@ -239,7 +239,7 @@ namespace OpenRa.Game.Graphics
{ {
var tagImages = new Animation("pips"); var tagImages = new Animation("pips");
tagImages.PlayRepeating(tagStrings[(int)tag]); tagImages.PlayRepeating(tagStrings[(int)tag]);
spriteRenderer.DrawSprite(tagImages.Image, tagxyBase + tagxyOffset, HardwarePalette.Chrome); spriteRenderer.DrawSprite(tagImages.Image, tagxyBase + tagxyOffset, PaletteType.Chrome);
// Increment row // Increment row
tagxyOffset.Y += 8; tagxyOffset.Y += 8;

View File

@@ -92,6 +92,7 @@
<Compile Include="GameRules\TechTree.cs" /> <Compile Include="GameRules\TechTree.cs" />
<Compile Include="GameRules\VoiceInfo.cs" /> <Compile Include="GameRules\VoiceInfo.cs" />
<Compile Include="Effects\IEffect.cs" /> <Compile Include="Effects\IEffect.cs" />
<Compile Include="Graphics\PaletteType.cs" />
<Compile Include="IOrderSource.cs" /> <Compile Include="IOrderSource.cs" />
<Compile Include="LocalOrderSource.cs" /> <Compile Include="LocalOrderSource.cs" />
<Compile Include="Effects\Missile.cs" /> <Compile Include="Effects\Missile.cs" />

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRa.Game.GameRules; using OpenRa.Game.GameRules;
using OpenRa.Game.Traits; using OpenRa.Game.Traits;
using OpenRa.Game.Graphics;
namespace OpenRa.Game namespace OpenRa.Game
{ {
@@ -11,7 +12,7 @@ namespace OpenRa.Game
class Player class Player
{ {
public Actor PlayerActor; public Actor PlayerActor;
public int Palette; public PaletteType Palette;
public int Kills; public int Kills;
public string PlayerName; public string PlayerName;
public string InternalName; public string InternalName;
@@ -26,7 +27,7 @@ namespace OpenRa.Game
public bool IsReady; public bool IsReady;
public Player( Actor playerActor, int index, int palette, string playerName, Race race, string internalName ) public Player( Actor playerActor, int index, PaletteType palette, string playerName, Race race, string internalName )
{ {
this.PlayerActor = playerActor; this.PlayerActor = playerActor;
this.Index = index; this.Index = index;

View File

@@ -25,7 +25,7 @@ namespace OpenRa.Game.Traits
return rs; return rs;
if (self.Owner == Game.LocalPlayer) if (self.Owner == Game.LocalPlayer)
return rs.Select(a => a.WithPalette(8)); return rs.Select(a => a.WithPalette(PaletteType.Shadow));
else else
return new Renderable[] { }; return new Renderable[] { };
} }

View File

@@ -28,7 +28,7 @@ namespace OpenRa.Game.Traits
return rs; return rs;
if (self.Owner == Game.LocalPlayer) if (self.Owner == Game.LocalPlayer)
return rs.Select(a => a.WithPalette(8)); return rs.Select(a => a.WithPalette(PaletteType.Shadow));
else else
return new Renderable[] { }; return new Renderable[] { };
} }

View File

@@ -15,10 +15,10 @@ namespace OpenRa.Game.Traits
{ {
public readonly Sprite Sprite; public readonly Sprite Sprite;
public readonly float2 Pos; public readonly float2 Pos;
public readonly int Palette; public readonly PaletteType Palette;
public readonly int ZOffset; public readonly int ZOffset;
public Renderable(Sprite sprite, float2 pos, int palette, int zOffset) public Renderable(Sprite sprite, float2 pos, PaletteType palette, int zOffset)
{ {
Sprite = sprite; Sprite = sprite;
Pos = pos; Pos = pos;
@@ -26,10 +26,10 @@ namespace OpenRa.Game.Traits
ZOffset = zOffset; ZOffset = zOffset;
} }
public Renderable(Sprite sprite, float2 pos, int palette) public Renderable(Sprite sprite, float2 pos, PaletteType palette)
: this(sprite, pos, palette, 0) { } : this(sprite, pos, palette, 0) { }
public Renderable WithPalette(int newPalette) { return new Renderable(Sprite, Pos, newPalette, ZOffset); } public Renderable WithPalette(PaletteType newPalette) { return new Renderable(Sprite, Pos, newPalette, ZOffset); }
public Renderable WithZOffset(int newOffset) { return new Renderable(Sprite, Pos, Palette, newOffset); } public Renderable WithZOffset(int newOffset) { return new Renderable(Sprite, Pos, Palette, newOffset); }
public Renderable WithPos(float2 newPos) { return new Renderable(Sprite, newPos, Palette, ZOffset); } public Renderable WithPos(float2 newPos) { return new Renderable(Sprite, newPos, Palette, ZOffset); }
} }

View File

@@ -14,7 +14,7 @@ namespace OpenRa.Game.Traits
{ {
var unit = self.traits.Get<Unit>(); var unit = self.traits.Get<Unit>();
var shadowSprites = r.Select(a => a.WithPalette(8)); var shadowSprites = r.Select(a => a.WithPalette(PaletteType.Shadow));
var flyingSprites = (unit.Altitude <= 0) ? r var flyingSprites = (unit.Altitude <= 0) ? r
: r.Select(a => a.WithPos(a.Pos - new float2(0, unit.Altitude)).WithZOffset(3)); : r.Select(a => a.WithPos(a.Pos - new float2(0, unit.Altitude)).WithZOffset(3));

View File

@@ -3,6 +3,7 @@ using System.Drawing;
using System.Linq; using System.Linq;
using OpenRa.Game.GameRules; using OpenRa.Game.GameRules;
using OpenRa.Game.Traits; using OpenRa.Game.Traits;
using OpenRa.Game.Graphics;
namespace OpenRa.Game namespace OpenRa.Game
{ {
@@ -96,7 +97,7 @@ namespace OpenRa.Game
{ {
int palette = int.Parse(order.TargetString); int palette = int.Parse(order.TargetString);
Game.chat.AddLine(order.Player, "has changed color to {0}".F(palette)); Game.chat.AddLine(order.Player, "has changed color to {0}".F(palette));
order.Player.Palette = palette; order.Player.Palette = (PaletteType) palette;
break; break;
} }
case "StartGame": case "StartGame":