242 lines
9.8 KiB
C#
242 lines
9.8 KiB
C#
using Logic.Multilingual;
|
||
using RuntimeData;
|
||
using TH1_Logic.Core;
|
||
using TH1_Logic.MatchConfig;
|
||
using Logic;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
namespace TH1_UI.View.Info
|
||
{
|
||
public class UIInfoCultureTaskMono : MonoBehaviour
|
||
{
|
||
public Image Icon;
|
||
public TextMeshProUGUI Desc;
|
||
public TextMeshProUGUI CultureValue;
|
||
public TextMeshProUGUI ExecuteCountText;
|
||
public GameObject CompletedGroup;
|
||
public GameObject CompletedGroupPer;
|
||
public GameObject ValueGroup;
|
||
public GameObject AwardTitle;
|
||
public GameObject AwardTitlePer;
|
||
public GameObject LockGroup;
|
||
public TextMeshProUGUI LockDesc;
|
||
public TextMeshProUGUI LockTechName;
|
||
|
||
private MomentItemBase _momentItem;
|
||
private MomentSubData _momentSubData;
|
||
private CultureTaskInfo _cultureTaskInfo;
|
||
|
||
public void Init(MomentItemBase momentItem)
|
||
{
|
||
_momentItem = momentItem;
|
||
if (_momentItem == null) return;
|
||
|
||
var subType = _momentItem.GetMomentSubType();
|
||
Table.Instance.CultureCardDataAssets.GetCultureTaskInfo(subType, out _cultureTaskInfo);
|
||
Table.Instance.MomentDataAssets.GetMomentSubData(subType, out _momentSubData);
|
||
|
||
// 描述
|
||
if (Desc != null)
|
||
{
|
||
if (_cultureTaskInfo != null)
|
||
SetUITextOrRaw(Desc, _cultureTaskInfo.Description);
|
||
else if (_momentSubData != null)
|
||
SetUITextOrRaw(Desc, _momentSubData.Desc);
|
||
else
|
||
Desc.text = _momentItem.GetFallbackDesc();
|
||
}
|
||
|
||
// 图标
|
||
if (Icon != null && _momentSubData != null && _momentSubData.Icon != null)
|
||
Icon.sprite = _momentSubData.Icon;
|
||
|
||
// 文化值
|
||
if (CultureValue != null)
|
||
CultureValue.text = (_cultureTaskInfo != null ? _cultureTaskInfo.CultureValue : _momentItem.PlayerCultureValue).ToString();
|
||
|
||
// 默认隐藏CompletedGroupPer,由UpdateInfo根据条件决定是否显示
|
||
if (CompletedGroupPer != null)
|
||
CompletedGroupPer.SetActive(false);
|
||
}
|
||
|
||
public void UpdateInfo(PlayerData player)
|
||
{
|
||
if (_momentItem == null) return;
|
||
|
||
UpdateIcon(player);
|
||
|
||
bool locked = IsLocked(player);
|
||
UpdateLockInfo(player, locked);
|
||
if (locked)
|
||
{
|
||
if (AwardTitle != null) AwardTitle.SetActive(false);
|
||
if (AwardTitlePer != null) AwardTitlePer.SetActive(false);
|
||
if (ExecuteCountText != null) ExecuteCountText.gameObject.SetActive(false);
|
||
if (CompletedGroup != null) CompletedGroup.SetActive(false);
|
||
if (CompletedGroupPer != null) CompletedGroupPer.SetActive(false);
|
||
if (ValueGroup != null) ValueGroup.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
bool isEveryTime = _momentSubData != null && _momentSubData.EveryTime;
|
||
bool oneTimeCompleted = _momentItem.IsExecute;
|
||
bool everyTimeCompleted = isEveryTime && _momentItem.ExecuteCount >= _momentSubData.MaxTime;
|
||
string progressText = _momentItem.GetProgressText(Main.MapData, player);
|
||
bool hasCustomProgress = !string.IsNullOrEmpty(progressText);
|
||
|
||
// 一次性显示AwardTitle;EveryTime且未达MaxTime显示AwardTitlePer;达到MaxTime两者都不显示
|
||
if (AwardTitle != null) AwardTitle.SetActive(!isEveryTime && !oneTimeCompleted);
|
||
if (AwardTitlePer != null) AwardTitlePer.SetActive(isEveryTime && !everyTimeCompleted);
|
||
|
||
// 执行次数:仅EveryTime且未达MaxTime时显示,格式为 "当前次数/最大次数"
|
||
if (ExecuteCountText != null)
|
||
{
|
||
if (hasCustomProgress && !oneTimeCompleted)
|
||
{
|
||
ExecuteCountText.gameObject.SetActive(true);
|
||
ExecuteCountText.text = progressText;
|
||
}
|
||
else if (isEveryTime && !everyTimeCompleted)
|
||
{
|
||
ExecuteCountText.gameObject.SetActive(true);
|
||
ExecuteCountText.text = _momentItem.ExecuteCount + "/" + _momentSubData.MaxTime;
|
||
}
|
||
else
|
||
{
|
||
ExecuteCountText.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
|
||
// 已完成状态:
|
||
// 一次性已完成 → 显示CompletedGroup
|
||
// EveryTime已达MaxTime → 显示CompletedGroupPer
|
||
// 未完成 → 显示ValueGroup
|
||
bool completed = (!isEveryTime && oneTimeCompleted) || everyTimeCompleted;
|
||
if (CompletedGroup != null) CompletedGroup.SetActive(!isEveryTime && oneTimeCompleted);
|
||
if (CompletedGroupPer != null) CompletedGroupPer.SetActive(everyTimeCompleted);
|
||
if (ValueGroup != null) ValueGroup.SetActive(!completed);
|
||
}
|
||
|
||
private bool IsLocked(PlayerData player)
|
||
{
|
||
if (player == null || _momentItem == null) return false;
|
||
var wonderType = GetWonderType();
|
||
if (wonderType == WonderTypeEnum.None) return false;
|
||
return player.Wonder.GetWonderState(wonderType) == WonderState.NO_HINT;
|
||
}
|
||
|
||
private void UpdateIcon(PlayerData player)
|
||
{
|
||
if (Icon == null) return;
|
||
|
||
var wonderType = GetWonderType();
|
||
if (player != null
|
||
&& wonderType != WonderTypeEnum.None
|
||
&& Table.Instance.GridAndResourceDataAssets.GetWonderInfoByType(wonderType, player, out var wonderInfo)
|
||
&& wonderInfo.Sprite != null)
|
||
{
|
||
Icon.sprite = wonderInfo.Sprite;
|
||
return;
|
||
}
|
||
|
||
if (_momentSubData != null && _momentSubData.Icon != null)
|
||
Icon.sprite = _momentSubData.Icon;
|
||
}
|
||
|
||
private void UpdateLockInfo(PlayerData player, bool locked)
|
||
{
|
||
if (LockGroup != null) LockGroup.SetActive(locked);
|
||
if (!locked) return;
|
||
|
||
var lockText = _cultureTaskInfo != null ? _cultureTaskInfo.LockText : string.Empty;
|
||
SetUITextOrRaw(LockDesc, string.IsNullOrEmpty(lockText) ? "\u9700\u8981\u89e3\u9501\u5bf9\u5e94\u5947\u89c2" : lockText);
|
||
|
||
string techName = string.Empty;
|
||
bool showTechName = _cultureTaskInfo != null
|
||
&& _cultureTaskInfo.LockByTech
|
||
&& TryGetUnlockTechName(player, out techName);
|
||
if (LockTechName != null)
|
||
{
|
||
LockTechName.gameObject.SetActive(showTechName);
|
||
if (showTechName) SetUITextOrRaw(LockTechName, techName);
|
||
}
|
||
}
|
||
|
||
private bool TryGetUnlockTechName(PlayerData player, out string techName)
|
||
{
|
||
techName = string.Empty;
|
||
if (player == null || _momentItem == null) return false;
|
||
var wonderType = GetWonderType();
|
||
if (!PlayerLogic.TryGetStartWonderTechAtom(wonderType, out var unlockAtom)) return false;
|
||
if (!Table.Instance.PlayerDataAssets.GetPlayerInfo(player, out var playerInfo)) return false;
|
||
|
||
foreach (var techType in playerInfo.TechPool)
|
||
{
|
||
if (!Table.Instance.TechDataAssets.GetTechInfo(techType, out var techInfo) || techInfo?.TechAtomList == null) continue;
|
||
if (!techInfo.TechAtomList.Contains(unlockAtom)) continue;
|
||
techName = techInfo.TechName;
|
||
return !string.IsNullOrEmpty(techName);
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
private WonderTypeEnum GetWonderType()
|
||
{
|
||
if (_cultureTaskInfo != null && _cultureTaskInfo.WonderType != WonderTypeEnum.None)
|
||
return _cultureTaskInfo.WonderType;
|
||
return _momentItem != null ? GetWonderType(_momentItem.GetMomentSubType()) : WonderTypeEnum.None;
|
||
}
|
||
|
||
private static WonderTypeEnum GetWonderType(MomentSubType subType)
|
||
{
|
||
return subType switch
|
||
{
|
||
MomentSubType.ExploitWonderPEACE => WonderTypeEnum.PEACE,
|
||
MomentSubType.ExploitWonderKNOWLEDGE => WonderTypeEnum.KNOWLEDGE,
|
||
MomentSubType.ExploitWonderTRADE => WonderTypeEnum.TRADE,
|
||
MomentSubType.ExploitWonderWEALTH => WonderTypeEnum.WEALTH,
|
||
MomentSubType.ExploitWonderPOWER => WonderTypeEnum.POWER,
|
||
MomentSubType.ExploitWonderPARK => WonderTypeEnum.PARK,
|
||
MomentSubType.ExploitWonderEYE => WonderTypeEnum.EYE,
|
||
_ => WonderTypeEnum.None
|
||
};
|
||
}
|
||
|
||
private static void SetUITextOrRaw(TextMeshProUGUI text, string value)
|
||
{
|
||
if (text == null) return;
|
||
if (string.IsNullOrEmpty(value))
|
||
{
|
||
var multilingual = text.gameObject.GetComponent<MultilingualTextMono>();
|
||
if (multilingual != null)
|
||
{
|
||
multilingual.ID = 0;
|
||
multilingual.Ban = true;
|
||
}
|
||
text.text = string.Empty;
|
||
return;
|
||
}
|
||
|
||
if (uint.TryParse(value, out _))
|
||
{
|
||
var multilingual = text.gameObject.GetComponent<MultilingualTextMono>();
|
||
if (multilingual != null) multilingual.Ban = false;
|
||
MultilingualManager.Instance.SetUIText(text, value);
|
||
}
|
||
else
|
||
{
|
||
var multilingual = text.gameObject.GetComponent<MultilingualTextMono>();
|
||
if (multilingual != null)
|
||
{
|
||
multilingual.ID = 0;
|
||
multilingual.Ban = true;
|
||
}
|
||
text.text = value;
|
||
}
|
||
}
|
||
}
|
||
}
|