init
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using GeometryTD.CustomComponent;
|
||||
using GeometryTD.CustomUtility;
|
||||
using GeometryTD.Definition;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatFinishFormUseCase : IUIUseCase
|
||||
{
|
||||
private ICombatSchedulerPort _combatSchedulerPort;
|
||||
private CombatSettlementContext _settlementContext;
|
||||
private bool _isSummaryPrepared;
|
||||
|
||||
public CombatFinishFormRawData CreateInitialModel()
|
||||
{
|
||||
return BuildModel();
|
||||
}
|
||||
|
||||
public CombatFinishFormRawData TryRefresh()
|
||||
{
|
||||
return BuildModel();
|
||||
}
|
||||
|
||||
internal void SetSummary(CombatSettlementContext settlementContext)
|
||||
{
|
||||
_settlementContext = settlementContext;
|
||||
_isSummaryPrepared = true;
|
||||
}
|
||||
|
||||
internal CombatFinishFormUseCase(ICombatSchedulerPort combatSchedulerPort)
|
||||
{
|
||||
_combatSchedulerPort = combatSchedulerPort;
|
||||
}
|
||||
|
||||
public bool TryReturnToMenu()
|
||||
{
|
||||
return _combatSchedulerPort != null && _combatSchedulerPort.OnCombatFinishReturnRequested();
|
||||
}
|
||||
|
||||
private CombatFinishFormRawData BuildModel()
|
||||
{
|
||||
if (!_isSummaryPrepared)
|
||||
{
|
||||
_settlementContext = null;
|
||||
}
|
||||
|
||||
BackpackInventoryData rewardInventory = _settlementContext?.Summary.RewardInventory;
|
||||
if (rewardInventory == null)
|
||||
{
|
||||
rewardInventory = InventorySeedUtility.CreateSampleInventory();
|
||||
}
|
||||
|
||||
return new CombatFinishFormRawData
|
||||
{
|
||||
DefeatedEnemyCount = Mathf.Max(0, _settlementContext?.Summary.DefeatedEnemyCount ?? 0),
|
||||
GainedGold = Mathf.Max(0, _settlementContext?.Summary.GainedGold ?? 0),
|
||||
RewardInventory = rewardInventory,
|
||||
CanReturn = true
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using GeometryTD.Definition;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatInfoFormUseCase : IUIUseCase
|
||||
{
|
||||
private Func<CombatInfoFormRawData> _modelProvider;
|
||||
private Func<bool> _tryEndCombat;
|
||||
private Func<bool> _tryDebugFail;
|
||||
|
||||
public CombatInfoFormRawData CreateInitialModel()
|
||||
{
|
||||
return BuildModel();
|
||||
}
|
||||
|
||||
public CombatInfoFormRawData TryRefresh()
|
||||
{
|
||||
return BuildModel();
|
||||
}
|
||||
|
||||
public void Configure(Func<CombatInfoFormRawData> modelProvider, Func<bool> tryEndCombat, Func<bool> tryDebugFail)
|
||||
{
|
||||
_modelProvider = modelProvider;
|
||||
_tryEndCombat = tryEndCombat;
|
||||
_tryDebugFail = tryDebugFail;
|
||||
}
|
||||
|
||||
public bool TryEndCombat()
|
||||
{
|
||||
if (_tryEndCombat == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _tryEndCombat.Invoke();
|
||||
}
|
||||
|
||||
public bool TryDebugFail()
|
||||
{
|
||||
if (_tryDebugFail == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _tryDebugFail.Invoke();
|
||||
}
|
||||
|
||||
private CombatInfoFormRawData BuildModel()
|
||||
{
|
||||
return _modelProvider != null ? _modelProvider.Invoke() : null;
|
||||
}
|
||||
|
||||
public static CombatInfoFormRawData BuildRawData(
|
||||
LevelThemeType themeType,
|
||||
int levelId,
|
||||
int currentPhaseIndex,
|
||||
int totalPhaseCount,
|
||||
int coin,
|
||||
int baseHp,
|
||||
int baseHpMax,
|
||||
bool canEnd)
|
||||
{
|
||||
return new CombatInfoFormRawData
|
||||
{
|
||||
LevelThemeType = themeType,
|
||||
LevelId = levelId,
|
||||
CurrentPhaseIndex = Mathf.Max(0, currentPhaseIndex),
|
||||
TotalPhaseCount = Mathf.Max(0, totalPhaseCount),
|
||||
Coin = Mathf.Max(0, coin),
|
||||
BaseHp = Mathf.Max(0, baseHp),
|
||||
BaseHpMax = Mathf.Max(0, baseHpMax),
|
||||
EnemyHpRateMultiplier = ResolveEnemyHpRateMultiplier(currentPhaseIndex, totalPhaseCount),
|
||||
CanPause = true,
|
||||
CanEnd = canEnd
|
||||
};
|
||||
}
|
||||
|
||||
private static int ResolveEnemyHpRateMultiplier(int currentPhaseIndex, int totalPhaseCount)
|
||||
{
|
||||
if (currentPhaseIndex <= 0 || totalPhaseCount <= 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int completedLoopCount = Mathf.Max(0, (currentPhaseIndex - 1) / totalPhaseCount);
|
||||
if (completedLoopCount >= 30)
|
||||
{
|
||||
return int.MaxValue;
|
||||
}
|
||||
|
||||
return 1 << completedLoopCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatSelectFormUseCase : IUIUseCase
|
||||
{
|
||||
private const int BuildOptionCount = 4;
|
||||
|
||||
private readonly Option[] _buildOptions = new Option[BuildOptionCount];
|
||||
private readonly Option _upgradeOption = new Option(CombatSelectActionType.UpgradeTower, 0, true);
|
||||
private readonly Option _destroyOption = new Option(CombatSelectActionType.DestroyTower, 0, false);
|
||||
|
||||
private Func<int> _coinProvider;
|
||||
private bool _isVisible;
|
||||
private CombatSelectDisplayMode _displayMode = CombatSelectDisplayMode.Hidden;
|
||||
private Vector2 _screenPosition;
|
||||
|
||||
public CombatSelectFormUseCase()
|
||||
{
|
||||
_coinProvider = DefaultCoinProvider;
|
||||
|
||||
for (int i = 0; i < BuildOptionCount; i++)
|
||||
{
|
||||
_buildOptions[i] = new Option(CombatSelectActionType.BuildTower, i, true);
|
||||
}
|
||||
}
|
||||
|
||||
public CombatSelectFormRawData CreateInitialModel()
|
||||
{
|
||||
return BuildModel();
|
||||
}
|
||||
|
||||
public CombatSelectFormRawData TryRefresh()
|
||||
{
|
||||
return BuildModel();
|
||||
}
|
||||
|
||||
public void SetCoinProvider(Func<int> coinProvider)
|
||||
{
|
||||
_coinProvider = coinProvider ?? DefaultCoinProvider;
|
||||
}
|
||||
|
||||
public void SetBuildAction(int buildIndex, Func<bool> buildAction, int cost, Sprite icon = null)
|
||||
{
|
||||
SetBuildAction(buildIndex, buildAction, cost, icon, false, Color.white, Color.white, Color.white);
|
||||
}
|
||||
|
||||
public void SetBuildAction(
|
||||
int buildIndex,
|
||||
Func<bool> buildAction,
|
||||
int cost,
|
||||
Sprite icon,
|
||||
bool useTowerLayers,
|
||||
Color baseColor,
|
||||
Color bearingColor,
|
||||
Color muzzleColor)
|
||||
{
|
||||
if (buildIndex < 0 || buildIndex >= _buildOptions.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Option option = _buildOptions[buildIndex];
|
||||
option.Action = buildAction;
|
||||
option.Price = Mathf.Max(0, cost);
|
||||
option.Icon = icon;
|
||||
option.IsGain = false;
|
||||
option.IsVisible = true;
|
||||
option.UseTowerLayers = useTowerLayers;
|
||||
option.BaseColor = baseColor;
|
||||
option.BearingColor = bearingColor;
|
||||
option.MuzzleColor = muzzleColor;
|
||||
}
|
||||
|
||||
public void SetBuildAction(int buildIndex, Action buildAction, int cost, Sprite icon = null)
|
||||
{
|
||||
if (buildAction == null)
|
||||
{
|
||||
SetBuildAction(buildIndex, (Func<bool>)null, cost, icon);
|
||||
return;
|
||||
}
|
||||
|
||||
SetBuildAction(
|
||||
buildIndex,
|
||||
() =>
|
||||
{
|
||||
buildAction.Invoke();
|
||||
return true;
|
||||
},
|
||||
cost,
|
||||
icon);
|
||||
}
|
||||
|
||||
public void SetBuildVisible(int buildIndex, bool visible)
|
||||
{
|
||||
if (buildIndex < 0 || buildIndex >= _buildOptions.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_buildOptions[buildIndex].IsVisible = visible;
|
||||
}
|
||||
|
||||
public void SetUpgradeAction(Func<bool> upgradeAction, int cost, Sprite icon = null)
|
||||
{
|
||||
_upgradeOption.Action = upgradeAction;
|
||||
_upgradeOption.Price = Mathf.Max(0, cost);
|
||||
_upgradeOption.Icon = icon;
|
||||
_upgradeOption.IsGain = false;
|
||||
_upgradeOption.IsVisible = true;
|
||||
_upgradeOption.UseTowerLayers = false;
|
||||
}
|
||||
|
||||
public void SetUpgradeAction(Action upgradeAction, int cost, Sprite icon = null)
|
||||
{
|
||||
if (upgradeAction == null)
|
||||
{
|
||||
SetUpgradeAction((Func<bool>)null, cost, icon);
|
||||
return;
|
||||
}
|
||||
|
||||
SetUpgradeAction(
|
||||
() =>
|
||||
{
|
||||
upgradeAction.Invoke();
|
||||
return true;
|
||||
},
|
||||
cost,
|
||||
icon);
|
||||
}
|
||||
|
||||
public void SetDestroyAction(Func<bool> destroyAction, int gain, Sprite icon = null)
|
||||
{
|
||||
_destroyOption.Action = destroyAction;
|
||||
_destroyOption.Price = Mathf.Max(0, gain);
|
||||
_destroyOption.Icon = icon;
|
||||
_destroyOption.IsGain = true;
|
||||
_destroyOption.IsVisible = true;
|
||||
_destroyOption.UseTowerLayers = false;
|
||||
}
|
||||
|
||||
public void SetDestroyAction(Action destroyAction, int gain, Sprite icon = null)
|
||||
{
|
||||
if (destroyAction == null)
|
||||
{
|
||||
SetDestroyAction((Func<bool>)null, gain, icon);
|
||||
return;
|
||||
}
|
||||
|
||||
SetDestroyAction(
|
||||
() =>
|
||||
{
|
||||
destroyAction.Invoke();
|
||||
return true;
|
||||
},
|
||||
gain,
|
||||
icon);
|
||||
}
|
||||
|
||||
public void SetUpgradePrice(int cost)
|
||||
{
|
||||
_upgradeOption.Price = Mathf.Max(0, cost);
|
||||
}
|
||||
|
||||
public void SetUpgradeVisible(bool visible)
|
||||
{
|
||||
_upgradeOption.IsVisible = visible;
|
||||
}
|
||||
|
||||
public void SetDestroyGain(int gain)
|
||||
{
|
||||
_destroyOption.Price = Mathf.Max(0, gain);
|
||||
_destroyOption.IsGain = true;
|
||||
}
|
||||
|
||||
public void ShowForFoundation(Vector2 screenPosition)
|
||||
{
|
||||
_screenPosition = screenPosition;
|
||||
_displayMode = CombatSelectDisplayMode.Build;
|
||||
_isVisible = true;
|
||||
}
|
||||
|
||||
public void ShowForTower(Vector2 screenPosition)
|
||||
{
|
||||
_screenPosition = screenPosition;
|
||||
_displayMode = CombatSelectDisplayMode.Func;
|
||||
_isVisible = true;
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
_isVisible = false;
|
||||
_displayMode = CombatSelectDisplayMode.Hidden;
|
||||
}
|
||||
|
||||
public bool TryExecuteAction(CombatSelectActionType actionType, int actionIndex)
|
||||
{
|
||||
if (!_isVisible)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Option option = GetOption(actionType, actionIndex);
|
||||
if (option == null || !option.IsVisible)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int currentCoin = Mathf.Max(0, _coinProvider != null ? _coinProvider.Invoke() : 0);
|
||||
if (!CanExecute(option, currentCoin))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (option.Action == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = option.Action.Invoke();
|
||||
if (result)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private CombatSelectFormRawData BuildModel()
|
||||
{
|
||||
int currentCoin = Mathf.Max(0, _coinProvider != null ? _coinProvider.Invoke() : 0);
|
||||
TowerSelectItemRawData[] buildItems = new TowerSelectItemRawData[_buildOptions.Length];
|
||||
for (int i = 0; i < _buildOptions.Length; i++)
|
||||
{
|
||||
buildItems[i] = BuildOptionRawData(_buildOptions[i], currentCoin);
|
||||
}
|
||||
|
||||
return new CombatSelectFormRawData
|
||||
{
|
||||
IsVisible = _isVisible,
|
||||
ScreenPosition = _screenPosition,
|
||||
DisplayMode = _displayMode,
|
||||
BuildItems = buildItems,
|
||||
UpgradeItem = BuildOptionRawData(_upgradeOption, currentCoin),
|
||||
DestroyItem = BuildOptionRawData(_destroyOption, currentCoin)
|
||||
};
|
||||
}
|
||||
|
||||
private Option GetOption(CombatSelectActionType actionType, int actionIndex)
|
||||
{
|
||||
switch (actionType)
|
||||
{
|
||||
case CombatSelectActionType.BuildTower:
|
||||
if (actionIndex < 0 || actionIndex >= _buildOptions.Length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _buildOptions[actionIndex];
|
||||
case CombatSelectActionType.UpgradeTower:
|
||||
return _upgradeOption;
|
||||
case CombatSelectActionType.DestroyTower:
|
||||
return _destroyOption;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static int DefaultCoinProvider()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static bool CanExecute(Option option, int currentCoin)
|
||||
{
|
||||
if (option == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (option.RequiresAffordable && currentCoin < option.Price)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static TowerSelectItemRawData BuildOptionRawData(Option option, int currentCoin)
|
||||
{
|
||||
if (option == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new TowerSelectItemRawData
|
||||
{
|
||||
Icon = option.Icon,
|
||||
Price = option.Price,
|
||||
IsGain = option.IsGain,
|
||||
IsVisible = option.IsVisible,
|
||||
IsInteractable = option.Action != null && CanExecute(option, currentCoin),
|
||||
ActionType = option.ActionType,
|
||||
ActionIndex = option.ActionIndex,
|
||||
UseTowerLayers = option.UseTowerLayers,
|
||||
BaseColor = option.BaseColor,
|
||||
BearingColor = option.BearingColor,
|
||||
MuzzleColor = option.MuzzleColor
|
||||
};
|
||||
}
|
||||
|
||||
private sealed class Option
|
||||
{
|
||||
public readonly CombatSelectActionType ActionType;
|
||||
public readonly int ActionIndex;
|
||||
public readonly bool RequiresAffordable;
|
||||
|
||||
public int Price;
|
||||
public bool IsGain;
|
||||
public bool IsVisible = true;
|
||||
public Sprite Icon;
|
||||
public Func<bool> Action;
|
||||
public bool UseTowerLayers;
|
||||
public Color BaseColor = Color.white;
|
||||
public Color BearingColor = Color.white;
|
||||
public Color MuzzleColor = Color.white;
|
||||
|
||||
public Option(CombatSelectActionType actionType, int actionIndex, bool requiresAffordable)
|
||||
{
|
||||
ActionType = actionType;
|
||||
ActionIndex = actionIndex;
|
||||
RequiresAffordable = requiresAffordable;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user