Skip to content

Commit

Permalink
get rid of all duplicate selection state in CourseScene
Browse files Browse the repository at this point in the history
  • Loading branch information
jupahe64 committed Nov 11, 2023
1 parent 8f46ed9 commit 6785d33
Showing 1 changed file with 18 additions and 48 deletions.
66 changes: 18 additions & 48 deletions Fushigi/ui/widgets/CourseScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using ZstdSharp.Unsafe;
using static System.Net.Mime.MediaTypeNames;

namespace Fushigi.ui.widgets
Expand All @@ -44,13 +45,7 @@ class CourseScene
bool mAllLayersVisible = true;
bool mShowAddActor = false;

CourseActor? mSelectedActor = null;
CourseUnit? mSelectedUnit = null;
BGUnitRail? mSelectedUnitRail = null;
CourseLink? mSelectedGlobalLink = null;
CourseRail? mSelectedRail = null;
CourseRail.CourseRailPoint? mSelectedRailPoint = null;

string mAddActorSearchQuery = "";

string[] linkTypes = [
Expand Down Expand Up @@ -95,13 +90,6 @@ public CourseScene(Course course, GL gl)
activeViewport = viewports[selectedArea];
}

public void DeselectAll()
{
mSelectedActor = null;
mSelectedUnit = null;
mSelectedUnitRail = null;
}

public void DrawUI(GL gl)
{
ActorsPanel();
Expand Down Expand Up @@ -201,17 +189,6 @@ public void DrawUI(GL gl)
lastCreatedViewports = viewports;
}

if (activeViewport.mEditContext.SelectionVersion != selectionVersionBefore)
{
DeselectAll();
if (activeViewport.mEditContext.IsSingleObjectSelected<CourseActor>(out var actor))
mSelectedActor = actor;
if (activeViewport.mEditContext.IsSingleObjectSelected<BGUnitRail>(out var bgUnitRail))
{
mSelectedUnitRail = bgUnitRail;
}
}

if (status)
ImGui.End();
}
Expand Down Expand Up @@ -434,9 +411,10 @@ private void GlobalLinksPanel()

private void SelectionParameterPanel()
{

bool status = ImGui.Begin("Selection Parameters", ImGuiWindowFlags.AlwaysVerticalScrollbar);

if (mSelectedActor != null)
if (activeViewport.mEditContext.IsSingleObjectSelected(out CourseActor? mSelectedActor))
{
string actorName = mSelectedActor.mActorName;
string name = mSelectedActor.mName;
Expand Down Expand Up @@ -608,7 +586,7 @@ private void SelectionParameterPanel()
}

}
else if (mSelectedUnit != null)
else if (activeViewport.mEditContext.IsSingleObjectSelected(out CourseUnit? mSelectedUnit))
{
ImGui.AlignTextToFramePadding();
ImGui.Text($"Selected BG Unit");
Expand All @@ -631,7 +609,7 @@ private void SelectionParameterPanel()
ImGui.Columns(1);
}
}
else if (mSelectedUnitRail != null)
else if (activeViewport.mEditContext.IsSingleObjectSelected(out BGUnitRail? mSelectedUnitRail))
{
ImGui.AlignTextToFramePadding();
ImGui.Text($"Selected BG Unit Rail");
Expand Down Expand Up @@ -699,7 +677,7 @@ private void SelectionParameterPanel()
ImGui.Columns(1);
}
}
else if (mSelectedRail != null)
else if (activeViewport.mEditContext.IsSingleObjectSelected(out CourseRail? mSelectedRail))
{
ImGui.AlignTextToFramePadding();
ImGui.Text($"Selected Rail");
Expand Down Expand Up @@ -756,7 +734,7 @@ private void SelectionParameterPanel()
}
}
}
else if (mSelectedRailPoint != null)
else if (activeViewport.mEditContext.IsSingleObjectSelected(out CourseRail.CourseRailPoint? mSelectedRailPoint))
{
ImGui.AlignTextToFramePadding();
ImGui.Text($"Selected Rail Point");
Expand Down Expand Up @@ -980,10 +958,10 @@ private void CourseUnitView(CourseUnitHolder unitHolder)
}
ImGui.SameLine();

