[Add] Game Loop Playable
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user