menu
menu:
call fade_out
bcall(_grbufclr)
ld bc,$240c ;c = largeur, b = hauteur
xor a ;a = x
ld l,a ;l = y
ld ix,title ;sprite de titre
call ionLargeSprite
ld hl,$201d
ld (pencol),hl
ld hl,monochrome_str
bcall(_vputs) ;afficher "MONOCHROME" sous le sprite de titre
xor a ;option choisie par défaut
ld de,$2B1D ;e = pencol, d = penrow
ld hl,menu_sample ;
call drawMenu ;afficher le menu
call fade_in
call menuKey ;attendre une réponse
exit:
ret
newGame:
call fade_out
bcall(_grbufclr)
call ionFastCopy
call fade_in
ld hl,genderTxt
call drawDialogue
call ionFastCopy
bcall(_GetKey)
ld de,$0108
push de
ld bc,$1c12
ld hl,player_man_right
call gbaDrawMaskSprite
pop de
ld bc,$3e12
ld hl,player_woman_left
call gbaDrawMaskSprite
xor a
ld (menu_cursor),a
call draw_new_game_cursor
ret
;une boîte de dialogue
drawDialogue:
ld bc,$1560
ld de,$002b
push hl
call draw_frame
pop hl
ld de,$2C02
ld b,1
ld a,COORD_SKIP
ld (textWait),a ;nous voulons une valeur non-zéro
jr drawMenu_start
;menu, avec options
drawMenu:
ld (menu_cursor),a
ld a,(hl)
inc hl
ld (optionList),hl
ld ix,menuCoordinates+1
ld (ix-1),a ;combien d'options il y a
add a,a
ld c,a
ld b,0
add hl,bc
rra
ld b,a
xor a
drawMenu_start:
ld (coordSMC),a
ld (penCol),de
ld a,e
ld (defaultCol),a
ld a,d ;a = penRow
drawMenuLoop:
coordSMC = $+1
jr $ ;ne sauver pas les coordonnées
ld a,e
sub 4
ld (ix),a ;coord X
ld (ix+1),d ;coord Y
inc ix
inc ix
COORD_SKIP = $-coordSMC-1
ld a,(hl)
push ix
drawTextLoop:
push de
bcall(_vPutMap)
pop de
ld a,(textWait) ;= 0 si pas de delai, != 0 s'il y en a
or a
call nz,textDelay
inc hl
ld a,(hl)
or a
jr z,endOfLine
cp $FE
call z,newLine
cp $FF
jr nz,drawTextLoop
endOfLine:
pop ix
inc a
jr nz,addNewLine
inc hl
ld e,(hl)
ld (penCol),de
inc hl
djnz drawMenuLoop
addNewLine:
call newLine
djnz drawMenuLoop
ld hl,textWait
ld (hl),0
ret
textDelay:
exx
xor a
call getKey
inc a
jr z,$+6
xor a
ld (textWait),a
ld b,6 ;charger ici une valeur selon la vitesse du texte
push bc
call ionFastCopy
pop bc
djnz $-5
exx
ret
newLine:
ld a,d
add a,6 ;penRow+6
ld d,a
defaultCol = $+1
ld e,0
ld (penCol),de
inc hl
ld a,(hl)
ret
menuSelect:
ld a,(menu_cursor)
add a,a
ld c,a
ld b,0
optionList = $+1
ld hl,$0000
add hl,bc
ld a,(hl)
inc hl
ld h,(hl)
ld l,a
jp (hl)
menuKey:
call drawCursor
menuKeyLoop:
ei
halt
halt
di
;verif 2nd/clear
ld a,$BF ;groupe 7 (Y= -> Graph, 2nd, Mode, Del)
call getKey
cp 223 ;2nd
jr z,menuSelect
;verif fleches
;*************************
ld hl,menuKeyLoop ;*
push hl ;* où sauter
;*************************
ld a,$FE ;les fleches
call getKey
or $F0 ;effacer bits 4-7
ld b,a
inc b ;si b+1 = 0, b = $FF alors on n'a pas touché une fleche
ld hl,cursorWait ;le compteur/delai
jr nz,$+4 ;sauter si une touche a été poussée
ld (hl),b ;remettre le compteur à zéro
ret
dec (hl) ;compteur-1
ret p ;quitter si positif (>=0)
ld (hl),cursor_speed
push af
call drawCursor ;effacer le cursor
pop af
;*************************
ld hl,drawCursor ;*
push hl ;* où sauter
;*************************
ld hl,menu_cursor
rra
jr nc,cursorDown
rra
jr nc,cursorLeft
rra
jr nc,cursorRight
cursorUp:
ld a,(hl)
or a
ret z
ld b,a ;menu_cursor actuel
call getCursorCoords ;ne modifie pas la valeur de DE
ld a,(hl) ;coordonnée X
findNextUp:
dec b
dec hl
dec hl
cp (hl)
jr z,foundUp
jr findNextUp
ret
foundUp:
ld a,b
ld (menu_cursor),a
ret
cursorDown:
ld a,(menuCoordinates) ;# de coordinées
dec a
cp (hl)
ret z
ld c,(hl) ;menu_cursor actuel
sub c ;nombre d'options - cursor actuel
ret z
ld b,a ;nombre de coordonnées à chercher
call getCursorCoords ;ne modifie pas la valeur de DE
ld a,(hl) ;coordonnée X
findNextDown
inc c
inc hl
inc hl
cp (hl)
jr z,foundDown
djnz findNextDown
ret
foundDown:
ld a,c
ld (menu_cursor),a
ret
cursorLeft:
ld a,(hl)
or a
ret z
dec (hl)
ret
cursorRight:
ld a,(menuCoordinates) ;# de coordinées
dec a
cp (hl)
ret z
inc (hl)
ret
drawCursor:
;afficher le cursor
call getCursorCoords
ld a,(hl) ;x
inc hl
ld l,(hl) ;y
ld ix,cursorSprite
ld b,5
call ionPutSprite
call ionFastCopy
ret
getCursorCoords:
ld a,(menu_cursor)
add a,a
ld e,a
ld d,0
ld hl,menuCoordinates+1
add hl,de
ret
getKey:
out (1),a
push af
pop af ;un petit delai
in a,(1)
ret
cursorSprite:
.db %10000000
.db %11000000
.db %11100000
.db %11000000
.db %10000000
cursorWait:
.db 0
textWait:
.db 0
menuCoordinates:
.db 0 ;nombre de choix
.dw $0000
.dw $0000
.dw $0000
.dw $0000
.dw $0000
.dw $0000
.dw $0000
menu_sample:
.db 3 ;nombre de choix
.dw new_game
.dw newGame
.dw exit
.db "Continuer",0
.db "Nouveau jeu",0
.db "Quitter",0
menu_battle:
.db 4
.db "Attaquer",$FF,$36,"Pok",$96,"mon",0
.db "Inventaire",$FF,$36,"Fuite",0
genderTxt:
.db $94,"tes vous un gar",$b3,"on ou une",$FE
.db "fille ?",0
Je suis en train de finir les boîtes de dialogues, tu peux voir que le code pour afficher un menu/boîte de dialogue est plus simple
(il ne faut que "ld hl,dialogueTxt \ call drawDialogue").