コード例 #1
0
        public void AddMainMenuButton()
        {
            // find main menu panel
            UIComponent mmUIComp = MainMenu.m_MainMenu;

            if (mmUIComp != null)
            {
                //DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Message, string.Format("found main menu UIComponent {0}", mmUIComp.GetType().FullName));

                UIButton loadGameButton = mmUIComp.Find <UIButton>("LoadGame");

                if (loadGameButton != null)
                {
                    // we don't want to clone or copy existing button, as it has event handlers we can't get rid of
                    UIButton newButton = UnityEngine.Object.Instantiate <UIButton>(loadGameButton);//mmUIComp.AddUIComponent<UIButton>(); //UnityEngine.Object.Instantiate<UIButton>(loadGameButton);
                    newButton.height = (adjustedLoadButtonHeight == 0f) ? loadGameButton.height / 2 : adjustedLoadButtonHeight;
                    newButton.width  = loadGameButton.width;

                    if (adjustedLoadButtonHeight == 0f)
                    {
                        // only do this once
                        loadGameButton.height    = loadGameButton.height / 2;
                        adjustedLoadButtonHeight = loadGameButton.height;
                    }

                    newButton.name           = "BetterLoadPanel";
                    newButton.cachedName     = "BetterLoadPanel";
                    newButton.stringUserData = "BetterLoadPanel";

                    newButton.transform.parent = mmUIComp.transform;
                    newButton.text             = string.Format("{0}++", Locale.Get(LocaleID.LOADGAME_TITLE)); // locale is subtly different than what game uses...
                    newButton.textColor        = new Color32(0xFF, 0, 0, 0xFF);
                    newButton.relativePosition = Vector3.zero;

                    newButton.transform.SetSiblingIndex(loadGameButton.transform.GetSiblingIndex());

                    // get rid of click handler that is hooked up as a result of cloning.  Note - probably not necessary, the issue was in the name and cachedname of the new button...
                    RemoveClickEvent(newButton);

                    PanelWrapper.eventVisibilityChanged += (component, visible) =>
                    {
                        if (visible)
                        {
                            PanelWrapper.Refresh(); //need to ensure up to date
                            PanelWrapper.Focus();
                        }
                    };

                    // hook up our click handler
                    newButton.eventClick += (component, param) => { PanelWrapper.Show(true); };

                    mmUIComp.PerformLayout();
                }
            }
        }
コード例 #2
0
        public void AddPauseMenuButton()
        {
            // find library pause menu
            //UIDynamicPanels.DynamicPanelInfo[] libpanels = UIView.library.m_DynamicPanels;

            //foreach (UIDynamicPanels.DynamicPanelInfo dpi in libpanels)
            //{
            //   DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Message, "panel: " + dpi.name);
            //}

            // create our panel now
            if (PanelWrapperForPauseMenu == null)
            {
                PanelWrapperForPauseMenu = (BetterLoadPanelWrapper)UIView.GetAView().AddUIComponent(typeof(BetterLoadPanelWrapper));

                PanelWrapperForPauseMenu.isVisible = false;
                PanelWrapperForPauseMenu.Initialize();
            }

            UIComponent pMenu = UIView.GetAView().FindUIComponent("Menu");

            //DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "uiview instanceid: " + pMenu.GetUIView().GetInstanceID().ToString());
            if (pMenu != null)
            {
                //DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Message, string.Format("found pause menu UIComponent {0}", pMenu.GetType().FullName));

                UIButton loadGameButton = pMenu.Find <UIButton>("LoadGame");

                if (loadGameButton != null)
                {
                    // we don't want to clone or copy existing button, as it has event handlers we can't get rid of
                    UIButton newButton = UnityEngine.Object.Instantiate <UIButton>(loadGameButton);//mmUIComp.AddUIComponent<UIButton>(); //UnityEngine.Object.Instantiate<UIButton>(loadGameButton);
                    newButton.height      = loadGameButton.height / 2;
                    newButton.width       = loadGameButton.width;
                    loadGameButton.height = loadGameButton.height / 2;
                    newButton.autoSize    = true;
                    //newButton.useGUILayout = true;

                    newButton.name           = "BetterLoadPanel2";
                    newButton.cachedName     = "BetterLoadPanel2";
                    newButton.stringUserData = "BetterLoadPanel2";

                    //pMenu.AttachUIComponent(newButton.gameObject);
                    newButton.transform.parent = loadGameButton.transform.parent.transform;

                    newButton.text                    = string.Format("{0}++", Locale.Get(LocaleID.LOADGAME_TITLE)); // locale is subtly different than what game uses...//loadGameButton.text);//
                    newButton.textColor               = new Color32(0xFF, 0, 0, 0xFF);
                    newButton.relativePosition        = Vector3.zero;
                    newButton.horizontalAlignment     = UIHorizontalAlignment.Center;
                    newButton.textHorizontalAlignment = UIHorizontalAlignment.Center;
                    newButton.verticalAlignment       = UIVerticalAlignment.Middle;
                    newButton.textVerticalAlignment   = UIVerticalAlignment.Middle;

                    newButton.transform.SetSiblingIndex(loadGameButton.transform.GetSiblingIndex());

                    // get rid of click handler that is hooked up as a result of cloning.  Note - probably not necessary, the issue was in the name and cachedname of the new button...
                    RemoveClickEvent(newButton);


                    // when hiding, pop modal that we pushed in eventClick handler
                    PanelWrapperForPauseMenu.eventVisibilityChanged += (component, visible) =>
                    {
                        if (visible)
                        {
                            PanelWrapperForPauseMenu.Refresh(); //need to ensure up to date
                            PanelWrapperForPauseMenu.Focus();
                        }
                    };

                    // hook up our click handler
                    newButton.eventClick += (component, param) =>
                    {
                        UIView.library.Hide(typeof(PauseMenu).Name);
                        PanelWrapperForPauseMenu.Show(true);
                    };
                }
            }
        }