From f1079293ffd2c40d789a614ecf8b47cc0cd163ca Mon Sep 17 00:00:00 2001 From: wildham0 <64616385+wildham0@users.noreply.github.com> Date: Sun, 17 Mar 2024 23:17:48 -0400 Subject: [PATCH] Code cleanup --- DockPicker.cs | 40 ++++---- EditorTasks.cs | 96 ++++++++++++++++++ Game1.cs | 65 ++++++------ MapObjectPicker.cs | 25 +++-- OptionPicker.cs | 1 + Overworld.cs | 33 ++++++ TilePicker.cs | 27 ++--- WindowsManager.cs | 244 +++++++++------------------------------------ 8 files changed, 261 insertions(+), 270 deletions(-) create mode 100644 EditorTasks.cs diff --git a/DockPicker.cs b/DockPicker.cs index 5209a8a..4e4cd4a 100644 --- a/DockPicker.cs +++ b/DockPicker.cs @@ -11,12 +11,14 @@ namespace FFRMapEditorMono { public class DockPicker : OptionPicker { - public DockPicker(Texture2D _window, Texture2D _selector, Texture2D _placedicons, SpriteFont _font) + private Overworld overworld; + public DockPicker(Texture2D _window, Texture2D _selector, Texture2D _placedicons, SpriteFont _font, Overworld _overworld) { optionsWindow = _window; optionSelector = _selector; optionIcons = _placedicons; optionFont = _font; + overworld = _overworld; Position = new Vector2(64, 0); zoom = 1.0f; @@ -28,7 +30,7 @@ public DockPicker(Texture2D _window, Texture2D _selector, Texture2D _placedicons new List() { new EditorTask() { Type = EditorTasks.DocksUpdate, Value = i } }, new List() { - new EditorTask() { Type = EditorTasks.DocksUpdate, Value = i } } + new EditorTask() { Type = EditorTasks.DocksRemove, Value = i } } )).ToList(); Show = false; @@ -38,26 +40,28 @@ public DockPicker(Texture2D _window, Texture2D _selector, Texture2D _placedicons SetOptionTextLength(); showPlaced = true; } - public void UpdatePlaced(Overworld overworld) + public override void ProcessTasks(List tasks) { - if (!overworld.UpdatePlacedDocks) - { - return; - } + var validtasks = tasks.ToList(); - placedOptions = overworld.GetShipData().Select(d => (int)d.TeleporterIndex).ToList(); - if (placedOptions.Contains((int)OverworldTeleportIndex.None)) + foreach (var task in validtasks) { - placedOptions.RemoveAll(o => o == (int)OverworldTeleportIndex.None); - placedOptions.Add((int)OverworldTeleportIndex.DefaultLocation); - unplacedOptions = new(); + if (task.Type == EditorTasks.UpdatePlacedDocksOverlay) + { + placedOptions = overworld.GetShipData().Select(d => (int)d.TeleporterIndex).ToList(); + if (placedOptions.Contains((int)OverworldTeleportIndex.None)) + { + placedOptions.RemoveAll(o => o == (int)OverworldTeleportIndex.None); + placedOptions.Add((int)OverworldTeleportIndex.DefaultLocation); + unplacedOptions = new(); + } + else + { + unplacedOptions.Add((int)OverworldTeleportIndex.DefaultLocation); + } + tasks.Remove(task); + } } - else - { - unplacedOptions.Add((int)OverworldTeleportIndex.DefaultLocation); - } - - overworld.UpdatePlacedDocks = false; } } } \ No newline at end of file diff --git a/EditorTasks.cs b/EditorTasks.cs new file mode 100644 index 0000000..4f0cf66 --- /dev/null +++ b/EditorTasks.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Collections; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace FFRMapEditorMono +{ + public enum EditorTasks + { + None, + + ToggleInfoWindow, + HideAllWindows, + + FileCreateNewMap, + FileLoadMap, + FileSaveMap, + //FileSaveMapAs, + + OverworldBlueMap, + OverworldLoadMap, + + TilesOpen, + TilesToggle, + TilesSetTool, + TilesUpdate, + TilesPickerUpdate, + + BrushesOpen, + BrushesToggle, + BrushesSetTool, + BrushesUpdate, + BrushesPickerUpdate, + BrushesUpdateSize, + + DocksOpen, + DocksUpdate, + DocksSetTool, + DocksRemove, + + DomainsOpen, + DomainsUpdate, + DomainsSetTool, + + TemplatesOpen, + TemplatesUpdate, + //TemplatesSetTool, + + MapObjectsOpen, + MapObjectsUpdate, + MapObjectsSetTool, + MapObjectsRemove, + + WindowsClose, + + ExitWarningOpen, + ExitWarningClose, + + SaveWarningOpen, + SaveWarningClose, + SaveNoWarning, + SetSavingMode, + SaveWarningUpdate, + + NewMapWarningOpen, + NewMapWarningClose, + + LoadMapWarningOpen, + LoadMapWarningClose, + + PaintingUndo, + PaintingRedo, + + UpdatePlacedObjectsOverlay, + UpdatePlacedDocksOverlay, + UpdatePlacedTilesOverlay, + + SaveBackupMap, + ResetBackupCounter, + + ExitProgramHard, + ExitProgram + + } + + public struct EditorTask + { + public EditorTasks Type { get; set; } + public int Value { get; set; } + } +} \ No newline at end of file diff --git a/Game1.cs b/Game1.cs index 391b71f..ee4a4b7 100644 --- a/Game1.cs +++ b/Game1.cs @@ -15,16 +15,11 @@ public class Game1 : Game private GraphicsDeviceManager _graphics; private SpriteBatch _spriteBatch; private Overworld overworld; - private TilePicker tilePicker; - private BrushPicker brushPicker; - private DomainPicker domainsPicker; - private DockPicker docksPicker; - private MapObjectPicker mapObjectsPicker; - private TemplatePicker templatesPicker; private ToolsMenu toolsMenu; private InfoWindow infoWindow; private List warningWindows; + private List optionPickers; private Point windowSize = new(1200, 800); private SpriteFont font; @@ -33,6 +28,7 @@ public class Game1 : Game private MouseState mouse; private List editorTasks; private WindowsManager windowsManager; + private bool LastActiveState = true; private List unplacedTiles; private int suspendKeyboard = 0; @@ -96,14 +92,18 @@ protected override void LoadContent() // Create menus toolsMenu = new(toolsTexture, selectors32, font); - domainsPicker = new(domainGroupsIcons, selectors32, font); - docksPicker = new(docksIcons, selectors32, placingIcons, font); - brushPicker = new(brushesTexture, selectors16, font); - templatesPicker = new(templatesIcons, selectors32, font); infoWindow = new(infowindowtexture, font, buttonTexture, windowSize); - mapObjectsPicker = new(mapobjectsIcons, selectors16, placingIcons, font); currentTool = new(); - tilePicker = new(tileSetTexture, selectors16, placingIcons, font); + + optionPickers = new() + { + new DomainPicker(domainGroupsIcons, selectors32, font), + new TemplatePicker(templatesIcons, selectors32, font), + new DockPicker(docksIcons, selectors32, placingIcons, font, overworld), + new MapObjectPicker(mapobjectsIcons, selectors16, placingIcons, font, overworld), + new BrushPicker(brushesTexture, selectors16, font), + new TilePicker(tileSetTexture, selectors16, placingIcons, font, overworld) + }; // Warning Windows warningWindows = new() @@ -115,8 +115,9 @@ protected override void LoadContent() }; // Create Windows manager - windowsManager = new(toolsMenu, tilePicker, brushPicker, domainsPicker, docksPicker, mapObjectsPicker, templatesPicker, infoWindow); + windowsManager = new(toolsMenu, infoWindow); windowsManager.RegisterWarningWindows(warningWindows); + windowsManager.RegisterOptionPickers(optionPickers); } protected override void Update(GameTime gameTime) @@ -183,7 +184,6 @@ protected override void Update(GameTime gameTime) } } - // Remove None tasks editorTasks.RemoveAll(t => t.Type == EditorTasks.None); @@ -191,15 +191,14 @@ protected override void Update(GameTime gameTime) mouse.Update(); // Select Options - editorTasks.AddRange(tilePicker.PickOption(mouse)); editorTasks.AddRange(toolsMenu.PickOption(mouse)); - editorTasks.AddRange(domainsPicker.PickOption(mouse)); - editorTasks.AddRange(docksPicker.PickOption(mouse)); - editorTasks.AddRange(mapObjectsPicker.PickOption(mouse)); - editorTasks.AddRange(brushPicker.PickOption(mouse)); - editorTasks.AddRange(templatesPicker.PickOption(mouse)); editorTasks.AddRange(infoWindow.ProcessInput(mouse)); + foreach (var picker in optionPickers) + { + editorTasks.AddRange(picker.PickOption(mouse)); + } + foreach (var warning in warningWindows) { editorTasks.AddRange(warning.ProcessInput(mouse)); @@ -207,7 +206,7 @@ protected override void Update(GameTime gameTime) // Update Selected Tool currentTool.Update(editorTasks); - currentTool.GetTemplate(editorTasks, templatesPicker.CurrentTemplate); + currentTool.GetTemplate(editorTasks, optionPickers.OfType().First().CurrentTemplate); toolsMenu.UpdateBrushSize(currentTool.BrushSize + 1); // Interact with the map @@ -218,21 +217,20 @@ protected override void Update(GameTime gameTime) overworld.UpdateDomain(mouse, currentTool); overworld.UpdateDock(mouse, currentTool); overworld.UpdateMapObject(mouse, currentTool); - mapObjectsPicker.UpdatePlaced(overworld); - docksPicker.UpdatePlaced(overworld); - unplacedTiles = tilePicker.UpdatePlaced(overworld); editorTasks.AddRange(overworld.GetTile(mouse)); } // Update selected tiles - tilePicker.ProcessTasks(editorTasks); - brushPicker.ProcessTasks(editorTasks); + foreach (var picker in optionPickers) + { + picker.ProcessTasks(editorTasks); + } // Update Windows windowsManager.ProcessTasks(editorTasks, overworld); // Update File management - warningWindows.OfType().First().ProcessTasks(overworld, unplacedTiles, windowSize, editorTasks); + warningWindows.OfType().First().ProcessTasks(overworld, optionPickers.OfType().First().GetUnplacedTiles(), windowSize, editorTasks); fileManager.ProcessTasks(overworld, unplacedTiles, editorTasks); overworld.ProcessTasks(fileManager.OverworldData, editorTasks); @@ -273,17 +271,16 @@ protected override void Draw(GameTime gameTime) // Draw map+overlays overworld.Draw(_spriteBatch, windowsManager, currentTool, mouse); - + // Draw menus - tilePicker.Draw(_spriteBatch, font, mouse.Position); - brushPicker.Draw(_spriteBatch, font, mouse.Position); - domainsPicker.Draw(_spriteBatch, font, mouse.Position); - docksPicker.Draw(_spriteBatch, font, mouse.Position); - mapObjectsPicker.Draw(_spriteBatch, font, mouse.Position); - templatesPicker.Draw(_spriteBatch, font, mouse.Position); toolsMenu.Draw(_spriteBatch, font, mouse.Position); infoWindow.Draw(_spriteBatch); + foreach (var picker in optionPickers) + { + picker.Draw(_spriteBatch, font, mouse.Position); + } + foreach (var warning in warningWindows) { warning.Draw(_spriteBatch); diff --git a/MapObjectPicker.cs b/MapObjectPicker.cs index 81a95e0..f316b5b 100644 --- a/MapObjectPicker.cs +++ b/MapObjectPicker.cs @@ -10,13 +10,16 @@ namespace FFRMapEditorMono { public class MapObjectPicker : OptionPicker { - public MapObjectPicker(Texture2D _window, Texture2D _selector, Texture2D _placingicons, SpriteFont _font) + private Overworld overworld; + public MapObjectPicker(Texture2D _window, Texture2D _selector, Texture2D _placingicons, SpriteFont _font, Overworld _overworld) { optionsWindow = _window; optionSelector = _selector; optionIcons = _placingicons; optionFont = _font; + overworld = _overworld; + Position = new Vector2(64, 0); zoom = 2.0f; optionsRows = 1; @@ -25,10 +28,9 @@ public MapObjectPicker(Texture2D _window, Texture2D _selector, Texture2D _placin options = mapObjectsNames.Select((o, i) => (o.Item1, new List() { - new EditorTask() { Type = EditorTasks.MapObjectsUpdate, Value = i }, - new EditorTask() { Type = EditorTasks.WindowsClose, Value = 10 } }, + new EditorTask() { Type = EditorTasks.MapObjectsUpdate, Value = i } }, new List() { - new EditorTask() { Type = EditorTasks.MapObjectsUpdate, Value = i } } + new EditorTask() { Type = EditorTasks.MapObjectsRemove, Value = i } } )).ToList(); Show = false; @@ -48,15 +50,18 @@ public MapObjectPicker(Texture2D _window, Texture2D _selector, Texture2D _placin ("Ship (Unused)", EditorTasks.None, EditorTasks.None), ("Airship", EditorTasks.None, EditorTasks.None), }; - public void UpdatePlaced(Overworld overworld) + public override void ProcessTasks(List tasks) { - if (!overworld.UpdatePlacedMapObjects) + var validtasks = tasks.ToList(); + + foreach (var task in validtasks) { - return; + if (task.Type == EditorTasks.UpdatePlacedObjectsOverlay) + { + placedOptions = overworld.GetPlacedMapObjects().Select(o => (int)o).ToList(); + tasks.Remove(task); + } } - - placedOptions = overworld.GetPlacedMapObjects().Select(o => (int)o).ToList(); - overworld.UpdatePlacedMapObjects = false; } } } \ No newline at end of file diff --git a/OptionPicker.cs b/OptionPicker.cs index cdc39c1..41a501b 100644 --- a/OptionPicker.cs +++ b/OptionPicker.cs @@ -96,6 +96,7 @@ public bool MouseHovering(Vector2 mousecursor) return window.Contains(mousecursor) && Show; } + public virtual void ProcessTasks(List tasks) { } public virtual void Draw(SpriteBatch spriteBatch, SpriteFont font, Vector2 mouseCursor) { if (!Show) diff --git a/Overworld.cs b/Overworld.cs index a267639..c13d970 100644 --- a/Overworld.cs +++ b/Overworld.cs @@ -232,7 +232,40 @@ public void ProcessTasks(OwMapExchangeData mapdata, List tasks) Redo(); tasks.Remove(task); } + else if (task.Type == EditorTasks.DocksRemove) + { + int dockToRemove = (task.Value == (int)OverworldTeleportIndex.DefaultLocation) ? (int)OverworldTeleportIndex.None : task.Value; + + docks.RemoveAll(d => d.location == (OverworldTeleportIndex)dockToRemove); + UpdatePlacedDocks = true; + tasks.Remove(task); + } + else if (task.Type == EditorTasks.MapObjectsRemove) + { + mapObjects.RemoveAll(o => o.mapobject == (MapObject)task.Value); + UpdatePlacedMapObjects = true; + tasks.Remove(task); + } } + + if (UpdatePlacedMapObjects) + { + tasks.Add(new EditorTask() { Type = EditorTasks.UpdatePlacedObjectsOverlay }); + UpdatePlacedMapObjects = false; + } + + if (UpdatePlacedDocks) + { + tasks.Add(new EditorTask() { Type = EditorTasks.UpdatePlacedDocksOverlay }); + UpdatePlacedDocks = false; + } + + if (UpdatePlacedRequiredTiles) + { + tasks.Add(new EditorTask() { Type = EditorTasks.UpdatePlacedTilesOverlay }); + UpdatePlacedRequiredTiles = false; + } + } public byte[] GetOwBytes() diff --git a/TilePicker.cs b/TilePicker.cs index 90e110e..1a05263 100644 --- a/TilePicker.cs +++ b/TilePicker.cs @@ -35,7 +35,7 @@ public BrushPicker(Texture2D _window, Texture2D _selector, SpriteFont _font) SetOptionTextLength(); showPlaced = false; } - public void ProcessTasks(List tasks) + public override void ProcessTasks(List tasks) { var validtasks = tasks.ToList(); @@ -76,12 +76,14 @@ public void UpdateTile(byte tile) } public class TilePicker : OptionPicker { - public TilePicker(Texture2D _window, Texture2D _selector, Texture2D _placedicons, SpriteFont _font) + private Overworld overworld; + public TilePicker(Texture2D _window, Texture2D _selector, Texture2D _placedicons, SpriteFont _font, Overworld _overworld) { optionsWindow = _window; optionSelector = _selector; optionIcons = _placedicons; optionFont = _font; + overworld = _overworld; Show = false; Position = new Vector2(64, 0); @@ -100,9 +102,11 @@ public TilePicker(Texture2D _window, Texture2D _selector, Texture2D _placedicons SetOptionTextLength(); lastSelection = 0x00; + placedOptions = new(); + unplacedOptions = requiredTiles.Select(t => (int)t).ToList(); showPlaced = true; } - public void ProcessTasks(List tasks) + public override void ProcessTasks(List tasks) { var validtasks = tasks.ToList(); @@ -113,6 +117,12 @@ public void ProcessTasks(List tasks) lastSelection = task.Value; tasks.Remove(task); } + else if (task.Type == EditorTasks.UpdatePlacedTilesOverlay) + { + placedOptions = overworld.GetOwBytes().ToList().Intersect(requiredTiles).Select(t => (int)t).ToList(); + unplacedOptions = requiredTiles.Select(t => (int)t).Except(placedOptions).ToList(); + tasks.Remove(task); + } } } public void UpdateTile(byte tile) @@ -160,17 +170,8 @@ public void UpdateTile(byte tile) 0x6D, 0x6E }; - public List UpdatePlaced(Overworld overworld) + public List GetUnplacedTiles() { - if (!overworld.UpdatePlacedRequiredTiles) - { - return unplacedOptions.Select(t => TileNames[t]).ToList(); - } - - placedOptions = overworld.GetOwBytes().ToList().Intersect(requiredTiles).Select(t => (int)t).ToList(); - unplacedOptions = requiredTiles.Select(t => (int)t).Except(placedOptions).ToList(); - overworld.UpdatePlacedRequiredTiles = false; - return unplacedOptions.Select(t => TileNames[t]).ToList(); } private List TileNames = new() diff --git a/WindowsManager.cs b/WindowsManager.cs index e2681cb..17589b7 100644 --- a/WindowsManager.cs +++ b/WindowsManager.cs @@ -10,110 +10,21 @@ namespace FFRMapEditorMono { - public enum EditorTasks - { - None, - - ToggleInfoWindow, - HideAllWindows, - - FileCreateNewMap, - FileLoadMap, - FileSaveMap, - //FileSaveMapAs, - - OverworldBlueMap, - OverworldLoadMap, - - TilesOpen, - TilesToggle, - TilesSetTool, - TilesUpdate, - TilesPickerUpdate, - - BrushesOpen, - BrushesToggle, - BrushesSetTool, - BrushesUpdate, - BrushesPickerUpdate, - BrushesUpdateSize, - - DocksOpen, - DocksUpdate, - DocksSetTool, - - DomainsOpen, - DomainsUpdate, - DomainsSetTool, - - TemplatesOpen, - TemplatesUpdate, - //TemplatesSetTool, - - MapObjectsOpen, - MapObjectsUpdate, - MapObjectsSetTool, - - WindowsClose, - - ExitWarningOpen, - ExitWarningClose, - - SaveWarningOpen, - SaveWarningClose, - SaveNoWarning, - SetSavingMode, - SaveWarningUpdate, - - NewMapWarningOpen, - NewMapWarningClose, - - LoadMapWarningOpen, - LoadMapWarningClose, - - PaintingUndo, - PaintingRedo, - - SaveBackupMap, - ResetBackupCounter, - - ExitProgramHard, - ExitProgram - - } - - public struct EditorTask - { - public EditorTasks Type { get; set; } - public int Value { get; set; } - } - public class WindowsManager { private ToolsMenu ToolsWindow; - private TilePicker TilesWindow; - private DomainPicker DomainsWindow; - private DockPicker DocksWindow; - private MapObjectPicker MapObjectsWindow; - private BrushPicker BrushWindow; - private TemplatePicker TemplateWindow; private InfoWindow InfoWindow; - public bool ShowDomainOverlay { get => showDomainOverlay || DomainsWindow.Show; } - public bool ShowDockOverlay { get => showDockOverlay || DocksWindow.Show; } + public bool ShowDomainOverlay { get => showDomainOverlay || optionPickers.OfType().First().Show; } + public bool ShowDockOverlay { get => showDockOverlay || optionPickers.OfType().First().Show; } public bool ShowMapObjectsOverlay { get => showMapObjectsOverlay; } private bool showDomainOverlay; private bool showDockOverlay; private bool showMapObjectsOverlay; private List warningWindows; - public WindowsManager(ToolsMenu _toolsmenu, TilePicker _tilepicker, BrushPicker _brushpicker, DomainPicker _domainpicker, DockPicker _dockppicker, MapObjectPicker _mapobjectpicker, TemplatePicker _templatepicker, InfoWindow _infowindow) + private List optionPickers; + public WindowsManager(ToolsMenu _toolsmenu, InfoWindow _infowindow) { ToolsWindow = _toolsmenu; - TilesWindow = _tilepicker; - DomainsWindow = _domainpicker; - DocksWindow = _dockppicker; - BrushWindow = _brushpicker; - MapObjectsWindow = _mapobjectpicker; - TemplateWindow = _templatepicker; InfoWindow = _infowindow; showDomainOverlay = false; @@ -124,6 +35,10 @@ public void RegisterWarningWindows(List _windows) { warningWindows = _windows; } + public void RegisterOptionPickers(List _pickers) + { + optionPickers = _pickers; + } public bool CanInteractWithMap(Vector2 mousecursor) { bool cursorinwindow = false; @@ -132,26 +47,24 @@ public bool CanInteractWithMap(Vector2 mousecursor) cursorinwindow |= window.MouseHovering(mousecursor); } + foreach (var picker in optionPickers) + { + cursorinwindow |= picker.MouseHovering(mousecursor); + } + bool inTools = ToolsWindow.MouseHovering(mousecursor); - bool inTiles = TilesWindow.MouseHovering(mousecursor); - bool inDomains = DomainsWindow.MouseHovering(mousecursor); - bool inDocks = DocksWindow.MouseHovering(mousecursor); - bool inMapObjects = MapObjectsWindow.MouseHovering(mousecursor); - bool inBrushes = BrushWindow.MouseHovering(mousecursor); bool inInfoWindow = InfoWindow.MouseHovering(mousecursor); - bool inTemplates = TemplateWindow.MouseHovering(mousecursor); - return (!inTools && !inTiles && !inDomains && !inDocks && !inMapObjects && !inBrushes && !inInfoWindow && !inTemplates && !cursorinwindow); + return (!inTools && !inInfoWindow && !cursorinwindow); } private void HideAllWindows() { - TilesWindow.Show = false; - DomainsWindow.Show = false; - DocksWindow.Show = false; - MapObjectsWindow.Show = false; - BrushWindow.Show = false; + foreach (var picker in optionPickers) + { + picker.Show = false; + } + InfoWindow.Show = false; - TemplateWindow.Show = false; } public void ProcessTasks(List tasks, Overworld overworld) { @@ -159,25 +72,7 @@ public void ProcessTasks(List tasks, Overworld overworld) foreach (var task in validtasks) { - if (task.Type == EditorTasks.MapObjectsOpen) - { - if (!MapObjectsWindow.Show) - { - HideAllWindows(); - MapObjectsWindow.Show = true; - } - tasks.Remove(task); - } - else if (task.Type == EditorTasks.DocksOpen) - { - if (!DocksWindow.Show) - { - HideAllWindows(); - DocksWindow.Show = true; - } - tasks.Remove(task); - } - else if (task.Type == EditorTasks.ToggleInfoWindow) + if (task.Type == EditorTasks.ToggleInfoWindow) { if (task.Value > 0) { @@ -221,58 +116,7 @@ public void ProcessTasks(List tasks, Overworld overworld) tasks.Remove(task); } } - else if (task.Type == EditorTasks.TemplatesOpen) - { - if (!TemplateWindow.Show) - { - HideAllWindows(); - TemplateWindow.Show = true; - } - tasks.Remove(task); - } - else if (task.Type == EditorTasks.TilesOpen) - { - if (!TilesWindow.Show) - { - HideAllWindows(); - TilesWindow.Show = true; - } - tasks.Remove(task); - } - else if (task.Type == EditorTasks.BrushesOpen) - { - if (!BrushWindow.Show) - { - HideAllWindows(); - BrushWindow.Show = true; - } - tasks.Remove(task); - } - else if (task.Type == EditorTasks.DomainsOpen) - { - if (!DomainsWindow.Show) - { - HideAllWindows(); - DomainsWindow.Show = true; - } - tasks.Remove(task); - } - else if (task.Type == EditorTasks.TilesToggle) - { - if (task.Value > 0) - { - tasks.Add(new EditorTask() { Type = task.Type, Value = task.Value - 1 }); - tasks.Remove(task); - } - else - { - bool currentState = TilesWindow.Show; - HideAllWindows(); - TilesWindow.Show = !currentState; - tasks.Remove(task); - } - } - else if (task.Type == EditorTasks.BrushesToggle) + else if (toggleTaskToType.ContainsKey(task.Type)) { if (task.Value > 0) { @@ -281,13 +125,11 @@ public void ProcessTasks(List tasks, Overworld overworld) } else { - bool currentState = BrushWindow.Show; - HideAllWindows(); - BrushWindow.Show = !currentState; + optionPickers.ForEach(w => w.Show = w.GetType() == toggleTaskToType[task.Type] && !w.Show); tasks.Remove(task); } } - else if (closeTaskToWarning.ContainsKey(task.Type)) + else if (closeTaskToType.ContainsKey(task.Type)) { if (task.Value > 0) { @@ -296,32 +138,44 @@ public void ProcessTasks(List tasks, Overworld overworld) } else { - warningWindows.Find(w => w.Type == closeTaskToWarning[task.Type]).Show = false; + warningWindows.ForEach(w => w.Show = w.GetType() != closeTaskToType[task.Type] && w.Show); + optionPickers.ForEach(w => w.Show = w.GetType() != closeTaskToType[task.Type] && w.Show); tasks.Remove(task); } } - else if (openTaskToWarning.ContainsKey(task.Type)) + else if (openTaskToType.ContainsKey(task.Type)) { HideAllWindows(); - warningWindows.Find(w => w.Type == openTaskToWarning[task.Type]).Show = true; + warningWindows.ForEach(w => w.Show = w.GetType() == openTaskToType[task.Type]); + optionPickers.ForEach(w => w.Show = w.GetType() == openTaskToType[task.Type]); tasks.Remove(task); } } } - Dictionary openTaskToWarning = new() + static Dictionary closeTaskToType = new() { - { EditorTasks.ExitWarningOpen, WarningType.Exit }, - { EditorTasks.SaveWarningOpen, WarningType.SaveValidation }, - { EditorTasks.LoadMapWarningOpen, WarningType.LoadMap }, - { EditorTasks.NewMapWarningOpen, WarningType.NewMap }, + { EditorTasks.ExitWarningClose, typeof(ExitWarningWindow) }, + { EditorTasks.SaveWarningClose, typeof(SaveWarningWindow) }, + { EditorTasks.LoadMapWarningClose, typeof(LoadMapWarningWindow) }, + { EditorTasks.NewMapWarningClose, typeof(NewMapWarningWindow) }, }; - Dictionary closeTaskToWarning = new() + static Dictionary toggleTaskToType = new() { - { EditorTasks.ExitWarningClose, WarningType.Exit }, - { EditorTasks.SaveWarningClose, WarningType.SaveValidation }, - { EditorTasks.LoadMapWarningClose, WarningType.LoadMap }, - { EditorTasks.NewMapWarningClose, WarningType.NewMap }, - + { EditorTasks.BrushesToggle, typeof(BrushPicker) }, + { EditorTasks.TilesToggle, typeof(TilePicker) }, + }; + static Dictionary openTaskToType = new() + { + { EditorTasks.DomainsOpen, typeof(DomainPicker) }, + { EditorTasks.BrushesOpen, typeof(BrushPicker) }, + { EditorTasks.TilesOpen, typeof(TilePicker) }, + { EditorTasks.TemplatesOpen, typeof(TemplatePicker) }, + { EditorTasks.DocksOpen, typeof(DockPicker) }, + { EditorTasks.MapObjectsOpen, typeof(MapObjectPicker) }, + { EditorTasks.ExitWarningOpen, typeof(ExitWarningWindow) }, + { EditorTasks.SaveWarningOpen, typeof(SaveWarningWindow) }, + { EditorTasks.LoadMapWarningOpen, typeof(LoadMapWarningWindow) }, + { EditorTasks.NewMapWarningOpen, typeof(NewMapWarningWindow) }, }; }