Example #1
0
        /// <summary>
        /// The method for reading the <see cref="KeyCode"/> data from the <paramref name="reader"/>.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="objectType"></param>
        /// <param name="existingValue"></param>
        /// <param name="serializer"></param>
        /// <returns></returns>
        public override object ReadJson(JsonReader reader, Type objectType,
                                        object existingValue, JsonSerializer serializer)
        {
            var s = (string)reader.Value;

            return(KeyCodeUtils.StringToKeyCode(s));
        }
Example #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);
#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.gameObject.EnsureComponent <ModBindingTag>();
            binding.bindingSet   = GameInput.BindingSet.Primary;
            binding.bindCallback = new Action <GameInput.Device, GameInput.Button, GameInput.BindingSet, string>((_, _1, _2, s) =>
            {
                binding.value = s;
                parentOptions.OnKeybindChange(Id, KeyCodeUtils.StringToKeyCode(s));
                binding.RefreshValue();
            });
#endif

            base.AddToPanel(panel, tabIndex);
        }
Example #3
0
        private static void RegisterNewButton(string name, string key, Button button, Device device)
        {
            var bind = new Tuple <Device, Button, string>(device, button, key);

            if (RegisteredButtons.Contains(bind))
            {
                return;
            }

            RegisteredButtons.Add(bind);
            LanguageHandler.SetLanguageLine($"Option{name}", name);
            Language.main.LoadLanguageFile(Language.main.GetCurrentLanguage());
            GameInput.AddKeyInput(name, KeyCodeUtils.StringToKeyCode(key), device);
            GameInput.instance.Initialize();
            for (int i = 0; i < GameInput.numDevices; i++)
            {
                GameInput.SetupDefaultBindings((GameInput.Device)i);
            }
            foreach (Tuple <Device, Button, string> binding in RegisteredButtons)
            {
                GameInput.SafeSetBinding(binding.Item1, binding.Item2, BindingSet.Primary, binding.Item3);
            }
        }
Example #4
0
 /// <summary>
 /// Adds a new <see cref="ModKeybindOption"/> to this instance.
 /// </summary>
 /// <param name="id">The internal ID for the toggle option.</param>
 /// <param name="label">The display text to use in the in-game menu.</param>
 /// <param name="device">The device name.</param>
 /// <param name="key">The starting keybind value.</param>
 protected void AddKeybindOption(string id, string label, GameInput.Device device, string key)
 {
     AddKeybindOption(id, label, device, KeyCodeUtils.StringToKeyCode(key));
 }
Example #5
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);
        }