private void AddShortcutDisplay(int i, string name, SavedInputKey shortcut)
        {
            const string keyBindingTemplate = "KeyBindingTemplate";
            var          pnl = (UIPanel)this.AttachUIComponent(UITemplateManager.GetAsGameObject(keyBindingTemplate));

            if (i % 2 == 0)
            {
                pnl.backgroundSprite = string.Empty;
            }

            var lbl = pnl.Find <UILabel>("Name");

            lbl.text    = name;
            lbl.tooltip = "C:S shortcut. Change in Cities:Skylines Keymapping settings";

            var btn = pnl.Find <UIButton>("Binding");

            btn.objectUserData = shortcut;
            btn.text           = shortcut.ToLocalizedString("KEYNAME");
            btn.tooltip        = lbl.tooltip;
            btn.canFocus       = false;
            btn.hoveredColor   = btn.color;
            btn.pressedColor   = btn.color;
            btn.focusedColor   = btn.color;
        }
        public static UIButton GetKeymapping(UIComponent parent, Shortcut shortcut)
        {
            UIPanel uIPanel = parent.AttachUIComponent(UITemplateManager.GetAsGameObject(kKeyBindingTemplate)) as UIPanel;

            UIButton uIButton = uIPanel.Find <UIButton>("Binding");

            //uIButton = UnityEngine.Object.Instantiate<GameObject>(uIButton.gameObject).GetComponent<UIButton>();
            m_components.Add(uIButton);
            parent.AttachUIComponent(uIButton.gameObject);

            uIButton.eventKeyDown   += new KeyPressHandler(OnBindingKeyDown);
            uIButton.eventMouseDown += new MouseEventHandler(OnBindingMouseDown);

            if (shortcut != null)
            {
                uIButton.text = SavedInputKey.ToLocalizedString("KEYNAME", shortcut.inputKey);
            }
            else
            {
                uIButton.text = Locale.Get("KEYNAME", ((InputKey)0).ToString());
            }
            uIButton.objectUserData = shortcut;

            //GameObject.DestroyImmediate(uIPanel);

            return(uIButton);
        }
        private static bool IsAlreadyBoundTtl(SavedInputKey target, InputKey inputKey, Options options,
                                              ref List <SavedInputKey> currentAssigned)
        {
            if (inputKey == SavedInputKey.Empty)
            {
                return(false);
            }

            bool newAssigned = false;

            foreach (var field in typeof(Options).GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                if (field.FieldType == typeof(SavedInputKey))
                {
                    var savedInputKey = (SavedInputKey)field.GetValue(options);
                    if (target != savedInputKey && inputKey == savedInputKey.value)
                    {
                        DebugLog.Info($"Already assigned: \n" +
                                      $"\tSavedInputKey: {savedInputKey.name}-{savedInputKey.ToLocalizedString("KEYNAME")}\n" +
                                      $"\tTarget: {target.name}-{target.ToLocalizedString("KEYNAME")}\n" +
                                      $"\tInputKey: {inputKey.ToString()}");
                        currentAssigned.Add(savedInputKey);
                        newAssigned = true;
                    }
                }
            }
            return(newAssigned);
        }
Beispiel #4
0
 /// <summary>
 /// Returns shortcut as a string in user's language. Modify for special handling.
 /// </summary>
 /// <param name="k">The key</param>
 /// <returns>The shortcut, example: "Ctrl + Alt + H"</returns>
 public static string ToLocalizedString(SavedInputKey k)
 {
     if (k.value == SavedInputKey.Empty)
     {
         return(Translation.Options.Get("Keybind:None"));
     }
     return(k.ToLocalizedString("KEYNAME"));
 }
Beispiel #5
0
 private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
 {
     if (m_EditingBinding != null && !IsModifierKey(p.keycode))
     {
         p.Use();
         UIView.PopModal();
         KeyCode  keycode = p.keycode;
         InputKey value   = (p.keycode == KeyCode.Escape) ? m_EditingBinding.value : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
         if (p.keycode == KeyCode.Backspace)
         {
             value = SavedInputKey.Empty;
         }
         m_EditingBinding.value             = value;
         (p.source as UITextComponent).text = m_EditingBinding.ToLocalizedString("KEYNAME");
         m_EditingBinding         = null;
         m_EditingBindingCategory = string.Empty;
     }
 }
