Include all the relevant palettes in the asset browser.

This commit is contained in:
Paul Chote
2015-04-16 19:03:26 +01:00
parent c4a63eee30
commit 8b7453070a
10 changed files with 46 additions and 18 deletions

View File

@@ -8,6 +8,7 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
using OpenRA.FileSystem; using OpenRA.FileSystem;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Traits; using OpenRA.Traits;
@@ -26,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new PaletteFromCurrentTileset(init.World, this); } public object Create(ActorInitializer init) { return new PaletteFromCurrentTileset(init.World, this); }
} }
class PaletteFromCurrentTileset : ILoadsPalettes class PaletteFromCurrentTileset : ILoadsPalettes, IProvidesAssetBrowserPalettes
{ {
readonly World world; readonly World world;
readonly PaletteFromCurrentTilesetInfo info; readonly PaletteFromCurrentTilesetInfo info;
@@ -41,5 +42,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
wr.AddPalette(info.Name, new ImmutablePalette(GlobalFileSystem.Open(world.TileSet.Palette), info.ShadowIndex), info.AllowModifiers); wr.AddPalette(info.Name, new ImmutablePalette(GlobalFileSystem.Open(world.TileSet.Palette), info.ShadowIndex), info.AllowModifiers);
} }
public IEnumerable<string> PaletteNames { get { yield return info.Name; } }
} }
} }

View File

@@ -8,6 +8,7 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
using OpenRA.FileSystem; using OpenRA.FileSystem;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Traits; using OpenRA.Traits;
@@ -29,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new PaletteFromFile(init.World, this); } public object Create(ActorInitializer init) { return new PaletteFromFile(init.World, this); }
} }
class PaletteFromFile : ILoadsPalettes class PaletteFromFile : ILoadsPalettes, IProvidesAssetBrowserPalettes
{ {
readonly World world; readonly World world;
readonly PaletteFromFileInfo info; readonly PaletteFromFileInfo info;
@@ -45,14 +46,14 @@ namespace OpenRA.Mods.Common.Traits
wr.AddPalette(info.Name, new ImmutablePalette(GlobalFileSystem.Open(info.Filename), info.ShadowIndex), info.AllowModifiers); wr.AddPalette(info.Name, new ImmutablePalette(GlobalFileSystem.Open(info.Filename), info.ShadowIndex), info.AllowModifiers);
} }
public string Filename public IEnumerable<string> PaletteNames
{ {
get { return info.Filename; } get
} {
// Only expose the palette if it is available for the shellmap's tileset (which is a requirement for its use).
public string Name if (info.Tileset == null || info.Tileset == world.TileSet.Id)
{ yield return info.Name;
get { return info.Name; } }
} }
} }
} }

View File

@@ -8,6 +8,7 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
@@ -27,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new ShroudPalette(this); } public object Create(ActorInitializer init) { return new ShroudPalette(this); }
} }
class ShroudPalette : ILoadsPalettes class ShroudPalette : ILoadsPalettes, IProvidesAssetBrowserPalettes
{ {
readonly ShroudPaletteInfo info; readonly ShroudPaletteInfo info;
@@ -58,5 +59,7 @@ namespace OpenRA.Mods.Common.Traits
Color.FromArgb(128, 0, 0, 0), Color.FromArgb(128, 0, 0, 0),
Color.FromArgb(64, 0, 0, 0) Color.FromArgb(64, 0, 0, 0)
}; };
public IEnumerable<string> PaletteNames { get { yield return info.Name; } }
} }
} }

View File

@@ -71,4 +71,9 @@ namespace OpenRA.Mods.Common.Traits
CVec DeliveryOffset { get; } CVec DeliveryOffset { get; }
bool AllowDocking { get; } bool AllowDocking { get; }
} }
public interface IProvidesAssetBrowserPalettes
{
IEnumerable<string> PaletteNames { get; }
}
} }

View File

@@ -369,9 +369,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
bool ShowPaletteDropdown(DropDownButtonWidget dropdown, World world) bool ShowPaletteDropdown(DropDownButtonWidget dropdown, World world)
{ {
Func<PaletteFromFile, ScrollItemWidget, ScrollItemWidget> setupItem = (palette, itemTemplate) => Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (name, itemTemplate) =>
{ {
var name = palette.Name;
var item = ScrollItemWidget.Setup(itemTemplate, var item = ScrollItemWidget.Setup(itemTemplate,
() => currentPalette == name, () => currentPalette == name,
() => currentPalette = name); () => currentPalette = name);
@@ -380,7 +379,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return item; return item;
}; };
var palettes = world.WorldActor.TraitsImplementing<PaletteFromFile>(); var palettes = world.WorldActor.TraitsImplementing<IProvidesAssetBrowserPalettes>()
.SelectMany(p => p.PaletteNames);
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 280, palettes, setupItem); dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 280, palettes, setupItem);
return true; return true;
} }

View File

