Beispiel #1
0
 private static void SetVisibleTab_Prefix(uGUI_TabbedControlsPanel __instance, int tabIndex)
 {
     if (tabIndex != __instance.currentTab)
     {
         StorePos(__instance, __instance.currentTab);
     }
 }
Beispiel #2
0
        internal override void AddToPanel(uGUI_TabbedControlsPanel panel, int tabIndex)
        {
            // Add item
            OptionGameObject = panel.AddItem(tabIndex, panel.bindingOptionPrefab);

            // Update text
            Text text = OptionGameObject.GetComponentInChildren <Text>();

            if (text != null)
            {
                OptionGameObject.GetComponentInChildren <TranslationLiveUpdate>().translationKey = Label;
                text.text = Language.main.Get(Label);
            }

            // Create bindings
            uGUI_Bindings bindings = OptionGameObject.GetComponentInChildren <uGUI_Bindings>();
            uGUI_Binding  binding  = bindings.bindings[0];

            // Destroy secondary bindings
            int last = bindings.bindings.Length - 1;

            UnityEngine.Object.Destroy(bindings.bindings[last].gameObject);
            UnityEngine.Object.Destroy(bindings);

            // Update bindings
            binding.device = Device;
            binding.value  = KeyCodeUtils.KeyCodeToString(Key);
            binding.onValueChanged.RemoveAllListeners();
            var callback = new UnityAction <KeyCode>((KeyCode key) => parentOptions.OnKeybindChange(Id, key));

            binding.onValueChanged.AddListener(new UnityAction <string>((string s) => callback?.Invoke(KeyCodeUtils.StringToKeyCode(s))));

            base.AddToPanel(panel, tabIndex);
        }
Beispiel #3
0
 public static void Postfix(uGUI_TabbedControlsPanel __instance, int __result, string label)
 {
     if (label == modsLabel)
     {
         nullableModsTabIndex = __result;
     }
 }
Beispiel #4
0
            private static void StorePos(uGUI_TabbedControlsPanel panel, int tabIndex)
            {
                var scrollPos = panel is uGUI_DeveloperPanel? devMenuScrollPos: optionsScrollPos;

                if (tabIndex >= 0 && tabIndex < panel.tabs.Count)
                {
                    scrollPos[tabIndex] = panel.tabs[tabIndex].pane.GetComponent <ScrollRect>().verticalNormalizedPosition;
                }
            }
Beispiel #5
0
            private static void RestorePos(uGUI_TabbedControlsPanel panel, int tabIndex)
            {
                var scrollPos = panel is uGUI_DeveloperPanel? devMenuScrollPos: optionsScrollPos;

                if (tabIndex >= 0 && tabIndex < panel.tabs.Count && scrollPos.TryGetValue(tabIndex, out float pos))
                {
                    panel.tabs[tabIndex].pane.GetComponent <ScrollRect>().verticalNormalizedPosition = pos;
                }
            }
        internal void AddOptionsToPanel(uGUI_TabbedControlsPanel panel, int tabIndex)
        {
            panel.AddHeading(tabIndex, Name);

            _options = new Dictionary <string, ModOption>(); // we need to do this every time we adding options
            BuildModOptions();

            _options.Values.ForEach(option => option.AddToPanel(panel, tabIndex));
        }
        // adds UI GameObject to panel and updates OptionGameObject
        internal virtual void AddToPanel(uGUI_TabbedControlsPanel panel, int tabIndex)
        {
            if (isNeedAdjusting && AdjusterComponent != null)
            {
                OptionGameObject.AddComponent(AdjusterComponent);
            }

            parentOptions.OnGameObjectCreated(Id, OptionGameObject);
        }
        internal override void AddToPanel(uGUI_TabbedControlsPanel panel, int tabIndex)
        {
            var choice = panel.AddChoiceOption(tabIndex, Label, Options, Index,
                                               new UnityAction <int>((int index) => parentOptions.OnChoiceChange(Id, index, Options[index])));

            OptionGameObject = choice.transform.parent.transform.parent.gameObject; // :(

            base.AddToPanel(panel, tabIndex);
        }
        internal override void AddToPanel(uGUI_TabbedControlsPanel panel, int tabIndex)
        {
            var toggle = panel.AddToggleOption(tabIndex, Label, Value,
                                               new UnityAction <bool>((bool value) => parentOptions.OnToggleChange(Id, value)));

            OptionGameObject = toggle.transform.parent.gameObject;

            base.AddToPanel(panel, tabIndex);
        }