Beispiel #6
0
        public static string ToLocalizedString(SavedInputKey k)
        {
            if (k.value == SavedInputKey.Empty)
            {
                return("None");
            }

            return(k.ToLocalizedString("KEYNAME"));
        }
        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;
                    });
                }
            }
        }
 private static void RefreshKeyMapping()
 {
     foreach (UITextComponent current in m_components)
     {
         Shortcut shortcut = (Shortcut)current.objectUserData;
         if (m_EditingBinding != shortcut)
         {
             current.text = SavedInputKey.ToLocalizedString("KEYNAME", shortcut.inputKey);
         }
     }
 }
 private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
 {
     if (_mEditingBinding != null && !IsModifierKey(p.keycode))
     {
         p.Use();
         UIView.PopModal();
         var keycode  = p.keycode;
         var inputKey = p.keycode == KeyCode.Escape
                            ? _mEditingBinding.value
                            : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
         if (p.keycode == KeyCode.Backspace)
         {
             inputKey = SavedInputKey.Empty;
         }
         _mEditingBinding.value = inputKey;
         var uITextComponent = p.source as UITextComponent;
         uITextComponent.text     = _mEditingBinding.ToLocalizedString("KEYNAME");
         _mEditingBinding         = null;
         _mEditingBindingCategory = string.Empty;
     }
 }
Beispiel #10
0
        private void AddKeymapping(string label, SavedInputKey savedInputKey)
        {
            UIPanel  uiPanel  = this.component.AttachUIComponent(UITemplateManager.GetAsGameObject(UIOptionsKeymapping.kKeyBindingTemplate)) as UIPanel;
            UILabel  uiLabel  = uiPanel.Find <UILabel>("Name");
            UIButton uiButton = uiPanel.Find <UIButton>("Binding");

            uiButton.eventKeyDown   += new KeyPressHandler(this.OnBindingKeyDown);
            uiButton.eventMouseDown += new MouseEventHandler(this.OnBindingMouseDown);
            uiLabel.text             = label;
            uiButton.text            = savedInputKey.ToLocalizedString("KEYNAME");
            uiButton.objectUserData  = (object)savedInputKey;
        }
 private void RefreshKeyMapping()
 {
     foreach (UIComponent current in component.GetComponentsInChildren <UIComponent>())
     {
         UITextComponent uITextComponent = current.Find <UITextComponent>("Binding");
         SavedInputKey   savedInputKey   = (SavedInputKey)uITextComponent.objectUserData;
         if (this.m_EditingBinding != savedInputKey)
         {
             uITextComponent.text = savedInputKey.ToLocalizedString("KEYNAME");
         }
     }
 }
Beispiel #12
0
 private void RefreshKeyMapping()
 {
     UIComponent[] componentsInChildren = base.component.GetComponentsInChildren <UIComponent>();
     for (int i = 0; i < componentsInChildren.Length; i++)
     {
         UITextComponent uitextComponent = componentsInChildren[i].Find <UITextComponent>("Binding");
         SavedInputKey   savedInputKey   = (SavedInputKey)uitextComponent.objectUserData;
         if (m_EditingBinding != savedInputKey)
         {
             uitextComponent.text = savedInputKey.ToLocalizedString("KEYNAME");
         }
     }
 }
Beispiel #13
0
        /// <summary>
        /// Applies a valid key to our settings.
        /// </summary>
        /// <param name="key">InputKey to apply</param>
        private void ApplyKey(InputKey key)
        {
            // Apply key to current settings and save.
            ModSettings.CurrentHotkey = key;
            ModSettings.Save();

            // Set the label for the new hotkey.
            button.text = SavedInputKey.ToLocalizedString("KEYNAME", key);

            // Remove priming.
            UIView.PopModal();
            isPrimed = false;
        }
