shaoxiadiablo/Assets/AGame/Scripts/UI/WorldPanel/WorldPanel.CityWidget.cs
2025-05-18 01:04:31 +08:00

147 lines
3.4 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-06-05
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "WorldPanel.CityWidget" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
using System.Collections;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace G.UI
{
partial class WorldPanel
{
/// <summary>
///
/// </summary>
class CityWidget : KUIWidget
{
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
Image _imgIcon;
[KUIFlag]
TextMeshProUGUI _tmpName;
[KUIFlag]
GameObject _goLock;
[KUIFlag]
GameObject _goBeauty;
[KUIFlag]
Image _imgBeautyHead;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
private bool _showBeauty;
#endregion
#region Method
public override void Refresh()
{
if (this.data is CityProxy.CityInfo cityInfo)
{
((RectTransform)this.transform).anchoredPosition = GlobalUtils.GetVector2(cityInfo.item.iconPos);
_tmpName.text = cityInfo.item.name;
//IconProxy.Instance.SetSprite(_imgIcon, cityInfo.item.icon);
//_imgIcon.SetNativeSize();
StartCoroutine(SetFigure(cityInfo.item.icon[0]));
_goLock.SetActive(!cityInfo.isUnlock);
int beautyId = cityInfo.beautyId;
//HomeProxy.Instance.GetBeautiy(beautyId);
if (beautyId > 0)
{
_goBeauty.SetActive(false);
var beautyItem = ItemProxy.Instance.GetStaticItem<ItemBeauty>(beautyId);
if (beautyItem != null)
{
IconProxy.Instance.SetSprite(_imgBeautyHead, beautyItem.icon);
}
_showBeauty = true;
}
else
{
_goBeauty.SetActive(false);
_showBeauty = false;
}
}
}
private IEnumerator SetFigure(string figure)
{
var spriteAddr = "sa_w_world";
var handle = AssetProxy.Instance.TryGetGlobalAssetAsync<UnityEngine.U2D.SpriteAtlas>(spriteAddr);
yield return handle;
if (handle.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
{
_imgIcon.gameObject.SetActive(true);
_imgIcon.overrideSprite = handle.Result.GetSprite(figure);
//_imgIcon.SetNativeSize();
}
else
{
_imgIcon.gameObject.SetActive(false);
}
}
private void OnIconBtnClick()
{
if (this.data is CityProxy.CityInfo cityInfo)
{
if (!cityInfo.isUnlock)
{
KUIWindow.OpenWindow<TipsBox>(cityInfo.unlockText);
}
//KUIWindow.OpenWindow<CityDetailBox>(cityInfo);
}
}
#endregion
#region Unity
/// <summary>
///
/// </summary>
private void Awake()
{
SetViewData();
_imgIcon.GetComponent<Button>().onClick.AddListener(OnIconBtnClick);
_nextShowTime = Random.Range(8f, 2f);
}
private float _nextShowTime = 5f;
private void Update()
{
_nextShowTime -= Time.deltaTime;
if (_nextShowTime < 0f)
{
_nextShowTime = Random.Range(20f, 160f);
if (_showBeauty && _goLock.activeSelf)
{
_goBeauty.SetActive(!_goBeauty.activeSelf);
if (_goBeauty.activeSelf)
{
_nextShowTime = Random.Range(4f, 2f);
}
}
}
}
#endregion
}
}
}