diff --git a/OpenRA.Game/Graphics/CursorProvider.cs b/OpenRA.Game/Graphics/CursorProvider.cs index 4184facd60..823e231c41 100644 --- a/OpenRA.Game/Graphics/CursorProvider.cs +++ b/OpenRA.Game/Graphics/CursorProvider.cs @@ -19,6 +19,7 @@ namespace OpenRA.Graphics { public static class CursorProvider { + public static Dictionary Palettes { get; private set; } static Dictionary cursors; public static void Initialize(string[] sequenceFiles) @@ -28,13 +29,14 @@ namespace OpenRA.Graphics int[] ShadowIndex = { }; if (sequences.NodesDict.ContainsKey("ShadowIndex")) - { - Array.Resize(ref ShadowIndex, ShadowIndex.Length + 1); - ShadowIndex[ShadowIndex.Length - 1] = Convert.ToInt32(sequences.NodesDict["ShadowIndex"].Value); - } + { + Array.Resize(ref ShadowIndex, ShadowIndex.Length + 1); + ShadowIndex[ShadowIndex.Length - 1] = Convert.ToInt32(sequences.NodesDict["ShadowIndex"].Value); + } + Palettes = new Dictionary(); 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) LoadSequencesForCursor(s.Key, s.Value); diff --git a/OpenRA.Game/Graphics/TerrainRenderer.cs b/OpenRA.Game/Graphics/TerrainRenderer.cs index 573d480cd1..317820217a 100644 --- a/OpenRA.Game/Graphics/TerrainRenderer.cs +++ b/OpenRA.Game/Graphics/TerrainRenderer.cs @@ -39,7 +39,7 @@ namespace OpenRA.Graphics 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 i = map.Bounds.Left; i < map.Bounds.Right; i++ ) diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index f5881d2e1e..4a15d081ac 100755 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -133,7 +133,7 @@ namespace OpenRA.Graphics renderer.SpriteRenderer.DrawSprite(cursorSprite, Viewport.LastMousePos - cursorSequence.Hotspot, - Game.modData.Palette.GetPaletteIndex(cursorSequence.Palette), + wr.Palette(cursorSequence.Palette).Index, cursorSprite.size); } diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 45ba653799..c590105a92 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -41,11 +41,17 @@ namespace OpenRA.Graphics internal WorldRenderer(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(CreatePaletteReference); foreach (var pal in world.traitDict.ActorsWithTraitMultiple(world)) pal.Trait.InitPalette( this ); + // Generate initial palette texture + palette.Update(new IPaletteModifier[] {}); + terrainRenderer = new TerrainRenderer(world, this); shroudRenderer = new ShroudRenderer(world); } diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index c8770da6b5..c614d4604b 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -28,7 +28,6 @@ namespace OpenRA public ILoadScreen LoadScreen = null; public SheetBuilder SheetBuilder; public SpriteLoader SpriteLoader; - public HardwarePalette Palette { get; private set; } public ModData( params string[] mods ) { @@ -51,13 +50,11 @@ namespace OpenRA AvailableMaps = FindMaps(Manifest.Mods); - Palette = new HardwarePalette(); ChromeMetrics.Initialize(Manifest.ChromeMetrics); ChromeProvider.Initialize(Manifest.Chrome); SheetBuilder = new SheetBuilder(TextureChannel.Red); SpriteLoader = new SpriteLoader(new string[] { ".shp" }, SheetBuilder); CursorProvider.Initialize(Manifest.Cursors); - Palette.Update(new IPaletteModifier[] { }); } public Map PrepareMap(string uid)