Beispiel #10
0
 private static void Postfix(uGUI_TabbedControlsPanel __instance, int tabIndex, string label, GameInput.Device device, GameInput.Button button)
 {
     if (button == GameInput.Button.Slot5 && device == GameInput.GetPrimaryDevice())
     {
         var qsc = __instance.gameObject.GetComponent <uGUI_QuickSlots_ConfigTab>();
         if (qsc != null)
         {
             qsc.SetControls();
         }
     }
 }
Beispiel #11
0
            private static void HighlightCurrentTab_Postfix(uGUI_TabbedControlsPanel __instance)
            {
                __instance.StartCoroutine(_restorePos());

                IEnumerator _restorePos()
                {
                    yield return(null);

                    RestorePos(__instance, __instance.currentTab);
                }
            }
Beispiel #12
0
 private static void Postfix(uGUI_TabbedControlsPanel __instance, string label, int __result)
 {
     if (label == "Keyboard" || label == "Controller")
     {
         if (__instance.gameObject.GetComponent <uGUI_QuickSlots_ConfigTab>() == null)
         {
             var tabConfig = __instance.gameObject.AddComponent <uGUI_QuickSlots_ConfigTab>();
             tabConfig.SetIndex(__result);
         }
     }
 }
Beispiel #13
0
        internal override void AddToPanel(uGUI_TabbedControlsPanel panel, int tabIndex)
        {
#if BELOWZERO
            UnityAction <float> callback = new UnityAction <float>((value) => parentOptions.OnSliderChange(Id, sliderValue?.ConvertToDisplayValue(value) ?? value));
#else
            UnityAction <float> callback = new UnityAction <float>((value) =>
            {
                value = sliderValue?.ConvertToDisplayValue(value) ?? value;
                if (value != previousValue)
                {
                    previousValue = value;
                    parentOptions.OnSliderChange(Id, value);
                }
            });
#endif

#if SUBNAUTICA
            panel.AddSliderOption(tabIndex, Label, Value, MinValue, MaxValue, DefaultValue, callback);
#elif BELOWZERO
            panel.AddSliderOption(tabIndex, Label, Value, MinValue, MaxValue, DefaultValue, Step, callback, SliderLabelMode.Default, "0.0");
#endif

            // AddSliderOption for some reason doesn't return created GameObject, so we need this little hack
            Transform options = panel.tabs[tabIndex].container.transform;
            OptionGameObject = options.GetChild(options.childCount - 1).gameObject; // last added game object

#if BELOWZERO
            // if we using custom value format, we need to replace vanilla uGUI_SliderWithLabel with our component
            if (ValueFormat != null)
            {
                OptionGameObject.transform.Find("Slider").gameObject.AddComponent <SliderValue>().ValueFormat = ValueFormat;
            }

            // fixing tooltip for slider
            OptionGameObject.transform.Find("Slider/Caption").GetComponent <Text>().raycastTarget = true;
#else
            // if we using custom value format or step, we need to replace vanilla uGUI_SliderWithLabel with our component
            if (ValueFormat != null || Step >= Mathf.Epsilon)
            {
                var sliderValue = OptionGameObject.transform.Find("Slider").gameObject.AddComponent <SliderValue>();
                sliderValue.Step = Step;
                if (ValueFormat != null)
                {
                    sliderValue.ValueFormat = ValueFormat;
                }
            }
#endif

            base.AddToPanel(panel, tabIndex);

            sliderValue = OptionGameObject.GetComponentInChildren <SliderValue>(); // we can also add custom SliderValue in OnGameObjectCreated event
        }
Beispiel #14
0
            public static void Prefix(uGUI_TabbedControlsPanel __instance, int tabIndex)
            {
                if (nullableModsTabIndex.HasValue)
                {
                    var modsTabIndex = nullableModsTabIndex.Value;

                    // If navigating from Mods tab...
                    if (__instance.currentTab == modsTabIndex && tabIndex != modsTabIndex)
                    {
                        Config.Save();
                    }
                }
            }
