From 7c223b1873ca82112647faabcdee9bfece7a5677 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Fri, 23 Feb 2024 14:45:25 -0500 Subject: [PATCH] g/j2: allow customizing the speedrunner menu bind (#3386) The bind carried forward from Jak 1 is annoying -- R1 shoots the gun. Allow the user to use whatever button combination they want by modifying it in the `pc-settings` file. ```clj (controller-led-status? 1360729) (speedrunner-mode-custom-bind 4098) ``` --- goal_src/jak2/pc/features/speedruns.gc | 72 ++++++++++++++++---------- goal_src/jak2/pc/pckernel-impl.gc | 10 ++-- goal_src/jak2/pc/pckernel.gc | 4 +- 3 files changed, 55 insertions(+), 31 deletions(-) diff --git a/goal_src/jak2/pc/features/speedruns.gc b/goal_src/jak2/pc/features/speedruns.gc index f57443c53f2..fc1047ab1db 100644 --- a/goal_src/jak2/pc/features/speedruns.gc +++ b/goal_src/jak2/pc/features/speedruns.gc @@ -151,32 +151,52 @@ (none))) (defmethod draw! ((this speedrun-menu)) - ;; handle opening and closing the menu - ;; allow the menu to be toggled again once one of the current buttons are released - (when (and (-> this ignore-menu-toggle?) - (or (not (cpad-hold? 0 l1)) (not (cpad-hold? 0 r1))) - (or (and (-> this opened-with-start?) (not (cpad-hold? 0 start))) - (and (not (-> this opened-with-start?)) (not (cpad-hold? 0 select))))) - (set! (-> this ignore-menu-toggle?) #f)) - (when (and (cpad-hold? 0 l1) (cpad-hold? 0 r1) (or (cpad-hold? 0 select) (cpad-hold? 0 start)) - (not (-> this ignore-menu-toggle?))) - (cond - ((= *master-mode* 'game) - (set-master-mode 'menu) - (set! (-> this draw-menu?) #t)) - ((= *master-mode* 'menu) - (set-master-mode 'game) - (set! (-> this draw-menu?) #f))) - (cpad-clear! 0 l1 r1) - ;; Track whether or not the menu was opened with start or select... - (cond - ((cpad-hold? 0 select) - (cpad-clear! 0 select) - (set! (-> this opened-with-start?) #f)) - ((cpad-hold? 0 start) - (cpad-clear! 0 start) - (set! (-> this opened-with-start?) #t))) - (set! (-> this ignore-menu-toggle?) #t)) + (cond + ((!= (-> *pc-settings* speedrunner-mode-custom-bind) 0) + ;; the user has let go of the keybind completely or partially, allow the bind to trigger again + (when (and (-> this ignore-menu-toggle?) + (!= (cpad-hold 0) + (logior (cpad-hold 0) (-> *pc-settings* speedrunner-mode-custom-bind)))) + (set! (-> this ignore-menu-toggle?) #f)) + ;; bind handler + (when (and (not (-> this ignore-menu-toggle?)) + (= (cpad-hold 0) + (logior (cpad-hold 0) (-> *pc-settings* speedrunner-mode-custom-bind)))) + (cond + ((= *master-mode* 'game) + (set-master-mode 'menu) + (set! (-> this draw-menu?) #t)) + ((= *master-mode* 'menu) + (set-master-mode 'game) + (set! (-> this draw-menu?) #f))) + (logclear! (cpad-hold 0) (-> *pc-settings* speedrunner-mode-custom-bind)) + (logclear! (cpad-pressed 0) (-> *pc-settings* speedrunner-mode-custom-bind)) + (set! (-> this ignore-menu-toggle?) #t))) + (else + (when (and (-> this ignore-menu-toggle?) + (or (not (cpad-hold? 0 l1)) (not (cpad-hold? 0 r1))) + (or (and (-> this opened-with-start?) (not (cpad-hold? 0 start))) + (and (not (-> this opened-with-start?)) (not (cpad-hold? 0 select))))) + (set! (-> this ignore-menu-toggle?) #f)) + (when (and (cpad-hold? 0 l1) (cpad-hold? 0 r1) (or (cpad-hold? 0 select) (cpad-hold? 0 start)) + (not (-> this ignore-menu-toggle?))) + (cond + ((= *master-mode* 'game) + (set-master-mode 'menu) + (set! (-> this draw-menu?) #t)) + ((= *master-mode* 'menu) + (set-master-mode 'game) + (set! (-> this draw-menu?) #f))) + (cpad-clear! 0 l1 r1) + (cond + ((cpad-hold? 0 select) + (cpad-clear! 0 select) + (set! (-> this opened-with-start?) #f)) + ((cpad-hold? 0 start) + (cpad-clear! 0 start) + (set! (-> this opened-with-start?) #t))) + (set! (-> this ignore-menu-toggle?) #t)))) + ;; render the menu (when (-> this draw-menu?) ;; handle any inputs for within the menu (cond diff --git a/goal_src/jak2/pc/pckernel-impl.gc b/goal_src/jak2/pc/pckernel-impl.gc index d6f72a6dcba..930ea989f1e 100644 --- a/goal_src/jak2/pc/pckernel-impl.gc +++ b/goal_src/jak2/pc/pckernel-impl.gc @@ -91,7 +91,7 @@ (fast-airlock? symbol) (fast-elevator? symbol) (fast-progress? symbol) - + (stats statistics) ;; gfx @@ -100,6 +100,7 @@ ;; other (controller-led-status? symbol) + (speedrunner-mode-custom-bind uint32) (text-language pc-language) ;; language for game text ) @@ -144,7 +145,8 @@ (false! (-> obj fast-progress?)) (true! (-> obj smooth-minimap?)) (false! (-> obj hires-clouds?)) - + (set! (-> obj speedrunner-mode-custom-bind) 0) + (cond ((and (= *default-territory* GAME_TERRITORY_SCEE) (= (-> obj text-language) (pc-language english))) (set! (-> obj text-language) (pc-language uk-english)) @@ -172,7 +174,7 @@ (clear-all! (-> obj music-unlocked)) (dotimes (i 6) (set! (-> obj flava-unlocked i) #f)) - + (set! (-> obj stats) *statistics*) 0) @@ -265,7 +267,7 @@ :hijack-speech-chance 0.45 :sewer-valve-target-seconds 75 - + :kill-civvie-target 40 :kill-car-target 20 )) diff --git a/goal_src/jak2/pc/pckernel.gc b/goal_src/jak2/pc/pckernel.gc index 81f53caf5ea..6ff09deb224 100644 --- a/goal_src/jak2/pc/pckernel.gc +++ b/goal_src/jak2/pc/pckernel.gc @@ -734,6 +734,7 @@ (("hires-clouds?") (set! (-> obj hires-clouds?) (file-stream-read-symbol file))) (("text-language") (set! (-> obj text-language) (the-as pc-language (file-stream-read-int file)))) (("controller-led-status?") (set! (-> obj controller-led-status?) (file-stream-read-symbol file))) + (("speedrunner-mode-custom-bind") (set! (-> obj speedrunner-mode-custom-bind) (file-stream-read-int file))) (("cheats") (set! (-> obj cheats) (the-as pc-cheats (file-stream-read-int file)))) (("cheats-revealed") (set! (-> obj cheats-revealed) (the-as pc-cheats (file-stream-read-int file)))) (("cheats-purchased") (set! (-> obj cheats-purchased) (the-as pc-cheats (file-stream-read-int file)))) @@ -783,7 +784,8 @@ (format file " (smooth-minimap? ~A)~%" (-> obj smooth-minimap?)) (format file " (hires-clouds? ~A)~%" (-> obj hires-clouds?)) (format file " (text-language ~D)~%" (-> obj text-language)) - (format file " (controller-led-status? ~D)~%" (-> obj controller-led-status?)) + (format file " (controller-led-status? ~A)~%" (-> obj controller-led-status?)) + (format file " (speedrunner-mode-custom-bind ~D)~%" (-> obj speedrunner-mode-custom-bind)) (format file " (cheats #x~x)~%" (-> obj cheats)) (format file " (cheats-revealed #x~x)~%" (-> obj cheats-revealed)) (format file " (cheats-purchased #x~x)~%" (-> obj cheats-purchased))