From d3a816f3e3f2d295cedb79535a886f67a32db600 Mon Sep 17 00:00:00 2001 From: shibbo Date: Tue, 7 Nov 2023 02:39:31 -0500 Subject: [PATCH] fix issue that caused InternalRail nodes to be null on save --- Fushigi.Byml/BymlArrayNode.cs | 4 +- Fushigi/course/CourseUnit.cs | 2 +- Fushigi/ui/CourseAreaEditContext.cs | 8 ++++ Fushigi/ui/widgets/LevelViewport.cs | 61 ++++++++++++++++++++++++++++- 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/Fushigi.Byml/BymlArrayNode.cs b/Fushigi.Byml/BymlArrayNode.cs index 5dfc0818..2a35990d 100644 --- a/Fushigi.Byml/BymlArrayNode.cs +++ b/Fushigi.Byml/BymlArrayNode.cs @@ -10,7 +10,9 @@ public class BymlArrayNode : IBymlNode public IBymlNode this[int i] => Array[i]; - public BymlArrayNode() { } + public BymlArrayNode() { + Array = new List(); + } public BymlArrayNode(Byml by, Stream stream) { diff --git a/Fushigi/course/CourseUnit.cs b/Fushigi/course/CourseUnit.cs index cbf5e782..301a5998 100644 --- a/Fushigi/course/CourseUnit.cs +++ b/Fushigi/course/CourseUnit.cs @@ -129,7 +129,7 @@ BymlHashTable SaveRail(Rail rail) BymlHashTable railNode = new(); railNode.AddNode(BymlNodeId.Bool, BymlUtil.CreateNode("IsClosed", rail.IsClosed), "IsClosed"); - BymlArrayNode pointsArrayNode = new((uint)rail.mPoints.Count); + BymlArrayNode pointsArrayNode = new(); foreach (System.Numerics.Vector3 point in rail.mPoints) { diff --git a/Fushigi/ui/CourseAreaEditContext.cs b/Fushigi/ui/CourseAreaEditContext.cs index a39fb5cd..ed5d9e9b 100644 --- a/Fushigi/ui/CourseAreaEditContext.cs +++ b/Fushigi/ui/CourseAreaEditContext.cs @@ -1,6 +1,7 @@ using Fushigi.course; using Fushigi.ui.undo; using Fushigi.ui.widgets; +using Fushigi.util; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -18,6 +19,8 @@ class CourseAreaEditContext(CourseArea area) public ulong SelectionVersion { get; private set; } = 0; + private bool mHasDialog = false; + public void Undo() => mUndoHandler.Undo(); public void Redo() => mUndoHandler.Redo(); @@ -140,5 +143,10 @@ public void DeleteSelectedActors() mUndoHandler.EndUndoCollection(); } + + public bool IsActorDestForLink(CourseActor actor) + { + return area.mLinkHolder.GetLinkWithDestHash(actor.GetHash()) != null; + } } } diff --git a/Fushigi/ui/widgets/LevelViewport.cs b/Fushigi/ui/widgets/LevelViewport.cs index 843b6781..3952aa08 100644 --- a/Fushigi/ui/widgets/LevelViewport.cs +++ b/Fushigi/ui/widgets/LevelViewport.cs @@ -18,6 +18,8 @@ using Silk.NET.OpenGL; using Fushigi.gl; using Fushigi.util; +using System.Reflection.PortableExecutable; +using static Fushigi.util.MessageBox; namespace Fushigi.ui.widgets { @@ -31,6 +33,7 @@ internal class LevelViewport(CourseArea area, GL gl, CourseAreaEditContext editC ImDrawListPtr mDrawList; public EditorMode mEditorMode = EditorMode.Actors; public EditorState mEditorState = EditorState.Selecting; + private bool mIsDialogOpen = false; Vector2 mSize = Vector2.Zero; @@ -58,6 +61,7 @@ public enum EditorState { Selecting, AddingActor, + DeleteActorLinkCheck, DeletingActor, SelectingLink } @@ -286,7 +290,7 @@ public void Draw(Vector2 size, IDictionary layersVisibility) if (ImGui.IsKeyDown(ImGuiKey.Delete)) { - mEditorState = EditorState.DeletingActor; + mEditorState = EditorState.DeleteActorLinkCheck; } if (ImGui.IsKeyDown(ImGuiKey.Escape)) @@ -323,6 +327,61 @@ public void Draw(Vector2 size, IDictionary layersVisibility) } } } + else if (isFocused && mEditorState == EditorState.DeleteActorLinkCheck) + { + var actors = mEditContext.GetSelectedObjects(); + string msgStr = ""; + + foreach (var actor in actors) + { + if (mEditContext.IsActorDestForLink(actor)) + { + var links = area.mLinkHolder.GetSrcHashesFromDest(actor.GetHash()); + + foreach (KeyValuePair> kvp in links) + { + var hashes = kvp.Value; + + foreach (var hash in hashes) + { + msgStr += $"{area.mActorHolder[hash].mActorName} [{area.mActorHolder[hash].mName}]\n"; + } + } + } + } + + /*MessageBox box = new MessageBox(MessageBox.MessageBoxType.YesNo); + MessageBox.MessageBoxResult res; + + if ((res = box.Show("Link Warning", $"The actor you are about to delete is a destination link for another actor.\n {msgStr} Do you wish to continue?")) != MessageBox.MessageBoxResult.Waiting) + { + if (res == MessageBox.MessageBoxResult.Yes) + { + + } + }*/ + + bool status = ImGui.Begin("Link Warning"); + ImGui.Text($"The actor you are about to delete is a destination link for another actor.\n {msgStr} Do you wish to continue?"); + + if (ImGui.Button("Yes")) + { + + } + + ImGui.SameLine(); + + if (ImGui.Button("No")) + { + + } + + if (status) + { + ImGui.End(); + } + + } else if (isFocused && mEditorState == EditorState.DeletingActor) { if (mEditContext.IsAnySelected())