Ejemplo n.º 1
0
        /// <summary>
        /// Our private little function to do whatever we need to un-setup and un-initialize our Gui screen object.
        /// </summary>
        private static void RemoveGui()
        {
            if (SomeModName.DEBUG_LOG_ON) Logger.dbgLog(" Removing Gui.");
            try
            {
                if (guiPanel != null)
                {
                    // I've seen some people try to clean up their gui objects with code like this.
                    // I could be wrong but it seem unneccessary in most cases, but I leave it as an example
                    // of something to do in 'removing' your gui object.
                    // Frankly it seems to me the game cleans these up for you anyway, but in theory doesn't
                    // hurt to do it yourself to maybe trigger garbage collection faster.
                    guiPanel.gameObject.SetActive(false);
                    GameObject.DestroyImmediate(guiPanel.gameObject);
                    guiPanel = null;
                    if (SomeModName.DEBUG_LOG_ON) Logger.dbgLog("Destroyed GUI objects.");
                }
            }
            catch (Exception ex)
            {
                Logger.dbgLog("Error: ",ex,true);
            }

            isGuiRunning = false;
            if (parentGuiView != null) { parentGuiView = null; } //destroy our reference to primary guiview
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Our private little function to do whatever we need to setup and initialize our Gui screen object.
        /// </summary>
        private static void SetupGui()
        {
            if (SomeModName.DEBUG_LOG_ON) Logger.dbgLog(" Setting up Gui panel.");
            try
            {
                parentGuiView = null; //make sure we start fresh, even though we could just assume that was set during the last map unload.
                parentGuiView = UIView.GetAView(); //go get the root screen\view object from Unity via Colosalframework.ui function.

                //if our object is null (it should be) then lets create one, have the game ADD it, and store it and set our isGUIrunning flag.
                if (guiPanel == null)
                {
                    guiPanel = (SomeModNameGUI)parentGuiView.AddUIComponent(typeof(SomeModNameGUI));
                    if (SomeModName.DEBUG_LOG_ON) Logger.dbgLog(" GUI Created.");
                }
                isGuiRunning = true;
            }
            catch (Exception ex)
            {
                Logger.dbgLog("Error: \r\n", ex,true);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets called upon the base UI component's creation. Basically it's the constructor...but not really.
        /// </summary>
        public override void Start()
        {
            base.Start();
            if (SomeModName.DEBUG_LOG_ON & SomeModName.DEBUG_LOG_LEVEL > 0) Logger.dbgLog(string.Concat("Attempting to create our display panel.  ",DateTime.Now.ToString(DTMilli).ToString()));
            this.size = new Vector2(WIDTH, HEIGHT);
            this.backgroundSprite = "MenuPanel";
            this.canFocus = true;
            this.isInteractive = true;
            this.BringToFront();
            this.relativePosition = new Vector3((Loader.parentGuiView.fixedWidth / 2) - 200, (Loader.parentGuiView.fixedHeight / 2) - 350);
            this.opacity = SomeModName.config.GuiOpacity;
            this.cachedName = cacheName;
            SomeModNameGUI.instance = this;
            CurrentMode = Singleton<ToolManager>.instance.m_properties.m_mode;

            //DragHandler
            m_DragHandler = this.AddUIComponent<UIDragHandle>();
            m_DragHandler.target = this;  //set the drag hangler target to this panel. it will do the rest magically.

            //Our Titlebar UILabel
            m_title = this.AddUIComponent<UILabel>();
            m_title.text = "Vehicle Cargo Data"; //spaces on purpose
            m_title.relativePosition = new Vector3(WIDTH / 2 - (m_title.width / 2) - 25f, (HEADER / 2) - (m_title.height / 2));
            m_title.textAlignment = UIHorizontalAlignment.Center;

            //Our Close Button UIButton
            m_closeButton = this.AddUIComponent<UIButton>();
            m_closeButton.normalBgSprite = "buttonclose";
            m_closeButton.hoveredBgSprite = "buttonclosehover";
            m_closeButton.pressedBgSprite = "buttonclosepressed";
            m_closeButton.relativePosition = new Vector3(WIDTH - 35, 5, 10);
            m_closeButton.eventClick += (component, eventParam) =>
            {
                this.Hide();
            };
            //^^above that's just an inline delegate to trigger hidding the panel when someone clicks the ' X ' (close) Button

            //What's our config say about Showing on map load?
            if (!SomeModName.config.AutoShowOnMapLoad)
            {
                this.Hide();
            }

            DoOnStartup(); //let go do some other stuff too during "start"
            if (SomeModName.DEBUG_LOG_ON) Logger.dbgLog(string.Concat("Display panel created. ",DateTime.Now.ToString(DTMilli).ToString()));
        }