-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSlotInspectorHighlighter.cs
More file actions
108 lines (93 loc) · 4.1 KB
/
SlotInspectorHighlighter.cs
File metadata and controls
108 lines (93 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using Elements.Core;
using FrooxEngine;
using FrooxEngine.UIX;
using HarmonyLib;
using ResoniteModLoader;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SlotInspectorHighlighter
{
public class SlotInspectorHighlighter : ResoniteMod
{
internal const string DOMAIN_NAME = "com.Sinduy.SlotInspectorHighlighter";
internal const string VERSION = "1.0.6";
public override string Name => "SlotInspectorHighlighter";
public override string Author => "Sinduy";
public override string Version => VERSION;
public override string Link => "https://github.com/sjsanjsrh/SlotInspectorHighlighter";
[AutoRegisterConfigKey]
private static readonly ModConfigurationKey<bool> enabled =
new ModConfigurationKey<bool>("enabled", "Should the mod be enabled", () => true);
[AutoRegisterConfigKey]
private static readonly ModConfigurationKey<bool> localOnly =
new ModConfigurationKey<bool>("localOnly", "Highlight only inspector element allocated by the local user", () => true);
[AutoRegisterConfigKey]
private static readonly ModConfigurationKey<colorX> hightlightColor =
new ModConfigurationKey<colorX>("highlightColor", "Color of the highlighter", () => new colorX(0, 0.85f, 0.95f, 0.1f));
private static ModConfiguration Config;
public static bool Enabled => Config.GetValue(enabled);
public static bool LocalOnly => Config.GetValue(localOnly);
public static colorX HighlightColor => Config.GetValue(hightlightColor);
public static readonly String HIGHLITER_SLOT_NAME = "Highlighter";
public override void OnEngineInit()
{
Config = GetConfiguration();
new Harmony(DOMAIN_NAME).PatchAll();
}
}
[HarmonyPatch(typeof(SlotInspector))]
class SlotInspectorHighlighterPatch
{
[HarmonyPatch("UpdateText")]
[HarmonyPostfix]
static void UpdateTextPostfix(SlotInspector __instance, Slot ____setupRoot, RelayRef<SyncRef<Slot>> ____selectionReference, SyncRef<Text> ____slotNameText)
{
bool isLocalUserFlag = true;
if (SlotInspectorHighlighter.LocalOnly)
{
SceneInspector sceneInspector = __instance.Slot.GetComponentInParents<SceneInspector>();
User allocatedUser = GetAllocatingUser(sceneInspector);
isLocalUserFlag = allocatedUser == __instance.LocalUser;
}
// Get or create highlighter slot
Slot selectedSlot = ____selectionReference.Target?.Target;
Slot textSlot = ____slotNameText.Target.Slot;
Slot hlSlot = textSlot.FindChild(SlotInspectorHighlighter.HIGHLITER_SLOT_NAME);
if (!(SlotInspectorHighlighter.Enabled && isLocalUserFlag))
{
if (hlSlot != null)
{ hlSlot.Destroy(); }
return;
}
if (hlSlot == null)
{
UIBuilder builder = new UIBuilder(textSlot);
var hlImg = builder.Image(null, SlotInspectorHighlighter.HighlightColor);
hlImg.Slot.Name = SlotInspectorHighlighter.HIGHLITER_SLOT_NAME;
hlSlot = hlImg.Slot;
}
hlSlot.ActiveSelf = selectedSlot == ____setupRoot;
}
private static User GetAllocatingUser(IWorldElement worldElement)
{
if (worldElement == null)
return null;
World world = worldElement.World;
if (world == null)
return null;
ulong position;
byte userId;
worldElement.ReferenceID.ExtractIDs(out position, out userId);
User userByAllocationId = world.GetUserByAllocationID(userId);
if (userByAllocationId == null)
return null;
return position < userByAllocationId.AllocationIDStart ? null : userByAllocationId;
}
}
}