From 5fb5152ec7dd10f12127221433bff3b8a517f75d Mon Sep 17 00:00:00 2001
From: AsY!um- <377468+AsYlum-@users.noreply.github.com>
Date: Tue, 17 Nov 2026 23:11:12 +0100
Subject: [PATCH 01/16] Shape and place roofs in the multi editor
Eaves fit the wall tops; gable and joined roofs are shaped as wings and placed on a Roof layer.
---
.../MultiEditorComponentList.Layers.cs | 49 +
.../Classes/MultiEditorComponentList.cs | 25 +-
.../Classes/RoofPlanner.cs | 281 +++++
.../Editing/EditorSession.Commands.cs | 33 +-
.../Editing/EditorSession.cs | 21 +-
.../Tools/HousePartTools.cs | 359 ------
.../Tools/PlaneDragTool.cs | 9 +-
.../Tools/RoofTool.cs | 1113 +++++++++++++++++
.../UI/MultiEditorControl.Designer.cs | 20 +-
.../UI/MultiEditorControl.cs | 63 +-
.../UI/ShortcutsForm.cs | 12 +-
11 files changed, 1606 insertions(+), 379 deletions(-)
create mode 100644 UoFiddler.Plugin.MultiEditor/Classes/RoofPlanner.cs
create mode 100644 UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/MultiEditorComponentList.Layers.cs b/UoFiddler.Plugin.MultiEditor/Classes/MultiEditorComponentList.Layers.cs
index 07cece0e..5014f086 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/MultiEditorComponentList.Layers.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/MultiEditorComponentList.Layers.cs
@@ -111,6 +111,55 @@ public TileLayer LayerAdd(string name)
return layer;
}
+ ///
+ /// Removes some tiles and adds others in one undo step, the new ones on the layer each
+ /// names or, when it names none, on the layer called . That
+ /// layer is made on top of the others when the multi has none of that name; the active
+ /// layer stays as it is. The multi grows to hold tiles added past its +X/+Y end.
+ ///
+ public void ReplaceTilesOnLayer(IEnumerable remove, IEnumerable<(ushort Id, int X, int Y, int Z, TileLayer Layer)> add,
+ string action, string layerName)
+ {
+ var added = new List<(ushort Id, int X, int Y, int Z, TileLayer Layer)>(add);
+ BeginEdit(action);
+ foreach (MultiTile tile in new List(remove))
+ {
+ RecordRemove(tile);
+ }
+
+ int width = Width, height = Height;
+ foreach (var (_, x, y, _, _) in added)
+ {
+ if (x >= 0 && y >= 0)
+ {
+ width = Math.Max(width, x + 1);
+ height = Math.Max(height, y + 1);
+ }
+ }
+
+ if (width != Width || height != Height)
+ {
+ RebuildGrid(width, height, new List(RealTiles));
+ }
+
+ TileLayer named = _layers.FirstOrDefault(l => l.Name == layerName);
+ if (named == null && added.Any(a => a.Layer == null))
+ {
+ RecordLayers();
+ TileLayer active = ActiveLayer;
+ named = new TileLayer(layerName);
+ _layers.Add(named);
+ ActiveLayer = active;
+ }
+
+ foreach (var (id, x, y, z, layer) in added)
+ {
+ RecordNew(id, x, y, z, false, 0, layer: layer != null && _layers.Contains(layer) ? layer : named);
+ }
+
+ EndEdit();
+ }
+
/// Removes a layer with its tiles. The last layer stays.
public bool LayerRemove(TileLayer layer)
{
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/MultiEditorComponentList.cs b/UoFiddler.Plugin.MultiEditor/Classes/MultiEditorComponentList.cs
index b11941e1..e4d5fa2b 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/MultiEditorComponentList.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/MultiEditorComponentList.cs
@@ -528,16 +528,37 @@ public void TileSetIds(IEnumerable<(MultiTile Tile, ushort Id)> changes, string
}
///
- /// Removes some tiles and adds others in one undo step (wall and house part tools).
+ /// Removes some tiles and adds others in one undo step (wall and house part tools). With
+ /// the multi is made bigger, in the same step, to hold tiles added
+ /// past its +X/+Y end; otherwise those are dropped.
///
- public void ReplaceTiles(IEnumerable remove, IEnumerable<(ushort Id, int X, int Y, int Z)> add, string action)
+ public void ReplaceTiles(IEnumerable remove, IEnumerable<(ushort Id, int X, int Y, int Z)> add, string action, bool grow = false)
{
+ add = new List<(ushort Id, int X, int Y, int Z)>(add);
BeginEdit(action);
foreach (MultiTile tile in new List(remove))
{
RecordRemove(tile);
}
+ if (grow)
+ {
+ int width = Width, height = Height;
+ foreach (var (_, x, y, _) in add)
+ {
+ if (x >= 0 && y >= 0)
+ {
+ width = Math.Max(width, x + 1);
+ height = Math.Max(height, y + 1);
+ }
+ }
+
+ if (width != Width || height != Height)
+ {
+ RebuildGrid(width, height, new List(RealTiles));
+ }
+ }
+
foreach (var (id, x, y, z) in add)
{
RecordNew(id, x, y, z, false, 0);
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/RoofPlanner.cs b/UoFiddler.Plugin.MultiEditor/Classes/RoofPlanner.cs
new file mode 100644
index 00000000..09c44867
--- /dev/null
+++ b/UoFiddler.Plugin.MultiEditor/Classes/RoofPlanner.cs
@@ -0,0 +1,281 @@
+/***************************************************************************
+ *
+ * $Author: Turley
+ *
+ * "THE BEER-WARE LICENSE"
+ * As long as you retain this notice you can do whatever you want with
+ * this stuff. If we meet some day, and you think this stuff is worth it,
+ * you can buy me a beer in return.
+ *
+ ***************************************************************************/
+
+using System;
+using System.Collections.Generic;
+
+namespace UoFiddler.Plugin.MultiEditor.Classes
+{
+ /// The shape of one roof wing.
+ internal enum RoofShape
+ {
+ /// Two slopes meeting in a ridge.
+ Gable
+ }
+
+ ///
+ /// Roofs as a height per cell. A wing (a rectangle with a ridge direction) gives each of its
+ /// cells a height, wings are joined by taking the higher one, and the roof.txt piece of a cell
+ /// follows from how its neighbours' heights compare with its own. The rules were measured on
+ /// the official multis and the UO Architect designs (109,000 roof cells):
+ ///
+ /// - a slope is named for the side it comes down to: lower to the west is a West piece;
+ /// - a ridge cell (lower on both sides) is the crosspiece running the other way;
+ /// - a valley cell, level with two neighbours and below the other two, is a Dent piece:
+ /// higher to the west and south EDent, west and north SDent, east and north WDent, east and
+ /// south NDent;
+ /// - where a wing's ridge runs into another ridge of the same height the cell is the T
+ /// piece named for the side the wing comes from, and the X piece where two ridges cross.
+ ///
+ ///
+ internal static class RoofPlanner
+ {
+ /// Z a slope gains per cell: the roof pieces are 3 high.
+ public const int Rise = 3;
+
+ /// Narrowest part of a house that gets a wing of its own.
+ private const int _minWing = 3;
+
+ ///
+ /// The ridge direction the official houses would give a box: across the odd side, so the
+ /// ridge gets its crosspiece; otherwise along the longer side, along Y when square.
+ ///
+ public static bool RidgeAlongY((int X0, int Y0, int X1, int Y1) box)
+ {
+ int spanX = box.X1 - box.X0 + 1, spanY = box.Y1 - box.Y0 + 1;
+ return spanX % 2 != spanY % 2 ? spanX % 2 == 1 : spanY >= spanX;
+ }
+
+ ///
+ /// Adds a wing to a roof: every cell of the box gets the wing's height there unless the
+ /// roof is already higher. A gable climbs from its two long sides to the ridge. A cell it
+ /// raises loses any fixed piece another wing gave it in .
+ /// Cells with a negative coordinate are left out.
+ ///
+ public static void AddWing(Dictionary<(int X, int Y), int> heights, Dictionary<(int X, int Y), string> fixedPieces,
+ (int X0, int Y0, int X1, int Y1) box, bool ridgeAlongY, RoofShape shape, int eaveZ)
+ {
+ int across0 = ridgeAlongY ? box.X0 : box.Y0;
+ int across1 = ridgeAlongY ? box.X1 : box.Y1;
+ for (int x = Math.Max(0, box.X0); x <= box.X1; ++x)
+ {
+ for (int y = Math.Max(0, box.Y0); y <= box.Y1; ++y)
+ {
+ int a = ridgeAlongY ? x : y;
+ int steps = Math.Min(a - across0, across1 - a);
+ int z = eaveZ + (Rise * steps);
+ if (heights.TryGetValue((x, y), out int known) && known >= z)
+ {
+ continue;
+ }
+
+ heights[(x, y)] = z;
+ fixedPieces.Remove((x, y));
+ }
+ }
+ }
+
+ ///
+ /// The roof.txt column of the piece for a cell, from the heights around it; null for a
+ /// cell level with all its neighbours. is the plain piece to
+ /// use when the style has no such joint piece.
+ ///
+ public static string Piece(IReadOnlyDictionary<(int X, int Y), int> heights, int x, int y, out string fallback)
+ {
+ fallback = null;
+ if (!heights.TryGetValue((x, y), out int h))
+ {
+ return null;
+ }
+
+ // -1 lower (or no roof there), 0 level, 1 higher.
+ int Side(int cx, int cy, int ch) => heights.TryGetValue((cx, cy), out int n) ? Math.Sign(n - ch) : -1;
+ bool RidgeAlongYAt(int cx, int cy) => heights.TryGetValue((cx, cy), out int ch) && Side(cx - 1, cy, ch) < 0 && Side(cx + 1, cy, ch) < 0;
+ bool RidgeAlongXAt(int cx, int cy) => heights.TryGetValue((cx, cy), out int ch) && Side(cx, cy - 1, ch) < 0 && Side(cx, cy + 1, ch) < 0;
+
+ int w = Side(x - 1, y, h), e = Side(x + 1, y, h), n = Side(x, y - 1, h), s = Side(x, y + 1, h);
+
+ // Valley: level with one neighbour and below the other on both axes.
+ if (w + e == 1 && w * e == 0 && n + s == 1 && n * s == 0)
+ {
+ if (w > 0)
+ {
+ fallback = s > 0 ? "East" : "South";
+ return s > 0 ? "EDent" : "SDent";
+ }
+
+ fallback = n > 0 ? "West" : "North";
+ return n > 0 ? "WDent" : "NDent";
+ }
+
+ // Ridges of this height leaving the cell.
+ bool armW = w == 0 && RidgeAlongXAt(x - 1, y), armE = e == 0 && RidgeAlongXAt(x + 1, y);
+ bool armN = n == 0 && RidgeAlongYAt(x, y - 1), armS = s == 0 && RidgeAlongYAt(x, y + 1);
+ int arms = (armW ? 1 : 0) + (armE ? 1 : 0) + (armN ? 1 : 0) + (armS ? 1 : 0);
+ if (arms == 4)
+ {
+ fallback = "NSCrosspiece";
+ return "XPiece";
+ }
+
+ if (arms == 3)
+ {
+ fallback = armN && armS ? "NSCrosspiece" : "EWCrosspiece";
+ return !armW ? "ETPiece" : !armE ? "WTPiece" : !armN ? "STPiece" : "NTPiece";
+ }
+
+ bool ridgeY = w < 0 && e < 0, ridgeX = n < 0 && s < 0;
+ if (ridgeY && ridgeX)
+ {
+ return armE || armW ? "EWCrosspiece" : "NSCrosspiece";
+ }
+
+ if (ridgeY)
+ {
+ return "NSCrosspiece";
+ }
+
+ if (ridgeX)
+ {
+ return "EWCrosspiece";
+ }
+
+ int climbX = e - w, climbY = s - n;
+ if (climbX == 0 && climbY == 0)
+ {
+ return null;
+ }
+
+ return Math.Abs(climbX) >= Math.Abs(climbY) ? (climbX > 0 ? "West" : "East") : (climbY > 0 ? "North" : "South");
+ }
+
+ ///
+ /// The wings that roof a house whose cells are : its largest
+ /// rectangles, biggest first, each with its ridge along its longer side. A wing that runs
+ /// through an earlier one across its ridge stops at that ridge, so the two meet in a T
+ /// instead of the wing showing a gable on the far side. Parts narrower than three cells
+ /// get no wing. A plain rectangle, or a shape too ragged to split, is one wing: the
+ /// region's box.
+ ///
+ public static List<((int X0, int Y0, int X1, int Y1) Box, bool RidgeAlongY)> Wings(ICollection<(int X, int Y)> region)
+ {
+ var wings = new List<((int X0, int Y0, int X1, int Y1) Box, bool RidgeAlongY)>();
+ if (region.Count == 0)
+ {
+ return wings;
+ }
+
+ int minX = int.MaxValue, minY = int.MaxValue, maxX = int.MinValue, maxY = int.MinValue;
+ foreach ((int x, int y) in region)
+ {
+ minX = Math.Min(minX, x);
+ minY = Math.Min(minY, y);
+ maxX = Math.Max(maxX, x);
+ maxY = Math.Max(maxY, y);
+ }
+
+ var whole = (minX, minY, maxX, maxY);
+ int width = maxX - minX + 1, height = maxY - minY + 1;
+ if (region.Count == width * height)
+ {
+ wings.Add((whole, RidgeAlongY(whole)));
+ return wings;
+ }
+
+ // Filled cells before (x, y), so a rectangle is checked in one step.
+ var sum = new int[width + 1, height + 1];
+ var set = region as ISet<(int X, int Y)> ?? new HashSet<(int X, int Y)>(region);
+ for (int x = 0; x < width; ++x)
+ {
+ for (int y = 0; y < height; ++y)
+ {
+ sum[x + 1, y + 1] = sum[x, y + 1] + sum[x + 1, y] - sum[x, y] + (set.Contains((minX + x, minY + y)) ? 1 : 0);
+ }
+ }
+
+ bool Full(int x0, int y0, int x1, int y1)
+ {
+ return x0 >= 0 && y0 >= 0 && x1 < width && y1 < height &&
+ sum[x1 + 1, y1 + 1] - sum[x0, y1 + 1] - sum[x1 + 1, y0] + sum[x0, y0] == (x1 - x0 + 1) * (y1 - y0 + 1);
+ }
+
+ var found = new List<(int X0, int Y0, int X1, int Y1)>();
+ for (int x0 = 0; x0 < width; ++x0)
+ {
+ for (int y0 = 0; y0 < height; ++y0)
+ {
+ for (int x1 = x0 + _minWing - 1; x1 < width && Full(x0, y0, x1, y0); ++x1)
+ {
+ for (int y1 = y0 + _minWing - 1; y1 < height && Full(x0, y0, x1, y1); ++y1)
+ {
+ if (!Full(x0 - 1, y0, x0 - 1, y1) && !Full(x1 + 1, y0, x1 + 1, y1) &&
+ !Full(x0, y0 - 1, x1, y0 - 1) && !Full(x0, y1 + 1, x1, y1 + 1))
+ {
+ found.Add((minX + x0, minY + y0, minX + x1, minY + y1));
+ }
+ }
+ }
+ }
+ }
+
+ found.Sort((a, b) => ((b.X1 - b.X0 + 1) * (b.Y1 - b.Y0 + 1)).CompareTo((a.X1 - a.X0 + 1) * (a.Y1 - a.Y0 + 1)));
+ if (found.Count == 0 || found.Count > 6)
+ {
+ wings.Add((whole, RidgeAlongY(whole)));
+ return wings;
+ }
+
+ foreach ((int X0, int Y0, int X1, int Y1) rect in found)
+ {
+ var box = rect;
+ bool alongY = box.Y1 - box.Y0 != box.X1 - box.X0 ? box.Y1 - box.Y0 > box.X1 - box.X0 : RidgeAlongY(box);
+ foreach (((int X0, int Y0, int X1, int Y1) other, bool otherAlongY) in wings)
+ {
+ bool overlap = box.X0 <= other.X1 && box.X1 >= other.X0 && box.Y0 <= other.Y1 && box.Y1 >= other.Y0;
+ if (!overlap || otherAlongY == alongY)
+ {
+ continue;
+ }
+
+ if (alongY)
+ {
+ // The other ridge runs along X: stop at its row when sticking out one way only.
+ bool south = box.Y1 > other.Y1, north = box.Y0 < other.Y0;
+ if (south && !north)
+ {
+ box.Y0 = Math.Max(box.Y0, (other.Y0 + other.Y1 + 1) / 2);
+ }
+ else if (north && !south)
+ {
+ box.Y1 = Math.Min(box.Y1, (other.Y0 + other.Y1) / 2);
+ }
+ }
+ else
+ {
+ bool east = box.X1 > other.X1, west = box.X0 < other.X0;
+ if (east && !west)
+ {
+ box.X0 = Math.Max(box.X0, (other.X0 + other.X1 + 1) / 2);
+ }
+ else if (west && !east)
+ {
+ box.X1 = Math.Min(box.X1, (other.X0 + other.X1) / 2);
+ }
+ }
+ }
+
+ wings.Add((box, alongY));
+ }
+
+ return wings;
+ }
+ }
+}
diff --git a/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.Commands.cs b/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.Commands.cs
index 0712822d..52a88e3b 100644
--- a/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.Commands.cs
+++ b/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.Commands.cs
@@ -998,6 +998,7 @@ private void ApplyLevelDefinitions(IEnumerable levels, bool cus
///
/// The first floor is the lowest Z, up to , that holds a real
/// share of the flat walkable tiles. One stray flat tile low down does not make a floor.
+ /// A design without a floor has it where most of its walls stand.
///
private int DetectFirstFloorZ()
{
@@ -1010,21 +1011,39 @@ private int DetectFirstFloorZ()
}
}
- if (flat.Count == 0)
+ if (flat.Count > 0)
{
- return 0;
+ int needed = Math.Max(4, flat.Values.Max() / 4);
+ foreach ((int z, int count) in flat)
+ {
+ if (z >= 0 && z <= MaxFirstFloorZ && count >= needed)
+ {
+ return z;
+ }
+ }
+ }
+
+ // No floor laid (a building lifted off the map stands on terrain): where its walls stand.
+ var walls = new Dictionary();
+ foreach (MultiTile tile in CompList.RealTiles)
+ {
+ if (tile.Z >= 0 && tile.Z <= MaxFirstFloorZ && tile.Height >= 10 &&
+ (TileData.ItemTable[tile.Id].Flags & TileFlag.Wall) != 0)
+ {
+ walls[tile.Z] = walls.GetValueOrDefault(tile.Z) + 1;
+ }
}
- int needed = Math.Max(4, flat.Values.Max() / 4);
- foreach ((int z, int count) in flat)
+ int best = 0, most = 3;
+ foreach ((int z, int count) in walls)
{
- if (z >= 0 && z <= MaxFirstFloorZ && count >= needed)
+ if (count > most)
{
- return z;
+ (best, most) = (z, count);
}
}
- return 0;
+ return best;
}
/// A short label for a level's button: the number of "Floor 2", else the start of the name.
diff --git a/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.cs b/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.cs
index 2fa581f9..932ee8ad 100644
--- a/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.cs
+++ b/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.cs
@@ -92,7 +92,14 @@ public EditorSession(ArtMasks masks, HouseStyles houseStyles)
_tools[ToolKind.Floor] = new FloorStyleTool(this);
_tools[ToolKind.Door] = new DoorTool(this);
_tools[ToolKind.Stair] = new StairTool(this);
- _tools[ToolKind.Roof] = new RoofTool(this);
+ var roof = new RoofTool(this);
+ roof.Changed += () =>
+ {
+ ToolChanged?.Invoke();
+ Invalidated?.Invoke();
+ };
+ roof.Committed += () => LayersChanged?.Invoke();
+ _tools[ToolKind.Roof] = roof;
_tools[ToolKind.Foundation] = new FoundationTool(this);
_tools[ToolKind.FloorPattern] = new FloorPatternTool(this);
_pasteTool = new PasteTool(this);
@@ -181,6 +188,7 @@ public bool Redo()
private void SetDocument(MultiEditorComponentList list)
{
CancelTool();
+ Roof.Discard();
CompList = list;
_selection.Clear();
HoverTile = null;
@@ -343,6 +351,12 @@ public ToolKind Tool
get => _toolKind;
set
{
+ // A roof still being shaped is placed when another tool is taken up.
+ if (_toolKind == ToolKind.Roof && value != ToolKind.Roof)
+ {
+ Roof.Commit();
+ }
+
CancelTool();
_toolKind = value;
if (IsTileTool(value))
@@ -374,9 +388,12 @@ public static bool IsTileTool(ToolKind kind)
/// The bordered floor laid by the floor pattern tool, or null.
public FloorPattern FloorPattern { get; set; }
- /// The roof tool, for its shape options (ridge, gables, gable fill).
+ /// The roof tool, for its shape options (ridge, gables, gable fill) and the roof being shaped.
public RoofTool Roof => (RoofTool)_tools[ToolKind.Roof];
+ /// True while the roof tool is in use and holds a roof that is not placed yet.
+ public bool ShapingRoof => _temporaryTool == null && _toolKind == ToolKind.Roof && Roof.HasPending;
+
/// Call after a tool option changed, so the preview under the cursor follows.
public void ToolOptionsChanged()
{
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/HousePartTools.cs b/UoFiddler.Plugin.MultiEditor/Tools/HousePartTools.cs
index 80547dc7..7edca4cd 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/HousePartTools.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/HousePartTools.cs
@@ -66,365 +66,6 @@ protected override (List Remove, List<(ushort Id, int X, int Y, int Z
}
}
- /// Which way a gable roof's ridge runs.
- internal enum RoofRidge
- {
- /// As the official houses: along the longer side, or so the ridge gets its crosspiece.
- Auto,
- AlongX,
- AlongY
- }
-
- /// Which gable ends of a roof are closed.
- internal enum RoofGables
- {
- /// The south or east end, as the official houses do.
- Front,
- Both,
- None
- }
-
- /// What closes a gable.
- internal enum RoofGableFill
- {
- /// 3 high cap pieces matching the walls.
- Caps,
-
- /// Whole wall pieces as far as they fit under the slope, caps for the rest: for big, high roofs.
- Walls
- }
-
- ///
- /// A gable roof over a house. A click on (or inside) a walled room fits the roof to its walls;
- /// a drag over the wall cells sizes it by hand, as with the wall tool. The slopes rise 3 per
- /// cell from the eaves, like the official house roofs: West pieces climb to an NS crosspiece
- /// and East pieces come down (North / EW crosspiece / South the other way). Roof pieces
- /// already in those cells are replaced. , and
- /// choose the shape; Shift turns the ridge and Ctrl switches between
- /// one and both gables for a single stroke.
- ///
- internal sealed class RoofTool : PlaneDragTool
- {
- private const int _rise = 3;
- private const string _capStyles = "Miscellaneous Roof Pieces";
-
- public RoofRidge Ridge { get; set; } = RoofRidge.Auto;
-
- public RoofGables Gables { get; set; } = RoofGables.Front;
-
- public RoofGableFill GableFill { get; set; } = RoofGableFill.Caps;
-
- public RoofTool(IEditorContext context) : base(context)
- {
- }
-
- protected override HousePartKind Kind => HousePartKind.Roof;
-
- protected override string ActionName => "Roof";
-
- ///
- /// The eaves go on the work plane, or on top of what the mouse points at (a wall top).
- ///
- protected override void BaseCell(out int x, out int y, out int z)
- {
- Context.CellAt(Context.MouseLoc, out x, out y, out z);
- if (Context.WorkZ is { } baseZ)
- {
- z = baseZ;
- Context.PlaneCell(Context.MouseLoc, z, out x, out y);
- }
- }
-
- protected override (List Remove, List<(ushort Id, int X, int Y, int Z)> Add) Plan(
- int startX, int startY, int endX, int endY, int z, bool final)
- {
- var remove = new List();
- var add = new List<(ushort, int, int, int)>();
- MultiEditorComponentList list = Context.CompList;
-
- // Dragged like the wall tool, over the wall cells. Walls sit on the +X/+Y edges of their
- // cells, so the roof over them is the same box one cell further along X and Y (as in the
- // official houses, which overhang their east and south walls by a cell).
- int wallX0 = Math.Min(startX, endX), wallX1 = Math.Max(startX, endX);
- int wallY0 = Math.Min(startY, endY), wallY1 = Math.Max(startY, endY);
-
- // A click, not a drag: take the walls of the room it points at.
- if (startX == endX && startY == endY && FitToWalls(startX, startY, z, out var fitted))
- {
- (wallX0, wallY0, wallX1, wallY1) = fitted;
- }
-
- int x0 = wallX0 + 1, x1 = wallX1 + 1;
- int y0 = wallY0 + 1, y1 = wallY1 + 1;
-
- // Like the official houses: the slopes go across the odd side, so the ridge gets its
- // crosspiece; otherwise the ridge runs along the longer side, along Y when square.
- int spanX = x1 - x0 + 1, spanY = y1 - y0 + 1;
- bool ridgeAlongY = Ridge switch
- {
- RoofRidge.AlongX => false,
- RoofRidge.AlongY => true,
- _ => spanX % 2 != spanY % 2 ? spanX % 2 == 1 : spanY >= spanX
- };
- ridgeAlongY ^= ShiftHeld;
- int across0 = ridgeAlongY ? x0 : y0;
- int across1 = ridgeAlongY ? x1 : y1;
- int span = across1 - across0 + 1;
- string low = ridgeAlongY ? "West" : "North";
- string high = ridgeAlongY ? "East" : "South";
- string ridge = ridgeAlongY ? "NSCrosspiece" : "EWCrosspiece";
-
- for (int x = x0; x <= x1; ++x)
- {
- for (int y = y0; y <= y1; ++y)
- {
- if (!list.InBounds(x, y))
- {
- continue;
- }
-
- int a = ridgeAlongY ? x : y;
- int fromLow = a - across0;
- int fromHigh = across1 - a;
- string column = span % 2 == 1 && fromLow == fromHigh ? ridge : fromLow < fromHigh ? low : high;
- ushort id = Style.Get(column);
- if (id == 0)
- {
- continue;
- }
-
- foreach (MultiTile tile in list.GetTilesAt(x, y))
- {
- if (list.IsShown(tile) && Context.HouseStyles.TryGetRole(tile.Id, out HouseStyle owner, out _) && owner.Kind == HousePartKind.Roof)
- {
- remove.Add(tile);
- }
- }
-
- add.Add((id, x, y, z + (_rise * Math.Min(fromLow, fromHigh))));
- }
- }
-
- // Caps from an earlier roof over these walls go too, so a turned ridge leaves none behind.
- for (int x = wallX0; x <= x1; ++x)
- {
- for (int y = wallY0; y <= y1; ++y)
- {
- foreach (MultiTile tile in list.GetTilesAt(x, y))
- {
- if (IsCap(tile.Id) && list.IsShown(tile))
- {
- remove.Add(tile);
- }
- }
- }
- }
-
- // Gables: in the wall row at the gable end, filled up to where the slope has risen there.
- RoofGables gables = Gables;
- if (CtrlHeld)
- {
- gables = gables == RoofGables.Both ? RoofGables.Front : RoofGables.Both;
- }
-
- var gableRows = new List();
- if (gables != RoofGables.None)
- {
- gableRows.Add(ridgeAlongY ? wallY1 : wallX1);
- }
-
- if (gables == RoofGables.Both)
- {
- gableRows.Add(ridgeAlongY ? wallY0 : wallX0);
- }
-
- foreach (int row in gableRows)
- {
- ushort wall = GableWall(row, ridgeAlongY, wallX0, wallX1, wallY0, wallY1, z);
- ushort cap = wall != 0 ? CapFor(wall, ridgeAlongY) : (ushort)0;
-
- // Whole walls: the plain piece of the wall's own style that runs along the gable.
- ushort block = 0;
- int blockHeight = 0;
- if (GableFill == RoofGableFill.Walls && wall != 0)
- {
- block = wall;
- if (Context.HouseStyles.TryGetRole(wall, out HouseStyle wallStyle, out _) &&
- wallStyle.Get(ridgeAlongY ? "South2" : "East2") is var plain and not 0)
- {
- block = plain;
- }
-
- blockHeight = TileData.ItemTable[block].Height;
- }
-
- if (cap == 0 && blockHeight <= 0)
- {
- continue;
- }
-
- for (int a = across0; a <= across1; ++a)
- {
- int top = _rise * Math.Min(a - across0, across1 - a);
- int x = ridgeAlongY ? a : row;
- int y = ridgeAlongY ? row : a;
- if (!list.InBounds(x, y))
- {
- continue;
- }
-
- int filled = 0;
- while (blockHeight > 0 && top - filled >= blockHeight)
- {
- add.Add((block, x, y, z + filled));
- filled += blockHeight;
- }
-
- while (cap != 0 && top - filled >= _rise)
- {
- add.Add((cap, x, y, z + filled));
- filled += _rise;
- }
- }
- }
-
- return (remove, add);
- }
-
- ///
- /// The walls a click means: the box of the connected run of wall cells, on the level just
- /// below , that holds the clicked cell. A click inside a room takes the
- /// smallest such box around it. False when there are no walls there.
- ///
- private bool FitToWalls(int cx, int cy, int z, out (int X0, int Y0, int X1, int Y1) box)
- {
- MultiEditorComponentList list = Context.CompList;
- bool IsWall(int x, int y)
- {
- foreach (MultiTile tile in list.GetTilesAt(x, y))
- {
- if (tile.Z < z && tile.Z >= z - 20 &&
- Context.HouseStyles.TryGetRole(tile.Id, out HouseStyle owner, out _) && owner.Kind == HousePartKind.Wall)
- {
- return true;
- }
- }
-
- return false;
- }
-
- box = default;
- long bestArea = long.MaxValue;
- var seen = new HashSet<(int, int)>();
- var queue = new Queue<(int X, int Y)>();
- for (int sx = 0; sx < list.Width; ++sx)
- {
- for (int sy = 0; sy < list.Height; ++sy)
- {
- if (seen.Contains((sx, sy)) || !IsWall(sx, sy))
- {
- continue;
- }
-
- int x0 = sx, y0 = sy, x1 = sx, y1 = sy, cells = 0;
- seen.Add((sx, sy));
- queue.Enqueue((sx, sy));
- while (queue.Count > 0)
- {
- (int x, int y) = queue.Dequeue();
- ++cells;
- x0 = Math.Min(x0, x);
- y0 = Math.Min(y0, y);
- x1 = Math.Max(x1, x);
- y1 = Math.Max(y1, y);
- foreach ((int dx, int dy) in new[] { (1, 0), (-1, 0), (0, 1), (0, -1) })
- {
- (int nx, int ny) = (x + dx, y + dy);
- if (list.InBounds(nx, ny) && !seen.Contains((nx, ny)) && IsWall(nx, ny))
- {
- seen.Add((nx, ny));
- queue.Enqueue((nx, ny));
- }
- }
- }
-
- long area = (long)(x1 - x0 + 1) * (y1 - y0 + 1);
- if (cells > 1 && cx >= x0 && cx <= x1 && cy >= y0 && cy <= y1 && area < bestArea)
- {
- bestArea = area;
- box = (x0, y0, x1, y1);
- }
- }
- }
-
- return bestArea != long.MaxValue;
- }
-
- private bool IsCap(ushort id)
- {
- return Context.HouseStyles.TryGetRole(id, out HouseStyle owner, out _) &&
- owner.Kind == HousePartKind.Misc && owner.Group.StartsWith(_capStyles, StringComparison.Ordinal);
- }
-
- /// A wall tile below the eaves in a gable wall row, or 0 when the row has none.
- private ushort GableWall(int row, bool alongX, int wallX0, int wallX1, int wallY0, int wallY1, int z)
- {
- MultiEditorComponentList list = Context.CompList;
- ushort wall = 0;
- int from = alongX ? wallX0 : wallY0, to = alongX ? wallX1 : wallY1;
- for (int a = from; a <= to && wall == 0; ++a)
- {
- foreach (MultiTile tile in list.GetTilesAt(alongX ? a : row, alongX ? row : a))
- {
- if (tile.Z < z && Context.HouseStyles.TryGetRole(tile.Id, out HouseStyle owner, out _) && owner.Kind == HousePartKind.Wall)
- {
- wall = tile.Id;
- break;
- }
- }
- }
-
- return wall;
- }
-
- ///
- /// The cap for a gable over a wall: the misc.txt roof piece with the wall's tiledata name and
- /// the id nearest its own. Odd pieces close walls along X, even pieces walls along Y (as
- /// placed in the official multis). 0 when no cap matches.
- ///
- private ushort CapFor(ushort wall, bool alongX)
- {
- string name = TileData.ItemTable[wall].Name;
- ushort best = 0;
- foreach (HouseStyle style in Context.HouseStyles.Styles)
- {
- if (style.Kind != HousePartKind.Misc || !style.Group.StartsWith(_capStyles, StringComparison.Ordinal))
- {
- continue;
- }
-
- for (int pair = 1; pair <= 7; pair += 2)
- {
- ushort first = style.Get($"Piece{pair}");
- ushort second = style.Get($"Piece{pair + 1}");
- ushort cap = alongX ? first : second;
- if (first == 0 || second == 0 || TileData.ItemTable[cap].Height > 4 ||
- !string.Equals(TileData.ItemTable[cap].Name, name, StringComparison.OrdinalIgnoreCase))
- {
- continue;
- }
-
- if (best == 0 || Math.Abs(cap - wall) < Math.Abs(best - wall))
- {
- best = cap;
- }
- }
- }
-
- return best;
- }
- }
-
///
/// A house foundation like the client's customizable house multis: the dragged rectangle gets
/// a ring of 5 high foundation walls at the base Z and a dirt floor 7 above it inside.
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/PlaneDragTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/PlaneDragTool.cs
index 323adc08..153f80d3 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/PlaneDragTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/PlaneDragTool.cs
@@ -9,8 +9,10 @@
*
***************************************************************************/
+using System;
using System.Collections.Generic;
using System.Drawing;
+using System.Linq;
using System.Windows.Forms;
using UoFiddler.Plugin.MultiEditor.Classes;
@@ -45,6 +47,9 @@ protected PlaneDragTool(IEditorContext context) : base(context)
/// The edit's name in the undo list.
protected abstract string ActionName { get; }
+ /// True when tiles planned past the +X/+Y end of the multi make it bigger instead of being dropped.
+ protected virtual bool GrowsMulti => false;
+
public override void OnMouseDown(MouseEventArgs e)
{
if (Style == null)
@@ -78,8 +83,8 @@ public override void OnMouseUp(MouseEventArgs e)
var (remove, add) = Plan(_startX, _startY, _endX, _endY, _z, final: true);
if (remove.Count > 0 || add.Count > 0)
{
- Context.CompList.ReplaceTiles(remove, add, ActionName);
- Context.AfterEdit(_z);
+ Context.CompList.ReplaceTiles(remove, add, ActionName, GrowsMulti);
+ Context.AfterEdit(add.Count > 0 ? Math.Max(_z, add.Max(a => a.Z)) : _z);
}
}
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs
new file mode 100644
index 00000000..e4dea8bd
--- /dev/null
+++ b/UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs
@@ -0,0 +1,1113 @@
+/***************************************************************************
+ *
+ * $Author: Turley
+ *
+ * "THE BEER-WARE LICENSE"
+ * As long as you retain this notice you can do whatever you want with
+ * this stuff. If we meet some day, and you think this stuff is worth it,
+ * you can buy me a beer in return.
+ *
+ ***************************************************************************/
+
+
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Windows.Forms;
+using Ultima;
+using UoFiddler.Plugin.MultiEditor.Classes;
+
+namespace UoFiddler.Plugin.MultiEditor.Tools
+{
+ /// Which way a gable roof's ridge runs.
+ internal enum RoofRidge
+ {
+ /// As the official houses: along the longer side, or so the ridge gets its crosspiece.
+ Auto,
+ AlongX,
+ AlongY
+ }
+
+ /// Which gable ends of a roof are closed.
+ internal enum RoofGables
+ {
+ /// The south or east end, as the official houses do.
+ Front,
+ Both,
+ None
+ }
+
+ /// What closes a gable.
+ internal enum RoofGableFill
+ {
+ /// 3 high cap pieces matching the walls.
+ Caps,
+
+ /// Whole wall pieces as far as they fit under the slope, caps for the rest: for big, high roofs.
+ Walls
+ }
+
+ /// One rectangle of a roof being shaped: where it lies, how high its eaves are and how it slopes.
+ internal sealed class RoofWing
+ {
+ public int X0 { get; set; }
+
+ public int Y0 { get; set; }
+
+ public int X1 { get; set; }
+
+ public int Y1 { get; set; }
+
+ public int EaveZ { get; set; }
+
+ public RoofShape Shape { get; set; }
+
+ public bool RidgeAlongY { get; set; }
+
+ /// True while the ridge follows the box's proportions as it is resized.
+ public bool RidgeAuto { get; set; }
+
+ public (int X0, int Y0, int X1, int Y1) Box => (X0, Y0, X1, Y1);
+
+ public RoofWing Clone() => (RoofWing)MemberwiseClone();
+
+ public void CopyFrom(RoofWing other)
+ {
+ (X0, Y0, X1, Y1, EaveZ) = (other.X0, other.Y0, other.X1, other.Y1, other.EaveZ);
+ (Shape, RidgeAlongY, RidgeAuto) = (other.Shape, other.RidgeAlongY, other.RidgeAuto);
+ }
+ }
+
+ ///
+ /// Roofs, shaped before they are placed. The first click on (or inside) a walled room fits a
+ /// roof to its walls, part by part on an L or T shaped house; a drag over the walls, the floor
+ /// inside them or the area the roof will cover fits it too, and any other drag is a roof of
+ /// that size on the work plane. The roof then stays pending, shown as it will be built:
+ ///
+ /// - click a wing to select it, drag it to move it, drag an edge of the selected wing to
+ /// resize it;
+ /// - drag anywhere else to add a wing, which joins the others with valleys and T pieces;
+ /// - Shift+click turns a wing's ridge, the Shape and Ridge options
+ /// change the selected wing, Delete removes it;
+ /// - Enter, or switching to another tool, places the roof on the layer named
+ /// in one undo step; Esc drops it.
+ ///
+ /// A fitted roof sits on the wall tops whatever floor is chosen, overhangs the south and east
+ /// walls by a cell and grows the multi when that cell lies outside it. Slopes rise 3 per cell
+ /// like the official house roofs. A roof already there is replaced when it lies wholly under
+ /// the new one and joined otherwise.
+ ///
+ internal sealed class RoofTool : EditorTool
+ {
+ /// The layer a placed roof goes on; made on first use.
+ public const string LayerName = "Roof";
+
+ private const int _rise = RoofPlanner.Rise;
+ private const int _storey = 20;
+ private const string _capStyles = "Miscellaneous Roof Pieces";
+
+ private enum DragKind
+ {
+ None,
+ New,
+ Move,
+ Resize
+ }
+
+ private readonly List _wings = new List();
+ private int _selected = -1;
+ private HouseStyle _lastStyle;
+ private RoofShape _shape = RoofShape.Gable;
+ private RoofRidge _ridge = RoofRidge.Auto;
+
+ private DragKind _drag;
+ private int _startX;
+ private int _startY;
+ private int _endX;
+ private int _endY;
+ private int _z;
+ private RoofWing _before;
+ private int _grabX;
+ private int _grabY;
+ private bool _west;
+ private bool _east;
+ private bool _north;
+ private bool _south;
+
+ public RoofTool(IEditorContext context) : base(context)
+ {
+ }
+
+ /// Raised when the pending roof starts, changes or ends.
+ public event Action Changed;
+
+ /// Raised after a roof was placed.
+ public event Action Committed;
+
+ /// The shape of new wings; also sets the selected wing's.
+ public RoofShape Shape
+ {
+ get => _shape;
+ set
+ {
+ _shape = value;
+ if (SelectedWing is { } wing)
+ {
+ wing.Shape = value;
+ }
+ }
+ }
+
+ /// The ridge direction of new wings; also sets the selected wing's.
+ public RoofRidge Ridge
+ {
+ get => _ridge;
+ set
+ {
+ _ridge = value;
+ if (SelectedWing is { } wing)
+ {
+ wing.RidgeAuto = value == RoofRidge.Auto;
+ wing.RidgeAlongY = value == RoofRidge.Auto ? RoofPlanner.RidgeAlongY(wing.Box) : value == RoofRidge.AlongY;
+ }
+ }
+ }
+
+ public RoofGables Gables { get; set; } = RoofGables.Front;
+
+ public RoofGableFill GableFill { get; set; } = RoofGableFill.Caps;
+
+ /// True while a roof is being shaped and not yet placed.
+ public bool HasPending => _wings.Count > 0;
+
+ public bool HasSelectedWing => SelectedWing != null;
+
+ public IReadOnlyList Wings => _wings;
+
+ public override bool IsDragging => _drag != DragKind.None;
+
+ public override bool TracksCursorCell => true;
+
+ private RoofWing SelectedWing => _selected >= 0 && _selected < _wings.Count ? _wings[_selected] : null;
+
+ /// The roof style chosen in the House tab; a pending roof keeps the last one.
+ private HouseStyle Style
+ {
+ get
+ {
+ if (Context.HouseStyle is { Kind: HousePartKind.Roof } style)
+ {
+ _lastStyle = style;
+ return style;
+ }
+
+ return HasPending ? _lastStyle : null;
+ }
+ }
+
+ // ---------------------------------------------------------------- shaping
+
+ public override void OnMouseDown(MouseEventArgs e)
+ {
+ if (Style == null)
+ {
+ return;
+ }
+
+ if (HasPending)
+ {
+ int hit = HitWing(out int cx, out int cy);
+ if (hit >= 0)
+ {
+ RoofWing wing = _wings[hit];
+ bool wasSelected = hit == _selected;
+ _selected = hit;
+ if (ShiftHeld)
+ {
+ Turn(wing);
+ Changed?.Invoke();
+ return;
+ }
+
+ _before = wing.Clone();
+ (_grabX, _grabY) = (cx, cy);
+
+ // The selected wing is resized by its outermost cells; a side too short to
+ // have a middle moves the wing instead.
+ bool wide = wing.X1 - wing.X0 >= 2, deep = wing.Y1 - wing.Y0 >= 2;
+ _west = wasSelected && wide && cx == wing.X0;
+ _east = wasSelected && wide && cx == wing.X1;
+ _north = wasSelected && deep && cy == wing.Y0;
+ _south = wasSelected && deep && cy == wing.Y1;
+ _drag = _west || _east || _north || _south ? DragKind.Resize : DragKind.Move;
+ Changed?.Invoke();
+ return;
+ }
+
+ // A new wing, level with the wing worked on last.
+ _z = (SelectedWing ?? _wings[^1]).EaveZ;
+ Context.PlaneCell(Context.MouseLoc, _z, out _startX, out _startY);
+ }
+ else
+ {
+ BaseCell(out _startX, out _startY, out _z);
+ }
+
+ (_endX, _endY) = (_startX, _startY);
+ _drag = DragKind.New;
+ }
+
+ public override void OnMouseMove(MouseEventArgs e)
+ {
+ switch (_drag)
+ {
+ case DragKind.New:
+ Context.PlaneCell(Context.MouseLoc, _z, out _endX, out _endY);
+ break;
+ case DragKind.Move:
+ case DragKind.Resize:
+ DragWing();
+ break;
+ }
+ }
+
+ public override void OnMouseUp(MouseEventArgs e)
+ {
+ DragKind drag = _drag;
+ if (drag is DragKind.Move or DragKind.Resize)
+ {
+ DragWing();
+ }
+
+ _drag = DragKind.None;
+ if (drag == DragKind.New)
+ {
+ Context.PlaneCell(Context.MouseLoc, _z, out _endX, out _endY);
+ List wings = WingsFor(_startX, _startY, _endX, _endY, _z, out bool fitted);
+ if (HasPending && !fitted && _startX == _endX && _startY == _endY)
+ {
+ // A click beside the roof lets go of the selected wing.
+ _selected = -1;
+ }
+ else
+ {
+ _wings.AddRange(wings);
+ _selected = _wings.Count - wings.Count;
+ }
+
+ Changed?.Invoke();
+ }
+ else if (drag != DragKind.None)
+ {
+ _before = null;
+ Changed?.Invoke();
+ }
+ }
+
+ /// Stops a drag: a wing being moved or resized goes back to where it was.
+ public override void Cancel()
+ {
+ if (_drag is DragKind.Move or DragKind.Resize && _before != null && SelectedWing is { } wing)
+ {
+ wing.CopyFrom(_before);
+ }
+
+ _before = null;
+ _drag = DragKind.None;
+ }
+
+ /// Drops the pending roof.
+ public void Discard()
+ {
+ bool had = HasPending;
+ _wings.Clear();
+ _selected = -1;
+ _before = null;
+ _drag = DragKind.None;
+ if (had)
+ {
+ Changed?.Invoke();
+ }
+ }
+
+ /// Removes the selected wing from the pending roof.
+ public void DeleteWing()
+ {
+ if (SelectedWing == null || IsDragging)
+ {
+ return;
+ }
+
+ _wings.RemoveAt(_selected);
+ _selected = _wings.Count - 1;
+ Changed?.Invoke();
+ }
+
+ ///
+ /// Places the pending roof: its tiles go on the layer, pieces of
+ /// an older roof that had to change stay on their own layer, all in one undo step.
+ ///
+ public void Commit()
+ {
+ Cancel();
+ if (!HasPending)
+ {
+ return;
+ }
+
+ if (Style != null)
+ {
+ var (remove, add) = Plan(_wings);
+ if (remove.Count > 0 || add.Count > 0)
+ {
+ Context.CompList.ReplaceTilesOnLayer(remove, add, "Roof", LayerName);
+ Context.AfterEdit(add.Count > 0 ? add.Max(a => a.Z) : null);
+ Committed?.Invoke();
+ }
+ }
+
+ Discard();
+ }
+
+ /// Lays a roof in one go, as a press at one cell and a release at another would shape it. For scripts and tests.
+ public void Place(int startX, int startY, int endX, int endY, int z)
+ {
+ if (Style == null)
+ {
+ return;
+ }
+
+ _wings.AddRange(WingsFor(startX, startY, endX, endY, z, out _));
+ Commit();
+ }
+
+ ///
+ /// The eaves go on the work plane, or on top of what the mouse points at (a wall top).
+ ///
+ private void BaseCell(out int x, out int y, out int z)
+ {
+ Context.CellAt(Context.MouseLoc, out x, out y, out z);
+ if (Context.WorkZ is { } baseZ)
+ {
+ z = baseZ;
+ Context.PlaneCell(Context.MouseLoc, z, out x, out y);
+ }
+ }
+
+ /// The pending wing under the mouse, the selected one first, and the cell pointed at on its eaves.
+ private int HitWing(out int cx, out int cy)
+ {
+ (cx, cy) = (0, 0);
+ for (int pass = 0; pass < 2; ++pass)
+ {
+ for (int i = _wings.Count - 1; i >= 0; --i)
+ {
+ if ((pass == 0) != (i == _selected))
+ {
+ continue;
+ }
+
+ RoofWing wing = _wings[i];
+ Context.PlaneCell(Context.MouseLoc, wing.EaveZ, out cx, out cy);
+ if (cx >= wing.X0 && cx <= wing.X1 && cy >= wing.Y0 && cy <= wing.Y1)
+ {
+ return i;
+ }
+ }
+ }
+
+ return -1;
+ }
+
+ private void DragWing()
+ {
+ if (_before == null || SelectedWing is not { } wing)
+ {
+ return;
+ }
+
+ Context.PlaneCell(Context.MouseLoc, _before.EaveZ, out int cx, out int cy);
+ int dx = cx - _grabX, dy = cy - _grabY;
+ if (_drag == DragKind.Move)
+ {
+ dx = Math.Max(dx, -_before.X0);
+ dy = Math.Max(dy, -_before.Y0);
+ (wing.X0, wing.X1, wing.Y0, wing.Y1) = (_before.X0 + dx, _before.X1 + dx, _before.Y0 + dy, _before.Y1 + dy);
+ return;
+ }
+
+ wing.X0 = _west ? Math.Clamp(_before.X0 + dx, 0, _before.X1) : _before.X0;
+ wing.X1 = _east ? Math.Max(_before.X1 + dx, _before.X0) : _before.X1;
+ wing.Y0 = _north ? Math.Clamp(_before.Y0 + dy, 0, _before.Y1) : _before.Y0;
+ wing.Y1 = _south ? Math.Max(_before.Y1 + dy, _before.Y0) : _before.Y1;
+ if (wing.RidgeAuto)
+ {
+ wing.RidgeAlongY = RoofPlanner.RidgeAlongY(wing.Box);
+ }
+ }
+
+ /// Turns a wing's ridge the other way.
+ private static void Turn(RoofWing wing)
+ {
+ wing.RidgeAlongY = !wing.RidgeAlongY;
+ wing.RidgeAuto = false;
+ }
+
+ ///
+ /// The wings a stroke makes. Walls sit on the +X/+Y edges of their cells, so the roof over
+ /// them is their box one cell further along X and Y (as in the official houses, which
+ /// overhang their east and south walls by a cell). A click takes the walls of the room it
+ /// points at, each part of an L or T shaped house as a wing of its own; a drag that comes
+ /// within a cell of such a roof on every side means that roof. Any other stroke is the
+ /// roof itself, at . Shift turns a gable's ridge.
+ ///
+ private List WingsFor(int startX, int startY, int endX, int endY, int z, out bool fitted)
+ {
+ int x0 = Math.Min(startX, endX), x1 = Math.Max(startX, endX);
+ int y0 = Math.Min(startY, endY), y1 = Math.Max(startY, endY);
+ bool click = x0 == x1 && y0 == y1;
+ var wings = new List();
+ fitted = FitToWalls(x0, y0, x1, y1, z, out WallBox walls);
+ if (fitted)
+ {
+ (x0, y0, x1, y1) = (walls.X0 + 1, walls.Y0 + 1, walls.X1 + 1, walls.Y1 + 1);
+ z = walls.Top;
+ if (click && Shape == RoofShape.Gable)
+ {
+ var parts = RoofPlanner.Wings(RoofRegion(walls));
+ if (parts.Count > 1)
+ {
+ foreach (((int X0, int Y0, int X1, int Y1) box, bool alongY) in parts)
+ {
+ wings.Add(new RoofWing { X0 = box.X0, Y0 = box.Y0, X1 = box.X1, Y1 = box.Y1, EaveZ = z, RidgeAlongY = alongY });
+ }
+
+ return wings;
+ }
+ }
+ }
+
+ bool auto = Ridge == RoofRidge.Auto;
+ bool ridgeAlongY = auto ? RoofPlanner.RidgeAlongY((x0, y0, x1, y1)) : Ridge == RoofRidge.AlongY;
+ if (ShiftHeld && Shape == RoofShape.Gable)
+ {
+ (ridgeAlongY, auto) = (!ridgeAlongY, false);
+ }
+
+ wings.Add(new RoofWing
+ {
+ X0 = x0, Y0 = y0, X1 = x1, Y1 = y1, EaveZ = z, Shape = Shape,
+ RidgeAlongY = ridgeAlongY, RidgeAuto = auto
+ });
+ return wings;
+ }
+
+ // ---------------------------------------------------------------- overlay
+
+ public override void PaintOverlay(IToolOverlay overlay)
+ {
+ if (Style == null)
+ {
+ return;
+ }
+
+ // What is shown is what Enter would build: the pending wings, with the one being
+ // dragged out; before there is a roof, the one a click here would start.
+ var wings = new List(_wings);
+ if (_drag == DragKind.New)
+ {
+ wings.AddRange(WingsFor(_startX, _startY, _endX, _endY, _z, out _));
+ }
+ else if (!HasPending)
+ {
+ BaseCell(out int x, out int y, out int z);
+ wings.AddRange(WingsFor(x, y, x, y, z, out _));
+ }
+
+ var (remove, add) = Plan(wings);
+ foreach (MultiTile tile in remove)
+ {
+ overlay.Highlight(tile, TileHighlight.Remove);
+ }
+
+ foreach (var (id, x, y, z, _) in add)
+ {
+ overlay.Ghost(id, x, y, z);
+ }
+
+ for (int i = 0; i < _wings.Count; ++i)
+ {
+ RoofWing wing = _wings[i];
+ Point top = Corner(wing.X0, wing.Y0, wing.EaveZ), right = Corner(wing.X1 + 1, wing.Y0, wing.EaveZ);
+ Point bottom = Corner(wing.X1 + 1, wing.Y1 + 1, wing.EaveZ), left = Corner(wing.X0, wing.Y1 + 1, wing.EaveZ);
+ overlay.Polyline(new[] { top, right, bottom, left }, closed: true);
+ if (i != _selected)
+ {
+ continue;
+ }
+
+ // Grips in the middle of the selected wing's sides.
+ foreach ((Point a, Point b) in new[] { (top, right), (right, bottom), (bottom, left), (left, top) })
+ {
+ var mid = new Point((a.X + b.X) / 2, (a.Y + b.Y) / 2);
+ overlay.Polyline(new[]
+ {
+ new Point(mid.X - 5, mid.Y - 5), new Point(mid.X + 5, mid.Y - 5),
+ new Point(mid.X + 5, mid.Y + 5), new Point(mid.X - 5, mid.Y + 5)
+ }, closed: true);
+ }
+ }
+ }
+
+ /// Canvas position of the top corner of a cell's diamond at height z.
+ private static Point Corner(int x, int y, int z)
+ {
+ return new Point(((x - y) * 22) + MultiEditorComponentList.GapXMod, ((x + y) * 22) - (z * 4) - 22);
+ }
+
+ // ---------------------------------------------------------------- planning
+
+ ///
+ /// The tiles a roof of these wings takes away and adds. An added tile with no layer goes
+ /// on the roof layer; a re-pieced tile of an older roof names the layer it stays on.
+ ///
+ private (List Remove, List<(ushort Id, int X, int Y, int Z, TileLayer Layer)> Add) Plan(IReadOnlyList wings)
+ {
+ var remove = new List();
+ var add = new List<(ushort Id, int X, int Y, int Z, TileLayer Layer)>();
+ HouseStyle style = Style;
+ if (wings.Count == 0 || style == null)
+ {
+ return (remove, add);
+ }
+
+ MultiEditorComponentList list = Context.CompList;
+ var heights = new Dictionary<(int X, int Y), int>();
+ var fixedPieces = new Dictionary<(int X, int Y), string>();
+ foreach (RoofWing wing in wings)
+ {
+ RoofPlanner.AddWing(heights, fixedPieces, wing.Box, wing.RidgeAlongY, wing.Shape, wing.EaveZ);
+ }
+
+ var footprint = new HashSet<(int X, int Y)>(heights.Keys);
+ JoinExisting(footprint, heights, fixedPieces, remove, add);
+
+ foreach ((int x, int y) in footprint)
+ {
+ if (!fixedPieces.TryGetValue((x, y), out string column))
+ {
+ column = RoofPlanner.Piece(heights, x, y, out string fallback) ?? (wings[0].RidgeAlongY ? "West" : "North");
+ if (style.Get(column) == 0 && fallback != null)
+ {
+ column = fallback;
+ }
+ }
+
+ ushort id = style.Get(column);
+ if (id != 0)
+ {
+ add.Add((id, x, y, heights[(x, y)], null));
+ }
+ }
+
+ // Caps from an earlier roof over these walls go too, so a turned ridge leaves none behind.
+ foreach (RoofWing wing in wings)
+ {
+ for (int x = wing.X0 - 1; x <= wing.X1; ++x)
+ {
+ for (int y = wing.Y0 - 1; y <= wing.Y1; ++y)
+ {
+ foreach (MultiTile tile in list.GetTilesAt(x, y))
+ {
+ if (IsCap(tile.Id) && list.IsShown(tile) && !remove.Contains(tile))
+ {
+ remove.Add(tile);
+ }
+ }
+ }
+ }
+ }
+
+ // Every gable wing closes the ends it shows.
+ var caps = new HashSet<(ushort, int, int, int)>();
+ foreach (RoofWing wing in wings)
+ {
+ if (wing.Shape == RoofShape.Gable)
+ {
+ AddGables(wing, heights, caps, add);
+ }
+ }
+
+ return (remove, add);
+ }
+
+ ///
+ /// Closes a gable's ends: in the wall row at the gable end, each wall cell is filled up
+ /// to where the wing's slope has risen over it. An end that runs into another wing shows
+ /// no gable and gets none: only cells with no roof beyond them are filled.
+ ///
+ private void AddGables(RoofWing wing, Dictionary<(int X, int Y), int> heights, HashSet<(ushort, int, int, int)> placed,
+ List<(ushort Id, int X, int Y, int Z, TileLayer Layer)> add)
+ {
+ MultiEditorComponentList list = Context.CompList;
+ bool ridgeAlongY = wing.RidgeAlongY;
+ int z = wing.EaveZ;
+ int wallX0 = wing.X0 - 1, wallX1 = wing.X1 - 1;
+ int wallY0 = wing.Y0 - 1, wallY1 = wing.Y1 - 1;
+ int across0 = ridgeAlongY ? wing.X0 : wing.Y0;
+ int across1 = ridgeAlongY ? wing.X1 : wing.Y1;
+
+ var gableRows = new List<(int Row, bool Front)>();
+ if (Gables != RoofGables.None)
+ {
+ gableRows.Add((ridgeAlongY ? wallY1 : wallX1, true));
+ }
+
+ if (Gables == RoofGables.Both)
+ {
+ gableRows.Add((ridgeAlongY ? wallY0 : wallX0, false));
+ }
+
+ foreach ((int row, bool front) in gableRows)
+ {
+ ushort wall = GableWall(row, ridgeAlongY, wallX0, wallX1, wallY0, wallY1, z);
+ ushort cap = wall != 0 ? CapFor(wall, ridgeAlongY) : (ushort)0;
+
+ // Whole walls: the plain piece of the wall's own style that runs along the gable.
+ ushort block = 0;
+ int blockHeight = 0;
+ if (GableFill == RoofGableFill.Walls && wall != 0)
+ {
+ block = wall;
+ if (Context.HouseStyles.TryGetRole(wall, out HouseStyle wallStyle, out _) &&
+ wallStyle.Get(ridgeAlongY ? "South2" : "East2") is var plain and not 0)
+ {
+ block = plain;
+ }
+
+ blockHeight = TileData.ItemTable[block].Height;
+ }
+
+ if (cap == 0 && blockHeight <= 0)
+ {
+ continue;
+ }
+
+ for (int a = across0; a <= across1; ++a)
+ {
+ int x = ridgeAlongY ? a : row;
+ int y = ridgeAlongY ? row : a;
+
+ // The front wall stands a cell inside the roof's last row, the back wall a
+ // cell before its first; the end shows where no roof lies past it.
+ (int X, int Y) beyond = front ? (ridgeAlongY ? (x, y + 2) : (x + 2, y)) : (x, y);
+ if (!list.InBounds(x, y) || heights.ContainsKey(beyond) || !HasStoreyWall(x, y, z))
+ {
+ continue;
+ }
+
+ int top = _rise * Math.Min(a - across0, across1 - a);
+ int filled = 0;
+ while (blockHeight > 0 && top - filled >= blockHeight)
+ {
+ if (placed.Add((block, x, y, z + filled)))
+ {
+ add.Add((block, x, y, z + filled, null));
+ }
+
+ filled += blockHeight;
+ }
+
+ while (cap != 0 && top - filled >= _rise)
+ {
+ if (placed.Add((cap, x, y, z + filled)))
+ {
+ add.Add((cap, x, y, z + filled, null));
+ }
+
+ filled += _rise;
+ }
+ }
+ }
+ }
+
+ /// A connected run of wall cells and the Z its walls end at.
+ private readonly record struct WallBox(int X0, int Y0, int X1, int Y1, int Top, HashSet<(int X, int Y)> Cells);
+
+ ///
+ /// The cells a roof over these walls covers: the wall cells and everything they enclose,
+ /// one cell further along X and Y. For walls that do not close it is the walls alone.
+ ///
+ private static HashSet<(int X, int Y)> RoofRegion(WallBox walls)
+ {
+ // Flood the outside, from a ring one cell around the box.
+ var outside = new HashSet<(int X, int Y)>();
+ var queue = new Queue<(int X, int Y)>();
+ outside.Add((walls.X0 - 1, walls.Y0 - 1));
+ queue.Enqueue((walls.X0 - 1, walls.Y0 - 1));
+ while (queue.Count > 0)
+ {
+ (int x, int y) = queue.Dequeue();
+ foreach ((int dx, int dy) in new[] { (1, 0), (-1, 0), (0, 1), (0, -1) })
+ {
+ (int X, int Y) next = (x + dx, y + dy);
+ if (next.X >= walls.X0 - 1 && next.X <= walls.X1 + 1 && next.Y >= walls.Y0 - 1 && next.Y <= walls.Y1 + 1 &&
+ !walls.Cells.Contains(next) && outside.Add(next))
+ {
+ queue.Enqueue(next);
+ }
+ }
+ }
+
+ var region = new HashSet<(int X, int Y)>();
+ for (int x = walls.X0; x <= walls.X1; ++x)
+ {
+ for (int y = walls.Y0; y <= walls.Y1; ++y)
+ {
+ if (!outside.Contains((x, y)))
+ {
+ region.Add((x + 1, y + 1));
+ }
+ }
+ }
+
+ return region;
+ }
+
+ ///
+ /// Fits a new roof to the roof already there. A roof lying wholly under the new one is
+ /// replaced. One that reaches beyond it is joined: each cell keeps the higher of the two,
+ /// and the old cells next to the new roof get the piece their place now calls for (a
+ /// valley, a T where the ridges meet), in their own style. Cells the old roof keeps are
+ /// taken out of .
+ ///
+ private void JoinExisting(HashSet<(int X, int Y)> footprint, Dictionary<(int X, int Y), int> heights,
+ Dictionary<(int X, int Y), string> fixedPieces, List remove, List<(ushort Id, int X, int Y, int Z, TileLayer Layer)> add)
+ {
+ MultiEditorComponentList list = Context.CompList;
+ var existing = new Dictionary<(int X, int Y), List>();
+ foreach (MultiTile tile in list.RealTiles)
+ {
+ if (!list.IsShown(tile) || !IsRoofPiece(tile.Id))
+ {
+ continue;
+ }
+
+ if (!existing.TryGetValue((tile.X, tile.Y), out List tiles))
+ {
+ existing[(tile.X, tile.Y)] = tiles = new List();
+ }
+
+ tiles.Add(tile);
+ }
+
+ var seen = new HashSet<(int X, int Y)>();
+ var queue = new Queue<(int X, int Y)>();
+ var kept = new Dictionary<(int X, int Y), MultiTile>();
+ foreach ((int X, int Y) start in new List<(int X, int Y)>(footprint))
+ {
+ if (!existing.ContainsKey(start) || !seen.Add(start))
+ {
+ continue;
+ }
+
+ var roof = new List<(int X, int Y)>();
+ bool inside = true;
+ queue.Enqueue(start);
+ while (queue.Count > 0)
+ {
+ (int x, int y) = queue.Dequeue();
+ roof.Add((x, y));
+ inside &= footprint.Contains((x, y)) || kept.ContainsKey((x, y));
+ foreach ((int dx, int dy) in new[] { (1, 0), (-1, 0), (0, 1), (0, -1) })
+ {
+ if (existing.ContainsKey((x + dx, y + dy)) && seen.Add((x + dx, y + dy)))
+ {
+ queue.Enqueue((x + dx, y + dy));
+ }
+ }
+ }
+
+ foreach ((int X, int Y) cell in roof)
+ {
+ List tiles = existing[cell];
+ MultiTile top = tiles[0];
+ foreach (MultiTile tile in tiles)
+ {
+ if (tile.Z > top.Z)
+ {
+ top = tile;
+ }
+ }
+
+ if (inside || (footprint.Contains(cell) && heights[cell] > top.Z))
+ {
+ remove.AddRange(tiles);
+ continue;
+ }
+
+ heights[cell] = top.Z;
+ fixedPieces.Remove(cell);
+ footprint.Remove(cell);
+ kept[cell] = top;
+ }
+ }
+
+ foreach (((int x, int y), MultiTile tile) in kept)
+ {
+ bool beside = false;
+ for (int dx = -2; dx <= 2 && !beside; ++dx)
+ {
+ for (int dy = -2; dy <= 2 && !beside; ++dy)
+ {
+ beside = footprint.Contains((x + dx, y + dy));
+ }
+ }
+
+ string fallback = null;
+ string column = beside ? RoofPlanner.Piece(heights, x, y, out fallback) : null;
+ if (column == null)
+ {
+ continue;
+ }
+
+ HouseStyle style = Style;
+ string now = null;
+ if (Context.HouseStyles.TryGetRoleByArt(tile.Id, out HouseStyle owner, out string slot, out _) && owner.Kind == HousePartKind.Roof)
+ {
+ (style, now) = (owner, slot);
+ }
+
+ if (now == column || (style.Get(column) == 0 && now == fallback))
+ {
+ continue;
+ }
+
+ ushort id = style.Get(column) != 0 ? style.Get(column) : style.Get(fallback ?? column);
+ if (id != 0 && id != tile.Id)
+ {
+ remove.Add(tile);
+ add.Add((id, x, y, tile.Z, tile.Layer));
+ }
+ }
+ }
+
+ private bool IsRoofPiece(ushort id)
+ {
+ return Context.HouseStyles.TryGetRole(id, out HouseStyle owner, out _)
+ ? owner.Kind == HousePartKind.Roof
+ : (TileData.ItemTable[id].Flags & TileFlag.Roof) != 0;
+ }
+
+ ///
+ /// The walls a stroke means, among the walls standing on or just below
+ /// . A click (one cell) takes the smallest box of connected wall cells
+ /// around it. A drag takes the box whose roof it matches to within a cell on every side.
+ /// False when no walls fit.
+ ///
+ private bool FitToWalls(int x0, int y0, int x1, int y1, int z, out WallBox box)
+ {
+ box = default;
+ bool click = x0 == x1 && y0 == y1;
+ long best = long.MaxValue;
+ foreach (WallBox walls in WallBoxes(z))
+ {
+ long score;
+ if (click)
+ {
+ if (x0 < walls.X0 || x0 > walls.X1 || y0 < walls.Y0 || y0 > walls.Y1)
+ {
+ continue;
+ }
+
+ score = (long)(walls.X1 - walls.X0 + 1) * (walls.Y1 - walls.Y0 + 1);
+ }
+ else
+ {
+ int dx0 = Math.Abs(x0 - (walls.X0 + 1)), dx1 = Math.Abs(x1 - (walls.X1 + 1));
+ int dy0 = Math.Abs(y0 - (walls.Y0 + 1)), dy1 = Math.Abs(y1 - (walls.Y1 + 1));
+ if (Math.Max(Math.Max(dx0, dx1), Math.Max(dy0, dy1)) > 1)
+ {
+ continue;
+ }
+
+ score = dx0 + dx1 + dy0 + dy1;
+ }
+
+ if (score < best)
+ {
+ best = score;
+ box = walls;
+ }
+ }
+
+ return best != long.MaxValue;
+ }
+
+ ///
+ /// The boxes of connected wall cells of the storey that stands on or just below
+ /// (the work plane, or the top of what the mouse points at), each with
+ /// the Z its walls end at. Walls a little short of a storey count as a full one, as the
+ /// official houses roof their 19 high plaster walls at 20.
+ ///
+ private List WallBoxes(int z)
+ {
+ MultiEditorComponentList list = Context.CompList;
+ var tops = new Dictionary<(int, int), int>();
+ foreach (MultiTile tile in list.RealTiles)
+ {
+ if (tile.Z > z || tile.Z <= z - _storey - 5 || !list.IsShown(tile) || !IsStoreyWall(tile))
+ {
+ continue;
+ }
+
+ int height = tile.Height >= _storey - 3 ? Math.Max(tile.Height, _storey) : tile.Height;
+ int top = tile.Z + height;
+ if (!tops.TryGetValue((tile.X, tile.Y), out int known) || top > known)
+ {
+ tops[(tile.X, tile.Y)] = top;
+ }
+ }
+
+ var boxes = new List();
+ var seen = new HashSet<(int, int)>();
+ var queue = new Queue<(int X, int Y)>();
+ var counts = new Dictionary();
+ foreach ((int, int) start in tops.Keys)
+ {
+ if (!seen.Add(start))
+ {
+ continue;
+ }
+
+ int x0 = start.Item1, y0 = start.Item2, x1 = x0, y1 = y0;
+ var cells = new HashSet<(int X, int Y)>();
+ counts.Clear();
+ queue.Enqueue(start);
+ while (queue.Count > 0)
+ {
+ (int x, int y) = queue.Dequeue();
+ cells.Add((x, y));
+ x0 = Math.Min(x0, x);
+ y0 = Math.Min(y0, y);
+ x1 = Math.Max(x1, x);
+ y1 = Math.Max(y1, y);
+ int top = tops[(x, y)];
+ counts[top] = counts.GetValueOrDefault(top) + 1;
+ foreach ((int dx, int dy) in new[] { (1, 0), (-1, 0), (0, 1), (0, -1) })
+ {
+ (int, int) next = (x + dx, y + dy);
+ if (tops.ContainsKey(next) && seen.Add(next))
+ {
+ queue.Enqueue(next);
+ }
+ }
+ }
+
+ if (cells.Count > 1)
+ {
+ int common = counts.OrderByDescending(c => c.Value).ThenByDescending(c => c.Key).First().Key;
+ boxes.Add(new WallBox(x0, y0, x1, y1, common, cells));
+ }
+ }
+
+ return boxes;
+ }
+
+ /// True when a wall of the storey below stands in the cell.
+ private bool HasStoreyWall(int x, int y, int z)
+ {
+ foreach (MultiTile tile in Context.CompList.GetTilesAt(x, y))
+ {
+ if (tile.Z < z && tile.Z > z - _storey - 5 && IsStoreyWall(tile))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /// A wall, window or door at least half a storey high; not a gable cap or a roof piece.
+ private bool IsStoreyWall(MultiTile tile)
+ {
+ if (tile.Height < _storey / 2)
+ {
+ return false;
+ }
+
+ if (Context.HouseStyles.TryGetRole(tile.Id, out HouseStyle owner, out _))
+ {
+ return owner.Kind is HousePartKind.Wall or HousePartKind.Door;
+ }
+
+ TileFlag flags = TileData.ItemTable[tile.Id].Flags;
+ return (flags & (TileFlag.Wall | TileFlag.Window | TileFlag.Door)) != 0 && (flags & TileFlag.Roof) == 0;
+ }
+
+ private bool IsCap(ushort id)
+ {
+ return Context.HouseStyles.TryGetRole(id, out HouseStyle owner, out _) &&
+ owner.Kind == HousePartKind.Misc && owner.Group.StartsWith(_capStyles, StringComparison.Ordinal);
+ }
+
+ /// A wall tile below the eaves in a gable wall row, or 0 when the row has none.
+ private ushort GableWall(int row, bool alongX, int wallX0, int wallX1, int wallY0, int wallY1, int z)
+ {
+ MultiEditorComponentList list = Context.CompList;
+ ushort wall = 0;
+ int from = alongX ? wallX0 : wallY0, to = alongX ? wallX1 : wallY1;
+ for (int a = from; a <= to && wall == 0; ++a)
+ {
+ foreach (MultiTile tile in list.GetTilesAt(alongX ? a : row, alongX ? row : a))
+ {
+ if (tile.Z < z && Context.HouseStyles.TryGetRole(tile.Id, out HouseStyle owner, out _) && owner.Kind == HousePartKind.Wall)
+ {
+ wall = tile.Id;
+ break;
+ }
+ }
+ }
+
+ return wall;
+ }
+
+ ///
+ /// The cap for a gable over a wall: the misc.txt roof piece with the wall's tiledata name and
+ /// the id nearest its own. Odd pieces close walls along X, even pieces walls along Y (as
+ /// placed in the official multis). 0 when no cap matches.
+ ///
+ private ushort CapFor(ushort wall, bool alongX)
+ {
+ string name = TileData.ItemTable[wall].Name;
+ ushort best = 0;
+ foreach (HouseStyle style in Context.HouseStyles.Styles)
+ {
+ if (style.Kind != HousePartKind.Misc || !style.Group.StartsWith(_capStyles, StringComparison.Ordinal))
+ {
+ continue;
+ }
+
+ for (int pair = 1; pair <= 7; pair += 2)
+ {
+ ushort first = style.Get($"Piece{pair}");
+ ushort second = style.Get($"Piece{pair + 1}");
+ ushort cap = alongX ? first : second;
+ if (first == 0 || second == 0 || TileData.ItemTable[cap].Height > 4 ||
+ !string.Equals(TileData.ItemTable[cap].Name, name, StringComparison.OrdinalIgnoreCase))
+ {
+ continue;
+ }
+
+ if (best == 0 || Math.Abs(cap - wall) < Math.Abs(best - wall))
+ {
+ best = cap;
+ }
+ }
+ }
+
+ return best;
+ }
+ }
+}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.Designer.cs b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.Designer.cs
index 2c244ae0..9cb96933 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.Designer.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.Designer.cs
@@ -54,6 +54,8 @@ private void InitializeComponent()
_floorLabel = new System.Windows.Forms.ToolStripLabel();
_optionsSeparator3 = new System.Windows.Forms.ToolStripSeparator();
_drawTileLabel = new System.Windows.Forms.ToolStripLabel();
+ _shapeSeparator = new System.Windows.Forms.ToolStripSeparator();
+ _shapeLabel = new System.Windows.Forms.ToolStripLabel();
_ridgeSeparator = new System.Windows.Forms.ToolStripSeparator();
_ridgeLabel = new System.Windows.Forms.ToolStripLabel();
_gablesSeparator = new System.Windows.Forms.ToolStripSeparator();
@@ -242,7 +244,7 @@ private void InitializeComponent()
// _optionsStrip
//
_optionsStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
- _optionsStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { _toolLabel, _optionsSeparator1, _placeLabel, _brushLabel, _zStepLabel, _zStepCombo, _optionsSeparator2, _floorLabel, _optionsSeparator3, _drawTileLabel, _ridgeSeparator, _ridgeLabel, _gablesSeparator, _gablesLabel, _gableFillSeparator, _gableFillLabel });
+ _optionsStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { _toolLabel, _optionsSeparator1, _placeLabel, _brushLabel, _zStepLabel, _zStepCombo, _optionsSeparator2, _floorLabel, _optionsSeparator3, _drawTileLabel, _shapeSeparator, _shapeLabel, _ridgeSeparator, _ridgeLabel, _gablesSeparator, _gablesLabel, _gableFillSeparator, _gableFillLabel });
_optionsStrip.Location = new System.Drawing.Point(0, 25);
_optionsStrip.Name = "_optionsStrip";
_optionsStrip.Size = new System.Drawing.Size(1280, 25);
@@ -312,6 +314,18 @@ private void InitializeComponent()
_drawTileLabel.Text = "Tile: none";
_drawTileLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
+ // _shapeSeparator
+ //
+ _shapeSeparator.Name = "_shapeSeparator";
+ _shapeSeparator.Size = new System.Drawing.Size(6, 25);
+ //
+ // _shapeLabel
+ //
+ _shapeLabel.Name = "_shapeLabel";
+ _shapeLabel.Size = new System.Drawing.Size(39, 22);
+ _shapeLabel.Text = "Shape";
+ _shapeLabel.ToolTipText = "Gable: two slopes and a ridge.";
+ //
// _ridgeSeparator
//
_ridgeSeparator.Name = "_ridgeSeparator";
@@ -322,7 +336,7 @@ private void InitializeComponent()
_ridgeLabel.Name = "_ridgeLabel";
_ridgeLabel.Size = new System.Drawing.Size(36, 22);
_ridgeLabel.Text = "Ridge";
- _ridgeLabel.ToolTipText = "Which way the ridge runs. Shift turns it for one stroke.";
+ _ridgeLabel.ToolTipText = "Which way the ridge runs. Shift turns a gable's ridge for one stroke.";
//
// _gablesSeparator
//
@@ -525,6 +539,8 @@ private void InitializeComponent()
private System.Windows.Forms.ToolStripLabel _floorLabel;
private System.Windows.Forms.ToolStripSeparator _optionsSeparator3;
private System.Windows.Forms.ToolStripLabel _drawTileLabel;
+ private System.Windows.Forms.ToolStripSeparator _shapeSeparator;
+ private System.Windows.Forms.ToolStripLabel _shapeLabel;
private System.Windows.Forms.ToolStripSeparator _ridgeSeparator;
private System.Windows.Forms.ToolStripLabel _ridgeLabel;
private System.Windows.Forms.ToolStripSeparator _gablesSeparator;
diff --git a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
index 007ed9df..1ace2356 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
@@ -503,7 +503,8 @@ private void DefineCommands()
_paste = Command("Edit", "Paste", () => Session.Paste(), Keys.Control | Keys.V, hasDoc, glyph: Glyphs.Paste);
_duplicate = Command("Edit", "Duplicate selection", () => Session.Duplicate(), Keys.Control | Keys.D, hasSelection);
_repeat = Command("Edit", "Repeat selection...", RepeatSelectionPrompt, Keys.Control | Keys.Shift | Keys.D, hasSelection);
- _delete = Command("Edit", "Delete selection", () => Session.DeleteSelection(), Keys.Delete, hasSelection, glyph: Glyphs.Delete);
+ _delete = Command("Edit", "Delete selection", DeleteSelectionOrWing, Keys.Delete,
+ () => Session != null && (Session.ShapingRoof ? Session.Roof.HasSelectedWing : Session.Selection.Count > 0), glyph: Glyphs.Delete);
_selectAll = Command("Select", "Select all", () => Session.SelectAll(), Keys.Control | Keys.A, hasDoc);
_invert = Command("Select", "Invert selection", () => Session.InvertSelection(), Keys.Control | Keys.Shift | Keys.A, hasDoc);
@@ -598,6 +599,8 @@ private void DefineCommands()
hasDoc, () => Session?.BrushSize == size));
}
_escape = Command("Tools", "Cancel tool, then clear selection", Escape, Keys.Escape, hasDoc);
+ _placeRoof = Command("Tools", "Place the roof being shaped", () => Session.Roof.Commit(), Keys.Enter,
+ () => Session != null && Session.ShapingRoof);
_shortcuts = Command("Help", "Keyboard shortcuts", ShowShortcuts, Keys.F1, glyph: Glyphs.Help);
_drawWithSelected = Command("Tools", "Draw with this tile", DrawWithSelected, can: () => (_menuTile ?? Session?.SelectedTile) != null);
}
@@ -673,8 +676,27 @@ private void CyclePlacement()
SyncOptions();
}
+ private void DeleteSelectionOrWing()
+ {
+ if (Session.ShapingRoof)
+ {
+ Session.Roof.DeleteWing();
+ }
+ else
+ {
+ Session.DeleteSelection();
+ }
+ }
+
private void Escape()
{
+ // With a roof being shaped: the first Esc stops a drag, the next one drops the roof.
+ if (Session.ShapingRoof && !Session.ActiveTool.IsDragging)
+ {
+ Session.Roof.Discard();
+ return;
+ }
+
// First Esc stops what the tool is doing, the next one clears the selection.
if (Session.Pasting || Session.ActiveTool.IsDragging || Session.Selection.Count == 0)
{
@@ -1318,6 +1340,8 @@ private void BuildOptionsStrip()
}
// Roof options, shown only with the Roof tool.
+ RoofGroup(strip, _shapeSeparator, _shapeLabel,
+ ("Gable", () => Session.Roof.Shape == RoofShape.Gable, () => Session.Roof.Shape = RoofShape.Gable));
RoofGroup(strip, _ridgeSeparator, _ridgeLabel,
("Auto", () => Session.Roof.Ridge == RoofRidge.Auto, () => Session.Roof.Ridge = RoofRidge.Auto),
("X", () => Session.Roof.Ridge == RoofRidge.AlongX, () => Session.Roof.Ridge = RoofRidge.AlongX),
@@ -1329,6 +1353,10 @@ private void BuildOptionsStrip()
RoofGroup(strip, _gableFillSeparator, _gableFillLabel,
("Caps", () => Session.Roof.GableFill == RoofGableFill.Caps, () => Session.Roof.GableFill = RoofGableFill.Caps),
("Walls", () => Session.Roof.GableFill == RoofGableFill.Walls, () => Session.Roof.GableFill = RoofGableFill.Walls));
+
+ // Shown while a roof is being shaped.
+ _placeRoofButton = RoofAction(strip, "Place roof", "Places the roof on the Roof layer (Enter).", () => Session.Roof.Commit());
+ _dropRoofButton = RoofAction(strip, "Drop", "Drops the roof being shaped (Esc).", () => Session.Roof.Discard());
}
private void ZStepCombo_SelectedIndexChanged(object sender, EventArgs e)
@@ -1336,6 +1364,9 @@ private void ZStepCombo_SelectedIndexChanged(object sender, EventArgs e)
Apply(() => Session.ZStep = int.Parse(_zStepCombo.Text));
}
+ private EditorCommand _placeRoof;
+ private ToolStripButton _placeRoofButton;
+ private ToolStripButton _dropRoofButton;
private readonly List _roofItems = new List();
private readonly List<(ToolStripButton Button, Func IsOn)> _roofButtons = new List<(ToolStripButton, Func)>();
@@ -1376,6 +1407,29 @@ private void RoofGroup(ToolStrip strip, ToolStripSeparator separator, ToolStripL
}
}
+ private ToolStripButton RoofAction(ToolStrip strip, string text, string tip, Action run)
+ {
+ var button = new ToolStripButton(text)
+ {
+ DisplayStyle = ToolStripItemDisplayStyle.Text,
+ ToolTipText = tip,
+ AutoToolTip = false,
+ Margin = new Padding(6, 1, 0, 2),
+ Visible = false
+ };
+ button.Click += (_, _) =>
+ {
+ if (Session != null && Session.ShapingRoof)
+ {
+ run();
+ _commands.RefreshStates();
+ _canvas.Focus();
+ }
+ };
+ strip.Items.Add(button);
+ return button;
+ }
+
private void SyncRoofOptions()
{
bool show = Session != null && !Session.Pasting && Session.Tool == ToolKind.Roof;
@@ -1384,6 +1438,8 @@ private void SyncRoofOptions()
item.Visible = show;
}
+ _placeRoofButton.Visible = _dropRoofButton.Visible = show && Session.ShapingRoof;
+
foreach ((ToolStripButton button, Func isOn) in _roofButtons)
{
button.Checked = show && isOn();
@@ -1537,6 +1593,7 @@ private EditorDocument CreateDocument(string title, int? clientId)
if (_active != null)
{
session.FloorPattern = _active.Session.FloorPattern;
+ session.Roof.Shape = _active.Session.Roof.Shape;
session.Roof.Ridge = _active.Session.Roof.Ridge;
session.Roof.Gables = _active.Session.Roof.Gables;
session.Roof.GableFill = _active.Session.Roof.GableFill;
@@ -2180,6 +2237,8 @@ private void UpdateStatus()
_statusHint.Text = session.PreviewMode ? "Preview: editing is off. Right click picks the ground. F5 returns to the editor."
: session.PreviewingRepeat ? "The copies are shown as they would be placed."
: session.Pasting ? "Click to place the tiles, as often as you like. Esc or right click stops."
+ : session.ShapingRoof ? "Shaping the roof: drag a wing to move it, an edge of the selected wing to resize it, anywhere else to add a wing. " +
+ "Shift+click turns a ridge, Delete removes a wing. Enter places the roof on the Roof layer, Esc drops it."
: ToolHint(session.Tool);
(int x, int y, int z) = session.CursorCell;
@@ -2213,7 +2272,7 @@ private static string ToolHint(ToolKind kind)
ToolKind.Floor => "Drag an area to lay the chosen floor style.",
ToolKind.Door => "Click a wall cell to hang the chosen door.",
ToolKind.Stair => "Drag in the direction the stairs climb.",
- ToolKind.Roof => "Click a walled room to roof it, or drag over the wall cells to size the roof by hand. Options: Ridge, Gables, Fill.",
+ ToolKind.Roof => "Click a walled room to start its roof, or drag out a roof of any size. It stays open for shaping until Enter places it.",
ToolKind.Foundation => "Drag an area to lay a foundation under it.",
ToolKind.FloorPattern => "Drag an area to lay the bordered floor: corners, sides and fill repeat to fit.",
_ => string.Empty
diff --git a/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs b/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs
index 9d1c172b..25f2943c 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs
@@ -64,9 +64,15 @@ public void ShowCommands(IEnumerable commands)
("Keep the line straight (Line)", "Shift + drag"),
("One straight wall instead of a room (Walls)", "Shift + drag"),
("Erase walls (Walls)", "Ctrl + drag"),
- ("Fit the roof to the walls (Roof)", "Click without dragging"),
- ("Turn the ridge the other way (Roof)", "Shift"),
- ("Gables at one end or both (Roof)", "Ctrl"));
+ ("Start a roof fitted to the walls, part by part on an L or T shaped house (Roof)", "Click without dragging"),
+ ("Start a roof fitted to the walls (Roof)", "Drag over the walls, the floor or the roof area"),
+ ("Select a wing of the roof being shaped, or move it (Roof)", "Click / drag the wing"),
+ ("Resize the selected wing (Roof)", "Drag one of its edges"),
+ ("Add a wing: valleys, and a T where the ridges meet (Roof)", "Drag beside the roof"),
+ ("Turn a wing's ridge (Roof)", "Shift + click the wing"),
+ ("Remove the selected wing (Roof)", "Delete"),
+ ("Place the roof on the Roof layer (Roof)", "Enter, or pick another tool"),
+ ("Drop the roof being shaped (Roof)", "Esc"));
Section("Tile browser",
("Go from the search box to the results", "Down"),
From 0e9ee64e05ac25f43250cdafac5046068a36f657 Mon Sep 17 00:00:00 2001
From: AsY!um- <377468+AsYlum-@users.noreply.github.com>
Date: Tue, 17 Nov 2026 23:40:19 +0100
Subject: [PATCH 02/16] Add a House tool that designs a house as a draft
---
.../Classes/HouseDraft.cs | 360 +++++++++
.../MultiEditorComponentList.Layers.cs | 43 +-
.../Editing/EditorSession.cs | 131 +++-
.../Rendering/SceneRenderer.cs | 49 +-
.../Tools/DraftEditTools.cs | 312 ++++++++
.../Tools/EditorTool.cs | 24 +
.../Tools/HousePartTools.cs | 22 +-
.../Tools/HouseTool.cs | 515 ++++++++++++
.../Tools/RoofTool.cs | 489 +++---------
.../Tools/WingDraftTool.cs | 733 ++++++++++++++++++
.../UI/HousePanel.Designer.cs | 459 +++++++++++
UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs | 233 ++++++
.../UI/MultiEditorControl.cs | 158 +++-
.../UI/ShortcutsForm.cs | 10 +-
.../UoFiddler.Plugin.MultiEditor.csproj | 6 +
15 files changed, 3108 insertions(+), 436 deletions(-)
create mode 100644 UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
create mode 100644 UoFiddler.Plugin.MultiEditor/Tools/DraftEditTools.cs
create mode 100644 UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
create mode 100644 UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
create mode 100644 UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs
create mode 100644 UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
new file mode 100644
index 00000000..59bec0c6
--- /dev/null
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
@@ -0,0 +1,360 @@
+/***************************************************************************
+ *
+ * $Author: Turley
+ *
+ * "THE BEER-WARE LICENSE"
+ * As long as you retain this notice you can do whatever you want with
+ * this stuff. If we meet some day, and you think this stuff is worth it,
+ * you can buy me a beer in return.
+ *
+ ***************************************************************************/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using UoFiddler.Plugin.MultiEditor.Tools;
+
+namespace UoFiddler.Plugin.MultiEditor.Classes
+{
+ ///
+ /// A house being designed, beside its wings: the materials of each storey and what was changed
+ /// by hand (partitions, openings, doors, windows, floor areas, stairs).
+ /// turns wings and draft into tiles. A wing's box is its wall cells, as the wall tool drags
+ /// them: walls stand on the +Y / +X edges of their cells, so the rooms inside are the box
+ /// without its first row and column.
+ ///
+ internal sealed class HouseDraft
+ {
+ public const int StoreyHeight = 20;
+ public const int MaxStoreys = 4;
+ public const string WallsLayer = "Walls";
+ public const string FloorsLayer = "Floors";
+ public const string StairsLayer = "Stairs";
+ public const string FoundationLayer = "Foundation";
+
+ // The foundation ring stands this far below the ground floor, as in the client's house foundations.
+ private const int _foundationBelow = 7;
+
+ /// Z of the ground floor.
+ public int BaseZ { get; set; }
+
+ public HouseStyle[] WallStyles { get; } = new HouseStyle[MaxStoreys];
+
+ public HouseStyle[] FloorStyles { get; } = new HouseStyle[MaxStoreys];
+
+ public HouseStyle RoofStyle { get; set; }
+
+ public bool Foundation { get; set; }
+
+ // Wall edges added and taken away by hand, per storey: cells with a wall on their +Y edge
+ // (south) and on their +X edge (east).
+ public HashSet<(int X, int Y)>[] AddedSouth { get; } = Sets();
+
+ public HashSet<(int X, int Y)>[] AddedEast { get; } = Sets();
+
+ public HashSet<(int X, int Y)>[] ErasedSouth { get; } = Sets();
+
+ public HashSet<(int X, int Y)>[] ErasedEast { get; } = Sets();
+
+ /// Doors by storey and wall cell: the door style and its piece (hinge variant).
+ public Dictionary<(int Storey, int X, int Y), (HouseStyle Style, string Piece)> Doors { get; } = new Dictionary<(int, int, int), (HouseStyle, string)>();
+
+ /// Wall cells whose piece is the style's window.
+ public HashSet<(int Storey, int X, int Y)> Windows { get; } = new HashSet<(int, int, int)>();
+
+ /// Floor areas laid in another style than the storey's; later ones lie on top.
+ public List<(int Storey, int X0, int Y0, int X1, int Y1, HouseStyle Style)> FloorAreas { get; } = new List<(int, int, int, int, int, HouseStyle)>();
+
+ /// Stairs by storey: the cell of the bottom step, the stair column (MultiNorth ...) and the style.
+ public List<(int Storey, int X, int Y, string Column, HouseStyle Style)> Stairs { get; } = new List<(int, int, int, string, HouseStyle)>();
+
+ private static HashSet<(int X, int Y)>[] Sets()
+ {
+ var sets = new HashSet<(int X, int Y)>[MaxStoreys];
+ for (int i = 0; i < MaxStoreys; ++i)
+ {
+ sets[i] = new HashSet<(int X, int Y)>();
+ }
+
+ return sets;
+ }
+
+ /// A copy that shares nothing but the styles.
+ public HouseDraft Clone()
+ {
+ HouseDraft copy = Fresh();
+ copy.BaseZ = BaseZ;
+ for (int k = 0; k < MaxStoreys; ++k)
+ {
+ copy.AddedSouth[k].UnionWith(AddedSouth[k]);
+ copy.AddedEast[k].UnionWith(AddedEast[k]);
+ copy.ErasedSouth[k].UnionWith(ErasedSouth[k]);
+ copy.ErasedEast[k].UnionWith(ErasedEast[k]);
+ }
+
+ foreach (var door in Doors)
+ {
+ copy.Doors[door.Key] = door.Value;
+ }
+
+ copy.Windows.UnionWith(Windows);
+ copy.FloorAreas.AddRange(FloorAreas);
+ copy.Stairs.AddRange(Stairs);
+ return copy;
+ }
+
+ /// A draft with the same materials and nothing changed by hand: the next house.
+ public HouseDraft Fresh()
+ {
+ var copy = new HouseDraft { RoofStyle = RoofStyle, Foundation = Foundation };
+ Array.Copy(WallStyles, copy.WallStyles, MaxStoreys);
+ Array.Copy(FloorStyles, copy.FloorStyles, MaxStoreys);
+ return copy;
+ }
+
+ /// Storeys of the tallest wing.
+ public static int Top(IReadOnlyList wings)
+ {
+ int top = 0;
+ foreach (RoofWing wing in wings)
+ {
+ top = Math.Max(top, Math.Clamp(wing.Storeys, 1, MaxStoreys));
+ }
+
+ return top;
+ }
+
+ /// The cells inside the house on a storey (0 is the ground floor): the rooms of every wing that high.
+ public static HashSet<(int X, int Y)> Region(IReadOnlyList wings, int storey)
+ {
+ var region = new HashSet<(int X, int Y)>();
+ foreach (RoofWing wing in wings)
+ {
+ if (wing.Storeys <= storey)
+ {
+ continue;
+ }
+
+ for (int x = wing.X0 + 1; x <= wing.X1; ++x)
+ {
+ for (int y = wing.Y0 + 1; y <= wing.Y1; ++y)
+ {
+ region.Add((x, y));
+ }
+ }
+ }
+
+ return region;
+ }
+
+ /// The wall edges around a region: its outline.
+ public static void Outline(HashSet<(int X, int Y)> region, HashSet<(int X, int Y)> south, HashSet<(int X, int Y)> east)
+ {
+ foreach ((int x, int y) in region)
+ {
+ if (!region.Contains((x, y + 1)))
+ {
+ south.Add((x, y));
+ }
+
+ if (!region.Contains((x, y - 1)))
+ {
+ south.Add((x, y - 1));
+ }
+
+ if (!region.Contains((x + 1, y)))
+ {
+ east.Add((x, y));
+ }
+
+ if (!region.Contains((x - 1, y)))
+ {
+ east.Add((x - 1, y));
+ }
+ }
+ }
+
+ ///
+ /// The wall edges of a storey: the outline of its rooms, with the edges added by hand that
+ /// still touch a room and without the ones taken away.
+ ///
+ public void Edges(IReadOnlyList wings, int storey, out HashSet<(int X, int Y)> south, out HashSet<(int X, int Y)> east)
+ {
+ HashSet<(int X, int Y)> region = Region(wings, storey);
+ south = new HashSet<(int X, int Y)>();
+ east = new HashSet<(int X, int Y)>();
+ Outline(region, south, east);
+ foreach ((int x, int y) in AddedSouth[storey])
+ {
+ if (region.Contains((x, y)) || region.Contains((x, y + 1)))
+ {
+ south.Add((x, y));
+ }
+ }
+
+ foreach ((int x, int y) in AddedEast[storey])
+ {
+ if (region.Contains((x, y)) || region.Contains((x + 1, y)))
+ {
+ east.Add((x, y));
+ }
+ }
+
+ south.ExceptWith(ErasedSouth[storey]);
+ east.ExceptWith(ErasedEast[storey]);
+ }
+
+ /// The tiles of a built draft, each with its layer, and the walls among them.
+ public sealed class Built
+ {
+ public List<(ushort Id, int X, int Y, int Z, string Layer)> Tiles { get; } = new List<(ushort, int, int, int, string)>();
+
+ public List<(ushort Id, int X, int Y, int Z)> Walls { get; } = new List<(ushort, int, int, int)>();
+ }
+
+ ///
+ /// Foundation, walls with their doors and windows, floors and stairs of the house, storey
+ /// by storey. The roof is not part of it: the roof tool plans it over these walls.
+ ///
+ public Built Build(IReadOnlyList wings, HouseStyles styles)
+ {
+ var built = new Built();
+ int top = Top(wings);
+ var cut = new HashSet<(int X, int Y)>[MaxStoreys + 1];
+
+ // Stairs first: a run opens the floor of the storey it climbs to.
+ foreach ((int storey, int x, int y, string column, HouseStyle style) in Stairs)
+ {
+ if (storey >= top || !Region(wings, storey).Contains((x, y)))
+ {
+ continue;
+ }
+
+ foreach ((ushort id, int tx, int ty, int tz) in StairTool.Tiles(style, column, x, y, BaseZ + (storey * StoreyHeight)))
+ {
+ built.Tiles.Add((id, tx, ty, tz, StairsLayer));
+ (cut[storey + 1] ??= new HashSet<(int X, int Y)>()).Add((tx, ty));
+ }
+ }
+
+ for (int storey = 0; storey < top; ++storey)
+ {
+ int z = BaseZ + (storey * StoreyHeight);
+ HashSet<(int X, int Y)> region = Region(wings, storey);
+ Edges(wings, storey, out HashSet<(int X, int Y)> south, out HashSet<(int X, int Y)> east);
+
+ if (storey == 0 && Foundation && styles.TryGetRole(FoundationTool.FoundationPost, out HouseStyle foundation, out _))
+ {
+ var ringSouth = new HashSet<(int X, int Y)>();
+ var ringEast = new HashSet<(int X, int Y)>();
+ Outline(region, ringSouth, ringEast);
+ foreach ((int x, int y) in WallCells(ringSouth, ringEast))
+ {
+ string column = WallPlanner.PieceFor(ringSouth, ringEast, x, y);
+ ushort id = column != null ? foundation.Get(column) : (ushort)0;
+ if (id != 0)
+ {
+ built.Tiles.Add((id, x, y, z - _foundationBelow, FoundationLayer));
+ }
+ }
+ }
+
+ HouseStyle wallStyle = WallStyles[storey];
+ foreach ((int x, int y) in WallCells(south, east))
+ {
+ if (Doors.TryGetValue((storey, x, y), out (HouseStyle Style, string Piece) door) &&
+ (WallPlanner.DoorAlongX(door.Piece) ? south : east).Contains((x, y)) && door.Style.Get(door.Piece) is var doorId and not 0)
+ {
+ built.Tiles.Add((doorId, x, y, z, WallsLayer));
+ built.Walls.Add((doorId, x, y, z));
+ continue;
+ }
+
+ string column = WallPlanner.PieceFor(south, east, x, y);
+ if (column == null || wallStyle == null)
+ {
+ continue;
+ }
+
+ if (Windows.Contains((storey, x, y)) && column != "Corner" && column != "Post")
+ {
+ string window = column.StartsWith("South", StringComparison.Ordinal) ? "WindowS" : "WindowE";
+ if (wallStyle.Get(window) != 0)
+ {
+ column = window;
+ }
+ }
+
+ ushort id = wallStyle.Get(column);
+ if (id != 0)
+ {
+ built.Tiles.Add((id, x, y, z, WallsLayer));
+ built.Walls.Add((id, x, y, z));
+ }
+ }
+
+ foreach ((int x, int y) in region)
+ {
+ if (cut[storey] != null && cut[storey].Contains((x, y)))
+ {
+ continue;
+ }
+
+ HouseStyle floorStyle = FloorStyles[storey];
+ foreach ((int areaStorey, int x0, int y0, int x1, int y1, HouseStyle areaStyle) in FloorAreas)
+ {
+ if (areaStorey == storey && x >= x0 && x <= x1 && y >= y0 && y <= y1)
+ {
+ floorStyle = areaStyle;
+ }
+ }
+
+ if (floorStyle == null)
+ {
+ continue;
+ }
+
+ ushort[] pieces = Pieces(floorStyle);
+ if (pieces.Length > 0)
+ {
+ // The same cell always gets the same piece, so the preview does not flicker.
+ built.Tiles.Add((pieces[(int)((uint)HashCode.Combine(x, y, storey) % (uint)pieces.Length)], x, y, z, FloorsLayer));
+ }
+ }
+ }
+
+ return built;
+ }
+
+ private readonly Dictionary _pieces = new Dictionary();
+
+ private ushort[] Pieces(HouseStyle style)
+ {
+ if (!_pieces.TryGetValue(style, out ushort[] pieces))
+ {
+ _pieces[style] = pieces = style.Slots.Values.Distinct().ToArray();
+ }
+
+ return pieces;
+ }
+
+ /// Every cell that may hold a wall piece: the cells with an edge, and the ones a post goes in.
+ private static HashSet<(int X, int Y)> WallCells(HashSet<(int X, int Y)> south, HashSet<(int X, int Y)> east)
+ {
+ var cells = new HashSet<(int X, int Y)>(south);
+ cells.UnionWith(east);
+ foreach ((int x, int y) in south)
+ {
+ cells.Add((x - 1, y));
+ }
+
+ foreach ((int x, int y) in east)
+ {
+ cells.Add((x, y - 1));
+ }
+
+ cells.RemoveWhere(c => c.X < 0 || c.Y < 0);
+ return cells;
+ }
+ }
+}
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/MultiEditorComponentList.Layers.cs b/UoFiddler.Plugin.MultiEditor/Classes/MultiEditorComponentList.Layers.cs
index 5014f086..d56c3890 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/MultiEditorComponentList.Layers.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/MultiEditorComponentList.Layers.cs
@@ -112,15 +112,15 @@ public TileLayer LayerAdd(string name)
}
///
- /// Removes some tiles and adds others in one undo step, the new ones on the layer each
- /// names or, when it names none, on the layer called . That
- /// layer is made on top of the others when the multi has none of that name; the active
- /// layer stays as it is. The multi grows to hold tiles added past its +X/+Y end.
+ /// Removes some tiles and adds others in one undo step, each new one on the layer it
+ /// names, or on when it names none. Layers the multi does
+ /// not have yet are made on top of the others, in the order they are first named; the
+ /// active layer stays as it is. The multi grows to hold tiles added past its +X/+Y end.
///
- public void ReplaceTilesOnLayer(IEnumerable remove, IEnumerable<(ushort Id, int X, int Y, int Z, TileLayer Layer)> add,
- string action, string layerName)
+ public void ReplaceTilesOnLayers(IEnumerable remove, IEnumerable<(ushort Id, int X, int Y, int Z, string Layer)> add,
+ string action, string defaultLayer)
{
- var added = new List<(ushort Id, int X, int Y, int Z, TileLayer Layer)>(add);
+ var added = new List<(ushort Id, int X, int Y, int Z, string Layer)>(add);
BeginEdit(action);
foreach (MultiTile tile in new List(remove))
{
@@ -142,19 +142,26 @@ public void ReplaceTilesOnLayer(IEnumerable remove, IEnumerable<(usho
RebuildGrid(width, height, new List(RealTiles));
}
- TileLayer named = _layers.FirstOrDefault(l => l.Name == layerName);
- if (named == null && added.Any(a => a.Layer == null))
+ var byName = new Dictionary();
+ foreach (var (id, x, y, z, name) in added)
{
- RecordLayers();
- TileLayer active = ActiveLayer;
- named = new TileLayer(layerName);
- _layers.Add(named);
- ActiveLayer = active;
- }
+ string wanted = name ?? defaultLayer;
+ if (!byName.TryGetValue(wanted, out TileLayer layer))
+ {
+ layer = _layers.FirstOrDefault(l => l.Name == wanted);
+ if (layer == null)
+ {
+ RecordLayers();
+ TileLayer active = ActiveLayer;
+ layer = new TileLayer(wanted);
+ _layers.Add(layer);
+ ActiveLayer = active;
+ }
- foreach (var (id, x, y, z, layer) in added)
- {
- RecordNew(id, x, y, z, false, 0, layer: layer != null && _layers.Contains(layer) ? layer : named);
+ byName[wanted] = layer;
+ }
+
+ RecordNew(id, x, y, z, false, 0, layer: layer);
}
EndEdit();
diff --git a/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.cs b/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.cs
index 932ee8ad..5ff747ce 100644
--- a/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.cs
+++ b/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.cs
@@ -41,7 +41,10 @@ internal enum ToolKind
Foundation,
/// Lays a bordered floor pattern; chosen from the House page, not the palette.
- FloorPattern
+ FloorPattern,
+
+ /// Designs a whole house as a draft and places it.
+ House
}
///
@@ -53,6 +56,7 @@ internal sealed partial class EditorSession : IEditorContext, IMultiViewSettings
{
private readonly HashSet _selection = new HashSet();
private readonly Dictionary _tools = new Dictionary();
+ private readonly Dictionary _draftTools = new Dictionary();
private readonly ArtMasks _masks;
private readonly PasteTool _pasteTool;
private readonly RepeatPreviewTool _repeatTool;
@@ -93,13 +97,24 @@ public EditorSession(ArtMasks masks, HouseStyles houseStyles)
_tools[ToolKind.Door] = new DoorTool(this);
_tools[ToolKind.Stair] = new StairTool(this);
var roof = new RoofTool(this);
- roof.Changed += () =>
+ var house = new HouseTool(this, roof);
+ foreach (WingDraftTool draft in new WingDraftTool[] { roof, house })
{
- ToolChanged?.Invoke();
- Invalidated?.Invoke();
- };
- roof.Committed += () => LayersChanged?.Invoke();
+ draft.Changed += () =>
+ {
+ DraftChanged?.Invoke();
+ ToolChanged?.Invoke();
+ Invalidated?.Invoke();
+ };
+ draft.Committed += () => LayersChanged?.Invoke();
+ }
+
_tools[ToolKind.Roof] = roof;
+ _tools[ToolKind.House] = house;
+ _draftTools[ToolKind.Wall] = new DraftWallTool(this, house);
+ _draftTools[ToolKind.Door] = new DraftDoorTool(this, house);
+ _draftTools[ToolKind.Floor] = new DraftFloorTool(this, house);
+ _draftTools[ToolKind.Stair] = new DraftStairTool(this, house);
_tools[ToolKind.Foundation] = new FoundationTool(this);
_tools[ToolKind.FloorPattern] = new FloorPatternTool(this);
_pasteTool = new PasteTool(this);
@@ -163,32 +178,87 @@ public void MarkSaved()
DocumentChanged?.Invoke();
}
+ /// True when Undo has something to take back: a step of an open draft, or of the multi.
+ public bool CanUndo => HasDocument && (UndoDraftTool != null || CompList.UndoList.Count > 0);
+
+ public bool CanRedo => HasDocument && (RedoDraftTool != null || (OpenDraft == null && CompList.RedoList.Count > 0) ||
+ (OpenDraft is { ReopenedFrom: not null } reopened && CompList.RedoList.Count > 0 &&
+ ReferenceEquals(CompList.RedoList[0], reopened.ReopenedFrom)));
+
+ // The draft whose history undo and redo walk first: the wing tool in use, else the house.
+ private WingDraftTool UndoDraftTool => WingTool is { CanUndoDraft: true } tool ? tool : House.CanUndoDraft ? House : null;
+
+ private WingDraftTool RedoDraftTool => WingTool is { CanRedoDraft: true } tool ? tool : House.CanRedoDraft ? House : null;
+
+ ///
+ /// Takes back the last step: of the draft being shaped while there is one, else of the
+ /// multi. Undoing the step that placed a roof or house brings its draft back as it was.
+ ///
public bool Undo()
{
+ if (UndoDraftTool is { } draft)
+ {
+ return draft.UndoDraft();
+ }
+
+ EditCommand step = CompList.UndoList.Count > 0 ? CompList.UndoList[0] : null;
if (!CompList.UndoStep())
{
return false;
}
+ foreach (WingDraftTool tool in new WingDraftTool[] { House, Roof })
+ {
+ // A roof draft shows only with the roof tool, so it comes back only there; a
+ // house draft shows under every tool.
+ if (tool.PlacedBy != null && ReferenceEquals(tool.PlacedBy, step) && !tool.HasPending &&
+ (tool is HouseTool || _toolKind == ToolKind.Roof))
+ {
+ tool.Reopen();
+ }
+ }
+
AfterEdit();
+ LayersChanged?.Invoke();
return true;
}
+ ///
+ /// Redoes a step of the draft being shaped, else of the multi. While a draft is open the
+ /// multi's steps wait, except the one that placed that very draft.
+ ///
public bool Redo()
{
+ if (RedoDraftTool is { } draft)
+ {
+ return draft.RedoDraft();
+ }
+
+ if (OpenDraft is { } open)
+ {
+ if (open.ReopenedFrom == null || CompList.RedoList.Count == 0 || !ReferenceEquals(CompList.RedoList[0], open.ReopenedFrom))
+ {
+ return false;
+ }
+
+ open.CloseReopened();
+ }
+
if (!CompList.RedoStep())
{
return false;
}
AfterEdit();
+ LayersChanged?.Invoke();
return true;
}
private void SetDocument(MultiEditorComponentList list)
{
CancelTool();
- Roof.Discard();
+ Roof.Reset();
+ House.Reset();
CompList = list;
_selection.Clear();
HoverTile = null;
@@ -352,6 +422,7 @@ public ToolKind Tool
set
{
// A roof still being shaped is placed when another tool is taken up.
+ // A house draft stays open instead: the wall, door, floor and stair tools work on it.
if (_toolKind == ToolKind.Roof && value != ToolKind.Roof)
{
Roof.Commit();
@@ -369,7 +440,12 @@ public ToolKind Tool
}
}
- public EditorTool ActiveTool => _temporaryTool ?? _tools[_toolKind];
+ ///
+ /// The tool in use. While a house draft is open the wall, door, floor and stair tools are
+ /// the ones that change the draft.
+ ///
+ public EditorTool ActiveTool => _temporaryTool ??
+ (House.HasPending && _draftTools.TryGetValue(_toolKind, out EditorTool draftTool) ? draftTool : _tools[_toolKind]);
/// True for the tools that place the draw tile (draw, rectangle, line).
public static bool IsTileTool(ToolKind kind)
@@ -391,8 +467,43 @@ public static bool IsTileTool(ToolKind kind)
/// The roof tool, for its shape options (ridge, gables, gable fill) and the roof being shaped.
public RoofTool Roof => (RoofTool)_tools[ToolKind.Roof];
- /// True while the roof tool is in use and holds a roof that is not placed yet.
- public bool ShapingRoof => _temporaryTool == null && _toolKind == ToolKind.Roof && Roof.HasPending;
+ /// The house tool, for its draft and options.
+ public HouseTool House => (HouseTool)_tools[ToolKind.House];
+
+ /// Raised when a roof or house draft starts, changes or ends.
+ public event Action DraftChanged;
+
+ /// The roof or house tool when it is the tool in use, else null.
+ public WingDraftTool WingTool => _temporaryTool == null ? _tools[_toolKind] as WingDraftTool : null;
+
+ ///
+ /// The draft that Enter places, Esc drops and undo steps through: the one of the wing
+ /// tool in use, else an open house draft (which stays open under the other tools).
+ ///
+ public WingDraftTool OpenDraft => WingTool is { HasPending: true } tool ? tool : House.HasPending ? House : null;
+
+ ///
+ /// The open draft when the tool in use works on it (a wing tool, or a tool that edits the
+ /// house draft): the one Enter places and Esc drops.
+ ///
+ public WingDraftTool DraftInFocus => _temporaryTool != null ? null
+ : WingTool is { HasPending: true } tool ? tool
+ : House.HasPending && ActiveTool is DraftEditTool ? House : null;
+
+ /// True while a wing tool is in use and holds a draft that is not placed yet.
+ public bool ShapingRoof => WingTool is { HasPending: true };
+
+ /// The storey of an open house draft that the chosen floor means.
+ public int DraftStorey => House.StoreyFor(WorkZ);
+
+ /// Draws an open house draft while a tool that does not work on it is in use.
+ public void PaintIdleDraft(IToolOverlay overlay)
+ {
+ if (House.HasPending && _temporaryTool == null && ActiveTool is not (HouseTool or DraftEditTool))
+ {
+ House.PaintDraft(overlay, active: false);
+ }
+ }
/// Call after a tool option changed, so the preview under the cursor follows.
public void ToolOptionsChanged()
diff --git a/UoFiddler.Plugin.MultiEditor/Rendering/SceneRenderer.cs b/UoFiddler.Plugin.MultiEditor/Rendering/SceneRenderer.cs
index 0b725215..aa0b3313 100644
--- a/UoFiddler.Plugin.MultiEditor/Rendering/SceneRenderer.cs
+++ b/UoFiddler.Plugin.MultiEditor/Rendering/SceneRenderer.cs
@@ -126,6 +126,7 @@ public void Draw(EditorSession session, Camera2D camera, Size viewport)
if (!session.PickingWithAlt)
{
session.ActiveTool.PaintOverlay(this);
+ session.PaintIdleDraft(this);
}
LastSpriteCount += _sprites.Count;
_sprites.Flush(_atlas, camera, viewport);
@@ -566,7 +567,8 @@ void IToolOverlay.Ghost(ushort id, int x, int y, int z)
return;
}
- if (!_session.CompList.InBounds(x, y) || !_atlas.TryGet(id, out AtlasSprite sprite))
+ // A ghost may lie past the multi's end: tools that grow the multi show what they add.
+ if (x < 0 || y < 0 || !_atlas.TryGet(id, out AtlasSprite sprite))
{
return;
}
@@ -604,6 +606,51 @@ void IToolOverlay.Polyline(System.Collections.Generic.IReadOnlyList point
}
}
+ private static Color ToneColor(OverlayTone tone) => tone switch
+ {
+ OverlayTone.Selected => Color.FromArgb(255, 255, 214, 64),
+ OverlayTone.Hover => Color.FromArgb(255, 255, 255, 255),
+ OverlayTone.Remove => Color.FromArgb(255, 255, 80, 80),
+ _ => Color.FromArgb(200, 120, 190, 255)
+ };
+
+ void IToolOverlay.Outline(System.Collections.Generic.IReadOnlyList points, OverlayTone tone)
+ {
+ // Lines are a pixel wide: a strong outline is the same line drawn side by side.
+ Color color = ToneColor(tone);
+ int width = tone == OverlayTone.Selected ? 3 : tone == OverlayTone.Plain ? 1 : 2;
+ for (int pass = 0; pass < width; ++pass)
+ {
+ int shift = pass == 0 ? 0 : pass == 1 ? 1 : -1;
+ for (int i = 0; i < points.Count; i++)
+ {
+ Point a = points[i], b = points[(i + 1) % points.Count];
+ _lines.Add(a.X, a.Y + shift, b.X, b.Y + shift, color);
+ if (shift != 0)
+ {
+ _lines.Add(a.X + shift, a.Y, b.X + shift, b.Y, color);
+ }
+ }
+ }
+ }
+
+ void IToolOverlay.CellMark(int x, int y, int z, OverlayTone tone)
+ {
+ Color color = Color.FromArgb(tone == OverlayTone.Plain ? 40 : tone == OverlayTone.Selected ? 70 : 110, ToneColor(tone));
+ if (_session.PlanMode)
+ {
+ Point o = PlanView.CellOrigin(x, y);
+ Fill(o.X, o.Y, PlanView.Cell, PlanView.Cell, color);
+ return;
+ }
+
+ if (_atlas.TryGet(ArtAtlas.FloorKey, out AtlasSprite diamond))
+ {
+ PointF corner = EditorSession.CellCorner(x, y, z);
+ _sprites.Add(diamond, corner.X - 22, corner.Y, SpriteTint.Solid(color));
+ }
+ }
+
void IToolOverlay.Marquee(Rectangle rect)
{
if (_atlas.TryGet(ArtAtlas.WhiteKey, out AtlasSprite white))
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/DraftEditTools.cs b/UoFiddler.Plugin.MultiEditor/Tools/DraftEditTools.cs
new file mode 100644
index 00000000..6d52efb9
--- /dev/null
+++ b/UoFiddler.Plugin.MultiEditor/Tools/DraftEditTools.cs
@@ -0,0 +1,312 @@
+/***************************************************************************
+ *
+ * $Author: Turley
+ *
+ * "THE BEER-WARE LICENSE"
+ * As long as you retain this notice you can do whatever you want with
+ * this stuff. If we meet some day, and you think this stuff is worth it,
+ * you can buy me a beer in return.
+ *
+ ***************************************************************************/
+
+using System;
+using System.Collections.Generic;
+using System.Windows.Forms;
+using UoFiddler.Plugin.MultiEditor.Classes;
+
+namespace UoFiddler.Plugin.MultiEditor.Tools
+{
+ ///
+ /// Base for the tools that stand in for the wall, door, floor and stair tools while a house
+ /// draft is open: they change the draft, on the storey of the chosen floor, instead of the
+ /// multi. The draft is drawn under what the tool itself shows.
+ ///
+ internal abstract class DraftEditTool : EditorTool
+ {
+ protected DraftEditTool(IEditorContext context, HouseTool house) : base(context)
+ {
+ House = house;
+ }
+
+ protected HouseTool House { get; }
+
+ public override bool TracksCursorCell => true;
+
+ /// The storey worked on: the chosen floor's.
+ protected int Storey => House.StoreyFor(Context.WorkZ);
+
+ protected int StoreyZ => House.BaseZ + (Storey * HouseDraft.StoreyHeight);
+
+ /// The cell under the mouse on the storey's floor.
+ protected void MouseCell(out int x, out int y)
+ {
+ Context.PlaneCell(Context.MouseLoc, StoreyZ, out x, out y);
+ }
+
+ public override void PaintOverlay(IToolOverlay overlay)
+ {
+ House.PaintDraft(overlay, active: false);
+ PaintEdit(overlay);
+ }
+
+ protected abstract void PaintEdit(IToolOverlay overlay);
+ }
+
+ ///
+ /// Walls of a house draft. A drag adds walls along the cells (a rectangle of them, or one
+ /// straight wall with Shift or along a single row or column); Ctrl takes walls away, also
+ /// outer ones, which leaves an opening. A click on a straight wall turns it into a window
+ /// and back.
+ ///
+ internal sealed class DraftWallTool : DraftEditTool
+ {
+ private bool _dragging;
+ private int _startX;
+ private int _startY;
+ private int _endX;
+ private int _endY;
+
+ public DraftWallTool(IEditorContext context, HouseTool house) : base(context, house)
+ {
+ }
+
+ public override bool IsDragging => _dragging;
+
+ public override void OnMouseDown(MouseEventArgs e)
+ {
+ MouseCell(out _startX, out _startY);
+ (_endX, _endY) = (_startX, _startY);
+ _dragging = true;
+ }
+
+ public override void OnMouseMove(MouseEventArgs e)
+ {
+ if (_dragging)
+ {
+ MouseCell(out _endX, out _endY);
+ }
+ }
+
+ public override void OnMouseUp(MouseEventArgs e)
+ {
+ if (!_dragging)
+ {
+ return;
+ }
+
+ _dragging = false;
+ MouseCell(out _endX, out _endY);
+ if (_startX == _endX && _startY == _endY && !CtrlHeld && House.ToggleWindow(Storey, _startX, _startY))
+ {
+ return;
+ }
+
+ var (south, east) = WallPlanner.DragEdges(_startX, _startY, _endX, _endY, ShiftHeld);
+ House.EditEdges(Storey, south, east, CtrlHeld);
+ }
+
+ public override void Cancel()
+ {
+ _dragging = false;
+ }
+
+ protected override void PaintEdit(IToolOverlay overlay)
+ {
+ if (!_dragging)
+ {
+ MouseCell(out int x, out int y);
+ overlay.CellMark(x, y, StoreyZ, OverlayTone.Hover);
+ return;
+ }
+
+ OverlayTone tone = CtrlHeld ? OverlayTone.Remove : OverlayTone.Hover;
+ var (south, east) = WallPlanner.DragEdges(_startX, _startY, _endX, _endY, ShiftHeld);
+ var cells = new HashSet<(int X, int Y)>(south);
+ cells.UnionWith(east);
+ foreach ((int x, int y) in cells)
+ {
+ overlay.CellMark(x, y, StoreyZ, tone);
+ }
+ }
+ }
+
+ ///
+ /// Doors of a house draft: a click on a straight wall hangs the chosen door there, a click on
+ /// that door turns it to its next hinge variant, Ctrl+click takes the door out.
+ ///
+ internal sealed class DraftDoorTool : DraftEditTool
+ {
+ public DraftDoorTool(IEditorContext context, HouseTool house) : base(context, house)
+ {
+ }
+
+ public override void OnMouseUp(MouseEventArgs e)
+ {
+ MouseCell(out int x, out int y);
+ House.CycleDoor(Storey, x, y, Context.HouseStyle, CtrlHeld);
+ }
+
+ protected override void PaintEdit(IToolOverlay overlay)
+ {
+ MouseCell(out int x, out int y);
+ House.EdgesOf(Storey, out HashSet<(int X, int Y)> south, out HashSet<(int X, int Y)> east);
+ bool fits = south.Contains((x, y)) != east.Contains((x, y));
+ overlay.CellMark(x, y, StoreyZ, CtrlHeld || !fits ? OverlayTone.Remove : OverlayTone.Hover);
+ }
+ }
+
+ ///
+ /// Floors of a house draft: a drag lays that area of the storey in the chosen floor style;
+ /// the rest keeps the storey's own.
+ ///
+ internal sealed class DraftFloorTool : DraftEditTool
+ {
+ private bool _dragging;
+ private int _startX;
+ private int _startY;
+ private int _endX;
+ private int _endY;
+
+ public DraftFloorTool(IEditorContext context, HouseTool house) : base(context, house)
+ {
+ }
+
+ public override bool IsDragging => _dragging;
+
+ public override void OnMouseDown(MouseEventArgs e)
+ {
+ MouseCell(out _startX, out _startY);
+ (_endX, _endY) = (_startX, _startY);
+ _dragging = true;
+ }
+
+ public override void OnMouseMove(MouseEventArgs e)
+ {
+ if (_dragging)
+ {
+ MouseCell(out _endX, out _endY);
+ }
+ }
+
+ public override void OnMouseUp(MouseEventArgs e)
+ {
+ if (!_dragging)
+ {
+ return;
+ }
+
+ _dragging = false;
+ MouseCell(out _endX, out _endY);
+ House.AddFloorArea(Storey, _startX, _startY, _endX, _endY, Context.HouseStyle);
+ }
+
+ public override void Cancel()
+ {
+ _dragging = false;
+ }
+
+ protected override void PaintEdit(IToolOverlay overlay)
+ {
+ int x0, y0, x1, y1;
+ if (_dragging)
+ {
+ (x0, y0, x1, y1) = (Math.Min(_startX, _endX), Math.Min(_startY, _endY), Math.Max(_startX, _endX), Math.Max(_startY, _endY));
+ }
+ else
+ {
+ MouseCell(out x0, out y0);
+ (x1, y1) = (x0, y0);
+ }
+
+ for (int x = x0; x <= x1; ++x)
+ {
+ for (int y = y0; y <= y1; ++y)
+ {
+ overlay.CellMark(x, y, StoreyZ, OverlayTone.Hover);
+ }
+ }
+ }
+ }
+
+ ///
+ /// Stairs of a house draft: press on the cell of the bottom step and drag the way the stairs
+ /// should climb (a click climbs north). They open the floor of the storey above.
+ /// Ctrl+click on a bottom step takes the stairs out.
+ ///
+ internal sealed class DraftStairTool : DraftEditTool
+ {
+ private bool _dragging;
+ private int _startX;
+ private int _startY;
+ private int _endX;
+ private int _endY;
+
+ public DraftStairTool(IEditorContext context, HouseTool house) : base(context, house)
+ {
+ }
+
+ public override bool IsDragging => _dragging;
+
+ public override void OnMouseDown(MouseEventArgs e)
+ {
+ MouseCell(out _startX, out _startY);
+ (_endX, _endY) = (_startX, _startY);
+ _dragging = true;
+ }
+
+ public override void OnMouseMove(MouseEventArgs e)
+ {
+ if (_dragging)
+ {
+ MouseCell(out _endX, out _endY);
+ }
+ }
+
+ public override void OnMouseUp(MouseEventArgs e)
+ {
+ if (!_dragging)
+ {
+ return;
+ }
+
+ _dragging = false;
+ MouseCell(out _endX, out _endY);
+ if (CtrlHeld)
+ {
+ House.RemoveStairs(Storey, _startX, _startY);
+ }
+ else
+ {
+ House.AddStairs(Storey, _startX, _startY, StairTool.Column(_endX - _startX, _endY - _startY), Context.HouseStyle);
+ }
+ }
+
+ public override void Cancel()
+ {
+ _dragging = false;
+ }
+
+ protected override void PaintEdit(IToolOverlay overlay)
+ {
+ int x, y;
+ if (_dragging)
+ {
+ (x, y) = (_startX, _startY);
+ }
+ else
+ {
+ MouseCell(out x, out y);
+ }
+
+ overlay.CellMark(x, y, StoreyZ, CtrlHeld ? OverlayTone.Remove : OverlayTone.Hover);
+ if (!CtrlHeld && Context.HouseStyle is { Kind: HousePartKind.Stair } style)
+ {
+ string column = _dragging ? StairTool.Column(_endX - _startX, _endY - _startY) : "MultiNorth";
+ foreach ((ushort id, int tx, int ty, int tz) in StairTool.Tiles(style, column, x, y, StoreyZ))
+ {
+ overlay.Ghost(id, tx, ty, tz);
+ }
+ }
+ }
+ }
+}
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/EditorTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/EditorTool.cs
index 356e1f13..df2e9913 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/EditorTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/EditorTool.cs
@@ -104,6 +104,24 @@ internal enum TileHighlight
Remove
}
+ ///
+ /// How strongly a tool marks something it draws.
+ ///
+ internal enum OverlayTone
+ {
+ /// There, but not what is being worked on.
+ Plain,
+
+ /// Under the mouse: what a press would take hold of.
+ Hover,
+
+ /// The thing being worked on.
+ Selected,
+
+ /// Something a release would take away.
+ Remove
+ }
+
///
/// What a tool draws over the multi. The canvas decides how it looks.
///
@@ -120,6 +138,12 @@ internal interface IToolOverlay
/// A line through canvas points, joined back to the start when closed.
void Polyline(IReadOnlyList points, bool closed);
+
+ /// A closed outline through canvas points, drawn as strongly as its tone asks.
+ void Outline(IReadOnlyList points, OverlayTone tone);
+
+ /// A cell tinted on the plane at height z.
+ void CellMark(int x, int y, int z, OverlayTone tone);
}
///
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/HousePartTools.cs b/UoFiddler.Plugin.MultiEditor/Tools/HousePartTools.cs
index 7edca4cd..52a1cf35 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/HousePartTools.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/HousePartTools.cs
@@ -216,18 +216,26 @@ public StairTool(IEditorContext context) : base(context)
protected override (List Remove, List<(ushort Id, int X, int Y, int Z)> Add) Plan(
int startX, int startY, int endX, int endY, int z, bool final)
{
- var add = new List<(ushort, int, int, int)>();
- int dx = endX - startX;
- int dy = endY - startY;
- string column = Math.Abs(dx) > Math.Abs(dy)
+ return (new List(), Tiles(Style, Column(endX - startX, endY - startY), startX, startY, z));
+ }
+
+ /// The stair column for the way a drag points: the stairs climb that way, north for a click.
+ public static string Column(int dx, int dy)
+ {
+ return Math.Abs(dx) > Math.Abs(dy)
? (dx > 0 ? "MultiEast" : "MultiWest")
: (dy > 0 ? "MultiSouth" : "MultiNorth");
+ }
- ushort multiId = Style.Get(column);
+ /// The tiles of a style's stairs with their lowest step in a cell, climbing one level from .
+ public static List<(ushort Id, int X, int Y, int Z)> Tiles(HouseStyle style, string column, int startX, int startY, int z)
+ {
+ var add = new List<(ushort, int, int, int)>();
+ ushort multiId = style.Get(column);
MultiComponentList stairs = multiId != 0 ? Multis.GetComponents(multiId) : MultiComponentList.Empty;
if (stairs == MultiComponentList.Empty || stairs.Width == 0)
{
- return (new List(), add);
+ return add;
}
// The lowest step goes under the cursor.
@@ -260,7 +268,7 @@ protected override (List Remove, List<(ushort Id, int X, int Y, int Z
}
}
- return (new List(), add);
+ return add;
}
}
}
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
new file mode 100644
index 00000000..bab2fdd7
--- /dev/null
+++ b/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
@@ -0,0 +1,515 @@
+/***************************************************************************
+ *
+ * $Author: Turley
+ *
+ * "THE BEER-WARE LICENSE"
+ * As long as you retain this notice you can do whatever you want with
+ * this stuff. If we meet some day, and you think this stuff is worth it,
+ * you can buy me a beer in return.
+ *
+ ***************************************************************************/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using UoFiddler.Plugin.MultiEditor.Classes;
+
+namespace UoFiddler.Plugin.MultiEditor.Tools
+{
+ ///
+ /// A whole house, designed before it is placed. Drag a rectangle of wall cells to add a wing;
+ /// wings are selected, moved, resized and removed as describes.
+ /// Each wing has a number of storeys and a roof; each storey of the house has a wall style
+ /// and a floor style. The house is shown as it will be built and nothing is written to the
+ /// multi until it is placed, on the layers Foundation, Walls, Floors, Stairs and Roof.
+ /// While the draft is open the wall, door, floor and stair tools change the draft
+ /// (), and every change is a step of the draft's undo history.
+ ///
+ internal sealed class HouseTool : WingDraftTool
+ {
+ private readonly RoofTool _roof;
+ private HouseDraft _draft = new HouseDraft();
+ private int _storeys = 1;
+ private RoofShape _shape = RoofShape.Gable;
+ private bool _noRoof;
+ private RoofRidge _ridge = RoofRidge.Auto;
+
+ // The last build, kept while nothing it depends on changes: a house is thousands of tiles.
+ private string _builtFor;
+ private (List Remove, List<(ushort Id, int X, int Y, int Z, string Layer)> Add) _built;
+ private int _version;
+
+ public HouseTool(IEditorContext context, RoofTool roof) : base(context)
+ {
+ _roof = roof;
+ }
+
+ /// The materials and hand-made changes of the house. Change it through this tool, so the history follows.
+ public HouseDraft Draft => _draft;
+
+ /// Z of the ground floor: the first wing's, which the others share.
+ public int BaseZ => Wings.Count > 0 ? Wings[0].EaveZ : _draft.BaseZ;
+
+ /// Storeys of the tallest wing; 1 before there is one.
+ public int TopStorey => Math.Max(1, HouseDraft.Top(Wings));
+
+ /// Storeys of new wings.
+ public int Storeys => SelectedWing?.Storeys ?? _storeys;
+
+ public RoofShape Shape => SelectedWing?.Shape ?? _shape;
+
+ public bool NoRoof => SelectedWing?.NoRoof ?? _noRoof;
+
+ public RoofRidge Ridge => SelectedWing is { } wing
+ ? wing.RidgeAuto ? RoofRidge.Auto : wing.RidgeAlongY ? RoofRidge.AlongY : RoofRidge.AlongX
+ : _ridge;
+
+ protected override bool Ready
+ {
+ get
+ {
+ EnsureMaterials();
+ return _draft.WallStyles[0] != null;
+ }
+ }
+
+ protected override string ActionName => "House";
+
+ protected override string DefaultLayer => HouseDraft.WallsLayer;
+
+ protected override bool PreviewsFirstClick => false;
+
+ protected override bool GhostsFollowView => true;
+
+ ///
+ /// Storeys without a material take the one below; the ground floor and the roof take the
+ /// first style the client has, until one is chosen.
+ ///
+ private void EnsureMaterials()
+ {
+ if (Context.HouseStyles == null)
+ {
+ return;
+ }
+
+ HouseStyle First(HousePartKind kind) => Context.HouseStyles.Styles.FirstOrDefault(s => s.Kind == kind && s.IconId != 0);
+ _draft.WallStyles[0] ??= Context.HouseStyles.Styles.FirstOrDefault(s =>
+ s.Kind == HousePartKind.Wall && s.Get("South2") is var id and not 0 && Ultima.TileData.ItemTable[id].Height >= 15) ?? First(HousePartKind.Wall);
+ _draft.FloorStyles[0] ??= First(HousePartKind.Floor);
+ _draft.RoofStyle ??= First(HousePartKind.Roof);
+ for (int k = 1; k < HouseDraft.MaxStoreys; ++k)
+ {
+ _draft.WallStyles[k] ??= _draft.WallStyles[k - 1];
+ _draft.FloorStyles[k] ??= _draft.FloorStyles[k - 1];
+ }
+ }
+
+ // ---------------------------------------------------------------- wings
+
+ protected override void StartCell(out int x, out int y, out int z)
+ {
+ Context.CellAt(Context.MouseLoc, out x, out y, out z);
+ if (Context.WorkZ is { } baseZ)
+ {
+ z = baseZ;
+ }
+
+ Context.PlaneCell(Context.MouseLoc, z, out x, out y);
+ }
+
+ protected override int NextWingZ => BaseZ;
+
+ /// A wing is the dragged rectangle of wall cells; it needs room for a room.
+ protected override List WingsFor(int startX, int startY, int endX, int endY, int z, out bool fitted)
+ {
+ fitted = false;
+ var wings = new List();
+ int x0 = Math.Max(0, Math.Min(startX, endX)), x1 = Math.Max(startX, endX);
+ int y0 = Math.Max(0, Math.Min(startY, endY)), y1 = Math.Max(startY, endY);
+ if (x1 - x0 < 2 || y1 - y0 < 2)
+ {
+ return wings;
+ }
+
+ var wing = new RoofWing
+ {
+ X0 = x0, Y0 = y0, X1 = x1, Y1 = y1, EaveZ = z, Storeys = _storeys,
+ Shape = _shape, NoRoof = _noRoof, RidgeAuto = _ridge == RoofRidge.Auto
+ };
+ wing.RidgeAlongY = wing.RidgeAuto ? RoofPlanner.RidgeAlongY(RoofBox(wing)) : _ridge == RoofRidge.AlongY;
+ wings.Add(wing);
+ return wings;
+ }
+
+ private static (int X0, int Y0, int X1, int Y1) RoofBox(RoofWing wing) => (wing.X0 + 1, wing.Y0 + 1, wing.X1 + 1, wing.Y1 + 1);
+
+ protected override void WingResized(RoofWing wing)
+ {
+ if (wing.RidgeAuto)
+ {
+ wing.RidgeAlongY = RoofPlanner.RidgeAlongY(RoofBox(wing));
+ }
+ }
+
+ protected override void Turn(RoofWing wing)
+ {
+ wing.RidgeAlongY = !wing.RidgeAlongY;
+ wing.RidgeAuto = false;
+ }
+
+ protected override object CaptureExtra() => _draft.Clone();
+
+ protected override void RestoreExtra(object extra)
+ {
+ _draft = extra is HouseDraft saved ? saved.Clone() : _draft.Fresh();
+ ++_version;
+ }
+
+ // ---------------------------------------------------------------- changes to the draft
+
+ /// Runs a change to the draft as one step of its history.
+ private void Edit(Action change)
+ {
+ Remember();
+ change();
+ ++_version;
+ RaiseChanged();
+ }
+
+ /// Sets the storeys of the selected wing, and of the wings drawn next.
+ public void SetStoreys(int storeys)
+ {
+ storeys = Math.Clamp(storeys, 1, HouseDraft.MaxStoreys);
+ _storeys = storeys;
+ if (SelectedWing is { } wing && wing.Storeys != storeys)
+ {
+ Edit(() => wing.Storeys = storeys);
+ }
+ else
+ {
+ RaiseChanged();
+ }
+ }
+
+ /// Sets the roof of the selected wing, and of the wings drawn next: a shape, or none.
+ public void SetRoof(RoofShape shape, bool none)
+ {
+ (_shape, _noRoof) = (shape, none);
+ if (SelectedWing is { } wing && (wing.Shape != shape || wing.NoRoof != none))
+ {
+ Edit(() => (wing.Shape, wing.NoRoof) = (shape, none));
+ }
+ else
+ {
+ RaiseChanged();
+ }
+ }
+
+ public void SetRidge(RoofRidge ridge)
+ {
+ _ridge = ridge;
+ if (SelectedWing is { } wing)
+ {
+ Edit(() =>
+ {
+ wing.RidgeAuto = ridge == RoofRidge.Auto;
+ wing.RidgeAlongY = wing.RidgeAuto ? RoofPlanner.RidgeAlongY(RoofBox(wing)) : ridge == RoofRidge.AlongY;
+ });
+ }
+ else
+ {
+ RaiseChanged();
+ }
+ }
+
+ /// Moves the whole house up or down.
+ public void SetBaseZ(int z)
+ {
+ z = Math.Clamp(z, -100, 100);
+ if (Wings.Count == 0 || z == BaseZ)
+ {
+ return;
+ }
+
+ Edit(() =>
+ {
+ foreach (RoofWing wing in Wings)
+ {
+ wing.EaveZ = z;
+ }
+ });
+ }
+
+ public void SetFoundation(bool on)
+ {
+ if (_draft.Foundation != on)
+ {
+ Edit(() => _draft.Foundation = on);
+ }
+ }
+
+ ///
+ /// Sets a wall, floor or roof style. A wall or floor style goes to one storey, or to
+ /// every storey when is null.
+ ///
+ public void SetMaterial(HouseStyle style, int? storey)
+ {
+ if (style == null)
+ {
+ return;
+ }
+
+ Edit(() =>
+ {
+ if (style.Kind == HousePartKind.Roof)
+ {
+ _draft.RoofStyle = style;
+ return;
+ }
+
+ HouseStyle[] target = style.Kind == HousePartKind.Floor ? _draft.FloorStyles : style.Kind == HousePartKind.Wall ? _draft.WallStyles : null;
+ for (int k = 0; target != null && k < HouseDraft.MaxStoreys; ++k)
+ {
+ if (storey == null || storey == k)
+ {
+ target[k] = style;
+ }
+ }
+ });
+ }
+
+ /// The storey the work plane is on (the chosen floor); the ground floor with all floors shown.
+ public int StoreyFor(int? workZ)
+ {
+ if (workZ is not { } z)
+ {
+ return 0;
+ }
+
+ return Math.Clamp((int)Math.Round((z - BaseZ) / (double)HouseDraft.StoreyHeight), 0, TopStorey - 1);
+ }
+
+ /// The wall edges of a storey as the draft has them now.
+ public void EdgesOf(int storey, out HashSet<(int X, int Y)> south, out HashSet<(int X, int Y)> east)
+ {
+ _draft.Edges(Wings, storey, out south, out east);
+ }
+
+ /// Adds wall edges to a storey (partitions), or takes edges away (openings).
+ public void EditEdges(int storey, IReadOnlyCollection<(int X, int Y)> south, IReadOnlyCollection<(int X, int Y)> east, bool erase)
+ {
+ if (south.Count + east.Count == 0)
+ {
+ return;
+ }
+
+ Edit(() =>
+ {
+ if (erase)
+ {
+ _draft.AddedSouth[storey].ExceptWith(south);
+ _draft.AddedEast[storey].ExceptWith(east);
+ _draft.ErasedSouth[storey].UnionWith(south);
+ _draft.ErasedEast[storey].UnionWith(east);
+ }
+ else
+ {
+ _draft.ErasedSouth[storey].ExceptWith(south);
+ _draft.ErasedEast[storey].ExceptWith(east);
+ _draft.AddedSouth[storey].UnionWith(south);
+ _draft.AddedEast[storey].UnionWith(east);
+ }
+ });
+ }
+
+ /// Turns the wall in a cell into a window, or back. False when the cell has no straight wall.
+ public bool ToggleWindow(int storey, int x, int y)
+ {
+ EdgesOf(storey, out HashSet<(int X, int Y)> south, out HashSet<(int X, int Y)> east);
+ if (south.Contains((x, y)) == east.Contains((x, y)))
+ {
+ return false;
+ }
+
+ Edit(() =>
+ {
+ if (!_draft.Windows.Remove((storey, x, y)))
+ {
+ _draft.Windows.Add((storey, x, y));
+ _draft.Doors.Remove((storey, x, y));
+ }
+ });
+ return true;
+ }
+
+ // Hinge variants per wall direction, in the order a click cycles through them.
+ private static readonly string[] _doorsAlongX = { "Piece3", "Piece1", "Piece4", "Piece2" };
+ private static readonly string[] _doorsAlongY = { "Piece5", "Piece7", "Piece6", "Piece8" };
+
+ ///
+ /// Hangs a door in the wall of a cell, or turns the door there to its next hinge variant;
+ /// with takes it out. False when the cell has no straight wall.
+ ///
+ public bool CycleDoor(int storey, int x, int y, HouseStyle style, bool remove)
+ {
+ EdgesOf(storey, out HashSet<(int X, int Y)> south, out HashSet<(int X, int Y)> east);
+ bool alongX = south.Contains((x, y));
+ if (alongX == east.Contains((x, y)))
+ {
+ return false;
+ }
+
+ bool has = _draft.Doors.TryGetValue((storey, x, y), out (HouseStyle Style, string Piece) door);
+ if (remove)
+ {
+ if (has)
+ {
+ Edit(() => _draft.Doors.Remove((storey, x, y)));
+ }
+
+ return has;
+ }
+
+ if (style == null || style.Kind != HousePartKind.Door)
+ {
+ return false;
+ }
+
+ string[] variants = alongX ? _doorsAlongX : _doorsAlongY;
+ int next = has && door.Style == style ? (Array.IndexOf(variants, door.Piece) + 1) % variants.Length : 0;
+ for (int i = 0; i < variants.Length; ++i)
+ {
+ string piece = variants[(next + i) % variants.Length];
+ if (style.Get(piece) != 0)
+ {
+ Edit(() =>
+ {
+ _draft.Doors[(storey, x, y)] = (style, piece);
+ _draft.Windows.Remove((storey, x, y));
+ });
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /// Lays an area of a storey's floor in another style.
+ public void AddFloorArea(int storey, int x0, int y0, int x1, int y1, HouseStyle style)
+ {
+ if (style is { Kind: HousePartKind.Floor })
+ {
+ Edit(() => _draft.FloorAreas.Add((storey, Math.Min(x0, x1), Math.Min(y0, y1), Math.Max(x0, x1), Math.Max(y0, y1), style)));
+ }
+ }
+
+ /// Puts stairs on a storey, their bottom step in a cell; they open the floor above.
+ public void AddStairs(int storey, int x, int y, string column, HouseStyle style)
+ {
+ if (style is { Kind: HousePartKind.Stair } && style.Get(column) != 0)
+ {
+ Edit(() => _draft.Stairs.Add((storey, x, y, column, style)));
+ }
+ }
+
+ /// Takes out the stairs whose bottom step is in a cell.
+ public bool RemoveStairs(int storey, int x, int y)
+ {
+ int index = _draft.Stairs.FindLastIndex(s => s.Storey == storey && s.X == x && s.Y == y);
+ if (index < 0)
+ {
+ return false;
+ }
+
+ Edit(() => _draft.Stairs.RemoveAt(index));
+ return true;
+ }
+
+ // ---------------------------------------------------------------- building
+
+ protected override (List Remove, List<(ushort Id, int X, int Y, int Z, string Layer)> Add) Plan(IReadOnlyList wings)
+ {
+ if (wings.Count == 0)
+ {
+ return (new List(), new List<(ushort, int, int, int, string)>());
+ }
+
+ EnsureMaterials();
+ string key = string.Join(";", wings.Select(w =>
+ $"{w.X0},{w.Y0},{w.X1},{w.Y1},{w.EaveZ},{w.Storeys},{w.Shape},{w.NoRoof},{w.RidgeAlongY}")) +
+ $"|{_version}|{_roof.Gables}|{_roof.GableFill}|{Context.CompList.UndoList.Count}|{Context.CompList.RedoList.Count}";
+ if (key == _builtFor)
+ {
+ return _built;
+ }
+
+ int baseZ = wings[0].EaveZ;
+ _draft.BaseZ = baseZ;
+ HouseDraft.Built built = _draft.Build(wings, Context.HouseStyles);
+ var remove = new List();
+ var add = built.Tiles;
+
+ // A new floor replaces the flat tiles lying where it goes, as the floor tool does.
+ MultiEditorComponentList list = Context.CompList;
+ foreach ((ushort _, int x, int y, int z, string layer) in built.Tiles)
+ {
+ if (layer != HouseDraft.FloorsLayer)
+ {
+ continue;
+ }
+
+ foreach (MultiTile tile in list.GetTilesAt(x, y))
+ {
+ if (tile.Z == z && tile.Height == 0 && list.IsShown(tile))
+ {
+ remove.Add(tile);
+ }
+ }
+ }
+
+ // The roof: each wing's walls one cell further along X and Y, eaves on its top storey.
+ var roofWings = new List();
+ foreach (RoofWing wing in wings)
+ {
+ if (wing.NoRoof)
+ {
+ continue;
+ }
+
+ RoofWing roof = wing.Clone();
+ (roof.X0, roof.Y0, roof.X1, roof.Y1) = RoofBox(wing);
+ roof.EaveZ = baseZ + (Math.Clamp(wing.Storeys, 1, HouseDraft.MaxStoreys) * HouseDraft.StoreyHeight);
+ roofWings.Add(roof);
+ }
+
+ if (roofWings.Count > 0 && _draft.RoofStyle != null)
+ {
+ // A lower wing's roof stops at the walls of a taller one.
+ bool Hidden(int x, int y, int z)
+ {
+ foreach (RoofWing wing in wings)
+ {
+ if (x >= wing.X0 && x <= wing.X1 && y >= wing.Y0 && y <= wing.Y1 &&
+ z < baseZ + (wing.Storeys * HouseDraft.StoreyHeight))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ var (roofRemove, roofAdd) = _roof.PlanRoof(roofWings, _draft.RoofStyle, built.Walls, Hidden);
+ remove.AddRange(roofRemove);
+ foreach (var (id, x, y, z, layer) in roofAdd)
+ {
+ add.Add((id, x, y, z, layer ?? RoofTool.LayerName));
+ }
+ }
+
+ _builtFor = key;
+ _built = (remove, add);
+ return _built;
+ }
+ }
+}
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs
index e4dea8bd..d76afbdc 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs
@@ -48,57 +48,20 @@ internal enum RoofGableFill
Walls
}
- /// One rectangle of a roof being shaped: where it lies, how high its eaves are and how it slopes.
- internal sealed class RoofWing
- {
- public int X0 { get; set; }
-
- public int Y0 { get; set; }
-
- public int X1 { get; set; }
-
- public int Y1 { get; set; }
-
- public int EaveZ { get; set; }
-
- public RoofShape Shape { get; set; }
-
- public bool RidgeAlongY { get; set; }
-
- /// True while the ridge follows the box's proportions as it is resized.
- public bool RidgeAuto { get; set; }
-
- public (int X0, int Y0, int X1, int Y1) Box => (X0, Y0, X1, Y1);
-
- public RoofWing Clone() => (RoofWing)MemberwiseClone();
-
- public void CopyFrom(RoofWing other)
- {
- (X0, Y0, X1, Y1, EaveZ) = (other.X0, other.Y0, other.X1, other.Y1, other.EaveZ);
- (Shape, RidgeAlongY, RidgeAuto) = (other.Shape, other.RidgeAlongY, other.RidgeAuto);
- }
- }
-
///
- /// Roofs, shaped before they are placed. The first click on (or inside) a walled room fits a
- /// roof to its walls, part by part on an L or T shaped house; a drag over the walls, the floor
- /// inside them or the area the roof will cover fits it too, and any other drag is a roof of
- /// that size on the work plane. The roof then stays pending, shown as it will be built:
- ///
- /// - click a wing to select it, drag it to move it, drag an edge of the selected wing to
- /// resize it;
- /// - drag anywhere else to add a wing, which joins the others with valleys and T pieces;
- /// - Shift+click turns a wing's ridge, the Shape and Ridge options
- /// change the selected wing, Delete removes it;
- /// - Enter, or switching to another tool, places the roof on the layer named
- /// in one undo step; Esc drops it.
- ///
+ /// Roofs, shaped before they are placed (see for the shaping).
+ /// The first click on (or inside) a walled room fits a roof to its walls, part by part on an
+ /// L or T shaped house; a drag over the walls, the floor inside them or the area the roof
+ /// will cover fits it too, and any other drag is a roof of that size on the work plane.
+ /// Further wings join the others with valleys and T pieces. The Shape and Ridge options
+ /// change the selected wing; Shift+click turns a wing's ridge. Enter, or
+ /// switching to another tool, places the roof on the layer named .
/// A fitted roof sits on the wall tops whatever floor is chosen, overhangs the south and east
/// walls by a cell and grows the multi when that cell lies outside it. Slopes rise 3 per cell
/// like the official house roofs. A roof already there is replaced when it lies wholly under
/// the new one and joined otherwise.
///
- internal sealed class RoofTool : EditorTool
+ internal sealed class RoofTool : WingDraftTool
{
/// The layer a placed roof goes on; made on first use.
public const string LayerName = "Roof";
@@ -107,55 +70,33 @@ internal sealed class RoofTool : EditorTool
private const int _storey = 20;
private const string _capStyles = "Miscellaneous Roof Pieces";
- private enum DragKind
- {
- None,
- New,
- Move,
- Resize
- }
-
- private readonly List _wings = new List();
- private int _selected = -1;
private HouseStyle _lastStyle;
+ private HouseStyle _planStyle;
private RoofShape _shape = RoofShape.Gable;
private RoofRidge _ridge = RoofRidge.Auto;
+ private RoofGables _gables = RoofGables.Front;
+ private RoofGableFill _gableFill = RoofGableFill.Caps;
- private DragKind _drag;
- private int _startX;
- private int _startY;
- private int _endX;
- private int _endY;
- private int _z;
- private RoofWing _before;
- private int _grabX;
- private int _grabY;
- private bool _west;
- private bool _east;
- private bool _north;
- private bool _south;
+ // Walls a house draft is about to build, which the multi does not hold yet.
+ private Dictionary<(int X, int Y), List<(ushort Id, int Z)>> _draftWalls;
public RoofTool(IEditorContext context) : base(context)
{
}
- /// Raised when the pending roof starts, changes or ends.
- public event Action Changed;
-
- /// Raised after a roof was placed.
- public event Action Committed;
-
/// The shape of new wings; also sets the selected wing's.
public RoofShape Shape
{
get => _shape;
set
{
- _shape = value;
- if (SelectedWing is { } wing)
+ if (SelectedWing is { } wing && wing.Shape != value)
{
+ Remember();
wing.Shape = value;
}
+
+ _shape = value;
}
}
@@ -165,31 +106,34 @@ public RoofRidge Ridge
get => _ridge;
set
{
- _ridge = value;
if (SelectedWing is { } wing)
{
+ Remember();
wing.RidgeAuto = value == RoofRidge.Auto;
wing.RidgeAlongY = value == RoofRidge.Auto ? RoofPlanner.RidgeAlongY(wing.Box) : value == RoofRidge.AlongY;
}
+
+ _ridge = value;
}
}
- public RoofGables Gables { get; set; } = RoofGables.Front;
-
- public RoofGableFill GableFill { get; set; } = RoofGableFill.Caps;
-
- /// True while a roof is being shaped and not yet placed.
- public bool HasPending => _wings.Count > 0;
-
- public bool HasSelectedWing => SelectedWing != null;
+ public RoofGables Gables
+ {
+ get => _gables;
+ set => _gables = value;
+ }
- public IReadOnlyList Wings => _wings;
+ public RoofGableFill GableFill
+ {
+ get => _gableFill;
+ set => _gableFill = value;
+ }
- public override bool IsDragging => _drag != DragKind.None;
+ protected override bool Ready => Style != null;
- public override bool TracksCursorCell => true;
+ protected override string ActionName => "Roof";
- private RoofWing SelectedWing => _selected >= 0 && _selected < _wings.Count ? _wings[_selected] : null;
+ protected override string DefaultLayer => LayerName;
/// The roof style chosen in the House tab; a pending roof keeps the last one.
private HouseStyle Style
@@ -206,186 +150,10 @@ private HouseStyle Style
}
}
- // ---------------------------------------------------------------- shaping
-
- public override void OnMouseDown(MouseEventArgs e)
- {
- if (Style == null)
- {
- return;
- }
-
- if (HasPending)
- {
- int hit = HitWing(out int cx, out int cy);
- if (hit >= 0)
- {
- RoofWing wing = _wings[hit];
- bool wasSelected = hit == _selected;
- _selected = hit;
- if (ShiftHeld)
- {
- Turn(wing);
- Changed?.Invoke();
- return;
- }
-
- _before = wing.Clone();
- (_grabX, _grabY) = (cx, cy);
-
- // The selected wing is resized by its outermost cells; a side too short to
- // have a middle moves the wing instead.
- bool wide = wing.X1 - wing.X0 >= 2, deep = wing.Y1 - wing.Y0 >= 2;
- _west = wasSelected && wide && cx == wing.X0;
- _east = wasSelected && wide && cx == wing.X1;
- _north = wasSelected && deep && cy == wing.Y0;
- _south = wasSelected && deep && cy == wing.Y1;
- _drag = _west || _east || _north || _south ? DragKind.Resize : DragKind.Move;
- Changed?.Invoke();
- return;
- }
-
- // A new wing, level with the wing worked on last.
- _z = (SelectedWing ?? _wings[^1]).EaveZ;
- Context.PlaneCell(Context.MouseLoc, _z, out _startX, out _startY);
- }
- else
- {
- BaseCell(out _startX, out _startY, out _z);
- }
-
- (_endX, _endY) = (_startX, _startY);
- _drag = DragKind.New;
- }
-
- public override void OnMouseMove(MouseEventArgs e)
- {
- switch (_drag)
- {
- case DragKind.New:
- Context.PlaneCell(Context.MouseLoc, _z, out _endX, out _endY);
- break;
- case DragKind.Move:
- case DragKind.Resize:
- DragWing();
- break;
- }
- }
-
- public override void OnMouseUp(MouseEventArgs e)
- {
- DragKind drag = _drag;
- if (drag is DragKind.Move or DragKind.Resize)
- {
- DragWing();
- }
-
- _drag = DragKind.None;
- if (drag == DragKind.New)
- {
- Context.PlaneCell(Context.MouseLoc, _z, out _endX, out _endY);
- List wings = WingsFor(_startX, _startY, _endX, _endY, _z, out bool fitted);
- if (HasPending && !fitted && _startX == _endX && _startY == _endY)
- {
- // A click beside the roof lets go of the selected wing.
- _selected = -1;
- }
- else
- {
- _wings.AddRange(wings);
- _selected = _wings.Count - wings.Count;
- }
-
- Changed?.Invoke();
- }
- else if (drag != DragKind.None)
- {
- _before = null;
- Changed?.Invoke();
- }
- }
-
- /// Stops a drag: a wing being moved or resized goes back to where it was.
- public override void Cancel()
- {
- if (_drag is DragKind.Move or DragKind.Resize && _before != null && SelectedWing is { } wing)
- {
- wing.CopyFrom(_before);
- }
-
- _before = null;
- _drag = DragKind.None;
- }
-
- /// Drops the pending roof.
- public void Discard()
- {
- bool had = HasPending;
- _wings.Clear();
- _selected = -1;
- _before = null;
- _drag = DragKind.None;
- if (had)
- {
- Changed?.Invoke();
- }
- }
-
- /// Removes the selected wing from the pending roof.
- public void DeleteWing()
- {
- if (SelectedWing == null || IsDragging)
- {
- return;
- }
-
- _wings.RemoveAt(_selected);
- _selected = _wings.Count - 1;
- Changed?.Invoke();
- }
-
- ///
- /// Places the pending roof: its tiles go on the layer, pieces of
- /// an older roof that had to change stay on their own layer, all in one undo step.
- ///
- public void Commit()
- {
- Cancel();
- if (!HasPending)
- {
- return;
- }
-
- if (Style != null)
- {
- var (remove, add) = Plan(_wings);
- if (remove.Count > 0 || add.Count > 0)
- {
- Context.CompList.ReplaceTilesOnLayer(remove, add, "Roof", LayerName);
- Context.AfterEdit(add.Count > 0 ? add.Max(a => a.Z) : null);
- Committed?.Invoke();
- }
- }
-
- Discard();
- }
-
- /// Lays a roof in one go, as a press at one cell and a release at another would shape it. For scripts and tests.
- public void Place(int startX, int startY, int endX, int endY, int z)
- {
- if (Style == null)
- {
- return;
- }
-
- _wings.AddRange(WingsFor(startX, startY, endX, endY, z, out _));
- Commit();
- }
-
///
/// The eaves go on the work plane, or on top of what the mouse points at (a wall top).
///
- private void BaseCell(out int x, out int y, out int z)
+ protected override void StartCell(out int x, out int y, out int z)
{
Context.CellAt(Context.MouseLoc, out x, out y, out z);
if (Context.WorkZ is { } baseZ)
@@ -395,52 +163,8 @@ private void BaseCell(out int x, out int y, out int z)
}
}
- /// The pending wing under the mouse, the selected one first, and the cell pointed at on its eaves.
- private int HitWing(out int cx, out int cy)
+ protected override void WingResized(RoofWing wing)
{
- (cx, cy) = (0, 0);
- for (int pass = 0; pass < 2; ++pass)
- {
- for (int i = _wings.Count - 1; i >= 0; --i)
- {
- if ((pass == 0) != (i == _selected))
- {
- continue;
- }
-
- RoofWing wing = _wings[i];
- Context.PlaneCell(Context.MouseLoc, wing.EaveZ, out cx, out cy);
- if (cx >= wing.X0 && cx <= wing.X1 && cy >= wing.Y0 && cy <= wing.Y1)
- {
- return i;
- }
- }
- }
-
- return -1;
- }
-
- private void DragWing()
- {
- if (_before == null || SelectedWing is not { } wing)
- {
- return;
- }
-
- Context.PlaneCell(Context.MouseLoc, _before.EaveZ, out int cx, out int cy);
- int dx = cx - _grabX, dy = cy - _grabY;
- if (_drag == DragKind.Move)
- {
- dx = Math.Max(dx, -_before.X0);
- dy = Math.Max(dy, -_before.Y0);
- (wing.X0, wing.X1, wing.Y0, wing.Y1) = (_before.X0 + dx, _before.X1 + dx, _before.Y0 + dy, _before.Y1 + dy);
- return;
- }
-
- wing.X0 = _west ? Math.Clamp(_before.X0 + dx, 0, _before.X1) : _before.X0;
- wing.X1 = _east ? Math.Max(_before.X1 + dx, _before.X0) : _before.X1;
- wing.Y0 = _north ? Math.Clamp(_before.Y0 + dy, 0, _before.Y1) : _before.Y0;
- wing.Y1 = _south ? Math.Max(_before.Y1 + dy, _before.Y0) : _before.Y1;
if (wing.RidgeAuto)
{
wing.RidgeAlongY = RoofPlanner.RidgeAlongY(wing.Box);
@@ -448,7 +172,7 @@ private void DragWing()
}
/// Turns a wing's ridge the other way.
- private static void Turn(RoofWing wing)
+ protected override void Turn(RoofWing wing)
{
wing.RidgeAlongY = !wing.RidgeAlongY;
wing.RidgeAuto = false;
@@ -462,7 +186,7 @@ private static void Turn(RoofWing wing)
/// within a cell of such a roof on every side means that roof. Any other stroke is the
/// roof itself, at . Shift turns a gable's ridge.
///
- private List WingsFor(int startX, int startY, int endX, int endY, int z, out bool fitted)
+ protected override List WingsFor(int startX, int startY, int endX, int endY, int z, out bool fitted)
{
int x0 = Math.Min(startX, endX), x1 = Math.Max(startX, endX);
int y0 = Math.Min(startY, endY), y1 = Math.Max(startY, endY);
@@ -503,85 +227,45 @@ private List WingsFor(int startX, int startY, int endX, int endY, int
return wings;
}
- // ---------------------------------------------------------------- overlay
-
- public override void PaintOverlay(IToolOverlay overlay)
+ protected override (List Remove, List<(ushort Id, int X, int Y, int Z, string Layer)> Add) Plan(IReadOnlyList wings)
{
- if (Style == null)
- {
- return;
- }
-
- // What is shown is what Enter would build: the pending wings, with the one being
- // dragged out; before there is a roof, the one a click here would start.
- var wings = new List(_wings);
- if (_drag == DragKind.New)
- {
- wings.AddRange(WingsFor(_startX, _startY, _endX, _endY, _z, out _));
- }
- else if (!HasPending)
- {
- BaseCell(out int x, out int y, out int z);
- wings.AddRange(WingsFor(x, y, x, y, z, out _));
- }
-
- var (remove, add) = Plan(wings);
- foreach (MultiTile tile in remove)
- {
- overlay.Highlight(tile, TileHighlight.Remove);
- }
-
- foreach (var (id, x, y, z, _) in add)
- {
- overlay.Ghost(id, x, y, z);
- }
-
- for (int i = 0; i < _wings.Count; ++i)
- {
- RoofWing wing = _wings[i];
- Point top = Corner(wing.X0, wing.Y0, wing.EaveZ), right = Corner(wing.X1 + 1, wing.Y0, wing.EaveZ);
- Point bottom = Corner(wing.X1 + 1, wing.Y1 + 1, wing.EaveZ), left = Corner(wing.X0, wing.Y1 + 1, wing.EaveZ);
- overlay.Polyline(new[] { top, right, bottom, left }, closed: true);
- if (i != _selected)
- {
- continue;
- }
-
- // Grips in the middle of the selected wing's sides.
- foreach ((Point a, Point b) in new[] { (top, right), (right, bottom), (bottom, left), (left, top) })
- {
- var mid = new Point((a.X + b.X) / 2, (a.Y + b.Y) / 2);
- overlay.Polyline(new[]
- {
- new Point(mid.X - 5, mid.Y - 5), new Point(mid.X + 5, mid.Y - 5),
- new Point(mid.X + 5, mid.Y + 5), new Point(mid.X - 5, mid.Y + 5)
- }, closed: true);
- }
- }
- }
-
- /// Canvas position of the top corner of a cell's diamond at height z.
- private static Point Corner(int x, int y, int z)
- {
- return new Point(((x - y) * 22) + MultiEditorComponentList.GapXMod, ((x + y) * 22) - (z * 4) - 22);
+ return PlanRoof(wings, Style, null, null);
}
-
// ---------------------------------------------------------------- planning
///
- /// The tiles a roof of these wings takes away and adds. An added tile with no layer goes
- /// on the roof layer; a re-pieced tile of an older roof names the layer it stays on.
+ /// The tiles a roof of these wings takes away and adds, in a roof style. An added tile
+ /// with no layer goes on the roof layer; a re-pieced tile of an older roof names the layer
+ /// it stays on. are walls about to be built with the roof (a
+ /// house draft), which count as standing for the gable ends.
+ /// tells roof cells that must not be built (inside a taller part of the house).
///
- private (List Remove, List<(ushort Id, int X, int Y, int Z, TileLayer Layer)> Add) Plan(IReadOnlyList wings)
+ public (List Remove, List<(ushort Id, int X, int Y, int Z, string Layer)> Add) PlanRoof(IReadOnlyList wings,
+ HouseStyle style, IReadOnlyList<(ushort Id, int X, int Y, int Z)> draftWalls, Func hidden)
{
var remove = new List();
- var add = new List<(ushort Id, int X, int Y, int Z, TileLayer Layer)>();
- HouseStyle style = Style;
+ var add = new List<(ushort Id, int X, int Y, int Z, string Layer)>();
if (wings.Count == 0 || style == null)
{
return (remove, add);
}
+ _planStyle = style;
+ _draftWalls = null;
+ if (draftWalls != null)
+ {
+ _draftWalls = new Dictionary<(int X, int Y), List<(ushort Id, int Z)>>();
+ foreach ((ushort id, int x, int y, int z) in draftWalls)
+ {
+ if (!_draftWalls.TryGetValue((x, y), out List<(ushort Id, int Z)> there))
+ {
+ _draftWalls[(x, y)] = there = new List<(ushort Id, int Z)>();
+ }
+
+ there.Add((id, z));
+ }
+ }
+
MultiEditorComponentList list = Context.CompList;
var heights = new Dictionary<(int X, int Y), int>();
var fixedPieces = new Dictionary<(int X, int Y), string>();
@@ -590,6 +274,18 @@ private static Point Corner(int x, int y, int z)
RoofPlanner.AddWing(heights, fixedPieces, wing.Box, wing.RidgeAlongY, wing.Shape, wing.EaveZ);
}
+ if (hidden != null)
+ {
+ foreach (((int X, int Y) cell, int height) in new List>(heights).Select(h => (h.Key, h.Value)))
+ {
+ if (hidden(cell.X, cell.Y, height))
+ {
+ heights.Remove(cell);
+ fixedPieces.Remove(cell);
+ }
+ }
+ }
+
var footprint = new HashSet<(int X, int Y)>(heights.Keys);
JoinExisting(footprint, heights, fixedPieces, remove, add);
@@ -648,7 +344,7 @@ private static Point Corner(int x, int y, int z)
/// no gable and gets none: only cells with no roof beyond them are filled.
///
private void AddGables(RoofWing wing, Dictionary<(int X, int Y), int> heights, HashSet<(ushort, int, int, int)> placed,
- List<(ushort Id, int X, int Y, int Z, TileLayer Layer)> add)
+ List<(ushort Id, int X, int Y, int Z, string Layer)> add)
{
MultiEditorComponentList list = Context.CompList;
bool ridgeAlongY = wing.RidgeAlongY;
@@ -783,7 +479,7 @@ private void AddGables(RoofWing wing, Dictionary<(int X, int Y), int> heights, H
/// taken out of .
///
private void JoinExisting(HashSet<(int X, int Y)> footprint, Dictionary<(int X, int Y), int> heights,
- Dictionary<(int X, int Y), string> fixedPieces, List remove, List<(ushort Id, int X, int Y, int Z, TileLayer Layer)> add)
+ Dictionary<(int X, int Y), string> fixedPieces, List remove, List<(ushort Id, int X, int Y, int Z, string Layer)> add)
{
MultiEditorComponentList list = Context.CompList;
var existing = new Dictionary<(int X, int Y), List>();
@@ -872,7 +568,7 @@ private void JoinExisting(HashSet<(int X, int Y)> footprint, Dictionary<(int X,
continue;
}
- HouseStyle style = Style;
+ HouseStyle style = _planStyle;
string now = null;
if (Context.HouseStyles.TryGetRoleByArt(tile.Id, out HouseStyle owner, out string slot, out _) && owner.Kind == HousePartKind.Roof)
{
@@ -888,7 +584,7 @@ private void JoinExisting(HashSet<(int X, int Y)> footprint, Dictionary<(int X,
if (id != 0 && id != tile.Id)
{
remove.Add(tile);
- add.Add((id, x, y, tile.Z, tile.Layer));
+ add.Add((id, x, y, tile.Z, tile.Layer.Name));
}
}
}
@@ -1026,6 +722,17 @@ private bool HasStoreyWall(int x, int y, int z)
}
}
+ if (_draftWalls != null && _draftWalls.TryGetValue((x, y), out List<(ushort Id, int Z)> planned))
+ {
+ foreach ((ushort id, int wallZ) in planned)
+ {
+ if (wallZ < z && wallZ > z - _storey - 5 && TileData.ItemTable[id].Height >= _storey / 2)
+ {
+ return true;
+ }
+ }
+ }
+
return false;
}
@@ -1060,7 +767,8 @@ private ushort GableWall(int row, bool alongX, int wallX0, int wallX1, int wallY
int from = alongX ? wallX0 : wallY0, to = alongX ? wallX1 : wallY1;
for (int a = from; a <= to && wall == 0; ++a)
{
- foreach (MultiTile tile in list.GetTilesAt(alongX ? a : row, alongX ? row : a))
+ (int X, int Y) cell = (alongX ? a : row, alongX ? row : a);
+ foreach (MultiTile tile in list.GetTilesAt(cell.X, cell.Y))
{
if (tile.Z < z && Context.HouseStyles.TryGetRole(tile.Id, out HouseStyle owner, out _) && owner.Kind == HousePartKind.Wall)
{
@@ -1068,6 +776,19 @@ private ushort GableWall(int row, bool alongX, int wallX0, int wallX1, int wallY
break;
}
}
+
+ // The top storey of a house being drafted: the walls the gable stands on.
+ if (wall == 0 && _draftWalls != null && _draftWalls.TryGetValue(cell, out List<(ushort Id, int Z)> planned))
+ {
+ foreach ((ushort id, int wallZ) in planned.OrderByDescending(p => p.Z))
+ {
+ if (wallZ < z && Context.HouseStyles.TryGetRole(id, out HouseStyle owner, out _) && owner.Kind == HousePartKind.Wall)
+ {
+ wall = id;
+ break;
+ }
+ }
+ }
}
return wall;
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
new file mode 100644
index 00000000..5d4ed7d5
--- /dev/null
+++ b/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
@@ -0,0 +1,733 @@
+/***************************************************************************
+ *
+ * $Author: Turley
+ *
+ * "THE BEER-WARE LICENSE"
+ * As long as you retain this notice you can do whatever you want with
+ * this stuff. If we meet some day, and you think this stuff is worth it,
+ * you can buy me a beer in return.
+ *
+ ***************************************************************************/
+
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Windows.Forms;
+using UoFiddler.Plugin.MultiEditor.Classes;
+
+namespace UoFiddler.Plugin.MultiEditor.Tools
+{
+ ///
+ /// One rectangle of a roof or a house being shaped. For a roof the box is the cells the roof
+ /// covers and the height of its eaves; for a house the box is the wall
+ /// cells and the Z its ground floor stands on.
+ ///
+ internal sealed class RoofWing
+ {
+ public int X0 { get; set; }
+
+ public int Y0 { get; set; }
+
+ public int X1 { get; set; }
+
+ public int Y1 { get; set; }
+
+ public int EaveZ { get; set; }
+
+ /// Storeys of a house wing.
+ public int Storeys { get; set; } = 1;
+
+ /// A house wing left without a roof.
+ public bool NoRoof { get; set; }
+
+ public RoofShape Shape { get; set; }
+
+ public bool RidgeAlongY { get; set; }
+
+ /// True while the ridge follows the box's proportions as it is resized.
+ public bool RidgeAuto { get; set; }
+
+ public (int X0, int Y0, int X1, int Y1) Box => (X0, Y0, X1, Y1);
+
+ public RoofWing Clone() => (RoofWing)MemberwiseClone();
+
+ public void CopyFrom(RoofWing other)
+ {
+ (X0, Y0, X1, Y1, EaveZ) = (other.X0, other.Y0, other.X1, other.Y1, other.EaveZ);
+ (Shape, RidgeAlongY, RidgeAuto, Storeys, NoRoof) = (other.Shape, other.RidgeAlongY, other.RidgeAuto, other.Storeys, other.NoRoof);
+ }
+ }
+
+ ///
+ /// Base for the tools that shape something out of wings before it is placed (roofs, houses).
+ /// The first stroke starts a draft, shown as it will be built. Then: click a wing to select
+ /// it, drag it to move it, drag an outermost row or column of the selected wing to resize
+ /// it, drag anywhere else to add a wing, Shift+click to turn one, Delete to remove one.
+ /// Nothing is written to the multi until ; drops
+ /// the draft. Every change to the draft is a step of its own undo history, which
+ /// and walk; dropping the draft is such a
+ /// step too, and undoing a placement in the multi brings the draft back with its history.
+ ///
+ internal abstract class WingDraftTool : EditorTool
+ {
+ private const int _historySize = 200;
+
+ private enum DragKind
+ {
+ None,
+ New,
+ Move,
+ Resize
+ }
+
+ private sealed class State
+ {
+ public List Wings;
+ public int Selected;
+ public object Extra;
+ }
+
+ private List _wings = new List();
+ private int _selected = -1;
+ private List _undo = new List();
+ private List _redo = new List();
+
+ private DragKind _drag;
+ private int _startX;
+ private int _startY;
+ private int _endX;
+ private int _endY;
+ private int _z;
+ private RoofWing _before;
+ private State _dragStart;
+ private int _grabX;
+ private int _grabY;
+ private bool _west;
+ private bool _east;
+ private bool _north;
+ private bool _south;
+
+ // The last placement, so undoing it in the multi can bring the draft back.
+ private State _placed;
+ private List _placedHistory;
+
+ protected WingDraftTool(IEditorContext context) : base(context)
+ {
+ }
+
+ /// Raised when the draft starts, changes or ends, and when the selected wing changes.
+ public event Action Changed;
+
+ /// Raised after the draft was placed.
+ public event Action Committed;
+
+ /// True while there is a draft that is not placed yet.
+ public bool HasPending => _wings.Count > 0;
+
+ public IReadOnlyList Wings => _wings;
+
+ public RoofWing SelectedWing => _selected >= 0 && _selected < _wings.Count ? _wings[_selected] : null;
+
+ public bool HasSelectedWing => SelectedWing != null;
+
+ public int SelectedIndex
+ {
+ get => SelectedWing != null ? _selected : -1;
+ set
+ {
+ int index = value >= 0 && value < _wings.Count ? value : -1;
+ if (index != _selected)
+ {
+ _selected = index;
+ RaiseChanged();
+ }
+ }
+ }
+
+ public bool CanUndoDraft => _undo.Count > 0;
+
+ public bool CanRedoDraft => _redo.Count > 0;
+
+ /// The multi's undo step that placed the last draft, or null.
+ public object PlacedBy { get; private set; }
+
+ /// The multi's undo step whose undoing brought the current draft back, or null.
+ public object ReopenedFrom { get; private set; }
+
+ public override bool IsDragging => _drag != DragKind.None;
+
+ public override bool TracksCursorCell => true;
+
+ /// True when the tool has what it needs to build (its styles).
+ protected abstract bool Ready { get; }
+
+ /// The edit's name in the multi's undo list.
+ protected abstract string ActionName { get; }
+
+ /// The layer tiles go on when they name none.
+ protected abstract string DefaultLayer { get; }
+
+ /// The cell and Z a first stroke starts at.
+ protected abstract void StartCell(out int x, out int y, out int z);
+
+ /// The wings a stroke makes; none when the stroke means nothing. tells a stroke that was fitted to something there.
+ protected abstract List WingsFor(int startX, int startY, int endX, int endY, int z, out bool fitted);
+
+ /// The tiles a draft of these wings takes away and adds; an added tile names its layer or none.
+ protected abstract (List Remove, List<(ushort Id, int X, int Y, int Z, string Layer)> Add) Plan(IReadOnlyList wings);
+
+ /// The height a wing's outline and grips are drawn and taken hold of at.
+ protected virtual int GripZ(RoofWing wing) => wing.EaveZ;
+
+ /// The Z a further wing starts at.
+ protected virtual int NextWingZ => GripZ(SelectedWing ?? _wings[^1]);
+
+ /// True when the tool shows what a click would start before there is a draft.
+ protected virtual bool PreviewsFirstClick => true;
+
+ /// True when the draft is drawn only up to the highest Z the view shows (the chosen floor, the height slider).
+ protected virtual bool GhostsFollowView => false;
+
+ /// What the draft holds beside its wings, for the undo history.
+ protected virtual object CaptureExtra() => null;
+
+ protected virtual void RestoreExtra(object extra)
+ {
+ }
+
+ /// Called when a wing's box changed.
+ protected virtual void WingResized(RoofWing wing)
+ {
+ }
+
+ /// Shift+click on a wing.
+ protected virtual void Turn(RoofWing wing)
+ {
+ }
+
+ /// Drawn after the ghost tiles and before the wing outlines.
+ protected virtual void PaintDetails(IToolOverlay overlay, bool active)
+ {
+ }
+
+ // ---------------------------------------------------------------- history
+
+ private State Capture()
+ {
+ return new State { Wings = _wings.Select(w => w.Clone()).ToList(), Selected = _selected, Extra = CaptureExtra() };
+ }
+
+ private void Restore(State state)
+ {
+ _wings = state.Wings.Select(w => w.Clone()).ToList();
+ _selected = state.Selected;
+ RestoreExtra(state.Extra);
+ }
+
+ /// Call before changing the draft: the state as it is becomes an undo step.
+ public void Remember()
+ {
+ Push(Capture());
+ }
+
+ private void Push(State state)
+ {
+ _undo.Add(state);
+ if (_undo.Count > _historySize)
+ {
+ _undo.RemoveAt(0);
+ }
+
+ _redo.Clear();
+ ReopenedFrom = null;
+ }
+
+ protected void RaiseChanged() => Changed?.Invoke();
+
+ public bool UndoDraft()
+ {
+ if (_undo.Count == 0)
+ {
+ return false;
+ }
+
+ CancelDrag();
+ _redo.Add(Capture());
+ Restore(_undo[^1]);
+ _undo.RemoveAt(_undo.Count - 1);
+ RaiseChanged();
+ return true;
+ }
+
+ public bool RedoDraft()
+ {
+ if (_redo.Count == 0)
+ {
+ return false;
+ }
+
+ CancelDrag();
+ _undo.Add(Capture());
+ Restore(_redo[^1]);
+ _redo.RemoveAt(_redo.Count - 1);
+ RaiseChanged();
+ return true;
+ }
+
+ // ---------------------------------------------------------------- shaping
+
+ public override void OnMouseDown(MouseEventArgs e)
+ {
+ if (!Ready)
+ {
+ return;
+ }
+
+ if (HasPending)
+ {
+ int hit = HitWing(out int cx, out int cy);
+ if (hit >= 0)
+ {
+ RoofWing wing = _wings[hit];
+ bool wasSelected = hit == _selected;
+ if (ShiftHeld)
+ {
+ Remember();
+ _selected = hit;
+ Turn(wing);
+ RaiseChanged();
+ return;
+ }
+
+ _selected = hit;
+ _before = wing.Clone();
+ _dragStart = Capture();
+ (_grabX, _grabY) = (cx, cy);
+ Edges(wing, cx, cy, wasSelected, out _west, out _east, out _north, out _south);
+ _drag = _west || _east || _north || _south ? DragKind.Resize : DragKind.Move;
+ RaiseChanged();
+ return;
+ }
+
+ _z = NextWingZ;
+ Context.PlaneCell(Context.MouseLoc, _z, out _startX, out _startY);
+ }
+ else
+ {
+ StartCell(out _startX, out _startY, out _z);
+ }
+
+ (_endX, _endY) = (_startX, _startY);
+ _drag = DragKind.New;
+ }
+
+ ///
+ /// The sides a press on a cell of the selected wing takes hold of: its outermost rows and
+ /// columns. A side too short to have a middle moves the wing instead.
+ ///
+ private static void Edges(RoofWing wing, int cx, int cy, bool selected, out bool west, out bool east, out bool north, out bool south)
+ {
+ bool wide = wing.X1 - wing.X0 >= 2, deep = wing.Y1 - wing.Y0 >= 2;
+ west = selected && wide && cx == wing.X0;
+ east = selected && wide && cx == wing.X1;
+ north = selected && deep && cy == wing.Y0;
+ south = selected && deep && cy == wing.Y1;
+ }
+
+ public override void OnMouseMove(MouseEventArgs e)
+ {
+ switch (_drag)
+ {
+ case DragKind.New:
+ Context.PlaneCell(Context.MouseLoc, _z, out _endX, out _endY);
+ break;
+ case DragKind.Move:
+ case DragKind.Resize:
+ DragWing();
+ break;
+ }
+ }
+
+ public override void OnMouseUp(MouseEventArgs e)
+ {
+ DragKind drag = _drag;
+ if (drag is DragKind.Move or DragKind.Resize)
+ {
+ DragWing();
+ }
+
+ _drag = DragKind.None;
+ if (drag == DragKind.New)
+ {
+ Context.PlaneCell(Context.MouseLoc, _z, out _endX, out _endY);
+ List wings = WingsFor(_startX, _startY, _endX, _endY, _z, out bool fitted);
+ if (wings.Count == 0 || (HasPending && !fitted && _startX == _endX && _startY == _endY))
+ {
+ // A click beside the draft lets go of the selected wing.
+ _selected = -1;
+ }
+ else
+ {
+ Remember();
+ _wings.AddRange(wings);
+ _selected = _wings.Count - wings.Count;
+ }
+
+ RaiseChanged();
+ }
+ else if (drag != DragKind.None)
+ {
+ if (SelectedWing is { } wing && _before != null && wing.Box != _before.Box && _dragStart != null)
+ {
+ Push(_dragStart);
+ }
+
+ _before = null;
+ _dragStart = null;
+ RaiseChanged();
+ }
+ }
+
+ /// Stops a drag: a wing being moved or resized goes back to where it was.
+ public override void Cancel()
+ {
+ CancelDrag();
+ }
+
+ private void CancelDrag()
+ {
+ if (_drag is DragKind.Move or DragKind.Resize && _before != null && SelectedWing is { } wing)
+ {
+ wing.CopyFrom(_before);
+ }
+
+ _before = null;
+ _dragStart = null;
+ _drag = DragKind.None;
+ }
+
+ /// Drops the draft. A step of the draft's history: undo brings it back.
+ public void Discard()
+ {
+ CancelDrag();
+ if (!HasPending)
+ {
+ return;
+ }
+
+ Remember();
+ _wings.Clear();
+ _selected = -1;
+ RestoreExtra(null);
+ RaiseChanged();
+ }
+
+ /// Forgets the draft and its history (another document).
+ public void Reset()
+ {
+ CancelDrag();
+ bool had = HasPending;
+ _wings.Clear();
+ _selected = -1;
+ _undo.Clear();
+ _redo.Clear();
+ _placed = null;
+ _placedHistory = null;
+ PlacedBy = null;
+ ReopenedFrom = null;
+ RestoreExtra(null);
+ if (had)
+ {
+ RaiseChanged();
+ }
+ }
+
+ /// Removes the selected wing from the draft.
+ public void DeleteWing()
+ {
+ if (SelectedWing == null || IsDragging)
+ {
+ return;
+ }
+
+ Remember();
+ _wings.RemoveAt(_selected);
+ _selected = _wings.Count - 1;
+ RaiseChanged();
+ }
+
+ ///
+ /// Places the draft in one undo step of the multi. Undoing that step brings the draft
+ /// back ().
+ ///
+ public void Commit()
+ {
+ CancelDrag();
+ if (!HasPending)
+ {
+ return;
+ }
+
+ if (Ready)
+ {
+ var (remove, add) = Plan(_wings);
+ if (remove.Count > 0 || add.Count > 0)
+ {
+ int steps = Context.CompList.UndoList.Count;
+ object top = steps > 0 ? Context.CompList.UndoList[0] : null;
+ Context.CompList.ReplaceTilesOnLayers(remove, add, ActionName, DefaultLayer);
+ Context.AfterEdit(add.Count > 0 ? add.Max(a => a.Z) : null);
+ object placedBy = Context.CompList.UndoList.Count > 0 ? Context.CompList.UndoList[0] : null;
+ if (placedBy != null && !ReferenceEquals(placedBy, top))
+ {
+ _placed = Capture();
+ _placedHistory = new List(_undo);
+ PlacedBy = placedBy;
+ }
+
+ Committed?.Invoke();
+ }
+ }
+
+ _wings.Clear();
+ _selected = -1;
+ _undo.Clear();
+ _redo.Clear();
+ ReopenedFrom = null;
+ RestoreExtra(null);
+ RaiseChanged();
+ }
+
+ /// Brings back the draft that placed, after that step was undone.
+ public void Reopen()
+ {
+ if (_placed == null)
+ {
+ return;
+ }
+
+ Restore(_placed);
+ _undo = new List(_placedHistory);
+ _redo.Clear();
+ ReopenedFrom = PlacedBy;
+ PlacedBy = null;
+ RaiseChanged();
+ }
+
+ /// Lets go of a reopened draft because its placement is being redone in the multi.
+ public void CloseReopened()
+ {
+ if (ReopenedFrom == null)
+ {
+ return;
+ }
+
+ _placed = Capture();
+ _placedHistory = new List(_undo);
+ PlacedBy = ReopenedFrom;
+ ReopenedFrom = null;
+ _wings.Clear();
+ _selected = -1;
+ _undo.Clear();
+ _redo.Clear();
+ RestoreExtra(null);
+ RaiseChanged();
+ }
+
+ /// Lays a draft in one go, as a press at one cell and a release at another would start it. For scripts and tests.
+ public void Place(int startX, int startY, int endX, int endY, int z)
+ {
+ if (!Ready)
+ {
+ return;
+ }
+
+ _wings.AddRange(WingsFor(startX, startY, endX, endY, z, out _));
+ Commit();
+ }
+
+ /// The wing under the mouse, the selected one first, and the cell pointed at on its plane.
+ private int HitWing(out int cx, out int cy)
+ {
+ (cx, cy) = (0, 0);
+ for (int pass = 0; pass < 2; ++pass)
+ {
+ for (int i = _wings.Count - 1; i >= 0; --i)
+ {
+ if ((pass == 0) != (i == _selected))
+ {
+ continue;
+ }
+
+ RoofWing wing = _wings[i];
+ Context.PlaneCell(Context.MouseLoc, GripZ(wing), out cx, out cy);
+ if (cx >= wing.X0 && cx <= wing.X1 && cy >= wing.Y0 && cy <= wing.Y1)
+ {
+ return i;
+ }
+ }
+ }
+
+ return -1;
+ }
+
+ private void DragWing()
+ {
+ if (_before == null || SelectedWing is not { } wing)
+ {
+ return;
+ }
+
+ Context.PlaneCell(Context.MouseLoc, GripZ(_before), out int cx, out int cy);
+ int dx = cx - _grabX, dy = cy - _grabY;
+ if (_drag == DragKind.Move)
+ {
+ dx = Math.Max(dx, -_before.X0);
+ dy = Math.Max(dy, -_before.Y0);
+ (wing.X0, wing.X1, wing.Y0, wing.Y1) = (_before.X0 + dx, _before.X1 + dx, _before.Y0 + dy, _before.Y1 + dy);
+ return;
+ }
+
+ wing.X0 = _west ? Math.Clamp(_before.X0 + dx, 0, _before.X1) : _before.X0;
+ wing.X1 = _east ? Math.Max(_before.X1 + dx, _before.X0) : _before.X1;
+ wing.Y0 = _north ? Math.Clamp(_before.Y0 + dy, 0, _before.Y1) : _before.Y0;
+ wing.Y1 = _south ? Math.Max(_before.Y1 + dy, _before.Y0) : _before.Y1;
+ WingResized(wing);
+ }
+
+ // ---------------------------------------------------------------- overlay
+
+ public override void PaintOverlay(IToolOverlay overlay)
+ {
+ PaintDraft(overlay, active: true);
+ }
+
+ ///
+ /// Draws the draft as it would be built. With (this tool is in
+ /// use) it also shows what the mouse would take hold of: the wing under it, the side of
+ /// the selected wing a press would resize, and the wing being dragged out.
+ ///
+ public void PaintDraft(IToolOverlay overlay, bool active)
+ {
+ if (!Ready)
+ {
+ return;
+ }
+
+ var wings = new List(_wings);
+ List stroke = null;
+ if (active && _drag == DragKind.New)
+ {
+ stroke = WingsFor(_startX, _startY, _endX, _endY, _z, out _);
+ }
+ else if (active && !HasPending && PreviewsFirstClick)
+ {
+ StartCell(out int x, out int y, out int z);
+ stroke = WingsFor(x, y, x, y, z, out _);
+ }
+
+ if (stroke != null)
+ {
+ wings.AddRange(stroke);
+ }
+
+ var (remove, add) = Plan(wings);
+ foreach (MultiTile tile in remove)
+ {
+ overlay.Highlight(tile, TileHighlight.Remove);
+ }
+
+ // A house is looked into like the multi: storeys above the chosen floor are left out.
+ int highest = GhostsFollowView ? Context.MaxHeight : int.MaxValue;
+ foreach (var (id, x, y, z, _) in add)
+ {
+ if (z <= highest)
+ {
+ overlay.Ghost(id, x, y, z);
+ }
+ }
+
+ PaintDetails(overlay, active);
+
+ int hover = -1, hx = 0, hy = 0;
+ if (active && _drag == DragKind.None && HasPending)
+ {
+ hover = HitWing(out hx, out hy);
+ }
+
+ for (int i = 0; i < _wings.Count; ++i)
+ {
+ RoofWing wing = _wings[i];
+ int z = GripZ(wing);
+ bool selected = i == _selected;
+ if (selected && active)
+ {
+ // The rows and columns a press would resize by; the one under the mouse stands out.
+ Edges(wing, hx, hy, hover == i, out bool west, out bool east, out bool north, out bool south);
+ if (_drag == DragKind.Resize)
+ {
+ (west, east, north, south) = (_west, _east, _north, _south);
+ }
+
+ for (int x = wing.X0; x <= wing.X1; ++x)
+ {
+ for (int y = wing.Y0; y <= wing.Y1; ++y)
+ {
+ bool band = x == wing.X0 || x == wing.X1 || y == wing.Y0 || y == wing.Y1;
+ bool held = (west && x == wing.X0) || (east && x == wing.X1) || (north && y == wing.Y0) || (south && y == wing.Y1);
+ if (held)
+ {
+ overlay.CellMark(x, y, z, OverlayTone.Hover);
+ }
+ else if (band)
+ {
+ overlay.CellMark(x, y, z, OverlayTone.Selected);
+ }
+ }
+ }
+ }
+
+ OverlayTone tone = selected ? OverlayTone.Selected : i == hover ? OverlayTone.Hover : OverlayTone.Plain;
+ Point[] corners = BoxOutline(wing.X0, wing.Y0, wing.X1, wing.Y1, z);
+ overlay.Outline(corners, tone);
+ if (!selected || !active)
+ {
+ continue;
+ }
+
+ // Grips in the middle of the selected wing's sides.
+ for (int side = 0; side < 4; ++side)
+ {
+ Point a = corners[side], b = corners[(side + 1) % 4];
+ var mid = new Point((a.X + b.X) / 2, (a.Y + b.Y) / 2);
+ overlay.Outline(new[]
+ {
+ new Point(mid.X - 5, mid.Y - 5), new Point(mid.X + 5, mid.Y - 5),
+ new Point(mid.X + 5, mid.Y + 5), new Point(mid.X - 5, mid.Y + 5)
+ }, OverlayTone.Selected);
+ }
+ }
+
+ if (stroke != null && _drag == DragKind.New)
+ {
+ foreach (RoofWing wing in stroke)
+ {
+ overlay.Outline(BoxOutline(wing.X0, wing.Y0, wing.X1, wing.Y1, GripZ(wing)), OverlayTone.Hover);
+ }
+ }
+ }
+
+ /// The corners of a box of cells on the plane at height z: top, right, bottom, left.
+ protected static Point[] BoxOutline(int x0, int y0, int x1, int y1, int z)
+ {
+ return new[] { Corner(x0, y0, z), Corner(x1 + 1, y0, z), Corner(x1 + 1, y1 + 1, z), Corner(x0, y1 + 1, z) };
+ }
+
+ /// Canvas position of the top corner of a cell's diamond at height z.
+ protected static Point Corner(int x, int y, int z)
+ {
+ return new Point(((x - y) * 22) + MultiEditorComponentList.GapXMod, ((x + y) * 22) - (z * 4) - 22);
+ }
+ }
+}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs
new file mode 100644
index 00000000..2e2646fe
--- /dev/null
+++ b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs
@@ -0,0 +1,459 @@
+namespace UoFiddler.Plugin.MultiEditor.UI
+{
+ partial class HousePanel
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ houseBox = new System.Windows.Forms.GroupBox();
+ _wingList = new System.Windows.Forms.ListBox();
+ _wingHint = new System.Windows.Forms.Label();
+ _storeysLabel = new System.Windows.Forms.Label();
+ _storeys = new System.Windows.Forms.NumericUpDown();
+ _removeWing = new System.Windows.Forms.Button();
+ _roofLabel = new System.Windows.Forms.Label();
+ _roofShape = new System.Windows.Forms.ComboBox();
+ _ridge = new System.Windows.Forms.ComboBox();
+ _materialsLabel = new System.Windows.Forms.Label();
+ _storey1 = new System.Windows.Forms.Label();
+ _wall1 = new System.Windows.Forms.Button();
+ _floor1 = new System.Windows.Forms.Button();
+ _storey2 = new System.Windows.Forms.Label();
+ _wall2 = new System.Windows.Forms.Button();
+ _floor2 = new System.Windows.Forms.Button();
+ _storey3 = new System.Windows.Forms.Label();
+ _wall3 = new System.Windows.Forms.Button();
+ _floor3 = new System.Windows.Forms.Button();
+ _storey4 = new System.Windows.Forms.Label();
+ _wall4 = new System.Windows.Forms.Button();
+ _floor4 = new System.Windows.Forms.Button();
+ _roofStyleLabel = new System.Windows.Forms.Label();
+ _roofStyle = new System.Windows.Forms.Button();
+ _foundation = new System.Windows.Forms.CheckBox();
+ _baseZLabel = new System.Windows.Forms.Label();
+ _baseZ = new System.Windows.Forms.NumericUpDown();
+ _undo = new System.Windows.Forms.Button();
+ _redo = new System.Windows.Forms.Button();
+ _place = new System.Windows.Forms.Button();
+ _drop = new System.Windows.Forms.Button();
+ _status = new System.Windows.Forms.Label();
+ houseBox.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)_storeys).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)_baseZ).BeginInit();
+ SuspendLayout();
+ //
+ // houseBox
+ //
+ houseBox.Controls.Add(_wingList);
+ houseBox.Controls.Add(_wingHint);
+ houseBox.Controls.Add(_storeysLabel);
+ houseBox.Controls.Add(_storeys);
+ houseBox.Controls.Add(_removeWing);
+ houseBox.Controls.Add(_roofLabel);
+ houseBox.Controls.Add(_roofShape);
+ houseBox.Controls.Add(_ridge);
+ houseBox.Controls.Add(_materialsLabel);
+ houseBox.Controls.Add(_storey1);
+ houseBox.Controls.Add(_wall1);
+ houseBox.Controls.Add(_floor1);
+ houseBox.Controls.Add(_storey2);
+ houseBox.Controls.Add(_wall2);
+ houseBox.Controls.Add(_floor2);
+ houseBox.Controls.Add(_storey3);
+ houseBox.Controls.Add(_wall3);
+ houseBox.Controls.Add(_floor3);
+ houseBox.Controls.Add(_storey4);
+ houseBox.Controls.Add(_wall4);
+ houseBox.Controls.Add(_floor4);
+ houseBox.Controls.Add(_roofStyleLabel);
+ houseBox.Controls.Add(_roofStyle);
+ houseBox.Controls.Add(_foundation);
+ houseBox.Controls.Add(_baseZLabel);
+ houseBox.Controls.Add(_baseZ);
+ houseBox.Controls.Add(_undo);
+ houseBox.Controls.Add(_redo);
+ houseBox.Controls.Add(_place);
+ houseBox.Controls.Add(_drop);
+ houseBox.Controls.Add(_status);
+ houseBox.Dock = System.Windows.Forms.DockStyle.Fill;
+ houseBox.Location = new System.Drawing.Point(0, 0);
+ houseBox.Name = "houseBox";
+ houseBox.Size = new System.Drawing.Size(250, 430);
+ houseBox.TabIndex = 0;
+ houseBox.TabStop = false;
+ houseBox.Text = "House draft";
+ //
+ // _wingList
+ //
+ _wingList.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _wingList.FormattingEnabled = true;
+ _wingList.IntegralHeight = false;
+ _wingList.Location = new System.Drawing.Point(6, 20);
+ _wingList.Name = "_wingList";
+ _wingList.Size = new System.Drawing.Size(238, 64);
+ _wingList.TabIndex = 0;
+ _wingList.SelectedIndexChanged += WingList_SelectedIndexChanged;
+ //
+ // _wingHint
+ //
+ _wingHint.AutoSize = true;
+ _wingHint.Location = new System.Drawing.Point(6, 90);
+ _wingHint.Name = "_wingHint";
+ _wingHint.Size = new System.Drawing.Size(120, 15);
+ _wingHint.TabIndex = 1;
+ _wingHint.Text = "New wings:";
+ //
+ // _storeysLabel
+ //
+ _storeysLabel.AutoSize = true;
+ _storeysLabel.Location = new System.Drawing.Point(6, 113);
+ _storeysLabel.Name = "_storeysLabel";
+ _storeysLabel.Size = new System.Drawing.Size(50, 15);
+ _storeysLabel.TabIndex = 2;
+ _storeysLabel.Text = "Storeys";
+ //
+ // _storeys
+ //
+ _storeys.Maximum = new decimal(new int[] { 4, 0, 0, 0 });
+ _storeys.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
+ _storeys.Value = new decimal(new int[] { 1, 0, 0, 0 });
+ _storeys.Location = new System.Drawing.Point(60, 110);
+ _storeys.Name = "_storeys";
+ _storeys.Size = new System.Drawing.Size(44, 23);
+ _storeys.TabIndex = 3;
+ _storeys.ValueChanged += Storeys_ValueChanged;
+ //
+ // _removeWing
+ //
+ _removeWing.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right;
+ _removeWing.UseVisualStyleBackColor = true;
+ _removeWing.Location = new System.Drawing.Point(150, 109);
+ _removeWing.Name = "_removeWing";
+ _removeWing.Size = new System.Drawing.Size(94, 25);
+ _removeWing.TabIndex = 4;
+ _removeWing.Text = "Remove wing";
+ _removeWing.Click += RemoveWing_Click;
+ //
+ // _roofLabel
+ //
+ _roofLabel.AutoSize = true;
+ _roofLabel.Location = new System.Drawing.Point(6, 143);
+ _roofLabel.Name = "_roofLabel";
+ _roofLabel.Size = new System.Drawing.Size(50, 15);
+ _roofLabel.TabIndex = 5;
+ _roofLabel.Text = "Roof";
+ //
+ // _roofShape
+ //
+ _roofShape.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ _roofShape.FormattingEnabled = true;
+ _roofShape.Items.AddRange(new object[] { "Gable", "None" });
+ _roofShape.Location = new System.Drawing.Point(60, 140);
+ _roofShape.Name = "_roofShape";
+ _roofShape.Size = new System.Drawing.Size(80, 23);
+ _roofShape.TabIndex = 6;
+ _roofShape.SelectedIndexChanged += RoofShape_SelectedIndexChanged;
+ //
+ // _ridge
+ //
+ _ridge.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _ridge.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ _ridge.FormattingEnabled = true;
+ _ridge.Items.AddRange(new object[] { "Ridge: auto", "Ridge along X", "Ridge along Y" });
+ _ridge.Location = new System.Drawing.Point(146, 140);
+ _ridge.Name = "_ridge";
+ _ridge.Size = new System.Drawing.Size(98, 23);
+ _ridge.TabIndex = 7;
+ _ridge.SelectedIndexChanged += Ridge_SelectedIndexChanged;
+ //
+ // _materialsLabel
+ //
+ _materialsLabel.Location = new System.Drawing.Point(6, 172);
+ _materialsLabel.Name = "_materialsLabel";
+ _materialsLabel.Size = new System.Drawing.Size(238, 15);
+ _materialsLabel.TabIndex = 8;
+ _materialsLabel.Text = "Storey: walls and floor style";
+ //
+ // _storey1
+ //
+ _storey1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ _storey1.Location = new System.Drawing.Point(6, 196);
+ _storey1.Name = "_storey1";
+ _storey1.Size = new System.Drawing.Size(18, 17);
+ _storey1.TabIndex = 9;
+ _storey1.Text = "1";
+ //
+ // _wall1
+ //
+ _wall1.UseVisualStyleBackColor = true;
+ _wall1.Location = new System.Drawing.Point(28, 192);
+ _wall1.Name = "_wall1";
+ _wall1.Size = new System.Drawing.Size(106, 25);
+ _wall1.TabIndex = 10;
+ _wall1.Text = "(walls)";
+ //
+ // _floor1
+ //
+ _floor1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _floor1.UseVisualStyleBackColor = true;
+ _floor1.Location = new System.Drawing.Point(138, 192);
+ _floor1.Name = "_floor1";
+ _floor1.Size = new System.Drawing.Size(106, 25);
+ _floor1.TabIndex = 11;
+ _floor1.Text = "(floor)";
+ //
+ // _storey2
+ //
+ _storey2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ _storey2.Location = new System.Drawing.Point(6, 223);
+ _storey2.Name = "_storey2";
+ _storey2.Size = new System.Drawing.Size(18, 17);
+ _storey2.TabIndex = 12;
+ _storey2.Text = "2";
+ //
+ // _wall2
+ //
+ _wall2.UseVisualStyleBackColor = true;
+ _wall2.Location = new System.Drawing.Point(28, 219);
+ _wall2.Name = "_wall2";
+ _wall2.Size = new System.Drawing.Size(106, 25);
+ _wall2.TabIndex = 13;
+ _wall2.Text = "(walls)";
+ //
+ // _floor2
+ //
+ _floor2.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _floor2.UseVisualStyleBackColor = true;
+ _floor2.Location = new System.Drawing.Point(138, 219);
+ _floor2.Name = "_floor2";
+ _floor2.Size = new System.Drawing.Size(106, 25);
+ _floor2.TabIndex = 14;
+ _floor2.Text = "(floor)";
+ //
+ // _storey3
+ //
+ _storey3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ _storey3.Location = new System.Drawing.Point(6, 250);
+ _storey3.Name = "_storey3";
+ _storey3.Size = new System.Drawing.Size(18, 17);
+ _storey3.TabIndex = 15;
+ _storey3.Text = "3";
+ //
+ // _wall3
+ //
+ _wall3.UseVisualStyleBackColor = true;
+ _wall3.Location = new System.Drawing.Point(28, 246);
+ _wall3.Name = "_wall3";
+ _wall3.Size = new System.Drawing.Size(106, 25);
+ _wall3.TabIndex = 16;
+ _wall3.Text = "(walls)";
+ //
+ // _floor3
+ //
+ _floor3.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _floor3.UseVisualStyleBackColor = true;
+ _floor3.Location = new System.Drawing.Point(138, 246);
+ _floor3.Name = "_floor3";
+ _floor3.Size = new System.Drawing.Size(106, 25);
+ _floor3.TabIndex = 17;
+ _floor3.Text = "(floor)";
+ //
+ // _storey4
+ //
+ _storey4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ _storey4.Location = new System.Drawing.Point(6, 277);
+ _storey4.Name = "_storey4";
+ _storey4.Size = new System.Drawing.Size(18, 17);
+ _storey4.TabIndex = 18;
+ _storey4.Text = "4";
+ //
+ // _wall4
+ //
+ _wall4.UseVisualStyleBackColor = true;
+ _wall4.Location = new System.Drawing.Point(28, 273);
+ _wall4.Name = "_wall4";
+ _wall4.Size = new System.Drawing.Size(106, 25);
+ _wall4.TabIndex = 19;
+ _wall4.Text = "(walls)";
+ //
+ // _floor4
+ //
+ _floor4.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _floor4.UseVisualStyleBackColor = true;
+ _floor4.Location = new System.Drawing.Point(138, 273);
+ _floor4.Name = "_floor4";
+ _floor4.Size = new System.Drawing.Size(106, 25);
+ _floor4.TabIndex = 20;
+ _floor4.Text = "(floor)";
+ //
+ // _roofStyleLabel
+ //
+ _roofStyleLabel.AutoSize = true;
+ _roofStyleLabel.Location = new System.Drawing.Point(6, 305);
+ _roofStyleLabel.Name = "_roofStyleLabel";
+ _roofStyleLabel.Size = new System.Drawing.Size(50, 15);
+ _roofStyleLabel.TabIndex = 21;
+ _roofStyleLabel.Text = "Roof";
+ //
+ // _roofStyle
+ //
+ _roofStyle.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _roofStyle.UseVisualStyleBackColor = true;
+ _roofStyle.Location = new System.Drawing.Point(60, 300);
+ _roofStyle.Name = "_roofStyle";
+ _roofStyle.Size = new System.Drawing.Size(184, 25);
+ _roofStyle.TabIndex = 22;
+ _roofStyle.Text = "(roof)";
+ //
+ // _foundation
+ //
+ _foundation.AutoSize = true;
+ _foundation.UseVisualStyleBackColor = true;
+ _foundation.Location = new System.Drawing.Point(6, 332);
+ _foundation.Name = "_foundation";
+ _foundation.Size = new System.Drawing.Size(100, 19);
+ _foundation.TabIndex = 23;
+ _foundation.Text = "Foundation";
+ _foundation.CheckedChanged += Foundation_CheckedChanged;
+ //
+ // _baseZLabel
+ //
+ _baseZLabel.AutoSize = true;
+ _baseZLabel.Location = new System.Drawing.Point(126, 334);
+ _baseZLabel.Name = "_baseZLabel";
+ _baseZLabel.Size = new System.Drawing.Size(44, 15);
+ _baseZLabel.TabIndex = 24;
+ _baseZLabel.Text = "Base Z";
+ //
+ // _baseZ
+ //
+ _baseZ.Maximum = new decimal(new int[] { 100, 0, 0, 0 });
+ _baseZ.Minimum = new decimal(new int[] { 100, 0, 0, int.MinValue });
+ _baseZ.Location = new System.Drawing.Point(174, 331);
+ _baseZ.Name = "_baseZ";
+ _baseZ.Size = new System.Drawing.Size(56, 23);
+ _baseZ.TabIndex = 25;
+ _baseZ.ValueChanged += BaseZ_ValueChanged;
+ //
+ // _undo
+ //
+ _undo.UseVisualStyleBackColor = true;
+ _undo.Location = new System.Drawing.Point(6, 362);
+ _undo.Name = "_undo";
+ _undo.Size = new System.Drawing.Size(54, 25);
+ _undo.TabIndex = 26;
+ _undo.Text = "Undo";
+ _undo.Click += Undo_Click;
+ //
+ // _redo
+ //
+ _redo.UseVisualStyleBackColor = true;
+ _redo.Location = new System.Drawing.Point(62, 362);
+ _redo.Name = "_redo";
+ _redo.Size = new System.Drawing.Size(54, 25);
+ _redo.TabIndex = 27;
+ _redo.Text = "Redo";
+ _redo.Click += Redo_Click;
+ //
+ // _place
+ //
+ _place.UseVisualStyleBackColor = true;
+ _place.Location = new System.Drawing.Point(122, 362);
+ _place.Name = "_place";
+ _place.Size = new System.Drawing.Size(72, 25);
+ _place.TabIndex = 28;
+ _place.Text = "Place";
+ _place.Click += Place_Click;
+ //
+ // _drop
+ //
+ _drop.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _drop.UseVisualStyleBackColor = true;
+ _drop.Location = new System.Drawing.Point(196, 362);
+ _drop.Name = "_drop";
+ _drop.Size = new System.Drawing.Size(48, 25);
+ _drop.TabIndex = 29;
+ _drop.Text = "Drop";
+ _drop.Click += Drop_Click;
+ //
+ // _status
+ //
+ _status.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _status.Location = new System.Drawing.Point(6, 392);
+ _status.Name = "_status";
+ _status.Size = new System.Drawing.Size(238, 32);
+ _status.TabIndex = 30;
+ //
+ // HousePanel
+ //
+ AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ Controls.Add(houseBox);
+ Name = "HousePanel";
+ Size = new System.Drawing.Size(250, 430);
+ houseBox.ResumeLayout(false);
+ houseBox.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)_storeys).EndInit();
+ ((System.ComponentModel.ISupportInitialize)_baseZ).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private System.Windows.Forms.GroupBox houseBox;
+ private System.Windows.Forms.ListBox _wingList;
+ private System.Windows.Forms.Label _wingHint;
+ private System.Windows.Forms.Label _storeysLabel;
+ private System.Windows.Forms.NumericUpDown _storeys;
+ private System.Windows.Forms.Button _removeWing;
+ private System.Windows.Forms.Label _roofLabel;
+ private System.Windows.Forms.ComboBox _roofShape;
+ private System.Windows.Forms.ComboBox _ridge;
+ private System.Windows.Forms.Label _materialsLabel;
+ private System.Windows.Forms.Label _storey1;
+ private System.Windows.Forms.Button _wall1;
+ private System.Windows.Forms.Button _floor1;
+ private System.Windows.Forms.Label _storey2;
+ private System.Windows.Forms.Button _wall2;
+ private System.Windows.Forms.Button _floor2;
+ private System.Windows.Forms.Label _storey3;
+ private System.Windows.Forms.Button _wall3;
+ private System.Windows.Forms.Button _floor3;
+ private System.Windows.Forms.Label _storey4;
+ private System.Windows.Forms.Button _wall4;
+ private System.Windows.Forms.Button _floor4;
+ private System.Windows.Forms.Label _roofStyleLabel;
+ private System.Windows.Forms.Button _roofStyle;
+ private System.Windows.Forms.CheckBox _foundation;
+ private System.Windows.Forms.Label _baseZLabel;
+ private System.Windows.Forms.NumericUpDown _baseZ;
+ private System.Windows.Forms.Button _undo;
+ private System.Windows.Forms.Button _redo;
+ private System.Windows.Forms.Button _place;
+ private System.Windows.Forms.Button _drop;
+ private System.Windows.Forms.Label _status;
+ }
+}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
new file mode 100644
index 00000000..d744288b
--- /dev/null
+++ b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
@@ -0,0 +1,233 @@
+/***************************************************************************
+ *
+ * $Author: Turley
+ *
+ * "THE BEER-WARE LICENSE"
+ * As long as you retain this notice you can do whatever you want with
+ * this stuff. If we meet some day, and you think this stuff is worth it,
+ * you can buy me a beer in return.
+ *
+ ***************************************************************************/
+
+using System;
+using System.Drawing;
+using System.Linq;
+using System.Windows.Forms;
+using UoFiddler.Plugin.MultiEditor.Classes;
+using UoFiddler.Plugin.MultiEditor.Editing;
+using UoFiddler.Plugin.MultiEditor.Tools;
+
+namespace UoFiddler.Plugin.MultiEditor.UI
+{
+ ///
+ /// The house draft of the session: its wings, the storeys and roof of the selected wing, the
+ /// wall and floor style of each storey, the roof style, foundation and base Z, and the
+ /// draft's undo, redo, place and drop. The row of the storey that the chosen floor means is
+ /// marked, as that is the storey the wall, door, floor and stair tools work on.
+ ///
+ internal sealed partial class HousePanel : UserControl
+ {
+ private readonly Button[] _wallButtons;
+ private readonly Button[] _floorButtons;
+ private readonly Label[] _storeyLabels;
+ private readonly Font _boldFont;
+ private EditorSession _session;
+ private bool _updating;
+
+ public HousePanel()
+ {
+ InitializeComponent();
+ _wallButtons = new[] { _wall1, _wall2, _wall3, _wall4 };
+ _floorButtons = new[] { _floor1, _floor2, _floor3, _floor4 };
+ _storeyLabels = new[] { _storey1, _storey2, _storey3, _storey4 };
+ _boldFont = new Font(Font, FontStyle.Bold);
+ Disposed += (_, _) => _boldFont.Dispose();
+
+ for (int k = 0; k < HouseDraft.MaxStoreys; ++k)
+ {
+ int storey = k;
+ _wallButtons[k].Click += (_, _) => PickStyle?.Invoke(HousePartKind.Wall, storey);
+ _floorButtons[k].Click += (_, _) => PickStyle?.Invoke(HousePartKind.Floor, storey);
+ }
+
+ _roofStyle.Click += (_, _) => PickStyle?.Invoke(HousePartKind.Roof, 0);
+ }
+
+ /// Asks for a style to be picked on the House page for a storey's walls or floor, or for the roof.
+ public event Action PickStyle;
+
+ /// Raised after a button of the panel was used, so the canvas can take the keyboard back.
+ public event Action Used;
+
+ public void Bind(EditorSession session)
+ {
+ if (_session != null)
+ {
+ _session.DraftChanged -= RefreshDraft;
+ _session.ViewChanged -= RefreshDraft;
+ }
+
+ _session = session;
+ if (_session != null)
+ {
+ _session.DraftChanged += RefreshDraft;
+ _session.ViewChanged += RefreshDraft;
+ }
+
+ RefreshDraft();
+ }
+
+ /// Fills the panel from the session's house draft.
+ public void RefreshDraft()
+ {
+ HouseTool house = _session?.House;
+ Enabled = house != null;
+ if (house == null)
+ {
+ return;
+ }
+
+ _updating = true;
+ try
+ {
+ _wingList.BeginUpdate();
+ _wingList.Items.Clear();
+ for (int i = 0; i < house.Wings.Count; ++i)
+ {
+ RoofWing wing = house.Wings[i];
+ string roof = wing.NoRoof ? "no roof" : wing.Shape.ToString().ToLowerInvariant();
+ _wingList.Items.Add($"Wing {i + 1}: {wing.X1 - wing.X0 + 1} x {wing.Y1 - wing.Y0 + 1}, {wing.Storeys} storey{(wing.Storeys == 1 ? string.Empty : "s")}, {roof}");
+ }
+
+ _wingList.SelectedIndex = house.SelectedIndex;
+ _wingList.EndUpdate();
+
+ _storeys.Value = Math.Clamp(house.Storeys, 1, HouseDraft.MaxStoreys);
+ // The drop-down lists the roof shapes in their order, then None.
+ _roofShape.SelectedIndex = house.NoRoof ? _roofShape.Items.Count - 1 : (int)house.Shape;
+ _ridge.SelectedIndex = (int)house.Ridge;
+ _ridge.Enabled = !house.NoRoof;
+ _removeWing.Enabled = house.HasSelectedWing;
+ _wingHint.Text = house.HasSelectedWing ? "Selected wing:" : "New wings:";
+
+ int top = house.TopStorey;
+ int active = house.HasPending ? _session.DraftStorey : -1;
+ for (int k = 0; k < HouseDraft.MaxStoreys; ++k)
+ {
+ bool used = k < top || k < house.Storeys;
+ _storeyLabels[k].Visible = _wallButtons[k].Visible = _floorButtons[k].Visible = used;
+ _wallButtons[k].Text = house.Draft.WallStyles[k]?.Name ?? "(walls)";
+ _floorButtons[k].Text = house.Draft.FloorStyles[k]?.Name ?? "(floor)";
+
+ // The storey the chosen floor means: where the other tools work.
+ bool current = k == active;
+ _storeyLabels[k].Font = current ? _boldFont : Font;
+ _storeyLabels[k].BackColor = current ? Color.FromArgb(255, 214, 64) : Color.Transparent;
+ _storeyLabels[k].ForeColor = current ? Color.Black : ForeColor;
+ }
+
+ _roofStyle.Text = house.Draft.RoofStyle?.Name ?? "(roof)";
+ _foundation.Checked = house.Draft.Foundation;
+ _baseZ.Enabled = house.HasPending;
+ _baseZ.Value = Math.Clamp(house.BaseZ, (int)_baseZ.Minimum, (int)_baseZ.Maximum);
+
+ _undo.Enabled = house.CanUndoDraft;
+ _redo.Enabled = house.CanRedoDraft;
+ _place.Enabled = _drop.Enabled = house.HasPending;
+
+ if (!house.HasPending)
+ {
+ _status.Text = "Drag on the canvas to draw the first wing.";
+ }
+ else
+ {
+ int x0 = house.Wings.Min(w => w.X0), x1 = house.Wings.Max(w => w.X1);
+ int y0 = house.Wings.Min(w => w.Y0), y1 = house.Wings.Max(w => w.Y1);
+ _status.Text = $"{house.Wings.Count} wing{(house.Wings.Count == 1 ? string.Empty : "s")}, {x1 - x0 + 1} x {y1 - y0 + 1} cells, " +
+ $"{top} storey{(top == 1 ? string.Empty : "s")}. Not in the multi until placed.";
+ }
+ }
+ finally
+ {
+ _updating = false;
+ }
+ }
+
+ private void Run(Action action)
+ {
+ if (_updating || _session == null)
+ {
+ return;
+ }
+
+ action(_session.House);
+ Used?.Invoke();
+ }
+
+ private void WingList_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ if (!_updating && _session != null)
+ {
+ _session.House.SelectedIndex = _wingList.SelectedIndex;
+ }
+ }
+
+ private void Storeys_ValueChanged(object sender, EventArgs e)
+ {
+ if (!_updating && _session != null)
+ {
+ _session.House.SetStoreys((int)_storeys.Value);
+ }
+ }
+
+ private void RoofShape_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ int index = _roofShape.SelectedIndex;
+ bool none = index == _roofShape.Items.Count - 1;
+ Run(house => house.SetRoof(!none && Enum.IsDefined((RoofShape)index) ? (RoofShape)index : RoofShape.Gable, none));
+ }
+
+ private void Ridge_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ Run(house => house.SetRidge((RoofRidge)Math.Max(0, _ridge.SelectedIndex)));
+ }
+
+ private void RemoveWing_Click(object sender, EventArgs e)
+ {
+ Run(house => house.DeleteWing());
+ }
+
+ private void Foundation_CheckedChanged(object sender, EventArgs e)
+ {
+ Run(house => house.SetFoundation(_foundation.Checked));
+ }
+
+ private void BaseZ_ValueChanged(object sender, EventArgs e)
+ {
+ if (!_updating && _session != null)
+ {
+ _session.House.SetBaseZ((int)_baseZ.Value);
+ }
+ }
+
+ private void Undo_Click(object sender, EventArgs e)
+ {
+ Run(house => house.UndoDraft());
+ }
+
+ private void Redo_Click(object sender, EventArgs e)
+ {
+ Run(house => house.RedoDraft());
+ }
+
+ private void Place_Click(object sender, EventArgs e)
+ {
+ Run(house => house.Commit());
+ }
+
+ private void Drop_Click(object sender, EventArgs e)
+ {
+ Run(house => house.Discard());
+ }
+ }
+}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
index 1ace2356..7d0e3074 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
@@ -59,6 +59,16 @@ public MultiEditorControl()
InitializeComponent();
SplitterGrip.Attach(_sideSplit);
+ // The house draft's panel sits above the floors and selection; shown with the House tool or an open draft.
+ _housePanel = new HousePanel { Dock = DockStyle.Top, Visible = false };
+ _housePanel.PickStyle += PickHouseMaterial;
+ _housePanel.Used += () =>
+ {
+ _commands.RefreshStates();
+ _canvas.Focus();
+ };
+ _sideSplit.Panel2.Controls.Add(_housePanel);
+
// Room after each tab's text for its close button, at any DPI.
_docTabs.Padding = new Point((CloseGlyphSize + LogicalToDeviceUnits(16)) / 2, _docTabs.Padding.Y);
}
@@ -495,16 +505,16 @@ private void DefineCommands()
_closeAll = Command("File", "Close all designs", CloseAllDocuments, Keys.Control | Keys.Shift | Keys.W, hasDoc);
_undo = Command("Edit", "Undo", () => Session.Undo(), Keys.Control | Keys.Z,
- () => Session != null && Session.CompList.UndoList.Count > 0, glyph: Glyphs.Undo);
+ () => Session != null && Session.CanUndo, glyph: Glyphs.Undo);
_redo = Command("Edit", "Redo", () => Session.Redo(), Keys.Control | Keys.Y,
- () => Session != null && Session.CompList.RedoList.Count > 0, glyph: Glyphs.Redo, alt: Keys.Control | Keys.Shift | Keys.Z);
+ () => Session != null && Session.CanRedo, glyph: Glyphs.Redo, alt: Keys.Control | Keys.Shift | Keys.Z);
_cut = Command("Edit", "Cut", () => Session.Cut(), Keys.Control | Keys.X, hasSelection, glyph: Glyphs.Cut);
_copy = Command("Edit", "Copy", () => Session.Copy(), Keys.Control | Keys.C, hasSelection, glyph: Glyphs.Copy);
_paste = Command("Edit", "Paste", () => Session.Paste(), Keys.Control | Keys.V, hasDoc, glyph: Glyphs.Paste);
_duplicate = Command("Edit", "Duplicate selection", () => Session.Duplicate(), Keys.Control | Keys.D, hasSelection);
_repeat = Command("Edit", "Repeat selection...", RepeatSelectionPrompt, Keys.Control | Keys.Shift | Keys.D, hasSelection);
_delete = Command("Edit", "Delete selection", DeleteSelectionOrWing, Keys.Delete,
- () => Session != null && (Session.ShapingRoof ? Session.Roof.HasSelectedWing : Session.Selection.Count > 0), glyph: Glyphs.Delete);
+ () => Session != null && (Session.ShapingRoof ? Session.WingTool.HasSelectedWing : Session.Selection.Count > 0), glyph: Glyphs.Delete);
_selectAll = Command("Select", "Select all", () => Session.SelectAll(), Keys.Control | Keys.A, hasDoc);
_invert = Command("Select", "Invert selection", () => Session.InvertSelection(), Keys.Control | Keys.Shift | Keys.A, hasDoc);
@@ -575,6 +585,7 @@ private void DefineCommands()
AddTool(ToolKind.Stair, "Stairs", Keys.D4, Glyphs.Stair);
AddTool(ToolKind.Roof, "Roofs", Keys.D5, Glyphs.Roof);
AddTool(ToolKind.Foundation, "Foundation", Keys.D6, Glyphs.Foundation);
+ AddTool(ToolKind.House, "House", Keys.D7, Glyphs.Foundation);
AddTool(ToolKind.FloorPattern, "Floor pattern", Keys.None, Glyphs.Floor);
_cyclePlacement = Command("Tools", "Next placement mode", CyclePlacement, Keys.M, hasDoc);
@@ -599,8 +610,8 @@ private void DefineCommands()
hasDoc, () => Session?.BrushSize == size));
}
_escape = Command("Tools", "Cancel tool, then clear selection", Escape, Keys.Escape, hasDoc);
- _placeRoof = Command("Tools", "Place the roof being shaped", () => Session.Roof.Commit(), Keys.Enter,
- () => Session != null && Session.ShapingRoof);
+ _placeRoof = Command("Tools", "Place the roof or house being shaped", () => Session.DraftInFocus?.Commit(), Keys.Enter,
+ () => Session?.DraftInFocus != null);
_shortcuts = Command("Help", "Keyboard shortcuts", ShowShortcuts, Keys.F1, glyph: Glyphs.Help);
_drawWithSelected = Command("Tools", "Draw with this tile", DrawWithSelected, can: () => (_menuTile ?? Session?.SelectedTile) != null);
}
@@ -625,6 +636,12 @@ private void SetTool(ToolKind kind, bool fromHousePage = false)
Session.Tool = kind;
+ // The house draft is worked on in its panel, which sits in the floors and selection sidebar.
+ if (kind == ToolKind.House && !_inspectorShown)
+ {
+ ToggleSidebar(browser: false);
+ }
+
// A house tool builds with a style from the House page: bring that page up on the
// matching kind. The page answers by choosing the style, which comes back here.
if (IsHouseTool(kind) && !fromHousePage && !_openingHousePage && _browserShown)
@@ -658,6 +675,16 @@ private void ChooseHouseStyle(HouseStyle style)
return;
}
+ // A pick asked for by the house panel is a material of the draft, not a tool's style.
+ if (_housePick is { } pick && pick.Kind == style.Kind)
+ {
+ _housePick = null;
+ Session.House.SetMaterial(style, style.Kind == HousePartKind.Roof ? null : pick.Storey);
+ SetTool(ToolKind.House, fromHousePage: true);
+ return;
+ }
+
+ _housePick = null;
Session.HouseStyle = style;
ToolKind kind = style.Kind switch
{
@@ -670,6 +697,35 @@ private void ChooseHouseStyle(HouseStyle style)
SetTool(kind, fromHousePage: true);
}
+ /// The house panel asks for a style: the House page comes up on that kind and the next pick there goes to the draft.
+ private void PickHouseMaterial(HousePartKind kind, int storey)
+ {
+ if (Session == null)
+ {
+ return;
+ }
+
+ if (!_browserShown)
+ {
+ ToggleSidebar(browser: true);
+ }
+
+ _housePick = (kind, storey);
+ _openingHousePage = true;
+ try
+ {
+ _browser.ShowHousePage(kind, foundation: false);
+ }
+ finally
+ {
+ _openingHousePage = false;
+ }
+
+ _statusHint.Text = kind == HousePartKind.Roof
+ ? "Pick the roof style of the house on the House page."
+ : $"Pick the {(kind == HousePartKind.Wall ? "wall" : "floor")} style of storey {storey + 1} on the House page.";
+ }
+
private void CyclePlacement()
{
Session.Placement = (PlacementMode)(((int)Session.Placement + 1) % 3);
@@ -680,7 +736,7 @@ private void DeleteSelectionOrWing()
{
if (Session.ShapingRoof)
{
- Session.Roof.DeleteWing();
+ Session.WingTool.DeleteWing();
}
else
{
@@ -691,9 +747,9 @@ private void DeleteSelectionOrWing()
private void Escape()
{
// With a roof being shaped: the first Esc stops a drag, the next one drops the roof.
- if (Session.ShapingRoof && !Session.ActiveTool.IsDragging)
+ if (Session.DraftInFocus is { } draft && !Session.ActiveTool.IsDragging)
{
- Session.Roof.Discard();
+ draft.Discard();
return;
}
@@ -1355,8 +1411,22 @@ private void BuildOptionsStrip()
("Walls", () => Session.Roof.GableFill == RoofGableFill.Walls, () => Session.Roof.GableFill = RoofGableFill.Walls));
// Shown while a roof is being shaped.
- _placeRoofButton = RoofAction(strip, "Place roof", "Places the roof on the Roof layer (Enter).", () => Session.Roof.Commit());
- _dropRoofButton = RoofAction(strip, "Drop", "Drops the roof being shaped (Esc).", () => Session.Roof.Discard());
+ _placeRoofButton = RoofAction(strip, "Place", "Places what is being shaped: the roof on the Roof layer, the house on its layers (Enter).", () => Session.DraftInFocus?.Commit());
+ _dropRoofButton = RoofAction(strip, "Drop", "Drops what is being shaped (Esc). Undo brings it back.", () => Session.DraftInFocus?.Discard());
+ }
+
+ /// What the tool in use does to the open house draft.
+ private static string DraftHint(EditorSession session)
+ {
+ string storey = $"House draft, storey {session.DraftStorey + 1} (the floor buttons choose it): ";
+ return session.Tool switch
+ {
+ ToolKind.Wall => storey + "drag to add walls, Ctrl+drag to take walls away, click a wall for a window.",
+ ToolKind.Door => storey + "click a wall to hang the chosen door, again to turn it, Ctrl+click to take it out.",
+ ToolKind.Floor => storey + "drag an area to lay it in the chosen floor style.",
+ ToolKind.Stair => storey + "press on the bottom step and drag the way the stairs climb; Ctrl+click a bottom step removes them.",
+ _ => "A house draft is open. This tool works on the multi; House, Walls, Doors, Floors and Stairs work on the draft."
+ };
}
private void ZStepCombo_SelectedIndexChanged(object sender, EventArgs e)
@@ -1364,6 +1434,8 @@ private void ZStepCombo_SelectedIndexChanged(object sender, EventArgs e)
Apply(() => Session.ZStep = int.Parse(_zStepCombo.Text));
}
+ private readonly HousePanel _housePanel;
+ private (HousePartKind Kind, int Storey)? _housePick;
private EditorCommand _placeRoof;
private ToolStripButton _placeRoofButton;
private ToolStripButton _dropRoofButton;
@@ -1419,7 +1491,7 @@ private ToolStripButton RoofAction(ToolStrip strip, string text, string tip, Act
};
button.Click += (_, _) =>
{
- if (Session != null && Session.ShapingRoof)
+ if (Session?.DraftInFocus != null)
{
run();
_commands.RefreshStates();
@@ -1438,7 +1510,13 @@ private void SyncRoofOptions()
item.Visible = show;
}
- _placeRoofButton.Visible = _dropRoofButton.Visible = show && Session.ShapingRoof;
+ _placeRoofButton.Visible = _dropRoofButton.Visible = Session != null && !Session.Pasting && Session.DraftInFocus != null;
+
+ bool house = Session != null && (Session.Tool == ToolKind.House || Session.House.HasPending);
+ if (_housePanel.Visible != house)
+ {
+ _housePanel.Visible = house;
+ }
foreach ((ToolStripButton button, Func isOn) in _roofButtons)
{
@@ -1479,7 +1557,7 @@ void Section(ToolStripLabel title, params ToolKind[] kinds)
Section(_editToolsLabel, ToolKind.Select, ToolKind.Lasso, ToolKind.Altitude, ToolKind.Pipette, ToolKind.Transparent, ToolKind.Remove);
Section(_drawToolsLabel, ToolKind.Draw, ToolKind.RectFill, ToolKind.Line);
- Section(_houseToolsLabel, ToolKind.Wall, ToolKind.Floor, ToolKind.Door, ToolKind.Stair, ToolKind.Roof, ToolKind.Foundation);
+ Section(_houseToolsLabel, ToolKind.Wall, ToolKind.Floor, ToolKind.Door, ToolKind.Stair, ToolKind.Roof, ToolKind.Foundation, ToolKind.House);
}
// ---------------------------------------------------------------- documents
@@ -1627,6 +1705,11 @@ private void ShowDocument(EditorDocument document)
private void SaveToClient()
{
+ if (!SettleOpenDraft())
+ {
+ return;
+ }
+
if (AskIncludeHiddenLayers("Leaves them out of the client's multi. They stay in the editor's layers and come back when you open it here.") is not { } includeHidden)
{
return;
@@ -1656,6 +1739,11 @@ private void SaveToClient()
private void ExportFile()
{
+ if (!SettleOpenDraft())
+ {
+ return;
+ }
+
if (AskIncludeHiddenLayers("Leaves them out of the file. Exported files do not keep layers.") is not { } includeHidden)
{
return;
@@ -1671,6 +1759,37 @@ private void ExportFile()
/// Before a save: asks whether tiles on hidden layers go into it. True without asking when
/// no hidden layer has tiles; null when the save is cancelled.
///
+ ///
+ /// Before a save: a roof or house still being shaped is not in the multi. Asks whether to
+ /// place it first. False when the save was cancelled.
+ ///
+ private bool SettleOpenDraft()
+ {
+ WingDraftTool draft = Session.House.HasPending ? Session.House : Session.Roof.HasPending ? Session.Roof : null;
+ if (draft == null)
+ {
+ return true;
+ }
+
+ string what = draft is HouseTool ? "house" : "roof";
+ DialogResult answer = MessageBox.Show(this,
+ $"The {what} being shaped is not placed yet, so it is not part of the multi.\r\n\r\nPlace it before saving?\r\n\r\n" +
+ "Yes places it. No saves without it and keeps it open.",
+ "Multi Editor", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
+ if (answer == DialogResult.Cancel)
+ {
+ return false;
+ }
+
+ if (answer == DialogResult.Yes)
+ {
+ draft.Commit();
+ _commands.RefreshStates();
+ }
+
+ return true;
+ }
+
private bool? AskIncludeHiddenLayers(string whenLeftOut)
{
MultiEditorComponentList list = Session.CompList;
@@ -1742,6 +1861,11 @@ private void OpenDesignFile()
///
private void SaveDesignFile(bool saveAs)
{
+ if (!SettleOpenDraft())
+ {
+ return;
+ }
+
string path = _active.FilePath;
if (saveAs || path == null)
{
@@ -2032,6 +2156,7 @@ private void Activate(int index)
{
_canvas.Show(null, null);
_inspector.Bind(null);
+ _housePanel.Bind(null);
}
else
{
@@ -2048,6 +2173,7 @@ private void Activate(int index)
_canvas.Show(session, document.Camera);
_inspector.Bind(session);
+ _housePanel.Bind(session);
if (session.DrawTileId != 0)
{
_browser.SetCurrentTile(session.DrawTileId);
@@ -2237,8 +2363,9 @@ private void UpdateStatus()
_statusHint.Text = session.PreviewMode ? "Preview: editing is off. Right click picks the ground. F5 returns to the editor."
: session.PreviewingRepeat ? "The copies are shown as they would be placed."
: session.Pasting ? "Click to place the tiles, as often as you like. Esc or right click stops."
- : session.ShapingRoof ? "Shaping the roof: drag a wing to move it, an edge of the selected wing to resize it, anywhere else to add a wing. " +
- "Shift+click turns a ridge, Delete removes a wing. Enter places the roof on the Roof layer, Esc drops it."
+ : session.ShapingRoof ? "Shaping: drag a wing to move it, a marked edge of the selected wing to resize it, anywhere else to add a wing. " +
+ "Shift+click turns a ridge, Delete removes a wing, Ctrl+Z steps back. Enter places it, Esc drops it."
+ : session.House.HasPending ? DraftHint(session)
: ToolHint(session.Tool);
(int x, int y, int z) = session.CursorCell;
@@ -2274,6 +2401,7 @@ private static string ToolHint(ToolKind kind)
ToolKind.Stair => "Drag in the direction the stairs climb.",
ToolKind.Roof => "Click a walled room to start its roof, or drag out a roof of any size. It stays open for shaping until Enter places it.",
ToolKind.Foundation => "Drag an area to lay a foundation under it.",
+ ToolKind.House => "Drag out the wall cells of a wing to start a house. Storeys, roof and materials are in the House panel; nothing is placed until Enter.",
ToolKind.FloorPattern => "Drag an area to lay the bordered floor: corners, sides and fill repeat to fit.",
_ => string.Empty
};
diff --git a/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs b/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs
index 25f2943c..bb82b089 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs
@@ -72,7 +72,15 @@ public void ShowCommands(IEnumerable commands)
("Turn a wing's ridge (Roof)", "Shift + click the wing"),
("Remove the selected wing (Roof)", "Delete"),
("Place the roof on the Roof layer (Roof)", "Enter, or pick another tool"),
- ("Drop the roof being shaped (Roof)", "Esc"));
+ ("Drop the roof being shaped (Roof)", "Esc"),
+ ("Add a wing to the house draft (House)", "Drag out its wall cells"),
+ ("Select, move, resize, turn or remove a wing (House)", "As with the roof's wings"),
+ ("Step back and forth through the draft (Roof, House)", "Ctrl+Z / Ctrl+Y"),
+ ("Partitions and openings in the house draft (Walls)", "Drag / Ctrl + drag"),
+ ("Window in a wall of the house draft (Walls)", "Click the wall"),
+ ("Door in the house draft (Doors)", "Click a wall; Ctrl + click removes"),
+ ("Place the house on its layers (House and its draft tools)", "Enter"),
+ ("Drop the house draft; undo brings it back (House)", "Esc"));
Section("Tile browser",
("Go from the search box to the results", "Down"),
diff --git a/UoFiddler.Plugin.MultiEditor/UoFiddler.Plugin.MultiEditor.csproj b/UoFiddler.Plugin.MultiEditor/UoFiddler.Plugin.MultiEditor.csproj
index 0484dc45..f2f388ee 100644
--- a/UoFiddler.Plugin.MultiEditor/UoFiddler.Plugin.MultiEditor.csproj
+++ b/UoFiddler.Plugin.MultiEditor/UoFiddler.Plugin.MultiEditor.csproj
@@ -83,6 +83,12 @@
FloorsDialog.cs
+
+ UserControl
+
+
+ HousePanel.cs
+
UserControl
From 754a0d335adacf0171d1b147c67f3af3d36409e9 Mon Sep 17 00:00:00 2001
From: AsY!um- <377468+AsYlum-@users.noreply.github.com>
Date: Tue, 17 Nov 2026 23:52:33 +0100
Subject: [PATCH 03/16] Let shortcut keys be typed while a layer is renamed
---
.../UI/MultiEditorControl.cs | 25 ++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
index 7d0e3074..2d571e83 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
@@ -2467,7 +2467,30 @@ private bool IsTextInputFocused()
}
return focused is TextBoxBase || focused is NumericUpDown || focused is ComboBox ||
- focused.Parent is NumericUpDown || focused is ToolStrip;
+ focused.Parent is NumericUpDown || focused is ToolStrip || NativeEditHasFocus();
}
+
+ ///
+ /// True while a plain Windows edit box has the keyboard: the box a list or tree shows to
+ /// rename an item (a layer's name) is one, and it is no WinForms control, so the
+ /// focused control is still the list.
+ ///
+ private static bool NativeEditHasFocus()
+ {
+ IntPtr focus = GetFocus();
+ if (focus == IntPtr.Zero)
+ {
+ return false;
+ }
+
+ var name = new System.Text.StringBuilder(32);
+ return GetClassName(focus, name, name.Capacity) > 0 && name.ToString().Equals("Edit", StringComparison.OrdinalIgnoreCase);
+ }
+
+ [System.Runtime.InteropServices.DllImport("user32.dll")]
+ private static extern IntPtr GetFocus();
+
+ [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
+ private static extern int GetClassName(IntPtr hWnd, System.Text.StringBuilder className, int maxCount);
}
}
From 99975247fb907b20a8143b0835b330a037f82174 Mon Sep 17 00:00:00 2001
From: AsY!um- <377468+AsYlum-@users.noreply.github.com>
Date: Wed, 18 Nov 2026 00:39:25 +0100
Subject: [PATCH 04/16] Add hip roofs, rooms, house files and a house tab
Placed houses reopen as drafts; the preview can hide walls, floors or roof; preview opacity setting.
---
.../Classes/DesignFile.cs | 14 +-
.../Classes/HouseDraft.cs | 127 +++++++++
.../Classes/HouseDraftFile.cs | 244 ++++++++++++++++++
.../Classes/LayerStore.cs | 12 +-
.../Classes/RoofPlanner.cs | 57 +++-
.../Editing/EditorSession.Commands.cs | 3 +-
.../Editing/EditorSession.cs | 109 ++++++++
.../Rendering/SceneRenderer.cs | 4 +-
.../Tools/HouseTool.cs | 227 +++++++++++++++-
.../Tools/RoofTool.cs | 20 +-
.../Tools/WingDraftTool.cs | 44 +++-
.../UI/EditorSettings.cs | 10 +
.../UI/EditorSettingsDialog.Designer.cs | 71 ++++-
.../UI/EditorSettingsDialog.cs | 14 +
.../UI/HousePanel.Designer.cs | 199 ++++++++++++--
UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs | 90 ++++++-
.../UI/MultiEditorControl.Designer.cs | 2 +-
.../UI/MultiEditorControl.cs | 203 +++++++++++++--
18 files changed, 1381 insertions(+), 69 deletions(-)
create mode 100644 UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/DesignFile.cs b/UoFiddler.Plugin.MultiEditor/Classes/DesignFile.cs
index 12bcb59b..aad0effa 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/DesignFile.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/DesignFile.cs
@@ -29,8 +29,9 @@ namespace UoFiddler.Plugin.MultiEditor.Classes
/// The floors when they were set by hand, else null.
/// The layers, bottom first, each with all its tiles by cell.
/// Index of the active layer.
+ /// The houses placed with the House tool, each as a house draft, so they can be opened as drafts again; or null.
internal sealed record DesignData(string Name, int Width, int Height, int FirstFloorZ,
- List Levels, List Layers, int ActiveLayer);
+ List Levels, List Layers, int ActiveLayer, List Houses = null);
///
/// The editor's own design file (*.uomd): XML with the size, the floors and one element per
@@ -79,6 +80,14 @@ public static void Save(string path, DesignData design)
}
root.Add(layers);
+
+ // Read by this editor from the first format version on: an editor that does not know
+ // the element skips it, so it needs no new version.
+ if (design.Houses is { Count: > 0 })
+ {
+ root.Add(new XElement("Houses", design.Houses.Select(h => new XElement(h))));
+ }
+
new XDocument(root).Save(path);
}
@@ -131,7 +140,8 @@ public static DesignData Load(string path)
return new DesignData((string)root.Attribute("name") ?? string.Empty, width, height,
(int?)root.Attribute("firstFloorZ") ?? 0, levels is { Count: > 0 } ? levels : null,
- layers, (int?)layersElement?.Attribute("active") ?? 0);
+ layers, (int?)layersElement?.Attribute("active") ?? 0,
+ root.Element("Houses")?.Elements("House").Select(h => new XElement(h)).ToList());
}
catch (Exception ex) when (ex is XmlException or FormatException or OverflowException or IndexOutOfRangeException or ArgumentNullException)
{
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
index 59bec0c6..1ddff348 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
@@ -46,6 +46,9 @@ internal sealed class HouseDraft
public bool Foundation { get; set; }
+ /// Most rooms a wing can be divided into.
+ public const int MaxRooms = 6;
+
// Wall edges added and taken away by hand, per storey: cells with a wall on their +Y edge
// (south) and on their +X edge (east).
public HashSet<(int X, int Y)>[] AddedSouth { get; } = Sets();
@@ -184,6 +187,7 @@ public void Edges(IReadOnlyList wings, int storey, out HashSet<(int X,
south = new HashSet<(int X, int Y)>();
east = new HashSet<(int X, int Y)>();
Outline(region, south, east);
+ Partitions(wings, storey, south, east);
foreach ((int x, int y) in AddedSouth[storey])
{
if (region.Contains((x, y)) || region.Contains((x, y + 1)))
@@ -204,6 +208,103 @@ public void Edges(IReadOnlyList wings, int storey, out HashSet<(int X,
east.ExceptWith(ErasedEast[storey]);
}
+ ///
+ /// The walls that divide each wing of a storey into its rooms ():
+ /// across the wing's longer side, evenly spaced, with the middle cell of each left open as
+ /// a doorway. A wing too short for that many rooms gets as many as fit two cells each.
+ ///
+ private static void Partitions(IReadOnlyList wings, int storey, HashSet<(int X, int Y)> south, HashSet<(int X, int Y)> east)
+ {
+ foreach (RoofWing wing in wings)
+ {
+ int width = wing.X1 - wing.X0, depth = wing.Y1 - wing.Y0;
+ bool alongX = width >= depth;
+ int length = alongX ? width : depth;
+ int rooms = Math.Min(Math.Clamp(wing.Rooms, 1, MaxRooms), length / 2);
+ if (wing.Storeys <= storey || rooms < 2)
+ {
+ continue;
+ }
+
+ for (int i = 1; i < rooms; ++i)
+ {
+ int at = (int)Math.Round(i * length / (double)rooms);
+ if (alongX)
+ {
+ int doorway = wing.Y0 + 1 + ((depth - 1) / 2);
+ for (int y = wing.Y0 + 1; y <= wing.Y1; ++y)
+ {
+ if (y != doorway)
+ {
+ east.Add((wing.X0 + at, y));
+ }
+ }
+ }
+ else
+ {
+ int doorway = wing.X0 + 1 + ((width - 1) / 2);
+ for (int x = wing.X0 + 1; x <= wing.X1; ++x)
+ {
+ if (x != doorway)
+ {
+ south.Add((x, wing.Y0 + at));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /// Moves everything changed by hand along with the house.
+ public void Shift(int dx, int dy)
+ {
+ static void Move(HashSet<(int X, int Y)> set, int dx, int dy)
+ {
+ var moved = new List<(int X, int Y)>(set.Count);
+ foreach ((int x, int y) in set)
+ {
+ moved.Add((x + dx, y + dy));
+ }
+
+ set.Clear();
+ set.UnionWith(moved);
+ }
+
+ for (int k = 0; k < MaxStoreys; ++k)
+ {
+ Move(AddedSouth[k], dx, dy);
+ Move(AddedEast[k], dx, dy);
+ Move(ErasedSouth[k], dx, dy);
+ Move(ErasedEast[k], dx, dy);
+ }
+
+ var doors = new List>(Doors);
+ Doors.Clear();
+ foreach (var door in doors)
+ {
+ Doors[(door.Key.Storey, door.Key.X + dx, door.Key.Y + dy)] = door.Value;
+ }
+
+ var windows = new List<(int Storey, int X, int Y)>(Windows);
+ Windows.Clear();
+ foreach ((int storey, int x, int y) in windows)
+ {
+ Windows.Add((storey, x + dx, y + dy));
+ }
+
+ for (int i = 0; i < FloorAreas.Count; ++i)
+ {
+ var a = FloorAreas[i];
+ FloorAreas[i] = (a.Storey, a.X0 + dx, a.Y0 + dy, a.X1 + dx, a.Y1 + dy, a.Style);
+ }
+
+ for (int i = 0; i < Stairs.Count; ++i)
+ {
+ var s = Stairs[i];
+ Stairs[i] = (s.Storey, s.X + dx, s.Y + dy, s.Column, s.Style);
+ }
+ }
+
/// The tiles of a built draft, each with its layer, and the walls among them.
public sealed class Built
{
@@ -323,6 +424,32 @@ public Built Build(IReadOnlyList wings, HouseStyles styles)
}
}
+ // Flat roofs: the floor of the wing's top storey once more, on top of its walls. Where a
+ // taller wing stands, its own floor is there already.
+ foreach (RoofWing wing in wings)
+ {
+ int storeys = Math.Clamp(wing.Storeys, 1, MaxStoreys);
+ HouseStyle style = FloorStyles[storeys - 1];
+ if (wing.NoRoof || wing.Shape != RoofShape.Flat || style == null)
+ {
+ continue;
+ }
+
+ HashSet<(int X, int Y)> above = Region(wings, storeys);
+ ushort[] pieces = Pieces(style);
+ for (int x = wing.X0 + 1; pieces.Length > 0 && x <= wing.X1; ++x)
+ {
+ for (int y = wing.Y0 + 1; y <= wing.Y1; ++y)
+ {
+ if (!above.Contains((x, y)))
+ {
+ built.Tiles.Add((pieces[(int)((uint)HashCode.Combine(x, y, storeys) % (uint)pieces.Length)], x, y,
+ BaseZ + (storeys * StoreyHeight), RoofTool.LayerName));
+ }
+ }
+ }
+ }
+
return built;
}
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs
new file mode 100644
index 00000000..2d3f0896
--- /dev/null
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs
@@ -0,0 +1,244 @@
+/***************************************************************************
+ *
+ * $Author: Turley
+ *
+ * "THE BEER-WARE LICENSE"
+ * As long as you retain this notice you can do whatever you want with
+ * this stuff. If we meet some day, and you think this stuff is worth it,
+ * you can buy me a beer in return.
+ *
+ ***************************************************************************/
+
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Xml;
+using System.Xml.Linq;
+using UoFiddler.Plugin.MultiEditor.Tools;
+
+namespace UoFiddler.Plugin.MultiEditor.Classes
+{
+ ///
+ /// A house draft as XML: one House element with its wings, the materials of each storey
+ /// and everything changed by hand. It is what a house draft file (*.uohouse) holds, and what
+ /// a design file and the layers file keep of each house placed in a multi, so the house can
+ /// be opened as a draft again. Styles are kept by kind and name, as the client's tables name
+ /// them; one the client no longer has is left to the draft's defaults.
+ ///
+ internal static class HouseDraftFile
+ {
+ public const string Extension = "uohouse";
+
+ public const string Filter = "House draft (*.uohouse)|*.uohouse|All files (*.*)|*.*";
+
+ private const string _root = "House";
+
+ /// Format version of the element: raise it when an older editor would misread the content.
+ private const int _version = 1;
+
+ public static XElement ToXml(IReadOnlyList wings, HouseDraft draft, string name)
+ {
+ var root = new XElement(_root,
+ new XAttribute("version", _version),
+ new XAttribute("name", LayerStore.XmlSafe(name ?? string.Empty, "House")),
+ new XAttribute("baseZ", wings.Count > 0 ? wings[0].EaveZ : draft.BaseZ),
+ new XAttribute("foundation", draft.Foundation));
+ if (draft.RoofStyle != null)
+ {
+ root.Add(new XAttribute("roof", draft.RoofStyle.Name));
+ }
+
+ foreach (RoofWing wing in wings)
+ {
+ root.Add(new XElement("Wing",
+ new XAttribute("x0", wing.X0), new XAttribute("y0", wing.Y0), new XAttribute("x1", wing.X1), new XAttribute("y1", wing.Y1),
+ new XAttribute("storeys", wing.Storeys),
+ new XAttribute("rooms", wing.Rooms),
+ new XAttribute("roof", wing.NoRoof ? "None" : wing.Shape.ToString()),
+ new XAttribute("ridge", wing.RidgeAuto ? "Auto" : wing.RidgeAlongY ? "Y" : "X")));
+ }
+
+ for (int k = 0; k < HouseDraft.MaxStoreys; ++k)
+ {
+ var storey = new XElement("Storey", new XAttribute("index", k));
+ if (draft.WallStyles[k] != null)
+ {
+ storey.Add(new XAttribute("walls", draft.WallStyles[k].Name));
+ }
+
+ if (draft.FloorStyles[k] != null)
+ {
+ storey.Add(new XAttribute("floor", draft.FloorStyles[k].Name));
+ }
+
+ AddCells(storey, "addedSouth", draft.AddedSouth[k]);
+ AddCells(storey, "addedEast", draft.AddedEast[k]);
+ AddCells(storey, "erasedSouth", draft.ErasedSouth[k]);
+ AddCells(storey, "erasedEast", draft.ErasedEast[k]);
+ AddCells(storey, "windows", draft.Windows.Where(w => w.Storey == k).Select(w => (w.X, w.Y)));
+ root.Add(storey);
+ }
+
+ foreach (var door in draft.Doors)
+ {
+ root.Add(new XElement("Door", new XAttribute("storey", door.Key.Storey), new XAttribute("x", door.Key.X), new XAttribute("y", door.Key.Y),
+ new XAttribute("style", door.Value.Style.Name), new XAttribute("piece", door.Value.Piece)));
+ }
+
+ foreach ((int storey, int x0, int y0, int x1, int y1, HouseStyle style) in draft.FloorAreas)
+ {
+ root.Add(new XElement("FloorArea", new XAttribute("storey", storey), new XAttribute("x0", x0), new XAttribute("y0", y0),
+ new XAttribute("x1", x1), new XAttribute("y1", y1), new XAttribute("style", style.Name)));
+ }
+
+ foreach ((int storey, int x, int y, string column, HouseStyle style) in draft.Stairs)
+ {
+ root.Add(new XElement("Stairs", new XAttribute("storey", storey), new XAttribute("x", x), new XAttribute("y", y),
+ new XAttribute("column", column), new XAttribute("style", style.Name)));
+ }
+
+ return root;
+ }
+
+ private static void AddCells(XElement element, string name, IEnumerable<(int X, int Y)> cells)
+ {
+ string text = string.Join(" ", cells.Select(c => $"{c.X.ToString(CultureInfo.InvariantCulture)},{c.Y.ToString(CultureInfo.InvariantCulture)}"));
+ if (text.Length > 0)
+ {
+ element.Add(new XAttribute(name, text));
+ }
+ }
+
+ private static IEnumerable<(int X, int Y)> Cells(XElement element, string name)
+ {
+ foreach (string cell in ((string)element.Attribute(name) ?? string.Empty).Split(' ', StringSplitOptions.RemoveEmptyEntries))
+ {
+ string[] parts = cell.Split(',');
+ yield return (int.Parse(parts[0], CultureInfo.InvariantCulture), int.Parse(parts[1], CultureInfo.InvariantCulture));
+ }
+ }
+
+ ///
+ /// Reads a house back. gives the styles for anything the
+ /// element does not name or the client no longer has. Throws
+ /// when the element is not a house or is damaged.
+ ///
+ public static (List Wings, HouseDraft Draft, string Name) FromXml(XElement root, HouseStyles styles, HouseDraft materials)
+ {
+ try
+ {
+ if (root == null || root.Name.LocalName != _root)
+ {
+ throw new InvalidDataException("This is not a house draft.");
+ }
+
+ if (((int?)root.Attribute("version") ?? 0) > _version)
+ {
+ throw new InvalidDataException("This house draft was saved by a newer multi editor.");
+ }
+
+ HouseStyle Style(HousePartKind kind, string name) =>
+ name == null ? null : styles.Styles.FirstOrDefault(s => s.Kind == kind && string.Equals(s.Name, name, StringComparison.Ordinal));
+
+ HouseDraft draft = materials.Fresh();
+ int baseZ = (int?)root.Attribute("baseZ") ?? 0;
+ draft.BaseZ = baseZ;
+ draft.Foundation = (bool?)root.Attribute("foundation") ?? false;
+ // A draft saved before rooms were set per wing names one count for the house.
+ int houseRooms = (int?)root.Attribute("rooms") ?? 1;
+ draft.RoofStyle = Style(HousePartKind.Roof, (string)root.Attribute("roof")) ?? draft.RoofStyle;
+
+ var wings = new List();
+ foreach (XElement element in root.Elements("Wing"))
+ {
+ string roof = (string)element.Attribute("roof") ?? "Gable";
+ string ridge = (string)element.Attribute("ridge") ?? "Auto";
+ var wing = new RoofWing
+ {
+ X0 = (int)element.Attribute("x0"), Y0 = (int)element.Attribute("y0"),
+ X1 = (int)element.Attribute("x1"), Y1 = (int)element.Attribute("y1"),
+ EaveZ = baseZ,
+ Storeys = Math.Clamp((int?)element.Attribute("storeys") ?? 1, 1, HouseDraft.MaxStoreys),
+ Rooms = Math.Clamp((int?)element.Attribute("rooms") ?? houseRooms, 1, HouseDraft.MaxRooms),
+ NoRoof = roof == "None",
+ Shape = Enum.TryParse(roof, out RoofShape shape) ? shape : RoofShape.Gable,
+ RidgeAuto = ridge == "Auto"
+ };
+ wing.RidgeAlongY = wing.RidgeAuto
+ ? RoofPlanner.RidgeAlongY((wing.X0 + 1, wing.Y0 + 1, wing.X1 + 1, wing.Y1 + 1))
+ : ridge == "Y";
+ if (wing.X1 - wing.X0 >= 2 && wing.Y1 - wing.Y0 >= 2)
+ {
+ wings.Add(wing);
+ }
+ }
+
+ foreach (XElement element in root.Elements("Storey"))
+ {
+ int k = (int?)element.Attribute("index") ?? -1;
+ if (k < 0 || k >= HouseDraft.MaxStoreys)
+ {
+ continue;
+ }
+
+ draft.WallStyles[k] = Style(HousePartKind.Wall, (string)element.Attribute("walls")) ?? draft.WallStyles[k];
+ draft.FloorStyles[k] = Style(HousePartKind.Floor, (string)element.Attribute("floor")) ?? draft.FloorStyles[k];
+ draft.AddedSouth[k].UnionWith(Cells(element, "addedSouth"));
+ draft.AddedEast[k].UnionWith(Cells(element, "addedEast"));
+ draft.ErasedSouth[k].UnionWith(Cells(element, "erasedSouth"));
+ draft.ErasedEast[k].UnionWith(Cells(element, "erasedEast"));
+ foreach ((int x, int y) in Cells(element, "windows"))
+ {
+ draft.Windows.Add((k, x, y));
+ }
+ }
+
+ foreach (XElement element in root.Elements("Door"))
+ {
+ if (Style(HousePartKind.Door, (string)element.Attribute("style")) is { } style && (string)element.Attribute("piece") is { } piece)
+ {
+ draft.Doors[((int)element.Attribute("storey"), (int)element.Attribute("x"), (int)element.Attribute("y"))] = (style, piece);
+ }
+ }
+
+ foreach (XElement element in root.Elements("FloorArea"))
+ {
+ if (Style(HousePartKind.Floor, (string)element.Attribute("style")) is { } style)
+ {
+ draft.FloorAreas.Add(((int)element.Attribute("storey"), (int)element.Attribute("x0"), (int)element.Attribute("y0"),
+ (int)element.Attribute("x1"), (int)element.Attribute("y1"), style));
+ }
+ }
+
+ foreach (XElement element in root.Elements("Stairs"))
+ {
+ if (Style(HousePartKind.Stair, (string)element.Attribute("style")) is { } style && (string)element.Attribute("column") is { } column)
+ {
+ draft.Stairs.Add(((int)element.Attribute("storey"), (int)element.Attribute("x"), (int)element.Attribute("y"), column, style));
+ }
+ }
+
+ return (wings, draft, (string)root.Attribute("name") ?? "House");
+ }
+ catch (Exception ex) when (ex is XmlException or FormatException or OverflowException or IndexOutOfRangeException or ArgumentNullException)
+ {
+ throw new InvalidDataException("The house draft is damaged: " + ex.Message, ex);
+ }
+ }
+
+ /// The same house moved by a number of cells.
+ public static XElement Shifted(XElement house, int dx, int dy, HouseStyles styles)
+ {
+ var (wings, draft, name) = FromXml(house, styles, new HouseDraft());
+ foreach (RoofWing wing in wings)
+ {
+ (wing.X0, wing.X1, wing.Y0, wing.Y1) = (wing.X0 + dx, wing.X1 + dx, wing.Y0 + dy, wing.Y1 + dy);
+ }
+
+ draft.Shift(dx, dy);
+ return ToXml(wings, draft, name);
+ }
+ }
+}
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/LayerStore.cs b/UoFiddler.Plugin.MultiEditor/Classes/LayerStore.cs
index 126f0d43..0fc322de 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/LayerStore.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/LayerStore.cs
@@ -46,7 +46,8 @@ public static string FilePath(int clientId)
/// Keeps the layers of a multi saved to the client. A design with only the one plain layer
/// every design starts with has nothing to keep, and an older set for the same tiles goes.
///
- public static void Save(int clientId, List layers, int activeIndex, long fingerprint)
+ /// The houses placed with the House tool, as house drafts with cells counted from the save origin.
+ public static void Save(int clientId, List layers, int activeIndex, long fingerprint, IReadOnlyList houses = null)
{
string path = FilePath(clientId);
string multi = fingerprint.ToString(CultureInfo.InvariantCulture);
@@ -66,6 +67,11 @@ public static void Save(int clientId, List layers, int activeIndex,
TilesText(layer.Tiles)));
}
+ foreach (XElement house in houses ?? Array.Empty())
+ {
+ set.Add(new XElement(house));
+ }
+
sets.Insert(0, set);
}
@@ -87,7 +93,7 @@ public static void Save(int clientId, List layers, int activeIndex,
/// Reads the layers kept for a client multi with these tiles. Null when there are none or
/// the file cannot be read.
///
- public static (List Layers, int Active)? Load(int clientId, long fingerprint)
+ public static (List Layers, int Active, List Houses)? Load(int clientId, long fingerprint)
{
try
{
@@ -105,7 +111,7 @@ public static (List Layers, int Active)? Load(int clientId, long fin
(bool?)element.Attribute("visible") ?? true, (bool?)element.Attribute("inFile") ?? true, ParseTiles(element.Value)));
}
- return layers.Count == 0 ? null : (layers, (int?)set.Attribute("active") ?? 0);
+ return layers.Count == 0 ? null : (layers, (int?)set.Attribute("active") ?? 0, set.Elements("House").Select(h => new XElement(h)).ToList());
}
catch (Exception ex) when (ex is FormatException or IndexOutOfRangeException or OverflowException)
{
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/RoofPlanner.cs b/UoFiddler.Plugin.MultiEditor/Classes/RoofPlanner.cs
index 09c44867..92e74e12 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/RoofPlanner.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/RoofPlanner.cs
@@ -18,7 +18,16 @@ namespace UoFiddler.Plugin.MultiEditor.Classes
internal enum RoofShape
{
/// Two slopes meeting in a ridge.
- Gable
+ Gable,
+
+ /// Four slopes: the ends slope too, instead of standing as gables.
+ Hip,
+
+ ///
+ /// No slopes: a floor on top of the walls, as the towers have. Only a house wing can have
+ /// it; the house draft lays it, not this planner.
+ ///
+ Flat
}
///
@@ -34,6 +43,11 @@ internal enum RoofShape
/// south NDent;
/// - where a wing's ridge runs into another ridge of the same height the cell is the T
/// piece named for the side the wing comes from, and the X piece where two ridges cross.
+ /// - roof.txt has no pieces made for hips. The Dent pieces serve: each is a tile of two
+ /// faces, and on a hip line the one with the same two faces closes the corner when it sits 3
+ /// lower than the slopes beside it (the south-east one at their height). Found by drawing
+ /// every piece at every corner; it closes cleanly in thatch, stone, slate and shingles and
+ /// leaves small seams in Tile Roof.
///
///
internal static class RoofPlanner
@@ -41,6 +55,15 @@ internal static class RoofPlanner
/// Z a slope gains per cell: the roof pieces are 3 high.
public const int Rise = 3;
+ /// Marks a fixed piece that sits lower than its cell's height: "EDent@-3".
+ public const char LiftMark = '@';
+
+ // The corner pieces of a hip, by the corner of the wing they lie towards.
+ private const string _hipNorthWest = "NDent@-3";
+ private const string _hipNorthEast = "EDent@-3";
+ private const string _hipSouthEast = "SDent";
+ private const string _hipSouthWest = "WDent@-3";
+
/// Narrowest part of a house that gets a wing of its own.
private const int _minWing = 3;
@@ -56,9 +79,9 @@ public static bool RidgeAlongY((int X0, int Y0, int X1, int Y1) box)
///
/// Adds a wing to a roof: every cell of the box gets the wing's height there unless the
- /// roof is already higher. A gable climbs from its two long sides to the ridge. A cell it
- /// raises loses any fixed piece another wing gave it in .
- /// Cells with a negative coordinate are left out.
+ /// roof is already higher. A gable climbs from its two long sides to the ridge. A hip
+ /// climbs from all four sides; the cells on its hip lines get their corner piece in
+ /// . Cells with a negative coordinate are left out.
///
public static void AddWing(Dictionary<(int X, int Y), int> heights, Dictionary<(int X, int Y), string> fixedPieces,
(int X0, int Y0, int X1, int Y1) box, bool ridgeAlongY, RoofShape shape, int eaveZ)
@@ -71,6 +94,23 @@ public static void AddWing(Dictionary<(int X, int Y), int> heights, Dictionary<(
{
int a = ridgeAlongY ? x : y;
int steps = Math.Min(a - across0, across1 - a);
+ string corner = null;
+ if (shape == RoofShape.Hip)
+ {
+ int west = x - box.X0, east = box.X1 - x, north = y - box.Y0, south = box.Y1 - y;
+ steps = Math.Min(Math.Min(west, east), Math.Min(north, south));
+
+ // On a hip line two sides are equally near; on the ridge the opposite ones are.
+ if (west != east && north != south)
+ {
+ corner = west == steps && north == steps ? _hipNorthWest
+ : east == steps && north == steps ? _hipNorthEast
+ : east == steps && south == steps ? _hipSouthEast
+ : west == steps && south == steps ? _hipSouthWest
+ : null;
+ }
+ }
+
int z = eaveZ + (Rise * steps);
if (heights.TryGetValue((x, y), out int known) && known >= z)
{
@@ -78,7 +118,14 @@ public static void AddWing(Dictionary<(int X, int Y), int> heights, Dictionary<(
}
heights[(x, y)] = z;
- fixedPieces.Remove((x, y));
+ if (corner != null)
+ {
+ fixedPieces[(x, y)] = corner;
+ }
+ else
+ {
+ fixedPieces.Remove((x, y));
+ }
}
}
}
diff --git a/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.Commands.cs b/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.Commands.cs
index 52a88e3b..42a0bb52 100644
--- a/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.Commands.cs
+++ b/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.Commands.cs
@@ -239,7 +239,7 @@ public DesignData ToDesign()
{
return new DesignData(Title, CompList.Width, CompList.Height, FirstFloorZ,
CustomLevels ? _levelDefinitions.ToList() : null, CompList.DesignLayers(),
- CompList.Layers.ToList().IndexOf(CompList.ActiveLayer));
+ CompList.Layers.ToList().IndexOf(CompList.ActiveLayer), PlacedHouses.ToList());
}
/// Opens what a design file holds as this session's document.
@@ -247,6 +247,7 @@ public void LoadDesign(DesignData design)
{
NewBlank(design.Width, design.Height, design.FirstFloorZ);
CompList.RestoreLayers(design.Layers, design.ActiveLayer, (0, 0));
+ SetPlacedHouses(design.Houses);
if (design.Levels != null)
{
SetLevelDefinitions(design.Levels);
diff --git a/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.cs b/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.cs
index 5ff747ce..35839679 100644
--- a/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.cs
+++ b/UoFiddler.Plugin.MultiEditor/Editing/EditorSession.cs
@@ -109,6 +109,9 @@ public EditorSession(ArtMasks masks, HouseStyles houseStyles)
draft.Committed += () => LayersChanged?.Invoke();
}
+ house.FreeName = FreeHouseName;
+ house.Placed += placed => _placedHouses.Add(placed);
+
_tools[ToolKind.Roof] = roof;
_tools[ToolKind.House] = house;
_draftTools[ToolKind.Wall] = new DraftWallTool(this, house);
@@ -215,6 +218,10 @@ public bool Undo()
(tool is HouseTool || _toolKind == ToolKind.Roof))
{
tool.Reopen();
+ if (tool is HouseTool reopened && reopened.LastPlaced != null)
+ {
+ _placedHouses.Remove(reopened.LastPlaced);
+ }
}
}
@@ -242,6 +249,10 @@ public bool Redo()
}
open.CloseReopened();
+ if (open is HouseTool closed && closed.LastPlaced != null && !_placedHouses.Contains(closed.LastPlaced))
+ {
+ _placedHouses.Add(closed.LastPlaced);
+ }
}
if (!CompList.RedoStep())
@@ -259,6 +270,7 @@ private void SetDocument(MultiEditorComponentList list)
CancelTool();
Roof.Reset();
House.Reset();
+ _placedHouses.Clear();
CompList = list;
_selection.Clear();
HoverTile = null;
@@ -467,6 +479,103 @@ public static bool IsTileTool(ToolKind kind)
/// The roof tool, for its shape options (ridge, gables, gable fill) and the roof being shaped.
public RoofTool Roof => (RoofTool)_tools[ToolKind.Roof];
+ // ---------------------------------------------------------------- placed houses
+
+ private readonly List _placedHouses = new List();
+
+ ///
+ /// The houses placed with the House tool, each as the draft it was placed from. They are
+ /// kept with the design (design file, layers file), so a placed house can be opened as a
+ /// draft again.
+ ///
+ public IReadOnlyList PlacedHouses => _placedHouses;
+
+ private string FreeHouseName()
+ {
+ for (int n = _placedHouses.Count + 1; ; ++n)
+ {
+ string name = $"House {n}";
+ if (_placedHouses.All(h => (string)h.Attribute("name") != name) && CompList.Layers.All(l => l.Name != name))
+ {
+ return name;
+ }
+ }
+ }
+
+ /// Sets the placed houses of a design just opened, moved by an offset (the layers file counts cells from the save origin).
+ public void SetPlacedHouses(IEnumerable houses, int dx = 0, int dy = 0)
+ {
+ _placedHouses.Clear();
+ foreach (System.Xml.Linq.XElement house in houses ?? Enumerable.Empty())
+ {
+ try
+ {
+ _placedHouses.Add(dx == 0 && dy == 0 ? new System.Xml.Linq.XElement(house) : HouseDraftFile.Shifted(house, dx, dy, HouseStyles));
+ }
+ catch (System.IO.InvalidDataException)
+ {
+ // A house that cannot be read is only lost as a draft: its tiles are in the multi.
+ }
+ }
+
+ DraftChanged?.Invoke();
+ }
+
+ /// The placed houses moved by an offset, for a file that counts cells from another origin.
+ public List PlacedHousesShifted(int dx, int dy)
+ {
+ return _placedHouses.Select(h => HouseDraftFile.Shifted(h, dx, dy, HouseStyles)).ToList();
+ }
+
+ ///
+ /// Opens a placed house as a draft again: the tiles it was placed with that are still in
+ /// the multi are taken out (one undo step) and the House tool gets its draft back. Tiles
+ /// changed by hand since stay where they are. Returns what is wrong, or null.
+ ///
+ public string ReopenHouse(System.Xml.Linq.XElement house)
+ {
+ if (House.HasPending)
+ {
+ return "Place or drop the house being designed first.";
+ }
+
+ List<(ushort Id, int X, int Y, int Z, string Layer)> built;
+ try
+ {
+ built = House.TilesOf(house);
+ }
+ catch (System.IO.InvalidDataException ex)
+ {
+ return ex.Message;
+ }
+
+ // The house is on the layer named after it, or on a layer per part.
+ string name = (string)house.Attribute("name");
+ var remove = new List();
+ foreach ((ushort id, int x, int y, int z, string layer) in built)
+ {
+ MultiTile tile = CompList.GetTilesAt(x, y).FirstOrDefault(t =>
+ t.Id == id && t.Z == z && (t.Layer.Name == name || t.Layer.Name == layer) && !remove.Contains(t));
+ if (tile != null)
+ {
+ remove.Add(tile);
+ }
+ }
+
+ _placedHouses.Remove(house);
+ if (remove.Count * 2 < built.Count)
+ {
+ DraftChanged?.Invoke();
+ return "This house is no longer in the multi: most of its tiles were changed or removed.";
+ }
+
+ CompList.ReplaceTilesOnLayers(remove, new List<(ushort, int, int, int, string)>(), "Edit house", HouseDraft.WallsLayer);
+ House.OpenXml(house, keepName: true);
+ AfterEdit();
+ LayersChanged?.Invoke();
+ return null;
+ }
+
/// The house tool, for its draft and options.
public HouseTool House => (HouseTool)_tools[ToolKind.House];
diff --git a/UoFiddler.Plugin.MultiEditor/Rendering/SceneRenderer.cs b/UoFiddler.Plugin.MultiEditor/Rendering/SceneRenderer.cs
index aa0b3313..d750d47c 100644
--- a/UoFiddler.Plugin.MultiEditor/Rendering/SceneRenderer.cs
+++ b/UoFiddler.Plugin.MultiEditor/Rendering/SceneRenderer.cs
@@ -29,7 +29,8 @@ internal sealed class SceneRenderer : IDisposable, IToolOverlay
private static readonly SpriteTint _belowLevel = new SpriteTint(0.55f, 0.55f, 0.55f, 1f, 0f, 0f, 0f);
private static readonly SpriteTint _transparent = SpriteTint.Alpha(0.3f);
private static readonly SpriteTint _standable = new SpriteTint(0.6f, 1f, 0.6f, 1f, 0f, 0.3f, 0f);
- private static readonly SpriteTint _toolGhost = new SpriteTint(1f, 1f, 1f, 0.6f, 0f, 0.08f, 0.16f);
+ // Tiles a tool is about to place: see-through by the setting, with a little blue so they differ from placed ones.
+ private SpriteTint _toolGhost = new SpriteTint(1f, 1f, 1f, 0.8f, 0f, 0.08f, 0.16f);
private static readonly SpriteTint _removeMark = new SpriteTint(1f, 0.3f, 0.3f, 0.85f, 0.45f, 0f, 0f);
private static readonly SpriteTint _reference = new SpriteTint(0.7f, 0.8f, 1f, 0.4f, 0f, 0.05f, 0.15f);
@@ -81,6 +82,7 @@ public void Draw(EditorSession session, Camera2D camera, Size viewport)
_marqueeLine = settings.SelectionBox;
_marqueeFill = Color.FromArgb(40, settings.SelectionBox);
_workPlane = SpriteTint.Solid(settings.WorkPlane);
+ _toolGhost = new SpriteTint(1f, 1f, 1f, settings.PreviewOpacity / 100f, 0f, 0.08f, 0.16f);
if (!session.HasDocument)
{
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
index bab2fdd7..9baae6f3 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
@@ -12,6 +12,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Xml.Linq;
using UoFiddler.Plugin.MultiEditor.Classes;
namespace UoFiddler.Plugin.MultiEditor.Tools
@@ -30,6 +31,7 @@ internal sealed class HouseTool : WingDraftTool
private readonly RoofTool _roof;
private HouseDraft _draft = new HouseDraft();
private int _storeys = 1;
+ private int _rooms = 1;
private RoofShape _shape = RoofShape.Gable;
private bool _noRoof;
private RoofRidge _ridge = RoofRidge.Auto;
@@ -53,9 +55,12 @@ public HouseTool(IEditorContext context, RoofTool roof) : base(context)
/// Storeys of the tallest wing; 1 before there is one.
public int TopStorey => Math.Max(1, HouseDraft.Top(Wings));
- /// Storeys of new wings.
+ /// Storeys of the selected wing, else of the wings drawn next.
public int Storeys => SelectedWing?.Storeys ?? _storeys;
+ /// Rooms of the selected wing, else of the wings drawn next.
+ public int Rooms => SelectedWing?.Rooms ?? _rooms;
+
public RoofShape Shape => SelectedWing?.Shape ?? _shape;
public bool NoRoof => SelectedWing?.NoRoof ?? _noRoof;
@@ -81,6 +86,47 @@ protected override bool Ready
protected override bool GhostsFollowView => true;
+ // What the preview shows. A view choice: it is no step of the history and what is placed
+ // is always the whole house.
+ private bool _showWalls = true;
+ private bool _showFloors = true;
+ private bool _showRoof = true;
+
+ /// Walls, doors, windows, stairs and the foundation in the preview.
+ public bool ShowWalls
+ {
+ get => _showWalls;
+ set => SetShown(ref _showWalls, value);
+ }
+
+ /// Floors in the preview: off to look at the walls of a storey without the floor above.
+ public bool ShowFloors
+ {
+ get => _showFloors;
+ set => SetShown(ref _showFloors, value);
+ }
+
+ /// The roof and its gable ends in the preview.
+ public bool ShowRoof
+ {
+ get => _showRoof;
+ set => SetShown(ref _showRoof, value);
+ }
+
+ private void SetShown(ref bool field, bool value)
+ {
+ if (field != value)
+ {
+ field = value;
+ RaiseChanged();
+ }
+ }
+
+ protected override bool ShowsInPreview(string layer)
+ {
+ return layer == HouseDraft.FloorsLayer ? _showFloors : layer == RoofTool.LayerName ? _showRoof : _showWalls;
+ }
+
///
/// Storeys without a material take the one below; the ground floor and the roof take the
/// first style the client has, until one is chosen.
@@ -133,9 +179,10 @@ protected override List WingsFor(int startX, int startY, int endX, int
var wing = new RoofWing
{
- X0 = x0, Y0 = y0, X1 = x1, Y1 = y1, EaveZ = z, Storeys = _storeys,
+ X0 = x0, Y0 = y0, X1 = x1, Y1 = y1, EaveZ = z, Storeys = _storeys, Rooms = _rooms,
Shape = _shape, NoRoof = _noRoof, RidgeAuto = _ridge == RoofRidge.Auto
};
+ Snap(wing, moved: false);
wing.RidgeAlongY = wing.RidgeAuto ? RoofPlanner.RidgeAlongY(RoofBox(wing)) : _ridge == RoofRidge.AlongY;
wings.Add(wing);
return wings;
@@ -143,6 +190,47 @@ protected override List WingsFor(int startX, int startY, int endX, int
private static (int X0, int Y0, int X1, int Y1) RoofBox(RoofWing wing) => (wing.X0 + 1, wing.Y0 + 1, wing.X1 + 1, wing.Y1 + 1);
+ ///
+ /// A wing drawn or moved to stand right beside another would leave two walls back to back
+ /// and its roof a cell short of the other's wall. It is pulled in by that cell, so the two
+ /// share the wall between them: one house inside, and the lower roof runs up to the
+ /// higher wall.
+ ///
+ protected override void Snap(RoofWing wing, bool moved)
+ {
+ foreach (RoofWing other in Wings)
+ {
+ if (ReferenceEquals(other, wing))
+ {
+ continue;
+ }
+
+ bool besideX = wing.Y0 <= other.Y1 && wing.Y1 >= other.Y0;
+ bool besideY = wing.X0 <= other.X1 && wing.X1 >= other.X0;
+ if (besideX && wing.X0 == other.X1 + 1)
+ {
+ wing.X0 -= 1;
+ wing.X1 -= moved ? 1 : 0;
+ }
+ else if (besideX && wing.X1 == other.X0 - 1)
+ {
+ wing.X1 += 1;
+ wing.X0 += moved ? 1 : 0;
+ }
+
+ if (besideY && wing.Y0 == other.Y1 + 1)
+ {
+ wing.Y0 -= 1;
+ wing.Y1 -= moved ? 1 : 0;
+ }
+ else if (besideY && wing.Y1 == other.Y0 - 1)
+ {
+ wing.Y1 += 1;
+ wing.Y0 += moved ? 1 : 0;
+ }
+ }
+ }
+
protected override void WingResized(RoofWing wing)
{
if (wing.RidgeAuto)
@@ -240,6 +328,118 @@ public void SetBaseZ(int z)
});
}
+ /// Divides the selected wing, and the wings drawn next, into this many rooms on every storey (1: undivided).
+ public void SetRooms(int rooms)
+ {
+ rooms = Math.Clamp(rooms, 1, HouseDraft.MaxRooms);
+ _rooms = rooms;
+ if (SelectedWing is { } wing && wing.Rooms != rooms)
+ {
+ Edit(() => wing.Rooms = rooms);
+ }
+ else
+ {
+ RaiseChanged();
+ }
+ }
+
+ // ---------------------------------------------------------------- layers
+
+ private static readonly string[] _parts =
+ {
+ HouseDraft.FoundationLayer, HouseDraft.WallsLayer, HouseDraft.FloorsLayer, HouseDraft.StairsLayer, RoofTool.LayerName
+ };
+
+ // The name the house being placed gets: of the house it was reopened from, else a free one.
+ private string _placeName;
+ private string _reopenedName;
+
+ /// Gives a name no placed house and no layer of the multi has yet.
+ public Func FreeName { get; set; }
+
+ /// True when a placed house's parts each go on a layer of their own instead of one layer named after the house.
+ public static bool LayerPerPart => !UI.EditorSettings.Current.HouseOnOneLayer;
+
+ private string PlaceName => _placeName ??= _reopenedName ?? FreeName?.Invoke() ?? "House";
+
+ /// The house's parts go on the layer named after the house; a tile that names another layer (a re-pieced older roof) keeps it.
+ protected override string LayerFor(string layer)
+ {
+ return !LayerPerPart && (layer == null || Array.IndexOf(_parts, layer) >= 0) ? PlaceName : layer;
+ }
+
+ // ---------------------------------------------------------------- drafts kept outside the tool
+
+ /// The house last placed, as it is kept with the multi.
+ public XElement LastPlaced { get; private set; }
+
+ /// Raised when a house was placed, with what is kept of it.
+ public event Action Placed;
+
+ /// The draft as XML: what a house draft file holds.
+ public XElement ToXml(string name)
+ {
+ return HouseDraftFile.ToXml(Wings, _draft, name);
+ }
+
+ ///
+ /// Makes a saved house the draft, in place of the one being worked on (a step of the
+ /// history). A house reaching past the multi's first row or column is moved inside.
+ ///
+ public void OpenXml(XElement house, bool keepName = false)
+ {
+ EnsureMaterials();
+ _reopenedName = keepName ? (string)house.Attribute("name") : null;
+ var (wings, draft, _) = HouseDraftFile.FromXml(house, Context.HouseStyles, _draft);
+ if (wings.Count == 0)
+ {
+ throw new System.IO.InvalidDataException("The house draft has no wings.");
+ }
+
+ int dx = Math.Max(0, -wings.Min(w => w.X0)), dy = Math.Max(0, -wings.Min(w => w.Y0));
+ if (dx != 0 || dy != 0)
+ {
+ foreach (RoofWing wing in wings)
+ {
+ (wing.X0, wing.X1, wing.Y0, wing.Y1) = (wing.X0 + dx, wing.X1 + dx, wing.Y0 + dy, wing.Y1 + dy);
+ }
+
+ draft.Shift(dx, dy);
+ }
+
+ LoadWings(wings);
+ _draft = draft;
+ ++_version;
+ RaiseChanged();
+ }
+
+ /// The tiles a saved house builds, each with its layer: what placing it put into the multi.
+ public List<(ushort Id, int X, int Y, int Z, string Layer)> TilesOf(XElement house)
+ {
+ EnsureMaterials();
+ var (wings, draft, _) = HouseDraftFile.FromXml(house, Context.HouseStyles, _draft);
+ HouseDraft own = _draft;
+ _draft = draft;
+ ++_version;
+ try
+ {
+ return new List<(ushort Id, int X, int Y, int Z, string Layer)>(Plan(wings).Add);
+ }
+ finally
+ {
+ _draft = own;
+ ++_version;
+ }
+ }
+
+ protected override void OnPlaced()
+ {
+ LastPlaced = ToXml(PlaceName);
+ _placeName = null;
+ _reopenedName = null;
+ Placed?.Invoke(LastPlaced);
+ }
+
public void SetFoundation(bool on)
{
if (_draft.Foundation != on)
@@ -436,7 +636,7 @@ protected override (List Remove, List<(ushort Id, int X, int Y, int Z
EnsureMaterials();
string key = string.Join(";", wings.Select(w =>
- $"{w.X0},{w.Y0},{w.X1},{w.Y1},{w.EaveZ},{w.Storeys},{w.Shape},{w.NoRoof},{w.RidgeAlongY}")) +
+ $"{w.X0},{w.Y0},{w.X1},{w.Y1},{w.EaveZ},{w.Storeys},{w.Rooms},{w.Shape},{w.NoRoof},{w.RidgeAlongY}")) +
$"|{_version}|{_roof.Gables}|{_roof.GableFill}|{Context.CompList.UndoList.Count}|{Context.CompList.RedoList.Count}";
if (key == _builtFor)
{
@@ -471,7 +671,7 @@ protected override (List Remove, List<(ushort Id, int X, int Y, int Z
var roofWings = new List();
foreach (RoofWing wing in wings)
{
- if (wing.NoRoof)
+ if (wing.NoRoof || wing.Shape == RoofShape.Flat)
{
continue;
}
@@ -484,12 +684,14 @@ protected override (List Remove, List<(ushort Id, int X, int Y, int Z
if (roofWings.Count > 0 && _draft.RoofStyle != null)
{
- // A lower wing's roof stops at the walls of a taller one.
+ // A lower wing's roof stops at the walls of a taller one. A roof piece is seen half a
+ // cell before its own cell, and the walls stand on the far edges of theirs: the
+ // first row and column inside a north or west wall still reach it from outside.
bool Hidden(int x, int y, int z)
{
foreach (RoofWing wing in wings)
{
- if (x >= wing.X0 && x <= wing.X1 && y >= wing.Y0 && y <= wing.Y1 &&
+ if (x >= wing.X0 + 2 && x <= wing.X1 && y >= wing.Y0 + 2 && y <= wing.Y1 &&
z < baseZ + (wing.Storeys * HouseDraft.StoreyHeight))
{
return true;
@@ -499,11 +701,16 @@ bool Hidden(int x, int y, int z)
return false;
}
- var (roofRemove, roofAdd) = _roof.PlanRoof(roofWings, _draft.RoofStyle, built.Walls, Hidden);
- remove.AddRange(roofRemove);
- foreach (var (id, x, y, z, layer) in roofAdd)
+ // Wings of the same height share one roof; a lower wing has a roof of its own, which
+ // lies under the eaves of a taller one where the two meet.
+ foreach (IGrouping level in roofWings.GroupBy(r => r.EaveZ))
{
- add.Add((id, x, y, z, layer ?? RoofTool.LayerName));
+ var (roofRemove, roofAdd) = _roof.PlanRoof(level.ToList(), _draft.RoofStyle, built.Walls, Hidden);
+ remove.AddRange(roofRemove.Where(t => !remove.Contains(t)));
+ foreach (var (id, x, y, z, layer) in roofAdd)
+ {
+ add.Add((id, x, y, z, layer ?? RoofTool.LayerName));
+ }
}
}
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs
index d76afbdc..ee1f8871 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs
@@ -291,7 +291,23 @@ protected override (List Remove, List<(ushort Id, int X, int Y, int Z
foreach ((int x, int y) in footprint)
{
- if (!fixedPieces.TryGetValue((x, y), out string column))
+ int lift = 0;
+ if (fixedPieces.TryGetValue((x, y), out string column))
+ {
+ // A hip's corner piece names how far below the slopes it sits.
+ int mark = column.IndexOf(RoofPlanner.LiftMark);
+ if (mark > 0)
+ {
+ lift = int.Parse(column.AsSpan(mark + 1));
+ column = column.Substring(0, mark);
+ if (style.Get(column) == 0)
+ {
+ // A style without corner pieces: the slope facing the same way.
+ (column, lift) = (column[0] switch { 'N' => "North", 'E' => "East", 'S' => "South", _ => "West" }, 0);
+ }
+ }
+ }
+ else
{
column = RoofPlanner.Piece(heights, x, y, out string fallback) ?? (wings[0].RidgeAlongY ? "West" : "North");
if (style.Get(column) == 0 && fallback != null)
@@ -303,7 +319,7 @@ protected override (List Remove, List<(ushort Id, int X, int Y, int Z
ushort id = style.Get(column);
if (id != 0)
{
- add.Add((id, x, y, heights[(x, y)], null));
+ add.Add((id, x, y, heights[(x, y)] + lift, null));
}
}
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
index 5d4ed7d5..293de389 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
@@ -41,6 +41,12 @@ internal sealed class RoofWing
/// A house wing left without a roof.
public bool NoRoof { get; set; }
+ ///
+ /// Rooms a house wing is divided into on each of its storeys: partitions across its longer
+ /// side, each with a doorway left in the middle. 1 leaves the wing undivided.
+ ///
+ public int Rooms { get; set; } = 1;
+
public RoofShape Shape { get; set; }
public bool RidgeAlongY { get; set; }
@@ -56,6 +62,7 @@ public void CopyFrom(RoofWing other)
{
(X0, Y0, X1, Y1, EaveZ) = (other.X0, other.Y0, other.X1, other.Y1, other.EaveZ);
(Shape, RidgeAlongY, RidgeAuto, Storeys, NoRoof) = (other.Shape, other.RidgeAlongY, other.RidgeAuto, other.Storeys, other.NoRoof);
+ Rooms = other.Rooms;
}
}
@@ -189,6 +196,12 @@ public int SelectedIndex
/// True when the draft is drawn only up to the highest Z the view shows (the chosen floor, the height slider).
protected virtual bool GhostsFollowView => false;
+ /// The layer of the multi that tiles planned for a layer are placed on: the same one, unless the tool gathers them.
+ protected virtual string LayerFor(string layer) => layer;
+
+ /// True when the tiles a draft puts on a layer are drawn in its preview. What is placed does not depend on it.
+ protected virtual bool ShowsInPreview(string layer) => true;
+
/// What the draft holds beside its wings, for the undo history.
protected virtual object CaptureExtra() => null;
@@ -196,6 +209,28 @@ protected virtual void RestoreExtra(object extra)
{
}
+ /// Called when the draft was written to the multi, before it is cleared.
+ protected virtual void OnPlaced()
+ {
+ }
+
+ /// Makes these wings the draft, as one step of its history.
+ protected void LoadWings(List wings)
+ {
+ CancelDrag();
+ Remember();
+ _wings = wings;
+ _selected = wings.Count > 0 ? 0 : -1;
+ }
+
+ ///
+ /// Called while a wing is moved or resized, to pull it into line with the other wings.
+ /// A moved wing is shifted whole; a resized one has the side in question moved.
+ ///
+ protected virtual void Snap(RoofWing wing, bool moved)
+ {
+ }
+
/// Called when a wing's box changed.
protected virtual void WingResized(RoofWing wing)
{
@@ -476,7 +511,7 @@ public void Commit()
{
int steps = Context.CompList.UndoList.Count;
object top = steps > 0 ? Context.CompList.UndoList[0] : null;
- Context.CompList.ReplaceTilesOnLayers(remove, add, ActionName, DefaultLayer);
+ Context.CompList.ReplaceTilesOnLayers(remove, add.Select(a => (a.Id, a.X, a.Y, a.Z, LayerFor(a.Layer))), ActionName, DefaultLayer);
Context.AfterEdit(add.Count > 0 ? add.Max(a => a.Z) : null);
object placedBy = Context.CompList.UndoList.Count > 0 ? Context.CompList.UndoList[0] : null;
if (placedBy != null && !ReferenceEquals(placedBy, top))
@@ -484,6 +519,7 @@ public void Commit()
_placed = Capture();
_placedHistory = new List(_undo);
PlacedBy = placedBy;
+ OnPlaced();
}
Committed?.Invoke();
@@ -586,6 +622,7 @@ private void DragWing()
dx = Math.Max(dx, -_before.X0);
dy = Math.Max(dy, -_before.Y0);
(wing.X0, wing.X1, wing.Y0, wing.Y1) = (_before.X0 + dx, _before.X1 + dx, _before.Y0 + dy, _before.Y1 + dy);
+ Snap(wing, moved: true);
return;
}
@@ -593,6 +630,7 @@ private void DragWing()
wing.X1 = _east ? Math.Max(_before.X1 + dx, _before.X0) : _before.X1;
wing.Y0 = _north ? Math.Clamp(_before.Y0 + dy, 0, _before.Y1) : _before.Y0;
wing.Y1 = _south ? Math.Max(_before.Y1 + dy, _before.Y0) : _before.Y1;
+ Snap(wing, moved: false);
WingResized(wing);
}
@@ -640,9 +678,9 @@ public void PaintDraft(IToolOverlay overlay, bool active)
// A house is looked into like the multi: storeys above the chosen floor are left out.
int highest = GhostsFollowView ? Context.MaxHeight : int.MaxValue;
- foreach (var (id, x, y, z, _) in add)
+ foreach (var (id, x, y, z, layer) in add)
{
- if (z <= highest)
+ if (z <= highest && ShowsInPreview(layer))
{
overlay.Ghost(id, x, y, z);
}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/EditorSettings.cs b/UoFiddler.Plugin.MultiEditor/UI/EditorSettings.cs
index 5b1006ca..e336e33d 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/EditorSettings.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/EditorSettings.cs
@@ -56,6 +56,15 @@ internal sealed class EditorSettings
public Color SelectionBox { get; set; } = Color.DodgerBlue;
+ ///
+ /// True puts a placed house on one layer named after it ("House 1"); false gives its
+ /// foundation, walls, floors, stairs and roof a layer each.
+ ///
+ public bool HouseOnOneLayer { get; set; } = true;
+
+ /// How solid the tiles a tool is about to place are drawn (roof and house drafts, walls, stamps), in percent.
+ public int PreviewOpacity { get; set; } = 80;
+
// How a new document starts.
public bool StartWithWorkPlane { get; set; } = true;
@@ -138,6 +147,7 @@ public static void Load()
settings.Background = Color.Empty;
}
+ settings.PreviewOpacity = Math.Clamp(settings.PreviewOpacity, 20, 100);
settings.TileBrowserWidth = Math.Clamp(settings.TileBrowserWidth, 200, 900);
settings.InspectorWidth = Math.Clamp(settings.InspectorWidth, 200, 600);
Current = settings;
diff --git a/UoFiddler.Plugin.MultiEditor/UI/EditorSettingsDialog.Designer.cs b/UoFiddler.Plugin.MultiEditor/UI/EditorSettingsDialog.Designer.cs
index 0050485f..a84a3270 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/EditorSettingsDialog.Designer.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/EditorSettingsDialog.Designer.cs
@@ -34,6 +34,9 @@ private void InitializeComponent()
labelWorkPlane = new System.Windows.Forms.Label();
labelWorkPlaneOpacity = new System.Windows.Forms.Label();
alphaWorkPlane = new System.Windows.Forms.NumericUpDown();
+ labelPreview = new System.Windows.Forms.Label();
+ labelPreviewOpacity = new System.Windows.Forms.Label();
+ alphaPreview = new System.Windows.Forms.NumericUpDown();
swatchWorkPlane = new System.Windows.Forms.Button();
labelGrid = new System.Windows.Forms.Label();
labelGridOpacity = new System.Windows.Forms.Label();
@@ -49,10 +52,12 @@ private void InitializeComponent()
checkWorkPlane = new System.Windows.Forms.CheckBox();
checkGrid = new System.Windows.Forms.CheckBox();
checkHideFloorsAbove = new System.Windows.Forms.CheckBox();
+ checkHouseOneLayer = new System.Windows.Forms.CheckBox();
buttonDefaults = new System.Windows.Forms.Button();
buttonOk = new System.Windows.Forms.Button();
buttonCancel = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)alphaWorkPlane).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)alphaPreview).BeginInit();
((System.ComponentModel.ISupportInitialize)alphaGrid).BeginInit();
((System.ComponentModel.ISupportInitialize)alphaOutline).BeginInit();
SuspendLayout();
@@ -223,11 +228,41 @@ private void InitializeComponent()
swatchSelection.TabIndex = 20;
swatchSelection.UseVisualStyleBackColor = true;
swatchSelection.Click += SwatchSelection_Click;
+ //
+ // labelPreview
+ //
+ labelPreview.AutoSize = true;
+ labelPreview.Location = new System.Drawing.Point(24, 190);
+ labelPreview.Name = "labelPreview";
+ labelPreview.Size = new System.Drawing.Size(190, 15);
+ labelPreview.TabIndex = 30;
+ labelPreview.Text = "Preview of what a tool will place";
+ //
+ // labelPreviewOpacity
+ //
+ labelPreviewOpacity.AutoSize = true;
+ labelPreviewOpacity.Location = new System.Drawing.Point(272, 190);
+ labelPreviewOpacity.Name = "labelPreviewOpacity";
+ labelPreviewOpacity.Size = new System.Drawing.Size(62, 15);
+ labelPreviewOpacity.TabIndex = 31;
+ labelPreviewOpacity.Text = "Opacity %";
+ //
+ // alphaPreview
+ //
+ alphaPreview.Increment = new decimal(new int[] { 5, 0, 0, 0 });
+ alphaPreview.Location = new System.Drawing.Point(340, 187);
+ alphaPreview.Maximum = new decimal(new int[] { 100, 0, 0, 0 });
+ alphaPreview.Minimum = new decimal(new int[] { 20, 0, 0, 0 });
+ alphaPreview.Name = "alphaPreview";
+ alphaPreview.Size = new System.Drawing.Size(56, 23);
+ alphaPreview.TabIndex = 32;
+ alphaPreview.Value = new decimal(new int[] { 80, 0, 0, 0 });
+ alphaPreview.ValueChanged += AlphaPreview_ValueChanged;
//
// headingStart
//
headingStart.AutoSize = true;
- headingStart.Location = new System.Drawing.Point(12, 194);
+ headingStart.Location = new System.Drawing.Point(12, 224);
headingStart.Name = "headingStart";
headingStart.Size = new System.Drawing.Size(202, 15);
headingStart.TabIndex = 21;
@@ -236,7 +271,7 @@ private void InitializeComponent()
// checkWorkPlane
//
checkWorkPlane.AutoSize = true;
- checkWorkPlane.Location = new System.Drawing.Point(24, 218);
+ checkWorkPlane.Location = new System.Drawing.Point(24, 248);
checkWorkPlane.Name = "checkWorkPlane";
checkWorkPlane.Size = new System.Drawing.Size(129, 19);
checkWorkPlane.TabIndex = 23;
@@ -247,7 +282,7 @@ private void InitializeComponent()
// checkGrid
//
checkGrid.AutoSize = true;
- checkGrid.Location = new System.Drawing.Point(24, 242);
+ checkGrid.Location = new System.Drawing.Point(24, 272);
checkGrid.Name = "checkGrid";
checkGrid.Size = new System.Drawing.Size(86, 19);
checkGrid.TabIndex = 24;
@@ -258,17 +293,28 @@ private void InitializeComponent()
// checkHideFloorsAbove
//
checkHideFloorsAbove.AutoSize = true;
- checkHideFloorsAbove.Location = new System.Drawing.Point(24, 266);
+ checkHideFloorsAbove.Location = new System.Drawing.Point(24, 296);
checkHideFloorsAbove.Name = "checkHideFloorsAbove";
checkHideFloorsAbove.Size = new System.Drawing.Size(365, 19);
checkHideFloorsAbove.TabIndex = 25;
checkHideFloorsAbove.Text = "Floors above the active one hidden (off: drawn faintly)";
checkHideFloorsAbove.UseVisualStyleBackColor = true;
checkHideFloorsAbove.CheckedChanged += CheckHideFloorsAbove_CheckedChanged;
+ //
+ // checkHouseOneLayer
+ //
+ checkHouseOneLayer.AutoSize = true;
+ checkHouseOneLayer.Location = new System.Drawing.Point(24, 326);
+ checkHouseOneLayer.Name = "checkHouseOneLayer";
+ checkHouseOneLayer.Size = new System.Drawing.Size(365, 19);
+ checkHouseOneLayer.TabIndex = 33;
+ checkHouseOneLayer.Text = "A placed house goes on one layer (off: one per part)";
+ checkHouseOneLayer.UseVisualStyleBackColor = true;
+ checkHouseOneLayer.CheckedChanged += CheckHouseOneLayer_CheckedChanged;
//
// buttonDefaults
//
- buttonDefaults.Location = new System.Drawing.Point(12, 302);
+ buttonDefaults.Location = new System.Drawing.Point(12, 362);
buttonDefaults.Name = "buttonDefaults";
buttonDefaults.Size = new System.Drawing.Size(80, 23);
buttonDefaults.TabIndex = 26;
@@ -279,7 +325,7 @@ private void InitializeComponent()
// buttonOk
//
buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK;
- buttonOk.Location = new System.Drawing.Point(236, 302);
+ buttonOk.Location = new System.Drawing.Point(236, 362);
buttonOk.Name = "buttonOk";
buttonOk.Size = new System.Drawing.Size(76, 23);
buttonOk.TabIndex = 27;
@@ -289,7 +335,7 @@ private void InitializeComponent()
// buttonCancel
//
buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
- buttonCancel.Location = new System.Drawing.Point(320, 302);
+ buttonCancel.Location = new System.Drawing.Point(320, 362);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new System.Drawing.Size(76, 23);
buttonCancel.TabIndex = 28;
@@ -302,7 +348,7 @@ private void InitializeComponent()
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
CancelButton = buttonCancel;
- ClientSize = new System.Drawing.Size(410, 340);
+ ClientSize = new System.Drawing.Size(410, 400);
Controls.Add(headingColours);
Controls.Add(labelBackground);
Controls.Add(swatchBackground);
@@ -320,10 +366,14 @@ private void InitializeComponent()
Controls.Add(swatchOutline);
Controls.Add(labelSelection);
Controls.Add(swatchSelection);
+ Controls.Add(labelPreview);
+ Controls.Add(labelPreviewOpacity);
+ Controls.Add(alphaPreview);
Controls.Add(headingStart);
Controls.Add(checkWorkPlane);
Controls.Add(checkGrid);
Controls.Add(checkHideFloorsAbove);
+ Controls.Add(checkHouseOneLayer);
Controls.Add(buttonDefaults);
Controls.Add(buttonOk);
Controls.Add(buttonCancel);
@@ -335,6 +385,7 @@ private void InitializeComponent()
StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
Text = "Multi Editor settings";
((System.ComponentModel.ISupportInitialize)alphaWorkPlane).EndInit();
+ ((System.ComponentModel.ISupportInitialize)alphaPreview).EndInit();
((System.ComponentModel.ISupportInitialize)alphaGrid).EndInit();
((System.ComponentModel.ISupportInitialize)alphaOutline).EndInit();
ResumeLayout(false);
@@ -349,6 +400,9 @@ private void InitializeComponent()
private System.Windows.Forms.Label labelWorkPlane;
private System.Windows.Forms.Label labelWorkPlaneOpacity;
private System.Windows.Forms.NumericUpDown alphaWorkPlane;
+ private System.Windows.Forms.Label labelPreview;
+ private System.Windows.Forms.Label labelPreviewOpacity;
+ private System.Windows.Forms.NumericUpDown alphaPreview;
private System.Windows.Forms.Button swatchWorkPlane;
private System.Windows.Forms.Label labelGrid;
private System.Windows.Forms.Label labelGridOpacity;
@@ -364,6 +418,7 @@ private void InitializeComponent()
private System.Windows.Forms.CheckBox checkWorkPlane;
private System.Windows.Forms.CheckBox checkGrid;
private System.Windows.Forms.CheckBox checkHideFloorsAbove;
+ private System.Windows.Forms.CheckBox checkHouseOneLayer;
private System.Windows.Forms.Button buttonDefaults;
private System.Windows.Forms.Button buttonOk;
private System.Windows.Forms.Button buttonCancel;
diff --git a/UoFiddler.Plugin.MultiEditor/UI/EditorSettingsDialog.cs b/UoFiddler.Plugin.MultiEditor/UI/EditorSettingsDialog.cs
index b8adf601..d79ade19 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/EditorSettingsDialog.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/EditorSettingsDialog.cs
@@ -37,9 +37,13 @@ public EditorSettingsDialog(EditorSettings current)
ColorRow(swatchOutline, alphaOutline, () => _settings.Outline);
ColorRow(swatchSelection, null, () => _settings.SelectionBox);
+ alphaPreview.Value = Math.Clamp(_settings.PreviewOpacity, 20, 100);
+ _refresh.Add(() => alphaPreview.Value = Math.Clamp(_settings.PreviewOpacity, 20, 100));
+
CheckRow(checkWorkPlane, () => _settings.StartWithWorkPlane);
CheckRow(checkGrid, () => _settings.StartWithGrid);
CheckRow(checkHideFloorsAbove, () => _settings.HideFloorsAbove);
+ CheckRow(checkHouseOneLayer, () => _settings.HouseOnOneLayer);
}
/// The edited copy; apply it when the dialog returns OK.
@@ -115,6 +119,11 @@ private void AlphaWorkPlane_ValueChanged(object sender, EventArgs e)
ChangeOpacity(alphaWorkPlane, () => _settings.WorkPlane, c => _settings.WorkPlane = c);
}
+ private void AlphaPreview_ValueChanged(object sender, EventArgs e)
+ {
+ _settings.PreviewOpacity = (int)alphaPreview.Value;
+ }
+
private void AlphaGrid_ValueChanged(object sender, EventArgs e)
{
ChangeOpacity(alphaGrid, () => _settings.Grid, c => _settings.Grid = c);
@@ -135,6 +144,11 @@ private void CheckGrid_CheckedChanged(object sender, EventArgs e)
_settings.StartWithGrid = checkGrid.Checked;
}
+ private void CheckHouseOneLayer_CheckedChanged(object sender, EventArgs e)
+ {
+ _settings.HouseOnOneLayer = checkHouseOneLayer.Checked;
+ }
+
private void CheckHideFloorsAbove_CheckedChanged(object sender, EventArgs e)
{
_settings.HideFloorsAbove = checkHideFloorsAbove.Checked;
diff --git a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs
index 2e2646fe..c5476469 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs
@@ -55,14 +55,27 @@ private void InitializeComponent()
_foundation = new System.Windows.Forms.CheckBox();
_baseZLabel = new System.Windows.Forms.Label();
_baseZ = new System.Windows.Forms.NumericUpDown();
+ _roomsLabel = new System.Windows.Forms.Label();
+ _rooms = new System.Windows.Forms.NumericUpDown();
+ _showLabel = new System.Windows.Forms.Label();
+ _showWalls = new System.Windows.Forms.CheckBox();
+ _showFloors = new System.Windows.Forms.CheckBox();
+ _showRoof = new System.Windows.Forms.CheckBox();
_undo = new System.Windows.Forms.Button();
_redo = new System.Windows.Forms.Button();
_place = new System.Windows.Forms.Button();
_drop = new System.Windows.Forms.Button();
+ _saveDraft = new System.Windows.Forms.Button();
+ _openDraft = new System.Windows.Forms.Button();
+ _blueprint = new System.Windows.Forms.Button();
+ _placedLabel = new System.Windows.Forms.Label();
+ _placed = new System.Windows.Forms.ComboBox();
+ _edit = new System.Windows.Forms.Button();
_status = new System.Windows.Forms.Label();
houseBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)_storeys).BeginInit();
((System.ComponentModel.ISupportInitialize)_baseZ).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)_rooms).BeginInit();
SuspendLayout();
//
// houseBox
@@ -93,15 +106,27 @@ private void InitializeComponent()
houseBox.Controls.Add(_foundation);
houseBox.Controls.Add(_baseZLabel);
houseBox.Controls.Add(_baseZ);
+ houseBox.Controls.Add(_roomsLabel);
+ houseBox.Controls.Add(_rooms);
+ houseBox.Controls.Add(_showLabel);
+ houseBox.Controls.Add(_showWalls);
+ houseBox.Controls.Add(_showFloors);
+ houseBox.Controls.Add(_showRoof);
houseBox.Controls.Add(_undo);
houseBox.Controls.Add(_redo);
houseBox.Controls.Add(_place);
houseBox.Controls.Add(_drop);
+ houseBox.Controls.Add(_saveDraft);
+ houseBox.Controls.Add(_openDraft);
+ houseBox.Controls.Add(_blueprint);
+ houseBox.Controls.Add(_placedLabel);
+ houseBox.Controls.Add(_placed);
+ houseBox.Controls.Add(_edit);
houseBox.Controls.Add(_status);
houseBox.Dock = System.Windows.Forms.DockStyle.Fill;
houseBox.Location = new System.Drawing.Point(0, 0);
houseBox.Name = "houseBox";
- houseBox.Size = new System.Drawing.Size(250, 430);
+ houseBox.Size = new System.Drawing.Size(250, 518);
houseBox.TabIndex = 0;
houseBox.TabStop = false;
houseBox.Text = "House draft";
@@ -150,11 +175,11 @@ private void InitializeComponent()
//
_removeWing.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right;
_removeWing.UseVisualStyleBackColor = true;
- _removeWing.Location = new System.Drawing.Point(150, 109);
+ _removeWing.Location = new System.Drawing.Point(206, 109);
_removeWing.Name = "_removeWing";
- _removeWing.Size = new System.Drawing.Size(94, 25);
+ _removeWing.Size = new System.Drawing.Size(38, 25);
_removeWing.TabIndex = 4;
- _removeWing.Text = "Remove wing";
+ _removeWing.Text = "Del";
_removeWing.Click += RemoveWing_Click;
//
// _roofLabel
@@ -170,7 +195,7 @@ private void InitializeComponent()
//
_roofShape.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
_roofShape.FormattingEnabled = true;
- _roofShape.Items.AddRange(new object[] { "Gable", "None" });
+ _roofShape.Items.AddRange(new object[] { "Gable", "Hip", "Flat", "None" });
_roofShape.Location = new System.Drawing.Point(60, 140);
_roofShape.Name = "_roofShape";
_roofShape.Size = new System.Drawing.Size(80, 23);
@@ -358,33 +383,101 @@ private void InitializeComponent()
_baseZ.TabIndex = 25;
_baseZ.ValueChanged += BaseZ_ValueChanged;
//
+ // _roomsLabel
+ //
+ _roomsLabel.AutoSize = true;
+ _roomsLabel.Location = new System.Drawing.Point(110, 113);
+ _roomsLabel.Name = "_roomsLabel";
+ _roomsLabel.Size = new System.Drawing.Size(44, 15);
+ _roomsLabel.TabIndex = 26;
+ _roomsLabel.Text = "Rooms";
+ //
+ // _rooms
+ //
+ _rooms.Maximum = new decimal(new int[] { 6, 0, 0, 0 });
+ _rooms.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
+ _rooms.Value = new decimal(new int[] { 1, 0, 0, 0 });
+ _rooms.Location = new System.Drawing.Point(156, 110);
+ _rooms.Name = "_rooms";
+ _rooms.Size = new System.Drawing.Size(44, 23);
+ _rooms.TabIndex = 27;
+ _rooms.ValueChanged += Rooms_ValueChanged;
+ //
+ // _showLabel
+ //
+ _showLabel.AutoSize = true;
+ _showLabel.Location = new System.Drawing.Point(6, 364);
+ _showLabel.Name = "_showLabel";
+ _showLabel.Size = new System.Drawing.Size(50, 15);
+ _showLabel.TabIndex = 28;
+ _showLabel.Text = "Preview";
+ //
+ // _showWalls
+ //
+ _showWalls.AutoSize = true;
+ _showWalls.Checked = true;
+ _showWalls.CheckState = System.Windows.Forms.CheckState.Checked;
+ _showWalls.UseVisualStyleBackColor = true;
+ _showWalls.Location = new System.Drawing.Point(60, 362);
+ _showWalls.Name = "_showWalls";
+ _showWalls.Size = new System.Drawing.Size(56, 19);
+ _showWalls.TabIndex = 29;
+ _showWalls.Text = "Walls";
+ _showWalls.CheckedChanged += Show_CheckedChanged;
+ //
+ // _showFloors
+ //
+ _showFloors.AutoSize = true;
+ _showFloors.Checked = true;
+ _showFloors.CheckState = System.Windows.Forms.CheckState.Checked;
+ _showFloors.UseVisualStyleBackColor = true;
+ _showFloors.Location = new System.Drawing.Point(122, 362);
+ _showFloors.Name = "_showFloors";
+ _showFloors.Size = new System.Drawing.Size(60, 19);
+ _showFloors.TabIndex = 30;
+ _showFloors.Text = "Floors";
+ _showFloors.CheckedChanged += Show_CheckedChanged;
+ //
+ // _showRoof
+ //
+ _showRoof.AutoSize = true;
+ _showRoof.Checked = true;
+ _showRoof.CheckState = System.Windows.Forms.CheckState.Checked;
+ _showRoof.UseVisualStyleBackColor = true;
+ _showRoof.Location = new System.Drawing.Point(188, 362);
+ _showRoof.Name = "_showRoof";
+ _showRoof.Size = new System.Drawing.Size(52, 19);
+ _showRoof.TabIndex = 31;
+ _showRoof.Text = "Roof";
+ _showRoof.CheckedChanged += Show_CheckedChanged;
+ //
// _undo
//
_undo.UseVisualStyleBackColor = true;
- _undo.Location = new System.Drawing.Point(6, 362);
+ _undo.Location = new System.Drawing.Point(6, 392);
_undo.Name = "_undo";
_undo.Size = new System.Drawing.Size(54, 25);
- _undo.TabIndex = 26;
+ _undo.TabIndex = 32;
_undo.Text = "Undo";
_undo.Click += Undo_Click;
//
// _redo
//
_redo.UseVisualStyleBackColor = true;
- _redo.Location = new System.Drawing.Point(62, 362);
+ _redo.Location = new System.Drawing.Point(62, 392);
_redo.Name = "_redo";
_redo.Size = new System.Drawing.Size(54, 25);
- _redo.TabIndex = 27;
+ _redo.TabIndex = 33;
_redo.Text = "Redo";
_redo.Click += Redo_Click;
//
// _place
//
_place.UseVisualStyleBackColor = true;
- _place.Location = new System.Drawing.Point(122, 362);
+ _place.Location = new System.Drawing.Point(122, 392);
_place.Name = "_place";
_place.Size = new System.Drawing.Size(72, 25);
- _place.TabIndex = 28;
+ _place.TabIndex = 34;
_place.Text = "Place";
_place.Click += Place_Click;
//
@@ -392,20 +485,81 @@ private void InitializeComponent()
//
_drop.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
_drop.UseVisualStyleBackColor = true;
- _drop.Location = new System.Drawing.Point(196, 362);
+ _drop.Location = new System.Drawing.Point(196, 392);
_drop.Name = "_drop";
_drop.Size = new System.Drawing.Size(48, 25);
- _drop.TabIndex = 29;
+ _drop.TabIndex = 35;
_drop.Text = "Drop";
_drop.Click += Drop_Click;
//
+ // _saveDraft
+ //
+ _saveDraft.UseVisualStyleBackColor = true;
+ _saveDraft.Location = new System.Drawing.Point(6, 421);
+ _saveDraft.Name = "_saveDraft";
+ _saveDraft.Size = new System.Drawing.Size(76, 25);
+ _saveDraft.TabIndex = 36;
+ _saveDraft.Text = "Save draft";
+ _saveDraft.Click += SaveDraft_Click;
+ //
+ // _openDraft
+ //
+ _openDraft.UseVisualStyleBackColor = true;
+ _openDraft.Location = new System.Drawing.Point(84, 421);
+ _openDraft.Name = "_openDraft";
+ _openDraft.Size = new System.Drawing.Size(76, 25);
+ _openDraft.TabIndex = 37;
+ _openDraft.Text = "Open draft";
+ _openDraft.Click += OpenDraft_Click;
+ //
+ // _blueprint
+ //
+ _blueprint.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _blueprint.UseVisualStyleBackColor = true;
+ _blueprint.Location = new System.Drawing.Point(162, 421);
+ _blueprint.Name = "_blueprint";
+ _blueprint.Size = new System.Drawing.Size(82, 25);
+ _blueprint.TabIndex = 38;
+ _blueprint.Text = "As blueprint";
+ _blueprint.Click += Blueprint_Click;
+ //
+ // _placedLabel
+ //
+ _placedLabel.AutoSize = true;
+ _placedLabel.Location = new System.Drawing.Point(6, 454);
+ _placedLabel.Name = "_placedLabel";
+ _placedLabel.Size = new System.Drawing.Size(60, 15);
+ _placedLabel.TabIndex = 39;
+ _placedLabel.Text = "Placed";
+ //
+ // _placed
+ //
+ _placed.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _placed.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ _placed.FormattingEnabled = true;
+ _placed.Location = new System.Drawing.Point(60, 451);
+ _placed.Name = "_placed";
+ _placed.Size = new System.Drawing.Size(130, 23);
+ _placed.TabIndex = 40;
+ //
+ // _edit
+ //
+ _edit.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right;
+ _edit.UseVisualStyleBackColor = true;
+ _edit.Location = new System.Drawing.Point(196, 450);
+ _edit.Name = "_edit";
+ _edit.Size = new System.Drawing.Size(48, 25);
+ _edit.TabIndex = 41;
+ _edit.Text = "Edit";
+ _edit.Click += Edit_Click;
+ //
// _status
//
_status.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _status.Location = new System.Drawing.Point(6, 392);
+ _status.Location = new System.Drawing.Point(6, 480);
_status.Name = "_status";
_status.Size = new System.Drawing.Size(238, 32);
- _status.TabIndex = 30;
+ _status.TabIndex = 42;
//
// HousePanel
//
@@ -413,11 +567,12 @@ private void InitializeComponent()
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
Controls.Add(houseBox);
Name = "HousePanel";
- Size = new System.Drawing.Size(250, 430);
+ Size = new System.Drawing.Size(250, 518);
houseBox.ResumeLayout(false);
houseBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)_storeys).EndInit();
((System.ComponentModel.ISupportInitialize)_baseZ).EndInit();
+ ((System.ComponentModel.ISupportInitialize)_rooms).EndInit();
ResumeLayout(false);
}
@@ -450,10 +605,22 @@ private void InitializeComponent()
private System.Windows.Forms.CheckBox _foundation;
private System.Windows.Forms.Label _baseZLabel;
private System.Windows.Forms.NumericUpDown _baseZ;
+ private System.Windows.Forms.Label _roomsLabel;
+ private System.Windows.Forms.NumericUpDown _rooms;
+ private System.Windows.Forms.Label _showLabel;
+ private System.Windows.Forms.CheckBox _showWalls;
+ private System.Windows.Forms.CheckBox _showFloors;
+ private System.Windows.Forms.CheckBox _showRoof;
private System.Windows.Forms.Button _undo;
private System.Windows.Forms.Button _redo;
private System.Windows.Forms.Button _place;
private System.Windows.Forms.Button _drop;
+ private System.Windows.Forms.Button _saveDraft;
+ private System.Windows.Forms.Button _openDraft;
+ private System.Windows.Forms.Button _blueprint;
+ private System.Windows.Forms.Label _placedLabel;
+ private System.Windows.Forms.ComboBox _placed;
+ private System.Windows.Forms.Button _edit;
private System.Windows.Forms.Label _status;
}
}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
index d744288b..13c0243e 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
@@ -56,6 +56,17 @@ public HousePanel()
/// Asks for a style to be picked on the House page for a storey's walls or floor, or for the roof.
public event Action PickStyle;
+ /// Asks for the draft to be saved to, or opened from, a house draft file.
+ public event Action SaveDraft;
+
+ public event Action OpenDraft;
+
+ /// Asks for the house as built to be saved to the blueprints.
+ public event Action SaveBlueprint;
+
+ /// Asks for a placed house to be opened as a draft again.
+ public event Action EditHouse;
+
/// Raised after a button of the panel was used, so the canvas can take the keyboard back.
public event Action Used;
@@ -96,7 +107,7 @@ public void RefreshDraft()
{
RoofWing wing = house.Wings[i];
string roof = wing.NoRoof ? "no roof" : wing.Shape.ToString().ToLowerInvariant();
- _wingList.Items.Add($"Wing {i + 1}: {wing.X1 - wing.X0 + 1} x {wing.Y1 - wing.Y0 + 1}, {wing.Storeys} storey{(wing.Storeys == 1 ? string.Empty : "s")}, {roof}");
+ _wingList.Items.Add($"Wing {i + 1}: {wing.X1 - wing.X0 + 1} x {wing.Y1 - wing.Y0 + 1}, {wing.Storeys} storey{(wing.Storeys == 1 ? string.Empty : "s")}, {(wing.Rooms > 1 ? $"{wing.Rooms} rooms, " : string.Empty)}{roof}");
}
_wingList.SelectedIndex = house.SelectedIndex;
@@ -106,7 +117,7 @@ public void RefreshDraft()
// The drop-down lists the roof shapes in their order, then None.
_roofShape.SelectedIndex = house.NoRoof ? _roofShape.Items.Count - 1 : (int)house.Shape;
_ridge.SelectedIndex = (int)house.Ridge;
- _ridge.Enabled = !house.NoRoof;
+ _ridge.Enabled = !house.NoRoof && house.Shape == RoofShape.Gable;
_removeWing.Enabled = house.HasSelectedWing;
_wingHint.Text = house.HasSelectedWing ? "Selected wing:" : "New wings:";
@@ -128,6 +139,24 @@ public void RefreshDraft()
_roofStyle.Text = house.Draft.RoofStyle?.Name ?? "(roof)";
_foundation.Checked = house.Draft.Foundation;
+ _rooms.Value = Math.Clamp(house.Rooms, 1, HouseDraft.MaxRooms);
+ _showWalls.Checked = house.ShowWalls;
+ _showFloors.Checked = house.ShowFloors;
+ _showRoof.Checked = house.ShowRoof;
+ _saveDraft.Enabled = _blueprint.Enabled = house.HasPending;
+
+ // The houses already placed in this design, which can be opened as drafts again.
+ object chosen = _placed.SelectedItem;
+ _placed.Items.Clear();
+ foreach (System.Xml.Linq.XElement placed in _session.PlacedHouses)
+ {
+ _placed.Items.Add(new PlacedHouse(placed));
+ }
+
+ _placed.SelectedIndex = _placed.Items.Count == 0 ? -1
+ : Math.Max(0, _placed.Items.Cast().ToList().FindIndex(p => chosen is PlacedHouse c && c.House == p.House));
+ _placed.Enabled = _placed.Items.Count > 0;
+ _edit.Enabled = _placed.Items.Count > 0 && !house.HasPending;
_baseZ.Enabled = house.HasPending;
_baseZ.Value = Math.Clamp(house.BaseZ, (int)_baseZ.Minimum, (int)_baseZ.Maximum);
@@ -153,6 +182,63 @@ public void RefreshDraft()
}
}
+ /// A placed house in the list, shown by its name and size.
+ private sealed class PlacedHouse
+ {
+ public PlacedHouse(System.Xml.Linq.XElement house)
+ {
+ House = house;
+ }
+
+ public System.Xml.Linq.XElement House { get; }
+
+ public override string ToString()
+ {
+ int wings = House.Elements("Wing").Count();
+ return $"{(string)House.Attribute("name") ?? "House"} ({wings} wing{(wings == 1 ? string.Empty : "s")})";
+ }
+ }
+
+ private void Rooms_ValueChanged(object sender, EventArgs e)
+ {
+ if (!_updating && _session != null)
+ {
+ _session.House.SetRooms((int)_rooms.Value);
+ }
+ }
+
+ private void Show_CheckedChanged(object sender, EventArgs e)
+ {
+ Run(house => (house.ShowWalls, house.ShowFloors, house.ShowRoof) = (_showWalls.Checked, _showFloors.Checked, _showRoof.Checked));
+ }
+
+ private void SaveDraft_Click(object sender, EventArgs e)
+ {
+ SaveDraft?.Invoke();
+ Used?.Invoke();
+ }
+
+ private void OpenDraft_Click(object sender, EventArgs e)
+ {
+ OpenDraft?.Invoke();
+ Used?.Invoke();
+ }
+
+ private void Blueprint_Click(object sender, EventArgs e)
+ {
+ SaveBlueprint?.Invoke();
+ Used?.Invoke();
+ }
+
+ private void Edit_Click(object sender, EventArgs e)
+ {
+ if (_placed.SelectedItem is PlacedHouse placed)
+ {
+ EditHouse?.Invoke(placed.House);
+ Used?.Invoke();
+ }
+ }
+
private void Run(Action action)
{
if (_updating || _session == null)
diff --git a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.Designer.cs b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.Designer.cs
index 9cb96933..91afa961 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.Designer.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.Designer.cs
@@ -324,7 +324,7 @@ private void InitializeComponent()
_shapeLabel.Name = "_shapeLabel";
_shapeLabel.Size = new System.Drawing.Size(39, 22);
_shapeLabel.Text = "Shape";
- _shapeLabel.ToolTipText = "Gable: two slopes and a ridge.";
+ _shapeLabel.ToolTipText = "Gable: two slopes and a ridge. Hip: four slopes, no gable ends.";
//
// _ridgeSeparator
//
diff --git a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
index 2d571e83..cd0b086d 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
@@ -59,15 +59,29 @@ public MultiEditorControl()
InitializeComponent();
SplitterGrip.Attach(_sideSplit);
- // The house draft's panel sits above the floors and selection; shown with the House tool or an open draft.
- _housePanel = new HousePanel { Dock = DockStyle.Top, Visible = false };
+ // The right sidebar has two pages: the design (floors, layers, selection) and the
+ // house draft, which is too tall to share a page. The House page scrolls when the
+ // window is short, and comes to the front with the House tool or an open draft.
+ _housePanel = new HousePanel { Dock = DockStyle.Top };
_housePanel.PickStyle += PickHouseMaterial;
+ _housePanel.SaveDraft += SaveHouseDraft;
+ _housePanel.OpenDraft += OpenHouseDraft;
+ _housePanel.SaveBlueprint += SaveHouseBlueprint;
+ _housePanel.EditHouse += EditPlacedHouse;
_housePanel.Used += () =>
{
_commands.RefreshStates();
_canvas.Focus();
};
- _sideSplit.Panel2.Controls.Add(_housePanel);
+ _designPage = new TabPage("Design");
+ _housePage = new TabPage("House draft") { AutoScroll = true };
+ _sideSplit.Panel2.Controls.Remove(_inspector);
+ _designPage.Controls.Add(_inspector);
+ _housePage.Controls.Add(_housePanel);
+ _sideTabs = new UoFiddler.Controls.UserControls.ThemedTabControl { Dock = DockStyle.Fill };
+ _sideTabs.TabPages.Add(_designPage);
+ _sideTabs.TabPages.Add(_housePage);
+ _sideSplit.Panel2.Controls.Add(_sideTabs);
// Room after each tab's text for its close button, at any DPI.
_docTabs.Padding = new Point((CloseGlyphSize + LogicalToDeviceUnits(16)) / 2, _docTabs.Padding.Y);
@@ -675,6 +689,13 @@ private void ChooseHouseStyle(HouseStyle style)
return;
}
+ // The House page names its current style when it is brought up for a pick of the
+ // house panel: that is not the pick, which is the next style clicked there.
+ if (_housePick != null && _openingHousePage)
+ {
+ return;
+ }
+
// A pick asked for by the house panel is a material of the draft, not a tool's style.
if (_housePick is { } pick && pick.Kind == style.Kind)
{
@@ -685,6 +706,18 @@ private void ChooseHouseStyle(HouseStyle style)
}
_housePick = null;
+
+ // With the House tool in use, a wall, floor or roof style clicked on the House page is
+ // a material of the house too: of the storey the chosen floor means, or of every
+ // storey with all floors shown. Doors and stairs have tools of their own.
+ if (Session.Tool == ToolKind.House && style.Kind is HousePartKind.Wall or HousePartKind.Floor or HousePartKind.Roof)
+ {
+ int? storey = style.Kind == HousePartKind.Roof || Session.WorkZ == null ? null : Session.DraftStorey;
+ Session.House.SetMaterial(style, storey);
+ _canvas.Focus();
+ return;
+ }
+
Session.HouseStyle = style;
ToolKind kind = style.Kind switch
{
@@ -726,6 +759,113 @@ private void PickHouseMaterial(HousePartKind kind, int storey)
: $"Pick the {(kind == HousePartKind.Wall ? "wall" : "floor")} style of storey {storey + 1} on the House page.";
}
+ private static string HouseDraftFolder
+ {
+ get
+ {
+ string folder = System.IO.Path.Combine(Options.AppDataPath, "MultiEditorHouses");
+ System.IO.Directory.CreateDirectory(folder);
+ return folder;
+ }
+ }
+
+ /// Writes the house being designed to a house draft file, to open again in any design.
+ private void SaveHouseDraft()
+ {
+ if (Session == null || !Session.House.HasPending)
+ {
+ return;
+ }
+
+ using var dialog = new SaveFileDialog
+ {
+ Title = "Save house draft", Filter = HouseDraftFile.Filter, DefaultExt = HouseDraftFile.Extension,
+ InitialDirectory = HouseDraftFolder, FileName = "House"
+ };
+ if (dialog.ShowDialog(this) != DialogResult.OK)
+ {
+ return;
+ }
+
+ try
+ {
+ new System.Xml.Linq.XDocument(Session.House.ToXml(System.IO.Path.GetFileNameWithoutExtension(dialog.FileName))).Save(dialog.FileName);
+ }
+ catch (Exception ex) when (ex is System.IO.IOException or UnauthorizedAccessException)
+ {
+ MessageBox.Show(this, "The house draft could not be saved:\r\n" + ex.Message, "Multi Editor", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ }
+ }
+
+ /// Opens a house draft file as the draft of the House tool; the draft being designed can be had back with undo.
+ private void OpenHouseDraft()
+ {
+ if (Session == null)
+ {
+ return;
+ }
+
+ using var dialog = new OpenFileDialog { Title = "Open house draft", Filter = HouseDraftFile.Filter, InitialDirectory = HouseDraftFolder };
+ if (dialog.ShowDialog(this) != DialogResult.OK)
+ {
+ return;
+ }
+
+ try
+ {
+ Session.House.OpenXml(System.Xml.Linq.XDocument.Load(dialog.FileName).Root);
+ SetTool(ToolKind.House);
+ }
+ catch (Exception ex) when (ex is System.IO.IOException or UnauthorizedAccessException or System.Xml.XmlException or System.IO.InvalidDataException)
+ {
+ MessageBox.Show(this, "The house draft could not be opened:\r\n" + ex.Message, "Multi Editor", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ }
+ }
+
+ /// Saves the house being designed, as built, to the blueprints: tiles to stamp, not a draft.
+ private void SaveHouseBlueprint()
+ {
+ if (Session == null || !Session.House.HasPending)
+ {
+ return;
+ }
+
+ var built = Session.House.TilesOf(Session.House.ToXml("House"));
+ if (built.Count == 0)
+ {
+ return;
+ }
+
+ int ox = built.Min(t => t.X), oy = built.Min(t => t.Y), oz = built.Min(t => t.Z);
+ List tiles = built.Select(t => new ClipboardTile(t.Id, t.X - ox, t.Y - oy, t.Z - oz, false, 0)).ToList();
+ var source = new BlueprintSource("House", tiles.Count, () => tiles);
+ if (BlueprintSaveDialog.Run(this, new[] { source }, out string showGroup) != null)
+ {
+ BlueprintsSaved(showGroup);
+ }
+ }
+
+ /// Opens a placed house as a draft again.
+ private void EditPlacedHouse(System.Xml.Linq.XElement house)
+ {
+ if (Session == null || house == null)
+ {
+ return;
+ }
+
+ string problem = Session.ReopenHouse(house);
+ if (problem != null)
+ {
+ MessageBox.Show(this, problem, "Multi Editor", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ else
+ {
+ SetTool(ToolKind.House);
+ }
+
+ _commands.RefreshStates();
+ }
+
private void CyclePlacement()
{
Session.Placement = (PlacementMode)(((int)Session.Placement + 1) % 3);
@@ -1395,24 +1535,38 @@ private void BuildOptionsStrip()
strip.Items.Insert(at++, button);
}
- // Roof options, shown only with the Roof tool.
- RoofGroup(strip, _shapeSeparator, _shapeLabel,
- ("Gable", () => Session.Roof.Shape == RoofShape.Gable, () => Session.Roof.Shape = RoofShape.Gable));
- RoofGroup(strip, _ridgeSeparator, _ridgeLabel,
+ // Roof and draft options get a row of their own under the tool options, shown only
+ // while they apply: beside the other options they ended up far to the right.
+ _roofStrip = new ToolStrip { GripStyle = ToolStripGripStyle.Hidden, Dock = DockStyle.Top, Visible = false, Renderer = strip.Renderer, RenderMode = strip.RenderMode };
+ foreach (ToolStripItem item in new ToolStripItem[]
+ {
+ _shapeSeparator, _shapeLabel, _ridgeSeparator, _ridgeLabel, _gablesSeparator, _gablesLabel, _gableFillSeparator, _gableFillLabel
+ })
+ {
+ _roofStrip.Items.Add(item);
+ }
+
+ Controls.Add(_roofStrip);
+ Controls.SetChildIndex(_roofStrip, Controls.GetChildIndex(_optionsStrip));
+ RoofGroup(_roofStrip, _shapeSeparator, _shapeLabel,
+ ("Gable", () => Session.Roof.Shape == RoofShape.Gable, () => Session.Roof.Shape = RoofShape.Gable),
+ ("Hip", () => Session.Roof.Shape == RoofShape.Hip, () => Session.Roof.Shape = RoofShape.Hip));
+ RoofGroup(_roofStrip, _ridgeSeparator, _ridgeLabel,
("Auto", () => Session.Roof.Ridge == RoofRidge.Auto, () => Session.Roof.Ridge = RoofRidge.Auto),
("X", () => Session.Roof.Ridge == RoofRidge.AlongX, () => Session.Roof.Ridge = RoofRidge.AlongX),
("Y", () => Session.Roof.Ridge == RoofRidge.AlongY, () => Session.Roof.Ridge = RoofRidge.AlongY));
- RoofGroup(strip, _gablesSeparator, _gablesLabel,
+ RoofGroup(_roofStrip, _gablesSeparator, _gablesLabel,
("Front", () => Session.Roof.Gables == RoofGables.Front, () => Session.Roof.Gables = RoofGables.Front),
("Both", () => Session.Roof.Gables == RoofGables.Both, () => Session.Roof.Gables = RoofGables.Both),
("None", () => Session.Roof.Gables == RoofGables.None, () => Session.Roof.Gables = RoofGables.None));
- RoofGroup(strip, _gableFillSeparator, _gableFillLabel,
+ RoofGroup(_roofStrip, _gableFillSeparator, _gableFillLabel,
("Caps", () => Session.Roof.GableFill == RoofGableFill.Caps, () => Session.Roof.GableFill = RoofGableFill.Caps),
("Walls", () => Session.Roof.GableFill == RoofGableFill.Walls, () => Session.Roof.GableFill = RoofGableFill.Walls));
// Shown while a roof is being shaped.
- _placeRoofButton = RoofAction(strip, "Place", "Places what is being shaped: the roof on the Roof layer, the house on its layers (Enter).", () => Session.DraftInFocus?.Commit());
- _dropRoofButton = RoofAction(strip, "Drop", "Drops what is being shaped (Esc). Undo brings it back.", () => Session.DraftInFocus?.Discard());
+ _placeRoofButton = RoofAction(_roofStrip, "Place", "Places what is being shaped: the roof on the Roof layer, the house on its layers (Enter).", () => Session.DraftInFocus?.Commit());
+ _dropRoofButton = RoofAction(_roofStrip, "Drop", "Drops what is being shaped (Esc). Undo brings it back.", () => Session.DraftInFocus?.Discard());
+ StyleSeparators(_roofStrip);
}
/// What the tool in use does to the open house draft.
@@ -1435,7 +1589,12 @@ private void ZStepCombo_SelectedIndexChanged(object sender, EventArgs e)
}
private readonly HousePanel _housePanel;
+ private readonly TabControl _sideTabs;
+ private readonly TabPage _designPage;
+ private readonly TabPage _housePage;
+ private bool _houseWasShown;
private (HousePartKind Kind, int Storey)? _housePick;
+ private ToolStrip _roofStrip;
private EditorCommand _placeRoof;
private ToolStripButton _placeRoofButton;
private ToolStripButton _dropRoofButton;
@@ -1510,12 +1669,24 @@ private void SyncRoofOptions()
item.Visible = show;
}
- _placeRoofButton.Visible = _dropRoofButton.Visible = Session != null && !Session.Pasting && Session.DraftInFocus != null;
+ bool draft = Session != null && !Session.Pasting && Session.DraftInFocus != null;
+ _placeRoofButton.Visible = _dropRoofButton.Visible = draft;
+
+ // The first group needs no line before it on a row of its own.
+ _shapeSeparator.Visible = false;
+ if (_roofStrip.Visible != (show || draft))
+ {
+ _roofStrip.Visible = show || draft;
+ }
+ // The House page comes to the front when the House tool is taken up or a draft is
+ // opened, and gives way again when both are over; in between the pages are yours.
bool house = Session != null && (Session.Tool == ToolKind.House || Session.House.HasPending);
- if (_housePanel.Visible != house)
+ _housePanel.RefreshDraft();
+ if (house != _houseWasShown)
{
- _housePanel.Visible = house;
+ _houseWasShown = house;
+ _sideTabs.SelectedTab = house ? _housePage : _designPage;
}
foreach ((ToolStripButton button, Func isOn) in _roofButtons)
@@ -1656,6 +1827,7 @@ private void AddDocument(OpenedMulti opened)
LayerStore.Load(clientId, document.Session.CompList.Fingerprint(origin)) is { } saved)
{
document.Session.RestoreLayers(saved.Layers, saved.Active, origin);
+ document.Session.SetPlacedHouses(saved.Houses, origin.X, origin.Y);
}
ShowDocument(document);
}
@@ -1724,7 +1896,8 @@ private void SaveToClient()
try
{
- LayerStore.Save(id.Value, list.SaveLayers(includeHidden), list.Layers.ToList().IndexOf(list.ActiveLayer), list.Fingerprint(list.SaveOrigin, includeHidden));
+ LayerStore.Save(id.Value, list.SaveLayers(includeHidden), list.Layers.ToList().IndexOf(list.ActiveLayer), list.Fingerprint(list.SaveOrigin, includeHidden),
+ Session.PlacedHousesShifted(-list.SaveOrigin.X, -list.SaveOrigin.Y));
}
catch (Exception ex) when (ex is System.IO.IOException or UnauthorizedAccessException or ArgumentException or System.Xml.XmlException)
{
From b100810cd43f6eb925a6d416dd16bb875b43f48d Mon Sep 17 00:00:00 2001
From: AsY!um- <377468+AsYlum-@users.noreply.github.com>
Date: Wed, 18 Nov 2026 22:33:10 +0100
Subject: [PATCH 05/16] Read house styles from a style file and complete the
wall sets
Wall styles named by material and kind; shadow, celtic, gargish and gothic sets built from their plain pieces.
---
.../Classes/GroupTransform.cs | 23 +
.../Classes/HouseDraft.cs | 9 +-
.../Classes/HouseDraftFile.cs | 6 +
.../Classes/HouseStyleConfig.cs | 298 +++++++
.../Classes/HouseStyles.cs | 727 ++++++++++++++-
.../Classes/WallPlanner.cs | 49 +-
.../MultiEditorHouseStyles.xml | 831 ++++++++++++++++++
.../Tools/HouseTool.cs | 15 +-
.../Tools/RoofTool.cs | 31 +-
UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs | 13 +-
.../UI/MultiEditorControl.cs | 14 +-
.../UI/TileBrowserPanel.cs | 4 +-
.../UoFiddler.Plugin.MultiEditor.csproj | 3 +
13 files changed, 1986 insertions(+), 37 deletions(-)
create mode 100644 UoFiddler.Plugin.MultiEditor/Classes/HouseStyleConfig.cs
create mode 100644 UoFiddler.Plugin.MultiEditor/MultiEditorHouseStyles.xml
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/GroupTransform.cs b/UoFiddler.Plugin.MultiEditor/Classes/GroupTransform.cs
index e7f60b81..35eb222c 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/GroupTransform.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/GroupTransform.cs
@@ -469,8 +469,31 @@ private static string TurnSlot(string slot, Func mapDirection, b
}
}
+ // Eave + side, Hip + corner and HipEave + corner (ceramic, crystal and shadow sets).
+ if (slot.StartsWith("Eave", StringComparison.Ordinal) && _directions.ContainsKey(slot.Substring(4)))
+ {
+ return "Eave" + mapDirection(slot.Substring(4));
+ }
+
+ foreach (string prefix in new[] { "HipEave", "Hip" })
+ {
+ if (slot.Length == prefix.Length + 2 && slot.StartsWith(prefix, StringComparison.Ordinal))
+ {
+ // A corner is two sides: both turn, and north or south is named first.
+ string first = mapDirection(_directions.Keys.First(d => d[0] == slot[^2]));
+ string second = mapDirection(_directions.Keys.First(d => d[0] == slot[^1]));
+ (string ns, string ew) = first[0] is 'N' or 'S' ? (first, second) : (second, first);
+ return prefix + ns[0] + ew[0];
+ }
+ }
+
if (swapsAxes)
{
+ if (slot is "NSEnd" or "EWEnd")
+ {
+ return slot == "NSEnd" ? "EWEnd" : "NSEnd";
+ }
+
if (slot == "NSCrosspiece")
{
return "EWCrosspiece";
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
index 1ddff348..22c5e9c7 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
@@ -44,6 +44,9 @@ internal sealed class HouseDraft
public HouseStyle RoofStyle { get; set; }
+ /// The floor style a flat roof is laid in; without one, the floor style of the wing's top storey.
+ public HouseStyle FlatRoofStyle { get; set; }
+
public bool Foundation { get; set; }
/// Most rooms a wing can be divided into.
@@ -109,7 +112,7 @@ public HouseDraft Clone()
/// A draft with the same materials and nothing changed by hand: the next house.
public HouseDraft Fresh()
{
- var copy = new HouseDraft { RoofStyle = RoofStyle, Foundation = Foundation };
+ var copy = new HouseDraft { RoofStyle = RoofStyle, FlatRoofStyle = FlatRoofStyle, Foundation = Foundation };
Array.Copy(WallStyles, copy.WallStyles, MaxStoreys);
Array.Copy(FloorStyles, copy.FloorStyles, MaxStoreys);
return copy;
@@ -371,7 +374,7 @@ public Built Build(IReadOnlyList wings, HouseStyles styles)
continue;
}
- string column = WallPlanner.PieceFor(south, east, x, y);
+ string column = WallPlanner.PieceFor(wallStyle, south, east, x, y);
if (column == null || wallStyle == null)
{
continue;
@@ -429,7 +432,7 @@ public Built Build(IReadOnlyList wings, HouseStyles styles)
foreach (RoofWing wing in wings)
{
int storeys = Math.Clamp(wing.Storeys, 1, MaxStoreys);
- HouseStyle style = FloorStyles[storeys - 1];
+ HouseStyle style = FlatRoofStyle ?? FloorStyles[storeys - 1];
if (wing.NoRoof || wing.Shape != RoofShape.Flat || style == null)
{
continue;
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs
index 2d3f0896..85fd18c2 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs
@@ -50,6 +50,11 @@ public static XElement ToXml(IReadOnlyList wings, HouseDraft draft, st
root.Add(new XAttribute("roof", draft.RoofStyle.Name));
}
+ if (draft.FlatRoofStyle != null)
+ {
+ root.Add(new XAttribute("flatRoof", draft.FlatRoofStyle.Name));
+ }
+
foreach (RoofWing wing in wings)
{
root.Add(new XElement("Wing",
@@ -149,6 +154,7 @@ HouseStyle Style(HousePartKind kind, string name) =>
// A draft saved before rooms were set per wing names one count for the house.
int houseRooms = (int?)root.Attribute("rooms") ?? 1;
draft.RoofStyle = Style(HousePartKind.Roof, (string)root.Attribute("roof")) ?? draft.RoofStyle;
+ draft.FlatRoofStyle = Style(HousePartKind.Floor, (string)root.Attribute("flatRoof")) ?? draft.FlatRoofStyle;
var wings = new List();
foreach (XElement element in root.Elements("Wing"))
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseStyleConfig.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseStyleConfig.cs
new file mode 100644
index 00000000..a4786c3f
--- /dev/null
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseStyleConfig.cs
@@ -0,0 +1,298 @@
+/***************************************************************************
+ *
+ * $Author: Turley
+ *
+ * "THE BEER-WARE LICENSE"
+ * As long as you retain this notice you can do whatever you want with
+ * this stuff. If we meet some day, and you think this stuff is worth it,
+ * you can buy me a beer in return.
+ *
+ ***************************************************************************/
+
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Xml;
+using System.Xml.Linq;
+using UoFiddler.Controls.Classes;
+
+namespace UoFiddler.Plugin.MultiEditor.Classes
+{
+ /// One Style element of the style file: what it says about one house style.
+ internal sealed class HouseStyleEntry
+ {
+ public const string LayoutRun = "Run";
+ public const string LayoutPaired = "Paired";
+ public const string LayoutCycle = "Cycle";
+
+ public HousePartKind Kind { get; set; }
+
+ /// A piece of the style: the entry is about the first style of its kind that lists it.
+ public ushort Anchor { get; set; }
+
+ /// True for a style the tables do not have: it is made from the entry's pieces.
+ public bool IsNew { get; set; }
+
+ /// Pieces of further styles this one takes the place of.
+ public List Replaces { get; } = new List();
+
+ public string Name { get; set; }
+
+ public string Group { get; set; }
+
+ public string Family { get; set; }
+
+ public bool? Hidden { get; set; }
+
+ /// How a wall run is laid: , or . Null leaves it.
+ public string Layout { get; set; }
+
+ public bool? Borrows { get; set; }
+
+ /// The style's pieces by column label, in place of the table's. Null keeps the table's.
+ public List<(string Role, ushort Id)> Pieces { get; set; }
+
+ public (HousePartKind Kind, ushort Anchor, bool IsNew) Key => (Kind, Anchor, IsNew);
+ }
+
+ ///
+ /// The style file (MultiEditorHouseStyles.xml): names, groups, order and corrected pieces for
+ /// the house styles read from the client's tables. One ships beside the plugin; a file of the
+ /// same name in the profile's plugins folder holds the user's changes, entry by entry, on
+ /// top of it.
+ ///
+ internal sealed class HouseStyleConfig
+ {
+ public const string FileName = "MultiEditorHouseStyles.xml";
+
+ private const string _root = "HouseStyles";
+ private const int _version = 1;
+
+ public List Styles { get; } = new List();
+
+ public List Errors { get; } = new List();
+
+ public static string ShippedPath
+ {
+ get
+ {
+ string folder = Path.GetDirectoryName(typeof(HouseStyleConfig).Assembly.Location);
+ return string.IsNullOrEmpty(folder) ? null : Path.Combine(folder, FileName);
+ }
+ }
+
+ public static string UserPath => string.IsNullOrEmpty(Options.AppDataPath) ? null : Path.Combine(Options.AppDataPath, "plugins", FileName);
+
+ /// The shipped file with the user's file on top. A file that is missing or cannot be read counts as empty.
+ public static HouseStyleConfig Load()
+ {
+ HouseStyleConfig config = LoadFile(ShippedPath);
+ config.Merge(LoadFile(UserPath));
+ return config;
+ }
+
+ public static HouseStyleConfig LoadFile(string path)
+ {
+ var config = new HouseStyleConfig();
+ if (string.IsNullOrEmpty(path) || !File.Exists(path))
+ {
+ return config;
+ }
+
+ try
+ {
+ XElement root = XDocument.Load(path).Root;
+ if (root == null || root.Name.LocalName != _root)
+ {
+ config.Errors.Add($"{Path.GetFileName(path)}: not a house style file");
+ return config;
+ }
+
+ if (ParseInt((string)root.Attribute("version")) > _version)
+ {
+ config.Errors.Add($"{Path.GetFileName(path)}: written by a newer version of the editor");
+ return config;
+ }
+
+ foreach (XElement element in root.Elements("Style"))
+ {
+ HouseStyleEntry entry = ReadStyle(element);
+ if (entry != null)
+ {
+ config.Styles.Add(entry);
+ }
+ else
+ {
+ config.Errors.Add($"{Path.GetFileName(path)}: a Style without a kind or an anchor (line {((IXmlLineInfo)element).LineNumber})");
+ }
+ }
+ }
+ catch (Exception ex) when (ex is IOException or XmlException or UnauthorizedAccessException)
+ {
+ config.Errors.Add($"{Path.GetFileName(path)}: {ex.Message}");
+ }
+
+ return config;
+ }
+
+ ///
+ /// Lays another file's entries over these. An entry for a style both name takes the other
+ /// file's values where it gives any; its other entries are added at the end.
+ ///
+ public void Merge(HouseStyleConfig other)
+ {
+ Dictionary<(HousePartKind, ushort, bool), HouseStyleEntry> mine = Styles
+ .GroupBy(entry => entry.Key)
+ .ToDictionary(group => group.Key, group => group.First());
+ foreach (HouseStyleEntry theirs in other.Styles)
+ {
+ if (!mine.TryGetValue(theirs.Key, out HouseStyleEntry entry))
+ {
+ Styles.Add(theirs);
+ mine[theirs.Key] = theirs;
+ continue;
+ }
+
+ entry.Name = theirs.Name ?? entry.Name;
+ entry.Group = theirs.Group ?? entry.Group;
+ entry.Family = theirs.Family ?? entry.Family;
+ entry.Hidden = theirs.Hidden ?? entry.Hidden;
+ entry.Layout = theirs.Layout ?? entry.Layout;
+ entry.Borrows = theirs.Borrows ?? entry.Borrows;
+ entry.Pieces = theirs.Pieces ?? entry.Pieces;
+ if (theirs.Replaces.Count > 0)
+ {
+ entry.Replaces.Clear();
+ entry.Replaces.AddRange(theirs.Replaces);
+ }
+ }
+
+ Errors.AddRange(other.Errors);
+ }
+
+ public void Save(string path)
+ {
+ var root = new XElement(_root, new XAttribute("version", _version));
+ foreach (HouseStyleEntry entry in Styles)
+ {
+ root.Add(WriteStyle(entry));
+ }
+
+ Directory.CreateDirectory(Path.GetDirectoryName(path) ?? string.Empty);
+ new XDocument(root).Save(path);
+ }
+
+ private static HouseStyleEntry ReadStyle(XElement element)
+ {
+ if (!Enum.TryParse((string)element.Attribute("kind"), out HousePartKind kind) ||
+ !TryParseId((string)element.Attribute("anchor"), out ushort anchor) || anchor == 0)
+ {
+ return null;
+ }
+
+ var entry = new HouseStyleEntry
+ {
+ Kind = kind,
+ Anchor = anchor,
+ IsNew = (bool?)element.Attribute("new") ?? false,
+ Name = (string)element.Attribute("name"),
+ Group = (string)element.Attribute("group"),
+ Family = (string)element.Attribute("family"),
+ Hidden = (bool?)element.Attribute("hidden"),
+ Layout = (string)element.Attribute("layout"),
+ Borrows = (bool?)element.Attribute("borrows")
+ };
+ foreach (string text in ((string)element.Attribute("replaces") ?? string.Empty).Split(' ', StringSplitOptions.RemoveEmptyEntries))
+ {
+ if (TryParseId(text, out ushort id))
+ {
+ entry.Replaces.Add(id);
+ }
+ }
+
+ List pieces = element.Elements("Piece").ToList();
+ if (pieces.Count > 0)
+ {
+ entry.Pieces = new List<(string, ushort)>();
+ foreach (XElement piece in pieces)
+ {
+ string role = (string)piece.Attribute("role");
+ if (!string.IsNullOrEmpty(role) && TryParseId((string)piece.Attribute("id"), out ushort id))
+ {
+ entry.Pieces.Add((role, id));
+ }
+ }
+ }
+
+ return entry;
+ }
+
+ private static XElement WriteStyle(HouseStyleEntry entry)
+ {
+ var element = new XElement("Style",
+ new XAttribute("kind", entry.Kind),
+ new XAttribute("anchor", FormatId(entry.Anchor)));
+ if (entry.IsNew)
+ {
+ element.Add(new XAttribute("new", true));
+ }
+
+ if (entry.Replaces.Count > 0)
+ {
+ element.Add(new XAttribute("replaces", string.Join(" ", entry.Replaces.Select(FormatId))));
+ }
+
+ AddText(element, "name", entry.Name);
+ AddText(element, "group", entry.Group);
+ AddText(element, "family", entry.Family);
+ AddText(element, "layout", entry.Layout);
+ if (entry.Hidden.HasValue)
+ {
+ element.Add(new XAttribute("hidden", entry.Hidden.Value));
+ }
+
+ if (entry.Borrows.HasValue)
+ {
+ element.Add(new XAttribute("borrows", entry.Borrows.Value));
+ }
+
+ if (entry.Pieces != null)
+ {
+ foreach ((string role, ushort id) in entry.Pieces)
+ {
+ element.Add(new XElement("Piece", new XAttribute("role", role), new XAttribute("id", FormatId(id))));
+ }
+ }
+
+ return element;
+ }
+
+ private static void AddText(XElement element, string name, string value)
+ {
+ if (value != null)
+ {
+ element.Add(new XAttribute(name, value));
+ }
+ }
+
+ public static string FormatId(ushort id) => "0x" + id.ToString("X4", CultureInfo.InvariantCulture);
+
+ public static bool TryParseId(string text, out ushort id)
+ {
+ id = 0;
+ if (string.IsNullOrWhiteSpace(text))
+ {
+ return false;
+ }
+
+ text = text.Trim();
+ return text.StartsWith("0x", StringComparison.OrdinalIgnoreCase)
+ ? ushort.TryParse(text.AsSpan(2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out id)
+ : ushort.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out id);
+ }
+
+ private static int ParseInt(string text) => int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out int value) ? value : 0;
+ }
+}
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseStyles.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseStyles.cs
index 0d2d73d5..edf66c74 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/HouseStyles.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseStyles.cs
@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using UoFiddler.Controls.Classes.TilesInfo;
namespace UoFiddler.Plugin.MultiEditor.Classes
@@ -44,12 +45,46 @@ public HouseStyle(HousePartKind kind, string group, string name)
public HousePartKind Kind { get; }
/// The category name (the first style's comment), grouping a material's styles.
- public string Group { get; }
+ public string Group { get; internal set; }
- public string Name { get; }
+ public string Name { get; internal set; }
+
+ /// The material, shared by the styles of every kind made of it. From the style file; may be empty.
+ public string Family { get; internal set; } = string.Empty;
+
+ /// True for a style the style file keeps out of the lists.
+ public bool Hidden { get; internal set; }
+
+ /// A piece that tells the style from every other of its kind: how files refer to it. 0 when it has none.
+ public ushort Anchor { get; internal set; }
+
+ /// False for a wall style that takes no post or corner from the other rows of its category.
+ internal bool Borrows { get; set; } = true;
+
+ /// The table category the style was read from, counted over all tables.
+ internal int Category { get; set; } = -1;
+
+ /// True for a wall style of a category sorted by its art.
+ internal bool ByArt { get; set; }
public IReadOnlyDictionary Slots => _slots;
+ ///
+ /// True for a wall style whose run pieces are the two halves of an ornament (the shadow
+ /// banner): South1 and South3 along X, East3 and East1 along Y, with South2 and East2 the
+ /// plain wall. A run is then laid as pairs, not as start, middle and end.
+ ///
+ public bool Paired { get; internal set; }
+
+ ///
+ /// For a wall style that is a set of different panels (the carved red marble): how many
+ /// it has along X (CycleSouth1 ...) and along Y (CycleEast1 ...). A run is laid as one
+ /// panel after another, starting again after the last. 0 for an ordinary style.
+ ///
+ public int CycleSouth { get; internal set; }
+
+ public int CycleEast { get; internal set; }
+
/// A piece to show for the style in lists.
public ushort IconId { get; private set; }
@@ -65,6 +100,12 @@ internal void Add(string label, ushort id)
}
}
+ internal void Clear()
+ {
+ _slots.Clear();
+ IconId = 0;
+ }
+
public override string ToString() => Name;
}
@@ -104,15 +145,23 @@ private HouseStyles()
///
/// Reads the tables. With a floors.txt row, which is a
/// palette of up to 16 tiles often in several colours, becomes one style per colour, so a
- /// floor laid with a style does not mix them.
+ /// floor laid with a style does not mix them. The style file ()
+ /// then names, groups, orders and corrects what the tables give.
///
public static HouseStyles Load(bool splitFloorsByColour = false)
+ {
+ return Load(splitFloorsByColour, HouseStyleConfig.Load());
+ }
+
+ internal static HouseStyles Load(bool splitFloorsByColour, HouseStyleConfig config)
{
// New tables mean the client files may have changed: measure the art again.
ArtFacing.Clear();
var result = new HouseStyles();
+ var wallNamesUsed = new HashSet(System.StringComparer.OrdinalIgnoreCase);
List files = TileGroupRegistry.LoadAll(out List errors);
+ int categoryNumber = 0;
foreach (TileGroupFile file in files)
{
if (!_kinds.TryGetValue(file.DisplayName, out HousePartKind kind))
@@ -122,19 +171,48 @@ public static HouseStyles Load(bool splitFloorsByColour = false)
foreach (TileCategory category in file.Categories)
{
- foreach (TileStyle tileStyle in category.Styles)
+ int number = categoryNumber++;
+
+ // A roof set with more pieces than a row of roof.txt holds runs on into a second
+ // row of its category: the rows are one style.
+ if (kind == HousePartKind.Roof)
{
- var style = new HouseStyle(kind, category.Name, tileStyle.Name);
- foreach (TileSlot slot in tileStyle.Slots)
+ HouseStyle roof = RoofStyle(category);
+ if (roof.Slots.Count > 0)
{
- // Stairs list stair multis; they are multi ids, not art.
- bool multiColumn = slot.Label.StartsWith("Multi", System.StringComparison.Ordinal);
- if (slot.IsEmpty || slot.TileId > ushort.MaxValue || (!multiColumn && !slot.IsValid))
+ roof.Category = number;
+ result.Styles.Add(roof);
+ }
+
+ continue;
+ }
+
+ // A category whose pieces are mostly not what their headings say is sorted by its art.
+ bool byArt = kind == HousePartKind.Wall && HeadingsAreOff(category);
+
+ // Wall rows are named so that each row of a category can be told from the others.
+ (string wallGroup, List wallNames) = kind == HousePartKind.Wall ? WallNames(category, wallNamesUsed, byArt) : (null, null);
+ for (int row = 0; row < category.Styles.Count; ++row)
+ {
+ TileStyle tileStyle = category.Styles[row];
+ var style = new HouseStyle(kind, wallGroup ?? category.Name, wallNames != null ? wallNames[row] : tileStyle.Name);
+ if (byArt)
+ {
+ SortByArt(style, PiecesOf(tileStyle), WindowPieces(tileStyle));
+ }
+ else
+ {
+ foreach (TileSlot slot in tileStyle.Slots)
{
- continue;
- }
+ // Stairs list stair multis; they are multi ids, not art.
+ bool multiColumn = IsMultiColumn(slot.Label);
+ if (slot.IsEmpty || slot.TileId > ushort.MaxValue || (!multiColumn && !slot.IsValid))
+ {
+ continue;
+ }
- style.Add(slot.Label, (ushort)slot.TileId);
+ style.Add(slot.Label, (ushort)slot.TileId);
+ }
}
if (style.Slots.Count == 0)
@@ -147,24 +225,633 @@ public static HouseStyles Load(bool splitFloorsByColour = false)
: new[] { style };
foreach (HouseStyle part in parts)
{
+ part.Category = number;
+ part.ByArt = byArt;
result.Styles.Add(part);
- foreach (KeyValuePair piece in part.Slots)
- {
- // Stair multi columns hold multi ids, not art.
- if (!piece.Key.StartsWith("Multi", System.StringComparison.Ordinal))
- {
- result._roles.TryAdd(piece.Value, (part, piece.Key));
- }
- }
}
}
}
}
+ result.Apply(config);
+ result.BuildRoles();
+ result.FinishWalls();
+ result.Order();
+
result.Errors.AddRange(errors);
+ if (config != null)
+ {
+ result.Errors.AddRange(config.Errors);
+ }
+
return result;
}
+ /// Stairs list stair multis under "Multi" columns: multi ids, not art.
+ private static bool IsMultiColumn(string label) => label.StartsWith("Multi", System.StringComparison.Ordinal);
+
+ // Where each style named by the style file comes in the lists.
+ private readonly Dictionary _rank = new Dictionary();
+
+ ///
+ /// Applies the style file to the styles read from the tables. An entry finds its style by
+ /// a piece (its anchor): the first style of the kind that lists it. It can rename and
+ /// regroup the style, give it other pieces, and take the place of further styles (a set
+ /// the table spreads over several rows). An entry whose pieces this client has no art for
+ /// is left out, so one file serves every client.
+ ///
+ private void Apply(HouseStyleConfig config)
+ {
+ var owners = new Dictionary<(HousePartKind Kind, ushort Id), HouseStyle>();
+ foreach (HouseStyle style in Styles)
+ {
+ foreach (KeyValuePair piece in style.Slots)
+ {
+ if (!IsMultiColumn(piece.Key))
+ {
+ owners.TryAdd((style.Kind, piece.Value), style);
+ }
+ }
+ }
+
+ foreach (HouseStyle style in Styles)
+ {
+ foreach (KeyValuePair piece in style.Slots)
+ {
+ if (!IsMultiColumn(piece.Key) && owners[(style.Kind, piece.Value)] == style)
+ {
+ style.Anchor = piece.Value;
+ break;
+ }
+ }
+ }
+
+ if (config == null)
+ {
+ return;
+ }
+
+ var removed = new HashSet();
+ foreach (HouseStyleEntry entry in config.Styles)
+ {
+ List<(string Role, ushort Id)> pieces = entry.Pieces?
+ .Where(piece => IsMultiColumn(piece.Role) || (piece.Id < Ultima.TileData.ItemTable.Length && Ultima.Art.IsValidStatic(piece.Id)))
+ .ToList();
+ if (pieces != null && !pieces.Any(piece => !IsMultiColumn(piece.Role)))
+ {
+ continue;
+ }
+
+ HouseStyle target = null;
+ if (!entry.IsNew)
+ {
+ owners.TryGetValue((entry.Kind, entry.Anchor), out target);
+ }
+
+ if (target == null)
+ {
+ // A style of the file's own. It stands where the first style it replaces stood.
+ if (pieces == null)
+ {
+ continue;
+ }
+
+ HouseStyle first = null;
+ foreach (ushort id in entry.Replaces)
+ {
+ if (owners.TryGetValue((entry.Kind, id), out first))
+ {
+ break;
+ }
+ }
+
+ target = new HouseStyle(entry.Kind, entry.Group ?? entry.Name ?? string.Empty, entry.Name ?? string.Empty)
+ {
+ Category = first?.Category ?? -1,
+ ByArt = first?.ByArt ?? false
+ };
+ int at = first != null ? Styles.IndexOf(first) : -1;
+ Styles.Insert(at >= 0 ? at : Styles.Count, target);
+ }
+
+ if (pieces != null)
+ {
+ target.Clear();
+ foreach ((string role, ushort id) in pieces)
+ {
+ target.Add(role, id);
+ }
+ }
+
+ foreach (ushort id in entry.Replaces)
+ {
+ if (owners.TryGetValue((entry.Kind, id), out HouseStyle other) && other != target)
+ {
+ removed.Add(other);
+ }
+ }
+
+ target.Anchor = entry.Anchor != 0 ? entry.Anchor : target.IconId;
+ target.Name = entry.Name ?? target.Name;
+ target.Group = entry.Group ?? target.Group;
+ target.Family = entry.Family ?? target.Family;
+ target.Hidden = entry.Hidden ?? target.Hidden;
+ target.Borrows = entry.Borrows ?? target.Borrows;
+ if (entry.Layout != null)
+ {
+ target.Paired = entry.Layout == HouseStyleEntry.LayoutPaired;
+ bool cycle = entry.Layout == HouseStyleEntry.LayoutCycle;
+ target.CycleSouth = cycle ? target.Slots.Keys.Count(label => label.StartsWith("CycleSouth", System.StringComparison.Ordinal)) : 0;
+ target.CycleEast = cycle ? target.Slots.Keys.Count(label => label.StartsWith("CycleEast", System.StringComparison.Ordinal)) : 0;
+ }
+
+ _rank[target] = _rank.Count;
+ }
+
+ Styles.RemoveAll(removed.Contains);
+ }
+
+ ///
+ /// The lookup from a tile to its style and column: the first style that lists it. A panel
+ /// of a style that goes through its panels in turn counts as a plain run piece for
+ /// everything that asks what a tile is (redrawing, turning).
+ ///
+ private void BuildRoles()
+ {
+ foreach (HouseStyle style in Styles)
+ {
+ foreach (KeyValuePair piece in style.Slots)
+ {
+ if (IsMultiColumn(piece.Key))
+ {
+ continue;
+ }
+
+ string label = piece.Key.StartsWith("CycleSouth", System.StringComparison.Ordinal) ? "South2"
+ : piece.Key.StartsWith("CycleEast", System.StringComparison.Ordinal) ? "East2"
+ : piece.Key;
+ _roles.TryAdd(piece.Value, (style, label));
+ }
+ }
+ }
+
+ ///
+ /// Makes every wall style build whole walls: empty run columns are filled, a row without a
+ /// post borrows one from its category, and in a category sorted by its art corners and
+ /// posts are lent between the rows. A style the file marks as not borrowing is two or
+ /// three pieces on their own and stays as it is.
+ ///
+ private void FinishWalls()
+ {
+ var posts = new Dictionary>();
+ var sorted = new Dictionary>();
+ foreach (HouseStyle style in Styles)
+ {
+ if (style.Kind != HousePartKind.Wall)
+ {
+ continue;
+ }
+
+ if (style.ByArt && style.Borrows)
+ {
+ if (!sorted.TryGetValue(style.Category, out List rows))
+ {
+ sorted[style.Category] = rows = new List();
+ }
+
+ rows.Add(style);
+ }
+
+ FillWallRuns(style, style.Get("CycleSouth1"), style.Get("CycleEast1"));
+
+ // A row without a post (Celtic Walls 2) borrows the one of an earlier row
+ // of its category that is as high: the same wall, differently decorated.
+ if (!posts.TryGetValue(style.Category, out List categoryPosts))
+ {
+ posts[style.Category] = categoryPosts = new List();
+ }
+
+ ushort post = style.Get("Post"), straight = style.Get("South1");
+ if (post != 0)
+ {
+ categoryPosts.Add(post);
+ }
+ else if (straight != 0 && style.Borrows)
+ {
+ foreach (ushort other in categoryPosts)
+ {
+ if (Ultima.TileData.ItemTable[other].Height == Ultima.TileData.ItemTable[straight].Height)
+ {
+ style.Add("Post", other);
+ break;
+ }
+ }
+ }
+ }
+
+ foreach (List rows in sorted.Values)
+ {
+ LendCornersAndPosts(rows);
+ }
+ }
+
+ ///
+ /// Puts the styles in the style file's order. A style the file does not name (one only
+ /// another client version has) stays behind the style it follows in the tables.
+ ///
+ private void Order()
+ {
+ if (_rank.Count == 0)
+ {
+ return;
+ }
+
+ var last = new Dictionary();
+ var keys = new Dictionary();
+ for (int i = 0; i < Styles.Count; ++i)
+ {
+ HouseStyle style = Styles[i];
+ if (_rank.TryGetValue(style, out int rank))
+ {
+ last[style.Kind] = rank;
+ }
+ else if (!last.TryGetValue(style.Kind, out rank))
+ {
+ rank = -1;
+ }
+
+ keys[style] = (rank, _rank.ContainsKey(style) ? -1 : i);
+ }
+
+ List ordered = Styles.OrderBy(style => keys[style].Rank).ThenBy(style => keys[style].Index).ToList();
+ Styles.Clear();
+ Styles.AddRange(ordered);
+ }
+
+ ///
+ /// In a category sorted by its art, a row often has walls but no corner or post of its
+ /// own: the set's corners and posts sit in another row. Such a style takes the first
+ /// piece of the category that is a corner (or post) of its walls' height.
+ ///
+ private static void LendCornersAndPosts(List styles)
+ {
+ static int Class(ushort id) => Ultima.TileData.ItemTable[id].Height >= 15 ? 2 : Ultima.TileData.ItemTable[id].Height >= 8 ? 1 : 0;
+ var pieces = new List();
+ foreach (HouseStyle style in styles)
+ {
+ foreach (ushort id in style.Slots.Values)
+ {
+ if (!pieces.Contains(id))
+ {
+ pieces.Add(id);
+ }
+ }
+ }
+
+ foreach (HouseStyle style in styles)
+ {
+ ushort wall = style.Get("South1") != 0 ? style.Get("South1") : style.Get("East1");
+ if (wall == 0)
+ {
+ continue;
+ }
+
+ foreach ((string column, TilePlacement placement) in new[] { ("Corner", TilePlacement.Cell), ("Post", TilePlacement.Vertex) })
+ {
+ if (style.Get(column) != 0)
+ {
+ continue;
+ }
+
+ foreach (ushort id in pieces)
+ {
+ if (Class(id) == Class(wall) && ArtFacing.Placement(id) == placement &&
+ (Ultima.TileData.ItemTable[id].Flags & Ultima.TileFlag.Window) == 0)
+ {
+ style.Add(column, id);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ /// The pieces a row lists under its window headings.
+ private static HashSet WindowPieces(TileStyle row)
+ {
+ var ids = new HashSet();
+ foreach (TileSlot slot in row.Slots)
+ {
+ if (!slot.IsEmpty && slot.IsValid && slot.TileId <= ushort.MaxValue && slot.Label.Contains("Window", System.StringComparison.Ordinal))
+ {
+ ids.Add((ushort)slot.TileId);
+ }
+ }
+
+ return ids;
+ }
+
+ /// The pieces a row lists, each once, in the row's order.
+ private static List PiecesOf(TileStyle row)
+ {
+ var ids = new List();
+ foreach (TileSlot slot in row.Slots)
+ {
+ if (!slot.IsEmpty && slot.IsValid && slot.TileId <= ushort.MaxValue && !ids.Contains((ushort)slot.TileId))
+ {
+ ids.Add((ushort)slot.TileId);
+ }
+ }
+
+ return ids;
+ }
+
+ private static readonly string[] _southWindows = { "WindowS", "AltWindowS", "SecondAltWindowS" };
+ private static readonly string[] _eastWindows = { "WindowE", "AltWindowE", "SecondAltWindowE" };
+
+ /// What a wall column's heading says its piece is.
+ private static TilePlacement HeadingPlacement(string label)
+ {
+ return label == "Corner" ? TilePlacement.Cell
+ : label == "Post" ? TilePlacement.Vertex
+ : label.StartsWith("South", System.StringComparison.Ordinal) || label.EndsWith("S", System.StringComparison.Ordinal) ? TilePlacement.SouthEdge
+ : TilePlacement.EastEdge;
+ }
+
+ ///
+ /// True for a walls.txt category where at least three pieces in ten are not what their
+ /// column heading says, going by the art: a piece under "South" that runs along Y, a
+ /// "Corner" that is a straight wall. All the gargish sets and the gothic one are like
+ /// that; in the other categories it is at most a spare window under "Corner".
+ ///
+ private static bool HeadingsAreOff(TileCategory category)
+ {
+ int pieces = 0, off = 0;
+ foreach (TileStyle row in category.Styles)
+ {
+ foreach (TileSlot slot in row.Slots)
+ {
+ if (slot.IsEmpty || !slot.IsValid || slot.TileId > ushort.MaxValue)
+ {
+ continue;
+ }
+
+ ++pieces;
+ if (ArtFacing.Placement((ushort)slot.TileId) != HeadingPlacement(slot.Label))
+ {
+ ++off;
+ }
+ }
+ }
+
+ return pieces > 0 && off * 10 >= pieces * 3;
+ }
+
+ ///
+ /// Fills a wall style from a row whose headings cannot be trusted. Each piece goes where
+ /// its art says: a wall along X to the South columns, one along Y to the East columns, a
+ /// piece that fills its cell's corner to Corner, a column to Post, windows to the window
+ /// columns. The pieces keep the row's order. What does not fit (a fourth wall along X, a
+ /// second corner, a piece of another height than most of the row) stays with the style as
+ /// a "More" piece, to place by hand.
+ ///
+ private static void SortByArt(HouseStyle style, List ids, HashSet listedAsWindows)
+ {
+ if (ids.Count == 0)
+ {
+ return;
+ }
+
+ // The row's usual height: full, half or low walls.
+ static int Class(ushort id) => Ultima.TileData.ItemTable[id].Height >= 15 ? 2 : Ultima.TileData.ItemTable[id].Height >= 8 ? 1 : 0;
+ int usual = ids.GroupBy(Class).OrderByDescending(g => g.Count()).ThenByDescending(g => g.Key).First().Key;
+
+ int more = 0;
+ void Put(string[] columns, ushort id)
+ {
+ foreach (string column in columns)
+ {
+ if (style.Get(column) == 0)
+ {
+ style.Add(column, id);
+ return;
+ }
+ }
+
+ style.Add($"More{++more}", id);
+ }
+
+ foreach (ushort id in ids)
+ {
+ // An arch or opening the table lists under a window heading is one, flagged or not.
+ bool window = (Ultima.TileData.ItemTable[id].Flags & Ultima.TileFlag.Window) != 0 || listedAsWindows.Contains(id);
+ if (Class(id) != usual)
+ {
+ style.Add($"More{++more}", id);
+ continue;
+ }
+
+ switch (ArtFacing.Placement(id))
+ {
+ case TilePlacement.SouthEdge:
+ Put(window ? _southWindows : _southRun, id);
+ break;
+ case TilePlacement.EastEdge:
+ Put(window ? _eastWindows : _eastRun, id);
+ break;
+ case TilePlacement.Vertex:
+ Put(new[] { "Post" }, id);
+ break;
+ default:
+ Put(new[] { "Corner" }, id);
+ break;
+ }
+ }
+ }
+
+ private static readonly string[] _southRun = { "South1", "South2", "South3" };
+ private static readonly string[] _eastRun = { "East1", "East2", "East3" };
+
+ ///
+ /// Many wall rows list one piece per direction where the table has three columns (the
+ /// start, middle and end of a run): the later sets, and most half and quarter walls. A
+ /// run built from such a row had holes. The columns a row leaves empty take the piece of
+ /// the nearest one it has, so every row builds whole walls. (The piece keeps the one role
+ /// it is listed under.)
+ ///
+ private static void FillWallRuns(HouseStyle style, ushort south = 0, ushort east = 0)
+ {
+ foreach (string[] run in new[] { _southRun, _eastRun })
+ {
+ // The middle piece first: it stands in best for a missing end, and an end for a missing middle.
+ ushort have = style.Get(run[1]) != 0 ? style.Get(run[1]) : style.Get(run[0]) != 0 ? style.Get(run[0]) : style.Get(run[2]);
+ if (have == 0)
+ {
+ have = run == _southRun ? south : east;
+ }
+ if (have == 0)
+ {
+ continue;
+ }
+
+ foreach (string column in run)
+ {
+ if (style.Get(column) == 0)
+ {
+ style.Add(column, have);
+ }
+ }
+ }
+ }
+
+ private static readonly string[] _wallFillerWords = { "Standard", "Walls", "Wall", "Set", "Style", "-" };
+
+ ///
+ /// The group and the row names of a walls.txt category. The table's comments name many
+ /// rows alike ("Carved Wood 1" four times: full, windowed, half and quarter walls) or only
+ /// by number ("Crystal Walls 2"). The group is the material: what the rows' names share,
+ /// without filler words and numbers. A row whose name is used twice, or is only numbered,
+ /// is named by what it holds instead: material + Walls, Window Walls, Half Walls or
+ /// Quarter Walls, by the height of its pieces. Other rows keep their comment.
+ ///
+ private static (string Group, List Names) WallNames(TileCategory category, HashSet used, bool byArt)
+ {
+ var raw = new List();
+ foreach (TileStyle row in category.Styles)
+ {
+ string name = (row.Name ?? string.Empty).Trim().TrimEnd('\\').Trim();
+ raw.Add(name);
+ }
+
+ // The material: the words every row starts with.
+ string[] first = raw.Count > 0 ? raw[0].Split(' ', System.StringSplitOptions.RemoveEmptyEntries) : System.Array.Empty();
+ int shared = first.Length;
+ foreach (string name in raw)
+ {
+ string[] words = name.Split(' ', System.StringSplitOptions.RemoveEmptyEntries);
+ int same = 0;
+ while (same < shared && same < words.Length && string.Equals(words[same], first[same], System.StringComparison.OrdinalIgnoreCase))
+ {
+ ++same;
+ }
+
+ shared = same;
+ }
+
+ // A category of two materials (Weathered Stone and Granite) shares no words: it goes by its first row.
+ bool oneMaterial = shared > 0;
+ var material = new List(first.Take(oneMaterial ? shared : first.Length));
+
+ // "Gargish Wall Set 2": the set's number is part of what it is, as there are three such categories.
+ string set = material.Count >= 3 && material[^2] == "Set" && int.TryParse(material[^1], out _) ? " Set " + material[^1] : string.Empty;
+ while (material.Count > 0 && (System.Array.IndexOf(_wallFillerWords, material[^1]) >= 0 || int.TryParse(material[^1], out _)))
+ {
+ material.RemoveAt(material.Count - 1);
+ }
+
+ string group = material.Count > 0 ? string.Join(" ", material) + set : (category.Name ?? string.Empty).Trim();
+ if (group.Length > 0)
+ {
+ group = char.ToUpperInvariant(group[0]) + group.Substring(1);
+ }
+
+ var names = new List();
+ for (int row = 0; row < raw.Count; ++row)
+ {
+ string name = raw[row];
+ string[] words = name.Split(' ', System.StringSplitOptions.RemoveEmptyEntries);
+ // In a category sorted by its art the comments say little: any numbered row of the material is renamed.
+ bool numbered = words.Length >= 2 && int.TryParse(words[^1], out _) &&
+ (words[^2] is "Walls" or "Wall" or "Set" || raw.Count(n => n == name) > 1 ||
+ (byArt && material.Count > 0 && name.StartsWith(string.Join(" ", material), System.StringComparison.OrdinalIgnoreCase)));
+ bool vague = raw.Count(n => string.Equals(n, name, System.StringComparison.OrdinalIgnoreCase)) > 1 || numbered ||
+ name.Contains(" - Style", System.StringComparison.Ordinal);
+ if (vague && oneMaterial && material.Count > 0)
+ {
+ string kindName = WallKind(category.Styles[row]);
+ name = kindName == "Window Walls" && group.Contains("Window", System.StringComparison.OrdinalIgnoreCase) ? group : group + " " + kindName;
+ }
+
+ // Two rows of one kind: the second and later ones are numbered.
+ string unique = name;
+ for (int n = 2; !used.Add(unique); ++n)
+ {
+ unique = $"{name} {n}";
+ }
+
+ names.Add(unique);
+ }
+
+ return (group, names);
+ }
+
+ /// What a wall row holds, by its pieces: their usual height, and whether most are windows.
+ private static string WallKind(TileStyle row)
+ {
+ var heights = new List();
+ int windows = 0;
+ foreach (TileSlot slot in row.Slots)
+ {
+ if (slot.IsEmpty || slot.TileId > ushort.MaxValue || !slot.IsValid)
+ {
+ continue;
+ }
+
+ heights.Add(Ultima.TileData.ItemTable[slot.TileId].Height);
+ if ((Ultima.TileData.ItemTable[slot.TileId].Flags & Ultima.TileFlag.Window) != 0)
+ {
+ ++windows;
+ }
+ }
+
+ if (heights.Count == 0)
+ {
+ return "Walls";
+ }
+
+ heights.Sort();
+ int height = heights[heights.Count / 2];
+ return height >= 15 ? (windows * 2 > heights.Count ? "Window Walls" : "Walls") : height >= 8 ? "Half Walls" : "Quarter Walls";
+ }
+
+ ///
+ /// One style from the rows of a roof.txt category, named after the category without its
+ /// row number ("Straw Roof 1" and "Straw Roof 2" are "Straw Roof"). The first row's pieces
+ /// keep their column headings; the pieces of a further row are extras of the set, kept
+ /// under "More" + heading so they still count as its roof pieces. Sets whose rows do not
+ /// follow the headings (ceramic, crystal, shadow) get their pieces from the style file,
+ /// which has labels for what the headings have no word for: Eave + side (a slope with
+ /// the roof's edge), Hip + corner (a hip line), HipEave + corner, NSEnd and EWEnd.
+ ///
+ private static HouseStyle RoofStyle(TileCategory category)
+ {
+ string name = category.Name ?? string.Empty;
+ if (name.EndsWith(" 1", System.StringComparison.Ordinal))
+ {
+ name = name.Substring(0, name.Length - 2);
+ }
+
+ var style = new HouseStyle(HousePartKind.Roof, name, name);
+ for (int row = 0; row < category.Styles.Count; ++row)
+ {
+ foreach (TileSlot slot in category.Styles[row].Slots)
+ {
+ if (slot.IsEmpty || slot.TileId > ushort.MaxValue || !slot.IsValid)
+ {
+ continue;
+ }
+
+ string label = row == 0 ? slot.Label : "More" + slot.Label;
+ if (style.Get(label) == 0)
+ {
+ style.Add(label, (ushort)slot.TileId);
+ }
+ }
+ }
+
+ return style;
+ }
+
/// How far apart two radar colours may be (RGB distance) and still count as one floor colour.
private const int _sameColour = 20;
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/WallPlanner.cs b/UoFiddler.Plugin.MultiEditor/Classes/WallPlanner.cs
index 6dacbc84..f930d0e5 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/WallPlanner.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/WallPlanner.cs
@@ -173,7 +173,7 @@ void Edit(HashSet<(int, int)> set, (int X, int Y) cell)
continue;
}
- string column = PieceFor(cell.X, cell.Y);
+ string column = PieceFor(_style, _south, _east, cell.X, cell.Y);
ushort want = column != null ? _style.Get(column) : (ushort)0;
_pieces.TryGetValue(cell, out MultiTile have);
@@ -207,6 +207,53 @@ void Edit(HashSet<(int, int)> set, (int X, int Y) cell)
///
public string PieceFor(int x, int y) => PieceFor(_south, _east, x, y);
+ ///
+ /// The column of a style's piece for a cell. As ,
+ /// except in a paired style (): there the straight pieces of
+ /// a run alternate between the two halves of the ornament, counted from the run's start,
+ /// and the last piece of a run of odd length is the plain one.
+ ///
+ public static string PieceFor(HouseStyle style, HashSet<(int X, int Y)> southEdges, HashSet<(int X, int Y)> eastEdges, int x, int y)
+ {
+ string column = PieceFor(southEdges, eastEdges, x, y);
+ bool cycles = style != null && style.CycleSouth > 0 && style.CycleEast > 0;
+ if (style == null || (!style.Paired && !cycles) || column == null || column is "Corner" or "Post")
+ {
+ return column;
+ }
+
+ bool alongX = column.StartsWith("South", StringComparison.Ordinal);
+ bool Straight(int cx, int cy) => alongX
+ ? southEdges.Contains((cx, cy)) && !eastEdges.Contains((cx, cy))
+ : eastEdges.Contains((cx, cy)) && !southEdges.Contains((cx, cy));
+
+ int before = 0, after = 0;
+ while (Straight(alongX ? x - before - 1 : x, alongX ? y : y - before - 1))
+ {
+ ++before;
+ }
+
+ while (Straight(alongX ? x + after + 1 : x, alongX ? y : y + after + 1))
+ {
+ ++after;
+ }
+
+ // A set of panels: one after the other along the run.
+ if (cycles)
+ {
+ return alongX ? $"CycleSouth{(before % style.CycleSouth) + 1}" : $"CycleEast{(before % style.CycleEast) + 1}";
+ }
+
+ int length = before + after + 1;
+ if (length % 2 == 1 && after == 0)
+ {
+ return alongX ? "South2" : "East2";
+ }
+
+ bool firstHalf = before % 2 == 0;
+ return alongX ? (firstHalf ? "South1" : "South3") : (firstHalf ? "East3" : "East1");
+ }
+
///
/// The walls.txt column for a cell given the +Y edges () and
/// +X edges () of a wall layer.
diff --git a/UoFiddler.Plugin.MultiEditor/MultiEditorHouseStyles.xml b/UoFiddler.Plugin.MultiEditor/MultiEditorHouseStyles.xml
new file mode 100644
index 00000000..d20ccd03
--- /dev/null
+++ b/UoFiddler.Plugin.MultiEditor/MultiEditorHouseStyles.xml
@@ -0,0 +1,831 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
index 9baae6f3..de352a4f 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
@@ -138,11 +138,15 @@ private void EnsureMaterials()
return;
}
- HouseStyle First(HousePartKind kind) => Context.HouseStyles.Styles.FirstOrDefault(s => s.Kind == kind && s.IconId != 0);
+ HouseStyle First(HousePartKind kind) => Context.HouseStyles.Styles.FirstOrDefault(s => s.Kind == kind && s.IconId != 0 && !s.Hidden);
_draft.WallStyles[0] ??= Context.HouseStyles.Styles.FirstOrDefault(s =>
s.Kind == HousePartKind.Wall && s.Get("South2") is var id and not 0 && Ultima.TileData.ItemTable[id].Height >= 15) ?? First(HousePartKind.Wall);
_draft.FloorStyles[0] ??= First(HousePartKind.Floor);
_draft.RoofStyle ??= First(HousePartKind.Roof);
+
+ // The floors table has flat roof tiles (stone roof, marble roof): a flat roof starts with those.
+ _draft.FlatRoofStyle ??= Context.HouseStyles.Styles.FirstOrDefault(s => s.Kind == HousePartKind.Floor && s.Slots.Values.Any(id =>
+ (Ultima.TileData.ItemTable[id].Name ?? string.Empty).Contains("roof", StringComparison.OrdinalIgnoreCase)));
for (int k = 1; k < HouseDraft.MaxStoreys; ++k)
{
_draft.WallStyles[k] ??= _draft.WallStyles[k - 1];
@@ -478,6 +482,15 @@ public void SetMaterial(HouseStyle style, int? storey)
});
}
+ /// Sets the floor style flat roofs are laid in.
+ public void SetFlatRoofStyle(HouseStyle style)
+ {
+ if (style is { Kind: HousePartKind.Floor })
+ {
+ Edit(() => _draft.FlatRoofStyle = style);
+ }
+ }
+
/// The storey the work plane is on (the chosen floor); the ground floor with all floors shown.
public int StoreyFor(int? workZ)
{
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs
index ee1f8871..b679f570 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/RoofTool.cs
@@ -300,11 +300,22 @@ protected override (List Remove, List<(ushort Id, int X, int Y, int Z
{
lift = int.Parse(column.AsSpan(mark + 1));
column = column.Substring(0, mark);
- if (style.Get(column) == 0)
- {
- // A style without corner pieces: the slope facing the same way.
- (column, lift) = (column[0] switch { 'N' => "North", 'E' => "East", 'S' => "South", _ => "West" }, 0);
- }
+ }
+
+ // A hip's corner: a set with hip pieces of its own (ceramic) uses those, at the
+ // slopes' height, with the eave's piece where the hip line reaches the edge.
+ string hip = column switch { "NDent" => "HipNW", "EDent" => "HipNE", "SDent" => "HipSE", "WDent" => "HipSW", _ => null };
+ if (hip != null && style.Get(hip) != 0)
+ {
+ bool west = hip[^1] == 'W', north = hip[^2] == 'N';
+ bool atEdge = !heights.ContainsKey((x + (west ? -1 : 1), y)) && !heights.ContainsKey((x, y + (north ? -1 : 1)));
+ string atEave = "HipEave" + hip.Substring(3);
+ (column, lift) = (atEdge && style.Get(atEave) != 0 ? atEave : hip, 0);
+ }
+ else if (hip != null && style.Get(column) == 0)
+ {
+ // A style without corner pieces: the slope facing the same way.
+ (column, lift) = (column[0] switch { 'N' => "North", 'E' => "East", 'S' => "South", _ => "West" }, 0);
}
}
else
@@ -316,6 +327,16 @@ protected override (List Remove, List<(ushort Id, int X, int Y, int Z
}
}
+ // A slope at the roof's edge is the set's eave piece, when it has one.
+ (int X, int Y) below = column switch
+ {
+ "West" => (x - 1, y), "East" => (x + 1, y), "North" => (x, y - 1), "South" => (x, y + 1), _ => (int.MinValue, 0)
+ };
+ if (below.X != int.MinValue && !heights.ContainsKey(below) && style.Get("Eave" + column) != 0)
+ {
+ column = "Eave" + column;
+ }
+
ushort id = style.Get(column);
if (id != 0)
{
diff --git a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
index 13c0243e..02b04cac 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
@@ -50,9 +50,16 @@ public HousePanel()
_floorButtons[k].Click += (_, _) => PickStyle?.Invoke(HousePartKind.Floor, storey);
}
- _roofStyle.Click += (_, _) => PickStyle?.Invoke(HousePartKind.Roof, 0);
+ _roofStyle.Click += (_, _) =>
+ {
+ bool flat = _session != null && !_session.House.NoRoof && _session.House.Shape == RoofShape.Flat;
+ PickStyle?.Invoke(flat ? HousePartKind.Floor : HousePartKind.Roof, flat ? FlatRoof : 0);
+ };
}
+ /// The storey a pick names when it is for the flat roof's floor style.
+ public const int FlatRoof = -1;
+
/// Asks for a style to be picked on the House page for a storey's walls or floor, or for the roof.
public event Action PickStyle;
@@ -137,7 +144,9 @@ public void RefreshDraft()
_storeyLabels[k].ForeColor = current ? Color.Black : ForeColor;
}
- _roofStyle.Text = house.Draft.RoofStyle?.Name ?? "(roof)";
+ // A flat roof is laid in a floor style of its own; the button picks that one then.
+ bool flat = !house.NoRoof && house.Shape == RoofShape.Flat;
+ _roofStyle.Text = flat ? house.Draft.FlatRoofStyle?.Name ?? "(top floor's style)" : house.Draft.RoofStyle?.Name ?? "(roof)";
_foundation.Checked = house.Draft.Foundation;
_rooms.Value = Math.Clamp(house.Rooms, 1, HouseDraft.MaxRooms);
_showWalls.Checked = house.ShowWalls;
diff --git a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
index cd0b086d..2ac5bd80 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
@@ -700,7 +700,15 @@ private void ChooseHouseStyle(HouseStyle style)
if (_housePick is { } pick && pick.Kind == style.Kind)
{
_housePick = null;
- Session.House.SetMaterial(style, style.Kind == HousePartKind.Roof ? null : pick.Storey);
+ if (pick.Storey == HousePanel.FlatRoof)
+ {
+ Session.House.SetFlatRoofStyle(style);
+ }
+ else
+ {
+ Session.House.SetMaterial(style, style.Kind == HousePartKind.Roof ? null : pick.Storey);
+ }
+
SetTool(ToolKind.House, fromHousePage: true);
return;
}
@@ -754,8 +762,8 @@ private void PickHouseMaterial(HousePartKind kind, int storey)
_openingHousePage = false;
}
- _statusHint.Text = kind == HousePartKind.Roof
- ? "Pick the roof style of the house on the House page."
+ _statusHint.Text = kind == HousePartKind.Roof ? "Pick the roof style of the house on the House page."
+ : storey == HousePanel.FlatRoof ? "Pick the floor style of the flat roofs on the House page."
: $"Pick the {(kind == HousePartKind.Wall ? "wall" : "floor")} style of storey {storey + 1} on the House page.";
}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/TileBrowserPanel.cs b/UoFiddler.Plugin.MultiEditor/UI/TileBrowserPanel.cs
index c81ebcfc..e43bcf51 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/TileBrowserPanel.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/TileBrowserPanel.cs
@@ -1371,7 +1371,7 @@ private bool HouseStyleMatches(HouseStyle style)
{
TileBrowserQuery query = _query;
return query == null ||
- (query.IsIdQuery ? style.Slots.Values.Any(id => query.MatchesId(id)) : query.MatchesText(style.Group + " " + style.Name));
+ (query.IsIdQuery ? style.Slots.Values.Any(id => query.MatchesId(id)) : query.MatchesText(style.Group + " " + style.Name + " " + style.Family));
}
///
@@ -1389,7 +1389,7 @@ private void RebuildHouseTree()
_patternsButton.Checked = false;
_swapButton.Text = _swapText;
_swapButton.Enabled = true;
- List styles = _houseStyles?.Styles ?? new List();
+ List styles = _houseStyles?.Styles.Where(st => !st.Hidden).ToList() ?? new List();
_houseStyleCount = 0;
foreach (var (kind, title, _, _) in _houseKinds)
diff --git a/UoFiddler.Plugin.MultiEditor/UoFiddler.Plugin.MultiEditor.csproj b/UoFiddler.Plugin.MultiEditor/UoFiddler.Plugin.MultiEditor.csproj
index f2f388ee..755cae9c 100644
--- a/UoFiddler.Plugin.MultiEditor/UoFiddler.Plugin.MultiEditor.csproj
+++ b/UoFiddler.Plugin.MultiEditor/UoFiddler.Plugin.MultiEditor.csproj
@@ -189,6 +189,9 @@
PreserveNewest
+
+ PreserveNewest
+
@@ -828,4 +832,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/EditorTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/EditorTool.cs
index df2e9913..9d0acb40 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/EditorTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/EditorTool.cs
@@ -162,6 +162,9 @@ protected EditorTool(IEditorContext context)
/// True while a drag is in progress, so every mouse move repaints.
public virtual bool IsDragging => false;
+ /// Cells a drag in progress spans, for the status bar; null when the tool has no such drag.
+ public virtual (int Width, int Height)? DragSize => null;
+
/// True when the overlay follows the cell under the cursor.
public virtual bool TracksCursorCell => false;
@@ -215,6 +218,8 @@ protected CellDragTool(IEditorContext context) : base(context)
public override bool IsDragging => _dragging;
+ public override (int Width, int Height)? DragSize => _dragging ? (System.Math.Abs(EndX - StartX) + 1, System.Math.Abs(EndY - StartY) + 1) : null;
+
protected bool Dragging => _dragging;
public override void OnMouseDown(MouseEventArgs e)
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
index de352a4f..bc35b0bc 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
@@ -32,6 +32,7 @@ internal sealed class HouseTool : WingDraftTool
private HouseDraft _draft = new HouseDraft();
private int _storeys = 1;
private int _rooms = 1;
+ private RoomLayout _layout;
private RoofShape _shape = RoofShape.Gable;
private bool _noRoof;
private RoofRidge _ridge = RoofRidge.Auto;
@@ -61,6 +62,12 @@ public HouseTool(IEditorContext context, RoofTool roof) : base(context)
/// Rooms of the selected wing, else of the wings drawn next.
public int Rooms => SelectedWing?.Rooms ?? _rooms;
+ /// Rooms and layout of a storey of the selected wing, else of the wings drawn next.
+ public (int Rooms, RoomLayout Layout) RoomsOn(int storey) => SelectedWing?.RoomsOn(storey) ?? (_rooms, _layout);
+
+ /// True when a storey of the selected wing has rooms of its own, apart from the storey below.
+ public bool HasOwnRooms(int storey) => storey >= 1 && storey < HouseDraft.MaxStoreys && SelectedWing?.RoomsAbove[storey] != null;
+
public RoofShape Shape => SelectedWing?.Shape ?? _shape;
public bool NoRoof => SelectedWing?.NoRoof ?? _noRoof;
@@ -147,6 +154,8 @@ private void EnsureMaterials()
// The floors table has flat roof tiles (stone roof, marble roof): a flat roof starts with those.
_draft.FlatRoofStyle ??= Context.HouseStyles.Styles.FirstOrDefault(s => s.Kind == HousePartKind.Floor && s.Slots.Values.Any(id =>
(Ultima.TileData.ItemTable[id].Name ?? string.Empty).Contains("roof", StringComparison.OrdinalIgnoreCase)));
+ _draft.DoorStyle ??= First(HousePartKind.Door);
+ _draft.StairStyle ??= First(HousePartKind.Stair);
for (int k = 1; k < HouseDraft.MaxStoreys; ++k)
{
_draft.WallStyles[k] ??= _draft.WallStyles[k - 1];
@@ -183,7 +192,7 @@ protected override List WingsFor(int startX, int startY, int endX, int
var wing = new RoofWing
{
- X0 = x0, Y0 = y0, X1 = x1, Y1 = y1, EaveZ = z, Storeys = _storeys, Rooms = _rooms,
+ X0 = x0, Y0 = y0, X1 = x1, Y1 = y1, EaveZ = z, Storeys = _storeys, Rooms = _rooms, Layout = _layout,
Shape = _shape, NoRoof = _noRoof, RidgeAuto = _ridge == RoofRidge.Auto
};
Snap(wing, moved: false);
@@ -254,20 +263,55 @@ protected override void Turn(RoofWing wing)
protected override void RestoreExtra(object extra)
{
_draft = extra is HouseDraft saved ? saved.Clone() : _draft.Fresh();
+ _lastRun = null;
++_version;
}
// ---------------------------------------------------------------- changes to the draft
- /// Runs a change to the draft as one step of its history.
- private void Edit(Action change)
+ // What the last step of the history changed, when steps of that kind run together (a
+ // number stepped up and up is one step to take back, not ten).
+ private string _lastRun;
+
+ ///
+ /// Runs a change to the draft as one step of its history. Changes given the same
+ /// name one after another are one step together.
+ ///
+ private void Edit(Action change, string run = null)
{
- Remember();
+ if (run == null || run != _lastRun)
+ {
+ Remember();
+ }
+
+ _lastRun = run;
change();
++_version;
RaiseChanged();
}
+ /// The styles were read again: the draft takes the new style objects in place of the ones it holds.
+ public void StylesReloaded()
+ {
+ if (Context.HouseStyles == null)
+ {
+ return;
+ }
+
+ _draft.Remap(Context.HouseStyles.Successor);
+ ++_version;
+ RaiseChanged();
+ }
+
+ /// Which gable ends of the house's roofs are closed, and with what.
+ public void SetGables(RoofGables gables, RoofGableFill fill)
+ {
+ if (_draft.Gables != gables || _draft.GableFill != fill)
+ {
+ Edit(() => (_draft.Gables, _draft.GableFill) = (gables, fill));
+ }
+ }
+
/// Sets the storeys of the selected wing, and of the wings drawn next.
public void SetStoreys(int storeys)
{
@@ -329,21 +373,78 @@ public void SetBaseZ(int z)
{
wing.EaveZ = z;
}
- });
+ }, "baseZ");
}
- /// Divides the selected wing, and the wings drawn next, into this many rooms on every storey (1: undivided).
- public void SetRooms(int rooms)
+ ///
+ /// Sets the rooms and their layout for a storey of the selected wing: for that storey
+ /// alone when it has rooms of its own (), else for the ground
+ /// floor and every storey that follows it. Without a selected wing it is for the wings drawn next.
+ ///
+ public void SetRooms(int rooms, RoomLayout layout, int storey)
{
rooms = Math.Clamp(rooms, 1, HouseDraft.MaxRooms);
- _rooms = rooms;
- if (SelectedWing is { } wing && wing.Rooms != rooms)
+ if (SelectedWing is not { } wing)
{
- Edit(() => wing.Rooms = rooms);
+ (_rooms, _layout) = (rooms, layout);
+ RaiseChanged();
+ return;
}
- else
+
+ if (wing.RoomsOn(storey) == (rooms, layout))
{
- RaiseChanged();
+ return;
+ }
+
+ Edit(() =>
+ {
+ if (storey >= 1 && storey < HouseDraft.MaxStoreys && wing.RoomsAbove[storey] != null)
+ {
+ wing.RoomsAbove[storey] = (rooms, layout);
+ }
+ else
+ {
+ (wing.Rooms, wing.Layout) = (rooms, layout);
+ (_rooms, _layout) = (rooms, layout);
+ }
+ });
+ }
+
+ /// Gives a storey above the ground floor rooms of its own, or lets it follow the storey below again.
+ public void SetOwnRooms(int storey, bool own)
+ {
+ if (SelectedWing is not { } wing || storey < 1 || storey >= HouseDraft.MaxStoreys || (wing.RoomsAbove[storey] != null) == own)
+ {
+ return;
+ }
+
+ Edit(() => wing.RoomsAbove[storey] = own ? wing.RoomsOn(storey) : null);
+ }
+
+ /// Doors in the doorways between rooms, on or off.
+ public void SetAutoDoors(bool on)
+ {
+ if (_draft.AutoDoors != on)
+ {
+ Edit(() => _draft.AutoDoors = on);
+ }
+ }
+
+ public void SetFrontDoor(FrontDoorSide side)
+ {
+ if (_draft.FrontDoor != side)
+ {
+ Edit(() => _draft.FrontDoor = side);
+ }
+ }
+
+ /// Windows along the outer walls, this many cells apart; 0 for none.
+ public void SetWindowSpacing(int cells)
+ {
+ cells = Math.Clamp(cells, 0, 12);
+ if (_draft.WindowSpacing != cells)
+ {
+ Edit(() => _draft.WindowSpacing = cells, "windows");
}
}
@@ -453,8 +554,9 @@ public void SetFoundation(bool on)
}
///
- /// Sets a wall, floor or roof style. A wall or floor style goes to one storey, or to
- /// every storey when is null.
+ /// Sets a wall, floor, roof, door or stair style. A wall or floor style goes to one
+ /// storey, or to every storey when is null. A door or stair
+ /// style is the house's: the doors and stairs it already has change with it.
///
public void SetMaterial(HouseStyle style, int? storey)
{
@@ -471,6 +573,12 @@ public void SetMaterial(HouseStyle style, int? storey)
return;
}
+ if (style.Kind is HousePartKind.Door or HousePartKind.Stair)
+ {
+ Restyle(style);
+ return;
+ }
+
HouseStyle[] target = style.Kind == HousePartKind.Floor ? _draft.FloorStyles : style.Kind == HousePartKind.Wall ? _draft.WallStyles : null;
for (int k = 0; target != null && k < HouseDraft.MaxStoreys; ++k)
{
@@ -482,6 +590,148 @@ public void SetMaterial(HouseStyle style, int? storey)
});
}
+ /// Makes a door or stair style the house's, and gives it to the doors or stairs already there that it has the piece for.
+ private void Restyle(HouseStyle style)
+ {
+ if (style.Kind == HousePartKind.Door)
+ {
+ _draft.DoorStyle = style;
+ foreach (var key in _draft.Doors.Keys.ToList())
+ {
+ string piece = _draft.Doors[key].Piece;
+ if (style.Get(piece) != 0)
+ {
+ _draft.Doors[key] = (style, piece);
+ }
+ }
+ }
+ else if (style.Kind == HousePartKind.Stair)
+ {
+ _draft.StairStyle = style;
+ for (int i = 0; i < _draft.Stairs.Count; ++i)
+ {
+ var stairs = _draft.Stairs[i];
+ if (style.Get(stairs.Column) != 0)
+ {
+ _draft.Stairs[i] = (stairs.Storey, stairs.X, stairs.Y, stairs.Column, style);
+ }
+ }
+ }
+ }
+
+ /// Sets the wall style the foundation ring is built in; null is the client houses' own.
+ public void SetFoundationStyle(HouseStyle style)
+ {
+ if (style == null || style.Kind == HousePartKind.Wall)
+ {
+ Edit(() => _draft.FoundationStyle = style);
+ }
+ }
+
+ /// The themes this client can build.
+ public IReadOnlyList Themes => (IReadOnlyList)Context.HouseStyles?.Themes ?? Array.Empty();
+
+ ///
+ /// Gives the whole house the styles of a theme, as one step of the draft's history: walls
+ /// and floors of every storey, roof, flat roof, doors, stairs and foundation. Returns the
+ /// parts the theme names that this client does not have; those stay as they are.
+ ///
+ public List ApplyTheme(HouseTheme theme)
+ {
+ var missing = new List();
+ if (theme == null || Context.HouseStyles == null)
+ {
+ return missing;
+ }
+
+ EnsureMaterials();
+ HouseStyle Part(HousePartKind kind, ushort anchor, string what)
+ {
+ HouseStyle style = Context.HouseStyles.Find(kind, anchor);
+ if (style == null && anchor != 0)
+ {
+ missing.Add(what);
+ }
+
+ return style;
+ }
+
+ HouseStyle walls = Part(HousePartKind.Wall, theme.Walls, "walls"), floor = Part(HousePartKind.Floor, theme.Floor, "floor");
+ HouseStyle roof = Part(HousePartKind.Roof, theme.Roof, "roof"), flatRoof = Part(HousePartKind.Floor, theme.FlatRoof, "flat roof");
+ HouseStyle door = Part(HousePartKind.Door, theme.Door, "doors"), stairs = Part(HousePartKind.Stair, theme.Stairs, "stairs");
+ HouseStyle foundation = Part(HousePartKind.Wall, theme.Foundation, "foundation");
+ Edit(() =>
+ {
+ for (int k = 0; k < HouseDraft.MaxStoreys; ++k)
+ {
+ _draft.WallStyles[k] = walls ?? _draft.WallStyles[k];
+ _draft.FloorStyles[k] = floor ?? _draft.FloorStyles[k];
+ }
+
+ _draft.RoofStyle = roof ?? _draft.RoofStyle;
+ _draft.FlatRoofStyle = flatRoof ?? _draft.FlatRoofStyle;
+ _draft.FoundationStyle = foundation;
+ if (door != null)
+ {
+ Restyle(door);
+ }
+
+ if (stairs != null)
+ {
+ Restyle(stairs);
+ }
+ });
+ return missing;
+ }
+
+ /// The draft's styles as a theme of the given name: what "save as theme" stores.
+ public HouseTheme ThemeOfDraft(string name)
+ {
+ EnsureMaterials();
+ return new HouseTheme
+ {
+ Name = name,
+ Walls = _draft.WallStyles[0]?.Anchor ?? 0,
+ Floor = _draft.FloorStyles[0]?.Anchor ?? 0,
+ Roof = _draft.RoofStyle?.Anchor ?? 0,
+ FlatRoof = _draft.FlatRoofStyle?.Anchor ?? 0,
+ Door = _draft.DoorStyle?.Anchor ?? 0,
+ Stairs = _draft.StairStyle?.Anchor ?? 0,
+ Foundation = _draft.FoundationStyle?.Anchor ?? 0,
+ IsUser = true
+ };
+ }
+
+ /// The theme the draft's styles are, or null when they are a mix of the user's own.
+ public HouseTheme CurrentTheme()
+ {
+ if (Context.HouseStyles == null)
+ {
+ return null;
+ }
+
+ EnsureMaterials();
+ bool Is(HouseStyle style, HousePartKind kind, ushort anchor) => anchor == 0 || style == Context.HouseStyles.Find(kind, anchor);
+ foreach (HouseTheme theme in Themes)
+ {
+ bool storeys = true;
+ for (int k = 0; k < Math.Max(1, TopStorey) && storeys; ++k)
+ {
+ storeys = Is(_draft.WallStyles[k], HousePartKind.Wall, theme.Walls) && Is(_draft.FloorStyles[k], HousePartKind.Floor, theme.Floor);
+ }
+
+ if (storeys && Is(_draft.RoofStyle, HousePartKind.Roof, theme.Roof) &&
+ Is(_draft.FlatRoofStyle, HousePartKind.Floor, theme.FlatRoof) &&
+ Is(_draft.DoorStyle, HousePartKind.Door, theme.Door) && Is(_draft.StairStyle, HousePartKind.Stair, theme.Stairs) &&
+ _draft.FoundationStyle == Context.HouseStyles.Find(HousePartKind.Wall, theme.Foundation))
+ {
+ return theme;
+ }
+ }
+
+ return null;
+ }
+
/// Sets the floor style flat roofs are laid in.
public void SetFlatRoofStyle(HouseStyle style)
{
@@ -535,18 +785,30 @@ public void EditEdges(int storey, IReadOnlyCollection<(int X, int Y)> south, IRe
});
}
- /// Turns the wall in a cell into a window, or back. False when the cell has no straight wall.
+ ///
+ /// Turns the wall in a cell into a window, or back. A window the draft put there by itself
+ /// is set back to wall, and stays so. False when the cell has no straight wall.
+ ///
public bool ToggleWindow(int storey, int x, int y)
{
- EdgesOf(storey, out HashSet<(int X, int Y)> south, out HashSet<(int X, int Y)> east);
- if (south.Contains((x, y)) == east.Contains((x, y)))
+ HouseDraft.StoreyLayout layout = _draft.LayOut(Wings, storey);
+ if (layout.South.Contains((x, y)) == layout.East.Contains((x, y)))
{
return false;
}
Edit(() =>
{
- if (!_draft.Windows.Remove((storey, x, y)))
+ if (_draft.Windows.Remove((storey, x, y)))
+ {
+ return;
+ }
+
+ if (layout.Windows.Contains((x, y)))
+ {
+ _draft.Suppressed.Add((storey, x, y));
+ }
+ else if (!_draft.Suppressed.Remove((storey, x, y)) || !_draft.LayOut(Wings, storey).Windows.Contains((x, y)))
{
_draft.Windows.Add((storey, x, y));
_draft.Doors.Remove((storey, x, y));
@@ -565,7 +827,8 @@ public bool ToggleWindow(int storey, int x, int y)
///
public bool CycleDoor(int storey, int x, int y, HouseStyle style, bool remove)
{
- EdgesOf(storey, out HashSet<(int X, int Y)> south, out HashSet<(int X, int Y)> east);
+ HouseDraft.StoreyLayout layout = _draft.LayOut(Wings, storey);
+ HashSet<(int X, int Y)> south = layout.South, east = layout.East;
bool alongX = south.Contains((x, y));
if (alongX == east.Contains((x, y)))
{
@@ -575,12 +838,21 @@ public bool CycleDoor(int storey, int x, int y, HouseStyle style, bool remove)
bool has = _draft.Doors.TryGetValue((storey, x, y), out (HouseStyle Style, string Piece) door);
if (remove)
{
- if (has)
+ // A door the draft hung by itself is taken out for good: its doorway stays open.
+ bool own = layout.Doors.ContainsKey((x, y));
+ if (has || own)
{
- Edit(() => _draft.Doors.Remove((storey, x, y)));
+ Edit(() =>
+ {
+ _draft.Doors.Remove((storey, x, y));
+ if (own)
+ {
+ _draft.Suppressed.Add((storey, x, y));
+ }
+ });
}
- return has;
+ return has || own;
}
if (style == null || style.Kind != HousePartKind.Door)
@@ -649,8 +921,8 @@ protected override (List Remove, List<(ushort Id, int X, int Y, int Z
EnsureMaterials();
string key = string.Join(";", wings.Select(w =>
- $"{w.X0},{w.Y0},{w.X1},{w.Y1},{w.EaveZ},{w.Storeys},{w.Rooms},{w.Shape},{w.NoRoof},{w.RidgeAlongY}")) +
- $"|{_version}|{_roof.Gables}|{_roof.GableFill}|{Context.CompList.UndoList.Count}|{Context.CompList.RedoList.Count}";
+ $"{w.X0},{w.Y0},{w.X1},{w.Y1},{w.EaveZ},{w.Storeys},{w.Rooms},{w.Layout},{string.Join("/", w.RoomsAbove)},{w.Shape},{w.NoRoof},{w.RidgeAlongY}")) +
+ $"|{_version}|{_draft.Gables}|{_draft.GableFill}|{Context.CompList.UndoList.Count}|{Context.CompList.RedoList.Count}";
if (key == _builtFor)
{
return _built;
@@ -718,7 +990,20 @@ bool Hidden(int x, int y, int z)
// lies under the eaves of a taller one where the two meet.
foreach (IGrouping level in roofWings.GroupBy(r => r.EaveZ))
{
- var (roofRemove, roofAdd) = _roof.PlanRoof(level.ToList(), _draft.RoofStyle, built.Walls, Hidden);
+ // The house has gable settings of its own; the roof tool's are for roofs drawn with it.
+ (RoofGables gables, RoofGableFill fill) = (_roof.Gables, _roof.GableFill);
+ (_roof.Gables, _roof.GableFill) = (_draft.Gables, _draft.GableFill);
+ List roofRemove;
+ List<(ushort Id, int X, int Y, int Z, string Layer)> roofAdd;
+ try
+ {
+ (roofRemove, roofAdd) = _roof.PlanRoof(level.ToList(), _draft.RoofStyle, built.Walls, Hidden);
+ }
+ finally
+ {
+ (_roof.Gables, _roof.GableFill) = (gables, fill);
+ }
+
remove.AddRange(roofRemove.Where(t => !remove.Contains(t)));
foreach (var (id, x, y, z, layer) in roofAdd)
{
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/PlaneDragTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/PlaneDragTool.cs
index 153f80d3..73f636ae 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/PlaneDragTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/PlaneDragTool.cs
@@ -37,6 +37,8 @@ protected PlaneDragTool(IEditorContext context) : base(context)
public override bool IsDragging => _dragging;
+ public override (int Width, int Height)? DragSize => _dragging ? (Math.Abs(_endX - _startX) + 1, Math.Abs(_endY - _startY) + 1) : null;
+
public override bool TracksCursorCell => true;
/// The House tab style this tool works with, when it is the chosen one.
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/TileClickTools.cs b/UoFiddler.Plugin.MultiEditor/Tools/TileClickTools.cs
index e8a9506e..4a0466dd 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/TileClickTools.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/TileClickTools.cs
@@ -25,15 +25,17 @@ public AltitudeTool(IEditorContext context) : base(context)
public override void OnMouseUp(MouseEventArgs e)
{
+ // Shift lowers.
+ int step = (Control.ModifierKeys & Keys.Shift) != 0 ? -Context.ZStep : Context.ZStep;
if (Context.Selection.Count > 1)
{
- Context.CompList.TileZMod(Context.Selection, Context.ZStep);
+ Context.CompList.TileZMod(Context.Selection, step);
Context.AfterEdit();
}
else if (Context.HoverTile != null)
{
MultiTile tile = Context.HoverTile;
- Context.CompList.TileZMod(tile, Context.ZStep);
+ Context.CompList.TileZMod(tile, step);
Context.AfterEdit(tile.Z);
}
}
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
index 293de389..277a33db 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
@@ -47,6 +47,29 @@ internal sealed class RoofWing
///
public int Rooms { get; set; } = 1;
+ /// How the rooms of a house wing are laid out.
+ public RoomLayout Layout { get; set; }
+
+ ///
+ /// Rooms and layout of the storeys above the ground floor that have their own; a storey
+ /// without takes those of the storey below it. Index 0 is not used.
+ ///
+ public (int Rooms, RoomLayout Layout)?[] RoomsAbove { get; private set; } = new (int, RoomLayout)?[HouseDraft.MaxStoreys];
+
+ /// Rooms and layout of a storey.
+ public (int Rooms, RoomLayout Layout) RoomsOn(int storey)
+ {
+ for (int k = Math.Min(storey, HouseDraft.MaxStoreys - 1); k >= 1; --k)
+ {
+ if (RoomsAbove[k] is { } own)
+ {
+ return own;
+ }
+ }
+
+ return (Rooms, Layout);
+ }
+
public RoofShape Shape { get; set; }
public bool RidgeAlongY { get; set; }
@@ -56,13 +79,20 @@ internal sealed class RoofWing
public (int X0, int Y0, int X1, int Y1) Box => (X0, Y0, X1, Y1);
- public RoofWing Clone() => (RoofWing)MemberwiseClone();
+ public RoofWing Clone()
+ {
+ var copy = (RoofWing)MemberwiseClone();
+ copy.RoomsAbove = ((int, RoomLayout)?[])RoomsAbove.Clone();
+ return copy;
+ }
public void CopyFrom(RoofWing other)
{
(X0, Y0, X1, Y1, EaveZ) = (other.X0, other.Y0, other.X1, other.Y1, other.EaveZ);
(Shape, RidgeAlongY, RidgeAuto, Storeys, NoRoof) = (other.Shape, other.RidgeAlongY, other.RidgeAuto, other.Storeys, other.NoRoof);
Rooms = other.Rooms;
+ Layout = other.Layout;
+ RoomsAbove = ((int, RoomLayout)?[])other.RoomsAbove.Clone();
}
}
@@ -164,6 +194,13 @@ public int SelectedIndex
public override bool IsDragging => _drag != DragKind.None;
+ public override (int Width, int Height)? DragSize => _drag switch
+ {
+ DragKind.New => (Math.Abs(_endX - _startX) + 1, Math.Abs(_endY - _startY) + 1),
+ DragKind.Resize or DragKind.Move when SelectedWing is { } wing => (wing.X1 - wing.X0 + 1, wing.Y1 - wing.Y0 + 1),
+ _ => null
+ };
+
public override bool TracksCursorCell => true;
/// True when the tool has what it needs to build (its styles).
diff --git a/UoFiddler.Plugin.MultiEditor/UI/EditorCommands.cs b/UoFiddler.Plugin.MultiEditor/UI/EditorCommands.cs
index fa13537f..5d7fe26d 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/EditorCommands.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/EditorCommands.cs
@@ -119,19 +119,15 @@ public EditorCommand Add(EditorCommand command)
return command;
}
- /// Runs the command bound to a key. True when the key belongs to a command, also a disabled one.
+ /// Runs the command bound to a key. False when the key has no command or its command is disabled: the key is then free for whoever else wants it.
public bool TryRun(Keys keyData)
{
- if (!_byKey.TryGetValue(keyData, out EditorCommand command))
+ if (!_byKey.TryGetValue(keyData, out EditorCommand command) || !command.Enabled)
{
return false;
}
- if (command.Enabled)
- {
- command.Execute();
- }
-
+ command.Execute();
return true;
}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/EditorSettingsDialog.cs b/UoFiddler.Plugin.MultiEditor/UI/EditorSettingsDialog.cs
index d79ade19..b8e4ee7f 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/EditorSettingsDialog.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/EditorSettingsDialog.cs
@@ -165,7 +165,10 @@ private void Defaults_Click(object sender, EventArgs e)
TileBrowserWidth = _settings.TileBrowserWidth,
InspectorWidth = _settings.InspectorWidth,
HousePiecesHeight = _settings.HousePiecesHeight,
- DesignLibraryFolder = _settings.DesignLibraryFolder
+ DesignLibraryFolder = _settings.DesignLibraryFolder,
+ ImportFolder = _settings.ImportFolder,
+ ImportRecursive = _settings.ImportRecursive,
+ FavoriteBlueprintGroups = _settings.FavoriteBlueprintGroups
};
foreach (System.Reflection.PropertyInfo property in typeof(EditorSettings).GetProperties())
{
diff --git a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs
index c5476469..5dafc3bf 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs
@@ -28,15 +28,28 @@ protected override void Dispose(bool disposing)
///
private void InitializeComponent()
{
+ components = new System.ComponentModel.Container();
houseBox = new System.Windows.Forms.GroupBox();
+ _themeLabel = new System.Windows.Forms.Label();
+ _theme = new System.Windows.Forms.ComboBox();
+ _saveTheme = new System.Windows.Forms.Button();
+ _deleteTheme = new System.Windows.Forms.Button();
_wingList = new System.Windows.Forms.ListBox();
_wingHint = new System.Windows.Forms.Label();
_storeysLabel = new System.Windows.Forms.Label();
_storeys = new System.Windows.Forms.NumericUpDown();
+ _roomsLabel = new System.Windows.Forms.Label();
+ _rooms = new System.Windows.Forms.NumericUpDown();
_removeWing = new System.Windows.Forms.Button();
+ _layoutLabel = new System.Windows.Forms.Label();
+ _layout = new System.Windows.Forms.ComboBox();
+ _roomsPerStorey = new System.Windows.Forms.CheckBox();
_roofLabel = new System.Windows.Forms.Label();
_roofShape = new System.Windows.Forms.ComboBox();
_ridge = new System.Windows.Forms.ComboBox();
+ _gablesLabel = new System.Windows.Forms.Label();
+ _gables = new System.Windows.Forms.ComboBox();
+ _gableFill = new System.Windows.Forms.ComboBox();
_materialsLabel = new System.Windows.Forms.Label();
_storey1 = new System.Windows.Forms.Label();
_wall1 = new System.Windows.Forms.Button();
@@ -52,11 +65,20 @@ private void InitializeComponent()
_floor4 = new System.Windows.Forms.Button();
_roofStyleLabel = new System.Windows.Forms.Label();
_roofStyle = new System.Windows.Forms.Button();
+ _doorStyleLabel = new System.Windows.Forms.Label();
+ _doorStyle = new System.Windows.Forms.Button();
+ _stairStyleLabel = new System.Windows.Forms.Label();
+ _stairStyle = new System.Windows.Forms.Button();
_foundation = new System.Windows.Forms.CheckBox();
+ _foundationStyle = new System.Windows.Forms.Button();
_baseZLabel = new System.Windows.Forms.Label();
_baseZ = new System.Windows.Forms.NumericUpDown();
- _roomsLabel = new System.Windows.Forms.Label();
- _rooms = new System.Windows.Forms.NumericUpDown();
+ _autoDoors = new System.Windows.Forms.CheckBox();
+ _frontDoorLabel = new System.Windows.Forms.Label();
+ _frontDoor = new System.Windows.Forms.ComboBox();
+ _windowsLabel = new System.Windows.Forms.Label();
+ _windowSpacing = new System.Windows.Forms.NumericUpDown();
+ _windowsHint = new System.Windows.Forms.Label();
_showLabel = new System.Windows.Forms.Label();
_showWalls = new System.Windows.Forms.CheckBox();
_showFloors = new System.Windows.Forms.CheckBox();
@@ -72,22 +94,36 @@ private void InitializeComponent()
_placed = new System.Windows.Forms.ComboBox();
_edit = new System.Windows.Forms.Button();
_status = new System.Windows.Forms.Label();
+ _toolTip = new System.Windows.Forms.ToolTip(components);
houseBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)_storeys).BeginInit();
- ((System.ComponentModel.ISupportInitialize)_baseZ).BeginInit();
((System.ComponentModel.ISupportInitialize)_rooms).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)_baseZ).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)_windowSpacing).BeginInit();
SuspendLayout();
//
// houseBox
//
+ houseBox.Controls.Add(_themeLabel);
+ houseBox.Controls.Add(_theme);
+ houseBox.Controls.Add(_saveTheme);
+ houseBox.Controls.Add(_deleteTheme);
houseBox.Controls.Add(_wingList);
houseBox.Controls.Add(_wingHint);
houseBox.Controls.Add(_storeysLabel);
houseBox.Controls.Add(_storeys);
+ houseBox.Controls.Add(_roomsLabel);
+ houseBox.Controls.Add(_rooms);
houseBox.Controls.Add(_removeWing);
+ houseBox.Controls.Add(_layoutLabel);
+ houseBox.Controls.Add(_layout);
+ houseBox.Controls.Add(_roomsPerStorey);
houseBox.Controls.Add(_roofLabel);
houseBox.Controls.Add(_roofShape);
houseBox.Controls.Add(_ridge);
+ houseBox.Controls.Add(_gablesLabel);
+ houseBox.Controls.Add(_gables);
+ houseBox.Controls.Add(_gableFill);
houseBox.Controls.Add(_materialsLabel);
houseBox.Controls.Add(_storey1);
houseBox.Controls.Add(_wall1);
@@ -103,11 +139,20 @@ private void InitializeComponent()
houseBox.Controls.Add(_floor4);
houseBox.Controls.Add(_roofStyleLabel);
houseBox.Controls.Add(_roofStyle);
+ houseBox.Controls.Add(_doorStyleLabel);
+ houseBox.Controls.Add(_doorStyle);
+ houseBox.Controls.Add(_stairStyleLabel);
+ houseBox.Controls.Add(_stairStyle);
houseBox.Controls.Add(_foundation);
+ houseBox.Controls.Add(_foundationStyle);
houseBox.Controls.Add(_baseZLabel);
houseBox.Controls.Add(_baseZ);
- houseBox.Controls.Add(_roomsLabel);
- houseBox.Controls.Add(_rooms);
+ houseBox.Controls.Add(_autoDoors);
+ houseBox.Controls.Add(_frontDoorLabel);
+ houseBox.Controls.Add(_frontDoor);
+ houseBox.Controls.Add(_windowsLabel);
+ houseBox.Controls.Add(_windowSpacing);
+ houseBox.Controls.Add(_windowsHint);
houseBox.Controls.Add(_showLabel);
houseBox.Controls.Add(_showWalls);
houseBox.Controls.Add(_showFloors);
@@ -123,72 +168,174 @@ private void InitializeComponent()
houseBox.Controls.Add(_placed);
houseBox.Controls.Add(_edit);
houseBox.Controls.Add(_status);
- houseBox.Dock = System.Windows.Forms.DockStyle.Fill;
+ houseBox.Dock = System.Windows.Forms.DockStyle.Top;
houseBox.Location = new System.Drawing.Point(0, 0);
houseBox.Name = "houseBox";
- houseBox.Size = new System.Drawing.Size(250, 518);
+ houseBox.Size = new System.Drawing.Size(250, 743);
houseBox.TabIndex = 0;
houseBox.TabStop = false;
houseBox.Text = "House draft";
//
+ // _themeLabel
+ //
+ _themeLabel.AutoSize = true;
+ _themeLabel.Location = new System.Drawing.Point(6, 24);
+ _themeLabel.Name = "_themeLabel";
+ _themeLabel.Size = new System.Drawing.Size(44, 15);
+ _themeLabel.TabIndex = 0;
+ _themeLabel.Text = "Theme";
+ //
+ // _theme
+ //
+ _theme.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _theme.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ _theme.FormattingEnabled = true;
+ _theme.Location = new System.Drawing.Point(60, 20);
+ _theme.Name = "_theme";
+ _theme.Size = new System.Drawing.Size(108, 23);
+ _theme.TabIndex = 1;
+ _toolTip.SetToolTip(_theme, "Gives the whole house the styles of a theme: walls, floors, roof, doors, stairs and foundation.");
+ _theme.SelectionChangeCommitted += Theme_SelectionChangeCommitted;
+ //
+ // _saveTheme
+ //
+ _saveTheme.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right;
+ _saveTheme.Location = new System.Drawing.Point(172, 20);
+ _saveTheme.Name = "_saveTheme";
+ _saveTheme.Size = new System.Drawing.Size(38, 25);
+ _saveTheme.TabIndex = 2;
+ _saveTheme.Text = "Save";
+ _saveTheme.AutoEllipsis = true;
+ _saveTheme.UseVisualStyleBackColor = true;
+ _toolTip.SetToolTip(_saveTheme, "Saves the styles of this house as a theme of your own.");
+ _saveTheme.Click += SaveTheme_Click;
+ //
+ // _deleteTheme
+ //
+ _deleteTheme.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right;
+ _deleteTheme.Location = new System.Drawing.Point(212, 20);
+ _deleteTheme.Name = "_deleteTheme";
+ _deleteTheme.Size = new System.Drawing.Size(32, 25);
+ _deleteTheme.TabIndex = 3;
+ _deleteTheme.Text = "Del";
+ _deleteTheme.AutoEllipsis = true;
+ _deleteTheme.UseVisualStyleBackColor = true;
+ _toolTip.SetToolTip(_deleteTheme, "Deletes the chosen theme, if it is one of your own.");
+ _deleteTheme.Click += DeleteTheme_Click;
+ //
// _wingList
//
_wingList.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
_wingList.FormattingEnabled = true;
_wingList.IntegralHeight = false;
- _wingList.Location = new System.Drawing.Point(6, 20);
+ _wingList.ItemHeight = 15;
+ _wingList.Location = new System.Drawing.Point(6, 48);
_wingList.Name = "_wingList";
_wingList.Size = new System.Drawing.Size(238, 64);
- _wingList.TabIndex = 0;
+ _wingList.TabIndex = 4;
_wingList.SelectedIndexChanged += WingList_SelectedIndexChanged;
//
// _wingHint
//
_wingHint.AutoSize = true;
- _wingHint.Location = new System.Drawing.Point(6, 90);
+ _wingHint.Location = new System.Drawing.Point(6, 118);
_wingHint.Name = "_wingHint";
_wingHint.Size = new System.Drawing.Size(120, 15);
- _wingHint.TabIndex = 1;
+ _wingHint.TabIndex = 5;
_wingHint.Text = "New wings:";
//
// _storeysLabel
//
_storeysLabel.AutoSize = true;
- _storeysLabel.Location = new System.Drawing.Point(6, 113);
+ _storeysLabel.Location = new System.Drawing.Point(6, 141);
_storeysLabel.Name = "_storeysLabel";
_storeysLabel.Size = new System.Drawing.Size(50, 15);
- _storeysLabel.TabIndex = 2;
+ _storeysLabel.TabIndex = 6;
_storeysLabel.Text = "Storeys";
//
// _storeys
//
+ _storeys.Location = new System.Drawing.Point(60, 138);
_storeys.Maximum = new decimal(new int[] { 4, 0, 0, 0 });
_storeys.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
- _storeys.Value = new decimal(new int[] { 1, 0, 0, 0 });
- _storeys.Location = new System.Drawing.Point(60, 110);
_storeys.Name = "_storeys";
_storeys.Size = new System.Drawing.Size(44, 23);
- _storeys.TabIndex = 3;
+ _storeys.TabIndex = 7;
+ _storeys.Value = new decimal(new int[] { 1, 0, 0, 0 });
_storeys.ValueChanged += Storeys_ValueChanged;
//
+ // _roomsLabel
+ //
+ _roomsLabel.AutoSize = true;
+ _roomsLabel.Location = new System.Drawing.Point(110, 141);
+ _roomsLabel.Name = "_roomsLabel";
+ _roomsLabel.Size = new System.Drawing.Size(44, 15);
+ _roomsLabel.TabIndex = 8;
+ _roomsLabel.Text = "Rooms";
+ //
+ // _rooms
+ //
+ _rooms.Location = new System.Drawing.Point(156, 138);
+ _rooms.Maximum = new decimal(new int[] { 6, 0, 0, 0 });
+ _rooms.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
+ _rooms.Name = "_rooms";
+ _rooms.Size = new System.Drawing.Size(44, 23);
+ _rooms.TabIndex = 9;
+ _rooms.Value = new decimal(new int[] { 1, 0, 0, 0 });
+ _rooms.ValueChanged += Rooms_ValueChanged;
+ //
// _removeWing
//
_removeWing.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right;
- _removeWing.UseVisualStyleBackColor = true;
- _removeWing.Location = new System.Drawing.Point(206, 109);
+ _removeWing.Location = new System.Drawing.Point(206, 137);
_removeWing.Name = "_removeWing";
_removeWing.Size = new System.Drawing.Size(38, 25);
- _removeWing.TabIndex = 4;
+ _removeWing.TabIndex = 10;
_removeWing.Text = "Del";
+ _removeWing.AutoEllipsis = true;
+ _removeWing.UseVisualStyleBackColor = true;
_removeWing.Click += RemoveWing_Click;
//
+ // _layoutLabel
+ //
+ _layoutLabel.AutoSize = true;
+ _layoutLabel.Location = new System.Drawing.Point(6, 171);
+ _layoutLabel.Name = "_layoutLabel";
+ _layoutLabel.Size = new System.Drawing.Size(50, 15);
+ _layoutLabel.TabIndex = 11;
+ _layoutLabel.Text = "Layout";
+ //
+ // _layout
+ //
+ _layout.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ _layout.FormattingEnabled = true;
+ _layout.Items.AddRange(new object[] { "Row", "Grid", "Corridor", "Hall" });
+ _layout.Location = new System.Drawing.Point(60, 168);
+ _layout.Name = "_layout";
+ _layout.Size = new System.Drawing.Size(100, 23);
+ _layout.TabIndex = 12;
+ _toolTip.SetToolTip(_layout, "How the rooms of the wing are laid out. Row: side by side. Grid: two rows. Corridor: a hall with rooms on both sides. Hall: one large room and a row of small ones.");
+ _layout.SelectedIndexChanged += Layout_SelectedIndexChanged;
+ //
+ // _roomsPerStorey
+ //
+ _roomsPerStorey.AutoSize = true;
+ _roomsPerStorey.Location = new System.Drawing.Point(166, 170);
+ _roomsPerStorey.Name = "_roomsPerStorey";
+ _roomsPerStorey.Size = new System.Drawing.Size(80, 19);
+ _roomsPerStorey.TabIndex = 13;
+ _roomsPerStorey.Text = "This storey";
+ _roomsPerStorey.UseVisualStyleBackColor = true;
+ _toolTip.SetToolTip(_roomsPerStorey, "Rooms and layout apply to the storey of the chosen floor only; other storeys keep theirs.");
+ _roomsPerStorey.CheckedChanged += RoomsPerStorey_CheckedChanged;
+ //
// _roofLabel
//
_roofLabel.AutoSize = true;
- _roofLabel.Location = new System.Drawing.Point(6, 143);
+ _roofLabel.Location = new System.Drawing.Point(6, 201);
_roofLabel.Name = "_roofLabel";
_roofLabel.Size = new System.Drawing.Size(50, 15);
- _roofLabel.TabIndex = 5;
+ _roofLabel.TabIndex = 14;
_roofLabel.Text = "Roof";
//
// _roofShape
@@ -196,10 +343,10 @@ private void InitializeComponent()
_roofShape.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
_roofShape.FormattingEnabled = true;
_roofShape.Items.AddRange(new object[] { "Gable", "Hip", "Flat", "None" });
- _roofShape.Location = new System.Drawing.Point(60, 140);
+ _roofShape.Location = new System.Drawing.Point(60, 198);
_roofShape.Name = "_roofShape";
_roofShape.Size = new System.Drawing.Size(80, 23);
- _roofShape.TabIndex = 6;
+ _roofShape.TabIndex = 15;
_roofShape.SelectedIndexChanged += RoofShape_SelectedIndexChanged;
//
// _ridge
@@ -208,208 +355,345 @@ private void InitializeComponent()
_ridge.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
_ridge.FormattingEnabled = true;
_ridge.Items.AddRange(new object[] { "Ridge: auto", "Ridge along X", "Ridge along Y" });
- _ridge.Location = new System.Drawing.Point(146, 140);
+ _ridge.Location = new System.Drawing.Point(146, 198);
_ridge.Name = "_ridge";
_ridge.Size = new System.Drawing.Size(98, 23);
- _ridge.TabIndex = 7;
+ _ridge.TabIndex = 16;
_ridge.SelectedIndexChanged += Ridge_SelectedIndexChanged;
//
+ // _gablesLabel
+ //
+ _gablesLabel.AutoSize = true;
+ _gablesLabel.Location = new System.Drawing.Point(6, 231);
+ _gablesLabel.Name = "_gablesLabel";
+ _gablesLabel.Size = new System.Drawing.Size(50, 15);
+ _gablesLabel.TabIndex = 17;
+ _gablesLabel.Text = "Gables";
+ //
+ // _gables
+ //
+ _gables.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ _gables.FormattingEnabled = true;
+ _gables.Items.AddRange(new object[] { "Front", "Both", "None" });
+ _gables.Location = new System.Drawing.Point(60, 228);
+ _gables.Name = "_gables";
+ _gables.Size = new System.Drawing.Size(80, 23);
+ _gables.TabIndex = 18;
+ _toolTip.SetToolTip(_gables, "Which gable ends of the roofs are closed.");
+ _gables.SelectedIndexChanged += Gables_SelectedIndexChanged;
+ //
+ // _gableFill
+ //
+ _gableFill.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _gableFill.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ _gableFill.FormattingEnabled = true;
+ _gableFill.Items.AddRange(new object[] { "Fill: caps", "Fill: walls" });
+ _gableFill.Location = new System.Drawing.Point(146, 228);
+ _gableFill.Name = "_gableFill";
+ _gableFill.Size = new System.Drawing.Size(98, 23);
+ _gableFill.TabIndex = 19;
+ _toolTip.SetToolTip(_gableFill, "Caps: 3 high cap pieces. Walls: whole wall pieces as far as they fit under the slope.");
+ _gableFill.SelectedIndexChanged += Gables_SelectedIndexChanged;
+ //
// _materialsLabel
//
- _materialsLabel.Location = new System.Drawing.Point(6, 172);
+ _materialsLabel.Location = new System.Drawing.Point(6, 260);
_materialsLabel.Name = "_materialsLabel";
_materialsLabel.Size = new System.Drawing.Size(238, 15);
- _materialsLabel.TabIndex = 8;
+ _materialsLabel.TabIndex = 20;
_materialsLabel.Text = "Storey: walls and floor style";
//
// _storey1
//
- _storey1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- _storey1.Location = new System.Drawing.Point(6, 196);
+ _storey1.Location = new System.Drawing.Point(6, 282);
_storey1.Name = "_storey1";
_storey1.Size = new System.Drawing.Size(18, 17);
- _storey1.TabIndex = 9;
+ _storey1.TabIndex = 21;
_storey1.Text = "1";
+ _storey1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// _wall1
//
- _wall1.UseVisualStyleBackColor = true;
- _wall1.Location = new System.Drawing.Point(28, 192);
+ _wall1.Location = new System.Drawing.Point(28, 278);
_wall1.Name = "_wall1";
_wall1.Size = new System.Drawing.Size(106, 25);
- _wall1.TabIndex = 10;
+ _wall1.TabIndex = 22;
_wall1.Text = "(walls)";
+ _wall1.AutoEllipsis = true;
+ _wall1.UseVisualStyleBackColor = true;
//
// _floor1
//
_floor1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _floor1.UseVisualStyleBackColor = true;
- _floor1.Location = new System.Drawing.Point(138, 192);
+ _floor1.Location = new System.Drawing.Point(138, 278);
_floor1.Name = "_floor1";
_floor1.Size = new System.Drawing.Size(106, 25);
- _floor1.TabIndex = 11;
+ _floor1.TabIndex = 23;
_floor1.Text = "(floor)";
+ _floor1.AutoEllipsis = true;
+ _floor1.UseVisualStyleBackColor = true;
//
// _storey2
//
- _storey2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- _storey2.Location = new System.Drawing.Point(6, 223);
+ _storey2.Location = new System.Drawing.Point(6, 309);
_storey2.Name = "_storey2";
_storey2.Size = new System.Drawing.Size(18, 17);
- _storey2.TabIndex = 12;
+ _storey2.TabIndex = 24;
_storey2.Text = "2";
+ _storey2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// _wall2
//
- _wall2.UseVisualStyleBackColor = true;
- _wall2.Location = new System.Drawing.Point(28, 219);
+ _wall2.Location = new System.Drawing.Point(28, 305);
_wall2.Name = "_wall2";
_wall2.Size = new System.Drawing.Size(106, 25);
- _wall2.TabIndex = 13;
+ _wall2.TabIndex = 25;
_wall2.Text = "(walls)";
+ _wall2.AutoEllipsis = true;
+ _wall2.UseVisualStyleBackColor = true;
//
// _floor2
//
_floor2.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _floor2.UseVisualStyleBackColor = true;
- _floor2.Location = new System.Drawing.Point(138, 219);
+ _floor2.Location = new System.Drawing.Point(138, 305);
_floor2.Name = "_floor2";
_floor2.Size = new System.Drawing.Size(106, 25);
- _floor2.TabIndex = 14;
+ _floor2.TabIndex = 26;
_floor2.Text = "(floor)";
+ _floor2.AutoEllipsis = true;
+ _floor2.UseVisualStyleBackColor = true;
//
// _storey3
//
- _storey3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- _storey3.Location = new System.Drawing.Point(6, 250);
+ _storey3.Location = new System.Drawing.Point(6, 336);
_storey3.Name = "_storey3";
_storey3.Size = new System.Drawing.Size(18, 17);
- _storey3.TabIndex = 15;
+ _storey3.TabIndex = 27;
_storey3.Text = "3";
+ _storey3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// _wall3
//
- _wall3.UseVisualStyleBackColor = true;
- _wall3.Location = new System.Drawing.Point(28, 246);
+ _wall3.Location = new System.Drawing.Point(28, 332);
_wall3.Name = "_wall3";
_wall3.Size = new System.Drawing.Size(106, 25);
- _wall3.TabIndex = 16;
+ _wall3.TabIndex = 28;
_wall3.Text = "(walls)";
+ _wall3.AutoEllipsis = true;
+ _wall3.UseVisualStyleBackColor = true;
//
// _floor3
//
_floor3.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _floor3.UseVisualStyleBackColor = true;
- _floor3.Location = new System.Drawing.Point(138, 246);
+ _floor3.Location = new System.Drawing.Point(138, 332);
_floor3.Name = "_floor3";
_floor3.Size = new System.Drawing.Size(106, 25);
- _floor3.TabIndex = 17;
+ _floor3.TabIndex = 29;
_floor3.Text = "(floor)";
+ _floor3.AutoEllipsis = true;
+ _floor3.UseVisualStyleBackColor = true;
//
// _storey4
//
- _storey4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- _storey4.Location = new System.Drawing.Point(6, 277);
+ _storey4.Location = new System.Drawing.Point(6, 363);
_storey4.Name = "_storey4";
_storey4.Size = new System.Drawing.Size(18, 17);
- _storey4.TabIndex = 18;
+ _storey4.TabIndex = 30;
_storey4.Text = "4";
+ _storey4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// _wall4
//
- _wall4.UseVisualStyleBackColor = true;
- _wall4.Location = new System.Drawing.Point(28, 273);
+ _wall4.Location = new System.Drawing.Point(28, 359);
_wall4.Name = "_wall4";
_wall4.Size = new System.Drawing.Size(106, 25);
- _wall4.TabIndex = 19;
+ _wall4.TabIndex = 31;
_wall4.Text = "(walls)";
+ _wall4.AutoEllipsis = true;
+ _wall4.UseVisualStyleBackColor = true;
//
// _floor4
//
_floor4.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _floor4.UseVisualStyleBackColor = true;
- _floor4.Location = new System.Drawing.Point(138, 273);
+ _floor4.Location = new System.Drawing.Point(138, 359);
_floor4.Name = "_floor4";
_floor4.Size = new System.Drawing.Size(106, 25);
- _floor4.TabIndex = 20;
+ _floor4.TabIndex = 32;
_floor4.Text = "(floor)";
+ _floor4.AutoEllipsis = true;
+ _floor4.UseVisualStyleBackColor = true;
//
// _roofStyleLabel
//
_roofStyleLabel.AutoSize = true;
- _roofStyleLabel.Location = new System.Drawing.Point(6, 305);
+ _roofStyleLabel.Location = new System.Drawing.Point(6, 391);
_roofStyleLabel.Name = "_roofStyleLabel";
_roofStyleLabel.Size = new System.Drawing.Size(50, 15);
- _roofStyleLabel.TabIndex = 21;
+ _roofStyleLabel.TabIndex = 33;
_roofStyleLabel.Text = "Roof";
//
// _roofStyle
//
_roofStyle.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _roofStyle.UseVisualStyleBackColor = true;
- _roofStyle.Location = new System.Drawing.Point(60, 300);
+ _roofStyle.Location = new System.Drawing.Point(60, 386);
_roofStyle.Name = "_roofStyle";
_roofStyle.Size = new System.Drawing.Size(184, 25);
- _roofStyle.TabIndex = 22;
+ _roofStyle.TabIndex = 34;
_roofStyle.Text = "(roof)";
+ _roofStyle.AutoEllipsis = true;
+ _roofStyle.UseVisualStyleBackColor = true;
+ //
+ // _doorStyleLabel
+ //
+ _doorStyleLabel.AutoSize = true;
+ _doorStyleLabel.Location = new System.Drawing.Point(6, 418);
+ _doorStyleLabel.Name = "_doorStyleLabel";
+ _doorStyleLabel.Size = new System.Drawing.Size(50, 15);
+ _doorStyleLabel.TabIndex = 35;
+ _doorStyleLabel.Text = "Doors";
+ //
+ // _doorStyle
+ //
+ _doorStyle.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _doorStyle.Location = new System.Drawing.Point(60, 413);
+ _doorStyle.Name = "_doorStyle";
+ _doorStyle.Size = new System.Drawing.Size(184, 25);
+ _doorStyle.TabIndex = 36;
+ _doorStyle.Text = "(doors)";
+ _doorStyle.AutoEllipsis = true;
+ _doorStyle.UseVisualStyleBackColor = true;
+ //
+ // _stairStyleLabel
+ //
+ _stairStyleLabel.AutoSize = true;
+ _stairStyleLabel.Location = new System.Drawing.Point(6, 445);
+ _stairStyleLabel.Name = "_stairStyleLabel";
+ _stairStyleLabel.Size = new System.Drawing.Size(50, 15);
+ _stairStyleLabel.TabIndex = 37;
+ _stairStyleLabel.Text = "Stairs";
+ //
+ // _stairStyle
+ //
+ _stairStyle.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _stairStyle.Location = new System.Drawing.Point(60, 440);
+ _stairStyle.Name = "_stairStyle";
+ _stairStyle.Size = new System.Drawing.Size(184, 25);
+ _stairStyle.TabIndex = 38;
+ _stairStyle.Text = "(stairs)";
+ _stairStyle.AutoEllipsis = true;
+ _stairStyle.UseVisualStyleBackColor = true;
//
// _foundation
//
_foundation.AutoSize = true;
- _foundation.UseVisualStyleBackColor = true;
- _foundation.Location = new System.Drawing.Point(6, 332);
+ _foundation.Location = new System.Drawing.Point(6, 471);
_foundation.Name = "_foundation";
- _foundation.Size = new System.Drawing.Size(100, 19);
- _foundation.TabIndex = 23;
+ _foundation.Size = new System.Drawing.Size(86, 19);
+ _foundation.TabIndex = 39;
_foundation.Text = "Foundation";
+ _foundation.UseVisualStyleBackColor = true;
_foundation.CheckedChanged += Foundation_CheckedChanged;
//
+ // _foundationStyle
+ //
+ _foundationStyle.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _foundationStyle.Location = new System.Drawing.Point(96, 467);
+ _foundationStyle.Name = "_foundationStyle";
+ _foundationStyle.Size = new System.Drawing.Size(148, 25);
+ _foundationStyle.TabIndex = 40;
+ _foundationStyle.Text = "(foundation)";
+ _foundationStyle.AutoEllipsis = true;
+ _foundationStyle.UseVisualStyleBackColor = true;
+ //
// _baseZLabel
//
_baseZLabel.AutoSize = true;
- _baseZLabel.Location = new System.Drawing.Point(126, 334);
+ _baseZLabel.Location = new System.Drawing.Point(6, 499);
_baseZLabel.Name = "_baseZLabel";
_baseZLabel.Size = new System.Drawing.Size(44, 15);
- _baseZLabel.TabIndex = 24;
+ _baseZLabel.TabIndex = 41;
_baseZLabel.Text = "Base Z";
//
// _baseZ
//
+ _baseZ.Location = new System.Drawing.Point(60, 496);
_baseZ.Maximum = new decimal(new int[] { 100, 0, 0, 0 });
_baseZ.Minimum = new decimal(new int[] { 100, 0, 0, int.MinValue });
- _baseZ.Location = new System.Drawing.Point(174, 331);
_baseZ.Name = "_baseZ";
_baseZ.Size = new System.Drawing.Size(56, 23);
- _baseZ.TabIndex = 25;
+ _baseZ.TabIndex = 42;
_baseZ.ValueChanged += BaseZ_ValueChanged;
//
- // _roomsLabel
- //
- _roomsLabel.AutoSize = true;
- _roomsLabel.Location = new System.Drawing.Point(110, 113);
- _roomsLabel.Name = "_roomsLabel";
- _roomsLabel.Size = new System.Drawing.Size(44, 15);
- _roomsLabel.TabIndex = 26;
- _roomsLabel.Text = "Rooms";
- //
- // _rooms
- //
- _rooms.Maximum = new decimal(new int[] { 6, 0, 0, 0 });
- _rooms.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
- _rooms.Value = new decimal(new int[] { 1, 0, 0, 0 });
- _rooms.Location = new System.Drawing.Point(156, 110);
- _rooms.Name = "_rooms";
- _rooms.Size = new System.Drawing.Size(44, 23);
- _rooms.TabIndex = 27;
- _rooms.ValueChanged += Rooms_ValueChanged;
+ // _autoDoors
+ //
+ _autoDoors.AutoSize = true;
+ _autoDoors.Location = new System.Drawing.Point(6, 529);
+ _autoDoors.Name = "_autoDoors";
+ _autoDoors.Size = new System.Drawing.Size(96, 19);
+ _autoDoors.TabIndex = 43;
+ _autoDoors.Text = "Room doors";
+ _autoDoors.UseVisualStyleBackColor = true;
+ _toolTip.SetToolTip(_autoDoors, "Puts a door of the house's door style in every doorway between rooms.");
+ _autoDoors.CheckedChanged += AutoDoors_CheckedChanged;
+ //
+ // _frontDoorLabel
+ //
+ _frontDoorLabel.AutoSize = true;
+ _frontDoorLabel.Location = new System.Drawing.Point(110, 530);
+ _frontDoorLabel.Name = "_frontDoorLabel";
+ _frontDoorLabel.Size = new System.Drawing.Size(62, 15);
+ _frontDoorLabel.TabIndex = 44;
+ _frontDoorLabel.Text = "Front door";
+ //
+ // _frontDoor
+ //
+ _frontDoor.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _frontDoor.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ _frontDoor.FormattingEnabled = true;
+ _frontDoor.Items.AddRange(new object[] { "None", "South", "East" });
+ _frontDoor.Location = new System.Drawing.Point(176, 526);
+ _frontDoor.Name = "_frontDoor";
+ _frontDoor.Size = new System.Drawing.Size(68, 23);
+ _frontDoor.TabIndex = 45;
+ _toolTip.SetToolTip(_frontDoor, "The outer wall of the first wing that gets the front door.");
+ _frontDoor.SelectedIndexChanged += FrontDoor_SelectedIndexChanged;
+ //
+ // _windowsLabel
+ //
+ _windowsLabel.AutoSize = true;
+ _windowsLabel.Location = new System.Drawing.Point(6, 557);
+ _windowsLabel.Name = "_windowsLabel";
+ _windowsLabel.Size = new System.Drawing.Size(90, 15);
+ _windowsLabel.TabIndex = 46;
+ _windowsLabel.Text = "Windows every";
+ //
+ // _windowSpacing
+ //
+ _windowSpacing.Location = new System.Drawing.Point(100, 554);
+ _windowSpacing.Maximum = new decimal(new int[] { 12, 0, 0, 0 });
+ _windowSpacing.Minimum = new decimal(new int[] { 0, 0, 0, 0 });
+ _windowSpacing.Name = "_windowSpacing";
+ _windowSpacing.Size = new System.Drawing.Size(44, 23);
+ _windowSpacing.TabIndex = 47;
+ _toolTip.SetToolTip(_windowSpacing, "Puts windows along the outer walls, this many cells apart. 0: none.");
+ _windowSpacing.ValueChanged += WindowSpacing_ValueChanged;
+ //
+ // _windowsHint
+ //
+ _windowsHint.AutoSize = true;
+ _windowsHint.Location = new System.Drawing.Point(150, 557);
+ _windowsHint.Name = "_windowsHint";
+ _windowsHint.Size = new System.Drawing.Size(90, 15);
+ _windowsHint.TabIndex = 48;
+ _windowsHint.Text = "cells (0: none)";
//
// _showLabel
//
_showLabel.AutoSize = true;
- _showLabel.Location = new System.Drawing.Point(6, 364);
+ _showLabel.Location = new System.Drawing.Point(6, 586);
_showLabel.Name = "_showLabel";
_showLabel.Size = new System.Drawing.Size(50, 15);
- _showLabel.TabIndex = 28;
+ _showLabel.TabIndex = 49;
_showLabel.Text = "Preview";
//
// _showWalls
@@ -417,12 +701,12 @@ private void InitializeComponent()
_showWalls.AutoSize = true;
_showWalls.Checked = true;
_showWalls.CheckState = System.Windows.Forms.CheckState.Checked;
- _showWalls.UseVisualStyleBackColor = true;
- _showWalls.Location = new System.Drawing.Point(60, 362);
+ _showWalls.Location = new System.Drawing.Point(60, 584);
_showWalls.Name = "_showWalls";
_showWalls.Size = new System.Drawing.Size(56, 19);
- _showWalls.TabIndex = 29;
+ _showWalls.TabIndex = 50;
_showWalls.Text = "Walls";
+ _showWalls.UseVisualStyleBackColor = true;
_showWalls.CheckedChanged += Show_CheckedChanged;
//
// _showFloors
@@ -430,12 +714,12 @@ private void InitializeComponent()
_showFloors.AutoSize = true;
_showFloors.Checked = true;
_showFloors.CheckState = System.Windows.Forms.CheckState.Checked;
- _showFloors.UseVisualStyleBackColor = true;
- _showFloors.Location = new System.Drawing.Point(122, 362);
+ _showFloors.Location = new System.Drawing.Point(122, 584);
_showFloors.Name = "_showFloors";
_showFloors.Size = new System.Drawing.Size(60, 19);
- _showFloors.TabIndex = 30;
+ _showFloors.TabIndex = 51;
_showFloors.Text = "Floors";
+ _showFloors.UseVisualStyleBackColor = true;
_showFloors.CheckedChanged += Show_CheckedChanged;
//
// _showRoof
@@ -443,93 +727,100 @@ private void InitializeComponent()
_showRoof.AutoSize = true;
_showRoof.Checked = true;
_showRoof.CheckState = System.Windows.Forms.CheckState.Checked;
- _showRoof.UseVisualStyleBackColor = true;
- _showRoof.Location = new System.Drawing.Point(188, 362);
+ _showRoof.Location = new System.Drawing.Point(188, 584);
_showRoof.Name = "_showRoof";
_showRoof.Size = new System.Drawing.Size(52, 19);
- _showRoof.TabIndex = 31;
+ _showRoof.TabIndex = 52;
_showRoof.Text = "Roof";
+ _showRoof.UseVisualStyleBackColor = true;
_showRoof.CheckedChanged += Show_CheckedChanged;
//
// _undo
//
- _undo.UseVisualStyleBackColor = true;
- _undo.Location = new System.Drawing.Point(6, 392);
+ _undo.Location = new System.Drawing.Point(6, 612);
_undo.Name = "_undo";
_undo.Size = new System.Drawing.Size(54, 25);
- _undo.TabIndex = 32;
+ _undo.TabIndex = 53;
_undo.Text = "Undo";
+ _undo.AutoEllipsis = true;
+ _undo.UseVisualStyleBackColor = true;
_undo.Click += Undo_Click;
//
// _redo
//
- _redo.UseVisualStyleBackColor = true;
- _redo.Location = new System.Drawing.Point(62, 392);
+ _redo.Location = new System.Drawing.Point(62, 612);
_redo.Name = "_redo";
_redo.Size = new System.Drawing.Size(54, 25);
- _redo.TabIndex = 33;
+ _redo.TabIndex = 54;
_redo.Text = "Redo";
+ _redo.AutoEllipsis = true;
+ _redo.UseVisualStyleBackColor = true;
_redo.Click += Redo_Click;
//
// _place
//
- _place.UseVisualStyleBackColor = true;
- _place.Location = new System.Drawing.Point(122, 392);
+ _place.Location = new System.Drawing.Point(122, 612);
_place.Name = "_place";
_place.Size = new System.Drawing.Size(72, 25);
- _place.TabIndex = 34;
+ _place.TabIndex = 55;
_place.Text = "Place";
+ _place.AutoEllipsis = true;
+ _place.UseVisualStyleBackColor = true;
_place.Click += Place_Click;
//
// _drop
//
_drop.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _drop.UseVisualStyleBackColor = true;
- _drop.Location = new System.Drawing.Point(196, 392);
+ _drop.Location = new System.Drawing.Point(196, 612);
_drop.Name = "_drop";
_drop.Size = new System.Drawing.Size(48, 25);
- _drop.TabIndex = 35;
+ _drop.TabIndex = 56;
_drop.Text = "Drop";
+ _drop.AutoEllipsis = true;
+ _drop.UseVisualStyleBackColor = true;
_drop.Click += Drop_Click;
//
// _saveDraft
//
- _saveDraft.UseVisualStyleBackColor = true;
- _saveDraft.Location = new System.Drawing.Point(6, 421);
+ _saveDraft.Location = new System.Drawing.Point(6, 641);
_saveDraft.Name = "_saveDraft";
_saveDraft.Size = new System.Drawing.Size(76, 25);
- _saveDraft.TabIndex = 36;
+ _saveDraft.TabIndex = 57;
_saveDraft.Text = "Save draft";
+ _saveDraft.AutoEllipsis = true;
+ _saveDraft.UseVisualStyleBackColor = true;
_saveDraft.Click += SaveDraft_Click;
//
// _openDraft
//
- _openDraft.UseVisualStyleBackColor = true;
- _openDraft.Location = new System.Drawing.Point(84, 421);
+ _openDraft.Location = new System.Drawing.Point(84, 641);
_openDraft.Name = "_openDraft";
_openDraft.Size = new System.Drawing.Size(76, 25);
- _openDraft.TabIndex = 37;
+ _openDraft.TabIndex = 58;
_openDraft.Text = "Open draft";
+ _openDraft.AutoEllipsis = true;
+ _openDraft.UseVisualStyleBackColor = true;
_openDraft.Click += OpenDraft_Click;
//
// _blueprint
//
_blueprint.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _blueprint.UseVisualStyleBackColor = true;
- _blueprint.Location = new System.Drawing.Point(162, 421);
+ _blueprint.Location = new System.Drawing.Point(162, 641);
_blueprint.Name = "_blueprint";
_blueprint.Size = new System.Drawing.Size(82, 25);
- _blueprint.TabIndex = 38;
+ _blueprint.TabIndex = 59;
_blueprint.Text = "As blueprint";
+ _blueprint.AutoEllipsis = true;
+ _blueprint.UseVisualStyleBackColor = true;
_blueprint.Click += Blueprint_Click;
//
// _placedLabel
//
_placedLabel.AutoSize = true;
- _placedLabel.Location = new System.Drawing.Point(6, 454);
+ _placedLabel.Location = new System.Drawing.Point(6, 675);
_placedLabel.Name = "_placedLabel";
_placedLabel.Size = new System.Drawing.Size(60, 15);
- _placedLabel.TabIndex = 39;
+ _placedLabel.TabIndex = 60;
_placedLabel.Text = "Placed";
//
// _placed
@@ -537,56 +828,71 @@ private void InitializeComponent()
_placed.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
_placed.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
_placed.FormattingEnabled = true;
- _placed.Location = new System.Drawing.Point(60, 451);
+ _placed.Location = new System.Drawing.Point(60, 672);
_placed.Name = "_placed";
_placed.Size = new System.Drawing.Size(130, 23);
- _placed.TabIndex = 40;
+ _placed.TabIndex = 61;
//
// _edit
//
_edit.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right;
- _edit.UseVisualStyleBackColor = true;
- _edit.Location = new System.Drawing.Point(196, 450);
+ _edit.Location = new System.Drawing.Point(196, 671);
_edit.Name = "_edit";
_edit.Size = new System.Drawing.Size(48, 25);
- _edit.TabIndex = 41;
+ _edit.TabIndex = 62;
_edit.Text = "Edit";
+ _edit.AutoEllipsis = true;
+ _edit.UseVisualStyleBackColor = true;
_edit.Click += Edit_Click;
//
// _status
//
_status.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _status.Location = new System.Drawing.Point(6, 480);
+ _status.Location = new System.Drawing.Point(6, 701);
_status.Name = "_status";
_status.Size = new System.Drawing.Size(238, 32);
- _status.TabIndex = 42;
+ _status.TabIndex = 63;
//
// HousePanel
//
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ AutoScroll = true;
Controls.Add(houseBox);
Name = "HousePanel";
- Size = new System.Drawing.Size(250, 518);
+ Size = new System.Drawing.Size(250, 743);
houseBox.ResumeLayout(false);
houseBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)_storeys).EndInit();
- ((System.ComponentModel.ISupportInitialize)_baseZ).EndInit();
((System.ComponentModel.ISupportInitialize)_rooms).EndInit();
+ ((System.ComponentModel.ISupportInitialize)_baseZ).EndInit();
+ ((System.ComponentModel.ISupportInitialize)_windowSpacing).EndInit();
ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox houseBox;
+ private System.Windows.Forms.Label _themeLabel;
+ private System.Windows.Forms.ComboBox _theme;
+ private System.Windows.Forms.Button _saveTheme;
+ private System.Windows.Forms.Button _deleteTheme;
private System.Windows.Forms.ListBox _wingList;
private System.Windows.Forms.Label _wingHint;
private System.Windows.Forms.Label _storeysLabel;
private System.Windows.Forms.NumericUpDown _storeys;
+ private System.Windows.Forms.Label _roomsLabel;
+ private System.Windows.Forms.NumericUpDown _rooms;
private System.Windows.Forms.Button _removeWing;
+ private System.Windows.Forms.Label _layoutLabel;
+ private System.Windows.Forms.ComboBox _layout;
+ private System.Windows.Forms.CheckBox _roomsPerStorey;
private System.Windows.Forms.Label _roofLabel;
private System.Windows.Forms.ComboBox _roofShape;
private System.Windows.Forms.ComboBox _ridge;
+ private System.Windows.Forms.Label _gablesLabel;
+ private System.Windows.Forms.ComboBox _gables;
+ private System.Windows.Forms.ComboBox _gableFill;
private System.Windows.Forms.Label _materialsLabel;
private System.Windows.Forms.Label _storey1;
private System.Windows.Forms.Button _wall1;
@@ -602,11 +908,20 @@ private void InitializeComponent()
private System.Windows.Forms.Button _floor4;
private System.Windows.Forms.Label _roofStyleLabel;
private System.Windows.Forms.Button _roofStyle;
+ private System.Windows.Forms.Label _doorStyleLabel;
+ private System.Windows.Forms.Button _doorStyle;
+ private System.Windows.Forms.Label _stairStyleLabel;
+ private System.Windows.Forms.Button _stairStyle;
private System.Windows.Forms.CheckBox _foundation;
+ private System.Windows.Forms.Button _foundationStyle;
private System.Windows.Forms.Label _baseZLabel;
private System.Windows.Forms.NumericUpDown _baseZ;
- private System.Windows.Forms.Label _roomsLabel;
- private System.Windows.Forms.NumericUpDown _rooms;
+ private System.Windows.Forms.CheckBox _autoDoors;
+ private System.Windows.Forms.Label _frontDoorLabel;
+ private System.Windows.Forms.ComboBox _frontDoor;
+ private System.Windows.Forms.Label _windowsLabel;
+ private System.Windows.Forms.NumericUpDown _windowSpacing;
+ private System.Windows.Forms.Label _windowsHint;
private System.Windows.Forms.Label _showLabel;
private System.Windows.Forms.CheckBox _showWalls;
private System.Windows.Forms.CheckBox _showFloors;
@@ -622,5 +937,6 @@ private void InitializeComponent()
private System.Windows.Forms.ComboBox _placed;
private System.Windows.Forms.Button _edit;
private System.Windows.Forms.Label _status;
+ private System.Windows.Forms.ToolTip _toolTip;
}
}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
index 02b04cac..1ee571c7 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
@@ -10,6 +10,7 @@
***************************************************************************/
using System;
+using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
@@ -31,6 +32,7 @@ internal sealed partial class HousePanel : UserControl
private readonly Button[] _floorButtons;
private readonly Label[] _storeyLabels;
private readonly Font _boldFont;
+ private readonly TileBrowserThumbnails _thumbnails = new TileBrowserThumbnails();
private EditorSession _session;
private bool _updating;
@@ -41,7 +43,11 @@ public HousePanel()
_floorButtons = new[] { _floor1, _floor2, _floor3, _floor4 };
_storeyLabels = new[] { _storey1, _storey2, _storey3, _storey4 };
_boldFont = new Font(Font, FontStyle.Bold);
- Disposed += (_, _) => _boldFont.Dispose();
+ Disposed += (_, _) =>
+ {
+ _boldFont.Dispose();
+ _thumbnails.Dispose();
+ };
for (int k = 0; k < HouseDraft.MaxStoreys; ++k)
{
@@ -50,6 +56,9 @@ public HousePanel()
_floorButtons[k].Click += (_, _) => PickStyle?.Invoke(HousePartKind.Floor, storey);
}
+ _doorStyle.Click += (_, _) => PickStyle?.Invoke(HousePartKind.Door, 0);
+ _stairStyle.Click += (_, _) => PickStyle?.Invoke(HousePartKind.Stair, 0);
+ _foundationStyle.Click += (_, _) => PickStyle?.Invoke(HousePartKind.Wall, FoundationPick);
_roofStyle.Click += (_, _) =>
{
bool flat = _session != null && !_session.House.NoRoof && _session.House.Shape == RoofShape.Flat;
@@ -60,6 +69,19 @@ public HousePanel()
/// The storey a pick names when it is for the flat roof's floor style.
public const int FlatRoof = -1;
+ /// The storey a pick names when it is for the foundation's wall style.
+ public const int FoundationPick = -2;
+
+ private const string _customTheme = "(your own mix)";
+
+ /// Asks for the draft's styles to be saved as a theme, or for a theme of the user's to be deleted.
+ public event Action SaveTheme;
+
+ public event Action DeleteTheme;
+
+ /// Something to tell the user in the status bar.
+ public event Action Message;
+
/// Asks for a style to be picked on the House page for a storey's walls or floor, or for the roof.
public event Action PickStyle;
@@ -108,17 +130,37 @@ public void RefreshDraft()
_updating = true;
try
{
+ // Rows are changed in place: a list emptied and filled again on every step of a drag flickers.
_wingList.BeginUpdate();
- _wingList.Items.Clear();
+ while (_wingList.Items.Count > house.Wings.Count)
+ {
+ _wingList.Items.RemoveAt(_wingList.Items.Count - 1);
+ }
+
for (int i = 0; i < house.Wings.Count; ++i)
{
RoofWing wing = house.Wings[i];
string roof = wing.NoRoof ? "no roof" : wing.Shape.ToString().ToLowerInvariant();
- _wingList.Items.Add($"Wing {i + 1}: {wing.X1 - wing.X0 + 1} x {wing.Y1 - wing.Y0 + 1}, {wing.Storeys} storey{(wing.Storeys == 1 ? string.Empty : "s")}, {(wing.Rooms > 1 ? $"{wing.Rooms} rooms, " : string.Empty)}{roof}");
+ string divided = wing.Rooms > 1 ? $"{wing.Rooms} rooms{(wing.Layout == RoomLayout.Row ? string.Empty : " (" + wing.Layout.ToString().ToLowerInvariant() + ")")}, " : string.Empty;
+ string text = $"Wing {i + 1}: {wing.X1 - wing.X0 + 1} x {wing.Y1 - wing.Y0 + 1}, {wing.Storeys} storey{(wing.Storeys == 1 ? string.Empty : "s")}, {divided}{roof}";
+ if (i >= _wingList.Items.Count)
+ {
+ _wingList.Items.Add(text);
+ }
+ else if (!text.Equals(_wingList.Items[i]))
+ {
+ _wingList.Items[i] = text;
+ }
+ }
+
+ if (_wingList.SelectedIndex != house.SelectedIndex)
+ {
+ _wingList.SelectedIndex = house.SelectedIndex;
}
- _wingList.SelectedIndex = house.SelectedIndex;
_wingList.EndUpdate();
+ _gables.SelectedIndex = (int)house.Draft.Gables;
+ _gableFill.SelectedIndex = (int)house.Draft.GableFill;
_storeys.Value = Math.Clamp(house.Storeys, 1, HouseDraft.MaxStoreys);
// The drop-down lists the roof shapes in their order, then None.
@@ -134,8 +176,8 @@ public void RefreshDraft()
{
bool used = k < top || k < house.Storeys;
_storeyLabels[k].Visible = _wallButtons[k].Visible = _floorButtons[k].Visible = used;
- _wallButtons[k].Text = house.Draft.WallStyles[k]?.Name ?? "(walls)";
- _floorButtons[k].Text = house.Draft.FloorStyles[k]?.Name ?? "(floor)";
+ Show(_wallButtons[k], house.Draft.WallStyles[k], "(walls)", "South2");
+ Show(_floorButtons[k], house.Draft.FloorStyles[k], "(floor)", null);
// The storey the chosen floor means: where the other tools work.
bool current = k == active;
@@ -146,24 +188,44 @@ public void RefreshDraft()
// A flat roof is laid in a floor style of its own; the button picks that one then.
bool flat = !house.NoRoof && house.Shape == RoofShape.Flat;
- _roofStyle.Text = flat ? house.Draft.FlatRoofStyle?.Name ?? "(top floor's style)" : house.Draft.RoofStyle?.Name ?? "(roof)";
+ Show(_roofStyle, flat ? house.Draft.FlatRoofStyle : house.Draft.RoofStyle, flat ? "(top floor's style)" : "(roof)", null);
_foundation.Checked = house.Draft.Foundation;
- _rooms.Value = Math.Clamp(house.Rooms, 1, HouseDraft.MaxRooms);
+ Show(_doorStyle, house.Draft.DoorStyle, "(doors)", HouseDraft.DoorAlongX);
+ Show(_stairStyle, house.Draft.StairStyle, "(stairs)", null);
+ Show(_foundationStyle, house.Draft.FoundationStyle, "(light brick)", "South2");
+ _foundationStyle.Enabled = house.Draft.Foundation;
+ RefreshThemes(house);
+ // Rooms are those of the storey the chosen floor means.
+ int roomStorey = RoomStorey;
+ (int rooms, RoomLayout layout) = house.RoomsOn(roomStorey);
+ _rooms.Value = Math.Clamp(rooms, 1, HouseDraft.MaxRooms);
+ _layout.SelectedIndex = (int)layout;
+ _roomsPerStorey.Enabled = house.HasSelectedWing && roomStorey >= 1;
+ _roomsPerStorey.Checked = house.HasOwnRooms(roomStorey);
+ _roomsPerStorey.Text = roomStorey >= 1 ? $"Storey {roomStorey + 1} only" : "This storey";
+ _autoDoors.Checked = house.Draft.AutoDoors;
+ _frontDoor.SelectedIndex = (int)house.Draft.FrontDoor;
+ _windowSpacing.Value = Math.Clamp(house.Draft.WindowSpacing, 0, (int)_windowSpacing.Maximum);
_showWalls.Checked = house.ShowWalls;
_showFloors.Checked = house.ShowFloors;
_showRoof.Checked = house.ShowRoof;
_saveDraft.Enabled = _blueprint.Enabled = house.HasPending;
// The houses already placed in this design, which can be opened as drafts again.
- object chosen = _placed.SelectedItem;
- _placed.Items.Clear();
- foreach (System.Xml.Linq.XElement placed in _session.PlacedHouses)
+ List placedNow = _session.PlacedHouses.ToList();
+ if (!_placed.Items.Cast().Select(p => p.House).SequenceEqual(placedNow))
{
- _placed.Items.Add(new PlacedHouse(placed));
+ object chosen = _placed.SelectedItem;
+ _placed.Items.Clear();
+ foreach (System.Xml.Linq.XElement placed in placedNow)
+ {
+ _placed.Items.Add(new PlacedHouse(placed));
+ }
+
+ _placed.SelectedIndex = _placed.Items.Count == 0 ? -1
+ : Math.Max(0, _placed.Items.Cast().ToList().FindIndex(p => chosen is PlacedHouse c && c.House == p.House));
}
- _placed.SelectedIndex = _placed.Items.Count == 0 ? -1
- : Math.Max(0, _placed.Items.Cast().ToList().FindIndex(p => chosen is PlacedHouse c && c.House == p.House));
_placed.Enabled = _placed.Items.Count > 0;
_edit.Enabled = _placed.Items.Count > 0 && !house.HasPending;
_baseZ.Enabled = house.HasPending;
@@ -191,6 +253,119 @@ public void RefreshDraft()
}
}
+ /// Shows a style on its button: a piece of it, its name, and the whole name as the tip.
+ private void Show(Button button, HouseStyle style, string none, string iconSlot)
+ {
+ string text = style?.Name ?? none;
+ if (button.Text != text)
+ {
+ button.Text = text;
+ _toolTip.SetToolTip(button, style == null ? null : $"{style.Name} ({style.Group}). Click to pick another on the House page.");
+ }
+
+ ushort icon = style == null ? (ushort)0 : iconSlot != null && style.Get(iconSlot) is var piece and not 0 ? piece : style.IconId;
+ Image image = icon == 0 ? null : _thumbnails.Get(icon, 20);
+ if (!ReferenceEquals(button.Image, image))
+ {
+ button.Image = image;
+ button.ImageAlign = ContentAlignment.MiddleLeft;
+ button.TextImageRelation = TextImageRelation.ImageBeforeText;
+ }
+ }
+
+ private void Gables_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ Run(house => house.SetGables((RoofGables)Math.Max(0, _gables.SelectedIndex), (RoofGableFill)Math.Max(0, _gableFill.SelectedIndex)));
+ }
+
+ /// Lists the themes this client can build and marks the one the draft's styles are.
+ private void RefreshThemes(HouseTool house)
+ {
+ IReadOnlyList themes = house.Themes;
+ bool same = _theme.Items.Count == themes.Count + 1;
+ for (int i = 0; same && i < themes.Count; ++i)
+ {
+ same = ReferenceEquals(_theme.Items[i + 1], themes[i]);
+ }
+
+ if (!same)
+ {
+ _theme.BeginUpdate();
+ _theme.Items.Clear();
+ _theme.Items.Add(_customTheme);
+ foreach (HouseTheme theme in themes)
+ {
+ _theme.Items.Add(theme);
+ }
+
+ _theme.EndUpdate();
+ }
+
+ HouseTheme current = house.CurrentTheme();
+ _theme.SelectedIndex = current == null ? 0 : _theme.Items.IndexOf(current);
+ _theme.Enabled = themes.Count > 0;
+ _deleteTheme.Enabled = current is { IsUser: true };
+ }
+
+ private void Theme_SelectionChangeCommitted(object sender, EventArgs e)
+ {
+ if (_updating || _session == null || _theme.SelectedItem is not HouseTheme theme)
+ {
+ return;
+ }
+
+ List missing = _session.House.ApplyTheme(theme);
+ Message?.Invoke(missing.Count == 0
+ ? $"Theme \"{theme.Name}\" applied to the house."
+ : $"Theme \"{theme.Name}\" applied; this client has no {string.Join(", ", missing)} for it.");
+ Used?.Invoke();
+ }
+
+ private void SaveTheme_Click(object sender, EventArgs e)
+ {
+ SaveTheme?.Invoke();
+ Used?.Invoke();
+ }
+
+ private void DeleteTheme_Click(object sender, EventArgs e)
+ {
+ if (_theme.SelectedItem is HouseTheme { IsUser: true } theme)
+ {
+ DeleteTheme?.Invoke(theme);
+ Used?.Invoke();
+ }
+ }
+
+ /// Marks the button whose style is being picked on the House page; null clears the mark.
+ public void MarkPick(HousePartKind? kind, int storey)
+ {
+ Button picked = kind switch
+ {
+ null => null,
+ HousePartKind.Roof => _roofStyle,
+ HousePartKind.Door => _doorStyle,
+ HousePartKind.Stair => _stairStyle,
+ HousePartKind.Wall when storey == FoundationPick => _foundationStyle,
+ HousePartKind.Floor when storey == FlatRoof => _roofStyle,
+ HousePartKind.Wall => storey >= 0 && storey < _wallButtons.Length ? _wallButtons[storey] : null,
+ HousePartKind.Floor => storey >= 0 && storey < _floorButtons.Length ? _floorButtons[storey] : null,
+ _ => null
+ };
+ foreach (Button button in _wallButtons.Concat(_floorButtons).Concat(new[] { _roofStyle, _doorStyle, _stairStyle, _foundationStyle }))
+ {
+ if (button == picked)
+ {
+ button.BackColor = Color.FromArgb(255, 214, 64);
+ button.ForeColor = Color.Black;
+ }
+ else
+ {
+ button.ForeColor = ForeColor;
+ button.UseVisualStyleBackColor = true;
+ }
+ }
+ }
+
/// A placed house in the list, shown by its name and size.
private sealed class PlacedHouse
{
@@ -208,11 +383,42 @@ public override string ToString()
}
}
+ /// The storey the rooms shown are of: the one the chosen floor means, the ground floor with all floors shown.
+ private int RoomStorey => _session != null && _session.House.HasPending && _session.WorkZ != null ? _session.DraftStorey : 0;
+
private void Rooms_ValueChanged(object sender, EventArgs e)
{
if (!_updating && _session != null)
{
- _session.House.SetRooms((int)_rooms.Value);
+ _session.House.SetRooms((int)_rooms.Value, (RoomLayout)Math.Max(0, _layout.SelectedIndex), RoomStorey);
+ }
+ }
+
+ private void Layout_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ Run(house => house.SetRooms((int)_rooms.Value, (RoomLayout)Math.Max(0, _layout.SelectedIndex), RoomStorey));
+ }
+
+ private void RoomsPerStorey_CheckedChanged(object sender, EventArgs e)
+ {
+ Run(house => house.SetOwnRooms(RoomStorey, _roomsPerStorey.Checked));
+ }
+
+ private void AutoDoors_CheckedChanged(object sender, EventArgs e)
+ {
+ Run(house => house.SetAutoDoors(_autoDoors.Checked));
+ }
+
+ private void FrontDoor_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ Run(house => house.SetFrontDoor((FrontDoorSide)Math.Max(0, _frontDoor.SelectedIndex)));
+ }
+
+ private void WindowSpacing_ValueChanged(object sender, EventArgs e)
+ {
+ if (!_updating && _session != null)
+ {
+ _session.House.SetWindowSpacing((int)_windowSpacing.Value);
}
}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/HouseStyleEditorDialog.Designer.cs b/UoFiddler.Plugin.MultiEditor/UI/HouseStyleEditorDialog.Designer.cs
new file mode 100644
index 00000000..2eb5cce5
--- /dev/null
+++ b/UoFiddler.Plugin.MultiEditor/UI/HouseStyleEditorDialog.Designer.cs
@@ -0,0 +1,423 @@
+namespace UoFiddler.Plugin.MultiEditor.UI
+{
+ partial class HouseStyleEditorDialog
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ components = new System.ComponentModel.Container();
+ _kind = new System.Windows.Forms.ComboBox();
+ _styleList = new System.Windows.Forms.ListBox();
+ _up = new System.Windows.Forms.Button();
+ _down = new System.Windows.Forms.Button();
+ _reset = new System.Windows.Forms.Button();
+ _nameLabel = new System.Windows.Forms.Label();
+ _name = new System.Windows.Forms.TextBox();
+ _groupLabel = new System.Windows.Forms.Label();
+ _group = new System.Windows.Forms.TextBox();
+ _familyLabel = new System.Windows.Forms.Label();
+ _family = new System.Windows.Forms.TextBox();
+ _hidden = new System.Windows.Forms.CheckBox();
+ _layoutLabel = new System.Windows.Forms.Label();
+ _layout = new System.Windows.Forms.ComboBox();
+ _pieces = new System.Windows.Forms.ListView();
+ _role = new System.Windows.Forms.ComboBox();
+ _pieceId = new System.Windows.Forms.TextBox();
+ _fromBrowser = new System.Windows.Forms.Button();
+ _setPiece = new System.Windows.Forms.Button();
+ _removePiece = new System.Windows.Forms.Button();
+ _preview = new System.Windows.Forms.PictureBox();
+ _status = new System.Windows.Forms.Label();
+ _save = new System.Windows.Forms.Button();
+ _close = new System.Windows.Forms.Button();
+ _fileHint = new System.Windows.Forms.Label();
+ _roleColumn = new System.Windows.Forms.ColumnHeader();
+ _tileColumn = new System.Windows.Forms.ColumnHeader();
+ _tileNameColumn = new System.Windows.Forms.ColumnHeader();
+ _pieceImages = new System.Windows.Forms.ImageList(components);
+ _toolTip = new System.Windows.Forms.ToolTip(components);
+ ((System.ComponentModel.ISupportInitialize)_preview).BeginInit();
+ SuspendLayout();
+ //
+ // _kind
+ //
+ _kind.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ _kind.FormattingEnabled = true;
+ _kind.Location = new System.Drawing.Point(8, 8);
+ _kind.Name = "_kind";
+ _kind.Size = new System.Drawing.Size(260, 23);
+ _kind.TabIndex = 0;
+ _kind.SelectedIndexChanged += Kind_SelectedIndexChanged;
+ //
+ // _styleList
+ //
+ _styleList.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
+ _styleList.IntegralHeight = false;
+ _styleList.ItemHeight = 15;
+ _styleList.FormattingEnabled = true;
+ _styleList.Location = new System.Drawing.Point(8, 37);
+ _styleList.Name = "_styleList";
+ _styleList.Size = new System.Drawing.Size(260, 436);
+ _styleList.TabIndex = 1;
+ _styleList.SelectedIndexChanged += StyleList_SelectedIndexChanged;
+ //
+ // _up
+ //
+ _up.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
+ _up.Location = new System.Drawing.Point(8, 480);
+ _up.Name = "_up";
+ _up.Size = new System.Drawing.Size(60, 25);
+ _up.TabIndex = 2;
+ _up.Text = "Up";
+ _up.UseVisualStyleBackColor = true;
+ _toolTip.SetToolTip(_up, "Moves the style up in the lists.");
+ _up.Click += Up_Click;
+ //
+ // _down
+ //
+ _down.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
+ _down.Location = new System.Drawing.Point(72, 480);
+ _down.Name = "_down";
+ _down.Size = new System.Drawing.Size(60, 25);
+ _down.TabIndex = 3;
+ _down.Text = "Down";
+ _down.UseVisualStyleBackColor = true;
+ _toolTip.SetToolTip(_down, "Moves the style down in the lists.");
+ _down.Click += Down_Click;
+ //
+ // _reset
+ //
+ _reset.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
+ _reset.Location = new System.Drawing.Point(136, 480);
+ _reset.Name = "_reset";
+ _reset.Size = new System.Drawing.Size(132, 25);
+ _reset.TabIndex = 4;
+ _reset.Text = "Back to shipped";
+ _reset.UseVisualStyleBackColor = true;
+ _toolTip.SetToolTip(_reset, "Drops your changes to this style: it is again as the shipped style file has it.");
+ _reset.Click += Reset_Click;
+ //
+ // _nameLabel
+ //
+ _nameLabel.AutoSize = true;
+ _nameLabel.Location = new System.Drawing.Point(280, 11);
+ _nameLabel.Name = "_nameLabel";
+ _nameLabel.Size = new System.Drawing.Size(50, 15);
+ _nameLabel.TabIndex = 5;
+ _nameLabel.Text = "Name";
+ //
+ // _name
+ //
+ _name.Location = new System.Drawing.Point(336, 8);
+ _name.Name = "_name";
+ _name.Size = new System.Drawing.Size(224, 23);
+ _name.TabIndex = 6;
+ _name.TextChanged += Meta_Changed;
+ //
+ // _groupLabel
+ //
+ _groupLabel.AutoSize = true;
+ _groupLabel.Location = new System.Drawing.Point(280, 40);
+ _groupLabel.Name = "_groupLabel";
+ _groupLabel.Size = new System.Drawing.Size(50, 15);
+ _groupLabel.TabIndex = 7;
+ _groupLabel.Text = "Group";
+ //
+ // _group
+ //
+ _group.Location = new System.Drawing.Point(336, 37);
+ _group.Name = "_group";
+ _group.Size = new System.Drawing.Size(224, 23);
+ _group.TabIndex = 8;
+ _toolTip.SetToolTip(_group, "The heading the style is listed under.");
+ _group.TextChanged += Meta_Changed;
+ //
+ // _familyLabel
+ //
+ _familyLabel.AutoSize = true;
+ _familyLabel.Location = new System.Drawing.Point(280, 69);
+ _familyLabel.Name = "_familyLabel";
+ _familyLabel.Size = new System.Drawing.Size(50, 15);
+ _familyLabel.TabIndex = 9;
+ _familyLabel.Text = "Family";
+ //
+ // _family
+ //
+ _family.Location = new System.Drawing.Point(336, 66);
+ _family.Name = "_family";
+ _family.Size = new System.Drawing.Size(224, 23);
+ _family.TabIndex = 10;
+ _toolTip.SetToolTip(_family, "The material, shared by styles of every kind. The House page finds styles by it.");
+ _family.TextChanged += Meta_Changed;
+ //
+ // _hidden
+ //
+ _hidden.AutoSize = true;
+ _hidden.Location = new System.Drawing.Point(336, 95);
+ _hidden.Name = "_hidden";
+ _hidden.Size = new System.Drawing.Size(120, 19);
+ _hidden.TabIndex = 11;
+ _hidden.Text = "Hidden";
+ _hidden.UseVisualStyleBackColor = true;
+ _toolTip.SetToolTip(_hidden, "Keeps the style out of the lists. Its pieces stay in the tile browser.");
+ _hidden.CheckedChanged += Meta_Changed;
+ //
+ // _layoutLabel
+ //
+ _layoutLabel.AutoSize = true;
+ _layoutLabel.Location = new System.Drawing.Point(280, 122);
+ _layoutLabel.Name = "_layoutLabel";
+ _layoutLabel.Size = new System.Drawing.Size(50, 15);
+ _layoutLabel.TabIndex = 12;
+ _layoutLabel.Text = "Layout";
+ //
+ // _layout
+ //
+ _layout.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ _layout.FormattingEnabled = true;
+ _layout.Items.AddRange(new object[] { "Run", "Paired", "Cycle" });
+ _layout.Location = new System.Drawing.Point(336, 119);
+ _layout.Name = "_layout";
+ _layout.Size = new System.Drawing.Size(120, 23);
+ _layout.TabIndex = 13;
+ _toolTip.SetToolTip(_layout, "Walls only. Run: start, middle, end. Paired: South1+South3 and East3+East1 are two halves laid pair after pair. Cycle: CycleSouth1.. and CycleEast1.. laid one after another.");
+ _layout.SelectedIndexChanged += Meta_Changed;
+ //
+ // _pieces
+ //
+ _pieces.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
+ _pieces.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { _roleColumn, _tileColumn, _tileNameColumn });
+ _pieces.SmallImageList = _pieceImages;
+ _pieces.FullRowSelect = true;
+ _pieces.HideSelection = false;
+ _pieces.MultiSelect = false;
+ _pieces.View = System.Windows.Forms.View.Details;
+ _pieces.Location = new System.Drawing.Point(280, 150);
+ _pieces.Name = "_pieces";
+ _pieces.Size = new System.Drawing.Size(280, 293);
+ _pieces.TabIndex = 14;
+ _pieces.SelectedIndexChanged += Pieces_SelectedIndexChanged;
+ //
+ // _role
+ //
+ _role.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
+ _role.FormattingEnabled = true;
+ _role.Location = new System.Drawing.Point(280, 450);
+ _role.Name = "_role";
+ _role.Size = new System.Drawing.Size(118, 23);
+ _role.TabIndex = 15;
+ _toolTip.SetToolTip(_role, "The column of the piece: South1-3, East1-3, Corner, Post, WindowS, WindowE ...");
+ //
+ // _pieceId
+ //
+ _pieceId.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
+ _pieceId.Location = new System.Drawing.Point(402, 450);
+ _pieceId.Name = "_pieceId";
+ _pieceId.Size = new System.Drawing.Size(62, 23);
+ _pieceId.TabIndex = 16;
+ _toolTip.SetToolTip(_pieceId, "Tile id of the piece, as 0x1234.");
+ //
+ // _fromBrowser
+ //
+ _fromBrowser.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
+ _fromBrowser.Location = new System.Drawing.Point(466, 449);
+ _fromBrowser.Name = "_fromBrowser";
+ _fromBrowser.Size = new System.Drawing.Size(94, 25);
+ _fromBrowser.TabIndex = 17;
+ _fromBrowser.Text = "Drawn tile";
+ _fromBrowser.UseVisualStyleBackColor = true;
+ _toolTip.SetToolTip(_fromBrowser, "Takes the tile chosen in the tile browser.");
+ _fromBrowser.Click += FromBrowser_Click;
+ //
+ // _setPiece
+ //
+ _setPiece.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
+ _setPiece.Location = new System.Drawing.Point(280, 480);
+ _setPiece.Name = "_setPiece";
+ _setPiece.Size = new System.Drawing.Size(118, 25);
+ _setPiece.TabIndex = 18;
+ _setPiece.Text = "Set piece";
+ _setPiece.UseVisualStyleBackColor = true;
+ _toolTip.SetToolTip(_setPiece, "Gives the role this tile: a new piece, or another tile for one the style has.");
+ _setPiece.Click += SetPiece_Click;
+ //
+ // _removePiece
+ //
+ _removePiece.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
+ _removePiece.Location = new System.Drawing.Point(402, 480);
+ _removePiece.Name = "_removePiece";
+ _removePiece.Size = new System.Drawing.Size(158, 25);
+ _removePiece.TabIndex = 19;
+ _removePiece.Text = "Remove piece";
+ _removePiece.UseVisualStyleBackColor = true;
+ _removePiece.Click += RemovePiece_Click;
+ //
+ // _preview
+ //
+ _preview.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _preview.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ _preview.Location = new System.Drawing.Point(572, 8);
+ _preview.Name = "_preview";
+ _preview.Size = new System.Drawing.Size(320, 465);
+ _preview.TabIndex = 20;
+ _preview.TabStop = false;
+ //
+ // _status
+ //
+ _status.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _status.Location = new System.Drawing.Point(572, 480);
+ _status.Name = "_status";
+ _status.Size = new System.Drawing.Size(320, 30);
+ _status.TabIndex = 21;
+ //
+ // _save
+ //
+ _save.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
+ _save.Location = new System.Drawing.Point(734, 516);
+ _save.Name = "_save";
+ _save.Size = new System.Drawing.Size(76, 27);
+ _save.TabIndex = 22;
+ _save.Text = "Save";
+ _save.UseVisualStyleBackColor = true;
+ _toolTip.SetToolTip(_save, "Writes your changes to your copy of the style file and reads the styles again.");
+ _save.Click += Save_Click;
+ //
+ // _close
+ //
+ _close.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
+ _close.Location = new System.Drawing.Point(816, 516);
+ _close.Name = "_close";
+ _close.Size = new System.Drawing.Size(76, 27);
+ _close.TabIndex = 23;
+ _close.Text = "Close";
+ _close.UseVisualStyleBackColor = true;
+ _close.Click += Close_Click;
+ //
+ // _fileHint
+ //
+ _fileHint.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _fileHint.Location = new System.Drawing.Point(8, 520);
+ _fileHint.Name = "_fileHint";
+ _fileHint.Size = new System.Drawing.Size(700, 15);
+ _fileHint.TabIndex = 24;
+ //
+ // _roleColumn
+ //
+ _roleColumn.Text = "Role";
+ _roleColumn.Width = 104;
+ //
+ // _tileColumn
+ //
+ _tileColumn.Text = "Tile";
+ _tileColumn.Width = 60;
+ //
+ // _tileNameColumn
+ //
+ _tileNameColumn.Text = "Name";
+ _tileNameColumn.Width = 92;
+ //
+ // _pieceImages
+ //
+ _pieceImages.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
+ _pieceImages.ImageSize = new System.Drawing.Size(32, 32);
+ _pieceImages.TransparentColor = System.Drawing.Color.Transparent;
+ //
+ // HouseStyleEditorDialog
+ //
+ AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ ClientSize = new System.Drawing.Size(900, 551);
+ Controls.Add(_kind);
+ Controls.Add(_styleList);
+ Controls.Add(_up);
+ Controls.Add(_down);
+ Controls.Add(_reset);
+ Controls.Add(_nameLabel);
+ Controls.Add(_name);
+ Controls.Add(_groupLabel);
+ Controls.Add(_group);
+ Controls.Add(_familyLabel);
+ Controls.Add(_family);
+ Controls.Add(_hidden);
+ Controls.Add(_layoutLabel);
+ Controls.Add(_layout);
+ Controls.Add(_pieces);
+ Controls.Add(_role);
+ Controls.Add(_pieceId);
+ Controls.Add(_fromBrowser);
+ Controls.Add(_setPiece);
+ Controls.Add(_removePiece);
+ Controls.Add(_preview);
+ Controls.Add(_status);
+ Controls.Add(_save);
+ Controls.Add(_close);
+ Controls.Add(_fileHint);
+ MinimizeBox = false;
+ MinimumSize = new System.Drawing.Size(916, 500);
+ Name = "HouseStyleEditorDialog";
+ ShowInTaskbar = false;
+ StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
+ Text = "House styles";
+ FormClosing += Dialog_FormClosing;
+ ((System.ComponentModel.ISupportInitialize)_preview).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private System.Windows.Forms.ComboBox _kind;
+ private System.Windows.Forms.ListBox _styleList;
+ private System.Windows.Forms.Button _up;
+ private System.Windows.Forms.Button _down;
+ private System.Windows.Forms.Button _reset;
+ private System.Windows.Forms.Label _nameLabel;
+ private System.Windows.Forms.TextBox _name;
+ private System.Windows.Forms.Label _groupLabel;
+ private System.Windows.Forms.TextBox _group;
+ private System.Windows.Forms.Label _familyLabel;
+ private System.Windows.Forms.TextBox _family;
+ private System.Windows.Forms.CheckBox _hidden;
+ private System.Windows.Forms.Label _layoutLabel;
+ private System.Windows.Forms.ComboBox _layout;
+ private System.Windows.Forms.ListView _pieces;
+ private System.Windows.Forms.ComboBox _role;
+ private System.Windows.Forms.TextBox _pieceId;
+ private System.Windows.Forms.Button _fromBrowser;
+ private System.Windows.Forms.Button _setPiece;
+ private System.Windows.Forms.Button _removePiece;
+ private System.Windows.Forms.PictureBox _preview;
+ private System.Windows.Forms.Label _status;
+ private System.Windows.Forms.Button _save;
+ private System.Windows.Forms.Button _close;
+ private System.Windows.Forms.Label _fileHint;
+ private System.Windows.Forms.ColumnHeader _roleColumn;
+ private System.Windows.Forms.ColumnHeader _tileColumn;
+ private System.Windows.Forms.ColumnHeader _tileNameColumn;
+ private System.Windows.Forms.ImageList _pieceImages;
+ private System.Windows.Forms.ToolTip _toolTip;
+ }
+}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/HouseStyleEditorDialog.cs b/UoFiddler.Plugin.MultiEditor/UI/HouseStyleEditorDialog.cs
new file mode 100644
index 00000000..4fad130d
--- /dev/null
+++ b/UoFiddler.Plugin.MultiEditor/UI/HouseStyleEditorDialog.cs
@@ -0,0 +1,612 @@
+/***************************************************************************
+ *
+ * $Author: Turley
+ *
+ * "THE BEER-WARE LICENSE"
+ * As long as you retain this notice you can do whatever you want with
+ * this stuff. If we meet some day, and you think this stuff is worth it,
+ * you can buy me a beer in return.
+ *
+ ***************************************************************************/
+
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Windows.Forms;
+using UoFiddler.Plugin.MultiEditor.Classes;
+
+namespace UoFiddler.Plugin.MultiEditor.UI
+{
+ ///
+ /// Edits the house styles: their names, groups, families, order and pieces. Changes go to the
+ /// user's copy of the style file (), which is laid over
+ /// the shipped one, and the styles are read again. Only what was changed is written.
+ ///
+ internal sealed partial class HouseStyleEditorDialog : Form
+ {
+ /// A style as the dialog shows and changes it.
+ private sealed class Row
+ {
+ public HouseStyle Style;
+ public string Name;
+ public string Group;
+ public string Family;
+ public bool Hidden;
+ public string Layout;
+ public List<(string Role, ushort Id)> Pieces;
+ public bool MetaChanged;
+ public bool PiecesChanged;
+
+ public override string ToString() => (Hidden ? "(hidden) " : string.Empty) + Name + (MetaChanged || PiecesChanged ? " *" : string.Empty);
+ }
+
+ private static readonly HousePartKind[] _kinds =
+ {
+ HousePartKind.Wall, HousePartKind.Floor, HousePartKind.Roof, HousePartKind.Door, HousePartKind.Stair, HousePartKind.Misc
+ };
+
+ private readonly HouseStyles _styles;
+ private readonly Func _currentTile;
+ private readonly TileBrowserThumbnails _thumbnails = new TileBrowserThumbnails();
+ private readonly Dictionary> _rows = new Dictionary>();
+ private readonly HashSet _reordered = new HashSet();
+ private bool _updating;
+
+ public HouseStyleEditorDialog()
+ {
+ InitializeComponent();
+ }
+
+ public HouseStyleEditorDialog(HouseStyles styles, HouseStyle start, Func currentTile) : this()
+ {
+ _styles = styles;
+ _currentTile = currentTile;
+ _fileHint.Text = "Your changes are kept in " + (HouseStyleConfig.UserPath ?? "(no profile folder)");
+ foreach (HousePartKind kind in _kinds)
+ {
+ _kind.Items.Add(kind);
+ }
+
+ LoadRows();
+ Choose(start?.Kind ?? HousePartKind.Wall, start?.Anchor ?? 0);
+ Disposed += (_, _) =>
+ {
+ _thumbnails.Dispose();
+ _preview.Image?.Dispose();
+ };
+ }
+
+ /// True when the styles were saved and read again while the dialog was open.
+ public bool Saved { get; private set; }
+
+ private HousePartKind Kind => _kind.SelectedItem is HousePartKind kind ? kind : HousePartKind.Wall;
+
+ private Row Current => _styleList.SelectedItem as Row;
+
+ private bool HasChanges => _reordered.Count > 0 || _rows.Values.Any(rows => rows.Any(row => row.MetaChanged || row.PiecesChanged));
+
+ private void LoadRows()
+ {
+ _rows.Clear();
+ _reordered.Clear();
+ foreach (HousePartKind kind in _kinds)
+ {
+ _rows[kind] = new List();
+ }
+
+ foreach (HouseStyle style in _styles.Styles)
+ {
+ if (!_rows.TryGetValue(style.Kind, out List rows))
+ {
+ continue;
+ }
+
+ rows.Add(new Row
+ {
+ Style = style, Name = style.Name, Group = style.Group, Family = style.Family, Hidden = style.Hidden,
+ Layout = style.Paired ? HouseStyleEntry.LayoutPaired : style.CycleSouth > 0 ? HouseStyleEntry.LayoutCycle : HouseStyleEntry.LayoutRun,
+ Pieces = style.Slots.Select(piece => (piece.Key, piece.Value)).ToList()
+ });
+ }
+ }
+
+ private void Choose(HousePartKind kind, ushort anchor)
+ {
+ _kind.SelectedItem = kind;
+ ShowKind();
+ int index = _rows[Kind].FindIndex(row => anchor != 0 && row.Style.Anchor == anchor);
+ if (_styleList.Items.Count > 0)
+ {
+ _styleList.SelectedIndex = Math.Max(0, index);
+ }
+ }
+
+ private void ShowKind()
+ {
+ _updating = true;
+ try
+ {
+ _styleList.BeginUpdate();
+ _styleList.Items.Clear();
+ foreach (Row row in _rows[Kind])
+ {
+ _styleList.Items.Add(row);
+ }
+
+ _styleList.EndUpdate();
+
+ // The roles the styles of this kind use, to choose from.
+ _role.Items.Clear();
+ foreach (string role in _rows[Kind].SelectMany(row => row.Pieces.Select(piece => piece.Role)).Distinct().Take(80))
+ {
+ _role.Items.Add(role);
+ }
+
+ _layout.Enabled = _layoutLabel.Enabled = Kind == HousePartKind.Wall;
+ }
+ finally
+ {
+ _updating = false;
+ }
+
+ ShowRow();
+ }
+
+ private void ShowRow()
+ {
+ Row row = Current;
+ _updating = true;
+ try
+ {
+ _name.Enabled = _group.Enabled = _family.Enabled = _hidden.Enabled = _pieces.Enabled = _reset.Enabled = row != null;
+ _setPiece.Enabled = _removePiece.Enabled = _role.Enabled = _pieceId.Enabled = _fromBrowser.Enabled = row != null;
+ _name.Text = row?.Name ?? string.Empty;
+ _group.Text = row?.Group ?? string.Empty;
+ _family.Text = row?.Family ?? string.Empty;
+ _hidden.Checked = row?.Hidden ?? false;
+ _layout.SelectedItem = row?.Layout ?? HouseStyleEntry.LayoutRun;
+ _up.Enabled = row != null && _styleList.SelectedIndex > 0;
+ _down.Enabled = row != null && _styleList.SelectedIndex < _styleList.Items.Count - 1;
+ ShowPieces(row, null);
+ }
+ finally
+ {
+ _updating = false;
+ }
+
+ DrawPreview();
+ }
+
+ private void ShowPieces(Row row, string selectRole)
+ {
+ _pieces.BeginUpdate();
+ _pieces.Items.Clear();
+ _pieceImages.Images.Clear();
+ if (row != null)
+ {
+ foreach ((string role, ushort id) in row.Pieces)
+ {
+ string key = id.ToString("X4", CultureInfo.InvariantCulture);
+ if (!_pieceImages.Images.ContainsKey(key) && _thumbnails.Get(id, 32) is { } thumb)
+ {
+ _pieceImages.Images.Add(key, thumb);
+ }
+
+ var item = new ListViewItem(new[] { role, "0x" + key, TileBrowserThumbnails.NameOf(id) }) { ImageKey = key, Tag = role };
+ _pieces.Items.Add(item);
+ item.Selected = role == selectRole;
+ }
+ }
+
+ _pieces.EndUpdate();
+ }
+
+ private void DrawPreview()
+ {
+ Row row = Current;
+ int width = Math.Max(120, _preview.ClientSize.Width), height = Math.Max(120, _preview.ClientSize.Height);
+ var image = new Bitmap(width, height);
+ using (Graphics g = Graphics.FromImage(image))
+ {
+ g.Clear(Color.FromArgb(40, 44, 52));
+ if (row != null && row.Pieces.Count > 0)
+ {
+ HouseStyle style = HouseStyles.Compose(Kind, row.Group, row.Name, row.Pieces, row.Layout);
+ if (Kind == HousePartKind.Wall)
+ {
+ DrawRoom(g, style, width);
+ }
+
+ DrawPieces(g, row, Kind == HousePartKind.Wall ? 300 : 8, width, height);
+ }
+ }
+
+ Image old = _preview.Image;
+ _preview.Image = image;
+ old?.Dispose();
+ }
+
+ /// A small room in the style, with a window in each wall where the style has one.
+ private static void DrawRoom(Graphics g, HouseStyle style, int width)
+ {
+ var region = new HashSet<(int X, int Y)>();
+ for (int x = 1; x <= 5; ++x)
+ {
+ for (int y = 1; y <= 4; ++y)
+ {
+ region.Add((x, y));
+ }
+ }
+
+ var south = new HashSet<(int X, int Y)>();
+ var east = new HashSet<(int X, int Y)>();
+ HouseDraft.Outline(region, south, east);
+ var windows = new HashSet<(int X, int Y)> { (3, 4), (5, 2), (3, 0), (0, 2) };
+ var tiles = new List<(ushort Id, int X, int Y)>();
+ for (int x = 0; x <= 5; ++x)
+ {
+ for (int y = 0; y <= 4; ++y)
+ {
+ string column = WallPlanner.PieceFor(style, south, east, x, y);
+ if (column == null)
+ {
+ continue;
+ }
+
+ ushort id = style.Get(column);
+ if (windows.Contains((x, y)) && column != "Corner" && column != "Post")
+ {
+ ushort window = style.Get(south.Contains((x, y)) ? "WindowS" : "WindowE");
+ id = window != 0 ? window : id;
+ }
+
+ if (id != 0)
+ {
+ tiles.Add((id, x, y));
+ }
+ }
+ }
+
+ int cx = (width / 2) - 10, cy = 70;
+ foreach ((ushort id, int x, int y) in tiles.OrderBy(t => t.X + t.Y).ThenBy(t => t.X))
+ {
+ Bitmap art = Ultima.Art.GetStatic(id);
+ if (art != null)
+ {
+ g.DrawImage(art, cx + ((x - y) * 22) - (art.Width / 2), cy + ((x + y) * 22) + 44 - art.Height);
+ }
+ }
+ }
+
+ /// The style's pieces in rows, each with its role under it.
+ private void DrawPieces(Graphics g, Row row, int top, int width, int height)
+ {
+ const int cell = 62;
+ int x = 6, y = top;
+ foreach (IGrouping piece in row.Pieces.GroupBy(p => p.Id))
+ {
+ if (y + cell > height)
+ {
+ break;
+ }
+
+ if (_thumbnails.Get(piece.Key, 44) is { } thumb)
+ {
+ g.DrawImage(thumb, x + ((cell - 8 - thumb.Width) / 2), y + (44 - thumb.Height));
+ }
+
+ string label = piece.First().Role + (piece.Count() > 1 ? " +" + (piece.Count() - 1).ToString(CultureInfo.InvariantCulture) : string.Empty);
+ TextRenderer.DrawText(g, label, Font, new Rectangle(x - 2, y + 45, cell, 15), Color.Gainsboro, TextFormatFlags.EndEllipsis | TextFormatFlags.NoPadding);
+ x += cell;
+ if (x + cell > width)
+ {
+ x = 6;
+ y += cell + 4;
+ }
+ }
+ }
+
+ private void Kind_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ if (!_updating)
+ {
+ ShowKind();
+ if (_styleList.Items.Count > 0)
+ {
+ _styleList.SelectedIndex = 0;
+ }
+ }
+ }
+
+ private void StyleList_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ if (!_updating)
+ {
+ ShowRow();
+ }
+ }
+
+ /// Shows a row's line in the list again after it changed.
+ private void RefreshLine()
+ {
+ int index = _styleList.SelectedIndex;
+ if (index < 0)
+ {
+ return;
+ }
+
+ _updating = true;
+ try
+ {
+ _styleList.Items[index] = _styleList.Items[index];
+ }
+ finally
+ {
+ _updating = false;
+ }
+ }
+
+ private void Meta_Changed(object sender, EventArgs e)
+ {
+ Row row = Current;
+ if (_updating || row == null)
+ {
+ return;
+ }
+
+ string layout = _layout.SelectedItem as string ?? HouseStyleEntry.LayoutRun;
+ bool redraw = layout != row.Layout;
+ (row.Name, row.Group, row.Family, row.Hidden, row.Layout) = (_name.Text.Trim(), _group.Text.Trim(), _family.Text.Trim(), _hidden.Checked, layout);
+ row.MetaChanged = true;
+ RefreshLine();
+ if (redraw)
+ {
+ DrawPreview();
+ }
+ }
+
+ private void Pieces_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ if (_pieces.SelectedItems.Count == 1)
+ {
+ _role.Text = _pieces.SelectedItems[0].SubItems[0].Text;
+ _pieceId.Text = _pieces.SelectedItems[0].SubItems[1].Text;
+ }
+ }
+
+ private void FromBrowser_Click(object sender, EventArgs e)
+ {
+ int tile = _currentTile?.Invoke() ?? -1;
+ if (tile >= 0)
+ {
+ _pieceId.Text = "0x" + tile.ToString("X4", CultureInfo.InvariantCulture);
+ }
+ else
+ {
+ _status.Text = "No tile is chosen in the tile browser.";
+ }
+ }
+
+ private void SetPiece_Click(object sender, EventArgs e)
+ {
+ Row row = Current;
+ string role = _role.Text.Trim();
+ if (row == null)
+ {
+ return;
+ }
+
+ if (role.Length == 0 || role.Any(char.IsWhiteSpace))
+ {
+ _status.Text = "Give the piece a role: South1, Corner, WindowS ...";
+ return;
+ }
+
+ if (!HouseStyleConfig.TryParseId(_pieceId.Text, out ushort id) || id == 0 || id >= Ultima.TileData.ItemTable.Length || !Ultima.Art.IsValidStatic(id))
+ {
+ _status.Text = "That is not a tile this client has art for. Ids are written as 0x1234.";
+ return;
+ }
+
+ int index = row.Pieces.FindIndex(piece => piece.Role == role);
+ if (index >= 0)
+ {
+ row.Pieces[index] = (role, id);
+ }
+ else
+ {
+ row.Pieces.Add((role, id));
+ }
+
+ row.PiecesChanged = true;
+ _status.Text = string.Empty;
+ RefreshLine();
+ ShowPieces(row, role);
+ DrawPreview();
+ }
+
+ private void RemovePiece_Click(object sender, EventArgs e)
+ {
+ Row row = Current;
+ if (row == null || _pieces.SelectedItems.Count != 1)
+ {
+ return;
+ }
+
+ string role = (string)_pieces.SelectedItems[0].Tag;
+ if (row.Pieces.Count <= 1)
+ {
+ _status.Text = "A style needs a piece. Hide the style to take it out of the lists.";
+ return;
+ }
+
+ row.Pieces.RemoveAll(piece => piece.Role == role);
+ row.PiecesChanged = true;
+ RefreshLine();
+ ShowPieces(row, null);
+ DrawPreview();
+ }
+
+ private void Up_Click(object sender, EventArgs e) => MoveRow(-1);
+
+ private void Down_Click(object sender, EventArgs e) => MoveRow(1);
+
+ private void MoveRow(int by)
+ {
+ List rows = _rows[Kind];
+ int index = _styleList.SelectedIndex, to = index + by;
+ if (index < 0 || to < 0 || to >= rows.Count)
+ {
+ return;
+ }
+
+ (rows[index], rows[to]) = (rows[to], rows[index]);
+ _reordered.Add(Kind);
+ _updating = true;
+ try
+ {
+ (_styleList.Items[index], _styleList.Items[to]) = (_styleList.Items[to], _styleList.Items[index]);
+ _styleList.SelectedIndex = to;
+ }
+ finally
+ {
+ _updating = false;
+ }
+
+ _up.Enabled = to > 0;
+ _down.Enabled = to < rows.Count - 1;
+ }
+
+ private void Reset_Click(object sender, EventArgs e)
+ {
+ Row row = Current;
+ if (row == null || row.Style.Anchor == 0 ||
+ MessageBox.Show(this, $"Drop your changes to \"{row.Style.Name}\"?" + (HasChanges ? "\r\nChanges not saved yet are lost too." : string.Empty),
+ Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
+ {
+ return;
+ }
+
+ try
+ {
+ HouseStyleConfig user = HouseStyleConfig.LoadFile(HouseStyleConfig.UserPath);
+ user.Styles.RemoveAll(entry => entry.Kind == row.Style.Kind && entry.Anchor == row.Style.Anchor);
+ user.Save(HouseStyleConfig.UserPath);
+ Reload(row.Style.Kind, row.Style.Anchor);
+ _status.Text = "The style is as shipped again.";
+ }
+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException)
+ {
+ MessageBox.Show(this, "The style file could not be written: " + ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ }
+ }
+
+ private void Save_Click(object sender, EventArgs e)
+ {
+ if (!HasChanges)
+ {
+ _status.Text = "Nothing was changed.";
+ return;
+ }
+
+ if (HouseStyleConfig.UserPath == null)
+ {
+ MessageBox.Show(this, "There is no profile folder to keep the changes in.", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return;
+ }
+
+ Row current = Current;
+ int skipped = 0;
+ try
+ {
+ HouseStyleConfig user = HouseStyleConfig.LoadFile(HouseStyleConfig.UserPath);
+ foreach (Row row in _rows.Values.SelectMany(rows => rows).Where(row => row.MetaChanged || row.PiecesChanged))
+ {
+ // A style is known by its anchor piece; one without (every piece listed by an earlier style) cannot be named.
+ if (row.Style.Anchor == 0)
+ {
+ ++skipped;
+ continue;
+ }
+
+ HouseStyleEntry entry = user.Styles.FirstOrDefault(other => other.Kind == row.Style.Kind && other.Anchor == row.Style.Anchor && !other.IsNew);
+ if (entry == null)
+ {
+ entry = new HouseStyleEntry { Kind = row.Style.Kind, Anchor = row.Style.Anchor };
+ user.Styles.Add(entry);
+ }
+
+ if (row.MetaChanged)
+ {
+ (entry.Name, entry.Group, entry.Family, entry.Hidden) = (row.Name, row.Group, row.Family, row.Hidden);
+ if (row.Style.Kind == HousePartKind.Wall)
+ {
+ entry.Layout = row.Layout;
+ }
+ }
+
+ if (row.PiecesChanged)
+ {
+ entry.Pieces = new List<(string Role, ushort Id)>(row.Pieces);
+ }
+ }
+
+ foreach (HousePartKind kind in _reordered)
+ {
+ user.Order[kind] = _rows[kind].Where(row => row.Style.Anchor != 0).Select(row => row.Style.Anchor).ToList();
+ }
+
+ user.Save(HouseStyleConfig.UserPath);
+ Reload(current?.Style.Kind ?? Kind, current?.Style.Anchor ?? 0);
+ _status.Text = skipped == 0 ? "Saved." : $"Saved. {skipped} style(s) share all their pieces with others and could not be changed.";
+ }
+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException)
+ {
+ MessageBox.Show(this, "The style file could not be written: " + ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ }
+ }
+
+ /// Reads the styles again and shows them, on the style that was shown.
+ private void Reload(HousePartKind kind, ushort anchor)
+ {
+ Cursor = Cursors.WaitCursor;
+ try
+ {
+ _styles.Reload();
+ Saved = true;
+ LoadRows();
+ Choose(kind, anchor);
+ }
+ finally
+ {
+ Cursor = Cursors.Default;
+ }
+ }
+
+ private void Close_Click(object sender, EventArgs e)
+ {
+ Close();
+ }
+
+ private void Dialog_FormClosing(object sender, FormClosingEventArgs e)
+ {
+ if (HasChanges && MessageBox.Show(this, "Close without saving your changes to the styles?", Text, MessageBoxButtons.OKCancel,
+ MessageBoxIcon.Question) != DialogResult.OK)
+ {
+ e.Cancel = true;
+ }
+ }
+
+ protected override void OnResize(EventArgs e)
+ {
+ base.OnResize(e);
+ if (_styles != null && IsHandleCreated)
+ {
+ DrawPreview();
+ }
+ }
+ }
+}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/HouseStyleEditorDialog.resx b/UoFiddler.Plugin.MultiEditor/UI/HouseStyleEditorDialog.resx
new file mode 100644
index 00000000..8b2ff64a
--- /dev/null
+++ b/UoFiddler.Plugin.MultiEditor/UI/HouseStyleEditorDialog.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
index 2ac5bd80..8f9ebd83 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
@@ -64,6 +64,9 @@ public MultiEditorControl()
// window is short, and comes to the front with the House tool or an open draft.
_housePanel = new HousePanel { Dock = DockStyle.Top };
_housePanel.PickStyle += PickHouseMaterial;
+ _housePanel.SaveTheme += SaveHouseTheme;
+ _housePanel.DeleteTheme += DeleteHouseTheme;
+ _housePanel.Message += Tell;
_housePanel.SaveDraft += SaveHouseDraft;
_housePanel.OpenDraft += OpenHouseDraft;
_housePanel.SaveBlueprint += SaveHouseBlueprint;
@@ -198,6 +201,7 @@ private void WatchHostForm()
{
_hostForm.ResizeBegin -= HostForm_ResizeBegin;
_hostForm.ResizeEnd -= HostForm_ResizeEnd;
+ _hostForm.FormClosing -= HostForm_FormClosing;
}
_hostForm = form;
@@ -205,6 +209,7 @@ private void WatchHostForm()
{
form.ResizeBegin += HostForm_ResizeBegin;
form.ResizeEnd += HostForm_ResizeEnd;
+ form.FormClosing += HostForm_FormClosing;
}
}
@@ -270,7 +275,7 @@ private void EnsureBuilt()
}
catch (Exception ex)
{
- ShowMessage($"OpenGL could not be started:\r\n{ex.Message}");
+ ShowMessage($"The client's house tables could not be read:\r\n{ex.Message}");
return;
}
@@ -279,6 +284,7 @@ private void EnsureBuilt()
BuildCanvasMenu();
_browser.SetHouseStyles(_houseStyles);
+ _browser.EditStylesRequested += EditHouseStyles;
_browser.TileChosen += id =>
{
Session?.SetDrawTile(id);
@@ -650,6 +656,12 @@ private void SetTool(ToolKind kind, bool fromHousePage = false)
Session.Tool = kind;
+ // A tool chosen in place of the style a pick was waiting for: the pick is off.
+ if (!fromHousePage && !_openingHousePage)
+ {
+ CancelHousePick();
+ }
+
// The house draft is worked on in its panel, which sits in the floors and selection sidebar.
if (kind == ToolKind.House && !_inspectorShown)
{
@@ -700,10 +712,15 @@ private void ChooseHouseStyle(HouseStyle style)
if (_housePick is { } pick && pick.Kind == style.Kind)
{
_housePick = null;
+ _housePanel.MarkPick(null, 0);
if (pick.Storey == HousePanel.FlatRoof)
{
Session.House.SetFlatRoofStyle(style);
}
+ else if (pick.Storey == HousePanel.FoundationPick)
+ {
+ Session.House.SetFoundationStyle(style);
+ }
else
{
Session.House.SetMaterial(style, style.Kind == HousePartKind.Roof ? null : pick.Storey);
@@ -713,7 +730,7 @@ private void ChooseHouseStyle(HouseStyle style)
return;
}
- _housePick = null;
+ CancelHousePick();
// With the House tool in use, a wall, floor or roof style clicked on the House page is
// a material of the house too: of the storey the chosen floor means, or of every
@@ -752,6 +769,7 @@ private void PickHouseMaterial(HousePartKind kind, int storey)
}
_housePick = (kind, storey);
+ _housePanel.MarkPick(kind, storey);
_openingHousePage = true;
try
{
@@ -762,9 +780,120 @@ private void PickHouseMaterial(HousePartKind kind, int storey)
_openingHousePage = false;
}
- _statusHint.Text = kind == HousePartKind.Roof ? "Pick the roof style of the house on the House page."
+ _pickHint = kind == HousePartKind.Roof ? "Pick the roof style of the house on the House page."
+ : kind == HousePartKind.Door ? "Pick the door style of the house on the House page."
+ : kind == HousePartKind.Stair ? "Pick the stair style of the house on the House page."
+ : storey == HousePanel.FoundationPick ? "Pick the wall style of the foundation on the House page (a quarter wall suits it)."
: storey == HousePanel.FlatRoof ? "Pick the floor style of the flat roofs on the House page."
: $"Pick the {(kind == HousePartKind.Wall ? "wall" : "floor")} style of storey {storey + 1} on the House page.";
+ _pickHint += " Esc cancels.";
+ UpdateStatus();
+ }
+
+ /// Drops a style pick the house panel asked for and has not got yet.
+ private void CancelHousePick()
+ {
+ if (_housePick != null)
+ {
+ _housePick = null;
+ _housePanel.MarkPick(null, 0);
+ UpdateStatus();
+ }
+ }
+
+ // What the status bar says for a while in place of the tool's hint.
+ private string _told;
+ private long _messageUntil;
+ private string _pickHint;
+
+ /// Says something in the status bar. It stays a few seconds, or until the next command, whatever the mouse does.
+ private void Tell(string text)
+ {
+ _told = text;
+ _messageUntil = Environment.TickCount64 + 5000;
+ _statusHint.Text = text;
+ }
+
+ ///
+ /// Opens the style editor. When it saved, the styles are new objects: the House page shows
+ /// them, and every open design's draft and chosen style take their successors.
+ ///
+ private void EditHouseStyles(HouseStyle start)
+ {
+ if (_houseStyles == null)
+ {
+ return;
+ }
+
+ bool saved;
+ using (var dialog = new HouseStyleEditorDialog(_houseStyles, start, () => _browser.CurrentTile))
+ {
+ dialog.ShowDialog(this);
+ saved = dialog.Saved;
+ }
+
+ if (!saved)
+ {
+ return;
+ }
+
+ _browser.SetHouseStyles(_houseStyles);
+ foreach (EditorDocument document in _documents)
+ {
+ document.Session.HouseStyle = _houseStyles.Successor(document.Session.HouseStyle);
+ document.Session.House.StylesReloaded();
+ }
+
+ _housePanel.RefreshDraft();
+ _canvas.Invalidate();
+ Tell("House styles saved.");
+ }
+
+ /// Saves the styles of the house draft as a theme in the user's copy of the style file.
+ private void SaveHouseTheme()
+ {
+ if (Session == null || _houseStyles == null)
+ {
+ return;
+ }
+
+ using var prompt = new TextPromptForm("Save theme", "Theme name", Session.House.CurrentTheme()?.Name ?? "My theme");
+ if (prompt.ShowDialog(this) != DialogResult.OK || string.IsNullOrWhiteSpace(prompt.Value))
+ {
+ return;
+ }
+
+ try
+ {
+ HouseStyleConfig.SaveUserTheme(Session.House.ThemeOfDraft(prompt.Value.Trim()));
+ _houseStyles.ReloadThemes();
+ _housePanel.RefreshDraft();
+ Tell($"Theme \"{prompt.Value.Trim()}\" saved.");
+ }
+ catch (Exception ex) when (ex is System.IO.IOException or UnauthorizedAccessException)
+ {
+ MessageBox.Show(this, "The theme could not be saved: " + ex.Message, "Save theme", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ }
+ }
+
+ private void DeleteHouseTheme(HouseTheme theme)
+ {
+ if (_houseStyles == null ||
+ MessageBox.Show(this, $"Delete the theme \"{theme.Name}\"?", "Delete theme", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
+ {
+ return;
+ }
+
+ try
+ {
+ HouseStyleConfig.DeleteUserTheme(theme.Name);
+ _houseStyles.ReloadThemes();
+ _housePanel.RefreshDraft();
+ }
+ catch (Exception ex) when (ex is System.IO.IOException or UnauthorizedAccessException)
+ {
+ MessageBox.Show(this, "The theme could not be deleted: " + ex.Message, "Delete theme", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
+ }
}
private static string HouseDraftFolder
@@ -894,6 +1023,13 @@ private void DeleteSelectionOrWing()
private void Escape()
{
+ // A style pick the house panel is waiting for goes first.
+ if (_housePick != null)
+ {
+ CancelHousePick();
+ return;
+ }
+
// With a roof being shaped: the first Esc stops a drag, the next one drops the roof.
if (Session.DraftInFocus is { } draft && !Session.ActiveTool.IsDragging)
{
@@ -945,7 +1081,7 @@ private void ReplaceIdPrompt()
bool selectionOnly = Session.Selection.Count > 1;
int count = Session.ReplaceTileId(fromId, toId, selectionOnly);
- _statusHint.Text = $"Replaced {count} tile(s)" + (selectionOnly ? " in the selection" : string.Empty);
+ Tell($"Replaced {count} tile(s)" + (selectionOnly ? " in the selection" : string.Empty));
}
/// Saves the selection as a blueprint, or the whole design when nothing is selected.
@@ -1422,7 +1558,11 @@ private void BuildMainStrip()
ToolStrip strip = _mainStrip;
Menu(_fileMenu, _new, _open, _openDesign, _import, _importFolder, null, _saveDesign, _saveDesignAs, _saveClient, _export, _saveBlueprint, _savePattern, null, _resize, _settingsCommand, null, _close, _closeAll);
- Menu(_editMenu, _undo, _redo, null, _cut, _copy, _paste, _duplicate, _repeat, _delete, null,
+ _undoHistory = new ToolStripMenuItem("Undo back to");
+ _editMenu.DropDownOpening += (_, _) => FillUndoHistory();
+ Menu(_editMenu, _undo, _redo);
+ _editMenu.DropDownItems.Add(_undoHistory);
+ Menu(_editMenu, null, _cut, _copy, _paste, _duplicate, _repeat, _delete, null,
_rotateLeft, _rotateRight, _mirrorX, _mirrorY, _swapStyle, null, _zUp, _zDown, _hide, _showHidden,
null, _newLayer, _moveToLayer, _selectLayer);
Menu(_selectMenu, _selectAll, _invert, _selectConnected, _selectSameId, null, _replaceId);
@@ -1485,6 +1625,31 @@ private ToolStripDropDownButton Menu(ToolStripDropDownButton menu, params Editor
return menu;
}
+ private ToolStripMenuItem _undoHistory;
+
+ /// Lists the last steps of the history by name; choosing one takes it and every later step back.
+ private void FillUndoHistory()
+ {
+ _undoHistory.DropDownItems.Clear();
+ IReadOnlyList steps = Session?.UndoSteps(25) ?? Array.Empty();
+ _undoHistory.Enabled = steps.Count > 0;
+ for (int i = 0; i < steps.Count; ++i)
+ {
+ int count = i + 1;
+ var item = new ToolStripMenuItem($"{count}. {steps[i]}");
+ item.Click += (_, _) =>
+ {
+ for (int n = 0; n < count && Session != null && Session.Undo(); ++n)
+ {
+ }
+
+ _commands.RefreshStates();
+ Tell(count == 1 ? "1 step undone." : $"{count} steps undone.");
+ };
+ _undoHistory.DropDownItems.Add(item);
+ }
+ }
+
private void Menu_DropDownOpening(object sender, EventArgs e)
{
_commands.RefreshStates();
@@ -2080,7 +2245,7 @@ private void SaveDesignFile(bool saveAs)
_active.FilePath = path;
Session.MarkSaved();
- _statusHint.Text = $"Saved {path}";
+ Tell($"Saved {path}");
}
private static string SafeFileName(string title)
@@ -2102,10 +2267,7 @@ private void ResizePrompt()
/// Closes every tab, asking once when any of them has unsaved changes.
private void CloseAllDocuments()
{
- int modified = _documents.Count(d => d.Session.Modified);
- if (modified > 0 && MessageBox.Show(this,
- (modified == 1 ? "1 design has" : $"{modified} designs have") +
- " changes that were not saved to the client or exported.\r\nClose all designs anyway?",
+ if (UnsavedWarning() is { } warning && MessageBox.Show(this, warning + "\r\nClose all designs anyway?",
"Multi Editor", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
{
return;
@@ -2120,6 +2282,45 @@ private void CloseAllDocuments()
CloseDocument(_active, ask: false);
}
+ /// What would be lost by closing every design now, or null when nothing would.
+ private string UnsavedWarning()
+ {
+ int modified = _documents.Count(d => d.Session.Modified);
+ int drafts = _documents.Count(d => d.Session.OpenDraft != null);
+ if (modified + drafts == 0)
+ {
+ return null;
+ }
+
+ var parts = new List();
+ if (modified > 0)
+ {
+ parts.Add((modified == 1 ? "1 design has" : $"{modified} designs have") + " changes that were not saved to a design file or the client, or exported.");
+ }
+
+ if (drafts > 0)
+ {
+ parts.Add((drafts == 1 ? "1 design has" : $"{drafts} designs have") + " a house or roof draft that was not placed.");
+ }
+
+ return string.Join("\r\n", parts);
+ }
+
+ /// The application is closing: ask once when designs have unsaved changes or drafts.
+ private void HostForm_FormClosing(object sender, FormClosingEventArgs e)
+ {
+ if (e.Cancel || !_built || UnsavedWarning() is not { } warning)
+ {
+ return;
+ }
+
+ if (MessageBox.Show(this, "Multi Editor: " + warning + "\r\nClose anyway?", "Multi Editor", MessageBoxButtons.OKCancel,
+ MessageBoxIcon.Warning) != DialogResult.OK)
+ {
+ e.Cancel = true;
+ }
+ }
+
private void CloseDocument(EditorDocument document, bool ask = true)
{
if (document == null)
@@ -2127,6 +2328,28 @@ private void CloseDocument(EditorDocument document, bool ask = true)
return;
}
+ // A draft that is not placed is not in the multi: place it, drop it, or stay.
+ if (ask && document.Session.OpenDraft is { } draft)
+ {
+ DialogResult answer = MessageBox.Show(this,
+ $"\"{document.Session.Title}\" has a {(draft is HouseTool ? "house" : "roof")} draft that is not placed.\r\n" +
+ "Yes places it in the design, No drops it.",
+ "Multi Editor", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
+ if (answer == DialogResult.Cancel)
+ {
+ return;
+ }
+
+ if (answer == DialogResult.Yes)
+ {
+ draft.Commit();
+ }
+ else
+ {
+ draft.Discard();
+ }
+ }
+
if (ask && document.Session.Modified && MessageBox.Show(this,
$"\"{document.Session.Title}\" has changes that were not saved to a design file or the client, or exported.\r\nClose it anyway?",
"Multi Editor", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
@@ -2541,7 +2764,9 @@ private void UpdateStatus()
return;
}
- _statusHint.Text = session.PreviewMode ? "Preview: editing is off. Right click picks the ground. F5 returns to the editor."
+ _statusHint.Text = _housePick != null ? _pickHint
+ : _told != null && Environment.TickCount64 < _messageUntil ? _told
+ : session.PreviewMode ? "Preview: editing is off. Right click picks the ground. F5 returns to the editor."
: session.PreviewingRepeat ? "The copies are shown as they would be placed."
: session.Pasting ? "Click to place the tiles, as often as you like. Esc or right click stops."
: session.ShapingRoof ? "Shaping: drag a wing to move it, a marked edge of the selected wing to resize it, anywhere else to add a wing. " +
@@ -2550,7 +2775,8 @@ private void UpdateStatus()
: ToolHint(session.Tool);
(int x, int y, int z) = session.CursorCell;
- _statusCell.Text = session.MouseInside && session.CompList.InBounds(x, y) ? $"Cell {x}, {y}, Z {z}" : string.Empty;
+ _statusCell.Text = session.ActiveTool.DragSize is { } drag ? $"{drag.Width} x {drag.Height} cells"
+ : session.MouseInside && session.CompList.InBounds(x, y) ? $"Cell {x}, {y}, Z {z}" : string.Empty;
int offset = session.WorkPlaneOffset;
_statusPlane.Text = $"Work plane Z {session.WorkPlaneZ}" + (offset != 0 ? $" (floor {offset:+0;-0})" : string.Empty) +
(session.ShowWorkPlane ? string.Empty : " (hidden)");
@@ -2592,11 +2818,43 @@ private static string ToolHint(ToolKind kind)
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
- if (!_built || (keyData != Keys.Escape && IsTextInputFocused()))
+ if (!_built)
+ {
+ return base.ProcessCmdKey(ref msg, keyData);
+ }
+
+ Control focused = FocusedControl();
+ bool sidebar = InSidebar(focused);
+ Keys code = keyData & Keys.KeyCode, held = keyData & Keys.Modifiers;
+ if (keyData == Keys.Escape && sidebar)
+ {
+ // Esc is the sidebar control's first: a search box clears itself, a name being
+ // typed is dropped, an open list closes. With nothing of that, the canvas gets
+ // the keyboard back; the tool and the selection stay as they are.
+ if (focused is TextBoxBase { TextLength: > 0 } || focused is ComboBox { DroppedDown: true } || NativeEditHasFocus())
+ {
+ return base.ProcessCmdKey(ref msg, keyData);
+ }
+
+ _canvas.Focus();
+ return true;
+ }
+
+ if (keyData != Keys.Escape && IsTextInputFocused())
{
return base.ProcessCmdKey(ref msg, keyData);
}
+ // A list, tree, grid or gallery of a sidebar has keys of its own (arrows, Delete,
+ // Enter, letters to search): plain keys are its, and a button's Space and Enter the
+ // button's. Ctrl and Alt shortcuts and the function keys stay the editor's.
+ bool plain = (held == Keys.None || held == Keys.Shift) && !(code >= Keys.F1 && code <= Keys.F24);
+ if (sidebar && plain && (TakesKeys(focused) || (focused is ButtonBase && code is Keys.Space or Keys.Enter)))
+ {
+ return base.ProcessCmdKey(ref msg, keyData);
+ }
+
+ _messageUntil = 0;
if (_commands.TryRun(keyData))
{
_commands.RefreshStates();
@@ -2639,7 +2897,8 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
}
/// True while typing in a text, number or combo box, where letters must not switch tools.
- private bool IsTextInputFocused()
+ /// The control of the editor that has the keyboard.
+ private Control FocusedControl()
{
Control focused = this;
while (focused is ContainerControl container && container.ActiveControl != null)
@@ -2647,6 +2906,33 @@ private bool IsTextInputFocused()
focused = container.ActiveControl;
}
+ return focused;
+ }
+
+ /// True for a control of the tile browser, the design sidebar or the house panel.
+ private bool InSidebar(Control control)
+ {
+ for (Control at = control; at != null && at != this; at = at.Parent)
+ {
+ if (at == _browser || at == _inspector || at == _housePanel)
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /// True for a control that works with plain keys itself.
+ private static bool TakesKeys(Control control)
+ {
+ return control is ListView or ListBox or TreeView or TrackBar or TileBrowserGrid or TileBrowserHouseGallery;
+ }
+
+ private bool IsTextInputFocused()
+ {
+ Control focused = FocusedControl();
+
return focused is TextBoxBase || focused is NumericUpDown || focused is ComboBox ||
focused.Parent is NumericUpDown || focused is ToolStrip || NativeEditHasFocus();
}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs b/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs
index bb82b089..75b4a93a 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs
@@ -52,9 +52,12 @@ public void ShowCommands(IEnumerable commands)
("Step through the floors", "Shift + wheel"),
("Place a paste, blueprint or duplicate, as often as you like", "Click"),
("Context menu, or stop a drag, paste or blueprint", "Right click"),
- ("Select the tile under the cursor (any tool)", "Middle click"),
+ ("Select the tile under the cursor (any tool)", "Middle click"));
+
+ Section("Keys on the canvas",
("Move the selection one cell", "Arrow keys"),
- ("Pan one cell", "Ctrl + arrow keys"));
+ ("Pan one cell", "Ctrl + arrow keys"),
+ ("Give the keyboard back to the canvas from a sidebar", "Esc"));
Section("Keys held with a tool",
("Move the selection (Select)", "Drag a selected tile"),
diff --git a/UoFiddler.Plugin.MultiEditor/UI/TileBrowserHouseGallery.cs b/UoFiddler.Plugin.MultiEditor/UI/TileBrowserHouseGallery.cs
index ffd4bc62..0f0d7dc3 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/TileBrowserHouseGallery.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/TileBrowserHouseGallery.cs
@@ -376,7 +376,25 @@ protected override void OnKeyDown(KeyEventArgs e)
e.Handled = true;
next = Math.Clamp(next, 0, cells.Count - 1);
- Choose(_slots[cells[next]].Item);
+ HouseGalleryItem item = _slots[cells[next]].Item;
+
+ // Arrows only walk the styles; Enter chooses, as a click does. Choosing can change a
+ // house draft, which must not happen once per key on the way to a style.
+ if (e.KeyCode == Keys.Enter)
+ {
+ Choose(item);
+ }
+ else if (item.Tag != null)
+ {
+ _selectedTag = item.Tag;
+ Invalidate();
+ }
+ else
+ {
+ _selected = item.Style;
+ Invalidate();
+ }
+
ScrollToSelected();
}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/TileBrowserPanel.cs b/UoFiddler.Plugin.MultiEditor/UI/TileBrowserPanel.cs
index e43bcf51..37133943 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/TileBrowserPanel.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/TileBrowserPanel.cs
@@ -149,6 +149,9 @@ public TileBrowserPanel()
///
public event Action SwapToHouseStyleRequested;
+ /// Asks for the style editor, on the style chosen on the House page (or none).
+ public event Action EditStylesRequested;
+
/// The current draw tile, or -1.
public int CurrentTile => _currentTile;
@@ -1267,6 +1270,14 @@ private void BuildHousePage()
_houseKindBar.Items.Insert(_houseKindBar.Items.IndexOf(_patternsButton), button);
}
+ var edit = new ToolStripButton("Edit...")
+ {
+ Alignment = ToolStripItemAlignment.Right,
+ ToolTipText = "Names, groups, order and pieces of the house styles."
+ };
+ edit.Click += (_, _) => EditStylesRequested?.Invoke(_houseStyle);
+ _houseKindBar.Items.Add(edit);
+
// The pieces of the chosen style: click one to draw with exactly that tile.
// Roughly half the page each by default; the splitter above the pieces moves the line.
_housePieces = new TileBrowserGrid(_thumbnails)
diff --git a/UoFiddler.Plugin.MultiEditor/UoFiddler.Plugin.MultiEditor.csproj b/UoFiddler.Plugin.MultiEditor/UoFiddler.Plugin.MultiEditor.csproj
index 755cae9c..ad1c00f8 100644
--- a/UoFiddler.Plugin.MultiEditor/UoFiddler.Plugin.MultiEditor.csproj
+++ b/UoFiddler.Plugin.MultiEditor/UoFiddler.Plugin.MultiEditor.csproj
@@ -125,6 +125,12 @@
ShortcutsForm.cs
+
+ Form
+
+
+ HouseStyleEditorDialog.cs
+
Form
@@ -175,6 +181,9 @@
ShortcutsForm.cs
+
+ HouseStyleEditorDialog.cs
+
TextPromptForm.cs
From bf744efb952d3535eac97726fb94c860ccb42e86 Mon Sep 17 00:00:00 2001
From: AsY!um- <377468+AsYlum-@users.noreply.github.com>
Date: Wed, 18 Nov 2026 23:20:43 +0100
Subject: [PATCH 07/16] Fix the ridge ends of a gable roof with an even span
along X
---
UoFiddler.Plugin.MultiEditor/Classes/RoofPlanner.cs | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/RoofPlanner.cs b/UoFiddler.Plugin.MultiEditor/Classes/RoofPlanner.cs
index 92e74e12..a67f27c4 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/RoofPlanner.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/RoofPlanner.cs
@@ -201,6 +201,19 @@ public static string Piece(IReadOnlyDictionary<(int X, int Y), int> heights, int
return null;
}
+ // The roof's edge counts as lower, so at a gable end a cell of the top rows of an even
+ // span drops as much to the edge as down its slope. The slope is the side where roof
+ // lies lower, not the edge.
+ if (Math.Abs(climbX) == Math.Abs(climbY))
+ {
+ bool roofLowerX = heights.ContainsKey((climbX > 0 ? x - 1 : x + 1, y));
+ bool roofLowerY = heights.ContainsKey((x, climbY > 0 ? y - 1 : y + 1));
+ if (roofLowerY && !roofLowerX)
+ {
+ return climbY > 0 ? "North" : "South";
+ }
+ }
+
return Math.Abs(climbX) >= Math.Abs(climbY) ? (climbX > 0 ? "West" : "East") : (climbY > 0 ? "North" : "South");
}
From 253719a6385f32d95761180f3074285093a408ea Mon Sep 17 00:00:00 2001
From: AsY!um- <377468+AsYlum-@users.noreply.github.com>
Date: Wed, 18 Nov 2026 23:58:59 +0100
Subject: [PATCH 08/16] Add battlements, walled wings and tower, keep and
castle presets
Ctrl+drag moves a whole draft; door steps on a foundation and other small gaps closed.
---
.../Classes/HouseDraft.cs | 328 +++++++++++++++++-
.../Classes/HouseDraftFile.cs | 12 +
.../Classes/HouseStyles.cs | 56 +++
.../Classes/RoomPlanner.cs | 87 +++++
.../MultiEditorHouseStyles.xml | 1 +
.../Tools/DraftEditTools.cs | 4 +
.../Tools/HouseTool.cs | 106 +++++-
.../Tools/WingDraftTool.cs | 74 +++-
.../UI/HousePanel.Designer.cs | 302 +++++++++-------
UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs | 49 +++
.../UI/MultiEditorControl.cs | 56 ++-
.../UI/TileBrowserPanel.cs | 52 +++
12 files changed, 995 insertions(+), 132 deletions(-)
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
index eb93a3dc..654fed08 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
@@ -75,6 +75,12 @@ internal sealed class HouseDraft
public RoofGableFill GableFill { get; set; } = RoofGableFill.Caps;
+ ///
+ /// True when flat roofs get battlements, as the client's tower, keep and castle have them:
+ /// two rows of the walls' roof edging around the roof and a third of every second piece.
+ ///
+ public bool Parapet { get; set; }
+
/// True when the doorways between rooms get a door of .
public bool AutoDoors { get; set; }
@@ -189,7 +195,7 @@ public HouseDraft Fresh()
RoofStyle = RoofStyle, FlatRoofStyle = FlatRoofStyle, Foundation = Foundation,
FoundationStyle = FoundationStyle, DoorStyle = DoorStyle, StairStyle = StairStyle,
AutoDoors = AutoDoors, FrontDoor = FrontDoor, WindowSpacing = WindowSpacing,
- Gables = Gables, GableFill = GableFill
+ Gables = Gables, GableFill = GableFill, Parapet = Parapet
};
Array.Copy(WallStyles, copy.WallStyles, MaxStoreys);
Array.Copy(FloorStyles, copy.FloorStyles, MaxStoreys);
@@ -272,6 +278,9 @@ public sealed class StoreyLayout
/// Wall cells the draft makes windows itself.
public HashSet<(int X, int Y)> Windows { get; } = new HashSet<(int X, int Y)>();
+
+ /// The wall cell of the front door, when the storey has one.
+ public (int X, int Y)? FrontDoor { get; set; }
}
///
@@ -313,6 +322,7 @@ public StoreyLayout LayOut(IReadOnlyList wings, int storey)
(int rooms, RoomLayout kind) = wing.RoomsOn(storey);
RoomPlan plan = RoomPlanner.Plan(wing.X0 + 1, wing.Y0 + 1, wing.X1, wing.Y1, kind, Math.Clamp(rooms, 1, MaxRooms));
+ RoomPlanner.Avoid(plan, stairs);
if (index == 0)
{
firstPlan = plan;
@@ -321,6 +331,8 @@ public StoreyLayout LayOut(IReadOnlyList wings, int storey)
Partition(wings, index, storey, plan, stairs, layout);
}
+ WallOff(wings, storey, region, stairs, layout);
+
foreach ((int x, int y) in AddedSouth[storey])
{
if (region.Contains((x, y)) || region.Contains((x, y + 1)))
@@ -487,6 +499,119 @@ bool Other(int x, int y)
}
}
+ ///
+ /// The walls of the wings that keep them () against the wings
+ /// they meet. Each cell belongs to one wing: a walled one where there is one, else the
+ /// first. A wall stands between cells of different wings when either is walled, and each
+ /// stretch of wall between the same two wings gets one doorway in its middle (a door, with
+ /// ), as near to it as stairs allow.
+ ///
+ private void WallOff(IReadOnlyList wings, int storey, HashSet<(int X, int Y)> region, HashSet<(int X, int Y)> stairs, StoreyLayout layout)
+ {
+ bool any = false;
+ foreach (RoofWing wing in wings)
+ {
+ any |= wing.Walled && wing.Storeys > storey;
+ }
+
+ if (!any)
+ {
+ return;
+ }
+
+ var owners = new Dictionary<(int X, int Y), int>();
+ int Owner((int X, int Y) cell)
+ {
+ if (owners.TryGetValue(cell, out int known))
+ {
+ return known;
+ }
+
+ int first = -1, walled = -1;
+ for (int i = 0; i < wings.Count && walled < 0; ++i)
+ {
+ RoofWing wing = wings[i];
+ if (wing.Storeys > storey && cell.X > wing.X0 && cell.X <= wing.X1 && cell.Y > wing.Y0 && cell.Y <= wing.Y1)
+ {
+ first = first < 0 ? i : first;
+ walled = wing.Walled ? i : walled;
+ }
+ }
+
+ return owners[cell] = walled >= 0 ? walled : first;
+ }
+
+ // Stretches of wall: along one line, between the same two wings, cell after cell.
+ var stretches = new Dictionary<(bool South, int Line, int A, int B), List<(int X, int Y)>>();
+ foreach ((int x, int y) in region)
+ {
+ foreach ((int nx, int ny, bool south) in new[] { (x + 1, y, false), (x, y + 1, true) })
+ {
+ if (!region.Contains((nx, ny)) || (south ? layout.South : layout.East).Contains((x, y)))
+ {
+ continue;
+ }
+
+ int a = Owner((x, y)), b = Owner((nx, ny));
+ if (a == b || a < 0 || b < 0 || !(wings[a].Walled || wings[b].Walled))
+ {
+ continue;
+ }
+
+ var key = (south, south ? y : x, a, b);
+ if (!stretches.TryGetValue(key, out List<(int X, int Y)> cells))
+ {
+ stretches[key] = cells = new List<(int X, int Y)>();
+ }
+
+ cells.Add((x, y));
+ }
+ }
+
+ foreach (KeyValuePair<(bool South, int Line, int A, int B), List<(int X, int Y)>> stretch in stretches)
+ {
+ bool south = stretch.Key.South;
+ List<(int X, int Y)> cells = stretch.Value.OrderBy(c => south ? c.X : c.Y).ToList();
+ for (int start = 0; start < cells.Count;)
+ {
+ int end = start;
+ while (end + 1 < cells.Count && (south ? cells[end + 1].X - cells[end].X : cells[end + 1].Y - cells[end].Y) == 1)
+ {
+ ++end;
+ }
+
+ int middle = (start + end) / 2, pick = middle, nearest = int.MaxValue;
+ for (int i = start; i <= end; ++i)
+ {
+ (int x, int y) = cells[i];
+ bool free = !stairs.Contains((x, y)) && !stairs.Contains(south ? (x, y + 1) : (x + 1, y));
+ if (free && Math.Abs(i - middle) < nearest)
+ {
+ (pick, nearest) = (i, Math.Abs(i - middle));
+ }
+ }
+
+ for (int i = start; i <= end; ++i)
+ {
+ (int x, int y) = cells[i];
+ if (i == pick)
+ {
+ if (!AutoDoors || Suppressed.Contains((storey, x, y)))
+ {
+ continue;
+ }
+
+ layout.Doors[(x, y)] = south ? DoorAlongX : DoorAlongY;
+ }
+
+ (south ? layout.South : layout.East).Add((x, y));
+ }
+
+ start = end + 1;
+ }
+ }
+ }
+
///
/// The front door: in the chosen outer wall of the first wing, in the middle of it, or of
/// the corridor or hall where that reaches the wall. Corners, wall ends and stairs are passed over.
@@ -528,6 +653,7 @@ private void AddFrontDoor(IReadOnlyList wings, RoomPlan plan, HashSet<
if (best is { } door && !Suppressed.Contains((0, door.X, door.Y)))
{
layout.Doors[door] = south ? DoorAlongX : DoorAlongY;
+ layout.FrontDoor = door;
}
}
@@ -587,6 +713,79 @@ void Close()
}
}
+ ///
+ /// Moves what was changed by hand inside a wing along with that wing: walls added and
+ /// taken away, doors, windows, floor areas and stairs whose cell lies in the box.
+ ///
+ public void ShiftWithin((int X0, int Y0, int X1, int Y1) box, int dx, int dy)
+ {
+ if (dx == 0 && dy == 0)
+ {
+ return;
+ }
+
+ bool In(int x, int y) => x >= box.X0 && x <= box.X1 && y >= box.Y0 && y <= box.Y1;
+ void Move(HashSet<(int X, int Y)> set)
+ {
+ var moved = new List<(int X, int Y)>();
+ foreach ((int x, int y) in set)
+ {
+ moved.Add(In(x, y) ? (x + dx, y + dy) : (x, y));
+ }
+
+ set.Clear();
+ set.UnionWith(moved);
+ }
+
+ void MoveOnStoreys(HashSet<(int Storey, int X, int Y)> set)
+ {
+ var moved = new List<(int Storey, int X, int Y)>();
+ foreach ((int storey, int x, int y) in set)
+ {
+ moved.Add(In(x, y) ? (storey, x + dx, y + dy) : (storey, x, y));
+ }
+
+ set.Clear();
+ set.UnionWith(moved);
+ }
+
+ for (int k = 0; k < MaxStoreys; ++k)
+ {
+ Move(AddedSouth[k]);
+ Move(AddedEast[k]);
+ Move(ErasedSouth[k]);
+ Move(ErasedEast[k]);
+ }
+
+ MoveOnStoreys(Windows);
+ MoveOnStoreys(Suppressed);
+ var doors = new List>(Doors);
+ Doors.Clear();
+ foreach (var door in doors)
+ {
+ (int storey, int x, int y) = door.Key;
+ Doors[In(x, y) ? (storey, x + dx, y + dy) : door.Key] = door.Value;
+ }
+
+ for (int i = 0; i < FloorAreas.Count; ++i)
+ {
+ var a = FloorAreas[i];
+ if (In(a.X0, a.Y0) && In(a.X1, a.Y1))
+ {
+ FloorAreas[i] = (a.Storey, a.X0 + dx, a.Y0 + dy, a.X1 + dx, a.Y1 + dy, a.Style);
+ }
+ }
+
+ for (int i = 0; i < Stairs.Count; ++i)
+ {
+ var s = Stairs[i];
+ if (In(s.X, s.Y))
+ {
+ Stairs[i] = (s.Storey, s.X + dx, s.Y + dy, s.Column, s.Style);
+ }
+ }
+ }
+
/// Moves everything changed by hand along with the house.
public void Shift(int dx, int dy)
{
@@ -802,9 +1001,136 @@ public Built Build(IReadOnlyList wings, HouseStyles styles)
}
}
+ if (Parapet)
+ {
+ AddParapets(wings, styles, built);
+ }
+
+ if (Foundation && StairStyle != null && top > 0 && LayOut(wings, 0).FrontDoor is { } front)
+ {
+ AddSteps(front, styles, built);
+ }
+
return built;
}
+ ///
+ /// Steps up to the front door of a house on a foundation, as the client's houses have
+ /// them: one row outside the door, a step under it and a corner piece on each side, 5
+ /// below the floor (the pieces are 5 high).
+ ///
+ private void AddSteps((int X, int Y) door, HouseStyles styles, Built built)
+ {
+ bool south = FrontDoor == FrontDoorSide.South;
+ ushort step = StairStyle.Get(south ? "North" : "West");
+ if (step == 0)
+ {
+ return;
+ }
+
+ int z = BaseZ - Math.Max(1, (int)Ultima.TileData.ItemTable[step].Height);
+ (int X, int Y) at = south ? (door.X, door.Y + 1) : (door.X + 1, door.Y);
+ built.Tiles.Add((step, at.X, at.Y, z, StairsLayer));
+
+ // The corners: south-east, north-east, north-west, south-west of a stair set.
+ ushort before = StairStyle.Get("Squared1"), after = StairStyle.Get("Squared2");
+ if (after != 0 && styles.TryGetStairCorner(after, out ushort[] corners, out _) && corners.Length == 4)
+ {
+ (before, after) = south ? (corners[3], corners[0]) : (corners[1], corners[0]);
+ }
+ else if (!south)
+ {
+ (before, after) = (0, 0);
+ }
+
+ if (before != 0 && (south ? at.X : at.Y) > 0)
+ {
+ built.Tiles.Add((before, south ? at.X - 1 : at.X, south ? at.Y : at.Y - 1, z, StairsLayer));
+ }
+
+ if (after != 0)
+ {
+ built.Tiles.Add((after, south ? at.X + 1 : at.X, south ? at.Y : at.Y + 1, z, StairsLayer));
+ }
+ }
+
+ ///
+ /// Battlements around the flat roofs. The flat wings of one height are walled as one
+ /// roof: along its edge, but not where a taller wing stands (its wall is there). Measured
+ /// on the client's tower, keep and castle: the edging stands in the roof's wall cells at
+ /// the roof's Z and once more on top of that, and a third row has every second straight
+ /// piece, leaving the corners out.
+ ///
+ private void AddParapets(IReadOnlyList wings, HouseStyles styles, Built built)
+ {
+ // A wing without a roof is a walled yard: its walls carry battlements too.
+ foreach (IGrouping level in wings.Where(w => w.NoRoof || w.Shape == RoofShape.Flat).GroupBy(w => Math.Clamp(w.Storeys, 1, MaxStoreys)))
+ {
+ int storeys = level.Key;
+ HouseStyle style = styles.ParapetFor(WallStyles[storeys - 1]);
+ if (style == null)
+ {
+ continue;
+ }
+
+ HashSet<(int X, int Y)> above = Region(wings, storeys);
+ var roof = new HashSet<(int X, int Y)>();
+ foreach (RoofWing wing in level)
+ {
+ for (int x = wing.X0 + 1; x <= wing.X1; ++x)
+ {
+ for (int y = wing.Y0 + 1; y <= wing.Y1; ++y)
+ {
+ if (!above.Contains((x, y)))
+ {
+ roof.Add((x, y));
+ }
+ }
+ }
+ }
+
+ if (roof.Count == 0)
+ {
+ continue;
+ }
+
+ var south = new HashSet<(int X, int Y)>();
+ var east = new HashSet<(int X, int Y)>();
+ Outline(roof, south, east);
+ south.RemoveWhere(c => above.Contains(c) || above.Contains((c.X, c.Y + 1)));
+ east.RemoveWhere(c => above.Contains(c) || above.Contains((c.X + 1, c.Y)));
+
+ // The wall cells start one before the roof cells; the tower counts its merlons from there.
+ int minX = roof.Min(c => c.X) - 1, minY = roof.Min(c => c.Y) - 1;
+ int z = BaseZ + (storeys * StoreyHeight);
+ int tier = Math.Max(1, (int)Ultima.TileData.ItemTable[style.Get("South2")].Height);
+ foreach ((int x, int y) in WallCells(south, east))
+ {
+ string column = WallPlanner.PieceFor(south, east, x, y);
+ ushort id = column != null ? style.Get(column) : (ushort)0;
+ if (id == 0)
+ {
+ continue;
+ }
+
+ built.Tiles.Add((id, x, y, z, RoofTool.LayerName));
+ built.Tiles.Add((id, x, y, z + tier, RoofTool.LayerName));
+
+ // The merlons: every second straight piece.
+ bool alongX = column.StartsWith("South", StringComparison.Ordinal), alongY = column.StartsWith("East", StringComparison.Ordinal);
+ if ((alongX && (x - minX) % 2 == 0) || (alongY && (y - minY) % 2 == 0))
+ {
+ built.Tiles.Add((id, x, y, z + (2 * tier), RoofTool.LayerName));
+ }
+ else if (column == "Corner" && (x - minX) % 2 == 0 && style.Get("South2") is var merlon and not 0)
+ {
+ // A corner cell in step with the wall along X carries that wall's merlon (the tower's inner corner does).
+ built.Tiles.Add((merlon, x, y, z + (2 * tier), RoofTool.LayerName));
+ }
+ }
+ }
+ }
+
private readonly Dictionary _pieces = new Dictionary();
private ushort[] Pieces(HouseStyle style)
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs
index cf8f3928..3e567204 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs
@@ -56,6 +56,11 @@ public static XElement ToXml(IReadOnlyList wings, HouseDraft draft, st
root.Add(new XAttribute("gableFill", draft.GableFill));
}
+ if (draft.Parapet)
+ {
+ root.Add(new XAttribute("battlements", true));
+ }
+
if (draft.AutoDoors)
{
root.Add(new XAttribute("roomDoors", true));
@@ -90,6 +95,11 @@ public static XElement ToXml(IReadOnlyList wings, HouseDraft draft, st
element.Add(new XAttribute("layout", wing.Layout));
}
+ if (wing.Walled)
+ {
+ element.Add(new XAttribute("walled", true));
+ }
+
// Storeys with rooms of their own, as "storey:rooms:layout".
string above = string.Join(" ", Enumerable.Range(1, HouseDraft.MaxStoreys - 1).Where(k => wing.RoomsAbove[k] != null)
.Select(k => $"{k.ToString(CultureInfo.InvariantCulture)}:{wing.RoomsAbove[k].Value.Rooms.ToString(CultureInfo.InvariantCulture)}:{wing.RoomsAbove[k].Value.Layout}"));
@@ -214,6 +224,7 @@ HouseStyle Style(HousePartKind kind, XElement element, string attribute)
draft.Foundation = (bool?)root.Attribute("foundation") ?? false;
draft.Gables = Enum.TryParse((string)root.Attribute("gables"), out RoofGables gables) ? gables : RoofGables.Front;
draft.GableFill = Enum.TryParse((string)root.Attribute("gableFill"), out RoofGableFill gableFill) ? gableFill : RoofGableFill.Caps;
+ draft.Parapet = (bool?)root.Attribute("battlements") ?? false;
draft.AutoDoors = (bool?)root.Attribute("roomDoors") ?? false;
draft.FrontDoor = Enum.TryParse((string)root.Attribute("frontDoor"), out FrontDoorSide side) ? side : FrontDoorSide.None;
draft.WindowSpacing = Math.Clamp((int?)root.Attribute("windowSpacing") ?? 0, 0, 12);
@@ -238,6 +249,7 @@ HouseStyle Style(HousePartKind kind, XElement element, string attribute)
Storeys = Math.Clamp((int?)element.Attribute("storeys") ?? 1, 1, HouseDraft.MaxStoreys),
Rooms = Math.Clamp((int?)element.Attribute("rooms") ?? houseRooms, 1, HouseDraft.MaxRooms),
Layout = Enum.TryParse((string)element.Attribute("layout"), out RoomLayout layout) ? layout : RoomLayout.Row,
+ Walled = (bool?)element.Attribute("walled") ?? false,
NoRoof = roof == "None",
Shape = Enum.TryParse(roof, out RoofShape shape) ? shape : RoofShape.Gable,
RidgeAuto = ridge == "Auto"
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseStyles.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseStyles.cs
index 1f5c71ad..76496580 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/HouseStyles.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseStyles.cs
@@ -222,6 +222,53 @@ ushort Own(HouseStyle of)
return window;
}
+ private readonly Dictionary _parapets = new Dictionary();
+
+ ///
+ /// The style a wall style's battlements are built in: the roof edging of its material
+ /// (the one named most like it, where a material has several), or else its quarter
+ /// walls. Null when the material has neither.
+ ///
+ public HouseStyle ParapetFor(HouseStyle walls)
+ {
+ if (walls == null)
+ {
+ return null;
+ }
+
+ if (_parapets.TryGetValue(walls, out HouseStyle known))
+ {
+ return known;
+ }
+
+ string[] words = walls.Name.Split(' ', System.StringSplitOptions.RemoveEmptyEntries);
+ HouseStyle best = null, low = null;
+ int most = -1;
+ foreach (HouseStyle other in Styles)
+ {
+ ushort piece = other.Get("South2");
+ if (other.Kind != HousePartKind.Wall || other.Group != walls.Group || piece == 0 || other.Get("East2") == 0)
+ {
+ continue;
+ }
+
+ if (other.Name.Contains("Roof Edging", System.StringComparison.OrdinalIgnoreCase))
+ {
+ int shared = other.Name.Split(' ', System.StringSplitOptions.RemoveEmptyEntries).Count(word => words.Contains(word));
+ if (shared > most)
+ {
+ (best, most) = (other, shared);
+ }
+ }
+ else if (low == null && Ultima.TileData.ItemTable[piece].Height < 8)
+ {
+ low = other;
+ }
+ }
+
+ return _parapets[walls] = best ?? low;
+ }
+
/// Reads the themes again after the user's copy of the style file changed.
public void ReloadThemes()
{
@@ -283,6 +330,7 @@ public void Reload()
}
_windows.Clear();
+ _parapets.Clear();
_listedByArt = null;
_stairCorners = null;
Reloaded?.Invoke();
@@ -411,6 +459,14 @@ internal static HouseStyles Load(bool splitFloorsByColour, HouseStyleConfig conf
result.FinishWalls();
result.Order();
result.SetThemes(config);
+ foreach (HouseStyle style in result.Styles)
+ {
+ if (string.IsNullOrEmpty(style.Family))
+ {
+ style.Family = style.Group ?? string.Empty;
+ }
+ }
+
result.Errors.AddRange(errors);
if (config != null)
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/RoomPlanner.cs b/UoFiddler.Plugin.MultiEditor/Classes/RoomPlanner.cs
index 5e2dd8b4..db4041f4 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/RoomPlanner.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/RoomPlanner.cs
@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
namespace UoFiddler.Plugin.MultiEditor.Classes
{
@@ -159,6 +160,92 @@ public static RoomPlan Plan(int x0, int y0, int x1, int y1, RoomLayout layout, i
return plan;
}
+ ///
+ /// Moves the walls between rooms off stairs: a wall that would run between two stair
+ /// cells steps one or two cells aside, where the rooms on both sides stay wide enough.
+ /// A wall that cannot is left where it is (the draft then leaves it open at the stairs).
+ ///
+ public static void Avoid(RoomPlan plan, ICollection<(int X, int Y)> stairs)
+ {
+ if (stairs.Count == 0 || plan.Rooms.Count < 2)
+ {
+ return;
+ }
+
+ foreach (bool alongY in new[] { true, false })
+ {
+ // A wall along Y stands after column c: between the rooms that end at c and those that start at c + 1.
+ int End((int X0, int Y0, int X1, int Y1) r) => alongY ? r.X1 : r.Y1;
+ int Start((int X0, int Y0, int X1, int Y1) r) => alongY ? r.X0 : r.Y0;
+ (int From, int To) Side((int X0, int Y0, int X1, int Y1) r) => alongY ? (r.Y0, r.Y1) : (r.X0, r.X1);
+ bool Cut(int c, List before)
+ {
+ foreach (int i in before)
+ {
+ (int from, int to) = Side(plan.Rooms[i]);
+ for (int at = from; at <= to; ++at)
+ {
+ if (alongY ? stairs.Contains((c, at)) && stairs.Contains((c + 1, at)) : stairs.Contains((at, c)) && stairs.Contains((at, c + 1)))
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ foreach (int c in plan.Rooms.Select(End).Distinct().ToList())
+ {
+ var before = new List();
+ var after = new List();
+ for (int i = 0; i < plan.Rooms.Count; ++i)
+ {
+ if (End(plan.Rooms[i]) == c)
+ {
+ before.Add(i);
+ }
+ else if (Start(plan.Rooms[i]) == c + 1)
+ {
+ after.Add(i);
+ }
+ }
+
+ // Only a wall with the same rooms' length on both sides can move as one.
+ if (after.Count == 0 || before.Sum(i => Side(plan.Rooms[i]).To - Side(plan.Rooms[i]).From + 1) != after.Sum(i => Side(plan.Rooms[i]).To - Side(plan.Rooms[i]).From + 1) ||
+ !Cut(c, before))
+ {
+ continue;
+ }
+
+ foreach (int by in new[] { 1, -1, 2, -2 })
+ {
+ // A room keeps the least width; one already narrower (a corridor) keeps its own.
+ int least(int i) => Math.Min(MinRoom, End(plan.Rooms[i]) - Start(plan.Rooms[i]) + 1);
+ bool fits = before.All(i => c + by - Start(plan.Rooms[i]) + 1 >= least(i)) && after.All(i => End(plan.Rooms[i]) - (c + by + 1) + 1 >= least(i));
+ if (!fits || Cut(c + by, before))
+ {
+ continue;
+ }
+
+ foreach (int i in before)
+ {
+ (int x0, int y0, int x1, int y1) = plan.Rooms[i];
+ plan.Rooms[i] = alongY ? (x0, y0, c + by, y1) : (x0, y0, x1, c + by);
+ }
+
+ foreach (int i in after)
+ {
+ (int x0, int y0, int x1, int y1) = plan.Rooms[i];
+ plan.Rooms[i] = alongY ? (c + by + 1, y0, x1, y1) : (x0, c + by + 1, x1, y1);
+ }
+
+ break;
+ }
+ }
+ }
+ }
+
///
/// Cuts a span of cells into parts of about the same size, each at least
/// long: fewer parts when the span is too short for that many.
diff --git a/UoFiddler.Plugin.MultiEditor/MultiEditorHouseStyles.xml b/UoFiddler.Plugin.MultiEditor/MultiEditorHouseStyles.xml
index 8ce71e9b..bc29b861 100644
--- a/UoFiddler.Plugin.MultiEditor/MultiEditorHouseStyles.xml
+++ b/UoFiddler.Plugin.MultiEditor/MultiEditorHouseStyles.xml
@@ -837,6 +837,7 @@
+
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/DraftEditTools.cs b/UoFiddler.Plugin.MultiEditor/Tools/DraftEditTools.cs
index 6d52efb9..3797a9ce 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/DraftEditTools.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/DraftEditTools.cs
@@ -72,6 +72,8 @@ public DraftWallTool(IEditorContext context, HouseTool house) : base(context, ho
public override bool IsDragging => _dragging;
+ public override (int Width, int Height)? DragSize => _dragging ? (Math.Abs(_endX - _startX) + 1, Math.Abs(_endY - _startY) + 1) : null;
+
public override void OnMouseDown(MouseEventArgs e)
{
MouseCell(out _startX, out _startY);
@@ -173,6 +175,8 @@ public DraftFloorTool(IEditorContext context, HouseTool house) : base(context, h
public override bool IsDragging => _dragging;
+ public override (int Width, int Height)? DragSize => _dragging ? (Math.Abs(_endX - _startX) + 1, Math.Abs(_endY - _startY) + 1) : null;
+
public override void OnMouseDown(MouseEventArgs e)
{
MouseCell(out _startX, out _startY);
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
index bc35b0bc..e98d5179 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
@@ -33,6 +33,7 @@ internal sealed class HouseTool : WingDraftTool
private int _storeys = 1;
private int _rooms = 1;
private RoomLayout _layout;
+ private bool _walled;
private RoofShape _shape = RoofShape.Gable;
private bool _noRoof;
private RoofRidge _ridge = RoofRidge.Auto;
@@ -192,7 +193,7 @@ protected override List WingsFor(int startX, int startY, int endX, int
var wing = new RoofWing
{
- X0 = x0, Y0 = y0, X1 = x1, Y1 = y1, EaveZ = z, Storeys = _storeys, Rooms = _rooms, Layout = _layout,
+ X0 = x0, Y0 = y0, X1 = x1, Y1 = y1, EaveZ = z, Storeys = _storeys, Rooms = _rooms, Layout = _layout, Walled = _walled,
Shape = _shape, NoRoof = _noRoof, RidgeAuto = _ridge == RoofRidge.Auto
};
Snap(wing, moved: false);
@@ -260,6 +261,24 @@ protected override void Turn(RoofWing wing)
protected override object CaptureExtra() => _draft.Clone();
+ protected override void WingMoved(RoofWing before, int dx, int dy, object extraAtStart)
+ {
+ // What was set by hand inside the wing goes with it.
+ if (extraAtStart is HouseDraft start)
+ {
+ _draft = start.Clone();
+ _draft.ShiftWithin(before.Box, dx, dy);
+ ++_version;
+ }
+ }
+
+ protected override void DraftMoved(int dx, int dy)
+ {
+ // Walls, doors, windows, floor areas and stairs set by hand go with the house.
+ _draft.Shift(dx, dy);
+ ++_version;
+ }
+
protected override void RestoreExtra(object extra)
{
_draft = extra is HouseDraft saved ? saved.Clone() : _draft.Fresh();
@@ -421,6 +440,89 @@ public void SetOwnRooms(int storey, bool own)
Edit(() => wing.RoomsAbove[storey] = own ? wing.RoomsOn(storey) : null);
}
+ /// True when the selected wing, else the wings drawn next, keeps its walls against other wings.
+ public bool Walled => SelectedWing?.Walled ?? _walled;
+
+ /// Lets the selected wing, and the wings drawn next, keep its walls where it meets other wings.
+ public void SetWalled(bool walled)
+ {
+ _walled = walled;
+ if (SelectedWing is { } wing && wing.Walled != walled)
+ {
+ Edit(() => wing.Walled = walled);
+ }
+ else
+ {
+ RaiseChanged();
+ }
+ }
+
+ /// The fortified houses a draft can be started from.
+ public static readonly string[] Presets = { "Tower", "Keep", "Castle" };
+
+ ///
+ /// Makes a tower, keep or castle the draft, sized to the multi: flat roofs with
+ /// battlements, corner towers that keep their walls, a front door and windows. It is an
+ /// ordinary draft from there on, and one step of the history. Returns what is in the way,
+ /// or null when the draft was made.
+ ///
+ public string LoadPreset(string preset)
+ {
+ int room = Math.Min(Context.CompList.Width, Context.CompList.Height) - 3;
+ (int least, int most) = preset switch { "Tower" => (7, 11), "Keep" => (17, 23), _ => (24, 30) };
+ if (room < least)
+ {
+ return $"A {preset.ToLowerInvariant()} needs a multi of at least {least + 3} x {least + 3} cells.";
+ }
+
+ int n = Math.Min(room, most);
+ const int o = 1;
+ string Wing(int x0, int y0, int x1, int y1, int storeys, string roof, bool walled, int rooms = 1) =>
+ $"";
+ string Corners(int tower, int storeys) =>
+ Wing(o, o, o + tower, o + tower, storeys, "Flat", true) + Wing(o + n - tower, o, o + n, o + tower, storeys, "Flat", true) +
+ Wing(o, o + n - tower, o + tower, o + n, storeys, "Flat", true) + Wing(o + n - tower, o + n - tower, o + n, o + n, storeys, "Flat", true);
+
+ string wings;
+ switch (preset)
+ {
+ case "Tower":
+ wings = Wing(o, o, o + n, o + n, 3, "Flat", false);
+ break;
+ case "Keep":
+ {
+ // A hall of two storeys with a taller tower on each corner, standing two cells out of it.
+ const int tower = 6, inset = 2;
+ wings = Wing(o + inset, o + inset, o + n - inset, o + n - inset, 2, "Flat", false, 2) + Corners(tower, 3);
+ break;
+ }
+
+ default:
+ {
+ // A walled yard with a tower on each corner and a hall across its far side.
+ const int tower = 7, inset = 2;
+ wings = Wing(o + inset, o + inset, o + n - inset, o + n - inset, 1, "None", false) + Corners(tower, 3) +
+ Wing(o + tower, o + inset, o + n - tower, o + inset + 7, 2, "Flat", true, 2);
+ break;
+ }
+ }
+
+ EnsureMaterials();
+ XElement house = XElement.Parse(
+ $"{wings}");
+ OpenXml(house);
+ return null;
+ }
+
+ /// Battlements around the flat roofs, on or off.
+ public void SetParapet(bool on)
+ {
+ if (_draft.Parapet != on)
+ {
+ Edit(() => _draft.Parapet = on);
+ }
+ }
+
/// Doors in the doorways between rooms, on or off.
public void SetAutoDoors(bool on)
{
@@ -921,7 +1023,7 @@ protected override (List Remove, List<(ushort Id, int X, int Y, int Z
EnsureMaterials();
string key = string.Join(";", wings.Select(w =>
- $"{w.X0},{w.Y0},{w.X1},{w.Y1},{w.EaveZ},{w.Storeys},{w.Rooms},{w.Layout},{string.Join("/", w.RoomsAbove)},{w.Shape},{w.NoRoof},{w.RidgeAlongY}")) +
+ $"{w.X0},{w.Y0},{w.X1},{w.Y1},{w.EaveZ},{w.Storeys},{w.Rooms},{w.Layout},{w.Walled},{string.Join("/", w.RoomsAbove)},{w.Shape},{w.NoRoof},{w.RidgeAlongY}")) +
$"|{_version}|{_draft.Gables}|{_draft.GableFill}|{Context.CompList.UndoList.Count}|{Context.CompList.RedoList.Count}";
if (key == _builtFor)
{
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
index 277a33db..a593b064 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
@@ -50,6 +50,13 @@ internal sealed class RoofWing
/// How the rooms of a house wing are laid out.
public RoomLayout Layout { get; set; }
+ ///
+ /// True for a house wing that keeps its walls where it meets other wings, with a doorway
+ /// in each stretch of wall they share: a tower at a keep's corner, a hall in a castle's
+ /// yard. Wings without it run into each other as one open space.
+ ///
+ public bool Walled { get; set; }
+
///
/// Rooms and layout of the storeys above the ground floor that have their own; a storey
/// without takes those of the storey below it. Index 0 is not used.
@@ -92,6 +99,7 @@ public void CopyFrom(RoofWing other)
(Shape, RidgeAlongY, RidgeAuto, Storeys, NoRoof) = (other.Shape, other.RidgeAlongY, other.RidgeAuto, other.Storeys, other.NoRoof);
Rooms = other.Rooms;
Layout = other.Layout;
+ Walled = other.Walled;
RoomsAbove = ((int, RoomLayout)?[])other.RoomsAbove.Clone();
}
}
@@ -137,6 +145,10 @@ private sealed class State
private int _endY;
private int _z;
private RoofWing _before;
+
+ // A Ctrl+drag moves every wing: where they all stood, and how far they have been moved so far.
+ private List _beforeAll;
+ private (int X, int Y) _movedAll;
private State _dragStart;
private int _grabX;
private int _grabY;
@@ -242,6 +254,20 @@ public int SelectedIndex
/// What the draft holds beside its wings, for the undo history.
protected virtual object CaptureExtra() => null;
+ ///
+ /// One wing is being moved: it stood as and is now this far
+ /// from there. is what the draft kept besides its wings
+ /// when the drag began, so the move is always made from there, not step upon step.
+ ///
+ protected virtual void WingMoved(RoofWing before, int dx, int dy, object extraAtStart)
+ {
+ }
+
+ /// Every wing was moved by this many cells: what a draft keeps besides its wings moves along.
+ protected virtual void DraftMoved(int dx, int dy)
+ {
+ }
+
protected virtual void RestoreExtra(object extra)
{
}
@@ -378,6 +404,16 @@ public override void OnMouseDown(MouseEventArgs e)
(_grabX, _grabY) = (cx, cy);
Edges(wing, cx, cy, wasSelected, out _west, out _east, out _north, out _south);
_drag = _west || _east || _north || _south ? DragKind.Resize : DragKind.Move;
+
+ // With Ctrl the whole draft moves, not the one wing.
+ _beforeAll = null;
+ if (CtrlHeld)
+ {
+ _drag = DragKind.Move;
+ _beforeAll = _wings.Select(w => w.Clone()).ToList();
+ _movedAll = (0, 0);
+ }
+
RaiseChanged();
return;
}
@@ -469,11 +505,27 @@ public override void Cancel()
private void CancelDrag()
{
- if (_drag is DragKind.Move or DragKind.Resize && _before != null && SelectedWing is { } wing)
+ if (_drag == DragKind.Move && _beforeAll != null && _beforeAll.Count == _wings.Count)
+ {
+ // The whole draft was being moved: all of it goes back.
+ for (int i = 0; i < _wings.Count; ++i)
+ {
+ _wings[i].CopyFrom(_beforeAll[i]);
+ }
+
+ DraftMoved(-_movedAll.X, -_movedAll.Y);
+ }
+ else if (_drag is DragKind.Move or DragKind.Resize && _before != null && SelectedWing is { } wing)
{
wing.CopyFrom(_before);
+ if (_drag == DragKind.Move)
+ {
+ WingMoved(_before, 0, 0, _dragStart?.Extra);
+ }
}
+ _beforeAll = null;
+
_before = null;
_dragStart = null;
_drag = DragKind.None;
@@ -654,12 +706,32 @@ private void DragWing()
Context.PlaneCell(Context.MouseLoc, GripZ(_before), out int cx, out int cy);
int dx = cx - _grabX, dy = cy - _grabY;
+ if (_drag == DragKind.Move && _beforeAll != null && _beforeAll.Count == _wings.Count)
+ {
+ dx = Math.Max(dx, -_beforeAll.Min(w => w.X0));
+ dy = Math.Max(dy, -_beforeAll.Min(w => w.Y0));
+ for (int i = 0; i < _wings.Count; ++i)
+ {
+ RoofWing was = _beforeAll[i];
+ (_wings[i].X0, _wings[i].X1, _wings[i].Y0, _wings[i].Y1) = (was.X0 + dx, was.X1 + dx, was.Y0 + dy, was.Y1 + dy);
+ }
+
+ if ((dx, dy) != _movedAll)
+ {
+ DraftMoved(dx - _movedAll.X, dy - _movedAll.Y);
+ _movedAll = (dx, dy);
+ }
+
+ return;
+ }
+
if (_drag == DragKind.Move)
{
dx = Math.Max(dx, -_before.X0);
dy = Math.Max(dy, -_before.Y0);
(wing.X0, wing.X1, wing.Y0, wing.Y1) = (_before.X0 + dx, _before.X1 + dx, _before.Y0 + dy, _before.Y1 + dy);
Snap(wing, moved: true);
+ WingMoved(_before, wing.X0 - _before.X0, wing.Y0 - _before.Y0, _dragStart?.Extra);
return;
}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs
index 5dafc3bf..c3eb4b0c 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs
@@ -34,6 +34,8 @@ private void InitializeComponent()
_theme = new System.Windows.Forms.ComboBox();
_saveTheme = new System.Windows.Forms.Button();
_deleteTheme = new System.Windows.Forms.Button();
+ _presetLabel = new System.Windows.Forms.Label();
+ _preset = new System.Windows.Forms.ComboBox();
_wingList = new System.Windows.Forms.ListBox();
_wingHint = new System.Windows.Forms.Label();
_storeysLabel = new System.Windows.Forms.Label();
@@ -41,6 +43,7 @@ private void InitializeComponent()
_roomsLabel = new System.Windows.Forms.Label();
_rooms = new System.Windows.Forms.NumericUpDown();
_removeWing = new System.Windows.Forms.Button();
+ _walled = new System.Windows.Forms.CheckBox();
_layoutLabel = new System.Windows.Forms.Label();
_layout = new System.Windows.Forms.ComboBox();
_roomsPerStorey = new System.Windows.Forms.CheckBox();
@@ -50,6 +53,7 @@ private void InitializeComponent()
_gablesLabel = new System.Windows.Forms.Label();
_gables = new System.Windows.Forms.ComboBox();
_gableFill = new System.Windows.Forms.ComboBox();
+ _parapet = new System.Windows.Forms.CheckBox();
_materialsLabel = new System.Windows.Forms.Label();
_storey1 = new System.Windows.Forms.Label();
_wall1 = new System.Windows.Forms.Button();
@@ -108,6 +112,8 @@ private void InitializeComponent()
houseBox.Controls.Add(_theme);
houseBox.Controls.Add(_saveTheme);
houseBox.Controls.Add(_deleteTheme);
+ houseBox.Controls.Add(_presetLabel);
+ houseBox.Controls.Add(_preset);
houseBox.Controls.Add(_wingList);
houseBox.Controls.Add(_wingHint);
houseBox.Controls.Add(_storeysLabel);
@@ -115,6 +121,7 @@ private void InitializeComponent()
houseBox.Controls.Add(_roomsLabel);
houseBox.Controls.Add(_rooms);
houseBox.Controls.Add(_removeWing);
+ houseBox.Controls.Add(_walled);
houseBox.Controls.Add(_layoutLabel);
houseBox.Controls.Add(_layout);
houseBox.Controls.Add(_roomsPerStorey);
@@ -124,6 +131,7 @@ private void InitializeComponent()
houseBox.Controls.Add(_gablesLabel);
houseBox.Controls.Add(_gables);
houseBox.Controls.Add(_gableFill);
+ houseBox.Controls.Add(_parapet);
houseBox.Controls.Add(_materialsLabel);
houseBox.Controls.Add(_storey1);
houseBox.Controls.Add(_wall1);
@@ -171,7 +179,7 @@ private void InitializeComponent()
houseBox.Dock = System.Windows.Forms.DockStyle.Top;
houseBox.Location = new System.Drawing.Point(0, 0);
houseBox.Name = "houseBox";
- houseBox.Size = new System.Drawing.Size(250, 743);
+ houseBox.Size = new System.Drawing.Size(250, 823);
houseBox.TabIndex = 0;
houseBox.TabStop = false;
houseBox.Text = "House draft";
@@ -223,86 +231,120 @@ private void InitializeComponent()
_toolTip.SetToolTip(_deleteTheme, "Deletes the chosen theme, if it is one of your own.");
_deleteTheme.Click += DeleteTheme_Click;
//
+ // _presetLabel
+ //
+ _presetLabel.AutoSize = true;
+ _presetLabel.Location = new System.Drawing.Point(6, 52);
+ _presetLabel.Name = "_presetLabel";
+ _presetLabel.Size = new System.Drawing.Size(50, 15);
+ _presetLabel.TabIndex = 4;
+ _presetLabel.Text = "Start as";
+ //
+ // _preset
+ //
+ _preset.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _preset.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ _preset.FormattingEnabled = true;
+ _preset.Items.AddRange(new object[] { "(draw wings yourself)", "Tower", "Keep", "Castle" });
+ _preset.Location = new System.Drawing.Point(60, 48);
+ _preset.Name = "_preset";
+ _preset.Size = new System.Drawing.Size(184, 23);
+ _preset.TabIndex = 5;
+ _toolTip.SetToolTip(_preset, "Drafts a tower, keep or castle sized to the multi: flat roofs with battlements, corner towers, a front door and windows.");
+ _preset.SelectionChangeCommitted += Preset_SelectionChangeCommitted;
+ //
// _wingList
//
_wingList.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
_wingList.FormattingEnabled = true;
_wingList.IntegralHeight = false;
_wingList.ItemHeight = 15;
- _wingList.Location = new System.Drawing.Point(6, 48);
+ _wingList.Location = new System.Drawing.Point(6, 76);
_wingList.Name = "_wingList";
_wingList.Size = new System.Drawing.Size(238, 64);
- _wingList.TabIndex = 4;
+ _wingList.TabIndex = 6;
_wingList.SelectedIndexChanged += WingList_SelectedIndexChanged;
//
// _wingHint
//
_wingHint.AutoSize = true;
- _wingHint.Location = new System.Drawing.Point(6, 118);
+ _wingHint.Location = new System.Drawing.Point(6, 146);
_wingHint.Name = "_wingHint";
_wingHint.Size = new System.Drawing.Size(120, 15);
- _wingHint.TabIndex = 5;
+ _wingHint.TabIndex = 7;
_wingHint.Text = "New wings:";
//
// _storeysLabel
//
_storeysLabel.AutoSize = true;
- _storeysLabel.Location = new System.Drawing.Point(6, 141);
+ _storeysLabel.Location = new System.Drawing.Point(6, 169);
_storeysLabel.Name = "_storeysLabel";
_storeysLabel.Size = new System.Drawing.Size(50, 15);
- _storeysLabel.TabIndex = 6;
+ _storeysLabel.TabIndex = 8;
_storeysLabel.Text = "Storeys";
//
// _storeys
//
- _storeys.Location = new System.Drawing.Point(60, 138);
+ _storeys.Location = new System.Drawing.Point(60, 166);
_storeys.Maximum = new decimal(new int[] { 4, 0, 0, 0 });
_storeys.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
_storeys.Name = "_storeys";
_storeys.Size = new System.Drawing.Size(44, 23);
- _storeys.TabIndex = 7;
+ _storeys.TabIndex = 9;
_storeys.Value = new decimal(new int[] { 1, 0, 0, 0 });
_storeys.ValueChanged += Storeys_ValueChanged;
//
// _roomsLabel
//
_roomsLabel.AutoSize = true;
- _roomsLabel.Location = new System.Drawing.Point(110, 141);
+ _roomsLabel.Location = new System.Drawing.Point(110, 169);
_roomsLabel.Name = "_roomsLabel";
_roomsLabel.Size = new System.Drawing.Size(44, 15);
- _roomsLabel.TabIndex = 8;
+ _roomsLabel.TabIndex = 10;
_roomsLabel.Text = "Rooms";
//
// _rooms
//
- _rooms.Location = new System.Drawing.Point(156, 138);
+ _rooms.Location = new System.Drawing.Point(156, 166);
_rooms.Maximum = new decimal(new int[] { 6, 0, 0, 0 });
_rooms.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
_rooms.Name = "_rooms";
_rooms.Size = new System.Drawing.Size(44, 23);
- _rooms.TabIndex = 9;
+ _rooms.TabIndex = 11;
_rooms.Value = new decimal(new int[] { 1, 0, 0, 0 });
_rooms.ValueChanged += Rooms_ValueChanged;
//
// _removeWing
//
_removeWing.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right;
- _removeWing.Location = new System.Drawing.Point(206, 137);
+ _removeWing.Location = new System.Drawing.Point(206, 165);
_removeWing.Name = "_removeWing";
_removeWing.Size = new System.Drawing.Size(38, 25);
- _removeWing.TabIndex = 10;
+ _removeWing.TabIndex = 12;
_removeWing.Text = "Del";
_removeWing.AutoEllipsis = true;
_removeWing.UseVisualStyleBackColor = true;
_removeWing.Click += RemoveWing_Click;
//
+ // _walled
+ //
+ _walled.AutoSize = true;
+ _walled.Location = new System.Drawing.Point(60, 197);
+ _walled.Name = "_walled";
+ _walled.Size = new System.Drawing.Size(180, 19);
+ _walled.TabIndex = 13;
+ _walled.Text = "Keeps its walls to other wings";
+ _walled.UseVisualStyleBackColor = true;
+ _toolTip.SetToolTip(_walled, "The wing has walls where it meets other wings, with a doorway in each: a corner tower, a hall in a yard. Without it wings run into each other as one space.");
+ _walled.CheckedChanged += Walled_CheckedChanged;
+ //
// _layoutLabel
//
_layoutLabel.AutoSize = true;
- _layoutLabel.Location = new System.Drawing.Point(6, 171);
+ _layoutLabel.Location = new System.Drawing.Point(6, 225);
_layoutLabel.Name = "_layoutLabel";
_layoutLabel.Size = new System.Drawing.Size(50, 15);
- _layoutLabel.TabIndex = 11;
+ _layoutLabel.TabIndex = 14;
_layoutLabel.Text = "Layout";
//
// _layout
@@ -310,20 +352,20 @@ private void InitializeComponent()
_layout.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
_layout.FormattingEnabled = true;
_layout.Items.AddRange(new object[] { "Row", "Grid", "Corridor", "Hall" });
- _layout.Location = new System.Drawing.Point(60, 168);
+ _layout.Location = new System.Drawing.Point(60, 222);
_layout.Name = "_layout";
_layout.Size = new System.Drawing.Size(100, 23);
- _layout.TabIndex = 12;
+ _layout.TabIndex = 15;
_toolTip.SetToolTip(_layout, "How the rooms of the wing are laid out. Row: side by side. Grid: two rows. Corridor: a hall with rooms on both sides. Hall: one large room and a row of small ones.");
_layout.SelectedIndexChanged += Layout_SelectedIndexChanged;
//
// _roomsPerStorey
//
_roomsPerStorey.AutoSize = true;
- _roomsPerStorey.Location = new System.Drawing.Point(166, 170);
+ _roomsPerStorey.Location = new System.Drawing.Point(166, 224);
_roomsPerStorey.Name = "_roomsPerStorey";
_roomsPerStorey.Size = new System.Drawing.Size(80, 19);
- _roomsPerStorey.TabIndex = 13;
+ _roomsPerStorey.TabIndex = 16;
_roomsPerStorey.Text = "This storey";
_roomsPerStorey.UseVisualStyleBackColor = true;
_toolTip.SetToolTip(_roomsPerStorey, "Rooms and layout apply to the storey of the chosen floor only; other storeys keep theirs.");
@@ -332,10 +374,10 @@ private void InitializeComponent()
// _roofLabel
//
_roofLabel.AutoSize = true;
- _roofLabel.Location = new System.Drawing.Point(6, 201);
+ _roofLabel.Location = new System.Drawing.Point(6, 255);
_roofLabel.Name = "_roofLabel";
_roofLabel.Size = new System.Drawing.Size(50, 15);
- _roofLabel.TabIndex = 14;
+ _roofLabel.TabIndex = 17;
_roofLabel.Text = "Roof";
//
// _roofShape
@@ -343,10 +385,10 @@ private void InitializeComponent()
_roofShape.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
_roofShape.FormattingEnabled = true;
_roofShape.Items.AddRange(new object[] { "Gable", "Hip", "Flat", "None" });
- _roofShape.Location = new System.Drawing.Point(60, 198);
+ _roofShape.Location = new System.Drawing.Point(60, 252);
_roofShape.Name = "_roofShape";
_roofShape.Size = new System.Drawing.Size(80, 23);
- _roofShape.TabIndex = 15;
+ _roofShape.TabIndex = 18;
_roofShape.SelectedIndexChanged += RoofShape_SelectedIndexChanged;
//
// _ridge
@@ -355,19 +397,19 @@ private void InitializeComponent()
_ridge.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
_ridge.FormattingEnabled = true;
_ridge.Items.AddRange(new object[] { "Ridge: auto", "Ridge along X", "Ridge along Y" });
- _ridge.Location = new System.Drawing.Point(146, 198);
+ _ridge.Location = new System.Drawing.Point(146, 252);
_ridge.Name = "_ridge";
_ridge.Size = new System.Drawing.Size(98, 23);
- _ridge.TabIndex = 16;
+ _ridge.TabIndex = 19;
_ridge.SelectedIndexChanged += Ridge_SelectedIndexChanged;
//
// _gablesLabel
//
_gablesLabel.AutoSize = true;
- _gablesLabel.Location = new System.Drawing.Point(6, 231);
+ _gablesLabel.Location = new System.Drawing.Point(6, 285);
_gablesLabel.Name = "_gablesLabel";
_gablesLabel.Size = new System.Drawing.Size(50, 15);
- _gablesLabel.TabIndex = 17;
+ _gablesLabel.TabIndex = 20;
_gablesLabel.Text = "Gables";
//
// _gables
@@ -375,10 +417,10 @@ private void InitializeComponent()
_gables.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
_gables.FormattingEnabled = true;
_gables.Items.AddRange(new object[] { "Front", "Both", "None" });
- _gables.Location = new System.Drawing.Point(60, 228);
+ _gables.Location = new System.Drawing.Point(60, 282);
_gables.Name = "_gables";
_gables.Size = new System.Drawing.Size(80, 23);
- _gables.TabIndex = 18;
+ _gables.TabIndex = 21;
_toolTip.SetToolTip(_gables, "Which gable ends of the roofs are closed.");
_gables.SelectedIndexChanged += Gables_SelectedIndexChanged;
//
@@ -388,36 +430,48 @@ private void InitializeComponent()
_gableFill.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
_gableFill.FormattingEnabled = true;
_gableFill.Items.AddRange(new object[] { "Fill: caps", "Fill: walls" });
- _gableFill.Location = new System.Drawing.Point(146, 228);
+ _gableFill.Location = new System.Drawing.Point(146, 282);
_gableFill.Name = "_gableFill";
_gableFill.Size = new System.Drawing.Size(98, 23);
- _gableFill.TabIndex = 19;
+ _gableFill.TabIndex = 22;
_toolTip.SetToolTip(_gableFill, "Caps: 3 high cap pieces. Walls: whole wall pieces as far as they fit under the slope.");
_gableFill.SelectedIndexChanged += Gables_SelectedIndexChanged;
//
+ // _parapet
+ //
+ _parapet.AutoSize = true;
+ _parapet.Location = new System.Drawing.Point(60, 313);
+ _parapet.Name = "_parapet";
+ _parapet.Size = new System.Drawing.Size(180, 19);
+ _parapet.TabIndex = 23;
+ _parapet.Text = "Battlements on flat roofs";
+ _parapet.UseVisualStyleBackColor = true;
+ _toolTip.SetToolTip(_parapet, "Walls the flat roofs with the roof edging of their walls, as the towers, keeps and castles of the client have it.");
+ _parapet.CheckedChanged += Parapet_CheckedChanged;
+ //
// _materialsLabel
//
- _materialsLabel.Location = new System.Drawing.Point(6, 260);
+ _materialsLabel.Location = new System.Drawing.Point(6, 340);
_materialsLabel.Name = "_materialsLabel";
_materialsLabel.Size = new System.Drawing.Size(238, 15);
- _materialsLabel.TabIndex = 20;
+ _materialsLabel.TabIndex = 24;
_materialsLabel.Text = "Storey: walls and floor style";
//
// _storey1
//
- _storey1.Location = new System.Drawing.Point(6, 282);
+ _storey1.Location = new System.Drawing.Point(6, 362);
_storey1.Name = "_storey1";
_storey1.Size = new System.Drawing.Size(18, 17);
- _storey1.TabIndex = 21;
+ _storey1.TabIndex = 25;
_storey1.Text = "1";
_storey1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// _wall1
//
- _wall1.Location = new System.Drawing.Point(28, 278);
+ _wall1.Location = new System.Drawing.Point(28, 358);
_wall1.Name = "_wall1";
_wall1.Size = new System.Drawing.Size(106, 25);
- _wall1.TabIndex = 22;
+ _wall1.TabIndex = 26;
_wall1.Text = "(walls)";
_wall1.AutoEllipsis = true;
_wall1.UseVisualStyleBackColor = true;
@@ -425,29 +479,29 @@ private void InitializeComponent()
// _floor1
//
_floor1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _floor1.Location = new System.Drawing.Point(138, 278);
+ _floor1.Location = new System.Drawing.Point(138, 358);
_floor1.Name = "_floor1";
_floor1.Size = new System.Drawing.Size(106, 25);
- _floor1.TabIndex = 23;
+ _floor1.TabIndex = 27;
_floor1.Text = "(floor)";
_floor1.AutoEllipsis = true;
_floor1.UseVisualStyleBackColor = true;
//
// _storey2
//
- _storey2.Location = new System.Drawing.Point(6, 309);
+ _storey2.Location = new System.Drawing.Point(6, 389);
_storey2.Name = "_storey2";
_storey2.Size = new System.Drawing.Size(18, 17);
- _storey2.TabIndex = 24;
+ _storey2.TabIndex = 28;
_storey2.Text = "2";
_storey2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// _wall2
//
- _wall2.Location = new System.Drawing.Point(28, 305);
+ _wall2.Location = new System.Drawing.Point(28, 385);
_wall2.Name = "_wall2";
_wall2.Size = new System.Drawing.Size(106, 25);
- _wall2.TabIndex = 25;
+ _wall2.TabIndex = 29;
_wall2.Text = "(walls)";
_wall2.AutoEllipsis = true;
_wall2.UseVisualStyleBackColor = true;
@@ -455,29 +509,29 @@ private void InitializeComponent()
// _floor2
//
_floor2.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _floor2.Location = new System.Drawing.Point(138, 305);
+ _floor2.Location = new System.Drawing.Point(138, 385);
_floor2.Name = "_floor2";
_floor2.Size = new System.Drawing.Size(106, 25);
- _floor2.TabIndex = 26;
+ _floor2.TabIndex = 30;
_floor2.Text = "(floor)";
_floor2.AutoEllipsis = true;
_floor2.UseVisualStyleBackColor = true;
//
// _storey3
//
- _storey3.Location = new System.Drawing.Point(6, 336);
+ _storey3.Location = new System.Drawing.Point(6, 416);
_storey3.Name = "_storey3";
_storey3.Size = new System.Drawing.Size(18, 17);
- _storey3.TabIndex = 27;
+ _storey3.TabIndex = 31;
_storey3.Text = "3";
_storey3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// _wall3
//
- _wall3.Location = new System.Drawing.Point(28, 332);
+ _wall3.Location = new System.Drawing.Point(28, 412);
_wall3.Name = "_wall3";
_wall3.Size = new System.Drawing.Size(106, 25);
- _wall3.TabIndex = 28;
+ _wall3.TabIndex = 32;
_wall3.Text = "(walls)";
_wall3.AutoEllipsis = true;
_wall3.UseVisualStyleBackColor = true;
@@ -485,29 +539,29 @@ private void InitializeComponent()
// _floor3
//
_floor3.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _floor3.Location = new System.Drawing.Point(138, 332);
+ _floor3.Location = new System.Drawing.Point(138, 412);
_floor3.Name = "_floor3";
_floor3.Size = new System.Drawing.Size(106, 25);
- _floor3.TabIndex = 29;
+ _floor3.TabIndex = 33;
_floor3.Text = "(floor)";
_floor3.AutoEllipsis = true;
_floor3.UseVisualStyleBackColor = true;
//
// _storey4
//
- _storey4.Location = new System.Drawing.Point(6, 363);
+ _storey4.Location = new System.Drawing.Point(6, 443);
_storey4.Name = "_storey4";
_storey4.Size = new System.Drawing.Size(18, 17);
- _storey4.TabIndex = 30;
+ _storey4.TabIndex = 34;
_storey4.Text = "4";
_storey4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// _wall4
//
- _wall4.Location = new System.Drawing.Point(28, 359);
+ _wall4.Location = new System.Drawing.Point(28, 439);
_wall4.Name = "_wall4";
_wall4.Size = new System.Drawing.Size(106, 25);
- _wall4.TabIndex = 31;
+ _wall4.TabIndex = 35;
_wall4.Text = "(walls)";
_wall4.AutoEllipsis = true;
_wall4.UseVisualStyleBackColor = true;
@@ -515,10 +569,10 @@ private void InitializeComponent()
// _floor4
//
_floor4.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _floor4.Location = new System.Drawing.Point(138, 359);
+ _floor4.Location = new System.Drawing.Point(138, 439);
_floor4.Name = "_floor4";
_floor4.Size = new System.Drawing.Size(106, 25);
- _floor4.TabIndex = 32;
+ _floor4.TabIndex = 36;
_floor4.Text = "(floor)";
_floor4.AutoEllipsis = true;
_floor4.UseVisualStyleBackColor = true;
@@ -526,19 +580,19 @@ private void InitializeComponent()
// _roofStyleLabel
//
_roofStyleLabel.AutoSize = true;
- _roofStyleLabel.Location = new System.Drawing.Point(6, 391);
+ _roofStyleLabel.Location = new System.Drawing.Point(6, 471);
_roofStyleLabel.Name = "_roofStyleLabel";
_roofStyleLabel.Size = new System.Drawing.Size(50, 15);
- _roofStyleLabel.TabIndex = 33;
+ _roofStyleLabel.TabIndex = 37;
_roofStyleLabel.Text = "Roof";
//
// _roofStyle
//
_roofStyle.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _roofStyle.Location = new System.Drawing.Point(60, 386);
+ _roofStyle.Location = new System.Drawing.Point(60, 466);
_roofStyle.Name = "_roofStyle";
_roofStyle.Size = new System.Drawing.Size(184, 25);
- _roofStyle.TabIndex = 34;
+ _roofStyle.TabIndex = 38;
_roofStyle.Text = "(roof)";
_roofStyle.AutoEllipsis = true;
_roofStyle.UseVisualStyleBackColor = true;
@@ -546,19 +600,19 @@ private void InitializeComponent()
// _doorStyleLabel
//
_doorStyleLabel.AutoSize = true;
- _doorStyleLabel.Location = new System.Drawing.Point(6, 418);
+ _doorStyleLabel.Location = new System.Drawing.Point(6, 498);
_doorStyleLabel.Name = "_doorStyleLabel";
_doorStyleLabel.Size = new System.Drawing.Size(50, 15);
- _doorStyleLabel.TabIndex = 35;
+ _doorStyleLabel.TabIndex = 39;
_doorStyleLabel.Text = "Doors";
//
// _doorStyle
//
_doorStyle.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _doorStyle.Location = new System.Drawing.Point(60, 413);
+ _doorStyle.Location = new System.Drawing.Point(60, 493);
_doorStyle.Name = "_doorStyle";
_doorStyle.Size = new System.Drawing.Size(184, 25);
- _doorStyle.TabIndex = 36;
+ _doorStyle.TabIndex = 40;
_doorStyle.Text = "(doors)";
_doorStyle.AutoEllipsis = true;
_doorStyle.UseVisualStyleBackColor = true;
@@ -566,19 +620,19 @@ private void InitializeComponent()
// _stairStyleLabel
//
_stairStyleLabel.AutoSize = true;
- _stairStyleLabel.Location = new System.Drawing.Point(6, 445);
+ _stairStyleLabel.Location = new System.Drawing.Point(6, 525);
_stairStyleLabel.Name = "_stairStyleLabel";
_stairStyleLabel.Size = new System.Drawing.Size(50, 15);
- _stairStyleLabel.TabIndex = 37;
+ _stairStyleLabel.TabIndex = 41;
_stairStyleLabel.Text = "Stairs";
//
// _stairStyle
//
_stairStyle.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _stairStyle.Location = new System.Drawing.Point(60, 440);
+ _stairStyle.Location = new System.Drawing.Point(60, 520);
_stairStyle.Name = "_stairStyle";
_stairStyle.Size = new System.Drawing.Size(184, 25);
- _stairStyle.TabIndex = 38;
+ _stairStyle.TabIndex = 42;
_stairStyle.Text = "(stairs)";
_stairStyle.AutoEllipsis = true;
_stairStyle.UseVisualStyleBackColor = true;
@@ -586,10 +640,10 @@ private void InitializeComponent()
// _foundation
//
_foundation.AutoSize = true;
- _foundation.Location = new System.Drawing.Point(6, 471);
+ _foundation.Location = new System.Drawing.Point(6, 551);
_foundation.Name = "_foundation";
_foundation.Size = new System.Drawing.Size(86, 19);
- _foundation.TabIndex = 39;
+ _foundation.TabIndex = 43;
_foundation.Text = "Foundation";
_foundation.UseVisualStyleBackColor = true;
_foundation.CheckedChanged += Foundation_CheckedChanged;
@@ -597,10 +651,10 @@ private void InitializeComponent()
// _foundationStyle
//
_foundationStyle.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _foundationStyle.Location = new System.Drawing.Point(96, 467);
+ _foundationStyle.Location = new System.Drawing.Point(96, 547);
_foundationStyle.Name = "_foundationStyle";
_foundationStyle.Size = new System.Drawing.Size(148, 25);
- _foundationStyle.TabIndex = 40;
+ _foundationStyle.TabIndex = 44;
_foundationStyle.Text = "(foundation)";
_foundationStyle.AutoEllipsis = true;
_foundationStyle.UseVisualStyleBackColor = true;
@@ -608,29 +662,29 @@ private void InitializeComponent()
// _baseZLabel
//
_baseZLabel.AutoSize = true;
- _baseZLabel.Location = new System.Drawing.Point(6, 499);
+ _baseZLabel.Location = new System.Drawing.Point(6, 579);
_baseZLabel.Name = "_baseZLabel";
_baseZLabel.Size = new System.Drawing.Size(44, 15);
- _baseZLabel.TabIndex = 41;
+ _baseZLabel.TabIndex = 45;
_baseZLabel.Text = "Base Z";
//
// _baseZ
//
- _baseZ.Location = new System.Drawing.Point(60, 496);
+ _baseZ.Location = new System.Drawing.Point(60, 576);
_baseZ.Maximum = new decimal(new int[] { 100, 0, 0, 0 });
_baseZ.Minimum = new decimal(new int[] { 100, 0, 0, int.MinValue });
_baseZ.Name = "_baseZ";
_baseZ.Size = new System.Drawing.Size(56, 23);
- _baseZ.TabIndex = 42;
+ _baseZ.TabIndex = 46;
_baseZ.ValueChanged += BaseZ_ValueChanged;
//
// _autoDoors
//
_autoDoors.AutoSize = true;
- _autoDoors.Location = new System.Drawing.Point(6, 529);
+ _autoDoors.Location = new System.Drawing.Point(6, 609);
_autoDoors.Name = "_autoDoors";
_autoDoors.Size = new System.Drawing.Size(96, 19);
- _autoDoors.TabIndex = 43;
+ _autoDoors.TabIndex = 47;
_autoDoors.Text = "Room doors";
_autoDoors.UseVisualStyleBackColor = true;
_toolTip.SetToolTip(_autoDoors, "Puts a door of the house's door style in every doorway between rooms.");
@@ -639,10 +693,10 @@ private void InitializeComponent()
// _frontDoorLabel
//
_frontDoorLabel.AutoSize = true;
- _frontDoorLabel.Location = new System.Drawing.Point(110, 530);
+ _frontDoorLabel.Location = new System.Drawing.Point(110, 610);
_frontDoorLabel.Name = "_frontDoorLabel";
_frontDoorLabel.Size = new System.Drawing.Size(62, 15);
- _frontDoorLabel.TabIndex = 44;
+ _frontDoorLabel.TabIndex = 48;
_frontDoorLabel.Text = "Front door";
//
// _frontDoor
@@ -651,49 +705,49 @@ private void InitializeComponent()
_frontDoor.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
_frontDoor.FormattingEnabled = true;
_frontDoor.Items.AddRange(new object[] { "None", "South", "East" });
- _frontDoor.Location = new System.Drawing.Point(176, 526);
+ _frontDoor.Location = new System.Drawing.Point(176, 606);
_frontDoor.Name = "_frontDoor";
_frontDoor.Size = new System.Drawing.Size(68, 23);
- _frontDoor.TabIndex = 45;
+ _frontDoor.TabIndex = 49;
_toolTip.SetToolTip(_frontDoor, "The outer wall of the first wing that gets the front door.");
_frontDoor.SelectedIndexChanged += FrontDoor_SelectedIndexChanged;
//
// _windowsLabel
//
_windowsLabel.AutoSize = true;
- _windowsLabel.Location = new System.Drawing.Point(6, 557);
+ _windowsLabel.Location = new System.Drawing.Point(6, 637);
_windowsLabel.Name = "_windowsLabel";
_windowsLabel.Size = new System.Drawing.Size(90, 15);
- _windowsLabel.TabIndex = 46;
+ _windowsLabel.TabIndex = 50;
_windowsLabel.Text = "Windows every";
//
// _windowSpacing
//
- _windowSpacing.Location = new System.Drawing.Point(100, 554);
+ _windowSpacing.Location = new System.Drawing.Point(100, 634);
_windowSpacing.Maximum = new decimal(new int[] { 12, 0, 0, 0 });
_windowSpacing.Minimum = new decimal(new int[] { 0, 0, 0, 0 });
_windowSpacing.Name = "_windowSpacing";
_windowSpacing.Size = new System.Drawing.Size(44, 23);
- _windowSpacing.TabIndex = 47;
+ _windowSpacing.TabIndex = 51;
_toolTip.SetToolTip(_windowSpacing, "Puts windows along the outer walls, this many cells apart. 0: none.");
_windowSpacing.ValueChanged += WindowSpacing_ValueChanged;
//
// _windowsHint
//
_windowsHint.AutoSize = true;
- _windowsHint.Location = new System.Drawing.Point(150, 557);
+ _windowsHint.Location = new System.Drawing.Point(150, 637);
_windowsHint.Name = "_windowsHint";
_windowsHint.Size = new System.Drawing.Size(90, 15);
- _windowsHint.TabIndex = 48;
+ _windowsHint.TabIndex = 52;
_windowsHint.Text = "cells (0: none)";
//
// _showLabel
//
_showLabel.AutoSize = true;
- _showLabel.Location = new System.Drawing.Point(6, 586);
+ _showLabel.Location = new System.Drawing.Point(6, 666);
_showLabel.Name = "_showLabel";
_showLabel.Size = new System.Drawing.Size(50, 15);
- _showLabel.TabIndex = 49;
+ _showLabel.TabIndex = 53;
_showLabel.Text = "Preview";
//
// _showWalls
@@ -701,10 +755,10 @@ private void InitializeComponent()
_showWalls.AutoSize = true;
_showWalls.Checked = true;
_showWalls.CheckState = System.Windows.Forms.CheckState.Checked;
- _showWalls.Location = new System.Drawing.Point(60, 584);
+ _showWalls.Location = new System.Drawing.Point(60, 664);
_showWalls.Name = "_showWalls";
_showWalls.Size = new System.Drawing.Size(56, 19);
- _showWalls.TabIndex = 50;
+ _showWalls.TabIndex = 54;
_showWalls.Text = "Walls";
_showWalls.UseVisualStyleBackColor = true;
_showWalls.CheckedChanged += Show_CheckedChanged;
@@ -714,10 +768,10 @@ private void InitializeComponent()
_showFloors.AutoSize = true;
_showFloors.Checked = true;
_showFloors.CheckState = System.Windows.Forms.CheckState.Checked;
- _showFloors.Location = new System.Drawing.Point(122, 584);
+ _showFloors.Location = new System.Drawing.Point(122, 664);
_showFloors.Name = "_showFloors";
_showFloors.Size = new System.Drawing.Size(60, 19);
- _showFloors.TabIndex = 51;
+ _showFloors.TabIndex = 55;
_showFloors.Text = "Floors";
_showFloors.UseVisualStyleBackColor = true;
_showFloors.CheckedChanged += Show_CheckedChanged;
@@ -727,20 +781,20 @@ private void InitializeComponent()
_showRoof.AutoSize = true;
_showRoof.Checked = true;
_showRoof.CheckState = System.Windows.Forms.CheckState.Checked;
- _showRoof.Location = new System.Drawing.Point(188, 584);
+ _showRoof.Location = new System.Drawing.Point(188, 664);
_showRoof.Name = "_showRoof";
_showRoof.Size = new System.Drawing.Size(52, 19);
- _showRoof.TabIndex = 52;
+ _showRoof.TabIndex = 56;
_showRoof.Text = "Roof";
_showRoof.UseVisualStyleBackColor = true;
_showRoof.CheckedChanged += Show_CheckedChanged;
//
// _undo
//
- _undo.Location = new System.Drawing.Point(6, 612);
+ _undo.Location = new System.Drawing.Point(6, 692);
_undo.Name = "_undo";
_undo.Size = new System.Drawing.Size(54, 25);
- _undo.TabIndex = 53;
+ _undo.TabIndex = 57;
_undo.Text = "Undo";
_undo.AutoEllipsis = true;
_undo.UseVisualStyleBackColor = true;
@@ -748,10 +802,10 @@ private void InitializeComponent()
//
// _redo
//
- _redo.Location = new System.Drawing.Point(62, 612);
+ _redo.Location = new System.Drawing.Point(62, 692);
_redo.Name = "_redo";
_redo.Size = new System.Drawing.Size(54, 25);
- _redo.TabIndex = 54;
+ _redo.TabIndex = 58;
_redo.Text = "Redo";
_redo.AutoEllipsis = true;
_redo.UseVisualStyleBackColor = true;
@@ -759,10 +813,10 @@ private void InitializeComponent()
//
// _place
//
- _place.Location = new System.Drawing.Point(122, 612);
+ _place.Location = new System.Drawing.Point(122, 692);
_place.Name = "_place";
_place.Size = new System.Drawing.Size(72, 25);
- _place.TabIndex = 55;
+ _place.TabIndex = 59;
_place.Text = "Place";
_place.AutoEllipsis = true;
_place.UseVisualStyleBackColor = true;
@@ -771,10 +825,10 @@ private void InitializeComponent()
// _drop
//
_drop.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _drop.Location = new System.Drawing.Point(196, 612);
+ _drop.Location = new System.Drawing.Point(196, 692);
_drop.Name = "_drop";
_drop.Size = new System.Drawing.Size(48, 25);
- _drop.TabIndex = 56;
+ _drop.TabIndex = 60;
_drop.Text = "Drop";
_drop.AutoEllipsis = true;
_drop.UseVisualStyleBackColor = true;
@@ -782,10 +836,10 @@ private void InitializeComponent()
//
// _saveDraft
//
- _saveDraft.Location = new System.Drawing.Point(6, 641);
+ _saveDraft.Location = new System.Drawing.Point(6, 721);
_saveDraft.Name = "_saveDraft";
_saveDraft.Size = new System.Drawing.Size(76, 25);
- _saveDraft.TabIndex = 57;
+ _saveDraft.TabIndex = 61;
_saveDraft.Text = "Save draft";
_saveDraft.AutoEllipsis = true;
_saveDraft.UseVisualStyleBackColor = true;
@@ -793,10 +847,10 @@ private void InitializeComponent()
//
// _openDraft
//
- _openDraft.Location = new System.Drawing.Point(84, 641);
+ _openDraft.Location = new System.Drawing.Point(84, 721);
_openDraft.Name = "_openDraft";
_openDraft.Size = new System.Drawing.Size(76, 25);
- _openDraft.TabIndex = 58;
+ _openDraft.TabIndex = 62;
_openDraft.Text = "Open draft";
_openDraft.AutoEllipsis = true;
_openDraft.UseVisualStyleBackColor = true;
@@ -805,10 +859,10 @@ private void InitializeComponent()
// _blueprint
//
_blueprint.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _blueprint.Location = new System.Drawing.Point(162, 641);
+ _blueprint.Location = new System.Drawing.Point(162, 721);
_blueprint.Name = "_blueprint";
_blueprint.Size = new System.Drawing.Size(82, 25);
- _blueprint.TabIndex = 59;
+ _blueprint.TabIndex = 63;
_blueprint.Text = "As blueprint";
_blueprint.AutoEllipsis = true;
_blueprint.UseVisualStyleBackColor = true;
@@ -817,10 +871,10 @@ private void InitializeComponent()
// _placedLabel
//
_placedLabel.AutoSize = true;
- _placedLabel.Location = new System.Drawing.Point(6, 675);
+ _placedLabel.Location = new System.Drawing.Point(6, 755);
_placedLabel.Name = "_placedLabel";
_placedLabel.Size = new System.Drawing.Size(60, 15);
- _placedLabel.TabIndex = 60;
+ _placedLabel.TabIndex = 64;
_placedLabel.Text = "Placed";
//
// _placed
@@ -828,18 +882,18 @@ private void InitializeComponent()
_placed.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
_placed.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
_placed.FormattingEnabled = true;
- _placed.Location = new System.Drawing.Point(60, 672);
+ _placed.Location = new System.Drawing.Point(60, 752);
_placed.Name = "_placed";
_placed.Size = new System.Drawing.Size(130, 23);
- _placed.TabIndex = 61;
+ _placed.TabIndex = 65;
//
// _edit
//
_edit.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right;
- _edit.Location = new System.Drawing.Point(196, 671);
+ _edit.Location = new System.Drawing.Point(196, 751);
_edit.Name = "_edit";
_edit.Size = new System.Drawing.Size(48, 25);
- _edit.TabIndex = 62;
+ _edit.TabIndex = 66;
_edit.Text = "Edit";
_edit.AutoEllipsis = true;
_edit.UseVisualStyleBackColor = true;
@@ -848,10 +902,10 @@ private void InitializeComponent()
// _status
//
_status.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _status.Location = new System.Drawing.Point(6, 701);
+ _status.Location = new System.Drawing.Point(6, 781);
_status.Name = "_status";
_status.Size = new System.Drawing.Size(238, 32);
- _status.TabIndex = 63;
+ _status.TabIndex = 67;
//
// HousePanel
//
@@ -860,7 +914,7 @@ private void InitializeComponent()
AutoScroll = true;
Controls.Add(houseBox);
Name = "HousePanel";
- Size = new System.Drawing.Size(250, 743);
+ Size = new System.Drawing.Size(250, 823);
houseBox.ResumeLayout(false);
houseBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)_storeys).EndInit();
@@ -877,6 +931,8 @@ private void InitializeComponent()
private System.Windows.Forms.ComboBox _theme;
private System.Windows.Forms.Button _saveTheme;
private System.Windows.Forms.Button _deleteTheme;
+ private System.Windows.Forms.Label _presetLabel;
+ private System.Windows.Forms.ComboBox _preset;
private System.Windows.Forms.ListBox _wingList;
private System.Windows.Forms.Label _wingHint;
private System.Windows.Forms.Label _storeysLabel;
@@ -884,6 +940,7 @@ private void InitializeComponent()
private System.Windows.Forms.Label _roomsLabel;
private System.Windows.Forms.NumericUpDown _rooms;
private System.Windows.Forms.Button _removeWing;
+ private System.Windows.Forms.CheckBox _walled;
private System.Windows.Forms.Label _layoutLabel;
private System.Windows.Forms.ComboBox _layout;
private System.Windows.Forms.CheckBox _roomsPerStorey;
@@ -893,6 +950,7 @@ private void InitializeComponent()
private System.Windows.Forms.Label _gablesLabel;
private System.Windows.Forms.ComboBox _gables;
private System.Windows.Forms.ComboBox _gableFill;
+ private System.Windows.Forms.CheckBox _parapet;
private System.Windows.Forms.Label _materialsLabel;
private System.Windows.Forms.Label _storey1;
private System.Windows.Forms.Button _wall1;
diff --git a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
index 1ee571c7..30a9db17 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
@@ -79,6 +79,9 @@ public HousePanel()
public event Action DeleteTheme;
+ /// Raised when a draft was started from the panel: the House tool is the one to shape it with.
+ public event Action HouseToolWanted;
+
/// Something to tell the user in the status bar.
public event Action Message;
@@ -163,6 +166,8 @@ public void RefreshDraft()
_gableFill.SelectedIndex = (int)house.Draft.GableFill;
_storeys.Value = Math.Clamp(house.Storeys, 1, HouseDraft.MaxStoreys);
+ _walled.Checked = house.Walled;
+ _preset.SelectedIndex = 0;
// The drop-down lists the roof shapes in their order, then None.
_roofShape.SelectedIndex = house.NoRoof ? _roofShape.Items.Count - 1 : (int)house.Shape;
_ridge.SelectedIndex = (int)house.Ridge;
@@ -204,6 +209,7 @@ public void RefreshDraft()
_roomsPerStorey.Checked = house.HasOwnRooms(roomStorey);
_roomsPerStorey.Text = roomStorey >= 1 ? $"Storey {roomStorey + 1} only" : "This storey";
_autoDoors.Checked = house.Draft.AutoDoors;
+ _parapet.Checked = house.Draft.Parapet;
_frontDoor.SelectedIndex = (int)house.Draft.FrontDoor;
_windowSpacing.Value = Math.Clamp(house.Draft.WindowSpacing, 0, (int)_windowSpacing.Maximum);
_showWalls.Checked = house.ShowWalls;
@@ -404,6 +410,49 @@ private void RoomsPerStorey_CheckedChanged(object sender, EventArgs e)
Run(house => house.SetOwnRooms(RoomStorey, _roomsPerStorey.Checked));
}
+ private void Walled_CheckedChanged(object sender, EventArgs e)
+ {
+ Run(house => house.SetWalled(_walled.Checked));
+ }
+
+ private void Preset_SelectionChangeCommitted(object sender, EventArgs e)
+ {
+ if (_updating || _session == null || _preset.SelectedIndex <= 0)
+ {
+ return;
+ }
+
+ string preset = (string)_preset.SelectedItem;
+ HouseTool house = _session.House;
+ if (house.HasPending && MessageBox.Show(this, $"Replace the draft with a {preset.ToLowerInvariant()}? Undo brings it back.", "House draft",
+ MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
+ {
+ _preset.SelectedIndex = 0;
+ return;
+ }
+
+ // In the stone theme when the client has it: these are stone buildings.
+ string problem = house.LoadPreset(preset);
+ if (problem == null && house.Themes.FirstOrDefault(theme => theme.Name == "Weathered Stone Keep") is { } stone)
+ {
+ house.ApplyTheme(stone);
+ }
+
+ if (problem == null)
+ {
+ HouseToolWanted?.Invoke();
+ }
+
+ Message?.Invoke(problem ?? $"{preset} drafted. Drag a wing to move it, its edge to resize it, Ctrl+drag to move all of it. Place puts it in the multi.");
+ _preset.SelectedIndex = 0;
+ Used?.Invoke();
+ }
+
+ private void Parapet_CheckedChanged(object sender, EventArgs e)
+ {
+ Run(house => house.SetParapet(_parapet.Checked));
+ }
+
private void AutoDoors_CheckedChanged(object sender, EventArgs e)
{
Run(house => house.SetAutoDoors(_autoDoors.Checked));
diff --git a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
index 8f9ebd83..6aa193e9 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
@@ -67,6 +67,7 @@ public MultiEditorControl()
_housePanel.SaveTheme += SaveHouseTheme;
_housePanel.DeleteTheme += DeleteHouseTheme;
_housePanel.Message += Tell;
+ _housePanel.HouseToolWanted += () => SetTool(ToolKind.House);
_housePanel.SaveDraft += SaveHouseDraft;
_housePanel.OpenDraft += OpenHouseDraft;
_housePanel.SaveBlueprint += SaveHouseBlueprint;
@@ -285,6 +286,7 @@ private void EnsureBuilt()
_browser.SetHouseStyles(_houseStyles);
_browser.EditStylesRequested += EditHouseStyles;
+ _styleErrors = _houseStyles.Errors.Count == 0 ? null : string.Join("\r\n", _houseStyles.Errors.Take(5));
_browser.TileChosen += id =>
{
Session?.SetDrawTile(id);
@@ -656,6 +658,11 @@ private void SetTool(ToolKind kind, bool fromHousePage = false)
Session.Tool = kind;
+ if (IsHouseTool(kind) || kind == ToolKind.House)
+ {
+ TellStyleErrors();
+ }
+
// A tool chosen in place of the style a pick was waiting for: the pick is off.
if (!fromHousePage && !_openingHousePage)
{
@@ -838,6 +845,8 @@ private void EditHouseStyles(HouseStyle start)
}
_browser.SetHouseStyles(_houseStyles);
+ _styleErrors = _houseStyles.Errors.Count == 0 ? null : string.Join("\r\n", _houseStyles.Errors.Take(5));
+ TellStyleErrors();
foreach (EditorDocument document in _documents)
{
document.Session.HouseStyle = _houseStyles.Successor(document.Session.HouseStyle);
@@ -849,6 +858,23 @@ private void EditHouseStyles(HouseStyle start)
Tell("House styles saved.");
}
+ // What went wrong reading the house tables or a style file; told once, when the House page is first used.
+ private string _styleErrors;
+
+ private void TellStyleErrors()
+ {
+ if (_styleErrors == null)
+ {
+ return;
+ }
+
+ string errors = _styleErrors;
+ _styleErrors = null;
+ MessageBox.Show(this, "Some house style data could not be read and was left out:\r\n\r\n" + errors +
+ "\r\n\r\nYour own style file is " + (HouseStyleConfig.UserPath ?? "not set") + ".",
+ "Multi Editor", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ }
+
/// Saves the styles of the house draft as a theme in the user's copy of the style file.
private void SaveHouseTheme()
{
@@ -1559,7 +1585,7 @@ private void BuildMainStrip()
Menu(_fileMenu, _new, _open, _openDesign, _import, _importFolder, null, _saveDesign, _saveDesignAs, _saveClient, _export, _saveBlueprint, _savePattern, null, _resize, _settingsCommand, null, _close, _closeAll);
_undoHistory = new ToolStripMenuItem("Undo back to");
- _editMenu.DropDownOpening += (_, _) => FillUndoHistory();
+ _editMenu.DropDownOpening += (_, _) => FillUndoHistory(_undoHistory);
Menu(_editMenu, _undo, _redo);
_editMenu.DropDownItems.Add(_undoHistory);
Menu(_editMenu, null, _cut, _copy, _paste, _duplicate, _repeat, _delete, null,
@@ -1585,6 +1611,15 @@ private void BuildMainStrip()
InsertButtons(strip, _mainSeparator1, _new, _open, _saveClient);
InsertButtons(strip, _mainSeparator2, _undo, _redo);
+
+ // The steps Undo would take back, by name, beside the Undo and Redo buttons.
+ _undoDrop = new ToolStripDropDownButton("History")
+ {
+ DisplayStyle = ToolStripItemDisplayStyle.Text,
+ ToolTipText = "Undo back to a step of the history"
+ };
+ _undoDrop.DropDownOpening += (_, _) => FillUndoHistory(_undoDrop);
+ strip.Items.Insert(strip.Items.IndexOf(_mainSeparator2), _undoDrop);
InsertButtons(strip, _mainSeparator3, _cut, _copy, _paste, _delete);
InsertButtons(strip, _mainSeparator4, _workPlane, _grid, _hideWalls);
@@ -1626,13 +1661,22 @@ private ToolStripDropDownButton Menu(ToolStripDropDownButton menu, params Editor
}
private ToolStripMenuItem _undoHistory;
+ private ToolStripDropDownButton _undoDrop;
/// Lists the last steps of the history by name; choosing one takes it and every later step back.
- private void FillUndoHistory()
+ private void FillUndoHistory(ToolStripDropDownItem menu)
{
- _undoHistory.DropDownItems.Clear();
+ menu.DropDownItems.Clear();
IReadOnlyList steps = Session?.UndoSteps(25) ?? Array.Empty();
- _undoHistory.Enabled = steps.Count > 0;
+ if (menu is ToolStripMenuItem)
+ {
+ menu.Enabled = steps.Count > 0;
+ }
+ else if (steps.Count == 0)
+ {
+ menu.DropDownItems.Add(new ToolStripMenuItem("Nothing to undo") { Enabled = false });
+ }
+
for (int i = 0; i < steps.Count; ++i)
{
int count = i + 1;
@@ -1646,7 +1690,7 @@ private void FillUndoHistory()
_commands.RefreshStates();
Tell(count == 1 ? "1 step undone." : $"{count} steps undone.");
};
- _undoHistory.DropDownItems.Add(item);
+ menu.DropDownItems.Add(item);
}
}
@@ -2770,7 +2814,7 @@ private void UpdateStatus()
: session.PreviewingRepeat ? "The copies are shown as they would be placed."
: session.Pasting ? "Click to place the tiles, as often as you like. Esc or right click stops."
: session.ShapingRoof ? "Shaping: drag a wing to move it, a marked edge of the selected wing to resize it, anywhere else to add a wing. " +
- "Shift+click turns a ridge, Delete removes a wing, Ctrl+Z steps back. Enter places it, Esc drops it."
+ "Ctrl+drag moves all of it, Shift+click turns a ridge, Delete removes a wing, Ctrl+Z steps back. Enter places it, Esc drops it."
: session.House.HasPending ? DraftHint(session)
: ToolHint(session.Tool);
diff --git a/UoFiddler.Plugin.MultiEditor/UI/TileBrowserPanel.cs b/UoFiddler.Plugin.MultiEditor/UI/TileBrowserPanel.cs
index 37133943..1bc366d4 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/TileBrowserPanel.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/TileBrowserPanel.cs
@@ -1270,6 +1270,14 @@ private void BuildHousePage()
_houseKindBar.Items.Insert(_houseKindBar.Items.IndexOf(_patternsButton), button);
}
+ _familyButton = new ToolStripDropDownButton("Family")
+ {
+ Alignment = ToolStripItemAlignment.Right,
+ ToolTipText = "Shows only the styles of one material. A kind without styles of it shows all of its own."
+ };
+ _familyButton.DropDownOpening += (_, _) => FillFamilies();
+ _houseKindBar.Items.Add(_familyButton);
+
var edit = new ToolStripButton("Edit...")
{
Alignment = ToolStripItemAlignment.Right,
@@ -1385,6 +1393,44 @@ private bool HouseStyleMatches(HouseStyle style)
(query.IsIdQuery ? style.Slots.Values.Any(id => query.MatchesId(id)) : query.MatchesText(style.Group + " " + style.Name + " " + style.Family));
}
+ // The family the House page is narrowed to, or null for all, and its button.
+ private string _houseFamily;
+ private ToolStripDropDownButton _familyButton;
+
+ /// True for a style of the chosen family. A kind that has no style of that family shows all of its styles.
+ private bool InHouseFamily(HouseStyle style, ICollection kindsWithFamily)
+ {
+ return _houseFamily == null || style.Family == _houseFamily || !kindsWithFamily.Contains(style.Kind);
+ }
+
+ /// Lists the families of the kind shown, to narrow the page to one.
+ private void FillFamilies()
+ {
+ _familyButton.DropDownItems.Clear();
+ void Add(string text, string family)
+ {
+ var item = new ToolStripMenuItem(text) { Checked = _houseFamily == family };
+ item.Click += (_, _) =>
+ {
+ _houseFamily = family;
+ _familyButton.Text = family == null ? "Family" : "Family: " + family;
+ RebuildHouseTree();
+ };
+ _familyButton.DropDownItems.Add(item);
+ }
+
+ Add("All families", null);
+ if (_houseStyles == null)
+ {
+ return;
+ }
+
+ foreach (string family in _houseStyles.Styles.Where(st => st.Kind == _houseKind && !st.Hidden && st.Family.Length > 0).Select(st => st.Family).Distinct())
+ {
+ Add(family, family);
+ }
+ }
+
///
/// Shows the styles of the current kind that match the search (by style or material name,
/// or by a piece's id), and how many each kind has.
@@ -1401,6 +1447,12 @@ private void RebuildHouseTree()
_swapButton.Text = _swapText;
_swapButton.Enabled = true;
List styles = _houseStyles?.Styles.Where(st => !st.Hidden).ToList() ?? new List();
+ if (_houseFamily != null)
+ {
+ var kindsWithFamily = new HashSet(styles.Where(st => st.Family == _houseFamily).Select(st => st.Kind));
+ styles = styles.Where(st => InHouseFamily(st, kindsWithFamily)).ToList();
+ }
+
_houseStyleCount = 0;
foreach (var (kind, title, _, _) in _houseKinds)
From 160b761a7651c68c96811d1d9673c5714a8e2cdd Mon Sep 17 00:00:00 2001
From: AsY!um- <377468+AsYlum-@users.noreply.github.com>
Date: Thu, 19 Nov 2026 00:03:30 +0100
Subject: [PATCH 09/16] Start a new multi blank from the ground and offer the
usual sizes
---
.../UI/NewMultiDialog.Designer.cs | 99 ++++++++++++++-----
.../UI/NewMultiDialog.cs | 81 ++++++++++++++-
2 files changed, 151 insertions(+), 29 deletions(-)
diff --git a/UoFiddler.Plugin.MultiEditor/UI/NewMultiDialog.Designer.cs b/UoFiddler.Plugin.MultiEditor/UI/NewMultiDialog.Designer.cs
index 0ef1902c..1cabc6ad 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/NewMultiDialog.Designer.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/NewMultiDialog.Designer.cs
@@ -37,6 +37,10 @@ private void InitializeComponent()
_width = new System.Windows.Forms.NumericUpDown();
byLabel = new System.Windows.Forms.Label();
_height = new System.Windows.Forms.NumericUpDown();
+ _presetLabel = new System.Windows.Forms.Label();
+ _sizePreset = new System.Windows.Forms.ComboBox();
+ _customLabel = new System.Windows.Forms.Label();
+ _cellsLabel = new System.Windows.Forms.Label();
buttonOk = new System.Windows.Forms.Button();
buttonCancel = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)_width).BeginInit();
@@ -46,10 +50,10 @@ private void InitializeComponent()
// _custom
//
_custom.AutoSize = true;
- _custom.Location = new System.Drawing.Point(12, 12);
+ _custom.Location = new System.Drawing.Point(12, 40);
_custom.Name = "_custom";
_custom.Size = new System.Drawing.Size(222, 19);
- _custom.TabIndex = 0;
+ _custom.TabIndex = 1;
_custom.Text = "Custom house on a client foundation";
_custom.UseVisualStyleBackColor = true;
_custom.CheckedChanged += Kind_CheckedChanged;
@@ -57,39 +61,39 @@ private void InitializeComponent()
// _foundationCombo
//
_foundationCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- _foundationCombo.Location = new System.Drawing.Point(32, 36);
+ _foundationCombo.Location = new System.Drawing.Point(32, 64);
_foundationCombo.Name = "_foundationCombo";
_foundationCombo.Size = new System.Drawing.Size(250, 23);
- _foundationCombo.TabIndex = 1;
+ _foundationCombo.TabIndex = 2;
//
// customHint
//
customHint.AutoSize = true;
customHint.ForeColor = System.Drawing.SystemColors.GrayText;
- customHint.Location = new System.Drawing.Point(32, 62);
+ customHint.Location = new System.Drawing.Point(32, 90);
customHint.Name = "customHint";
customHint.Size = new System.Drawing.Size(329, 15);
- customHint.TabIndex = 2;
+ customHint.TabIndex = 3;
customHint.Text = "Starts with the foundation's tiles. Floors are at Z 7, 27, 47, 67.";
//
// _blankFoundation
//
_blankFoundation.AutoSize = true;
- _blankFoundation.Location = new System.Drawing.Point(12, 90);
+ _blankFoundation.Location = new System.Drawing.Point(12, 116);
_blankFoundation.Name = "_blankFoundation";
_blankFoundation.Size = new System.Drawing.Size(266, 19);
- _blankFoundation.TabIndex = 3;
- _blankFoundation.Text = "Blank, on a foundation (first floor at Z 7)";
+ _blankFoundation.TabIndex = 4;
+ _blankFoundation.Text = "Blank, first floor at Z 7 (as on a foundation)";
_blankFoundation.UseVisualStyleBackColor = true;
_blankFoundation.CheckedChanged += Kind_CheckedChanged;
//
// _blankGround
//
_blankGround.AutoSize = true;
- _blankGround.Location = new System.Drawing.Point(12, 114);
+ _blankGround.Location = new System.Drawing.Point(12, 12);
_blankGround.Name = "_blankGround";
_blankGround.Size = new System.Drawing.Size(268, 19);
- _blankGround.TabIndex = 4;
+ _blankGround.TabIndex = 0;
_blankGround.Text = "Blank, from the ground (first floor at Z 0)";
_blankGround.UseVisualStyleBackColor = true;
_blankGround.CheckedChanged += Kind_CheckedChanged;
@@ -97,7 +101,7 @@ private void InitializeComponent()
// sizeLabel
//
sizeLabel.AutoSize = true;
- sizeLabel.Location = new System.Drawing.Point(32, 146);
+ sizeLabel.Location = new System.Drawing.Point(12, 152);
sizeLabel.Name = "sizeLabel";
sizeLabel.Size = new System.Drawing.Size(120, 15);
sizeLabel.TabIndex = 5;
@@ -105,50 +109,89 @@ private void InitializeComponent()
//
// _width
//
- _width.Location = new System.Drawing.Point(170, 143);
+ _width.Location = new System.Drawing.Point(122, 205);
_width.Maximum = new decimal(new int[] { 200, 0, 0, 0 });
_width.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
_width.Name = "_width";
_width.Size = new System.Drawing.Size(56, 23);
- _width.TabIndex = 6;
+ _width.TabIndex = 9;
_width.Value = new decimal(new int[] { 10, 0, 0, 0 });
+ _width.ValueChanged += Size_ValueChanged;
//
// byLabel
//
byLabel.AutoSize = true;
- byLabel.Location = new System.Drawing.Point(232, 146);
+ byLabel.Location = new System.Drawing.Point(184, 208);
byLabel.Name = "byLabel";
byLabel.Size = new System.Drawing.Size(13, 15);
- byLabel.TabIndex = 7;
+ byLabel.TabIndex = 10;
byLabel.Text = "x";
//
// _height
//
- _height.Location = new System.Drawing.Point(250, 143);
+ _height.Location = new System.Drawing.Point(202, 205);
_height.Maximum = new decimal(new int[] { 200, 0, 0, 0 });
_height.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
_height.Name = "_height";
_height.Size = new System.Drawing.Size(56, 23);
- _height.TabIndex = 8;
+ _height.TabIndex = 11;
_height.Value = new decimal(new int[] { 10, 0, 0, 0 });
+ _height.ValueChanged += Size_ValueChanged;
+ //
+ // _presetLabel
+ //
+ _presetLabel.AutoSize = true;
+ _presetLabel.Location = new System.Drawing.Point(32, 178);
+ _presetLabel.Name = "_presetLabel";
+ _presetLabel.Size = new System.Drawing.Size(39, 15);
+ _presetLabel.TabIndex = 6;
+ _presetLabel.Text = "Preset";
+ //
+ // _sizePreset
+ //
+ _sizePreset.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ _sizePreset.FormattingEnabled = true;
+ _sizePreset.Location = new System.Drawing.Point(122, 175);
+ _sizePreset.Name = "_sizePreset";
+ _sizePreset.Size = new System.Drawing.Size(240, 23);
+ _sizePreset.TabIndex = 7;
+ _sizePreset.SelectedIndexChanged += SizePreset_SelectedIndexChanged;
+ //
+ // _customLabel
+ //
+ _customLabel.AutoSize = true;
+ _customLabel.Location = new System.Drawing.Point(32, 208);
+ _customLabel.Name = "_customLabel";
+ _customLabel.Size = new System.Drawing.Size(49, 15);
+ _customLabel.TabIndex = 8;
+ _customLabel.Text = "Width x depth";
+ //
+ // _cellsLabel
+ //
+ _cellsLabel.AutoSize = true;
+ _cellsLabel.Location = new System.Drawing.Point(264, 208);
+ _cellsLabel.Name = "_cellsLabel";
+ _cellsLabel.Size = new System.Drawing.Size(30, 15);
+ _cellsLabel.TabIndex = 12;
+ _cellsLabel.Text = "cells";
//
// buttonOk
//
buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK;
- buttonOk.Location = new System.Drawing.Point(224, 210);
+ buttonOk.Location = new System.Drawing.Point(224, 246);
buttonOk.Name = "buttonOk";
buttonOk.Size = new System.Drawing.Size(76, 23);
- buttonOk.TabIndex = 9;
+ buttonOk.TabIndex = 13;
buttonOk.Text = "OK";
buttonOk.UseVisualStyleBackColor = true;
//
// buttonCancel
//
buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
- buttonCancel.Location = new System.Drawing.Point(308, 210);
+ buttonCancel.Location = new System.Drawing.Point(308, 246);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new System.Drawing.Size(76, 23);
- buttonCancel.TabIndex = 10;
+ buttonCancel.TabIndex = 14;
buttonCancel.Text = "Cancel";
buttonCancel.UseVisualStyleBackColor = true;
//
@@ -158,16 +201,20 @@ private void InitializeComponent()
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
CancelButton = buttonCancel;
- ClientSize = new System.Drawing.Size(400, 250);
+ ClientSize = new System.Drawing.Size(400, 284);
+ Controls.Add(_blankGround);
Controls.Add(_custom);
Controls.Add(_foundationCombo);
Controls.Add(customHint);
Controls.Add(_blankFoundation);
- Controls.Add(_blankGround);
Controls.Add(sizeLabel);
+ Controls.Add(_presetLabel);
+ Controls.Add(_sizePreset);
+ Controls.Add(_customLabel);
Controls.Add(_width);
Controls.Add(byLabel);
Controls.Add(_height);
+ Controls.Add(_cellsLabel);
Controls.Add(buttonOk);
Controls.Add(buttonCancel);
FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
@@ -194,6 +241,10 @@ private void InitializeComponent()
private System.Windows.Forms.NumericUpDown _width;
private System.Windows.Forms.Label byLabel;
private System.Windows.Forms.NumericUpDown _height;
+ private System.Windows.Forms.Label _presetLabel;
+ private System.Windows.Forms.ComboBox _sizePreset;
+ private System.Windows.Forms.Label _customLabel;
+ private System.Windows.Forms.Label _cellsLabel;
private System.Windows.Forms.Button buttonOk;
private System.Windows.Forms.Button buttonCancel;
}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/NewMultiDialog.cs b/UoFiddler.Plugin.MultiEditor/UI/NewMultiDialog.cs
index 630cec27..5eb191fe 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/NewMultiDialog.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/NewMultiDialog.cs
@@ -17,7 +17,8 @@ namespace UoFiddler.Plugin.MultiEditor.UI
///
/// Asks what kind of multi to start. The client has two kinds of houses: custom houses, always
/// built on one of its ready-made foundations (floors from Z 7), and multis built whole, which
- /// may stand on a foundation of their own or start from the ground.
+ /// may stand on a foundation of their own or start from the ground. A blank multi starts
+ /// from the ground unless chosen otherwise; its size is one of the usual ones or typed in.
///
internal sealed partial class NewMultiDialog : Form
{
@@ -26,6 +27,28 @@ private sealed record FoundationEntry(int Id, MultiComponentList Components)
public override string ToString() => $"{Components.Width} x {Components.Height} (multi 0x{Id:X4})";
}
+ /// A usual size of a blank multi.
+ private sealed record SizePreset(int Width, int Height, string What)
+ {
+ public override string ToString() => Width == 0 ? What : $"{Width} x {Height} {What}";
+ }
+
+ // The sizes of the client's own houses, and what the House tool's tower, keep and castle need.
+ private static readonly SizePreset[] _sizes =
+ {
+ new SizePreset(8, 8, "small house"),
+ new SizePreset(10, 10, "house"),
+ new SizePreset(12, 12, "house, room for a tower"),
+ new SizePreset(15, 15, "large house"),
+ new SizePreset(18, 18, "largest house plot"),
+ new SizePreset(24, 16, "the client's tower"),
+ new SizePreset(24, 24, "the client's keep, room for a keep"),
+ new SizePreset(31, 31, "the client's castle, room for a castle"),
+ new SizePreset(0, 0, "Custom size")
+ };
+
+ private bool _syncingSize;
+
/// The floor of a custom house foundation.
private const ushort _foundationDirt = 0x31F4;
@@ -43,16 +66,21 @@ public NewMultiDialog()
if (_foundationCombo.Items.Count > 0)
{
_foundationCombo.SelectedIndex = 0;
- _custom.Checked = true;
}
else
{
// An old client without custom housing.
_custom.Enabled = false;
_foundationCombo.Enabled = false;
- _blankFoundation.Checked = true;
}
+ foreach (SizePreset size in _sizes)
+ {
+ _sizePreset.Items.Add(size);
+ }
+
+ _blankGround.Checked = true;
+ SyncPreset();
SyncEnabled();
}
@@ -72,8 +100,51 @@ private void Kind_CheckedChanged(object sender, EventArgs e)
private void SyncEnabled()
{
- _foundationCombo.Enabled = _custom.Checked;
- _width.Enabled = _height.Enabled = !_custom.Checked;
+ _foundationCombo.Enabled = _custom.Checked && _foundationCombo.Items.Count > 0;
+ _sizePreset.Enabled = _width.Enabled = _height.Enabled = !_custom.Checked;
+ }
+
+ /// A preset fills in its size.
+ private void SizePreset_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ if (_syncingSize || _sizePreset.SelectedItem is not SizePreset { Width: > 0 } size)
+ {
+ return;
+ }
+
+ _syncingSize = true;
+ try
+ {
+ _width.Value = size.Width;
+ _height.Value = size.Height;
+ }
+ finally
+ {
+ _syncingSize = false;
+ }
+ }
+
+ private void Size_ValueChanged(object sender, EventArgs e)
+ {
+ if (!_syncingSize)
+ {
+ SyncPreset();
+ }
+ }
+
+ /// Shows the preset the typed size is, or "Custom size".
+ private void SyncPreset()
+ {
+ _syncingSize = true;
+ try
+ {
+ int index = Array.FindIndex(_sizes, size => size.Width == (int)_width.Value && size.Height == (int)_height.Value);
+ _sizePreset.SelectedIndex = index >= 0 ? index : _sizes.Length - 1;
+ }
+ finally
+ {
+ _syncingSize = false;
+ }
}
/// Forgets the foundation list, after the client files changed.
From 61d6e041bec84854e7c646cbc741abc9a10f8710 Mon Sep 17 00:00:00 2001
From: AsY!um- <377468+AsYlum-@users.noreply.github.com>
Date: Thu, 19 Nov 2026 00:36:38 +0100
Subject: [PATCH 10/16] Add foundations to house drafts and refine wing editing
Shift keeps a wing square, previews draw in depth order, style picks stay on; shortcuts help updated.
---
.../Classes/HouseDraft.cs | 22 ++-
.../Classes/HouseDraftFile.cs | 11 ++
.../Classes/HouseStyleConfig.cs | 51 +++++-
.../Classes/HouseStyles.cs | 14 ++
.../Classes/HouseTheme.cs | 24 +++
.../MultiEditorHouseStyles.xml | 26 ++-
.../Tools/HouseTool.cs | 49 +++++-
.../Tools/WingDraftTool.cs | 97 +++++++++--
.../UI/HousePanel.Designer.cs | 151 ++++++++++--------
UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs | 51 +++++-
.../UI/MultiEditorControl.cs | 18 ++-
.../UI/ShortcutsForm.cs | 23 ++-
12 files changed, 429 insertions(+), 108 deletions(-)
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
index 654fed08..d2e4d4e7 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
@@ -44,8 +44,8 @@ internal sealed class HouseDraft
public const string StairsLayer = "Stairs";
public const string FoundationLayer = "Foundation";
- // The foundation ring stands this far below the ground floor, as in the client's house foundations.
- private const int _foundationBelow = 7;
+ /// How far below the ground floor the foundation of most client houses starts.
+ public const int UsualFoundationHeight = 7;
/// Z of the ground floor.
public int BaseZ { get; set; }
@@ -64,6 +64,12 @@ internal sealed class HouseDraft
/// The wall style the foundation ring is built in; without one, the client houses' own (light brick).
public HouseStyle FoundationStyle { get; set; }
+ /// Rows of foundation pieces, one on the other: the stone tower, keep and castle have two.
+ public int FoundationTiers { get; set; } = 1;
+
+ /// How far below the ground floor the foundation starts.
+ public int FoundationHeight { get; set; } = UsualFoundationHeight;
+
/// The door style of the house: what a theme sets, and what doors made for the rooms are.
public HouseStyle DoorStyle { get; set; }
@@ -193,7 +199,8 @@ public HouseDraft Fresh()
var copy = new HouseDraft
{
RoofStyle = RoofStyle, FlatRoofStyle = FlatRoofStyle, Foundation = Foundation,
- FoundationStyle = FoundationStyle, DoorStyle = DoorStyle, StairStyle = StairStyle,
+ FoundationStyle = FoundationStyle, FoundationTiers = FoundationTiers, FoundationHeight = FoundationHeight,
+ DoorStyle = DoorStyle, StairStyle = StairStyle,
AutoDoors = AutoDoors, FrontDoor = FrontDoor, WindowSpacing = WindowSpacing,
Gables = Gables, GableFill = GableFill, Parapet = Parapet
};
@@ -898,9 +905,11 @@ public Built Build(IReadOnlyList wings, HouseStyles styles)
{
string column = WallPlanner.PieceFor(ringSouth, ringEast, x, y);
ushort id = column != null ? foundation.Get(column) : (ushort)0;
- if (id != 0)
+ // One row, or rows one on the other, each as high as the piece.
+ int rise = id != 0 ? Math.Max(1, (int)Ultima.TileData.ItemTable[id].Height) : 0;
+ for (int tier = 0; id != 0 && tier < Math.Clamp(FoundationTiers, 1, 3); ++tier)
{
- built.Tiles.Add((id, x, y, z - _foundationBelow, FoundationLayer));
+ built.Tiles.Add((id, x, y, z - FoundationHeight + (tier * rise), FoundationLayer));
}
}
}
@@ -1028,7 +1037,8 @@ private void AddSteps((int X, int Y) door, HouseStyles styles, Built built)
return;
}
- int z = BaseZ - Math.Max(1, (int)Ultima.TileData.ItemTable[step].Height);
+ // The step's top meets the floor; on a foundation lower than the step it starts where the foundation does.
+ int z = BaseZ - Math.Min(FoundationHeight, Math.Max(1, (int)Ultima.TileData.ItemTable[step].Height));
(int X, int Y) at = south ? (door.X, door.Y + 1) : (door.X + 1, door.Y);
built.Tiles.Add((step, at.X, at.Y, z, StairsLayer));
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs
index 3e567204..4c00849d 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraftFile.cs
@@ -81,6 +81,15 @@ public static XElement ToXml(IReadOnlyList wings, HouseDraft draft, st
AddStyle(root, "door", draft.DoorStyle);
AddStyle(root, "stairs", draft.StairStyle);
AddStyle(root, "foundationStyle", draft.FoundationStyle);
+ if (draft.FoundationTiers != 1)
+ {
+ root.Add(new XAttribute("foundationTiers", draft.FoundationTiers));
+ }
+
+ if (draft.FoundationHeight != HouseDraft.UsualFoundationHeight)
+ {
+ root.Add(new XAttribute("foundationHeight", draft.FoundationHeight));
+ }
foreach (RoofWing wing in wings)
{
@@ -235,6 +244,8 @@ HouseStyle Style(HousePartKind kind, XElement element, string attribute)
draft.DoorStyle = Style(HousePartKind.Door, root, "door") ?? draft.DoorStyle;
draft.StairStyle = Style(HousePartKind.Stair, root, "stairs") ?? draft.StairStyle;
draft.FoundationStyle = Style(HousePartKind.Wall, root, "foundationStyle");
+ draft.FoundationTiers = Math.Clamp((int?)root.Attribute("foundationTiers") ?? 1, 1, 3);
+ draft.FoundationHeight = Math.Clamp((int?)root.Attribute("foundationHeight") ?? HouseDraft.UsualFoundationHeight, 1, 20);
var wings = new List();
foreach (XElement element in root.Elements("Wing"))
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseStyleConfig.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseStyleConfig.cs
index f0f0a8f9..f347f4d9 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/HouseStyleConfig.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseStyleConfig.cs
@@ -74,6 +74,8 @@ internal sealed class HouseStyleConfig
public List Themes { get; } = new List();
+ public List Foundations { get; } = new List();
+
/// The order of the styles of a kind, as anchors, where it is other than the order of the Style elements.
public Dictionary> Order { get; } = new Dictionary>();
@@ -177,7 +179,26 @@ public static HouseStyleConfig LoadFile(string path)
FlatRoof = Id("flatRoof"),
Door = Id("door"),
Stairs = Id("stairs"),
- Foundation = Id("foundation")
+ Foundation = Id("foundation"),
+ FoundationTiers = Math.Clamp(ParseInt((string)element.Attribute("foundationTiers") ?? "1"), 1, 3),
+ FoundationHeight = Math.Clamp(ParseInt((string)element.Attribute("foundationHeight") ?? "7"), 1, 20)
+ });
+ }
+
+ foreach (XElement element in root.Elements("Foundation"))
+ {
+ string name = ((string)element.Attribute("name"))?.Trim();
+ if (string.IsNullOrEmpty(name))
+ {
+ continue;
+ }
+
+ config.Foundations.Add(new HouseFoundation
+ {
+ Name = name,
+ Style = TryParseId((string)element.Attribute("style"), out ushort style) ? style : (ushort)0,
+ Tiers = Math.Clamp(ParseInt((string)element.Attribute("tiers") ?? "1"), 1, 3),
+ Height = Math.Clamp(ParseInt((string)element.Attribute("height") ?? "7"), 1, 20)
});
}
}
@@ -227,6 +248,12 @@ public void Merge(HouseStyleConfig other)
Order[order.Key] = order.Value;
}
+ foreach (HouseFoundation foundation in other.Foundations)
+ {
+ Foundations.RemoveAll(mine => string.Equals(mine.Name, foundation.Name, StringComparison.OrdinalIgnoreCase));
+ Foundations.Add(foundation);
+ }
+
foreach (HouseTheme theme in other.Themes)
{
int index = Themes.FindIndex(mine => string.Equals(mine.Name, theme.Name, StringComparison.OrdinalIgnoreCase));
@@ -293,6 +320,28 @@ void Id(string attribute, ushort id)
Id("door", theme.Door);
Id("stairs", theme.Stairs);
Id("foundation", theme.Foundation);
+ if (theme.FoundationTiers != 1)
+ {
+ element.Add(new XAttribute("foundationTiers", theme.FoundationTiers));
+ }
+
+ if (theme.FoundationHeight != HouseDraft.UsualFoundationHeight)
+ {
+ element.Add(new XAttribute("foundationHeight", theme.FoundationHeight));
+ }
+
+ root.Add(element);
+ }
+
+ foreach (HouseFoundation foundation in Foundations)
+ {
+ var element = new XElement("Foundation", new XAttribute("name", foundation.Name));
+ if (foundation.Style != 0)
+ {
+ element.Add(new XAttribute("style", FormatId(foundation.Style)));
+ }
+
+ element.Add(new XAttribute("tiers", foundation.Tiers), new XAttribute("height", foundation.Height));
root.Add(element);
}
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseStyles.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseStyles.cs
index 76496580..d8ac6e6a 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/HouseStyles.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseStyles.cs
@@ -149,6 +149,9 @@ private HouseStyles()
///
public List Themes { get; } = new List();
+ /// The foundations of the style file whose wall style this client has.
+ public List Foundations { get; } = new List();
+
/// The style of a kind that a piece names: the one with that anchor, or else the one that lists the piece.
public HouseStyle Find(HousePartKind kind, ushort anchor)
{
@@ -278,11 +281,20 @@ public void ReloadThemes()
private void SetThemes(HouseStyleConfig config)
{
Themes.Clear();
+ Foundations.Clear();
if (config == null)
{
return;
}
+ foreach (HouseFoundation foundation in config.Foundations)
+ {
+ if (foundation.Style == 0 ? TryGetRole(Tools.FoundationTool.FoundationPost, out _, out _) : Find(HousePartKind.Wall, foundation.Style) != null)
+ {
+ Foundations.Add(foundation);
+ }
+ }
+
foreach (HouseTheme theme in config.Themes)
{
if (Find(HousePartKind.Wall, theme.Walls) != null && Find(HousePartKind.Floor, theme.Floor) != null &&
@@ -323,6 +335,8 @@ public void Reload()
Errors.AddRange(fresh.Errors);
Themes.Clear();
Themes.AddRange(fresh.Themes);
+ Foundations.Clear();
+ Foundations.AddRange(fresh.Foundations);
_roles.Clear();
foreach (KeyValuePair role in fresh._roles)
{
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseTheme.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseTheme.cs
index dca81a8b..c61fc502 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/HouseTheme.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseTheme.cs
@@ -35,9 +35,33 @@ internal sealed class HouseTheme
public ushort Foundation { get; set; }
+ /// Rows of the foundation's pieces, one on the other, and how far below the ground floor the foundation starts.
+ public int FoundationTiers { get; set; } = 1;
+
+ public int FoundationHeight { get; set; } = HouseDraft.UsualFoundationHeight;
+
/// True for a theme from the user's copy of the style file.
public bool IsUser { get; set; }
public override string ToString() => Name;
}
+
+ ///
+ /// A foundation as the client's houses have them: a low wall style around the house, in one
+ /// or two rows, with the ground floor a given height above where it starts. From the style
+ /// file; offered when the client has the wall style.
+ ///
+ internal sealed class HouseFoundation
+ {
+ public string Name { get; set; }
+
+ /// Anchor piece of the wall style; 0 for the usual one (light brick quarter walls).
+ public ushort Style { get; set; }
+
+ public int Tiers { get; set; } = 1;
+
+ public int Height { get; set; } = HouseDraft.UsualFoundationHeight;
+
+ public override string ToString() => Name;
+ }
}
diff --git a/UoFiddler.Plugin.MultiEditor/MultiEditorHouseStyles.xml b/UoFiddler.Plugin.MultiEditor/MultiEditorHouseStyles.xml
index bc29b861..50c9b8f1 100644
--- a/UoFiddler.Plugin.MultiEditor/MultiEditorHouseStyles.xml
+++ b/UoFiddler.Plugin.MultiEditor/MultiEditorHouseStyles.xml
@@ -26,6 +26,12 @@
Theme the styles of every part of a house, picked together; each is a tile id of the style
(its anchor): walls, floor, roof, flatRoof, door, stairs, foundation. A theme is offered
when the client has its wall, floor and roof style.
+ foundation is the wall style of the foundation, foundationTiers its rows (1) and
+ foundationHeight how far below the floor it starts (7).
+
+ Foundation a kind of foundation to choose for a house: name, style (a tile id of the low wall
+ style; none for light brick quarter walls), tiers (rows one on the other) and height
+ (how far below the ground floor it starts). Offered when the client has the style.
-->
@@ -832,14 +838,14 @@
-
+
-
-
-
-
-
+
+
+
+
+
@@ -853,4 +859,12 @@
+
+
+
+
+
+
+
+
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
index e98d5179..1fd0cdf0 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
@@ -94,6 +94,9 @@ protected override bool Ready
protected override bool GhostsFollowView => true;
+ /// A house wing is at least three wall cells each way, as it is drawn: walls with a room between, and a middle to move it by.
+ protected override int MinSpan => 2;
+
// What the preview shows. A view choice: it is no step of the history and what is placed
// is always the whole house.
private bool _showWalls = true;
@@ -721,6 +724,45 @@ private void Restyle(HouseStyle style)
}
}
+ /// The foundations this client can build.
+ public IReadOnlyList Foundations => (IReadOnlyList)Context.HouseStyles?.Foundations ?? Array.Empty();
+
+ /// Gives the house one of the client's kinds of foundation: its wall style, rows and height.
+ public void SetFoundation(HouseFoundation foundation)
+ {
+ if (foundation == null || Context.HouseStyles == null)
+ {
+ return;
+ }
+
+ HouseStyle style = Context.HouseStyles.Find(HousePartKind.Wall, foundation.Style);
+ Edit(() =>
+ {
+ _draft.Foundation = true;
+ (_draft.FoundationStyle, _draft.FoundationTiers, _draft.FoundationHeight) = (style, foundation.Tiers, foundation.Height);
+ });
+ }
+
+ /// The kind of foundation the house has, or null when it has none or one put together by hand.
+ public HouseFoundation CurrentFoundation()
+ {
+ if (!_draft.Foundation || Context.HouseStyles == null)
+ {
+ return null;
+ }
+
+ foreach (HouseFoundation foundation in Foundations)
+ {
+ if (_draft.FoundationStyle == Context.HouseStyles.Find(HousePartKind.Wall, foundation.Style) &&
+ _draft.FoundationTiers == foundation.Tiers && _draft.FoundationHeight == foundation.Height)
+ {
+ return foundation;
+ }
+ }
+
+ return null;
+ }
+
/// Sets the wall style the foundation ring is built in; null is the client houses' own.
public void SetFoundationStyle(HouseStyle style)
{
@@ -772,7 +814,7 @@ HouseStyle Part(HousePartKind kind, ushort anchor, string what)
_draft.RoofStyle = roof ?? _draft.RoofStyle;
_draft.FlatRoofStyle = flatRoof ?? _draft.FlatRoofStyle;
- _draft.FoundationStyle = foundation;
+ (_draft.FoundationStyle, _draft.FoundationTiers, _draft.FoundationHeight) = (foundation, theme.FoundationTiers, theme.FoundationHeight);
if (door != null)
{
Restyle(door);
@@ -800,6 +842,8 @@ public HouseTheme ThemeOfDraft(string name)
Door = _draft.DoorStyle?.Anchor ?? 0,
Stairs = _draft.StairStyle?.Anchor ?? 0,
Foundation = _draft.FoundationStyle?.Anchor ?? 0,
+ FoundationTiers = _draft.FoundationTiers,
+ FoundationHeight = _draft.FoundationHeight,
IsUser = true
};
}
@@ -825,7 +869,8 @@ public HouseTheme CurrentTheme()
if (storeys && Is(_draft.RoofStyle, HousePartKind.Roof, theme.Roof) &&
Is(_draft.FlatRoofStyle, HousePartKind.Floor, theme.FlatRoof) &&
Is(_draft.DoorStyle, HousePartKind.Door, theme.Door) && Is(_draft.StairStyle, HousePartKind.Stair, theme.Stairs) &&
- _draft.FoundationStyle == Context.HouseStyles.Find(HousePartKind.Wall, theme.Foundation))
+ _draft.FoundationStyle == Context.HouseStyles.Find(HousePartKind.Wall, theme.Foundation) &&
+ _draft.FoundationTiers == theme.FoundationTiers && _draft.FoundationHeight == theme.FoundationHeight)
{
return theme;
}
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
index a593b064..016d2fc6 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
@@ -144,6 +144,9 @@ private sealed class State
private int _endX;
private int _endY;
private int _z;
+ /// Least distance between a wing's first and last row or column when it is resized. A roof may be a single row.
+ protected virtual int MinSpan => 0;
+
private RoofWing _before;
// A Ctrl+drag moves every wing: where they all stood, and how far they have been moved so far.
@@ -389,7 +392,11 @@ public override void OnMouseDown(MouseEventArgs e)
{
RoofWing wing = _wings[hit];
bool wasSelected = hit == _selected;
- if (ShiftHeld)
+
+ // Shift on a corner of the selected wing resizes it as a square; anywhere else on a wing it turns the wing.
+ Edges(wing, cx, cy, wasSelected, out bool cornerWest, out bool cornerEast, out bool cornerNorth, out bool cornerSouth);
+ bool corner = (cornerWest || cornerEast) && (cornerNorth || cornerSouth);
+ if (ShiftHeld && !corner)
{
Remember();
_selected = hit;
@@ -432,15 +439,18 @@ public override void OnMouseDown(MouseEventArgs e)
///
/// The sides a press on a cell of the selected wing takes hold of: its outermost rows and
- /// columns. A side too short to have a middle moves the wing instead.
+ /// columns, however narrow the wing is, so a wing can always be made wider again.
///
private static void Edges(RoofWing wing, int cx, int cy, bool selected, out bool west, out bool east, out bool north, out bool south)
{
- bool wide = wing.X1 - wing.X0 >= 2, deep = wing.Y1 - wing.Y0 >= 2;
- west = selected && wide && cx == wing.X0;
- east = selected && wide && cx == wing.X1;
- north = selected && deep && cy == wing.Y0;
- south = selected && deep && cy == wing.Y1;
+ west = selected && cx == wing.X0;
+ east = selected && cx == wing.X1;
+ north = selected && cy == wing.Y0;
+ south = selected && cy == wing.Y1;
+
+ // A wing of one row or column has both sides in the same cell: the far side is the one to pull out again.
+ west &= !east;
+ north &= !south;
}
public override void OnMouseMove(MouseEventArgs e)
@@ -735,11 +745,41 @@ private void DragWing()
return;
}
- wing.X0 = _west ? Math.Clamp(_before.X0 + dx, 0, _before.X1) : _before.X0;
- wing.X1 = _east ? Math.Max(_before.X1 + dx, _before.X0) : _before.X1;
- wing.Y0 = _north ? Math.Clamp(_before.Y0 + dy, 0, _before.Y1) : _before.Y0;
- wing.Y1 = _south ? Math.Max(_before.Y1 + dy, _before.Y0) : _before.Y1;
- Snap(wing, moved: false);
+ // Not narrower than the tool lets a wing be.
+ wing.X0 = _west ? Math.Clamp(_before.X0 + dx, 0, Math.Max(0, _before.X1 - MinSpan)) : _before.X0;
+ wing.X1 = _east ? Math.Max(_before.X1 + dx, _before.X0 + MinSpan) : _before.X1;
+ wing.Y0 = _north ? Math.Clamp(_before.Y0 + dy, 0, Math.Max(0, _before.Y1 - MinSpan)) : _before.Y0;
+ wing.Y1 = _south ? Math.Max(_before.Y1 + dy, _before.Y0 + MinSpan) : _before.Y1;
+
+ // A corner dragged with Shift makes the wing square: the side dragged further sets the size.
+ // (Keeping a ratio does not work on a grid of cells: the two sides round apart.)
+ bool square = ShiftHeld && (_west || _east) && (_north || _south);
+ if (square)
+ {
+ int side = Math.Max(wing.X1 - wing.X0, wing.Y1 - wing.Y0);
+
+ // Not past the multi's first row or column, and not smaller than a wing can be.
+ if (_west)
+ {
+ side = Math.Min(side, _before.X1);
+ }
+
+ if (_north)
+ {
+ side = Math.Min(side, _before.Y1);
+ }
+
+ side = Math.Max(side, 2);
+ (wing.X0, wing.X1) = _west ? (_before.X1 - side, _before.X1) : (_before.X0, _before.X0 + side);
+ (wing.Y0, wing.Y1) = _north ? (_before.Y1 - side, _before.Y1) : (_before.Y0, _before.Y0 + side);
+ }
+
+ // Snapping to a wing one cell away would stretch one side by a cell: a square stays as dragged.
+ if (!square)
+ {
+ Snap(wing, moved: false);
+ }
+
WingResized(wing);
}
@@ -750,6 +790,33 @@ public override void PaintOverlay(IToolOverlay overlay)
PaintDraft(overlay, active: true);
}
+ // The planned tiles in the order they are drawn, kept until the plan changes.
+ private object _orderedFor;
+ private List<(MultiTile Tile, string Layer)> _ordered;
+
+ ///
+ /// The planned tiles in the order the multi's own tiles are drawn: cell after cell, and
+ /// within a cell from the bottom up, floors before what stands on them. Drawn in the
+ /// order they were planned, a floor laid after its walls, or the floor of the storey
+ /// above, would lie over walls that stand in front of it.
+ ///
+ private List<(MultiTile Tile, string Layer)> InDrawOrder(List<(ushort Id, int X, int Y, int Z, string Layer)> add)
+ {
+ if (!ReferenceEquals(_orderedFor, add) || _ordered == null || _ordered.Count != add.Count)
+ {
+ _ordered = new List<(MultiTile, string)>(add.Count);
+ foreach (var (id, x, y, z, layer) in add)
+ {
+ _ordered.Add((new MultiTile(id, x, y, z, 0), layer));
+ }
+
+ _ordered.Sort((a, b) => a.Tile.CompareTo(b.Tile));
+ _orderedFor = add;
+ }
+
+ return _ordered;
+ }
+
///
/// Draws the draft as it would be built. With (this tool is in
/// use) it also shows what the mouse would take hold of: the wing under it, the side of
@@ -787,11 +854,11 @@ public void PaintDraft(IToolOverlay overlay, bool active)
// A house is looked into like the multi: storeys above the chosen floor are left out.
int highest = GhostsFollowView ? Context.MaxHeight : int.MaxValue;
- foreach (var (id, x, y, z, layer) in add)
+ foreach ((MultiTile tile, string layer) in InDrawOrder(add))
{
- if (z <= highest && ShowsInPreview(layer))
+ if (tile.Z <= highest && ShowsInPreview(layer))
{
- overlay.Ghost(id, x, y, z);
+ overlay.Ghost(tile.Id, tile.X, tile.Y, tile.Z);
}
}
diff --git a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs
index c3eb4b0c..8f63b58e 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.Designer.cs
@@ -73,7 +73,9 @@ private void InitializeComponent()
_doorStyle = new System.Windows.Forms.Button();
_stairStyleLabel = new System.Windows.Forms.Label();
_stairStyle = new System.Windows.Forms.Button();
- _foundation = new System.Windows.Forms.CheckBox();
+ _foundationLabel = new System.Windows.Forms.Label();
+ _foundationKind = new System.Windows.Forms.ComboBox();
+ _foundationStyleLabel = new System.Windows.Forms.Label();
_foundationStyle = new System.Windows.Forms.Button();
_baseZLabel = new System.Windows.Forms.Label();
_baseZ = new System.Windows.Forms.NumericUpDown();
@@ -151,7 +153,9 @@ private void InitializeComponent()
houseBox.Controls.Add(_doorStyle);
houseBox.Controls.Add(_stairStyleLabel);
houseBox.Controls.Add(_stairStyle);
- houseBox.Controls.Add(_foundation);
+ houseBox.Controls.Add(_foundationLabel);
+ houseBox.Controls.Add(_foundationKind);
+ houseBox.Controls.Add(_foundationStyleLabel);
houseBox.Controls.Add(_foundationStyle);
houseBox.Controls.Add(_baseZLabel);
houseBox.Controls.Add(_baseZ);
@@ -179,7 +183,7 @@ private void InitializeComponent()
houseBox.Dock = System.Windows.Forms.DockStyle.Top;
houseBox.Location = new System.Drawing.Point(0, 0);
houseBox.Name = "houseBox";
- houseBox.Size = new System.Drawing.Size(250, 823);
+ houseBox.Size = new System.Drawing.Size(250, 851);
houseBox.TabIndex = 0;
houseBox.TabStop = false;
houseBox.Text = "House draft";
@@ -637,24 +641,43 @@ private void InitializeComponent()
_stairStyle.AutoEllipsis = true;
_stairStyle.UseVisualStyleBackColor = true;
//
- // _foundation
+ // _foundationLabel
//
- _foundation.AutoSize = true;
- _foundation.Location = new System.Drawing.Point(6, 551);
- _foundation.Name = "_foundation";
- _foundation.Size = new System.Drawing.Size(86, 19);
- _foundation.TabIndex = 43;
- _foundation.Text = "Foundation";
- _foundation.UseVisualStyleBackColor = true;
- _foundation.CheckedChanged += Foundation_CheckedChanged;
+ _foundationLabel.AutoSize = true;
+ _foundationLabel.Location = new System.Drawing.Point(6, 551);
+ _foundationLabel.Name = "_foundationLabel";
+ _foundationLabel.Size = new System.Drawing.Size(66, 15);
+ _foundationLabel.TabIndex = 43;
+ _foundationLabel.Text = "Foundation";
+ //
+ // _foundationKind
+ //
+ _foundationKind.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
+ _foundationKind.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ _foundationKind.FormattingEnabled = true;
+ _foundationKind.Location = new System.Drawing.Point(76, 547);
+ _foundationKind.Name = "_foundationKind";
+ _foundationKind.Size = new System.Drawing.Size(168, 23);
+ _foundationKind.TabIndex = 44;
+ _toolTip.SetToolTip(_foundationKind, "The foundation the house stands on, as the client houses have them: the low wall around it, in one or two rows, and how far it reaches below the floor.");
+ _foundationKind.SelectionChangeCommitted += FoundationKind_SelectionChangeCommitted;
+ //
+ // _foundationStyleLabel
+ //
+ _foundationStyleLabel.AutoSize = true;
+ _foundationStyleLabel.Location = new System.Drawing.Point(6, 580);
+ _foundationStyleLabel.Name = "_foundationStyleLabel";
+ _foundationStyleLabel.Size = new System.Drawing.Size(50, 15);
+ _foundationStyleLabel.TabIndex = 45;
+ _foundationStyleLabel.Text = "Its walls";
//
// _foundationStyle
//
_foundationStyle.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _foundationStyle.Location = new System.Drawing.Point(96, 547);
+ _foundationStyle.Location = new System.Drawing.Point(60, 575);
_foundationStyle.Name = "_foundationStyle";
- _foundationStyle.Size = new System.Drawing.Size(148, 25);
- _foundationStyle.TabIndex = 44;
+ _foundationStyle.Size = new System.Drawing.Size(184, 25);
+ _foundationStyle.TabIndex = 46;
_foundationStyle.Text = "(foundation)";
_foundationStyle.AutoEllipsis = true;
_foundationStyle.UseVisualStyleBackColor = true;
@@ -662,29 +685,29 @@ private void InitializeComponent()
// _baseZLabel
//
_baseZLabel.AutoSize = true;
- _baseZLabel.Location = new System.Drawing.Point(6, 579);
+ _baseZLabel.Location = new System.Drawing.Point(6, 607);
_baseZLabel.Name = "_baseZLabel";
_baseZLabel.Size = new System.Drawing.Size(44, 15);
- _baseZLabel.TabIndex = 45;
+ _baseZLabel.TabIndex = 47;
_baseZLabel.Text = "Base Z";
//
// _baseZ
//
- _baseZ.Location = new System.Drawing.Point(60, 576);
+ _baseZ.Location = new System.Drawing.Point(60, 604);
_baseZ.Maximum = new decimal(new int[] { 100, 0, 0, 0 });
_baseZ.Minimum = new decimal(new int[] { 100, 0, 0, int.MinValue });
_baseZ.Name = "_baseZ";
_baseZ.Size = new System.Drawing.Size(56, 23);
- _baseZ.TabIndex = 46;
+ _baseZ.TabIndex = 48;
_baseZ.ValueChanged += BaseZ_ValueChanged;
//
// _autoDoors
//
_autoDoors.AutoSize = true;
- _autoDoors.Location = new System.Drawing.Point(6, 609);
+ _autoDoors.Location = new System.Drawing.Point(6, 637);
_autoDoors.Name = "_autoDoors";
_autoDoors.Size = new System.Drawing.Size(96, 19);
- _autoDoors.TabIndex = 47;
+ _autoDoors.TabIndex = 49;
_autoDoors.Text = "Room doors";
_autoDoors.UseVisualStyleBackColor = true;
_toolTip.SetToolTip(_autoDoors, "Puts a door of the house's door style in every doorway between rooms.");
@@ -693,10 +716,10 @@ private void InitializeComponent()
// _frontDoorLabel
//
_frontDoorLabel.AutoSize = true;
- _frontDoorLabel.Location = new System.Drawing.Point(110, 610);
+ _frontDoorLabel.Location = new System.Drawing.Point(110, 638);
_frontDoorLabel.Name = "_frontDoorLabel";
_frontDoorLabel.Size = new System.Drawing.Size(62, 15);
- _frontDoorLabel.TabIndex = 48;
+ _frontDoorLabel.TabIndex = 50;
_frontDoorLabel.Text = "Front door";
//
// _frontDoor
@@ -705,49 +728,49 @@ private void InitializeComponent()
_frontDoor.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
_frontDoor.FormattingEnabled = true;
_frontDoor.Items.AddRange(new object[] { "None", "South", "East" });
- _frontDoor.Location = new System.Drawing.Point(176, 606);
+ _frontDoor.Location = new System.Drawing.Point(176, 634);
_frontDoor.Name = "_frontDoor";
_frontDoor.Size = new System.Drawing.Size(68, 23);
- _frontDoor.TabIndex = 49;
+ _frontDoor.TabIndex = 51;
_toolTip.SetToolTip(_frontDoor, "The outer wall of the first wing that gets the front door.");
_frontDoor.SelectedIndexChanged += FrontDoor_SelectedIndexChanged;
//
// _windowsLabel
//
_windowsLabel.AutoSize = true;
- _windowsLabel.Location = new System.Drawing.Point(6, 637);
+ _windowsLabel.Location = new System.Drawing.Point(6, 665);
_windowsLabel.Name = "_windowsLabel";
_windowsLabel.Size = new System.Drawing.Size(90, 15);
- _windowsLabel.TabIndex = 50;
+ _windowsLabel.TabIndex = 52;
_windowsLabel.Text = "Windows every";
//
// _windowSpacing
//
- _windowSpacing.Location = new System.Drawing.Point(100, 634);
+ _windowSpacing.Location = new System.Drawing.Point(100, 662);
_windowSpacing.Maximum = new decimal(new int[] { 12, 0, 0, 0 });
_windowSpacing.Minimum = new decimal(new int[] { 0, 0, 0, 0 });
_windowSpacing.Name = "_windowSpacing";
_windowSpacing.Size = new System.Drawing.Size(44, 23);
- _windowSpacing.TabIndex = 51;
+ _windowSpacing.TabIndex = 53;
_toolTip.SetToolTip(_windowSpacing, "Puts windows along the outer walls, this many cells apart. 0: none.");
_windowSpacing.ValueChanged += WindowSpacing_ValueChanged;
//
// _windowsHint
//
_windowsHint.AutoSize = true;
- _windowsHint.Location = new System.Drawing.Point(150, 637);
+ _windowsHint.Location = new System.Drawing.Point(150, 665);
_windowsHint.Name = "_windowsHint";
_windowsHint.Size = new System.Drawing.Size(90, 15);
- _windowsHint.TabIndex = 52;
+ _windowsHint.TabIndex = 54;
_windowsHint.Text = "cells (0: none)";
//
// _showLabel
//
_showLabel.AutoSize = true;
- _showLabel.Location = new System.Drawing.Point(6, 666);
+ _showLabel.Location = new System.Drawing.Point(6, 694);
_showLabel.Name = "_showLabel";
_showLabel.Size = new System.Drawing.Size(50, 15);
- _showLabel.TabIndex = 53;
+ _showLabel.TabIndex = 55;
_showLabel.Text = "Preview";
//
// _showWalls
@@ -755,10 +778,10 @@ private void InitializeComponent()
_showWalls.AutoSize = true;
_showWalls.Checked = true;
_showWalls.CheckState = System.Windows.Forms.CheckState.Checked;
- _showWalls.Location = new System.Drawing.Point(60, 664);
+ _showWalls.Location = new System.Drawing.Point(60, 692);
_showWalls.Name = "_showWalls";
_showWalls.Size = new System.Drawing.Size(56, 19);
- _showWalls.TabIndex = 54;
+ _showWalls.TabIndex = 56;
_showWalls.Text = "Walls";
_showWalls.UseVisualStyleBackColor = true;
_showWalls.CheckedChanged += Show_CheckedChanged;
@@ -768,10 +791,10 @@ private void InitializeComponent()
_showFloors.AutoSize = true;
_showFloors.Checked = true;
_showFloors.CheckState = System.Windows.Forms.CheckState.Checked;
- _showFloors.Location = new System.Drawing.Point(122, 664);
+ _showFloors.Location = new System.Drawing.Point(122, 692);
_showFloors.Name = "_showFloors";
_showFloors.Size = new System.Drawing.Size(60, 19);
- _showFloors.TabIndex = 55;
+ _showFloors.TabIndex = 57;
_showFloors.Text = "Floors";
_showFloors.UseVisualStyleBackColor = true;
_showFloors.CheckedChanged += Show_CheckedChanged;
@@ -781,20 +804,20 @@ private void InitializeComponent()
_showRoof.AutoSize = true;
_showRoof.Checked = true;
_showRoof.CheckState = System.Windows.Forms.CheckState.Checked;
- _showRoof.Location = new System.Drawing.Point(188, 664);
+ _showRoof.Location = new System.Drawing.Point(188, 692);
_showRoof.Name = "_showRoof";
_showRoof.Size = new System.Drawing.Size(52, 19);
- _showRoof.TabIndex = 56;
+ _showRoof.TabIndex = 58;
_showRoof.Text = "Roof";
_showRoof.UseVisualStyleBackColor = true;
_showRoof.CheckedChanged += Show_CheckedChanged;
//
// _undo
//
- _undo.Location = new System.Drawing.Point(6, 692);
+ _undo.Location = new System.Drawing.Point(6, 720);
_undo.Name = "_undo";
_undo.Size = new System.Drawing.Size(54, 25);
- _undo.TabIndex = 57;
+ _undo.TabIndex = 59;
_undo.Text = "Undo";
_undo.AutoEllipsis = true;
_undo.UseVisualStyleBackColor = true;
@@ -802,10 +825,10 @@ private void InitializeComponent()
//
// _redo
//
- _redo.Location = new System.Drawing.Point(62, 692);
+ _redo.Location = new System.Drawing.Point(62, 720);
_redo.Name = "_redo";
_redo.Size = new System.Drawing.Size(54, 25);
- _redo.TabIndex = 58;
+ _redo.TabIndex = 60;
_redo.Text = "Redo";
_redo.AutoEllipsis = true;
_redo.UseVisualStyleBackColor = true;
@@ -813,10 +836,10 @@ private void InitializeComponent()
//
// _place
//
- _place.Location = new System.Drawing.Point(122, 692);
+ _place.Location = new System.Drawing.Point(122, 720);
_place.Name = "_place";
_place.Size = new System.Drawing.Size(72, 25);
- _place.TabIndex = 59;
+ _place.TabIndex = 61;
_place.Text = "Place";
_place.AutoEllipsis = true;
_place.UseVisualStyleBackColor = true;
@@ -825,10 +848,10 @@ private void InitializeComponent()
// _drop
//
_drop.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _drop.Location = new System.Drawing.Point(196, 692);
+ _drop.Location = new System.Drawing.Point(196, 720);
_drop.Name = "_drop";
_drop.Size = new System.Drawing.Size(48, 25);
- _drop.TabIndex = 60;
+ _drop.TabIndex = 62;
_drop.Text = "Drop";
_drop.AutoEllipsis = true;
_drop.UseVisualStyleBackColor = true;
@@ -836,10 +859,10 @@ private void InitializeComponent()
//
// _saveDraft
//
- _saveDraft.Location = new System.Drawing.Point(6, 721);
+ _saveDraft.Location = new System.Drawing.Point(6, 749);
_saveDraft.Name = "_saveDraft";
_saveDraft.Size = new System.Drawing.Size(76, 25);
- _saveDraft.TabIndex = 61;
+ _saveDraft.TabIndex = 63;
_saveDraft.Text = "Save draft";
_saveDraft.AutoEllipsis = true;
_saveDraft.UseVisualStyleBackColor = true;
@@ -847,10 +870,10 @@ private void InitializeComponent()
//
// _openDraft
//
- _openDraft.Location = new System.Drawing.Point(84, 721);
+ _openDraft.Location = new System.Drawing.Point(84, 749);
_openDraft.Name = "_openDraft";
_openDraft.Size = new System.Drawing.Size(76, 25);
- _openDraft.TabIndex = 62;
+ _openDraft.TabIndex = 64;
_openDraft.Text = "Open draft";
_openDraft.AutoEllipsis = true;
_openDraft.UseVisualStyleBackColor = true;
@@ -859,10 +882,10 @@ private void InitializeComponent()
// _blueprint
//
_blueprint.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _blueprint.Location = new System.Drawing.Point(162, 721);
+ _blueprint.Location = new System.Drawing.Point(162, 749);
_blueprint.Name = "_blueprint";
_blueprint.Size = new System.Drawing.Size(82, 25);
- _blueprint.TabIndex = 63;
+ _blueprint.TabIndex = 65;
_blueprint.Text = "As blueprint";
_blueprint.AutoEllipsis = true;
_blueprint.UseVisualStyleBackColor = true;
@@ -871,10 +894,10 @@ private void InitializeComponent()
// _placedLabel
//
_placedLabel.AutoSize = true;
- _placedLabel.Location = new System.Drawing.Point(6, 755);
+ _placedLabel.Location = new System.Drawing.Point(6, 783);
_placedLabel.Name = "_placedLabel";
_placedLabel.Size = new System.Drawing.Size(60, 15);
- _placedLabel.TabIndex = 64;
+ _placedLabel.TabIndex = 66;
_placedLabel.Text = "Placed";
//
// _placed
@@ -882,18 +905,18 @@ private void InitializeComponent()
_placed.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
_placed.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
_placed.FormattingEnabled = true;
- _placed.Location = new System.Drawing.Point(60, 752);
+ _placed.Location = new System.Drawing.Point(60, 780);
_placed.Name = "_placed";
_placed.Size = new System.Drawing.Size(130, 23);
- _placed.TabIndex = 65;
+ _placed.TabIndex = 67;
//
// _edit
//
_edit.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right;
- _edit.Location = new System.Drawing.Point(196, 751);
+ _edit.Location = new System.Drawing.Point(196, 779);
_edit.Name = "_edit";
_edit.Size = new System.Drawing.Size(48, 25);
- _edit.TabIndex = 66;
+ _edit.TabIndex = 68;
_edit.Text = "Edit";
_edit.AutoEllipsis = true;
_edit.UseVisualStyleBackColor = true;
@@ -902,10 +925,10 @@ private void InitializeComponent()
// _status
//
_status.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
- _status.Location = new System.Drawing.Point(6, 781);
+ _status.Location = new System.Drawing.Point(6, 809);
_status.Name = "_status";
_status.Size = new System.Drawing.Size(238, 32);
- _status.TabIndex = 67;
+ _status.TabIndex = 69;
//
// HousePanel
//
@@ -914,7 +937,7 @@ private void InitializeComponent()
AutoScroll = true;
Controls.Add(houseBox);
Name = "HousePanel";
- Size = new System.Drawing.Size(250, 823);
+ Size = new System.Drawing.Size(250, 851);
houseBox.ResumeLayout(false);
houseBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)_storeys).EndInit();
@@ -970,7 +993,9 @@ private void InitializeComponent()
private System.Windows.Forms.Button _doorStyle;
private System.Windows.Forms.Label _stairStyleLabel;
private System.Windows.Forms.Button _stairStyle;
- private System.Windows.Forms.CheckBox _foundation;
+ private System.Windows.Forms.Label _foundationLabel;
+ private System.Windows.Forms.ComboBox _foundationKind;
+ private System.Windows.Forms.Label _foundationStyleLabel;
private System.Windows.Forms.Button _foundationStyle;
private System.Windows.Forms.Label _baseZLabel;
private System.Windows.Forms.NumericUpDown _baseZ;
diff --git a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
index 30a9db17..844e22a9 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs
@@ -56,6 +56,7 @@ public HousePanel()
_floorButtons[k].Click += (_, _) => PickStyle?.Invoke(HousePartKind.Floor, storey);
}
+ _foundationKind.DropDownWidth = 240;
_doorStyle.Click += (_, _) => PickStyle?.Invoke(HousePartKind.Door, 0);
_stairStyle.Click += (_, _) => PickStyle?.Invoke(HousePartKind.Stair, 0);
_foundationStyle.Click += (_, _) => PickStyle?.Invoke(HousePartKind.Wall, FoundationPick);
@@ -194,7 +195,7 @@ public void RefreshDraft()
// A flat roof is laid in a floor style of its own; the button picks that one then.
bool flat = !house.NoRoof && house.Shape == RoofShape.Flat;
Show(_roofStyle, flat ? house.Draft.FlatRoofStyle : house.Draft.RoofStyle, flat ? "(top floor's style)" : "(roof)", null);
- _foundation.Checked = house.Draft.Foundation;
+ RefreshFoundations(house);
Show(_doorStyle, house.Draft.DoorStyle, "(doors)", HouseDraft.DoorAlongX);
Show(_stairStyle, house.Draft.StairStyle, "(stairs)", null);
Show(_foundationStyle, house.Draft.FoundationStyle, "(light brick)", "South2");
@@ -547,9 +548,53 @@ private void RemoveWing_Click(object sender, EventArgs e)
Run(house => house.DeleteWing());
}
- private void Foundation_CheckedChanged(object sender, EventArgs e)
+ private const string _noFoundation = "None";
+ private const string _ownFoundation = "(your own)";
+
+ /// Lists the kinds of foundation this client can build and marks the one the house has.
+ private void RefreshFoundations(HouseTool house)
{
- Run(house => house.SetFoundation(_foundation.Checked));
+ IReadOnlyList kinds = house.Foundations;
+ bool same = _foundationKind.Items.Count == kinds.Count + 2;
+ for (int i = 0; same && i < kinds.Count; ++i)
+ {
+ same = ReferenceEquals(_foundationKind.Items[i + 1], kinds[i]);
+ }
+
+ if (!same)
+ {
+ _foundationKind.BeginUpdate();
+ _foundationKind.Items.Clear();
+ _foundationKind.Items.Add(_noFoundation);
+ foreach (HouseFoundation kind in kinds)
+ {
+ _foundationKind.Items.Add(kind);
+ }
+
+ _foundationKind.Items.Add(_ownFoundation);
+ _foundationKind.EndUpdate();
+ }
+
+ HouseFoundation current = house.CurrentFoundation();
+ _foundationKind.SelectedIndex = !house.Draft.Foundation ? 0 : current != null ? _foundationKind.Items.IndexOf(current) : _foundationKind.Items.Count - 1;
+ }
+
+ private void FoundationKind_SelectionChangeCommitted(object sender, EventArgs e)
+ {
+ if (_updating || _session == null)
+ {
+ return;
+ }
+
+ if (_foundationKind.SelectedItem is HouseFoundation kind)
+ {
+ Run(house => house.SetFoundation(kind));
+ }
+ else
+ {
+ // "(your own)" keeps what the house has and turns it on: the style button below changes it.
+ Run(house => house.SetFoundation(_foundationKind.SelectedIndex != 0));
+ }
}
private void BaseZ_ValueChanged(object sender, EventArgs e)
diff --git a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
index 6aa193e9..8d5c7a26 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/MultiEditorControl.cs
@@ -716,10 +716,10 @@ private void ChooseHouseStyle(HouseStyle style)
}
// A pick asked for by the house panel is a material of the draft, not a tool's style.
+ // It stays on, so one style after another can be tried, until Esc, another tool or
+ // another button of the panel ends it.
if (_housePick is { } pick && pick.Kind == style.Kind)
{
- _housePick = null;
- _housePanel.MarkPick(null, 0);
if (pick.Storey == HousePanel.FlatRoof)
{
Session.House.SetFlatRoofStyle(style);
@@ -739,10 +739,12 @@ private void ChooseHouseStyle(HouseStyle style)
CancelHousePick();
- // With the House tool in use, a wall, floor or roof style clicked on the House page is
- // a material of the house too: of the storey the chosen floor means, or of every
- // storey with all floors shown. Doors and stairs have tools of their own.
- if (Session.Tool == ToolKind.House && style.Kind is HousePartKind.Wall or HousePartKind.Floor or HousePartKind.Roof)
+ // With the House tool in use, a style clicked on the House page is a material of the
+ // house too: a wall or floor style of the storey the chosen floor means (of every
+ // storey with all floors shown), a roof, door or stair style of the whole house. To
+ // hang single doors or build stairs in another style, the Doors and Stairs tools are chosen first.
+ if (Session.Tool == ToolKind.House &&
+ style.Kind is HousePartKind.Wall or HousePartKind.Floor or HousePartKind.Roof or HousePartKind.Door or HousePartKind.Stair)
{
int? storey = style.Kind == HousePartKind.Roof || Session.WorkZ == null ? null : Session.DraftStorey;
Session.House.SetMaterial(style, storey);
@@ -793,7 +795,7 @@ private void PickHouseMaterial(HousePartKind kind, int storey)
: storey == HousePanel.FoundationPick ? "Pick the wall style of the foundation on the House page (a quarter wall suits it)."
: storey == HousePanel.FlatRoof ? "Pick the floor style of the flat roofs on the House page."
: $"Pick the {(kind == HousePartKind.Wall ? "wall" : "floor")} style of storey {storey + 1} on the House page.";
- _pickHint += " Esc cancels.";
+ _pickHint += " Click one style after another to try them; Esc ends.";
UpdateStatus();
}
@@ -2814,7 +2816,7 @@ private void UpdateStatus()
: session.PreviewingRepeat ? "The copies are shown as they would be placed."
: session.Pasting ? "Click to place the tiles, as often as you like. Esc or right click stops."
: session.ShapingRoof ? "Shaping: drag a wing to move it, a marked edge of the selected wing to resize it, anywhere else to add a wing. " +
- "Ctrl+drag moves all of it, Shift+click turns a ridge, Delete removes a wing, Ctrl+Z steps back. Enter places it, Esc drops it."
+ "Ctrl+drag moves all of it, Shift+corner drag makes a wing square, Shift+click turns a ridge, Delete removes a wing. Enter places it, Esc drops it."
: session.House.HasPending ? DraftHint(session)
: ToolHint(session.Tool);
diff --git a/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs b/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs
index 75b4a93a..d6844e8e 100644
--- a/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs
+++ b/UoFiddler.Plugin.MultiEditor/UI/ShortcutsForm.cs
@@ -64,6 +64,7 @@ public void ShowCommands(IEnumerable commands)
("Add a tile to the selection or take it out (Select)", "Ctrl + click"),
("Add to the selection (Select, Lasso)", "Ctrl + drag"),
("Pick the tile under the cursor (Draw, Rectangle, Line)", "Alt + click"),
+ ("Lower the tile instead of raising it (Altitude)", "Shift + click"),
("Keep the line straight (Line)", "Shift + drag"),
("One straight wall instead of a room (Walls)", "Shift + drag"),
("Erase walls (Walls)", "Ctrl + drag"),
@@ -78,12 +79,24 @@ public void ShowCommands(IEnumerable commands)
("Drop the roof being shaped (Roof)", "Esc"),
("Add a wing to the house draft (House)", "Drag out its wall cells"),
("Select, move, resize, turn or remove a wing (House)", "As with the roof's wings"),
+ ("Move the whole draft, with all it holds (Roof, House)", "Ctrl + drag a wing"),
+ ("Resize the selected wing as a square (Roof, House)", "Shift + drag one of its corners"),
("Step back and forth through the draft (Roof, House)", "Ctrl+Z / Ctrl+Y"),
("Partitions and openings in the house draft (Walls)", "Drag / Ctrl + drag"),
- ("Window in a wall of the house draft (Walls)", "Click the wall"),
- ("Door in the house draft (Doors)", "Click a wall; Ctrl + click removes"),
+ ("Window in a wall of the house draft, or wall again (Walls)", "Click the wall"),
+ ("Door in the house draft, then its next hinge side (Doors)", "Click a wall; Ctrl + click removes"),
+ ("Floor area in another style in the house draft (Floors)", "Drag the area"),
+ ("Stairs in the house draft (Stairs)", "Drag from the bottom step the way they climb; Ctrl + click removes"),
("Place the house on its layers (House and its draft tools)", "Enter"),
- ("Drop the house draft; undo brings it back (House)", "Esc"));
+ ("Drop the house draft; undo brings it back (House)", "Esc"),
+ ("End a style pick started in the House draft panel", "Esc, or pick another tool"));
+
+ Section("House draft panel",
+ ("Change a material: walls, floor, roof, doors, stairs, foundation", "Click its button, then styles on the House page"),
+ ("Try one style after another for that material", "Keep clicking styles; the button stays marked"),
+ ("Change the house's style of the kind shown, with the House tool", "Click a style on the House page"),
+ ("Start a tower, keep or castle", "Start as"),
+ ("Rooms of one storey only", "Choose the floor, then tick the storey box beside Layout"));
Section("Tile browser",
("Go from the search box to the results", "Down"),
@@ -95,7 +108,9 @@ public void ShowCommands(IEnumerable commands)
("Place a blueprint", "Click, Enter"),
("Rename a blueprint", "F2"),
("Delete a blueprint", "Delete"),
- ("Open UO Architect designs (Designs page)", "Enter, double click"));
+ ("Open UO Architect designs (Designs page)", "Enter, double click"),
+ ("Walk the styles of the House page", "Arrow keys, Home, End"),
+ ("Choose the style walked to", "Enter, click"));
Section("Selected tiles list",
("Take the chosen rows out of the selection", "Delete"),
From ce0b05f54255989d3c74e59c7325d06adedb48ab Mon Sep 17 00:00:00 2001
From: AsY!um- <377468+AsYlum-@users.noreply.github.com>
Date: Thu, 19 Nov 2026 23:26:29 +0100
Subject: [PATCH 11/16] Copy, paste and duplicate a wing of a roof or house
draft
---
.../Classes/HouseDraft.cs | 74 +++++++
.../Tools/HouseTool.cs | 24 +++
.../Tools/WingDraftTool.cs | 186 +++++++++++++++++-
.../UI/HousePanel.Designer.cs | 16 ++
UoFiddler.Plugin.MultiEditor/UI/HousePanel.cs | 7 +
.../UI/MultiEditorControl.cs | 49 ++++-
.../UI/ShortcutsForm.cs | 3 +
7 files changed, 351 insertions(+), 8 deletions(-)
diff --git a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
index d2e4d4e7..14b1b961 100644
--- a/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
+++ b/UoFiddler.Plugin.MultiEditor/Classes/HouseDraft.cs
@@ -793,6 +793,80 @@ void MoveOnStoreys(HashSet<(int Storey, int X, int Y)> set)
}
}
+ ///
+ /// What was changed by hand inside a wing, for a copy of the wing: walls added and taken
+ /// away, doors, windows, floor areas and stairs whose cell lies in the box.
+ ///
+ public HouseDraft CopyWithin((int X0, int Y0, int X1, int Y1) box)
+ {
+ bool In(int x, int y) => x >= box.X0 && x <= box.X1 && y >= box.Y0 && y <= box.Y1;
+ var part = new HouseDraft();
+ for (int k = 0; k < MaxStoreys; ++k)
+ {
+ part.AddedSouth[k].UnionWith(AddedSouth[k].Where(c => In(c.X, c.Y)));
+ part.AddedEast[k].UnionWith(AddedEast[k].Where(c => In(c.X, c.Y)));
+ part.ErasedSouth[k].UnionWith(ErasedSouth[k].Where(c => In(c.X, c.Y)));
+ part.ErasedEast[k].UnionWith(ErasedEast[k].Where(c => In(c.X, c.Y)));
+ }
+
+ foreach (var door in Doors)
+ {
+ if (In(door.Key.X, door.Key.Y))
+ {
+ part.Doors[door.Key] = door.Value;
+ }
+ }
+
+ part.Windows.UnionWith(Windows.Where(c => In(c.X, c.Y)));
+ part.Suppressed.UnionWith(Suppressed.Where(c => In(c.X, c.Y)));
+ part.FloorAreas.AddRange(FloorAreas.Where(a => In(a.X0, a.Y0) && In(a.X1, a.Y1)));
+ part.Stairs.AddRange(Stairs.Where(s => In(s.X, s.Y)));
+ return part;
+ }
+
+ /// Adds what took, moved by this many cells: the hand edits of a pasted wing.
+ public void AddShifted(HouseDraft part, int dx, int dy)
+ {
+ HouseDraft moved = part.Clone();
+ moved.Shift(dx, dy);
+
+ // Where the pasted wing says otherwise, it wins: a wall added there is no longer
+ // taken away, a door replaces a window, and the reverse.
+ for (int k = 0; k < MaxStoreys; ++k)
+ {
+ ErasedSouth[k].ExceptWith(moved.AddedSouth[k]);
+ ErasedEast[k].ExceptWith(moved.AddedEast[k]);
+ AddedSouth[k].ExceptWith(moved.ErasedSouth[k]);
+ AddedEast[k].ExceptWith(moved.ErasedEast[k]);
+ AddedSouth[k].UnionWith(moved.AddedSouth[k]);
+ AddedEast[k].UnionWith(moved.AddedEast[k]);
+ ErasedSouth[k].UnionWith(moved.ErasedSouth[k]);
+ ErasedEast[k].UnionWith(moved.ErasedEast[k]);
+ }
+
+ foreach (var door in moved.Doors)
+ {
+ Doors[door.Key] = door.Value;
+ Windows.Remove(door.Key);
+ }
+
+ foreach (var window in moved.Windows)
+ {
+ Windows.Add(window);
+ Doors.Remove(window);
+ }
+
+ Suppressed.UnionWith(moved.Suppressed);
+ FloorAreas.AddRange(moved.FloorAreas);
+
+ // A stair already starting in a cell gives way to the pasted one.
+ foreach (var stair in moved.Stairs)
+ {
+ Stairs.RemoveAll(s => s.Storey == stair.Storey && s.X == stair.X && s.Y == stair.Y);
+ Stairs.Add(stair);
+ }
+ }
+
/// Moves everything changed by hand along with the house.
public void Shift(int dx, int dy)
{
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
index 1fd0cdf0..1e56f92a 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/HouseTool.cs
@@ -275,6 +275,26 @@ protected override void WingMoved(RoofWing before, int dx, int dy, object extraA
}
}
+ protected override object CopyWingExtra(RoofWing wing) => _draft.CopyWithin(wing.Box);
+
+ protected override void WingPasted(object extraAtStart, object copied, int dx, int dy)
+ {
+ // Walls, doors, windows, floor areas and stairs set by hand in the copied wing come with it.
+ if (extraAtStart is HouseDraft start)
+ {
+ _draft = start.Clone();
+ if (copied is HouseDraft part)
+ {
+ _draft.AddShifted(part, dx, dy);
+ }
+
+ ++_version;
+ }
+ }
+
+ /// Every wing of a house stands on its ground floor.
+ protected override int PastedWingZ(RoofWing copy) => BaseZ;
+
protected override void DraftMoved(int dx, int dy)
{
// Walls, doors, windows, floor areas and stairs set by hand go with the house.
@@ -289,6 +309,9 @@ protected override void RestoreExtra(object extra)
++_version;
}
+ // A step made outside Edit (a move, a paste) ends a run: the next change is a step of its own.
+ protected override void StepPushed() => _lastRun = null;
+
// ---------------------------------------------------------------- changes to the draft
// What the last step of the history changed, when steps of that kind run together (a
@@ -321,6 +344,7 @@ public void StylesReloaded()
}
_draft.Remap(Context.HouseStyles.Successor);
+ RemapCopies(copied => (copied as HouseDraft)?.Remap(Context.HouseStyles.Successor));
++_version;
RaiseChanged();
}
diff --git a/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs b/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
index 016d2fc6..da9b1f0f 100644
--- a/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
+++ b/UoFiddler.Plugin.MultiEditor/Tools/WingDraftTool.cs
@@ -109,6 +109,7 @@ public void CopyFrom(RoofWing other)
/// The first stroke starts a draft, shown as it will be built. Then: click a wing to select
/// it, drag it to move it, drag an outermost row or column of the selected wing to resize
/// it, drag anywhere else to add a wing, Shift+click to turn one, Delete to remove one.
+ /// A copied or duplicated wing follows the mouse until a click drops it.
/// Nothing is written to the multi until ; drops
/// the draft. Every change to the draft is a step of its own undo history, which
/// and walk; dropping the draft is such a
@@ -123,7 +124,10 @@ private enum DragKind
None,
New,
Move,
- Resize
+ Resize,
+
+ /// A pasted wing following the mouse until a click drops it.
+ Float
}
private sealed class State
@@ -160,6 +164,14 @@ private sealed class State
private bool _north;
private bool _south;
+ // The copied wing and what the tool keeps of it besides (a house's hand edits inside it).
+ private RoofWing _clipWing;
+ private object _clipExtra;
+
+ // A pasted wing on the mouse: the wing it was copied from, as it stood, and what came with it.
+ private RoofWing _floatSource;
+ private object _floatExtra;
+
// The last placement, so undoing it in the multi can bring the draft back.
private State _placed;
private List _placedHistory;
@@ -212,7 +224,7 @@ public int SelectedIndex
public override (int Width, int Height)? DragSize => _drag switch
{
DragKind.New => (Math.Abs(_endX - _startX) + 1, Math.Abs(_endY - _startY) + 1),
- DragKind.Resize or DragKind.Move when SelectedWing is { } wing => (wing.X1 - wing.X0 + 1, wing.Y1 - wing.Y0 + 1),
+ DragKind.Resize or DragKind.Move or DragKind.Float when SelectedWing is { } wing => (wing.X1 - wing.X0 + 1, wing.Y1 - wing.Y0 + 1),
_ => null
};
@@ -271,6 +283,20 @@ protected virtual void DraftMoved(int dx, int dy)
{
}
+ /// What a copy of this wing takes along besides the wing itself.
+ protected virtual object CopyWingExtra(RoofWing wing) => null;
+
+ ///
+ /// A pasted wing stands this far from the wing it was copied from: what came with it is
+ /// laid there, onto , what the draft kept before the paste.
+ ///
+ protected virtual void WingPasted(object extraAtStart, object copied, int dx, int dy)
+ {
+ }
+
+ /// The Z a pasted wing stands at.
+ protected virtual int PastedWingZ(RoofWing copy) => copy.EaveZ;
+
protected virtual void RestoreExtra(object extra)
{
}
@@ -342,12 +368,40 @@ private void Push(State state)
_redo.Clear();
ReopenedFrom = null;
+ StepPushed();
+ }
+
+ /// Called when a step was added to the draft's history.
+ protected virtual void StepPushed()
+ {
+ }
+
+ /// Runs on what copied wings took along besides themselves.
+ protected void RemapCopies(Action