Beispiel #15
0
        internal override void AddToPanel(uGUI_TabbedControlsPanel panel, int tabIndex)
        {
            panel.AddSliderOption(tabIndex, Label, Value, MinValue, MaxValue, DefaultValue,
                                  new UnityAction <float>((float value) => parentOptions.OnSliderChange(Id, sliderValue?.ConvertToDisplayValue(value) ?? value)));

            // AddSliderOption for some reason doesn't return created GameObject, so we need this little hack
            Transform options = panel.tabs[tabIndex].container.transform;

            OptionGameObject = options.GetChild(options.childCount - 1).gameObject; // last added game object

            // if we using custom value format, we need to replace vanilla uGUI_SliderWithLabel with our component
            if (ValueFormat != null)
            {
                OptionGameObject.transform.Find("Slider").gameObject.AddComponent <SliderValue>().ValueFormat = ValueFormat;
            }

            base.AddToPanel(panel, tabIndex);

            sliderValue = OptionGameObject.GetComponentInChildren <SliderValue>(); // we can also add custom SliderValue in OnGameObjectCreated event
        }
        internal override void AddToPanel(uGUI_TabbedControlsPanel panel, int tabIndex)
        {
            // Add button to GUI
            Button componentInChildren = panel.AddItem(tabIndex, panel.buttonPrefab, Label).GetComponentInChildren <Button>();

            // Store a reference to parent object to simplify further modifications
            OptionGameObject = componentInChildren.transform.parent.gameObject;

            // Setup "on click" event
            componentInChildren.onClick.AddListener(new UnityAction(() =>
            {
                // Apply "deselected" style to button right after it is clicked
                componentInChildren.OnDeselect(null);
                // Propagate button click event to parent
                parentOptions.OnButtonClicked(Id);
            }));

            // Add button to panel
            base.AddToPanel(panel, tabIndex);
        }
Beispiel #17
0
        internal override void AddToPanel(uGUI_TabbedControlsPanel panel, int tabIndex)
        {
            // Add item
            OptionGameObject = panel.AddItem(tabIndex, panel.bindingOptionPrefab);

            // Update text
            Text text = OptionGameObject.GetComponentInChildren <Text>();

            if (text != null)
            {
                OptionGameObject.GetComponentInChildren <TranslationLiveUpdate>().translationKey = Label;
                text.text = Language.main.Get(Label);
            }

            // Create bindings
            uGUI_Bindings bindings = OptionGameObject.GetComponentInChildren <uGUI_Bindings>();
            uGUI_Binding  binding  = bindings.bindings[0];

            // Destroy secondary bindings
            int last = bindings.bindings.Length - 1;

            UnityEngine.Object.Destroy(bindings.bindings[last].gameObject);
            UnityEngine.Object.Destroy(bindings);

            // Update bindings
            binding.device = Device;
            binding.value  = KeyCodeUtils.KeyCodeToString(Key);
#if SUBNAUTICA
            binding.onValueChanged.RemoveAllListeners();
            var callback = new UnityAction <KeyCode>((KeyCode key) => parentOptions.OnKeybindChange(Id, key));
            binding.onValueChanged.AddListener(new UnityAction <string>((string s) => callback?.Invoke(KeyCodeUtils.StringToKeyCode(s))));
#elif BELOWZERO
            binding.action     = ButtonPatcher.EnsureButton(Label, KeyCodeUtils.KeyCodeToString(Key), Device);
            binding.bindingSet = GameInput.BindingSet.Primary;
            var callback = new UnityAction <KeyCode>((KeyCode key) => parentOptions.OnKeybindChange(Id, key));
            binding.bindCallback = new Action <GameInput.Device, GameInput.Button, GameInput.BindingSet, string>((GameInput.Device device, GameInput.Button button, GameInput.BindingSet bindingSet, string s) => { callback?.Invoke(KeyCodeUtils.StringToKeyCode(s)); panel.TryBind1_0(device, button, bindingSet, s); binding.RefreshValue(); });
#endif

            base.AddToPanel(panel, tabIndex);
        }
Beispiel #18
0
 private static void RemoveTabs_Prefix(uGUI_TabbedControlsPanel __instance)
 {
     StorePos(__instance, __instance.currentTab);
 }
