Skip to content

Commit d30073b

Browse files
committed
refactor(UI): ♻️ streamline dialog management and entry point logic
1 parent 18bef73 commit d30073b

6 files changed

Lines changed: 22 additions & 73 deletions

File tree

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
<PropertyGroup Condition="'$(ResoniteAssembliesDir)'==''">
1010
<ResoniteAssembliesDir>$(MSBuildThisFileDirectory)Resonite/</ResoniteAssembliesDir>
11+
<ResoniteAssembliesDir Condition="Exists('/mnt/c/Program Files (x86)/Steam/steamapps/common/Resonite/')">/mnt/c/Program Files (x86)/Steam/steamapps/common/Resonite/</ResoniteAssembliesDir>
1112
<ResoniteAssembliesDir Condition="Exists('C:\\Program Files (x86)\\Steam\\steamapps\\common\\Resonite\\')">C:\\Program Files (x86)\\Steam\\steamapps\\common\\Resonite\\</ResoniteAssembliesDir>
1213
<ResoniteAssembliesDir Condition="Exists('$(HOME)/.steam/steam/steamapps/common/Resonite/')">$(HOME)/.steam/steam/steamapps/common/Resonite/</ResoniteAssembliesDir>
1314
</PropertyGroup>

src/ReferenceReplacement/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
[assembly: AssemblyVersion("0.1.0.0")]
44
[assembly: AssemblyFileVersion("0.1.0.0")]
5-
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReferenceReplacement.Tests")]
5+
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReferenceReplacement.Tests")]

src/ReferenceReplacement/ReferenceReplacementMod.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ private static void RegisterCreationEntry()
6363
return;
6464
}
6565

66-
DevCreateNewForm.AddAction(CreationMenuCategory, CreationMenuLabel, ReferenceReplacementEntryPoint.OpenFromSlot);
66+
DevCreateNewForm.AddAction(CreationMenuCategory, CreationMenuLabel, ReferenceReplacementDialog.OpenFromSlot);
6767

6868
_creationEntryRegistered = true;
6969
}
70-
}
70+
}

src/ReferenceReplacement/UI/ReferenceReplacementDialog.cs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace ReferenceReplacement.UI;
1414

1515
public sealed class ReferenceReplacementDialog
1616
{
17-
private readonly User _owner;
1817
private readonly Slot _rootSlot;
1918
private readonly ISyncRef _processRootRef;
2019
private readonly ISyncRef _sourceRef;
@@ -24,15 +23,28 @@ public sealed class ReferenceReplacementDialog
2423
private Text? _detailText;
2524
private bool _disposed;
2625

26+
public static void OpenFromSlot(Slot creationSlot)
27+
{
28+
ArgumentNullException.ThrowIfNull(creationSlot);
29+
30+
User? localUser = creationSlot.World?.LocalUser;
31+
if (localUser == null)
32+
{
33+
creationSlot.Destroy();
34+
return;
35+
}
36+
37+
_ = Create(localUser, creationSlot);
38+
}
39+
2740
private ReferenceReplacementDialog(User owner, Slot dialogSlot)
2841
{
29-
_owner = owner ?? throw new ArgumentNullException(nameof(owner));
42+
ArgumentNullException.ThrowIfNull(owner);
3043
_rootSlot = dialogSlot ?? throw new ArgumentNullException(nameof(dialogSlot));
3144
_rootSlot.Destroyed += OnSlotDestroyed;
3245
ClearSlot(_rootSlot);
3346

3447
(_processRootRef, _sourceRef, _targetRef) = CreateReferenceFields();
35-
ClearInputs();
3648

3749
ConfigureRootSlot();
3850
BuildUI();
@@ -63,7 +75,7 @@ public void RepositionFor(User? user)
6375
return;
6476
}
6577

66-
PrepareRootSlot(user);
78+
ResetRootTransform();
6779
_rootSlot.PositionInFrontOfUser(float3.Backward);
6880
if (user.LocalUserRoot != null)
6981
{
@@ -86,8 +98,6 @@ public void Close()
8698
{
8799
_rootSlot.Destroy();
88100
}
89-
90-
ReferenceReplacementDialogManager.Unregister(this);
91101
}
92102

93103
private (ISyncRef processRoot, ISyncRef source, ISyncRef target) CreateReferenceFields()
@@ -97,7 +107,7 @@ public void Close()
97107

98108
private ISyncRef CreateReferenceProxy()
99109
{
100-
var proxy = _rootSlot.AttachComponent<ReferenceProxy>();
110+
ReferenceProxy proxy = _rootSlot.AttachComponent<ReferenceProxy>();
101111
proxy.Persistent = false;
102112
return ExtractSyncRef(proxy);
103113
}
@@ -123,7 +133,6 @@ private void OnSlotDestroyed(IDestroyable _)
123133
}
124134

125135
_disposed = true;
126-
ReferenceReplacementDialogManager.Unregister(this);
127136
}
128137

129138
private void ConfigureRootSlot()
@@ -358,21 +367,8 @@ private static void ClearSlot(Slot slot)
358367
}
359368
}
360369

361-
private void ClearInputs()
362-
{
363-
_processRootRef.Target = null!;
364-
_sourceRef.Target = null!;
365-
_targetRef.Target = null!;
366-
}
367-
368-
private void PrepareRootSlot(User owner)
370+
private void ResetRootTransform()
369371
{
370-
Slot? parent = owner.LocalUserSpace;
371-
if (parent != null && _rootSlot.Parent != parent)
372-
{
373-
_rootSlot.SetParent(parent, false);
374-
}
375-
376372
_rootSlot.LocalPosition = float3.Zero;
377373
_rootSlot.LocalRotation = floatQ.Identity;
378374
}

src/ReferenceReplacement/UI/ReferenceReplacementDialogManager.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/ReferenceReplacement/UI/ReferenceReplacementEntryPoint.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)