EquipInfo.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using LitJson;
  6. public class EquipInfo : MonoBehaviour {
  7. public Image border;
  8. public Image icon;
  9. public Text nameTxt;
  10. public Text levelTxt;
  11. public Text descTxt;
  12. public Text upgradeLabel;
  13. public Button upgradeBtn;
  14. public Text upgradePrice;
  15. public Text equipLabel;
  16. public Button equipBtn;
  17. public EquipPanel equipPanel;
  18. public UAVPanel uavPanel;
  19. public UAVSkillInfo uavSkillInfo;
  20. private Equipment equipment;
  21. void Awake()
  22. {
  23. upgradeLabel.text = Language.GetStr ("EquipPanel", "upgrade");
  24. equipLabel.text = Language.GetStr ("EquipPanel", "equip");
  25. }
  26. void OnDestroy()
  27. {
  28. if(equipment != null)
  29. {
  30. equipment.Updated.RemoveListener (EquipUpdated);
  31. }
  32. }
  33. public void SetEquip(Equipment equip)
  34. {
  35. OnDestroy ();
  36. this.equipment = equip;
  37. if(equip != null)
  38. {
  39. equip.Updated.AddListener (EquipUpdated);
  40. border.color = equip.GetData ().GetBorderColor ();
  41. icon.sprite = equip.GetData ().GetIconSprite ();
  42. nameTxt.text = equip.GetData ().GetName ();
  43. nameTxt.color = equip.GetData ().GetTextColor ();
  44. levelTxt.text = equip.GetLevelLabel ();
  45. descTxt.text = equip.GetDescription ();
  46. if (equip.GetLevel () < equip.GetMaxLevel ()) {
  47. if (equip.GetCount () >= equip.GetNextLevelCount ())
  48. ButtonUtil.Selected (upgradeBtn.gameObject);
  49. else
  50. ButtonUtil.Unselect (upgradeBtn.gameObject);
  51. upgradePrice.text = equip.GetUpgradePrice ().ToString();
  52. } else {
  53. ButtonUtil.Unselect (upgradeBtn.gameObject);
  54. upgradePrice.text = "0";
  55. }
  56. if((equipPanel != null && equipPanel.IsEquiped(equip)) || (uavPanel != null && uavPanel.IsEquiped(equip)))
  57. {
  58. ButtonUtil.Unselect (equipBtn.gameObject);
  59. }
  60. else
  61. {
  62. ButtonUtil.Selected (equipBtn.gameObject);
  63. }
  64. }
  65. else
  66. {
  67. border.color = UpgradeUtil.GetCommonBorderColor ();
  68. icon.sprite = EquipData.GetUnknowIconSprite ();
  69. nameTxt.text = "???";
  70. nameTxt.color = UpgradeUtil.GetCommonBorderColor ();
  71. levelTxt.text = "???";
  72. descTxt.text = "";
  73. upgradePrice.text = "0";
  74. ButtonUtil.Unselect (upgradeBtn.gameObject);
  75. ButtonUtil.Unselect (equipBtn.gameObject);
  76. }
  77. if (uavSkillInfo != null)
  78. uavSkillInfo.SetData (equip);
  79. }
  80. private void EquipUpdated()
  81. {
  82. SetEquip (equipment);
  83. }
  84. public void OnClickUpgrade()
  85. {
  86. if (equipment == null)
  87. return;
  88. if (equipment.GetUpgradePrice () > Session.GetInstance ().myUserData.coin) {
  89. BuyCoinPanel.Show ();
  90. return;
  91. }
  92. if (equipment.GetLevel() < equipment.GetMaxLevel() && equipment.GetCount () >= equipment.GetNextLevelCount ()) {
  93. string info = Language.GetStr ("EquipPanel", "upgradeConfirm");
  94. info = info.Replace ("%NAME%", equipment.GetData().GetName());
  95. info = info.Replace ("%LEVEL%", (equipment.GetLevel() + 1).ToString());
  96. AlertPanel.Show (info, AlertPanel.YES | AlertPanel.NO, AlertCloseEvent);
  97. }
  98. }
  99. private void AlertCloseEvent(AlertCloseEvent evt)
  100. {
  101. if(evt.detail == AlertPanel.YES)
  102. {
  103. EquipRequest.Upgrade (equipment.GetId()).ResultEvent.AddListener ((bool success, JsonData data)=>{
  104. if(success)
  105. {
  106. int count = JsonUtil.ToInt(data["count"]);
  107. int level = JsonUtil.ToInt(data["level"]);
  108. int itemId = JsonUtil.ToInt(data["item_id"]);
  109. int coin = JsonUtil.ToInt(data["coin"]);
  110. Session.GetInstance().myUserData.coin = coin;
  111. equipment.Upgrade(level, count);
  112. }
  113. });
  114. }
  115. }
  116. public void OnClickEquip()
  117. {
  118. if (equipment == null)
  119. return;
  120. if(equipPanel != null)
  121. equipPanel.Equip (equipment);
  122. if(uavPanel != null)
  123. uavPanel.Equip (equipment);
  124. }
  125. }