Rework player palette loading.
This commit is contained in:
@@ -30,6 +30,11 @@ namespace OpenRA.Graphics
|
||||
readOnlyModifiablePalettes = modifiablePalettes.AsReadOnly();
|
||||
}
|
||||
|
||||
public bool Contains(string name)
|
||||
{
|
||||
return modifiablePalettes.ContainsKey(name) || palettes.ContainsKey(name);
|
||||
}
|
||||
|
||||
public IPalette GetPalette(string name)
|
||||
{
|
||||
MutablePalette mutable;
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
@@ -26,24 +27,23 @@ namespace OpenRA.Traits
|
||||
[Desc("Allow palette modifiers to change the palette.")]
|
||||
public readonly bool AllowModifiers = true;
|
||||
|
||||
public object Create(ActorInitializer init) { return new PlayerColorPalette(init.Self.Owner, this); }
|
||||
public object Create(ActorInitializer init) { return new PlayerColorPalette(this); }
|
||||
}
|
||||
|
||||
public class PlayerColorPalette : ILoadsPalettes
|
||||
public class PlayerColorPalette : ILoadsPlayerPalettes
|
||||
{
|
||||
readonly Player owner;
|
||||
readonly PlayerColorPaletteInfo info;
|
||||
|
||||
public PlayerColorPalette(Player owner, PlayerColorPaletteInfo info)
|
||||
public PlayerColorPalette(PlayerColorPaletteInfo info)
|
||||
{
|
||||
this.owner = owner;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void LoadPalettes(WorldRenderer wr)
|
||||
public void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor color, bool replaceExisting)
|
||||
{
|
||||
var remap = new PlayerColorRemap(info.RemapIndex, owner.Color, info.Ramp);
|
||||
wr.AddPalette(info.BaseName + owner.InternalName, new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap), info.AllowModifiers);
|
||||
var remap = new PlayerColorRemap(info.RemapIndex, color, info.Ramp);
|
||||
var pal = new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap);
|
||||
wr.AddPalette(info.BaseName + playerName, pal, info.AllowModifiers, replaceExisting);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
@@ -20,24 +21,23 @@ namespace OpenRA.Traits
|
||||
[Desc("The prefix for the resulting player palettes")]
|
||||
public readonly string BaseName = "highlight";
|
||||
|
||||
public object Create(ActorInitializer init) { return new PlayerHighlightPalette(init.Self.Owner, this); }
|
||||
public object Create(ActorInitializer init) { return new PlayerHighlightPalette(this); }
|
||||
}
|
||||
|
||||
public class PlayerHighlightPalette : ILoadsPalettes
|
||||
public class PlayerHighlightPalette : ILoadsPlayerPalettes
|
||||
{
|
||||
readonly Player owner;
|
||||
readonly PlayerHighlightPaletteInfo info;
|
||||
|
||||
public PlayerHighlightPalette(Player owner, PlayerHighlightPaletteInfo info)
|
||||
public PlayerHighlightPalette(PlayerHighlightPaletteInfo info)
|
||||
{
|
||||
this.owner = owner;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void LoadPalettes(WorldRenderer wr)
|
||||
public void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor color, bool replaceExisting)
|
||||
{
|
||||
var argb = (uint)Color.FromArgb(128, owner.Color.RGB).ToArgb();
|
||||
wr.AddPalette(info.BaseName + owner.InternalName, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => i == 0 ? 0 : argb)));
|
||||
var argb = (uint)Color.FromArgb(128, color.RGB).ToArgb();
|
||||
var pal = new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => i == 0 ? 0 : argb));
|
||||
wr.AddPalette(info.BaseName + playerName, pal, false, replaceExisting);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +194,7 @@ namespace OpenRA.Traits
|
||||
public interface IInaccuracyModifier { int GetInaccuracyModifier(); }
|
||||
public interface IPowerModifier { int GetPowerModifier(); }
|
||||
public interface ILoadsPalettes { void LoadPalettes(WorldRenderer wr); }
|
||||
public interface ILoadsPlayerPalettes { void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor playerColor, bool replaceExisting); }
|
||||
public interface IPaletteModifier { void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> b); }
|
||||
public interface IPips { IEnumerable<PipType> GetPips(Actor self); }
|
||||
public interface ITags { IEnumerable<TagType> GetTags(); }
|
||||
|
||||
Reference in New Issue
Block a user