247 lines
9.5 KiB
C#
247 lines
9.5 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.CrashSight;
|
||
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 Image CostIcon;
|
||
public TextMeshProUGUI CostText;
|
||
public Sprite CoinCostSprite;
|
||
public Sprite CultureCostSprite;
|
||
public GameObject TimeBar;
|
||
public TextMeshProUGUI TimeText;
|
||
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,ShowType cantType, CommonActionParams param, Action<CommonActionId,CommonActionParams> actionClickCallback)
|
||
{
|
||
// 添加参数校验
|
||
if (actionId == null)
|
||
{
|
||
Debug.LogError("UIInfoCommonBaseActionCircleMono.SetContent: actionId 为 null");
|
||
return;
|
||
}
|
||
|
||
if (param == null)
|
||
{
|
||
Debug.LogError("UIInfoCommonBaseActionCircleMono.SetContent: param 为 null");
|
||
return;
|
||
}
|
||
|
||
//Step #0 基础变量设置
|
||
if (!Table.Instance.ActionDataAssets.GetActionInfo(actionId, out var info))
|
||
{
|
||
return;
|
||
}
|
||
var player = Main.MapData.PlayerMap.SelfPlayerData;
|
||
|
||
//Step #1 处理图片 名字
|
||
var civ = Main.MapData.PlayerMap.SelfPlayerData.CivEnum;
|
||
var force = Main.MapData.PlayerMap.SelfPlayerData.ForceEnum;
|
||
var gridSp = GridSpType.None;
|
||
|
||
if (actionId.ActionType == CommonActionType.Gain && param.GridData != null)
|
||
{
|
||
civ = param.GridData.CivEnum;
|
||
gridSp = param.GridData.GetOnlyOneSpType();
|
||
//吃饭回来:测试图标是否跟着环境变化,尤其要测永远亭
|
||
}
|
||
|
||
MultilingualManager.Instance.SetUIText(Title,info.GetActionName(civ,force,gridSp));
|
||
ActionImg.sprite = info.GetIcon(civ,force,gridSp);
|
||
IconSizingUtility.SetIconSize(ActionImg,info.IconViewSizeType,true);
|
||
|
||
//Step #2 确定背景图是groundcircle还是普通circle
|
||
bool circleGround = actionId.ActionType is CommonActionType.Build or CommonActionType.TrainUnit
|
||
or CommonActionType.BuildWonder or CommonActionType.Gain;
|
||
if (actionId.GridMiscActionType is GridMiscActionType.SellMetal or GridMiscActionType.GrowForest or GridMiscActionType.GrowForestOutside or GridMiscActionType.CreateMountain)
|
||
circleGround = true;
|
||
BG.sprite = circleGround ? GroundBG : BlueBG;
|
||
|
||
//Step #2.5 预计算成本和显示状态
|
||
var action = ActionLogicFactory.GetActionLogic(actionId);
|
||
int cost = action.GetCost(param);
|
||
bool isCultureTrain = actionId.ActionType == CommonActionType.TrainUnit
|
||
&& (UnitData.IsBigGuyType(actionId.UnitType) || actionId.UnitType == UnitType.Giant);
|
||
bool isCultureCost = isCultureTrain
|
||
|| (actionId.ActionType == CommonActionType.UnitAction
|
||
&& actionId.UnitActionType == UnitActionType.CultureUnitUpgrade);
|
||
CostText.text = cost.ToString();
|
||
CostText.color = TextBlue;
|
||
if (isCultureCost)
|
||
{
|
||
// BigGuy用文化值判断
|
||
if (CostIcon != null && CultureCostSprite != null)
|
||
CostIcon.sprite = CultureCostSprite;
|
||
if (player.PlayerCultureInfo.PlayerCulture < cost)
|
||
CostText.color = Color.red;
|
||
}
|
||
else
|
||
{
|
||
if (CostIcon != null && CoinCostSprite != null)
|
||
CostIcon.sprite = CoinCostSprite;
|
||
if (player.PlayerCoin < cost)
|
||
CostText.color = Color.red;
|
||
}
|
||
// 默认显示costBar(cost>0时),后续根据状态可能隐藏
|
||
CostBar.SetActive(cost > 0);
|
||
|
||
//Step #3 设置背景颜色,设置绑定点击执行
|
||
bool locked = false;
|
||
ClickButton.onClick.RemoveAllListeners();
|
||
Title.color = TextBlue;
|
||
TimeBar.SetActive(false);
|
||
if (cantType == ShowType.Cold)
|
||
{
|
||
if (Table.Instance.UnitTypeDataAssets.GetGiantTypeChessType(actionId.GiantType, out var coldChessType))
|
||
{
|
||
TimeBar.SetActive(true);
|
||
TimeText.text = player.giantPenalty[(int)coldChessType].ToString();
|
||
}
|
||
}
|
||
|
||
//如果目前无法执行
|
||
if (!action.CheckCan(param))
|
||
{
|
||
//如果是cityLevelUp,必须可执行
|
||
if (action.ActionId.ActionType == CommonActionType.CityLevelUpAction)
|
||
{
|
||
LogSystem.LogError($"CityLevelUpAction 不应该出现在无法执行的action circle里, Tyep :{cantType}");
|
||
BGCanvasGroup.alpha = 1f;
|
||
CircleBG.color = CircleYellow;
|
||
if (actionClickCallback != null)
|
||
{
|
||
ClickButton.onClick.AddListener(()=>
|
||
{
|
||
actionClickCallback.Invoke(actionId,param);
|
||
});
|
||
}
|
||
|
||
}
|
||
else
|
||
//如果是因为人口满了,灰圈 + 降低透明度
|
||
if (cantType == ShowType.Locked)
|
||
{
|
||
//BGCanvasGroup.alpha = 0.3f;
|
||
CircleBG.color = CircleGray;
|
||
CostBar.SetActive(false);
|
||
BG.sprite = circleGround ? GroundGrayBG : GrayBG;
|
||
locked = true;
|
||
Title.color = TextGrey;
|
||
}
|
||
//否则如果是在冷却时间
|
||
else if(cantType == ShowType.Cold)
|
||
{
|
||
CircleBG.color = CircleGray;
|
||
BG.sprite = circleGround ? GroundGrayBG : GrayBG;
|
||
locked = true;
|
||
Title.color = TextGrey;
|
||
|
||
if (cost > 0)
|
||
{
|
||
CostBar.SetActive(true);
|
||
CostText.text = cost.ToString();
|
||
CostText.color = player.PlayerCultureInfo.PlayerCulture < cost ? TextRed : TextBlue;
|
||
if (CostIcon != null && CultureCostSprite != null)
|
||
CostIcon.sprite = CultureCostSprite;
|
||
}
|
||
else
|
||
{
|
||
CostBar.SetActive(false);
|
||
}
|
||
}
|
||
//否则如果是因为钱/文化值不够
|
||
else if (cantType == ShowType.Cost
|
||
|| (isCultureCost
|
||
? player.PlayerCultureInfo.PlayerCulture < cost
|
||
: player.PlayerCoin < cost))
|
||
{
|
||
BGCanvasGroup.alpha = 1f;
|
||
CircleBG.color = CircleGray;
|
||
Title.color = TextRed;
|
||
}
|
||
//兜底:其他原因无法执行(如科技未解锁等),灰圈+隐藏cost
|
||
else
|
||
{
|
||
CircleBG.color = CircleGray;
|
||
CostBar.SetActive(false);
|
||
BG.sprite = circleGround ? GroundGrayBG : GrayBG;
|
||
locked = true;
|
||
Title.color = TextGrey;
|
||
}
|
||
|
||
|
||
}
|
||
//如果可以执行,那么绑定
|
||
else
|
||
{
|
||
BGCanvasGroup.alpha = 1f;
|
||
CircleBG.color = CircleYellow;
|
||
if (actionClickCallback != null)
|
||
{
|
||
ClickButton.onClick.AddListener(()=>
|
||
{
|
||
actionClickCallback.Invoke(actionId,param);
|
||
});
|
||
}
|
||
}
|
||
|
||
//Step #4 设置hint trigger
|
||
HintTrigger.DataProvider.HintDataType = HintDataType.ActionHintData;
|
||
HintTrigger.DataProvider.ActionIdData = actionId;
|
||
HintTrigger.DataProvider.locked = locked;
|
||
|
||
|
||
|
||
}
|
||
|
||
public void OnClose()
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|