From 3688114be633f90ee01fbbed3d76cbb715a4de16 Mon Sep 17 00:00:00 2001 From: shibbo Date: Tue, 7 Nov 2023 03:09:10 -0500 Subject: [PATCH] add support for deleting an actor properly --- Fushigi/course/CourseLink.cs | 14 ++++++++ Fushigi/ui/CourseAreaEditContext.cs | 9 +++++ Fushigi/ui/widgets/CourseScene.cs | 48 +++++++++++++++++++++++-- Fushigi/ui/widgets/LevelViewport.cs | 54 +---------------------------- 4 files changed, 70 insertions(+), 55 deletions(-) diff --git a/Fushigi/course/CourseLink.cs b/Fushigi/course/CourseLink.cs index 4fdafa60..765ad35a 100644 --- a/Fushigi/course/CourseLink.cs +++ b/Fushigi/course/CourseLink.cs @@ -87,6 +87,20 @@ public List DoSanityCheck(CourseActorHolder actorHolder) return badLinks; } + public void DeleteLinkWithDest(ulong hash) + { + int idx = -1; + foreach (CourseLink link in mLinks) + { + if (link.GetDestHash() == hash) + { + idx = mLinks.IndexOf(link); + } + } + + mLinks.RemoveAt(idx); + } + public Dictionary> GetDestHashesFromSrc(ulong hash) { Dictionary> hashes = []; diff --git a/Fushigi/ui/CourseAreaEditContext.cs b/Fushigi/ui/CourseAreaEditContext.cs index ed5d9e9b..e7f6593b 100644 --- a/Fushigi/ui/CourseAreaEditContext.cs +++ b/Fushigi/ui/CourseAreaEditContext.cs @@ -139,11 +139,20 @@ public void DeleteSelectedActors() mUndoHandler.BeginUndoCollection(); foreach (var actor in selectedActors) + { + DeleteLinksWithDestHash(actor.GetHash()); DeleteActor(actor); + } + mUndoHandler.EndUndoCollection(); } + public void DeleteLinksWithDestHash(ulong hash) + { + area.mLinkHolder.DeleteLinkWithDest(hash); + } + public bool IsActorDestForLink(CourseActor actor) { return area.mLinkHolder.GetLinkWithDestHash(actor.GetHash()) != null; diff --git a/Fushigi/ui/widgets/CourseScene.cs b/Fushigi/ui/widgets/CourseScene.cs index 6eaf9869..3fb14577 100644 --- a/Fushigi/ui/widgets/CourseScene.cs +++ b/Fushigi/ui/widgets/CourseScene.cs @@ -77,9 +77,9 @@ public void DrawUI(GL gl) SelectActor(); } - if (mShowErrors) + if (activeViewport.mEditorState == LevelViewport.EditorState.DeleteActorLinkCheck) { - CourseErrorList(); + LinkDeletionCheck(); } ulong selectionVersionBefore = activeViewport.mEditContext.SelectionVersion; @@ -242,6 +242,50 @@ private void SelectActor() } } + private void LinkDeletionCheck() + { + var actors = activeViewport.mEditContext.GetSelectedObjects(); + string msgStr = ""; + + foreach (var actor in actors) + { + if (activeViewport.mEditContext.IsActorDestForLink(actor)) + { + var links = selectedArea.mLinkHolder.GetSrcHashesFromDest(actor.GetHash()); + + foreach (KeyValuePair> kvp in links) + { + var hashes = kvp.Value; + + foreach (var hash in hashes) + { + msgStr += $"{selectedArea.mActorHolder[hash].mActorName} [{selectedArea.mActorHolder[hash].mName}]\n"; + } + } + } + } + + bool status = ImGui.Begin("Link Warning"); + ImGui.Text($"The actor you are about to delete is a destination link for the following actors.\n {msgStr} Do you wish to continue?"); + + if (ImGui.Button("Yes")) + { + activeViewport.mEditorState = LevelViewport.EditorState.DeletingActor; + } + + ImGui.SameLine(); + + if (ImGui.Button("No")) + { + activeViewport.mEditorState = LevelViewport.EditorState.Selecting; + } + + if (status) + { + ImGui.End(); + } + } + private void CourseErrorList() { bool status = ImGui.Begin("Course Saving Errors"); diff --git a/Fushigi/ui/widgets/LevelViewport.cs b/Fushigi/ui/widgets/LevelViewport.cs index 3952aa08..c8fc6593 100644 --- a/Fushigi/ui/widgets/LevelViewport.cs +++ b/Fushigi/ui/widgets/LevelViewport.cs @@ -33,7 +33,6 @@ 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; @@ -329,58 +328,7 @@ 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) {