CombatChipStore.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using GadgetCore.API;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using UnityEngine;
  8. namespace CombatChipChest
  9. {
  10. public class CombatChipStore
  11. {
  12. public CombatChipStore(int size, string id)
  13. {
  14. m_ChipIDs = new int[size];
  15. _id = id;
  16. }
  17. private string _id;
  18. private int[] m_ChipIDs;
  19. public int[] ChipIDs
  20. {
  21. get { return m_ChipIDs; }
  22. set { m_ChipIDs = value; }
  23. }
  24. public void Save()
  25. {
  26. for (int i = 0; i < m_ChipIDs.Length; i++)
  27. {
  28. PreviewLabs.PlayerPrefs.SetInt("customChipsStore:" + _id + ":" + i, m_ChipIDs[i]);
  29. }
  30. }
  31. public void Load()
  32. {
  33. for (int i = 0; i < m_ChipIDs.Length; i++)
  34. {
  35. m_ChipIDs[i] = PreviewLabs.PlayerPrefs.GetInt("customChipsStore:" + _id + ":" + i, 0);
  36. }
  37. }
  38. public void UpdateLatestUI()
  39. {
  40. UpdateUI(lastUsed);
  41. }
  42. private GameObject lastUsed;
  43. public void UpdateUI(GameObject menu)
  44. {
  45. lastUsed = menu;
  46. var gameScript = (GameScript)Camera.main.GetComponent("GameScript");
  47. try
  48. {
  49. for (int i = 0; i < menu.transform.childCount; i++)
  50. {
  51. var obj = menu.transform.GetChild(i).gameObject;
  52. int number;
  53. if (obj.name.Length > "combat_storage_slot".Length && int.TryParse(obj.name.Substring("combat_storage_slot".Length), out number))
  54. {
  55. obj.GetComponent<Renderer>().material = (Material)Resources.Load("cc/cc" + m_ChipIDs[number]);
  56. }
  57. }
  58. }
  59. catch (Exception e)
  60. {
  61. Core.logger.LogConsole(e.Message);
  62. }
  63. }
  64. public void UpdateText(int id)
  65. {
  66. if (lastUsed != null)
  67. {
  68. var txtChipName = lastUsed.transform.FindChild("txtTitle").gameObject.GetComponent<TextMesh>();
  69. txtChipName.text = GadgetCoreAPI.GetChipName(id);
  70. var txtDesc = lastUsed.transform.FindChild("txtDesc").gameObject.GetComponent<TextMesh>();
  71. txtDesc.text = GadgetCoreAPI.GetChipDesc(id);
  72. var gameScript = (GameScript)Camera.main.GetComponent("GameScript");
  73. var txtCost = lastUsed.transform.FindChild("txtCost").gameObject.GetComponent<TextMesh>();
  74. int chipCost = gameScript.GetChipCost(id);
  75. if (chipCost == -1 && txtChipName.text != string.Empty)
  76. txtCost.text = "Passive";
  77. else if (chipCost > 0)
  78. txtCost.text = chipCost + " Mana";
  79. else
  80. txtCost.text = string.Empty;
  81. }
  82. }
  83. }
  84. }