299 lines
12 KiB
C#
299 lines
12 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_Core.Events;
|
||
using TH1_Core.Managers;
|
||
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 UIInfoHeroPickedRowMono : MonoBehaviour
|
||
{
|
||
public GameObject InfoGroup;
|
||
public GameObject LockHint;
|
||
public GameObject BlankHint;
|
||
|
||
public Image CircleBG;
|
||
public Image RowBG;
|
||
public Image HeroAvatar;
|
||
public Image HeroIllustration;
|
||
public CanvasGroup HeroAvatarCanvas;
|
||
public Image ChessIcon;
|
||
public GameObject LockIcon;
|
||
|
||
public GameObject GiantMissionGroup;
|
||
public GameObject GoUpgradeHint;
|
||
public GameObject MaxLevelHint;
|
||
|
||
|
||
|
||
[Header("要修改文字或参数的对象")]
|
||
public TextMeshProUGUI GiantNameText;
|
||
public TextMeshProUGUI GiantLevelText;
|
||
public HintTrigger HintTrigger;
|
||
public TextMeshProUGUI MissionDesc;
|
||
public TextMeshProUGUI ForceFinishCost;
|
||
|
||
[Header("会响应玩家交互的模块")]
|
||
public Button ForceFinishButton;
|
||
|
||
[Header("解锁购买按钮(位于LockHint子对象下)")]
|
||
public UIInfoCultureCardBuyButtonMono BuyButtonMono;
|
||
|
||
[Header("可选值的缓存")]
|
||
public Sprite NormalCircle;
|
||
public Sprite LockedCircle;
|
||
public Color RowBGNormal;
|
||
public Color RowBGGrey;
|
||
|
||
private bool _isLock;
|
||
private bool _isBlank;
|
||
private UnitFullType _unitFullType;
|
||
private ChessType _chessType;
|
||
|
||
|
||
private Action _refreshAfterForceFinish;
|
||
|
||
public void SetupContent(UnitFullType unitFullType, bool blank, bool locked,Action callback, int rowIndex = 0)
|
||
{
|
||
_unitFullType = unitFullType;
|
||
_isBlank = blank;
|
||
_isLock = locked;
|
||
if (Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(_unitFullType, out var info))
|
||
_chessType = info.ChessType;
|
||
//处理上锁
|
||
if (locked) SetLock(rowIndex);
|
||
else if (blank) SetBlank();
|
||
else SetHero();
|
||
_refreshAfterForceFinish = callback;
|
||
}
|
||
|
||
public void UpdateContent(UnitFullType unitFullType, bool blank, bool locked, int rowIndex = 0)
|
||
{
|
||
_unitFullType = unitFullType;
|
||
_isBlank = blank;
|
||
_isLock = locked;
|
||
if (Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(_unitFullType, out var info))
|
||
_chessType = info.ChessType;
|
||
//处理上锁
|
||
if (locked) SetLock(rowIndex);
|
||
else if (blank) SetBlank();
|
||
else SetHero();
|
||
}
|
||
|
||
public void SetLock(int rowIndex = 0)
|
||
{
|
||
CircleBG.sprite = LockedCircle;
|
||
LockIcon.SetActive(true);
|
||
HeroAvatar.gameObject.SetActive(false);
|
||
HeroIllustration.gameObject.SetActive(false);
|
||
InfoGroup.SetActive(false);
|
||
BlankHint.SetActive(false);
|
||
LockHint.SetActive(true);
|
||
RowBG.color = RowBGGrey;
|
||
HintTrigger.DataProvider.UnitFullType.GiantType = GiantType.None;
|
||
|
||
// 根据行索引设置LockHint的文字参数:第2行→SecondHero,第3行→ThirdHero
|
||
var cardType = rowIndex == 1 ? CultureCardType.SecondHero : CultureCardType.ThirdHero;
|
||
var hasCardInfo = Table.Instance.CultureCardDataAssets.GetCultureCardInfo(cardType, out var cardInfo);
|
||
var lockTmp = LockHint.GetComponent<TextMeshProUGUI>();
|
||
if (lockTmp != null && hasCardInfo)
|
||
{
|
||
var cardName = MultilingualManager.Instance.GetMultilingualTextSafe(cardInfo.Name);
|
||
MultilingualManager.Instance.SetUIText(lockTmp, new List<string> { cardName });
|
||
}
|
||
|
||
SetupBuyButton(rowIndex, hasCardInfo ? cardInfo : null, cardType);
|
||
}
|
||
|
||
// 解锁购买按钮:仅在 rowIndex>=1 且前置法典已满足时显示。
|
||
// 点击行为:CheckCan 通过则购买并广播刷新事件;文化值不够会被 CheckCan 拦住,静默无反应。
|
||
private void SetupBuyButton(int rowIndex, CultureCardInfo cardInfo, CultureCardType cardType)
|
||
{
|
||
if (BuyButtonMono == null) return;
|
||
|
||
// 首行不显示购买按钮(避免异常进入锁定态时误导玩家)
|
||
if (rowIndex == 0 || cardInfo == null)
|
||
{
|
||
BuyButtonMono.gameObject.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
var player = Main.MapData?.PlayerMap?.SelfPlayerData;
|
||
if (player == null || !cardInfo.CheckPrerequisiteCardsOwned(player))
|
||
{
|
||
BuyButtonMono.gameObject.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
BuyButtonMono.gameObject.SetActive(true);
|
||
BuyButtonMono.UpdateVisual(cardInfo.Cost, player.PlayerCultureInfo.PlayerCulture);
|
||
|
||
if (BuyButtonMono.BuyButton == null) return;
|
||
BuyButtonMono.BuyButton.onClick.RemoveAllListeners();
|
||
BuyButtonMono.BuyButton.onClick.AddListener(() =>
|
||
{
|
||
var self = Main.MapData?.PlayerMap?.SelfPlayerData;
|
||
if (self == null) return;
|
||
var actionId = new CommonActionId
|
||
{
|
||
ActionType = CommonActionType.BuyCultureCard,
|
||
CultureCardType = cardType,
|
||
};
|
||
var action = ActionLogicFactory.GetActionLogic(actionId);
|
||
var param = new CommonActionParams(Main.MapData, playerData: self,
|
||
mainObjectType: MainObjectType.Player);
|
||
param.RefreshParams();
|
||
if (!action.CheckCan(param)) return; // 文化不够或其他原因不可购买,静默
|
||
action.CompleteExecute(param);
|
||
EventManager.Publish(new UpdateUIInfoHeroCultureCards());
|
||
EventManager.Publish(new UpdateUITopTopBar { UpdateType = UpdateTopBarType.UpdateCulture });
|
||
EventManager.Publish(new UpdateUITopTopBar { UpdateType = UpdateTopBarType.UpdateCoinPerTurn });
|
||
});
|
||
}
|
||
|
||
public void SetBlank()
|
||
{
|
||
CircleBG.sprite = NormalCircle;
|
||
LockIcon.SetActive(false);
|
||
|
||
HeroAvatar.sprite = Table.Instance.UnitTypeDataAssets.GetUnitSpriteByGiantType(_unitFullType.GiantType, out var sprite) ? sprite : null;
|
||
HeroAvatar.gameObject.SetActive(true);
|
||
InfoGroup.SetActive(false);
|
||
BlankHint.SetActive(true);
|
||
LockHint.SetActive(false);
|
||
HeroAvatarCanvas.alpha = 0.5f;
|
||
ChessIcon.sprite = ResourceCache.Instance.SpriteCache.ChessSpriteDict.GetValueOrDefault(_chessType);
|
||
|
||
if (Table.Instance.HeroDataAssets.GetHeroIllustration(_unitFullType.GiantType, out var illustration))
|
||
{
|
||
HeroIllustration.sprite = illustration;
|
||
HeroIllustration.gameObject.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
HeroIllustration.gameObject.SetActive(false);
|
||
}
|
||
|
||
RowBG.color = RowBGNormal;
|
||
HintTrigger.DataProvider.HintDataType = HintDataType.TextDataGiantUpgrate;
|
||
HintTrigger.DataProvider.UnitFullType = _unitFullType;
|
||
}
|
||
|
||
public void SetHero()
|
||
{
|
||
//Step #1 设置基础图像
|
||
CircleBG.sprite = NormalCircle;
|
||
LockIcon.SetActive(false);
|
||
if (Table.Instance.UnitTypeDataAssets.GetUnitSpriteByGiantType(_unitFullType.GiantType, out var sprite))
|
||
HeroAvatar.sprite = sprite;
|
||
HeroAvatar.gameObject.SetActive(true);
|
||
InfoGroup.SetActive(true);
|
||
BlankHint.SetActive(false);
|
||
LockHint.SetActive(false);
|
||
HeroAvatarCanvas.alpha = 1f;
|
||
if (ResourceCache.Instance.SpriteCache.ChessSpriteDict.TryGetValue(_chessType, out var chessSprite))
|
||
ChessIcon.sprite = chessSprite;
|
||
|
||
if (Table.Instance.HeroDataAssets.GetHeroIllustration(_unitFullType.GiantType, out var illustration))
|
||
{
|
||
HeroIllustration.sprite = illustration;
|
||
HeroIllustration.gameObject.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
HeroIllustration.gameObject.SetActive(false);
|
||
}
|
||
|
||
//Step #2 设置英雄info
|
||
if (Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(_unitFullType, out var unitInfo))
|
||
{
|
||
MultilingualManager.Instance.SetUIText(GiantNameText,unitInfo.Name);
|
||
GiantLevelText.text = "Lv." + _unitFullType.UnitLevel;
|
||
}
|
||
|
||
SetGiantMissionDesc(_unitFullType.GiantType,_unitFullType.UnitLevel);
|
||
RowBG.color = RowBGNormal;
|
||
HintTrigger.DataProvider.HintDataType = HintDataType.TextDataGiantUpgrate;
|
||
HintTrigger.DataProvider.UnitFullType = _unitFullType;
|
||
}
|
||
|
||
public void SetGiantMissionDesc(GiantType giantType,uint giantLevel)
|
||
{
|
||
if (!Table.Instance.HeroDataAssets.GetHeroInfo(giantType, out var info)) return;
|
||
bool maxLevel = info.TaskList.Count <= giantLevel - 1;
|
||
GiantMissionGroup.SetActive(!maxLevel);
|
||
MaxLevelHint.SetActive(maxLevel);
|
||
if (maxLevel)
|
||
{
|
||
ForceFinishButton.gameObject.SetActive(false);
|
||
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.GetMultilingualTextSafe(skillInfo.SkillName);
|
||
|
||
}
|
||
|
||
var taskDesc = info.TaskList[(int)(giantLevel - 1)].Desc;
|
||
var taskFinishedDesc = Table.Instance.TextDataAssets.HeroTaskFinishedDesc;
|
||
var finished = task.CheckFinished(Main.MapData, Main.MapData.PlayerMap.SelfPlayerData);
|
||
|
||
var selfPlayer = Main.MapData.PlayerMap.SelfPlayerData;
|
||
selfPlayer.GetHeroCostDiscount(Main.MapData, out var discount);
|
||
var cost = selfPlayer.PlayerHeroData.GetHeroFinishTaskCost(giantType, discount);
|
||
ForceFinishCost.text = cost.ToString();
|
||
ForceFinishCost.color = Color.red;
|
||
ForceFinishButton.onClick.RemoveAllListeners();
|
||
|
||
MultilingualManager.Instance.SetUIText(MissionDesc, taskDesc,
|
||
new List<string> { param1, param2, param3 });
|
||
|
||
MissionDesc.gameObject.SetActive(!finished);
|
||
ForceFinishButton.gameObject.SetActive(!finished);
|
||
GoUpgradeHint.SetActive(finished);
|
||
|
||
if (cost <= Main.MapData.PlayerMap.SelfPlayerData.PlayerCultureInfo.PlayerCulture && !finished)
|
||
{
|
||
ForceFinishCost.color = Color.white;
|
||
ForceFinishButton.onClick.AddListener(() =>
|
||
{
|
||
if (Main.MapData.CurPlayer != Main.MapData.PlayerMap.SelfPlayerData) return;
|
||
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();
|
||
});
|
||
}
|
||
|
||
|
||
}
|
||
|
||
}
|
||
} |