示例#1
0
        /// <summary>
        /// Creates the panel object in-game and displays it.
        /// </summary>
        private static void Create(PrefabInfo selectedPrefab)
        {
            try
            {
                // If no instance already set, create one.
                if (uiGameObject == null)
                {
                    if (selectedPrefab is BuildingInfo)
                    {
                        // A building prefab is selected; create a BuildingInfo panel.
                        // Give it a unique name for easy finding with ModTools.
                        uiGameObject = new GameObject("BOBBuildingPanel");
                        uiGameObject.transform.parent = UIView.GetAView().transform;

                        panel = uiGameObject.AddComponent <BOBBuildingInfoPanel>();
                    }
                    else if (selectedPrefab is NetInfo)
                    {
                        // A network prefab is selected; create a NetInfo panel.
                        // Give it a unique name for easy finding with ModTools.
                        uiGameObject = new GameObject("BOBNetPanel");
                        uiGameObject.transform.parent = UIView.GetAView().transform;

                        panel = uiGameObject.AddComponent <BOBNetInfoPanel>();
                    }
                    else if (selectedPrefab is TreeInfo || selectedPrefab is PropInfo)
                    {
                        // A tree prefab is selected; create a TreeInfo panel.
                        // Give it a unique name for easy finding with ModTools.
                        uiGameObject = new GameObject("BOBMapPanel");
                        uiGameObject.transform.parent = UIView.GetAView().transform;
                        panel = uiGameObject.AddComponent <BOBMapInfoPanel>();
                    }
                    else
                    {
                        Logging.Message("unsupported prefab type ", selectedPrefab);
                        return;
                    }

                    // Set up panel with selected prefab.
                    Panel.transform.parent = uiGameObject.transform.parent;
                    Panel.SetTarget(selectedPrefab);
                }
            }
            catch (Exception e)
            {
                Logging.LogException(e, "exception creating InfoPanel");

                // Destroy the GameObjects rather than have a half-functional (at best) panel that confuses players.
                GameObject.Destroy(Panel);
                GameObject.Destroy(uiGameObject);
            }
        }
示例#2
0
        /// <summary>
        /// Creates the panel object in-game and displays it.
        /// </summary>
        internal static void Create(PrefabInfo selectedPrefab)
        {
            try
            {
                // If no instance already set, create one.
                if (uiGameObject == null)
                {
                    if (selectedPrefab is BuildingInfo)
                    {
                        // A building prefab is selected; create a BuildingInfo panel.
                        // Give it a unique name for easy finding with ModTools.
                        uiGameObject = new GameObject("BOBBuildingPanel");
                        uiGameObject.transform.parent = UIView.GetAView().transform;

                        panel = uiGameObject.AddComponent <BOBBuildingInfoPanel>();
                    }
                    else if (selectedPrefab is NetInfo)
                    {
                        // A network prefab is selected; create a NetInfo panel.
                        // Give it a unique name for easy finding with ModTools.
                        uiGameObject = new GameObject("BOBNetPanel");
                        uiGameObject.transform.parent = UIView.GetAView().transform;

                        panel = uiGameObject.AddComponent <BOBNetInfoPanel>();
                    }
                    else if (selectedPrefab is TreeInfo || selectedPrefab is PropInfo)
                    {
                        // A tree prefab is selected; create a TreeInfo panel.
                        // Give it a unique name for easy finding with ModTools.
                        uiGameObject = new GameObject("BOBMapPanel");
                        uiGameObject.transform.parent = UIView.GetAView().transform;

                        panel = uiGameObject.AddComponent <BOBMapInfoPanel>();
                    }
                    else
                    {
                        Logging.Message("unsupported prefab type ", selectedPrefab.ToString());
                        return;
                    }

                    // Set up panel with selected prefab.
                    Panel.Setup(uiGameObject.transform.parent, selectedPrefab);
                }
            }
            catch (Exception e)
            {
                Logging.LogException(e, "exception creating InfoPanel");
            }
        }
示例#3
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;
        }
示例#4
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>();
                }
            }
        }