Quellcode durchsuchen

[RecipeMenuCore] [2.0.2.2] releas version

Zariteis vor 4 Jahren
Ursprung
Commit
a912d2a348

BIN
RecipeMenuCore/Assets/hoverItem.png


+ 6 - 4
RecipeMenuCore/Core.cs

@@ -7,10 +7,12 @@ namespace RecipeMenuCore
 {
   internal static class Core
   {
-    public static List<RecipePage> pageGearForgeInfoList = new List<RecipePage>();
-    public static List<RecipePage> pageAlchemyStationInfoList = new List<RecipePage>();
-    public static List<RecipePage> pageUltimateForgeInfoList = new List<RecipePage>();
+    internal static List<RecipePage> pageGearForgeInfoList = new List<RecipePage>();
+    internal static List<RecipePage> pageAlchemyStationInfoList = new List<RecipePage>();
+    internal static List<RecipePage> pageUltimateForgeInfoList = new List<RecipePage>();
 
-    public static GadgetLogger logger;
+    internal static bool settingUseDialog;
+
+    internal static GadgetLogger logger;
   }
 }

+ 1 - 1
RecipeMenuCore/ModInfo.txt

@@ -1 +1 @@
-A utility mod providing recipe menu extension.
+A utility mod providing a recipe menu API.

+ 75 - 12
RecipeMenuCore/Patches/Patch_GameScript_HoverRecipeSelect.cs

@@ -4,6 +4,7 @@ using UnityEngine;
 using System.Collections;
 using System.Reflection;
 using System.Collections.Generic;
