Beispiel #1
0
        private void OnBindingMouseDown(UIComponent component, UIMouseEventParameter evParam)
        {
            var editable      = (SavedInputKey)evParam.source.objectUserData;
            var keybindButton = evParam.source as UIButton;

            // This will only work if the user is not in the process of changing the shortcut
            if (_currentlyEditingBinding == null)
            {
                evParam.Use();
                StartKeybindEditMode(editable, keybindButton);
            }
            else if (!IsUnbindableMouseButton(evParam.buttons))
            {
                // This will work if the user clicks while the shortcut change is in progress
                evParam.Use();
                var editedBinding = _currentlyEditingBinding; // will be nulled by closing modal
                UIView.PopModal();

                var inputKey = SavedInputKey.Encode(ButtonToKeycode(evParam.buttons),
                                                    IsControlDown(),
                                                    IsShiftDown(),
                                                    IsAltDown());
                editedBinding.value = inputKey;

                keybindButton.buttonsMask = UIMouseButton.Left;
                keybindButton.text        = ToLocalizedString(editedBinding);
                _currentlyEditingBinding  = null;
                ModService.Instance.FinishKeybindEdit();
            }
        }
Beispiel #2
0
        private void OnBindingMouseDown(UIComponent comp, UIMouseEventParameter p)
        {
            if (m_EditingBinding == null)
            {
                p.Use();
                m_EditingBinding         = (SavedInputKey)p.source.objectUserData;
                m_EditingBindingCategory = p.source.stringUserData;
                var uIButton = p.source as UIButton;
                uIButton.buttonsMask = UIMouseButton.Left | UIMouseButton.Right | UIMouseButton.Middle |
                                       UIMouseButton.Special0 | UIMouseButton.Special1 | UIMouseButton.Special2 |
                                       UIMouseButton.Special3;
                uIButton.text = "Press any key";
                p.source.Focus();
                UIView.PushModal(p.source);
            }
            else if (!IsUnbindableMouseButton(p.buttons))
            {
                p.Use();
                UIView.PopModal();
                var inputKey = SavedInputKey.Encode(ButtonToKeycode(p.buttons), IsControlDown(), IsShiftDown(),
                                                    IsAltDown());

                m_EditingBinding.value = inputKey;
                var uIButton2 = p.source as UIButton;
                uIButton2.text           = m_EditingBinding.ToLocalizedString("KEYNAME");
                uIButton2.buttonsMask    = UIMouseButton.Left;
                m_EditingBinding         = null;
                m_EditingBindingCategory = string.Empty;
            }
        }
Beispiel #3
0
        private void OnBindingMouseDown(UIComponent comp, UIMouseEventParameter p)
        {
            if (this.m_EditingBinding == null)
            {
                p.Use();
                this.m_EditingBinding         = (SavedInputKey)p.source.objectUserData;
                this.m_EditingBindingCategory = p.source.stringUserData;
                UIButton uIButton = p.source as UIButton;
                uIButton.buttonsMask = (UIMouseButton.Left | UIMouseButton.Right | UIMouseButton.Middle | UIMouseButton.Special0 | UIMouseButton.Special1 | UIMouseButton.Special2 | UIMouseButton.Special3);
                uIButton.text        = ModInfo.translation.GetTranslation("NBM_PRESS_KEY");
                p.source.Focus();
                UIView.PushModal(p.source);
            }
            else if (!this.IsUnbindableMouseButton(p.buttons))
            {
                p.Use();
                UIView.PopModal();
                InputKey inputKey = SavedInputKey.Encode(this.ButtonToKeycode(p.buttons), this.IsControlDown(), this.IsShiftDown(), this.IsAltDown());

                this.m_EditingBinding.value = inputKey;
                UIButton uIButton2 = p.source as UIButton;
                uIButton2.text                = this.m_EditingBinding.ToLocalizedString("KEYNAME");
                uIButton2.buttonsMask         = UIMouseButton.Left;
                this.m_EditingBinding         = null;
                this.m_EditingBindingCategory = string.Empty;
            }
        }
