コード例 #1
0
        /// <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);
        }