CombatNodeComponent 战斗节点功能补全
- 失败逻辑补全:添加基地血量,当血量归0时强制结束关卡 - `CombatInfoForm` 刷新逻辑补全:通过订阅 `CombatCoinChanged/Process/BaseHpChangedEventArgs` 来更新 UI,同时可以避免一点小变动刷新整个 UI - `CombatSelectForm` 逻辑优化:订阅 `CombatCoinChanged` 来实时更新当前 Coin 是否满足操作条件
This commit is contained in:
@@ -5,6 +5,7 @@ namespace GeometryTD.UI
|
||||
public string LevelMetaText;
|
||||
public string LevelPhaseText;
|
||||
public string CoinText;
|
||||
public string BaseHpText;
|
||||
public bool CanPause;
|
||||
public bool CanEnd;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,18 @@ namespace GeometryTD.UI
|
||||
{
|
||||
GameEntry.Event.Subscribe(CombatPauseEventArgs.EventId, OnCombatPauseButtonClicked);
|
||||
GameEntry.Event.Subscribe(CombatEndEventArgs.EventId, OnCombatEndButtonClicked);
|
||||
GameEntry.Event.Subscribe(CombatProcessEventArgs.EventId, OnCombatProcessChanged);
|
||||
GameEntry.Event.Subscribe(CombatCoinChangedEventArgs.EventId, OnCombatCoinChanged);
|
||||
GameEntry.Event.Subscribe(CombatBaseHpChangedEventArgs.EventId, OnCombatBaseHpChanged);
|
||||
}
|
||||
|
||||
protected override void UnsubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(CombatPauseEventArgs.EventId, OnCombatPauseButtonClicked);
|
||||
GameEntry.Event.Unsubscribe(CombatEndEventArgs.EventId, OnCombatEndButtonClicked);
|
||||
GameEntry.Event.Unsubscribe(CombatProcessEventArgs.EventId, OnCombatProcessChanged);
|
||||
GameEntry.Event.Unsubscribe(CombatCoinChangedEventArgs.EventId, OnCombatCoinChanged);
|
||||
GameEntry.Event.Unsubscribe(CombatBaseHpChangedEventArgs.EventId, OnCombatBaseHpChanged);
|
||||
}
|
||||
|
||||
public int? OpenUI(CombatInfoFormRawData rawData)
|
||||
@@ -85,6 +91,7 @@ namespace GeometryTD.UI
|
||||
LevelMetaText = BuildLevelMetaText(rawData.LevelThemeType, rawData.LevelId),
|
||||
LevelPhaseText = BuildPhaseText(rawData.CurrentPhaseIndex, rawData.TotalPhaseCount),
|
||||
CoinText = BuildCoinText(rawData.Coin),
|
||||
BaseHpText = BuildBaseHpText(rawData.BaseHp, rawData.BaseHpMax),
|
||||
CanPause = rawData.CanPause,
|
||||
CanEnd = rawData.CanEnd
|
||||
};
|
||||
@@ -121,6 +128,18 @@ namespace GeometryTD.UI
|
||||
return $"Coin: {coin}";
|
||||
}
|
||||
|
||||
private static string BuildBaseHpText(int baseHp, int baseHpMax)
|
||||
{
|
||||
if (baseHpMax <= 0)
|
||||
{
|
||||
return "\u57FA\u5730\uFF1A-";
|
||||
}
|
||||
|
||||
int clampedHp = UnityEngine.Mathf.Clamp(baseHp, 0, baseHpMax);
|
||||
int percent = UnityEngine.Mathf.RoundToInt((float)clampedHp / baseHpMax * 100f);
|
||||
return $"\u57FA\u5730\uFF1A{percent}%";
|
||||
}
|
||||
|
||||
private void OnCombatPauseButtonClicked(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(sender is CombatInfoForm) || !(e is CombatPauseEventArgs))
|
||||
@@ -147,5 +166,53 @@ namespace GeometryTD.UI
|
||||
|
||||
_useCase?.TryEndCombat();
|
||||
}
|
||||
|
||||
private void OnCombatProcessChanged(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is CombatProcessEventArgs))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RefreshFromUseCase();
|
||||
}
|
||||
|
||||
private void OnCombatCoinChanged(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is CombatCoinChangedEventArgs))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RefreshFromUseCase();
|
||||
}
|
||||
|
||||
private void OnCombatBaseHpChanged(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is CombatBaseHpChangedEventArgs))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RefreshFromUseCase();
|
||||
}
|
||||
|
||||
private void RefreshFromUseCase()
|
||||
{
|
||||
if (_useCase == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CombatInfoFormRawData rawData = _useCase.TryRefresh();
|
||||
CombatInfoFormContext context = BuildContext(rawData);
|
||||
if (context == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SetContext(context);
|
||||
RefreshCurrentUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,13 @@ namespace GeometryTD.UI
|
||||
protected override void SubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Subscribe(CombatSelectItemClickEventArgs.EventId, OnSelectItemClicked);
|
||||
GameEntry.Event.Subscribe(CombatCoinChangedEventArgs.EventId, OnCombatCoinChanged);
|
||||
}
|
||||
|
||||
protected override void UnsubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(CombatSelectItemClickEventArgs.EventId, OnSelectItemClicked);
|
||||
GameEntry.Event.Unsubscribe(CombatCoinChangedEventArgs.EventId, OnCombatCoinChanged);
|
||||
}
|
||||
|
||||
public int? OpenUI(CombatSelectFormRawData rawData)
|
||||
@@ -262,5 +264,20 @@ namespace GeometryTD.UI
|
||||
_useCase.TryExecuteAction(args.ActionType, args.ActionIndex);
|
||||
RefreshFromUseCase();
|
||||
}
|
||||
|
||||
private void OnCombatCoinChanged(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is CombatCoinChangedEventArgs))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Form == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RefreshFromUseCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace GeometryTD.UI
|
||||
public int CurrentPhaseIndex;
|
||||
public int TotalPhaseCount;
|
||||
public int Coin;
|
||||
public int BaseHp;
|
||||
public int BaseHpMax;
|
||||
public bool CanPause;
|
||||
public bool CanEnd;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace GeometryTD.UI
|
||||
var level = GameEntry.CombatNode.CurrentLevel;
|
||||
LevelThemeType themeType = level != null ? level.LevelThemeType : GameEntry.CombatNode.CurrentThemeType;
|
||||
int levelId = level != null ? level.Id : 0;
|
||||
int baseHpMax = level != null ? level.BaseHp : 0;
|
||||
|
||||
return new CombatInfoFormRawData
|
||||
{
|
||||
@@ -42,6 +43,8 @@ namespace GeometryTD.UI
|
||||
CurrentPhaseIndex = GameEntry.CombatNode.CurrentPhaseIndex,
|
||||
TotalPhaseCount = GameEntry.CombatNode.CurrentLevelPhaseCount,
|
||||
Coin = GameEntry.CombatNode.CurrentCoin,
|
||||
BaseHp = GameEntry.CombatNode.CurrentBaseHp,
|
||||
BaseHpMax = baseHpMax,
|
||||
CanPause = true,
|
||||
CanEnd = GameEntry.CombatNode.CanEndCombat
|
||||
};
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace GeometryTD.UI
|
||||
[SerializeField] private TMP_Text _levelPhaseText;
|
||||
|
||||
[SerializeField] private TMP_Text _coinText;
|
||||
|
||||
[SerializeField] private TMP_Text _baseHpText;
|
||||
|
||||
[SerializeField] private CommonButton _pauseButton;
|
||||
|
||||
@@ -37,6 +39,11 @@ namespace GeometryTD.UI
|
||||
{
|
||||
_coinText.text = context?.CoinText ?? "0";
|
||||
}
|
||||
|
||||
if (_baseHpText != null)
|
||||
{
|
||||
_baseHpText.text = context?.BaseHpText ?? string.Empty;
|
||||
}
|
||||
|
||||
if (_pauseButton != null)
|
||||
{
|
||||
@@ -100,6 +107,11 @@ namespace GeometryTD.UI
|
||||
{
|
||||
_coinText.text = string.Empty;
|
||||
}
|
||||
|
||||
if (_baseHpText != null)
|
||||
{
|
||||
_baseHpText.text = string.Empty;
|
||||
}
|
||||
|
||||
base.OnClose(isShutdown, userData);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user