125 lines
4.1 KiB
C#
125 lines
4.1 KiB
C#
// 文件位置: Assets/Scripts/TH1_UI/View/Announce/UIInteractionCityUpgradeItem.cs
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Logic.Action;
|
|
using Logic.Multilingual;
|
|
using RuntimeData;
|
|
using TH1_Logic.Action;
|
|
using TH1_Logic.Core;
|
|
using TH1_Logic.HeroTask;
|
|
using TH1_UI.HintUI;
|
|
using TH1Resource;
|
|
using TMPro;
|
|
using UI.HintUI;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace TH1_UI.View.Info
|
|
{
|
|
public class UIInfoHeroAvatarMono : MonoBehaviour
|
|
{
|
|
[Header("要替换的图片")]
|
|
public Image HeroImage;
|
|
public Image ChessImage;
|
|
public Image StatusBG;
|
|
public GameObject PickedBlockBG;
|
|
public GameObject PickedText;
|
|
public GameObject SelectedText;
|
|
public GameObject SelectedCircleBG;
|
|
public Color PickedBGColor;
|
|
public Color SelectedBGColor;
|
|
public HintTrigger HintTrigger;
|
|
public Button SelectButton;
|
|
public ChessType ChessType;
|
|
|
|
private bool _selected;
|
|
private bool _picked;
|
|
|
|
private GiantType _giantType;
|
|
public GiantType GiantType => _giantType;
|
|
public bool Selected => _selected;
|
|
public bool Picked => _picked;
|
|
|
|
private Action<GiantType> _onClickCallback;
|
|
|
|
/*public void SetClickCallback(Action<GiantType> callback)
|
|
{
|
|
_onClickCallback = callback;
|
|
ClickButton.onClick.RemoveAllListeners();
|
|
ClickButton.onClick.AddListener(OnClick);
|
|
}*/
|
|
|
|
//每次开局只会执行一次
|
|
public void SetupContent(CivEnum civ,ForceEnum force,ChessType chess,Action<GiantType> clickCallback,bool picked, bool selected)
|
|
{
|
|
_picked = picked;
|
|
_selected = selected;
|
|
//Step #1 设置hero图像
|
|
_giantType = Table.Instance.UnitTypeDataAssets.GetGiantType(civ, force, chess);
|
|
if (!Table.Instance.UnitTypeDataAssets.GetUnitSpriteByGiantType(_giantType, out var sprite)) return;
|
|
HeroImage.sprite = sprite;
|
|
//Step #2 设置chessicon图像
|
|
if(ResourceCache.Instance.SpriteCache.ChessSpriteDict.TryGetValue(chess,out Sprite chessSprite))
|
|
ChessImage.sprite = chessSprite;
|
|
//Step #3 设置HintTriggerData
|
|
HintTrigger.DataProvider.HintDataType = HintDataType.TextDataGiantUpgrate;
|
|
HintTrigger.DataProvider.UnitFullType = new UnitFullType(){GiantType = _giantType};
|
|
//Step #4 绑定点击事件
|
|
_onClickCallback = clickCallback;
|
|
SelectButton.onClick.RemoveAllListeners();
|
|
SelectButton.onClick.AddListener(OnSelect);
|
|
//Step #5 设置初始状态
|
|
if (picked) SetPicked();
|
|
else if (selected) SetSelected();
|
|
else SetDeselected();
|
|
}
|
|
|
|
public void UpdateContent(bool picked, bool selected)
|
|
{
|
|
if(picked)SetPicked();
|
|
else if(selected)SetSelected();
|
|
else SetDeselected();
|
|
}
|
|
|
|
public void SetPicked()
|
|
{
|
|
_picked = true;
|
|
_selected = false;
|
|
PickedText.SetActive(true);
|
|
SelectedText.SetActive(false);
|
|
PickedBlockBG.SetActive(true);
|
|
StatusBG.gameObject.SetActive(true);
|
|
StatusBG.color = PickedBGColor;
|
|
}
|
|
|
|
public void SetSelected()
|
|
{
|
|
_selected = true;
|
|
PickedBlockBG.SetActive(true);
|
|
PickedText.SetActive(false);
|
|
SelectedText.SetActive(true);
|
|
SelectedCircleBG.SetActive(true);
|
|
StatusBG.gameObject.SetActive(true);
|
|
StatusBG.color = SelectedBGColor;
|
|
}
|
|
|
|
public void SetDeselected()
|
|
{
|
|
_selected = false;
|
|
PickedBlockBG.SetActive(false);
|
|
PickedText.SetActive(false);
|
|
SelectedText.SetActive(false);
|
|
SelectedCircleBG.SetActive(false);
|
|
StatusBG.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void OnSelect()
|
|
{
|
|
if(_selected || _picked) return;
|
|
SetSelected();
|
|
_onClickCallback.Invoke(_giantType);
|
|
}
|
|
}
|
|
} |