342 lines
11 KiB
C#
342 lines
11 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2021-08-02
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "SkinWindow.View" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
namespace G.UI
|
|
{
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
partial class SkinWindow
|
|
{
|
|
class SkinItemWidget : KUIWidget
|
|
{
|
|
[KUIFlag]
|
|
Image _imgQuality;
|
|
[KUIFlag]
|
|
Image _imgIcon;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpName;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpDescription;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpCombatValue;
|
|
[KUIFlag]
|
|
Button _btnGet;
|
|
[KUIFlag]
|
|
Button _btnBuy;
|
|
[KUIFlag]
|
|
Button _btnPutOn;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpPutOn;
|
|
[KUIFlag]
|
|
GameObject __goBuyCost;
|
|
[KUIFlag]
|
|
Button _btnPreview;
|
|
|
|
private CostWidget _buyCostWidget;
|
|
private ChaSkinProxy.ChaSkinInfo _skin;
|
|
private int _weapon;
|
|
|
|
public override void Refresh()
|
|
{
|
|
_tmpName.text = _skin.item.name;
|
|
_tmpDescription.text = _skin.item.description;
|
|
_tmpCombatValue.text = "战力+" + _skin.item.combatValue;
|
|
if (_weapon > 0)
|
|
IconProxy.Instance.SetSprite(_imgIcon, _skin.item.weaponIcons[_weapon - 1]);
|
|
else
|
|
IconProxy.Instance.SetSprite(_imgIcon, _skin.item.icon);
|
|
|
|
if (_skin.isUnlock)
|
|
{
|
|
if (_weapon >= 0)
|
|
{
|
|
if (_skin.IsActive(_weapon))
|
|
{
|
|
_btnBuy.gameObject.SetActive(false);
|
|
_btnPutOn.gameObject.SetActive(true);
|
|
|
|
var curSkin = ChaSkinProxy.Instance.GetCurrentSkin(_weapon);
|
|
if (curSkin == _skin)
|
|
{
|
|
_tmpPutOn.text = "已穿戴";
|
|
_btnPutOn.interactable = false;
|
|
}
|
|
else
|
|
{
|
|
_tmpPutOn.text = "穿戴";
|
|
_btnPutOn.interactable = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_btnBuy.gameObject.SetActive(true);
|
|
_btnPutOn.gameObject.SetActive(false);
|
|
|
|
if (_weapon > 0)
|
|
{
|
|
var cost = _skin.item.weaponPriceInfo;
|
|
_buyCostWidget.SetPriceWithMax(cost);
|
|
}
|
|
else if (_weapon == 0)
|
|
{
|
|
var cost = _skin.item.costumePriceInfo;
|
|
_buyCostWidget.SetPriceWithMax(cost);
|
|
}
|
|
}
|
|
_btnGet.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
if (_skin.IsActive(_weapon))
|
|
{
|
|
_btnBuy.gameObject.SetActive(false);
|
|
_btnPutOn.gameObject.SetActive(true);
|
|
|
|
_tmpPutOn.text = "已拥有";
|
|
_btnPutOn.interactable = false;
|
|
}
|
|
else
|
|
{
|
|
_btnBuy.gameObject.SetActive(true);
|
|
_btnPutOn.gameObject.SetActive(false);
|
|
|
|
var cost = _skin.buyPrice;
|
|
_buyCostWidget.SetPriceWithMax(cost);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_btnGet.gameObject.SetActive(true);
|
|
_btnBuy.gameObject.SetActive(false);
|
|
_btnPutOn.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void SetSkin(ChaSkinProxy.ChaSkinInfo skin, int weapon)
|
|
{
|
|
_skin = skin;
|
|
_weapon = weapon;
|
|
|
|
Refresh();
|
|
}
|
|
|
|
void OnPutOnBtnClick()
|
|
{
|
|
GetWindow<SkinWindow>().PutOn(_weapon, _skin);
|
|
}
|
|
|
|
void OnPreviewBtnClick()
|
|
{
|
|
GetWindow<SkinWindow>().Preview(_weapon, _skin);
|
|
}
|
|
|
|
void OnBuyBtnClick()
|
|
{
|
|
if (_skin != null)
|
|
{
|
|
ChaSkinProxy.Instance.BuyChaSkin(_skin, _weapon, (error, message) =>
|
|
{
|
|
if (error == 0)
|
|
{
|
|
Refresh();
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText(message);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
void OnGetBtnClick()
|
|
{
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
SetViewData();
|
|
|
|
_buyCostWidget = __goBuyCost.AddComponent<CostWidget>();
|
|
|
|
_btnGet.onClick.AddListener(this.OnGetBtnClick);
|
|
_btnBuy.onClick.AddListener(this.OnBuyBtnClick);
|
|
_btnPutOn.onClick.AddListener(this.OnPutOnBtnClick);
|
|
_btnPreview.onClick.AddListener(this.OnPreviewBtnClick);
|
|
}
|
|
}
|
|
|
|
#region Field
|
|
|
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
[KUIFlag]
|
|
KUIList __listSkins;
|
|
[KUIFlag]
|
|
KUIToggleGroup _goPages;
|
|
[KUIFlag]
|
|
Button _btnBack;
|
|
[KUIFlag]
|
|
GameObject _goChaRoot;
|
|
|
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
|
|
private ChaWidget _chaWidget;
|
|
|
|
private int _weaponKind = 0;
|
|
private int _skinKind;
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void InitView()
|
|
{
|
|
SetViewData();
|
|
_chaWidget = _goChaRoot.AddComponent<ChaWidget>();
|
|
__listSkins.AddTemplate<SkinItemWidget>(true);
|
|
_btnBack.onClick.AddListener(this.OnCloseBtnClick);
|
|
_goPages.onToggleSelected.AddListener(this.OnWeaponSelected);
|
|
|
|
|
|
_weaponSkin = PlayerProxy.Instance.GetCurrentChaSkin();
|
|
_clothSkin = ChaSkinProxy.Instance.GetCurrentSkin(0).item;
|
|
|
|
//SetWeapon(0);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void RefreshView()
|
|
{
|
|
//_weaponSkin = PlayerProxy.Instance.GetCurrentChaSkin();
|
|
//_clothSkin = ChaSkinProxy.Instance.GetCurrentSkin(0).item;
|
|
|
|
SetWeapon(_weaponKind);
|
|
}
|
|
|
|
public void PutOn(int weaponKind, ChaSkinProxy.ChaSkinInfo skin)
|
|
{
|
|
if (weaponKind >= 0)
|
|
ChaSkinProxy.Instance.SetCurrentSkin(skin.id, weaponKind);
|
|
SetWeapon(weaponKind);
|
|
}
|
|
|
|
public void Preview(int weaponKind, ChaSkinProxy.ChaSkinInfo skin)
|
|
{
|
|
ShowSkin(weaponKind, skin.item);
|
|
}
|
|
|
|
ItemChaSkin _clothSkin;
|
|
ItemChaSkin _weaponSkin;
|
|
|
|
private void ShowSkin(int weapon, ItemChaSkin skin)
|
|
{
|
|
if (weapon == -1)
|
|
{
|
|
_clothSkin = skin;
|
|
int weaponKind = Random.Range(1, 3);
|
|
_chaWidget.Show(skin.GetUIAssetByWeapon(weaponKind), skin.GetWeaponUIAssetByWeapon(weaponKind), null);
|
|
}
|
|
else if (weapon == 0)
|
|
{
|
|
_clothSkin = skin;
|
|
var weaponSkin = _weaponSkin ?? skin;
|
|
_chaWidget.Show(skin.GetUIAssetByWeapon(1), weaponSkin.GetWeaponUIAssetByWeapon(1), null);
|
|
}
|
|
else if (weapon == 1)
|
|
{
|
|
_weaponSkin = skin;
|
|
var clothSkin = _clothSkin;
|
|
_chaWidget.Show(clothSkin.GetUIAssetByWeapon(1), skin.GetWeaponUIAssetByWeapon(1), null);
|
|
}
|
|
else if (weapon == 2)
|
|
{
|
|
_weaponSkin = skin;
|
|
var clothSkin = _clothSkin;
|
|
|
|
_chaWidget.Show(clothSkin.GetUIAssetByWeapon(2), skin.GetWeaponUIAssetByWeapon(2), null);
|
|
}
|
|
else if (weapon == 3)
|
|
{
|
|
_weaponSkin = skin;
|
|
var clothSkin = _clothSkin;
|
|
|
|
_chaWidget.Show(clothSkin.GetUIAssetByWeapon(3), skin.GetWeaponUIAssetByWeapon(3), null);
|
|
}
|
|
}
|
|
|
|
void SetWeapon(int weaponKind)
|
|
{
|
|
__listSkins.Clear();
|
|
var skins = ChaSkinProxy.Instance.GetChaSkinInfos();
|
|
foreach (var skin in skins)
|
|
{
|
|
__listSkins.GetItem<SkinItemWidget>().SetSkin(skin, weaponKind);
|
|
}
|
|
|
|
if (weaponKind > 0)
|
|
{
|
|
var curSkin = ChaSkinProxy.Instance.GetCurrentSkin(weaponKind).item;
|
|
ShowSkin(weaponKind, curSkin);
|
|
}
|
|
else
|
|
{
|
|
var curSkin = ChaSkinProxy.Instance.GetCurrentSkin(0).item;
|
|
ShowSkin(weaponKind, curSkin);
|
|
}
|
|
}
|
|
|
|
void OnWeaponSelected(int index)
|
|
{
|
|
if (index == 0)
|
|
{
|
|
SetWeapon(-1);
|
|
}
|
|
else if (index == 1)
|
|
{
|
|
_weaponKind = 0;
|
|
SetWeapon(0);
|
|
}
|
|
else if (index == 2)
|
|
{
|
|
_weaponKind = 1;
|
|
SetWeapon(_weaponKind);
|
|
}
|
|
else if (index == 3)
|
|
{
|
|
_weaponKind = 2;
|
|
SetWeapon(_weaponKind);
|
|
}
|
|
else if (index == 4)
|
|
{
|
|
_weaponKind = 3;
|
|
SetWeapon(_weaponKind);
|
|
}
|
|
}
|
|
|
|
void OnCloseBtnClick()
|
|
{
|
|
CloseWindow(this);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|