119 lines
4.2 KiB
C#
119 lines
4.2 KiB
C#
// 文件位置: Assets/Scripts/TH1_UI/View/Announce/UIInteractionCityUpgradeItem.cs
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Mime;
|
|
using System.Text;
|
|
using Animancer;
|
|
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
|
|
{
|
|
[RequireComponent(typeof(Button))]
|
|
public class UIInfoTechTreeCheckPanelMono : MonoBehaviour
|
|
{
|
|
public AnimancerComponent CheckPanelAnimancer;
|
|
public Button CloseButton;
|
|
public Button BlockButton;
|
|
public Button ResearchButton;
|
|
public TextMeshProUGUI CostText;
|
|
public TextMeshProUGUI ResearchText;
|
|
public List<UIInfoTechTreeCircleMono> CircleList;
|
|
public TextMeshProUGUI Title;
|
|
public Color CostRed;
|
|
|
|
private Action _refreshTechTree;
|
|
public void InitStart(Action refresh)
|
|
{
|
|
CloseButton.onClick.RemoveAllListeners();
|
|
CloseButton.onClick.AddListener(OnClose);
|
|
BlockButton.onClick.RemoveAllListeners();
|
|
BlockButton.onClick.AddListener(OnClose);
|
|
gameObject.SetActive(false);
|
|
_refreshTechTree = refresh;
|
|
}
|
|
|
|
public void SetContent(TechType techType)
|
|
{
|
|
if (!Table.Instance.TechDataAssets.GetTechInfo(techType, out var info)) return;
|
|
var player = Main.MapData.PlayerMap.SelfPlayerData;
|
|
int count = Mathf.Min(info.TechAtomList.Count, 3);
|
|
if(CircleList.Count < count) return;
|
|
var learned = player.TechTree.CheckIfHasTech(techType);
|
|
for (int i = 0; i < CircleList.Count; i++)
|
|
{
|
|
if (i >= count)
|
|
{
|
|
CircleList[i].gameObject.SetActive(false);
|
|
continue;
|
|
}
|
|
CircleList[i].gameObject.SetActive(true);
|
|
CircleList[i].SetContentForCheckPanel(info.TechAtomList[i],learned);
|
|
}
|
|
MultilingualManager.Instance.SetUIText(Title,info.TechName);
|
|
|
|
//Step #3 设置研究按钮
|
|
ResearchButton.gameObject.SetActive(false);
|
|
ResearchButton.onClick.RemoveAllListeners();
|
|
if (player.TechTree.CheckIfTechCanLearn(techType))
|
|
{
|
|
ResearchButton.gameObject.SetActive(true);
|
|
var cost = player.GetTechCost(info);
|
|
CostText.text = cost.ToString();
|
|
bool can = player.PlayerWealth + player.PlayerTechPoint >= cost;
|
|
CostText.color = can ? Color.white : CostRed ;
|
|
ResearchText.color = CostText.color;
|
|
|
|
if (can)
|
|
{
|
|
ResearchButton.onClick.AddListener(()=>
|
|
{
|
|
if (OnResearch(techType))
|
|
{
|
|
OnClose();
|
|
_refreshTechTree?.Invoke();
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
public void OnClose()
|
|
{
|
|
AnimancerState state = CheckPanelAnimancer.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeOut);
|
|
state.Events.OnEnd += () => { gameObject.SetActive(false); };
|
|
}
|
|
|
|
public bool OnResearch(TechType techType)
|
|
{
|
|
var player = Main.MapData.PlayerMap.SelfPlayerData;
|
|
CommonActionParams param = new CommonActionParams(mapData :Main.MapData,playerData : player,mainObjectType: MainObjectType.Player);
|
|
CommonActionId actionId = new CommonActionId(){ActionType = CommonActionType.LearnTech,TechType = techType};
|
|
var action = ActionLogicFactory.GetActionLogic(actionId);
|
|
return action.CheckCan(param) && action.CompleteExecute(param);
|
|
}
|
|
|
|
public void Open(TechType techType)
|
|
{
|
|
gameObject.SetActive(true);
|
|
CheckPanelAnimancer.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeIn);
|
|
SetContent(techType);
|
|
}
|
|
|
|
}
|
|
} |