diff --git a/CommunityBugFixCollection/BetterListEditor.cs b/CommunityBugFixCollection/BetterListEditor.cs new file mode 100644 index 0000000..b01a1a2 --- /dev/null +++ b/CommunityBugFixCollection/BetterListEditor.cs @@ -0,0 +1,108 @@ +using Elements.Core; +using FrooxEngine; +using FrooxEngine.UIX; +using HarmonyLib; +using System.Globalization; + +namespace CommunityBugFixCollection +{ + [HarmonyPatch(typeof(ListEditor))] + [HarmonyPatchCategory(nameof(BetterListEditor))] + internal sealed class BetterListEditor : ResoniteBugFixMonkey + { + public override IEnumerable Authors => Contributors.Banane9; + + [HarmonyPrefix] + [HarmonyPatch(nameof(ListEditor.Target_ElementsAdded))] + private static bool ElementsAddedPrefix(ListEditor __instance, ISyncList list, int startIndex, int count) + { + if (!Enabled) + return true; + + if (count is 0) + return false; + + var addedElements = Pool.BorrowList(); + + for (var i = startIndex; i < startIndex + count; ++i) + addedElements.Add(list.GetElement(i)); + + __instance.World.RunSynchronously(() => + { + for (var i = __instance.Slot.ChildrenCount - 1; i >= startIndex; --i) + __instance.Slot[i].OrderOffset += count; + + for (var i = 0; i < addedElements.Count; ++i) + { + if (addedElements[i].FilterWorldElement() is null) + continue; + + var slot = __instance.Slot.AddSlot("Element"); + slot.OrderOffset = startIndex + i; + + __instance.BuildListItem(list, startIndex + i, addedElements[i], slot); + } + + Pool.Return(ref addedElements); + }); + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(ListEditor.GetElementName))] + private static bool GetElementNamePrefix(int index, ref string __result) + { + if (!Enabled) + return true; + + __result = index.ToString(CultureInfo.InvariantCulture) + ':'; + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(ListEditor.MoveElement))] + private static bool MoveElementPrefix(ListEditor __instance, IButton button, int offset) + { + if (!Enabled) + return true; + + if (__instance._targetList.Target.FilterWorldElement() is null) + return false; + + if (__instance._targetList.Target is ConflictingSyncElement { DirectAccessOnly: true } && !__instance.LocalUser.IsDirectlyInteracting()) + return false; + + var index = __instance.FindButtonIndex(button); + var newIndex = index + offset; + + if (index < 0 || newIndex < 0 || newIndex >= __instance._targetList.Target.Count) + return false; + + __instance._targetList.Target.MoveElementToIndex(index, newIndex); + + __instance.reindex = true; + __instance.MarkChangeDirty(); + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(ListEditor.Reindex))] + private static bool ReindexPrefix(ListEditor __instance) + { + if (!Enabled) + return true; + + for (var i = 0; i < __instance.Slot.ChildrenCount; ++i) + { + if (__instance.Slot[i].GetComponentInChildren() is not Text text) + continue; + + text.Content.Value = __instance.GetElementName(__instance._targetList.Target, i); + } + + return false; + } + } +} \ No newline at end of file diff --git a/CommunityBugFixCollection/Locale/de.json b/CommunityBugFixCollection/Locale/de.json index 03a3595..c0d1a61 100644 --- a/CommunityBugFixCollection/Locale/de.json +++ b/CommunityBugFixCollection/Locale/de.json @@ -9,6 +9,7 @@ "CommunityBugFixCollection.AnyProtocolHyperlinks.Description": "Erlaubt es Hyperlink-Komponenten URLs mit beliebigen Schemata zu öffnen, statt nur http(s).", "CommunityBugFixCollection.BetterGridWorldPreset.Description": "Verbessert das Grid Welt Preset indem das zittern des Bodens verhindert und das Grid zentriert wird.", + "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.", "CommunityBugFixCollection.BreakDragAndDropCopiedComponentDrives.Description": "Sorgt dafür, dass Drives beim Kopieren von Komponenten mittels Drag-und-Drop nicht kaputt gehen.", "CommunityBugFixCollection.CaseInsensitiveCustomGenerics.Description": "Macht das Auswählen von eigenen generischen Typparametern unabhängig von Groß- und Kleinschreibung.", "CommunityBugFixCollection.CenteredNotifications.Description": "Zentriert den Inhalt von Benachrichtigungen.", diff --git a/CommunityBugFixCollection/Locale/en.json b/CommunityBugFixCollection/Locale/en.json index 4fcb5ef..e5d3329 100644 --- a/CommunityBugFixCollection/Locale/en.json +++ b/CommunityBugFixCollection/Locale/en.json @@ -14,6 +14,7 @@ "CommunityBugFixCollection.AnyProtocolHyperlinks.Description": "Allows Hyperlink components to open URLs with any scheme, not just http(s).", "CommunityBugFixCollection.BetterGridWorldPreset.Description": "Improves the Grid World Preset by preventing the shaking ground and centering the grid.", + "CommunityBugFixCollection.BetterListEditor.Description": "Improves the list editors in inspectors, preventing an exception while adding elements and renaming them when they're moved around.", "CommunityBugFixCollection.BreakDragAndDropCopiedComponentDrives.Description": "Fixes copying components using drag-and-drop breaking drives.", "CommunityBugFixCollection.CaseInsensitiveCustomGenerics.Description": "Makes picking custom generic type parameters case-insensitive.", "CommunityBugFixCollection.CenteredNotifications.Description": "Centers the content of notifications.", diff --git a/README.md b/README.md index 96582e2..dbae887 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ just disable them in the settings in the meantime. * April Fools content is active for users in Universes (commercial usage) (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/4016) * Instantly removing an AudioOutput component crashes the session (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/4286) * Log spam from `TrackedDevicePositioner.UpdateBodyNode()` in certain scenarios (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/5182) +* 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) Fixes with no issue (that could be found). * Content of notification being off-center.