Rework player palette loading.

This commit is contained in:
Paul Chote
2015-05-09 22:09:23 +01:00
parent 1d835edfca
commit 7eae157ad8
21 changed files with 375 additions and 333 deletions

View File

@@ -41,6 +41,9 @@ namespace OpenRA.Graphics
foreach (var pal in world.TraitDict.ActorsWithTrait<ILoadsPalettes>())
pal.Trait.LoadPalettes(this);
foreach (var p in world.Players)
UpdatePalettesForPlayer(p.InternalName, p.Color, false);
palette.Initialize();
Theater = new Theater(world.TileSet);
@@ -49,6 +52,12 @@ namespace OpenRA.Graphics
devTrait = Exts.Lazy(() => world.LocalPlayer != null ? world.LocalPlayer.PlayerActor.Trait<DeveloperMode>() : null);
}
public void UpdatePalettesForPlayer(string internalName, HSLColor color, bool replaceExisting)
{
foreach (var pal in World.WorldActor.TraitsImplementing<ILoadsPlayerPalettes>())
pal.LoadPlayerPalettes(this, internalName, color, replaceExisting);
}
PaletteReference CreatePaletteReference(string name)
{
var pal = palette.GetPalette(name);
@@ -56,9 +65,22 @@ namespace OpenRA.Graphics
}
public PaletteReference Palette(string name) { return palettes.GetOrAdd(name, createPaletteReference); }
public void AddPalette(string name, ImmutablePalette pal) { palette.AddPalette(name, pal, false); }
public void AddPalette(string name, ImmutablePalette pal, bool allowModifiers) { palette.AddPalette(name, pal, allowModifiers); }
public void ReplacePalette(string name, IPalette pal) { palette.ReplacePalette(name, pal); palettes[name].Palette = pal; }
public void AddPalette(string name, ImmutablePalette pal, bool allowModifiers = false, bool allowOverwrite = false)
{
if (allowOverwrite && palette.Contains(name))
ReplacePalette(name, pal);
else
palette.AddPalette(name, pal, allowModifiers);
}
public void ReplacePalette(string name, IPalette pal)
{
palette.ReplacePalette(name, pal);
// Update cached PlayerReference if one exists
if (palettes.ContainsKey(name))
palettes[name].Palette = pal;
}
List<IFinalizedRenderable> GenerateRenderables()
{