From b949508b913aa67e8cb774038446af00b5ee1669 Mon Sep 17 00:00:00 2001 From: Venomalia <87765258+Venomalia@users.noreply.github.com> Date: Tue, 3 Dec 2024 22:13:02 +0100 Subject: [PATCH] Highlights used layers. --- EFSAdvent/CheckedListBoxColorable.cs | 32 ++++++++++++++++++++++++++++ EFSAdvent/EFSAdvent.csproj | 3 +++ EFSAdvent/Form1.Designer.cs | 8 ++++--- EFSAdvent/Form1.cs | 26 ++++++++++++++++++---- EFSAdvent/FourSwords/Layer.cs | 12 +++++++++++ EFSAdvent/FourSwords/Room.cs | 6 ++++-- README.md | 2 ++ 7 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 EFSAdvent/CheckedListBoxColorable.cs diff --git a/EFSAdvent/CheckedListBoxColorable.cs b/EFSAdvent/CheckedListBoxColorable.cs new file mode 100644 index 0000000..960af46 --- /dev/null +++ b/EFSAdvent/CheckedListBoxColorable.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; + +namespace EFSAdvent +{ + public class CheckedListBoxColorable : CheckedListBox + { + public readonly Dictionary Colors; + + public CheckedListBoxColorable() + { + Colors = new Dictionary(); + this.DrawMode = DrawMode.OwnerDrawFixed; + this.DoubleBuffered = true; + } + + protected override void OnDrawItem(DrawItemEventArgs e) + { + if (e.Index < 0) return; + + Color foreColor = e.ForeColor; + + if (e.Index < Items.Count && Colors.TryGetValue(Items[e.Index], out Color customColor)) + foreColor = customColor; + + var tweakedEventArgs = new DrawItemEventArgs(e.Graphics, e.Font, e.Bounds, e.Index, e.State, foreColor, e.BackColor); + base.OnDrawItem(tweakedEventArgs); + } + + } +} diff --git a/EFSAdvent/EFSAdvent.csproj b/EFSAdvent/EFSAdvent.csproj index d477811..6933824 100644 --- a/EFSAdvent/EFSAdvent.csproj +++ b/EFSAdvent/EFSAdvent.csproj @@ -74,6 +74,9 @@ + + Component + Form diff --git a/EFSAdvent/Form1.Designer.cs b/EFSAdvent/Form1.Designer.cs index 9ba0b9c..384715e 100644 --- a/EFSAdvent/Form1.Designer.cs +++ b/EFSAdvent/Form1.Designer.cs @@ -1,4 +1,6 @@ -namespace EFSAdvent +using System.Windows.Forms; + +namespace EFSAdvent { partial class Form1 { @@ -68,7 +70,7 @@ private void InitializeComponent() this.rightSideGroupBox = new System.Windows.Forms.GroupBox(); this.updateLayersButton = new System.Windows.Forms.Button(); this.buttonSaveLayers = new System.Windows.Forms.Button(); - this.layersCheckList = new System.Windows.Forms.CheckedListBox(); + this.layersCheckList = new EFSAdvent.CheckedListBoxColorable(); this.tabControl = new System.Windows.Forms.TabControl(); this.tabPage3 = new System.Windows.Forms.TabPage(); this.MapVariablesGroupBox = new System.Windows.Forms.GroupBox(); @@ -2147,7 +2149,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem quitToolStripMenuItem; private System.Windows.Forms.GroupBox rightSideGroupBox; - private System.Windows.Forms.CheckedListBox layersCheckList; + private EFSAdvent.CheckedListBoxColorable layersCheckList; private System.Windows.Forms.TabControl tabControl; private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.TabPage tabPage1; diff --git a/EFSAdvent/Form1.cs b/EFSAdvent/Form1.cs index 4c1fb66..41d48f3 100644 --- a/EFSAdvent/Form1.cs +++ b/EFSAdvent/Form1.cs @@ -14,7 +14,7 @@ namespace EFSAdvent { public partial class Form1 : Form { - const string VERSION = "1.3 [Venomalia]"; + const string VERSION = "1.4 [Venomalia]"; private string BaseTitel = $"EFSAdvent {VERSION}"; const int ACTOR_PIXELS_PER_COORDINATE = 8; @@ -324,6 +324,12 @@ private void LoadRoom(bool newRoom) layersCheckList.SetItemChecked(0, true); layersCheckList.SetItemChecked(8, true); + for (int i = 0; i < 16; i++) + { + Color color = _level.Room.IsLayerEmpty(i) ? Color.Gray : Color.Black; + layersCheckList.Colors[$"Layer {(i < 8 ? 1 : 2)}-{i % 8}"] = color; + } + layersCheckList.Refresh(); UpdateView(false); } if (newRoom) @@ -334,7 +340,7 @@ private void LoadRoom(bool newRoom) { for (int x = 0; x < Layer.DIMENSION; x++) { - _level.Room.SetLayerTile(0, x, y, 432); + ChangeTile(0, x, y, 432); } } } @@ -874,6 +880,17 @@ private void ChangeTile(int layer, int x, int y, ushort newTileValue) if (_level.Room.SetLayerTile(layer, x, y, newTileValue)) { buttonSaveLayers.Enabled = true; + + if (newTileValue != 0) + { + layersCheckList.Colors[$"Layer {(layer < 8 ? 1 : 2)}-{layer % 8}"] = Color.Black; + layersCheckList.Refresh(); + } + else if (newTileValue == 0 && _level.Room.IsLayerEmpty(layer)) + { + layersCheckList.Colors[$"Layer {(layer < 8 ? 1 : 2)}-{layer % 8}"] = Color.Gray; + layersCheckList.Refresh(); + } } } @@ -937,6 +954,7 @@ private void LayersCheckList_ItemCheck(object sender, ItemCheckEventArgs e) { // Need to delay redraw because right now the newly checked layer won't have checked=true this.BeginInvoke((MethodInvoker)(() => UpdateView(false))); + layersCheckList.SelectedIndex = -1; } private void currentTileSheetComboBox_SelectionChangeCommitted(object sender, EventArgs e) @@ -1055,12 +1073,12 @@ private void quitToolStripMenuItem_Click(object sender, EventArgs e) private void Form1_FormClosing(object sender, FormClosingEventArgs e) { - e.Cancel = ShowSaveChangesDialog(true,"Save all changes before exiting?"); + e.Cancel = ShowSaveChangesDialog(true, "Save all changes before exiting?"); } private bool ShowSaveChangesDialog(bool saveMap = true, string message = "Save all changes?") { - if (saveMap? _level?.IsDirty ?? false : (_level?.LayersAreDirty ?? false) || (_level?.ActorsAreDirty ?? false)) + if (saveMap ? _level?.IsDirty ?? false : (_level?.LayersAreDirty ?? false) || (_level?.ActorsAreDirty ?? false)) { var dirtyDataBuilder = new StringBuilder(); diff --git a/EFSAdvent/FourSwords/Layer.cs b/EFSAdvent/FourSwords/Layer.cs index 22d1992..9910f1b 100644 --- a/EFSAdvent/FourSwords/Layer.cs +++ b/EFSAdvent/FourSwords/Layer.cs @@ -55,6 +55,18 @@ public Layer(string szsFilePath, Logger logger) : this() return _data[(y * DIMENSION) + x]; } + public bool IsEmpty() + { + for (int i = 0; i < _data.Length; i++) + { + if (_data[i] != 0) + { + return false; + } + } + return true; + } + public bool SetTile(int x, int y, ushort newValue) { if (x < 0 || x >= DIMENSION || y < 0 || y >= DIMENSION) diff --git a/EFSAdvent/FourSwords/Room.cs b/EFSAdvent/FourSwords/Room.cs index fd47b5b..34d2af7 100644 --- a/EFSAdvent/FourSwords/Room.cs +++ b/EFSAdvent/FourSwords/Room.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -107,6 +106,9 @@ public bool SetLayerTile(int layer, int x, int y, ushort newValue) return success; } + public bool IsLayerEmpty(int layer) + => _layers[layer % 8, layer < 8 ? 0 : 1].IsEmpty(); + private void SortActors() { _actors = _actors.OrderBy(a => a.Layer).ThenBy(a => a.Name).ThenBy(a => a.XCoord).ThenBy(a => a.YCoord).ToList(); diff --git a/README.md b/README.md index 91ac7c6..25de13c 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ This branch is an unoficial update based on the [source code](https://bitbucket. - Import rooms and actors from other levels. - Preview which tiles will be changed by PNPC and PNP2 actors. - Detailed documentation for a significant number of actors. +- Shadow Battle Map vaules will be loaded and can be edited. +- Highlights used layers. ## Goals Fully document all actor variables and their behavior.