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); }
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); }
public static string FormatButton(Toggle toggle) { string displayText = null; if (toggle.KeyCode == KeyCode.None) { displayText = GetLanguage("NoInputAssigned"); } else { #pragma warning disable CS0436 // Type conflicts with imported type string bindingName = KeyCodeUtils.KeyCodeToString(toggle.KeyCode); #pragma warning restore CS0436 // Type conflicts with imported type if (!string.IsNullOrEmpty(bindingName)) { displayText = uGUI.GetDisplayTextForBinding(bindingName); } if (string.IsNullOrEmpty(displayText)) { displayText = GetLanguage("NoInputAssigned"); } } return($"<color=#ADF8FFFF>{displayText}</color>{(toggle.KeyMode == Toggle.Mode.Hold ? " (Hold)" : string.Empty)}"); }
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); }
public static string FormatButton(Toggle toggle) { string displayText = null; if (toggle.KeyCode == KeyCode.None) { displayText = SMLHelper.Language.Get("NoInputAssigned"); } else { string bindingName = KeyCodeUtils.KeyCodeToString(toggle.KeyCode); if (!string.IsNullOrEmpty(bindingName)) { displayText = uGUI.GetDisplayTextForBinding(bindingName); } if (string.IsNullOrEmpty(displayText)) { displayText = SMLHelper.Language.Get("NoInputAssigned"); } } return($"<color=#ADF8FFFF>{displayText}</color>{(toggle.KeyMode == Toggle.Mode.Hold ? " (Hold)" : string.Empty)}"); }
/// <summary> /// The method for writing the <paramref name="value"/> data to the <paramref name="writer"/>. /// </summary> /// <param name="writer"></param> /// <param name="value"></param> /// <param name="serializer"></param> public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var keyCode = (KeyCode)value; writer.WriteValue(KeyCodeUtils.KeyCodeToString(keyCode)); }
internal static void DisplayVehicleInfoForPSTD(Exosuit thisExosuit) { GameObject gameObject = GameObject.Find("HUD"); GameObject gameObject2 = GameObject.Find("AirVentsDisplayUI"); if (Player.main.currentMountedVehicle == thisExosuit) { if (gameObject2 == null) { gameObject2 = new GameObject("AirVentsDisplayUI"); } gameObject2.transform.SetParent(gameObject.transform, false); Text text = gameObject2.GetComponent <Text>(); if (text == null) { text = gameObject2.gameObject.AddComponent <Text>(); } text.font = Player.main.textStyle.font; text.fontSize = Mathf.RoundToInt(Config.AirVentsFontSizeSliderValue); text.alignment = TextAnchor.LowerCenter; text.color = Color.white; RectTransform component = text.GetComponent <RectTransform>(); component.localPosition = AirVentHUDPosition; component.sizeDelta = AirVentHUDSize; AirVentDisplayText = text; gameObject = gameObject2; StringBuilder stringBuilder = new StringBuilder(); // Air vents display if (Player.main.GetDepth() > DepthDetection) { if (Config.AirVentsAutoToggleValue) { stringBuilder.Append(colorYellow); stringBuilder.Append(AirVentHUDTextAutoClosed); stringBuilder.Append(colorEnd); } //AirVentDisplayText.text = colorYellow + AirVentHUDTextAutoClosed + colorEnd; else //AirVentDisplayText.text = colorYellow + AirVentHUDTextClosed + colorEnd; { stringBuilder.Append(colorYellow); stringBuilder.Append(AirVentHUDTextClosed); stringBuilder.Append(colorEnd); } } else { if (Config.AirVentsAutoToggleValue) { // AirVentDisplayText.text = colorYellow + AirVentHUDTextAutoOpened + colorEnd; stringBuilder.Append(colorYellow); stringBuilder.Append(AirVentHUDTextAutoOpened); stringBuilder.Append(colorEnd); } else { if (!AirVentsOn) { stringBuilder.Append(colorRed); stringBuilder.Append(AirVentHUDTextPromptOpen); stringBuilder.Append(colorEnd); stringBuilder.AppendFormat("(<color=#ADF8FFFF>{0}</color>)", Config.ToggleAirVentsKeybindValue.ToString()); //AirVentDisplayText.text = AirVentDisplayText.text + stringBuilder.ToString(); } else { stringBuilder.Append(AirVentHUDTextPromptClose); stringBuilder.AppendFormat("(<color=#ADF8FFFF>{0}</color>)", Config.ToggleAirVentsKeybindValue.ToString()); //AirVentDisplayText.text = AirVentDisplayText.text + stringBuilder.ToString(); } } } if (OtherModsInfo.Rm_VehicleLightsImprovedPresent) { stringBuilder.Append('\n'); stringBuilder.Append("Exit "); stringBuilder.AppendFormat("(<color=#ADF8FFFF>{0}</color>)", KeyCodeUtils.KeyCodeToString(KeyCode.E)); stringBuilder.Append('\n'); stringBuilder.Append("Toggle lights "); string displayMidMouseButton = uGUI.GetDisplayTextForBinding("MouseButtonMiddle"); stringBuilder.AppendFormat("(<color=#ADF8FFFF>{0}</color>)", displayMidMouseButton); } // AirVentDisplayText.text = AirVentDisplayText.text + stringBuilder.ToString(); AirVentDisplayText.text = stringBuilder.ToString(); gameObject2.SetActive(true); } else { if (gameObject2 != null) { gameObject2.SetActive(false); } } }
public KeybindChangedEventArgs(string id, KeyCode key) { Id = id; Key = key; KeyName = KeyCodeUtils.KeyCodeToString(key); }
static void TooltipFactory_ItemActions_Postfix(StringBuilder sb, InventoryItem item) { if (item.item.GetTechType() != TechType.Beacon) { return; } string btn = Main.config.renameBeaconsKey == default? Strings.Mouse.middleButton: KeyCodeUtils.KeyCodeToString(Main.config.renameBeaconsKey); TooltipFactory.WriteAction(sb, btn, L10n.str(L10n.ids_beaconRename)); if (Main.config.renameBeaconsKey != default && Input.GetKeyDown(Main.config.renameBeaconsKey)) { renameBeacon(item.item.GetComponent <Beacon>()); } }