Beispiel #14
0
        private void AddKeymapping(string label, SavedInputKey savedInputKey)
        {
            var uIPanel = component.AttachUIComponent(UITemplateManager.GetAsGameObject(BindingTemplate)) as UIPanel;

            var uILabel  = uIPanel.Find <UILabel>("Name");
            var uIButton = uIPanel.Find <UIButton>("Binding");

            uIButton.eventKeyDown   += OnBindingKeyDown;
            uIButton.eventMouseDown += OnBindingMouseDown;

            uILabel.text            = label;
            uIButton.text           = savedInputKey.ToLocalizedString("KEYNAME");
            uIButton.objectUserData = savedInputKey;
        }
        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;
                    });
                }
            }
        }
        private void AddKeymapping(string label, Shortcut shortcut)
        {
            UIPanel uIPanel = component.AttachUIComponent(UITemplateManager.GetAsGameObject(kKeyBindingTemplate)) as UIPanel;

            uIPanel.name = "ShortcutItem";
            if (count++ % 2 == 1)
            {
                uIPanel.backgroundSprite = null;
            }

            UILabel  uILabel  = uIPanel.Find <UILabel>("Name");
            UIButton uIButton = uIPanel.Find <UIButton>("Binding");

            uIButton.eventClick += (c, p) =>
            {
                GUI.UIShortcutModal.instance.title    = "Edit Shortcut";
                GUI.UIShortcutModal.instance.shortcut = shortcut;

                UIView.PushModal(GUI.UIShortcutModal.instance);
                GUI.UIShortcutModal.instance.Show();
            };

            uILabel.text            = label;
            uIButton.text           = SavedInputKey.ToLocalizedString("KEYNAME", shortcut.inputKey);
            uIButton.objectUserData = shortcut;
            uIButton.stringUserData = "MoreShortcuts";

            UIButton delete = uIPanel.AddUIComponent <UIButton>();

            delete.atlas           = UIUtils.GetAtlas("Ingame");
            delete.normalBgSprite  = "buttonclose";
            delete.hoveredBgSprite = "buttonclosehover";
            delete.pressedBgSprite = "buttonclosepressed";
            delete.tooltip         = "Delete Shortcut";
            delete.eventClick     += (c, p) =>
            {
                ConfirmPanel.ShowModal("Delete Shortcut", "Are you sure you want to delete the [" + shortcut.name + "] shortcut?", (c2, ret) =>
                {
                    if (ret == 1)
                    {
                        Shortcut.RemoveShortcut(shortcut);
                        Shortcut.SaveShorcuts();
                        RefreshShortcutsList();
                    }
                });
            };

            delete.relativePosition = uIButton.relativePosition + new Vector3(uIButton.width + 10, 0);
        }
        private void UpdateKeyBinding(InputKey newKey, UIButton button, bool isMouseInput)
        {
            if (_editingBinding == null)
            {
                return;
            }

            _editingBinding.value = newKey;
            button.text           = _editingBinding.ToLocalizedString("KEYNAME");
            if (isMouseInput)
            {
                button.buttonsMask = UIMouseButton.Left;
            }
            _editingBinding = null;
        }
Beispiel #18
0
        /// <summary>
        /// Setup this control
        /// Called by Unity immediately before the first update.
        /// </summary>
        public void Start()
        {
            // Get the template from the game and attach it here.
            UIPanel uIPanel = component.AttachUIComponent(UITemplateManager.GetAsGameObject("KeyBindingTemplate")) as UIPanel;

            // Find our sub-components.
            label  = uIPanel.Find <UILabel>("Name");
            button = uIPanel.Find <UIButton>("Binding");

            // Attach our event handlers.
            button.eventKeyDown   += (control, keyEvent) => OnKeyDown(keyEvent);
            button.eventMouseDown += (control, mouseEvent) => OnMouseDown(mouseEvent);

            // Set label and button text.
            label.text  = Translations.Translate("BOB_OPT_KEY");
            button.text = SavedInputKey.ToLocalizedString("KEYNAME", ModSettings.CurrentHotkey);
        }
        private void AddKeymapping(string label, SavedInputKey savedInputKey)
        {
            UIPanel uIPanel = component.AttachUIComponent(UITemplateManager.GetAsGameObject(kKeyBindingTemplate)) as UIPanel;

            if (count++ % 2 == 1)
            {
                uIPanel.backgroundSprite = null;
            }

            UILabel  uILabel  = uIPanel.Find <UILabel>("Name");
            UIButton uIButton = uIPanel.Find <UIButton>("Binding");

            uIButton.eventKeyDown   += new KeyPressHandler(this.OnBindingKeyDown);
            uIButton.eventMouseDown += new MouseEventHandler(this.OnBindingMouseDown);

            uILabel.text            = label;
            uIButton.text           = savedInputKey.ToLocalizedString("KEYNAME");
            uIButton.objectUserData = savedInputKey;
        }
