[Add] Game Loop Playable

This commit is contained in:
2026-03-28 12:53:34 +07:00
parent 78ad76120f
commit f2173d2c73
20 changed files with 1433 additions and 122 deletions
@@ -41,7 +41,7 @@ namespace YachtDice.UI.Presentation
public void PrepareForRoll()
{
_view.SetRollButtonState(false, _gameLoopController.CurrentRoll, _gameLoopController.MaxRollsPerTurn);
_view.SetRollButtonPending();
_view.SetDiceInteractable(false);
}
@@ -49,7 +49,7 @@ namespace YachtDice.UI.Presentation
{
var canRollAgain = _gameLoopController.CanRoll;
_view.SetRollButtonState(canRollAgain, rollNumber, _gameLoopController.MaxRollsPerTurn);
_view.SetDiceInteractable(true);
_view.SetDiceInteractable(canRollAgain);
_view.SetAllDiceValues(_diceManager.GetCurrentValues());
}
@@ -65,6 +65,7 @@ namespace YachtDice.UI.Presentation
_gameLoopController.OnQuotaChanged += HandleQuotaChanged;
_gameLoopController.OnCycleCompleted += HandleCycleCompleted;
_gameLoopController.OnPhaseChanged += HandlePhaseChanged;
_gameLoopController.OnShopAvailabilityChanged += HandleShopAvailabilityChanged;
_dicePanelPresenter.RollClicked += HandleRollClicked;
_dicePanelPresenter.DiceToggled += HandleDiceToggled;
@@ -72,13 +73,14 @@ namespace YachtDice.UI.Presentation
_gameInfoPresenter.NewGameClicked += HandleNewGameClicked;
_gameInfoPresenter.ShopClicked += HandleShopClicked;
_gameInfoPresenter.InventoryClicked += HandleInventoryClicked;
_shopController.OnCloseRequested += HandleShopCloseRequested;
_currencyBank.OnBalanceChanged += HandleCurrencyChanged;
_playerModel.OnChanged += HandlePlayerChangedForSave;
_saveService.Load();
_gameInfoPresenter.SetCurrencyText(_currencyBank.Balance);
_gameInfoPresenter.SetShopButtonInteractable(false);
_gameInfoPresenter.SetShopButtonInteractable(_gameLoopController.CanOpenShopManually());
_gameLoopController.StartNewGame();
}
@@ -95,6 +97,7 @@ namespace YachtDice.UI.Presentation
_gameLoopController.OnQuotaChanged -= HandleQuotaChanged;
_gameLoopController.OnCycleCompleted -= HandleCycleCompleted;
_gameLoopController.OnPhaseChanged -= HandlePhaseChanged;
_gameLoopController.OnShopAvailabilityChanged -= HandleShopAvailabilityChanged;
_dicePanelPresenter.RollClicked -= HandleRollClicked;
_dicePanelPresenter.DiceToggled -= HandleDiceToggled;
@@ -102,6 +105,7 @@ namespace YachtDice.UI.Presentation
_gameInfoPresenter.NewGameClicked -= HandleNewGameClicked;
_gameInfoPresenter.ShopClicked -= HandleShopClicked;
_gameInfoPresenter.InventoryClicked -= HandleInventoryClicked;
_shopController.OnCloseRequested -= HandleShopCloseRequested;
_currencyBank.OnBalanceChanged -= HandleCurrencyChanged;
@@ -115,12 +119,14 @@ namespace YachtDice.UI.Presentation
_dicePanelPresenter.ResetForNewTurn();
_dicePanelPresenter.SetRollingEnabled(true);
_scoreCardPresenter.ClearAllPreviews();
_gameInfoPresenter.SetShopButtonInteractable(_gameLoopController.CanOpenShopManually());
}
private void HandleRollComplete(int rollNumber)
{
_dicePanelPresenter.HandleRollComplete(rollNumber);
_scoreCardPresenter.UpdatePreviewScores();
_gameInfoPresenter.SetShopButtonInteractable(_gameLoopController.CanOpenShopManually());
}
private void HandleScored(CategoryDefinition category, int finalScore)
@@ -143,9 +149,11 @@ namespace YachtDice.UI.Presentation
private void HandleRollClicked()
{
if (!_gameLoopController.Roll())
return;
_dicePanelPresenter.PrepareForRoll();
_scoreCardPresenter.SetAllInteractable(false);
_gameLoopController.Roll();
}
private void HandleDiceToggled(int index)
@@ -175,14 +183,9 @@ namespace YachtDice.UI.Presentation
return;
if (_shopController.IsOpen)
{
_shopController.Close();
_gameLoopController.CompleteShop();
}
else
{
_shopController.Open();
}
}
private void HandleInventoryClicked()
@@ -208,16 +211,14 @@ namespace YachtDice.UI.Presentation
private void HandleShopOpened()
{
_shopController.Open();
_gameInfoPresenter.SetShopButtonInteractable(true);
_dicePanelPresenter.SetRollingEnabled(false);
_gameInfoPresenter.SetShopButtonInteractable(_gameLoopController.CanOpenShopManually());
UpdateRunInfoText();
}
private void HandleShopClosed()
{
_shopController.Close();
_gameInfoPresenter.SetShopButtonInteractable(false);
_gameInfoPresenter.SetShopButtonInteractable(_gameLoopController.CanOpenShopManually());
UpdateRunInfoText();
}
@@ -240,16 +241,36 @@ namespace YachtDice.UI.Presentation
private void HandlePhaseChanged(RunPhase phase)
{
if (phase != RunPhase.Shop)
_gameInfoPresenter.SetShopButtonInteractable(false);
_gameInfoPresenter.SetShopButtonInteractable(_gameLoopController.CanOpenShopManually());
UpdateRunInfoText();
}
private void UpdateRunInfoText()
{
var info = $"Bet {_gameLoopController.CurrentBet} | Stage {_gameLoopController.CurrentStage}/3 | Target {_gameLoopController.CurrentStageTarget} | Quota {_gameLoopController.CurrentBaseQuota} | Bank {_gameLoopController.StoredRolls}";
_gameInfoPresenter.SetRunInfoText(info);
var phase = _gameLoopController.CurrentPhase.ToString();
_gameInfoPresenter.SetRunHud(
phase,
_gameLoopController.CurrentBet,
_gameLoopController.CurrentStage,
3,
_gameLoopController.CurrentStageTarget,
_gameLoopController.CurrentBaseQuota,
_gameLoopController.StoredRolls);
}
private void HandleShopCloseRequested()
{
_shopController.Close();
_gameLoopController.CompleteShop();
}
private void HandleShopAvailabilityChanged(bool isAvailable)
{
if (!isAvailable && _shopController.IsOpen)
_shopController.Close();
_gameInfoPresenter.SetShopButtonInteractable(isAvailable);
UpdateRunInfoText();
}
}
}
@@ -39,6 +39,11 @@ namespace YachtDice.UI.Presentation
_view.SetRunInfoText(text);
}
public void SetRunHud(string phase, int bet, int stage, int stageCount, int target, int quota, int storedRolls)
{
_view.SetRunHud(phase, bet, stage, stageCount, target, quota, storedRolls);
}
public void SetCurrencyText(int amount)
{
_view.SetCurrencyText(amount);