IEnumerator WaitForKeyPress(Button button) { string currentLabel = button.Label.Text; InputManager.Actions buttonAction = (InputManager.Actions)Enum.Parse(typeof(InputManager.Actions), button.Name); button.Label.Text = ""; yield return(new WaitForSecondsRealtime(0.05f)); while (!Input.anyKeyDown) { waitingForInput = true; yield return(null); } waitingForInput = false; foreach (KeyCode code in Enum.GetValues(typeof(KeyCode))) { if (Input.GetKeyDown(code)) { if (code.ToString() != "Escape") { button.Label.Text = code.ToString(); CheckDuplicates(); InputManager.Instance.ClearBinding(buttonAction); InputManager.Instance.SetBinding(code, buttonAction); InputManager.Instance.SaveKeyBinds(); } else { button.Label.Text = currentLabel; } } } }
private void SetupKeybindButtons(List <Button> buttonGroup, int startPoint, int endPoint, int leftOffset, int topOffset, bool firstSetup) { for (int i = startPoint; i < endPoint; i++) { InputManager.Actions key = (InputManager.Actions)Enum.Parse(typeof(InputManager.Actions), actions[i]); int j = i - startPoint; if (firstSetup) { buttonGroup.Add(new Button()); buttonGroup[j].Label.ShadowPosition = Vector2.zero; buttonGroup[j].Size = new Vector2(47, 7); if (j == 0) { buttonGroup[j].Position = new Vector2(leftOffset, topOffset); } else { buttonGroup[j].Position = new Vector2(leftOffset, buttonGroup[j - 1].Position.y + 11); } controlsPanel.Components.Add(buttonGroup[j]); buttonGroup[j].Name = actions[i]; buttonGroup[j].OnMouseClick += KeybindButton_OnMouseClick; if (i == endPoint - 1) { allKeys.Add(buttonGroup); } } buttonGroup[j].Label.Text = InputManager.Instance.GetBinding(key).ToString(); buttonGroup[j].Label.TextColor = DaggerfallUI.DaggerfallDefaultTextColor; } }
private void SetupKeybindButton(Button button, InputManager.Actions action) { var code = ControlsConfigManager.Instance.GetUnsavedBindingKeyCode(action); button.Label.Text = ControlsConfigManager.Instance.GetButtonText(code); button.Label.TextColor = DaggerfallUI.DaggerfallDefaultTextColor; button.ToolTip = defaultToolTip; button.SuppressToolTip = button.Label.Text != ControlsConfigManager.ElongatedButtonText; button.ToolTipText = ControlsConfigManager.Instance.GetButtonText(code, true); }
public string GetUnsavedBinding(InputManager.Actions action, UnaryBindings binding = UnaryBindings.Current) { var dict = GetUnsavedBindingDictionary(binding); string ret; if (dict.TryGetValue(action, out ret)) { return(ret); } return(null); }
//for initialization private void SetupKeybindButton(Button button, InputManager.Actions action, int x, int y) { Panel panel = new Panel(); panel.Position = new Vector2(x, y); panel.Size = new Vector2(85, 15); Panel labelPanel = new Panel(); labelPanel.Size = new Vector2(40, 10); labelPanel.Position = new Vector2(0, 0); labelPanel.HorizontalAlignment = HorizontalAlignment.Left; labelPanel.VerticalAlignment = VerticalAlignment.Middle; TextLabel label = new TextLabel(); label.Position = new Vector2(0, 0); label.HorizontalAlignment = HorizontalAlignment.Right; label.VerticalAlignment = VerticalAlignment.Middle; label.ShadowPosition = Vector2.zero; //"ToggleConsole" is too long as a word when looking in non-SDF font view //"Screenshot" is a better word and is one letter less than "PrintScreen" label.Text = action == InputManager.Actions.Escape ? "Pause" : action == InputManager.Actions.ToggleConsole ? "Console" : action == InputManager.Actions.PrintScreen ? "Screenshot" : action.ToString(); label.TextColor = DaggerfallUI.DaggerfallDefaultTextColor; button.Name = action.ToString(); button.Label.ShadowPosition = Vector2.zero; button.Label.TextScale = 0.9f; button.Size = new Vector2(43, 10); button.Position = new Vector2(43, 0); button.HorizontalAlignment = HorizontalAlignment.Right; button.VerticalAlignment = VerticalAlignment.Middle; SetBackground(button, keybindButtonBackgroundColor, "advancedControlsKeybindBackgroundColor"); button.OnMouseClick += KeybindButton_OnMouseClick; button.OnRightMouseClick += KeybindButton_OnMouseRightClick; buttonGroup.Add(button); labelPanel.Components.Add(label); panel.Components.Add(labelPanel); panel.Components.Add(button); mainPanel.Components.Add(panel); SetupKeybindButton(button, action); }
private void SaveKeybindValues(List <Button> buttonGroup, int startPoint, int endPoint) { for (int i = startPoint; i < endPoint; i++) { // Get action and code for this button int j = i - startPoint; InputManager.Actions action = (InputManager.Actions)Enum.Parse(typeof(InputManager.Actions), actions[i]); KeyCode code = (KeyCode)Enum.Parse(typeof(KeyCode), buttonGroup[j].Label.Text); // Rebind only if new code is different KeyCode curCode = InputManager.Instance.GetBinding(action); if (curCode != code) { InputManager.Instance.SetBinding(code, action); Debug.LogFormat("Bound Action {0} with Code {1}", action, code.ToString()); } } }
private void SetupKeybindButtons(List <Button> buttonGroup, int startPoint, int endPoint, int leftOffset, int topOffset, bool firstSetup) { for (int i = startPoint; i < endPoint; i++) { InputManager.Actions key = (InputManager.Actions)Enum.Parse(typeof(InputManager.Actions), actions[i]); int j = i - startPoint; if (firstSetup) { buttonGroup.Add(new Button()); buttonGroup[j].Label.ShadowPosition = Vector2.zero; buttonGroup[j].Size = new Vector2(47, 7); if (j == 0) { buttonGroup[j].Position = new Vector2(leftOffset, topOffset); } else { buttonGroup[j].Position = new Vector2(leftOffset, buttonGroup[j - 1].Position.y + 11); } controlsPanel.Components.Add(buttonGroup[j]); buttonGroup[j].Name = actions[i]; buttonGroup[j].OnMouseClick += KeybindButton_OnMouseClick; buttonGroup[j].OnRightMouseClick += KeybindButton_OnMouseRightClick; if (i == endPoint - 1) { allKeys.Add(buttonGroup); } } var code = ControlsConfigManager.Instance.GetUnsavedBindingKeyCode(key); buttonGroup[j].Label.Text = ControlsConfigManager.Instance.GetButtonText(code); buttonGroup[j].Label.TextColor = DaggerfallUI.DaggerfallDefaultTextColor; buttonGroup[j].ToolTip = defaultToolTip; buttonGroup[j].SuppressToolTip = buttonGroup[j].Label.Text != ControlsConfigManager.ElongatedButtonText; buttonGroup[j].ToolTipText = ControlsConfigManager.Instance.GetButtonText(code, true); } }
//for "reset defaults" overload //**might delete this, since reset defaults is in the main controls window private void SetupKeybindButton(Button button, InputManager.Actions action) { button.Label.Text = DaggerfallControlsWindow.UnsavedKeybindDict[action]; button.Label.TextColor = DaggerfallUI.DaggerfallDefaultTextColor; }
//for "reset defaults" overload //**might delete this, since reset defaults is in the main controls window private void SetupKeybindButton(Button button, InputManager.Actions action) { button.Label.Text = ControlsConfigManager.Instance.GetUnsavedBinding(action); button.Label.TextColor = DaggerfallUI.DaggerfallDefaultTextColor; }
public void SetUnsavedBinding(InputManager.Actions action, string keyCodeString, UnaryBindings binding = UnaryBindings.Current) { GetUnsavedBindingDictionary(binding)[action] = keyCodeString; }