QuickStack.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using UnityEngine;
  2. using GadgetCore.API;
  3. using UnityEngine.SceneManagement;
  4. using System;
  5. using QuickStack.ConfigEnums;
  6. using System.Reflection;
  7. using GadgetCore.API.ConfigMenu;
  8. namespace QuickStack
  9. {
  10. [Gadget("QuickStack", RequiredOnClients: false)]
  11. public class QuickStack : Gadget<QuickStack>
  12. {
  13. public const string MOD_VERSION = "1.2"; // Set this to the version of your mod.
  14. public const string CONFIG_VERSION = "1.1"; // Increment this whenever you change your mod's config file.
  15. protected override void LoadConfig()
  16. {
  17. Config.Load();
  18. string fileVersion = Config.ReadString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
  19. if (fileVersion != CONFIG_VERSION)
  20. {
  21. Config.Reset();
  22. Config.WriteString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
  23. }
  24. Core.settingStackSource = Config.ReadEnum("TakeItemsFrom", StackSourceInventoryEnum.Both, comments: new string[] { "Were should items be taken from?" });
  25. Core.settingStackPotionsSource = Config.ReadEnum("TakePotionsFrom", StackSourceInventoryPotionsEnum.OnlyMainInventory, comments: new string[] { "Were should potions be taken from?" });
  26. Core.settingStackMode = Config.ReadEnum("StackMode", StackModeEnum.FillPageContaining, comments: new string[] { "How should items be inserted?" });
  27. Core.settingStackRange = Config.ReadEnum("StackRange", StackRangeEnum.AllPages, comments: new string[] { "Were should items be inserted?" });
  28. Config.Save();
  29. }
  30. private T GetFromStatic<T>(string classString, string paramString)
  31. {
  32. var type = Type.GetType("GadgetCore" + "." + classString + ", GadgetCore");
  33. var field = type.GetProperty(paramString, BindingFlags.Public | BindingFlags.Static);
  34. MethodInfo strGetter = field.GetGetMethod();
  35. return (T)strGetter.Invoke(null, null);
  36. }
  37. public override string GetModDescription()
  38. {
  39. return "A mod that add a quick stack button to the chest menu.";
  40. }
  41. protected override void Initialize()
  42. {
  43. Logger.Log("QuickStack v" + Info.Mod.Version);
  44. Core.logger = Logger;
  45. SceneManager.sceneLoaded += OnSceneLoaded;
  46. }
  47. internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
  48. {
  49. if (scene.buildIndex == 1)
  50. {
  51. try
  52. {
  53. var storageMenu = GameObject.Find("Main Camera").transform.Find("menuStorage").gameObject;
  54. var pagge0 = storageMenu.transform.Find("page0");
  55. var btn = UnityEngine.Object.Instantiate(pagge0, pagge0.transform.parent).gameObject;
  56. btn.name = "button_quick_stack";
  57. Component.Destroy(btn.GetComponentInChildren<ButtonMenu>());
  58. btn.transform.localPosition = new Vector3(-0.3359f, -0.1251f, 0.97f) + new Vector3(-0.175f, 0.475f, -2);
  59. btn.transform.localScale = new Vector3(1f / 16f, 1f / 16f, 1);
  60. btn.AddComponent<StackButtonScript>();
  61. btn.GetComponentInChildren<BoxCollider>().size = new Vector3(2, 2, 2);
  62. btn.transform.SetParent(storageMenu.transform);
  63. }
  64. catch (Exception e) { Core.logger.Log(e.Message); }
  65. }
  66. }
  67. }
  68. }