Browse Source

[2.0.4.6] Better Interface to StorageExtention

Zariteis 4 years ago
parent
commit
3303e3e5ca

+ 9 - 0
DataConnection/IStorageData.cs

@@ -0,0 +1,9 @@
+namespace QuickStack.DataConnection
+{
+  public interface IStorageData
+  {
+    int slots { get; }
+    int slotsActual { get; }
+    int pages { get; }
+  }
+}

+ 11 - 0
DataConnection/StorageExtentionStorageData.cs

@@ -0,0 +1,11 @@
+using System;
+
+namespace QuickStack.DataConnection
+{
+  internal class StorageExtentionStorageData : IStorageData
+  {
+    public int slots => Math.Max(StorageExpansion.API.StorageSizeInterface.Slots, 5 * 6);
+    public int slotsActual => StorageExpansion.API.StorageSizeInterface.Slots;
+    public int pages => StorageExpansion.API.StorageSizeInterface.Pages;
+  }
+}

+ 9 - 0
DataConnection/VanillaStorageData.cs

@@ -0,0 +1,9 @@
+namespace QuickStack.DataConnection
+{
+  internal class VanillaStorageData : IStorageData
+  {
+    public int slots => 5 * 6;
+    public int slotsActual => 5 * 6;
+    public int pages => 2 * 6;
+  }
+}

+ 23 - 14
Patches/Patch_GameScript_Update.cs

@@ -2,6 +2,7 @@
 using GadgetCore.API;
 using GadgetCore.API;
 using HarmonyLib;
 using HarmonyLib;
 using QuickStack.ConfigEnums;
 using QuickStack.ConfigEnums;
+using QuickStack.DataConnection;
 using System;
 using System;
 using System.Collections;
 using System.Collections;
 using System.Reflection;
 using System.Reflection;
