Esempio n. 1
0
        void clientListBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.None)
            return;

              var listBoxItem = sender as ListBoxItem;
              if (listBoxItem == null)
            return;

              var player = listBoxItem.Content as Player;
              if (player == null)
            return;

              var key = ((e.Key == Key.System) ? e.SystemKey : e.Key);
              var hasControl = Keyboard.Modifiers.HasFlag(ModifierKeys.Control) || (e.SystemKey == Key.LeftCtrl || e.SystemKey == Key.RightCtrl);
              var hasAlt = Keyboard.Modifiers.HasFlag(ModifierKeys.Alt) || (e.SystemKey == Key.LeftAlt || e.SystemKey == Key.RightAlt);
              var hasShift = Keyboard.Modifiers.HasFlag(ModifierKeys.Shift) || (e.SystemKey == Key.LeftShift || e.SystemKey == Key.RightShift);
              var hasWindows = Keyboard.Modifiers.HasFlag(ModifierKeys.Windows);
              var isFunctionKey = Hotkey.IsFunctionKey(key);

              if (key == Key.LeftCtrl || key == Key.RightCtrl)
            return;

              if (key == Key.LeftAlt || e.Key == Key.RightAlt)
            return;

              if (key == Key.LeftShift || e.Key == Key.RightShift)
            return;

              if (!hasControl && !hasAlt && !hasShift && !isFunctionKey)
              {
            if (e.Key == Key.Delete || e.Key == Key.Back || e.Key == Key.Escape)
            {
              if (player.Hotkey != null)
            HotkeyManager.Instance.UnregisterHotkey(windowSource.Handle, player.Hotkey);

              player.Hotkey = null;
            }
            return;
              }

              var modifiers = ModifierKeys.None;

              if (hasControl)
            modifiers |= ModifierKeys.Control;
              if (hasAlt)
            modifiers |= ModifierKeys.Alt;
              if (hasShift)
            modifiers |= ModifierKeys.Shift;
              if (hasWindows)
            modifiers |= ModifierKeys.Windows;

              var hotkey = new Hotkey(modifiers, key);
              var oldHotkey = HotkeyManager.Instance.GetHotkey(hotkey.Key, hotkey.Modifiers);

              if (oldHotkey != null)
              {
            foreach (var p in PlayerManager.Instance.Players)
            {
              if (!p.HasHotkey)
            continue;

              if (p.Hotkey.Key == hotkey.Key && p.Hotkey.Modifiers == hotkey.Modifiers)
            p.Hotkey = null;
            }
              }

              HotkeyManager.Instance.UnregisterHotkey(windowSource.Handle, hotkey);

              if (!HotkeyManager.Instance.RegisterHotkey(windowSource.Handle, hotkey))
              {
            this.ShowMessageBox("Set Hotkey Error",
               "There was an error setting the hotkey, please try again.",
               "If this continues, try restarting the application.",
               MessageBoxButton.OK,
               420, 240);
              }
              else
              {
            if (player.Hotkey != null)
              HotkeyManager.Instance.UnregisterHotkey(windowSource.Handle, player.Hotkey);

            player.Hotkey = hotkey;
              }

              e.Handled = true;
        }
