[Add] Game Loop Playable
This commit is contained in:
@@ -82,6 +82,12 @@ namespace YachtDice.UI
|
||||
rollButtonText.text = $"Бросок {currentRoll + 1}/{maxRolls}";
|
||||
}
|
||||
|
||||
public void SetRollButtonPending()
|
||||
{
|
||||
rollButton.interactable = false;
|
||||
rollButtonText.text = "Бросок...";
|
||||
}
|
||||
|
||||
public void SetRollButtonInteractable(bool interactable)
|
||||
{
|
||||
rollButton.interactable = interactable;
|
||||
|
||||
@@ -7,8 +7,14 @@ namespace YachtDice.UI
|
||||
{
|
||||
public class GameInfoView : MonoBehaviour
|
||||
{
|
||||
[Header("Turn Info")]
|
||||
[Header("Run HUD")]
|
||||
[SerializeField] private TMP_Text turnText;
|
||||
[SerializeField] private TMP_Text phaseText;
|
||||
[SerializeField] private TMP_Text betText;
|
||||
[SerializeField] private TMP_Text stageText;
|
||||
[SerializeField] private TMP_Text targetText;
|
||||
[SerializeField] private TMP_Text quotaText;
|
||||
[SerializeField] private TMP_Text storedRollsText;
|
||||
|
||||
[Header("Currency")]
|
||||
[SerializeField] private TMP_Text currencyText;
|
||||
@@ -28,6 +34,9 @@ namespace YachtDice.UI
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
EnsureHudBindings();
|
||||
EnsureGameOverBindings();
|
||||
|
||||
newGameButton.onClick.AddListener(() => OnNewGameClicked?.Invoke());
|
||||
gameOverPanel.SetActive(false);
|
||||
|
||||
@@ -43,9 +52,27 @@ namespace YachtDice.UI
|
||||
}
|
||||
|
||||
public void SetRunInfoText(string text)
|
||||
{
|
||||
if (phaseText != null)
|
||||
phaseText.text = text;
|
||||
}
|
||||
|
||||
public void SetRunHud(string phase, int bet, int stage, int stageCount, int target, int quota, int storedRolls)
|
||||
{
|
||||
if (turnText != null)
|
||||
turnText.text = text;
|
||||
turnText.text = $"Turn {stage}/{stageCount}";
|
||||
if (phaseText != null)
|
||||
phaseText.text = $"Phase: {phase}";
|
||||
if (betText != null)
|
||||
betText.text = $"Bet: {bet}";
|
||||
if (stageText != null)
|
||||
stageText.text = $"Stage: {stage}/{stageCount}";
|
||||
if (targetText != null)
|
||||
targetText.text = $"Target: {target}";
|
||||
if (quotaText != null)
|
||||
quotaText.text = $"Quota: {quota}";
|
||||
if (storedRollsText != null)
|
||||
storedRollsText.text = $"Stored Rolls: {storedRolls}";
|
||||
}
|
||||
|
||||
public void SetCurrencyText(int amount)
|
||||
@@ -80,5 +107,61 @@ namespace YachtDice.UI
|
||||
if (inventoryButton != null)
|
||||
inventoryButton.onClick.RemoveAllListeners();
|
||||
}
|
||||
|
||||
private void EnsureHudBindings()
|
||||
{
|
||||
if (turnText == null)
|
||||
return;
|
||||
|
||||
phaseText ??= turnText;
|
||||
betText ??= CreateHudLabel("Bet Text", -34);
|
||||
stageText ??= CreateHudLabel("Stage Text", -68);
|
||||
targetText ??= CreateHudLabel("Target Text", -102);
|
||||
quotaText ??= CreateHudLabel("Quota Text", -136);
|
||||
storedRollsText ??= CreateHudLabel("Stored Rolls Text", -170);
|
||||
}
|
||||
|
||||
private void EnsureGameOverBindings()
|
||||
{
|
||||
if (gameOverPanel == null)
|
||||
return;
|
||||
|
||||
if (finalScoreText == null || finalScoreText == currencyText)
|
||||
{
|
||||
TMP_Text source = turnText != null ? turnText : currencyText;
|
||||
if (source == null)
|
||||
return;
|
||||
|
||||
finalScoreText = Instantiate(source, gameOverPanel.transform);
|
||||
finalScoreText.name = "Final Score Text";
|
||||
|
||||
if (finalScoreText.transform is RectTransform rect)
|
||||
{
|
||||
rect.anchorMin = new Vector2(0.5f, 0.5f);
|
||||
rect.anchorMax = new Vector2(0.5f, 0.5f);
|
||||
rect.pivot = new Vector2(0.5f, 0.5f);
|
||||
rect.anchoredPosition = new Vector2(0f, 40f);
|
||||
rect.sizeDelta = new Vector2(360f, 60f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TMP_Text CreateHudLabel(string objectName, float yOffset)
|
||||
{
|
||||
var clone = Instantiate(turnText, turnText.transform.parent);
|
||||
clone.name = objectName;
|
||||
clone.text = string.Empty;
|
||||
|
||||
if (clone.transform is RectTransform rect && turnText.transform is RectTransform sourceRect)
|
||||
{
|
||||
rect.anchorMin = sourceRect.anchorMin;
|
||||
rect.anchorMax = sourceRect.anchorMax;
|
||||
rect.pivot = sourceRect.pivot;
|
||||
rect.sizeDelta = sourceRect.sizeDelta;
|
||||
rect.anchoredPosition = sourceRect.anchoredPosition + new Vector2(0f, yOffset);
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user