Skip to content

Commit

Permalink
add support for deleting an actor properly
Browse files Browse the repository at this point in the history
  • Loading branch information
shibbo committed Nov 7, 2023
1 parent d3a816f commit 3688114
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 55 deletions.
14 changes: 14 additions & 0 deletions Fushigi/course/CourseLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ public List<int> 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<string, List<ulong>> GetDestHashesFromSrc(ulong hash)
{
Dictionary<string, List<ulong>> hashes = [];
Expand Down
9 changes: 9 additions & 0 deletions Fushigi/ui/CourseAreaEditContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 46 additions & 2 deletions Fushigi/ui/widgets/CourseScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -242,6 +242,50 @@ private void SelectActor()
}
}

private void LinkDeletionCheck()
{
var actors = activeViewport.mEditContext.GetSelectedObjects<CourseActor>();
string msgStr = "";

foreach (var actor in actors)
{
if (activeViewport.mEditContext.IsActorDestForLink(actor))
{
var links = selectedArea.mLinkHolder.GetSrcHashesFromDest(actor.GetHash());

foreach (KeyValuePair<string, List<ulong>> 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");
Expand Down
54 changes: 1 addition & 53 deletions Fushigi/ui/widgets/LevelViewport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -329,58 +328,7 @@ public void Draw(Vector2 size, IDictionary<string, bool> layersVisibility)
}
else if (isFocused && mEditorState == EditorState.DeleteActorLinkCheck)
{
var actors = mEditContext.GetSelectedObjects<CourseActor>();
string msgStr = "";

foreach (var actor in actors)
{
if (mEditContext.IsActorDestForLink(actor))
{
var links = area.mLinkHolder.GetSrcHashesFromDest(actor.GetHash());

foreach (KeyValuePair<string, List<ulong>> 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)
{
Expand Down

0 comments on commit 3688114

Please sign in to comment.