Skip to content

Commit

Permalink
make actor to rail links editable
Browse files Browse the repository at this point in the history
  • Loading branch information
jupahe64 committed Nov 29, 2023
1 parent ddec255 commit 7cdf42c
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Fushigi/course/CourseRail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public BymlArrayNode SerializeToArray()

public class CourseActorToRailLinks
{
struct Link
public struct Link
{
public ulong Source;
public ulong Dest;
Expand Down Expand Up @@ -432,6 +432,6 @@ public BymlArrayNode SerializeToArray()
return node;
}

List<Link> mLinks = new();
public List<Link> mLinks = new();
}
}
98 changes: 98 additions & 0 deletions Fushigi/ui/widgets/CourseScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public void DrawUI(GL gl, double deltaSeconds)
RailsPanel();

GlobalLinksPanel();
RailLinksPanel();

BGUnitPanel();

Expand Down Expand Up @@ -544,6 +545,103 @@ private void GlobalLinksPanel()
ImGui.End();
}

private void RailLinksPanel()
{
ImGui.Begin("Actor to Rail Links");

ImGui.Columns(4);
ImGui.Text("Actor-Hash");
ImGui.NextColumn();
ImGui.Text("Rail");
ImGui.NextColumn();
ImGui.Text("Point");
ImGui.NextColumn();
ImGui.NextColumn();

var ctx = areaScenes[selectedArea].EditContext;
var rails = selectedArea.mRailHolder.mRails;
var actors = selectedArea.mActorHolder.GetActors();
var railLinks = selectedArea.mRailLinks.mLinks;

for (int i = 0; i < railLinks.Count; i++)
{
ImGui.PushID(i);
CourseActorToRailLinks.Link link = railLinks[i];

string hash = link.Source.ToString();
int actorIndex = actors.FindIndex(x => x.GetHash() == link.Source);
if (ImGui.InputText("##actor", ref hash, 100) &&
ulong.TryParse(hash, out ulong hashInt))
link.Source = hashInt;
if(actorIndex == -1)
{
ImGui.SameLine();
ImGui.TextDisabled("Invalid");
}

ImGui.NextColumn();
int railIndex = rails.FindIndex(x => x.mHash == link.Dest);
if (ImGui.BeginCombo("##rail", railIndex >= 0 ? ("rail " + railIndex) : "None"))
{
for (int iRail = 0; iRail < rails.Count; iRail++)
{
if (ImGui.Selectable("Rail " + iRail, railIndex == iRail))
link.Dest = rails[iRail].mHash;
}
ImGui.EndCombo();
}
if (railIndex == -1)
{
ImGui.SameLine();
ImGui.TextDisabled("Invalid");
}
ImGui.NextColumn();
if (railIndex >= 0)
{
int pointIndex = rails[railIndex].mPoints.FindIndex(x => x.mHash == link.Point);

if (pointIndex == -1)
pointIndex = 0;

if (ImGui.InputInt("##railpoint", ref pointIndex))
pointIndex = Math.Clamp(pointIndex, 0, rails[railIndex].mPoints.Count - 1);

link.Point = rails[railIndex].mPoints[pointIndex].GetHash();
}

railLinks[i] = link;

ImGui.NextColumn();
if (ImGui.Button("Delete", new Vector2(ImGui.GetContentRegionAvail().X * 0.65f, 0)))
{
railLinks.RemoveAt(i);
i--;
}


ImGui.NextColumn();
ImGui.PopID();
}

float width = ImGui.GetItemRectMax().X - ImGui.GetCursorScreenPos().X;

ImGui.Columns(1);
ImGui.Dummy(new Vector2(0, ImGui.GetFrameHeight() * 0.5f));

if (ImGui.Button("Add", new Vector2(width, ImGui.GetFrameHeight() * 1.5f)))
{
railLinks.Add(new CourseActorToRailLinks.Link
{
Name = "Reference",
Source = 0,
Dest = 0,
Point = 0
});
}

ImGui.End();
}

private void SelectionParameterPanel()
{
var editContext = areaScenes[selectedArea].EditContext;
Expand Down

0 comments on commit 7cdf42c

Please sign in to comment.