+using System.Globalization;
 
 namespace RecipeMenuCore.Patches
 {
@@ -13,11 +14,19 @@ namespace RecipeMenuCore.Patches
   public static class Patch_GameScript_HoverRecipeSelect
   {
     [HarmonyPrefix]
-    public static bool Prefix(GameScript __instance, int id, int ___craftType, ref int ___curRecipePage, GameObject ___itemexpbar, Item[] ___storage, GameObject[] ___aspectObj, TextMesh ___itemName,
+    public static bool Prefix(GameScript __instance, int id, int ___craftType, ref int ___curRecipePage, GameObject ___itemexpbar, GameObject[] ___aspectObj, TextMesh ___itemName,
       GameObject ___hoverItem, TextMesh[] ___itemStat, GameObject ___txtStats, TextMesh ___itemDesc, Material ___hoverItemMat2, Material ___hoverItemMat1, GameObject ___hoverDroid,
-      TextMesh[] ___txtHoverStat, TextMesh ___txtHoverStatInfo, TextMesh[] ___itemAspect, TextMesh ___itemLevel)
+      TextMesh[] ___txtHoverStat, TextMesh ___txtHoverStatInfo, TextMesh[] ___itemAspect, TextMesh ___itemLevel, GameObject[] ___recipeLock)
     {
-      var item = new Item(GetItemId(id, ___craftType, ___curRecipePage), 1, 0, 0, 0, new int[3], new int[3]);
+      if (!Core.settingUseDialog)
+        return true;
+
+      if(___craftType == 0 || ___craftType == 1)
+      {
+        if (id >= 12 || ___recipeLock[id].active)
+          return false;
+      }
+      var item = new Item(GetItemId(__instance, id, ___craftType, ___curRecipePage), 1, 0, 0, 0, new int[3], new int[3]);
       var itemInfo = ItemRegistry.GetItem(item.id);
 
       ___txtHoverStat[0].text = string.Empty;
@@ -43,7 +52,7 @@ namespace RecipeMenuCore.Patches
       {
         ___itemName.text = itemInfo.Name;
         ___itemName.color = Color.white;
-        ___itemDesc.text = itemInfo.Desc;
+        ___itemDesc.text = GenerateDescription(itemInfo);
 
         bool hasStats = false;
         int[] gearBaseStats = ItemRegistry.GetItem(item.id).Stats.GetStatArray();
@@ -76,21 +85,75 @@ namespace RecipeMenuCore.Patches
       mainTexture = GadgetCoreAPI.LoadTexture2D("hoverItem.png")
     };
 
-    private static int GetItemId(int index, int craftType, int curRecipePage)
+    private static string GenerateDescription(ItemInfo item)
     {
-      if (craftType == 0 && curRecipePage >= 6)
+      if ((item.GetID() >= 1000 && item.GetID() < 1000 + 6 )
+        || (item.GetID() >= 1012 && item.GetID() < 1012 + 3 * 6))
+        return "";
+      var desc = item.Desc;
+      if (desc == null || desc.Length <= 0)
       {
-        return Core.pageGearForgeInfoList[curRecipePage - 6].GetRecipePageEntries()[index].ItemIdBase;
+        float[] ws = item.WeaponScaling;
+        if (ws != null)
+        {
+          string o = "";
+          for (int i = 0; i < ws.Length; i++)
+          {
+            if (ws[i] > 0)
+            {
+              string type = i == 0 ? "VIT" : i == 1 ? "STR" : i == 2 ? "DEX" : i == 3 ? "TEC" : i == 4 ? "MAG" : "FTH";
+              o += "DMG x" + (ws[i] >= 1 ? ws[i].ToString(CultureInfo.InvariantCulture) : "1/" + (1 / ws[i])).ToString(CultureInfo.InvariantCulture) + " " + type + "\n";
+            }
+          }
+          return o;
+        }
       }
-      else if (craftType == 1 && curRecipePage >= 2)
+      return desc;
+    }
+
+    private static int GetItemId(GameScript __instance, int index, int craftType, int curRecipePage)
+    {
+      if (index >= 12)
       {
-        return Core.pageAlchemyStationInfoList[curRecipePage - 2].GetRecipePageEntries()[index].ItemIdBase;
+        if (craftType == 2 && curRecipePage >= 6)
+          return Core.pageUltimateForgeInfoList[curRecipePage - 6].GetRecipePageEntries()[(index - 12) / 3].ItemIdExtension[(index - 12) % 3];
+        return CalculateUltimaleWeapon((index - 12) % (3 * 6), (index - 12) / (3 * 6) + curRecipePage * 2);
       }
+      if (craftType == 0 && curRecipePage >= 6)
+        return Core.pageGearForgeInfoList[curRecipePage - 6].GetRecipePageEntries()[index].ItemIdBase;
+      else if (craftType == 1 && curRecipePage >= 2)
+        return Core.pageAlchemyStationInfoList[curRecipePage - 2].GetRecipePageEntries()[index].ItemIdBase;
       else if (craftType == 2 && curRecipePage >= 6)
-      {
         return Core.pageUltimateForgeInfoList[curRecipePage - 6].GetRecipePageEntries()[index].ItemIdBase;
-      }
-      return 1;
+      return __instance.GetRecipeItem(curRecipePage, index).id;
+    }
+    private static int CalculateUltimaleWeapon(int index, int page)
+    {
+      if (page == 0)
+        return 312 + index;
+      if (page == 1)
+        return 362 + index;
+      if (page == 2)
+        return 412 + index;
+      if (page == 3)
+        return 462 + index;
+      if (page == 4)
+        return 512 + index;
+      if (page == 5)
+        return 562 + index;
+      if (page == 6) //shield
+        return 612 + index;
+      if (page == 7) //droid
+        return 1012 + index;
+      if (page == 8) //helmet 1
+        return 750 + index;
+      if (page == 9) //helmet 2
+        return 768 + index;
+      if (page == 10) //armor 1
+        return 850 + index;
+      if (page == 11) //armor 2
+        return 868 + index;
+      return 0;
     }
   }
 }

+ 31 - 1
RecipeMenuCore/Patches/Patch_GameScript_RefreshRecipeUnlock.cs

@@ -14,7 +14,7 @@ namespace RecipeMenuCore.Patches
   {
     [HarmonyPrefix]
     public static bool Prefix(GameScript __instance, int ___craftType, int ___curRecipePage, GameObject ___ultLocksObj, GameObject ___recipeButtons,
-      GameObject[] ___recipeLock, GameObject[] ___ultLocks)
+      GameObject[] ___recipeLock, GameObject[] ___ultLocks, int[,] ___ultLocksUnlocked)
     {
       if (___craftType == 0 || ___craftType == 1)
       {
@@ -23,6 +23,26 @@ namespace RecipeMenuCore.Patches
           ___recipeButtons.transform.GetChild(i).gameObject.SetActive(true);
         }
       }
+
+      var hoverElements = ___ultLocksObj.transform.parent.Find("hoverElements").gameObject;
+      hoverElements.SetActive(false);
+
+      if (___craftType == 2 && ___curRecipePage < 6)
+      {
+        hoverElements.SetActive(true);
+        for (int i = 0; i < 36; i++)
+        {
+          if (___ultLocksUnlocked[___curRecipePage, i] == 0)
+          {
+            hoverElements.transform.GetChild(i).gameObject.SetActive(false);
+          }
+          else
+          {
+            hoverElements.transform.GetChild(i).gameObject.SetActive(true);
+          }
+        }
+      }
+
       if (___craftType == 0 && ___curRecipePage >= 6)
       {
         ___ultLocksObj.SetActive(false);
@@ -69,6 +89,7 @@ namespace RecipeMenuCore.Patches
       }
       else if (___craftType == 2 && ___curRecipePage >= 6)
       {
+        hoverElements.SetActive(true);
         ___ultLocksObj.SetActive(true);
         ___recipeButtons.SetActive(false);
         for (int i = 0; i < 36; i++)
@@ -81,12 +102,21 @@ namespace RecipeMenuCore.Patches
           {
             int itemID = Core.pageUltimateForgeInfoList[___curRecipePage - 6].GetRecipePageEntries()[i / 3].ItemIdExtension[i % 3];
             if (__instance.RecipeCraftedAlready(itemID, 0))
+            {
               ___ultLocks[i].SetActive(false);
+              hoverElements.transform.GetChild(i).gameObject.SetActive(true);
+            }
             else
+            {
               ___ultLocks[i].SetActive(true);
+              hoverElements.transform.GetChild(i).gameObject.SetActive(false);
+            }
           }
           else
+          {
             ___ultLocks[i].SetActive(false);
+            hoverElements.transform.GetChild(i).gameObject.SetActive(false);
+          }
         }
         return false;
       }

