Merge pull request #7968 from pchote/ts-tileset-depth
Load depth data from tmp(ts) sprites.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
@@ -26,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public object Create(ActorInitializer init) { return new PaletteFromCurrentTileset(init.World, this); }
|
||||
}
|
||||
|
||||
class PaletteFromCurrentTileset : ILoadsPalettes
|
||||
class PaletteFromCurrentTileset : ILoadsPalettes, IProvidesAssetBrowserPalettes
|
||||
{
|
||||
readonly World world;
|
||||
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);
|
||||
}
|
||||
|
||||
public IEnumerable<string> PaletteNames { get { yield return info.Name; } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
@@ -29,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public object Create(ActorInitializer init) { return new PaletteFromFile(init.World, this); }
|
||||
}
|
||||
|
||||
class PaletteFromFile : ILoadsPalettes
|
||||
class PaletteFromFile : ILoadsPalettes, IProvidesAssetBrowserPalettes
|
||||
{
|
||||
readonly World world;
|
||||
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);
|
||||
}
|
||||
|
||||
public string Filename
|
||||
public IEnumerable<string> PaletteNames
|
||||
{
|
||||
get { return info.Filename; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return info.Name; }
|
||||
get
|
||||
{
|
||||
// Only expose the palette if it is available for the shellmap's tileset (which is a requirement for its use).
|
||||
if (info.Tileset == null || info.Tileset == world.TileSet.Id)
|
||||
yield return info.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
@@ -27,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public object Create(ActorInitializer init) { return new ShroudPalette(this); }
|
||||
}
|
||||
|
||||
class ShroudPalette : ILoadsPalettes
|
||||
class ShroudPalette : ILoadsPalettes, IProvidesAssetBrowserPalettes
|
||||
{
|
||||
readonly ShroudPaletteInfo info;
|
||||
|
||||
@@ -58,5 +59,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Color.FromArgb(128, 0, 0, 0),
|
||||
Color.FromArgb(64, 0, 0, 0)
|
||||
};
|
||||
|
||||
public IEnumerable<string> PaletteNames { get { yield return info.Name; } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,4 +79,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
CVec DeliveryOffset { get; }
|
||||
bool AllowDocking { get; }
|
||||
}
|
||||
|
||||
public interface IProvidesAssetBrowserPalettes
|
||||
{
|
||||
IEnumerable<string> PaletteNames { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,9 +369,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
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,
|
||||
() => currentPalette == name,
|
||||
() => currentPalette = name);
|
||||
@@ -380,7 +379,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,9 +8,11 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.D2k.Traits
|
||||
@@ -29,7 +31,7 @@ namespace OpenRA.Mods.D2k.Traits
|
||||
public object Create(ActorInitializer init) { return new FogPaletteFromR8(this); }
|
||||
}
|
||||
|
||||
class FogPaletteFromR8 : ILoadsPalettes
|
||||
class FogPaletteFromR8 : ILoadsPalettes, IProvidesAssetBrowserPalettes
|
||||
{
|
||||
readonly FogPaletteFromR8Info 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);
|
||||
}
|
||||
|
||||
public IEnumerable<string> PaletteNames { get { yield return info.Name; } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,11 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.D2k.Traits
|
||||
@@ -29,7 +31,7 @@ namespace OpenRA.Mods.D2k.Traits
|
||||
public object Create(ActorInitializer init) { return new PaletteFromR8(this); }
|
||||
}
|
||||
|
||||
class PaletteFromR8 : ILoadsPalettes
|
||||
class PaletteFromR8 : ILoadsPalettes, IProvidesAssetBrowserPalettes
|
||||
{
|
||||
readonly PaletteFromR8Info 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);
|
||||
}
|
||||
|
||||
public IEnumerable<string> PaletteNames { get { yield return info.Name; } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,10 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.D2k.Traits
|
||||
@@ -35,7 +37,7 @@ namespace OpenRA.Mods.D2k.Traits
|
||||
public object Create(ActorInitializer init) { return new PaletteFromScaledPalette(this); }
|
||||
}
|
||||
|
||||
class PaletteFromScaledPalette : ILoadsPalettes
|
||||
class PaletteFromScaledPalette : ILoadsPalettes, IProvidesAssetBrowserPalettes
|
||||
{
|
||||
readonly PaletteFromScaledPaletteInfo 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);
|
||||
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
|
||||
|
||||
@@ -66,8 +66,8 @@
|
||||
<Compile Include="Traits\Render\WithVoxelUnloadBody.cs" />
|
||||
<Compile Include="Traits\Render\WithVoxelWaterBody.cs" />
|
||||
<Compile Include="Traits\World\VoxelNormalsPalette.cs" />
|
||||
<Compile Include="Traits\World\ShroudPalette.cs" />
|
||||
<Compile Include="UtilityCommands\LegacyTilesetImporter.cs" />
|
||||
<Compile Include="Traits\World\TSShroudPalette.cs" />
|
||||
</ItemGroup>
|
||||
<!-- 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.
|
||||
|
||||
@@ -17,12 +17,29 @@ namespace OpenRA.Mods.TS.SpriteLoaders
|
||||
{
|
||||
public class TmpTSLoader : ISpriteLoader
|
||||
{
|
||||
class TmpTSDepthFrame : ISpriteFrame
|
||||
{
|
||||
readonly TmpTSFrame parent;
|
||||
|
||||
public Size Size { get { return parent.Size; } }
|
||||
public Size FrameSize { get { return Size; } }
|
||||
public float2 Offset { get { return parent.Offset; } }
|
||||
public byte[] Data { get { return parent.DepthData; } }
|
||||
public bool DisableExportPadding { get { return false; } }
|
||||
|
||||
public TmpTSDepthFrame(TmpTSFrame parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
||||
|
||||
class TmpTSFrame : ISpriteFrame
|
||||
{
|
||||
public Size Size { get; private set; }
|
||||
public Size FrameSize { get { return Size; } }
|
||||
public float2 Offset { get; private set; }
|
||||
public byte[] Data { get; set; }
|
||||
public byte[] DepthData { get; set; }
|
||||
public bool DisableExportPadding { get { return false; } }
|
||||
|
||||
public TmpTSFrame(Stream s, Size size, int u, int v)
|
||||
@@ -55,20 +72,10 @@ namespace OpenRA.Mods.TS.SpriteLoaders
|
||||
s.Position += 12;
|
||||
|
||||
Data = new byte[bounds.Width * bounds.Height];
|
||||
DepthData = new byte[bounds.Width * bounds.Height];
|
||||
|
||||
// Unpack tile data
|
||||
var width = 4;
|
||||
for (var j = 0; j < size.Height; j++)
|
||||
{
|
||||
var start = (j - bounds.Y) * bounds.Width + (size.Width - width) / 2 - bounds.X;
|
||||
for (var i = 0; i < width; i++)
|
||||
Data[start + i] = s.ReadUInt8();
|
||||
|
||||
width += (j < size.Height / 2 - 1 ? 1 : -1) * 4;
|
||||
}
|
||||
|
||||
// TODO: Load Z-data once the renderer can handle it
|
||||
s.Position += size.Width * size.Height / 2;
|
||||
UnpackTileData(s, Data, size, bounds);
|
||||
UnpackTileData(s, DepthData, size, bounds);
|
||||
|
||||
if ((flags & 0x01) == 0)
|
||||
return;
|
||||
@@ -84,12 +91,39 @@ namespace OpenRA.Mods.TS.SpriteLoaders
|
||||
Data[start + i] = extra;
|
||||
}
|
||||
}
|
||||
|
||||
// Extra data depth
|
||||
for (var j = 0; j < extraHeight; j++)
|
||||
{
|
||||
var start = (j + extraY - bounds.Y) * bounds.Width + extraX - bounds.X;
|
||||
for (var i = 0; i < extraWidth; i++)
|
||||
{
|
||||
var extra = s.ReadUInt8();
|
||||
|
||||
// XCC source indicates that there are only 32 valid values
|
||||
if (extra < 32)
|
||||
DepthData[start + i] = extra;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
Data = new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
static void UnpackTileData(Stream s, byte[] data, Size size, Rectangle frameBounds)
|
||||
{
|
||||
var width = 4;
|
||||
for (var j = 0; j < size.Height; j++)
|
||||
{
|
||||
var start = (j - frameBounds.Y) * frameBounds.Width + (size.Width - width) / 2 - frameBounds.X;
|
||||
for (var i = 0; i < width; i++)
|
||||
data[start + i] = s.ReadUInt8();
|
||||
|
||||
width += (j < size.Height / 2 - 1 ? 1 : -1) * 4;
|
||||
}
|
||||
}
|
||||
|
||||
bool IsTmpTS(Stream s)
|
||||
{
|
||||
var start = s.Position;
|
||||
@@ -115,7 +149,7 @@ namespace OpenRA.Mods.TS.SpriteLoaders
|
||||
return test == sx * sy / 2 + 52;
|
||||
}
|
||||
|
||||
TmpTSFrame[] ParseFrames(Stream s)
|
||||
ISpriteFrame[] ParseFrames(Stream s)
|
||||
{
|
||||
var start = s.Position;
|
||||
var templateWidth = s.ReadUInt32();
|
||||
@@ -127,7 +161,9 @@ namespace OpenRA.Mods.TS.SpriteLoaders
|
||||
for (var i = 0; i < offsets.Length; i++)
|
||||
offsets[i] = s.ReadUInt32();
|
||||
|
||||
var tiles = new TmpTSFrame[offsets.Length];
|
||||
// Depth information are stored as a second set of frames (like split shadows)
|
||||
var stride = offsets.Length;
|
||||
var tiles = new ISpriteFrame[stride * 2];
|
||||
|
||||
for (var j = 0; j < templateHeight; j++)
|
||||
{
|
||||
@@ -135,7 +171,11 @@ namespace OpenRA.Mods.TS.SpriteLoaders
|
||||
{
|
||||
var k = j * templateWidth + i;
|
||||
s.Position = offsets[k];
|
||||
tiles[k] = new TmpTSFrame(s, size, i, j);
|
||||
|
||||
var tileStart = s.Position;
|
||||
var frame = new TmpTSFrame(s, size, i, j);
|
||||
tiles[k] = frame;
|
||||
tiles[k + stride] = new TmpTSDepthFrame(frame);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,10 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.TS.Traits
|
||||
@@ -24,7 +26,7 @@ namespace OpenRA.Mods.TS.Traits
|
||||
public object Create(ActorInitializer init) { return new TSShroudPalette(this); }
|
||||
}
|
||||
|
||||
class TSShroudPalette : ILoadsPalettes
|
||||
class TSShroudPalette : ILoadsPalettes, IProvidesAssetBrowserPalettes
|
||||
{
|
||||
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))));
|
||||
}
|
||||
|
||||
public IEnumerable<string> PaletteNames { get { yield return info.Name; } }
|
||||
}
|
||||
}
|
||||
BIN
mods/ts/bits/depth.pal
Normal file
BIN
mods/ts/bits/depth.pal
Normal file
Binary file not shown.
@@ -23,6 +23,9 @@ World:
|
||||
Tileset: TEMPERAT
|
||||
Filename: unittem.pal
|
||||
ShadowIndex: 1
|
||||
PaletteFromFile@depth:
|
||||
Name: depth
|
||||
Filename: depth.pal
|
||||
PaletteFromCurrentTileset:
|
||||
Name: terrain
|
||||
ShadowIndex: 1
|
||||
|
||||
Reference in New Issue
Block a user