internal bool IsPressedAndIgnored(KeyCode key) { UpdateCurrentCombinations(); var cleanKey = ModInputLibrary.NormalizeKeyCode(key); return(UnityEngine.Input.GetKey(cleanKey) && _currentCombinations.Count > 0 && Time.realtimeSinceStartup - _timeout[(int)cleanKey] < Cooldown); }
public Texture2D KeyTexture(KeyCode key) { if (_loadedTextures == null) { FillTextureLibrary(); } var keyName = ModInputLibrary.KeyCodeToString(key); if (_loadedTextures.ContainsKey(keyName)) { return(_loadedTextures[keyName]); } var config = OWInput.GetActivePadConfig() ?? InputUtil.GamePadConfig_Xbox; var toStore = (int)key >= ModInputLibrary.MinGamepadKey ? ButtonPromptLibrary.SharedInstance.GetButtonTexture(InputTranslator.ConvertKeyCodeToButton(key, config)) : ButtonPromptLibrary.SharedInstance.GetButtonTexture(key); _loadedTextures.Add(keyName, toStore); return(toStore); }
internal void RegisterGamesBinding(InputCommand binding) { if (binding == null) { return; } var fields = binding is SingleAxisCommand ? typeof(SingleAxisCommand).GetFields(NonPublic) : typeof(DoubleAxisCommand).GetFields(NonPublic); foreach (var field in fields.Where(x => x.FieldType == typeof(List <KeyCode>))) { var keys = (List <KeyCode>)field.GetValue(binding); foreach (var key in keys.Where(x => x != KeyCode.None)) { var intKey = (int)ModInputLibrary.NormalizeKeyCode(key); _gameBindingCounter[intKey]++; } } }
public List <string> GetWarningMessages(string combinations) { var hashes = new List <long>(); var errorMessages = new List <string>(); foreach (var combo in combinations.Split('/')) { var hash = ModInputLibrary.StringToHash(combo); if (hash <= 0) { errorMessages.Add(ModInputLibrary.GetReadableMessage((RegistrationCode)(-hash))); continue; } hashes.Add(hash); } var warningMessages = GetCollisions(hashes.AsReadOnly()) .Select(combination => $"Collides with {combination}").ToList(); warningMessages.AddRange(errorMessages); return(warningMessages); }
private List <long> StringToHashes(string combinations) { var hashes = new List <long>(); foreach (var combo in combinations.Split('/')) { var hash = ModInputLibrary.StringToHash(combo); if (hash <= 0) { _console.WriteLine($"Warning: Invalid part of combo in {FullName}: {combo}, " + ModInputLibrary.GetReadableMessage((RegistrationCode)hash)); continue; } hashes.Add(hash); if (hash < ModInputLibrary.MaxUsefulKey) { _singles.Add((KeyCode)hash); } } return(hashes); }
internal void FillTextureLibrary() { _loadedTextures = new Dictionary <string, Texture2D>(); var config = OWInput.GetActivePadConfig() ?? InputUtil.GamePadConfig_Xbox; for (var code = ModInputLibrary.MinUsefulKey; code < ModInputLibrary.MaxUsefulKey; code++) { var key = (KeyCode)code; if (!Enum.IsDefined(typeof(KeyCode), key)) { continue; } var keyName = ModInputLibrary.KeyCodeToString(key); if (_loadedTextures.ContainsKey(keyName)) { continue; } var button = InputTranslator.ConvertKeyCodeToButton(key, config); var toStore = (int)key >= ModInputLibrary.MinGamepadKey ? ButtonPromptLibrary.SharedInstance.GetButtonTexture(button) : ButtonPromptLibrary.SharedInstance.GetButtonTexture(key); _loadedTextures.Add(keyName, toStore); } }
public Texture2D KeyTexture(string key) { return(KeyTexture(ModInputLibrary.StringToKeyCode(key))); }