Esempio n. 2
0
        public void ImportMacroState(Player player, SavedMacroState state)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }

            if (state == null)
            {
                throw new ArgumentNullException("state");
            }

            var macro = GetMacroState(player);

            if (macro == null)
            {
                return;
            }

            macro.Stop();

            var process = Process.GetCurrentProcess();

            if (player.HasHotkey)
            {
                HotkeyManager.Instance.UnregisterHotkey(process.MainWindowHandle, player.Hotkey);
                player.Hotkey = null;
            }

            player.Skillbook.ClearActiveSkills();
            macro.ClearSpellQueue();
            macro.ClearFlowerQueue();

            player.Update(PlayerFieldFlags.Spellbook);
            macro.UseLyliacVineyard         = player.HasLyliacVineyard && state.UseLyliacVineyard;
            macro.FlowerAlternateCharacters = player.HasLyliacPlant && state.FlowerAlternateCharacters;

            player.Update(PlayerFieldFlags.Skillbook);
            foreach (var skill in state.Skills)
            {
                if (!player.Skillbook.ContainSkill(skill.SkillName))
                {
                    continue;
                }

                player.Skillbook.ToggleActive(skill.SkillName, true);
            }

            foreach (var spell in state.Spells)
            {
                if (!player.Spellbook.ContainSpell(spell.SpellName))
                {
                    continue;
                }

                var spellInfo = player.Spellbook.GetSpell(spell.SpellName);
                if (spellInfo == null)
                {
                    continue;
                }

                var queueItem = new SpellQueueItem(spellInfo, spell);
                macro.AddToSpellQueue(queueItem);
            }

            if (player.HasLyliacPlant)
            {
                foreach (var flower in state.Flowers)
                {
                    if (flower.TargetMode == TargetCoordinateUnits.None)
                    {
                        continue;
                    }

                    var queueItem = new FlowerQueueItem(flower);
                    macro.AddToFlowerQueue(queueItem);
                }
            }

            var windowHandle = Process.GetCurrentProcess().MainWindowHandle;

            if (state.HotkeyKey != Key.None && (state.HotkeyModifiers != ModifierKeys.None || Hotkey.IsFunctionKey(state.HotkeyKey)))
            {
                var hotkey = new Hotkey(state.HotkeyModifiers, state.HotkeyKey);

                if (HotkeyManager.Instance.RegisterHotkey(windowHandle, hotkey))
                {
                    player.Hotkey = hotkey;
                }
            }
        }
Esempio n. 3
0
        public void ImportMacroState(Player player, SavedMacroState state)
        {
            if (player == null)
            throw new ArgumentNullException("player");

              if (state == null)
            throw new ArgumentNullException("state");

              var macro = GetMacroState(player);
              if (macro == null)
            return;

              macro.Stop();

              var process = Process.GetCurrentProcess();

              if (player.HasHotkey)
              {
            HotkeyManager.Instance.UnregisterHotkey(process.MainWindowHandle, player.Hotkey);
            player.Hotkey = null;
              }

              player.Skillbook.ClearActiveSkills();
              macro.ClearSpellQueue();
              macro.ClearFlowerQueue();

              player.Update(PlayerFieldFlags.Spellbook);
              macro.UseLyliacVineyard = player.HasLyliacVineyard && state.UseLyliacVineyard;
              macro.FlowerAlternateCharacters = player.HasLyliacPlant && state.FlowerAlternateCharacters;

              player.Update(PlayerFieldFlags.Skillbook);
              foreach (var skill in state.Skills)
              {
            if (!player.Skillbook.ContainSkill(skill.SkillName))
              continue;

            player.Skillbook.ToggleActive(skill.SkillName, true);
              }

              foreach (var spell in state.Spells)
              {
            if (!player.Spellbook.ContainSpell(spell.SpellName))
              continue;

            var spellInfo = player.Spellbook.GetSpell(spell.SpellName);
            if (spellInfo == null)
              continue;

            var queueItem = new SpellQueueItem(spellInfo, spell);
            macro.AddToSpellQueue(queueItem);
              }

              if (player.HasLyliacPlant)
            foreach (var flower in state.Flowers)
            {
              if (flower.TargetMode == TargetCoordinateUnits.None)
            continue;

              var queueItem = new FlowerQueueItem(flower);
              macro.AddToFlowerQueue(queueItem);
            }

              var windowHandle = Process.GetCurrentProcess().MainWindowHandle;

              if (state.HotkeyKey != Key.None && (state.HotkeyModifiers != ModifierKeys.None || Hotkey.IsFunctionKey(state.HotkeyKey)))
              {
            var hotkey = new Hotkey(state.HotkeyModifiers, state.HotkeyKey);

            if (HotkeyManager.Instance.RegisterHotkey(windowHandle, hotkey))
              player.Hotkey = hotkey;
              }
        }