Skip to content

Commit

Permalink
fix issue that caused InternalRail nodes to be null on save
Browse files Browse the repository at this point in the history
  • Loading branch information
shibbo committed Nov 7, 2023
1 parent fb67cb9 commit d3a816f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Fushigi.Byml/BymlArrayNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public class BymlArrayNode : IBymlNode

public IBymlNode this[int i] => Array[i];

public BymlArrayNode() { }
public BymlArrayNode() {
Array = new List<IBymlNode>();
}

public BymlArrayNode(Byml by, Stream stream)
{
Expand Down
2 changes: 1 addition & 1 deletion Fushigi/course/CourseUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ BymlHashTable SaveRail(Rail rail)
BymlHashTable railNode = new();
railNode.AddNode(BymlNodeId.Bool, BymlUtil.CreateNode<bool>("IsClosed", rail.IsClosed), "IsClosed");

BymlArrayNode pointsArrayNode = new((uint)rail.mPoints.Count);
BymlArrayNode pointsArrayNode = new();

foreach (System.Numerics.Vector3 point in rail.mPoints)
{
Expand Down
8 changes: 8 additions & 0 deletions Fushigi/ui/CourseAreaEditContext.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -140,5 +143,10 @@ public void DeleteSelectedActors()

mUndoHandler.EndUndoCollection();
}

public bool IsActorDestForLink(CourseActor actor)
{
return area.mLinkHolder.GetLinkWithDestHash(actor.GetHash()) != null;
}
}
}
61 changes: 60 additions & 1 deletion Fushigi/ui/widgets/LevelViewport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;

Expand Down Expand Up @@ -58,6 +61,7 @@ public enum EditorState
{
Selecting,
AddingActor,
DeleteActorLinkCheck,
DeletingActor,
SelectingLink
}
Expand Down Expand Up @@ -286,7 +290,7 @@ public void Draw(Vector2 size, IDictionary<string, bool> layersVisibility)

if (ImGui.IsKeyDown(ImGuiKey.Delete))
{
mEditorState = EditorState.DeletingActor;
mEditorState = EditorState.DeleteActorLinkCheck;
}

if (ImGui.IsKeyDown(ImGuiKey.Escape))
Expand Down Expand Up @@ -323,6 +327,61 @@ 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)
{
if (mEditContext.IsAnySelected<CourseActor>())
Expand Down

0 comments on commit d3a816f

Please sign in to comment.