Exemplo n.º 1
0
        private static void RegisterOptionsToggleInternal(OptionsButton button)
        {
            if (optionsList == null)
            {
                GameObject.Find("O P T I O N S")
                .GetComponent <EnableObjOnClick>().OnMouseUp();
                optionsList = GameObject.Find("OPTIONS LIST").transform;
            }

            if (numRegistered == 0)
            {
                // Move Windowed setting up to make room
                windowedText = optionsList.FindChild("WINDOWED");
                windowedText.Translate(0f, 1.3f, 0f);
                windowedTickBox = optionsList.FindChild("WINDOWED TICK BOX");
                windowedTickBox.Translate(0f, 1.3f, 0f);
            }

            var textPos = windowedText.position
                          + Vector3.down * 0.45f * (numRegistered + 1);
            var textScale = windowedText.localScale;
            var boxPos    = windowedTickBox.position
                            + Vector3.down * 0.45f * (numRegistered + 1);
            var boxScale = windowedTickBox.localScale;

            var newText = (Transform)Instantiate(windowedText, textPos,
                                                 Quaternion.identity);
            var newBox = (Transform)Instantiate(windowedTickBox, boxPos,
                                                Quaternion.identity);

            newText.parent = optionsList;
            newBox.parent  = optionsList;

            newText.name = button.text + " (Modded)";
            newBox.name  = button.text + "TickBox (Modded)";

            newText.localScale = textScale;
            newBox.localScale  = boxScale;

            newText.GetComponent <TextMesh>().text = button.text;
            if (button.fontSize != 0)
            {
                newText.GetComponent <TextMesh>().fontSize = button.fontSize;
            }

            var fullscreenController = newBox.GetComponent <FullScreenController>();
            var optionsComponent     = newBox.gameObject.AddComponent <OptionsComponent>();

            optionsComponent.darkMaterial = fullscreenController.darkMaterial;
            optionsComponent.redMaterial  = fullscreenController.redMaterial;
            Destroy(fullscreenController);

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

            numRegistered++;

            optionsList.FindChild("QUIT WINDOW ICON")
            .GetComponent <DisableObjOnClick>().OnMouseUp();
        }
Exemplo n.º 2
0
        internal static void RegisterOptionsToggle(OptionsButton button)
        {
            ToAdd.Add(button);

            if (SceneManager.GetActiveScene().buildIndex == 1) // Main Menu
            {
                RegisterOptionsToggleInternal(button);
            }
        }
Exemplo n.º 3
0
        /// <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 RegisterOptionsToggle(string text, OptionsToggle cb,
                                                 bool defaultValue = false, int fontSize = 0)
        {
            var button = new OptionsButton()
            {
                text         = text,
                cb           = cb,
                defaultValue = defaultValue,
                fontSize     = fontSize
            };

            toAdd.Add(button);

            if (Application.loadedLevel == 2)
            {
                RegisterOptionsToggleInternal(button);
            }
        }
Exemplo n.º 4
0
        public static void RegisterOptionsToggle(string text, OptionsToggle cb,
                                                 bool defaultValue = false, int fontSize = 0)
        {
            var button = new OptionsButton
            {
                Text     = text,
                OnToggle = cb,
                Value    = defaultValue,
                FontSize = fontSize
            };

            ToAdd.Add(button);

            if (SceneManager.GetActiveScene().buildIndex == 1) // Main Menu
            {
                RegisterOptionsToggleInternal(button);
            }
        }
Exemplo n.º 5
0
        private static void RegisterOptionsToggleInternal(OptionsButton button)
        {
            if (_optionsList == null)
            {
                GameObject.Find("O P T I O N S")
                .GetComponent <EnableObjOnClick>().OnMouseUp();
                _optionsList = GameObject.Find("OPTIONS LIST").transform;
            }

            if (_numRegistered == 0)
            {
                // Move Windowed setting up to make room
                _windowedText = _optionsList.FindChild("WINDOWED");
                _windowedText.Translate(0f, 1.3f, 0f);
                _windowedTickBox = _optionsList.FindChild("WINDOWED TICK BOX");
                _windowedTickBox.Translate(0f, 1.3f, 0f);
            }

            var textPos = _windowedText.position
                          + Vector3.down * 0.45f * (_numRegistered + 1);
            var textScale = _windowedText.localScale;
            var boxPos    = _windowedTickBox.position
                            + Vector3.down * 0.45f * (_numRegistered + 1);
            var boxScale = _windowedTickBox.localScale;

            var newText = (Transform)Instantiate(_windowedText, textPos,
                                                 Quaternion.identity);
            var newBox = (Transform)Instantiate(_windowedTickBox, boxPos,
                                                Quaternion.identity);

            newText.parent = _optionsList;
            newBox.parent  = _optionsList;

            newText.name = button.Text + " (Modded)";
            newBox.name  = button.Text + "TickBox (Modded)";

            newText.localScale = textScale;
            newBox.localScale  = boxScale;

            newText.GetComponent <TextMesh>().text = button.Text;
            if (button.FontSize != 0)
            {
                newText.GetComponent <TextMesh>().fontSize = button.FontSize;
            }

            var fullscreenController = newBox.GetComponent <FullScreenController>();
            var optionsComponent     = newBox.gameObject.AddComponent <OptionsComponent>();

            optionsComponent.darkMaterial = fullscreenController.darkMaterial;
            optionsComponent.redMaterial  = fullscreenController.redMaterial;
            Destroy(fullscreenController);

            optionsComponent.SetCallback(button.OnToggle);
            optionsComponent.SetOn(button.Value);

            // Change material on button OnToggle
            button.OnToggle += value => optionsComponent.SetOn(value);

            // Change textMesh on Text property change
            button.OnTextChange += value => newText.GetComponent <TextMesh>().text = value;

            // Change font size on FontSize property change
            button.OnFontSizeChange += value => newText.GetComponent <TextMesh>().fontSize = value;

            // Set button OnDestroy method
            button.OnDestroy += () =>
            {
                Destroy(newText.gameObject);
                Destroy(newBox.gameObject);
                _numRegistered--;
            };

            _numRegistered++;

            _optionsList.FindChild("QUIT WINDOW ICON")
            .GetComponent <DisableObjOnClick>().OnMouseUp();
        }