summaryrefslogtreecommitdiff
path: root/src/SMAPI/Events/EventArgsInput.cs
blob: d60f4017f563658a7226c66b7d6dc2dd6a40d030 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;

namespace StardewModdingAPI.Events
{
    /// <summary>Event arguments when a button is pressed or released.</summary>
    public class EventArgsInput : EventArgs
    {
        /*********
        ** Properties
        *********/
        /// <summary>The buttons to suppress.</summary>
        private readonly HashSet<SButton> SuppressButtons;


        /*********
        ** Accessors
        *********/
        /// <summary>The button on the controller, keyboard, or mouse.</summary>
        public SButton Button { get; }

        /// <summary>The current cursor position.</summary>
        public ICursorPosition Cursor { get; }

        /// <summary>Whether the input should trigger actions on the affected tile.</summary>
        public bool IsActionButton { get; }

        /// <summary>Whether the input should use tools on the affected tile.</summary>
        public bool IsUseToolButton { get; }

        /// <summary>Whether a mod has indicated the key was already handled.</summary>
        public bool IsSuppressed => this.SuppressButtons.Contains(this.Button);


        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="button">The button on the controller, keyboard, or mouse.</param>
        /// <param name="cursor">The cursor position.</param>
        /// <param name="isActionButton">Whether the input should trigger actions on the affected tile.</param>
        /// <param name="isUseToolButton">Whether the input should use tools on the affected tile.</param>
        /// <param name="suppressButtons">The buttons to suppress.</param>
        public EventArgsInput(SButton button, ICursorPosition cursor, bool isActionButton, bool isUseToolButton, HashSet<SButton> suppressButtons)
        {
            this.Button = button;
            this.Cursor = cursor;
            this.IsActionButton = isActionButton;
            this.IsUseToolButton = isUseToolButton;
            this.SuppressButtons = suppressButtons;
        }

        /// <summary>Prevent the game from handling the current button press. This doesn't prevent other mods from receiving the event.</summary>
        public void SuppressButton()
        {
            this.SuppressButton(this.Button);
        }

        /// <summary>Prevent the game from handling a button press. This doesn't prevent other mods from receiving the event.</summary>
        /// <param name="button">The button to suppress.</param>
        public void SuppressButton(SButton button)
        {
            this.SuppressButtons.Add(button);
        }
    }
}