Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions CommunityBugFixCollection/BetterListEditor.cs
Original file line number Diff line number Diff line change
@@ -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<BetterListEditor>
{
public override IEnumerable<string> 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<ISyncMember>();

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<Text>() is not Text text)
continue;

text.Content.Value = __instance.GetElementName(__instance._targetList.Target, i);
}

return false;
}
}
}
1 change: 1 addition & 0 deletions CommunityBugFixCollection/Locale/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions CommunityBugFixCollection/Locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading