EquipInfo.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. private Equipment equipment;
  19. void Awake()
  20. {
  21. upgradeLabel.text = Language.GetStr ("EquipPanel", "upgrade");
  22. equipLabel.text = Language.GetStr ("EquipPanel", "equip");
  23. }
  24. void OnDestroy()
  25. {
  26. if(equipment != null)
  27. {
  28. equipment.Updated.RemoveListener (EquipUpdated);
  29. }
  30. }
  31. public void SetEquip(Equipment equip)
  32. {
  33. OnDestroy ();
  34. this.equipment = equip;
  35. if(equip != null)
  36. {
  37. equip.Updated.AddListener (EquipUpdated);
  38. border.color = equip.GetData ().GetBorderColor ();
  39. icon.sprite = equip.GetData ().GetIconSprite ();
  40. nameTxt.text = equip.GetData ().GetName ();
  41. nameTxt.color = equip.GetData ().GetTextColor ();
  42. levelTxt.text = equip.GetLevelLabel ();
  43. descTxt.text = equip.GetDescription ();
  44. if (equip.GetLevel () < equip.GetMaxLevel ()) {
  45. if (equip.GetCount () >= equip.GetNextLevelCount ())
  46. ButtonUtil.Selected (upgradeBtn.gameObject);
  47. else
  48. ButtonUtil.Unselect (upgradeBtn.gameObject);
  49. upgradePrice.text = equip.GetUpgradePrice ().ToString();
  50. } else {
  51. ButtonUtil.Unselect (upgradeBtn.gameObject);
  52. upgradePrice.text = "0";
  53. }
  54. }
  55. else
  56. {
  57. border.color = UpgradeUtil.GetCommonBorderColor ();
  58. icon.sprite = EquipData.GetUnknowIconSprite ();
  59. nameTxt.text = "???";
  60. nameTxt.color = UpgradeUtil.GetCommonBorderColor ();
  61. levelTxt.text = "???";
  62. descTxt.text = "";
  63. upgradePrice.text = "0";
  64. ButtonUtil.Unselect (upgradeBtn.gameObject);
  65. ButtonUtil.Unselect (equipBtn.gameObject);
  66. }
  67. }
  68. private void EquipUpdated()
  69. {
  70. SetEquip (equipment);
  71. }
  72. public void OnClickUpgrade()
  73. {
  74. if (equipment == null)
  75. return;
  76. if (equipment.GetUpgradePrice () > Session.GetInstance ().myUserData.coin) {
  77. BuyCoinPanel.Show ();
  78. return;
  79. }
  80. if (equipment.GetLevel() < equipment.GetMaxLevel() && equipment.GetCount () >= equipment.GetNextLevelCount ()) {
  81. string info = Language.GetStr ("EquipPanel", "upgradeConfirm");
  82. info = info.Replace ("%NAME%", equipment.GetData().GetName());
  83. info = info.Replace ("%LEVEL%", (equipment.GetLevel() + 1).ToString());
  84. AlertPanel.Show (info, AlertPanel.YES | AlertPanel.NO, AlertCloseEvent);
  85. }
  86. }
  87. private void AlertCloseEvent(AlertCloseEvent evt)
  88. {
  89. if(evt.detail == AlertPanel.YES)
  90. {
  91. EquipRequest.Upgrade (equipment.GetId()).ResultEvent.AddListener ((bool success, JsonData data)=>{
  92. if(success)
  93. {
  94. int count = JsonUtil.ToInt(data["count"]);
  95. int level = JsonUtil.ToInt(data["level"]);
  96. int itemId = JsonUtil.ToInt(data["item_id"]);
  97. int coin = JsonUtil.ToInt(data["coin"]);
  98. Session.GetInstance().myUserData.coin = coin;
  99. equipment.Upgrade(level, count);
  100. }
  101. });
  102. }
  103. }
  104. public void OnClickEquip()
  105. {
  106. if (equipment == null)
  107. return;
  108. equipPanel.Equip (equipment);
  109. }
  110. }