// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-06-16
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
//
//
// ***********************************************************************
namespace G.UI
{
using TMPro;
using UnityEngine;
using UnityEngine.UI;
///
///
///
partial class FriendBox
{
class FriendWidget : KUIWidget
{
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
Image _imgPicture;
[KUIFlag]
TextMeshProUGUI _tmpName;
//[KUIFlag]
//TextMeshProUGUI _tmpDescription;
[KUIFlag]
TextMeshProUGUI _tmpGainway;
[KUIFlag]
TextMeshProUGUI _tmpMeet;
[KUIFlag]
KUIList __listFriend;
[KUIFlag]
GameObject _goActived;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
#endregion
#region Method
public override void Refresh()
{
if (this.data is BeautyProxy.BeautyInfo beautyInfo)
{
var beautyItem = beautyInfo.item;
_tmpName.text = beautyItem.name;
IconProxy.Instance.SetSprite(_imgPicture, beautyItem.icon);
if (beautyInfo.isFriend)
{
_tmpMeet.gameObject.SetActive(true);
_tmpMeet.text = beautyItem.location;
_goActived.SetActive(true);
__listFriend.Clear();
_tmpGainway.gameObject.SetActive(false);
}
else if (beautyInfo.isUnlock)
{
__listFriend.Clear();
for (int i = 0; i < beautyInfo.friendMax; i++)
{
__listFriend.GetItem().SetGray(i >= beautyInfo.friend);
}
//_tmpDescription.gameObject.SetActive(false);
_tmpGainway.gameObject.SetActive(false);
_goActived.SetActive(false);
_tmpMeet.gameObject.SetActive(true);
_tmpMeet.text = beautyItem.location;
}
else
{
//_tmpDescription.gameObject.SetActive(true);
//_tmpDescription.text = beautyItem.description;
_tmpGainway.gameObject.SetActive(true);
_tmpGainway.text = beautyInfo.gainWayText;
_goActived.SetActive(false);
__listFriend.Clear();
_tmpMeet.gameObject.SetActive(false);
}
}
else if (this.data is PetProxy.PetInfo petInfo)
{
var petItem = petInfo.item;
_tmpName.text = petItem.name;
IconProxy.Instance.SetSprite(_imgPicture, petItem.icon);
if (petInfo.isFriend)
{
_tmpMeet.gameObject.SetActive(true);
_tmpMeet.text = petItem.location;
_goActived.SetActive(true);
__listFriend.Clear();
_tmpGainway.gameObject.SetActive(false);
}
else if (petInfo.isUnlock)
{
__listFriend.Clear();
for (int i = 0; i < petInfo.friendMax; i++)
{
__listFriend.GetItem().SetGray(i >= petInfo.friend);
}
//_tmpDescription.gameObject.SetActive(false);
_tmpGainway.gameObject.SetActive(false);
_goActived.SetActive(false);
_tmpMeet.gameObject.SetActive(true);
_tmpMeet.text = petItem.location;
}
else
{
//_tmpDescription.gameObject.SetActive(true);
//_tmpDescription.text = beautyItem.description;
_tmpGainway.gameObject.SetActive(true);
_tmpGainway.text = petInfo.unlockText;
_goActived.SetActive(false);
__listFriend.Clear();
_tmpMeet.gameObject.SetActive(false);
}
}
}
#endregion
#region Unity
///
///
///
private void Awake()
{
SetViewData();
__listFriend.AddTemplate(true);
}
#endregion
}
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
Button _btnClose;
[KUIFlag]
Button _btnBack;
[KUIFlag]
KUIToggleGroup _goPages;
[KUIFlag]
KUIList __listFriends;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
private int _curPage;
#endregion
#region Method
///
///
///
public void InitView()
{
SetViewData();
_btnClose.onClick.AddListener(this.OnCloseBtnClick);
_btnBack.onClick.AddListener(this.OnCloseBtnClick);
_goPages.onToggleSelected.AddListener(this.OnToggleSelected);
__listFriends.AddTemplate();
}
///
///
///
public void RefreshView()
{
if (_curPage == 0)
ShowBeauties();
else
ShowPets();
}
void ShowBeauties()
{
var beauties = BeautyProxy.Instance.GetBeauties();
if (beauties != null)
{
__listFriends.Clear();
foreach (var beauty in beauties)
{
__listFriends.GetItem().SetData(beauty);
}
}
}
void ShowPets()
{
var pets = PetProxy.Instance.GetAllPets();
if (pets != null)
{
__listFriends.Clear();
foreach (var pet in pets)
{
if (pet.item.label == 0)
__listFriends.GetItem().SetData(pet);
}
}
}
private void OnToggleSelected(int index)
{
if (index == 0)
{
_curPage = 0;
ShowBeauties();
}
else
{
_curPage = 1;
ShowPets();
}
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private void OnCloseBtnClick()
{
CloseWindow(this);
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
#endregion
}
}