Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Depth Sorting #117

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Fushigi/course/CourseActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ public BymlArrayNode SerializeToArray(CourseLinkHolder linkHolder)
return node;
}

public List<CourseActor> mActors = new List<CourseActor>();
public List<CourseActor> mActors = [];
public List<CourseActor> mSortedActors = [];
}

public class CourseActorRender //This can be overridden per actor for individual behavior
Expand Down
10 changes: 10 additions & 0 deletions Fushigi/course/CourseArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ public IReadOnlyList<CourseActor> GetActors()
return mActorHolder.mActors;
}

public IReadOnlyList<CourseActor> GetSortedActors()
{
if (!mActorHolder.mActors.TrueForAll(mActorHolder.mSortedActors.Contains))
{
mActorHolder.mSortedActors = new List<CourseActor>(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;
Expand Down
29 changes: 24 additions & 5 deletions Fushigi/course/CourseRail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -33,8 +51,8 @@ public CourseRail(BymlHashTable node)
mHash = BymlUtil.GetNodeData<ulong>(node["Hash"]);
mIsClosed = BymlUtil.GetNodeData<bool>(node["IsClosed"]);

string pointParam = Path.GetFileNameWithoutExtension(BymlUtil.GetNodeData<string>(node["Gyaml"])).Split(".game")[0];
var railParams = ParamDB.GetRailComponent(pointParam);
mType = Path.GetFileNameWithoutExtension(BymlUtil.GetNodeData<string>(node["Gyaml"])).Split(".game")[0];
var railParams = ParamDB.GetRailComponent(mType);
var railParent = ParamDB.GetRailComponentParent(railParams);
var comp = ParamDB.GetRailComponentParams(railParams);
if (railParent != "null")
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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<CourseRailPoint> mPoints = new();
public Dictionary<string, object> mParameters = new();
Expand Down
37 changes: 31 additions & 6 deletions Fushigi/ui/widgets/CourseScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion Fushigi/ui/widgets/LevelViewport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
Loading