234 lines
9.0 KiB
C#
234 lines
9.0 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
|
|
{
|
|
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("可选值的缓存")]
|
|
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)
|
|
{
|
|
_unitFullType = unitFullType;
|
|
_isBlank = blank;
|
|
_isLock = locked;
|
|
if (Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(_unitFullType, out var info))
|
|
_chessType = info.ChessType;
|
|
//处理上锁
|
|
if (locked) SetLock();
|
|
else if (blank) SetBlank();
|
|
else SetHero();
|
|
_refreshAfterForceFinish = callback;
|
|
}
|
|
|
|
public void UpdateContent(UnitFullType unitFullType, bool blank, bool locked)
|
|
{
|
|
_unitFullType = unitFullType;
|
|
_isBlank = blank;
|
|
_isLock = locked;
|
|
if (Table.Instance.UnitTypeDataAssets.GetUnitTypeInfo(_unitFullType, out var info))
|
|
_chessType = info.ChessType;
|
|
//处理上锁
|
|
if (locked) SetLock();
|
|
else if (blank) SetBlank();
|
|
else SetHero();
|
|
}
|
|
|
|
public void SetLock()
|
|
{
|
|
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;
|
|
}
|
|
|
|
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 + 1);
|
|
}
|
|
|
|
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;
|
|
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].Desc;
|
|
var taskFinishedDesc = Table.Instance.TextDataAssets.HeroTaskFinishedDesc;
|
|
var finished = task.CheckFinished(Main.MapData, Main.MapData.PlayerMap.SelfPlayerData);
|
|
|
|
var cost = task.GetFinishCost() * (giantLevel + 1);
|
|
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();
|
|
});
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
} |