149 lines
5.0 KiB
C#
149 lines
5.0 KiB
C#
// 文件位置: Assets/Scripts/TH1_UI/View/Announce/UIInteractionCityUpgradeItem.cs
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Mime;
|
|
using System.Text;
|
|
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 UnityEditor.Rendering;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace TH1_UI.View.Info
|
|
{
|
|
public class UIInfoCommonBaseActionCircleMono : MonoBehaviour
|
|
{
|
|
[Header("会响应玩家交互的模块")]
|
|
public Button ClickButton;
|
|
public HintTrigger HintTrigger;
|
|
|
|
|
|
[Header("需要每局游戏开始初始化的模块")]
|
|
public Image ActionImg;
|
|
public TextMeshProUGUI Title;
|
|
|
|
[Header("需要每次打开界面都刷新的模块")]
|
|
public Image BG;
|
|
public CanvasGroup BGCanvasGroup;
|
|
public Image CircleBG;
|
|
public GameObject CostBar;
|
|
public TextMeshProUGUI CostText;
|
|
public Color TextBlue;
|
|
public Color TextRed;
|
|
public Color TextGrey;
|
|
public Color CircleGray;
|
|
public Color CircleYellow;
|
|
public Color CircleRed;
|
|
public Sprite GroundBG;
|
|
public Sprite GroundGrayBG;
|
|
public Sprite BlueBG;
|
|
public Sprite GrayBG;
|
|
|
|
|
|
public void SetContent(CommonActionId actionId,ActionCantType cantType, CommonActionParams param, Action<CommonActionId,CommonActionParams> actionClickCallback)
|
|
{
|
|
|
|
|
|
|
|
//Step #0 基础变量设置
|
|
if (!Table.Instance.ActionDataAssets.GetActionInfo(actionId, out var info)) return;
|
|
var player = Main.MapData.PlayerMap.SelfPlayerData;
|
|
|
|
//Step #1 处理图片
|
|
MultilingualManager.Instance.SetUIText(Title,info.ActionName);
|
|
ActionImg.sprite = info.GetIcon(Main.MapData.PlayerMap.SelfPlayerData.CivEnum,Main.MapData.PlayerMap.SelfPlayerData.ForceEnum,GridSpType.None);
|
|
IconSizingUtility.SetIconSize(ActionImg,info.IconViewSizeType);
|
|
|
|
//Step #2 设置价格条
|
|
CostText.text = info.Cost.ToString();
|
|
CostBar.SetActive(info.Cost > 0);
|
|
CostText.color = TextBlue;
|
|
if(player.PlayerWealth < info.Cost)
|
|
CostText.color = Color.red;
|
|
|
|
//Step #3 确定背景图是groundcircle还是普通circle
|
|
bool circleGround = actionId.ActionType is CommonActionType.Build or CommonActionType.TrainUnit
|
|
or CommonActionType.BuildWonder or CommonActionType.Gain;
|
|
BG.sprite = circleGround ? GroundBG : BlueBG;
|
|
|
|
//Step #4 设置背景颜色,设置绑定点击执行
|
|
|
|
bool locked = false;
|
|
ClickButton.onClick.RemoveAllListeners();
|
|
var action = ActionLogicFactory.GetActionLogic(actionId);
|
|
Title.color = TextBlue;
|
|
|
|
//如果目前无法执行
|
|
if (!action.CheckCan(param))
|
|
{
|
|
//如果是因为人口满了,灰圈 + 降低透明度
|
|
if (cantType == ActionCantType.Locked)
|
|
{
|
|
//BGCanvasGroup.alpha = 0.3f;
|
|
CircleBG.color = CircleGray;
|
|
CostBar.SetActive(false);
|
|
BG.sprite = circleGround ? GroundGrayBG : GrayBG;
|
|
locked = true;
|
|
Title.color = TextGrey;
|
|
}
|
|
//如果是因为科技没有
|
|
else if (!player.TechTree.CheckActionCan(actionId))
|
|
{
|
|
CircleBG.color = CircleGray;
|
|
CostBar.SetActive(false);
|
|
BG.sprite = circleGround ? GroundGrayBG : GrayBG;
|
|
locked = true;
|
|
Title.color = TextGrey;
|
|
}
|
|
//否则如果是因为钱不够
|
|
else if (player.PlayerWealth < info.Cost)
|
|
{
|
|
BGCanvasGroup.alpha = 1f;
|
|
CircleBG.color = CircleGray;
|
|
Title.color = TextRed;
|
|
}
|
|
|
|
}
|
|
//如果可以执行,那么绑定
|
|
else
|
|
{
|
|
BGCanvasGroup.alpha = 1f;
|
|
CircleBG.color = CircleYellow;
|
|
if (actionClickCallback != null)
|
|
{
|
|
ClickButton.onClick.AddListener(()=>
|
|
{
|
|
actionClickCallback.Invoke(actionId,param);
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//Step #5 设置hint trigger
|
|
HintTrigger.DataProvider.HintDataType = HintDataType.ActionHintData;
|
|
HintTrigger.DataProvider.ActionIdData = actionId;
|
|
HintTrigger.DataProvider.locked = locked;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
public void OnClose()
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
} |