Beispiel #4
0
 private void OnBindingMouseDown(UIComponent comp, UIMouseEventParameter p)
 {
     if ((SavedValue)this.m_EditingBinding == (SavedValue)null)
     {
         p.Use();
         this.m_EditingBinding = (SavedInputKey)p.source.objectUserData;
         UIButton source = p.source as UIButton;
         source.buttonsMask = UIMouseButton.Left | UIMouseButton.Right | UIMouseButton.Middle | UIMouseButton.Special0 | UIMouseButton.Special1 | UIMouseButton.Special2 | UIMouseButton.Special3;
         source.text        = ColossalFramework.Globalization.Locale.Get("KEYMAPPING_PRESSANYKEY");
         p.source.Focus();
         UIView.PushModal(p.source);
     }
     else
     {
         if (this.IsUnbindableMouseButton(p.buttons))
         {
             return;
         }
         p.Use();
         UIView.PopModal();
         this.m_EditingBinding.value = SavedInputKey.Encode(this.ButtonToKeycode(p.buttons), this.IsControlDown(), this.IsShiftDown(), this.IsAltDown());
         UIButton source = p.source as UIButton;
         source.text           = this.m_EditingBinding.ToLocalizedString("KEYNAME");
         source.buttonsMask    = UIMouseButton.Left;
         this.m_EditingBinding = (SavedInputKey)null;
     }
 }
Beispiel #5
0
 private void OnBindingMouseDown(UIComponent comp, UIMouseEventParameter p)
 {
     if (this.editingBinding == null)
     {
         p.Use();
         this.editingBinding = (SavedInputKey)p.source.objectUserData;
         UIButton uibutton = p.source as UIButton;
         uibutton.buttonsMask = (UIMouseButton.Left | UIMouseButton.Right | UIMouseButton.Middle | UIMouseButton.Special0 | UIMouseButton.Special1 | UIMouseButton.Special2 | UIMouseButton.Special3);
         uibutton.text        = "Press any key";
         p.source.Focus();
         UIView.PushModal(p.source);
         return;
     }
     if (!this.IsUnbindableMouseButton(p.buttons))
     {
         p.Use();
         UIView.PopModal();
         InputKey value = SavedInputKey.Encode(this.ButtonToKeycode(p.buttons), this.IsControlDown(), this.IsShiftDown(), this.IsAltDown());
         this.editingBinding.value = value;
         UIButton uibutton2 = p.source as UIButton;
         uibutton2.text        = this.editingBinding.ToLocalizedString("KEYNAME");
         uibutton2.buttonsMask = UIMouseButton.Left;
         this.editingBinding   = null;
     }
 }
Beispiel #6
0
 void LoadSaved()
 {
     try
     {
         SettingsFile settingsfile = new SettingsFile();
         settingsfile.fileName = FireworksMod.settingsfilename;
         GameSettings.AddSettingsFile(settingsfile);
         //FireworksUI.Init();
         LogMsg("file created");
     }
     catch (Exception ex)
     {
         LogErr(ex.ToString() + ex.StackTrace);
     }
     btnX       = new SavedFloat("btnx", FireworksMod.settingsfilename, 100);
     btnY       = new SavedFloat("btny", FireworksMod.settingsfilename, 100);
     panelX     = new SavedFloat("panelx", FireworksMod.settingsfilename, 200);
     panelY     = new SavedFloat("panely", FireworksMod.settingsfilename, 100);
     colorR     = new SavedFloat("colorr", FireworksMod.settingsfilename, 255);
     colorG     = new SavedFloat("colorg", FireworksMod.settingsfilename, 255);
     colorB     = new SavedFloat("colorb", FireworksMod.settingsfilename, 255);
     heightFrom = new SavedFloat("heightfrom", FireworksMod.settingsfilename, 50);
     heightTo   = new SavedFloat("heightto", FireworksMod.settingsfilename, 60);
     mulExpVel  = new SavedFloat("mulexpvel", FireworksMod.settingsfilename, 0);
     mulSize    = new SavedFloat("mulsize", FireworksMod.settingsfilename, 0);
     defaultstyle.height_from       = heightFrom.value;
     defaultstyle.height_to         = heightTo.value;
     defaultstyle.mul_exp_vel       = Mathf.Pow(10, mulExpVel.value);
     defaultstyle.mul_particle_size = Mathf.Pow(10, mulSize.value);
     hotkey = new SavedInputKey("key", FireworksMod.settingsfilename, SavedInputKey.Encode(KeyCode.F, true, true, false));
 }
