Refactored cursors.yaml to use palettes from rules.

This commit is contained in:
Andre Mohren
2018-09-29 19:17:51 +02:00
committed by abcdefg30
parent c71f97e2c6
commit 450dc70375
15 changed files with 78 additions and 55 deletions

View File

@@ -10,13 +10,14 @@
#endregion
using System.Collections.Generic;
using OpenRA.FileSystem;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Load VGA palette (.pal) registers.")]
class PaletteFromFileInfo : ITraitInfo
class PaletteFromFileInfo : ITraitInfo, IProvidesCursorPaletteInfo
{
[FieldLoader.Require, PaletteDefinition]
[Desc("internal palette name")]
@@ -34,7 +35,17 @@ namespace OpenRA.Mods.Common.Traits
public readonly bool AllowModifiers = true;
[Desc("Whether this palette is available for cursors.")]
public readonly bool CursorPalette = false;
public object Create(ActorInitializer init) { return new PaletteFromFile(init.World, this); }
string IProvidesCursorPaletteInfo.Palette { get { return CursorPalette ? Name : null; } }
ImmutablePalette IProvidesCursorPaletteInfo.ReadPalette(IReadOnlyFileSystem fileSystem)
{
return new ImmutablePalette(fileSystem.Open(Filename), ShadowIndex);
}
}
class PaletteFromFile : ILoadsPalettes, IProvidesAssetBrowserPalettes
@@ -50,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits
public void LoadPalettes(WorldRenderer wr)
{
if (info.Tileset == null || info.Tileset.ToLowerInvariant() == world.Map.Tileset.ToLowerInvariant())
wr.AddPalette(info.Name, new ImmutablePalette(world.Map.Open(info.Filename), info.ShadowIndex), info.AllowModifiers);
wr.AddPalette(info.Name, ((IProvidesCursorPaletteInfo)info).ReadPalette(world.Map), info.AllowModifiers);
}
public IEnumerable<string> PaletteNames