Ejemplo n.º 1
0
            /// <param name="kb">check if this key bind is being triggered</param>
            /// <param name="list">where to mark if this is indeed triggered</param>
            /// <param name="additionalFilter">an additional gate that might prevent this particluar keybind from triggering. possibly heavy method, so only checked if the key is triggered</param>
            bool KeyCheck(KBind kb, List <KeyTrigger> list, Func <KBind, bool> additionalFilter = null)
            {
                KCombo kp = trigger.Invoke(kb);

                if (kp != null && (additionalFilter == null || !additionalFilter.Invoke(kb)))
                {
                    //Debug.Log("triggered: " + kp + " -> " + kb.name);
                    list.Add(new KeyTrigger {
                        kb = kb, kp = kp
                    });
                    return(true);
                }
                return(false);
            }
Ejemplo n.º 2
0
        public bool IsValueChanged()
        {
            bool isAllowed = modifiers == null || modifiers.Length == 0 || KCombo.IsSatisfiedHeld(modifiers);

            if (!isAllowed)
            {
                if (!stickyInput)
                {
                    cachedValue = 0;
                }
            }
            else
            {
                cachedValue = filteredValue ? GetValue() : GetValueRaw();
            }
            return(cachedValue != knownValue);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// describes functions to execute when a specific key-combination is pressed/held/released
 /// </summary>
 public KBind(KCombo kCombo, string name  = null, Func <bool> onPressEvent          = null, Func <bool> onHoldEvent = null,
              Func <bool> onReleaseEvent  = null, Func <bool> additionalRequirement = null,
              bool eventAlwaysTriggerable = false, EventBind pressFunc              = null, EventBind holdFunc = null, EventBind releaseFunc = null)
     : this(new[] { kCombo }, name, onPressEvent, onHoldEvent, onReleaseEvent, additionalRequirement, eventAlwaysTriggerable, pressFunc, holdFunc, releaseFunc)
 {
 }
Ejemplo n.º 4
0
            /// <param name="kBind"></param>
            /// <param name="kind"></param>
            /// <returns></returns>
            public bool UpdateKeyBinding(KBind kBind, KBindChange kind)
            {
                if (kind == KBindChange.Add && putInList != null && !putInList.Invoke(kBind))
                {
                    return(false);
                }
                bool changeHappened = false;
                int  index          = allKeyBindings.IndexOf(kBind);       // TODO get index from sorted list with IList extension?

                switch (kind)
                {
                case KBindChange.Add:
                    if (index >= 0)
                    {
                        Show.Log("already added " + name + " " + kBind.name + "?");
                    }
                    if (index < 0)
                    {
                        allKeyBindings.Add(kBind); allKeyBindings.Sort();                         // TODO insert sorted in IList extension?
                        for (int i = 0; i < kBind.keyCombinations.Length; ++i)
                        {
                            KCombo kCombo = kBind.keyCombinations[i];
                            if (!bindingsByKey.TryGetValue(kCombo.key, out List <KBindTrigger> kBinds))
                            {
                                kBinds = new List <KBindTrigger>();
                                bindingsByKey[kCombo.key] = kBinds;
                            }
                            kBinds.Add(new KBindTrigger {
                                kCombo = kCombo, kBind = kBind
                            }); kBinds.Sort();                                                                                          // TODO insert sorted in IList extension?
                        }
                        changeHappened = true;
                        //Log($"added {name} {kBind.name}");
                    }
                    else
                    {
                        if (index >= 0)
                        {
                            Show.Log("will not add duplicate " + name + " " + kBind.name);
                        }
                    }
                    break;

                case KBindChange.Remove:
                    if (index >= 0)
                    {
                        allKeyBindings.RemoveAt(index); changeHappened = true;
                        for (int i = 0; i < kBind.keyCombinations.Length; ++i)
                        {
                            KCombo kCombo = kBind.keyCombinations[i];
                            if (bindingsByKey.TryGetValue(kCombo.key, out List <KBindTrigger> kBinds))
                            {
                                int subIndex = kBinds.FindIndex(k => k.kBind == kBind);                                 // TODO get index from sorted list with IList extension?
                                kBinds.RemoveAt(subIndex);
                            }
                        }
                    }
                    break;

                case KBindChange.Update:
                    throw new Exception("Update is composed of a Remove and Add, should never be called directly like this.");
                }
                return(changeHappened);
            }
Ejemplo n.º 5
0
        public string CalcualteCurrentKeyBindText()
        {
            EnsureInitializedKeyBinding();
            StringBuilder sb = new StringBuilder();

            for (int s = 0; s < keyBindGroups.Length; ++s)
            {
                KBindGroup ks = keyBindGroups[s];
                if (ks.allKeyBindings.Count == 0)
                {
                    continue;
                }
                sb.Append("[" + ks.name + "]\n");
                for (int i = 0; i < ks.allKeyBindings.Count; ++i)
                {
                    KBind kb            = ks.allKeyBindings[i];
                    bool  needsPriority = true;
                    bool  hasKeys       = true;
                    if (kb.keyCombinations.Length != 0 && (kb.keyCombinations.Length != 1 || kb.keyCombinations[0].key != KCode.None))
                    {
                        KCombo theseKeys = kb.keyCombinations[0];
                        bool   hasPrev   = i > 0;
                        bool   hasNext   = i < ks.allKeyBindings.Count - 1;
                        KBind  prev      = (hasPrev) ? ks.allKeyBindings[i - 1] : null;
                        KBind  next      = (hasNext) ? ks.allKeyBindings[i + 1] : null;
                        KCombo prevKeys  = hasPrev && prev.keyCombinations.Length > 0 ? prev.keyCombinations[0] : null;
                        KCombo nextKeys  = hasNext && next.keyCombinations.Length > 0 ? next.keyCombinations[0] : null;
                        needsPriority = (prevKeys != null && prevKeys.CompareTo(theseKeys) == 0 ||
                                         nextKeys != null && nextKeys.CompareTo(theseKeys) == 0);
                    }
                    else
                    {
                        hasKeys = false;
                    }
                    if (hasKeys)
                    {
                        sb.Append(kb.ShortDescribe(" | "));
                    }
                    else
                    {
                        sb.Append("(no keys)");
                    }
                    sb.Append(" :");
                    if (needsPriority)
                    {
                        sb.Append(kb.priority.ToString());
                    }
                    sb.Append(": ");
                    sb.Append(kb.name);
                    sb.Append("\n");
                }
            }
            if (AxisBinds.Count > 0)
            {
                sb.Append("[Axis]\n");
                for (int i = 0; i < AxisBinds.Count; ++i)
                {
                    AxBind ab = AxisBinds[i];
                    sb.Append(ab.ShortDescribe(" | "));
                    sb.Append(" :: ");
                    sb.Append(ab.name);
                    sb.Append("\n");
                }
            }
            return(sb.ToString());
        }
Ejemplo n.º 6
0
 public override string ToString()
 {
     return(KCombo.ToString(modifiers) + axis.ToString());
 }