Beispiel #7
0
        private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
        {
            if (EditingBinding == null || IsModifierKey(p.keycode))
            {
                return;
            }

            p.Use();
            UIView.PopModal();

            switch (p.keycode)
            {
            case KeyCode.Escape:
                break;

            case KeyCode.Backspace:
                EditingBinding.value = SavedInputKey.Empty;
                break;

            default:
                EditingBinding.value = SavedInputKey.Encode(p.keycode, p.control, p.shift, p.alt);
                break;
            }

            var uITextComponent = p.source as UITextComponent;

            uITextComponent.text = EditingBinding.ToLocalizedString("KEYNAME");

            EditingBinding = null;
        }
Beispiel #8
0
        private void OnBindingKeyDown(UIComponent component, UIKeyEventParameter evParam)
        {
            try {
                if (IsModifierKey(evParam.keycode))
                {
                    return;
                }

                evParam.Use();
                var editedBinding = _currentlyEditingBinding;
                UIView.PopModal();

                var keybindButton = evParam.source as UIButton;
                var inputKey      = SavedInputKey.Encode(evParam.keycode, evParam.control, evParam.shift, evParam.alt);

                if (evParam.keycode != KeyCode.Escape)
                {
                    editedBinding.value = inputKey;
                }

                keybindButton.text       = ToLocalizedString(editedBinding);
                _currentlyEditingBinding = null;
                ModService.Instance.FinishKeybindEdit();
            } catch (Exception e) {
                Debug.LogError($"{e}");
            }
        }
        private static void OnBindingMouseDown(UIComponent comp, UIMouseEventParameter p)
        {
            if (m_EditingBinding == null)
            {
                p.Use();
                m_EditingBinding = (Shortcut)p.source.objectUserData;
                UIButton uIButton = p.source as UIButton;
                uIButton.buttonsMask = (UIMouseButton.Left | UIMouseButton.Right | UIMouseButton.Middle | UIMouseButton.Special0 | UIMouseButton.Special1 | UIMouseButton.Special2 | UIMouseButton.Special3);
                uIButton.text        = "Press any key";
                p.source.Focus();
                UIView.PushModal(p.source);
            }
            else if (!IsUnbindableMouseButton(p.buttons))
            {
                p.Use();
                UIView.PopModal();
                InputKey        inputKey = SavedInputKey.Encode(ButtonToKeycode(p.buttons), IsControlDown(), IsShiftDown(), IsAltDown());
                List <Shortcut> currentAssigned;
                if (!IsAlreadyBound(m_EditingBinding, inputKey, out currentAssigned))
                {
                    if (m_EditingBinding.inputKey != inputKey)
                    {
                        m_EditingBinding.inputKey = inputKey;
                        Shortcut.SaveShorcuts();
                    }

                    UIButton uIButton = p.source as UIButton;
                    uIButton.text        = SavedInputKey.ToLocalizedString("KEYNAME", m_EditingBinding.inputKey);
                    uIButton.buttonsMask = UIMouseButton.Left;
                    m_EditingBinding     = null;
                }
                else
                {
                    string arg     = (currentAssigned.Count <= 1) ? Locale.Get("KEYMAPPING", currentAssigned[0].name) : Locale.Get("KEYMAPPING_MULTIPLE");
                    string message = string.Format(Locale.Get("CONFIRM_REBINDKEY", "Message"), SavedInputKey.ToLocalizedString("KEYNAME", inputKey), arg);
                    ConfirmPanel.ShowModal(Locale.Get("CONFIRM_REBINDKEY", "Title"), message, delegate(UIComponent c, int ret)
                    {
                        if (ret == 1)
                        {
                            m_EditingBinding.inputKey = inputKey;

                            for (int i = 0; i < currentAssigned.Count; i++)
                            {
                                currentAssigned[i].inputKey = 0;
                            }
                            Shortcut.SaveShorcuts();
                            RefreshKeyMapping();
                        }
                        UIButton uIButton    = p.source as UIButton;
                        uIButton.text        = SavedInputKey.ToLocalizedString("KEYNAME", m_EditingBinding.inputKey);
                        uIButton.buttonsMask = UIMouseButton.Left;
                        m_EditingBinding     = null;
                    });
                }
            }
        }
