From bb321eec34703eb0d5d6c423efe3a00915555f2d Mon Sep 17 00:00:00 2001 From: Donavin Draws <51259260+DonavinDraws@users.noreply.github.com> Date: Sat, 2 Mar 2024 16:49:46 -0600 Subject: [PATCH 1/2] Better Depth Sorting Depth Sorting caches and won't copy the list every frame. --- Fushigi/course/CourseActor.cs | 3 ++- Fushigi/course/CourseArea.cs | 10 ++++++++++ Fushigi/ui/widgets/LevelViewport.cs | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Fushigi/course/CourseActor.cs b/Fushigi/course/CourseActor.cs index 9d55bffd..e4facfab 100644 --- a/Fushigi/course/CourseActor.cs +++ b/Fushigi/course/CourseActor.cs @@ -284,7 +284,8 @@ public BymlArrayNode SerializeToArray(CourseLinkHolder linkHolder) return node; } - public List mActors = new List(); + public List mActors = []; + public List mSortedActors = []; } public class CourseActorRender //This can be overridden per actor for individual behavior diff --git a/Fushigi/course/CourseArea.cs b/Fushigi/course/CourseArea.cs index 74aeccd5..6f9e7b18 100644 --- a/Fushigi/course/CourseArea.cs +++ b/Fushigi/course/CourseArea.cs @@ -159,6 +159,16 @@ public IReadOnlyList GetActors() return mActorHolder.mActors; } + public IReadOnlyList GetSortedActors() + { + if (!mActorHolder.mActors.TrueForAll(mActorHolder.mSortedActors.Contains)) + { + mActorHolder.mSortedActors = new List(mActorHolder.mActors); + mActorHolder.mSortedActors.Sort((x, y) => x.mTranslation.Z.CompareTo(y.mTranslation.Z)); + } + return mActorHolder.mSortedActors; + } + public string mAreaName; public uint mRootHash; string mStageParams; diff --git a/Fushigi/ui/widgets/LevelViewport.cs b/Fushigi/ui/widgets/LevelViewport.cs index 1b7d01a6..3f70f409 100644 --- a/Fushigi/ui/widgets/LevelViewport.cs +++ b/Fushigi/ui/widgets/LevelViewport.cs @@ -364,7 +364,7 @@ TileBfresRender CreateTileRendererForSkin(SkinDivision division, string skinName // Actors are listed in the order they were pulled from the yaml. // So they are ordered by depth for rendering. - foreach (var actor in this.mArea.GetActors().OrderBy(x => x.mTranslation.Z)) + foreach (var actor in this.mArea.GetSortedActors()) { actor.wonderVisible = WonderViewMode == actor.mWonderView || WonderViewMode == WonderViewType.Normal || From 2421441b79bee567eaad5690faabb05d858b1e0f Mon Sep 17 00:00:00 2001 From: Donavin Draws <51259260+DonavinDraws@users.noreply.github.com> Date: Wed, 18 Sep 2024 12:59:49 -0500 Subject: [PATCH 2/2] Create Rails w/ Types --- Fushigi/course/CourseRail.cs | 29 +++++++++++++++++++----- Fushigi/ui/widgets/CourseScene.cs | 37 ++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/Fushigi/course/CourseRail.cs b/Fushigi/course/CourseRail.cs index 936c5fa2..0762cfd0 100644 --- a/Fushigi/course/CourseRail.cs +++ b/Fushigi/course/CourseRail.cs @@ -18,12 +18,30 @@ namespace Fushigi.course { public class CourseRail { - public CourseRail(uint areaHash) + public CourseRail(uint areaHash, string type = "Default") { + mType = type; mHash = RandomUtil.GetRandom(); mAreaHash = areaHash; - mRailParam = "Work/Gyml/Rail/RailParam/Default.game__rail__RailParam.gyml"; + mRailParam = "Work/Gyml/Rail/RailParam/"+type+".game__rail__RailParam.gyml"; mIsClosed = false; + var railParams = ParamDB.GetRailComponent(mType); + var railParent = ParamDB.GetRailComponentParent(railParams); + var comp = ParamDB.GetRailComponentParams(railParams); + if (railParent != "null") + { + var parentComp = ParamDB.GetRailComponentParams(railParent); + foreach (var component in parentComp) + { + comp.TryAdd(component.Key, component.Value); + } + } + + foreach (string component in comp.Keys) + { + var c = comp[component]; + mParameters.Add(component, c.InitValue); + } } public CourseRail(BymlHashTable node) @@ -33,8 +51,8 @@ public CourseRail(BymlHashTable node) mHash = BymlUtil.GetNodeData(node["Hash"]); mIsClosed = BymlUtil.GetNodeData(node["IsClosed"]); - string pointParam = Path.GetFileNameWithoutExtension(BymlUtil.GetNodeData(node["Gyaml"])).Split(".game")[0]; - var railParams = ParamDB.GetRailComponent(pointParam); + mType = Path.GetFileNameWithoutExtension(BymlUtil.GetNodeData(node["Gyaml"])).Split(".game")[0]; + var railParams = ParamDB.GetRailComponent(mType); var railParent = ParamDB.GetRailComponentParent(railParams); var comp = ParamDB.GetRailComponentParams(railParams); if (railParent != "null") @@ -76,7 +94,7 @@ public CourseRail(BymlHashTable node) foreach(BymlHashTable rail in railArray.Array) { - mPoints.Add(new CourseRailPoint(rail, pointParam)); + mPoints.Add(new CourseRailPoint(rail, mType)); } } @@ -131,6 +149,7 @@ public CourseRailPoint this[ulong hash] public uint mAreaHash; public string mRailParam; public ulong mHash; + public string mType; public bool mIsClosed; public List mPoints = new(); public Dictionary mParameters = new(); diff --git a/Fushigi/ui/widgets/CourseScene.cs b/Fushigi/ui/widgets/CourseScene.cs index 59c22c10..a206dc42 100644 --- a/Fushigi/ui/widgets/CourseScene.cs +++ b/Fushigi/ui/widgets/CourseScene.cs @@ -105,7 +105,19 @@ class CourseScene "DvFar9", "DvFar10" ]; - public static Regex NumberRegex = new(@"\d+"); + + public static readonly string[] RailTypes = [ + "Default", + "NextGoTo", + "BadgeChallenge", + "CRing", + "Scroll", + "SectionFrame", + "ShabonMove", + "SwitchON", + "SwitchOFF", + ]; + public static readonly Regex NumberRegex = new(@"\d+"); // This code sorts the layer order on the layer panel. // You can look through it before deciding if it's optimized enough to include. @@ -1146,7 +1158,7 @@ void ProcessRail(BGUnitRail rail) else if (editContext.IsSingleObjectSelected(out CourseRail? mSelectedRail)) { ImGui.AlignTextToFramePadding(); - ImGui.Text($"Selected Rail"); + ImGui.Text($"Selected {mSelectedRail.mType} Rail"); ImGui.NewLine(); ImGui.Separator(); @@ -1624,14 +1636,27 @@ void SelectRail() removed_tile_units.Clear(); } } - - private void CourseRailsView(CourseRailHolder railHolder) + private async void CourseRailsView(CourseRailHolder railHolder) { var editContext = areaScenes[selectedArea].EditContext; - if (ImGui.Button("Add Rail")) + ImGui.Text("Select a Rail"); + ImGui.Text("Alt + Left Click to add point"); + ImGui.Text("Double click to add/remove a curve point"); + ImGui.Text("Delete to remove point"); + + ImGui.SetNextWindowSize(ImGui.GetContentRegionAvail()); + if (ImGui.BeginCombo("##Add Rail", "Add Rail")) { - railHolder.mRails.Add(new CourseRail(this.selectedArea.mRootHash)); + foreach (string type in RailTypes) + { + ImGui.Selectable(type); + + if (ImGui.IsItemHovered() && ImGui.IsMouseClicked(0)) + railHolder.mRails.Add(new CourseRail(this.selectedArea.mRootHash, type)); + } + + ImGui.EndCombo(); } ImGui.SameLine(); if (ImGui.Button("Remove Rail"))