Ejemplo n.º 1
0
    /// <summary>
    /// When one of our menu buttons is clicked, we go here to deal with the command issued
    /// </summary>
    /// <param name="buttonCommand">Button command.</param>
    public IEnumerator ButtonClicked(Options buttonCommand)
    {
        isActive = false;
        Destroy(waitingObject);

        if (selectionMade)
        {
            /// what type of options list do we have? conversation or more main menu?
            if (menuType == "conversation")
            {
                if (buttonCommand.command == "exit")
                {
                    yield break;
                }
                else if (buttonCommand.command == "accept")
                {
                    hasAccepted = true;
                    yield break;
                }

                Commands command = new Commands();
                command.resolveConversationCommands(buttonCommand);
            }

            // if we have a main menu, we can send those commands over to commands as well
            // and just run our functions for that.
            else if (menuType == "PauseMenu")
            {
                Commands command = new Commands();
                command.resolvePauseMenuCommands(buttonCommand);
                // what is our command?
            }
            else if (menuType == "BattleMenu")
            {
                // yield on starting a new
                // add targetpicker to this player character, and then use that
                // to get the list of players from his battlemenu? who has the list of
                // units to attack?
                // player -> battle menu -> all combatants shoved into player -> add component -> targetpicker
                TargetPicker playerTargetPicker = attackingPlayer.GetOrAddComponent <TargetPicker>();
                playerTargetPicker.currentPlayer = attackingPlayer;
                playerTargetPicker.battleList    = attackingPlayer.GetComponent <BattleMenu> ().allCombatants;
                playerTargetPicker.loadBattle();


                // disable button presses
                // 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 = false;
                }

                // now that we've loaded the battle, we want to do an enumerator that waits
                // for an input from our user. Either we get a "back up" with a null, or we get
                // a character to attack (for now let's just assume it will be an enemy)
                yield return(StartCoroutine(playerTargetPicker.selectTarget()));


                while (!playerTargetPicker.hasChosenTarget)
                {
                    yield return(null);
                }



                if (playerTargetPicker.chosenTarget == null)
                {
                    Destroy(playerTargetPicker);

                    // if we get a null, make the buttons live again and we'll try again?
                    // disable button presses
                    // check and see which item is highlighted here before we enter and make that
                    // our indexselected
                    // 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();
                        }
                    }

                    selectionMade = false;
                    isActive      = true;

                    yield break;
                }


                // get our command object
                Commands command = new Commands();

                GameObject targetObject = playerTargetPicker.chosenTarget.gameObject;
                command.setAttackingPlayer(attackingPlayer);
                if (targetObject.GetComponent <PlayerUnit> () != null)
                {
                    command.setPlayerBeingBuffed(targetObject.GetComponent <PlayerUnit> ());
                }
                if (targetObject.GetComponent <EnemyUnit> ())
                {
                    command.setEnemyUnderAttack(targetObject.GetComponent <EnemyUnit>());
                }

                Destroy(playerTargetPicker);

                // let's resolve our battle commands
                buttonCommand.playerToAlter = "Player";
                command.resolveBattleCommands(buttonCommand);
            }
        }

        yield return(new WaitForSeconds(0.01f));
    }