Support rectangular tiles.

This commit is contained in:
Paul Chote
2013-12-28 19:04:30 +13:00
parent 1e792fa58b
commit 0143e8bfb8
10 changed files with 31 additions and 23 deletions

View File

@@ -145,7 +145,7 @@ namespace OpenRA.Editor
{ {
Rules.LoadRules(manifest, map); Rules.LoadRules(manifest, map);
tileset = Rules.TileSets[map.Tileset]; tileset = Rules.TileSets[map.Tileset];
tilesetRenderer = new TileSetRenderer(tileset, new Size(manifest.TileSize, manifest.TileSize)); tilesetRenderer = new TileSetRenderer(tileset, manifest.TileSize);
var shadowIndex = new int[] { 3, 4 }; var shadowIndex = new int[] { 3, 4 };
var palette = new Palette(FileSystem.Open(tileset.Palette), shadowIndex); var palette = new Palette(FileSystem.Open(tileset.Palette), shadowIndex);

View File

@@ -303,14 +303,16 @@ namespace OpenRA.Editor
bitmap.UnlockBits(data); bitmap.UnlockBits(data);
if (ShowGrid) if (ShowGrid)
{
using (var g = SGraphics.FromImage(bitmap)) using (var g = SGraphics.FromImage(bitmap))
{ {
var ts = Game.modData.Manifest.TileSize;
var rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); var rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
ControlPaint.DrawGrid(g, rect, new Size(2, Game.CellSize), Color.DarkRed); ControlPaint.DrawGrid(g, rect, new Size(2, ts.Height), Color.DarkRed);
ControlPaint.DrawGrid(g, rect, new Size(Game.CellSize, 2), Color.DarkRed); ControlPaint.DrawGrid(g, rect, new Size(ts.Width, 2), Color.DarkRed);
ControlPaint.DrawGrid(g, rect, new Size(Game.CellSize, Game.CellSize), Color.Red); ControlPaint.DrawGrid(g, rect, new Size(ts.Width, ts.Height), Color.Red);
} }
}
return bitmap; return bitmap;
} }

View File

@@ -9,6 +9,7 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@@ -28,7 +29,7 @@ namespace OpenRA.FileFormats
public readonly MiniYaml LoadScreen; public readonly MiniYaml LoadScreen;
public readonly MiniYaml LobbyDefaults; public readonly MiniYaml LobbyDefaults;
public readonly Dictionary<string, Pair<string, int>> Fonts; public readonly Dictionary<string, Pair<string, int>> Fonts;
public readonly int TileSize = 24; public readonly Size TileSize = new Size(24, 24);
public Manifest(string mod) public Manifest(string mod)
{ {
@@ -68,7 +69,7 @@ namespace OpenRA.FileFormats
int.Parse(x.Value.NodesDict["Size"].Value))); int.Parse(x.Value.NodesDict["Size"].Value)));
if (yaml.ContainsKey("TileSize")) if (yaml.ContainsKey("TileSize"))
TileSize = int.Parse(yaml["TileSize"].Value); TileSize = FieldLoader.GetValue<Size>("TileSize", yaml["TileSize"].Value);
// Allow inherited mods to import parent maps. // Allow inherited mods to import parent maps.
var compat = new List<string>(); var compat = new List<string>();

View File

@@ -27,8 +27,6 @@ namespace OpenRA
{ {
public static class Game public static class Game
{ {
public static int CellSize { get { return modData.Manifest.TileSize; } }
public static MouseButtonPreference mouseButtonPreference = new MouseButtonPreference(); public static MouseButtonPreference mouseButtonPreference = new MouseButtonPreference();
public static ModData modData; public static ModData modData;

View File

@@ -235,8 +235,8 @@ namespace OpenRA.Graphics
// Conversion between world and screen coordinates // Conversion between world and screen coordinates
public float2 ScreenPosition(WPos pos) public float2 ScreenPosition(WPos pos)
{ {
var c = Game.CellSize / 1024f; var ts = Game.modData.Manifest.TileSize;
return new float2(c * pos.X, c * (pos.Y - pos.Z)); return new float2(ts.Width * pos.X / 1024f, ts.Height * (pos.Y - pos.Z) / 1024f);
} }
public int2 ScreenPxPosition(WPos pos) public int2 ScreenPxPosition(WPos pos)
@@ -249,8 +249,8 @@ namespace OpenRA.Graphics
// For scaling vectors to pixel sizes in the voxel renderer // For scaling vectors to pixel sizes in the voxel renderer
public float[] ScreenVector(WVec vec) public float[] ScreenVector(WVec vec)
{ {
var c = Game.CellSize / 1024f; var ts = Game.modData.Manifest.TileSize;
return new float[] { c * vec.X, c * vec.Y, c * vec.Z, 1 }; return new float[] { ts.Width * vec.X / 1024f, ts.Height * vec.Y / 1024f, ts.Height * vec.Z / 1024f, 1 };
} }
public int2 ScreenPxOffset(WVec vec) public int2 ScreenPxOffset(WVec vec)
@@ -262,12 +262,14 @@ namespace OpenRA.Graphics
public float ScreenZPosition(WPos pos, int offset) public float ScreenZPosition(WPos pos, int offset)
{ {
return (pos.Y + pos.Z + offset) * Game.CellSize / 1024f; var ts = Game.modData.Manifest.TileSize;
return (pos.Y + pos.Z + offset) * ts.Height / 1024f;
} }
public WPos Position(int2 screenPx) public WPos Position(int2 screenPx)
{ {
return new WPos(1024 * screenPx.X / Game.CellSize, 1024 * screenPx.Y / Game.CellSize, 0); var ts = Game.modData.Manifest.TileSize;
return new WPos(1024 * screenPx.X / ts.Width, 1024 * screenPx.Y / ts.Height, 0);
} }
} }
} }

