summaryrefslogtreecommitdiff
path: root/src/SMAPI/Events/ControlEvents.cs
blob: 5626ff819e5d99d13facf341c09a493da23e4aa9 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#if !SMAPI_3_0_STRICT
using System;
using Microsoft.Xna.Framework.Input;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Events;

namespace StardewModdingAPI.Events
{
    /// <summary>Events raised when the player uses a controller, keyboard, or mouse.</summary>
    [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")]
    public static class ControlEvents
    {
        /*********
        ** Properties
        *********/
        /// <summary>The core event manager.</summary>
        private static EventManager EventManager;

        /// <summary>Manages deprecation warnings.</summary>
        private static DeprecationManager DeprecationManager;


        /*********
        ** 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.DeprecationManager.WarnForOldEvents();
                ControlEvents.EventManager.Legacy_KeyboardChanged.Add(value);
            }
            remove => ControlEvents.EventManager.Legacy_KeyboardChanged.Remove(value);
        }

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

        /// <summary>Raised after the player releases a keyboard key.</summary>
        public static event EventHandler<EventArgsKeyPressed> KeyReleased
        {
            add
            {
                ControlEvents.DeprecationManager.WarnForOldEvents();
                ControlEvents.EventManager.Legacy_KeyReleased.Add(value);
            }
            remove => ControlEvents.EventManager.Legacy_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.DeprecationManager.WarnForOldEvents();
                ControlEvents.EventManager.Legacy_MouseChanged.Add(value);
            }
            remove => ControlEvents.EventManager.Legacy_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.DeprecationManager.WarnForOldEvents();
                ControlEvents.EventManager.Legacy_ControllerButtonPressed.Add(value);
            }
            remove => ControlEvents.EventManager.Legacy_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.DeprecationManager.WarnForOldEvents();
                ControlEvents.EventManager.Legacy_ControllerButtonReleased.Add(value);
            }
            remove => ControlEvents.EventManager.Legacy_ControllerButtonReleased.Remove(value);
        }

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

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


        /*********
        ** Public methods
        *********/
        /// <summary>Initialise the events.</summary>
        /// <param name="eventManager">The core event manager.</param>
        /// <param name="deprecationManager">Manages deprecation warnings.</param>
        internal static void Init(EventManager eventManager, DeprecationManager deprecationManager)
        {
            ControlEvents.EventManager = eventManager;
            ControlEvents.DeprecationManager = deprecationManager;
        }
    }
}
#endif