Skip to content

Commit

Permalink
Highlights used layers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Venomalia committed Dec 3, 2024
1 parent 8a0e1eb commit b949508
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 9 deletions.
32 changes: 32 additions & 0 deletions EFSAdvent/CheckedListBoxColorable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace EFSAdvent
{
public class CheckedListBoxColorable : CheckedListBox
{
public readonly Dictionary<object, Color> Colors;

public CheckedListBoxColorable()
{
Colors = new Dictionary<object, Color>();
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);
}

}
}
3 changes: 3 additions & 0 deletions EFSAdvent/EFSAdvent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CheckedListBoxColorable.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="FourSwords\Actor.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
Expand Down
8 changes: 5 additions & 3 deletions EFSAdvent/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions EFSAdvent/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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();
}
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();

Expand Down
12 changes: 12 additions & 0 deletions EFSAdvent/FourSwords/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions EFSAdvent/FourSwords/Room.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b949508

Please sign in to comment.