Code updates
This commit is contained in:
parent
34e0013ff4
commit
b51696fb45
6 changed files with 203 additions and 76 deletions
99
Plugin.cs
99
Plugin.cs
|
|
@ -1,4 +1,5 @@
|
|||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using BepInEx.Logging;
|
||||
using HarmonyLib;
|
||||
using MyBox;
|
||||
|
|
@ -6,32 +7,43 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace DisableShelves
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
public static string GetColor(this Label label)
|
||||
{
|
||||
return label.gameObject.transform.GetChild(0).GetChild(0).GetComponent<MeshRenderer>().material.color.ToHex();
|
||||
}
|
||||
public static Label GetLabel(this DisplaySlot slot)
|
||||
{
|
||||
return ((Label)typeof(DisplaySlot).GetField("m_Label", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(slot));
|
||||
}
|
||||
}
|
||||
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
|
||||
public class Plugin : BaseUnityPlugin
|
||||
{
|
||||
public const string YellowColor = "#FFDF00";
|
||||
public const string RedColor = "#FF0000";
|
||||
public static List<Label> RedLabels = new();
|
||||
public static ManualLogSource StaticLogger;
|
||||
public static ConfigEntry<string> DisabledLabels { get; private set; }
|
||||
public static List<string> DisabledLabelsGUIDs { get => DisabledLabels.Value.Split(';', StringSplitOptions.RemoveEmptyEntries).ToList(); set => DisabledLabels.Value = string.Join(";", value); }
|
||||
public static ConfigEntry<KeyboardShortcut> MultiModeShortcut { get; private set; }
|
||||
private void Dumbass() => Awake();
|
||||
private void Awake()
|
||||
{
|
||||
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded! Applying patch...");
|
||||
Harmony harmony = new Harmony("com.orpticon.DisableShelves");
|
||||
harmony.PatchAll();
|
||||
StaticLogger = Logger;
|
||||
DisabledLabels = Config.Bind("Storage", "Disabled Labels (Do not edit)", "", "Semicolon separated list of labels to disable. This is maintained automatically and should not be manually altered.");
|
||||
MultiModeShortcut = Config.Bind("General", "Multi Mode Shortcut", new KeyboardShortcut(KeyCode.LeftControl), "What key to hold while clicking in order to enable/disable entire shelves at once.");
|
||||
//SceneManager.sceneLoaded += (a, b) =>
|
||||
//{
|
||||
// if (Singleton<DisplayManager>.Instance != null)
|
||||
// {
|
||||
// var disabled = DisabledLabelsGUIDs;
|
||||
// Singleton<DisplayManager>.Instance.DisplayedProducts.Values.SelectMany(x => x).Where(x =>
|
||||
// {
|
||||
// bool disable = disabled.Contains(x.GetLabel().ToGUID());
|
||||
// StaticLogger.LogInfo(x.GetLabel().ToGUID() + ": " + disable);
|
||||
// return disable;
|
||||
// }).ForEach(x => x.GetLabel().Disable());
|
||||
// }
|
||||
//};
|
||||
}
|
||||
public void Update()
|
||||
{
|
||||
|
|
@ -40,7 +52,8 @@ namespace DisableShelves
|
|||
foreach (var label in RedLabels)
|
||||
{
|
||||
var displaySlot = ((DisplaySlot)fi_m_DisplaySlot.GetValue(label));
|
||||
if (!displaySlot.HasProduct) {
|
||||
if (!displaySlot.HasProduct)
|
||||
{
|
||||
mi_ClearLabel.Invoke(label, null);
|
||||
var cube = label.gameObject.transform.GetChild(0).GetChild(0);
|
||||
var canvasbg = label.gameObject.transform.GetChild(1).GetChild(0);
|
||||
|
|
@ -53,66 +66,4 @@ namespace DisableShelves
|
|||
}
|
||||
}
|
||||
}
|
||||
public static class ShelfLabelPatch
|
||||
{
|
||||
[HarmonyPatch(typeof(DisplayManager), "GetLabeledEmptyDisplaySlots")]
|
||||
public static class DisplayManager_GetLabeledEmptyDisplaySlots_Patch
|
||||
{
|
||||
public static void Postfix(ref List<DisplaySlot> __result)
|
||||
{
|
||||
__result = __result.Where(x => x.GetLabel().GetColor() != "#FF0000").ToList();
|
||||
}
|
||||
}
|
||||
[HarmonyPatch(typeof(Restocker), "IsDisplaySlotAvailableToRestock")]
|
||||
public static class Restocker_IsDisplaySlotAvailableToRestock_Patch
|
||||
{
|
||||
public static void Postfix(DisplaySlot displaySlot, ref bool __result)
|
||||
{
|
||||
if (!__result) return;
|
||||
var color = displaySlot.GetLabel().GetColor();
|
||||
//if (!(color == "#FFD53A" || color == "#FFEB04")) Plugin.StaticLogger.LogError("color is " + color);
|
||||
if (color == "#FF0000") __result = false;
|
||||
}
|
||||
}
|
||||
[HarmonyPatch(typeof(Label), "ClearLabel")]
|
||||
[HarmonyPriority(10000)]
|
||||
public static class Label_ClearLabel_Patch
|
||||
{
|
||||
public static bool Prefix(Label __instance)
|
||||
{
|
||||
//Plugin.StaticLogger.LogInfo("Running prefix patcher");
|
||||
var fi_m_DisplaySlot = typeof(Label).GetField("m_DisplaySlot", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||
var displaySlot = ((DisplaySlot)fi_m_DisplaySlot.GetValue(__instance));
|
||||
if (displaySlot != null)
|
||||
{
|
||||
if (displaySlot.HasProduct)
|
||||
{
|
||||
//Plugin.StaticLogger.LogInfo("Label is shelf");
|
||||
var cube = __instance.gameObject.transform.GetChild(0).GetChild(0);
|
||||
var canvasbg = __instance.gameObject.transform.GetChild(1).GetChild(0);
|
||||
|
||||
var mat = cube.GetComponent<MeshRenderer>().material;
|
||||
var color = mat.color.ToHex();
|
||||
//Plugin.StaticLogger.LogInfo("Color is " + color);
|
||||
if (color == "#FFD53A" || color == "#FFEB04")
|
||||
{
|
||||
//Plugin.StaticLogger.LogInfo("Making label red");
|
||||
mat.color = Color.red;
|
||||
canvasbg.GetComponent<RawImage>().enabled = false;
|
||||
Plugin.RedLabels.Add(__instance);
|
||||
}
|
||||
else
|
||||
{
|
||||
mat.color = Color.yellow;
|
||||
canvasbg.GetComponent<RawImage>().enabled = true;
|
||||
Plugin.RedLabels.Remove(__instance);
|
||||
}
|
||||
//Plugin.StaticLogger.LogWarning("Returning true");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue