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); }
public void SetControls() { var labelTemplate = Language.main.Get("OptionSlot1").Split(' '); var translatedLabel = labelTemplate.Length == 2 ? labelTemplate[0] : "Slot"; Config.Instance.SlotLabels = new Dictionary <int, string>(); Config.Instance.SlotBindings = new Dictionary <int, uGUI_QuickSlots_Bindings>(); if (index > -1) { for (int i = Player.quickSlotButtonsCount; i < Mod.config.SlotCount; i++) { var label = $"{translatedLabel} {(i + 1)}"; if (!Config.Instance.SlotLabels.ContainsKey(i)) { Config.Instance.SlotLabels.Add(i, label); } var gameObject = optionsPanel.AddItem(index, optionsPanel.bindingOptionPrefab); var componentInChildren = gameObject.GetComponentInChildren <TextMeshProUGUI>(); if (componentInChildren != null) { gameObject.name = "OptionSlot" + i; componentInChildren.text = label; componentInChildren.color = uGUI.currentColor; } var originalBindingsComponent = gameObject.GetComponentInChildren <uGUI_Bindings>(); var originalBindingComponents = gameObject.GetComponentsInChildren <uGUI_Binding>().Select(x => x.gameObject).ToList(); foreach (var ob in gameObject.GetComponentsInChildren <uGUI_Binding>()) { dataState = ob.data; Destroy(ob); } var bg = originalBindingsComponent.selectionBackground; bindings.Remove(originalBindingsComponent); Destroy(originalBindingsComponent); var qsBinds = gameObject.transform.Find("Bindings").gameObject.AddComponent <uGUI_QuickSlots_Bindings>(); Config.Instance.SlotBindings.Add(i, qsBinds); qsBinds.Setup(i, bg, null); } } }
//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); }