246 lines
9.6 KiB
C#
246 lines
9.6 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
|
||
{
|
||
[RequireComponent(typeof(Button))]
|
||
public class UIInfoHeroAvatarMono : MonoBehaviour
|
||
{
|
||
[Header("要替换的图片")]
|
||
public Image BGImage;
|
||
public Image CharImage;
|
||
public Image ChessImage;
|
||
public Image ChessBG;
|
||
public Image Ground;
|
||
public Color BGColorLock;
|
||
public Color BGColorNormal;
|
||
public Color ChessColorBlank;
|
||
public Color ChessColorNormal;
|
||
|
||
|
||
[Header("根据状态决定是否显示的模块")]
|
||
public GameObject Char;
|
||
public GameObject Chess;
|
||
public GameObject Lock;
|
||
//被选择时的红框
|
||
public GameObject Choose;
|
||
//锁住时的提示词
|
||
public GameObject LockDesc;
|
||
//英雄满级提示词
|
||
public GameObject MaxLevelDesc;
|
||
//等待pick时的提示词
|
||
public GameObject BlankDesc;
|
||
public GameObject GiantName;
|
||
public GameObject GiantMissionGroup;
|
||
public GameObject GoUpgradeHint;
|
||
|
||
[Header("要修改文字或参数的对象")]
|
||
public TextMeshProUGUI GiantNameText;
|
||
public TextMeshProUGUI GiantLevelText;
|
||
public HintTrigger HintTrigger;
|
||
public TextMeshProUGUI MissionDesc;
|
||
public TextMeshProUGUI ForceFinishCost;
|
||
|
||
|
||
[Header("会响应玩家交互的模块")] public Button ClickButton;
|
||
public Button ForceFinishButton;
|
||
//是否在pool里,有额外的选项(可选,不显示任务等等)
|
||
public bool InPool = false;
|
||
//存储该模块的
|
||
private bool _isLock;
|
||
private bool _isBlank;
|
||
private GiantType _giantType;
|
||
private uint _giantLevel;
|
||
private bool _chosen;
|
||
|
||
public GiantType GetGiantType() {return _giantType;}
|
||
|
||
public void SetGiantType(GiantType type) { _giantType = type;}
|
||
|
||
private Action<GiantType> _onClickCallback;
|
||
private Action _refreshAfterForceFinish;
|
||
|
||
public void RefreshAfterForceFinish(Action callback)
|
||
{
|
||
_refreshAfterForceFinish = callback;
|
||
}
|
||
|
||
public void SetClickCallback(Action<GiantType> callback)
|
||
{
|
||
_onClickCallback = callback;
|
||
ClickButton.onClick.RemoveAllListeners();
|
||
ClickButton.onClick.AddListener(OnClick);
|
||
}
|
||
//用于图片替换使用的参数
|
||
public void UpdateInfo(bool isLock,bool isBlank,GiantType giantType,uint giantLevel,bool chosen = false)
|
||
{
|
||
//Step 1设置模块参数
|
||
_isLock = isLock;
|
||
_isBlank = isBlank;
|
||
_giantType = giantType;
|
||
_giantLevel = giantLevel;
|
||
_chosen = chosen;
|
||
|
||
Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(UnitType.Giant, giantType, giantLevel, out var giantInfo);
|
||
|
||
|
||
//Step 2处理BGImage
|
||
BGImage.color = isLock ? BGColorLock:BGColorNormal;
|
||
|
||
//Step 3处理CharImage (或者Lock
|
||
Char.SetActive(!isLock);
|
||
Lock.SetActive(isLock);
|
||
if(!isLock)
|
||
{
|
||
CharImage.color = isBlank ? ChessColorBlank : ChessColorNormal;
|
||
if (giantInfo != null)
|
||
CharImage.sprite = giantInfo.Sprite;
|
||
}
|
||
|
||
//Step 4处理ChessImage
|
||
Chess.SetActive(!isLock);
|
||
if(!isLock)
|
||
if(giantInfo != null && ResourceCache.Instance.SpriteCache.ChessSpriteDict.TryGetValue(giantInfo.ChessType,out var spr))
|
||
ChessImage.sprite = spr;
|
||
|
||
//Step 5处理Ground
|
||
var civEnum = Table.Instance.TransCivIdToCivEnum(Main.MapData.PlayerMap.SelfPlayerData.PlayerCivId);
|
||
var forceEnum = Table.Instance.TransForceIdToForceEnum(Main.MapData.PlayerMap.SelfPlayerData.PlayerForceId);
|
||
var sp = (civEnum == CivEnum.French && forceEnum == ForceEnum.Kaguya)
|
||
? GridSpType.KaguyaGrid
|
||
: GridSpType.None;
|
||
Ground.sprite = Table.Instance.GridAndResourceDataAssets.GetGroundSprite(civEnum, sp);
|
||
|
||
//Step 6 处理GiantNameText和GiantLevelText
|
||
GiantName.SetActive(!_isLock && !_isBlank);
|
||
if (!_isLock && !_isBlank && giantInfo != null)
|
||
{
|
||
MultilingualManager.Instance.SetUIText(GiantNameText,giantInfo.Name);
|
||
GiantLevelText.text = $"<color=yellow>Lv.{giantInfo.UnitLevel}</color>";
|
||
}
|
||
|
||
//Step 7 设置HintTrigger
|
||
|
||
//GiantUpgradeHint.SetActive(!_isLock);
|
||
HintTrigger.DataProvider.HintDataType = HintDataType.TextDataGiantUpgrate;
|
||
HintTrigger.DataProvider.UnitType = UnitType.Giant;
|
||
HintTrigger.DataProvider.GiantType = _isLock ? GiantType.None : _giantType;
|
||
HintTrigger.DataProvider.UnitLevel = _giantLevel;
|
||
|
||
//Step 8 设置LockDesc
|
||
LockDesc.SetActive(!InPool && _isLock);
|
||
|
||
//Step 9 设置BlankDesc
|
||
BlankDesc.SetActive(!InPool && _isBlank);
|
||
|
||
//Step 10 设置MaxLevelDesc
|
||
MaxLevelDesc.SetActive(!InPool && !_isLock && giantLevel == 3);
|
||
|
||
//Step 11 设置GiantMission
|
||
GiantMissionGroup.SetActive(!InPool && !_isLock && !_isBlank && giantLevel < 3);
|
||
if (!InPool && !_isLock && !_isBlank && giantLevel < 3)
|
||
SetGiantMissionDesc(giantType,giantLevel);
|
||
//Step #12 设置Chosen选择的红框
|
||
_chosen = chosen;
|
||
Choose.SetActive(_chosen);
|
||
|
||
//Step #13 设置Pool英雄的初始召唤等级
|
||
if (InPool)
|
||
{
|
||
//StartLevel = "Lv.0";
|
||
}
|
||
}
|
||
|
||
public void SetLockDesc(int t)
|
||
{
|
||
var mul = LockDesc.gameObject.GetComponent<MultilingualTextMono>();
|
||
var lockText = LockDesc.gameObject.GetComponent<TextMeshProUGUI>();
|
||
if (mul == null) return;
|
||
MultilingualManager.Instance.SetUIText(lockText,mul.ID.ToString(),new List<string>{t.ToString()});
|
||
}
|
||
|
||
public void OnClick()
|
||
{
|
||
if (_onClickCallback != null)
|
||
_onClickCallback.Invoke(_giantType);
|
||
_chosen = true;
|
||
Choose.SetActive(true);
|
||
}
|
||
|
||
public void Deselect()
|
||
{
|
||
_chosen = false;
|
||
Choose.SetActive(false);
|
||
}
|
||
|
||
public void SetGiantMissionDesc(GiantType giantType,uint giantLevel)
|
||
{
|
||
if (!Table.Instance.HeroDataAssets.GetHeroInfo(giantType, out var info)) return;
|
||
if (info.TaskList.Count <= giantLevel) return;
|
||
if (!Main.MapData.PlayerMap.SelfPlayerData.PlayerHeroData.GetHeroTask(giantType, out var task)) return;
|
||
var param1 = task.LevelShowString();
|
||
var param2 = task.TargetLevelShowString();
|
||
var param3 = "";
|
||
if (task.SkillType != SkillType.NONE && Table.Instance.SkillDataAssets.GetSkillInfo(task.SkillType, out var skillInfo))
|
||
{
|
||
param3 = MultilingualManager.Instance.GetMultilingualText(uint.Parse(skillInfo.SkillName));
|
||
|
||
}
|
||
|
||
var taskDesc = info.TaskList[(int)giantLevel].Desc;
|
||
var taskFinishedDesc = Table.Instance.TextDataAssets.HeroTaskFinishedDesc;
|
||
|
||
if(!task.IsForceFinished)
|
||
MultilingualManager.Instance.SetUIText(MissionDesc,taskDesc,new List<string> {param1,param2,param3});
|
||
else
|
||
MultilingualManager.Instance.SetUIText(MissionDesc,taskFinishedDesc);
|
||
|
||
|
||
var cost = task.GetFinishCost() * (giantLevel + 1);
|
||
ForceFinishCost.text = cost.ToString();
|
||
ForceFinishCost.color = Color.red;
|
||
ForceFinishButton.onClick.RemoveAllListeners();
|
||
var finished = task.CheckFinished(Main.MapData, Main.MapData.PlayerMap.SelfPlayerData);
|
||
ForceFinishButton.gameObject.SetActive(!finished);
|
||
GoUpgradeHint.SetActive(finished);
|
||
if (cost <= Main.MapData.PlayerMap.SelfPlayerData.PlayerWealth && !finished)
|
||
{
|
||
ForceFinishCost.color = Color.white;
|
||
ForceFinishButton.onClick.AddListener(() =>
|
||
{
|
||
var type = giantType;
|
||
var actionId = new CommonActionId()
|
||
{
|
||
ActionType = CommonActionType.PlayerAction,
|
||
PlayerActionType = PlayerActionType.FinishHeroTask,
|
||
GiantType = type
|
||
};
|
||
var param = new CommonActionParams(mapData: Main.MapData, mainObjectType: MainObjectType.Player,
|
||
playerData: Main.MapData.PlayerMap.SelfPlayerData);
|
||
var action = ActionLogicFactory.GetActionLogic(actionId);
|
||
//通知父界面的回调,更新整个页面
|
||
if (action.CheckCan(param) && action.CompleteExecute(param))
|
||
_refreshAfterForceFinish.Invoke();
|
||
});
|
||
}
|
||
|
||
|
||
}
|
||
|
||
}
|
||
} |