Example #1
0
 private void assignKeybinding(object sender, ButtonPressedEventArgs e)
 {
     if (keybindingOpt == null)
     {
         return;
     }
     if (!e.Button.TryGetKeyboard(out Keys keys) && !e.Button.TryGetController(out _))
     {
         return;
     }
     if (e.Button.ToString() == "Escape")
     {
         Game1.playSound("bigDeSelect");
     }
     else
     {
         Game1.playSound("coin");
         keybindingOpt.Value    = e.Button;
         keybindingLabel.String = e.Button.ToString();
     }
     Mod.instance.Helper.Events.Input.ButtonPressed -= assignKeybinding;
     keybindingOpt   = null;
     keybindingLabel = null;
     ui.Obscured     = false;
 }
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="option">The keybind option being bound.</param>
        /// <param name="label">The label to update with the bound keys when <see cref="Option"/> is rebound.</param>
        public KeybindOverlay(SimpleModOption <TKeybind> option, Label label)
        {
            this.Option = option;
            this.Label  = label;

            this.ShouldResetLayout = true;
        }
Example #3
0
 private void doKeybindingFor(SimpleModOption <SButton> opt, Label label)
 {
     Game1.playSound("breathin");
     keybindingOpt   = opt;
     keybindingLabel = label;
     ui.Obscured     = true;
     Mod.instance.Helper.Events.Input.ButtonPressed += assignKeybinding;
 }
 private void doKeybinding2For(SimpleModOption <KeybindList> opt, Label label)
 {
     Game1.playSound("breathin");
     keybinding2Opt  = opt;
     keybindingLabel = label;
     ui.Obscured     = true;
     Mod.instance.Helper.Events.Input.ButtonsChanged += assignKeybinding2;
 }
 private void assignKeybinding(object sender, ButtonPressedEventArgs e)
 {
     if (keybindingOpt == null)
     {
         return;
     }
     keybindingOpt.Value    = e.Button;
     keybindingLabel.String = e.Button.ToString();
     Mod.instance.Helper.Events.Input.ButtonPressed -= assignKeybinding;
     keybindingOpt   = null;
     keybindingLabel = null;
 }
        private void assignKeybinding2(object sender, ButtonsChangedEventArgs e)
        {
            if (keybinding2Opt == null)
            {
                return;
            }

            List <SButton> all = new List <SButton>();

            foreach (var button in e.Held)
            {
                if (button.TryGetKeyboard(out Keys keys) || button.TryGetController(out _))
                {
                    all.Add(button);
                }
            }

            foreach (var button in e.Released)
            {
                bool stop = false;
                if (button.ToString() == "Escape")
                {
                    stop = true;
                    Game1.playSound("bigDeSelect");
                }
                if (!stop && (button.TryGetKeyboard(out Keys keys) || button.TryGetController(out _)))
                {
                    stop = true;
                    all.Add(button);

                    Game1.playSound("coin");
                    keybinding2Opt.Value.Keybinds[0] = new Keybind(all.ToArray());
                    keybindingLabel.String           = keybinding2Opt.Value.Keybinds[0].ToString();
                }

                if (stop)
                {
                    Mod.instance.Helper.Events.Input.ButtonsChanged -= assignKeybinding2;
                    keybinding2Opt  = null;
                    keybindingLabel = null;
                    ui.Obscured     = false;
                }

                return;
            }
        }
 private void doKeybindingFor(SimpleModOption <SButton> opt, Label label)
 {
     keybindingOpt   = opt;
     keybindingLabel = label;
     Mod.instance.Helper.Events.Input.ButtonPressed += assignKeybinding;
 }