Beispiel #20
0
        internal void AddKeymapping(string label, SavedInputKey savedInputKey)
        {
            UIPanel uipanel = base.component.AttachUIComponent(UITemplateManager.GetAsGameObject(KeymappingsPanel.kKeyBindingTemplate)) as UIPanel;
            int     num     = count;

            count = num + 1;
            if (num % 2 == 1)
            {
                uipanel.backgroundSprite = null;
            }
            UILabel  uilabel  = uipanel.Find <UILabel>("Name");
            UIButton uibutton = uipanel.Find <UIButton>("Binding");

            uibutton.eventKeyDown   += OnBindingKeyDown;
            uibutton.eventMouseDown += OnBindingMouseDown;
            uilabel.text             = label;
            uibutton.text            = savedInputKey.ToLocalizedString("KEYNAME");
            uibutton.objectUserData  = savedInputKey;
        }
        private void Init()
        {
            if (shortcut == null)
            {
                return;
            }

            m_title.title              = title;
            m_name.text                = shortcut.name;
            m_componentName.text       = shortcut.component;
            m_componentName.tooltip    = string.Join(">", shortcut.path);
            m_binding.objectUserData   = new Shortcut(shortcut);
            m_binding.text             = SavedInputKey.ToLocalizedString("KEYNAME", shortcut.inputKey);
            m_binding.relativePosition = m_usePath.relativePosition - new Vector3(0, m_binding.height + 15);
            m_usePath.isChecked        = shortcut.usePath;
            m_onlyVisible.isChecked    = shortcut.onlyVisible;

            OptionsKeymapping.EditBinding(m_binding);
        }
 private void RefreshBindableInputs()
 {
     foreach (UIComponent current in component.GetComponentsInChildren <UIComponent>())
     {
         UITextComponent uITextComponent = current.Find <UITextComponent>("Binding");
         if (uITextComponent != null)
         {
             SavedInputKey savedInputKey = uITextComponent.objectUserData as SavedInputKey;
             if (savedInputKey != null)
             {
                 uITextComponent.text = savedInputKey.ToLocalizedString("KEYNAME");
             }
         }
         UILabel uILabel = current.Find <UILabel>("Name");
         if (uILabel != null)
         {
             uILabel.text = Locale.Get("KEYMAPPING", uILabel.stringUserData);
         }
     }
 }
Beispiel #23
0
 private void RefreshBindableInputs()
 {
     foreach (UIComponent componentsInChild in this.component.GetComponentsInChildren <UIComponent>())
     {
         UITextComponent uiTextComponent = componentsInChild.Find <UITextComponent>("Binding");
         if (uiTextComponent != null)
         {
             SavedInputKey objectUserData = uiTextComponent.objectUserData as SavedInputKey;
             if ((SavedValue)objectUserData != (SavedValue)null)
             {
                 uiTextComponent.text = objectUserData.ToLocalizedString("KEYNAME");
             }
         }
         UILabel uiLabel = componentsInChild.Find <UILabel>("Name");
         if (uiLabel != null)
         {
             uiLabel.text = ColossalFramework.Globalization.Locale.Get("KEYMAPPING", uiLabel.stringUserData);
         }
     }
 }
Beispiel #24
0
 private void RefreshBindableInputs()
 {
     foreach (UIComponent uicomponent in base.component.GetComponentsInChildren <UIComponent>())
     {
         UITextComponent uitextComponent = uicomponent.Find <UITextComponent>("Binding");
         if (uitextComponent != null)
         {
             SavedInputKey savedInputKey = uitextComponent.objectUserData as SavedInputKey;
             if (savedInputKey != null)
             {
                 uitextComponent.text = savedInputKey.ToLocalizedString("KEYNAME");
             }
         }
         UILabel uilabel = uicomponent.Find <UILabel>("Name");
         if (uilabel != null)
         {
             uilabel.text = uilabel.stringUserData;
         }
     }
 }