Beispiel #10
0
        private void OnBindingMouseDown(UIComponent comp, UIMouseEventParameter evParam)
        {
            var editable      = (KeybindSetting.Editable)evParam.source.objectUserData;
            var keybindButton = evParam.source as UIButton;

            // This will only work if the user is not in the process of changing the shortcut
            if (currentlyEditedBinding_ == null)
            {
                evParam.Use();
                StartKeybindEditMode(editable, keybindButton);
            }
            else if (!Keybind.IsUnbindableMouseButton(evParam.buttons))
            {
                // This will work if the user clicks while the shortcut change is in progress
                evParam.Use();
                var editedBinding = currentlyEditedBinding_; // will be nulled by closing modal
                UIView.PopModal();

                var inputKey = SavedInputKey.Encode(Keybind.ButtonToKeycode(evParam.buttons),
                                                    Keybind.IsControlDown(),
                                                    Keybind.IsShiftDown(),
                                                    Keybind.IsAltDown());
                var category      = editable.Target.Category;
                var maybeConflict = FindConflict(editedBinding.Value, inputKey, category);
                if (maybeConflict != string.Empty)
                {
                    var message = Translation.Options.Get("Keybinds.Dialog.Text:Keybind conflict")
                                  + "\n\n" + maybeConflict;
                    Log.Info($"Keybind conflict: {message}");
                    UIView.library
                    .ShowModal <ExceptionPanel>("ExceptionPanel")
                    .SetMessage("Key Conflict", message, false);
                }
                else
                {
                    editedBinding.Value.TargetKey.value = inputKey;
                    editedBinding.Value.Target.NotifyKeyChanged();
                }

                keybindButton.buttonsMask = UIMouseButton.Left;
                keybindButton.text        = Keybind.ToLocalizedString(editedBinding.Value.TargetKey);
                currentlyEditedBinding_   = null;
            }
        }
Beispiel #11
0
        private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter evParam)
        {
            try {
                // This will only work if the user clicked the modify button
                // otherwise no effect
                if (!currentlyEditedBinding_.HasValue || Keybind.IsModifierKey(evParam.keycode))
                {
                    return;
                }

                evParam.Use();                               // Consume the event
                var editedBinding = currentlyEditedBinding_; // will be nulled by closing modal
                UIView.PopModal();

                var keybindButton = evParam.source as UIButton;
                var inputKey      = SavedInputKey.Encode(evParam.keycode, evParam.control, evParam.shift, evParam.alt);
                var editable      = (KeybindSetting.Editable)evParam.source.objectUserData;
                var category      = editable.Target.Category;

                if (evParam.keycode != KeyCode.Escape)
                {
                    // Check the key conflict
                    var maybeConflict = FindConflict(editedBinding.Value, inputKey, category);
                    if (maybeConflict != string.Empty)
                    {
                        var message = Translation.Options.Get("Keybinds.Dialog.Text:Keybind conflict")
                                      + "\n\n" + maybeConflict;
                        Log.Info($"Keybind conflict: {message}");
                        UIView.library
                        .ShowModal <ExceptionPanel>("ExceptionPanel")
                        .SetMessage("Key Conflict", message, false);
                    }
                    else
                    {
                        editedBinding.Value.TargetKey.value = inputKey;
                        editedBinding.Value.Target.NotifyKeyChanged();
                    }
                }

                keybindButton.text      = Keybind.ToLocalizedString(editedBinding.Value.TargetKey);
                currentlyEditedBinding_ = null;
            } catch (Exception e) { Log.Error($"{e}"); }
        }
