Beispiel #1
0
        public void UnregisterCombination(IModInputCombination combination)
        {
            if (combination == null)
            {
                _console.WriteLine("Failed to unregister: null combination!");
                return;
            }
            switch (SwapCombination(combination, true))
            {
            case RegistrationCode.InvalidCombination:
                _console.WriteLine($"Failed to unregister \"{combination.FullName}\": invalid combination!");
                return;

            case RegistrationCode.CombinationTooLong:
                _console.WriteLine($"Failed to unregister \"{combination.FullName}\": too long!");
                return;

            case RegistrationCode.AllNormal:
                _logger.Log($"Successfully unregistered \"{combination.FullName}\"");
                return;

            default:
                return;
            }
        }
Beispiel #2
0
 public bool WasTapped(IModInputCombination combination)
 {
     return(combination != null &&
            !IsPressed(combination) &&
            combination.PressDuration < TapDuration &&
            combination.IsFirst);
 }
Beispiel #3
0
        private RegistrationCode SwapCombination(IModInputCombination combination, bool toUnregister)
        {
            var isTaken = false;

            if (combination.Hashes.Count == 0)
            {
                return(RegistrationCode.InvalidCombination);
            }
            foreach (var hash in combination.Hashes)
            {
                if (toUnregister)
                {
                    if (!_comboRegistry.ContainsKey(hash))
                    {
                        continue;
                    }
                    _comboRegistry[hash].Remove(combination);
                    if (_comboRegistry[hash].Count == 0)
                    {
                        _comboRegistry.Remove(hash);
                    }
                    continue;
                }
                if (_comboRegistry.ContainsKey(hash) || hash < ModInputLibrary.MaxUsefulKey && _gameBindingCounter[hash] > 0)
                {
                    isTaken = true;
                }
                if (!_comboRegistry.ContainsKey(hash))
                {
                    _comboRegistry.Add(hash, new HashSet <IModInputCombination>());
                }
                _comboRegistry[hash].Add(combination);
            }
            return(isTaken ? RegistrationCode.CombinationTaken : RegistrationCode.AllNormal);
        }
Beispiel #4
0
 public bool IsPressedExact(IModInputCombination combination)
 {
     if (combination == null)
     {
         return(false);
     }
     UpdateCurrentCombinations();
     return(_currentCombinations.Contains(combination));
 }
        public override void Configure(IModConfig config)
        {
            if (_crouchCombo != null)
            {
                ModHelper.Input.UnregisterCombination(_crouchCombo);
            }
            var combination = config.GetSettingsValue <string>("Crouch combination");

            _crouchCombo = ModHelper.Input.RegisterCombination(this, "Crouch", combination) ?? TemporaryHack("Crouch");
        }
Beispiel #6
0
        private bool IsPressedSingle(IModInputCombination combination)
        {
            CleanupSinglesPressed();
            if (_currentCombinations.Contains(combination))
            {
                return(true);
            }
            var single = combination.Singles.FirstOrDefault(key => UnityEngine.Input.GetKey(key) && !IsPressedAndIgnored(key));

            if (single == 0)
            {
                return(false);
            }
            _singlesPressed.Add(combination);
            combination.InternalSetPressed();
            return(true);
        }
Beispiel #7
0
 public bool WasNewlyReleased(IModInputCombination combination)
 {
     return(combination != null &&
            !IsPressed(combination) &&
            combination.IsFirst);
 }
Beispiel #8
0
 public bool IsNewlyPressed(IModInputCombination combination)
 {
     return(combination != null &&
            IsPressed(combination) &&
            combination.IsFirst);
 }
Beispiel #9
0
 public bool IsPressed(IModInputCombination combination)
 {
     return(combination != null &&
            (IsPressedExact(combination) || IsPressedSingle(combination)));
 }