Beispiel #19
0
 private static void SetVisibleTab_Postfix(uGUI_TabbedControlsPanel __instance, int tabIndex)
 {
     RestorePos(__instance, tabIndex);
 }
        public void ConfigOptions_GameObjectCreated(object sender, GameObjectCreatedEventArgs e)
        {
            GameObject go = e.GameObject;

            if (e.Id == "OpenDecorationsModConfigurator" && go != null)
            {
                uGUI_TabbedControlsPanel tcp = null;
                try { tcp = go.transform.parent.parent.parent.parent.parent.GetComponent <uGUI_TabbedControlsPanel>(); }
                catch { tcp = null; }
                if (tcp != null)
                {
                    ICollection tabs = _tabsField.GetValue(tcp) as ICollection;
                    if (tabs != null)
                    {
                        IEnumerator enumerator = tabs.GetEnumerator();
                        if (enumerator != null)
                        {
                            int i = 0;
                            // Iterate through each panel tabs
                            while (enumerator.MoveNext())
                            {
                                object     currentTab = enumerator.Current;
                                GameObject pane       = (GameObject)_paneField.GetValue(currentTab);
                                GameObject tab        = (GameObject)_tabField.GetValue(currentTab);
                                OpenConfiguratorBtnContainer = (RectTransform)_containerField.GetValue(currentTab);
                                if (pane != null && tab != null && OpenConfiguratorBtnContainer != null)
                                {
                                    Text paneText = pane.GetComponentInChildren <Text>();
                                    Text tabText  = tab.GetComponentInChildren <Text>();
                                    // If current panel is "QModManager" and current tab is "Mods"
                                    if (paneText != null && string.Compare(paneText.text, "QModManager", false, CultureInfo.InvariantCulture) == 0 &&
                                        tabText != null && string.Compare(tabText.text, "Mods", false, CultureInfo.InvariantCulture) == 0)
                                    {
                                        // Detroy toggle
                                        GameObject.DestroyImmediate(go);
                                        // Add button
                                        tcp.AddButton(i, LanguageHelper.GetFriendlyWord("Config_OpenDecorationsModConfigurator"), new UnityEngine.Events.UnityAction(() => {
                                            ConfigSwitcher.OpenDecorationsModConfigurator = !ConfigSwitcher.OpenDecorationsModConfigurator;
                                            // If button state changed
                                            if (ConfigSwitcher.OpenConfiguratorLastState != ConfigSwitcher.OpenDecorationsModConfigurator)
                                            {
                                                // Update button state
                                                ConfigSwitcher.OpenConfiguratorLastState = ConfigSwitcher.OpenDecorationsModConfigurator;
                                                // Open configurator
                                                string configuratorPath = ConfiguratorPath();
                                                if (File.Exists(configuratorPath))
                                                {
                                                    // Try launch configurator
                                                    try { Configurator = Process.Start(new ProcessStartInfo {
                                                            Arguments = "/C \"" + configuratorPath + "\"", FileName = "cmd", WindowStyle = ProcessWindowStyle.Hidden
                                                        }); }
                                                    catch (Exception ex)
                                                    {
                                                        // Cleanup any running instance on failure
                                                        if (Configurator != null)
                                                        {
                                                            if (!Configurator.HasExited)
                                                            {
                                                                try { Configurator.CloseMainWindow(); }
                                                                catch { }
                                                            }
                                                            try { Configurator.Close(); }
                                                            catch { }
                                                        }
                                                        // Log error
                                                        Logger.Log("ERROR: Unable to open configurator. Exception=[" + ex.ToString() + "]");
                                                    }
                                                }
                                                // Apply "deselected" style to button
                                                foreach (Transform tr in OpenConfiguratorBtnContainer)
                                                {
                                                    // If current transform is GUI button
                                                    if (tr != null && !string.IsNullOrEmpty(tr.name) && tr.name.StartsWith("uGUI_OptionButton"))
                                                    {
                                                        Text btnText = tr.GetComponentInChildren <Text>();
                                                        if (btnText != null && !string.IsNullOrEmpty(btnText.text) &&
                                                            (string.Compare(btnText.text, "Cliquez ici pour configurer", true, CultureInfo.InvariantCulture) == 0 ||
                                                             string.Compare(btnText.text, "Haga clic aquí para configurar", true, CultureInfo.InvariantCulture) == 0 ||
                                                             string.Compare(btnText.text, "Yapılandırmak için burayı tıklayın", true, CultureInfo.InvariantCulture) == 0 ||
                                                             string.Compare(btnText.text, "Klicken Sie hier zum Konfigurieren", true, CultureInfo.InvariantCulture) == 0 ||
                                                             string.Compare(btnText.text, "Нажмите здесь, чтобы настроить", true, CultureInfo.InvariantCulture) == 0 ||
                                                             string.Compare(btnText.text, "Click here to configure", true, CultureInfo.InvariantCulture) == 0))
                                                        {
                                                            // Deselect button
                                                            Button btn = tr.GetComponentInChildren <Button>();
                                                            if (btn != null)
                                                            {
                                                                btn.OnDeselect(null);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }));
                                        break;
                                    }
                                }
                                ++i;
                            }
                        }
                    }
                }
            }
        }