Beispiel #12
0
        private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
        {
            if (EditBinding != null && !IsModifierKey(p.keycode))
            {
                p.Use();
                UIView.PopModal();

                if (p.keycode == KeyCode.Backspace)
                {
                    EditBinding.value = SavedInputKey.Empty;
                }
                else if (p.keycode != KeyCode.Escape)
                {
                    EditBinding.value = SavedInputKey.Encode(p.keycode, p.control, p.shift, p.alt);
                }

                (p.source as UITextComponent).text = EditBinding.ToLocalizedString("KEYNAME");
                EditBinding = null;
            }
        }
Beispiel #13
0
 private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
 {
     if (m_EditingBinding != null && !IsModifierKey(p.keycode))
     {
         p.Use();
         UIView.PopModal();
         var keycode  = p.keycode;
         var inputKey = p.keycode == KeyCode.Escape
             ? m_EditingBinding.value
             : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
         if (p.keycode == KeyCode.Backspace)
         {
             inputKey = SavedInputKey.Empty;
         }
         m_EditingBinding.value = inputKey;
         var uITextComponent = p.source as UITextComponent;
         uITextComponent.text     = m_EditingBinding.ToLocalizedString("KEYNAME");
         m_EditingBinding         = null;
         m_EditingBindingCategory = string.Empty;
     }
 }
Beispiel #14
0
        public static Settings Default()
        {
            var defaultBrush = Brush.Default();

            return(new Settings(
                       200f,
                       100f,
                       false,
                       false,
                       false,
                       true,
                       TreeSorting.Name,
                       SortingOrder.Ascending,
                       FilterStyle.AND,
                       Enumerable.Empty <Brush>(),
                       string.Empty,
                       new SavedInputKey("toggleTool", Constants.ModName, SavedInputKey.Encode(KeyCode.B, false, false, true), true),
                       false,
                       false,
                       true
                       ));
        }
Beispiel #15
0
 private void OnBindingMouseDown(UIComponent comp, UIMouseEventParameter p)
 {
     if (EditBinding == null)
     {
         p.Use();
         EditBinding = (SavedInputKey)p.source.objectUserData;
         var button = p.source as UIButton;
         button.buttonsMask = UIMouseButton.Left | UIMouseButton.Right | UIMouseButton.Middle | UIMouseButton.Special0 | UIMouseButton.Special1 | UIMouseButton.Special2 | UIMouseButton.Special3;
         button.text        = Locale.Get("KEYMAPPING_PRESSANYKEY");
         p.source.Focus();
         UIView.PushModal(p.source);
     }
     else if (!IsUnbindableMouseButton(p.buttons))
     {
         p.Use();
         UIView.PopModal();
         EditBinding.value = SavedInputKey.Encode(ButtonToKeycode(p.buttons), Utility.CtrlIsPressed, Utility.ShiftIsPressed, Utility.AltIsPressed);
         var button = p.source as UIButton;
         button.text        = EditBinding.ToLocalizedString("KEYNAME");
         button.buttonsMask = UIMouseButton.Left;
         EditBinding        = null;
     }
 }
        private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter e)
        {
            var key = e.keycode;

            if (_editingBinding == null || KeyHelper.IsModifierKey(key))
            {
                return;
            }

            e.Use();
            UIView.PopModal();

            InputKey newKey;

            switch (key)
            {
            case KeyCode.Backspace:
                newKey = SavedInputKey.Empty;
                break;

            case KeyCode.Escape:
                newKey = _editingBinding.value;
                break;

            default:
                newKey = SavedInputKey.Encode(key, e.control, e.shift, e.alt);
                break;
            }

            if (IsAlreadyBound(_editingBinding, newKey, out var currentAssigned))
            {
                var text = currentAssigned.Count <= 1
          ? (
                    Locale.Exists("KEYMAPPING", currentAssigned[0].name)
              ? Locale.Get("KEYMAPPING", currentAssigned[0].name)
              : Options.GetShortcutName(currentAssigned[0].name)
                    )
          : Locale.Get("KEYMAPPING_MULTIPLE");
                var message = StringUtils.SafeFormat(Locale.Get("CONFIRM_REBINDKEY", "Message"),
                                                     SavedInputKey.ToLocalizedString("KEYNAME", newKey), text);

                ConfirmPanel.ShowModal(Locale.Get("CONFIRM_REBINDKEY", "Title"), message, (c, ret) =>
                {
                    var btn = (UIButton)comp;
                    if (ret == 1)
                    {
                        _editingBinding.value = newKey;
                        foreach (var asigned in currentAssigned)
                        {
                            asigned.value = SavedInputKey.Empty;
                        }
                        UpdateKeyBinding(newKey, btn, false);
                        RefreshKeyMapping();
                    }
                    _editingBinding = null;
                    btn.text        = ((SavedInputKey)btn.objectUserData).ToLocalizedString("KEYNAME");
                });
            }
            else
            {
                UpdateKeyBinding(newKey, (UIButton)comp, false);
            }
        }
