/// <summary>
        /// Display a GUI that shows all of the available carpet bombing hexes available
        /// </summary>
        public static void DisplayCarpetBombingHexesAvailable()
        {
            Canvas bombingCanvas = new Canvas();
            Button tempOKButton;
            int    widthSeed  = 6; // Just to make the development easier since position is based on width
            int    heightSeed = GlobalDefinitions.hexesAttackedLastTurn.Count + 2;

            float panelWidth  = widthSeed * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE;
            float panelHeight = heightSeed * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE;

            // The avaialble carpet bombing hexes are stored in the hexesAttackedLastTurn list.  All non valid
            // hexes were removed already (i.e. hexes attacked last turn but do not have Germans on them this turn)
            GUIRoutines.CreateGUICanvas("CarpetBombingGUI",
                                        panelWidth,
                                        panelHeight,
                                        ref bombingCanvas);

            for (int index = 0; index < GlobalDefinitions.hexesAttackedLastTurn.Count; index++)
            {
                Toggle tempToggle;
                Button tempLocateButton;

                GUIRoutines.CreateUIText("Carpet bombing available - you may select a hex", "CarpetBombingAvailableText",
                                         widthSeed * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                         GlobalDefinitions.GUIUNITIMAGESIZE,
                                         (widthSeed * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE) / 2 - 0.5f * panelWidth,
                                         heightSeed * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                         Color.white, bombingCanvas);

                for (int index2 = 0; index2 < GlobalDefinitions.hexesAttackedLastTurn[index].GetComponent <HexDatabaseFields>().occupyingUnit.Count; index2++)
                {
                    GUIRoutines.CreateUnitImage(GlobalDefinitions.hexesAttackedLastTurn[index].GetComponent <HexDatabaseFields>().occupyingUnit[index2], "UnitImage",
                                                index2 * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE + GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth,
                                                (index + 1) * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE + 0.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                bombingCanvas);
                }

                tempLocateButton = GUIRoutines.CreateButton("BombingLocateButton" + index, "Locate",
                                                            3 * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE + GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth,
                                                            (index + 1) * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE + 0.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                            bombingCanvas);
                tempLocateButton.gameObject.AddComponent <CarpetBombingToggleRoutines>();
                tempLocateButton.GetComponent <CarpetBombingToggleRoutines>().hex = GlobalDefinitions.hexesAttackedLastTurn[index];
                tempLocateButton.onClick.AddListener(tempLocateButton.GetComponent <CarpetBombingToggleRoutines>().LocateCarpetBombingHex);
                tempToggle = GUIRoutines.CreateToggle("BombingToggle" + index,
                                                      4 * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE + GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth,
                                                      (index + 1) * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE + 0.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                      bombingCanvas).GetComponent <Toggle>();
                tempToggle.gameObject.AddComponent <CarpetBombingToggleRoutines>();
                tempToggle.GetComponent <CarpetBombingToggleRoutines>().hex = GlobalDefinitions.hexesAttackedLastTurn[index];
                tempToggle.GetComponent <Toggle>().onValueChanged.AddListener((bool value) => tempToggle.GetComponent <CarpetBombingToggleRoutines>().SelectHex());
            }
            tempOKButton = GUIRoutines.CreateButton("BombingOKButton", "OK",
                                                    widthSeed * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE / 2 - 0.5f * panelWidth,
                                                    0.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                    bombingCanvas);
            tempOKButton.gameObject.AddComponent <CarpetBombingOKRoutines>();
            tempOKButton.onClick.AddListener(tempOKButton.GetComponent <CarpetBombingOKRoutines>().CarpetBombingOK);
        }
        /// <summary>
        /// Routine pulls up a list of the invasion areas for the user to select from.
        /// </summary>
        /// <returns></returns>
        public void SelectInvasionArea()
        {
            GlobalDefinitions.WriteToLogFile("selectInvasionArea: executing");
            Canvas invasionAreaSelectionCanvasInstance = new Canvas();

            float panelWidth  = 3 * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE;
            float panelHeight = 9 * GlobalDefinitions.GUIUNITIMAGESIZE;

            GlobalDefinitions.invasionAreaSelectionGUIInstance = GUIRoutines.CreateGUICanvas("InvasionAreaSelectionGUIInstance",
                                                                                             panelWidth,
                                                                                             panelHeight,
                                                                                             ref invasionAreaSelectionCanvasInstance, 0.16f, 0.16f);
            GlobalDefinitions.invasionAreaSelectionGUIInstance.GetComponent <RectTransform>().anchorMin = new Vector2(0.16f, 0.5f);

            GUIRoutines.CreateUIText("Select invasion area", "InvasionAreaSelectionText",
                                     (3) * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     1 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     1.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth,
                                     (8) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                     Color.white,
                                     invasionAreaSelectionCanvasInstance, 0.16f, 0.16f, 0.5f, 0.5f);
            for (int index = 0; index < 7; index++)
            {
                Toggle tempToggle;
                GUIRoutines.CreateUIText(GlobalDefinitions.invasionAreas[index].name,
                                         "InvasionAreaSelectionText",
                                         2 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                         GlobalDefinitions.GUIUNITIMAGESIZE,
                                         GlobalDefinitions.GUIUNITIMAGESIZE * 1.25f - 0.5f * panelWidth,
                                         (index + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                         Color.white,
                                         invasionAreaSelectionCanvasInstance, 0.16f, 0.16f, 0.5f, 0.5f);
                tempToggle = GUIRoutines.CreateToggle("InvasionAreaSelectionToggle" + index,
                                                      2 * 1.25f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth,
                                                      (index + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                      invasionAreaSelectionCanvasInstance, 0.16f, 0.16f, 0.5f, 0.5f).GetComponent <Toggle>();
                tempToggle.gameObject.AddComponent <InvasionSelectionToggleRoutines>();
                tempToggle.GetComponent <InvasionSelectionToggleRoutines>().index = index;
                tempToggle.onValueChanged.AddListener((bool value) => tempToggle.GetComponent <InvasionSelectionToggleRoutines>().InvadedAreaSelected());
            }
        }
예제 #3
0
        public void UpdateSettings()
        {
            // Turn the button off so that it can't pull up more of the same window
            GameObject.Find("SettingsButton").GetComponent <Button>().interactable = false;

            Slider agressivenessSlider;
            Slider diffiultySlider;
            Button cancelButton;
            Button okButton;
            Canvas settingCanvas = new Canvas();
            //GameObject settingCanvasGameObject = new GameObject("settingCanvasGameObject");

            float panelWidth  = 10 * GlobalDefinitions.GUIUNITIMAGESIZE;
            float panelHeight = 7 * GlobalDefinitions.GUIUNITIMAGESIZE;

            // Turn off any guis that are on
            if (GUIRoutines.guiList.Count > 0)
            {
                foreach (GameObject gui in GUIRoutines.guiList)
                {
                    gui.SetActive(false);
                }
            }

            //settingCanvasGameObject = GUIRoutines.CreateGUICanvas("SettingsGUIInstance",
            GUIRoutines.CreateGUICanvas("SettingsGUIInstance",
                                        panelWidth,
                                        panelHeight,
                                        ref settingCanvas);

            GUIRoutines.CreateUIText("Settings", "SettingsText",
                                     2 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     GlobalDefinitions.GUIUNITIMAGESIZE,
                                     0,
                                     3f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     Color.white, settingCanvas);

            agressivenessSlider = GUIRoutines.CreateSlider("AgressivenessSlider", "GUI Slider15",
                                                           0,
                                                           2f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                           settingCanvas);
            agressivenessSlider.value = GlobalDefinitions.aggressiveSetting;
            agressivenessSlider.onValueChanged.AddListener(delegate { UpdateAggressivenessSettingText(agressivenessSlider.value); });

            GUIRoutines.CreateUIText("Aggressive", "AggressiveText",
                                     3 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     GlobalDefinitions.GUIUNITIMAGESIZE,
                                     3f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     2f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     Color.white, settingCanvas);

            GUIRoutines.CreateUIText("Defensive", "DefensiveText",
                                     3 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     GlobalDefinitions.GUIUNITIMAGESIZE,
                                     -3f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     2f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     Color.white, settingCanvas);

            GlobalDefinitions.aggressivenessSettingText = GUIRoutines.CreateUIText(Convert.ToString(agressivenessSlider.value), "AggressivenessSettingText",
                                                                                   2 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                                                   GlobalDefinitions.GUIUNITIMAGESIZE,
                                                                                   0,
                                                                                   1.5f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                                                   Color.white, settingCanvas);

            GUIRoutines.CreateUIText("Computer Aggressiveness", "ComputerAggressivenessText",
                                     3 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     GlobalDefinitions.GUIUNITIMAGESIZE,
                                     0,
                                     1f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     Color.white, settingCanvas);

            diffiultySlider = GUIRoutines.CreateSlider("DifficultySlider", "GUI Slider010",
                                                       0,
                                                       0,
                                                       settingCanvas);
            diffiultySlider.value = GlobalDefinitions.difficultySetting;
            diffiultySlider.onValueChanged.AddListener(delegate { UpdateDifficultySettingText(diffiultySlider.value); });

            GUIRoutines.CreateUIText("Harder", "HarderText",
                                     3 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     GlobalDefinitions.GUIUNITIMAGESIZE,
                                     3f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     0,
                                     Color.white, settingCanvas);

            GUIRoutines.CreateUIText("Easier", "EasierText",
                                     3 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     GlobalDefinitions.GUIUNITIMAGESIZE,
                                     -3f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     0,
                                     Color.white, settingCanvas);

            GlobalDefinitions.difficultySettingText = GUIRoutines.CreateUIText(Convert.ToString(diffiultySlider.value), "DifficultySettingText",
                                                                               2 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                                               GlobalDefinitions.GUIUNITIMAGESIZE,
                                                                               0,
                                                                               -0.5f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                                               Color.white, settingCanvas);

            GUIRoutines.CreateUIText("Game Difficulty", "GameDifficultyText",
                                     2 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     GlobalDefinitions.GUIUNITIMAGESIZE,
                                     0,
                                     -1f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     Color.white, settingCanvas);

            okButton = GUIRoutines.CreateButton("settingOKButton", "OK",
                                                -1f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                -3f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                settingCanvas);
            okButton.gameObject.AddComponent <SettingGUIButtons>();
            okButton.onClick.AddListener(okButton.GetComponent <SettingGUIButtons>().OkSelected);

            cancelButton = GUIRoutines.CreateButton("settingCancelButton", "Cancel",
                                                    1f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                    -3f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                    settingCanvas);
            cancelButton.gameObject.AddComponent <SettingGUIButtons>();
            cancelButton.onClick.AddListener(cancelButton.GetComponent <SettingGUIButtons>().CancelSelected);
        }
        /// <summary>
        /// This routine is what pulls up the GUI to assign units to a single combat
        /// </summary>
        /// <param name="singleCombat"></param>
        public void CallCombatDisplay(GameObject singleCombat)
        {
            Button okButton;
            Button cancelButton;
            Canvas combatCanvas = new Canvas();

            // I'm going to unhighight all the units potentially involved in this attack.  When selected for inclusion in the attack they
            // will be highlighted.  I will restore the must-attack and must-be-attacked highlighting when leaving the gui

            foreach (GameObject unit in singleCombat.GetComponent <Combat>().defendingUnits)
            {
                GlobalDefinitions.UnhighlightUnit(unit);
            }
            foreach (GameObject unit in singleCombat.GetComponent <Combat>().attackingUnits)
            {
                GlobalDefinitions.UnhighlightUnit(unit);
            }

            // The panel needs to be at least the width for four units to fit everything
            int maxUnits = 5;

            if (singleCombat.GetComponent <Combat>().defendingUnits.Count > maxUnits)
            {
                maxUnits = singleCombat.GetComponent <Combat>().defendingUnits.Count;
            }
            if (singleCombat.GetComponent <Combat>().attackingUnits.Count > maxUnits)
            {
                maxUnits = singleCombat.GetComponent <Combat>().attackingUnits.Count;
            }
            float panelWidth  = (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE;
            float panelHeight = 7 * GlobalDefinitions.GUIUNITIMAGESIZE;

            GlobalDefinitions.combatGUIInstance = GUIRoutines.CreateGUICanvas("CombatGUIInstance",
                                                                              panelWidth,
                                                                              panelHeight,
                                                                              ref combatCanvas);

            GUIRoutines.CreateUIText("Combat Odds", "OddsText",
                                     3 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     GlobalDefinitions.GUIUNITIMAGESIZE,
                                     (0.5f * (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE) - 0.5f * panelWidth,
                                     6.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                     Color.white, combatCanvas);

            float xSeperation = (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE / maxUnits;
            float xOffset     = xSeperation / 2;

            for (int index = 0; index < singleCombat.GetComponent <Combat>().defendingUnits.Count; index++)
            {
                Toggle tempToggle;
                tempToggle = GUIRoutines.CreateUnitTogglePair("unitToggleDefendingPair" + index,
                                                              index * xSeperation + xOffset - 0.5f * panelWidth,
                                                              5.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                              combatCanvas,
                                                              singleCombat.GetComponent <Combat>().defendingUnits[index]);
                tempToggle.gameObject.AddComponent <CombatToggleRoutines>();
                tempToggle.gameObject.GetComponent <CombatToggleRoutines>().currentCombat     = singleCombat;
                tempToggle.gameObject.GetComponent <CombatToggleRoutines>().unit              = singleCombat.GetComponent <Combat>().defendingUnits[index];
                tempToggle.gameObject.GetComponent <CombatToggleRoutines>().attackingUnitFlag = false;
                tempToggle.onValueChanged.AddListener((bool value) => tempToggle.GetComponent <CombatToggleRoutines>().AddOrDeleteSelectedUnit());

                if (CheckForInvasionDefense(singleCombat.GetComponent <Combat>().defendingUnits[index], singleCombat))
                {
                    // This executes if the defender is on an invasion hex of at least one of the attackers.  If it is the toggle will be set and there are checks in the toggle routines from allowing
                    // it to be turned off.  If the defenders are being invaded they can't be attacked separately.
                    tempToggle.isOn         = true;
                    tempToggle.interactable = false;
                }
            }

            for (int index = 0; index < singleCombat.GetComponent <Combat>().attackingUnits.Count; index++)
            {
                Toggle tempToggle;
                tempToggle = GUIRoutines.CreateUnitTogglePair("unitToggleAttackingPair" + index,
                                                              index * xSeperation + xOffset - 0.5f * panelWidth,
                                                              3.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                              combatCanvas,
                                                              singleCombat.GetComponent <Combat>().attackingUnits[index]);
                tempToggle.gameObject.AddComponent <CombatToggleRoutines>();
                tempToggle.gameObject.GetComponent <CombatToggleRoutines>().currentCombat     = singleCombat;
                tempToggle.gameObject.GetComponent <CombatToggleRoutines>().unit              = singleCombat.GetComponent <Combat>().attackingUnits[index];
                tempToggle.gameObject.GetComponent <CombatToggleRoutines>().attackingUnitFlag = true;
                tempToggle.onValueChanged.AddListener((bool value) => tempToggle.GetComponent <CombatToggleRoutines>().AddOrDeleteSelectedUnit());

                if (CheckForInvadingAttacker(singleCombat.GetComponent <Combat>().attackingUnits[index]))
                {
                    // This executes if the attacker is invading this turn. The unit will be selected and the toggle routines will not allow it to be turned off
                    tempToggle.isOn         = true;
                    tempToggle.interactable = false;
                }
            }

            GlobalDefinitions.combatAirSupportToggle    = null;
            GlobalDefinitions.combatCarpetBombingToggle = null;
            // If there are air missions left present the user with the option of adding air support to the attack
            if (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality == GlobalDefinitions.Nationality.Allied)
            {
                Toggle airToggle;
                airToggle = GUIRoutines.CreateToggle("CombatAirSupportToggle",
                                                     0.5f * (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth - 2 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                     1.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                     combatCanvas).GetComponent <Toggle>();
                GlobalDefinitions.combatAirSupportToggle = airToggle.gameObject;
                airToggle.gameObject.AddComponent <CombatToggleRoutines>();
                airToggle.gameObject.GetComponent <CombatToggleRoutines>().currentCombat = singleCombat;
                airToggle.onValueChanged.AddListener((bool value) => airToggle.GetComponent <CombatToggleRoutines>().ToggleAirSupport());
                if (GlobalDefinitions.tacticalAirMissionsThisTurn <= GlobalDefinitions.maxNumberOfTacticalAirMissions)
                {
                    airToggle.GetComponent <Toggle>().interactable = true;
                }
                else
                {
                    airToggle.GetComponent <Toggle>().interactable = false;
                }

                GUIRoutines.CreateUIText("Air Support", "CombatAirSupportText",
                                         1 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                         1 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                         0.5f * (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth - 1 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                         1.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                         Color.white, combatCanvas);

                Toggle carpetToggle;
                carpetToggle = GUIRoutines.CreateToggle("CombatCarpetBombingToggle",
                                                        0.5f * (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth + 1 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                        1.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                        combatCanvas).GetComponent <Toggle>();
                GlobalDefinitions.combatCarpetBombingToggle = carpetToggle.gameObject;
                carpetToggle.gameObject.AddComponent <CombatToggleRoutines>();
                carpetToggle.gameObject.GetComponent <CombatToggleRoutines>().currentCombat = singleCombat;
                carpetToggle.onValueChanged.AddListener((bool value) => carpetToggle.GetComponent <CombatToggleRoutines>().ToggleCarpetBombing());
                if (CheckIfCarpetBombingIsAvailable(singleCombat))
                {
                    carpetToggle.GetComponent <Toggle>().interactable = true;
                }
                else
                {
                    carpetToggle.GetComponent <Toggle>().interactable = false;
                }

                GUIRoutines.CreateUIText("Carpet Bombing", "CarpetBombingSupportText",
                                         1.5f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                         1 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                         0.5f * (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth + 2 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                         1.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                         Color.white, combatCanvas);
            }

            // OK button
            okButton = GUIRoutines.CreateButton("combatOKButton", "OK",
                                                0.5f * (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth - 0.5f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                0.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                combatCanvas);
            okButton.gameObject.AddComponent <CombatGUIOK>();
            okButton.gameObject.GetComponent <CombatGUIOK>().singleCombat = singleCombat;
            okButton.onClick.AddListener(okButton.GetComponent <CombatGUIOK>().OkCombatGUISelection);

            // Cancel button
            cancelButton = GUIRoutines.CreateButton("combatCancelButton", "Cancel",
                                                    0.5f * (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth + 0.5f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                    0.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                    combatCanvas);
            cancelButton.gameObject.AddComponent <CombatGUIOK>();
            cancelButton.gameObject.GetComponent <CombatGUIOK>().singleCombat = singleCombat;
            cancelButton.onClick.AddListener(cancelButton.GetComponent <CombatGUIOK>().CancelCombatGUISelection);
        }
예제 #5
0
        /// <summary>
        /// Pulls up a gui for the user to select the type of game mode
        /// </summary>
        public static void GetGameModeUI()
        {
            Button     okButton;
            GameObject tempText;

            // Set the localControl to true in order to enable the buttons and toggles
            GlobalDefinitions.localControl = true;

            float  panelWidth        = 6 * GlobalDefinitions.GUIUNITIMAGESIZE;
            float  panelHeight       = 5 * GlobalDefinitions.GUIUNITIMAGESIZE;
            Canvas getGameModeCanvas = new Canvas();

            GUIRoutines.CreateGUICanvas("GameModeCanvas",
                                        panelWidth,
                                        panelHeight,
                                        ref getGameModeCanvas);

            // This gui has two columns, selection toggles and desription
            tempText = GUIRoutines.CreateUIText("Select", "gameModeSelectText",
                                                GlobalDefinitions.GUIUNITIMAGESIZE,
                                                GlobalDefinitions.GUIUNITIMAGESIZE,
                                                GlobalDefinitions.GUIUNITIMAGESIZE * 1 - (0.5f * panelWidth),
                                                panelHeight - 0.5f * GlobalDefinitions.GUIUNITIMAGESIZE - (0.5f * panelHeight),
                                                Color.white, getGameModeCanvas);
            tempText.GetComponent <TextMeshProUGUI>().alignment = TextAlignmentOptions.MidlineLeft;

            tempText = GUIRoutines.CreateUIText("Game Mode", "gameModeDescriptionText",
                                                4 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                GlobalDefinitions.GUIUNITIMAGESIZE,
                                                GlobalDefinitions.GUIUNITIMAGESIZE * 4 - (0.5f * panelWidth),
                                                panelHeight - 0.5f * GlobalDefinitions.GUIUNITIMAGESIZE - (0.5f * panelHeight),
                                                Color.white, getGameModeCanvas);
            tempText.GetComponent <TextMeshProUGUI>().alignment = TextAlignmentOptions.MidlineLeft;

            // Now list the three game modes
            hotseatToggle = GUIRoutines.CreateToggle("hostseatToggle",
                                                     GlobalDefinitions.GUIUNITIMAGESIZE * 1 - (0.5f * panelWidth),
                                                     panelHeight - 1.5f * GlobalDefinitions.GUIUNITIMAGESIZE - (0.5f * panelHeight),
                                                     getGameModeCanvas);

            tempText = GUIRoutines.CreateUIText("Hot-seat", "hotseatDescriptionText",
                                                4 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                GlobalDefinitions.GUIUNITIMAGESIZE,
                                                GlobalDefinitions.GUIUNITIMAGESIZE * 4 - (0.5f * panelWidth),
                                                panelHeight - 1.5f * GlobalDefinitions.GUIUNITIMAGESIZE - (0.5f * panelHeight),
                                                Color.white, getGameModeCanvas);
            tempText.GetComponent <TextMeshProUGUI>().alignment = TextAlignmentOptions.MidlineLeft;
            hotseatToggle.gameObject.AddComponent <GameModeSelectionButtonRoutines>();
            hotseatToggle.GetComponent <Toggle>().onValueChanged.AddListener((bool value) => hotseatToggle.gameObject.GetComponent <GameModeSelectionButtonRoutines>().ToggleChange());

            AIToggle = GUIRoutines.CreateToggle("AIToggle",
                                                GlobalDefinitions.GUIUNITIMAGESIZE * 1 - (0.5f * panelWidth),
                                                panelHeight - 2.5f * GlobalDefinitions.GUIUNITIMAGESIZE - (0.5f * panelHeight),
                                                getGameModeCanvas);

            tempText = GUIRoutines.CreateUIText("Play against Computer", "AIDescriptionText",
                                                4 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                GlobalDefinitions.GUIUNITIMAGESIZE,
                                                GlobalDefinitions.GUIUNITIMAGESIZE * 4 - (0.5f * panelWidth),
                                                panelHeight - 2.5f * GlobalDefinitions.GUIUNITIMAGESIZE - (0.5f * panelHeight),
                                                Color.white, getGameModeCanvas);
            tempText.GetComponent <TextMeshProUGUI>().alignment = TextAlignmentOptions.MidlineLeft;
            AIToggle.gameObject.AddComponent <GameModeSelectionButtonRoutines>();
            AIToggle.GetComponent <Toggle>().onValueChanged.AddListener((bool value) => AIToggle.gameObject.GetComponent <GameModeSelectionButtonRoutines>().ToggleChange());

            peerToPeerNetworkToggle = GUIRoutines.CreateToggle("PeerToPeerNetworkToggle",
                                                               GlobalDefinitions.GUIUNITIMAGESIZE * 1 - (0.5f * panelWidth),
                                                               panelHeight - 3.5f * GlobalDefinitions.GUIUNITIMAGESIZE - (0.5f * panelHeight),
                                                               getGameModeCanvas);
            tempText = GUIRoutines.CreateUIText("Peer to Peer network play", "PeerToPeerNetworkDescriptionText",
                                                4 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                GlobalDefinitions.GUIUNITIMAGESIZE,
                                                GlobalDefinitions.GUIUNITIMAGESIZE * 4 - (0.5f * panelWidth),
                                                panelHeight - 3.5f * GlobalDefinitions.GUIUNITIMAGESIZE - (0.5f * panelHeight),
                                                Color.white, getGameModeCanvas);
            tempText.GetComponent <TextMeshProUGUI>().alignment = TextAlignmentOptions.MidlineLeft;
            peerToPeerNetworkToggle.gameObject.AddComponent <GameModeSelectionButtonRoutines>();
            peerToPeerNetworkToggle.GetComponent <Toggle>().onValueChanged.AddListener((bool value) => peerToPeerNetworkToggle.gameObject.GetComponent <GameModeSelectionButtonRoutines>().ToggleChange());

            // Add an OK button
            okButton = GUIRoutines.CreateButton("getGameModeOKButton", "OK",
                                                GlobalDefinitions.GUIUNITIMAGESIZE * 3 - (0.5f * panelWidth),
                                                panelHeight - 4.5f * GlobalDefinitions.GUIUNITIMAGESIZE - (0.5f * panelHeight),
                                                getGameModeCanvas);
            okButton.gameObject.AddComponent <GameModeSelectionButtonRoutines>();
            okButton.onClick.AddListener(okButton.GetComponent <GameModeSelectionButtonRoutines>().OkGameMode);
        }