Skip to content

Commit 7057ef9

Browse files
committed
Make drag and drop copying of components use fixed Slot.DuplicateComponent method
Fixes the drag and drop copying aspect of Yellow-Dog-Man/Resonite-Issues#92 as well
1 parent de2e54a commit 7057ef9

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using Elements.Core;
2+
using FrooxEngine;
3+
using FrooxEngine.UIX;
4+
using HarmonyLib;
5+
using MonkeyLoader.Resonite;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Text;
9+
10+
namespace CommunityBugFixCollection
11+
{
12+
[HarmonyPatchCategory(nameof(BreakDragAndDropCopiedComponentDrives))]
13+
[HarmonyPatch(typeof(SlotComponentReceiver), nameof(SlotComponentReceiver.TryReceive))]
14+
internal sealed class BreakDragAndDropCopiedComponentDrives : ResoniteMonkey<BreakDragAndDropCopiedComponentDrives>
15+
{
16+
public override IEnumerable<string> Authors => Contributors.Banane9;
17+
18+
public override bool CanBeDisabled => true;
19+
20+
private static bool Prefix(SlotComponentReceiver __instance, IEnumerable<IGrabbable> items, Canvas.InteractionData eventData, in float3 globalPoint, out bool __result)
21+
{
22+
__result = false;
23+
24+
if (__instance.Target.Target is null)
25+
return false;
26+
27+
foreach (var item in items)
28+
{
29+
foreach (ReferenceProxy componentsInChild in item.Slot.GetComponentsInChildren<ReferenceProxy>())
30+
{
31+
if (componentsInChild.Reference.Target is not Component component || __instance.Target.Target == component.Slot)
32+
continue;
33+
34+
__instance.StartTask(async () =>
35+
{
36+
var contextMenu = await __instance.LocalUser.OpenContextMenu(__instance, eventData.source.Slot);
37+
38+
var copyItem = contextMenu.AddItem("Inspector.Actions.CopyComponent".AsLocaleKey(), (Uri)null!, RadiantUI_Constants.Hero.GREEN);
39+
var moveItem = contextMenu.AddItem("Inspector.Actions.MoveComponent".AsLocaleKey(), (Uri)null!, RadiantUI_Constants.Hero.PURPLE);
40+
var cancelItem = contextMenu.AddItem("General.Cancel".AsLocaleKey(), (Uri)null!, colorX.White);
41+
42+
copyItem.Button.LocalPressed += delegate
43+
{
44+
__instance.Target.Target.DuplicateComponent(component);
45+
__instance.LocalUser.CloseContextMenu(__instance);
46+
};
47+
48+
moveItem.Button.LocalPressed += delegate
49+
{
50+
__instance.Target.Target.MoveComponent(component);
51+
__instance.LocalUser.CloseContextMenu(__instance);
52+
};
53+
54+
cancelItem.Button.LocalPressed += delegate
55+
{
56+
__instance.LocalUser.CloseContextMenu(__instance);
57+
};
58+
});
59+
60+
__result = true;
61+
return false;
62+
}
63+
}
64+
65+
return false;
66+
}
67+
}
68+
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ If any of them have been closed and not removed from the mod,
2121
just disable them in the settings in the meantime.
2222

2323
* Duplicating Components breaking drives (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/92)
24+
* Pressing Duplicate on the Component in an Inspector
25+
* Using the Component Clone Tool to duplicate them onto a slot
26+
* Selecting Copy Component when drag and dropping a Component onto an Inspector
2427
* Worlds crashing when a (multi)tool is scaled to zero (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/98)
2528
* Most ProtoFlux nodes in Strings > Constants having invisible names (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/177)
2629
* The `Remap -1 1 to 0 1` ProtoFlux node having a hard to understand name (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/245)

0 commit comments

Comments
 (0)