Beispiel #25
0
        /// <summary>
        /// Returns shortcut as a string in user's language. Modify for special handling.
        /// </summary>
        /// <param name="k">The key</param>
        /// <returns>The shortcut, example: "Ctrl + Alt + H"</returns>
        public static string ToLocalizedString(SavedInputKey k)
        {
            if (k.value == SavedInputKey.Empty)
            {
                return(Translation.Options.Get("Keybind:None"));
            }

            switch (k.Key)
            {
            case KeyCode.Mouse0:
                return(Translation.Options.Get("Shortcut:Click"));

            case KeyCode.Mouse1:
                return(Translation.Options.Get("Shortcut:RightClick"));

            case KeyCode.Mouse2:
                return(Translation.Options.Get("Shortcut:MiddleClick"));
            }

            return(k.ToLocalizedString("KEYNAME"));
        }
Beispiel #26
0
        internal UIComponent AddKeymapping(string label, SavedInputKey savedInputKey)
        {
            UIPanel uipanel = base.component.AttachUIComponent(UITemplateManager.GetAsGameObject(kKeyBindingTemplate)) as UIPanel;
            int     num     = this.count;

            this.count = num + 1;
            if (num % 2 == 1)
            {
                uipanel.backgroundSprite = null;
            }
            UILabel  uilabel  = uipanel.Find <UILabel>("Name");
            UIButton uibutton = uipanel.Find <UIButton>("Binding");

            uibutton.eventKeyDown          += this.OnBindingKeyDown;
            uibutton.eventMouseDown        += this.OnBindingMouseDown;
            uilabel.text                    = label;
            uibutton.text                   = savedInputKey.ToLocalizedString("KEYNAME");
            uibutton.objectUserData         = savedInputKey;
            uipanel.eventVisibilityChanged += (_, __) => RefreshBindableInputs();
            return(uibutton);
        }
        private void AddShortcut(int i, string name, SavedInputKey shortcut)
        {
            //Source: OptionsKeymappingPanel.CreateBindableInputs
            const string keyBindingTemplate = "KeyBindingTemplate";
            var          pnl = (UIPanel)this.AttachUIComponent(UITemplateManager.GetAsGameObject(keyBindingTemplate));

            if (i % 2 == 0)
            {
                pnl.backgroundSprite = string.Empty;
            }
            var lbl = pnl.Find <UILabel>("Name");

            lbl.text = name;

            var btn = pnl.Find <UIButton>("Binding");

            btn.objectUserData  = shortcut;
            btn.text            = shortcut.ToLocalizedString("KEYNAME");
            btn.eventKeyDown   += OnBindingKeyDown;
            btn.eventMouseDown += OnBindingMouseDown;
        }
        protected void AddKeymapping(string label, SavedInputKey savedInputKey, string legacySaveFileName)
        {
            savedInputKey.value = savedInputKey.value;
            UIPanel uIPanel = component.AttachUIComponent(UITemplateManager.GetAsGameObject(kKeyBindingTemplate)) as UIPanel;

            uIPanel.name = legacySaveFileName;
            if (count++ % 2 == 1)
            {
                uIPanel.backgroundSprite = null;
            }

            UILabel  uILabel  = uIPanel.Find <UILabel>("Name");
            UIButton uIButton = uIPanel.Find <UIButton>("Binding");

            uIButton.eventKeyDown   += new KeyPressHandler(this.OnBindingKeyDown);
            uIButton.eventMouseDown += new MouseEventHandler(this.OnBindingMouseDown);

            if (File.Exists(KeyBindingsManager.BindingsConfigPath))
            {
                var    lines = new List <string>(File.ReadAllLines(KeyBindingsManager.BindingsConfigPath));
                string line  = "########";
                foreach (string l in lines)
                {
                    if (l.Contains(legacySaveFileName))
                    {
                        line = l; break;
                    }
                }
                if (line != "########")
                {
                    lines.Remove(line);
                    KeyBindingsManager.RewriteCfgLines(lines);
                }
            }

            uILabel.text            = label;
            uIButton.text           = savedInputKey.ToLocalizedString("KEYNAME");
            uIButton.objectUserData = savedInputKey;
        }
Beispiel #29
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;
             });
         }
     }
 }
        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);
            }
        }