feat: добавлена панель выбора режима игры с поддержкой классического, растущих полей и рифов
This commit is contained in:
parent
85e7fa174a
commit
6ceafddd00
@ -75,7 +75,7 @@ MonoBehaviour:
|
||||
m_fontColor32:
|
||||
serializedVersion: 2
|
||||
rgba: 4294967295
|
||||
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_fontColor: {r: 0.9725491, g: 0.854902, b: 0.5686275, a: 1}
|
||||
m_enableVertexGradient: 0
|
||||
m_colorMode: 3
|
||||
m_fontColorGradient:
|
||||
|
||||
@ -731,7 +731,9 @@ public void DeclineInvite()
|
||||
public void StartPlayerGame()
|
||||
{
|
||||
// PvP всегда использует классический режим 10x10
|
||||
// Конфигурируем оба поля — это сбрасывает сохранённые рифы (если были в режиме "Рифы")
|
||||
playerField.Configure(10, 10);
|
||||
enemyField.Configure(10, 10);
|
||||
PrepareNewGame();
|
||||
Debug.Log("Начинаем игру с игроком");
|
||||
gameMode = GameMode.PlayerVsPlayer;
|
||||
@ -752,6 +754,62 @@ public void StartPlayerGame()
|
||||
enemyManager.SetEnemyPlayer();
|
||||
}
|
||||
|
||||
private string _modeOverride = null;
|
||||
/// <summary>Режим, применённый в текущей игре (определяется в ConfigureFields).</summary>
|
||||
private string _effectiveMode = "Классика";
|
||||
|
||||
/// <summary>Вызывается кнопкой «Играть с ботом».
|
||||
/// Если в настройках включён «Выбор режима игроком» — показывает панель выбора,
|
||||
/// иначе сразу запускает игру с режимом из настроек.</summary>
|
||||
public void TryStartBotGame()
|
||||
{
|
||||
bool playerChooses = SettingsManager.instance?.GetSettingValue("Выбор режима игроком") == "Вкл";
|
||||
if (playerChooses)
|
||||
{
|
||||
// Проверяем баланс ДО показа панели, чтобы не открывать её зря
|
||||
bool isFreeMode = SettingsManager.instance?.GetSettingValue("Бесплатная игра") == "Вкл";
|
||||
if (!isFreeMode)
|
||||
{
|
||||
int price = CreditSystem.GetEffectiveBotPrice(isReplay: false);
|
||||
int credits = CreditSystem.GetPlayerCredits(playerId);
|
||||
if (credits < price)
|
||||
{
|
||||
uiManager?.ShowOverlay("InsufficientFunds", true, hideOtherOverlays: false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
uiManager.ShowOverlay("GameModeSelect", true, hideOtherOverlays: true);
|
||||
SetInputMode(InputMode.UI);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Баланс проверит сам StartBotGame через PayBotGame
|
||||
StartBotGame();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Кнопка «Классика» на панели выбора режима.</summary>
|
||||
public void StartBotClassic()
|
||||
{
|
||||
_modeOverride = "Классика";
|
||||
StartBotGame();
|
||||
}
|
||||
|
||||
/// <summary>Кнопка «Растущие поля» на панели выбора режима.</summary>
|
||||
public void StartBotGrowing()
|
||||
{
|
||||
_modeOverride = "Растущие поля";
|
||||
StartBotGame();
|
||||
}
|
||||
|
||||
/// <summary>Кнопка «Рифы» на панели выбора режима.</summary>
|
||||
public void StartBotReefs()
|
||||
{
|
||||
_modeOverride = "Рифы";
|
||||
StartBotGame();
|
||||
}
|
||||
|
||||
public void StartBotGame(bool isReplay = false)
|
||||
{
|
||||
// Сбрасываем скидку Виндисты — начинается новая игра
|
||||
@ -798,7 +856,9 @@ public void StartBotGame(bool isReplay = false)
|
||||
/// </summary>
|
||||
private void ConfigureFields()
|
||||
{
|
||||
string mode = SettingsManager.instance?.GetSettingValue("Режим игры") ?? "Классика";
|
||||
string mode = _modeOverride ?? SettingsManager.instance?.GetSettingValue("Режим игры") ?? "Классика";
|
||||
_modeOverride = null; // сбрасываем override
|
||||
_effectiveMode = mode; // сохраняем для ApplyModeReefs
|
||||
|
||||
int fieldSize = 10;
|
||||
int shipCount = 10;
|
||||
@ -814,8 +874,8 @@ private void ConfigureFields()
|
||||
}
|
||||
else if (mode == "Рифы")
|
||||
{
|
||||
fieldSize = 10; // поле всегда 10x10
|
||||
shipCount = data.shipCountGame2; // отдельное кол-во кораблей
|
||||
fieldSize = 10;
|
||||
shipCount = data.shipCountGame2;
|
||||
}
|
||||
}
|
||||
|
||||
@ -825,16 +885,11 @@ private void ConfigureFields()
|
||||
Debug.Log($"[GameManager] Режим игры: '{mode}', поле: {fieldSize}x{fieldSize}, кораблей: {shipCount}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Применяет случайные рифы для режима "Рифы".
|
||||
/// Вызывается ПОСЛЕ PrepareNewGame() (после ClearPole), ДО расстановки кораблей.
|
||||
/// </summary>
|
||||
private void ApplyModeReefs()
|
||||
{
|
||||
if (bossLevelConfig == null) return;
|
||||
|
||||
string mode = SettingsManager.instance?.GetSettingValue("Режим игры") ?? "Классика";
|
||||
if (mode != "Рифы") return;
|
||||
if (_effectiveMode != "Рифы") return;
|
||||
|
||||
var data = bossLevelConfig.GetLevel(currentBotLevel);
|
||||
playerField.ApplyRandomReefs(data.reefs);
|
||||
|
||||
@ -86,6 +86,10 @@ public static List<SettingOption> CreateBuiltinDefaults()
|
||||
settings.Add(new SettingOption(settingName: "Ðåæèì èãðû",
|
||||
options: new List<string>() { "Êëàññèêà", "Ðàñòóùèå ïîëÿ", "Ðèôû" },
|
||||
defaultIndex: 0));
|
||||
settings.Add(new SettingOption(settingName: "Âûáîð ðåæèìà èãðîêîì",
|
||||
options: new List<string>() { "Âêë", "Âûêë" },
|
||||
defaultIndex: 1,
|
||||
type: SettingType.Svitcher));
|
||||
settings.Add(new SettingOption(settingName: "Âûäà÷à ïðèçîâ ïðè èãðå ñ áîòîì",
|
||||
options: new List<string>() { "Âûäàâàòü", "Íå âûäàâàòü" },
|
||||
defaultIndex: 0,
|
||||
|
||||
98
Assets/Scripts/UI/Panels/GameModeSelectPanel.cs
Normal file
98
Assets/Scripts/UI/Panels/GameModeSelectPanel.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
/// <summary>
|
||||
/// Панель выбора режима игры.
|
||||
/// Три кнопки — «Классика», «Растущие поля», «Рифы».
|
||||
/// Навигация клавишами — через PlayerCursorUI (InputMode.UI).
|
||||
/// </summary>
|
||||
public class GameModeSelectPanel : MonoBehaviour
|
||||
{
|
||||
[Header("Кнопки режимов (порядок: Классика, Растущие поля, Рифы)")]
|
||||
[SerializeField] private Button buttonClassic;
|
||||
[SerializeField] private Button buttonGrowing;
|
||||
[SerializeField] private Button buttonReefs;
|
||||
|
||||
[Header("Отображение")]
|
||||
[SerializeField] private Image previewImage;
|
||||
[SerializeField] private TMP_Text descriptionText;
|
||||
|
||||
[Header("Картинки режимов (порядок: Классика, Растущие поля, Рифы)")]
|
||||
[SerializeField] private Sprite spriteClassic;
|
||||
[SerializeField] private Sprite spriteGrowing;
|
||||
[SerializeField] private Sprite spriteReefs;
|
||||
|
||||
[Header("Описания режимов")]
|
||||
[SerializeField, TextArea(3, 6)] private string descClassic = "Классический режим 10×10. Стандартные правила морского боя.";
|
||||
[SerializeField, TextArea(3, 6)] private string descGrowing = "Растущие поля — размер поля и количество кораблей увеличиваются с каждым уровнем.";
|
||||
[SerializeField, TextArea(3, 6)] private string descReefs = "Рифы — на поле расставляются случайные рифы, меняя тактику боя.";
|
||||
|
||||
private static readonly string[] ModeNames = { "Классика", "Растущие поля", "Рифы" };
|
||||
|
||||
private Button[] _buttons;
|
||||
private Sprite[] _sprites;
|
||||
private string[] _descriptions;
|
||||
private int _selectedIndex;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_buttons = new[] { buttonClassic, buttonGrowing, buttonReefs };
|
||||
_sprites = new[] { spriteClassic, spriteGrowing, spriteReefs };
|
||||
_descriptions = new[] { descClassic, descGrowing, descReefs };
|
||||
|
||||
for (int i = 0; i < _buttons.Length; i++)
|
||||
{
|
||||
int idx = i;
|
||||
if (_buttons[i] == null) continue;
|
||||
|
||||
_buttons[i].onClick.AddListener(() => SelectMode(idx));
|
||||
|
||||
// При смене фокуса — обновляем превью и описание
|
||||
var hl = _buttons[i].GetComponent<UIButtonHighlight>();
|
||||
if (hl != null)
|
||||
hl.onFocused = () => UpdatePreview(idx);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
SyncFromSettings();
|
||||
}
|
||||
|
||||
/// <summary>Обновляет только картинку и описание — без сохранения настройки и без подсветки.</summary>
|
||||
private void UpdatePreview(int index)
|
||||
{
|
||||
if (previewImage != null) previewImage.sprite = _sprites [index];
|
||||
if (descriptionText != null) descriptionText.text = _descriptions[index];
|
||||
}
|
||||
|
||||
public void SelectMode(int index)
|
||||
{
|
||||
if (index < 0 || index >= ModeNames.Length) return;
|
||||
_selectedIndex = index;
|
||||
SettingsManager.instance?.ChangeSetting("Режим игры", index);
|
||||
RefreshUI();
|
||||
}
|
||||
|
||||
private void SyncFromSettings()
|
||||
{
|
||||
string current = SettingsManager.instance?.GetSettingValue("Режим игры") ?? "Классика";
|
||||
int idx = System.Array.IndexOf(ModeNames, current);
|
||||
_selectedIndex = idx >= 0 ? idx : 0;
|
||||
RefreshUI();
|
||||
}
|
||||
|
||||
private void RefreshUI()
|
||||
{
|
||||
UpdatePreview(_selectedIndex);
|
||||
|
||||
for (int i = 0; i < _buttons.Length; i++)
|
||||
{
|
||||
if (_buttons[i] == null) continue;
|
||||
var hl = _buttons[i].GetComponent<UIButtonHighlight>();
|
||||
if (hl != null)
|
||||
hl.SetHighlighted(i == _selectedIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/UI/Panels/GameModeSelectPanel.cs.meta
Normal file
3
Assets/Scripts/UI/Panels/GameModeSelectPanel.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 234edf74d86242d08ba722398c50f340
|
||||
timeCreated: 1777026250
|
||||
Loading…
x
Reference in New Issue
Block a user