if (ImGui.Selectable(name, mSelectedUnit == unit))
if (ImGui.Selectable(name, activeViewport.mEditContext.IsSelected(unit)))
{
DeselectAll();
mSelectedUnit = unit;
activeViewport.mEditContext.DeselectAllOfType<CourseUnit>();
activeViewport.mEditContext.Select(unit);
}
if (expanded)
{
Expand All @@ -1007,11 +985,6 @@ void SelectRail()
activeViewport.mEditContext.DeselectAllOfType<BGUnitRail>();

activeViewport.mEditContext.Select(rail);

//Remove actor properties to show path properties
DeselectAll();
//Show selection for rail with properties
mSelectedUnitRail = rail;
}

if (ImGui.Selectable($"##{name}{wallname}", isSelected, ImGuiSelectableFlags.SpanAllColumns))
Expand All @@ -1038,7 +1011,7 @@ void SelectRail()
ImGui.Unindent();
}

if (unit == mSelectedUnit)
if (activeViewport.mEditContext.IsSelected(unit))
{
if (ImGui.BeginPopupContextWindow("RailMenu", ImGuiPopupFlags.MouseButtonRight))
{
Expand Down Expand Up @@ -1103,34 +1076,32 @@ private void CourseRailsView(CourseRailHolder railHolder)
foreach(CourseRail rail in railHolder.mRails)
{
var rail_node_flags = ImGuiTreeNodeFlags.None;
if (mSelectedRail == rail && mSelectedRailPoint == null)
if (activeViewport.mEditContext.IsSelected(rail) ||
!activeViewport.mEditContext.IsAnySelected<CourseRail.CourseRailPoint>())
rail_node_flags |= ImGuiTreeNodeFlags.Selected;

bool expanded = ImGui.TreeNodeEx($"Rail {railHolder.mRails.IndexOf(rail)}", rail_node_flags);
if (ImGui.IsItemHovered(0) && ImGui.IsMouseClicked(0))
{
/* deselect from viewport and list */
mSelectedActor = null;
activeViewport.mEditContext.DeselectAll();
mSelectedRailPoint = null;
mSelectedRail = rail;
activeViewport.mEditContext.Select(rail);
}

if (expanded)
{
foreach (CourseRail.CourseRailPoint pnt in rail.mPoints)
{
var flags = ImGuiTreeNodeFlags.Leaf;
if (mSelectedRailPoint == pnt)
if (activeViewport.mEditContext.IsSelected(pnt))
flags |= ImGuiTreeNodeFlags.Selected;

if (ImGui.TreeNodeEx($"Point {rail.mPoints.IndexOf(pnt)}", flags))
ImGui.TreePop();

if (ImGui.IsItemHovered(0) && ImGui.IsMouseClicked(0))
{
mSelectedRail = null;
mSelectedRailPoint = pnt;
activeViewport.mEditContext.DeselectAll();
activeViewport.mEditContext.Select(pnt);
}
}

Expand Down Expand Up @@ -1260,13 +1231,12 @@ private void CourseActorsLayerView(CourseActorHolder actorArray)
continue;
}

bool isSelected = (actor == mSelectedActor);
bool isSelected = activeViewport.mEditContext.IsSelected(actor);

ImGui.PushID(actorHash.ToString());
ImGui.Columns(2);
if (ImGui.Selectable(actorName, isSelected, ImGuiSelectableFlags.SpanAllColumns))
{
mSelectedActor = actor;
activeViewport.SelectedActor(actor);
}
if (ImGui.IsItemHovered() && ImGui.IsMouseDoubleClicked(0))
Expand Down

0 comments on commit 6785d33

Please sign in to comment.