Ejemplo n.º 1
0
        /// <summary>
        /// Closes the panel by destroying the object (removing any ongoing UI overhead).
        /// </summary>
        internal static void Close()
        {
            // Stop highlighting.
            panel.CurrentTargetItem        = null;
            RenderOverlays.CurrentBuilding = null;

            // Revert overlay patches.
            Patcher.PatchBuildingOverlays(false);
            Patcher.PatchNetworkOverlays(false);
            Patcher.PatchMapOverlays(false);

            // Store previous position.
            lastX = Panel.relativePosition.x;
            lastY = Panel.relativePosition.y;

            // Destroy game objects.
            GameObject.Destroy(Panel);
            GameObject.Destroy(uiGameObject);

            // Let the garbage collector do its work (and also let us know that we've closed the object).
            panel        = null;
            uiGameObject = null;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Closes the panel by destroying the object (removing any ongoing UI overhead).
        /// </summary>
        /// <param name="resetTool">True to reset to default tool; false to leave current tool untouched (default true)</param>
        internal static void Close(bool resetTool = true)
        {
            // Check for null, just in case - this is also called by pressing Esc when BOB tool is active.
            if (panel != null)
            {
                // Perform any panel actions on close.
                panel.Close();

                // Stop highlighting.
                panel.CurrentTargetItem        = null;
                RenderOverlays.CurrentBuilding = null;

                // Revert overlay patches.
                Patcher.PatchBuildingOverlays(false);
                Patcher.PatchNetworkOverlays(false);
                Patcher.PatchMapOverlays(false);

                // Store previous position.
                lastX = Panel.relativePosition.x;
                lastY = Panel.relativePosition.y;

                // Destroy game objects.
                GameObject.Destroy(Panel);
                GameObject.Destroy(uiGameObject);

                // Let the garbage collector do its work (and also let us know that we've closed the object).
                panel        = null;
                uiGameObject = null;

                // Restore default tool if needed.
                if (resetTool)
                {
                    ToolsModifierControl.SetTool <DefaultTool>();
                }
            }
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the target prefab.
        /// </summary>
        /// <param name="targetPrefabInfo">Target prefab to set</param>
        internal override void SetTarget(PrefabInfo targetPrefabInfo)
        {
            // Don't do anything if invalid target, or target hasn't changed.
            if (!(targetPrefabInfo is BuildingInfo) || selectedPrefab == targetPrefabInfo)
            {
                return;
            }

            // Base setup.
            base.SetTarget(targetPrefabInfo);

            // Set target reference.
            currentBuilding = SelectedBuilding;

            // 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;
                SubBuildingNames    = new string[numChoices];
                subBuildings        = new BuildingInfo[numChoices];
                SubBuildingNames[0] = PrefabLists.GetDisplayName(currentBuilding);
                subBuildings[0]     = currentBuilding;

                object[] subBuildingIndexes = new object[numChoices];
                subBuildingIndexes[0] = 0;

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

                // Add sub-building menu, if it doesn't already exist.
                if (subBuildingPanel == null)
                {
                    subBuildingPanel = this.AddUIComponent <UIPanel>();

                    // Basic behaviour.
                    subBuildingPanel.autoLayout    = false;
                    subBuildingPanel.canFocus      = true;
                    subBuildingPanel.isInteractive = true;

                    // Appearance.
                    subBuildingPanel.backgroundSprite = "MenuPanel2";
                    subBuildingPanel.opacity          = PanelOpacity;

                    // Size and position.
                    subBuildingPanel.size             = new Vector2(200f, PanelHeight - TitleHeight);
                    subBuildingPanel.relativePosition = new Vector2(-205f, TitleHeight);

                    // Heading.
                    UILabel subTitleLabel = UIControls.AddLabel(subBuildingPanel, 5f, 5f, Translations.Translate("BOB_PNL_SUB"), 190f);
                    subTitleLabel.textAlignment    = UIHorizontalAlignment.Center;
                    subTitleLabel.relativePosition = new Vector2(5f, (TitleHeight - subTitleLabel.height) / 2f);

                    // List panel.
                    UIPanel subBuildingListPanel = subBuildingPanel.AddUIComponent <UIPanel>();
                    subBuildingListPanel.relativePosition = new Vector2(Margin, TitleHeight);
                    subBuildingListPanel.width            = subBuildingPanel.width - (Margin * 2f);
                    subBuildingListPanel.height           = subBuildingPanel.height - TitleHeight - (Margin * 2f);


                    subBuildingList = UIFastList.Create <UISubBuildingRow>(subBuildingListPanel);
                    ListSetup(subBuildingList);

                    // Create return fastlist from our filtered list.
                    subBuildingList.rowsData = new FastList <object>
                    {
                        m_buffer = subBuildingIndexes,
                        m_size   = subBuildingIndexes.Length
                    };
                }
                else
                {
                    // If the sub-building panel has already been created. just make sure it's visible.
                    subBuildingPanel.Show();
                }
            }
            else
            {
                // Otherwise, hide the sub-building panel (if it exists).
                subBuildingPanel?.Hide();
            }

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

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