+ 2 - 16
RecipeMenuCore/Patches/Patch_GameScript_Update.cs

@@ -13,25 +13,11 @@ namespace RecipeMenuCore.Patches
   public static class Patch_GameScript_Update
   {
     [HarmonyPrefix]
-    public static bool Prefix(GameScript __instance, int ___craftType, int ___curRecipePage, GameObject ___ultLocksObj, GameObject ___recipeButtons,
-      GameObject[] ___recipeLock, int[,] ___ultLocksUnlocked, GameObject[] ___ultLocks, Item[] ___inventory, Item[] ___craft)
+    public static bool Prefix(GameScript __instance, int ___craftType, int ___curRecipePage, Item[] ___inventory, Item[] ___craft)
     {
       bool acted = false;
       if (MenuScript.player)
       {
-        if (GameScript.inventoryOpen)
-        {
-          var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
-          RaycastHit hit;
-          if (Physics.Raycast(ray, out hit, 5f))
-          {
-            if (hit.transform.gameObject.tag == "recipe")
-            {
-              __instance.HoverRecipeSelect(int.Parse(hit.transform.gameObject.name));
-              //acted = true;
-            }
-          }
-        }
         if (!GameScript.pausing)
         {
           if (Input.GetMouseButtonDown(0) && GameScript.inventoryOpen)
@@ -181,7 +167,7 @@ namespace RecipeMenuCore.Patches
           else
             __instance.Error(6);
         }
-        catch (System.Exception e) { Core.logger.LogConsole(e); }
+        catch (System.Exception e) { Core.logger.Log(e); }
         finally
         {
           quickCraftingField.SetValue(__instance, false);

+ 1 - 1
RecipeMenuCore/Properties/AssemblyInfo.cs

@@ -3,7 +3,7 @@ using static RecipeMenuCore.RecipeMenuCore;
 
 [assembly: AssemblyProduct("RecipeMenuCore")] //Set this to the full name of the mod including spaces.
 [assembly: AssemblyTitle("ScrapYard")] //This is only used when mousing over a dll file in Windows explorer.
-[assembly: AssemblyDescription("A utility mod providing recipe menu extension.")] //This is a short description for your mod's assembly.
+[assembly: AssemblyDescription("A utility mod providing a recipe menu API.")] //This is a short description for your mod's assembly.
 [assembly: AssemblyCompany("")] //Set this to your name/nickname and/or website
 [assembly: AssemblyCopyright("© 2021 Zariteis. All rights reserved.")] //Set this to your copyright name.
 [assembly: AssemblyVersion(MOD_VERSION)]

+ 43 - 4
RecipeMenuCore/RecipeMenuCore.cs

@@ -2,6 +2,8 @@ using GadgetCore.API;
 using GadgetCore.API.ConfigMenu;
 using RecipeMenuCore.API;
 using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.SceneManagement;
 
 namespace RecipeMenuCore
 {
@@ -14,15 +16,22 @@ namespace RecipeMenuCore
 
     protected override void LoadConfig()
     {
-      Config.Reset();
+      Config.Load();
+      string fileVersion = Config.ReadString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
+      if (fileVersion != CONFIG_VERSION)
+      {
+        Config.Reset();
+        Config.WriteString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
+      }
+
+      Core.settingUseDialog = Config.ReadBool("UseDialog", true, comments: new string[] { "Should an item dialog be shown in recipe menus?" });
+
       Config.Save();
     }
 
-    public override IGadgetConfigMenu GetConfigMenu() { return null; }
-
     public override string GetModDescription()
     {
-      return "A utility mod providing recipe menu extension.";
+      return "A utility mod providing a recipe menu API.";
     }
 
     protected override void Initialize()
@@ -33,6 +42,36 @@ namespace RecipeMenuCore
       Core.pageGearForgeInfoList = new List<RecipePage>();
       Core.pageAlchemyStationInfoList = new List<RecipePage>();
       Core.pageUltimateForgeInfoList = new List<RecipePage>();
+      SceneManager.sceneLoaded += OnSceneLoaded;
+    }
+
+    internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
+    {
+      if (scene.buildIndex == 1)
+      {
+        var menuRecipeElement = GameObject.Find("Main Camera").transform.Find("menuRecipe");
+        var locksElement = menuRecipeElement.Find("ultLocks").gameObject;
+        var hoverElements = Object.Instantiate(locksElement, menuRecipeElement.transform);
+        hoverElements.name = "hoverElements";
+        for (int i = 0; i < 12 * 3; i++)
+        {
+          var element = hoverElements.transform.GetChild(i).gameObject;
+          Component.DestroyImmediate(element.GetComponent<Renderer>());
+          var collider = element.AddComponent<BoxCollider>();
+          collider.size = new Vector3(14f / 32f * 2, (18f + 1) / 32f * 2, 1);
+          collider.isTrigger = true;
+          element.tag = "recipe";
+          element.layer = 16;
+          element.name = "" + (i + 12);
+        }
+        var buttonsElement = menuRecipeElement.Find("buttons").gameObject;
+        for (int i = 0; i < 12; i++)
+        {
+          var element = buttonsElement.transform.GetChild(i).gameObject;
+          var collider = element.GetComponent<BoxCollider>();
+          collider.size = new Vector3(collider.size.x, 0.6f, collider.size.z);
+        }
+      }
     }
   }
 }