Esempio n. 1
0
        public static KeyData Add(HKCategory cat, HKSubCat sub, int name, HotKeyCallback callback)
        {
            KeyData kd = new KeyData(name, cat, sub, callback);

            m_List.Add(kd);
            return(kd);
        }
Esempio n. 2
0
        public static KeyData Add(HKCategory cat, HKSubCat sub, string name, HotKeyCallbackState callback, object state)
        {
            KeyData kd = new KeyData(name, cat, sub, callback, state);

            m_List.Add(kd);
            return(kd);
        }
Esempio n. 3
0
        public static void Save(XmlTextWriter xml)
        {
            for (int i = 0; i < m_List.Count; i++)
            {
                KeyData k = (KeyData)m_List[i];
                if (k.Key != 0)
                {
                    xml.WriteStartElement("key");
                    xml.WriteAttributeString("mod", ((int)k.Mod).ToString());
                    xml.WriteAttributeString("key", k.Key.ToString());
                    xml.WriteAttributeString("send", k.SendToUO.ToString());

                    //xml.WriteAttributeString( "name", ((int)k.LocName).ToString() );
                    if (k.LocName != 0)
                    {
                        xml.WriteString("L:" + k.LocName.ToString());
                    }
                    else
                    {
                        xml.WriteString(k.StrName); //xml.WriteAttributeString( "name", k.StrName );
                    }
                    xml.WriteEndElement();
                }
            }
        }
Esempio n. 4
0
        public static void Initialize()
        {
            m_HK_En = Add(HKCategory.None, LocString.ToggleHKEnable, new HotKeyCallback(OnToggleEnableDisable));

            _hotKeyEnableToggle  = Add(HKCategory.None, LocString.EnableHotkeys, OnToggleEnable);
            _hotKeyDisableToggle = Add(HKCategory.None, LocString.DisableHotkeys, OnToggleDisable);
        }
Esempio n. 5
0
        public static void Load(XmlElement xml)
        {
            if (xml == null)
            {
                return;
            }

            ClearAll();

            foreach (XmlElement el in xml.GetElementsByTagName("key"))
            {
                try
                {
                    string name = el.GetAttribute("name");
                    string loc  = el.GetAttribute("loc");
                    string mod  = el.GetAttribute("mod");
                    string key  = el.GetAttribute("key");
                    string send = el.GetAttribute("send");

                    KeyData k = null;

                    if (loc != null && loc.Length > 0)
                    {
                        k = Get(Convert.ToInt32(loc));
                    }
                    else if (name != null && name.Length > 0)
                    {
                        k = Get(name);
                    }
                    else if (el.InnerText != null && el.InnerText.Length > 1)
                    {
                        if (el.InnerText[0] == 'L' && el.InnerText[1] == ':')
                        {
                            try
                            {
                                k = Get(Convert.ToInt32(el.InnerText.Substring(2)));
                            }
                            catch
                            {
                            }
                        }
                        else
                        {
                            k = Get(el.InnerText);
                        }
                    }

                    if (k != null)
                    {
                        k.Mod      = (ModKeys)Convert.ToInt32(mod);
                        k.Key      = Convert.ToInt32(key);
                        k.SendToUO = Convert.ToBoolean(send);
                    }
                }
                catch
                {
                }
            }
        }
Esempio n. 6
0
        public static void OnMouse(int button, int wheel)
        {
            if (World.Player == null || !m_Enabled)
            {
                return;
            }

            ModKeys cur = ModKeys.None;
            int     key = 0;

            switch (button)
            {
            case 0:
                if (wheel == 1)
                {
                    // Wheel down
                    key = -2;
                }
                else
                {
                    // Wheel up
                    key = -1;
                }
                break;

            case 1:
                key = -3;
                break;

            case 2:
                key = -4;
                break;

            case 3:
                key = -5;
                break;
            }

            if (KeyDown(Keys.ControlKey))
            {
                cur |= ModKeys.Control;
            }
            if (KeyDown(Keys.Menu))
            {
                cur |= ModKeys.Alt;
            }
            if (KeyDown(Keys.ShiftKey))
            {
                cur |= ModKeys.Shift;
            }

            KeyData hk = Get(key, cur);

            if (hk != null)
            {
                hk.Callback();
            }
        }
Esempio n. 7
0
 public static void ClearAll()
 {
     for (int i = 0; i < m_List.Count; i++)
     {
         KeyData kd = m_List[i];
         kd.Key      = 0;
         kd.Mod      = ModKeys.None;
         kd.SendToUO = false;
     }
 }
Esempio n. 8
0
 public static KeyData Get(int key, ModKeys mod)
 {
     for (int i = 0; i < m_List.Count; i++)
     {
         KeyData hk = (KeyData)m_List[i];
         if (hk.Key == key && hk.Mod == mod && hk.Key != 0)
         {
             return(hk);
         }
     }
     return(null);
 }
