summaryrefslogtreecommitdiff
path: root/src/SMAPI/Events/ControlEvents.cs
blob: 973bb24540ca45473d5d219bb9ccbb6ee765305c (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using Microsoft.Xna.Framework.Input;
using StardewModdingAPI.Framework.Events;

namespace StardewModdingAPI.Events
{
    /// <summary>Events raised when the player uses a controller, keyboard, or mouse.</summary>
    public static class ControlEvents
    {
        /*********
        ** Properties
        *********/
        /// <summary>The core event manager.</summary>
        private static EventManager EventManager;


        /*********
        ** Events
        *********/
        /// <summary>Raised when the <see cref="KeyboardState"/> changes. That happens when the player presses or releases a key.</summary>
        public static event EventHandler<EventArgsKeyboardStateChanged> KeyboardChanged
        {
            add => ControlEvents.EventManager.Control_KeyboardChanged.Add(value);
            remove => ControlEvents.EventManager.Control_KeyboardChanged.Remove(value);
        }

        /// <summary>Raised when the player presses a keyboard key.</summary>
        public static event EventHandler<EventArgsKeyPressed> KeyPressed
        {
            add => ControlEvents.EventManager.Control_KeyPressed.Add(value);
            remove => ControlEvents.EventManager.Control_KeyPressed.Remove(value);
        }

        /// <summary>Raised when the player releases a keyboard key.</summary>
        public static event EventHandler<EventArgsKeyPressed> KeyReleased
        {
            add => ControlEvents.EventManager.Control_KeyReleased.Add(value);
            remove => ControlEvents.EventManager.Control_KeyReleased.Remove(value);
        }

        /// <summary>Raised when the <see cref="MouseState"/> changes. That happens when the player moves the mouse, scrolls the mouse wheel, or presses/releases a button.</summary>
        public static event EventHandler<EventArgsMouseStateChanged> MouseChanged
        {
            add => ControlEvents.EventManager.Control_MouseChanged.Add(value);
            remove => ControlEvents.EventManager.Control_MouseChanged.Remove(value);
        }

        /// <summary>The player pressed a controller button. This event isn't raised for trigger buttons.</summary>
        public static event EventHandler<EventArgsControllerButtonPressed> ControllerButtonPressed
        {
            add => ControlEvents.EventManager.Control_ControllerButtonPressed.Add(value);
            remove => ControlEvents.EventManager.Control_ControllerButtonPressed.Remove(value);
        }

        /// <summary>The player released a controller button. This event isn't raised for trigger buttons.</summary>
        public static event EventHandler<EventArgsControllerButtonReleased> ControllerButtonReleased
        {
            add => ControlEvents.EventManager.Control_ControllerButtonReleased.Add(value);
            remove => ControlEvents.EventManager.Control_ControllerButtonReleased.Remove(value);
        }

        /// <summary>The player pressed a controller trigger button.</summary>
        public static event EventHandler<EventArgsControllerTriggerPressed> ControllerTriggerPressed
        {
            add => ControlEvents.EventManager.Control_ControllerTriggerPressed.Add(value);
            remove => ControlEvents.EventManager.Control_ControllerTriggerPressed.Remove(value);
        }

        /// <summary>The player released a controller trigger button.</summary>
        public static event EventHandler<EventArgsControllerTriggerReleased> ControllerTriggerReleased
        {
            add => ControlEvents.EventManager.Control_ControllerTriggerReleased.Add(value);
            remove => ControlEvents.EventManager.Control_ControllerTriggerReleased.Remove(value);
        }


        /*********
        ** Public methods
        *********/
        /// <summary>Initialise the events.</summary>
        /// <param name="eventManager">The core event manager.</param>
        internal static void Init(EventManager eventManager)
        {
            ControlEvents.EventManager = eventManager;
        }
    }
}