示例#1
0
    /// <summary>
    /// Key was pressed in new game menu
    /// </summary>
    /// <param name="keyPressed">Key pressed.</param>
    public IEnumerator GamePanelKeypress(string keyPressed)
    {
        if (keyPressed.Equals("up"))
        {
            selectedItem--;

            // for now, the item is just 0
            if (selectedItem < 0)
            {
                // set the selected item at the end
                // right now, we have 2 save files
                selectedItem = saveFilesItems.Length - 1;
            }



            saveFilesItems [selectedItem].Select();
        }
        else if (keyPressed.Equals("down"))
        {
            selectedItem++;

            if (selectedItem >= saveFilesItems.Length)
            {
                selectedItem = 0;
            }

            saveFilesItems [selectedItem].Select();
        }
        else if (keyPressed.Equals("forward"))
        {
            if (currentState == MENU_STATES.NEW_GAME)
            {
                // if we have a sting source, play sting
                if (stingPlayer != null)
                {
                    stingPlayer.playSelectItemSound();
                }

                WaitingForTime pauseItem = gameObject.AddComponent <WaitingForTime> ();
                ScreenFader    sf        = GameObject.FindGameObjectWithTag("Fader").GetComponent <ScreenFader>();

                StartCoroutine(sf.FadeToBlack());
                yield return(StartCoroutine(pauseItem.WaitForTime(0.9f)));

                // just overwrite the game here - we'll later on want to do a confirm if we have
                // a legitimate game at this location
                // for now, just overwrite.
                NewGame newGame = new NewGame(selectedItem);
                newGame.CreateNewGame();
            }
            else if (currentState == MENU_STATES.LOAD && SaveLoad.savedGames [selectedItem] != null)
            {
                // if we have a sting source, play sting
                if (stingPlayer != null)
                {
                    stingPlayer.playLoadGameSound();
                }

                // load game here
                SaveLoad.Load(selectedItem);

                WaitingForTime pauseItem = gameObject.AddComponent <WaitingForTime> ();
                ScreenFader    sf        = GameObject.FindGameObjectWithTag("Fader").GetComponent <ScreenFader>();

                StartCoroutine(sf.FadeToBlack());
                yield return(StartCoroutine(pauseItem.WaitForTime(0.9f)));

                // toolbox scene
                SceneManager.LoadScene("LoadingScene");
            }
            else if (currentState == MENU_STATES.LOAD && SaveLoad.savedGames [selectedItem] == null)
            {
                // display tiny error message briefly?
                // if we have a sting source, play sting
                if (stingPlayer != null)
                {
                    stingPlayer.playBackButtonSound();
                }
            }
        }
        else if (keyPressed.Equals("back"))
        {
            ShowMainMenu();
        }
    }
示例#2
0
    // if selection made and we are in battle, we want to update and wait for input until we receive
    // and new updates from our new class of battle


    /// <summary>
    /// Initialize this instance.
    /// </summary>
    public IEnumerator Initialize()
    {
        selectionMade = false;
        isActive      = true;
        hasAccepted   = false;

        if (GUIdisplayItems == null)
        {
            GUIdisplayItems = GameObject.FindGameObjectWithTag("GameTools").GetComponent <GUIDisplayItems>();
        }


        // we need to be careful with this - because some menus won't have this few
        // indices. We need to remove the hardcoding for this. What if a menu has more
        // options here?
        if (indexSelected <= 0 || indexSelected >= 4)
        {
            indexSelected = 0;
        }


        if (optionsBox == null)
        {
            yield return(null);
        }


        optionsBox.AddComponent <WaitingForTime> ();
        waitingObject = optionsBox.GetComponent <WaitingForTime> ();


        // wait for input if we are dealing with a pause menu - might want to replace
        // this with a flag
        if (menuType != "PauseMenu")
        {
            yield return(StartCoroutine(waitingObject.PauseBeforeInput()));
        }


        // check and see which item is highlighted here before we enter and make that
        // our indexselected
        for (var i = 0; i < menuOptions.Count; i++)
        {
            // if the item is highlighted, set our value to that
            // set i to max
            Button currentButton = optionsBox.transform.GetChild(i).gameObject.GetComponent <Button>();
            currentButton.interactable = true;

            if (i == 0 && indexSelected <= 0)
            {
                currentButton.Select();
            }
            else if (i == indexSelected)
            {
                currentButton.Select();
            }
        }


        // until we have made a selection and while we still have an options box,
        // wait for input
        while (selectionMade == false && optionsBox.activeInHierarchy)
        {
            yield return(StartCoroutine(waitingObject.WaitForKeyDown()));

            if (EventSystem.current.currentSelectedGameObject == null)
            {
                // if we have no more object
                if (optionsBox.activeInHierarchy == false)
                {
                    yield return(null);
                }
                else if (indexSelected >= 0 && indexSelected <= menuOptions.Count - 1)
                {
                    optionsBox.GetComponentsInChildren <Button> () [indexSelected].Select();
                }
                else
                {
                    optionsBox.GetComponentsInChildren <Button> () [0].Select();
                }
            }



            // if we haven't made a selection yet -
            if (!selectionMade && isActive == true && Input.anyKeyDown)
            {
                if (!isHorizontal)
                {
                    if (Input.GetKeyDown(KeyCode.DownArrow) == true)
                    {
                        incrementIndex();
                    }

                    /// INPUT KEY DOWN : MOVE DOWN THE LIST
                    if (Input.GetKeyDown(KeyCode.UpArrow) == true)
                    {
                        decrementIndex();
                    }
                }
                else
                {
                    // if we are on a horizontal menu, right should go right
                    if (Input.GetKeyDown(KeyCode.RightArrow) == true)
                    {
                        incrementIndex();
                    }

                    // if we are on a horizontal menu, left should go left
                    else if (Input.GetKeyDown(KeyCode.LeftArrow) == true)
                    {
                        decrementIndex();
                    }
                }

                if (Input.GetKeyDown(KeyCode.Return))
                {
                    selectionMade = true;

                    // play selection made sting if possible
                    if (menuType == "PauseMenu" && stingPlayer != null)
                    {
                        stingPlayer.playSelectItemSound();
                    }


                    yield return(StartCoroutine(ButtonClicked(menuOptions [indexSelected])));
                }

                if (Input.GetKeyDown(KeyCode.X))
                {
                    selectionMade = true;

                    // play selection made sting if possible
                    if (menuType == "PauseMenu" && stingPlayer != null)
                    {
                        stingPlayer.playSelectItemSound();
                    }

                    yield return(StartCoroutine(ButtonClicked(menuOptions [indexSelected])));
                }
            }
        }
    }