UseTokenTrackerItem:
	ld a, [wUsingItemWithSelect]
	and a
	jr nz, .fromSelect
	ld c, 1 << 7 | 3
	call FadeToWhite
.fromSelect
	call ClearScreen
	ld b, SCGB_SCROLLINGMENU
	predef GetSGBLayout
	ld a, [hInMenu]
	push af
	ld a, $1
	ld [hInMenu], a
	ld hl, GoldTokenEvents
	ld de, wTempTokenTrackerOverworldInventory
	ld a, (GoldTokenEventsEnd - GoldTokenEvents) / 2 - 1
	ld c, 1
	call InitTokenTrackerList
	ld a, b
	ld [wTokenTrackerOverworldTokensCount], a
	ld a, (BingoGoldTokenEventsEnd - BingoGoldTokenEvents) / 2 - 1
	call InitTokenTrackerList
	ld a, b
	ld [wTokenTrackerBingoTokensCount], a
	ld hl, FourGoldTokenEvents
	ld a, (FourGoldTokenEventsEnd - FourGoldTokenEvents) / 2 - 1
	call InitTokenTrackerList
	ld a, b
	add a
	add a
	ld [wTokenTrackerMersonTokensCount], a
	ld hl, wTokenTrackerOverworldTokensCount
	ld b, a
	ld a, [hli]
	add b
	add [hl]
	ld [wTotalTokensCount], a
	ld hl, TokenTrader_MenuDataHeader
	call CopyMenuDataHeader
	ld hl, wTokenTrackerPage
	xor a
	ld [hli], a
	ld bc, wTokenTrackerCursorScrollPositionPairsEnd - wTokenTrackerCursorScrollPositionPairs
	call ByteFill
	call CopyMenuData2
	jr .loopNoPackSFX
.loop
	ld de, SFX_SWITCH_POCKETS
	call PlaySFX
	call ClearWholeMenuBox
	call ApplyTilemap
.loopNoPackSFX
	coord hl, 0, 0
	lb bc, 2, 18
	call TextBox
	ld a, [wTokenTrackerPage]
	ld bc, .TokenTrackerPageEntrySizeEnd - .TokenTrackerPages
	ld hl, .TokenTrackerPages
	rst AddNTimes
	ld a, [hli]
	ld e, a
	ld a, [hli]
	ld d, a
	ld a, [hli]
	push hl
	ld b, a
	call .GetTokenTrackerPageTokenCount
	ld a, [hl]
	and a
	jr nz, .dontPrintFiveQuestionMarks
	ld de, TokenTracker_FiveQuestionMarksString
	coord hl, 7, 0
	jr .noCarry
.dontPrintFiveQuestionMarks
	ld a, b
	coord hl, 1, 0
	add l
	ld l, a
	jr nc, .noCarry
	inc h
.noCarry
	call PlaceText
	ld de, .FoundTokensText
	coord hl, 1, 1
	call PlaceText
	pop hl
	ld a, [hl]
	cp 10
	push hl
	coord hl, 11, 1
	jr nc, .gotSpacing
	inc hl
.gotSpacing
	push hl
	call .GetTokenTrackerPageTokenCount
	ld d, h
	ld e, l
	pop hl
	push hl
	dec hl
	lb bc, 1, 2
	call PrintNum
	pop hl
	inc hl
	ld a, "/"
	ld [hli], a
	pop de
	ld a, [de]
	push de
	ld [wTokenTrackerPageTotal], a
	ld de, wTokenTrackerPageTotal
	lb bc, PRINTNUM_LEFTALIGN | 1, 2
	call PrintNum
	ld de, .TotalTokensText
	coord hl, 1, 2
	call PlaceText
	ld de, wTotalTokensCount
	coord hl, 8, 2
	lb bc, 1, 3
	call PrintNum
	pop hl
	inc hl
	ld a, [hli]
	ld [wMenuData2_ItemsPointerAddr], a
	ld a, [hl]
	ld [wMenuData2_ItemsPointerAddr + 1], a
	ld hl, wTokenTrackerOverworldCursor
	ld a, [wTokenTrackerPage]
	add a
	add l
	ld l, a
	jr nc, .noCarry3
	inc h
.noCarry3
	ld a, [hli]
	ld [wMenuCursorBuffer], a
	ld a, [hl]
	ld [wMenuScrollPosition], a
	push hl
	callba _InitScrollingMenu
	call ScrollingMenu_UpdatePalettes
	callba _ScrollingMenu
	pop hl
	ld a, [wMenuScrollPosition]
	ld [hld], a
	ld a, [wMenuCursorY]
	ld [hl], a
	ld hl, wTokenTrackerPage
	ld a, [wMenuJoypad]
	cp D_RIGHT
	jr nz, .notRight
	ld a, [hl]
	cp 2
	jr c, .noWraparound1
	ld [hl], -1
.noWraparound1
	inc [hl]
	jp .loop
.notRight
	cp D_LEFT
	jr nz, .notLeft
	ld a, [hl]
	and a
	jr nz, .noWraparound2
	ld [hl], 3