View File

@@ -36,8 +36,9 @@ namespace OpenRA.Traits
public ScreenMap(World world, ScreenMapInfo info) public ScreenMap(World world, ScreenMapInfo info)
{ {
this.info = info; this.info = info;
cols = world.Map.MapSize.X * Game.CellSize / info.BinSize + 1; var ts = Game.modData.Manifest.TileSize;
rows = world.Map.MapSize.Y * Game.CellSize / info.BinSize + 1; cols = world.Map.MapSize.X * ts.Width / info.BinSize + 1;
rows = world.Map.MapSize.Y * ts.Height / info.BinSize + 1;
frozen = new Cache<Player, Dictionary<FrozenActor, Rectangle>[]>(InitializeFrozenActors); frozen = new Cache<Player, Dictionary<FrozenActor, Rectangle>[]>(InitializeFrozenActors);
actors = new Dictionary<Actor, Rectangle>[rows * cols]; actors = new Dictionary<Actor, Rectangle>[rows * cols];

View File

@@ -95,9 +95,9 @@ namespace OpenRA.Mods.RA
// Synthesize unexplored tile if it isn't defined // Synthesize unexplored tile if it isn't defined
if (!info.Index.Contains(0)) if (!info.Index.Contains(0))
{ {
var size = new Size(Game.modData.Manifest.TileSize, Game.modData.Manifest.TileSize); var ts = Game.modData.Manifest.TileSize;
var data = Exts.MakeArray<byte>(size.Width * size.Height, _ => (byte)info.ShroudColor); var data = Exts.MakeArray<byte>(ts.Width * ts.Height, _ => (byte)info.ShroudColor);
var s = Game.modData.SheetBuilder.Add(data, size); var s = Game.modData.SheetBuilder.Add(data, ts);
unexploredTile = new Sprite(s.sheet, s.bounds, s.offset, s.channel, info.ShroudBlend); unexploredTile = new Sprite(s.sheet, s.bounds, s.offset, s.channel, info.ShroudBlend);
} }
else else

View File

@@ -43,7 +43,8 @@ namespace OpenRA.Utility
static void ConvertPxToRange(ref string input, int scaleMult, int scaleDiv) static void ConvertPxToRange(ref string input, int scaleMult, int scaleDiv)
{ {
var value = int.Parse(input); var value = int.Parse(input);
var world = value * 1024 * scaleMult / (scaleDiv * Game.CellSize); var ts = Game.modData.Manifest.TileSize;
var world = value * 1024 * scaleMult / (scaleDiv * ts.Height);
var cells = world / 1024; var cells = world / 1024;
var subcells = world - 1024 * cells; var subcells = world - 1024 * cells;
@@ -59,7 +60,8 @@ namespace OpenRA.Utility
static void ConvertInt2ToWVec(ref string input) static void ConvertInt2ToWVec(ref string input)
{ {
var offset = FieldLoader.GetValue<int2>("(value)", input); var offset = FieldLoader.GetValue<int2>("(value)", input);
var world = new WVec(offset.X * 1024 / Game.CellSize, offset.Y * 1024 / Game.CellSize, 0); var ts = Game.modData.Manifest.TileSize;
var world = new WVec(offset.X * 1024 / ts.Width, offset.Y * 1024 / ts.Height, 0);
input = world.ToString(); input = world.ToString();
} }

View File

@@ -91,7 +91,7 @@ Notifications:
TileSets: TileSets:
mods/d2k/tilesets/arrakis.yaml mods/d2k/tilesets/arrakis.yaml
TileSize: 32 TileSize: 32,32
Music: Music:
mods/d2k/music.yaml mods/d2k/music.yaml

View File

@@ -134,6 +134,8 @@ Notifications:
TileSets: TileSets:
mods/ra/tilesets/interior.yaml mods/ra/tilesets/interior.yaml
TileSize: 48,24
Music: Music:
mods/ts/music.yaml mods/ts/music.yaml