123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- using System.Collections.Generic;
- using LitJson;
- public class EquipInfo : MonoBehaviour {
- public Image border;
- public Image icon;
- public Text nameTxt;
- public Text levelTxt;
- public Text descTxt;
- public Text upgradeLabel;
- public Button upgradeBtn;
- public Text upgradePrice;
- public Text equipLabel;
- public Button equipBtn;
- public EquipPanel equipPanel;
- private Equipment equipment;
- void Awake()
- {
- upgradeLabel.text = Language.GetStr ("EquipPanel", "upgrade");
- equipLabel.text = Language.GetStr ("EquipPanel", "equip");
- }
- void OnDestroy()
- {
- if(equipment != null)
- {
- equipment.Updated.RemoveListener (EquipUpdated);
- }
- }
- public void SetEquip(Equipment equip)
- {
- OnDestroy ();
- this.equipment = equip;
- if(equip != null)
- {
- equip.Updated.AddListener (EquipUpdated);
- border.color = equip.GetData ().GetBorderColor ();
- icon.sprite = equip.GetData ().GetIconSprite ();
- nameTxt.text = equip.GetData ().GetName ();
- nameTxt.color = equip.GetData ().GetTextColor ();
- levelTxt.text = equip.GetLevelLabel ();
- descTxt.text = equip.GetDescription ();
- if (equip.GetLevel () < equip.GetMaxLevel ()) {
- if (equip.GetCount () >= equip.GetNextLevelCount ())
- ButtonUtil.Selected (upgradeBtn.gameObject);
- else
- ButtonUtil.Unselect (upgradeBtn.gameObject);
- upgradePrice.text = equip.GetUpgradePrice ().ToString();
- } else {
- ButtonUtil.Unselect (upgradeBtn.gameObject);
- upgradePrice.text = "0";
- }
- }
- else
- {
- border.color = UpgradeUtil.GetCommonBorderColor ();
- icon.sprite = EquipData.GetUnknowIconSprite ();
- nameTxt.text = "???";
- nameTxt.color = UpgradeUtil.GetCommonBorderColor ();
- levelTxt.text = "???";
- descTxt.text = "";
- upgradePrice.text = "0";
- ButtonUtil.Unselect (upgradeBtn.gameObject);
- ButtonUtil.Unselect (equipBtn.gameObject);
- }
- }
- private void EquipUpdated()
- {
- SetEquip (equipment);
- }
- public void OnClickUpgrade()
- {
- if (equipment == null)
- return;
- if (equipment.GetUpgradePrice () > Session.GetInstance ().myUserData.coin) {
- BuyCoinPanel.Show ();
- return;
- }
- if (equipment.GetLevel() < equipment.GetMaxLevel() && equipment.GetCount () >= equipment.GetNextLevelCount ()) {
- string info = Language.GetStr ("EquipPanel", "upgradeConfirm");
- info = info.Replace ("%NAME%", equipment.GetData().GetName());
- info = info.Replace ("%LEVEL%", (equipment.GetLevel() + 1).ToString());
- AlertPanel.Show (info, AlertPanel.YES | AlertPanel.NO, AlertCloseEvent);
- }
- }
- private void AlertCloseEvent(AlertCloseEvent evt)
- {
- if(evt.detail == AlertPanel.YES)
- {
- EquipRequest.Upgrade (equipment.GetId()).ResultEvent.AddListener ((bool success, JsonData data)=>{
- if(success)
- {
- int count = JsonUtil.ToInt(data["count"]);
- int level = JsonUtil.ToInt(data["level"]);
- int itemId = JsonUtil.ToInt(data["item_id"]);
- int coin = JsonUtil.ToInt(data["coin"]);
- Session.GetInstance().myUserData.coin = coin;
- equipment.Upgrade(level, count);
- }
- });
- }
- }
- public void OnClickEquip()
- {
- if (equipment == null)
- return;
-
- equipPanel.Equip (equipment);
- }
- }
|