.noWraparound2
	dec [hl]
	jp .loop
.notLeft
	cp B_BUTTON
	jp nz, .loopNoPackSFX
	pop af
	ld [hInMenu], a
	ret

.GetTokenTrackerPageTokenCount:
	ld a, [wTokenTrackerPage]
	ld hl, wTokenTrackerOverworldTokensCount
	add l
	ld l, a
	ret nc
	inc h
	ret

tokentrackerpage: MACRO
	dw \1 ; pointer to title text
	db \2, \3 ; center spacing, found tokens offset
	dw \4 ; list pointer
ENDM

.TokenTrackerPages:
	tokentrackerpage .OverworldTokensText, 1, 65, wTempTokenTrackerOverworldInventory
.TokenTrackerPageEntrySizeEnd:
	tokentrackerpage .BingoTokensText, 3, 3, wTempTokenTrackerBingoInventory
	tokentrackerpage .MersonTokensText, 3, 32, wTempTokenTrackerMersonInventory

.TotalTokensText:
	db TX_COMPRESSED, $b0, $de, $f5, $c6, $49, $01, $d1, $68, $58, $16
	db $29, $a0

.FoundTokensText:
	db TX_COMPRESSED, $c0, $2d, $13, $2e
	db $34, $d0

.OverworldTokensText:
	db TX_COMPRESSED, $76, $0c, $6b, $a8, $2b, $ee, $61, $41, $52, $32
	db $22, $9a

.BingoTokensText:
	db TX_COMPRESSED, $12, $19, $39, $0c, $28, $2a, $46, $44
	db $53, $40

.MersonTokensText:
	db TX_COMPRESSED, $15, $35, $a0, $24, $85, $05, $48, $c8
	db $8a, $68

TokenTracker_FiveQuestionMarksString:
	db TX_COMPRESSED, $a5, $a5, $a5, $a5, $a5
	db $a6, $80

InitTokenTrackerList:
	ld [de], a
	inc de
	ld b, 0
	inc a
.loop
	push af
	push de
	ld a, [hli]
	ld e, a
	ld a, [hli]
	ld d, a
	push bc
	push hl
	ld b, CHECK_FLAG
	predef EventFlagAction
	pop hl
	pop bc
	pop de
	ld a, 0
	jr z, .overworldGoldTokenNotFound
	ld a, c
	inc b
.overworldGoldTokenNotFound
	ld [de], a
	inc de
	inc c
	pop af
	dec a
	jr nz, .loop
	ret

TokenTrader_MenuDataHeader:
	db %11100000 ; flags
	db 05, 00 ; start coords
	db 17, 19 ; end coords
	dw .MenuData2
	db 1 ; default option

.MenuData2
	db %00011100 ; flags
	db 7, $80 | SCREEN_WIDTH ; rows, quantity spacing
	db 1 ; num bytes per entry
	dbw 0, wTempTokenTrackerOverworldInventory
	dba .PrintTokenLandmark
	dba .PrintTokenNumber
	dba NULL

.PrintTokenLandmark
	push de
	ld a, [wMenuSelection]
	add a
	ld e, a
	ld d, 0
	ld hl, .GoldTokenMapNamePointerOrLandmark + 1
	add hl, de
	ld a, [hld]
	cp 3
	ld e, [hl]
	ld d, a
	jr nc, .gotMapName
	ld b, e
	cp 1
	ld de, .PhloxBingoCardString
	jr z, .getPhloxBingoCard
	cp 2
	jr nz, .getLandmarkName
	ld de, .MersonMilestoneString
.getPhloxBingoCard
	ld a, b
	push af
	call CopyName1
	pop af
	dec hl
	ld a, b
	ld [hli], a
	ld [hl], "@"
	ld de, wStringBuffer2
	jr .gotPhloxBingoCardName
.getLandmarkName
	ld e, b
	callba GetLandmarkName
	ld de, wStringBuffer1
.gotPhloxBingoCardName
	pop hl
	jp PlaceString
.gotMapName
	pop hl
	jp PlaceText

.MersonMilestoneString:
	db "Merson Milestone @"

.PhloxBingoCardString:
	db "Phlox Bingo Card @"

.PrintTokenNumber
	push de
	ld a, [wMenuScrollPosition]
	ld b, a
	ld a, [wScrollingMenuCursorPosition]
	sub b
	and a
	jr nz, .dontClearFirstTokenNumber
	coord hl, 1, 4
	lb bc, 1, 5
	call ClearBox
.dontClearFirstTokenNumber
	ld a, [wTokenTrackerPage]
	and a
	ld b, 1
	jr z, .gotStartingNumber
	dec a
	ld b, 66
	jr z, .gotStartingNumber
; doubles as entry point for mersont tokens
	ld a, [wScrollingMenuCursorPosition]
	ld c, 4
	call SimpleMultiply
	add 69
	pop hl
	push af
	call .printSingleToken
	ld a, "-"
	ld [hli], a
	pop af
	add 3
	jr .printSingleToken

