diff --git a/Assets/Scripts/GameFSM/MenuState.cs b/Assets/Scripts/GameFSM/MenuState.cs index e713b45..5428950 100644 --- a/Assets/Scripts/GameFSM/MenuState.cs +++ b/Assets/Scripts/GameFSM/MenuState.cs @@ -6,10 +6,15 @@ public class MenuState : IState { GameManager gm; - float timeToPromo = 180; + float SecondsToPromo = 180; + float ElapsedPromoTimer; + float timeToFastcheck = 2; + float GotoSettingsPressedTime = 3; + float ElapsedSettinsPressedTime; bool animationEnded = true; + public Transform label, buttonLeft, @@ -29,21 +34,13 @@ public class MenuState : IState sLabel = new Vector2(0, 300), eLabel = new Vector2(0, 1000), - //свечение - sGlow = new Vector2(490, 0), - eGlow = new Vector2(2000, 0), - - //режимы + //Иконки режимов sButton = new Vector2(250, 180), eButton = new Vector2(2000, 180), //подсказка + лого + техподдержка sLabel2 = new Vector2(0, -380), eLabel2 = new Vector2(0, -1000), - - //земля - sGround = new Vector2(0, -15), - eGround = new Vector2(0, -5.75f), //Доска sBoard = new Vector2(-40, -0.5f), @@ -59,12 +56,32 @@ public class MenuState : IState Vector2 eSmallPrizesOutSize = new Vector2(660, 100); #endregion - //bool leftPosition = true; public MenuState() { - gm = GameManager.instance; + subState = MenuSubStates.Choosing;//субстейт и так ставится в энтере + } + //если пришли из игры, то нужно начать с открытия меню + public MenuState(bool fromGameplay) : this() + { + subState = MenuSubStates.OpeningMenu;//субстейт и так ставится в энтере + } + + public void enter() + { + PullRefs(); + ResetGameSession(); + + ElapsedPromoTimer = 0; + + subState = gm.menuOpened ? MenuSubStates.Choosing : MenuSubStates.OpeningMenu; + LightUtility.Idle(); + } + + private void PullRefs() + { + gm = GameManager.instance; label = gm.label; buttonLeft = gm.buttonLeft; buttonRight = gm.buttonRight; @@ -72,50 +89,24 @@ public class MenuState : IState label2 = gm.label2; board = gm.board; noPrizeLabel = gm.noPrizeLabel; - SmallPrizesOut = gm.smallPrizesOut; - - - subState = MenuSubStates.Choosing; } - - //если пришли из игры, то нужно начать с открытия меню - public MenuState(bool fromGameplay) : this() - { - subState = MenuSubStates.OpeningMenu; - } - - public void enter() + private void ResetGameSession() { + //ресет gm.vsBotThinkTime = 0; gm.vsBotMoves = 0; CharacterController.HideCharacter(); CharacterController.I.SetAllCharactersPrizeAvailable(true); - DifficultyManager.instance.ResetDifficulty(); - if (!gm.menuOpened) - { - subState = MenuSubStates.OpeningMenu; - } - else - { - subState = MenuSubStates.Choosing; - restTimeToPromo = timeToPromo; - } - gm.player1score = 0; gm.player2score = 0; gm.vsBotScore = 0; - - LightUtility.Idle(); } - public void exit() - { - - } + public void exit() { } public void update() { @@ -140,90 +131,108 @@ public class MenuState : IState } } - - float restTimeToPromo /*= timeToPromo*/; - //float timeToPromo = 180; - float timeToCheck = 2; - float timeToMenu; - private void ChoosingMode() + private void ChoosingMode()//основное состояние(выбор) { if (!animationEnded) return; //Заход в настройки - bool menuKeys = In.GetButton(ButtonPinMapping.secret) || Input.GetKey(KeyCode.F5); - if (menuKeys) + if (ShouldGotosettings()) { - timeToMenu += Time.deltaTime; - if(timeToMenu >= 3f) - { - gm.stateMachine.ChangeState(new SettingsState()); - timeToMenu = 0; - return; - } - } - else - { - timeToMenu -= Time.deltaTime; - } - timeToMenu = Mathf.Clamp(timeToMenu, 0, 3); - - if (In.GetButtonDown(ButtonPinMapping.startOnePlayer)) - { - gm.SetMode(GameMode.pve); - - // тут проинициализировать шкалы для 1 или 2 игроков - gm.InitVictoryScales(); - SoundManager.instance.playChoose(); - - subState = MenuSubStates.Payment; - } - if (In.GetButtonDown(ButtonPinMapping.startTwoPlayers)) - { - gm.SetMode(GameMode.pvp); - - // тут проинициализировать шкалы для 1 или 2 игроков - gm.InitVictoryScales(); - SoundManager.instance.playChoose(); - - subState = MenuSubStates.Payment; + SoundManager.instance.playSwitch(); + gm.stateMachine.ChangeState(new SettingsState()); + return; } + //Определяемся с режимом игры + if (GamemodeChosen()) return; + + //Правила if (In.GetButtonDownAnyPlayer(PlayerAction.down)) { gm.stateMachine.ChangeState(new RulesState()); + return; } - restTimeToPromo -= Time.deltaTime; - if (restTimeToPromo < 0) + + //Промовидос + ElapsedPromoTimer = Mathf.Clamp(ElapsedPromoTimer +Time.deltaTime, 0, SecondsToPromo); + if (ElapsedPromoTimer == SecondsToPromo) + { gm.stateMachine.ChangeState(new PromoState()); + return; + } - + //Заход в лидерборд bool gotoLeaderboard = In.GetButtonDownAnyPlayer(PlayerAction.left) && In.GetButtonDownAnyPlayer(PlayerAction.right); if (gotoLeaderboard) - gm.stateMachine.ChangeState(new CheckLeadersFromMenuState()); + { + ElapsedPromoTimer = 0; + gm.stateMachine.ChangeState(new CheckLeadersFromMenuState()); + return; + } + + //проверка счетчиков bool checkCountersCombination = In.GetButton(ButtonPinMapping.startOnePlayer) && In.GetButton(ButtonPinMapping.startTwoPlayers); if (checkCountersCombination) { - timeToCheck -= Time.deltaTime; - if (timeToCheck <= 0) + timeToFastcheck -= Time.deltaTime; + if (timeToFastcheck <= 0) { - if (SettingsManager.GetBool("FastCheck", false)) - { - gm.fastCheckCounters.SetActive(true); - timeToCheck = 2; - } - else - timeToCheck = 2; + bool fastCheckEnabled = SettingsManager.GetBool("FastCheck", false); + if (fastCheckEnabled) gm.fastCheckCounters.SetActive(true); + + timeToFastcheck = 2; } } else - timeToCheck = 2; + timeToFastcheck = 2; } + private bool ShouldGotosettings() + { + //читаем кнопки + bool settingButtonPressed = In.GetButton(ButtonPinMapping.secret) || Input.GetKey(KeyCode.F5); + + //считаем таймер + float sign = settingButtonPressed ? 1 : -1; + ElapsedSettinsPressedTime += Time.deltaTime * sign; + ElapsedSettinsPressedTime = Mathf.Clamp(ElapsedSettinsPressedTime, 0, GotoSettingsPressedTime); + + //Жали столько сколько надо для захода в меню + if (ElapsedSettinsPressedTime == GotoSettingsPressedTime) + { + ElapsedSettinsPressedTime = 0; + return true; + } + + return false; + } + private bool GamemodeChosen() + { + bool onePlayer = In.GetButtonDown(ButtonPinMapping.startOnePlayer); + bool twoPlayer = In.GetButtonDown(ButtonPinMapping.startTwoPlayers); + + if (onePlayer) gm.SetMode(GameMode.pve); + if (twoPlayer) gm.SetMode(GameMode.pvp); + + if (onePlayer || twoPlayer) + { + ElapsedPromoTimer = 0; + + gm.InitVictoryScales(); + SoundManager.instance.playChoose(); + subState = MenuSubStates.Payment; + return true; + } + + return false; + } + private void Payment() { + int creditsPrice = gm.gameMode == GameMode.pve ? PlayerPrefs.GetInt("PricePVE", 10) : PlayerPrefs.GetInt("PricePVP", 10); if (ComWrapper.Pay(creditsPrice)) {//оплата успешно - закрываем меню @@ -233,7 +242,6 @@ public class MenuState : IState {//не хватило монет - возвращаемся к выбору gm.OnNoMoney?.Invoke(); subState = MenuSubStates.Choosing; - restTimeToPromo = timeToPromo; } } @@ -243,6 +251,7 @@ public class MenuState : IState gm.menuOpened = true; animationEnded = false; + gm.StartCoroutine(closeMenuAnimation()); subState = MenuSubStates.SwitchState; } @@ -253,7 +262,6 @@ public class MenuState : IState gm.menuOpened = true; gm.StartCoroutine(openMenuAnimation()); subState = MenuSubStates.Choosing; - restTimeToPromo = timeToPromo; } void SwitchState() @@ -263,7 +271,6 @@ public class MenuState : IState if (subState == MenuSubStates.OpeningMenu) { subState = MenuSubStates.Choosing; - restTimeToPromo = timeToPromo; return; } else @@ -271,9 +278,9 @@ public class MenuState : IState gm.menuOpened = false; CharacterController.ResetState(); - gm.stateMachine.ChangeState(new StartRoundState(CellState.Player1));//из меню по любому первым ходит игрок + //при переходе из меню первым ходит игрок1 + gm.stateMachine.ChangeState(new StartRoundState(CellState.Player1)); } - } } @@ -318,7 +325,6 @@ public class MenuState : IState animationEnded = true; } - IEnumerator openMenuAnimation() { diff --git a/Assets/Scripts/GameFSM/SettingsState.cs b/Assets/Scripts/GameFSM/SettingsState.cs index 6ffc1a0..fa52111 100644 --- a/Assets/Scripts/GameFSM/SettingsState.cs +++ b/Assets/Scripts/GameFSM/SettingsState.cs @@ -1,43 +1,48 @@ -using System.Collections; -using System.Collections.Generic; -using TMPro; +//refactored 12.01.26 using UnityEngine; public class SettingsState : IState { - SettingsScreen settings; - float elapsedTime = 0; float timeToExit = 3f; + public void enter() { GameManager.instance.AdminPanel.SetActive(true); - settings = GameManager.instance.AdminPanel.GetComponent(); - //settings.Open(); + elapsedTime = 0; } public void exit() { - //settings.Close(); GameManager.instance.AdminPanel.SetActive(false); } public void update() { - if (In.GetButton(ButtonPinMapping.startOnePlayer) && In.GetButton(ButtonPinMapping.startTwoPlayers)) + if (ShouldExit()) + { + SoundManager.instance.playChoose(); + GameManager.instance.stateMachine.ChangeState(new MenuState()); + } + } + + private bool ShouldExit() + { + //опрашиваем кнопки + bool startButtonsPressed = In.GetButton(ButtonPinMapping.startOnePlayer) && In.GetButton(ButtonPinMapping.startTwoPlayers); + bool serviceButtonPressed = In.GetButton(ButtonPinMapping.secret) || Input.GetKey(KeyCode.F5); + bool exitPressed = startButtonsPressed || serviceButtonPressed; + + //считаем таймеры + if (exitPressed) elapsedTime += Time.deltaTime; - else + else elapsedTime -= Time.deltaTime; + //подгоняем прошедшее время к интервалу elapsedTime = Mathf.Clamp(elapsedTime, 0f, timeToExit); - - - - bool exitCondition = - In.GetButtonDown(ButtonPinMapping.secret) - || Input.GetKeyDown(KeyCode.F5) - || elapsedTime >= timeToExit; - if (exitCondition) GameManager.instance.stateMachine.ChangeState(new MenuState()); + //Если жали столько, сколько надо для выхода - надо выходить + return elapsedTime == timeToExit; } } diff --git a/Assets/Scripts/Inputs/ComSystem/ComWrapper.cs b/Assets/Scripts/Inputs/ComSystem/ComWrapper.cs index 613c569..4399ca0 100644 --- a/Assets/Scripts/Inputs/ComSystem/ComWrapper.cs +++ b/Assets/Scripts/Inputs/ComSystem/ComWrapper.cs @@ -296,7 +296,6 @@ public class ComWrapper : MonoBehaviour //ComNativeWrapper.Serial_Close(h); var ports = ComNativeWrapper.ListPorts(); - Debug.Log("Ports: " + string.Join(", ", ports)); if (ports.Length == 0) { Debug.LogError("Нет портов, завершаю"); return; } string port = ports[^1]; diff --git a/Assets/Scripts/Logger.cs b/Assets/Scripts/Logger.cs index e14f72c..3bd128a 100644 --- a/Assets/Scripts/Logger.cs +++ b/Assets/Scripts/Logger.cs @@ -12,12 +12,6 @@ public class Logger : MonoBehaviour { get { - //if (instance == null) - //{ - // GameObject loggerObject = new GameObject("Logger"); - // instance = loggerObject.AddComponent(); - // //DontDestroyOnLoad(loggerObject); - //} return instance; } } @@ -96,8 +90,6 @@ public class Logger : MonoBehaviour writer.Flush(); writer.Close(); writer = null; - - Debug.Log("Логгер закрыт."); } catch (Exception e) { diff --git a/Assets/Scripts/Statistics/PlayerStatsService.cs b/Assets/Scripts/Statistics/PlayerStatsService.cs index adf5e4d..6d69403 100644 --- a/Assets/Scripts/Statistics/PlayerStatsService.cs +++ b/Assets/Scripts/Statistics/PlayerStatsService.cs @@ -33,13 +33,7 @@ public class PlayerStatsService : IDisposable if (isNewDatabase) { InitialRecords(8); - Debug.Log("New database created with initial records"); } - else - { - Debug.Log("Existing database loaded"); - } - Debug.Log("PlayerStatsService initialized successfully"); } catch (Exception ex) {