Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu work #452

Merged
merged 3 commits into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ INCLUDE "constants/battle_tower_constants.asm"
INCLUDE "constants/cry_constants.asm"
INCLUDE "constants/audio_constants.asm"
INCLUDE "constants/printer_constants.asm"
INCLUDE "constants/menu_constants.asm"
33 changes: 33 additions & 0 deletions constants/menu_constants.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
; MenuDataHeader flags
const_def
shift_const MENU_RESTORE_TILES ; Will be set if MENU_BACKUP_TILES(_2) is set.
shift_const MENU_UNUSED_1
shift_const MENU_UNUSED_2
shift_const MENU_NO_CLICK_SFX
shift_const MENU_SPRITE_ANIMS
shift_const MENU_UNUSED_3
shift_const MENU_BACKUP_TILES
shift_const MENU_BACKUP_TILES_2

; VerticalMenu/DoNthMenu/SetUpMenu/_2DMenu MenuDataHeader2 flags
; Per flag the comment specifies which menus actually implement it
const_def
shift_const STATICMENU_DISABLE_B ; VerticalMenu/_2DMenu
shift_const STATICMENU_ENABLE_SELECT ; VerticalMenu/_2DMenu
shift_const STATICMENU_ENABLE_LEFT_RIGHT ; DoNthMenu/SetUpMenu
shift_const STATICMENU_ENABLE_START ; DoNthMenu/SetUpMenu
shift_const STATICMENU_PLACE_TITLE ; VerticalMenu
shift_const STATICMENU_WRAP ; All
shift_const STATICMENU_NO_TOP_SPACING ; VerticalMenu/_2DMenu
shift_const STATICMENU_CURSOR ; VerticalMenu/_2DMenu

; ScrollingMenu MenuDataHeader2 flags
const_def
shift_const SCROLLINGMENU_CALL_FUNCTION1_CANCEL
shift_const SCROLLINGMENU_CALL_FUNCTION3_NO_SWITCH
shift_const SCROLLINGMENU_ENABLE_LEFT
shift_const SCROLLINGMENU_ENABLE_RIGHT
shift_const SCROLLINGMENU_DISPLAY_ARROWS
shift_const SCROLLINGMENU_ENABLE_FUNCTION3
shift_const SCROLLINGMENU_ENABLE_START
shift_const SCROLLINGMENU_ENABLE_SELECT
8 changes: 4 additions & 4 deletions data/default_names.asm
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
ChrisNameMenuHeader: ; 882b5
db $40 ; flags
db MENU_BACKUP_TILES ; flags
db 00, 00 ; start coords
db 11, 10 ; end coords
dw .MaleNames
db 1 ; ????
db 0 ; default option

.MaleNames: ; 882be
db $91 ; flags
db STATICMENU_CURSOR | STATICMENU_PLACE_TITLE | STATICMENU_DISABLE_B ; flags
db 5 ; items
db "NEW NAME@"
MalePlayerNameArray: ; 882c9
Expand All @@ -19,15 +19,15 @@ MalePlayerNameArray: ; 882c9
db " NAME @" ; title

KrisNameMenuHeader: ; 882e5
db $40 ; flags
db MENU_BACKUP_TILES ; flags
db 00, 00 ; start coords
db 11, 10 ; end coords
dw .FemaleNames
db 1 ; ????
db 0 ; default option

.FemaleNames: ; 882ee
db $91 ; flags
db STATICMENU_CURSOR | STATICMENU_PLACE_TITLE | STATICMENU_DISABLE_B ; flags
db 5 ; items
db "NEW NAME@"
FemalePlayerNameArray: ; 882f9
Expand Down
272 changes: 272 additions & 0 deletions docs/menu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
### Everything you've ever wanted to know about menus*

##### *but were afraid to ask

## Contents

