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 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);
        }