From c8baaa6f4b44f6aeee3d14d4776c31762e78f331 Mon Sep 17 00:00:00 2001 From: Matthew Coppola Date: Thu, 5 Dec 2024 19:41:32 -0500 Subject: [PATCH] Allow dragging sliders with the mouse Additional code was introduced to handle edge cases. Sliders are always dimmed when clicked with the mouse, now. When the mouse button is release, dimmed mode is turned off. This was done to prevent adjacent slider items from being accidentally modified by moving the mouse over them with the left mouse button held down, as well as to allow proper functioning of deferred sliders with the mouse. --- src/game/menu.c | 17 +++++++++++++++++ src/game/menuitem.c | 30 +++++++++++++++++------------- src/include/data.h | 2 ++ src/include/types.h | 5 +++-- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/game/menu.c b/src/game/menu.c index 7a324f746..fb0b8ac18 100644 --- a/src/game/menu.c +++ b/src/game/menu.c @@ -141,6 +141,8 @@ s32 g_MpPlayerNum = 0; #ifndef PLATFORM_N64 s32 g_MenuMouseControl = true; s32 g_MenuUsingMouse = false; +s32 g_AllowMouseHeld = true; +s32 g_MouseDimmedMode = false; #endif void menuPlaySound(s32 menusound) @@ -1507,6 +1509,12 @@ void menuOpenDialog(struct menudialogdef *dialogdef, struct menudialog *dialog, void menuPushDialog(struct menudialogdef *dialogdef) { +#ifndef PLATFORM_N64 + // Prevent the mouse from immediately changing a slider's value, as was + // happening while entering the Audio menu. + g_AllowMouseHeld = false; +#endif + if (dialogdef) { menuUnsetModel(&g_Menus[g_MpPlayerNum].menumodel); @@ -4695,6 +4703,7 @@ void menuProcessInput(void) inputs.back2 = 0; #ifndef PLATFORM_N64 + inputs.mouseheld = false; inputs.mousemoved = false; inputs.mousescroll = 0; inputs.mousex = 0; @@ -4704,6 +4713,14 @@ void menuProcessInput(void) // ESC always acts as back inputs.back = inputKeyJustPressed(VK_ESCAPE); if (inputMouseIsEnabled() && !inputMouseIsLocked() && g_MenuMouseControl) { + inputs.mouseheld = inputKeyPressed(VK_MOUSE_LEFT); + if (!inputs.mouseheld) { + g_AllowMouseHeld = true; + if (g_MouseDimmedMode) { + g_MouseDimmedMode = false; + dialog->dimmed = false; + } + } inputs.mousescroll = inputKeyPressed(VK_MOUSE_WHEEL_DN) - inputKeyPressed(VK_MOUSE_WHEEL_UP); inputs.mousemoved = inputMouseGetPosition(&inputs.mousex, &inputs.mousey) || inputs.mousescroll; // aspect correct the X diff --git a/src/game/menuitem.c b/src/game/menuitem.c index ff3210887..99ea06fd7 100644 --- a/src/game/menuitem.c +++ b/src/game/menuitem.c @@ -2455,7 +2455,7 @@ bool menuitemSliderTick(struct menuitem *item, struct menudialog *dialog, struct if ((tickflags & MENUTICKFLAG_ITEMISFOCUSED)) { #ifndef PLATFORM_N64 - if (g_MenuUsingMouse && inputs->select) { + if (g_AllowMouseHeld && g_MenuUsingMouse && (inputs->select || inputs->mouseheld)) { // handle mouse struct menudialog *dialog = g_Menus[g_MpPlayerNum].curdialog; if (dialog) { @@ -2464,19 +2464,23 @@ bool menuitemSliderTick(struct menuitem *item, struct menudialog *dialog, struct const s32 size = right - left; const s32 delta = inputs->mousex - left; if (delta >= -8 && delta <= size + 8) { - index = (delta / (f32)size) * item->param3; - if (index < 0) { - index = 0; - } - if (index > item->param3) { - index = item->param3; - } - if (item->handler) { - item->handler(MENUOP_GET, item, &handlerdata); - handlerdata.slider.value = index; - item->handler(MENUOP_SET, item, &handlerdata); + if ((tickflags & MENUTICKFLAG_DIALOGISDIMMED) == 0) { + g_MouseDimmedMode = true; + } else { + index = (delta / (f32)size) * item->param3; + if (index < 0) { + index = 0; + } + if (index > item->param3) { + index = item->param3; + } + if (item->handler) { + item->handler(MENUOP_GET, item, &handlerdata); + handlerdata.slider.value = index; + item->handler(MENUOP_SET, item, &handlerdata); + } + return true; } - return true; } } } diff --git a/src/include/data.h b/src/include/data.h index 24c106292..87cd65bda 100644 --- a/src/include/data.h +++ b/src/include/data.h @@ -538,6 +538,8 @@ extern const struct weathercfg g_DefaultWeatherConfig; extern const struct weathercfg *g_CurWeatherConfig; extern s32 g_MenuUsingMouse; +extern s32 g_AllowMouseHeld; +extern s32 g_MouseDimmedMode; extern f32 g_ViShakeIntensityMult; extern u32 g_TexFilter2D; diff --git a/src/include/types.h b/src/include/types.h index da5d058b4..07832dcdc 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -4996,8 +4996,9 @@ struct menuinputs { /*0x10*/ s32 unk10; /*0x14*/ u8 unk14; #ifndef PLATFORM_N64 - /*0x15*/ u8 mousemoved; - /*0x16*/ s8 mousescroll; + /*0x15*/ u8 mouseheld; + /*0x16*/ u8 mousemoved; + /*0x17*/ s8 mousescroll; /*0x18*/ s32 mousex; /*0x1c*/ s32 mousey; #endif