/EquipmentForgeContent.cs

https://bitbucket.org/MyongJu/decompile · C# · 139 lines · 124 code · 10 blank · 5 comment · 32 complexity · 0b4e94c9f6eab3d76661c89e6fe9d672 MD5 · raw file

  1. // Decompiled with JetBrains decompiler
  2. // Type: EquipmentForgeContent
  3. // Assembly: Assembly-CSharp, Version=4.12.6598.34475, Culture=neutral, PublicKeyToken=null
  4. // MVID: 117C5EA5-1942-44C4-A271-22ED43202EF1
  5. // Assembly location: D:\Work\apk_reversing\assets\bin\Data\Managed\Assembly-CSharp.dll
  6. using DB;
  7. using System.Collections.Generic;
  8. using UnityEngine;
  9. public class EquipmentForgeContent : MonoBehaviour
  10. {
  11. public GameObject template;
  12. public UIGrid grid;
  13. public UIScrollView scrollView;
  14. public EquipmentForgeInfo info;
  15. public UILabel gotoBtnLabel;
  16. public int currentSelectInfoID;
  17. public EquipmentScrollComponent current;
  18. private List<EquipmentScrollComponent> contentList;
  19. private List<ConfigEquipmentScrollInfo> infos;
  20. private BagType _bagType;
  21. public void Init(BagType bagType, List<ConfigEquipmentScrollInfo> infos, bool clear = false, int targetSelectInfoID = 0)
  22. {
  23. this._bagType = bagType;
  24. this.infos = infos;
  25. if (targetSelectInfoID != 0)
  26. this.currentSelectInfoID = targetSelectInfoID;
  27. this.current = (EquipmentScrollComponent) null;
  28. if (clear)
  29. this.currentSelectInfoID = 0;
  30. this.ClearGrid();
  31. this.contentList = new List<EquipmentScrollComponent>();
  32. for (int index = 0; index < infos.Count; ++index)
  33. {
  34. GameObject gameObject = NGUITools.AddChild(this.grid.gameObject, this.template);
  35. gameObject.SetActive(true);
  36. EquipmentScrollComponent component = gameObject.GetComponent<EquipmentScrollComponent>();
  37. component.OnSelectedHandler = new System.Action<EquipmentScrollComponent>(this.OnSelectedHandler);
  38. this.contentList.Add(component);
  39. component.FeedData((IComponentData) new EquipmentScrollComponetData(infos[index], this._bagType));
  40. if (component.scrollInfo.internalId == this.currentSelectInfoID)
  41. {
  42. this.current = component;
  43. this.current.Select = true;
  44. }
  45. }
  46. if (this.contentList.Count > 0)
  47. {
  48. if ((UnityEngine.Object) this.current == (UnityEngine.Object) null)
  49. {
  50. this.current = this.contentList[0];
  51. this.current.Select = true;
  52. this.currentSelectInfoID = this.current.scrollInfo.internalId;
  53. }
  54. this.info.Init(this._bagType, this.current.scrollInfo.internalId);
  55. }
  56. else
  57. this.info.Init(this._bagType, 0);
  58. this.grid.Reposition();
  59. this.scrollView.ResetPosition();
  60. if ((UnityEngine.Object) this.current != (UnityEngine.Object) null)
  61. this.CenterOn(this.current.transform);
  62. this.ConfigGotBtn();
  63. DBManager.inst.GetInventory(this._bagType).onDataRemoved -= new System.Action<long, long>(this.OnInventoryChanged);
  64. DBManager.inst.GetInventory(this._bagType).onDataRemoved += new System.Action<long, long>(this.OnInventoryChanged);
  65. DBManager.inst.GetInventory(this._bagType).onDataChanged -= new System.Action<long, long>(this.OnInventoryChanged);
  66. DBManager.inst.GetInventory(this._bagType).onDataChanged += new System.Action<long, long>(this.OnInventoryChanged);
  67. }
  68. private void ConfigGotBtn()
  69. {
  70. if ((UnityEngine.Object) this.gotoBtnLabel == (UnityEngine.Object) null)
  71. return;
  72. if (DBManager.inst.GetInventory(this._bagType).HasMyEquipment(this.current.scrollInfo.equipmenID))
  73. this.gotoBtnLabel.text = Utils.XLAT("forge_uppercase_go_to_enhance_button");
  74. else
  75. this.gotoBtnLabel.text = Utils.XLAT("forge_uppercase_go_to_forge_button");
  76. }
  77. private void OnInventoryChanged(long uid, long itemId)
  78. {
  79. this.Init(this._bagType, this.infos, false, this.currentSelectInfoID);
  80. }
  81. public void Dispose()
  82. {
  83. DBManager.inst.GetInventory(this._bagType).onDataRemoved -= new System.Action<long, long>(this.OnInventoryChanged);
  84. DBManager.inst.GetInventory(this._bagType).onDataChanged -= new System.Action<long, long>(this.OnInventoryChanged);
  85. this.info.Dispose();
  86. }
  87. private void OnSelectedHandler(EquipmentScrollComponent selected)
  88. {
  89. if (!((UnityEngine.Object) this.current != (UnityEngine.Object) null) || this.current.scrollInfo.internalId == selected.scrollInfo.internalId)
  90. return;
  91. this.currentSelectInfoID = selected.scrollInfo.internalId;
  92. this.current.Select = false;
  93. this.current = selected;
  94. this.current.Select = true;
  95. this.info.Init(this._bagType, this.current.scrollInfo.internalId);
  96. this.ConfigGotBtn();
  97. }
  98. private void ClearGrid()
  99. {
  100. UIUtils.CleanGrid(this.grid);
  101. }
  102. public void CenterOn(Transform target)
  103. {
  104. if (!((UnityEngine.Object) this.scrollView != (UnityEngine.Object) null) || !((UnityEngine.Object) this.scrollView.panel != (UnityEngine.Object) null))
  105. return;
  106. Vector3[] worldCorners = this.scrollView.panel.worldCorners;
  107. Vector3 panelBottom = (worldCorners[1] + worldCorners[2]) * 0.5f;
  108. this.CenterOn(target, panelBottom);
  109. }
  110. private void CenterOn(Transform target, Vector3 panelBottom)
  111. {
  112. if (!((UnityEngine.Object) target != (UnityEngine.Object) null) || !((UnityEngine.Object) this.scrollView != (UnityEngine.Object) null) || (!((UnityEngine.Object) this.scrollView.panel != (UnityEngine.Object) null) || !(this.scrollView.currentMomentum == Vector3.zero)))
  113. return;
  114. Transform cachedTransform = this.scrollView.panel.cachedTransform;
  115. Vector3 vector3 = cachedTransform.InverseTransformPoint(target.position) - cachedTransform.InverseTransformPoint(panelBottom);
  116. if (!this.scrollView.canMoveHorizontally)
  117. vector3.x = 0.0f;
  118. if (!this.scrollView.canMoveVertically)
  119. vector3.y = 0.0f;
  120. vector3.z = 0.0f;
  121. vector3.y += this.grid.cellHeight / 2f;
  122. cachedTransform.localPosition -= vector3;
  123. Vector4 clipOffset = (Vector4) this.scrollView.panel.clipOffset;
  124. clipOffset.x += vector3.x;
  125. clipOffset.y += vector3.y;
  126. this.scrollView.panel.clipOffset = (Vector2) clipOffset;
  127. this.scrollView.RestrictWithinBounds(true);
  128. }
  129. }