Skip to content

Commit 574b0bf

Browse files
committed
Add some patches to remove an exception from and improve the ListEditor behavior
Adds a fix for Yellow-Dog-Man/Resonite-Issues#5416
1 parent 7389f9e commit 574b0bf

4 files changed

Lines changed: 111 additions & 0 deletions

File tree

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using Elements.Core;
2+
using FrooxEngine;
3+
using FrooxEngine.UIX;
4+
using HarmonyLib;
5+
using System.Globalization;
6+
7+
namespace CommunityBugFixCollection
8+
{
9+
[HarmonyPatch(typeof(ListEditor))]
10+
[HarmonyPatchCategory(nameof(BetterListEditor))]
11+
internal sealed class BetterListEditor : ResoniteBugFixMonkey<BetterListEditor>
12+
{
13+
public override IEnumerable<string> Authors => Contributors.Banane9;
14+
15+
[HarmonyPrefix]
16+
[HarmonyPatch(nameof(ListEditor.Target_ElementsAdded))]
17+
private static bool ElementsAddedPrefix(ListEditor __instance, ISyncList list, int startIndex, int count)
18+
{
19+
if (!Enabled)
20+
return true;
21+
22+
if (count is 0)
23+
return false;
24+
25+
var addedElements = Pool.BorrowList<ISyncMember>();
26+
27+
for (var i = startIndex; i < startIndex + count; ++i)
28+
addedElements.Add(list.GetElement(i));
29+
30+
__instance.World.RunSynchronously(() =>
31+
{
32+
for (var i = __instance.Slot.ChildrenCount - 1; i >= startIndex; --i)
33+
__instance.Slot[i].OrderOffset += count;
34+
35+
for (var i = 0; i < addedElements.Count; ++i)
36+
{
37+
if (addedElements[i].FilterWorldElement() is null)
38+
continue;
39+
40+
var slot = __instance.Slot.AddSlot("Element");
41+
slot.OrderOffset = startIndex + i;
42+
43+
__instance.BuildListItem(list, startIndex + i, addedElements[i], slot);
44+
}
45+
46+
Pool.Return(ref addedElements);
47+
});
48+
49+
return false;
50+
}
51+
52+
[HarmonyPrefix]
53+
[HarmonyPatch(nameof(ListEditor.GetElementName))]
54+
private static bool GetElementNamePrefix(int index, ref string __result)
55+
{
56+
if (!Enabled)
57+
return true;
58+
59+
__result = index.ToString(CultureInfo.InvariantCulture) + ':';
60+
return false;
61+
}
62+
63+
[HarmonyPrefix]
64+
[HarmonyPatch(nameof(ListEditor.MoveElement))]
65+
private static bool MoveElementPrefix(ListEditor __instance, IButton button, int offset)
66+
{
67+
if (!Enabled)
68+
return true;
69+
70+
if (__instance._targetList.Target.FilterWorldElement() is null)
71+
return false;
72+
73+
if (__instance._targetList.Target is ConflictingSyncElement { DirectAccessOnly: true } && !__instance.LocalUser.IsDirectlyInteracting())
74+
return false;
75+
76+
var index = __instance.FindButtonIndex(button);
77+
var newIndex = index + offset;
78+
79+
if (index < 0 || newIndex < 0 || newIndex >= __instance._targetList.Target.Count)
80+
return false;
81+
82+
__instance._targetList.Target.MoveElementToIndex(index, newIndex);
83+
84+
__instance.reindex = true;
85+
__instance.MarkChangeDirty();
86+
87+
return false;
88+
}
89+
90+
[HarmonyPrefix]
91+
[HarmonyPatch(nameof(ListEditor.Reindex))]
92+
private static bool ReindexPrefix(ListEditor __instance)
93+
{
94+
if (!Enabled)
95+
return true;
96+
97+
for (var i = 0; i < __instance.Slot.ChildrenCount; ++i)
98+
{
99+
if (__instance.Slot[i].GetComponentInChildren<Text>() is not Text text)
100+
continue;
101+
102+
text.Content.Value = __instance.GetElementName(__instance._targetList.Target, i);
103+
}
104+
105+
return false;
106+
}
107+
}
108+
}

CommunityBugFixCollection/Locale/de.json

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

1010
"CommunityBugFixCollection.AnyProtocolHyperlinks.Description": "Erlaubt es Hyperlink-Komponenten URLs mit beliebigen Schemata zu öffnen, statt nur http(s).",
1111
"CommunityBugFixCollection.BetterGridWorldPreset.Description": "Verbessert das Grid Welt Preset indem das zittern des Bodens verhindert und das Grid zentriert wird.",
12+
"CommunityBugFixCollection.BetterListEditor.Description": "Verbessert Listeneditoren in Inspektoren, wodurch eine Exception beim Hinzufügen von Elementen verhindert wird und deren Namen beim Verschieben entsprechend angepasst werden.",
1213
"CommunityBugFixCollection.BreakDragAndDropCopiedComponentDrives.Description": "Sorgt dafür, dass Drives beim Kopieren von Komponenten mittels Drag-und-Drop nicht kaputt gehen.",
1314
"CommunityBugFixCollection.CaseInsensitiveCustomGenerics.Description": "Macht das Auswählen von eigenen generischen Typparametern unabhängig von Groß- und Kleinschreibung.",
1415
"CommunityBugFixCollection.CenteredNotifications.Description": "Zentriert den Inhalt von Benachrichtigungen.",

CommunityBugFixCollection/Locale/en.json

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

1515
"CommunityBugFixCollection.AnyProtocolHyperlinks.Description": "Allows Hyperlink components to open URLs with any scheme, not just http(s).",
1616
"CommunityBugFixCollection.BetterGridWorldPreset.Description": "Improves the Grid World Preset by preventing the shaking ground and centering the grid.",
17+
"CommunityBugFixCollection.BetterListEditor.Description": "Improves the list editors in inspectors, preventing an exception while adding elements and renaming them when they're moved around.",
1718
"CommunityBugFixCollection.BreakDragAndDropCopiedComponentDrives.Description": "Fixes copying components using drag-and-drop breaking drives.",
1819
"CommunityBugFixCollection.CaseInsensitiveCustomGenerics.Description": "Makes picking custom generic type parameters case-insensitive.",
1920
"CommunityBugFixCollection.CenteredNotifications.Description": "Centers the content of notifications.",

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ just disable them in the settings in the meantime.
6363
* April Fools content is active for users in Universes (commercial usage) (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/4016)
6464
* Instantly removing an AudioOutput component crashes the session (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/4286)
6565
* Log spam from `TrackedDevicePositioner.UpdateBodyNode()` in certain scenarios (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/5182)
66+
* List editors in inspectors throw an exception when elements are added and don't rename them when they're moved around (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/5416)
6667

6768
Fixes with no issue (that could be found).
6869
* Content of notification being off-center.

0 commit comments

Comments
 (0)