Skip to content

Commit

Permalink
g/j2: allow customizing the speedrunner menu bind (#3386)
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
xTVaser authored Feb 23, 2024
1 parent 7ae1b4b commit 7c223b1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 31 deletions.
72 changes: 46 additions & 26 deletions goal_src/jak2/pc/features/speedruns.gc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions goal_src/jak2/pc/pckernel-impl.gc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
(fast-airlock? symbol)
(fast-elevator? symbol)
(fast-progress? symbol)

(stats statistics)

;; gfx
Expand All @@ -100,6 +100,7 @@

;; other
(controller-led-status? symbol)
(speedrunner-mode-custom-bind uint32)

(text-language pc-language) ;; language for game text
)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -172,7 +174,7 @@
(clear-all! (-> obj music-unlocked))
(dotimes (i 6)
(set! (-> obj flava-unlocked i) #f))

(set! (-> obj stats) *statistics*)
0)

Expand Down Expand Up @@ -265,7 +267,7 @@
:hijack-speech-chance 0.45

:sewer-valve-target-seconds 75

:kill-civvie-target 40
:kill-car-target 20
))
Expand Down
4 changes: 3 additions & 1 deletion goal_src/jak2/pc/pckernel.gc
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 7c223b1

Please sign in to comment.