.gotStartingNumber
	ld a, [wScrollingMenuCursorPosition]
	add b
	pop hl
.printSingleToken
	push hl
	ld hl, sp + 1
	ld d, h
	ld e, l
	pop hl
	push af
	cp 100
	jr nc, .noDecrement
	dec hl
.noDecrement
	lb bc, 1, 3
	call PrintNum
	pop af
	ret

.GoldTokenMapNamePointerOrLandmark:
	dw TokenTracker_FiveQuestionMarksString
	dw .CaperMartString
	dw .HappinessRaterString
	dw .HeathGymString
	dw LAUREL_CITY
	dw .ToreniaMartString
	dw ROUTE_68
	dw .Route69GateString
	dw ROUTE_70
	dw ROUTE_71
	dw ROUTE_72
	dw ROUTE_73
	dw ROUTE_74
	dw ROUTE_75
	dw ROUTE_76
	dw ROUTE_77
	dw ROUTE_79
	dw ROUTE_82
	dw ROUTE_83
	dw ROUTE_84
	dw ACQUA_MINES
	dw .LaurelForestHouseString
	dw .ClathriteB2FString
	dw .SeashoreGymString
	dw GRAVEL_TOWN
	dw MERSON_CITY
	dw HAYWARD_CITY
	dw .OwsauriGameCornerString
	dw MORAGA_TOWN
	dw JAERU_CITY
	dw BOTAN_CITY
	dw CASTRO_VALLEY
	dw CASTRO_MANSION
	dw EAGULOU_CITY
	dw RIJON_LEAGUE
	dw ROUTE_47
	dw ROUTE_48
	dw ROUTE_49
	dw ROUTE_50
	dw ROUTE_51
	dw ROUTE_52
	dw ROUTE_53
	dw ROUTE_54
	dw ROUTE_55
	dw ROUTE_56
	dw ROUTE_57
	dw ROUTE_58
	dw ROUTE_59
	dw ROUTE_60
	dw POWER_PLANT
	dw .Route61NorthGateString
	dw ROUTE_62
	dw ROUTE_63
	dw ROUTE_64
	dw ROUTE_65
	dw ROUTE_66
	dw ROUTE_67
	dw .MersonCaveB2FString
	dw .MtBoulderB1FString
	dw .SilkTunnelB5FString
	dw CASTRO_FOREST
	dw ILEX_FOREST
	dw .Route34GateString
	dw GOLDENROD_CITY
	dw GOLDENROD_CAPE
	dw TUNOD_WATERWAY
	db "1", 1
	db "2", 1
	db "3", 1
	db "1", 2
	db "2", 2
	db "3", 2
	db "4", 2
	db "5", 2
	db "6", 2
	db "7", 2
	db "8", 2

.CaperMartString
	db TX_COMPRESSED, $6d, $d1, $06, $b8, $2b, $ab
	db $ba, $68

.HappinessRaterString:
	db TX_COMPRESSED, $63, $a2, $04, $0c, $86, $84, $47, $26, $d9
	db $ae, $9a

.HeathGymString:
	db TX_COMPRESSED, $62, $7b, $69, $8c, $20, $4f
	db $d3, $40

.ToreniaMartString:
	db TX_COMPRESSED, $28, $2b, $32, $0f, $60, $ae, $ae
	db $e9, $a0

.Route69GateString:
	db TX_COMPRESSED, $72, $05, $ab, $38, $26, $8e, $66, $30, $b6
	db $ce, $9a

.LaurelForestHouseString:
	db TX_COMPRESSED, $c7, $d6, $96, $7d, $8a, $61, $59, $a2, $e3, $10, $b4, $83
	db $a6, $80

.ClathriteB2FString:
	db TX_COMPRESSED, $6d, $ee, $da, $56, $3b, $38, $24, $e6, $a9
	db $d3, $40

.SeashoreGymString:
	db TX_COMPRESSED, $50, $7a, $84, $85, $67, $18, $40, $9f
	db $a6, $80

.OwsauriGameCornerString:
	db TX_COMPRESSED, $77, $52, $35, $a5, $8e, $30, $b5, $f3, $8d, $a1, $59, $0d
	db $74, $d0

.Route61NorthGateString:
	db TX_COMPRESSED, $72, $05, $ab, $38, $26, $82, $d4, $07, $85, $76, $98, $c2, $db
	db $3a, $68

.MersonCaveB2FString:
	db TX_COMPRESSED, $15, $35, $a0, $24, $8d, $ba, $0c, $70, $49, $cd, $53
	db $a6, $80

.MtBoulderB1FString:
	db TX_COMPRESSED, $15, $bf, $41, $20, $b5, $dc, $9a, $e0, $90, $b4
	db $a7, $4d

.SilkTunnelB5FString:
	db TX_COMPRESSED, $50, $3e, $a9, $42, $9a, $21, $0f, $b0, $48, $5b, $53
	db $a6, $80

.Route34GateString:
	db TX_COMPRESSED, $72, $05, $ab, $38, $2c, $a9, $fc, $61, $6d
	db $9d, $34