- [ScrollingMenu](#scrollingmenu)
- [\_2DMenu](#_2dmenu)
- [DoNthMenu/SetUpMenu](#donthmenusetupmenu)
- [VerticalMenu](#verticalmenu)
- [Misc/Generic](#miscgeneric)

## ScrollingMenu

This is the only menu that does scrolling. It doesn't draw any TextBox around the menu.

Structure:
```
.MenuDataHeader:
db $40 ; flags
db 04, 02 ; start coords
db 13, 17 ; end coords
dw .MenuData2
db 1 ; default option

.MenuData2:
db $00 ; flags
db 5, 0 ; rows, columns
db 1 ; horizontal spacing
dba Items
dba Function1
dba Function2
dba Function3
```

wMenuData2Flags:
```
7: Select is functional
6: Start is functional
5: Call Function3
4: Show arrows on the right-hand side
3: D-Left is functional
2: D-Right is functional
1: Call Function3 only if [wSwitchItem] is 0
0: Call Function1 to display the cancel entry
```

If the columns entry in MenuDataHeader2 of a scrolling menu is 0, Function2 isn't called either. It doesn't affect the position of the arrows.

Call state for functions in MenuDataHeader2 of ScrollingMenu:
```
All of them:
[MenuSelection] = Current item. -1 is the CANCEL item.
[MenuSelectionQuantity] = Quantity of the current item.

Function1: Called to display a menu entry.
de = Cursor position in TileMap

Function2: Called to display the quantity of a menu entry.
de = Cursor position in TileMap + columns

Function3: Called to display anything else, whenever the cursor is moved.
```
There is no register of importance that should be preserved in any of these functions.

The `; horizontal spacing` item in each MenuData2 is a misnomer. It changes how the Items struct looks.
If it's 1:
```
db entries not including cancel
db entry1
db entry2
db -1 ; cancel
...
```
If it's 2:
```
db entries not including cancel
db entry1, quantity1
db entry2, quantity2
db -1 ; cancel
...
```
In case it's 1, [MenuSelectionQuantity] will simply contain the next entry.

## \_2DMenu

This, like is implied by the name, is a 2-dimensional menu, where you can move your cursor in all 4 directions. It's only used for the battle menus as well as earl's academy.

Structure:
```
.MenuDataHeader:
db $40 ; flags
db 12, 08 ; start coords
db 17, 19 ; end coords
dw .MenuData2
db 1 ; default option

.MenuData2:
db $81 ; flags
dn 2, 2 ; rows, columns
db 6 ; spacing
dba Strings
dba Function
```

wMenuData2Flags:
```
7: Leave one tile of spacing between the left textbox border and the text, enabling the cursor.
6: Don't leave one tile of spacing between the top textbox border and the text
5: Set bits 4 and 5 in w2DMenuFlags1 (Wrap around horizontally and vertically)
4: Unused
3: Unused
2: Unused
1: Select is functional
0: Disable B button
```

The bank for the Strings is generated when you call `_2DMenu`, and as such it doesn't really matter what bank you specify there (unless you callba `_2DMenu_` directly, of course).
`; spacing` is not a misnomer here, it's used to define how much space there is between columns.
`Function` is called after printing all the strings. `hl` will be pointed at the row below the last in the menu in TileMap. We don't know of its purpose, since it's never actually used anywhere. Only the bank number is always set to the same bank as the menu, but not used otherwise, since the address is 0.

## DoNthMenu/SetUpMenu

These are like the regular VerticalMenu, except they allow for creating slightly more "dynamic" menus, where the options aren't predefined, much like the ScrollingMenu.

Structure:
```
.MenuDataHeader:
db $40 ; flags
db 00, 00 ; start coords
db 07, 10 ; end coords
dw .MenuData2
db 1 ; default option

.MenuData2:
db $81 ; flags
db 0 ; items
dw Items
dw DisplayFunction
dw StringPointers
```

wMenuData2Flags:
```
7: Unused
6: Unused
5: Set bit 5 in w2DMenuFlags1 (Wrap around vertically)
4: Unused
3: Start is functional
2: D-left and D-right are functional
1: Unused
0: Unused
```

The `; items` entry should be left empty, as it's autogenerated with the `Items` array in `GetMenuIndexSet`.
The bottom coord (`07` in the example) is autogenerated regardless of what you specify when building the MenuBox in `AutomaticGetMenuBottomCoord`, which also calculates the `bc` passed to MenuBox, which is useless because it's calculated again by MenuBox in `GetMenuBoxDims`.
[wWhichIndexSet] decides which menu is used through `GetMenuIndexSet`. You can define multiple menus at the Items pointer as such:
```
Items:
db entries not including cancel
db entry1, entry2, entry3
db -1 ; cancel
db entries not including cancel for 2nd menu
db entry1, entry2, entry3, entry4
db -1 ; cancel
```
This is actively used in MainMenu.

StringPointers isn't handled by DoNthMenu internally. It's handled by different `DisplayFunction`s.
A custom one could choose to completely ignore it.

StringPointers struct handled through `PlaceNthMenuStrings` as DisplayFunction and `MenuJumptable`:
```
StringPointers:
dw FunctionToCall, PointerToString ; index 1
dw FunctionToCall, PointerToString ; index 2
...
```

StringPointers struct handled through `PlaceMenuStrings`:
```
StringPointers:
db "STRING1@"
db "STRING2@"
...
```

Call state for DisplayFunction:
```
[MenuSelection] = Current item. -1 is the CANCEL item.
de = Cursor position in TileMap
```

## VerticalMenu

This is the simplest menu. Like, the most boring. Nothing special. Just normal. ...nooooooormal...

Structure:
```
.MenuDataHeader:
db %01010000 ; flags
db 12, 12 ; start coords
db 17, 19 ; end coords
dw .MenuData2
db 1 ; default option

.MenuData2:
db %10000000 ; flags
db 2 ; # items
db "GIVE@"
db "TAKE@"
```

wMenuData2Flags:
```
7: Leave one tile of spacing between the left textbox border and the text
6: Don't leave one tile of spacing between the top textbox border and the text
5: Set bit 5 in w2DMenuFlags1 (Wrap around vertically)
4: Place menubox "title". See notes.
3: Unused
2: Unused
1: Select is functional
0: Disable B button
```

If bit 4 is set, a string at the end of the items array will be put at an offset from the start coord of the menu box. This string is defined like this:
```
db 2 ; # items
db "GIVE@"
db "TAKE@"
db 2 ; x offset
db "TEST@"
```
This is used in the menu for selecting the character's name.

## Misc/Generic

MenuDataHeader flags (wMenuFlags):
```
7: Save a backup of the tiles
6: Save a backup of the tiles
5: Unused
4: Set bit 6 in w2DMenuFlags1 (Enable sprite animations)
3: Disable click sound
2: Unused
1: Unused
0: Call RestoreTileBackup when exiting the menu. This bit depends on whether bit 6 or 7 are set.
```

w2DMenuFlags1:
```
7: Disable checking of wMenuJoypadFilter
6: Enable sprite animations
5: Wrap around vertically
4: Wrap around horizontally
3: Set bit 7 in w2DMenuFlags2 and exit the loop if bit 5 is disabled and we tried to go too far down
2: Set bit 7 in w2DMenuFlags2 and exit the loop if bit 5 is disabled and we tried to go too far up
1: Set bit 7 in w2DMenuFlags2 and exit the loop if bit 4 is disabled and we tried to go too far left
0: Set bit 7 in w2DMenuFlags2 and exit the loop if bit 4 is disabled and we tried to go too far right
```

w2DMenuFlags2:
```
7: ?????
6: ?????
5: ?????
4: ?????
3: ?????
2: ?????
1: ?????
0: ?????
```
12 changes: 6 additions & 6 deletions engine/battle/menu.asm
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ Function24f19: ; 24f19
; 24f2c

BattleMenuDataHeader: ; 24f2c
db $40 ; flags
db MENU_BACKUP_TILES ; flags
db 12, 08 ; start coords
db 17, 19 ; end coords
dw MenuData_0x24f34
db 1 ; default option
; 24f34

MenuData_0x24f34: ; 0x24f34
db $81 ; flags
db STATICMENU_CURSOR | STATICMENU_DISABLE_B ; flags
dn 2, 2 ; rows, columns
db 6 ; spacing
dba Strings24f3d
Expand All @@ -56,15 +56,15 @@ Strings24f3d: ; 0x24f3d
; 24f4e

MenuDataHeader_0x24f4e: ; 24f4e
db $40 ; flags
db MENU_BACKUP_TILES ; flags
db 12, 00 ; start coords
db 17, 19 ; end coords
dw MenuData_0x24f56
db 1 ; default option
; 24f56

MenuData_0x24f56: ; 24f56
db $81 ; flags
db STATICMENU_CURSOR | STATICMENU_DISABLE_B ; flags
dn 2, 2 ; rows, columns
db 11 ; spacing
dba Strings24f5f
Expand All @@ -87,15 +87,15 @@ Function24f7c: ; 24f7c
; 24f89

MenuDataHeader_0x24f89: ; 24f89
db $40 ; flags
db MENU_BACKUP_TILES ; flags
db 12, 02 ; start coords
db 17, 19 ; end coords
dw MenuData_0x24f91
db 1 ; default option
; 24f91

MenuData_0x24f91: ; 24f91
db $81 ; flags
db STATICMENU_CURSOR | STATICMENU_DISABLE_B ; flags
dn 2, 2 ; rows, columns
db 12 ; spacing
dba Strings24f9a
Expand Down
Loading