示例#1
0
        void OnTrackingLoad()
        {
            if (!spaar.ModLoader.Configuration.DoesKeyExist("MovieMode"))
            {
                Configuration.SetBool("MovieMode", false);
            }

            MovieMode          = new spaar.ModLoader.SettingsButton();
            MovieMode.Text     = "Tracking C.\r\nMovie Mode";
            MovieMode.Value    = spaar.ModLoader.Configuration.GetBool("MovieMode", false);
            MovieMode.FontSize = 12;
            MovieMode.Create();
            MovieMode.OnToggle = OnMovieModeToggle;
            //spaar.ModLoader.SettingsMenu.RegisterSettingsButton("Tracking C.\r\nMovie Mode", GetMovieModeOn, spaar.ModLoader.Configuration.GetBool("MovieMode", false), 12);

            if (!spaar.ModLoader.Configuration.DoesKeyExist("LockingTimer"))
            {
                spaar.ModLoader.Configuration.SetFloat("LockingTimer", 4);
            }

            spaar.Commands.RegisterCommand("SetTrackingComputerMovieMode", (args, notUses) =>
            {
                if (!spaar.ModLoader.Configuration.DoesKeyExist("MovieMode"))
                {
                    spaar.ModLoader.Configuration.SetBool("MovieMode", true);
                }
                else
                {
                    spaar.ModLoader.Configuration.SetBool("MovieMode", !spaar.ModLoader.Configuration.GetBool("MovieMode", false));
                }
                spaar.ModLoader.Configuration.Save();
                MovieMode.Value = spaar.ModLoader.Configuration.GetBool("MovieMode", false);
                return("Complete! Now Movie Mode is " + spaar.ModLoader.Configuration.GetBool("MovieMode", false));
            }, "Set Tracking Computer for taking movies, thus ignore overload, target lost, cloak, and allow customized locking timer.");



            spaar.Commands.RegisterCommand("SetTrackingComputerLockingTimer", (args, notUses) =>
            {
                if (!spaar.ModLoader.Configuration.DoesKeyExist("LockingTimer"))
                {
                    spaar.ModLoader.Configuration.SetFloat("LockingTimer", 4);
                }
                float i = 0;
                if (float.TryParse(args[0], out i) && i >= 0)
                {
                    spaar.ModLoader.Configuration.SetFloat("LockingTimer", i);
                    spaar.ModLoader.Configuration.Save();
                    return("Complete! Now Locking need " + spaar.ModLoader.Configuration.GetFloat("LockingTimer", 4) + " seconds to lock.");
                }
                else
                {
                    return("Movie Mode is not ON or your input is incorrect! Your current locking timer is " + spaar.ModLoader.Configuration.GetFloat("LockingTimer", 4));
                }
            }, "Set Tracking Computer locking timer.");
            LoadBlock(TurretBlock);                      //加载该模块
            LoadBlock(CormacksModifiedTrackingComputer); //加载该模块
        }
        internal static void RegisterSettingsButton(SettingsButton button)
        {
            ToAdd.Add(button);

            if (Game.AddPiece != null)
            {
                RegisterSettingsButtonInternal(button);
            }
        }
        /// <summary>
        /// Registers a new toggle button. It will be placed below all others
        /// that are currently registered.
        /// </summary>
        /// <param name="text">The text to display on the button</param>
        /// <param name="cb">Callback to call when the button is clicked</param>
        /// <param name="defaultValue">Starting state of the toggle</param>
        /// <param name="fontSize">Font size of the text on the button</param>
        public static void RegisterSettingsButton(string text, SettingsToggle cb,
                                                  bool defaultValue = false, int fontSize = 0)
        {
            var button = new SettingsButton()
            {
                text         = text,
                cb           = cb,
                defaultValue = defaultValue,
                fontSize     = fontSize
            };

            toAdd.Add(button);

            if (Game.AddPiece != null)
            {
                RegisterSettingsButtonInternal(button);
            }
        }
        private static void RegisterSettingsButtonInternal(SettingsButton button)
        {
            var settingsObjects = GameObject.Find("Settings").transform
                                  .FindChild("SettingsObjects");
            var     bottomDefaultSetting = settingsObjects.FindChild("GOD/INFINITE AMMO");
            Vector3 SettingSize          = new Vector3(0.748f, 0.375f);

            if (modSection == null)
            {
                // Create a MODS section
                var settings = settingsObjects.FindChild("SETTINGS");

                var modsPos = settings.position;
                modsPos.y = bottomDefaultSetting.position.y - 1.2f;
                modsPos.z = 7.0f; // Prevent blocks GUI from being over the toggles

                modSection = (Transform)Instantiate(settings, modsPos,
                                                    settings.rotation);
                modSection.parent = settingsObjects;
                modSection.name   = "MOD SETTINGS";

                foreach (Transform child in modSection)
                {
                    if (child.name == "GENERAL")
                    {
                        child.GetComponent <TextMesh>().text = "M O D S";
                        child.name = "Title";
                    }
                    else
                    {
                        Destroy(child.gameObject);
                    }
                }

                // Adjust background to include mods section title
                var bg      = settingsObjects.FindChild("BG");
                var bgScale = bg.localScale;
                bgScale.y    += 2.85f;
                bg.localScale = bgScale;
                // Also need to remove background of infinite ammo as long as it's
                // the only thing in its row.
                Destroy(settingsObjects.FindChild("GOD/INFINITE AMMO/BG (1)").gameObject);

                bg.gameObject.AddComponent <BoxCollider>();
                var scrollCollider = new GameObject("Scrolling").transform;
                scrollCollider.parent           = settingsObjects;
                scrollCollider.rotation         = bg.rotation;
                scrollCollider.localScale       = bg.localScale;
                scrollCollider.gameObject.layer = bg.gameObject.layer;
                var pos = bg.position;
                pos.z = 15.0f; // Put collider behind all settings items
                scrollCollider.position = pos;
                scrollCollider.gameObject.AddComponent <ScrollSettingsMenu>()
                .settingsObjects = settingsObjects;
            }
            var settingPos = bottomDefaultSetting.position;

            settingPos.x += (numRegistered % 2) * SettingSize.x;
            settingPos.y -= 1.25f + (numRegistered / 2) * SettingSize.y;
            settingPos.z  = 7.0f; // Prevent blocks GUI from being over any toggles

            var fxaa = settingsObjects.FindChild("SETTINGS/FXAA");

            var newSetting = (Transform)Instantiate(fxaa, settingPos, fxaa.rotation);

            newSetting.parent = modSection;

            if (numRegistered % 2 == 0)
            {
                // Expand background to include new toggle
                var background      = settingsObjects.FindChild("BG");
                var backgroundScale = background.localScale;
                backgroundScale.y    += SettingSize.y * 2;
                background.localScale = backgroundScale;

                // Expand the scrolling object to the same size
                var scrolling = settingsObjects.FindChild("Scrolling");
                scrolling.localScale = backgroundScale;
                scrolling.GetComponent <ScrollSettingsMenu>().CalcBounds();

                // Check whether the new element row is outside of the screen
                // and enable scrolling if it is
                var lowestPoint = newSetting.position - SettingSize;
                var cam         = GameObject.Find("HUD Cam").GetComponent <Camera>();
                if (cam.WorldToViewportPoint(lowestPoint).y < 0.0f)
                {
                    scrolling.GetComponent <ScrollSettingsMenu>().scrollingEnabled = true;
                }
            }

            var newSettingButton = newSetting.FindChild("AA BUTTON");
            var newSettingText   = newSetting.FindChild("AA text");

            newSetting.gameObject.name       = button.text;
            newSettingButton.gameObject.name = button.text + " button";
            newSettingText.gameObject.name   = button.text + " text";
            var textMesh = newSettingText.gameObject.GetComponent <TextMesh>();

            textMesh.text     = button.text;
            textMesh.fontSize = button.fontSize;

            var settingsComponent
                = newSettingButton.gameObject.AddComponent <SettingsComponent>();

            var fxaaToggle = newSettingButton.gameObject.GetComponent <ToggleAA>();

            settingsComponent.darkMaterial = fxaaToggle.darkMaterial;
            settingsComponent.redMaterial  = fxaaToggle.redMaterial;
            Destroy(fxaaToggle);

            settingsComponent.SetCallback(button.cb);
            settingsComponent.SetOn(button.defaultValue);

            numRegistered++;
        }