[Fix] Code visual

This commit is contained in:
2026-02-28 19:25:26 +07:00
parent bee20fd1f8
commit e24b30743b
39 changed files with 2611 additions and 2687 deletions
+73 -74
View File
@@ -6,89 +6,88 @@ using YachtDice.Scoring;
namespace YachtDice.UI
{
public sealed class CategoryRowView : MonoBehaviour
{
[Header("UI Elements")]
[SerializeField] private TMP_Text categoryNameText;
[SerializeField] private TMP_Text previewText;
[SerializeField] private TMP_Text recordedScoreText;
[SerializeField] private Button selectButton;
[SerializeField] private Image background;
[Header("Colors")]
[SerializeField] private Color normalColor = new Color(0.95f, 0.95f, 0.95f, 1f);
[SerializeField] private Color usedColor = new Color(0.75f, 0.75f, 0.75f, 1f);
[SerializeField] private Color previewPositiveColor = new Color(0.85f, 1f, 0.85f, 1f);
[SerializeField] private Color previewZeroColor = new Color(1f, 0.88f, 0.88f, 1f);
private YachtCategory category;
private bool isUsed;
public event Action<YachtCategory> OnCategorySelected;
public void Initialize(YachtCategory cat, string displayName)
public class CategoryRowView : MonoBehaviour
{
category = cat;
isUsed = false;
categoryNameText.text = displayName;
previewText.text = "";
recordedScoreText.text = "-";
selectButton.onClick.AddListener(HandleClick);
SetInteractable(false);
background.color = normalColor;
}
[Header("UI Elements")]
[SerializeField] private TMP_Text categoryNameText;
[SerializeField] private TMP_Text previewText;
[SerializeField] private TMP_Text recordedScoreText;
[SerializeField] private Button selectButton;
[SerializeField] private Image background;
public void ShowPreview(int previewScore)
{
if (isUsed) return;
previewText.text = previewScore.ToString();
background.color = previewScore > 0 ? previewPositiveColor : previewZeroColor;
}
[Header("Colors")]
[SerializeField] private Color normalColor = new Color(0.95f, 0.95f, 0.95f, 1f);
[SerializeField] private Color usedColor = new Color(0.75f, 0.75f, 0.75f, 1f);
[SerializeField] private Color previewPositiveColor = new Color(0.85f, 1f, 0.85f, 1f);
[SerializeField] private Color previewZeroColor = new Color(1f, 0.88f, 0.88f, 1f);
public void HidePreview()
{
if (isUsed) return;
previewText.text = "";
background.color = normalColor;
}
private YachtCategory category;
private bool isUsed;
public void SetRecordedScore(int score)
{
isUsed = true;
recordedScoreText.text = score.ToString();
previewText.text = "";
SetInteractable(false);
background.color = usedColor;
}
public event Action<YachtCategory> OnCategorySelected;
public void SetInteractable(bool interactable)
{
if (isUsed)
public void Initialize(YachtCategory cat, string displayName)
{
selectButton.interactable = false;
return;
category = cat;
isUsed = false;
categoryNameText.text = displayName;
previewText.text = "";
recordedScoreText.text = "-";
selectButton.onClick.AddListener(HandleClick);
SetInteractable(false);
background.color = normalColor;
}
selectButton.interactable = interactable;
}
public void ResetRow()
{
isUsed = false;
previewText.text = "";
recordedScoreText.text = "-";
SetInteractable(false);
background.color = normalColor;
}
public void ShowPreview(int previewScore)
{
if (isUsed) return;
previewText.text = previewScore.ToString();
background.color = previewScore > 0 ? previewPositiveColor : previewZeroColor;
}
private void HandleClick()
{
OnCategorySelected?.Invoke(category);
}
public void HidePreview()
{
if (isUsed) return;
previewText.text = "";
background.color = normalColor;
}
private void OnDestroy()
{
selectButton.onClick.RemoveListener(HandleClick);
public void SetRecordedScore(int score)
{
isUsed = true;
recordedScoreText.text = score.ToString();
previewText.text = "";
SetInteractable(false);
background.color = usedColor;
}
public void SetInteractable(bool interactable)
{
if (isUsed)
{
selectButton.interactable = false;
return;
}
selectButton.interactable = interactable;
}
public void ResetRow()
{
isUsed = false;
previewText.text = "";
recordedScoreText.text = "-";
SetInteractable(false);
background.color = normalColor;
}
private void HandleClick()
{
OnCategorySelected?.Invoke(category);
}
private void OnDestroy()
{
selectButton.onClick.RemoveListener(HandleClick);
}
}
}
}
+83 -84
View File
@@ -5,101 +5,100 @@ using TMPro;
namespace YachtDice.UI
{
public sealed class DicePanelView : MonoBehaviour
{
[Header("Dice Display")]
[SerializeField] private Button[] diceButtons = new Button[5];
[SerializeField] private TMP_Text[] diceValueTexts = new TMP_Text[5];
[SerializeField] private Image[] diceBackgrounds = new Image[5];
[Header("Roll")]
[SerializeField] private Button rollButton;
[SerializeField] private TMP_Text rollButtonText;
[Header("Colors")]
[SerializeField] private Color unlockedColor = Color.white;
[SerializeField] private Color lockedColor = new Color(1f, 0.85f, 0.4f, 1f);
public event Action<int> OnDiceToggled;
public event Action OnRollClicked;
private void Awake()
public class DicePanelView : MonoBehaviour
{
for (int i = 0; i < diceButtons.Length; i++)
[Header("Dice Display")]
[SerializeField] private Button[] diceButtons = new Button[5];
[SerializeField] private TMP_Text[] diceValueTexts = new TMP_Text[5];
[SerializeField] private Image[] diceBackgrounds = new Image[5];
[Header("Roll")]
[SerializeField] private Button rollButton;
[SerializeField] private TMP_Text rollButtonText;
[Header("Colors")]
[SerializeField] private Color unlockedColor = Color.white;
[SerializeField] private Color lockedColor = new Color(1f, 0.85f, 0.4f, 1f);
public event Action<int> OnDiceToggled;
public event Action OnRollClicked;
private void Awake()
{
int capturedIndex = i;
diceButtons[i].onClick.AddListener(() => OnDiceToggled?.Invoke(capturedIndex));
for (int i = 0; i < diceButtons.Length; i++)
{
int capturedIndex = i;
diceButtons[i].onClick.AddListener(() => OnDiceToggled?.Invoke(capturedIndex));
}
rollButton.onClick.AddListener(() => OnRollClicked?.Invoke());
for (int i = 0; i < diceValueTexts.Length; i++)
{
diceValueTexts[i].text = "?";
diceBackgrounds[i].color = unlockedColor;
diceButtons[i].interactable = false;
}
SetRollButtonState(true, 0, 3);
}
rollButton.onClick.AddListener(() => OnRollClicked?.Invoke());
for (int i = 0; i < diceValueTexts.Length; i++)
public void SetDieValue(int index, int value)
{
diceValueTexts[i].text = "?";
diceBackgrounds[i].color = unlockedColor;
diceButtons[i].interactable = false;
if (index >= 0 && index < diceValueTexts.Length)
diceValueTexts[index].text = value.ToString();
}
SetRollButtonState(true, 0, 3);
}
public void SetDieValue(int index, int value)
{
if (index >= 0 && index < diceValueTexts.Length)
diceValueTexts[index].text = value.ToString();
}
public void SetAllDiceValues(int[] values)
{
for (int i = 0; i < values.Length && i < diceValueTexts.Length; i++)
diceValueTexts[i].text = values[i].ToString();
}
public void SetDieLocked(int index, bool isLocked)
{
if (index >= 0 && index < diceBackgrounds.Length)
diceBackgrounds[index].color = isLocked ? lockedColor : unlockedColor;
}
public void SetDiceInteractable(bool interactable)
{
for (int i = 0; i < diceButtons.Length; i++)
diceButtons[i].interactable = interactable;
}
public void SetRollButtonState(bool interactable, int currentRoll, int maxRolls)
{
rollButton.interactable = interactable;
if (currentRoll >= maxRolls)
rollButtonText.text = "Выберите категорию";
else
rollButtonText.text = $"Бросок {currentRoll + 1}/{maxRolls}";
}
public void ResetForNewTurn()
{
for (int i = 0; i < diceValueTexts.Length; i++)
public void SetAllDiceValues(int[] values)
{
diceValueTexts[i].text = "?";
diceBackgrounds[i].color = unlockedColor;
diceButtons[i].interactable = false;
for (int i = 0; i < values.Length && i < diceValueTexts.Length; i++)
diceValueTexts[i].text = values[i].ToString();
}
}
public void ResetForNewGame()
{
ResetForNewTurn();
SetRollButtonState(true, 0, 3);
}
public void SetDieLocked(int index, bool isLocked)
{
if (index >= 0 && index < diceBackgrounds.Length)
diceBackgrounds[index].color = isLocked ? lockedColor : unlockedColor;
}
private void OnDestroy()
{
for (int i = 0; i < diceButtons.Length; i++)
diceButtons[i].onClick.RemoveAllListeners();
public void SetDiceInteractable(bool interactable)
{
for (int i = 0; i < diceButtons.Length; i++)
diceButtons[i].interactable = interactable;
}
rollButton.onClick.RemoveAllListeners();
public void SetRollButtonState(bool interactable, int currentRoll, int maxRolls)
{
rollButton.interactable = interactable;
if (currentRoll >= maxRolls)
rollButtonText.text = "Выберите категорию";
else
rollButtonText.text = $"Бросок {currentRoll + 1}/{maxRolls}";
}
public void ResetForNewTurn()
{
for (int i = 0; i < diceValueTexts.Length; i++)
{
diceValueTexts[i].text = "?";
diceBackgrounds[i].color = unlockedColor;
diceButtons[i].interactable = false;
}
}
public void ResetForNewGame()
{
ResetForNewTurn();
SetRollButtonState(true, 0, 3);
}
private void OnDestroy()
{
for (int i = 0; i < diceButtons.Length; i++)
diceButtons[i].onClick.RemoveAllListeners();
rollButton.onClick.RemoveAllListeners();
}
}
}
}
+311 -312
View File
@@ -11,348 +11,347 @@ using YachtDice.Modifiers;
namespace YachtDice.UI
{
public sealed class GameController : MonoBehaviour
{
[Header("Model")]
[SerializeField] private GameManager gameManager;
[SerializeField] private ScoringSystem scoringSystem;
[SerializeField] private DiceManager diceManager;
[Header("Views")]
[SerializeField] private ScoreCardView scoreCardView;
[SerializeField] private DicePanelView dicePanelView;
[SerializeField] private GameInfoView gameInfoView;
[Header("Economy & Modifiers")]
[SerializeField] private CurrencyBank currencyBank;
[SerializeField] private ShopController shopController;
[SerializeField] private InventoryController inventoryController;
[Header("Settings")]
[SerializeField] private int maxRollsPerTurn = 3;
[SerializeField] private int maxActiveModifierSlots = 5;
private static readonly YachtCategory[] UpperCategories =
public class GameController : MonoBehaviour
{
YachtCategory.Ones, YachtCategory.Twos, YachtCategory.Threes,
YachtCategory.Fours, YachtCategory.Fives, YachtCategory.Sixes
};
[Header("Model")]
[SerializeField] private GameManager gameManager;
[SerializeField] private ScoringSystem scoringSystem;
[SerializeField] private DiceManager diceManager;
private const int UpperBonusThreshold = 63;
private const int UpperBonusValue = 35;
[Header("Views")]
[SerializeField] private ScoreCardView scoreCardView;
[SerializeField] private DicePanelView dicePanelView;
[SerializeField] private GameInfoView gameInfoView;
private int totalCategoryCount;
[Header("Economy & Modifiers")]
[SerializeField] private CurrencyBank currencyBank;
[SerializeField] private ShopController shopController;
[SerializeField] private InventoryController inventoryController;
private InventoryModel inventoryModel;
private ShopModel shopModel;
[Header("Settings")]
[SerializeField] private int maxRollsPerTurn = 3;
[SerializeField] private int maxActiveModifierSlots = 5;
// ── Lifecycle ──────────────────────────────────────────────
private void Awake()
{
totalCategoryCount = Enum.GetValues(typeof(YachtCategory)).Length;
// Model → Controller
gameManager.OnTurnStarted += HandleTurnStarted;
gameManager.OnRollComplete += HandleRollComplete;
gameManager.OnScored += HandleScored;
gameManager.OnGameOver += HandleGameOver;
diceManager.OnDieSettled += HandleDieSettled;
// View → Controller
scoreCardView.OnCategorySelected += HandleCategorySelected;
dicePanelView.OnRollClicked += HandleRollClicked;
dicePanelView.OnDiceToggled += HandleDiceToggled;
gameInfoView.OnNewGameClicked += HandleNewGameClicked;
gameInfoView.OnShopClicked += HandleShopClicked;
gameInfoView.OnInventoryClicked += HandleInventoryClicked;
// Currency
if (currencyBank != null)
currencyBank.OnBalanceChanged += HandleCurrencyChanged;
InitializeModifierSystems();
}
private void OnDestroy()
{
gameManager.OnTurnStarted -= HandleTurnStarted;
gameManager.OnRollComplete -= HandleRollComplete;
gameManager.OnScored -= HandleScored;
gameManager.OnGameOver -= HandleGameOver;
diceManager.OnDieSettled -= HandleDieSettled;
scoreCardView.OnCategorySelected -= HandleCategorySelected;
dicePanelView.OnRollClicked -= HandleRollClicked;
dicePanelView.OnDiceToggled -= HandleDiceToggled;
gameInfoView.OnNewGameClicked -= HandleNewGameClicked;
gameInfoView.OnShopClicked -= HandleShopClicked;
gameInfoView.OnInventoryClicked -= HandleInventoryClicked;
if (currencyBank != null)
currencyBank.OnBalanceChanged -= HandleCurrencyChanged;
if (inventoryModel != null)
inventoryModel.OnInventoryChanged -= HandleInventoryChangedForSave;
}
// ── Modifier System Init ─────────────────────────────────
private void InitializeModifierSystems()
{
inventoryModel = new InventoryModel(maxActiveModifierSlots);
inventoryModel.OnInventoryChanged += HandleInventoryChangedForSave;
ShopCatalog catalog = shopController != null ? shopController.Catalog : null;
shopModel = new ShopModel(currencyBank, inventoryModel);
LoadSaveData(catalog);
if (inventoryController != null)
inventoryController.Initialize(inventoryModel);
if (shopController != null)
shopController.Initialize(shopModel);
if (currencyBank != null)
gameInfoView.SetCurrencyText(currencyBank.Balance);
}
private void LoadSaveData(ShopCatalog catalog)
{
SaveData save = SaveSystem.Load();
if (currencyBank != null && save.Currency > 0)
currencyBank.SetBalance(save.Currency);
if (catalog != null && save.OwnedModifiers.Count > 0)
private static readonly YachtCategory[] UpperCategories =
{
var runtimeList = new List<ModifierRuntime>();
var permanentIds = new HashSet<string>();
for (int i = 0; i < save.OwnedModifiers.Count; i++)
{
var entry = save.OwnedModifiers[i];
ModifierData data = catalog.FindById(entry.ModifierId);
if (data == null)
{
Debug.LogWarning($"Modifier '{entry.ModifierId}' not found in catalog, skipping.");
continue;
}
var runtime = new ModifierRuntime
{
ModifierId = entry.ModifierId,
IsActive = entry.IsActive,
RemainingUses = entry.RemainingUses,
Data = data
};
runtimeList.Add(runtime);
if (data.Durability == ModifierDurability.Permanent)
permanentIds.Add(data.Id);
}
inventoryModel.LoadState(runtimeList);
shopModel.LoadPurchasedPermanentIds(permanentIds);
}
}
private void PerformSave()
{
var save = new SaveData
{
Currency = currencyBank != null ? currencyBank.Balance : 0
YachtCategory.Ones, YachtCategory.Twos, YachtCategory.Threes,
YachtCategory.Fours, YachtCategory.Fives, YachtCategory.Sixes
};
var owned = inventoryModel.GetAllForSave();
for (int i = 0; i < owned.Count; i++)
private const int UpperBonusThreshold = 63;
private const int UpperBonusValue = 35;
private int totalCategoryCount;
private InventoryModel inventoryModel;
private ShopModel shopModel;
// ── Lifecycle ──────────────────────────────────────────────
private void Awake()
{
save.OwnedModifiers.Add(new ModifierSaveEntry
{
ModifierId = owned[i].ModifierId,
IsActive = owned[i].IsActive,
RemainingUses = owned[i].RemainingUses
});
totalCategoryCount = Enum.GetValues(typeof(YachtCategory)).Length;
// Model → Controller
gameManager.OnTurnStarted += HandleTurnStarted;
gameManager.OnRollComplete += HandleRollComplete;
gameManager.OnScored += HandleScored;
gameManager.OnGameOver += HandleGameOver;
diceManager.OnDieSettled += HandleDieSettled;
// View → Controller
scoreCardView.OnCategorySelected += HandleCategorySelected;
dicePanelView.OnRollClicked += HandleRollClicked;
dicePanelView.OnDiceToggled += HandleDiceToggled;
gameInfoView.OnNewGameClicked += HandleNewGameClicked;
gameInfoView.OnShopClicked += HandleShopClicked;
gameInfoView.OnInventoryClicked += HandleInventoryClicked;
// Currency
if (currencyBank != null)
currencyBank.OnBalanceChanged += HandleCurrencyChanged;
InitializeModifierSystems();
}
SaveSystem.Save(save);
}
// ── Model Event Handlers ──────────────────────────────────
private void HandleTurnStarted(int turn)
{
gameInfoView.SetTurnText(turn, totalCategoryCount);
dicePanelView.ResetForNewTurn();
dicePanelView.SetRollButtonState(true, 0, maxRollsPerTurn);
scoreCardView.ClearAllPreviews();
}
private void HandleRollComplete(int rollNumber)
{
bool canRollAgain = gameManager.CanRoll;
dicePanelView.SetRollButtonState(canRollAgain, rollNumber, maxRollsPerTurn);
dicePanelView.SetDiceInteractable(true);
int[] values = diceManager.GetCurrentValues();
dicePanelView.SetAllDiceValues(values);
UpdatePreviewScores(values);
}
private void HandleDieSettled(int index, int value)
{
dicePanelView.SetDieValue(index, value);
}
private void HandleScored(YachtCategory category, int finalScore)
{
scoreCardView.SetCategoryScored(category, finalScore);
UpdateTotalDisplay();
PerformSave();
}
private void HandleGameOver(int totalScore)
{
dicePanelView.SetRollButtonState(false, maxRollsPerTurn, maxRollsPerTurn);
dicePanelView.SetDiceInteractable(false);
scoreCardView.SetAllInteractable(false);
int displayTotal = CalculateDisplayTotal();
gameInfoView.ShowGameOver(displayTotal);
PerformSave();
}
// ── View Event Handlers ───────────────────────────────────
private void HandleRollClicked()
{
if (!gameManager.CanRoll) return;
dicePanelView.SetRollButtonState(false, gameManager.CurrentRoll, maxRollsPerTurn);
dicePanelView.SetDiceInteractable(false);
scoreCardView.SetAllInteractable(false);
gameManager.Roll();
}
private void HandleDiceToggled(int index)
{
if (gameManager.CurrentRoll == 0) return;
if (diceManager.IsAnyRolling) return;
gameManager.ToggleDiceLock(index);
bool isLocked = diceManager.IsLocked(index);
dicePanelView.SetDieLocked(index, isLocked);
}
private void HandleCategorySelected(YachtCategory category)
{
if (!gameManager.CanScore) return;
if (scoringSystem.IsCategoryUsed(category)) return;
gameManager.ScoreInCategory(category);
}
private void HandleNewGameClicked()
{
gameInfoView.HideGameOver();
scoreCardView.ResetAll();
dicePanelView.ResetForNewGame();
gameManager.StartNewGame();
}
private void HandleShopClicked()
{
if (shopController != null)
private void OnDestroy()
{
var shopView = shopController.GetComponentInChildren<ShopView>(true);
if (shopView != null)
gameManager.OnTurnStarted -= HandleTurnStarted;
gameManager.OnRollComplete -= HandleRollComplete;
gameManager.OnScored -= HandleScored;
gameManager.OnGameOver -= HandleGameOver;
diceManager.OnDieSettled -= HandleDieSettled;
scoreCardView.OnCategorySelected -= HandleCategorySelected;
dicePanelView.OnRollClicked -= HandleRollClicked;
dicePanelView.OnDiceToggled -= HandleDiceToggled;
gameInfoView.OnNewGameClicked -= HandleNewGameClicked;
gameInfoView.OnShopClicked -= HandleShopClicked;
gameInfoView.OnInventoryClicked -= HandleInventoryClicked;
if (currencyBank != null)
currencyBank.OnBalanceChanged -= HandleCurrencyChanged;
if (inventoryModel != null)
inventoryModel.OnInventoryChanged -= HandleInventoryChangedForSave;
}
// ── Modifier System Init ─────────────────────────────────
private void InitializeModifierSystems()
{
inventoryModel = new InventoryModel(maxActiveModifierSlots);
inventoryModel.OnInventoryChanged += HandleInventoryChangedForSave;
ShopCatalog catalog = shopController != null ? shopController.Catalog : null;
shopModel = new ShopModel(currencyBank, inventoryModel);
LoadSaveData(catalog);
if (inventoryController != null)
inventoryController.Initialize(inventoryModel);
if (shopController != null)
shopController.Initialize(shopModel);
if (currencyBank != null)
gameInfoView.SetCurrencyText(currencyBank.Balance);
}
private void LoadSaveData(ShopCatalog catalog)
{
SaveData save = SaveSystem.Load();
if (currencyBank != null && save.Currency > 0)
currencyBank.SetBalance(save.Currency);
if (catalog != null && save.OwnedModifiers.Count > 0)
{
if (shopView.IsVisible) shopView.Hide();
else shopView.Show();
var runtimeList = new List<ModifierRuntime>();
var permanentIds = new HashSet<string>();
for (int i = 0; i < save.OwnedModifiers.Count; i++)
{
var entry = save.OwnedModifiers[i];
ModifierData data = catalog.FindById(entry.ModifierId);
if (data == null)
{
Debug.LogWarning($"Modifier '{entry.ModifierId}' not found in catalog, skipping.");
continue;
}
var runtime = new ModifierRuntime
{
ModifierId = entry.ModifierId,
IsActive = entry.IsActive,
RemainingUses = entry.RemainingUses,
Data = data
};
runtimeList.Add(runtime);
if (data.Durability == ModifierDurability.Permanent)
permanentIds.Add(data.Id);
}
inventoryModel.LoadState(runtimeList);
shopModel.LoadPurchasedPermanentIds(permanentIds);
}
}
}
private void HandleInventoryClicked()
{
if (inventoryController != null)
private void PerformSave()
{
var inventoryView = inventoryController.GetComponentInChildren<InventoryView>(true);
if (inventoryView != null)
var save = new SaveData
{
if (inventoryView.IsVisible) inventoryView.Hide();
else inventoryView.Show();
Currency = currencyBank != null ? currencyBank.Balance : 0
};
var owned = inventoryModel.GetAllForSave();
for (int i = 0; i < owned.Count; i++)
{
save.OwnedModifiers.Add(new ModifierSaveEntry
{
ModifierId = owned[i].ModifierId,
IsActive = owned[i].IsActive,
RemainingUses = owned[i].RemainingUses
});
}
SaveSystem.Save(save);
}
// ── Model Event Handlers ──────────────────────────────────
private void HandleTurnStarted(int turn)
{
gameInfoView.SetTurnText(turn, totalCategoryCount);
dicePanelView.ResetForNewTurn();
dicePanelView.SetRollButtonState(true, 0, maxRollsPerTurn);
scoreCardView.ClearAllPreviews();
}
private void HandleRollComplete(int rollNumber)
{
bool canRollAgain = gameManager.CanRoll;
dicePanelView.SetRollButtonState(canRollAgain, rollNumber, maxRollsPerTurn);
dicePanelView.SetDiceInteractable(true);
int[] values = diceManager.GetCurrentValues();
dicePanelView.SetAllDiceValues(values);
UpdatePreviewScores(values);
}
private void HandleDieSettled(int index, int value)
{
dicePanelView.SetDieValue(index, value);
}
private void HandleScored(YachtCategory category, int finalScore)
{
scoreCardView.SetCategoryScored(category, finalScore);
UpdateTotalDisplay();
PerformSave();
}
private void HandleGameOver(int totalScore)
{
dicePanelView.SetRollButtonState(false, maxRollsPerTurn, maxRollsPerTurn);
dicePanelView.SetDiceInteractable(false);
scoreCardView.SetAllInteractable(false);
int displayTotal = CalculateDisplayTotal();
gameInfoView.ShowGameOver(displayTotal);
PerformSave();
}
// ── View Event Handlers ───────────────────────────────────
private void HandleRollClicked()
{
if (!gameManager.CanRoll) return;
dicePanelView.SetRollButtonState(false, gameManager.CurrentRoll, maxRollsPerTurn);
dicePanelView.SetDiceInteractable(false);
scoreCardView.SetAllInteractable(false);
gameManager.Roll();
}
private void HandleDiceToggled(int index)
{
if (gameManager.CurrentRoll == 0) return;
if (diceManager.IsAnyRolling) return;
gameManager.ToggleDiceLock(index);
bool isLocked = diceManager.IsLocked(index);
dicePanelView.SetDieLocked(index, isLocked);
}
private void HandleCategorySelected(YachtCategory category)
{
if (!gameManager.CanScore) return;
if (scoringSystem.IsCategoryUsed(category)) return;
gameManager.ScoreInCategory(category);
}
private void HandleNewGameClicked()
{
gameInfoView.HideGameOver();
scoreCardView.ResetAll();
dicePanelView.ResetForNewGame();
gameManager.StartNewGame();
}
private void HandleShopClicked()
{
if (shopController != null)
{
var shopView = shopController.GetComponentInChildren<ShopView>(true);
if (shopView != null)
{
if (shopView.IsVisible) shopView.Hide();
else shopView.Show();
}
}
}
}
private void HandleCurrencyChanged(int newBalance)
{
gameInfoView.SetCurrencyText(newBalance);
PerformSave();
}
private void HandleInventoryChangedForSave()
{
PerformSave();
}
// ── Helpers ────────────────────────────────────────────────
private void UpdatePreviewScores(int[] diceValues)
{
var previews = new Dictionary<YachtCategory, int>();
var categories = (YachtCategory[])Enum.GetValues(typeof(YachtCategory));
for (int i = 0; i < categories.Length; i++)
private void HandleInventoryClicked()
{
if (scoringSystem.IsCategoryUsed(categories[i])) continue;
ScoreResult result = scoringSystem.PreviewScore(diceValues, categories[i]);
previews[categories[i]] = result.FinalScore;
if (inventoryController != null)
{
var inventoryView = inventoryController.GetComponentInChildren<InventoryView>(true);
if (inventoryView != null)
{
if (inventoryView.IsVisible) inventoryView.Hide();
else inventoryView.Show();
}
}
}
scoreCardView.UpdatePreviews(previews);
}
private void UpdateTotalDisplay()
{
int upperSum = 0;
for (int i = 0; i < UpperCategories.Length; i++)
private void HandleCurrencyChanged(int newBalance)
{
int catScore = scoringSystem.GetCategoryScore(UpperCategories[i]);
if (catScore >= 0) upperSum += catScore;
gameInfoView.SetCurrencyText(newBalance);
PerformSave();
}
bool hasBonus = upperSum >= UpperBonusThreshold;
int displayTotal = CalculateDisplayTotal();
scoreCardView.UpdateTotalDisplay(displayTotal, upperSum, hasBonus);
}
private int CalculateDisplayTotal()
{
int total = scoringSystem.TotalScore;
int upperSum = 0;
for (int i = 0; i < UpperCategories.Length; i++)
private void HandleInventoryChangedForSave()
{
int catScore = scoringSystem.GetCategoryScore(UpperCategories[i]);
if (catScore >= 0) upperSum += catScore;
PerformSave();
}
if (upperSum >= UpperBonusThreshold)
total += UpperBonusValue;
// ── Helpers ────────────────────────────────────────────────
return total;
private void UpdatePreviewScores(int[] diceValues)
{
var previews = new Dictionary<YachtCategory, int>();
var categories = (YachtCategory[])Enum.GetValues(typeof(YachtCategory));
for (int i = 0; i < categories.Length; i++)
{
if (scoringSystem.IsCategoryUsed(categories[i])) continue;
ScoreResult result = scoringSystem.PreviewScore(diceValues, categories[i]);
previews[categories[i]] = result.FinalScore;
}
scoreCardView.UpdatePreviews(previews);
}
private void UpdateTotalDisplay()
{
int upperSum = 0;
for (int i = 0; i < UpperCategories.Length; i++)
{
int catScore = scoringSystem.GetCategoryScore(UpperCategories[i]);
if (catScore >= 0) upperSum += catScore;
}
bool hasBonus = upperSum >= UpperBonusThreshold;
int displayTotal = CalculateDisplayTotal();
scoreCardView.UpdateTotalDisplay(displayTotal, upperSum, hasBonus);
}
private int CalculateDisplayTotal()
{
int total = scoringSystem.TotalScore;
int upperSum = 0;
for (int i = 0; i < UpperCategories.Length; i++)
{
int catScore = scoringSystem.GetCategoryScore(UpperCategories[i]);
if (catScore >= 0) upperSum += catScore;
}
if (upperSum >= UpperBonusThreshold)
total += UpperBonusValue;
return total;
}
}
}
}
+55 -56
View File
@@ -5,69 +5,68 @@ using TMPro;
namespace YachtDice.UI
{
public sealed class GameInfoView : MonoBehaviour
{
[Header("Turn Info")]
[SerializeField] private TMP_Text turnText;
[Header("Currency")]
[SerializeField] private TMP_Text currencyText;
[Header("Navigation")]
[SerializeField] private Button shopButton;
[SerializeField] private Button inventoryButton;
[Header("Game Over Overlay")]
[SerializeField] private GameObject gameOverPanel;
[SerializeField] private TMP_Text finalScoreText;
[SerializeField] private Button newGameButton;
public event Action OnNewGameClicked;
public event Action OnShopClicked;
public event Action OnInventoryClicked;
private void Awake()
public class GameInfoView : MonoBehaviour
{
newGameButton.onClick.AddListener(() => OnNewGameClicked?.Invoke());
gameOverPanel.SetActive(false);
[Header("Turn Info")]
[SerializeField] private TMP_Text turnText;
if (shopButton != null)
shopButton.onClick.AddListener(() => OnShopClicked?.Invoke());
if (inventoryButton != null)
inventoryButton.onClick.AddListener(() => OnInventoryClicked?.Invoke());
}
[Header("Currency")]
[SerializeField] private TMP_Text currencyText;
public void SetTurnText(int turn, int maxTurns)
{
turnText.text = $"Ход {turn} / {maxTurns}";
}
[Header("Navigation")]
[SerializeField] private Button shopButton;
[SerializeField] private Button inventoryButton;
public void SetCurrencyText(int amount)
{
if (currencyText != null)
currencyText.text = amount.ToString();
}
[Header("Game Over Overlay")]
[SerializeField] private GameObject gameOverPanel;
[SerializeField] private TMP_Text finalScoreText;
[SerializeField] private Button newGameButton;
public void ShowGameOver(int finalScore)
{
gameOverPanel.SetActive(true);
finalScoreText.text = $"Итого: {finalScore}";
}
public event Action OnNewGameClicked;
public event Action OnShopClicked;
public event Action OnInventoryClicked;
public void HideGameOver()
{
gameOverPanel.SetActive(false);
}
private void Awake()
{
newGameButton.onClick.AddListener(() => OnNewGameClicked?.Invoke());
gameOverPanel.SetActive(false);
private void OnDestroy()
{
newGameButton.onClick.RemoveAllListeners();
if (shopButton != null)
shopButton.onClick.AddListener(() => OnShopClicked?.Invoke());
if (inventoryButton != null)
inventoryButton.onClick.AddListener(() => OnInventoryClicked?.Invoke());
}
if (shopButton != null)
shopButton.onClick.RemoveAllListeners();
if (inventoryButton != null)
inventoryButton.onClick.RemoveAllListeners();
public void SetTurnText(int turn, int maxTurns)
{
turnText.text = $"Ход {turn} / {maxTurns}";
}
public void SetCurrencyText(int amount)
{
if (currencyText != null)
currencyText.text = amount.ToString();
}
public void ShowGameOver(int finalScore)
{
gameOverPanel.SetActive(true);
finalScoreText.text = $"Итого: {finalScore}";
}
public void HideGameOver()
{
gameOverPanel.SetActive(false);
}
private void OnDestroy()
{
newGameButton.onClick.RemoveAllListeners();
if (shopButton != null)
shopButton.onClick.RemoveAllListeners();
if (inventoryButton != null)
inventoryButton.onClick.RemoveAllListeners();
}
}
}
}
+89 -90
View File
@@ -6,109 +6,108 @@ using YachtDice.Scoring;
namespace YachtDice.UI
{
public sealed class ScoreCardView : MonoBehaviour
{
[Header("Category Rows (in YachtCategory enum order)")]
[SerializeField] private List<CategoryRowView> categoryRows = new();
[Header("Summary")]
[SerializeField] private TMP_Text upperSumText;
[SerializeField] private TMP_Text upperBonusText;
[SerializeField] private TMP_Text totalScoreText;
public event Action<YachtCategory> OnCategorySelected;
private static readonly string[] CategoryNames =
public class ScoreCardView : MonoBehaviour
{
"Единицы",
"Двойки",
"Тройки",
"Четвёрки",
"Пятёрки",
"Шестёрки",
"Тройка",
"Каре",
"Фулл-хаус",
"Малый стрит",
"Большой стрит",
"Яхта",
"Шанс"
};
[Header("Category Rows (in YachtCategory enum order)")]
[SerializeField] private List<CategoryRowView> categoryRows = new();
private YachtCategory[] allCategories;
[Header("Summary")]
[SerializeField] private TMP_Text upperSumText;
[SerializeField] private TMP_Text upperBonusText;
[SerializeField] private TMP_Text totalScoreText;
private void Awake()
{
allCategories = (YachtCategory[])Enum.GetValues(typeof(YachtCategory));
public event Action<YachtCategory> OnCategorySelected;
for (int i = 0; i < categoryRows.Count && i < allCategories.Length; i++)
private static readonly string[] CategoryNames =
{
categoryRows[i].Initialize(allCategories[i], CategoryNames[i]);
categoryRows[i].OnCategorySelected += HandleCategorySelected;
"Единицы",
"Двойки",
"Тройки",
"Четвёрки",
"Пятёрки",
"Шестёрки",
"Тройка",
"Каре",
"Фулл-хаус",
"Малый стрит",
"Большой стрит",
"Яхта",
"Шанс"
};
private YachtCategory[] allCategories;
private void Awake()
{
allCategories = (YachtCategory[])Enum.GetValues(typeof(YachtCategory));
for (int i = 0; i < categoryRows.Count && i < allCategories.Length; i++)
{
categoryRows[i].Initialize(allCategories[i], CategoryNames[i]);
categoryRows[i].OnCategorySelected += HandleCategorySelected;
}
UpdateTotalDisplay(0, 0, false);
}
UpdateTotalDisplay(0, 0, false);
}
public void UpdatePreviews(Dictionary<YachtCategory, int> previews)
{
for (int i = 0; i < categoryRows.Count && i < allCategories.Length; i++)
public void UpdatePreviews(Dictionary<YachtCategory, int> previews)
{
if (previews.TryGetValue(allCategories[i], out int preview))
for (int i = 0; i < categoryRows.Count && i < allCategories.Length; i++)
{
categoryRows[i].ShowPreview(preview);
categoryRows[i].SetInteractable(true);
if (previews.TryGetValue(allCategories[i], out int preview))
{
categoryRows[i].ShowPreview(preview);
categoryRows[i].SetInteractable(true);
}
}
}
}
public void ClearAllPreviews()
{
for (int i = 0; i < categoryRows.Count; i++)
public void ClearAllPreviews()
{
categoryRows[i].HidePreview();
categoryRows[i].SetInteractable(false);
for (int i = 0; i < categoryRows.Count; i++)
{
categoryRows[i].HidePreview();
categoryRows[i].SetInteractable(false);
}
}
public void SetCategoryScored(YachtCategory category, int score)
{
int index = (int)category;
if (index >= 0 && index < categoryRows.Count)
categoryRows[index].SetRecordedScore(score);
}
public void SetAllInteractable(bool interactable)
{
for (int i = 0; i < categoryRows.Count; i++)
categoryRows[i].SetInteractable(interactable);
}
public void UpdateTotalDisplay(int totalScore, int upperSum, bool hasUpperBonus)
{
totalScoreText.text = totalScore.ToString();
upperSumText.text = $"{upperSum} / 63";
upperBonusText.text = hasUpperBonus ? "+35" : "---";
}
public void ResetAll()
{
for (int i = 0; i < categoryRows.Count; i++)
categoryRows[i].ResetRow();
UpdateTotalDisplay(0, 0, false);
}
private void HandleCategorySelected(YachtCategory category)
{
OnCategorySelected?.Invoke(category);
}
private void OnDestroy()
{
for (int i = 0; i < categoryRows.Count; i++)
categoryRows[i].OnCategorySelected -= HandleCategorySelected;
}
}
public void SetCategoryScored(YachtCategory category, int score)
{
int index = (int)category;
if (index >= 0 && index < categoryRows.Count)
categoryRows[index].SetRecordedScore(score);
}
public void SetAllInteractable(bool interactable)
{
for (int i = 0; i < categoryRows.Count; i++)
categoryRows[i].SetInteractable(interactable);
}
public void UpdateTotalDisplay(int totalScore, int upperSum, bool hasUpperBonus)
{
totalScoreText.text = totalScore.ToString();
upperSumText.text = $"{upperSum} / 63";
upperBonusText.text = hasUpperBonus ? "+35" : "---";
}
public void ResetAll()
{
for (int i = 0; i < categoryRows.Count; i++)
categoryRows[i].ResetRow();
UpdateTotalDisplay(0, 0, false);
}
private void HandleCategorySelected(YachtCategory category)
{
OnCategorySelected?.Invoke(category);
}
private void OnDestroy()
{
for (int i = 0; i < categoryRows.Count; i++)
categoryRows[i].OnCategorySelected -= HandleCategorySelected;
}
}
}