Beispiel #17
0
 private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
 {
     if (this.editingBinding != null && !this.IsModifierKey(p.keycode))
     {
         p.Use();
         UIView.PopModal();
         KeyCode  keycode = p.keycode;
         InputKey value   = (p.keycode == KeyCode.Escape) ? this.editingBinding.value : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
         if (p.keycode == KeyCode.Backspace)
         {
             value = SavedInputKey.Empty;
         }
         this.editingBinding.value          = value;
         (p.source as UITextComponent).text = this.editingBinding.ToLocalizedString("KEYNAME");
         this.editingBinding = null;
     }
 }
Beispiel #18
0
 public SavedInputKey(string name, string fileName, KeyCode key, bool control, bool shift, bool alt, bool autoUpdate) : base(name, fileName, autoUpdate)
 {
     this.m_Value = SavedInputKey.Encode(key, control, shift, alt);
 }
Beispiel #19
0
        public static bool IsEmpty(InputKey sample)
        {
            var noKey = SavedInputKey.Encode(KeyCode.None, false, false, false);

            return(sample == SavedInputKey.Empty || sample == noKey);
        }
Beispiel #20
0
        /// <summary>
        /// MouseDown event handler to handle mouse clicks; primarily used to prime hotkey entry.
        /// </summary>
        /// <param name="mouseEvent">Mouse button event parameter</param>
        public void OnMouseDown(UIMouseEventParameter mouseEvent)
        {
            // Use the event.
            mouseEvent.Use();

            // Check to see if we're already primed for hotkey entry.
            if (isPrimed)
            {
                // We were already primed; is this a bindable mouse button?
                if (mouseEvent.buttons == UIMouseButton.Left || mouseEvent.buttons == UIMouseButton.Right)
                {
                    // Not a bindable mouse button - set the button text and cancel priming.
                    button.text = SavedInputKey.ToLocalizedString("KEYNAME", ModSettings.CurrentHotkey);
                    UIView.PopModal();
                    isPrimed = false;
                }
                else
                {
                    // Bindable mouse button - do keybinding as if this was a keystroke.
                    KeyCode mouseCode;

                    switch (mouseEvent.buttons)
                    {
                    // Convert buttons to keycodes (we don't bother with left and right buttons as they're non-bindable).
                    case UIMouseButton.Middle:
                        mouseCode = KeyCode.Mouse2;
                        break;

                    case UIMouseButton.Special0:
                        mouseCode = KeyCode.Mouse3;
                        break;

                    case UIMouseButton.Special1:
                        mouseCode = KeyCode.Mouse4;
                        break;

                    case UIMouseButton.Special2:
                        mouseCode = KeyCode.Mouse5;
                        break;

                    case UIMouseButton.Special3:
                        mouseCode = KeyCode.Mouse6;
                        break;

                    default:
                        // No valid button pressed: exit without doing anything.
                        return;
                    }

                    // We got a valid mouse button key - apply settings and save.
                    ApplyKey(SavedInputKey.Encode(mouseCode, IsControlDown(), IsShiftDown(), IsAltDown()));
                }
            }
            else
            {
                // We weren't already primed - set our text and focus the button.
                button.buttonsMask = (UIMouseButton.Left | UIMouseButton.Right | UIMouseButton.Middle | UIMouseButton.Special0 | UIMouseButton.Special1 | UIMouseButton.Special2 | UIMouseButton.Special3);
                button.text        = Translations.Translate("KEY_PRS");
                button.Focus();

                // Prime for new keybinding entry.
                isPrimed = true;
                UIView.PushModal(button);
            }
        }
