176 lines
4.0 KiB
C#
176 lines
4.0 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2021-03-28
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "SwordWindow.View" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
namespace G.UI
|
|
{
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
partial class SwordWindow
|
|
{
|
|
class SwordUpgradePanel : KUIWidget
|
|
{
|
|
[KUIFlag]
|
|
Button _btnClose;
|
|
[KUIFlag]
|
|
Button _btnLeft;
|
|
[KUIFlag]
|
|
Button _btnRight;
|
|
[KUIFlag]
|
|
GameObject __goUpgradeCost;
|
|
[KUIFlag]
|
|
Button _btnUpgrade;
|
|
[KUIFlag]
|
|
GameObject _goCurrStatus;
|
|
[KUIFlag]
|
|
KUIList _listAttributes;
|
|
[KUIFlag]
|
|
GameObject __goSword;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpGrade;
|
|
[KUIFlag]
|
|
GameObject _goUnlock;
|
|
[KUIFlag]
|
|
GameObject _goLock;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpUnlockPointer;
|
|
[KUIFlag]
|
|
KUIImage _imgName;
|
|
|
|
private CostWidget _upgradeCostWidget;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public Transform swordRoot => __goSword.transform;
|
|
|
|
public override void Refresh()
|
|
{
|
|
if (this.data is SwordProxy.SwordInfo swordInfo)
|
|
{
|
|
_imgName.ShowSprite(swordInfo.id - 1);
|
|
if (swordInfo.isUnlock)
|
|
{
|
|
_goUnlock.SetActive(true);
|
|
_goLock.SetActive(false);
|
|
|
|
_upgradeCostWidget.SetPriceWithMax(swordInfo.upgradeCost);
|
|
var attributes = swordInfo.attributes;
|
|
_listAttributes.Clear();
|
|
for (int i = 0; i < attributes.Count; i++)
|
|
{
|
|
var at = _listAttributes.GetItem<AttributeWidget>();
|
|
at.SetData(attributes[i].ToString3());
|
|
}
|
|
_tmpGrade.text = $"等级 {swordInfo.grade}";
|
|
}
|
|
else
|
|
{
|
|
_goUnlock.SetActive(false);
|
|
_goLock.SetActive(true);
|
|
_tmpUnlockPointer.text = swordInfo.unlockText;
|
|
}
|
|
|
|
RefreshArrowState(swordInfo.id);
|
|
}
|
|
}
|
|
|
|
void OnUpgradeBtnClick()
|
|
{
|
|
if (this.data is SwordProxy.SwordInfo swordInfo)
|
|
{
|
|
SwordProxy.Instance.UpgradeSword(swordInfo.id,
|
|
(error, message) =>
|
|
{
|
|
if (error == 0)
|
|
{
|
|
Refresh();
|
|
PostNotification(GlobalDefine.EVENT_SHOW_TOAST, "升级成功");
|
|
}
|
|
else
|
|
{
|
|
PostNotification(GlobalDefine.EVENT_SHOW_TOAST, message);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
void RefreshArrowState(int swordId)
|
|
{
|
|
if (swordId <= 1)
|
|
{
|
|
_btnLeft.interactable = false;
|
|
_btnRight.interactable = true;
|
|
}
|
|
else if (swordId >= 5)
|
|
{
|
|
_btnLeft.interactable = true;
|
|
_btnRight.interactable = false;
|
|
}
|
|
else
|
|
{
|
|
_btnLeft.interactable = true;
|
|
_btnRight.interactable = true;
|
|
}
|
|
}
|
|
|
|
void OnLeftBtnClick()
|
|
{
|
|
if (this.data is SwordProxy.SwordInfo swordInfo)
|
|
{
|
|
RefreshArrowState(swordInfo.id);
|
|
if (swordInfo.id > 1)
|
|
{
|
|
var prevSwordInfo = SwordProxy.Instance.GetSwordInfo(swordInfo.id - 1);
|
|
if (prevSwordInfo != null)
|
|
GetWindow<SwordWindow>().ShowSwordDetail(prevSwordInfo);
|
|
}
|
|
}
|
|
}
|
|
|
|
void OnRightBtnClick()
|
|
{
|
|
if (this.data is SwordProxy.SwordInfo swordInfo)
|
|
{
|
|
RefreshArrowState(swordInfo.id);
|
|
if (swordInfo.id < 5)
|
|
{
|
|
var nextSwordInfo = SwordProxy.Instance.GetSwordInfo(swordInfo.id + 1);
|
|
if (nextSwordInfo != null)
|
|
GetWindow<SwordWindow>().ShowSwordDetail(nextSwordInfo);
|
|
}
|
|
}
|
|
}
|
|
|
|
void OnCloseBtnClick()
|
|
{
|
|
Close();
|
|
GetWindow<SwordWindow>().HideSwordDetail();
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
SetViewData();
|
|
_btnClose.onClick.AddListener(this.OnCloseBtnClick);
|
|
_btnLeft.onClick.AddListener(this.OnLeftBtnClick);
|
|
_btnRight.onClick.AddListener(this.OnRightBtnClick);
|
|
_btnUpgrade.onClick.AddListener(this.OnUpgradeBtnClick);
|
|
|
|
_upgradeCostWidget = __goUpgradeCost.AddComponent<CostWidget>();
|
|
_listAttributes.AddTemplate<AttributeWidget>(true);
|
|
}
|
|
}
|
|
}
|
|
}
|