Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        internal static GameObject AddBindingOptionWithCallback(uGUI_OptionsPanel panel, int tab, string label, KeyCode key, GameInput.Device device, UnityAction <KeyCode> callback)
        {
            // Add item
            GameObject gameObject = panel.AddItem(tab, panel.bindingOptionPrefab);

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

            if (text != null)
            {
                gameObject.GetComponentInChildren <TranslationLiveUpdate>().translationKey = label;
                text.text = Language.main.Get(label);
                //text.text = label;
            }

            // Create bindings
            uGUI_Bindings bindings = gameObject.GetComponentInChildren <uGUI_Bindings>();
            uGUI_Binding  binding  = bindings.bindings.First();

            // Destroy secondary bindings
            UnityEngine.Object.Destroy(bindings.bindings.Last().gameObject);
            UnityEngine.Object.Destroy(bindings);

            // Update bindings
            binding.device = device;
            binding.value  = KeyCodeUtils.KeyCodeToString(key);
            binding.onValueChanged.RemoveAllListeners();
            binding.onValueChanged.AddListener(new UnityAction <string>((string s) => callback?.Invoke(KeyCodeUtils.StringToKeyCode(s))));

            return(gameObject);
        }
Exemplo n.º 3
0
        internal static bool RefreshValue_Prefix(uGUI_Binding __instance)
        {
            if (__instance.gameObject.GetComponent <ModBindingTag>() is null)
            {
                return(true);
            }

            __instance.currentText.text = (__instance.active || __instance.value == null) ? "" : __instance.value;
            __instance.UpdateState();
            return(false);
        }
Exemplo n.º 4
0
            static bool Prefix(uGUI_Binding __instance)
            {
                if (!__instance.gameObject.GetComponent <KeyWModBindOption.Tag>())
                {
                    return(true);
                }

                __instance.currentText.text = (__instance.active || __instance.value == null)? "": __instance.value;
                __instance.UpdateState();
                return(false);
            }
Exemplo n.º 5
0
        private void AddTab()
        {
            m_tabIndex = -1;

            Transform tab;
            Text      tabText;

            for (int i = 0; i < m_optionsPanel.tabsContainer.childCount; ++i) //search for "Mods" tab
            {
                tab     = m_optionsPanel.tabsContainer.GetChild(i);
                tabText = tab.GetComponentInChildren <Text>(true);
                if (tabText != null && tabText.text == "Mods")
                {
                    m_tabIndex = i;
                }
            }

            if (m_tabIndex == -1) //no existing mods tab found. add new
            {
                m_tabIndex = m_optionsPanel.AddTab("Mods");
            }

            //add options
            m_optionsPanel.AddHeading(m_tabIndex, "Cyclops Strafe");

            //m_optionsPanel.AddHeading(m_tabIndex, "Keyboard");
            m_useModifierToggle        = m_optionsPanel.AddToggleOption(m_tabIndex, "Use modifier key", m_config.UseModifier, OnStrafeUseModifierToggle);
            m_useModifierBindingOption = AddBinding(m_tabIndex, "Modifier", GetKeyCodeAsInputName(m_config.StrafeModifierKey), GameInput.Device.Keyboard, OnModifierBindingChange);
            AddBinding(m_tabIndex, "Strafe left key", GetKeyCodeAsInputName(m_config.StrafeLeftKey), GameInput.Device.Keyboard, OnStrafeLeftBindingChange);
            AddBinding(m_tabIndex, "Strafe right key", GetKeyCodeAsInputName(m_config.StrafeRightKey), GameInput.Device.Keyboard, OnStrafeRightBindingChange);

            //m_optionsPanel.AddHeading(m_tabIndex, "Controller");

            //AddBinding(m_tabIndex, "Strafe left button", GetKeyCodeAsInputName(m_config.StrafeLeftButton), GameInput.Device.Controller, OnStrafeLeftButtonBindingChange);
            //AddBinding(m_tabIndex, "Strafe right button", GetKeyCodeAsInputName(m_config.StrafeRightButton), GameInput.Device.Controller, OnStrafeRightButtonBindingChange);

            //no speed editing for now
            //m_optionsPanel.AddSliderOption(m_tabIndex, "Strafe speed", m_config.StrafeSpeed, 0.01f, 2f, m_config.StrafeSpeed, OnStrafeSpeedValueChange);
            m_currentModifierBinding = System.Enum.GetName(typeof(KeyCode), m_config.StrafeModifierKey);
            m_modifierBindingOption  = m_useModifierBindingOption.GetComponentInChildren <uGUI_Binding>(true);

            if (!m_config.UseModifier)
            {
                m_useModifierBindingOption.SetActive(false);
            }
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        //from map mod
        private GameObject AddBinding(int _tabIndex, string _label, string _value, GameInput.Device _device, UnityAction <string> _action)
        {
            GameObject gameObject = m_optionsPanel.AddItem(_tabIndex, m_optionsPanel.bindingOptionPrefab);
            Text       txt        = gameObject.GetComponentInChildren <Text>();

            if (txt != null)
            {
                gameObject.GetComponentInChildren <TranslationLiveUpdate>().translationKey = _label;
                txt.text = Language.main.Get(_label);
            }

            uGUI_Bindings bindings = gameObject.GetComponentInChildren <uGUI_Bindings>();
            uGUI_Binding  binding  = bindings.bindings.First <uGUI_Binding>();

            Destroy(bindings.bindings.Last <uGUI_Binding>().gameObject);
            Destroy(bindings);

            binding.device = _device;
            binding.value  = _value;
            binding.onValueChanged.RemoveAllListeners();
            binding.onValueChanged.AddListener(_action);
            return(gameObject);
        }
Exemplo n.º 8
0
 static KeyCode _getKeyCode(uGUI_Binding bind)
 {
     if (bind.value.isNullOrEmpty())
     {
         return(default);
Exemplo n.º 9
0
 static void Postfix(uGUI_Binding __instance) =>
 __instance.gameObject.ensureComponent <BindCheckPointer>();