From af3c591808b3a0f5279b388d7fafdc4811baf805 Mon Sep 17 00:00:00 2001 From: Maxim Date: Sun, 6 Oct 2024 21:35:50 +0100 Subject: [PATCH] Show part names on sprites tabs --- editor/ArtItem.cs | 5 +- editor/Cartridge.cs | 2 +- editor/Form1.cs | 6 +- editor/GameObjects/Level.cs | 106 ++++++------------------------------ 4 files changed, 25 insertions(+), 94 deletions(-) diff --git a/editor/ArtItem.cs b/editor/ArtItem.cs index 149e21b..a7e6806 100644 --- a/editor/ArtItem.cs +++ b/editor/ArtItem.cs @@ -3,6 +3,9 @@ namespace sth1edwv { + /// + /// Represents one non-level "thing", which may have multiple types of data. + /// public class ArtItem { public TileSet TileSet { get; set; } @@ -10,7 +13,7 @@ public class ArtItem public bool PaletteEditable { get; set; } public string Name { get; init; } public TileMap TileMap { get; set; } - public List SpriteTileSets { get; } = []; + public Dictionary SpriteTileSets { get; } = []; public List TileMapData { get; } = []; public List Assets { get; } = []; public List RawValues { get; } = []; diff --git a/editor/Cartridge.cs b/editor/Cartridge.cs index 0dbd444..8da03c2 100644 --- a/editor/Cartridge.cs +++ b/editor/Cartridge.cs @@ -2787,7 +2787,7 @@ private void ReadAssets() ? GetTileSet(offset, asset.GetLength(Memory), asset.BitPlanes, asset.TileGrouping, asset.TilesPerRow) : GetTileSet(offset, asset.TileGrouping, asset.TilesPerRow); _assetsLookup[asset] = tileSet; - item.SpriteTileSets.Add(tileSet); + item.SpriteTileSets.Add(part.Name, tileSet); break; case Game.Asset.Types.RawValue: var rawValue = new RawValue(Memory, part.Asset.OriginalOffset, part.Asset.OriginalSize, part.Asset.Encoding, part.Name); diff --git a/editor/Form1.cs b/editor/Form1.cs index 0089f1b..eb69ff7 100644 --- a/editor/Form1.cs +++ b/editor/Form1.cs @@ -119,7 +119,6 @@ private void SelectedLevelChanged(object sender, EventArgs e) { PalettesLayout.Controls.Add(new PaletteEditor(level.Palette, "Base palette (only sprites part is used)", OnPaletteChanged)); PalettesLayout.Controls.Add(new PaletteEditor(level.CyclingPalette, "Colour cycling", OnPaletteChanged)); - // TODO: extra palettes for some levels? } propertyGridLevel.SelectedObject = level; @@ -582,9 +581,10 @@ private void listBoxArt_SelectedIndexChanged(object sender, EventArgs e) tabControlArt.TabPages.Add(tabPageArtTiles); } - foreach (var tileSet in artItem.SpriteTileSets) + foreach (var kvp in artItem.SpriteTileSets) { - var page = new TabPage("Sprites") { Tag = tileSet, Padding = new Padding(3), UseVisualStyleBackColor = true}; + var tileSet = kvp.Value; + var page = new TabPage(kvp.Key) { Tag = tileSet, Padding = new Padding(3), UseVisualStyleBackColor = true}; var viewer = new TileSetViewer { Dock = DockStyle.Fill, TilesPerRow = tileSet.TilesPerRow }; page.Controls.Add(viewer); var palette = firstPalette.GetData().Count >= 32 diff --git a/editor/GameObjects/Level.cs b/editor/GameObjects/Level.cs index 6af5c64..cac1bd6 100644 --- a/editor/GameObjects/Level.cs +++ b/editor/GameObjects/Level.cs @@ -1,6 +1,9 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.ComponentModel; +using System.Globalization; using System.IO; +using System.Linq; using System.Windows.Forms; namespace sth1edwv.GameObjects @@ -102,84 +105,9 @@ public class Level : IDataItem public bool UseUnderwaterBossPalette { get; set; } [Category("General")] - [Description("Which music track to play")] - //[TypeConverter(typeof(MusicConverter))] + [Description("Which music track to play. Value 7 can be used for silence.")] public int MusicIndex { get; set; } - /* - public class MusicConverter : StringConverter - { - // Enable a combo - public override bool GetStandardValuesSupported(ITypeDescriptorContext context) - { - return true; - } - - // Disable free-form text - public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) - { - return true; - } - - // Get values - public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) - { - return new StandardValuesCollection(_musicTracks); - } - - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) - { - return (value as MusicItem)?.ToString(); - } - - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) - { - if (value is int i && destinationType == typeof(string)) - { - return _musicTracks.First(x => x.Index == i).ToString(); - } - - if (value is MusicItem mi && destinationType == typeof(string)) - { - return mi.ToString(); - } - return null; - } - } - - private class MusicItem - { - public int Index { get; } - private readonly string _name; - - public MusicItem(int index, string name) - { - Index = index; - _name = name; - } - - public override string ToString() - { - return $"{Index}: {_name}"; - } - } - - private static List _musicTracks = new() - { - new(0, "Green Hill"), - new(1, "Bridge"), - new(2, "Jungle"), - new(3, "Labyrinth"), - new(4, "Scrap Brain"), - new(5, "Sky Base"), - new(6, "Title"), - new(8, "Invincibility"), - new(9, "Level Complete"), - new(10, "Death"), - new(11, "Boss"), - }; -*/ - // Objects representing referenced data [Category("General")] public TileSet TileSet { get; } [Category("General")] public TileSet SpriteTileSet { get; } @@ -197,10 +125,6 @@ public override string ToString() [Category("General")] public int Offset { get; set; } private readonly string _label; - private readonly int _floorAddress; - private readonly int _floorSize; - private readonly int _offsetArt; - private readonly int _offsetObjectLayout; private readonly int _initPalette; // These should be encapsulated by a cycling palette object @@ -213,6 +137,10 @@ public override string ToString() public Level(Cartridge cartridge, int offset, string label) { + int offsetObjectLayout; + int offsetArt; + int floorSize; + int floorAddress; _label = label; Offset = offset; int blockMappingOffset; @@ -237,17 +165,17 @@ public Level(Cartridge cartridge, int offset, string label) BottomEdgeFactor = reader.ReadByte(); // LH StartX = reader.ReadByte(); // SX StartY = reader.ReadByte(); // SY - _floorAddress = reader.ReadUInt16(); // FL FL: relative to 0x14000 - _floorSize = reader.ReadUInt16(); // FS FS: compressed size in bytes + floorAddress = reader.ReadUInt16(); // FL FL: relative to 0x14000 + floorSize = reader.ReadUInt16(); // FS FS: compressed size in bytes blockMappingOffset = reader.ReadUInt16(); // BM BM: relative to 0x10000 - _offsetArt = reader.ReadUInt16(); // LA LA: Relative to 0x30000 + offsetArt = reader.ReadUInt16(); // LA LA: Relative to 0x30000 spriteArtPage = reader.ReadByte(); // SP: Page for the below spriteArtAddress = reader.ReadUInt16(); // SA SA: offset from start of above bank _initPalette = reader.ReadByte(); // IP: Index of palette PaletteCycleRate = reader.ReadByte(); // CS: Number of frames between palette cycles _paletteCycleCount = reader.ReadByte(); // CC: Number of palette cycles in a loop _paletteCycleIndex = reader.ReadByte(); // CP: Which cycling palette to use - _offsetObjectLayout = reader.ReadUInt16(); // OL OL: relative to 0x15580 + offsetObjectLayout = reader.ReadUInt16(); // OL OL: relative to 0x15580 var flags = reader.ReadByte(); // SR // Nothing for bit 0 DemoMode = (flags & (1 << 1)) != 0; @@ -277,13 +205,13 @@ public Level(Cartridge cartridge, int offset, string label) Palette = cartridge.GetPalette(cartridge.Memory.Word(0x627C + _initPalette*2), 2); CyclingPalette = cartridge.GetPalette(cartridge.Memory.Word(0x628C + _paletteCycleIndex*2), _paletteCycleCount); - TileSet = cartridge.GetTileSet(_offsetArt + 0x30000, null, 16); + TileSet = cartridge.GetTileSet(offsetArt + 0x30000, null, 16); SpriteTileSet = cartridge.GetTileSet(spriteArtAddress + spriteArtPage * 0x4000, TileSet.Groupings.Sprite, 16); Floor = cartridge.GetFloor( - _floorAddress + 0x14000, - _floorSize, + floorAddress + 0x14000, + floorSize, FloorWidth); // We rewrite FloorHeight to match the data size. @@ -308,7 +236,7 @@ public Level(Cartridge cartridge, int offset, string label) }; BlockMapping = cartridge.GetBlockMapping(blockMappingOffset + 0x10000, blockCount, _solidityIndex, TileSet); - Objects = cartridge.GetLevelObjectSet(0x15580 + _offsetObjectLayout); + Objects = cartridge.GetLevelObjectSet(0x15580 + offsetObjectLayout); // We generate sub-palettes for rendering UpdateRenderingPalettes();