using System; using UnityEngine; using UnityEngine.UI; using static GameManager; public class SettingsInput : MonoBehaviour { [SerializeField] private SettingsScreen screen; public GameManager gameManager; private bool isPaused = false; private bool pushUp = false; private bool leftHeld; private bool rightHeld; private bool downHeld; private bool turn; private bool isActivePanel = false; private bool waitForKeyRelease = false; // Ждём отпускания кнопки после открытия панели private float unifiedTimer = 0f; private float timerThreshold = 1.25f; private ButtonPinMapping secretKey = ButtonPinMapping.secret1; private ButtonPinMapping downKey = ButtonPinMapping.down1; private ButtonPinMapping upKey = ButtonPinMapping.up1; private ButtonPinMapping leftKey = ButtonPinMapping.left1; private ButtonPinMapping rightKey = ButtonPinMapping.right1; private ButtonPinMapping action1 = ButtonPinMapping.action1; private ButtonPinMapping turn1 = ButtonPinMapping.turn1; private SettingsPanelBase panel = null ; // переключашка панели private void OnEnable() { ComWrapper.OnInitialize += Subscribe; } private void OnDisable() { ComWrapper.onCoinAdded.RemoveListener(View); ComWrapper.OnInitialize -= Subscribe; } private void Subscribe() { ComWrapper.onCoinAdded.AddListener(View); } private void View(int __,int _) { screen.AcceptView(); } void Start() { screen.Open(); } void Update() { // --- Переключение паузы / вход в настройки --- if (In.GetButtonDown(secretKey)) { if (gameManager.currentState != GameState.MainMenu && gameManager.currentState != GameState.Setting) return; isPaused = !isPaused; gameManager.SetState(isPaused ? GameState.Setting : GameState.MainMenu); gameManager.SetInputMode(isPaused ? InputMode.Settings : InputMode.UI); } if (!isPaused) return; if (isActivePanel) { HandelPanelInput(); return; } // --- Иначе обычная логика настроек --- HandleSettingsLogic(); } private void HandelPanelInput() { // Ждём отпускания кнопки после открытия панели if (waitForKeyRelease) { if (!In.GetButton(downKey)) { waitForKeyRelease = false; // Кнопка отпущена, разрешаем ввод } return; // Пока кнопка зажата - не обрабатываем ввод } int dirX = 0; if (panel.UsesContinuousInput) { if (In.GetButton(upKey)) dirX++; if (In.GetButton(downKey)) dirX--; } else { if (In.GetButtonDown(upKey)) dirX++; if (In.GetButtonDown(downKey)) dirX--; } panel.SwitchVertical(dirX); bool changeAmount = In.GetButton(turn1); int dirY = 0; if (In.GetButtonDown(leftKey)) dirY--; if (In.GetButtonDown(rightKey)) dirY++; panel.SwitchHorizontal(dirY, changeAmount); if (In.GetButtonDown(action1)) { ClosePanel(); } } private void HandleSettingsLogic() { // Обработка удержания кнопки для открытия панели или выполнения экшена if (In.GetButton(downKey) && screen.CanOpenPanel()) { unifiedTimer += Time.deltaTime; float fillAmount = unifiedTimer / timerThreshold; screen.UpdateProgressBar(fillAmount); // обновляем прогресс-бар в настройке if (unifiedTimer >= timerThreshold) { int id = screen.GetCurrentPanelId(); SettingType currentType = screen.GetCurrentSettingType(); if (currentType == SettingType.Panel) OpenPanel(id); else if (currentType == SettingType.Action) ExecuteAction(id); ResetTimer(); } return; } // Сброс таймера если кнопка не зажата ResetTimer(); // Обычное управление настройками int direction = 0; if (In.GetButtonDown(leftKey)) direction--; if (In.GetButtonDown(rightKey)) direction++; if (direction != 0) screen.Switch(direction); // Переключение слайдера для настроек типа Svitcher if (screen.GetCurrentSettingType() == SettingType.Svitcher) { if (In.GetButtonDown(downKey)) { screen.ToggleSwitcher(); } } else { // Обычный Accept только для не-свитчеров if (In.GetButtonDown(downKey) && screen.isActiveAndEnabled) screen.Accept(); } } private void OpenPanel(int idPanel) { if (panel != null) return; isActivePanel = true; waitForKeyRelease = true; // Блокируем ввод до отпускания кнопки panel = PanelRouter.Instance.GetPanel(idPanel); gameManager.SetState(panel.State); gameManager.SetInputMode(InputMode.Settings); panel.Initialize(idPanel); } private void ClosePanel() { isActivePanel = false; panel.Accept(); panel = null; gameManager.SetState(GameState.Setting); gameManager.SetInputMode(InputMode.Settings); } /// /// Выполняет экшен по ID (для настроек типа Action) /// private void ExecuteAction(int actionId) { switch (actionId) { case 100: // Сброс статистики игр Zeroize(PrizeSystem.key_startsNul); screen.AcceptView(); Debug.Log("Сброс статистики игр выполнен"); break; case 101: // Сброс статистики призов Zeroize(PrizeSystem.key_prizesgivenNul); screen.AcceptView(); Debug.Log("Сброс статистики призов выполнен"); break; case 102: DifficultyManager.SyncChanceToMax(); screen.AcceptView(); Debug.Log("Сброс прогресса до суперприза"); break; default: Debug.LogWarning($"Неизвестный actionId: {actionId}"); break; } } private void ResetTimer() { unifiedTimer = 0f; screen.UpdateProgressBar(0f); // сбрасываем прогресс-бар } private void Zeroize(string key) { PlayerPrefs.SetInt(key, 0); } }