예제 #1
0
        /// <summary>
        /// Performs initial setup
        /// </summary>
        /// <param name="parentTransform">Parent transform</param>
        /// <param name="targetPrefabInfo">Currently selected target prefab</param>
        internal override void Setup(Transform parentTransform, PrefabInfo targetPrefabInfo)
        {
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();

            // Set target reference.
            currentBuilding = targetPrefabInfo as BuildingInfo;

            // Base setup.
            base.Setup(parentTransform, targetPrefabInfo);

            Logging.Message("base setup time ", stopwatch.ElapsedMilliseconds.ToString());

            // Add group checkbox.
            indCheck = UIControls.LabelledCheckBox(this, 155f, TitleHeight + Margin, Translations.Translate("BOB_PNL_IND"), 12f, 0.7f);

            // Does this building have sub-buildings?
            if (currentBuilding.m_subBuildings != null && currentBuilding.m_subBuildings.Length > 0)
            {
                // Yes - create lists of sub-buildings (names and infos).
                int      numSubs          = currentBuilding.m_subBuildings.Length;
                int      numChoices       = numSubs + 1;
                string[] subBuildingNames = new string[numChoices];
                subBuildings        = new BuildingInfo[numChoices];
                subBuildingNames[0] = PrefabLists.GetDisplayName(currentBuilding.name);
                subBuildings[0]     = currentBuilding;

                for (int i = 0; i < numSubs; ++i)
                {
                    subBuildingNames[i + 1] = PrefabLists.GetDisplayName(currentBuilding.m_subBuildings[i].m_buildingInfo.name);
                    subBuildings[i + 1]     = currentBuilding.m_subBuildings[i].m_buildingInfo;
                }

                // Add sub-building menu.
                subBuildingMenu = UIControls.AddLabelledDropDown(this, 155f, indCheck.relativePosition.y + indCheck.height + (Margin / 2f), Translations.Translate("BOB_PNL_SUB"), 250f, 20f, 0.7f, 15, 4);
                subBuildingMenu.listBackground = "GenericPanelDark";
                subBuildingMenu.items          = subBuildingNames;
                subBuildingMenu.selectedIndex  = 0;

                // Sub-building menu event handler.
                subBuildingMenu.eventSelectedIndexChanged += (control, index) =>
                {
                    // Set current building.
                    currentBuilding = subBuildings[index];

                    // Reset current items.
                    CurrentTargetItem = null;
                    replacementPrefab = null;

                    // Reset loaded lists.
                    LoadedList();
                    TargetList();
                };
            }

            // Event handler for group checkbox.
            indCheck.eventCheckChanged += (control, isChecked) =>
            {
                // Rebuild target list.
                TargetList();

                // Clear selection.
                targetList.selectedIndex = -1;
                CurrentTargetItem        = null;

                // Store current group state as most recent state.
                ModSettings.lastInd = isChecked;

                // Toggle replace all button visibility.
                if (isChecked)
                {
                    replaceAllButton.Hide();
                }
                else
                {
                    replaceAllButton.Show();
                }
            };

            // Set grouped checkbox initial state according to preferences.
            switch (ModSettings.indDefault)
            {
            case 0:
                // Most recent state.
                indCheck.isChecked = ModSettings.lastInd;
                break;

            case 1:
                // Grouping off by default.
                indCheck.isChecked = false;
                break;

            case 2:
                // Grouping on by default.
                indCheck.isChecked = true;
                break;
            }

            // Populate target list and select target item.
            TargetList();

            Logging.Message("building setup time ", stopwatch.ElapsedMilliseconds.ToString());

            // Apply Harmony rendering patches.
            RenderOverlays.CurrentBuilding = selectedPrefab as BuildingInfo;
            Patcher.PatchBuildingOverlays(true);

            stopwatch.Stop();
            Logging.Message("Harmony patching time ", stopwatch.ElapsedMilliseconds.ToString());
        }