Beispiel #21
0
        /// <summary>
        /// KeyDown event handler to record the new hotkey.
        /// </summary>
        /// <param name="keyEvent">Keypress event parameter</param>
        public void OnKeyDown(UIKeyEventParameter keyEvent)
        {
            Logging.Message("keydown ", isPrimed.ToString());

            // Only do this if we're primed and the keypress isn't a modifier key.
            if (isPrimed && !IsModifierKey(keyEvent.keycode))
            {
                // Variables.
                InputKey inputKey;

                // Use the event.
                keyEvent.Use();

                // If escape was entered, we don't change the code.
                if (keyEvent.keycode == KeyCode.Escape)
                {
                    inputKey = ModSettings.CurrentHotkey;
                }
                else
                {
                    // If backspace was pressed, then we blank the input; otherwise, encode the keypress.
                    inputKey = (keyEvent.keycode == KeyCode.Backspace) ? SavedInputKey.Empty : SavedInputKey.Encode(keyEvent.keycode, keyEvent.control, keyEvent.shift, keyEvent.alt);
                }

                // Apply our new key.
                ApplyKey(inputKey);
            }
        }
Beispiel #22
0
 protected void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
 {
     if (this.m_EditingBinding != null && !this.IsModifierKey(p.keycode))
     {
         p.Use();
         UIView.PopModal();
         KeyCode  keycode  = p.keycode;
         InputKey inputKey = (p.keycode == KeyCode.Escape) ? this.m_EditingBinding.value : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
         if (p.keycode == KeyCode.Backspace)
         {
             inputKey = SavedInputKey.Empty;
         }
         this.m_EditingBinding.value = inputKey;
         UITextComponent uITextComponent = p.source as UITextComponent;
         uITextComponent.text          = this.m_EditingBinding.ToLocalizedString("KEYNAME");
         this.m_EditingBinding         = null;
         this.m_EditingBindingCategory = string.Empty;
     }
 }
        private static void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
        {
            if (m_EditingBinding != null && !IsModifierKey(p.keycode))
            {
                p.Use();
                UIView.PopModal();
                KeyCode  keycode  = p.keycode;
                InputKey inputKey = (p.keycode == KeyCode.Escape) ? (InputKey)m_EditingBinding.inputKey : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
                if (p.keycode == KeyCode.Backspace)
                {
                    inputKey = 0;
                }
                List <Shortcut> currentAssigned;
                if (!IsAlreadyBound(m_EditingBinding, inputKey, out currentAssigned))
                {
                    if (m_EditingBinding.inputKey != inputKey)
                    {
                        m_EditingBinding.inputKey = inputKey;
                        Shortcut.SaveShorcuts();
                    }

                    UITextComponent uITextComponent = p.source as UITextComponent;
                    uITextComponent.text = SavedInputKey.ToLocalizedString("KEYNAME", inputKey);
                    m_EditingBinding     = null;
                }
                else
                {
                    string arg     = (currentAssigned.Count <= 1) ? currentAssigned[0].name : Locale.Get("KEYMAPPING_MULTIPLE");
                    string message = string.Format(Locale.Get("CONFIRM_REBINDKEY", "Message"), SavedInputKey.ToLocalizedString("KEYNAME", inputKey), arg);
                    ConfirmPanel.ShowModal(Locale.Get("CONFIRM_REBINDKEY", "Title"), message, delegate(UIComponent c, int ret)
                    {
                        if (ret == 1)
                        {
                            for (int i = 0; i < currentAssigned.Count; i++)
                            {
                                currentAssigned[i].inputKey = 0;
                            }
                        }

                        m_EditingBinding.inputKey = inputKey;
                        Shortcut.SaveShorcuts();
                        RefreshKeyMapping();

                        UITextComponent uITextComponent = p.source as UITextComponent;
                        uITextComponent.text            = SavedInputKey.ToLocalizedString("KEYNAME", m_EditingBinding.inputKey);
                        m_EditingBinding = null;
                    });
                }
            }
        }
