Webclient: WIP on properly supporting touchscreen input

When touch mode is off and a touchstart event is received, switch to touch mode. When touch mode is on and a mousedown event is received, disable touch mode. Unfortunately this still has a problem where touch mode will always get disabled if you touch while the keyboard is open. (because the game does NOT prevent the default behaviour of touchstart becoming a mousedown event when the keyboard is open, so that you can still click on the caret in text input box)
This commit is contained in:
UnknownShadow200 2021-02-01 22:15:29 +11:00
parent 58380529f9
commit 3e49f0f2a7
6 changed files with 28 additions and 5 deletions

View File

@ -97,6 +97,7 @@ void Event_UnregisterAll(void) {
InputEvents.Up.Count = 0;
InputEvents.Wheel.Count = 0;
InputEvents.TextChanged.Count = 0;
InputEvents.ModeChanged.Count = 0;
PointerEvents.Moved.Count = 0;
PointerEvents.Down.Count = 0;

View File

@ -164,6 +164,7 @@ CC_VAR extern struct _InputEventsList {
struct Event_Int Up; /* Key or button is released. Arg is a member of Key enumeration */
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_Void ModeChanged; /* Input_TouchMode has changed */
} InputEvents;
CC_VAR extern struct _PointerEventsList {

View File

@ -71,12 +71,22 @@ int Gui_ContainsPointers(int x, int y, int width, int height) {
return false;
}
#ifdef CC_BUILD_TOUCH
static void UpdateTouchMenu(void) {
if (Input_TouchMode) {
TouchScreen_Show();
} else {
TouchScreen_Remove();
}
}
#else
static void UpdateTouchMenu(void) { }
#endif
void Gui_ShowDefault(void) {
HUDScreen_Show();
ChatScreen_Show();
#ifdef CC_BUILD_TOUCH
TouchScreen_Show();
#endif
UpdateTouchMenu();
}
static void LoadOptions(void) {
@ -536,6 +546,7 @@ static void OnTextChanged(void* obj, const cc_string* str) {
if (s->VTABLE->HandlesTextChanged(s, str)) return;
}
}
static void OnModeChanged(void* obj) { UpdateTouchMenu(); }
#endif
static void OnContextLost(void* obj) {
@ -559,6 +570,7 @@ static void OnInit(void) {
#ifdef CC_BUILD_TOUCH
Event_Register_(&InputEvents.TextChanged, NULL, OnTextChanged);
Event_Register_(&InputEvents.ModeChanged, NULL, OnModeChanged);
Gui._onscreenButtons = Options_GetInt(OPT_TOUCH_BUTTONS, 0, Int32_MaxValue, 0);
#endif

View File

@ -78,10 +78,13 @@ void Input_SetTouchMode(cc_bool enabled) {
ClearTouches();
Input_TouchMode = enabled;
Pointers_Count = enabled ? 0 : 1;
Event_RaiseVoid(&InputEvents.ModeChanged);
}
void Input_AddTouch(long id, int x, int y) {
int i;
if (!Input_TouchMode) Input_SetTouchMode(true);
for (i = 0; i < INPUT_MAX_POINTERS; i++) {
if (touches[i].type) continue;
@ -232,6 +235,11 @@ void Input_SetPressed(int key) {
/* don't allow multiple left mouse down events */
if (key != KEY_LMOUSE || wasPressed) return;
#ifdef CC_BUILD_TOUCH
/* If touch mode, disable it since using mouse now */
if (Input_TouchMode) Input_SetTouchMode(false);
#endif
Pointer_SetPressed(0, true);
}

View File

@ -2186,8 +2186,8 @@ static const struct ScreenVTABLE TouchScreen_VTABLE = {
void TouchScreen_Show(void) {
struct TouchScreen* s = &TouchScreen;
s->VTABLE = &TouchScreen_VTABLE;
if (!Input_TouchMode) return;
Gui_Add((struct Screen*)s, GUI_PRIORITY_TOUCH);
}
void TouchScreen_Remove(void) { Gui_Remove((struct Screen*)&TouchScreen); }
#endif

View File

@ -32,6 +32,7 @@ void DisconnectScreen_Show(const cc_string* title, const cc_string* message);
#ifdef CC_BUILD_TOUCH
void TouchScreen_Refresh(void);
void TouchScreen_Show(void);
void TouchScreen_Remove(void);
#endif
/* Opens chat input for the HUD with the given initial text. */