Skip to content

Commit b949508

Browse files
committed
Highlights used layers.
1 parent 8a0e1eb commit b949508

File tree

7 files changed

+80
-9
lines changed

7 files changed

+80
-9
lines changed

EFSAdvent/CheckedListBoxColorable.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
using System.Drawing;
3+
using System.Windows.Forms;
4+
5+
namespace EFSAdvent
6+
{
7+
public class CheckedListBoxColorable : CheckedListBox
8+
{
9+
public readonly Dictionary<object, Color> Colors;
10+
11+
public CheckedListBoxColorable()
12+
{
13+
Colors = new Dictionary<object, Color>();
14+
this.DrawMode = DrawMode.OwnerDrawFixed;
15+
this.DoubleBuffered = true;
16+
}
17+
18+
protected override void OnDrawItem(DrawItemEventArgs e)
19+
{
20+
if (e.Index < 0) return;
21+
22+
Color foreColor = e.ForeColor;
23+
24+
if (e.Index < Items.Count && Colors.TryGetValue(Items[e.Index], out Color customColor))
25+
foreColor = customColor;
26+
27+
var tweakedEventArgs = new DrawItemEventArgs(e.Graphics, e.Font, e.Bounds, e.Index, e.State, foreColor, e.BackColor);
28+
base.OnDrawItem(tweakedEventArgs);
29+
}
30+
31+
}
32+
}

EFSAdvent/EFSAdvent.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
<Reference Include="System.Xml" />
7575
</ItemGroup>
7676
<ItemGroup>
77+
<Compile Include="CheckedListBoxColorable.cs">
78+
<SubType>Component</SubType>
79+
</Compile>
7780
<Compile Include="FourSwords\Actor.cs" />
7881
<Compile Include="Form1.cs">
7982
<SubType>Form</SubType>

EFSAdvent/Form1.Designer.cs

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EFSAdvent/Form1.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace EFSAdvent
1414
{
1515
public partial class Form1 : Form
1616
{
17-
const string VERSION = "1.3 [Venomalia]";
17+
const string VERSION = "1.4 [Venomalia]";
1818
private string BaseTitel = $"EFSAdvent {VERSION}";
1919

2020
const int ACTOR_PIXELS_PER_COORDINATE = 8;
@@ -324,6 +324,12 @@ private void LoadRoom(bool newRoom)
324324
layersCheckList.SetItemChecked(0, true);
325325
layersCheckList.SetItemChecked(8, true);
326326

327+
for (int i = 0; i < 16; i++)
328+
{
329+
Color color = _level.Room.IsLayerEmpty(i) ? Color.Gray : Color.Black;
330+
layersCheckList.Colors[$"Layer {(i < 8 ? 1 : 2)}-{i % 8}"] = color;
331+
}
332+
layersCheckList.Refresh();
327333
UpdateView(false);
328334
}
329335
if (newRoom)
@@ -334,7 +340,7 @@ private void LoadRoom(bool newRoom)
334340
{
335341
for (int x = 0; x < Layer.DIMENSION; x++)
336342
{
337-
_level.Room.SetLayerTile(0, x, y, 432);
343+
ChangeTile(0, x, y, 432);
338344
}
339345
}
340346
}
@@ -874,6 +880,17 @@ private void ChangeTile(int layer, int x, int y, ushort newTileValue)
874880
if (_level.Room.SetLayerTile(layer, x, y, newTileValue))
875881
{
876882
buttonSaveLayers.Enabled = true;
883+
884+
if (newTileValue != 0)
885+
{
886+
layersCheckList.Colors[$"Layer {(layer < 8 ? 1 : 2)}-{layer % 8}"] = Color.Black;
887+
layersCheckList.Refresh();
888+
}
889+
else if (newTileValue == 0 && _level.Room.IsLayerEmpty(layer))
890+
{
891+
layersCheckList.Colors[$"Layer {(layer < 8 ? 1 : 2)}-{layer % 8}"] = Color.Gray;
892+
layersCheckList.Refresh();
893+
}
877894
}
878895
}
879896

@@ -937,6 +954,7 @@ private void LayersCheckList_ItemCheck(object sender, ItemCheckEventArgs e)
937954
{
938955
// Need to delay redraw because right now the newly checked layer won't have checked=true
939956
this.BeginInvoke((MethodInvoker)(() => UpdateView(false)));
957+
layersCheckList.SelectedIndex = -1;
940958
}
941959

942960
private void currentTileSheetComboBox_SelectionChangeCommitted(object sender, EventArgs e)
@@ -1055,12 +1073,12 @@ private void quitToolStripMenuItem_Click(object sender, EventArgs e)
10551073

10561074
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
10571075
{
1058-
e.Cancel = ShowSaveChangesDialog(true,"Save all changes before exiting?");
1076+
e.Cancel = ShowSaveChangesDialog(true, "Save all changes before exiting?");
10591077
}
10601078

10611079
private bool ShowSaveChangesDialog(bool saveMap = true, string message = "Save all changes?")
10621080
{
1063-
if (saveMap? _level?.IsDirty ?? false : (_level?.LayersAreDirty ?? false) || (_level?.ActorsAreDirty ?? false))
1081+
if (saveMap ? _level?.IsDirty ?? false : (_level?.LayersAreDirty ?? false) || (_level?.ActorsAreDirty ?? false))
10641082
{
10651083
var dirtyDataBuilder = new StringBuilder();
10661084

EFSAdvent/FourSwords/Layer.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ public Layer(string szsFilePath, Logger logger) : this()
5555
return _data[(y * DIMENSION) + x];
5656
}
5757

58+
public bool IsEmpty()
59+
{
60+
for (int i = 0; i < _data.Length; i++)
61+
{
62+
if (_data[i] != 0)
63+
{
64+
return false;
65+
}
66+
}
67+
return true;
68+
}
69+
5870
public bool SetTile(int x, int y, ushort newValue)
5971
{
6072
if (x < 0 || x >= DIMENSION || y < 0 || y >= DIMENSION)

EFSAdvent/FourSwords/Room.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.IO;
43
using System.Linq;
54
using System.Text;
@@ -107,6 +106,9 @@ public bool SetLayerTile(int layer, int x, int y, ushort newValue)
107106
return success;
108107
}
109108

109+
public bool IsLayerEmpty(int layer)
110+
=> _layers[layer % 8, layer < 8 ? 0 : 1].IsEmpty();
111+
110112
private void SortActors()
111113
{
112114
_actors = _actors.OrderBy(a => a.Layer).ThenBy(a => a.Name).ThenBy(a => a.XCoord).ThenBy(a => a.YCoord).ToList();

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ This branch is an unoficial update based on the [source code](https://bitbucket.
1111
- Import rooms and actors from other levels.
1212
- Preview which tiles will be changed by PNPC and PNP2 actors.
1313
- Detailed documentation for a significant number of actors.
14+
- Shadow Battle Map vaules will be loaded and can be edited.
15+
- Highlights used layers.
1416

1517
## Goals
1618
Fully document all actor variables and their behavior.

0 commit comments

Comments
 (0)