Пример #1
0
        public void Register(string name, string source, Func <float, InputManager, Keys[], int, bool> func)
        {
            List <List <Keys> > stroke = new List <List <Keys> >();
            // try to get strokes from Profile, throw error if not found or if could not translate to strokes
            HotkeySave prof = FindInProfile(name, source);

            if (prof == null)
            {
                //ConsoleManager.Log(eLogType.ERROR, "HotkeyManager", "Failed to find binding for '" + name + "' from '" + source + "'.", null);
                stroke.Add(new List <Keys>());
                // make default profile
                Profile.Add(new HotkeySave(name, source, new List <string>()
                {
                    ""
                }));
            }
            else
            {
                try
                {
                    stroke = prof.GetStroke();
                }
                catch (Exception e)
                {
                    if (ErrorLogCallback != null)
                    {
                        ErrorLogCallback("Failed to read binding for '" + name + "' from '" + source + "': " + e.Message);
                    }
                    stroke.Add(new List <Keys>());
                }
            }
            for (int i = 0; i < stroke.Count; i++)
            {
                stroke[i] = SortKeys(stroke[i]);
            }
            foreach (List <Keys> s in stroke)
            {
                if (s.Count <= 0)
                {
                    continue; // skip empty hotkeys...
                }
                AddStroke(s.ToArray(), s.Count, new HotkeyResult(name, source));
            }

            // add function
            if (!HotkeyFunctions.ContainsKey(source))
            {
                HotkeyFunctions.Add(source, new Dictionary <string, Func <float, InputManager, Keys[], int, bool> >());
            }
            Dictionary <string, Func <float, InputManager, Keys[], int, bool> > innerHotkeyFunctions = HotkeyFunctions[source];

            if (!innerHotkeyFunctions.ContainsKey(name))
            {
                innerHotkeyFunctions.Add(name, func);
            }
            else
            {
                innerHotkeyFunctions[name] = func;
            }
        }
Пример #2
0
        public HotkeySave FindInProfile(string name, string source)
        {
            HotkeySave found = null;

            foreach (HotkeySave h in Profile)
            {
                if (h.Name == name && h.Source == source)
                {
                    found = h;
                    break;
                }
            }
            return(found);
        }
Пример #3
0
        public List <HotkeySave> MergeHotkeySaves(List <HotkeySave> lista, List <HotkeySave> listb)
        {
            // note: listb takes priority
            List <HotkeySave> results = new List <HotkeySave>();

            for (int i = 0; i < lista.Count; i++)
            {
                HotkeySave    hs     = lista[i];
                List <string> stroke = new List <string>();
                stroke.AddRange(hs.Stroke);
                results.Add(new HotkeySave(hs.Name, hs.Source, stroke));
            }

            for (int i = 0; i < listb.Count; i++)
            {
                HotkeySave hs    = listb[i];
                bool       found = false;
                for (int o = 0; o < results.Count; o++)
                {
                    if (results[o].Source == hs.Source &&
                        results[o].Name == hs.Name)
                    {
                        results[o].Stroke.Clear();
                        results[o].Stroke.AddRange(hs.Stroke);
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    List <string> stroke = new List <string>();
                    stroke.AddRange(hs.Stroke);
                    results.Add(new HotkeySave(hs.Name, hs.Source, stroke));
                }
            }

            return(results);
        }