This repository was archived by the owner on Sep 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCustomColorPicker.cs
More file actions
67 lines (57 loc) · 2.41 KB
/
Copy pathCustomColorPicker.cs
File metadata and controls
67 lines (57 loc) · 2.41 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
using System;
using System.Collections.Generic;
using BaseX;
using FrooxEngine;
using HarmonyLib;
using NeosModLoader;
using SpecialItemsLib;
namespace CustomColorPicker {
public class CustomColorPicker : NeosMod {
public override string Name => "CustomColorPicker";
public override string Author => "Delta";
public override string Version => "1.1.0";
public override string Link => "https://github.com/XDelta/CustomColorPicker/";
private static ModConfiguration Config;
[AutoRegisterConfigKey]
private static readonly ModConfigurationKey<bool> enabled = new ModConfigurationKey<bool>("enabled", "Enables the mod", () => true);
public override void OnEngineInit() {
Config = GetConfiguration();
Config.Save(true);
Harmony harmony = new Harmony("net.deltawolf.CustomColorPicker");
ColorPickerObject = SpecialItemsLib.SpecialItemsLib.RegisterItem(COLOR_PICKER_TAG);
harmony.PatchAll();
}
private static string COLOR_PICKER_TAG { get { return "custom_color_picker"; } }
private static CustomSpecialItem ColorPickerObject;
[HarmonyPatch(typeof(SlotHelper), "GenerateTags", new Type[] { typeof(Slot), typeof(HashSet<string>) })]
class SlotHelper_GenerateTags_Patch {
static void Postfix(Slot slot, HashSet<string> tags) {
if (slot.GetComponent<NeosColorDialog>() != null) {
tags.Add(COLOR_PICKER_TAG);
}
}
}
[HarmonyPatch(typeof(NeosColorDialog), "SetupColor")]
class NeosColorDialog_SetupColor_Patch {
static bool Prefix(NeosColorDialog __instance, color defaultColor) {
if (!Config.GetValue(enabled)) { return true; }
if (ColorPickerObject.Uri == null) { return true; }
var slot = __instance.Slot;
slot.StartTask(async delegate () {
await slot.LoadObjectAsync(ColorPickerObject.Uri);
InventoryItem component = slot.GetComponent<InventoryItem>();
slot = ((component != null) ? component.Unpack() : null) ?? slot;
__instance.Enabled = false;
slot.LocalScale = float3.One * 0.5f;
NeosColorDialog colorDialog = slot.GetComponentInChildren<NeosColorDialog>(excludeDisabled:true);
colorDialog.TargetField.Value = __instance.TargetField.Value;
var colorDialogOriginalColor = (AccessTools.Field(typeof(NeosColorDialog), "_originalColor").GetValue(colorDialog) as Sync<color>);
colorDialogOriginalColor.Value = defaultColor;
__instance.Destroy();
slot.PositionInFrontOfUser(float3.Backward);
});
return false;
}
}
}
}