@@ -8,9 +8,11 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
using System.IO; using System.IO;
using OpenRA.FileSystem; using OpenRA.FileSystem;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.D2k.Traits namespace OpenRA.Mods.D2k.Traits
@@ -29,7 +31,7 @@ namespace OpenRA.Mods.D2k.Traits
public object Create(ActorInitializer init) { return new FogPaletteFromR8(this); } public object Create(ActorInitializer init) { return new FogPaletteFromR8(this); }
} }
class FogPaletteFromR8 : ILoadsPalettes class FogPaletteFromR8 : ILoadsPalettes, IProvidesAssetBrowserPalettes
{ {
readonly FogPaletteFromR8Info info; readonly FogPaletteFromR8Info info;
public FogPaletteFromR8(FogPaletteFromR8Info info) { this.info = info; } public FogPaletteFromR8(FogPaletteFromR8Info info) { this.info = info; }
@@ -55,5 +57,7 @@ namespace OpenRA.Mods.D2k.Traits
wr.AddPalette(info.Name, new ImmutablePalette(colors), info.AllowModifiers); wr.AddPalette(info.Name, new ImmutablePalette(colors), info.AllowModifiers);
} }
public IEnumerable<string> PaletteNames { get { yield return info.Name; } }
} }
} }

View File

@@ -8,9 +8,11 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
using System.IO; using System.IO;
using OpenRA.FileSystem; using OpenRA.FileSystem;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.D2k.Traits namespace OpenRA.Mods.D2k.Traits
@@ -29,7 +31,7 @@ namespace OpenRA.Mods.D2k.Traits
public object Create(ActorInitializer init) { return new PaletteFromR8(this); } public object Create(ActorInitializer init) { return new PaletteFromR8(this); }
} }
class PaletteFromR8 : ILoadsPalettes class PaletteFromR8 : ILoadsPalettes, IProvidesAssetBrowserPalettes
{ {
readonly PaletteFromR8Info info; readonly PaletteFromR8Info info;
public PaletteFromR8(PaletteFromR8Info info) { this.info = info; } public PaletteFromR8(PaletteFromR8Info info) { this.info = info; }
@@ -53,5 +55,7 @@ namespace OpenRA.Mods.D2k.Traits
wr.AddPalette(info.Name, new ImmutablePalette(colors), info.AllowModifiers); wr.AddPalette(info.Name, new ImmutablePalette(colors), info.AllowModifiers);
} }
public IEnumerable<string> PaletteNames { get { yield return info.Name; } }
} }
} }

View File

@@ -8,8 +8,10 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.D2k.Traits namespace OpenRA.Mods.D2k.Traits
@@ -35,7 +37,7 @@ namespace OpenRA.Mods.D2k.Traits
public object Create(ActorInitializer init) { return new PaletteFromScaledPalette(this); } public object Create(ActorInitializer init) { return new PaletteFromScaledPalette(this); }
} }
class PaletteFromScaledPalette : ILoadsPalettes class PaletteFromScaledPalette : ILoadsPalettes, IProvidesAssetBrowserPalettes
{ {
readonly PaletteFromScaledPaletteInfo info; readonly PaletteFromScaledPaletteInfo info;
public PaletteFromScaledPalette(PaletteFromScaledPaletteInfo info) { this.info = info; } public PaletteFromScaledPalette(PaletteFromScaledPaletteInfo info) { this.info = info; }
@@ -45,6 +47,8 @@ namespace OpenRA.Mods.D2k.Traits
var remap = new ScaledPaletteRemap(info.Scale, info.Offset); var remap = new ScaledPaletteRemap(info.Scale, info.Offset);
wr.AddPalette(info.Name, new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap), info.AllowModifiers); wr.AddPalette(info.Name, new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap), info.AllowModifiers);
} }
public IEnumerable<string> PaletteNames { get { yield return info.Name; } }
} }
class ScaledPaletteRemap : IPaletteRemap class ScaledPaletteRemap : IPaletteRemap

View File

@@ -65,8 +65,8 @@
<Compile Include="Traits\Render\WithVoxelWalkerBody.cs" /> <Compile Include="Traits\Render\WithVoxelWalkerBody.cs" />
<Compile Include="Traits\Render\WithVoxelUnloadBody.cs" /> <Compile Include="Traits\Render\WithVoxelUnloadBody.cs" />
<Compile Include="Traits\World\VoxelNormalsPalette.cs" /> <Compile Include="Traits\World\VoxelNormalsPalette.cs" />
<Compile Include="Traits\World\ShroudPalette.cs" />
<Compile Include="UtilityCommands\LegacyTilesetImporter.cs" /> <Compile Include="UtilityCommands\LegacyTilesetImporter.cs" />
<Compile Include="Traits\World\TSShroudPalette.cs" />
</ItemGroup> </ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -9,8 +9,10 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.TS.Traits namespace OpenRA.Mods.TS.Traits
@@ -24,7 +26,7 @@ namespace OpenRA.Mods.TS.Traits
public object Create(ActorInitializer init) { return new TSShroudPalette(this); } public object Create(ActorInitializer init) { return new TSShroudPalette(this); }
} }
class TSShroudPalette : ILoadsPalettes class TSShroudPalette : ILoadsPalettes, IProvidesAssetBrowserPalettes
{ {
readonly TSShroudPaletteInfo info; readonly TSShroudPaletteInfo info;
@@ -41,5 +43,7 @@ namespace OpenRA.Mods.TS.Traits
wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => makeColor(i)))); wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => makeColor(i))));
} }
public IEnumerable<string> PaletteNames { get { yield return info.Name; } }
} }
} }