From 8349bfd8e646002105dfd6a7f997c26cf0e0624b Mon Sep 17 00:00:00 2001 From: Yoann Fievez Date: Fri, 5 Nov 2021 20:40:15 +0100 Subject: Refactorize check button pressed (#340) --- engine/menus/main_menu.asm | 14 +++++++------- engine/menus/pc.asm | 2 +- engine/menus/pokedex.asm | 12 ++++++------ engine/menus/save.asm | 2 +- engine/menus/start_sub_menus.asm | 4 ++-- engine/menus/text_box.asm | 10 +++++----- 6 files changed, 22 insertions(+), 22 deletions(-) (limited to 'engine/menus') diff --git a/engine/menus/main_menu.asm b/engine/menus/main_menu.asm index 95404cce..c3366b8e 100644 --- a/engine/menus/main_menu.asm +++ b/engine/menus/main_menu.asm @@ -66,7 +66,7 @@ MainMenu: ld a, [wSaveFileStatus] ld [wMaxMenuItem], a call HandleMenuInput - bit 1, a ; pressed B? + bit BIT_B_BUTTON, a jp nz, DisplayTitleScreen ; if so, go back to the title screen ld c, 20 call DelayFrames @@ -477,11 +477,11 @@ DisplayOptionMenu: ld b, a and A_BUTTON | B_BUTTON | START | D_RIGHT | D_LEFT | D_UP | D_DOWN ; any key besides select pressed? jr z, .getJoypadStateLoop - bit 1, b ; B button pressed? + bit BIT_B_BUTTON, b jr nz, .exitMenu - bit 3, b ; Start button pressed? + bit BIT_START, b jr nz, .exitMenu - bit 0, b ; A button pressed? + bit BIT_A_BUTTON, b jr z, .checkDirectionKeys ld a, [wTopMenuItemY] cp 16 ; is the cursor on Cancel? @@ -496,9 +496,9 @@ DisplayOptionMenu: jp .loop .checkDirectionKeys ld a, [wTopMenuItemY] - bit 7, b ; Down pressed? + bit BIT_D_DOWN, b jr nz, .downPressed - bit 6, b ; Up pressed? + bit BIT_D_UP, b jr nz, .upPressed cp 8 ; cursor in Battle Animation section? jr z, .cursorInBattleAnimation @@ -507,7 +507,7 @@ DisplayOptionMenu: cp 16 ; cursor on Cancel? jr z, .loop .cursorInTextSpeed - bit 5, b ; Left pressed? + bit BIT_D_LEFT, b jp nz, .pressedLeftInTextSpeed jp .pressedRightInTextSpeed .downPressed diff --git a/engine/menus/pc.asm b/engine/menus/pc.asm index 4c340e7b..6a15eaa5 100644 --- a/engine/menus/pc.asm +++ b/engine/menus/pc.asm @@ -14,7 +14,7 @@ PCMainMenu: ld hl, wFlags_0xcd60 set 5, [hl] call HandleMenuInput - bit 1, a ;if player pressed B + bit BIT_B_BUTTON, a jp nz, LogOff ld a, [wMaxMenuItem] cp 2 diff --git a/engine/menus/pokedex.asm b/engine/menus/pokedex.asm index 2af8d714..3411f729 100644 --- a/engine/menus/pokedex.asm +++ b/engine/menus/pokedex.asm @@ -95,7 +95,7 @@ HandlePokedexSideMenu: ld [wMenuWatchMovingOutOfBounds], a .handleMenuInput call HandleMenuInput - bit 1, a ; was the B button pressed? + bit BIT_B_BUTTON, a ld b, 2 jr nz, .buttonBPressed ld a, [wCurrentMenuItem] @@ -284,10 +284,10 @@ HandlePokedexListMenu: call Delay3 call GBPalNormal call HandleMenuInput - bit 1, a ; was the B button pressed? + bit BIT_B_BUTTON, a jp nz, .buttonBPressed .checkIfUpPressed - bit 6, a ; was Up pressed? + bit BIT_D_UP, a jr z, .checkIfDownPressed .upPressed ; scroll up one row ld a, [wListScrollOffset] @@ -297,7 +297,7 @@ HandlePokedexListMenu: ld [wListScrollOffset], a jp .loop .checkIfDownPressed - bit 7, a ; was Down pressed? + bit BIT_D_DOWN, a jr z, .checkIfRightPressed .downPressed ; scroll down one row ld a, [wDexMaxSeenMon] @@ -312,7 +312,7 @@ HandlePokedexListMenu: ld [wListScrollOffset], a jp .loop .checkIfRightPressed - bit 4, a ; was Right pressed? + bit BIT_D_RIGHT, a jr z, .checkIfLeftPressed .rightPressed ; scroll down 7 rows ld a, [wDexMaxSeenMon] @@ -330,7 +330,7 @@ HandlePokedexListMenu: ld [wListScrollOffset], a jp .loop .checkIfLeftPressed ; scroll up 7 rows - bit 5, a ; was Left pressed? + bit BIT_D_LEFT, a jr z, .buttonAPressed .leftPressed ld a, [wListScrollOffset] diff --git a/engine/menus/save.asm b/engine/menus/save.asm index 07eb5acb..83a5ca9b 100644 --- a/engine/menus/save.asm +++ b/engine/menus/save.asm @@ -356,7 +356,7 @@ ChangeBox:: call HandleMenuInput ld hl, hUILayoutFlags res 1, [hl] - bit 1, a ; pressed b + bit BIT_B_BUTTON, a ret nz call GetBoxSRAMLocation ld e, l diff --git a/engine/menus/start_sub_menus.asm b/engine/menus/start_sub_menus.asm index cd1e6da6..dbc6ab89 100644 --- a/engine/menus/start_sub_menus.asm +++ b/engine/menus/start_sub_menus.asm @@ -65,7 +65,7 @@ StartMenu_Pokemon:: push af call LoadScreenTilesFromBuffer1 ; restore saved screen pop af - bit 1, a ; was the B button pressed? + bit BIT_B_BUTTON, a jp nz, .loop ; if the B button wasn't pressed ld a, [wMaxMenuItem] @@ -360,7 +360,7 @@ StartMenu_Item:: ld [hl], a ; old menu item id call HandleMenuInput call PlaceUnfilledArrowMenuCursor - bit 1, a ; was the B button pressed? + bit BIT_B_BUTTON, a jr z, .useOrTossItem jp ItemMenuLoop .useOrTossItem ; if the player made the choice to use or toss the item diff --git a/engine/menus/text_box.asm b/engine/menus/text_box.asm index 5253ec48..cdb8841d 100644 --- a/engine/menus/text_box.asm +++ b/engine/menus/text_box.asm @@ -174,9 +174,9 @@ DoBuySellQuitMenu: ld [wd730], a call HandleMenuInput call PlaceUnfilledArrowMenuCursor - bit 0, a ; was A pressed? + bit BIT_A_BUTTON, a jr nz, .pressedA - bit 1, a ; was B pressed? (always true since only A/B are watched) + bit BIT_B_BUTTON, a ; always true since only A/B are watched jr z, .pressedA ld a, CANCELLED_MENU ld [wMenuExitMethod], a @@ -296,8 +296,8 @@ DisplayTwoOptionMenu: pop hl .noYesMenuInputLoop call HandleMenuInput - bit 1, a ; A button pressed? - jr nz, .noYesMenuInputLoop ; try again if A was not pressed + bit BIT_B_BUTTON, a + jr nz, .noYesMenuInputLoop ; try again if B was not pressed pop af pop hl ld [wFlags_0xcd60], a @@ -309,7 +309,7 @@ DisplayTwoOptionMenu: ld [wTwoOptionMenuID], a call HandleMenuInput pop hl - bit 1, a ; A button pressed? + bit BIT_B_BUTTON, a jr nz, .choseSecondMenuItem ; automatically choose the second option if B is pressed .pressedAButton ld a, [wCurrentMenuItem] -- cgit v1.3.1-sl0p From f68af5c6e95a11daa3bc8daaf28c4e9a779615b9 Mon Sep 17 00:00:00 2001 From: Yoann Fievez Date: Sat, 6 Nov 2021 00:45:09 +0100 Subject: Add some constants for options (#344) Co-authored-by: Rangi <35663410+Rangi42@users.noreply.github.com> --- constants/misc_constants.asm | 9 +++++++++ engine/battle/animations.asm | 2 +- engine/battle/core.asm | 2 +- engine/battle/move_effects/substitute.asm | 2 +- engine/debug/debug_menu.asm | 2 +- engine/menus/main_menu.asm | 13 ++++++------- home/start_menu.asm | 2 +- home/window.asm | 2 +- 8 files changed, 21 insertions(+), 13 deletions(-) (limited to 'engine/menus') diff --git a/constants/misc_constants.asm b/constants/misc_constants.asm index 1bb32f8e..4aff58da 100644 --- a/constants/misc_constants.asm +++ b/constants/misc_constants.asm @@ -7,3 +7,12 @@ TRUE EQU 1 const FLAG_RESET ; 0 const FLAG_SET ; 1 const FLAG_TEST ; 2 + +; wOptions +TEXT_DELAY_FAST EQU %001 ; 1 +TEXT_DELAY_MEDIUM EQU %011 ; 3 +TEXT_DELAY_SLOW EQU %101 ; 5 + + const_def 6 + const BIT_BATTLE_SHIFT ; 6 + const BIT_BATTLE_ANIMATION ; 7 diff --git a/engine/battle/animations.asm b/engine/battle/animations.asm index a93af9e9..476e937f 100644 --- a/engine/battle/animations.asm +++ b/engine/battle/animations.asm @@ -395,7 +395,7 @@ MoveAnimation: .moveAnimation ; check if battle animations are disabled in the options ld a, [wOptions] - bit 7, a + bit BIT_BATTLE_ANIMATION, a jr nz, .animationsDisabled call ShareMoveAnimations call PlayAnimation diff --git a/engine/battle/core.asm b/engine/battle/core.asm index 6c0585b6..efcba34b 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -1372,7 +1372,7 @@ EnemySendOutFirstMon: cp LINK_STATE_BATTLING jr z, .next4 ld a, [wOptions] - bit 6, a + bit BIT_BATTLE_SHIFT, a jr nz, .next4 ld hl, TrainerAboutToUseText call PrintText diff --git a/engine/battle/move_effects/substitute.asm b/engine/battle/move_effects/substitute.asm index 860b76b6..b1fd8ac2 100644 --- a/engine/battle/move_effects/substitute.asm +++ b/engine/battle/move_effects/substitute.asm @@ -45,7 +45,7 @@ SubstituteEffect_: ld l, c set HAS_SUBSTITUTE_UP, [hl] ld a, [wOptions] - bit 7, a ; battle animation is enabled? + bit BIT_BATTLE_ANIMATION, a ld hl, PlayCurrentMoveAnimation ld b, BANK(PlayCurrentMoveAnimation) jr z, .animationEnabled diff --git a/engine/debug/debug_menu.asm b/engine/debug/debug_menu.asm index 02280db0..f2297129 100644 --- a/engine/debug/debug_menu.asm +++ b/engine/debug/debug_menu.asm @@ -26,7 +26,7 @@ IF DEF(_DEBUG) ld de, DebugMenuOptions call PlaceString - ld a, 3 ; medium speed + ld a, TEXT_DELAY_MEDIUM ld [wOptions], a ld a, A_BUTTON | B_BUTTON | START diff --git a/engine/menus/main_menu.asm b/engine/menus/main_menu.asm index c3366b8e..7e4cc9be 100644 --- a/engine/menus/main_menu.asm +++ b/engine/menus/main_menu.asm @@ -125,9 +125,9 @@ MainMenu: jp SpecialEnterMap InitOptions: - ld a, 1 ; no delay + ld a, TEXT_DELAY_FAST ld [wLetterPrintingDelayFlags], a - ld a, 3 ; medium speed + ld a, TEXT_DELAY_MEDIUM ld [wOptions], a ret @@ -678,11 +678,10 @@ SetCursorPositionsFromOptions: ; 00: X coordinate of menu cursor ; 01: delay after printing a letter (in frames) TextSpeedOptionData: - db 14, 5 ; Slow - db 7, 3 ; Medium - db 1, 1 ; Fast - db 7 ; default X coordinate (Medium) - db -1 ; end + db 14, TEXT_DELAY_SLOW + db 7, TEXT_DELAY_MEDIUM + db 1, TEXT_DELAY_FAST + db 7, -1 ; end (default X coordinate) CheckForPlayerNameInSRAM: ; Check if the player name data in SRAM has a string terminator character diff --git a/home/start_menu.asm b/home/start_menu.asm index ed3d9470..5a531744 100644 --- a/home/start_menu.asm +++ b/home/start_menu.asm @@ -33,7 +33,7 @@ RedisplayStartMenu:: call EraseMenuCursor jr .loop .checkIfDownPressed - bit 7, a + bit BIT_D_DOWN, a jr z, .buttonPressed ; if the player pressed tried to go past the bottom item, wrap around to the top CheckEvent EVENT_GOT_POKEDEX diff --git a/home/window.asm b/home/window.asm index 45b207a8..0abe366d 100644 --- a/home/window.asm +++ b/home/window.asm @@ -68,7 +68,7 @@ HandleMenuInput_:: ld [wCurrentMenuItem], a ; wrap to the bottom of the menu jr .checkOtherKeys .checkIfDownPressed - bit 7, a + bit BIT_D_DOWN, a jr z, .checkOtherKeys .downPressed ld a, [wCurrentMenuItem] -- cgit v1.3.1-sl0p