Ejemplo n.º 1
0
        private void OnGUIAppLauncherReady()
        {
            if (applauncherButton == null)
            {
                ToolbarInfo tb = GetToolbarInfo();
                var         m  = new System.Collections.Generic.Dictionary <GameScenes, AppScenes>();
                m.Add(GameScenes.FLIGHT, AppScenes.FLIGHT);
                m.Add(GameScenes.EDITOR, AppScenes.SPH | AppScenes.VAB);
                m.Add(GameScenes.SPACECENTER, AppScenes.SPACECENTER);
                // and so on ...
                AppScenes v = AppScenes.NEVER;
                foreach (GameScenes s in tb.visibleInScenes)
                {
                    v |= m[s];
                }

                applauncherButton = KSP.UI.Screens.ApplicationLauncher.Instance.AddModApplication(
                    OnShowByToolbar,
                    OnHideByToolbar,
                    null,
                    null,
                    null,
                    null,
                    v,
                    (Texture)GameDatabase.Instance.GetTexture(tb.launcherTexture, false));
                if (visibleByToolbars)
                {
                    applauncherButton.SetTrue(false);
                }
            }
        }
Ejemplo n.º 2
0
        private void AddToolbarButton()
        {
            KSP.UI.Screens.ApplicationLauncher.AppScenes scenes =
                KSP.UI.Screens.ApplicationLauncher.AppScenes.FLIGHT
                | KSP.UI.Screens.ApplicationLauncher.AppScenes.MAPVIEW;

            if (!HighLogic.CurrentGame.Parameters.CustomParams <AntennaHelperSettings> ().enableInFlight)
            {
                scenes = KSP.UI.Screens.ApplicationLauncher.AppScenes.MAPVIEW;
            }
            if (!HighLogic.CurrentGame.Parameters.CustomParams <AntennaHelperSettings> ().enableInMapView)
            {
                scenes = KSP.UI.Screens.ApplicationLauncher.AppScenes.FLIGHT;
            }

            if (!toolbarButtonAdded)
            {
                toolbarController = gameObject.AddComponent <ToolbarControl> ();

                toolbarController.AddToAllToolbars(
                    ToolbarButtonOnTrue,
                    ToolbarButtonOnFalse,
                    scenes,
                    AHEditor.MODID,
                    "368879",
                    "AntennaHelper/Textures/icon_sat_on",
                    "AntennaHelper/Textures/icon_off",
                    "AntennaHelper/Textures/icon_dish_on_small",
                    "AntennaHelper/Textures/icon_dish_off_small",
                    Localizer.Format(AHEditor.MODNAME));

                toolbarButtonAdded = true;
            }
        }
Ejemplo n.º 3
0
        private void AddToolbarButton()
        {
            KSP.UI.Screens.ApplicationLauncher.AppScenes scenes =
                KSP.UI.Screens.ApplicationLauncher.AppScenes.FLIGHT
                | KSP.UI.Screens.ApplicationLauncher.AppScenes.MAPVIEW;

            if (!toolbarButtonAdded)
            {
                toolbarController = gameObject.AddComponent <ToolbarControl>();

                toolbarController.AddToAllToolbars(
                    ToolbarButtonOnTrue,
                    ToolbarButtonOnFalse,
                    scenes,
                    KerbalWx.MODID,
                    "368859",
                    "KerbalWeatherProject/Textures/KWP_minimal_large",
                    "KerbalWeatherProject/Textures/KWP_minimal_small",
                    Localizer.Format(KerbalWx.MODNAME));
                toolbarButtonAdded = true;
            }
        }
        public void Update()
        {
            // not the best way to avoid useless updates, but there are no relevant events
            if (modlist.Count == mods && !AdjustableModPanel.Instance.ForceUpdate)
            {
                return;
            }
            mods = modlist.Count;

            KSP.UI.UIListData <KSP.UI.UIListItem> myButton = null;

            AdjustableModPanel.Instance.StartRecordingMods();

            System.Collections.Generic.Dictionary <KSP.UI.Screens.ApplicationLauncherButton, uint> cashes =
                new System.Collections.Generic.Dictionary <KSP.UI.Screens.ApplicationLauncherButton, uint> ();

            foreach (var mod in modlist)
            {
                var button = mod.listItem.GetComponent <KSP.UI.Screens.ApplicationLauncherButton> ();
                if (AdjustableModPanel.Instance.IsAppButton(button))
                {
                    myButton = mod;
                }
                var texture = (Texture2D)button.sprite.texture;
                var func    = button.onTrue.GetInvocationList()[1];
                var method  = func.Method.Name;
                var module  = func.Method.Module.Name;
                if (module.EndsWith(".dll"))
                {
                    module = module.Substring(0, module.Length - 4);
                }

                if (AdjustableModPanel.Instance.IsButtonToolbarController(button, out string name, out string id))
                {
                    // button created by ToolbarControl needs special treatment
                    module = name;
                    method = id;
                }

                uint textureHash = 0;
                unchecked {
                    foreach (var byt in DuplicateTexture(texture).GetRawTextureData())
                    {
                        textureHash = textureHash * 8u + byt;
                    }
                }
                cashes[button] = textureHash;

                KSP.UI.Screens.ApplicationLauncher.AppScenes alwaysOn = KSP.UI.Screens.ApplicationLauncher.AppScenes.NEVER;

                if (button.container.Data is KSP.UI.Screens.ApplicationLauncher.AppScenes)
                {
                    alwaysOn = (KSP.UI.Screens.ApplicationLauncher.AppScenes)button.container.Data;
                    button.container.Data = null;
                }

                AdjustableModPanel.Instance.RecordMod(module, method, button.VisibleInScenes, textureHash, alwaysOn, texture);
            }

            AdjustableModPanel.Instance.EndRecordingMods();

            foreach (var mod in modlist)
            {
                var button = mod.listItem.GetComponent <KSP.UI.Screens.ApplicationLauncherButton> ();
                if (AdjustableModPanel.Instance.IsAppButton(button))
                {
                    myButton = mod;
                }
                var texture = (Texture2D)button.sprite.texture;
                var func    = button.onTrue.GetInvocationList()[1];
                var method  = func.Method.Name;
                var module  = func.Method.Module.Name;
                if (module.EndsWith(".dll"))
                {
                    module = module.Substring(0, module.Length - 4);
                }

                if (AdjustableModPanel.Instance.IsButtonToolbarController(button, out string name, out string id))
                {
                    // button created by ToolbarControl needs special treatment
                    module = name;
                    method = id;
                }

                button.VisibleInScenes = AdjustableModPanel.Instance.GetModScenes(module, method, button.VisibleInScenes, cashes[button]);
                // normally, this should be enough. But for some reason some mode buttons remain active,
                //even when they should not. So we change the button state explicitly.
                bool visible = KSP.UI.Screens.ApplicationLauncher.Instance.ShouldBeVisible(button);
                button.gameObject.SetActive(visible);

                if (visible && AdjustableModPanel.Instance.GetModPinned(module, method, button.VisibleInScenes, cashes[button]))
                {
                    // move to the top of the mod panel
                    mod.listItem.transform.SetAsFirstSibling();
                }
            }

            // our own button should always be the first
            myButton?.listItem.transform.SetAsFirstSibling();
        }