Beispiel #1
0
 private static bool WrapAndCheck <TButton>(
     TButton button,
     Func <InputKey, bool, bool> checkFunc,
     bool evenIfHandled)
     where TButton : struct, Enum
 {
     return(Check(
                WrappedButton <TButton> .GetWrappedButton(button),
                checkFunc,
                evenIfHandled));
 }
Beispiel #2
0
        public static WrappedButton <TButton> GetWrappedButton(TButton button)
        {
            if (WrappedButtons.TryGetValue(button, out var wrappedButton))
            {
                return(wrappedButton);
            }

            wrappedButton          = new WrappedButton <TButton>(button);
            WrappedButtons[button] = wrappedButton;
            return(wrappedButton);
        }
 public ClientInputContext HandleButtonDown <TButton>(
     TButton button,
     Action buttonCallback,
     bool evenIfHandled = false)
     where TButton : struct, Enum
 {
     this.buttonDownCallbacks.Add(
         new ButtonCallback(
             WrappedButton <TButton> .GetWrappedButton(button),
             buttonCallback,
             evenIfHandled));
     return(this);
 }
Beispiel #4
0
        public static void RegisterButtonsEnum <TButton>()
            where TButton : struct, Enum
        {
            if (isFrozen)
            {
                throw new Exception(
                          "Cannot register new button enums - "
                          + nameof(ClientInputManager)
                          + " is in a frozen state."
                          + Environment.NewLine
                          + "It's possible to register new button enums only during the bootstrappers initialization time (before any button or input context were accessed).");
            }

            var enumType = typeof(TButton);

            ValidateButtonType(enumType);

            if (!RegisteredButtonEnums.Add(enumType))
            {
                throw new Exception("Already registered buttons enum: " + enumType);
            }

            foreach (var button in EnumExtensions.GetValues <TButton>())
            {
                var memberInfo = enumType.ScriptingGetMember(button.ToString())[0];
                var buttonInfo = memberInfo.GetCustomAttribute <ButtonInfoAttribute>();
                if (buttonInfo is null)
                {
                    throw new Exception(
                              $"There is no {nameof(ButtonInfoAttribute)} on button {button} (enum {enumType.FullName})");
                }

                var description = memberInfo.GetCustomAttribute <DescriptionAttribute>();
                if (description is null)
                {
                    throw new Exception(
                              $"There is no {nameof(DescriptionAttribute)} on button {button} (enum {enumType.FullName})");
                }

                buttonInfo.Title = description.Description;

                var wrappedButton = WrappedButton <TButton> .GetWrappedButton(button);

                RegisteredButtons.Add(wrappedButton, buttonInfo);
                //ApplyDefaultMapping(wrappedButton, buttonInfo);
            }
        }
Beispiel #5
0
 public static void ConsumeButton <TButton>(TButton button)
     where TButton : struct, Enum
 {
     ConsumeButton(WrappedButton <TButton> .GetWrappedButton(button));
 }