Beispiel #24
0
 private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
 {
     if (this.m_EditingBinding != null && !this.IsModifierKey(p.keycode))
     {
         p.Use();
         UIView.PopModal();
         KeyCode  keycode  = p.keycode;
         InputKey inputKey = (p.keycode == KeyCode.Escape) ? this.m_EditingBinding.value : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
         if (p.keycode == KeyCode.Backspace)
         {
             inputKey = SavedInputKey.Empty;
         }
         List <SavedInputKey> currentAssigned;
         if (!this.IsAlreadyBound(this.m_EditingBinding, inputKey, this.m_EditingBindingCategory, out currentAssigned))
         {
             this.m_EditingBinding.value = inputKey;
             UITextComponent uITextComponent = p.source as UITextComponent;
             uITextComponent.text          = this.m_EditingBinding.ToLocalizedString("KEYNAME");
             this.m_EditingBinding         = null;
             this.m_EditingBindingCategory = string.Empty;
         }
         else
         {
             string arg     = (currentAssigned.Count <= 1) ? Locale.Get("KEYMAPPING", currentAssigned[0].name) : Locale.Get("KEYMAPPING_MULTIPLE");
             string message = string.Format(Locale.Get("CONFIRM_REBINDKEY", "Message"), SavedInputKey.ToLocalizedString("KEYNAME", inputKey), arg);
             ConfirmPanel.ShowModal(Locale.Get("CONFIRM_REBINDKEY", "Title"), message, delegate(UIComponent c, int ret)
             {
                 if (ret == 1)
                 {
                     this.m_EditingBinding.value = inputKey;
                     for (int i = 0; i < currentAssigned.Count; i++)
                     {
                         currentAssigned[i].value = SavedInputKey.Empty;
                     }
                     this.RefreshKeyMapping();
                 }
                 UITextComponent uITextComponent2 = p.source as UITextComponent;
                 uITextComponent2.text            = this.m_EditingBinding.ToLocalizedString("KEYNAME");
                 this.m_EditingBinding            = null;
                 this.m_EditingBindingCategory    = string.Empty;
             });
         }
     }
 }
Beispiel #25
0
        private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
        {
            if (!((SavedValue)this.m_EditingBinding != (SavedValue)null) || this.IsModifierKey(p.keycode))
            {
                return;
            }
            p.Use();
            UIView.PopModal();
            KeyCode  keycode  = p.keycode;
            InputKey inputKey = p.keycode == KeyCode.Escape ? this.m_EditingBinding.value : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);

            if (p.keycode == KeyCode.Backspace)
            {
                inputKey = SavedInputKey.Empty;
            }
            this.m_EditingBinding.value        = inputKey;
            (p.source as UITextComponent).text = this.m_EditingBinding.ToLocalizedString("KEYNAME");
            this.m_EditingBinding = (SavedInputKey)null;
        }