aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Client/mod/scripts/vscripts
diff options
context:
space:
mode:
authorJack <66967891+ASpoonPlaysGames@users.noreply.github.com>2022-11-10 00:05:18 +0000
committerGitHub <noreply@github.com>2022-11-10 00:05:18 +0000
commitf5e4a7be5b6d48006e5f3b9ac218993aa4ee284e (patch)
treeb9fe9e2a720fa0ccf612bffa0f8cba265c83719c /Northstar.Client/mod/scripts/vscripts
parent0a5c705f662773ecb97a9b06d2c92e023307b441 (diff)
downloadNorthstarMods-f5e4a7be5b6d48006e5f3b9ac218993aa4ee284e.tar.gz
NorthstarMods-f5e4a7be5b6d48006e5f3b9ac218993aa4ee284e.zip
Improve mouse capture handling in menus (#520)
* rework mouse capture handling * small improvement to comment * move to new script file * refactor to use only the capturePanel * refactor part 2 * github please commit everything * remove non-implemented global function * cleanup * rename variable * formatting and a comment * run callbacks for menus * update comment accordingly * small formatting change * slight refactor to avoid duplicate code * improve comment * pass correct parameters * newline at end of file :)
Diffstat (limited to 'Northstar.Client/mod/scripts/vscripts')
-rw-r--r--Northstar.Client/mod/scripts/vscripts/sh_menu_models.gnut36
-rw-r--r--Northstar.Client/mod/scripts/vscripts/ui/menu_map_select.nut2
-rw-r--r--Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut2
-rw-r--r--Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut2
-rw-r--r--Northstar.Client/mod/scripts/vscripts/ui/ui_mouse_capture.nut60
5 files changed, 63 insertions, 39 deletions
diff --git a/Northstar.Client/mod/scripts/vscripts/sh_menu_models.gnut b/Northstar.Client/mod/scripts/vscripts/sh_menu_models.gnut
index 6d446654..0bcb7864 100644
--- a/Northstar.Client/mod/scripts/vscripts/sh_menu_models.gnut
+++ b/Northstar.Client/mod/scripts/vscripts/sh_menu_models.gnut
@@ -207,19 +207,9 @@
#endif // CLIENT && MP
#if UI
- struct
- {
- table MouseMovementCaptureFunctionsTable = {}
- } file
-
- const MOUSE_ROTATE_MULTIPLIER = 25.0
-
global function UpdateUIMapSupportsMenuModels
global function RunMenuClientFunction
global function UI_SetPresentationType
-
- global function AddMouseMovementCaptureHandler
- global function UICodeCallback_MouseMovementCapture
#endif // UI
global const STORE_BG_DEFAULT = 0
@@ -2897,30 +2887,4 @@
RunClientScript( "UpdateMenuToHarvester" )
}
}
-
- void function AddMouseMovementCaptureHandler( var menu, void functionref( int, int ) func )
- {
- file.MouseMovementCaptureFunctionsTable.rawset( menu, func )
- }
-
- void function UpdateMouseMovementCaptureFunctions( int deltaX, int deltaY )
- {
- var activeMenu = GetActiveMenu()
- if ( file.MouseMovementCaptureFunctionsTable.rawin( activeMenu ) )
- file.MouseMovementCaptureFunctionsTable.rawget( activeMenu )(deltaX, deltaY)
- }
-
- void function UICodeCallback_MouseMovementCapture( var capturePanel, int deltaX, int deltaY )
- {
- float screenScaleXModifier = 1920.0 / GetScreenSize()[0] // 1920 is base screen width
- float mouseXRotateDelta = deltaX * screenScaleXModifier * MOUSE_ROTATE_MULTIPLIER
- //printt( "deltaX:", deltaX, "deltaY:", deltaY )
-
- float screenScaleYModifier = 1080.0 / GetScreenSize()[1] // 1920 is base screen width
- float mouseYRotationDelta = deltaY * screenScaleYModifier * MOUSE_ROTATE_MULTIPLIER
-
- UpdateMouseMovementCaptureFunctions( deltaX, deltaY )
-
- RunMenuClientFunction( "UpdateMouseRotateDelta", mouseXRotateDelta, mouseYRotationDelta )
- }
#endif // UI
diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_map_select.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_map_select.nut
index 930e472b..8e8071f5 100644
--- a/Northstar.Client/mod/scripts/vscripts/ui/menu_map_select.nut
+++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_map_select.nut
@@ -43,7 +43,7 @@ void function InitMapsMenu()
{
file.menu = GetMenu( "MapsMenu" )
- AddMouseMovementCaptureHandler( file.menu, UpdateMouseDeltaBuffer )
+ AddMouseMovementCaptureHandler( Hud_GetChild(file.menu, "MouseMovementCapture"), UpdateMouseDeltaBuffer )
AddMenuEventHandler( file.menu, eUIEvent.MENU_CLOSE, OnCloseMapsMenu )
diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut
index 329ea73f..3f643aa3 100644
--- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut
+++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut
@@ -83,7 +83,7 @@ void function InitModMenu()
RuiSetImage( rui, "basicImage", $"ui/menu/common/dialog_error" )
}
- AddMouseMovementCaptureHandler( file.menu, UpdateMouseDeltaBuffer )
+ AddMouseMovementCaptureHandler( Hud_GetChild(file.menu, "MouseMovementCapture"), UpdateMouseDeltaBuffer )
// UI Events
AddMenuEventHandler( file.menu, eUIEvent.MENU_OPEN, OnModMenuOpened )
diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut
index eb068374..d9b11ccc 100644
--- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut
+++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut
@@ -142,7 +142,7 @@ void function InitServerBrowserMenu()
{
file.menu = GetMenu( "ServerBrowserMenu" )
- AddMouseMovementCaptureHandler( file.menu, UpdateMouseDeltaBuffer )
+ AddMouseMovementCaptureHandler( Hud_GetChild(file.menu, "MouseMovementCapture"), UpdateMouseDeltaBuffer )
// Get menu stuff
file.serverButtons = GetElementsByClassname( file.menu, "ServerButton" )
diff --git a/Northstar.Client/mod/scripts/vscripts/ui/ui_mouse_capture.nut b/Northstar.Client/mod/scripts/vscripts/ui/ui_mouse_capture.nut
new file mode 100644
index 00000000..fa5c9217
--- /dev/null
+++ b/Northstar.Client/mod/scripts/vscripts/ui/ui_mouse_capture.nut
@@ -0,0 +1,60 @@
+untyped // untyped purely so I can index into a table with var
+
+global function AddMouseMovementCaptureHandler
+global function UICodeCallback_MouseMovementCapture
+
+struct
+{
+ // a table of capturePanels and menus, each of which contains an array of callbacks
+ table< var, array< void functionref( int deltaX, int deltaY ) > > mouseMovementCaptureCallbacks = {}
+} file
+
+// this function registers a callback (or "handler") function for a MouseMovementCapture menu panel
+// use this for scrollbars, sliders, etc.
+void function AddMouseMovementCaptureHandler( var capturePanelOrMenu, void functionref( int deltaX, int deltaY ) func )
+{
+ // if the capturePanel or menu already has an array in the table, we append to the array
+ // if not, we should create the array, [func] just turns func into an array
+ if ( capturePanelOrMenu in file.mouseMovementCaptureCallbacks )
+ file.mouseMovementCaptureCallbacks[capturePanelOrMenu].append( func )
+ else
+ file.mouseMovementCaptureCallbacks[capturePanelOrMenu] <- [func]
+}
+
+void function RunMouseMovementCallbacks( var capturePanelOrMenu, int deltaX, int deltaY )
+{
+ // check that the capturePanelOrMenu is in the table before trying anything stupid
+ if ( capturePanelOrMenu in file.mouseMovementCaptureCallbacks )
+ {
+ // iterate through the different callback functions
+ foreach ( void functionref( int deltaX, int deltaY ) callback in file.mouseMovementCaptureCallbacks[capturePanelOrMenu] )
+ {
+ // run the callback function
+ callback( deltaX, deltaY )
+ }
+ }
+}
+
+void function UICodeCallback_MouseMovementCapture( var capturePanel, int deltaX, int deltaY )
+{
+ // run callbacks for the capturePanel
+ RunMouseMovementCallbacks( capturePanel, deltaX, deltaY )
+
+ // get the current menu and run callbacks, this preserves backwards compatibility
+ RunMouseMovementCallbacks( GetActiveMenu(), deltaX, deltaY )
+
+ // everything below here originally existed in vanilla sh_menu_models.gnut and is meant to be used for like all of their rotation stuff
+ // its easier to move this here than to add a shared callback for all of the vanilla capture handlers (there are like >20)
+
+ // this const was moved instead of made global because it was literally only used in the code below
+ const MOUSE_ROTATE_MULTIPLIER = 25.0
+
+ float screenScaleXModifier = 1920.0 / GetScreenSize()[0] // 1920 is base screen width
+ float mouseXRotateDelta = deltaX * screenScaleXModifier * MOUSE_ROTATE_MULTIPLIER
+ //printt( "deltaX:", deltaX, "screenScaleModifier:", screenScaleModifier, "mouseRotateDelta:", mouseRotateDelta )
+
+ float screenScaleYModifier = 1080.0 / GetScreenSize()[1] // 1080 is base screen height
+ float mouseYRotationDelta = deltaY * screenScaleYModifier * MOUSE_ROTATE_MULTIPLIER
+
+ RunMenuClientFunction( "UpdateMouseRotateDelta", mouseXRotateDelta, mouseYRotationDelta )
+}