Esempio n. 1
0
        public HotkeyListScreen(Game game) : base(game)
        {
            titleText = "Modify hotkeys";
            HotkeyList hotkeys = game.Input.Hotkeys;
            int        count   = hotkeys.Hotkeys.Count;

            entries = new string[hotkeys.Hotkeys.Count + items];

            for (int i = 0; i < count; i++)
            {
                Hotkey hKey = hotkeys.Hotkeys[i];
                entries[i] = hKey.BaseKey + " |" + MakeFlagsString(hKey.Flags);
            }
            for (int i = 0; i < items; i++)
            {
                entries[count + i] = "-----";
            }
        }
Esempio n. 2
0
        void SaveChangesClick(Game game, Widget widget)
        {
            if (origHotkey.Trigger != Key.None)
            {
                HotkeyList.Remove(origHotkey.Trigger, origHotkey.Flags);
                HotkeyList.UserRemovedHotkey(origHotkey.Trigger, origHotkey.Flags);
            }
            MenuInputWidget input = (MenuInputWidget)widgets[actionI];

            if (curHotkey.Trigger != Key.None)
            {
                HotkeyList.Add(curHotkey.Trigger, curHotkey.Flags,
                               input.Text.ToString(), curHotkey.StaysOpen);
                HotkeyList.UserAddedHotkey(curHotkey.Trigger, curHotkey.Flags,
                                           curHotkey.StaysOpen, input.Text.ToString());
            }
            game.Gui.SetNewScreen(new HotkeyListScreen(game));
        }
        void HandleHotkey(Key key)
        {
            string text;
            bool   more;

            if (!HotkeyList.IsHotkey(key, game.Input, out text, out more))
            {
                return;
            }

            if (!more)
            {
                game.Chat.Send(text, false);
            }
            else if (game.Gui.activeScreen == null)
            {
                game.Gui.hudScreen.OpenInput(text);
            }
        }
Esempio n. 4
0
        private void UpdateHotkeyList()
        {
            HotkeyList.BeginUpdate();
            var idx = HotkeyList.SelectedIndices.Count == 0 ? 0 : HotkeyList.SelectedIndices[0];

            HotkeyList.Items.Clear();
            foreach (var hotkey in _hotkeys.OrderBy(x => x.ID))
            {
                var def = Hotkeys.GetHotkeyDefinition(hotkey.ID);
                HotkeyList.Items.Add(new ListViewItem(new[]
                {
                    def.Name,
                    def.Description,
                    String.IsNullOrWhiteSpace(hotkey.HotkeyString)
                                                                  ? "<unassigned>"
                                                                  : hotkey.HotkeyString
                })
                {
                    Tag = hotkey
                });
            }
            HotkeyList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            if (idx >= 0 && idx < HotkeyList.Items.Count)
            {
                HotkeyList.Items[idx].Selected = true;
            }
            HotkeyList.EndUpdate();

            HotkeyActionList.BeginUpdate();
            idx = HotkeyActionList.SelectedIndex;
            HotkeyActionList.Items.Clear();
            foreach (var def in Hotkeys.GetHotkeyDefinitions().OrderBy(x => x.ID))
            {
                HotkeyActionList.Items.Add(def);
            }
            if (idx < 0 || idx >= HotkeyActionList.Items.Count)
            {
                idx = 0;
            }
            HotkeyActionList.SelectedIndex = idx;
            HotkeyActionList.EndUpdate();
        }
        public HotkeyStatus RegisterHotkey(Keys hotkey, Action hotkeyPress = null, int tag = 0)
        {
            KeyInfo keyInfo = new KeyInfo(hotkey);

            if (keyInfo.KeyCode == Keys.None)
            {
                return(HotkeyStatus.NotConfigured);
            }

            if (IsHotkeyExist(hotkey))
            {
                DebugHelper.WriteLine("Hotkey already exist: " + keyInfo);
                return(HotkeyStatus.Failed);
            }

            string atomName = Thread.CurrentThread.ManagedThreadId.ToString("X8") + (int)hotkey;

            ushort id = NativeMethods.GlobalAddAtom(atomName);

            if (id == 0)
            {
                DebugHelper.WriteLine("Unable to generate unique hotkey ID. Error code: " + Marshal.GetLastWin32Error());
                return(HotkeyStatus.Failed);
            }

            if (!NativeMethods.RegisterHotKey(Handle, (int)id, (uint)keyInfo.ModifiersEnum, (uint)keyInfo.KeyCode))
            {
                NativeMethods.GlobalDeleteAtom(id);
                DebugHelper.WriteLine("Unable to register hotkey: {0}\r\nError code: {1}", keyInfo, Marshal.GetLastWin32Error());
                return(HotkeyStatus.Failed);
            }

            HotkeyInfo hotkeyInfo = new HotkeyInfo(id, hotkey, hotkeyPress, tag);

            HotkeyList.Add(hotkeyInfo);

            return(HotkeyStatus.Registered);
        }
 public EditHotkeyScreen(Game game, Hotkey original) : base(game)
 {
     hotkeys    = game.InputHandler.Hotkeys;
     origHotkey = original;
     curHotkey  = original;
 }
Esempio n. 7
0
 public HotkeyScreen(Game game) : base(game)
 {
     hotkeys = game.InputHandler.Hotkeys;
 }
 public HotkeyInfo GetHotkeyInfoFromID(ushort id)
 {
     return(HotkeyList.FirstOrDefault(x => x.ID == id));
 }
 public HotkeyInfo GetHotkeyInfoFromTag(int tag)
 {
     return(HotkeyList.FirstOrDefault(x => x.Tag == tag));
 }
 public HotkeyInfo GetHotkeyInfoFromKey(Keys key)
 {
     return(HotkeyList.FirstOrDefault(x => x.Key == key));
 }
 public bool IsHotkeyExist(Keys key)
 {
     return(HotkeyList.Any(x => x.Key == key));
 }