Esempio n. 9
0
        public static bool OnKeyDown(int key)
        {
            if (World.Player == null)
            {
                return(true);
            }

            ModKeys cur = ModKeys.None;

            if (KeyDown(Keys.ControlKey))
            {
                cur |= ModKeys.Control;
            }
            if (KeyDown(Keys.Menu))
            {
                cur |= ModKeys.Alt;
            }
            if (KeyDown(Keys.ShiftKey))
            {
                cur |= ModKeys.Shift;
            }

            if (m_HK_En != null && m_HK_En.Key > 0 && m_HK_En.Mod == cur && (m_HK_En.Key == key || KeyDown((Keys)m_HK_En.Key)))
            {
                m_HK_En.Callback();
                return(m_HK_En.SendToUO);
            }

            if (m_Enabled)
            {
                for (int i = 0; i < m_List.Count; i++)
                {
                    KeyData hk = (KeyData)m_List[i];
                    if (hk.Mod == cur && hk.Key > 0)
                    {
                        if (hk.Key == key || KeyDown((Keys)hk.Key))
                        {
                            if (Macros.MacroManager.AcceptActions)
                            {
                                Macros.MacroManager.Action(new Macros.HotKeyAction(hk));
                            }
                            hk.Callback();
                            return(hk.SendToUO);
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 10
0
        public static string UpdateStatus()
        {
            KeyData kd = Get((int)LocString.ToggleHKEnable);
            string  ks = null;

            if (kd != null)
            {
                ks = kd.KeyString();
            }

            string msg;

            if (ks != null)
            {
                if (m_Enabled)
                {
                    msg = Language.Format(LocString.HKEnabledPress, ks);
                }
                else
                {
                    msg = Language.Format(LocString.HKDisabledPress, ks);
                }
            }
            else
            {
                if (m_Enabled)
                {
                    msg = Language.GetString(LocString.HKEnabled);
                }
                else
                {
                    msg = Language.GetString(LocString.HKDisabled);
                }
            }

            m_Status?.SafeAction(s =>
            {
                s.Text = msg;
            });

            return(msg);
        }
Esempio n. 11
0
        public static bool Remove(string name)
        {
            if (name == null)
            {
                return(false);
            }

            for (int i = 0; i < m_List.Count; i++)
            {
                KeyData hk = (KeyData)m_List[i];
                if (hk.StrName == name)
                {
                    hk.Remove();
                    m_List.RemoveAt(i);
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 12
0
        public static bool OnKeyDown(int key, ModKeys mod)
        {
            if (World.Player == null)
            {
                return(true);
            }
            ModKeys cur = mod;

            if (KeyDown(Keys.ControlKey))
            {
                cur |= ModKeys.Control;
            }
            if (KeyDown(Keys.Menu))
            {
                cur |= ModKeys.Alt;
            }
            if (KeyDown(Keys.ShiftKey))
            {
                cur |= ModKeys.Shift;
            }

            if (m_HK_En != null && m_HK_En.Key > 0 && m_HK_En.Mod == cur &&
                (m_HK_En.Key == key || KeyDown((Keys)m_HK_En.Key)))
            {
                m_HK_En.Callback();
                return(m_HK_En.SendToUO);
            }

            if (_hotKeyEnableToggle != null && _hotKeyEnableToggle.Key > 0 && _hotKeyEnableToggle.Mod == cur &&
                (_hotKeyEnableToggle.Key == key || KeyDown((Keys)_hotKeyEnableToggle.Key)))
            {
                _hotKeyEnableToggle.Callback();
                return(_hotKeyEnableToggle.SendToUO);
            }

            if (_hotKeyDisableToggle != null && _hotKeyDisableToggle.Key > 0 && _hotKeyDisableToggle.Mod == cur &&
                (_hotKeyDisableToggle.Key == key || KeyDown((Keys)_hotKeyDisableToggle.Key)))
            {
                _hotKeyDisableToggle.Callback();
                return(_hotKeyDisableToggle.SendToUO);
            }

            if (m_Enabled)
            {
                for (int i = 0; i < m_List.Count; i++)
                {
                    KeyData hk = (KeyData)m_List[i];
                    if (hk.Mod == cur && hk.Key > 0)
                    {
                        if (hk.Key == key)
                        {
                            if (Macros.MacroManager.AcceptActions)
                            {
                                Macros.MacroManager.Action(new Macros.HotKeyAction(hk));
                            }

                            ScriptManager.AddToScript($"hotkey '{hk.DispName}'");

                            hk.Callback();
                            return(hk.SendToUO);
                        }
                    }
                }

                // if pressed key didn't match a hotkey, check for any key currently down
                for (int i = 0; i < m_List.Count; i++)
                {
                    KeyData hk = (KeyData)m_List[i];
                    if (hk.Mod == cur && hk.Key > 0)
                    {
                        if (KeyDown((Keys)hk.Key))
                        {
                            if (Macros.MacroManager.AcceptActions)
                            {
                                Macros.MacroManager.Action(new Macros.HotKeyAction(hk));
                            }

                            ScriptManager.AddToScript($"hotkey '{hk.DispName}'");

                            hk.Callback();
                            return(hk.SendToUO);
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 13
0
 public static void Initialize()
 {
     m_HK_En = Add(HKCategory.None, LocString.ToggleHKEnable, new HotKeyCallback(OnToggleEnable));
 }
Esempio n. 14
0
 public static KeyData Add( HKCategory cat, HKSubCat sub, string name, HotKeyCallbackState callback, object state )
 {
     KeyData kd = new KeyData( name, cat, sub, callback, state );
     m_List.Add( kd );
     return kd;
 }
Esempio n. 15
0
 public static KeyData Add( HKCategory cat, HKSubCat sub, LocString name, HotKeyCallback callback )
 {
     KeyData kd = new KeyData( (int)name, cat, sub, callback );
     m_List.Add( kd );
     return kd;
 }
Esempio n. 16
0
        private static void TargetResponse(PacketReader p, PacketHandlerEventArgs args)
        {
            TargetInfo info = new TargetInfo
            {
                Type   = p.ReadByte(),
                TargID = p.ReadUInt32(),
                Flags  = p.ReadByte(),
                Serial = p.ReadUInt32(),
                X      = p.ReadUInt16(),
                Y      = p.ReadUInt16(),
                Z      = p.ReadInt16(),
                Gfx    = p.ReadUInt16()
            };

            m_ClientTarget = false;

            OverheadTargetMessage(info);

            // check for cancel
            if (info.X == 0xFFFF && info.X == 0xFFFF && (info.Serial <= 0 || info.Serial >= 0x80000000))
            {
                m_HasTarget      = false;
                m_FromGrabHotKey = false;

                if (m_Intercept)
                {
                    args.Block = true;
                    Timer.DelayedCallbackState(TimeSpan.Zero, m_OneTimeRespCallback, info).Start();
                    EndIntercept();

                    if (m_PreviousID != 0)
                    {
                        m_CurrentID   = m_PreviousID;
                        m_AllowGround = m_PreviousGround;
                        m_CurFlags    = m_PrevFlags;

                        m_PreviousID = 0;

                        ResendTarget();
                    }
                }
                else if (m_FilterCancel.Contains((uint)info.TargID) || info.TargID == LocalTargID)
                {
                    args.Block = true;
                }

                m_FilterCancel.Clear();
                return;
            }

            ClearQueue();

            if (m_Intercept)
            {
                if (info.TargID == LocalTargID)
                {
                    Timer.DelayedCallbackState(TimeSpan.Zero, m_OneTimeRespCallback, info).Start();

                    m_HasTarget      = false;
                    m_FromGrabHotKey = false;
                    args.Block       = true;

                    if (m_PreviousID != 0)
                    {
                        m_CurrentID   = m_PreviousID;
                        m_AllowGround = m_PreviousGround;
                        m_CurFlags    = m_PrevFlags;

                        m_PreviousID = 0;

                        ResendTarget();
                    }

                    m_FilterCancel.Clear();

                    return;
                }
                else
                {
                    EndIntercept();
                }
            }

            m_HasTarget = false;

            if (CheckHealPoisonTarg(m_CurrentID, info.Serial))
            {
                ResendTarget();
                args.Block = true;
            }

            if (info.Serial != World.Player.Serial)
            {
                if (info.Serial.IsValid)
                {
                    // only let lasttarget be a non-ground target

                    m_LastTarget = info;
                    if (info.Flags == 1)
                    {
                        m_LastHarmTarg = info;
                    }
                    else if (info.Flags == 2)
                    {
                        m_LastBeneTarg = info;
                    }

                    LastTargetChanged();
                    LastBeneficialTargetChanged();
                    LastHarmfulTargetChanged();
                }

                m_LastGroundTarg = info; // ground target is the true last target

                if (Macros.MacroManager.AcceptActions)
                {
                    MacroManager.Action(new AbsoluteTargetAction(info));
                }
            }
            else
            {
                if (Macros.MacroManager.AcceptActions)
                {
                    KeyData hk = HotKey.Get((int)LocString.TargetSelf);
                    if (hk != null)
                    {
                        MacroManager.Action(new HotKeyAction(hk));
                    }
                    else
                    {
                        MacroManager.Action(new AbsoluteTargetAction(info));
                    }
                }
            }

            if (World.Player.LastSpell == 52 && !GateTimer.Running)
            {
                GateTimer.Start();
            }

            m_FilterCancel.Clear();
        }
Esempio n. 17
0
 public static void Initialize()
 {
     m_HK_En = Add( HKCategory.None, LocString.ToggleHKEnable, new HotKeyCallback( OnToggleEnable ) );
 }