diff --git a/src/constants/duel_constants.asm b/src/constants/duel_constants.asm index f7f2eea..b7cb0af 100644 --- a/src/constants/duel_constants.asm +++ b/src/constants/duel_constants.asm @@ -5,6 +5,7 @@ DEF MAX_HP EQU 120 DEF HP_BAR_LENGTH EQU MAX_HP / 10 DEF STARTING_HAND_SIZE EQU 7 +DEF MAX_PRIZE_CARDS EQU 6 ; coin result constants DEF TAILS EQU 0 diff --git a/src/constants/duel_interface_constants.asm b/src/constants/duel_interface_constants.asm index 833d106..80a5d3b 100644 --- a/src/constants/duel_interface_constants.asm +++ b/src/constants/duel_interface_constants.asm @@ -50,3 +50,61 @@ DEF CHECK_PLAY_AREA EQU $0a ;NONE EQU $00 DEF PLAY_CHECK EQU $01 DEF SELECT_CHECK EQU $02 + +; play area screen constants +DEF DUELIST_PLAYER EQU $0 +DEF DUELIST_OPPONENT EQU $1 +DEF ARENA_CARD_PLAYER EQU 1 << DUELIST_PLAYER ; $1 +DEF ARENA_CARD_OPPONENT EQU 1 << DUELIST_OPPONENT ; $2 + + const_def 6 ; PLAY_AREA_BENCH_5 + PRIZES_1 + const INPLAYAREA_PRIZE_1 ; $6 + const INPLAYAREA_PRIZE_2 ; $7 + const INPLAYAREA_PRIZE_3 ; $8 + const INPLAYAREA_PRIZE_4 ; $9 + const INPLAYAREA_PRIZE_5 ; $a + const INPLAYAREA_PRIZE_6 ; $b + + const_def + const PLAYAREA_PLAYER_POKEMON ; $0 + const PLAYAREA_PLAYER_HAND ; $1 + const PLAYAREA_PLAYER_DISCARD_PILE ; $2 + const PLAYAREA_PLAYER_PRIZES ; $3 + const PLAYAREA_OPPONENT_POKEMON ; $4 + const PLAYAREA_OPPONENT_HAND ; $5 + const PLAYAREA_OPPONENT_DISCARD_PILE ; $6 + const PLAYAREA_OPPONENT_PRIZES ; $7 + + const_def + const INPLAYAREA_PLAYER_BENCH_1 ; $00 + const INPLAYAREA_PLAYER_BENCH_2 ; $01 + const INPLAYAREA_PLAYER_BENCH_3 ; $02 + const INPLAYAREA_PLAYER_BENCH_4 ; $03 + const INPLAYAREA_PLAYER_BENCH_5 ; $04 + const INPLAYAREA_PLAYER_ACTIVE ; $05 + const INPLAYAREA_PLAYER_HAND ; $06 + const INPLAYAREA_PLAYER_DISCARD_PILE ; $07 + const INPLAYAREA_OPP_ACTIVE ; $08 + const INPLAYAREA_OPP_HAND ; $09 + const INPLAYAREA_OPP_DISCARD_PILE ; $0a + const INPLAYAREA_OPP_BENCH_1 ; $0b + const INPLAYAREA_OPP_BENCH_2 ; $0c + const INPLAYAREA_OPP_BENCH_3 ; $0d + const INPLAYAREA_OPP_BENCH_4 ; $0e + const INPLAYAREA_OPP_BENCH_5 ; $0f + const INPLAYAREA_PLAYER_PRIZE_1 ; $10 + const INPLAYAREA_PLAYER_PRIZE_2 ; $11 + const INPLAYAREA_PLAYER_PRIZE_3 ; $12 + const INPLAYAREA_PLAYER_PRIZE_4 ; $13 + const INPLAYAREA_PLAYER_PRIZE_5 ; $14 + const INPLAYAREA_PLAYER_PRIZE_6 ; $15 + const INPLAYAREA_OPP_PRIZE_1 ; $16 + const INPLAYAREA_OPP_PRIZE_2 ; $17 + const INPLAYAREA_OPP_PRIZE_3 ; $18 + const INPLAYAREA_OPP_PRIZE_4 ; $19 + const INPLAYAREA_OPP_PRIZE_5 ; $1a + const INPLAYAREA_OPP_PRIZE_6 ; $1b +DEF NUM_INPLAYAREA_POSITIONS EQU const_value + const_def $80 + const INPLAYAREA_PLAYER_PLAY_AREA ; $80 + const INPLAYAREA_OPP_PLAY_AREA ; $81 diff --git a/src/constants/menu_constants.asm b/src/constants/menu_constants.asm index 72cccc7..835c55f 100644 --- a/src/constants/menu_constants.asm +++ b/src/constants/menu_constants.asm @@ -142,6 +142,20 @@ DEF NUM_COIN_PAGES EQU const_value DEF MENU_CANCEL EQU -1 DEF MENU_CONFIRM EQU 1 ; != -1, but uses 1 most of the time +; cursor +; cursor_transition macro args +RSRESET +DEF CURSOR_TRANSITION_STRUCT_X RB ; 0 +DEF CURSOR_TRANSITION_STRUCT_Y RB ; 1 +DEF CURSOR_TRANSITION_STRUCT_ATTR RB ; 2 +DEF CURSOR_TRANSITION_STRUCT_DIR_INDICES EQU _RS +DEF CURSOR_TRANSITION_STRUCT_INDEX_UP RB ; 3 +DEF CURSOR_TRANSITION_STRUCT_INDEX_DOWN RB ; 4 +DEF CURSOR_TRANSITION_STRUCT_INDEX_RIGHT RB ; 5 +DEF CURSOR_TRANSITION_STRUCT_INDEX_LEFT RB ; 6 + +DEF CURSOR_TRANSITION_STRUCT_LENGTH EQU _RS ; 7 + ; filter types for CardTypeFilters ; used to categorise the different cards ; i.e. in the deck building screen diff --git a/src/engine/bank01.asm b/src/engine/bank01.asm index 8bcbd1d..2f0c6be 100644 --- a/src/engine/bank01.asm +++ b/src/engine/bank01.asm @@ -451,9 +451,22 @@ DuelMenuShortcut_PlayerDiscardPile: call OpenTurnHolderDiscardPileScreen jp c, PrintDuelMenuAndHandleInput jp DuelMainInterface -; 0x439d -SECTION "Bank 1@43be", ROMX[$43be], BANK[$1] +OpenNonTurnHolderPrizeCardsScreen: + call SwapTurn + call OpenTurnHolderPrizeCardsScreen + call SwapTurn + ret + +OpenTurnHolderPrizeCardsScreen: + call CreatePrizeCardList + call InitAndDrawCardListScreenLayout + ldtx hl, ChooseCardToCheckText + ldtx de, DuelistPrizeCardsText + call SetCardListHeaderAndInfoText + ld a, PAD_A | PAD_START + ld [wNoItemSelectionMenuKeys], a + jp DisplayCardList ; draw the non-turn holder's play area screen OpenNonTurnHolderPlayAreaScreen: @@ -493,7 +506,7 @@ OpenTurnHolderHandScreen_Simple: jp DrawWideTextBox_WaitForInput .got_cards_in_hand call InitAndDrawCardListScreenLayout - ld a, PAD_START + PAD_A + ld a, PAD_A | PAD_START ld [wNoItemSelectionMenuKeys], a jp DisplayCardList @@ -2563,7 +2576,7 @@ OpenDiscardPileScreen: ldtx hl, ChooseCardToCheckText ldtx de, DuelistDiscardPileText call SetCardListHeaderAndInfoText - ld a, PAD_START + PAD_A + ld a, PAD_A | PAD_START ld [wNoItemSelectionMenuKeys], a call DisplayCardList or a @@ -3093,7 +3106,7 @@ TurnDuelistTakePrizes: ld h, $00 call LoadTxRam3 .asm_587e - farcall Func_82b6 + farcall Func_83b3 ldtx hl, DrewXPrizesText call DrawWideTextBox_WaitForInput jr .return_has_prizes @@ -3345,7 +3358,7 @@ CardPageSwitch_TrainerEnd: ZeroObjectPositionsAndToggleOAMCopy: call ZeroObjectPositions - ld a, $01 + ld a, TRUE ld [wVBlankOAMCopyToggle], a ret ; 0x5647 @@ -4080,7 +4093,7 @@ _HasAlivePokemonInPlayArea: ret OpenPlayAreaScreenForViewing: - ld a, PAD_START + PAD_A + ld a, PAD_A | PAD_START jr DisplayPlayAreaScreen OpenPlayAreaScreenForSelection: @@ -6831,9 +6844,28 @@ ShuffleDeck: ld a, b ; a = number of cards in the deck call ShuffleCards ret -; 0x6a7c -SECTION "Bank 1@6a96", ROMX[$6a96], BANK[$1] +CreatePrizeCardList: + ld a, DUELVARS_PRIZES + get_turn_duelist_var + ld c, a + ld l, DUELVARS_PRIZE_CARDS + ld de, wDuelTempList +.loop_cards + ld b, [hl] + inc hl + rr c + jr nc, .next_card + ld a, b + ld [de], a + inc de +.next_card + ld a, c + or a + jr nz, .loop_cards + ld a, $ff ; terminating byte + ld [de], a + ret SortCardsInDuelTempListByID: ld hl, hTempListPtr_ff99 diff --git a/src/engine/bank02.asm b/src/engine/bank02.asm index 315953e..e5a94ee 100644 --- a/src/engine/bank02.asm +++ b/src/engine/bank02.asm @@ -1,6 +1,522 @@ -SECTION "Bank 2@4302", ROMX[$4302], BANK[$2] +_OpenDuelCheckMenu:: + call ResetCheckMenuCursorPositionAndBlink + xor a + ld [wd0cd], a + call DrawWideTextBox +; reset cursor blink + xor a + ld [wScrollMenuCursorBlinkCounter], a + ld hl, CheckMenuData + call PlaceTextItems +.wait_input + call DoFrame + call HandleCheckMenuInput + jr nc, .wait_input + cp MENU_CANCEL + ret z +; selected, jump to the corresponding function + ld a, [wCheckMenuCursorYPosition] + sla a + ld b, a + ld a, [wCheckMenuCursorXPosition] + add b + ld hl, .jump_table + call JumpToFunctionInTable + jr _OpenDuelCheckMenu -Func_8302: +.jump_table: + dw DuelCheckMenu_InPlayArea + dw DuelCheckMenu_Glossary + dw DuelCheckMenu_YourPlayArea + dw DuelCheckMenu_OppPlayArea + +; in play area submenu +DuelCheckMenu_InPlayArea: + xor a + ld [wInPlayAreaFromSelectButton], a + farcall OpenInPlayAreaScreen + ret + +; glossary submenu +DuelCheckMenu_Glossary: + farcall Glossary.OpenScreen + ret + +; your play area submenu +; also handles here comes team rocket +DuelCheckMenu_YourPlayArea: + call ResetCheckMenuCursorPositionAndBlink + + ld a, [wPrizeCardsFaceUp] + or a + jr z, .no_here_comes_team_rocket + ld a, $02 +.no_here_comes_team_rocket + ld [wd0cd], a + + ldh a, [hWhoseTurn] +.draw + ld h, a + ld l, a + call DrawYourOrOppPlayAreaScreen + + ld a, [wCheckMenuCursorYPosition] + sla a + ld b, a + ld a, [wCheckMenuCursorXPosition] + add b + ld [wYourOrOppPlayAreaLastCursorPosition], a + ld b, $f8 ; black arrow tile + call DrawYourOrOppPlayArea_DrawArrows + + call DrawWideTextBox +; reset cursor blink + xor a + ld [wScrollMenuCursorBlinkCounter], a +; set menu data + ld hl, YourPlayAreaMenuData + ld a, [wPrizeCardsFaceUp] + or a + jr z, .print + ld hl, YourPlayAreaMenuData_WithPrizes +.print + call PlaceTextItems +.wait_input + call DoFrame + xor a + call DrawYourOrOppPlayArea_RefreshArrows + call HandleCheckMenuInput_YourOrOppPlayArea + jr nc, .wait_input + call DrawYourOrOppPlayArea_EraseArrows + cp MENU_CANCEL + ret z +; selected, jump to the corresponding function + ld a, [wCheckMenuCursorYPosition] + sla a + ld b, a + ld a, [wCheckMenuCursorXPosition] + add b + ld hl, .jump_table + call JumpToFunctionInTable + jr .draw + +.jump_table + dw OpenYourOrOppPlayAreaScreen_TurnHolderPlayArea + dw OpenYourOrOppPlayAreaScreen_TurnHolderHand + dw OpenYourOrOppPlayAreaScreen_TurnHolderDiscardPile + dw OpenYourOrOppPlayAreaScreen_TurnHolderPrizeCards + +OpenYourOrOppPlayAreaScreen_TurnHolderPlayArea: + ldh a, [hWhoseTurn] + push af + bank1call OpenTurnHolderPlayAreaScreen + pop af + ldh [hWhoseTurn], a + ret + +OpenYourOrOppPlayAreaScreen_NonTurnHolderPlayArea: + ldh a, [hWhoseTurn] + push af + bank1call OpenNonTurnHolderPlayAreaScreen + pop af + ldh [hWhoseTurn], a + ret + +OpenYourOrOppPlayAreaScreen_TurnHolderHand: + ldh a, [hWhoseTurn] + push af + bank1call OpenTurnHolderHandScreen_Simple + pop af + ldh [hWhoseTurn], a + ret + +OpenYourOrOppPlayAreaScreen_NonTurnHolderHand: + ldh a, [hWhoseTurn] + push af + bank1call OpenNonTurnHolderHandScreen_Simple + pop af + ldh [hWhoseTurn], a + ret + +OpenYourOrOppPlayAreaScreen_TurnHolderDiscardPile: + ldh a, [hWhoseTurn] + push af + bank1call OpenTurnHolderDiscardPileScreen + pop af + ldh [hWhoseTurn], a + ret + +OpenYourOrOppPlayAreaScreen_NonTurnHolderDiscardPile: + ldh a, [hWhoseTurn] + push af + bank1call OpenNonTurnHolderDiscardPileScreen + pop af + ldh [hWhoseTurn], a + ret + +OpenYourOrOppPlayAreaScreen_TurnHolderPrizeCards: + ldh a, [hWhoseTurn] + push af + bank1call OpenTurnHolderPrizeCardsScreen + pop af + ldh [hWhoseTurn], a + ret + +OpenYourOrOppPlayAreaScreen_NonTurnHolderPrizeCards: + ldh a, [hWhoseTurn] + push af + bank1call OpenNonTurnHolderPrizeCardsScreen + pop af + ldh [hWhoseTurn], a + ret + +; opp. play area submenu +; also handles clairvoyance and here comes team rocket +DuelCheckMenu_OppPlayArea: + call ResetCheckMenuCursorPositionAndBlink + bank1call IsClairvoyanceActive + jr c, .clairvoyance_on_1 + + ld a, [wPrizeCardsFaceUp] + or a + jr z, .default_1 + +; here comes team rocket on + ld a, $01 + ld [wd0cd], a + jr .begin + +.default_1 + ld a, %10000000 + ld [wd0cd], a + jr .begin + +.clairvoyance_on_1 + ld a, [wPrizeCardsFaceUp] + or a + jr z, .clairvoyance_on_here_comes_team_rocket_off_1 + +; both on + ld a, $02 + +.clairvoyance_on_here_comes_team_rocket_off_1 + ld [wd0cd], a + +.begin + ldh a, [hWhoseTurn] +.turns + ld l, a + cp PLAYER_TURN + jr nz, .opponent + ld a, OPPONENT_TURN + ld h, a + jr .cursor +.opponent + ld a, PLAYER_TURN + ld h, a +.cursor + call DrawYourOrOppPlayAreaScreen +; convert and store cursor position + ld a, [wCheckMenuCursorYPosition] + sla a + ld b, a + ld a, [wCheckMenuCursorXPosition] + add b + add 4 + ld [wYourOrOppPlayAreaLastCursorPosition], a +; draw black arrows in the play area + ld b, $f8 ; black arrow tile + call DrawYourOrOppPlayArea_DrawArrows + call DrawWideTextBox +; reset cursor blink + xor a + ld [wScrollMenuCursorBlinkCounter], a + +; place text items +; depending on clairvoyance and here comes team rocket + bank1call IsClairvoyanceActive + jr c, .clairvoyance_on_2 + ld a, [wPrizeCardsFaceUp] + or a + jr z, .default_2 + +; here comes team rocket on + ld hl, OppPlayAreaMenuData_WithPrizes + call PlaceTextItems + jr .wait_input + +.default_2 + ld hl, OppPlayAreaMenuData + call PlaceTextItems + jr .wait_input + +.clairvoyance_on_2 + ld a, [wPrizeCardsFaceUp] + or a + jr z, .clairvoyance_on_here_comes_team_rocket_off_2 + +; both on + ld hl, OppPlayAreaMenuData_WithHandAndPrizes + call PlaceTextItems + jr .wait_input + +.clairvoyance_on_here_comes_team_rocket_off_2 + ld hl, OppPlayAreaMenuData_WithHand + call PlaceTextItems + +.wait_input + call DoFrame + ld a, 1 + call DrawYourOrOppPlayArea_RefreshArrows + call HandleCheckMenuInput_YourOrOppPlayArea + jr nc, .wait_input + call DrawYourOrOppPlayArea_EraseArrows + cp MENU_CANCEL + ret z +; selected, jump to the corresponding function + ld a, [wCheckMenuCursorYPosition] + sla a + ld b, a + ld a, [wCheckMenuCursorXPosition] + add b + ld hl, .jump_table + call JumpToFunctionInTable + jr .turns + +.jump_table + dw OpenYourOrOppPlayAreaScreen_NonTurnHolderPlayArea + dw OpenYourOrOppPlayAreaScreen_NonTurnHolderHand + dw OpenYourOrOppPlayAreaScreen_NonTurnHolderDiscardPile + dw OpenYourOrOppPlayAreaScreen_NonTurnHolderPrizeCards + +CheckMenuData: + textitem 2, 14, EntirePlayAreaHiraganaText + textitem 2, 16, YourPlayAreaHiraganaText + textitem 12, 14, GlossaryText + textitem 12, 16, OpponentsPlayAreaHiraganaText + textitems_end + +YourPlayAreaMenuData: + textitem 2, 14, YourPokemonHiraganaText + textitem 12, 14, YourHandHiraganaText + textitem 2, 16, YourDiscardPileHiraganaText + textitems_end + +YourPlayAreaMenuData_WithPrizes: + textitem 2, 14, YourPokemonHiraganaText + textitem 12, 14, YourHandHiraganaText + textitem 2, 16, YourDiscardPileHiraganaText + textitem 12, 16, YourPrizesHiraganaText + textitems_end + +OppPlayAreaMenuData: + textitem 2, 14, OpponentsPokemonHiraganaText + textitem 2, 16, OpponentsDiscardPileHiraganaText + textitems_end + +OppPlayAreaMenuData_WithHand: + textitem 2, 14, OpponentsPokemonHiraganaText + textitem 12, 14, OpponentsHandHiraganaText + textitem 2, 16, OpponentsDiscardPileHiraganaText + textitems_end + +OppPlayAreaMenuData_WithPrizes: + textitem 2, 14, OpponentsPokemonHiraganaText + textitem 2, 16, OpponentsDiscardPileHiraganaText + textitem 12, 16, OpponentsPrizesHiraganaText + textitems_end + +OppPlayAreaMenuData_WithHandAndPrizes: + textitem 2, 14, OpponentsPokemonHiraganaText + textitem 12, 14, OpponentsHandHiraganaText + textitem 2, 16, OpponentsDiscardPileHiraganaText + textitem 12, 16, OpponentsPrizesHiraganaText + textitems_end + +; for a = initial offset to the cursor position in your/opp. play area screen +; (due to different layouts), +; update arrows upon cursor position change +DrawYourOrOppPlayArea_RefreshArrows: + push af + ld b, a +REPT 3 + add b +ENDR + ld c, a + ld a, [wCheckMenuCursorYPosition] + sla a + ld b, a + ld a, [wCheckMenuCursorXPosition] + add b + add c +; a = 2y + x + 4a +; update arrows if changed + ld hl, wYourOrOppPlayAreaLastCursorPosition + cp [hl] + jr z, .done ; unchanged + call DrawYourOrOppPlayArea_EraseArrows + ld [wYourOrOppPlayAreaLastCursorPosition], a + ld b, $f8 ; black arrow tile + call DrawYourOrOppPlayArea_DrawArrows +.done + pop af + ret + +; for n = [wYourOrOppPlayAreaLastCursorPosition] (2y + x), +; draw SYM_SPACE at YourOrOppPlayAreaArrowPositions[n] +DrawYourOrOppPlayArea_EraseArrows: + push af + ld a, [wYourOrOppPlayAreaLastCursorPosition] + ld b, SYM_SPACE + call DrawYourOrOppPlayArea_DrawArrows + pop af + ret + +; for a = table offset (cursor 2y + x) and b = tile to draw, +; draw the tile at YourOrOppPlayAreaArrowPositions[a] +DrawYourOrOppPlayArea_DrawArrows: + push af + push bc + ld hl, YourOrOppPlayAreaArrowPositions + sla a + ld c, a + ld b, $00 + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + pop de + pop af + + push af + or a + jr z, .player_pkmn + cp PLAYAREA_OPPONENT_POKEMON + jr z, .opponent_pkmn + cp PLAYAREA_PLAYER_PRIZES + jr z, .player_prize_cards + cp PLAYAREA_OPPONENT_PRIZES + jr nz, .loop_draw + +; opponent prize cards + push de + lb de, 19, 6 + jr .prize_cards +.player_prize_cards + push de + lb de, 5, 3 +.prize_cards + ld a, $20 + lb bc, 1, 5 + push hl + lb hl, 0, 0 + call BankswitchVRAM1 + call FillRectangle + call BankswitchVRAM0 + pop hl + pop de + ld a, [wDuelInitialPrizes] + ld e, a + jr .loop_draw + +.player_pkmn + push de + lb de, 5, 5 + xor a + lb bc, 1, 1 + push hl + lb hl, 0, 0 + call BankswitchVRAM1 + call FillRectangle + call BankswitchVRAM0 + pop hl + pop de +.opponent_pkmn + ld a, [wMaxNumPlayAreaPokemon] + ld e, a + +.loop_draw + ld a, [hli] + cp $ff + jr z, .done + ld b, a + ld a, [hli] + ld c, a + ld a, d + call WriteByteToBGMap0 + dec e + jr nz, .loop_draw +.done + pop af + ret + +; (x, y) to draw tile at +YourOrOppPlayAreaArrowPositions: + dw .PlayerPokemon ; PLAYAREA_PLAYER_POKEMON + dw .PlayerHand ; PLAYAREA_PLAYER_HAND + dw .PlayerDiscardPile ; PLAYAREA_PLAYER_DISCARD_PILE + dw .PlayerPrizeCards ; PLAYAREA_PLAYER_PRIZES + dw .OpponentPokemon ; PLAYAREA_OPPONENT_POKEMON + dw .OpponentHand ; PLAYAREA_OPPONENT_HAND + dw .OpponentDiscardPile ; PLAYAREA_OPPONENT_DISCARD_PILE + dw .OpponentPrizeCards ; PLAYAREA_OPPONENT_PRIZES + +.PlayerPokemon: + db 5, 5 + db 0, 10 + db 4, 10 + db 8, 10 + db 12, 10 + db 16, 10 + db $ff + +.PlayerHand: + db 14, 7 + db $ff + +.PlayerDiscardPile: + db 14, 5 + db $ff + +.PlayerPrizeCards: + db 0, 3 + db 5, 3 + db 0, 5 + db 5, 5 + db 0, 7 + db 5, 7 + db $ff + +.OpponentPokemon: + db 5, 7 + db 16, 3 + db 12, 3 + db 8, 3 + db 4, 3 + db 0, 3 + db $ff + +.OpponentHand: + db 0, 5 + db $ff + +.OpponentDiscardPile: + db 0, 8 + db $ff + +.OpponentPrizeCards: + db 19, 10 + db 14, 10 + db 19, 8 + db 14, 8 + db 19, 6 + db 14, 6 + db $ff + +; loads tiles and icons to display your/opp. play area screen, +; and draws the screen according to the turn player +; input: h -> [wCheckMenuPlayAreaWhichDuelist] and l -> [wCheckMenuPlayAreaWhichLayout] +DrawYourOrOppPlayAreaScreen: ld a, h ld [wCheckMenuPlayAreaWhichDuelist], a ld a, l @@ -15,6 +531,7 @@ Func_8302: call LoadMenuCursorTile jr DrawYourOrOppPlayAreaScreen_EmptiedScreen +_DrawYourOrOppPlayAreaScreen:: xor a ld [wTileMapFill], a call ZeroObjectPositions @@ -22,7 +539,7 @@ Func_8302: ld [wVBlankOAMCopyToggle], a call DoFrame call EmptyScreen -; fallthrough +; fallthrough DrawYourOrOppPlayAreaScreen_EmptiedScreen: call LoadSymbolsFont @@ -87,7 +604,8 @@ DrawYourOrOppPlayAreaScreen_EmptiedScreen: call EnableLCD ret -Func_82b6: +; Func_82b6 in tcg1 +Func_83b3: ld a, [wCheckMenuPlayAreaWhichDuelist] ld b, a ld a, [wCheckMenuPlayAreaWhichLayout] @@ -102,9 +620,99 @@ Func_82b6: ld hl, PrizeCardsCoordinateData_YourOrOppPlayArea.opponent call DrawPlayArea_PrizeCards ret -; 0x83cb -SECTION "Bank 2@4495", ROMX[$4495], BANK[$2] +DrawInPlayAreaScreen:: + xor a + ld [wTileMapFill], a + call ZeroObjectPositions + ld a, TRUE + ld [wVBlankOAMCopyToggle], a + call DoFrame + call EmptyScreen + ld a, CHECK_PLAY_AREA + ld [wDuelDisplayedScreen], a + call LoadMenuCursorTile + call LoadSymbolsFont + ld a, [wConsole] + push af + ld a, CONSOLE_DMG + ld [wConsole], a + call Func_1dff + pop af + ld [wConsole], a + bank1call SetDefaultPalettes + lb de, $80, $9f + call SetupText +; reset turn holders + ldh a, [hWhoseTurn] + ld [wCheckMenuPlayAreaWhichDuelist], a + ld [wCheckMenuPlayAreaWhichLayout], a + + ld a, [wConsole] + push af + ld a, CONSOLE_DMG + ld [wConsole], a +; player prize cards + ld hl, PrizeCardsCoordinateData_InPlayArea.player + call DrawPlayArea_PrizeCards +; player bench cards + lb de, 3, 15 + ld c, 3 + call DrawPlayArea_BenchCards +; player icons + ld hl, PlayAreaIconCoordinates.player2 + call DrawInPlayArea_Icons + + call SwapTurn + ldh a, [hWhoseTurn] + ld [wCheckMenuPlayAreaWhichDuelist], a + call SwapTurn + +; opponent prize cards + ld hl, PrizeCardsCoordinateData_InPlayArea.opponent + call DrawPlayArea_PrizeCards +; opponent bench cards + lb de, 3, 0 + ld c, 3 + call DrawPlayArea_BenchCards +; opponent icons + call SwapTurn + ld hl, PlayAreaIconCoordinates.opponent2 + call DrawInPlayArea_Icons + call SwapTurn + pop af + ld [wConsole], a + call DrawInPlayArea_ActiveCardGfx + ret + +_DrawPlayersPrizeAndBenchCards:: + xor a + ld [wTileMapFill], a + call ZeroObjectPositions + ld a, TRUE + ld [wVBlankOAMCopyToggle], a + call DoFrame + call EmptyScreen + call LoadSymbolsFont + call Func_1dff +; player cards + ld a, PLAYER_TURN + ld [wCheckMenuPlayAreaWhichDuelist], a + ld [wCheckMenuPlayAreaWhichLayout], a + ld hl, PrizeCardsCoordinateData_2.player + call DrawPlayArea_PrizeCards + lb de, 5, 10 + ld c, 3 + call DrawPlayArea_BenchCards +; opponent cards + ld a, OPPONENT_TURN + ld [wCheckMenuPlayAreaWhichDuelist], a + ld hl, PrizeCardsCoordinateData_2.opponent + call DrawPlayArea_PrizeCards + lb de, 1, 0 + ld c, 3 + call DrawPlayArea_BenchCards + ret ; draws the active card gfx at coordinates de ; of the player (or opponent) depending on wCheckMenuPlayAreaWhichDuelist @@ -162,9 +770,92 @@ DrawYourOrOppPlayArea_ActiveCardGfx: bank1call Func_6c12 pop de ret -; 0x84eb -SECTION "Bank 2@4587", ROMX[$4587], BANK[$2] +; draws player and opponent arena card graphics +; in the entire play area screen +DrawInPlayArea_ActiveCardGfx: + xor a + ld [wArenaCardsInPlayArea], a + + ld a, DUELVARS_ARENA_CARD + get_turn_duelist_var + cp -1 ; no pkmn + jr z, .opponent1 + +; set player arena pkmn bit + push af + ld a, [wArenaCardsInPlayArea] + or ARENA_CARD_PLAYER + ld [wArenaCardsInPlayArea], a + pop af +; load card gfx + call LoadCardDataToBuffer1_FromDeckIndex + ld de, v0Tiles1 + $20 tiles + ld hl, wLoadedCard1Gfx + ld a, [hli] + ld h, [hl] + ld l, a + lb bc, $30, TILE_SIZE + call LoadCardGfx + lb de, 6, 9 + bank1call DrawCardGfxToDE_BGPalIndex5 + +.opponent1 + ld a, DUELVARS_ARENA_CARD + call GetNonTurnDuelistVariable + cp -1 ; no pkmn + jr z, .draw +; set opponent arena pkmn bit + push af + ld a, [wArenaCardsInPlayArea] + or ARENA_CARD_OPPONENT + ld [wArenaCardsInPlayArea], a + pop af +; load card gfx + call SwapTurn + call LoadCardDataToBuffer1_FromDeckIndex + ld de, v0Tiles2 + $50 tiles + ld hl, wLoadedCard1Gfx + ld a, [hli] + ld h, [hl] + ld l, a + lb bc, $30, TILE_SIZE + call LoadCardGfx + lb de, 6, 2 + bank1call DrawCardGfxToDE_BGPalIndex2 + call SwapTurn + +.draw + ld a, [wArenaCardsInPlayArea] + or a + ret z ; no arena cards + + bank1call FlushAllPalettesIfNotDMG + ld a, [wArenaCardsInPlayArea] + and ARENA_CARD_PLAYER + jr z, .opponent2 +; draw player arena card + ld a, $a0 + lb de, 6, 9 + lb hl, 6, 1 + lb bc, 8, 6 + call FillRectangle + bank1call StubbedApplyBGP6OrSGB3ToCardImage + +.opponent2 + ld a, [wArenaCardsInPlayArea] + and ARENA_CARD_OPPONENT + ret z +; draw opponent arena card + call SwapTurn + ld a, $50 + lb de, 6, 2 + lb hl, 6, 1 + lb bc, 8, 6 + call FillRectangle + bank1call StubbedApplyBGP6OrSGB3ToCardImage + call SwapTurn + ret ; draws prize cards depending on the turn ; loaded in wCheckMenuPlayAreaWhichDuelist @@ -250,7 +941,41 @@ PrizeCardsCoordinateData_YourOrOppPlayArea: db 5, 17 db 5, 15 -SECTION "Bank 2@4629", ROMX[$4629], BANK[$2] +PrizeCardsCoordinateData_2: +; x and y coordinates for player prize cards +.player + db 6, 0 + db 6, 2 + db 8, 0 + db 8, 2 + db 10, 0 + db 10, 2 +; x and y coordinates for opponent prize cards +.opponent + db 4, 18 + db 4, 16 + db 2, 18 + db 2, 16 + db 0, 18 + db 0, 16 + +PrizeCardsCoordinateData_InPlayArea: +; x and y coordinates for player prize cards +.player + db 9, 1 + db 9, 3 + db 11, 1 + db 11, 3 + db 13, 1 + db 13, 3 +; x and y coordinates for opponent prize cards +.opponent + db 6, 17 + db 6, 15 + db 4, 17 + db 4, 15 + db 2, 17 + db 2, 15 ; calculates bits set up to the number of initial prizes, with upper 2 bits set, i.e: ; 6 prizes: a = %11111111 @@ -393,13 +1118,11 @@ DrawPlayArea_BenchCards: ld d, a jr .loop_2 -; draws Your/Opp Play Area icons depending on value in a -; the icons correspond to Deck, Discard Pile, and Hand -; the corresponding number of cards is printed alongside each icon -; for "Hand", text is displayed rather than an icon -; input: -; a = $00: draws player icons -; a = $01: draws opponent icons +; for a = DUELIST_PLAYER/DUELIST_OPPONENT, +; draw in Your/Opp Play Area screen: +; - hand: text and value (rather than icon) +; - deck: icon and value +; - discard pile: icon and value DrawYourOrOppPlayArea_Icons: or a jr nz, .opponent @@ -409,14 +1132,14 @@ DrawYourOrOppPlayArea_Icons: ld hl, PlayAreaIconCoordinates.opponent1 .draw -; hand icon and value +; hand text and value ld a, [wCheckMenuPlayAreaWhichDuelist] ld d, a ld e, DUELVARS_NUMBER_OF_CARDS_IN_HAND ld a, [de] ld b, a - ld a, $d0 ; hand icon, unused? - call $47a3 + ld a, $d0 ; hand icon, unused + call DrawPlayArea_HandText ; deck icon and value ld a, [wCheckMenuPlayAreaWhichDuelist] @@ -525,9 +1248,78 @@ PlayAreaIconCoordinates: db 0, 2 db 0, 6 db 0, 4 -; 0x877a -SECTION "Bank 2@47d3", ROMX[$47d3], BANK[$2] +; for [hWhoseTurn], draw in In Play Area screen: +; - hand: text and value (rather than icon) +; - deck: icon and value +; - discard pile: icon and value +DrawInPlayArea_Icons: +; hand text and value + ldh a, [hWhoseTurn] + ld d, a + ld e, DUELVARS_NUMBER_OF_CARDS_IN_HAND + ld a, [de] + ld b, a + ld a, $d0 ; hand icon, unused + call DrawPlayArea_HandText + +; deck icon and value + ldh a, [hWhoseTurn] + ld d, a + ld e, DUELVARS_NUMBER_OF_CARDS_NOT_IN_DECK + ld a, [de] + ld b, a + ld a, DECK_SIZE + sub b + ld b, a + ld a, $d4 ; deck tile + call DrawPlayArea_IconWithValue + +; discard pile icon and value + ldh a, [hWhoseTurn] + ld d, a + ld e, DUELVARS_NUMBER_OF_CARDS_IN_DISCARD_PILE + ld a, [de] + ld b, a + ld a, $d8 ; discard pile tile + call DrawPlayArea_IconWithValue + ret + +; print HandText_2 with decimal value of b = hand count +; unlike in English, no SYM_CROSS in Japanese (lacking space) +DrawPlayArea_HandText: + ld d, [hl] + inc hl + ld e, [hl] + inc hl +; text + push hl + push bc + call InitTextPrinting + ldtx hl, HandText_2 + call ProcessTextFromID + pop bc +; decimal value + ld a, b + call CalculateOnesAndTensDigits + ld hl, wDecimalDigitsSymbols + ld a, [hli] + ld b, a + ld a, [hl] + ld hl, wDefaultText + ld [hl], TX_SYMBOL + inc hl + ld [hli], a + ld [hl], TX_SYMBOL + inc hl +; draw to screen + ld a, b + ld [hli], a + ld [hl], TX_END + ld hl, wDefaultText + call ProcessText + pop hl + ret ; handle player input in check menu ; works out which cursor coordinate to go to @@ -739,10 +1531,10 @@ HandleMultiDirectionalMenu: ld e, [hl] inc hl ld d, [hl] - ld a, [wd0c1] + ld a, [wMultiDirectionalMenuCursorPosition] ld [wd0d0], a ld l, a - ld h, 7 ; length of each transition table item + ld h, CURSOR_TRANSITION_STRUCT_LENGTH call HtimesL add hl, de @@ -750,10 +1542,10 @@ HandleMultiDirectionalMenu: ldh a, [hDPadHeld] or a jp z, .check_button - inc hl - inc hl - inc hl +REPT CURSOR_TRANSITION_STRUCT_DIR_INDICES + inc hl +ENDR bit B_PAD_UP, a jr z, .else_if_down ; up @@ -784,13 +1576,12 @@ HandleMultiDirectionalMenu: ld a, [hl] .process_dpad - ld [wd0c1], a - cp $8 ; if a >= 0x8 + ld [wMultiDirectionalMenuCursorPosition], a + cp 8 jr nc, .sfx - ld b, $1 -; this loop equals to -; b = (1 << a) +; bitmask b = 1 << a + ld b, 1 .make_bitmask_loop or a jr z, .make_bitmask_done @@ -822,29 +1613,29 @@ HandleMultiDirectionalMenu: cp PRIZES_5 jr nc, .sfx ; else if it's last card, - ld a, [wd0c1] + ld a, [wMultiDirectionalMenuCursorPosition] cp 5 jr nz, .not_last_card ; place it at pos 3 ld a, 3 - ld [wd0c1], a + ld [wMultiDirectionalMenuCursorPosition], a jr .ok .not_last_card ; otherwise place at pos 2 ld a, 2 - ld [wd0c1], a + ld [wMultiDirectionalMenuCursorPosition], a .ok ld a, [wDuelInitialPrizes] cp PRIZES_3 jr nc, .handled_cursor_pos ; in this case can just sub 2 from pos - ld a, [wd0c1] + ld a, [wMultiDirectionalMenuCursorPosition] sub 2 - ld [wd0c1], a + ld [wMultiDirectionalMenuCursorPosition], a .handled_cursor_pos - ld a, [wd0c1] + ld a, [wMultiDirectionalMenuCursorPosition] ld [wd0d0], a ld b, $1 jr .make_bitmask_loop @@ -871,7 +1662,7 @@ HandleMultiDirectionalMenu: call .DrawCursor ld a, MENU_CONFIRM call PlaySFXConfirmOrCancel - ld a, [wd0c1] + ld a, [wMultiDirectionalMenuCursorPosition] scf ret @@ -887,7 +1678,7 @@ HandleMultiDirectionalMenu: and $0f ret nz bit 4, [hl] - jr nz, ZeroObjectPositionsWithCopyToggleOn + jr nz, ZeroObjectPositionsAndToggleOAMCopy_Bank02 .DrawCursor: call ZeroObjectPositions @@ -895,26 +1686,27 @@ HandleMultiDirectionalMenu: ld e, [hl] inc hl ld d, [hl] - ld a, [wd0c1] + ld a, [wMultiDirectionalMenuCursorPosition] ld l, a - ld h, 7 + ld h, CURSOR_TRANSITION_STRUCT_LENGTH call HtimesL add hl, de -; hl = [wTransitionTablePtr] + 7 * wd0c1 +; for table = [wTransitionTablePtr] and i = wMultiDirectionalMenuCursorPosition, +; hl = table[i] - ld d, [hl] + ld d, [hl] ; CURSOR_TRANSITION_STRUCT_X inc hl - ld e, [hl] + ld e, [hl] ; CURSOR_TRANSITION_STRUCT_Y inc hl - ld b, [hl] + ld b, [hl] ; CURSOR_TRANSITION_STRUCT_ATTR ld c, $00 ; cursor tile call SetOneObjectAttributes or a ret -ZeroObjectPositionsWithCopyToggleOn: +ZeroObjectPositionsAndToggleOAMCopy_Bank02: call ZeroObjectPositions - ld a, $01 + ld a, TRUE ld [wVBlankOAMCopyToggle], a ret ; 0x8be6 @@ -937,7 +1729,7 @@ OpenPrizeCardPageIfFaceUp: ld a, MENU_CONFIRM call PlaySFXConfirmOrCancel - ld a, [wd0c1] + ld a, [wMultiDirectionalMenuCursorPosition] ld c, a ld b, $1 .loop_bitmasks @@ -965,13 +1757,13 @@ OpenPrizeCardPageIfFaceUp: HandlePrizeCardPlayerSelection: xor a call GetFirstSetPrizeCard - ld [wd0c1], a + ld [wMultiDirectionalMenuCursorPosition], a .draw_screen ldh a, [hWhoseTurn] ld h, a ld l, a - call Func_8302 + call DrawYourOrOppPlayAreaScreen call DrawWideTextBox lb de, 1, 14 call InitTextPrinting @@ -997,8 +1789,8 @@ HandlePrizeCardPlayerSelection: jr nc, .loop cp $ff jr z, .loop - call ZeroObjectPositionsWithCopyToggleOn - ld a, [wd0c1] + call ZeroObjectPositionsAndToggleOAMCopy_Bank02 + ld a, [wMultiDirectionalMenuCursorPosition] ld c, a ld b, $1 .loop_bitmasks @@ -2381,7 +3173,7 @@ HandleDeckBuildScreen: OpenDeckConfigurationMenu: xor a - ld [wd0c1], a + ld [wMultiDirectionalMenuCursorPosition], a ld de, wDeckConfigurationMenuTransitionTable ld hl, wTransitionTablePtr ld a, [de] diff --git a/src/engine/bank06.asm b/src/engine/bank06.asm index 45a1aa6..51c567d 100644 --- a/src/engine/bank06.asm +++ b/src/engine/bank06.asm @@ -1,4 +1,4 @@ -SECTION "Bank 6@46a6", ROMX[$46a6], BANK[$6] +INCLUDE "engine/play_area_menu.asm" INCLUDE "engine/glossary.asm" ; 0x1897e @@ -5347,7 +5347,7 @@ DisplayBoosterContent: ldtx hl, ChooseCardToCheckText ldtx de, BoosterPackCardsText bank1call SetCardListHeaderAndInfoText - ld a, PAD_START + PAD_A + ld a, PAD_A | PAD_START ld [wNoItemSelectionMenuKeys], a bank1call DisplayCardList ret diff --git a/src/engine/duel/effect_functions2.asm b/src/engine/duel/effect_functions2.asm index 3491740..d05dd39 100644 --- a/src/engine/duel/effect_functions2.asm +++ b/src/engine/duel/effect_functions2.asm @@ -4538,7 +4538,7 @@ Poltergeist_10DamagePerTrainerEffect: ldtx hl, ChooseCardToCheckText ldtx de, DuelistHandText bank1call SetCardListHeaderAndInfoText - ld a, PAD_START + PAD_A + ld a, PAD_A | PAD_START ld [wNoItemSelectionMenuKeys], a bank1call DisplayCardList diff --git a/src/engine/glossary.asm b/src/engine/glossary.asm index 7e921fb..f8a239e 100644 --- a/src/engine/glossary.asm +++ b/src/engine/glossary.asm @@ -5,6 +5,8 @@ Glossary: lb de, $38, $9f call SetupText jr .asm_186ba + +.OpenScreen ld a, $01 ld [wd0d2], a @@ -62,7 +64,7 @@ Glossary: xor a ld de, GlossaryTransitionTable_10Topics .got_transition_table - ld [wd0c1], a + ld [wMultiDirectionalMenuCursorPosition], a ld hl, wTransitionTablePtr ld [hl], e inc hl @@ -83,13 +85,13 @@ Glossary: jr nc, .topic_menu cp $ff jr nz, .selected_topic - farcall ZeroObjectPositionsWithCopyToggleOn + farcall ZeroObjectPositionsAndToggleOAMCopy_Bank02 ldh a, [hCurScrollMenuItem] jp .main_menu .selected_topic push af - farcall ZeroObjectPositionsWithCopyToggleOn + farcall ZeroObjectPositionsAndToggleOAMCopy_Bank02 pop af call .ShowExplanation call .ShowMenuContent diff --git a/src/engine/play_area_menu.asm b/src/engine/play_area_menu.asm new file mode 100644 index 0000000..6e88689 --- /dev/null +++ b/src/engine/play_area_menu.asm @@ -0,0 +1,755 @@ +; accessed from select btn (DuelMenuShortcut_BothActivePokemon) +; or from check menu (DuelCheckMenu_InPlayArea) +OpenInPlayAreaScreen:: + ld a, INPLAYAREA_PLAYER_ACTIVE + ld [wMultiDirectionalMenuCursorPosition], a +.start + xor a + ld [wScrollMenuCursorBlinkCounter], a + farcall DrawInPlayAreaScreen + call EnableLCD + bank1call IsClairvoyanceActive + jr c, .clairvoyance_on + ld a, [wPrizeCardsFaceUp] + or a + jr z, .default +; here comes team rocket on + ld de, OpenInPlayAreaScreen_TransitionTable_WithPrizes + jr .got_transition_table +.default + ld de, OpenInPlayAreaScreen_TransitionTable + jr .got_transition_table +.clairvoyance_on + ld de, OpenInPlayAreaScreen_TransitionTable_WithHand + +.got_transition_table + ld hl, wTransitionTablePtr + ld [hl], e + inc hl + ld [hl], d + ld a, [wMultiDirectionalMenuCursorPosition] + call .PrintAssociatedText + +.on_frame + ld a, TRUE + ld [wVBlankOAMCopyToggle], a + call DoFrame + + ldh a, [hDPadHeld] + and PAD_START + jr nz, .selection + +; handle input if called from check menu +; skip input if called from select btn + ld a, [wInPlayAreaFromSelectButton] + or a + jr z, .handle_input + ldh a, [hDPadHeld] + and PAD_SELECT + jr nz, .skip_input + +.handle_input + ld a, [wMultiDirectionalMenuCursorPosition] + ld [wTempInPlayAreaCursorPosition], a + call OpenInPlayAreaScreen_HandleInput + jr c, .pressed + + ld a, [wMultiDirectionalMenuCursorPosition] + cp INPLAYAREA_PLAYER_PLAY_AREA + jp z, .show_turn_holder_play_area + cp INPLAYAREA_OPP_PLAY_AREA + jp z, .show_non_turn_holder_play_area + ld hl, wTempInPlayAreaCursorPosition + cp [hl] + call nz, .PrintAssociatedText + jr .on_frame + +.pressed + cp MENU_CANCEL + jr nz, .selection +; cancelled + call ZeroObjectPositionsAndToggleOAMCopy_Bank06 + lb de, $38, $9f + call SetupText + scf + ret + +.skip_input + call ZeroObjectPositionsAndToggleOAMCopy_Bank06 + lb de, $38, $9f + call SetupText + or a + ret + +.selection + call ZeroObjectPositionsAndToggleOAMCopy_Bank06 + xor a + ld [wd0d2], a + ld a, [wMultiDirectionalMenuCursorPosition] + ld [wPreservedInPlayAreaCursorPosition], a + ld hl, .PositionsJumpTable + call JumpToFunctionInTable + ld a, [wd0d2] + or a + jr nz, .on_frame + ld a, [wPreservedInPlayAreaCursorPosition] + ld [wMultiDirectionalMenuCursorPosition], a + jp .start + +.PrintAssociatedText: + push af + lb de, 1, 17 + call InitTextPrinting + ldtx hl, EmptyLineText + call ProcessTextFromID + + ld hl, hffbb + ld [hl], $01 + ldtx hl, HandText_2 + call ProcessTextFromID + + ld hl, hffbb + ld [hl], $00 + lb de, 1, 17 + call InitTextPrinting + pop af + ld hl, OpenInPlayAreaScreen_TextTable + ld b, 0 + sla a + ld c, a + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + ld a, h + or a + jr nz, .hand_or_discard_pile + ld a, l + cp MAX_PLAY_AREA_POKEMON + MAX_PRIZE_CARDS + jr nc, .hand_or_discard_pile + cp MAX_PLAY_AREA_POKEMON + jr nc, .prize_cards + ld a, [wMultiDirectionalMenuCursorPosition] + cp INPLAYAREA_PLAYER_HAND + jr nc, .opponent_side + + ld a, l + add DUELVARS_ARENA_CARD + get_turn_duelist_var + cp -1 + ret z + + call GetCardIDFromDeckIndex + call LoadCardDataToBuffer1_FromCardID + jr .display_card_name + +.opponent_side + ld a, l + add DUELVARS_ARENA_CARD + call GetNonTurnDuelistVariable + cp -1 + ret z + + call SwapTurn + call GetCardIDFromDeckIndex + call LoadCardDataToBuffer1_FromCardID + call SwapTurn + +.display_card_name + ld a, 18 + call CopyCardNameAndLevel + ld hl, wDefaultText + call ProcessText + ret + +.prize_cards + sub INPLAYAREA_PRIZE_1 + ld b, a + ld a, [wMultiDirectionalMenuCursorPosition] + cp INPLAYAREA_OPP_PRIZE_1 + jr nc, .opp_side_prize_cards + push bc + ld a, b + call IsCurPrizeCardRemaining + pop bc + ret z + + ld a, b + add DUELVARS_PRIZE_CARDS + get_turn_duelist_var + call GetCardIDFromDeckIndex + call LoadCardDataToBuffer1_FromCardID + jr .display_card_name + +.opp_side_prize_cards + push bc + ld a, b + call SwapTurn + call IsCurPrizeCardRemaining + call SwapTurn + pop bc + ret z + + ld a, b + add DUELVARS_PRIZE_CARDS + call GetNonTurnDuelistVariable + call SwapTurn + call GetCardIDFromDeckIndex + call LoadCardDataToBuffer1_FromCardID + call SwapTurn + jr .display_card_name + +.hand_or_discard_pile + ld a, [wMultiDirectionalMenuCursorPosition] + cp INPLAYAREA_OPP_ACTIVE + jr nc, .opp_side_print_hand_or_discard_pile + call PrintTextNoDelay + ret + +.opp_side_print_hand_or_discard_pile + call SwapTurn + call PrintTextNoDelay + call SwapTurn + ret + +.show_turn_holder_play_area: + lb de, $38, $9f + call SetupText + ldh a, [hWhoseTurn] + push af + bank1call OpenTurnHolderPlayAreaScreen + pop af + ldh [hWhoseTurn], a + ld a, [wPreservedInPlayAreaCursorPosition] + ld [wMultiDirectionalMenuCursorPosition], a + jp .start + +.show_non_turn_holder_play_area: + lb de, $38, $9f + call SetupText + ldh a, [hWhoseTurn] + push af + bank1call OpenNonTurnHolderPlayAreaScreen + pop af + ldh [hWhoseTurn], a + ld a, [wPreservedInPlayAreaCursorPosition] + ld [wMultiDirectionalMenuCursorPosition], a + jp .start + +.PositionsJumpTable: + dw OpenInPlayAreaScreen_TurnHolderPlayArea ; INPLAYAREA_PLAYER_BENCH_1 + dw OpenInPlayAreaScreen_TurnHolderPlayArea ; INPLAYAREA_PLAYER_BENCH_2 + dw OpenInPlayAreaScreen_TurnHolderPlayArea ; INPLAYAREA_PLAYER_BENCH_3 + dw OpenInPlayAreaScreen_TurnHolderPlayArea ; INPLAYAREA_PLAYER_BENCH_4 + dw OpenInPlayAreaScreen_TurnHolderPlayArea ; INPLAYAREA_PLAYER_BENCH_5 + dw OpenInPlayAreaScreen_TurnHolderPlayArea ; INPLAYAREA_PLAYER_ACTIVE + dw OpenInPlayAreaScreen_TurnHolderHand ; INPLAYAREA_PLAYER_HAND + dw OpenInPlayAreaScreen_TurnHolderDiscardPile ; INPLAYAREA_PLAYER_DISCARD_PILE + dw OpenInPlayAreaScreen_NonTurnHolderPlayArea ; INPLAYAREA_OPP_ACTIVE + dw OpenInPlayAreaScreen_NonTurnHolderHand ; INPLAYAREA_OPP_HAND + dw OpenInPlayAreaScreen_NonTurnHolderDiscardPile ; INPLAYAREA_OPP_DISCARD_PILE + dw OpenInPlayAreaScreen_NonTurnHolderPlayArea ; INPLAYAREA_OPP_BENCH_1 + dw OpenInPlayAreaScreen_NonTurnHolderPlayArea ; INPLAYAREA_OPP_BENCH_2 + dw OpenInPlayAreaScreen_NonTurnHolderPlayArea ; INPLAYAREA_OPP_BENCH_3 + dw OpenInPlayAreaScreen_NonTurnHolderPlayArea ; INPLAYAREA_OPP_BENCH_4 + dw OpenInPlayAreaScreen_NonTurnHolderPlayArea ; INPLAYAREA_OPP_BENCH_5 + dw OpenInPlayAreaScreen_TurnHolderPrizeCards ; INPLAYAREA_PLAYER_PRIZE_1 + dw OpenInPlayAreaScreen_TurnHolderPrizeCards ; INPLAYAREA_PLAYER_PRIZE_2 + dw OpenInPlayAreaScreen_TurnHolderPrizeCards ; INPLAYAREA_PLAYER_PRIZE_3 + dw OpenInPlayAreaScreen_TurnHolderPrizeCards ; INPLAYAREA_PLAYER_PRIZE_4 + dw OpenInPlayAreaScreen_TurnHolderPrizeCards ; INPLAYAREA_PLAYER_PRIZE_5 + dw OpenInPlayAreaScreen_TurnHolderPrizeCards ; INPLAYAREA_PLAYER_PRIZE_6 + dw OpenInPlayAreaScreen_NonTurnHolderPrizeCards ; INPLAYAREA_OPP_PRIZE_1 + dw OpenInPlayAreaScreen_NonTurnHolderPrizeCards ; INPLAYAREA_OPP_PRIZE_2 + dw OpenInPlayAreaScreen_NonTurnHolderPrizeCards ; INPLAYAREA_OPP_PRIZE_3 + dw OpenInPlayAreaScreen_NonTurnHolderPrizeCards ; INPLAYAREA_OPP_PRIZE_4 + dw OpenInPlayAreaScreen_NonTurnHolderPrizeCards ; INPLAYAREA_OPP_PRIZE_5 + dw OpenInPlayAreaScreen_NonTurnHolderPrizeCards ; INPLAYAREA_OPP_PRIZE_6 + +OpenInPlayAreaScreen_TurnHolderPlayArea: + lb de, $38, $9f + call SetupText +; convert INPLAYAREA_PLAYER_* to PLAY_AREA_* + ld a, [wMultiDirectionalMenuCursorPosition] + inc a + cp INPLAYAREA_PLAYER_ACTIVE + 1 + jr nz, .on_bench + xor a ; PLAY_AREA_ARENA +.on_bench + ld [wCurPlayAreaSlot], a + add DUELVARS_ARENA_CARD + get_turn_duelist_var + cp -1 + ret z + + call GetCardIDFromDeckIndex + call LoadCardDataToBuffer1_FromCardID + xor a + ld [wCurPlayAreaY], a + bank1call OpenCardPage_FromCheckPlayArea + ret + +OpenInPlayAreaScreen_NonTurnHolderPlayArea: + lb de, $38, $9f + call SetupText +; convert INPLAYAREA_OPP_* to PLAY_AREA_* + ld a, [wMultiDirectionalMenuCursorPosition] + sub INPLAYAREA_OPP_ACTIVE + or a + jr z, .active + sub INPLAYAREA_OPP_BENCH_1 - INPLAYAREA_OPP_ACTIVE - PLAY_AREA_BENCH_1 +.active + ld [wCurPlayAreaSlot], a + add DUELVARS_ARENA_CARD + call GetNonTurnDuelistVariable + cp -1 + ret z + + call SwapTurn + call GetCardIDFromDeckIndex + call LoadCardDataToBuffer1_FromCardID + xor a + ld [wCurPlayAreaY], a + bank1call OpenCardPage_FromCheckPlayArea + call SwapTurn + ret + +OpenInPlayAreaScreen_TurnHolderPrizeCards: + ld a, [wMultiDirectionalMenuCursorPosition] + sub INPLAYAREA_PLAYER_PRIZE_1 + call IsCurPrizeCardRemaining + jr nz, .found + ld a, $01 + ld [wd0d2], a + ret + +.found + lb de, $38, $9f + call SetupText + ld a, [wMultiDirectionalMenuCursorPosition] + sub INPLAYAREA_PLAYER_PRIZE_1 + add DUELVARS_PRIZE_CARDS + get_turn_duelist_var + call GetCardIDFromDeckIndex + call LoadCardDataToBuffer1_FromCardID + bank1call OpenCardPage_FromHand + ret + +OpenInPlayAreaScreen_NonTurnHolderPrizeCards: + ld a, [wMultiDirectionalMenuCursorPosition] + sub INPLAYAREA_OPP_PRIZE_1 + call SwapTurn + call IsCurPrizeCardRemaining + call SwapTurn + jr nz, .found + ld a, $01 + ld [wd0d2], a + ret + +.found + lb de, $38, $9f + call SetupText + ld a, [wMultiDirectionalMenuCursorPosition] + sub INPLAYAREA_OPP_PRIZE_1 + add DUELVARS_PRIZE_CARDS + call GetNonTurnDuelistVariable + call SwapTurn + call GetCardIDFromDeckIndex + call LoadCardDataToBuffer1_FromCardID + bank1call OpenCardPage_FromHand + call SwapTurn + ret + +OpenInPlayAreaScreen_TurnHolderHand: + lb de, $38, $9f + call SetupText + ldh a, [hWhoseTurn] + push af + bank1call OpenTurnHolderHandScreen_Simple + pop af + ldh [hWhoseTurn], a + ret + +OpenInPlayAreaScreen_NonTurnHolderHand: + lb de, $38, $9f + call SetupText + ldh a, [hWhoseTurn] + push af + bank1call OpenNonTurnHolderHandScreen_Simple + pop af + ldh [hWhoseTurn], a + ret + +OpenInPlayAreaScreen_TurnHolderDiscardPile: + lb de, $38, $9f + call SetupText + ldh a, [hWhoseTurn] + push af + bank1call OpenTurnHolderDiscardPileScreen + pop af + ldh [hWhoseTurn], a + ret + +OpenInPlayAreaScreen_NonTurnHolderDiscardPile: + lb de, $38, $9f + call SetupText + ldh a, [hWhoseTurn] + push af + bank1call OpenNonTurnHolderDiscardPileScreen + pop af + ldh [hWhoseTurn], a + ret + +; only hand and discard pile slots have text id +OpenInPlayAreaScreen_TextTable: + dw PLAY_AREA_BENCH_1 ; INPLAYAREA_PLAYER_BENCH_1 + dw PLAY_AREA_BENCH_2 ; INPLAYAREA_PLAYER_BENCH_2 + dw PLAY_AREA_BENCH_3 ; INPLAYAREA_PLAYER_BENCH_3 + dw PLAY_AREA_BENCH_4 ; INPLAYAREA_PLAYER_BENCH_4 + dw PLAY_AREA_BENCH_5 ; INPLAYAREA_PLAYER_BENCH_5 + dw PLAY_AREA_ARENA ; INPLAYAREA_PLAYER_ACTIVE + tx DuelistHandText_2 ; INPLAYAREA_PLAYER_HAND + tx DuelistDiscardPileText_2 ; INPLAYAREA_PLAYER_DISCARD_PILE + dw PLAY_AREA_ARENA ; INPLAYAREA_OPP_ACTIVE + tx DuelistHandText_2 ; INPLAYAREA_OPP_HAND + tx DuelistDiscardPileText_2 ; INPLAYAREA_OPP_DISCARD_PILE + dw PLAY_AREA_BENCH_1 ; INPLAYAREA_OPP_BENCH_1 + dw PLAY_AREA_BENCH_2 ; INPLAYAREA_OPP_BENCH_2 + dw PLAY_AREA_BENCH_3 ; INPLAYAREA_OPP_BENCH_3 + dw PLAY_AREA_BENCH_4 ; INPLAYAREA_OPP_BENCH_4 + dw PLAY_AREA_BENCH_5 ; INPLAYAREA_OPP_BENCH_5 + dw INPLAYAREA_PRIZE_1 ; INPLAYAREA_PLAYER_PRIZE_1 + dw INPLAYAREA_PRIZE_2 ; INPLAYAREA_PLAYER_PRIZE_2 + dw INPLAYAREA_PRIZE_3 ; INPLAYAREA_PLAYER_PRIZE_3 + dw INPLAYAREA_PRIZE_4 ; INPLAYAREA_PLAYER_PRIZE_4 + dw INPLAYAREA_PRIZE_5 ; INPLAYAREA_PLAYER_PRIZE_5 + dw INPLAYAREA_PRIZE_6 ; INPLAYAREA_PLAYER_PRIZE_6 + dw INPLAYAREA_PRIZE_1 ; INPLAYAREA_OPP_PRIZE_1 + dw INPLAYAREA_PRIZE_2 ; INPLAYAREA_OPP_PRIZE_2 + dw INPLAYAREA_PRIZE_3 ; INPLAYAREA_OPP_PRIZE_3 + dw INPLAYAREA_PRIZE_4 ; INPLAYAREA_OPP_PRIZE_4 + dw INPLAYAREA_PRIZE_5 ; INPLAYAREA_OPP_PRIZE_5 + dw INPLAYAREA_PRIZE_6 ; INPLAYAREA_OPP_PRIZE_6 + +MACRO in_play_area_cursor_transition + cursor_transition \1, \2, \3, INPLAYAREA_\4, INPLAYAREA_\5, INPLAYAREA_\6, INPLAYAREA_\7 +ENDM + +OpenInPlayAreaScreen_TransitionTable: + in_play_area_cursor_transition $18, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_2, PLAYER_BENCH_5 + in_play_area_cursor_transition $30, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_3, PLAYER_BENCH_1 + in_play_area_cursor_transition $48, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_4, PLAYER_BENCH_2 + in_play_area_cursor_transition $60, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_5, PLAYER_BENCH_3 + in_play_area_cursor_transition $78, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_1, PLAYER_BENCH_4 + in_play_area_cursor_transition $30, $6c, $00, OPP_ACTIVE, PLAYER_BENCH_1, PLAYER_DISCARD_PILE, PLAYER_DISCARD_PILE + in_play_area_cursor_transition $78, $80, $00, PLAYER_DISCARD_PILE, PLAYER_BENCH_1, PLAYER_ACTIVE, PLAYER_ACTIVE + in_play_area_cursor_transition $78, $70, $00, OPP_ACTIVE, PLAYER_HAND, PLAYER_ACTIVE, PLAYER_ACTIVE + in_play_area_cursor_transition $78, $34, OAM_XFLIP, OPP_BENCH_1, PLAYER_ACTIVE, OPP_DISCARD_PILE, OPP_DISCARD_PILE + in_play_area_cursor_transition $30, $20, OAM_XFLIP, OPP_BENCH_1, OPP_DISCARD_PILE, OPP_ACTIVE, OPP_ACTIVE + in_play_area_cursor_transition $30, $38, OAM_XFLIP, OPP_BENCH_1, PLAYER_ACTIVE, OPP_ACTIVE, OPP_ACTIVE + in_play_area_cursor_transition $90, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_5, OPP_BENCH_2 + in_play_area_cursor_transition $78, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_1, OPP_BENCH_3 + in_play_area_cursor_transition $60, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_2, OPP_BENCH_4 + in_play_area_cursor_transition $48, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_3, OPP_BENCH_5 + in_play_area_cursor_transition $30, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_4, OPP_BENCH_1 + +OpenInPlayAreaScreen_TransitionTable_WithHand: + in_play_area_cursor_transition $18, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_2, PLAYER_BENCH_5 + in_play_area_cursor_transition $30, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_3, PLAYER_BENCH_1 + in_play_area_cursor_transition $48, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_4, PLAYER_BENCH_2 + in_play_area_cursor_transition $60, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_5, PLAYER_BENCH_3 + in_play_area_cursor_transition $78, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_1, PLAYER_BENCH_4 + in_play_area_cursor_transition $30, $6c, $00, OPP_ACTIVE, PLAYER_BENCH_1, PLAYER_DISCARD_PILE, PLAYER_DISCARD_PILE + in_play_area_cursor_transition $78, $80, $00, PLAYER_DISCARD_PILE, PLAYER_BENCH_1, PLAYER_ACTIVE, PLAYER_ACTIVE + in_play_area_cursor_transition $78, $70, $00, OPP_ACTIVE, PLAYER_HAND, PLAYER_ACTIVE, PLAYER_ACTIVE + in_play_area_cursor_transition $78, $34, OAM_XFLIP, OPP_BENCH_1, PLAYER_ACTIVE, OPP_DISCARD_PILE, OPP_DISCARD_PILE + in_play_area_cursor_transition $30, $20, OAM_XFLIP, OPP_BENCH_1, OPP_DISCARD_PILE, OPP_ACTIVE, OPP_ACTIVE + in_play_area_cursor_transition $30, $38, OAM_XFLIP, OPP_HAND, PLAYER_ACTIVE, OPP_ACTIVE, OPP_ACTIVE + in_play_area_cursor_transition $90, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_5, OPP_BENCH_2 + in_play_area_cursor_transition $78, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_1, OPP_BENCH_3 + in_play_area_cursor_transition $60, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_2, OPP_BENCH_4 + in_play_area_cursor_transition $48, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_3, OPP_BENCH_5 + in_play_area_cursor_transition $30, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_4, OPP_BENCH_1 + +OpenInPlayAreaScreen_TransitionTable_WithPrizes: + in_play_area_cursor_transition $18, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_2, PLAYER_BENCH_5 + in_play_area_cursor_transition $30, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_3, PLAYER_BENCH_1 + in_play_area_cursor_transition $48, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_4, PLAYER_BENCH_2 + in_play_area_cursor_transition $60, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_5, PLAYER_BENCH_3 + in_play_area_cursor_transition $78, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_1, PLAYER_BENCH_4 + in_play_area_cursor_transition $30, $6c, $00, OPP_ACTIVE, PLAYER_BENCH_1, PLAYER_DISCARD_PILE, PLAYER_PRIZE_1 + in_play_area_cursor_transition $78, $80, $00, PLAYER_DISCARD_PILE, PLAYER_BENCH_1, PLAYER_ACTIVE, PLAYER_ACTIVE + in_play_area_cursor_transition $78, $70, $00, OPP_ACTIVE, PLAYER_HAND, PLAYER_ACTIVE, PLAYER_ACTIVE + in_play_area_cursor_transition $78, $34, OAM_XFLIP, OPP_BENCH_1, PLAYER_ACTIVE, OPP_PRIZE_1, OPP_DISCARD_PILE + in_play_area_cursor_transition $30, $20, OAM_XFLIP, OPP_BENCH_1, OPP_DISCARD_PILE, OPP_ACTIVE, OPP_ACTIVE + in_play_area_cursor_transition $30, $38, OAM_XFLIP, OPP_BENCH_1, PLAYER_ACTIVE, OPP_ACTIVE, OPP_ACTIVE + in_play_area_cursor_transition $90, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_5, OPP_BENCH_2 + in_play_area_cursor_transition $78, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_1, OPP_BENCH_3 + in_play_area_cursor_transition $60, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_2, OPP_BENCH_4 + in_play_area_cursor_transition $48, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_3, OPP_BENCH_5 + in_play_area_cursor_transition $30, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_4, OPP_BENCH_1 + in_play_area_cursor_transition $08, $5c, $00, OPP_ACTIVE, PLAYER_PRIZE_3, PLAYER_PRIZE_2, PLAYER_PRIZE_1 + in_play_area_cursor_transition $30, $5c, OAM_XFLIP, OPP_ACTIVE, PLAYER_PRIZE_4, PLAYER_ACTIVE, PLAYER_PRIZE_1 + in_play_area_cursor_transition $08, $6c, $00, PLAYER_PRIZE_1, PLAYER_PRIZE_5, PLAYER_PRIZE_4, PLAYER_PRIZE_3 + in_play_area_cursor_transition $30, $6c, OAM_XFLIP, PLAYER_PRIZE_2, PLAYER_PRIZE_6, PLAYER_ACTIVE, PLAYER_PRIZE_3 + in_play_area_cursor_transition $08, $7c, $00, PLAYER_PRIZE_3, PLAYER_BENCH_1, PLAYER_PRIZE_6, PLAYER_PRIZE_5 + in_play_area_cursor_transition $30, $7c, OAM_XFLIP, PLAYER_PRIZE_4, PLAYER_BENCH_1, PLAYER_ACTIVE, PLAYER_PRIZE_5 + in_play_area_cursor_transition $a0, $44, OAM_XFLIP, OPP_PRIZE_3, PLAYER_ACTIVE, OPP_PRIZE_1, OPP_PRIZE_2 + in_play_area_cursor_transition $78, $44, $00, OPP_PRIZE_4, PLAYER_ACTIVE, OPP_PRIZE_1, OPP_ACTIVE + in_play_area_cursor_transition $a0, $34, OAM_XFLIP, OPP_PRIZE_5, OPP_PRIZE_1, OPP_PRIZE_3, OPP_PRIZE_4 + in_play_area_cursor_transition $78, $34, $00, OPP_PRIZE_6, OPP_PRIZE_2, OPP_PRIZE_3, OPP_ACTIVE + in_play_area_cursor_transition $a0, $24, OAM_XFLIP, OPP_BENCH_1, OPP_PRIZE_3, OPP_PRIZE_5, OPP_PRIZE_6 + in_play_area_cursor_transition $78, $24, $00, OPP_BENCH_1, OPP_PRIZE_4, OPP_PRIZE_5, OPP_ACTIVE + +OpenInPlayAreaScreen_TransitionTable_WithHandAndPrizes: + in_play_area_cursor_transition $18, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_2, PLAYER_BENCH_5 + in_play_area_cursor_transition $30, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_3, PLAYER_BENCH_1 + in_play_area_cursor_transition $48, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_4, PLAYER_BENCH_2 + in_play_area_cursor_transition $60, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_5, PLAYER_BENCH_3 + in_play_area_cursor_transition $78, $8c, $00, PLAYER_ACTIVE, PLAYER_PLAY_AREA, PLAYER_BENCH_1, PLAYER_BENCH_4 + in_play_area_cursor_transition $30, $6c, $00, OPP_ACTIVE, PLAYER_BENCH_1, PLAYER_DISCARD_PILE, PLAYER_PRIZE_1 + in_play_area_cursor_transition $78, $80, $00, PLAYER_DISCARD_PILE, PLAYER_BENCH_1, PLAYER_ACTIVE, PLAYER_ACTIVE + in_play_area_cursor_transition $78, $70, $00, OPP_ACTIVE, PLAYER_HAND, PLAYER_ACTIVE, PLAYER_ACTIVE + in_play_area_cursor_transition $78, $34, OAM_XFLIP, OPP_BENCH_1, PLAYER_ACTIVE, OPP_PRIZE_1, OPP_DISCARD_PILE + in_play_area_cursor_transition $30, $20, OAM_XFLIP, OPP_BENCH_1, OPP_DISCARD_PILE, OPP_ACTIVE, OPP_ACTIVE + in_play_area_cursor_transition $30, $38, OAM_XFLIP, OPP_HAND, PLAYER_ACTIVE, OPP_ACTIVE, OPP_ACTIVE + in_play_area_cursor_transition $90, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_5, OPP_BENCH_2 + in_play_area_cursor_transition $78, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_1, OPP_BENCH_3 + in_play_area_cursor_transition $60, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_2, OPP_BENCH_4 + in_play_area_cursor_transition $48, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_3, OPP_BENCH_5 + in_play_area_cursor_transition $30, $14, OAM_XFLIP, OPP_PLAY_AREA, OPP_ACTIVE, OPP_BENCH_4, OPP_BENCH_1 + in_play_area_cursor_transition $08, $5c, $00, OPP_ACTIVE, PLAYER_PRIZE_3, PLAYER_PRIZE_2, PLAYER_PRIZE_1 + in_play_area_cursor_transition $30, $5c, OAM_XFLIP, OPP_ACTIVE, PLAYER_PRIZE_4, PLAYER_ACTIVE, PLAYER_PRIZE_1 + in_play_area_cursor_transition $08, $6c, $00, PLAYER_PRIZE_1, PLAYER_PRIZE_5, PLAYER_PRIZE_4, PLAYER_PRIZE_3 + in_play_area_cursor_transition $30, $6c, OAM_XFLIP, PLAYER_PRIZE_2, PLAYER_PRIZE_6, PLAYER_ACTIVE, PLAYER_PRIZE_3 + in_play_area_cursor_transition $08, $7c, $00, PLAYER_PRIZE_3, PLAYER_BENCH_1, PLAYER_PRIZE_6, PLAYER_PRIZE_5 + in_play_area_cursor_transition $30, $7c, OAM_XFLIP, PLAYER_PRIZE_4, PLAYER_BENCH_1, PLAYER_ACTIVE, PLAYER_PRIZE_5 + in_play_area_cursor_transition $a0, $44, OAM_XFLIP, OPP_PRIZE_3, PLAYER_ACTIVE, OPP_PRIZE_1, OPP_PRIZE_2 + in_play_area_cursor_transition $78, $44, $00, OPP_PRIZE_4, PLAYER_ACTIVE, OPP_PRIZE_1, OPP_ACTIVE + in_play_area_cursor_transition $a0, $34, OAM_XFLIP, OPP_PRIZE_5, OPP_PRIZE_1, OPP_PRIZE_3, OPP_PRIZE_4 + in_play_area_cursor_transition $78, $34, $00, OPP_PRIZE_6, OPP_PRIZE_2, OPP_PRIZE_3, OPP_ACTIVE + in_play_area_cursor_transition $a0, $24, OAM_XFLIP, OPP_BENCH_1, OPP_PRIZE_3, OPP_PRIZE_5, OPP_PRIZE_6 + in_play_area_cursor_transition $78, $24, $00, OPP_BENCH_1, OPP_PRIZE_4, OPP_PRIZE_5, OPP_ACTIVE + +; variant of HandleMultiDirectionalMenu +OpenInPlayAreaScreen_HandleInput: + xor a + ld [wMenuInputSFX], a + ld hl, wTransitionTablePtr + ld e, [hl] + inc hl + ld d, [hl] + ld a, [wMultiDirectionalMenuCursorPosition] + ld l, a + ld h, CURSOR_TRANSITION_STRUCT_LENGTH + call HtimesL + add hl, de + + ldh a, [hDPadHeld] + or a + jp z, .check_button +; check d-pad +REPT CURSOR_TRANSITION_STRUCT_DIR_INDICES + inc hl +ENDR + bit B_PAD_UP, a + jr z, .elif_down +; up + ld a, [hl] + jr .process_dpad + +.elif_down + inc hl + bit B_PAD_DOWN, a + jr z, .elif_right +; down + ld a, [hl] + jr .process_dpad + +.elif_right + inc hl + bit B_PAD_RIGHT, a + jr z, .elif_left +; right + ld a, [hl] + jr .process_dpad + +.elif_left + inc hl + bit B_PAD_LEFT, a + jp z, .check_button +; left + ld a, [hl] + +.process_dpad + push af + ld a, [wMultiDirectionalMenuCursorPosition] + ld [wPreservedInPlayAreaCursorPosition], a + pop af + ld [wMultiDirectionalMenuCursorPosition], a + cp INPLAYAREA_PLAYER_ACTIVE + jr c, .player_area + cp INPLAYAREA_OPP_BENCH_1 + jr c, .next + cp INPLAYAREA_PLAYER_PRIZE_1 + jr c, .opponent_area + cp INPLAYAREA_OPP_PRIZE_1 + jr c, .player_prize_cards + cp NUM_INPLAYAREA_POSITIONS + jr c, .opponent_prize_cards + jr .next + +.player_area + ld a, DUELVARS_NUMBER_OF_POKEMON_IN_PLAY_AREA + get_turn_duelist_var + dec a + jr nz, .player_has_benched_pkmn +; no benched pkmn, so move to play area + ld a, INPLAYAREA_PLAYER_PLAY_AREA + ld [wMultiDirectionalMenuCursorPosition], a + jr .next +.player_has_benched_pkmn + ld b, a + ld a, [wMultiDirectionalMenuCursorPosition] + cp b + jr c, .next +; check wrap + ldh a, [hDPadHeld] + bit B_PAD_RIGHT, a + jr z, .on_left + xor a + ld [wMultiDirectionalMenuCursorPosition], a + jr .next +.on_left + ld a, b + dec a + ld [wMultiDirectionalMenuCursorPosition], a + jr .next + +.opponent_area + ld a, DUELVARS_NUMBER_OF_POKEMON_IN_PLAY_AREA + call GetNonTurnDuelistVariable + dec a + jr nz, .opponent_has_benched_pkmn +; no benched pkmn, so move to play area + ld a, INPLAYAREA_OPP_PLAY_AREA + ld [wMultiDirectionalMenuCursorPosition], a + jr .next +.opponent_has_benched_pkmn + ld b, a + ld a, [wMultiDirectionalMenuCursorPosition] + sub INPLAYAREA_OPP_BENCH_1 + cp b + jr c, .next +; check wrap + ldh a, [hDPadHeld] + bit B_PAD_LEFT, a + jr z, .on_right + ld a, INPLAYAREA_OPP_BENCH_1 + ld [wMultiDirectionalMenuCursorPosition], a + jr .next +.on_right + ld a, b + add INPLAYAREA_OPP_BENCH_1 - 1 + ld [wMultiDirectionalMenuCursorPosition], a + jr .next + +.player_prize_cards + sub INPLAYAREA_PLAYER_PRIZE_1 + ld hl, wDuelInitialPrizes + cp [hl] + jp nc, OpenInPlayAreaScreen_HandleInput + jr .next + +.opponent_prize_cards + sub INPLAYAREA_OPP_PRIZE_1 + ld hl, wDuelInitialPrizes + cp [hl] + jp nc, OpenInPlayAreaScreen_HandleInput + +.next + ld a, SFX_CURSOR + ld [wMenuInputSFX], a +; reset cursor blink + xor a + ld [wScrollMenuCursorBlinkCounter], a + +.check_button + ldh a, [hKeysPressed] + and PAD_A | PAD_B + jr z, .no_btns + and PAD_A + jr nz, .a_btn +; b btn + ld a, MENU_CANCEL + farcall PlaySFXConfirmOrCancel + scf + ret + +.a_btn + call .DrawCursor + ld a, MENU_CONFIRM + farcall PlaySFXConfirmOrCancel + ld a, [wMultiDirectionalMenuCursorPosition] + scf + ret + +.no_btns + ld a, [wMenuInputSFX] + or a + jr z, .skip_sfx + call PlaySFX +.skip_sfx + ld hl, wScrollMenuCursorBlinkCounter + ld a, [hl] + inc [hl] + and $0f + ret nz + bit 4, [hl] + jr nz, ZeroObjectPositionsAndToggleOAMCopy_Bank06 + +.DrawCursor: + call ZeroObjectPositions + ld hl, wTransitionTablePtr + ld e, [hl] + inc hl + ld d, [hl] + ld a, [wMultiDirectionalMenuCursorPosition] + ld l, a + ld h, CURSOR_TRANSITION_STRUCT_LENGTH + call HtimesL + add hl, de +; for table = [wTransitionTablePtr] and i = wMultiDirectionalMenuCursorPosition, +; hl = table[i] + + ld d, [hl] ; CURSOR_TRANSITION_STRUCT_X + inc hl + ld e, [hl] ; CURSOR_TRANSITION_STRUCT_Y + inc hl + ld b, [hl] ; CURSOR_TRANSITION_STRUCT_ATTR + ld c, $00 ; cursor tile + call SetOneObjectAttributes + or a + ret + +ZeroObjectPositionsAndToggleOAMCopy_Bank06: + call ZeroObjectPositions + ld a, TRUE + ld [wVBlankOAMCopyToggle], a + ret + +; a = prize card index +; get bit a, DUELVARS_PRIZES +IsCurPrizeCardRemaining: + ld b, 1 +.loop_bitmask + or a + jr z, .get_bit + sla b + dec a + jr .loop_bitmask +.get_bit + ld a, DUELVARS_PRIZES + get_turn_duelist_var + and b + ret diff --git a/src/home/duel_menus.asm b/src/home/duel_menus.asm index 6d2edf3..65a96b0 100644 --- a/src/home/duel_menus.asm +++ b/src/home/duel_menus.asm @@ -1,9 +1,9 @@ OpenDuelCheckMenu:: ldh a, [hBankROM] push af - ld a, $02 ; BANK(_OpenDuelCheckMenu) + ld a, BANK(_OpenDuelCheckMenu) call BankswitchROM - call $4000 ; _OpenDuelCheckMenu + call _OpenDuelCheckMenu pop af call BankswitchROM ret @@ -11,11 +11,11 @@ OpenDuelCheckMenu:: OpenInPlayAreaScreen_FromSelectButton:: ldh a, [hBankROM] push af - ld a, $06 ; BANK(OpenInPlayAreaScreen) + ld a, BANK(OpenInPlayAreaScreen) call BankswitchROM - ld a, $1 + ld a, TRUE ld [wInPlayAreaFromSelectButton], a - call $4000 ; OpenInPlayAreaScreen + call OpenInPlayAreaScreen pop bc ld a, b call BankswitchROM @@ -34,9 +34,9 @@ DrawYourOrOppPlayAreaScreen_Bank0:: ld [wCheckMenuPlayAreaWhichLayout], a ldh a, [hBankROM] push af - ld a, $02 ; BANK(_DrawYourOrOppPlayAreaScreen) + ld a, BANK(_DrawYourOrOppPlayAreaScreen) call BankswitchROM - call $4321 ; _DrawYourOrOppPlayAreaScreen + call _DrawYourOrOppPlayAreaScreen call DrawWideTextBox pop af call BankswitchROM @@ -45,9 +45,9 @@ DrawYourOrOppPlayAreaScreen_Bank0:: DrawPlayersPrizeAndBenchCards: ldh a, [hBankROM] push af - ld a, $02 ; BANK(_DrawPlayersPrizeAndBenchCards) + ld a, BANK(_DrawPlayersPrizeAndBenchCards) call BankswitchROM - call $4453 ; _DrawPlayersPrizeAndBenchCards + call _DrawPlayersPrizeAndBenchCards pop af call BankswitchROM ret diff --git a/src/wram.asm b/src/wram.asm index 8dc88ca..fab9ac6 100644 --- a/src/wram.asm +++ b/src/wram.asm @@ -1834,7 +1834,7 @@ wCheckMenuPlayAreaWhichDuelist:: ; d0bf wCheckMenuPlayAreaWhichLayout:: ; d0c0 ds $1 -wd0c1:: ; d0c1 +wMultiDirectionalMenuCursorPosition:: ; d0c1 ds $1 ; pointer to transition table data @@ -1847,22 +1847,33 @@ wDuelInitialPrizesUpperBitsSet:: ; d0c4 wd0c4:: ; d0c4 ds $1 - ds $3 + ds $1 + +wPreservedInPlayAreaCursorPosition:: ; d0c6 + ds $1 + +wTempInPlayAreaCursorPosition:: ; d0c7 + ds $1 ; number of prize cards still to be ; picked by the player wNumberOfPrizeCardsToSelect:: ; d0c8 ds $1 - ds $4 + ds $3 + +; stores ARENA_CARD_PLAYER/ARENA_CARD_OPPONENT flag +wArenaCardsInPlayArea:: ; d0cc + ds $1 wd0cd:: ; d0cd ds $1 +wYourOrOppPlayAreaLastCursorPosition:: ; d0ce ds $1 -; $00 when the "In Play Area" screen has been opened from the Check menu -; $01 when the "In Play Area" screen has been opened by pressing the select button +; FALSE when the "In Play Area" screen has been opened from the Check menu +; TRUE when the "In Play Area" screen has been opened by pressing the select button wInPlayAreaFromSelectButton:: ; d0cf ds $1