@@ -15,9 +16,17 @@ namespace QuickStack.Patches
   [HarmonyGadget("QuickStack")]
   [HarmonyGadget("QuickStack")]
   public static class Patch_GameScript_Update
   public static class Patch_GameScript_Update
   {
   {
+    private static IStorageData storageData;
+
     [HarmonyPrefix]
     [HarmonyPrefix]
     public static void Prefix(GameScript __instance, Item[] ___inventory, ref Item[] ___storage, int ___storageLevel, int ___curStoragePage)
     public static void Prefix(GameScript __instance, Item[] ___inventory, ref Item[] ___storage, int ___storageLevel, int ___curStoragePage)
     {
     {
+
+      if (Gadgets.GetGadget("StorageExpansion")?.Enabled ?? false)
+        storageData = new StorageExtentionStorageData();
+      else
+        storageData = new VanillaStorageData();
+
       try
       try
       {
       {
         if (MenuScript.player)
         if (MenuScript.player)
@@ -30,17 +39,17 @@ namespace QuickStack.Patches
             {
             {
               if (hit.transform.gameObject.name.StartsWith("button_quick_stack"))
               if (hit.transform.gameObject.name.StartsWith("button_quick_stack"))
               {
               {
-                for (int slot = 0; slot < 36; slot++)
+                for (int slot = 0; slot < 6 * 6; slot++)
                 {
                 {
                   bool updateSlot = false;
                   bool updateSlot = false;
                   int startPage = Core.settingStackRange == StackRangeEnum.OpenPage ? ___curStoragePage : 0;
                   int startPage = Core.settingStackRange == StackRangeEnum.OpenPage ? ___curStoragePage : 0;
-                  int endPage = Core.settingStackRange == StackRangeEnum.OpenPage ? ___curStoragePage + 1 : ___storageLevel + 1;
+                  int endPage = Core.settingStackRange == StackRangeEnum.OpenPage ? ___curStoragePage + 1 : Math.Min(___storageLevel + 1, storageData.pages);
                   for (int page = startPage; page < endPage; page++)
                   for (int page = startPage; page < endPage; page++)
                   {
                   {
                     bool contains = false;
                     bool contains = false;
                     Item item = ___inventory[slot];
                     Item item = ___inventory[slot];
-                    for (int slotPage = 0; slotPage < 30; slotPage++)
-                      if (___storage[page * 30 + slotPage].id == item.id)
+                    for (int slotPage = 0; slotPage < storageData.slotsActual; slotPage++)
+                      if (___storage[page * storageData.slots + slotPage].id == item.id)
                         contains = true;
                         contains = true;
 
 
                     bool potion = item.id >= 60 && item.id <= 73;
                     bool potion = item.id >= 60 && item.id <= 73;
@@ -66,12 +75,12 @@ namespace QuickStack.Patches
                       ItemType slotItemType = slotInfo != null ? (slotInfo.Type & (ItemType.EQUIP_MASK | ItemType.TYPE_MASK)) : ItemRegistry.GetDefaultTypeByID(item.id);
                       ItemType slotItemType = slotInfo != null ? (slotInfo.Type & (ItemType.EQUIP_MASK | ItemType.TYPE_MASK)) : ItemRegistry.GetDefaultTypeByID(item.id);
                       if ((slotItemType & ItemType.NONSTACKING) == ItemType.STACKING)
                       if ((slotItemType & ItemType.NONSTACKING) == ItemType.STACKING)
                       {
                       {
-                        for (int slotPage = 0; slotPage < 30; slotPage++)
-                          if (GadgetCoreAPI.CanItemsStack(___storage[page * 30 + slotPage], item))
+                        for (int slotPage = 0; slotPage < storageData.slotsActual; slotPage++)
+                          if (GadgetCoreAPI.CanItemsStack(___storage[page * storageData.slots + slotPage], item))
                           {
                           {
-                            while (___storage[page * 30 + slotPage].q < 9999 && item.q > 0)
+                            while (___storage[page * storageData.slots + slotPage].q < 9999 && item.q > 0)
                             {
                             {
-                              ___storage[page * 30 + slotPage].q++;
+                              ___storage[page * storageData.slots + slotPage].q++;
                               item.q--;
                               item.q--;
                               updateSlot = true;
                               updateSlot = true;
                             }
                             }
@@ -80,10 +89,10 @@ namespace QuickStack.Patches
                           ___inventory[slot] = new Item(0, 0, 0, 0, 0, new int[3], new int[3]);
                           ___inventory[slot] = new Item(0, 0, 0, 0, 0, new int[3], new int[3]);
                         else if (Core.settingStackMode != ConfigEnums.StackModeEnum.StackingOnly)
                         else if (Core.settingStackMode != ConfigEnums.StackModeEnum.StackingOnly)
                         {
                         {
-                          for (int slotPage = 0; slotPage < 30; slotPage++)
-                            if (___storage[page * 30 + slotPage].id == 0)
+                          for (int slotPage = 0; slotPage < storageData.slotsActual; slotPage++)
+                            if (___storage[page * storageData.slots + slotPage].id == 0)
                             {
                             {
-                              ___storage[page * 30 + slotPage] = item;
+                              ___storage[page * storageData.slots + slotPage] = item;
                               ___inventory[slot] = new Item(0, 0, 0, 0, 0, new int[3], new int[3]);
                               ___inventory[slot] = new Item(0, 0, 0, 0, 0, new int[3], new int[3]);
                               updateSlot = true;
                               updateSlot = true;
                               break;
                               break;
@@ -92,10 +101,10 @@ namespace QuickStack.Patches
                       }
                       }
                       else if (Core.settingStackMode != ConfigEnums.StackModeEnum.StackingOnly)
                       else if (Core.settingStackMode != ConfigEnums.StackModeEnum.StackingOnly)
                       {
                       {
-                        for (int slotPage = 0; slotPage < 30; slotPage++)
-                          if (___storage[page * 30 + slotPage].id == 0)
+                        for (int slotPage = 0; slotPage < storageData.slotsActual; slotPage++)
+                          if (___storage[page * storageData.slots + slotPage].id == 0)
                           {
                           {
-                            ___storage[page * 30 + slotPage] = item;
+                            ___storage[page * storageData.slots + slotPage] = item;
                             ___inventory[slot] = new Item(0, 0, 0, 0, 0, new int[3], new int[3]);
                             ___inventory[slot] = new Item(0, 0, 0, 0, 0, new int[3], new int[3]);
                             updateSlot = true;
                             updateSlot = true;
                             break;
                             break;

+ 2 - 2
QuickStack.cs

@@ -11,7 +11,7 @@ namespace QuickStack
   [Gadget("QuickStack", RequiredOnClients: false)]
   [Gadget("QuickStack", RequiredOnClients: false)]
   public class QuickStack : Gadget<QuickStack>
   public class QuickStack : Gadget<QuickStack>
   {
   {
-    public const string MOD_VERSION = "1.1"; // Set this to the version of your mod.
+    public const string MOD_VERSION = "1.2"; // Set this to the version of your mod.
     public const string CONFIG_VERSION = "1.1"; // Increment this whenever you change your mod's config file.
     public const string CONFIG_VERSION = "1.1"; // Increment this whenever you change your mod's config file.
 
 
     protected override void LoadConfig()
     protected override void LoadConfig()
@@ -63,7 +63,7 @@ namespace QuickStack
           var btn = UnityEngine.Object.Instantiate(pagge0, pagge0.transform.parent).gameObject;
           var btn = UnityEngine.Object.Instantiate(pagge0, pagge0.transform.parent).gameObject;
           btn.name = "button_quick_stack";
           btn.name = "button_quick_stack";
           Component.Destroy(btn.GetComponentInChildren<ButtonMenu>());
           Component.Destroy(btn.GetComponentInChildren<ButtonMenu>());
-          btn.transform.localPosition = pagge0.transform.localPosition + new Vector3(-0.175f, 0.475f, -2);
+          btn.transform.localPosition = new Vector3(-0.3359f, -0.1251f, 0.97f) + new Vector3(-0.175f, 0.475f, -2);
           btn.transform.localScale = new Vector3(1f / 16f, 1f / 16f, 1);
           btn.transform.localScale = new Vector3(1f / 16f, 1f / 16f, 1);
           btn.AddComponent<StackButtonScript>();
           btn.AddComponent<StackButtonScript>();
 
 

+ 5 - 0
QuickStack.csproj

@@ -46,6 +46,11 @@
       <HintPath>$(GamePath)$(ManagedFolder)GadgetCore.dll</HintPath>
       <HintPath>$(GamePath)$(ManagedFolder)GadgetCore.dll</HintPath>
       <Private>false</Private>
       <Private>false</Private>
     </Reference>
     </Reference>
+    <Reference Include="StorageExpansion">
+      <HintPath>..\StorageExpansion\Release\StorageExpansion.dll</HintPath>
+      <Private>false</Private>
+      <SpecificVersion>false</SpecificVersion>
+    </Reference>
     <Reference Include="UnityEngine">
     <Reference Include="UnityEngine">
       <HintPath>$(GamePath)$(ManagedFolder)UnityEngine.dll</HintPath>
       <HintPath>$(GamePath)$(ManagedFolder)UnityEngine.dll</HintPath>
       <Private>false</Private>
       <Private>false</Private>