Move Palette from ModData to WorldRenderer.

This commit is contained in:
Paul Chote
2013-02-25 19:00:35 +13:00
parent 3033eb8be0
commit 82426e0e45
5 changed files with 16 additions and 11 deletions

View File

@@ -19,6 +19,7 @@ namespace OpenRA.Graphics
{ {
public static class CursorProvider public static class CursorProvider
{ {
public static Dictionary<string, Palette> Palettes { get; private set; }
static Dictionary<string, CursorSequence> cursors; static Dictionary<string, CursorSequence> cursors;
public static void Initialize(string[] sequenceFiles) public static void Initialize(string[] sequenceFiles)
@@ -28,13 +29,14 @@ namespace OpenRA.Graphics
int[] ShadowIndex = { }; int[] ShadowIndex = { };
if (sequences.NodesDict.ContainsKey("ShadowIndex")) if (sequences.NodesDict.ContainsKey("ShadowIndex"))
{ {
Array.Resize(ref ShadowIndex, ShadowIndex.Length + 1); Array.Resize(ref ShadowIndex, ShadowIndex.Length + 1);
ShadowIndex[ShadowIndex.Length - 1] = Convert.ToInt32(sequences.NodesDict["ShadowIndex"].Value); ShadowIndex[ShadowIndex.Length - 1] = Convert.ToInt32(sequences.NodesDict["ShadowIndex"].Value);
} }
Palettes = new Dictionary<string, Palette>();
foreach (var s in sequences.NodesDict["Palettes"].Nodes) foreach (var s in sequences.NodesDict["Palettes"].Nodes)
Game.modData.Palette.AddPalette(s.Key, new Palette(FileSystem.Open(s.Value.Value), ShadowIndex), false); Palettes.Add(s.Key, new Palette(FileSystem.Open(s.Value.Value), ShadowIndex));
foreach (var s in sequences.NodesDict["Cursors"].Nodes) foreach (var s in sequences.NodesDict["Cursors"].Nodes)
LoadSequencesForCursor(s.Key, s.Value); LoadSequencesForCursor(s.Key, s.Value);

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Graphics
int nv = 0; int nv = 0;
var terrainPalette = Game.modData.Palette.GetPaletteIndex("terrain"); var terrainPalette = wr.Palette("terrain").Index;
for( int j = map.Bounds.Top; j < map.Bounds.Bottom; j++ ) for( int j = map.Bounds.Top; j < map.Bounds.Bottom; j++ )
for( int i = map.Bounds.Left; i < map.Bounds.Right; i++ ) for( int i = map.Bounds.Left; i < map.Bounds.Right; i++ )

View File

@@ -133,7 +133,7 @@ namespace OpenRA.Graphics
renderer.SpriteRenderer.DrawSprite(cursorSprite, renderer.SpriteRenderer.DrawSprite(cursorSprite,
Viewport.LastMousePos - cursorSequence.Hotspot, Viewport.LastMousePos - cursorSequence.Hotspot,
Game.modData.Palette.GetPaletteIndex(cursorSequence.Palette), wr.Palette(cursorSequence.Palette).Index,
cursorSprite.size); cursorSprite.size);
} }

View File

@@ -41,11 +41,17 @@ namespace OpenRA.Graphics
internal WorldRenderer(World world) internal WorldRenderer(World world)
{ {
this.world = world; this.world = world;
this.palette = Game.modData.Palette; palette = new HardwarePalette();
foreach (var p in CursorProvider.Palettes)
palette.AddPalette(p.Key, p.Value, false);
palettes = new Cache<string, PaletteReference>(CreatePaletteReference); palettes = new Cache<string, PaletteReference>(CreatePaletteReference);
foreach (var pal in world.traitDict.ActorsWithTraitMultiple<IPalette>(world)) foreach (var pal in world.traitDict.ActorsWithTraitMultiple<IPalette>(world))
pal.Trait.InitPalette( this ); pal.Trait.InitPalette( this );
// Generate initial palette texture
palette.Update(new IPaletteModifier[] {});
terrainRenderer = new TerrainRenderer(world, this); terrainRenderer = new TerrainRenderer(world, this);
shroudRenderer = new ShroudRenderer(world); shroudRenderer = new ShroudRenderer(world);
} }

View File

@@ -28,7 +28,6 @@ namespace OpenRA
public ILoadScreen LoadScreen = null; public ILoadScreen LoadScreen = null;
public SheetBuilder SheetBuilder; public SheetBuilder SheetBuilder;
public SpriteLoader SpriteLoader; public SpriteLoader SpriteLoader;
public HardwarePalette Palette { get; private set; }
public ModData( params string[] mods ) public ModData( params string[] mods )
{ {
@@ -51,13 +50,11 @@ namespace OpenRA
AvailableMaps = FindMaps(Manifest.Mods); AvailableMaps = FindMaps(Manifest.Mods);
Palette = new HardwarePalette();
ChromeMetrics.Initialize(Manifest.ChromeMetrics); ChromeMetrics.Initialize(Manifest.ChromeMetrics);
ChromeProvider.Initialize(Manifest.Chrome); ChromeProvider.Initialize(Manifest.Chrome);
SheetBuilder = new SheetBuilder(TextureChannel.Red); SheetBuilder = new SheetBuilder(TextureChannel.Red);
SpriteLoader = new SpriteLoader(new string[] { ".shp" }, SheetBuilder); SpriteLoader = new SpriteLoader(new string[] { ".shp" }, SheetBuilder);
CursorProvider.Initialize(Manifest.Cursors); CursorProvider.Initialize(Manifest.Cursors);
Palette.Update(new IPaletteModifier[] { });
} }
public Map PrepareMap(string uid) public Map PrepareMap(string uid)