Refactored cursors.yaml to use palettes from rules.
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Graphics
|
namespace OpenRA.Graphics
|
||||||
{
|
{
|
||||||
@@ -26,21 +27,18 @@ namespace OpenRA.Graphics
|
|||||||
var sequenceYaml = MiniYaml.Merge(modData.Manifest.Cursors.Select(
|
var sequenceYaml = MiniYaml.Merge(modData.Manifest.Cursors.Select(
|
||||||
s => MiniYaml.FromStream(fileSystem.Open(s), s)));
|
s => MiniYaml.FromStream(fileSystem.Open(s), s)));
|
||||||
|
|
||||||
var shadowIndex = new int[] { };
|
|
||||||
|
|
||||||
var nodesDict = new MiniYaml(null, sequenceYaml).ToDictionary();
|
var nodesDict = new MiniYaml(null, sequenceYaml).ToDictionary();
|
||||||
if (nodesDict.ContainsKey("ShadowIndex"))
|
|
||||||
{
|
|
||||||
Array.Resize(ref shadowIndex, shadowIndex.Length + 1);
|
|
||||||
Exts.TryParseIntegerInvariant(nodesDict["ShadowIndex"].Value,
|
|
||||||
out shadowIndex[shadowIndex.Length - 1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
var palettes = new Dictionary<string, ImmutablePalette>();
|
// Overwrite previous definitions if there are duplicates
|
||||||
foreach (var p in nodesDict["Palettes"].Nodes)
|
var pals = new Dictionary<string, IProvidesCursorPaletteInfo>();
|
||||||
palettes.Add(p.Key, new ImmutablePalette(fileSystem.Open(p.Value.Value), shadowIndex));
|
foreach (var p in modData.DefaultRules.Actors["world"].TraitInfos<IProvidesCursorPaletteInfo>())
|
||||||
|
if (p.Palette != null)
|
||||||
|
pals[p.Palette] = p;
|
||||||
|
|
||||||
Palettes = palettes.AsReadOnly();
|
Palettes = nodesDict["Cursors"].Nodes.Select(n => n.Value.Value)
|
||||||
|
.Distinct()
|
||||||
|
.ToDictionary(p => p, p => pals[p].ReadPalette(modData.DefaultFileSystem))
|
||||||
|
.AsReadOnly();
|
||||||
|
|
||||||
var frameCache = new FrameCache(fileSystem, modData.SpriteLoaders);
|
var frameCache = new FrameCache(fileSystem, modData.SpriteLoaders);
|
||||||
var cursors = new Dictionary<string, CursorSequence>();
|
var cursors = new Dictionary<string, CursorSequence>();
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using OpenRA.Activities;
|
using OpenRA.Activities;
|
||||||
|
using OpenRA.FileSystem;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Network;
|
using OpenRA.Network;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
@@ -271,6 +272,13 @@ namespace OpenRA.Traits
|
|||||||
IEnumerable<Rectangle> ModifyScreenBounds(Actor self, WorldRenderer wr, IEnumerable<Rectangle> r);
|
IEnumerable<Rectangle> ModifyScreenBounds(Actor self, WorldRenderer wr, IEnumerable<Rectangle> r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RequireExplicitImplementation]
|
||||||
|
public interface IProvidesCursorPaletteInfo : ITraitInfoInterface
|
||||||
|
{
|
||||||
|
string Palette { get; }
|
||||||
|
ImmutablePalette ReadPalette(IReadOnlyFileSystem fileSystem);
|
||||||
|
}
|
||||||
|
|
||||||
public interface ILoadsPalettes { void LoadPalettes(WorldRenderer wr); }
|
public interface ILoadsPalettes { void LoadPalettes(WorldRenderer wr); }
|
||||||
public interface ILoadsPlayerPalettes { void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor playerColor, bool replaceExisting); }
|
public interface ILoadsPlayerPalettes { void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor playerColor, bool replaceExisting); }
|
||||||
public interface IPaletteModifier { void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> b); }
|
public interface IPaletteModifier { void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> b); }
|
||||||
|
|||||||
@@ -10,13 +10,14 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using OpenRA.FileSystem;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Load VGA palette (.pal) registers.")]
|
[Desc("Load VGA palette (.pal) registers.")]
|
||||||
class PaletteFromFileInfo : ITraitInfo
|
class PaletteFromFileInfo : ITraitInfo, IProvidesCursorPaletteInfo
|
||||||
{
|
{
|
||||||
[FieldLoader.Require, PaletteDefinition]
|
[FieldLoader.Require, PaletteDefinition]
|
||||||
[Desc("internal palette name")]
|
[Desc("internal palette name")]
|
||||||
@@ -34,7 +35,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public readonly bool AllowModifiers = true;
|
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); }
|
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
|
class PaletteFromFile : ILoadsPalettes, IProvidesAssetBrowserPalettes
|
||||||
@@ -50,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public void LoadPalettes(WorldRenderer wr)
|
public void LoadPalettes(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
if (info.Tileset == null || info.Tileset.ToLowerInvariant() == world.Map.Tileset.ToLowerInvariant())
|
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
|
public IEnumerable<string> PaletteNames
|
||||||
|
|||||||
@@ -11,13 +11,14 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.FileSystem;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Load a PNG and use its embedded palette.")]
|
[Desc("Load a PNG and use its embedded palette.")]
|
||||||
class PaletteFromPngInfo : ITraitInfo
|
class PaletteFromPngInfo : ITraitInfo, IProvidesCursorPaletteInfo
|
||||||
{
|
{
|
||||||
[FieldLoader.Require, PaletteDefinition]
|
[FieldLoader.Require, PaletteDefinition]
|
||||||
[Desc("Internal palette name")]
|
[Desc("Internal palette name")]
|
||||||
@@ -35,7 +36,23 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public readonly bool AllowModifiers = true;
|
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 PaletteFromPng(init.World, this); }
|
public object Create(ActorInitializer init) { return new PaletteFromPng(init.World, this); }
|
||||||
|
|
||||||
|
string IProvidesCursorPaletteInfo.Palette { get { return CursorPalette ? Name : null; } }
|
||||||
|
|
||||||
|
ImmutablePalette IProvidesCursorPaletteInfo.ReadPalette(IReadOnlyFileSystem fileSystem)
|
||||||
|
{
|
||||||
|
var png = new Png(fileSystem.Open(Filename));
|
||||||
|
var colors = new uint[Palette.Size];
|
||||||
|
|
||||||
|
for (var i = 0; i < png.Palette.Length; i++)
|
||||||
|
colors[i] = (uint)png.Palette[i].ToArgb();
|
||||||
|
|
||||||
|
return new ImmutablePalette(colors);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PaletteFromPng : ILoadsPalettes, IProvidesAssetBrowserPalettes
|
class PaletteFromPng : ILoadsPalettes, IProvidesAssetBrowserPalettes
|
||||||
@@ -53,13 +70,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (info.Tileset != null && info.Tileset.ToLowerInvariant() != world.Map.Tileset.ToLowerInvariant())
|
if (info.Tileset != null && info.Tileset.ToLowerInvariant() != world.Map.Tileset.ToLowerInvariant())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var png = new Png(world.Map.Open(info.Filename));
|
wr.AddPalette(info.Name, ((IProvidesCursorPaletteInfo)info).ReadPalette(world.Map), info.AllowModifiers);
|
||||||
var colors = new uint[Palette.Size];
|
|
||||||
|
|
||||||
for (var i = 0; i < png.Palette.Length; i++)
|
|
||||||
colors[i] = (uint)png.Palette[i].ToArgb();
|
|
||||||
|
|
||||||
wr.AddPalette(info.Name, new ImmutablePalette(colors), info.AllowModifiers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> PaletteNames
|
public IEnumerable<string> PaletteNames
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
Palettes:
|
|
||||||
cursor: temperat.pal
|
|
||||||
|
|
||||||
Cursors:
|
Cursors:
|
||||||
mouse2.shp: cursor
|
mouse2.shp: chrome
|
||||||
scroll-t:
|
scroll-t:
|
||||||
Start: 1
|
Start: 1
|
||||||
Y: -12
|
Y: -12
|
||||||
@@ -139,7 +136,7 @@ Cursors:
|
|||||||
sell-vehicle:
|
sell-vehicle:
|
||||||
Start: 154
|
Start: 154
|
||||||
Length: 24
|
Length: 24
|
||||||
mouse3.shp: cursor
|
mouse3.shp: chrome
|
||||||
default:
|
default:
|
||||||
Start: 0
|
Start: 0
|
||||||
X: -16
|
X: -16
|
||||||
@@ -151,7 +148,7 @@ Cursors:
|
|||||||
deploy-blocked:
|
deploy-blocked:
|
||||||
Start: 1
|
Start: 1
|
||||||
Length: 1
|
Length: 1
|
||||||
mouse4.shp: cursor
|
mouse4.shp: chrome
|
||||||
move:
|
move:
|
||||||
Start: 0
|
Start: 0
|
||||||
Length: 8
|
Length: 8
|
||||||
@@ -191,14 +188,14 @@ Cursors:
|
|||||||
assaultmove-blocked-minimap:
|
assaultmove-blocked-minimap:
|
||||||
Start: 40
|
Start: 40
|
||||||
Length: 1
|
Length: 1
|
||||||
mouse5.shp: cursor
|
mouse5.shp: chrome
|
||||||
guard:
|
guard:
|
||||||
Start: 0
|
Start: 0
|
||||||
Length: 8
|
Length: 8
|
||||||
guard-minimap:
|
guard-minimap:
|
||||||
Start: 8
|
Start: 8
|
||||||
Length: 8
|
Length: 8
|
||||||
mouse6.shp: cursor
|
mouse6.shp: chrome
|
||||||
goldwrench:
|
goldwrench:
|
||||||
Start: 0
|
Start: 0
|
||||||
Length: 3
|
Length: 3
|
||||||
@@ -229,7 +226,7 @@ Cursors:
|
|||||||
enter-blocked-minimap:
|
enter-blocked-minimap:
|
||||||
Start: 17
|
Start: 17
|
||||||
Length: 1
|
Length: 1
|
||||||
mouse7.shp: cursor
|
mouse7.shp: chrome
|
||||||
attackoutsiderange:
|
attackoutsiderange:
|
||||||
Start: 0
|
Start: 0
|
||||||
Length: 8
|
Length: 8
|
||||||
|
|||||||
@@ -54,6 +54,7 @@
|
|||||||
Filename: temperat.pal
|
Filename: temperat.pal
|
||||||
ShadowIndex: 3
|
ShadowIndex: 3
|
||||||
AllowModifiers: false
|
AllowModifiers: false
|
||||||
|
CursorPalette: true
|
||||||
PaletteFromFile@beaconposter:
|
PaletteFromFile@beaconposter:
|
||||||
Name: beaconposter
|
Name: beaconposter
|
||||||
Filename: temperat.pal
|
Filename: temperat.pal
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
ShadowIndex: 1
|
|
||||||
|
|
||||||
Palettes:
|
|
||||||
mouse: PALETTE.BIN
|
|
||||||
|
|
||||||
Cursors:
|
Cursors:
|
||||||
MOUSE.R8: mouse
|
MOUSE.R8: d2k
|
||||||
scroll-t:
|
scroll-t:
|
||||||
Start: 112
|
Start: 112
|
||||||
X: 24
|
X: 24
|
||||||
@@ -284,7 +279,7 @@ Cursors:
|
|||||||
Length: 8
|
Length: 8
|
||||||
X: 24
|
X: 24
|
||||||
Y: 24
|
Y: 24
|
||||||
nopower.shp: mouse
|
nopower.shp: d2k
|
||||||
powerdown-blocked:
|
powerdown-blocked:
|
||||||
Start: 0
|
Start: 0
|
||||||
Length: 1
|
Length: 1
|
||||||
@@ -295,7 +290,7 @@ Cursors:
|
|||||||
Length: 3
|
Length: 3
|
||||||
X: 12
|
X: 12
|
||||||
Y: 12
|
Y: 12
|
||||||
attackmove.shp: mouse
|
attackmove.shp: d2k
|
||||||
attackmove:
|
attackmove:
|
||||||
Start: 0
|
Start: 0
|
||||||
Length: 8
|
Length: 8
|
||||||
@@ -314,7 +309,7 @@ Cursors:
|
|||||||
Start: 8
|
Start: 8
|
||||||
X: -2
|
X: -2
|
||||||
Y: -2
|
Y: -2
|
||||||
assaultmove.shp: mouse
|
assaultmove.shp: d2k
|
||||||
assaultmove:
|
assaultmove:
|
||||||
Start: 0
|
Start: 0
|
||||||
Length: 8
|
Length: 8
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
Name: d2k
|
Name: d2k
|
||||||
Filename: PALETTE.BIN
|
Filename: PALETTE.BIN
|
||||||
ShadowIndex: 1
|
ShadowIndex: 1
|
||||||
|
CursorPalette: true
|
||||||
PaletteFromFile@chrome:
|
PaletteFromFile@chrome:
|
||||||
Name: chrome
|
Name: chrome
|
||||||
Filename: PALETTE.BIN
|
Filename: PALETTE.BIN
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
Palettes:
|
|
||||||
cursor: cursor.pal
|
|
||||||
|
|
||||||
Cursors:
|
Cursors:
|
||||||
cursor.shp: cursor
|
cursor.shp: cursor
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ Packages:
|
|||||||
./mods/modcontent: modcontent
|
./mods/modcontent: modcontent
|
||||||
./mods/common: common
|
./mods/common: common
|
||||||
|
|
||||||
|
Rules:
|
||||||
|
modcontent|rules.yaml
|
||||||
|
|
||||||
Cursors:
|
Cursors:
|
||||||
modcontent|cursors.yaml
|
modcontent|cursors.yaml
|
||||||
|
|
||||||
|
|||||||
5
mods/modcontent/rules.yaml
Normal file
5
mods/modcontent/rules.yaml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
World:
|
||||||
|
PaletteFromFile:
|
||||||
|
Name: cursor
|
||||||
|
Filename: cursor.pal
|
||||||
|
CursorPalette: true
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
Palettes:
|
|
||||||
cursor: temperat.pal
|
|
||||||
|
|
||||||
Cursors:
|
Cursors:
|
||||||
mouse.shp: cursor
|
mouse.shp: chrome
|
||||||
scroll-t:
|
scroll-t:
|
||||||
Start: 1
|
Start: 1
|
||||||
Y: -7
|
Y: -7
|
||||||
@@ -203,14 +200,14 @@ Cursors:
|
|||||||
sell2:
|
sell2:
|
||||||
Start: 148
|
Start: 148
|
||||||
Length: 12
|
Length: 12
|
||||||
nopower.shp: cursor
|
nopower.shp: chrome
|
||||||
powerdown-blocked:
|
powerdown-blocked:
|
||||||
Start: 0
|
Start: 0
|
||||||
Length: 1
|
Length: 1
|
||||||
powerdown:
|
powerdown:
|
||||||
Start: 1
|
Start: 1
|
||||||
Length: 3
|
Length: 3
|
||||||
attackmove.shp: cursor
|
attackmove.shp: chrome
|
||||||
attackmove:
|
attackmove:
|
||||||
Start: 0
|
Start: 0
|
||||||
Length: 4
|
Length: 4
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
Filename: temperat.pal
|
Filename: temperat.pal
|
||||||
ShadowIndex: 3
|
ShadowIndex: 3
|
||||||
AllowModifiers: false
|
AllowModifiers: false
|
||||||
|
CursorPalette: true
|
||||||
PaletteFromFile@effect:
|
PaletteFromFile@effect:
|
||||||
Name: effect
|
Name: effect
|
||||||
Filename: temperat.pal
|
Filename: temperat.pal
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
Palettes:
|
|
||||||
cursor: mousepal.pal
|
|
||||||
|
|
||||||
Cursors:
|
Cursors:
|
||||||
mouse.shp: cursor
|
mouse.shp: mouse
|
||||||
scroll-t:
|
scroll-t:
|
||||||
Start: 2
|
Start: 2
|
||||||
Y: -19
|
Y: -19
|
||||||
@@ -218,7 +215,7 @@ Cursors:
|
|||||||
Start: 385
|
Start: 385
|
||||||
joystick-tl-blocked:
|
joystick-tl-blocked:
|
||||||
Start: 386
|
Start: 386
|
||||||
attackmove.shp: cursor
|
attackmove.shp: mouse
|
||||||
attackmove:
|
attackmove:
|
||||||
Start: 0
|
Start: 0
|
||||||
Length: 10
|
Length: 10
|
||||||
@@ -231,7 +228,7 @@ Cursors:
|
|||||||
attackmove-minimap-blocked:
|
attackmove-minimap-blocked:
|
||||||
Start: 21
|
Start: 21
|
||||||
Length: 1
|
Length: 1
|
||||||
assaultmove.shp: cursor
|
assaultmove.shp: mouse
|
||||||
assaultmove:
|
assaultmove:
|
||||||
Start: 0
|
Start: 0
|
||||||
Length: 10
|
Length: 10
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
PaletteFromFile@mouse:
|
PaletteFromFile@mouse:
|
||||||
Name: mouse
|
Name: mouse
|
||||||
Filename: mousepal.pal
|
Filename: mousepal.pal
|
||||||
|
CursorPalette: true
|
||||||
PaletteFromFile@terraintem:
|
PaletteFromFile@terraintem:
|
||||||
Name: terrain
|
Name: terrain
|
||||||
Tileset: TEMPERATE
|
Tileset: TEMPERATE
|
||||||
|
|||||||
Reference in New Issue
Block a user