mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 17:12:25 -05:00
Try to avoid breaking input event backwards compatibility
This commit is contained in:
parent
26879d1652
commit
c981d8272f
6 changed files with 34 additions and 16 deletions
|
@ -1,7 +1,7 @@
|
|||
#include "Event.h"
|
||||
#include "Logger.h"
|
||||
|
||||
int EventAPIVersion = 3;
|
||||
int EventAPIVersion = 4;
|
||||
struct _EntityEventsList EntityEvents;
|
||||
struct _TabListEventsList TabListEvents;
|
||||
struct _TextureEventsList TextureEvents;
|
||||
|
@ -99,10 +99,12 @@ void Event_UnregisterAll(void) {
|
|||
WindowEvents.Redrawing.Count = 0;
|
||||
|
||||
InputEvents.Press.Count = 0;
|
||||
InputEvents.Down.Count = 0;
|
||||
InputEvents.Up.Count = 0;
|
||||
InputEvents._down.Count = 0;
|
||||
InputEvents._up.Count = 0;
|
||||
InputEvents.Wheel.Count = 0;
|
||||
InputEvents.TextChanged.Count = 0;
|
||||
InputEvents.Down2.Count = 0;
|
||||
InputEvents.Up2.Count = 0;
|
||||
|
||||
PointerEvents.Moved.Count = 0;
|
||||
PointerEvents.Down.Count = 0;
|
||||
|
|
|
@ -128,6 +128,7 @@ void Event_UnregisterAll(void);
|
|||
/* Version 1 - Added NetEvents.PluginMessageReceived */
|
||||
/* Version 2 - Added WindowEvents.Redrawing */
|
||||
/* Version 3 - Changed InputEvent.Press from code page 437 to unicode character */
|
||||
/* Version 4 - Added InputEvents.Down2 and InputEvents.Up2 */
|
||||
/* You MUST CHECK the event API version before attempting to use the events listed above, */
|
||||
/* as otherwise if the player is using an older client that lacks some of the above events, */
|
||||
/* you will be calling Event_Register on random data instead of the expected EventsList struct */
|
||||
|
@ -198,10 +199,12 @@ CC_VAR extern struct _WindowEventsList {
|
|||
|
||||
CC_VAR extern struct _InputEventsList {
|
||||
struct Event_Int Press; /* Key input character is typed. Arg is a unicode character */
|
||||
struct Event_Input Down; /* Key or button is pressed. Arg is input button state. */
|
||||
struct Event_Input Up; /* Key or button is released. Arg is input button state. */
|
||||
struct Event_Input _down; /* DEPRECATED. Key or button is pressed. Arg is input button state. */
|
||||
struct Event_Input _up; /* DEPRECATED. Key or button is released. Arg is input button state. */
|
||||
struct Event_Float Wheel; /* Mouse wheel is moved/scrolled (Arg is wheel delta) */
|
||||
struct Event_String TextChanged; /* Text in the on-screen input keyboard changed (for Mobile) */
|
||||
struct Event_Input Down2; /* Key or button is pressed. Args are input button and device state. */
|
||||
struct Event_Input Up2; /* Key or button is released. Args are input button and device state. */
|
||||
} InputEvents;
|
||||
|
||||
CC_VAR extern struct _PointerEventsList {
|
||||
|
|
16
src/Input.c
16
src/Input.c
|
@ -214,10 +214,12 @@ const char* Input_DisplayNames[INPUT_COUNT] = {
|
|||
void Input_SetPressed(int key) {
|
||||
cc_bool wasPressed = Input.Pressed[key];
|
||||
Input.Pressed[key] = true;
|
||||
Event_RaiseInput(&InputEvents.Down, key, wasPressed, &NormDevice);
|
||||
|
||||
if (key == 'C' && Input_IsActionPressed()) Event_RaiseInput(&InputEvents.Down, INPUT_CLIPBOARD_COPY, 0, &NormDevice);
|
||||
if (key == 'V' && Input_IsActionPressed()) Event_RaiseInput(&InputEvents.Down, INPUT_CLIPBOARD_PASTE, 0, &NormDevice);
|
||||
if (key <= CCMOUSE_M) Event_RaiseInput(&InputEvents._down, key, wasPressed, &NormDevice);
|
||||
Event_RaiseInput(&InputEvents.Down2, key, wasPressed, &NormDevice);
|
||||
|
||||
if (key == 'C' && Input_IsActionPressed()) Event_RaiseInput(&InputEvents.Down2, INPUT_CLIPBOARD_COPY, 0, &NormDevice);
|
||||
if (key == 'V' && Input_IsActionPressed()) Event_RaiseInput(&InputEvents.Down2, INPUT_CLIPBOARD_PASTE, 0, &NormDevice);
|
||||
|
||||
/* don't allow multiple left mouse down events */
|
||||
if (key != CCMOUSE_L || wasPressed) return;
|
||||
|
@ -228,7 +230,9 @@ void Input_SetReleased(int key) {
|
|||
if (!Input.Pressed[key]) return;
|
||||
Input.Pressed[key] = false;
|
||||
|
||||
Event_RaiseInput(&InputEvents.Up, key, true, &NormDevice);
|
||||
if (key <= CCMOUSE_M) Event_RaiseInput(&InputEvents._up, key, true, &NormDevice);
|
||||
Event_RaiseInput(&InputEvents.Up2, key, true, &NormDevice);
|
||||
|
||||
if (key == CCMOUSE_L) Pointer_SetPressed(0, false);
|
||||
}
|
||||
|
||||
|
@ -526,9 +530,9 @@ static void Gamepad_Apply(int port, int btn, cc_bool was, int pressed) {
|
|||
device->mappedIndex = Game_MapState(device->rawIndex);
|
||||
|
||||
if (pressed) {
|
||||
Event_RaiseInput(&InputEvents.Down, btn + GAMEPAD_BEG_BTN, was, device);
|
||||
Event_RaiseInput(&InputEvents.Down2, btn + GAMEPAD_BEG_BTN, was, device);
|
||||
} else {
|
||||
Event_RaiseInput(&InputEvents.Up, btn + GAMEPAD_BEG_BTN, was, device);
|
||||
Event_RaiseInput(&InputEvents.Up2, btn + GAMEPAD_BEG_BTN, was, device);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -893,6 +893,14 @@ static void OnInputDown(void* obj, int key, cc_bool was, struct InputDevice* dev
|
|||
} else { HandleHotkeyDown(key); }
|
||||
}
|
||||
|
||||
static void OnInputDownLegacy(void* obj, int key, cc_bool was, struct InputDevice* device) {
|
||||
/* Event originated from ClassiCube, ignore it */
|
||||
if (device == &NormDevice) return;
|
||||
|
||||
/* Event originated from a plugin, convert it */
|
||||
OnInputDown(obj, key, was, &NormDevice);
|
||||
}
|
||||
|
||||
static void OnInputUp(void* obj, int key, cc_bool was, struct InputDevice* device) {
|
||||
struct Screen* s;
|
||||
int i;
|
||||
|
@ -973,8 +981,9 @@ static void OnInit(void) {
|
|||
|
||||
Event_Register_(&PointerEvents.Down, NULL, OnPointerDown);
|
||||
Event_Register_(&PointerEvents.Up, NULL, OnPointerUp);
|
||||
Event_Register_(&InputEvents.Down, NULL, OnInputDown);
|
||||
Event_Register_(&InputEvents.Up, NULL, OnInputUp);
|
||||
Event_Register_(&InputEvents._down, NULL, OnInputDownLegacy);
|
||||
Event_Register_(&InputEvents.Down2, NULL, OnInputDown);
|
||||
Event_Register_(&InputEvents.Up2, NULL, OnInputUp);
|
||||
|
||||
Event_Register_(&UserEvents.HackPermsChanged, NULL, InputHandler_CheckZoomFov);
|
||||
StoredHotkeys_LoadAll();
|
||||
|
|
|
@ -209,7 +209,7 @@ static void Launcher_Init(void) {
|
|||
Event_Register_(&WindowEvents.StateChanged, NULL, OnResize);
|
||||
Event_Register_(&WindowEvents.Closing, NULL, OnClosing);
|
||||
|
||||
Event_Register_(&InputEvents.Down, NULL, OnInputDown);
|
||||
Event_Register_(&InputEvents.Down2, NULL, OnInputDown);
|
||||
Event_Register_(&InputEvents.Wheel, NULL, OnMouseWheel);
|
||||
|
||||
Utils_EnsureDirectory("texpacks");
|
||||
|
|
|
@ -452,7 +452,7 @@ void Window_SetTitle(const cc_string* title) {
|
|||
static char pasteBuffer[512];
|
||||
static cc_string pasteStr;
|
||||
EMSCRIPTEN_KEEPALIVE void Window_RequestClipboardText(void) {
|
||||
Event_RaiseInput(&InputEvents.Down, INPUT_CLIPBOARD_COPY, 0, &NormDevice);
|
||||
Event_RaiseInput(&InputEvents.Down2, INPUT_CLIPBOARD_COPY, 0, &NormDevice);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Window_StoreClipboardText(char* src) {
|
||||
|
@ -462,7 +462,7 @@ EMSCRIPTEN_KEEPALIVE void Window_StoreClipboardText(char* src) {
|
|||
|
||||
EMSCRIPTEN_KEEPALIVE void Window_GotClipboardText(char* src) {
|
||||
Window_StoreClipboardText(src);
|
||||
Event_RaiseInput(&InputEvents.Down, INPUT_CLIPBOARD_PASTE, 0, &NormDevice);
|
||||
Event_RaiseInput(&InputEvents.Down2, INPUT_CLIPBOARD_PASTE, 0, &NormDevice);
|
||||
}
|
||||
|
||||
extern void interop_TryGetClipboardText(void);
|
||||
|
|
Loading…
Reference in a new issue