summaryrefslogtreecommitdiff
path: root/src/SMAPI/Events/InputButtonReleasedEventArgs.cs
blob: 4b0bc3264f443188e66cdfd1f76d4594f281c2e4 (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
using System;
using StardewModdingAPI.Framework.Input;

namespace StardewModdingAPI.Events
{
    /// <summary>Event arguments when a button is released.</summary>
    public class InputButtonReleasedEventArgs : EventArgs
    {
        /*********
        ** Properties
        *********/
        /// <summary>The game's current input state.</summary>
        private readonly SInputState InputState;


        /*********
        ** 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; }


        /*********
        ** 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="inputState">The game's current input state.</param>
        internal InputButtonReleasedEventArgs(SButton button, ICursorPosition cursor, SInputState inputState)
        {
            this.Button = button;
            this.Cursor = cursor;
            this.InputState = inputState;
        }

        /// <summary>Whether a mod has indicated the key was already handled, so the game should handle it.</summary>
        public bool IsSuppressed()
        {
            return this.IsSuppressed(this.Button);
        }

        /// <summary>Whether a mod has indicated the key was already handled, so the game should handle it.</summary>
        /// <param name="button">The button to check.</param>
        public bool IsSuppressed(SButton button)
        {
            return this.InputState.SuppressButtons.Contains(button);
        }

        /// <summary>Get whether a given button was pressed or held.</summary>
        /// <param name="button">The button to check.</param>
        public bool IsDown(SButton button)
        {
            return this.InputState.IsDown(button);
        }
    }
}