// Depending on where we are, we hop back to the previous option private void ReturnToPreviousOption() { if (prevIndexMenus.Count > 0) { ChangeSelectedText(currentMenuIndex, -1); DeactivateSubMenuItems(); switch (currentState) { case BattleMenuStates.ATTACK_TARGET: case BattleMenuStates.ITEM: case BattleMenuStates.SPECIAL: subCommandBox.gameObject.SetActive(false); currentMenuParent = battleUI.transform.GetChild(0); currentState = BattleMenuStates.MAIN; break; case BattleMenuStates.ITEM_TARGET: FillSubMenu(); currentState = BattleMenuStates.ITEM; break; case BattleMenuStates.SPECIAL_TARGET: FillSubMenu(battleController.GetCurrentCharacterInTurnOrder()); currentState = BattleMenuStates.SPECIAL; break; } int newIndex = prevIndexMenus.Pop(); ChangeSelectedText(currentMenuIndex, newIndex); currentMenuIndex = newIndex; } }
// This hides the main commands, the description box, and the sub box when called // This does NOT hide the action box public void HideMenus() { if (currentState != BattleMenuStates.INACTIVE) { ChangeSelectedText(currentMenuIndex, -1); commandBox.SetActive(false); descriptionBox.SetActive(false); subCommandBox.SetActive(false); currentState = BattleMenuStates.INACTIVE; } }
// This reenables the Command and Description box, resetting the state to the main user state public void ShowMenus() { if (currentState == BattleMenuStates.INACTIVE) { prevIndexMenus.Clear(); commandBox.SetActive(true); descriptionBox.SetActive(true); currentMenuParent = commandBox.transform; ChangeSelectedText(currentMenuIndex, 0); currentState = BattleMenuStates.MAIN; UpdateMenuContext(); DeactivateSubMenuItems(); } }
// Checks for the player input depending on the specific states private void Update() { if (currentState == BattleMenuStates.LEVEL_UP) { if (levelUpMenu.activeInHierarchy == false) { levelUpMenu.SetActive(true); } if (Input.GetButtonDown(selectInput)) { currentState = BattleMenuStates.LOADING; } } // If we are NOT hidden, we enact on the rest of the pause menu logic else if (currentState != BattleMenuStates.INACTIVE && currentState != BattleMenuStates.LOADING) { // Handles moving the player input up and down when the player is selecting an option if (Input.GetAxis(scrollInput) > 0f && currentMenuIndex > 0 && CheckIfOptionIsValid(currentMenuIndex - 1)) { // We delay the scroll so that it is easier to navigate the menus if (hasScrolled == false) { ChangeSelectedText(currentMenuIndex, currentMenuIndex - 1); currentMenuIndex--; UpdateMenuContext(); hasScrolled = true; Invoke("ResetScroll", scrollDelay); } } else if (Input.GetAxis(scrollInput) < 0f && currentMenuIndex + 1 < currentMenuParent.childCount && CheckIfOptionIsValid(currentMenuIndex + 1)) { // We delay the scroll so that it is easier to navigate the menus if (hasScrolled == false) { ChangeSelectedText(currentMenuIndex, currentMenuIndex + 1); currentMenuIndex++; UpdateMenuContext(); hasScrolled = true; Invoke("ResetScroll", scrollDelay); } } // Logic for selecting a field if (Input.GetButtonDown(selectInput)) { Debug.Log("We selected " + currentMenuParent.GetChild(currentMenuIndex).GetComponent <TextMeshProUGUI>().text); bool success = SelectOption(); if (success == true) { UpdateMenuContext(); } } // Logic for returning to the last selected item else if (Input.GetButtonDown(cancelInput)) { ReturnToPreviousOption(); UpdateMenuContext(); } } }
// Depending what state we are in, we handle how to handle the menu logic from here after selecting something // Returns true if we were able to get a successful option private bool SelectOption() { // We first check if we have any special cases before an option is selected. If we meet any, we exit out of the method early switch (currentState) { case BattleMenuStates.SPECIAL: if (battleController.GetCurrentCharacterInTurnOrder().CheckIfCanUseAttack(currentMenuIndex) == false) { // If we are selecting a special move, but we don't have enough sp, we prevent the player from using it descText.text = "Can't use that attack! Not enough SP!"; return(false); } break; } // Once we reach here, we will presume that the option will work // So we set up the next menus for the new context ChangeSelectedText(currentMenuIndex, -1); DeactivateSubMenuItems(); switch (currentState) { case BattleMenuStates.MAIN: // We make the sub menu visible subCommandBox.SetActive(true); currentMenuParent = subCommandBox.transform.GetChild(0).GetChild(0); // We then update the display if (currentMenuIndex == 0) { // We select the attack option FillEnemyTargetMenu(); currentState = BattleMenuStates.ATTACK_TARGET; } else if (currentMenuIndex == 1) { // We select the special option FillSubMenu(battleController.GetCurrentCharacterInTurnOrder()); currentState = BattleMenuStates.SPECIAL; } else { // We select the item option FillSubMenu(); currentState = BattleMenuStates.ITEM; } break; case BattleMenuStates.ATTACK_TARGET: // We have confirmed an action to attack HideMenus(); StartCoroutine(battleController.PerformAttackAction(prevIndexMenus.Peek(), battleController.GetSpecificEnemy(currentMenuIndex))); currentState = BattleMenuStates.INACTIVE; break; case BattleMenuStates.SPECIAL: // We have confirmed what special attack we want to do FillEnemyTargetMenu(); currentState = BattleMenuStates.SPECIAL_TARGET; break; case BattleMenuStates.SPECIAL_TARGET: // We have confirmed our target to hit our attack on HideMenus(); StartCoroutine(battleController.PerformAttackAction(prevIndexMenus.Peek(), battleController.GetSpecificEnemy(currentMenuIndex))); currentState = BattleMenuStates.INACTIVE; break; case BattleMenuStates.ITEM: // We confirmed what item to use FillPartyTargetMenu(); currentState = BattleMenuStates.ITEM_TARGET; break; case BattleMenuStates.ITEM_TARGET: // We have confirmed who to use the item on HideMenus(); StartCoroutine(battleController.PerformItemAction(playerInventory.GetItemAtIndex(prevIndexMenus.Peek()), battleController.GetSpecificPartyMember(currentMenuIndex))); currentState = BattleMenuStates.INACTIVE; break; } prevIndexMenus.Push(currentMenuIndex); currentMenuIndex = 0; ChangeSelectedText(currentMenuIndex, 0); return(true); }