diff --git a/graphics/interface/pss_unk_83CDAB8.png b/graphics/interface/pss_unk_83CDAB8.png deleted file mode 100644 index 5b7d0a3b6..000000000 Binary files a/graphics/interface/pss_unk_83CDAB8.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83CE2B8.png b/graphics/interface/pss_unk_83CE2B8.png deleted file mode 100644 index 18ac36e21..000000000 Binary files a/graphics/interface/pss_unk_83CE2B8.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83CE438.png b/graphics/interface/pss_unk_83CE438.png deleted file mode 100644 index 8be861a26..000000000 Binary files a/graphics/interface/pss_unk_83CE438.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83CE738.pal b/graphics/interface/pss_unk_83CE738.pal deleted file mode 100644 index 087a84a69..000000000 --- a/graphics/interface/pss_unk_83CE738.pal +++ /dev/null @@ -1,19 +0,0 @@ -JASC-PAL -0100 -16 -0 0 0 -148 148 172 -255 255 255 -0 0 0 -123 189 255 -0 123 255 -255 131 131 -172 24 24 -255 238 230 -255 230 213 -255 222 205 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -0 0 0 diff --git a/graphics/interface/pss_unk_83CE810.png b/graphics/interface/pss_unk_83CE810.png deleted file mode 100644 index d414dbc03..000000000 Binary files a/graphics/interface/pss_unk_83CE810.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83CEA10.pal b/graphics/interface/pss_unk_83CEA10.pal deleted file mode 100644 index b9c6f46de..000000000 --- a/graphics/interface/pss_unk_83CEA10.pal +++ /dev/null @@ -1,19 +0,0 @@ -JASC-PAL -0100 -16 -0 0 0 -255 255 255 -98 98 98 -213 213 205 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -0 0 0 diff --git a/graphics/interface/pss_unk_83CEC80.png b/graphics/interface/pss_unk_83CEC80.png deleted file mode 100644 index 7307fc601..000000000 Binary files a/graphics/interface/pss_unk_83CEC80.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83CF16C.png b/graphics/interface/pss_unk_83CF16C.png deleted file mode 100644 index baaff23a9..000000000 Binary files a/graphics/interface/pss_unk_83CF16C.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83CF464.png b/graphics/interface/pss_unk_83CF464.png deleted file mode 100644 index 6de13c4b0..000000000 Binary files a/graphics/interface/pss_unk_83CF464.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83CF874.png b/graphics/interface/pss_unk_83CF874.png deleted file mode 100644 index bacf96c2e..000000000 Binary files a/graphics/interface/pss_unk_83CF874.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83CFBA0.png b/graphics/interface/pss_unk_83CFBA0.png deleted file mode 100644 index 6092d1665..000000000 Binary files a/graphics/interface/pss_unk_83CFBA0.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83D0008.png b/graphics/interface/pss_unk_83D0008.png deleted file mode 100644 index 9724cf7fd..000000000 Binary files a/graphics/interface/pss_unk_83D0008.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83D0454.png b/graphics/interface/pss_unk_83D0454.png deleted file mode 100644 index 48156edee..000000000 Binary files a/graphics/interface/pss_unk_83D0454.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83D0818.png b/graphics/interface/pss_unk_83D0818.png deleted file mode 100644 index 6e42fd525..000000000 Binary files a/graphics/interface/pss_unk_83D0818.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83D0C78.png b/graphics/interface/pss_unk_83D0C78.png deleted file mode 100644 index ad4389d88..000000000 Binary files a/graphics/interface/pss_unk_83D0C78.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83D1124.png b/graphics/interface/pss_unk_83D1124.png deleted file mode 100644 index fe7810abb..000000000 Binary files a/graphics/interface/pss_unk_83D1124.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83D14F4.png b/graphics/interface/pss_unk_83D14F4.png deleted file mode 100644 index 92ddac031..000000000 Binary files a/graphics/interface/pss_unk_83D14F4.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83D18B4.png b/graphics/interface/pss_unk_83D18B4.png deleted file mode 100644 index 4444e6909..000000000 Binary files a/graphics/interface/pss_unk_83D18B4.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83D1C8C.png b/graphics/interface/pss_unk_83D1C8C.png deleted file mode 100644 index 5554f6a51..000000000 Binary files a/graphics/interface/pss_unk_83D1C8C.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83D1FD4.png b/graphics/interface/pss_unk_83D1FD4.png deleted file mode 100644 index c4cf6bd1e..000000000 Binary files a/graphics/interface/pss_unk_83D1FD4.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83D23DC.png b/graphics/interface/pss_unk_83D23DC.png deleted file mode 100644 index 8fce05efa..000000000 Binary files a/graphics/interface/pss_unk_83D23DC.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83D2654.png b/graphics/interface/pss_unk_83D2654.png deleted file mode 100644 index 00c506fc1..000000000 Binary files a/graphics/interface/pss_unk_83D2654.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83D29D0.pal b/graphics/interface/pss_unk_83D29D0.pal deleted file mode 100644 index 7f2f9ae51..000000000 --- a/graphics/interface/pss_unk_83D29D0.pal +++ /dev/null @@ -1,35 +0,0 @@ -JASC-PAL -0100 -32 -57 57 57 -255 255 255 -57 57 57 -255 255 255 -57 57 57 -255 255 255 -57 57 57 -255 255 255 -57 57 57 -255 255 255 -57 57 57 -255 255 255 -57 57 57 -255 255 255 -57 57 57 -255 255 255 -57 57 57 -255 255 255 -57 57 57 -255 255 255 -57 57 57 -255 255 255 -57 57 57 -255 255 255 -57 57 57 -255 255 255 -57 57 57 -255 255 255 -57 57 57 -255 255 255 -57 57 57 -255 255 255 diff --git a/graphics/interface/pss_unk_83D2AD0.png b/graphics/interface/pss_unk_83D2AD0.png deleted file mode 100644 index f6bdaadb8..000000000 Binary files a/graphics/interface/pss_unk_83D2AD0.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83D2BEC.png b/graphics/interface/pss_unk_83D2BEC.png deleted file mode 100644 index 3a6e35307..000000000 Binary files a/graphics/interface/pss_unk_83D2BEC.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83D33EC.png b/graphics/interface/pss_unk_83D33EC.png deleted file mode 100644 index 9b1e8f850..000000000 Binary files a/graphics/interface/pss_unk_83D33EC.png and /dev/null differ diff --git a/graphics/interface/pss_unk_83D35DC.png b/graphics/interface/pss_unk_83D35DC.png deleted file mode 100644 index 53ecc7ca5..000000000 Binary files a/graphics/interface/pss_unk_83D35DC.png and /dev/null differ diff --git a/graphics/pokemon_storage/box_scroll_arrow.png b/graphics/pokemon_storage/box_scroll_arrow.png new file mode 100644 index 000000000..c56139ea1 Binary files /dev/null and b/graphics/pokemon_storage/box_scroll_arrow.png differ diff --git a/graphics/pokemon_storage/choose_box_menu_center.png b/graphics/pokemon_storage/choose_box_menu_center.png new file mode 100644 index 000000000..81500fdf6 Binary files /dev/null and b/graphics/pokemon_storage/choose_box_menu_center.png differ diff --git a/graphics/pokemon_storage/choose_box_menu_corners.png b/graphics/pokemon_storage/choose_box_menu_corners.png new file mode 100644 index 000000000..5600b0462 Binary files /dev/null and b/graphics/pokemon_storage/choose_box_menu_corners.png differ diff --git a/graphics/pokemon_storage/close_box_button.bin b/graphics/pokemon_storage/close_box_button.bin new file mode 100644 index 000000000..8b130a481 --- /dev/null +++ b/graphics/pokemon_storage/close_box_button.bin @@ -0,0 +1 @@ +LMNOpqrst\]^_uvwxyz{|} \ No newline at end of file diff --git a/graphics/pokemon_storage/cursor.png b/graphics/pokemon_storage/cursor.png new file mode 100644 index 000000000..d64dc3bd8 Binary files /dev/null and b/graphics/pokemon_storage/cursor.png differ diff --git a/graphics/pokemon_storage/cursor_shadow.png b/graphics/pokemon_storage/cursor_shadow.png new file mode 100644 index 000000000..7b2e218e5 Binary files /dev/null and b/graphics/pokemon_storage/cursor_shadow.png differ diff --git a/graphics/interface/box_tiles_pal2.pal b/graphics/pokemon_storage/interface.pal similarity index 100% rename from graphics/interface/box_tiles_pal2.pal rename to graphics/pokemon_storage/interface.pal diff --git a/graphics/interface/box_tiles_pal3.pal b/graphics/pokemon_storage/interface_no_display_mon.pal similarity index 100% rename from graphics/interface/box_tiles_pal3.pal rename to graphics/pokemon_storage/interface_no_display_mon.pal diff --git a/graphics/pokemon_storage/item_info_frame.png b/graphics/pokemon_storage/item_info_frame.png new file mode 100644 index 000000000..dd5f52460 Binary files /dev/null and b/graphics/pokemon_storage/item_info_frame.png differ diff --git a/graphics/interface/pss_unk_83CE5FC.bin b/graphics/pokemon_storage/menu.bin similarity index 100% rename from graphics/interface/pss_unk_83CE5FC.bin rename to graphics/pokemon_storage/menu.bin diff --git a/graphics/interface/pss_unk_83CE5DC.pal b/graphics/pokemon_storage/menu.pal similarity index 100% rename from graphics/interface/pss_unk_83CE5DC.pal rename to graphics/pokemon_storage/menu.pal diff --git a/graphics/interface/box_tiles.png b/graphics/pokemon_storage/menu.png similarity index 100% rename from graphics/interface/box_tiles.png rename to graphics/pokemon_storage/menu.png diff --git a/graphics/interface/pss_unk_83D2BCC.pal b/graphics/pokemon_storage/misc1.pal similarity index 100% rename from graphics/interface/pss_unk_83D2BCC.pal rename to graphics/pokemon_storage/misc1.pal diff --git a/graphics/pokemon_storage/misc2.pal b/graphics/pokemon_storage/misc2.pal new file mode 100644 index 000000000..40bc5d1cb --- /dev/null +++ b/graphics/pokemon_storage/misc2.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +0 0 0 +148 148 172 +82 82 90 +255 255 255 +205 255 255 +90 189 238 +90 164 205 +82 131 164 +82 106 123 +82 82 90 +0 0 0 +222 222 246 +164 164 180 +148 148 172 +115 115 123 +82 82 90 diff --git a/graphics/unknown/unknown_E9CAEC.bin b/graphics/pokemon_storage/party_menu.bin similarity index 100% rename from graphics/unknown/unknown_E9CAEC.bin rename to graphics/pokemon_storage/party_menu.bin diff --git a/graphics/interface/box_tiles_pal1.pal b/graphics/pokemon_storage/party_menu.pal similarity index 100% rename from graphics/interface/box_tiles_pal1.pal rename to graphics/pokemon_storage/party_menu.pal diff --git a/graphics/pokemon_storage/party_slot_empty.bin b/graphics/pokemon_storage/party_slot_empty.bin new file mode 100644 index 000000000..991c232f7 --- /dev/null +++ b/graphics/pokemon_storage/party_slot_empty.bin @@ -0,0 +1 @@ +CDDESTTUcdde \ No newline at end of file diff --git a/graphics/pokemon_storage/party_slot_filled.bin b/graphics/pokemon_storage/party_slot_filled.bin new file mode 100644 index 000000000..c0b93bf14 --- /dev/null +++ b/graphics/pokemon_storage/party_slot_filled.bin @@ -0,0 +1 @@ +@AABPQQR`aab \ No newline at end of file diff --git a/graphics/pokemon_storage/pkmn_data.bin b/graphics/pokemon_storage/pkmn_data.bin new file mode 100644 index 000000000..3336797aa --- /dev/null +++ b/graphics/pokemon_storage/pkmn_data.bin @@ -0,0 +1 @@ +!!!!!!!!!!!!!!!! \ No newline at end of file diff --git a/graphics/interface/pss_unk_83CE4D0.bin b/graphics/pokemon_storage/scrolling_bg.bin similarity index 100% rename from graphics/interface/pss_unk_83CE4D0.bin rename to graphics/pokemon_storage/scrolling_bg.bin diff --git a/graphics/pokemon_storage/scrolling_bg.png b/graphics/pokemon_storage/scrolling_bg.png new file mode 100644 index 000000000..7215fdb40 Binary files /dev/null and b/graphics/pokemon_storage/scrolling_bg.png differ diff --git a/graphics/interface/pss_unk_83CE758.pal b/graphics/pokemon_storage/scrolling_bg_move_items.pal similarity index 100% rename from graphics/interface/pss_unk_83CE758.pal rename to graphics/pokemon_storage/scrolling_bg_move_items.pal diff --git a/graphics/interface/pss_unk_83CE9D0.pal b/graphics/pokemon_storage/unused.pal similarity index 100% rename from graphics/interface/pss_unk_83CE9D0.pal rename to graphics/pokemon_storage/unused.pal diff --git a/graphics/interface/pss_unk_83CDA98.pal b/graphics/pokemon_storage/unused_choose_box_menu.pal similarity index 100% rename from graphics/interface/pss_unk_83CDA98.pal rename to graphics/pokemon_storage/unused_choose_box_menu.pal diff --git a/graphics/pokemon_storage/wallpapers/beach/box.pal b/graphics/pokemon_storage/wallpapers/beach/box.pal new file mode 100644 index 000000000..b7cb930c4 --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/beach/box.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 255 255 +255 255 222 +246 238 180 +238 230 148 +238 222 131 +222 205 115 +213 189 98 +205 164 90 +197 172 65 +255 98 197 +255 148 172 +49 213 205 +164 230 213 +0 0 0 +82 98 255 +49 65 156 diff --git a/graphics/interface/pss_unk_83D0FFC.bin b/graphics/pokemon_storage/wallpapers/beach/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83D0FFC.bin rename to graphics/pokemon_storage/wallpapers/beach/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/beach/tiles.png b/graphics/pokemon_storage/wallpapers/beach/tiles.png new file mode 100644 index 000000000..f2594ae88 Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/beach/tiles.png differ diff --git a/graphics/interface/pss_unk_83D0C38.pal b/graphics/pokemon_storage/wallpapers/beach/title.pal similarity index 52% rename from graphics/interface/pss_unk_83D0C38.pal rename to graphics/pokemon_storage/wallpapers/beach/title.pal index dfc1ab464..360d77bde 100644 --- a/graphics/interface/pss_unk_83D0C38.pal +++ b/graphics/pokemon_storage/wallpapers/beach/title.pal @@ -1,6 +1,6 @@ JASC-PAL 0100 -32 +16 255 255 255 156 106 57 197 230 255 @@ -17,19 +17,3 @@ JASC-PAL 255 255 255 82 98 255 49 65 156 -255 255 255 -255 255 222 -246 238 180 -238 230 148 -238 222 131 -222 205 115 -213 189 98 -205 164 90 -197 172 65 -255 98 197 -255 148 172 -49 213 205 -164 230 213 -0 0 0 -82 98 255 -49 65 156 diff --git a/graphics/interface/pss_unk_83D07D8.pal b/graphics/pokemon_storage/wallpapers/cave/box.pal similarity index 52% rename from graphics/interface/pss_unk_83D07D8.pal rename to graphics/pokemon_storage/wallpapers/cave/box.pal index ddbe3e302..6b783cdd5 100644 --- a/graphics/interface/pss_unk_83D07D8.pal +++ b/graphics/pokemon_storage/wallpapers/cave/box.pal @@ -1,22 +1,6 @@ JASC-PAL 0100 -32 -255 255 255 -230 197 123 -213 180 98 -180 148 65 -148 115 32 -115 82 0 -0 0 0 -0 0 0 -139 90 115 -156 106 131 -115 65 90 -0 0 0 -230 230 230 -255 255 255 -90 90 131 -49 49 90 +16 255 255 255 246 213 131 213 180 98 diff --git a/graphics/interface/pss_unk_83D0B5C.bin b/graphics/pokemon_storage/wallpapers/cave/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83D0B5C.bin rename to graphics/pokemon_storage/wallpapers/cave/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/cave/tiles.png b/graphics/pokemon_storage/wallpapers/cave/tiles.png new file mode 100644 index 000000000..8a1a6e81e Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/cave/tiles.png differ diff --git a/graphics/pokemon_storage/wallpapers/cave/title.pal b/graphics/pokemon_storage/wallpapers/cave/title.pal new file mode 100644 index 000000000..f6e731395 --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/cave/title.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 255 255 +230 197 123 +213 180 98 +180 148 65 +148 115 32 +115 82 0 +0 0 0 +0 0 0 +139 90 115 +156 106 131 +115 65 90 +0 0 0 +230 230 230 +255 255 255 +90 90 131 +49 49 90 diff --git a/graphics/pokemon_storage/wallpapers/city/box.pal b/graphics/pokemon_storage/wallpapers/city/box.pal new file mode 100644 index 000000000..ba67b3414 --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/city/box.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 255 255 +255 255 246 +255 238 246 +230 213 222 +205 189 197 +164 148 156 +139 123 131 +0 0 0 +0 0 0 +180 164 172 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +156 123 82 +115 82 41 diff --git a/graphics/interface/pss_unk_83CF374.bin b/graphics/pokemon_storage/wallpapers/city/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83CF374.bin rename to graphics/pokemon_storage/wallpapers/city/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/city/tiles.png b/graphics/pokemon_storage/wallpapers/city/tiles.png new file mode 100644 index 000000000..f5684850a Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/city/tiles.png differ diff --git a/graphics/interface/pss_unk_83CF12C.pal b/graphics/pokemon_storage/wallpapers/city/title.pal similarity index 55% rename from graphics/interface/pss_unk_83CF12C.pal rename to graphics/pokemon_storage/wallpapers/city/title.pal index b430df83e..a5387638a 100644 --- a/graphics/interface/pss_unk_83CF12C.pal +++ b/graphics/pokemon_storage/wallpapers/city/title.pal @@ -1,6 +1,6 @@ JASC-PAL 0100 -32 +16 255 255 255 246 246 246 90 131 197 @@ -17,19 +17,3 @@ JASC-PAL 189 213 213 156 123 82 106 74 32 -255 255 255 -255 255 246 -255 238 246 -230 213 222 -205 189 197 -164 148 156 -139 123 131 -0 0 0 -0 0 0 -180 164 172 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -156 123 82 -115 82 41 diff --git a/graphics/pokemon_storage/wallpapers/crag/box.pal b/graphics/pokemon_storage/wallpapers/crag/box.pal new file mode 100644 index 000000000..f72b27d13 --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/crag/box.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 255 255 +222 222 222 +189 189 189 +156 156 156 +123 123 123 +90 90 90 +57 57 57 +41 41 41 +222 189 205 +197 164 180 +172 139 156 +246 213 230 +238 238 238 +255 255 255 +213 189 82 +172 148 41 diff --git a/graphics/interface/pss_unk_83CFEF0.bin b/graphics/pokemon_storage/wallpapers/crag/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83CFEF0.bin rename to graphics/pokemon_storage/wallpapers/crag/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/crag/tiles.png b/graphics/pokemon_storage/wallpapers/crag/tiles.png new file mode 100644 index 000000000..bfdc0a7e3 Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/crag/tiles.png differ diff --git a/graphics/interface/pss_unk_83CFB60.pal b/graphics/pokemon_storage/wallpapers/crag/title.pal similarity index 52% rename from graphics/interface/pss_unk_83CFB60.pal rename to graphics/pokemon_storage/wallpapers/crag/title.pal index 292b6db72..c4f85c644 100644 --- a/graphics/interface/pss_unk_83CFB60.pal +++ b/graphics/pokemon_storage/wallpapers/crag/title.pal @@ -1,6 +1,6 @@ JASC-PAL 0100 -32 +16 255 255 255 222 222 222 189 189 189 @@ -17,19 +17,3 @@ JASC-PAL 255 255 255 213 189 82 172 148 41 -255 255 255 -222 222 222 -189 189 189 -156 156 156 -123 123 123 -90 90 90 -57 57 57 -41 41 41 -222 189 205 -197 164 180 -172 139 156 -246 213 230 -238 238 238 -255 255 255 -213 189 82 -172 148 41 diff --git a/graphics/pokemon_storage/wallpapers/desert/box.pal b/graphics/pokemon_storage/wallpapers/desert/box.pal new file mode 100644 index 000000000..c5ca027d2 --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/desert/box.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 255 255 +255 238 189 +255 213 164 +230 189 139 +205 164 115 +180 139 90 +156 115 65 +131 90 41 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +164 139 82 +123 98 41 diff --git a/graphics/interface/pss_unk_83CF750.bin b/graphics/pokemon_storage/wallpapers/desert/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83CF750.bin rename to graphics/pokemon_storage/wallpapers/desert/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/desert/tiles.png b/graphics/pokemon_storage/wallpapers/desert/tiles.png new file mode 100644 index 000000000..373749994 Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/desert/tiles.png differ diff --git a/graphics/interface/pss_unk_83CF424.pal b/graphics/pokemon_storage/wallpapers/desert/title.pal similarity index 55% rename from graphics/interface/pss_unk_83CF424.pal rename to graphics/pokemon_storage/wallpapers/desert/title.pal index a3a5cb4ea..4cf04f8ae 100644 --- a/graphics/interface/pss_unk_83CF424.pal +++ b/graphics/pokemon_storage/wallpapers/desert/title.pal @@ -1,6 +1,6 @@ JASC-PAL 0100 -32 +16 255 255 255 255 255 139 205 189 131 @@ -17,19 +17,3 @@ JASC-PAL 255 255 255 164 139 82 123 98 41 -255 255 255 -255 238 189 -255 213 164 -230 189 139 -205 164 115 -180 139 90 -156 115 65 -131 90 41 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -164 139 82 -123 98 41 diff --git a/graphics/pokemon_storage/wallpapers/forest/box.pal b/graphics/pokemon_storage/wallpapers/forest/box.pal new file mode 100644 index 000000000..946becabb --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/forest/box.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 255 255 +230 255 172 +205 255 148 +180 230 123 +156 205 98 +131 180 74 +106 156 49 +82 131 24 +0 0 0 +205 213 172 +172 180 139 +0 0 0 +0 0 0 +0 0 0 +164 139 82 +123 98 41 diff --git a/graphics/interface/pss_unk_83CF050.bin b/graphics/pokemon_storage/wallpapers/forest/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83CF050.bin rename to graphics/pokemon_storage/wallpapers/forest/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/forest/tiles.png b/graphics/pokemon_storage/wallpapers/forest/tiles.png new file mode 100644 index 000000000..1c00feb82 Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/forest/tiles.png differ diff --git a/graphics/interface/pss_unk_83CEC40.pal b/graphics/pokemon_storage/wallpapers/forest/title.pal similarity index 54% rename from graphics/interface/pss_unk_83CEC40.pal rename to graphics/pokemon_storage/wallpapers/forest/title.pal index d2663e710..1b4166087 100644 --- a/graphics/interface/pss_unk_83CEC40.pal +++ b/graphics/pokemon_storage/wallpapers/forest/title.pal @@ -1,6 +1,6 @@ JASC-PAL 0100 -32 +16 255 255 255 246 255 230 255 255 213 @@ -17,19 +17,3 @@ JASC-PAL 255 255 255 164 139 82 123 98 41 -255 255 255 -230 255 172 -205 255 148 -180 230 123 -156 205 98 -131 180 74 -106 156 49 -82 131 24 -0 0 0 -205 213 172 -172 180 139 -0 0 0 -0 0 0 -0 0 0 -164 139 82 -123 98 41 diff --git a/graphics/pokemon_storage/wallpapers/pokecenter/box.pal b/graphics/pokemon_storage/wallpapers/pokecenter/box.pal new file mode 100644 index 000000000..60b96bbd9 --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/pokecenter/box.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 255 115 +41 82 82 +65 115 115 +115 164 156 +90 131 82 +131 172 123 +172 213 172 +189 230 197 +213 255 222 +255 164 139 +213 213 230 +0 0 255 +0 0 255 +0 0 255 +0 0 255 +255 255 255 diff --git a/graphics/interface/pss_unk_83D22B8.bin b/graphics/pokemon_storage/wallpapers/pokecenter/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83D22B8.bin rename to graphics/pokemon_storage/wallpapers/pokecenter/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/pokecenter/tiles.png b/graphics/pokemon_storage/wallpapers/pokecenter/tiles.png new file mode 100644 index 000000000..e82b88e07 Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/pokecenter/tiles.png differ diff --git a/graphics/interface/pss_unk_83D1F94.pal b/graphics/pokemon_storage/wallpapers/pokecenter/title.pal similarity index 52% rename from graphics/interface/pss_unk_83D1F94.pal rename to graphics/pokemon_storage/wallpapers/pokecenter/title.pal index 481d07b1e..332fff38b 100644 --- a/graphics/interface/pss_unk_83D1F94.pal +++ b/graphics/pokemon_storage/wallpapers/pokecenter/title.pal @@ -1,6 +1,6 @@ JASC-PAL 0100 -32 +16 255 255 115 41 82 82 65 115 115 @@ -17,19 +17,3 @@ JASC-PAL 164 205 172 230 230 230 255 255 255 -255 255 115 -41 82 82 -65 115 115 -115 164 156 -90 131 82 -131 172 123 -172 213 172 -189 230 197 -213 255 222 -255 164 139 -213 213 230 -0 0 255 -0 0 255 -0 0 255 -0 0 255 -255 255 255 diff --git a/graphics/interface/pss_unk_83D14B4.pal b/graphics/pokemon_storage/wallpapers/river/box.pal similarity index 53% rename from graphics/interface/pss_unk_83D14B4.pal rename to graphics/pokemon_storage/wallpapers/river/box.pal index 7a3f4656a..09d45090a 100644 --- a/graphics/interface/pss_unk_83D14B4.pal +++ b/graphics/pokemon_storage/wallpapers/river/box.pal @@ -1,22 +1,6 @@ JASC-PAL 0100 -32 -255 255 255 -238 255 255 -205 255 255 -164 255 255 -131 222 222 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -115 180 0 -148 213 24 -180 246 57 -230 230 230 -255 255 255 -180 148 106 -139 106 65 +16 255 255 255 230 255 156 197 255 123 diff --git a/graphics/interface/pss_unk_83D1788.bin b/graphics/pokemon_storage/wallpapers/river/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83D1788.bin rename to graphics/pokemon_storage/wallpapers/river/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/river/tiles.png b/graphics/pokemon_storage/wallpapers/river/tiles.png new file mode 100644 index 000000000..0a6d4d416 Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/river/tiles.png differ diff --git a/graphics/pokemon_storage/wallpapers/river/title.pal b/graphics/pokemon_storage/wallpapers/river/title.pal new file mode 100644 index 000000000..9fcc4cbca --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/river/title.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 255 255 +238 255 255 +205 255 255 +164 255 255 +131 222 222 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +115 180 0 +148 213 24 +180 246 57 +230 230 230 +255 255 255 +180 148 106 +139 106 65 diff --git a/graphics/pokemon_storage/wallpapers/savanna/box.pal b/graphics/pokemon_storage/wallpapers/savanna/box.pal new file mode 100644 index 000000000..d80816c35 --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/savanna/box.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 255 255 +255 255 131 +222 222 98 +189 189 65 +156 156 32 +123 123 0 +90 90 0 +57 57 0 +189 189 65 +131 180 57 +115 164 41 +205 205 82 +238 238 238 +255 255 255 +189 156 82 +148 115 41 diff --git a/graphics/interface/pss_unk_83CFA94.bin b/graphics/pokemon_storage/wallpapers/savanna/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83CFA94.bin rename to graphics/pokemon_storage/wallpapers/savanna/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/savanna/tiles.png b/graphics/pokemon_storage/wallpapers/savanna/tiles.png new file mode 100644 index 000000000..ec1e4e8fd Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/savanna/tiles.png differ diff --git a/graphics/interface/pss_unk_83CF834.pal b/graphics/pokemon_storage/wallpapers/savanna/title.pal similarity index 52% rename from graphics/interface/pss_unk_83CF834.pal rename to graphics/pokemon_storage/wallpapers/savanna/title.pal index a7789ddfe..1c1742cc2 100644 --- a/graphics/interface/pss_unk_83CF834.pal +++ b/graphics/pokemon_storage/wallpapers/savanna/title.pal @@ -1,6 +1,6 @@ JASC-PAL 0100 -32 +16 255 255 255 222 222 222 189 189 189 @@ -17,19 +17,3 @@ JASC-PAL 255 255 255 189 156 82 148 115 41 -255 255 255 -255 255 131 -222 222 98 -189 189 65 -156 156 32 -123 123 0 -90 90 0 -57 57 0 -189 189 65 -131 180 57 -115 164 41 -205 205 82 -238 238 238 -255 255 255 -189 156 82 -148 115 41 diff --git a/graphics/interface/pss_unk_83D10E4.pal b/graphics/pokemon_storage/wallpapers/seafloor/box.pal similarity index 52% rename from graphics/interface/pss_unk_83D10E4.pal rename to graphics/pokemon_storage/wallpapers/seafloor/box.pal index b91fdd173..43b2eecab 100644 --- a/graphics/interface/pss_unk_83D10E4.pal +++ b/graphics/pokemon_storage/wallpapers/seafloor/box.pal @@ -1,22 +1,6 @@ JASC-PAL 0100 -32 -255 255 255 -131 180 255 -98 148 222 -65 115 189 -32 82 156 -0 24 98 -0 0 0 -0 0 0 -139 90 115 -156 106 131 -115 65 90 -0 0 0 -230 230 230 -255 255 255 -148 180 41 -106 139 0 +16 255 255 255 164 213 255 131 180 255 diff --git a/graphics/interface/pss_unk_83D13D8.bin b/graphics/pokemon_storage/wallpapers/seafloor/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83D13D8.bin rename to graphics/pokemon_storage/wallpapers/seafloor/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/seafloor/tiles.png b/graphics/pokemon_storage/wallpapers/seafloor/tiles.png new file mode 100644 index 000000000..192f7126c Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/seafloor/tiles.png differ diff --git a/graphics/pokemon_storage/wallpapers/seafloor/title.pal b/graphics/pokemon_storage/wallpapers/seafloor/title.pal new file mode 100644 index 000000000..79c7650b4 --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/seafloor/title.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 255 255 +131 180 255 +98 148 222 +65 115 189 +32 82 156 +0 24 98 +0 0 0 +0 0 0 +139 90 115 +156 106 131 +115 65 90 +0 0 0 +230 230 230 +255 255 255 +148 180 41 +106 139 0 diff --git a/graphics/interface/pss_unk_83D2614.pal b/graphics/pokemon_storage/wallpapers/simple/box.pal similarity index 55% rename from graphics/interface/pss_unk_83D2614.pal rename to graphics/pokemon_storage/wallpapers/simple/box.pal index a508e7ba8..86596441a 100644 --- a/graphics/interface/pss_unk_83D2614.pal +++ b/graphics/pokemon_storage/wallpapers/simple/box.pal @@ -1,22 +1,6 @@ JASC-PAL 0100 -32 -255 156 213 -82 65 115 -106 90 139 -131 115 164 -172 172 255 -189 189 255 -0 0 255 -0 0 255 -0 0 255 -0 0 255 -0 0 255 -0 0 255 -0 0 255 -0 0 255 -0 0 255 -255 255 255 +16 255 156 213 82 65 115 106 90 139 diff --git a/graphics/interface/pss_unk_83D277C.bin b/graphics/pokemon_storage/wallpapers/simple/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83D277C.bin rename to graphics/pokemon_storage/wallpapers/simple/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/simple/tiles.png b/graphics/pokemon_storage/wallpapers/simple/tiles.png new file mode 100644 index 000000000..df046d843 Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/simple/tiles.png differ diff --git a/graphics/pokemon_storage/wallpapers/simple/title.pal b/graphics/pokemon_storage/wallpapers/simple/title.pal new file mode 100644 index 000000000..9b4ffb97f --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/simple/title.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 156 213 +82 65 115 +106 90 139 +131 115 164 +172 172 255 +189 189 255 +0 0 255 +0 0 255 +0 0 255 +0 0 255 +0 0 255 +0 0 255 +0 0 255 +0 0 255 +0 0 255 +255 255 255 diff --git a/graphics/interface/pss_unk_83D1874.pal b/graphics/pokemon_storage/wallpapers/sky/box.pal similarity index 51% rename from graphics/interface/pss_unk_83D1874.pal rename to graphics/pokemon_storage/wallpapers/sky/box.pal index a529046e5..3d722ed6d 100644 --- a/graphics/interface/pss_unk_83D1874.pal +++ b/graphics/pokemon_storage/wallpapers/sky/box.pal @@ -1,22 +1,6 @@ JASC-PAL 0100 -32 -255 255 255 -238 255 255 -205 255 255 -164 255 255 -123 213 246 -90 180 213 -57 148 180 -24 115 148 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -230 230 230 -255 255 255 -205 139 41 -164 98 0 +16 255 255 255 238 255 255 205 255 255 diff --git a/graphics/interface/pss_unk_83D1B4C.bin b/graphics/pokemon_storage/wallpapers/sky/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83D1B4C.bin rename to graphics/pokemon_storage/wallpapers/sky/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/sky/tiles.png b/graphics/pokemon_storage/wallpapers/sky/tiles.png new file mode 100644 index 000000000..2b28d3897 Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/sky/tiles.png differ diff --git a/graphics/pokemon_storage/wallpapers/sky/title.pal b/graphics/pokemon_storage/wallpapers/sky/title.pal new file mode 100644 index 000000000..951f59ecf --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/sky/title.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 255 255 +238 255 255 +205 255 255 +164 255 255 +123 213 246 +90 180 213 +57 148 180 +24 115 148 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +230 230 230 +255 255 255 +205 139 41 +164 98 0 diff --git a/graphics/pokemon_storage/wallpapers/snow/box.pal b/graphics/pokemon_storage/wallpapers/snow/box.pal new file mode 100644 index 000000000..01e46d027 --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/snow/box.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 255 255 +230 230 230 +205 205 205 +139 148 189 +106 115 156 +74 82 123 +41 49 90 +8 16 57 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +238 238 238 +255 255 255 +213 131 139 +172 90 98 diff --git a/graphics/interface/pss_unk_83D070C.bin b/graphics/pokemon_storage/wallpapers/snow/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83D070C.bin rename to graphics/pokemon_storage/wallpapers/snow/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/snow/tiles.png b/graphics/pokemon_storage/wallpapers/snow/tiles.png new file mode 100644 index 000000000..00225d6fc Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/snow/tiles.png differ diff --git a/graphics/interface/pss_unk_83D0414.pal b/graphics/pokemon_storage/wallpapers/snow/title.pal similarity index 51% rename from graphics/interface/pss_unk_83D0414.pal rename to graphics/pokemon_storage/wallpapers/snow/title.pal index 64a768cb1..437ccb934 100644 --- a/graphics/interface/pss_unk_83D0414.pal +++ b/graphics/pokemon_storage/wallpapers/snow/title.pal @@ -1,6 +1,6 @@ JASC-PAL 0100 -32 +16 255 255 255 230 230 230 205 205 205 @@ -17,19 +17,3 @@ JASC-PAL 255 255 255 213 131 139 172 90 98 -255 255 255 -230 230 230 -205 205 205 -139 148 189 -106 115 156 -74 82 123 -41 49 90 -8 16 57 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -238 238 238 -255 255 255 -213 131 139 -172 90 98 diff --git a/graphics/interface/pss_unk_83D1C2C.pal b/graphics/pokemon_storage/wallpapers/stars/box.pal similarity index 51% rename from graphics/interface/pss_unk_83D1C2C.pal rename to graphics/pokemon_storage/wallpapers/stars/box.pal index 0d9a33ee1..fc4215468 100644 --- a/graphics/interface/pss_unk_83D1C2C.pal +++ b/graphics/pokemon_storage/wallpapers/stars/box.pal @@ -1,22 +1,6 @@ JASC-PAL 0100 -32 -255 255 115 -106 8 115 -156 41 148 -205 74 180 -74 106 156 -98 123 205 -123 139 255 -238 238 57 -213 156 123 -156 230 82 -180 164 131 -213 106 189 -156 115 197 -139 180 164 -230 213 213 -255 255 255 +16 255 255 115 106 8 115 156 41 148 diff --git a/graphics/interface/pss_unk_83D1EC4.bin b/graphics/pokemon_storage/wallpapers/stars/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83D1EC4.bin rename to graphics/pokemon_storage/wallpapers/stars/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/stars/tiles.png b/graphics/pokemon_storage/wallpapers/stars/tiles.png new file mode 100644 index 000000000..51c9f8674 Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/stars/tiles.png differ diff --git a/graphics/pokemon_storage/wallpapers/stars/title.pal b/graphics/pokemon_storage/wallpapers/stars/title.pal new file mode 100644 index 000000000..e7b45e524 --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/stars/title.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 255 115 +106 8 115 +156 41 148 +205 74 180 +74 106 156 +98 123 205 +123 139 255 +238 238 57 +213 156 123 +156 230 82 +180 164 131 +213 106 189 +156 115 197 +139 180 164 +230 213 213 +255 255 255 diff --git a/graphics/interface/pss_unk_83D239C.pal b/graphics/pokemon_storage/wallpapers/tiles/box.pal similarity index 52% rename from graphics/interface/pss_unk_83D239C.pal rename to graphics/pokemon_storage/wallpapers/tiles/box.pal index 07d069629..9ff5c0789 100644 --- a/graphics/interface/pss_unk_83D239C.pal +++ b/graphics/pokemon_storage/wallpapers/tiles/box.pal @@ -1,22 +1,6 @@ JASC-PAL 0100 -32 -255 255 115 -156 90 41 -205 106 8 -230 156 8 -0 0 255 -0 0 255 -0 0 255 -164 156 139 -213 205 172 -0 0 255 -131 131 131 -164 164 164 -180 180 180 -197 197 197 -213 213 213 -255 255 255 +16 255 255 115 156 90 41 205 106 8 diff --git a/graphics/interface/pss_unk_83D256C.bin b/graphics/pokemon_storage/wallpapers/tiles/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83D256C.bin rename to graphics/pokemon_storage/wallpapers/tiles/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/tiles/tiles.png b/graphics/pokemon_storage/wallpapers/tiles/tiles.png new file mode 100644 index 000000000..1b3443a0a Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/tiles/tiles.png differ diff --git a/graphics/pokemon_storage/wallpapers/tiles/title.pal b/graphics/pokemon_storage/wallpapers/tiles/title.pal new file mode 100644 index 000000000..efcd01fa6 --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/tiles/title.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 255 115 +156 90 41 +205 106 8 +230 156 8 +0 0 255 +0 0 255 +0 0 255 +164 156 139 +213 205 172 +0 0 255 +131 131 131 +164 164 164 +180 180 180 +197 197 197 +213 213 213 +255 255 255 diff --git a/graphics/interface/pss_unk_83D2820.bin b/graphics/pokemon_storage/wallpapers/unused.bin similarity index 100% rename from graphics/interface/pss_unk_83D2820.bin rename to graphics/pokemon_storage/wallpapers/unused.bin diff --git a/graphics/interface/pss_unk_83CFFC8.pal b/graphics/pokemon_storage/wallpapers/volcano/box.pal similarity index 52% rename from graphics/interface/pss_unk_83CFFC8.pal rename to graphics/pokemon_storage/wallpapers/volcano/box.pal index e019bd6e9..8ea563b6e 100644 --- a/graphics/interface/pss_unk_83CFFC8.pal +++ b/graphics/pokemon_storage/wallpapers/volcano/box.pal @@ -1,22 +1,6 @@ JASC-PAL 0100 -32 -255 255 255 -222 222 222 -189 189 189 -139 148 189 -106 115 156 -74 82 123 -172 180 222 -0 0 0 -222 131 74 -205 115 57 -180 82 24 -0 0 0 -230 230 230 -255 255 255 -213 131 139 -172 90 98 +16 255 255 255 255 246 230 255 238 205 diff --git a/graphics/interface/pss_unk_83D033C.bin b/graphics/pokemon_storage/wallpapers/volcano/tilemap.bin similarity index 100% rename from graphics/interface/pss_unk_83D033C.bin rename to graphics/pokemon_storage/wallpapers/volcano/tilemap.bin diff --git a/graphics/pokemon_storage/wallpapers/volcano/tiles.png b/graphics/pokemon_storage/wallpapers/volcano/tiles.png new file mode 100644 index 000000000..812ce08c9 Binary files /dev/null and b/graphics/pokemon_storage/wallpapers/volcano/tiles.png differ diff --git a/graphics/pokemon_storage/wallpapers/volcano/title.pal b/graphics/pokemon_storage/wallpapers/volcano/title.pal new file mode 100644 index 000000000..0378aff29 --- /dev/null +++ b/graphics/pokemon_storage/wallpapers/volcano/title.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +255 255 255 +222 222 222 +189 189 189 +139 148 189 +106 115 156 +74 82 123 +172 180 222 +0 0 0 +222 131 74 +205 115 57 +180 82 24 +0 0 0 +230 230 230 +255 255 255 +213 131 139 +172 90 98 diff --git a/graphics/pokemon_storage/waveform.png b/graphics/pokemon_storage/waveform.png new file mode 100644 index 000000000..b8f101d61 Binary files /dev/null and b/graphics/pokemon_storage/waveform.png differ diff --git a/graphics_file_rules.mk b/graphics_file_rules.mk index d2f5ab5c6..2adb6e847 100644 --- a/graphics_file_rules.mk +++ b/graphics_file_rules.mk @@ -30,6 +30,7 @@ BERRYPOUCHGFXDIR := graphics/berry_pouch HALLOFFAMEGFXDIR := graphics/hall_of_fame MAPPREVIEWGFXDIR := graphics/map_preview NAMINGGFXDIR := graphics/naming_screen +WALLPAPERGFXDIR := graphics/pokemon_storage/wallpapers types := normal fight flying poison ground rock bug ghost steel mystery fire water grass electric psychic ice dragon dark contest_types := cool beauty cute smart tough @@ -664,3 +665,52 @@ $(NAMINGGFXDIR)/cursor_squished.4bpp: %.4bpp: %.png $(NAMINGGFXDIR)/cursor_filled.4bpp: %.4bpp: %.png $(GFX) $< $@ -num_tiles 5 + + +$(WALLPAPERGFXDIR)/beach/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 60 + +$(WALLPAPERGFXDIR)/cave/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 61 + +$(WALLPAPERGFXDIR)/city/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 40 + +$(WALLPAPERGFXDIR)/crag/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 54 + +$(WALLPAPERGFXDIR)/desert/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 52 + +$(WALLPAPERGFXDIR)/forest/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 53 + +$(WALLPAPERGFXDIR)/pokecenter/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 57 + +$(WALLPAPERGFXDIR)/river/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 63 + +$(WALLPAPERGFXDIR)/savanna/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 45 + +$(WALLPAPERGFXDIR)/seafloor/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 53 + +$(WALLPAPERGFXDIR)/simple/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 25 + +$(WALLPAPERGFXDIR)/sky/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 52 + +$(WALLPAPERGFXDIR)/snow/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 51 + +$(WALLPAPERGFXDIR)/stars/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 37 + +$(WALLPAPERGFXDIR)/tiles/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 31 + +$(WALLPAPERGFXDIR)/volcano/tiles.4bpp: %.4bpp: %.png + $(GFX) $< $@ -num_tiles 57 diff --git a/include/box_party_pokemon_dropdown.h b/include/box_party_pokemon_dropdown.h deleted file mode 100644 index 795a22e67..000000000 --- a/include/box_party_pokemon_dropdown.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef GUARD_BOX_PARTY_POKEMON_DROPDOWN_H -#define GUARD_BOX_PARTY_POKEMON_DROPDOWN_H - -enum -{ - BPPD_MOVE_INNER_LEFT = 0, - BPPD_MOVE_OUTER_LEFT, - BPPD_MOVE_INNER_TOP, - BPPD_MOVE_OUTER_TOP, - BPPD_MOVE_INNER_X, - BPPD_MOVE_INNER_Y -}; - -void AllocBoxPartyPokemonDropdowns(u8 num); -void FreeBoxPartyPokemonDropdowns(void); -void CopyAllBoxPartyPokemonDropdownsToVram(void); -void SetBoxPartyPokemonDropdownMap2(u8 idx, u8 bgId, const void *src, u16 width, u16 height); -void SetBoxPartyPokemonDropdownMap1Tiles(u8 idx, const void *src); -void SetBoxPartyPokemonDropdownMap2Pos(u8 idx, u16 x, u16 y); -void SetBoxPartyPokemonDropdownMap2Rect(u8 idx, u16 x, u16 y, u16 width, u16 height); -void AdjustBoxPartyPokemonDropdownPos(u8 a0, u8 a1, s8 a2); -void CopyBoxPartyPokemonDropdownToBgTilemapBuffer(u8 idx); - -#endif //GUARD_BOX_PARTY_POKEMON_DROPDOWN_H diff --git a/include/graphics.h b/include/graphics.h index 6739f937b..02cc0082e 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -4928,11 +4928,11 @@ extern const u16 gNamingScreenInputArrow_Gfx[]; extern const u16 gNamingScreenUnderscore_Gfx[]; // pokemon_storage_system -extern const u32 gPSSMenu_Gfx[]; -extern const u32 gUnknown_8E9CAEC[]; -extern const u16 gPSSMenu_Pal[]; -extern const u16 gUnknown_8E9C3F8[]; -extern const u16 gUnknown_8E9C418[]; +extern const u32 gPokeStorageMenu_Gfx[]; +extern const u32 gPokeStoragePartyMenu_Tilemap[]; +extern const u16 gPokeStoragePartyMenu_Pal[]; +extern const u16 gPokeStorageInterface_Pal[]; +extern const u16 gPokeStorageInterface_NoDisplayMon_Pal[]; // pokedex_screen extern const u16 gDexScreen_TopMenuIconPals_AtoZ[]; diff --git a/include/pokemon_storage_system.h b/include/pokemon_storage_system.h index f111796d8..388d3dba5 100644 --- a/include/pokemon_storage_system.h +++ b/include/pokemon_storage_system.h @@ -4,7 +4,18 @@ #include "global.h" #define TOTAL_BOXES_COUNT 14 -#define IN_BOX_COUNT 30 +#define IN_BOX_ROWS 5 // Number of rows, 6 Pokémon per row +#define IN_BOX_COLUMNS 6 // Number of columns, 5 Pokémon per column +#define IN_BOX_COUNT (IN_BOX_ROWS * IN_BOX_COLUMNS) + +/* + COLUMNS +ROWS 0 1 2 3 4 5 + 6 7 8 9 10 11 + 12 13 14 15 16 17 + 18 19 20 21 22 23 + 24 25 26 27 28 29 +*/ enum { @@ -20,10 +31,10 @@ enum WALLPAPER_SEAFLOOR, WALLPAPER_RIVER, WALLPAPER_SKY, - WALLPAPER_POLKADOT, + WALLPAPER_STARS, WALLPAPER_POKECENTER, - WALLPAPER_MACHINE, - WALLPAPER_PLAIN, + WALLPAPER_TILES, + WALLPAPER_SIMPLE, WALLPAPER_COUNT }; #define MAX_DEFAULT_WALLPAPER WALLPAPER_SAVANNA @@ -34,7 +45,7 @@ void SetBoxMonNickAt(u8 boxId, u8 monPosition, const u8 *newNick); s16 CompactPartySlots(void); u32 GetBoxMonDataAt(u8 boxId, u8 monPosition, s32 request); void ZeroBoxMonAt(u8 boxId, u8 monPosition); -void Cb2_ReturnToPSS(void); +void CB2_ReturnToPokeStorage(void); void ResetPokemonStorageSystem(void); u8 StorageGetCurrentBox(void); void DrawTextWindowAndBufferTiles(const u8 *string, void *dst, u8 zero1, u8 zero2, u8 *buffer, s32 bytesToBuffer); diff --git a/include/pokemon_storage_system_internal.h b/include/pokemon_storage_system_internal.h index 3582d1f32..9c1984825 100644 --- a/include/pokemon_storage_system_internal.h +++ b/include/pokemon_storage_system_internal.h @@ -4,9 +4,6 @@ #include "pokemon_storage_system.h" #include "mon_markings.h" -#define IN_BOX_COLUMNS 5 -#define IN_BOX_ROWS 6 - // The maximum number of Pokémon icons that can appear on-screen. // By default the limit is 40 (though in practice only 37 can be). #define MAX_MON_ICONS (IN_BOX_COUNT + PARTY_SIZE + 1 >= 40 ? IN_BOX_COUNT + PARTY_SIZE + 1 : 40) @@ -16,13 +13,6 @@ // between 2 Pokémon with held items #define MAX_ITEM_ICONS 3 -enum -{ - MODE_PARTY, - MODE_BOX, - MODE_2, -}; - enum { OPTION_WITHDRAW, @@ -35,139 +25,200 @@ enum enum { - PC_TEXT_EXIT_BOX, - PC_TEXT_WHAT_YOU_DO, - PC_TEXT_PICK_A_THEME, - PC_TEXT_PICK_A_WALLPAPER, - PC_TEXT_IS_SELECTED, - PC_TEXT_JUMP_TO_WHICH_BOX, - PC_TEXT_DEPOSIT_IN_WHICH_BOX, - PC_TEXT_WAS_DEPOSITED, - PC_TEXT_BOX_IS_FULL, - PC_TEXT_RELEASE_POKE, - PC_TEXT_WAS_RELEASED, - PC_TEXT_BYE_BYE, - PC_TEXT_MARK_POKE, - PC_TEXT_LAST_POKE, - PC_TEXT_PARTY_FULL, - PC_TEXT_HOLDING_POKE, - PC_TEXT_WHICH_ONE_WILL_TAKE, - PC_TEXT_CANT_RELEASE_EGG, - PC_TEXT_CONTINUE_BOX, - PC_TEXT_CAME_BACK, - PC_TEXT_WORRIED, - PC_TEXT_SURPRISE, - PC_TEXT_PLEASE_REMOVE_MAIL, - PC_TEXT_IS_SELECTED2, - PC_TEXT_GIVE_TO_MON, - PC_TEXT_PLACED_IN_BAG, - PC_TEXT_BAG_FULL, - PC_TEXT_PUT_IN_BAG, - PC_TEXT_ITEM_IS_HELD, - PC_TEXT_CHANGED_TO_ITEM, - PC_TEXT_CANT_STORE_MAIL, + MENU_TEXT_CANCEL, + MENU_TEXT_STORE, + MENU_TEXT_WITHDRAW, + MENU_TEXT_MOVE, + MENU_TEXT_SHIFT, + MENU_TEXT_PLACE, + MENU_TEXT_SUMMARY, + MENU_TEXT_RELEASE, + MENU_TEXT_MARK, + MENU_TEXT_JUMP, + MENU_TEXT_WALLPAPER, + MENU_TEXT_NAME, + MENU_TEXT_TAKE, + MENU_TEXT_GIVE, + MENU_TEXT_GIVE2, + MENU_TEXT_SWITCH, + MENU_TEXT_BAG, + MENU_TEXT_INFO, + MENU_TEXT_SCENERY_1, + MENU_TEXT_SCENERY_2, + MENU_TEXT_SCENERY_3, + MENU_TEXT_ETCETERA, + MENU_TEXT_FOREST, + MENU_TEXT_CITY, + MENU_TEXT_DESERT, + MENU_TEXT_SAVANNA, + MENU_TEXT_CRAG, + MENU_TEXT_VOLCANO, + MENU_TEXT_SNOW, + MENU_TEXT_CAVE, + MENU_TEXT_BEACH, + MENU_TEXT_SEAFLOOR, + MENU_TEXT_RIVER, + MENU_TEXT_SKY, + MENU_TEXT_POLKADOT, + MENU_TEXT_POKECENTER, + MENU_TEXT_MACHINE, + MENU_TEXT_SIMPLE, +}; + +// Return IDs for input handlers +enum { + INPUT_NONE, + INPUT_MOVE_CURSOR, + INPUT_2, // Unused + INPUT_3, // Unused + INPUT_CLOSE_BOX, + INPUT_SHOW_PARTY, + INPUT_HIDE_PARTY, + INPUT_BOX_OPTIONS, + INPUT_IN_MENU, + INPUT_SCROLL_RIGHT, + INPUT_SCROLL_LEFT, + INPUT_DEPOSIT, + INPUT_WITHDRAW, + INPUT_MOVE_MON, + INPUT_SHIFT_MON, + INPUT_PLACE_MON, + INPUT_TAKE_ITEM, + INPUT_GIVE_ITEM, + INPUT_SWITCH_ITEMS, + INPUT_PRESSED_B, + INPUT_MULTIMOVE_START, + INPUT_MULTIMOVE_CHANGE_SELECTION, + INPUT_MULTIMOVE_SINGLE, + INPUT_MULTIMOVE_GRAB_SELECTION, + INPUT_MULTIMOVE_UNABLE, + INPUT_MULTIMOVE_MOVE_MONS, + INPUT_MULTIMOVE_PLACE_MONS, }; enum { - PC_TEXT_FMT_NORMAL, - PC_TEXT_FMT_MON_NAME_1, - PC_TEXT_FMT_MON_NAME_2, - PC_TEXT_FMT_MON_NAME_3, - PC_TEXT_FMT_MON_NAME_4, - PC_TEXT_FMT_MON_NAME_5, - PC_TEXT_FMT_MON_NAME_6, - PC_TEXT_FMT_ITEM_NAME, + RELEASE_MON_NOT_ALLOWED, + RELEASE_MON_ALLOWED, + RELEASE_MON_UNDETERMINED = -1, }; enum { - PC_TEXT_CANCEL, - PC_TEXT_STORE, - PC_TEXT_WITHDRAW, - PC_TEXT_MOVE, - PC_TEXT_SHIFT, - PC_TEXT_PLACE, - PC_TEXT_SUMMARY, - PC_TEXT_RELEASE, - PC_TEXT_MARK, - PC_TEXT_JUMP, - PC_TEXT_WALLPAPER, - PC_TEXT_NAME, - PC_TEXT_TAKE, - PC_TEXT_GIVE, - PC_TEXT_GIVE2, - PC_TEXT_SWITCH, - PC_TEXT_BAG, - PC_TEXT_INFO, - PC_TEXT_SCENERY1, - PC_TEXT_SCENERY2, - PC_TEXT_SCENERY3, - PC_TEXT_ETCETERA, - PC_TEXT_FOREST, - PC_TEXT_CITY, - PC_TEXT_DESERT, - PC_TEXT_SAVANNA, - PC_TEXT_CRAG, - PC_TEXT_VOLCANO, - PC_TEXT_SNOW, - PC_TEXT_CAVE, - PC_TEXT_BEACH, - PC_TEXT_SEAFLOOR, - PC_TEXT_RIVER, - PC_TEXT_SKY, - PC_TEXT_POLKADOT, - PC_TEXT_POKECENTER, - PC_TEXT_MACHINE, - PC_TEXT_SIMPLE, + MODE_PARTY, + MODE_BOX, + MODE_MOVE, }; enum { CURSOR_AREA_IN_BOX, CURSOR_AREA_IN_PARTY, - CURSOR_AREA_BOX, + CURSOR_AREA_BOX_TITLE, CURSOR_AREA_BUTTONS, // Party Pokemon and Close Box }; +#define CURSOR_AREA_IN_HAND CURSOR_AREA_BOX_TITLE // Alt name for cursor area used by Move Items + +// IDs for InitMonPlaceChange +enum +{ + CHANGE_GRAB, + CHANGE_PLACE, + CHANGE_SHIFT, +}; + +// IDs for the main functions for moving multiple Pokémon. +// Given as arguments to MultiMove_SetFunction +enum +{ + MULTIMOVE_START, + MULTIMOVE_SINGLE, + MULTIMOVE_CHANGE_SELECTION, + MULTIMOVE_GRAB_SELECTION, + MULTIMOVE_MOVE_MONS, + MULTIMOVE_PLACE_MONS, +}; enum { - SCREEN_CHANGE_EXIT_BOX, - SCREEN_CHANGE_SUMMARY_SCREEN, - SCREEN_CHANGE_NAME_BOX, - SCREEN_CHANGE_ITEM_FROM_BAG, + PALTAG_MON_ICON_0 = 56000, + PALTAG_MON_ICON_1, // Used implicitly in CreateMonIconSprite + PALTAG_MON_ICON_2, // Used implicitly in CreateMonIconSprite + PALTAG_3, // Unused + PALTAG_4, // Unused + PALTAG_5, // Unused + PALTAG_DISPLAY_MON, + PALTAG_MISC_1, // Used by cursor in multimove mode, choose box menu popup + PALTAG_MARKING_COMBO, + PALTAG_BOX_TITLE, + PALTAG_MISC_2, // Used by waveforms, cursor in normal mode, cursor shadow, box scroll arrows + PALTAG_ITEM_ICON_0, + PALTAG_ITEM_ICON_1, // Used implicitly in CreateItemIconSprites + PALTAG_ITEM_ICON_2, // Used implicitly in CreateItemIconSprites + PALTAG_MARKING_MENU, }; -#define TAG_PAL_WAVEFORM 0xDACA -#define TAG_PAL_DAC8 0xDAC8 -#define TAG_PAL_DAC6 0xDAC6 -#define TAG_PAL_DACE 0xDACE -#define TAG_PAL_DAC7 0xDAC7 -#define TAG_PAL_DAC9 0xDAC9 -#define TAG_PAL_DAC0 0xDAC0 -#define TAG_PAL_DACB 0xDACB +enum +{ + GFXTAG_CURSOR, + GFXTAG_CURSOR_SHADOW, + GFXTAG_DISPLAY_MON, + GFXTAG_BOX_TITLE, + GFXTAG_BOX_TITLE_ALT, + GFXTAG_WAVEFORM, + GFXTAG_BOX_SCROLL_ARROW, + GFXTAG_ITEM_ICON_0, + GFXTAG_ITEM_ICON_1, // Used implicitly in CreateItemIconSprites + GFXTAG_ITEM_ICON_2, // Used implicitly in CreateItemIconSprites + GFXTAG_CHOOSE_BOX_MENU_CENTER, + GFXTAG_CHOOSE_BOX_MENU_CORNERS, // Used implicitly in LoadChooseBoxMenuGfx + GFXTAG_12, // Unused + GFXTAG_MARKING_MENU, + GFXTAG_14, // Unused + GFXTAG_15, // Unused + GFXTAG_MARKING_COMBO, + GFXTAG_17, // Unused + GFXTAG_MON_ICON, +}; -#define TAG_TILE_WAVEFORM 0x5 -#define TAG_TILE_10 0x10 -#define TAG_TILE_2 0x2 -#define TAG_TILE_D 0xD -#define TAG_TILE_A 0xA -#define TAG_TILE_3 0x3 -#define TAG_TILE_4 0x4 -#define TAG_TILE_12 0x12 -#define TAG_TILE_7 0x7 -#define TAG_TILE_0 0x0 -#define TAG_TILE_1 0x1 -#define TAG_TILE_6 0x6 +// Special box ids for the choose box menu +#define BOXID_NONE_CHOSEN 200 +#define BOXID_CANCELED 201 -struct WallpaperTable + +enum { + CURSOR_ANIM_BOUNCE, + CURSOR_ANIM_STILL, + CURSOR_ANIM_OPEN, + CURSOR_ANIM_FIST, +}; + +enum +{ + RELEASE_ANIM_RELEASE, + RELEASE_ANIM_COME_BACK, +}; + +// IDs for the item icons affine anims +enum +{ + ITEM_ANIM_NONE, + ITEM_ANIM_APPEAR, + ITEM_ANIM_DISAPPEAR, + ITEM_ANIM_PICK_UP, + ITEM_ANIM_PUT_DOWN, + ITEM_ANIM_PUT_AWAY, + ITEM_ANIM_LARGE, +}; + +struct Wallpaper { const u32 *tiles; const u32 *tileMap; const u16 *palettes; }; -struct StorageAction +struct StorageMessage { const u8 *text; u8 format; @@ -176,7 +227,7 @@ struct StorageAction struct ChooseBoxMenu { struct Sprite *menuSprite; - struct Sprite *menuSideSprites[4]; + struct Sprite *menuCornerSprites[4]; u32 unused1[3]; struct Sprite *arrowSprites[2]; u8 buffer[0x200]; // passed but not used @@ -212,7 +263,7 @@ struct UnkUtil u8 max; }; -struct PSS_ItemIconSprite +struct PokeStorageItemIcon { struct Sprite *sprite; u8 *tiles; @@ -222,12 +273,12 @@ struct PSS_ItemIconSprite u8 active; }; -struct PssQuestLogBuffer +struct PokeStorageQuestLogData { - u16 species; + u16 species1; u16 species2; - u8 fromBox; - u8 toBox; + u8 box1; + u8 box2; }; struct PokemonStorageSystemData @@ -235,7 +286,7 @@ struct PokemonStorageSystemData u8 state; u8 boxOption; u8 screenChangeType; - bool8 isReshowingPSS; + bool8 isReopening; u8 taskId; struct UnkUtil unkUtil; struct UnkUtilData unkUtilData[8]; @@ -262,8 +313,8 @@ struct PokemonStorageSystemData u16 scrollUnused5; // Never read u16 scrollUnused6; // Never read u8 filler1[22]; - u8 field_2F8[512]; - u8 field_4F8[512]; + u8 boxTitleTiles[512]; + u8 boxTitleUnused[512]; u8 boxTitleCycleId; u8 wallpaperLoadState; // Written to, but never read. u8 wallpaperLoadBoxId; @@ -276,7 +327,7 @@ struct PokemonStorageSystemData struct Sprite *arrowSprites[2]; u32 wallpaperPalBits; u8 filler2[80]; // Unused - u16 unkUnused1; // Never read. + u16 unusedField1; // Never read. s16 wallpaperSetId; s16 wallpaperId; u16 wallpaperTilemap[360]; @@ -285,112 +336,114 @@ struct PokemonStorageSystemData u8 scrollToBoxId; s8 scrollDirection; // u8 *wallpaperTiles; // used only in Emerald for Walda - /* 0a68 */ struct Sprite *movingMonSprite; - /* 0a6c */ struct Sprite *partySprites[PARTY_SIZE]; - /* 0a84 */ struct Sprite *boxMonsSprites[IN_BOX_COUNT]; - /* 0afc */ struct Sprite **shiftMonSpritePtr; - /* 0b00 */ struct Sprite **releaseMonSpritePtr; - /* 0b04 */ u16 numIconsPerSpecies[MAX_MON_ICONS]; - /* 0b54 */ u16 iconSpeciesList[MAX_MON_ICONS]; - /* 0ba4 */ u16 boxSpecies[IN_BOX_COUNT]; - /* 0be0 */ u32 boxPersonalities[IN_BOX_COUNT]; - /* 0c58 */ u8 incomingBoxId; - /* 0c59 */ u8 shiftTimer; - /* 0c5a */ u8 numPartyToCompact; - /* 0c5c */ u16 iconScrollDistance; - /* 0c5e */ s16 iconScrollPos; - /* 0c60 */ s16 iconScrollSpeed; - /* 0c62 */ u16 iconScrollNumIncoming; - /* 0c64 */ u8 iconScrollCurColumn; - /* 0c65 */ s8 iconScrollDirection; // Unnecessary duplicate of scrollDirection - /* 0c66 */ u8 iconScrollState; - /* 0c67 */ u8 iconScrollToBoxId; // Unused duplicate of scrollToBoxId - /* 0c68 */ struct WindowTemplate menuWindow; - /* 0c70 */ struct StorageMenu menuItems[7]; - /* 0ca8 */ u8 menuItemsCount; - /* 0ca9 */ u8 menuWidth; - /* 0caa */ u8 menuUnusedField; // Never read. - /* 0cac */ u16 menuWindowId; - /* 0cb0 */ struct Sprite *cursorSprite; - /* 0cb4 */ struct Sprite *cursorShadowSprite; - /* 0cb8 */ s32 cursorNewX; - /* 0cbc */ s32 cursorNewY; - /* 0cc0 */ u32 cursorSpeedX; - /* 0cc4 */ u32 cursorSpeedY; - /* 0cc8 */ s16 cursorTargetX; - /* 0cca */ s16 cursorTargetY; - /* 0ccc */ u16 cursorMoveSteps; - /* 0cce */ s8 cursorVerticalWrap; - /* 0ccf */ s8 cursorHorizontalWrap; - /* 0cd0 */ u8 newCursorArea; - /* 0cd1 */ u8 newCursorPosition; - /* 0cd2 */ u8 cursorPrevHorizPos; - /* 0cd3 */ u8 cursorFlipTimer; - /* 0cd4 */ u8 cursorPalNums[2]; - /* 0cd8 */ const u32 *displayMonPalette; - /* 0cdc */ u32 displayMonPersonality; - /* 0ce0 */ u16 displayMonSpecies; - /* 0ce2 */ u16 displayMonItemId; - /* 0ce4 */ u16 displayUnusedVar; - /* 0ce6 */ bool8 setMosaic; - /* 0ce7 */ u8 displayMonMarkings; - /* 0ce8 */ u8 displayMonLevel; - /* 0ce9 */ bool8 displayMonIsEgg; - /* 0cea */ u8 displayMonName[POKEMON_NAME_LENGTH + 1]; - /* 0cf5 */ u8 displayMonTexts[4][36]; - /* 0d88 */ bool8 (*monPlaceChangeFunc)(void); - /* 0d8c */ u8 monPlaceChangeState; - /* 0d8d */ u8 shiftBoxId; - /* 0d90 */ struct Sprite *markingComboSprite; - /* 0d94 */ struct Sprite *waveformSprites[2]; - /* 0d9c */ u16 *markingComboTilesPtr; - /* 0da0 */ struct MonMarkingsMenu markMenu; - /* 1e58 */ struct ChooseBoxMenu field_1E5C; - /* 20a0 */ struct Pokemon movingMon; - /* 2104 */ struct Pokemon field_2108; - /* 2168 */ u8 field_216C; - /* 2169 */ u8 field_216D; - /* 216c */ bool8 isSurfMon; - /* 216d */ bool8 isDiveMon; - /* 216a */ s8 field_216E; - /* 216b */ s8 field_216F; - /* 216e */ s8 field_2170; - /* 216f */ s8 field_2171; - /* 2170 */ u16 field_2172; - /* 2172 */ u16 field_2176[3]; - /* 2178 */ u8 field_2186; - /* 2179 */ u8 field_2187; - /* 217a */ u8 summaryScreenMode; - /* 217c */ union + struct Sprite *movingMonSprite; + struct Sprite *partySprites[PARTY_SIZE]; + struct Sprite *boxMonsSprites[IN_BOX_COUNT]; + struct Sprite **shiftMonSpritePtr; + struct Sprite **releaseMonSpritePtr; + u16 numIconsPerSpecies[MAX_MON_ICONS]; + u16 iconSpeciesList[MAX_MON_ICONS]; + u16 boxSpecies[IN_BOX_COUNT]; + u32 boxPersonalities[IN_BOX_COUNT]; + u8 incomingBoxId; + u8 shiftTimer; + u8 numPartySpritesToCompact; + u16 iconScrollDistance; + s16 iconScrollPos; + s16 iconScrollSpeed; + u16 iconScrollNumIncoming; + u8 iconScrollCurColumn; + s8 iconScrollDirection; // Unnecessary duplicate of scrollDirection + u8 iconScrollState; + u8 iconScrollToBoxId; // Unused duplicate of scrollToBoxId + struct WindowTemplate menuWindow; + struct StorageMenu menuItems[7]; + u8 menuItemsCount; + u8 menuWidth; + u8 menuUnusedField; // Never read. + u16 menuWindowId; + struct Sprite *cursorSprite; + struct Sprite *cursorShadowSprite; + s32 cursorNewX; + s32 cursorNewY; + u32 cursorSpeedX; + u32 cursorSpeedY; + s16 cursorTargetX; + s16 cursorTargetY; + u16 cursorMoveSteps; + s8 cursorVerticalWrap; + s8 cursorHorizontalWrap; + u8 newCursorArea; + u8 newCursorPosition; + u8 cursorPrevPartyPos; + u8 cursorFlipTimer; + u8 cursorPalNums[2]; + const u32 *displayMonPalette; + u32 displayMonPersonality; + u16 displayMonSpecies; + u16 displayMonItemId; + u16 displayUnusedVar; + bool8 setMosaic; + u8 displayMonMarkings; + u8 displayMonLevel; + bool8 displayMonIsEgg; + u8 displayMonNickname[POKEMON_NAME_LENGTH + 1]; + u8 displayMonTexts[4][36]; // nickname, species name, gender and level, item name + bool8 (*monPlaceChangeFunc)(void); + u8 monPlaceChangeState; + u8 shiftBoxId; + struct Sprite *markingComboSprite; + struct Sprite *waveformSprites[2]; + u16 *markingComboTilesPtr; + struct MonMarkingsMenu markMenu; + struct ChooseBoxMenu chooseBoxMenu; + struct Pokemon movingMon; + struct Pokemon tempMon; + s8 releaseMonStatus; + bool8 releaseMonStatusResolved; + bool8 isSurfMon; + bool8 isDiveMon; + s8 releaseCheckBoxId; + s8 releaseCheckBoxPos; + s8 releaseBoxId; + s8 releaseBoxPos; + u16 releaseCheckState; + u16 restrictedMoveList[3]; + u8 summaryLastIndex; + u8 summaryCursorPos; + u8 summaryScreenMode; + union { struct Pokemon *mon; struct BoxPokemon *box; - } field_218C; - /* 2180 */ u8 field_2190[40]; - /* 21a8 */ u8 field_21B8[40]; - /* 21d0 */ u8 field_21E0[POKEMON_NAME_LENGTH + 1]; - /* 21db */ u8 itemName[20]; - /* 21ef */ u8 inBoxMovingMode; - /* 21f0 */ u16 field_2200; - /* 21f4 */ struct PSS_ItemIconSprite itemIcons[MAX_ITEM_ICONS]; - /* 2224 */ u16 movingItemId; - /* 2226 */ u16 itemInfoWindowOffset; - /* 2228 */ struct PssQuestLogBuffer qlogBuffer; - /* 2230 */ u16 field_2238; - /* 2232 */ u16 field_223A; - /* 2234 */ u16 *field_223C; - /* 2238 */ struct Sprite *cursorMonSprite; - /* 223c */ u16 field_2244[0x40]; - /* 22bc */ u8 field_22C4[0x800]; - /* 2abc */ u8 field_2AC4[0x1800]; - /* 42bc */ u8 itemIconBuffer[0x800]; - /* 4abc */ u8 field_4AC4[0x1000]; - /* 5abc */ u8 field_5AC4[0x800]; -}; // size=62bc + } summaryMonPtr; + u8 actionText[40]; + u8 boxTitleText[40]; + u8 releaseMonName[POKEMON_NAME_LENGTH + 1]; + u8 itemName[20]; + u8 inBoxMovingMode; + u16 multiMoveWindowId; + struct PokeStorageItemIcon itemIcons[MAX_ITEM_ICONS]; + u16 movingItemId; + u16 itemInfoWindowOffset; + struct PokeStorageQuestLogData pokeStorageQuestLogData; + u16 unusedField2; + u16 displayMonPalOffset; + u16 *displayMonTilePtr; + struct Sprite *displayMonSprite; + u16 displayMonPalBuffer[0x20]; + u8 unusedBuffer1[0x40]; + u8 tileBuffer[0x800]; + u8 unusedBuffer2[0x1800]; + u8 itemIconBuffer[0x200]; + u8 unusedBuffer3[0x600]; + u8 wallpaperBgTilemapBuffer[0x1000]; + u8 menuTilemapBuffer[0x800]; +}; -extern struct PokemonStorageSystemData *gPSSData; +extern struct PokemonStorageSystemData *gStorage; -void Cb2_EnterPSS(u8 a0); +void EnterPokeStorage(u8 boxOption); u8 GetCurrentBoxOption(void); struct Sprite *CreateChooseBoxArrows(u16 x, u16 y, u8 animId, u8 priority, u8 subpriority); void SetBoxWallpaper(u8 boxId, u8 wallpaperId); @@ -400,46 +453,46 @@ void SetBoxMonAt(u8 boxId, u8 boxPosition, struct BoxPokemon * src); void CB2_ExitPokeStorage(void); void FreeBoxSelectionPopupSpriteGfx(void); -void sub_808C940(u8 curBox); -void sub_808C950(void); +void CreateChooseBoxMenuSprites(u8 curBox); +void DestroyChooseBoxMenuSprites(void); u8 HandleBoxChooseSelectionInput(void); -void LoadChooseBoxMenuGfx(struct ChooseBoxMenu *a0, u16 tileTag, u16 palTag, u8 a3, bool32 loadPal); +void LoadChooseBoxMenuGfx(struct ChooseBoxMenu *menu, u16 tileTag, u16 palTag, u8 subpriority, bool32 loadPal); void SetCurrentBoxMonData(u8 boxPosition, s32 request, const void *value); u32 GetCurrentBoxMonData(u8 boxPosition, s32 request); u32 GetAndCopyBoxMonDataAt(u8 boxId, u8 boxPosition, s32 request, void *dst); -void sub_80922C0(void); -void sub_8092340(void); -bool8 sub_80924A8(void); -void sub_8092AE4(void); -void sub_8092B3C(u8 a0); -void sub_8092B50(void); -void sub_8092B5C(void); -u8 sub_8092B70(void); -void sub_8092F54(void); -void sub_8093174(void); -void sub_8093194(void); -bool8 sub_80931EC(void); -void sub_8093264(void); -void sub_8093630(void); -void sub_8093660(void); -void sub_80936B8(void); -void sub_80937B4(void); -void sub_8094D14(u8 a0); -u8 sub_8094D34(void); -void sub_8094D60(void); -void sub_8094D84(void); -bool8 sub_8094F90(void); -s16 sub_8094F94(void); -void sub_8095024(void); -bool8 sub_8095050(void); -void sub_80950A4(void); -void sub_80950BC(u8 a0); -bool8 sub_80950D0(void); +void InitCursor(void); +void InitCursorOnReopen(void); +bool8 UpdateCursorPos(void); +void SetCursorInParty(void); +void SetCursorBoxPosition(u8 cursorBoxPosition); +void ClearSavedCursorPos(void); +void SaveCursorPos(void); +u8 GetSavedCursorPos(void); +void DoTrySetDisplayMonData(void); +void ResetSelectionAfterDeposit(void); +void InitReleaseMon(void); +bool8 TryHideReleaseMon(void); +void TrySetCursorFistAnim(void); +void SaveMovingMon(void); +void LoadSavedMovingMon(void); +void InitSummaryScreenData(void); +void SetSelectionAfterSummaryScreen(void); +void StartCursorAnim(u8 animNum); +u8 GetMovingMonOriginalBoxId(void); +void TryHideItemAtCursor(void); +void TryShowItemAtCursor(void); +bool8 IsMenuLoading(void); +s16 HandleMenuInput(void); +void RemoveMenu(void); +bool8 MultiMove_Init(void); +void MultiMove_Free(void); +void MultiMove_SetFunction(u8 funcId); +bool8 MultiMove_RunFunction(void); void CreateItemIconSprites(void); -void sub_8096088(void); -void sub_80960C0(void); -bool8 sub_809610C(void); +void MoveItemFromCursorToBag(void); +void MoveHeldItemWithPartyMenu(void); +bool8 IsItemIconAnimActive(void); const u8 *GetMovingItemName(void); void InitItemInfoWindow(void); bool8 UpdateItemInfoWindowSlideIn(void); @@ -455,7 +508,7 @@ u8 GetBoxCursorPosition(void); u16 GetMovingItem(void); u8 HandleInput(void); void InitCanReleaseMonVars(void); -void InitMonPlaceChange(u8 a0); +void InitMonPlaceChange(u8 type); bool8 IsActiveItemMoving(void); bool8 IsCursorOnCloseBox(void); bool8 IsMonBeingMoved(void); @@ -474,47 +527,47 @@ void SetWallpaperForCurrentBox(u8 wallpaper); bool8 TryStorePartyMonInBox(u8 boxId); void InitMenu(void); void SetMenuText(u8 textId); -void sub_8095C84(u8 cursorArea, u8 cursorPos); -void sub_8095E2C(u16 itemId); +void TryLoadItemIconAtPos(u8 cursorArea, u8 cursorPos); +void InitItemIconInCursor(u16 itemId); u8 GetBoxWallpaper(u8 boxId); bool8 IsCursorOnBoxTitle(void); bool8 IsCursorInBox(void); -void sub_808FFAC(void); +void InitMonIconFields(void); struct Sprite *CreateMonIconSprite(u16 species, u32 pid, s16 x, s16 y, u8 priority, u8 subpriority); void CreatePartyMonsSprites(bool8 species); -void sub_80909F4(void); -bool8 sub_8090A60(void); -void sub_8090B98(s16 yDelta); +void CompactPartySprites(void); +u8 GetNumPartySpritesCompacting(void); +void MovePartySprites(s16 yDelta); void DestroyAllPartyMonIcons(void); -void sub_8091114(void); -bool8 sub_8091150(void); -void sub_80913DC(u8 box); -bool8 sub_809140C(void); +void DoReleaseMonComeBackAnim(void); +bool8 ResetReleaseMonSpritePtr(void); +void CreateInitBoxTask(u8 boxId); +bool8 IsInitBoxActive(void); void AnimateBoxScrollArrows(bool8 species); void CreateMovingMonIcon(void); -void sub_8090E08(u8 boxId, u8 cursorPos); -bool8 sub_8090E74(void); -void sub_8090CC0(u8 cursorArea, u8 cursorPos); -void sub_8090D58(u8 cursorArea, u8 cursorPos); +void SetShiftMonSpritePtr(u8 boxId, u8 position); +bool8 ShiftMons(void); +void SetMovingMonSprite(u8 cursorArea, u8 cursorPos); +void SetPlacedMonSprite(u8 cursorArea, u8 cursorPos); void DestroyPartyMonIcon(u8 partyId); void DestroyMovingMonIcon(void); s16 GetFirstFreeBoxSpot(u8 boxId); -void sub_80901EC(u8 boxPosition); -void sub_8090FC4(u8 mode, u8 position); -bool8 sub_8091084(void); -void sub_80910CC(void); +void CreateBoxMonIconAtPos(u8 boxPosition); +void DoReleaseMonAnim(u8 mode, u8 position); +bool8 TryHideReleaseMonSprite(void); +void DestroyReleaseMonIcon(void); u8 CountPartyMons(void); u8 CountPartyAliveNonEggMonsExcept(u8 slotToIgnore); -s8 sub_8094E50(u8 a0); -bool8 sub_8095474(u8 action); -u8 sub_8095AA0(void); -bool8 sub_8095ABC(void); -void sub_8095D44(u8 cursorArea, u8 cursorPos); -void sub_8094CD4(u8 *arg0, u8 *arg1); -void sub_8094D40(void); -void sub_8092BAC(bool8 arg0); +s8 GetMenuItemTextId(u8 menuIndex); +bool8 MultiMove_TryMoveGroup(u8 dir); +u8 MultiMove_GetOriginPosition(void); +bool8 MultiMove_CanPlaceSelection(void); +void TryHideItemIconAtPos(u8 cursorArea, u8 cursorPos); +void GetCursorBoxColumnAndRow(u8 *column, u8 *row); +void SetCursorPriorityTo1(void); +void InitMultiMonPlaceChange(bool8 moveCursorUp); void DestroyBoxMonIconAtPosition(u8 boxPosition); void SetBoxMonIconObjMode(u8 cursorPos, u8 objMode); void SetPartyMonIconObjMode(u8 cursorPos, u8 objMode); diff --git a/include/tilemap_util.h b/include/tilemap_util.h new file mode 100644 index 000000000..b8388c6f5 --- /dev/null +++ b/include/tilemap_util.h @@ -0,0 +1,12 @@ +#ifndef GUARD_TILEMAP_UTIL_H +#define GUARD_TILEMAP_UTIL_H + +void TilemapUtil_Init(u8 numTilemapIds); +void TilemapUtil_Free(void); +void TilemapUtil_SetTilemap(u8 tilemapId, u8 bg, const void *tilemap, u16 width, u16 height); +void TilemapUtil_SetPos(u8 tilemapId, u16 destX, u16 destY); +void TilemapUtil_SetRect(u8 tilemapId, u16 x, u16 y, u16 width, u16 height); +void TilemapUtil_Move(u8 tilemapId, u8 mode, s8 param); +void TilemapUtil_Update(u8 tilemapId); + +#endif //GUARD_TILEMAP_UTIL_H diff --git a/ld_script.txt b/ld_script.txt index 21538a7ba..a97a5ac2a 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -130,13 +130,11 @@ SECTIONS { src/pokedex.o(.text); src/trainer_card.o(.text); src/pokemon_storage_system.o(.text); - src/pokemon_storage_system_2.o(.text); - src/pokemon_storage_system_3.o(.text); - src/pokemon_storage_system_4.o(.text); - src/pokemon_storage_system_5.o(.text); - src/pokemon_storage_system_6.o(.text); - src/pokemon_storage_system_7.o(.text); - src/pokemon_storage_system_8.o(.text); + src/pokemon_storage_system_menu.o(.text); + src/pokemon_storage_system_tasks.o(.text); + src/pokemon_storage_system_graphics.o(.text); + src/pokemon_storage_system_data.o(.text); + src/pokemon_storage_system_misc.o(.text); src/pokemon_icon.o(.text); src/script_movement.o(.text); src/fldeff_cut.o(.text); @@ -228,7 +226,7 @@ SECTIONS { src/evolution_graphics.o(.text); src/fldeff_teleport.o(.text); src/new_menu_helpers.o(.text); - src/box_party_pokemon_dropdown.o(.text); + src/tilemap_util.o(.text); src/save_menu_util.o(.text); src/map_preview_screen.o(.text); src/link_rfu_2.o(.text); @@ -452,13 +450,11 @@ SECTIONS { src/field_effect.o(.rodata); src/option_menu.o(.rodata); src/trainer_card.o(.rodata); - src/pokemon_storage_system_2.o(.rodata); - src/pokemon_storage_system_3.o(.rodata); - src/pokemon_storage_system_4.o(.rodata); - src/pokemon_storage_system_5.o(.rodata); - src/pokemon_storage_system_6.o(.rodata); - src/pokemon_storage_system_7.o(.rodata); - src/pokemon_storage_system_8.o(.rodata); + src/pokemon_storage_system_menu.o(.rodata); + src/pokemon_storage_system_tasks.o(.rodata); + src/pokemon_storage_system_graphics.o(.rodata); + src/pokemon_storage_system_data.o(.rodata); + src/pokemon_storage_system_misc.o(.rodata); src/pokemon_icon.o(.rodata); src/fldeff_cut.o(.rodata); src/map_name_popup.o(.rodata); @@ -524,7 +520,7 @@ SECTIONS { src/clear_save_data_screen.o(.rodata); src/evolution_graphics.o(.rodata); src/new_menu_helpers.o(.rodata); - src/box_party_pokemon_dropdown.o(.rodata); + src/tilemap_util.o(.rodata); src/map_preview_screen.o(.rodata); src/link_rfu_2.o(.rodata); src/link_rfu_3.o(.rodata); diff --git a/src/berry_pouch.c b/src/berry_pouch.c index 80fa333f7..576bc8d4f 100644 --- a/src/berry_pouch.c +++ b/src/berry_pouch.c @@ -1258,7 +1258,7 @@ static void Task_ContextMenu_FromPartyGiveMenu(u8 taskId) static void Task_ContextMenu_FromPokemonPC(u8 taskId) { - sResources->exitCallback = Cb2_ReturnToPSS; + sResources->exitCallback = CB2_ReturnToPokeStorage; gTasks[taskId].func = BerryPouch_StartFadeToExitCallback; } diff --git a/src/box_party_pokemon_dropdown.c b/src/box_party_pokemon_dropdown.c deleted file mode 100644 index 09767f3d9..000000000 --- a/src/box_party_pokemon_dropdown.c +++ /dev/null @@ -1,212 +0,0 @@ -#include "global.h" -#include "bg.h" -#include "box_party_pokemon_dropdown.h" -#include "malloc.h" - -struct BPPD_MapRect -{ - s16 destX; - s16 destY; - u16 width; - u16 height; - s16 destX2; - s16 destY2; -}; - -struct BPPD_Struct -{ - struct BPPD_MapRect map1Rect; - struct BPPD_MapRect map2Rect; - const void *src1; - const void *src2; - u16 src1Height; - u16 src1Width; - u16 src2Width; - u16 src2Height; - u16 bytesPerRow; - u8 mapSize; - u8 bgId; - bool8 bgUpdateScheduled; -}; - -static EWRAM_DATA struct BPPD_Struct * sBoxPartyPokemonDropdownPtr = NULL; -static EWRAM_DATA u16 sBoxPartyPokemonDropdownCount = 0; - -static void PushMap1(u8 idx); -static void PushMap2(u8 idx); - -static const struct { - u16 height; - u16 width; -} sBGdims[2][4] = { - { - {0x0100, 0x0100}, - {0x0200, 0x0100}, - {0x0100, 0x0200}, - {0x0200, 0x0200} - }, { - {0x0080, 0x0080}, - {0x0100, 0x0100}, - {0x0200, 0x0200}, - {0x0400, 0x0400} - } -}; - -void AllocBoxPartyPokemonDropdowns(u8 num) -{ - u16 i; - sBoxPartyPokemonDropdownPtr = Alloc(num * sizeof(struct BPPD_Struct)); - sBoxPartyPokemonDropdownCount = sBoxPartyPokemonDropdownPtr == NULL ? 0 : num; - for (i = 0; i < sBoxPartyPokemonDropdownCount; i++) - { - sBoxPartyPokemonDropdownPtr[i].src1 = NULL; - sBoxPartyPokemonDropdownPtr[i].bgUpdateScheduled = FALSE; - } -} - -void FreeBoxPartyPokemonDropdowns(void) -{ - Free(sBoxPartyPokemonDropdownPtr); -} - -void CopyAllBoxPartyPokemonDropdownsToVram(void) -{ - int i; - - for (i = 0; i < sBoxPartyPokemonDropdownCount; i++) - { - if (sBoxPartyPokemonDropdownPtr[i].bgUpdateScheduled == TRUE) - CopyBoxPartyPokemonDropdownToBgTilemapBuffer(i); - } -} - -void SetBoxPartyPokemonDropdownMap2(u8 idx, u8 bgId, const void *src, u16 width, u16 height) -{ - u16 screenSize; - u16 bgType; - - if (idx < sBoxPartyPokemonDropdownCount) - { - sBoxPartyPokemonDropdownPtr[idx].src1 = NULL; - sBoxPartyPokemonDropdownPtr[idx].src2 = src; - sBoxPartyPokemonDropdownPtr[idx].bgId = bgId; - sBoxPartyPokemonDropdownPtr[idx].src2Width = width; - sBoxPartyPokemonDropdownPtr[idx].src2Height = height; - screenSize = GetBgAttribute(bgId, BG_ATTR_SCREENSIZE); - bgType = GetBgAttribute(bgId, BG_ATTR_BGTYPE); - sBoxPartyPokemonDropdownPtr[idx].src1Height = sBGdims[bgType][screenSize].height; - sBoxPartyPokemonDropdownPtr[idx].src1Width = sBGdims[bgType][screenSize].width; - if (bgType != 0) - sBoxPartyPokemonDropdownPtr[idx].mapSize = 1; - else - sBoxPartyPokemonDropdownPtr[idx].mapSize = 2; - sBoxPartyPokemonDropdownPtr[idx].bytesPerRow = width * sBoxPartyPokemonDropdownPtr[idx].mapSize; - sBoxPartyPokemonDropdownPtr[idx].map2Rect.width = width; - sBoxPartyPokemonDropdownPtr[idx].map2Rect.height = height; - sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX = 0; - sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY = 0; - sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX2 = 0; - sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY2 = 0; - sBoxPartyPokemonDropdownPtr[idx].map1Rect = sBoxPartyPokemonDropdownPtr[idx].map2Rect; - sBoxPartyPokemonDropdownPtr[idx].bgUpdateScheduled = TRUE; - } -} - -void SetBoxPartyPokemonDropdownMap1Tiles(u8 idx, const void *src) -{ - if (idx < sBoxPartyPokemonDropdownCount) - { - sBoxPartyPokemonDropdownPtr[idx].src1 = src; - sBoxPartyPokemonDropdownPtr[idx].bgUpdateScheduled = TRUE; - } -} - -void SetBoxPartyPokemonDropdownMap2Pos(u8 idx, u16 x, u16 y) -{ - if (idx < sBoxPartyPokemonDropdownCount) - { - sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX2 = x; - sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY2 = y; - sBoxPartyPokemonDropdownPtr[idx].bgUpdateScheduled = TRUE; - } -} - -void SetBoxPartyPokemonDropdownMap2Rect(u8 idx, u16 x, u16 y, u16 width, u16 height) -{ - if (idx < sBoxPartyPokemonDropdownCount) - { - sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX = x; - sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY = y; - sBoxPartyPokemonDropdownPtr[idx].map2Rect.width = width; - sBoxPartyPokemonDropdownPtr[idx].map2Rect.height = height; - sBoxPartyPokemonDropdownPtr[idx].bgUpdateScheduled = TRUE; - } -} - -void AdjustBoxPartyPokemonDropdownPos(u8 idx, u8 op, s8 param) -{ - if (idx < sBoxPartyPokemonDropdownCount) - { - switch (op) - { - case BPPD_MOVE_INNER_LEFT: - sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX2 += param; - sBoxPartyPokemonDropdownPtr[idx].map2Rect.width -= param; - break; - case BPPD_MOVE_OUTER_LEFT: - sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX += param; - sBoxPartyPokemonDropdownPtr[idx].map2Rect.width += param; - break; - case BPPD_MOVE_INNER_TOP: - sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY2 += param; - sBoxPartyPokemonDropdownPtr[idx].map2Rect.height -= param; - break; - case BPPD_MOVE_OUTER_TOP: - sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY -= param; - sBoxPartyPokemonDropdownPtr[idx].map2Rect.height += param; - break; - case BPPD_MOVE_INNER_X: - sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX2 += param; - break; - case BPPD_MOVE_INNER_Y: - sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY2 += param; - break; - } - sBoxPartyPokemonDropdownPtr[idx].bgUpdateScheduled = TRUE; - } -} - -void CopyBoxPartyPokemonDropdownToBgTilemapBuffer(u8 idx) -{ - if (idx < sBoxPartyPokemonDropdownCount) - { - if (sBoxPartyPokemonDropdownPtr[idx].src1 != NULL) - PushMap1(idx); - PushMap2(idx); - sBoxPartyPokemonDropdownPtr[idx].map1Rect = sBoxPartyPokemonDropdownPtr[idx].map2Rect; - } -} - -static void PushMap1(u8 idx) -{ - int i; - int run = sBoxPartyPokemonDropdownPtr[idx].mapSize * sBoxPartyPokemonDropdownPtr[idx].src1Height; - const void *addr = sBoxPartyPokemonDropdownPtr[idx].src1 + run * sBoxPartyPokemonDropdownPtr[idx].map1Rect.destY2 + sBoxPartyPokemonDropdownPtr[idx].map1Rect.destX2 * sBoxPartyPokemonDropdownPtr[idx].mapSize; - for (i = 0; i < sBoxPartyPokemonDropdownPtr[idx].map1Rect.height; i++) - { - CopyToBgTilemapBufferRect(sBoxPartyPokemonDropdownPtr[idx].bgId, addr, sBoxPartyPokemonDropdownPtr[idx].map1Rect.destX2, sBoxPartyPokemonDropdownPtr[idx].map1Rect.destY2 + i, sBoxPartyPokemonDropdownPtr[idx].map1Rect.width, 1); - addr += run; - } -} - -static void PushMap2(u8 idx) -{ - int i; - int run = sBoxPartyPokemonDropdownPtr[idx].mapSize * sBoxPartyPokemonDropdownPtr[idx].src2Width; - const void *addr = sBoxPartyPokemonDropdownPtr[idx].src2 + run * sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY + sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX * sBoxPartyPokemonDropdownPtr[idx].mapSize; - for (i = 0; i < sBoxPartyPokemonDropdownPtr[idx].map2Rect.height; i++) - { - CopyToBgTilemapBufferRect(sBoxPartyPokemonDropdownPtr[idx].bgId, addr, sBoxPartyPokemonDropdownPtr[idx].map2Rect.destX2, sBoxPartyPokemonDropdownPtr[idx].map2Rect.destY2 + i, sBoxPartyPokemonDropdownPtr[idx].map2Rect.width, 1); - addr += run; - } -} diff --git a/src/graphics.c b/src/graphics.c index cf3f6bd37..d677561de 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1251,13 +1251,11 @@ const u32 gPokeSummary_StatusAilmentIconTiles[] = INCBIN_U32("graphics/interface const u16 gDexScreen_TopMenuIconPals_AtoZ[] = INCBIN_U16("graphics/pokedex/cat_icon_abc.gbapal"); const u32 gDexScreen_TopMenuIconTiles_AtoZ[] = INCBIN_U32("graphics/pokedex/cat_icon_abc.4bpp.lz"); -const u16 gPSSMenu_Pal[] = INCBIN_U16("graphics/interface/box_tiles_pal1.gbapal"); -const u16 gUnknown_8E9C3F8[] = INCBIN_U16("graphics/interface/box_tiles_pal2.gbapal"); -const u16 gUnknown_8E9C418[] = INCBIN_U16("graphics/interface/box_tiles_pal3.gbapal"); -const u32 gPSSMenu_Gfx[] = INCBIN_U32("graphics/interface/box_tiles.4bpp.lz"); - -const u32 gUnknown_8E9CAEC[] = INCBIN_U32("graphics/unknown/unknown_E9CAEC.bin.lz"); - +const u16 gPokeStoragePartyMenu_Pal[] = INCBIN_U16("graphics/pokemon_storage/party_menu.gbapal"); +const u16 gPokeStorageInterface_Pal[] = INCBIN_U16("graphics/pokemon_storage/interface.gbapal"); +const u16 gPokeStorageInterface_NoDisplayMon_Pal[] = INCBIN_U16("graphics/pokemon_storage/interface_no_display_mon.gbapal"); +const u32 gPokeStorageMenu_Gfx[] = INCBIN_U32("graphics/pokemon_storage/menu.4bpp.lz"); +const u32 gPokeStoragePartyMenu_Tilemap[] = INCBIN_U32("graphics/pokemon_storage/party_menu.bin.lz"); const u16 gMonMarkingsMenu_Pal[] = INCBIN_U16("graphics/misc/markings2.gbapal"); const u16 gMonMarkingsMenu_Gfx[] = INCBIN_U16("graphics/misc/markings2.4bpp"); diff --git a/src/item_menu.c b/src/item_menu.c index bf51d2f31..f04ac59d5 100644 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -1784,7 +1784,7 @@ static void GoToBerryPouch_PCBox(void) static void ReturnToBagMenuFromSubmenu_PCBox(void) { - GoToBagMenu(ITEMMENULOCATION_PCBOX, OPEN_BAG_LAST, Cb2_ReturnToPSS); + GoToBagMenu(ITEMMENULOCATION_PCBOX, OPEN_BAG_LAST, CB2_ReturnToPokeStorage); } static void Task_ItemContext_Sell(u8 taskId) diff --git a/src/pokemon_storage_system_3.c b/src/pokemon_storage_system_3.c deleted file mode 100644 index 46212d06c..000000000 --- a/src/pokemon_storage_system_3.c +++ /dev/null @@ -1,2777 +0,0 @@ -#include "global.h" -#include "gflib.h" -#include "box_party_pokemon_dropdown.h" -#include "data.h" -#include "decompress.h" -#include "dynamic_placeholder_text_util.h" -#include "event_data.h" -#include "graphics.h" -#include "help_system.h" -#include "item.h" -#include "item_menu.h" -#include "mail_data.h" -#include "menu.h" -#include "naming_screen.h" -#include "new_menu_helpers.h" -#include "pc_screen_effect.h" -#include "pokemon_icon.h" -#include "pokemon_storage_system_internal.h" -#include "pokemon_summary_screen.h" -#include "quest_log.h" -#include "strings.h" -#include "task.h" -#include "text_window.h" -#include "trig.h" -#include "constants/items.h" -#include "constants/help_system.h" -#include "constants/songs.h" - -EWRAM_DATA struct PokemonStorageSystemData *gPSSData = NULL; -static EWRAM_DATA bool8 sInPartyMenu = 0; -static EWRAM_DATA u8 sCurrentBoxOption = 0; -static EWRAM_DATA u8 gUnknown_20397B6 = 0; -static EWRAM_DATA u8 sWhichToReshow = 0; -static EWRAM_DATA u8 sLastUsedBox = 0; -static EWRAM_DATA u16 gUnknown_20397BA = ITEM_NONE; - -static void Cb_InitPSS(u8 taskId); -static void Cb_ShowPSS(u8 taskId); -static void Cb_ReshowPSS(u8 taskId); -static void Cb_MainPSS(u8 taskId); -static void Cb_ShowPartyPokemon(u8 taskId); -static void Cb_HidePartyPokemon(u8 taskId); -static void Cb_OnSelectedMon(u8 taskId); -static void Cb_MoveMon(u8 taskId); -static void Cb_PlaceMon(u8 taskId); -static void Cb_ShiftMon(u8 taskId); -static void Cb_WithdrawMon(u8 taskId); -static void Cb_DepositMenu(u8 taskId); -static void Cb_ReleaseMon(u8 taskId); -static void Cb_ShowMarkMenu(u8 taskId); -static void Cb_TakeItemForMoving(u8 taskId); -static void Cb_GiveMovingItemToMon(u8 taskId); -static void Cb_ItemToBag(u8 taskId); -static void Cb_SwitchSelectedItem(u8 taskId); -static void Cb_ShowItemInfo(u8 taskId); -static void Cb_HandleMovingMonFromParty(u8 taskId); -static void Cb_PrintCantStoreMail(u8 taskId); -static void Cb_HandleBoxOptions(u8 taskId); -static void Cb_HandleWallpapers(u8 taskId); -static void Cb_JumpBox(u8 taskId); -static void Cb_NameBox(u8 taskId); -static void Cb_ShowMonSummary(u8 taskId); -static void Cb_GiveItemFromBag(u8 taskId); -static void Cb_OnCloseBoxPressed(u8 taskId); -static void Cb_OnBPressed(u8 taskId); -static void Cb_ChangeScreen(u8 taskId); -static void GiveChosenBagItem(void); -static void FreePSSData(void); -static void SetScrollingBackground(void); -static void ScrollBackground(void); -static void LoadPSSMenuGfx(void); -static bool8 InitPSSWindows(void); -static void LoadWaveformSpritePalette(void); -static void sub_808F078(void); -static void PSS_CreateMonMarkingSprite(void); -static void CreateWaveformSprites(void); -static void RefreshCursorMonData(void); -static void BoxSetMosaic(void); -static void SpriteCB_CursorMon_Mosaic(struct Sprite *sprite); -static bool8 BoxGetMosaic(void); -static void LoadCursorMonSprite(void); -static void LoadCursorMonGfx(u16 species, u32 pid); -static void PrintCursorMonInfo(void); -static void sub_808F5E8(void); -static void sub_808F68C(void); -static void SetUpHidePartyMenu(void); -static bool8 HidePartyMenu(void); -static void sub_808F90C(bool8 species); -static void sub_808F948(void); -static void sub_808F974(void); -static void sub_808F99C(void); -static void sub_808F9FC(void); -static void sub_808FA30(u8 pos, bool8 isPartyMon); -static void sub_808FAA8(void); -static void SetUpDoShowPartyMenu(void); -static bool8 DoShowPartyMenu(void); -static void sub_808FB68(void); -static void PrintStorageActionText(u8 textId); -static void ShowYesNoWindow(s8 species); -static void ClearBottomWindow(void); -static void AddWallpaperSetsMenu(void); -static void AddWallpapersMenu(u8 wallpaperSet); -static void sub_808FDFC(void); -static void sub_808FE54(u8 species); -static void sub_808FF70(void); - -static const u32 sPokemonStorageScrollingBGTileset[] = INCBIN_U32("graphics/interface/pss_unk_83CE438.4bpp.lz"); -static const u32 sPokemonStorageScrollingBGTilemap[] = INCBIN_U32("graphics/interface/pss_unk_83CE4D0.bin.lz"); -static const u16 sPokemonStorageScrollingBGPalette[] = INCBIN_U16("graphics/interface/pss_unk_83CE5DC.gbapal"); -static const u32 gUnknown_83CE5FC[] = INCBIN_U32("graphics/interface/pss_unk_83CE5FC.bin.lz"); - -static const u16 gUnknown_83CE6F8[] = { - 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0x0106, 0x0107, 0x0108, - 0x0111, 0x0112, 0x0113, 0x0114, 0x0115, 0x0116, 0x0117, 0x0118, - 0x2101, 0x2102, 0x2103, 0x2104, 0x2105, 0x2106, 0x2107, 0x2108, - 0x2111, 0x2112, 0x2113, 0x2114, 0x2115, 0x2116, 0x2117, 0x2118, -}; - -static const u16 gUnknown_83CE738[] = INCBIN_U16("graphics/interface/pss_unk_83CE738.gbapal"); -static const u16 gUnknown_83CE758[] = INCBIN_U16("graphics/interface/pss_unk_83CE758.gbapal"); - -static const u16 gUnknown_83CE778[] = { - 0x014c, 0x014d, 0x014e, 0x014f, 0x0170, 0x0171, 0x0172, 0x0173, 0x0174, - 0x015c, 0x015d, 0x015e, 0x015f, 0x0180, 0x0181, 0x0182, 0x0183, 0x0184, - 0x0175, 0x0176, 0x0177, 0x0178, 0x0179, 0x017a, 0x017b, 0x017c, 0x017d, - 0x0185, 0x0186, 0x0187, 0x0188, 0x0189, 0x018a, 0x018b, 0x018c, 0x018d, -}; - -static const u16 gUnknown_83CE7C0[] = { - 0x1140, 0x1141, 0x1141, 0x1142, - 0x1150, 0x1151, 0x1151, 0x1152, - 0x1160, 0x1161, 0x1161, 0x1162, -}; - -static const u16 gUnknown_83CE7D8[] = { - 0x1143, 0x1144, 0x1144, 0x1145, - 0x1153, 0x1154, 0x1154, 0x1155, - 0x1163, 0x1164, 0x1164, 0x1165, -}; - -static const u16 gUnknown_83CE7F0[] = INCBIN_U16("graphics/interface/pss_unk_83CE810.gbapal"); -static const u16 gUnknown_83CE810[] = INCBIN_U16("graphics/interface/pss_unk_83CE810.4bpp"); -static const u16 gUnknown_83CE9D0[] = INCBIN_U16("graphics/interface/pss_unk_83CE9D0.gbapal"); -static const u16 gUnknown_83CEA10[] = INCBIN_U16("graphics/interface/pss_unk_83CEA10.gbapal"); - -static const struct WindowTemplate gUnknown_83CEA30[] = { - { - .bg = 1, - .tilemapLeft = 0, - .tilemapTop = 11, - .width = 9, - .height = 7, - .paletteNum = 3, - .baseBlock = 0x0c0 - }, { - .bg = 0, - .tilemapLeft = 11, - .tilemapTop = 17, - .width = 18, - .height = 2, - .paletteNum = 13, - .baseBlock = 0x014 - }, { - .bg = 0, - .tilemapLeft = 0, - .tilemapTop = 12, - .width = 25, - .height = 8, - .paletteNum = 15, - .baseBlock = 0x014 - }, DUMMY_WIN_TEMPLATE -}; - -static const struct BgTemplate gUnknown_83CEA50[] = { - { - .bg = 0, - .charBaseIndex = 0, - .mapBaseIndex = 29, - .screenSize = 0, - .paletteMode = 0, - .priority = 0, - .baseTile = 0x000 - }, { - .bg = 1, - .charBaseIndex = 1, - .mapBaseIndex = 30, - .screenSize = 0, - .paletteMode = 0, - .priority = 1, - .baseTile = 0x100 - }, { - .bg = 2, - .charBaseIndex = 2, - .mapBaseIndex = 27, - .screenSize = 1, - .paletteMode = 0, - .priority = 2, - .baseTile = 0x000 - }, { - .bg = 3, - .charBaseIndex = 3, - .mapBaseIndex = 31, - .screenSize = 0, - .paletteMode = 0, - .priority = 3, - .baseTile = 0x000 - } -}; - -static const struct SpritePalette sWaveformSpritePalette = { - gUnknown_83CE7F0, TAG_PAL_WAVEFORM -}; - -static const struct SpriteSheet sWaveformSpriteSheet = { - gUnknown_83CE810, 0x01c0, TAG_TILE_WAVEFORM -}; - -static const struct OamData gUnknown_83CEB88; - -static const struct SpriteTemplate sSpriteTemplate_CursorMon = { - .tileTag = TAG_TILE_2, - .paletteTag = TAG_PAL_DAC6, - .oam = &gUnknown_83CEB88, - .anims = gDummySpriteAnimTable, - .images = NULL, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = SpriteCallbackDummy -}; - -static const struct StorageAction sPCStorageActionTexts[] = { - [PC_TEXT_EXIT_BOX] = {gText_ExitFromBox, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_WHAT_YOU_DO] = {gText_WhatDoYouWantToDo, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_PICK_A_THEME] = {gText_PleasePickATheme, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_PICK_A_WALLPAPER] = {gText_PickTheWallpaper, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_IS_SELECTED] = {gText_PkmnIsSelected, PC_TEXT_FMT_MON_NAME_1}, - [PC_TEXT_JUMP_TO_WHICH_BOX] = {gText_JumpToWhichBox, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_DEPOSIT_IN_WHICH_BOX] = {gText_DepositInWhichBox, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_WAS_DEPOSITED] = {gText_PkmnWasDeposited, PC_TEXT_FMT_MON_NAME_1}, - [PC_TEXT_BOX_IS_FULL] = {gText_BoxIsFull2, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_RELEASE_POKE] = {gText_ReleaseThisPokemon, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_WAS_RELEASED] = {gText_PkmnWasReleased, PC_TEXT_FMT_MON_NAME_4}, - [PC_TEXT_BYE_BYE] = {gText_ByeByePkmn, PC_TEXT_FMT_MON_NAME_6}, - [PC_TEXT_MARK_POKE] = {gText_MarkYourPkmn, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_LAST_POKE] = {gText_ThatsYourLastPkmn, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_PARTY_FULL] = {gText_YourPartysFull, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_HOLDING_POKE] = {gText_YoureHoldingAPkmn, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_WHICH_ONE_WILL_TAKE] = {gText_WhichOneWillYouTake, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_CANT_RELEASE_EGG] = {gText_YouCantReleaseAnEgg, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_CONTINUE_BOX] = {gText_ContinueBoxOperations, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_CAME_BACK] = {gText_PkmnCameBack, PC_TEXT_FMT_MON_NAME_1}, - [PC_TEXT_WORRIED] = {gText_WasItWorriedAboutYou, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_SURPRISE] = {gText_FourEllipsesExclamation, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_PLEASE_REMOVE_MAIL] = {gText_PleaseRemoveTheMail, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_IS_SELECTED2] = {gText_PkmnIsSelected, PC_TEXT_FMT_ITEM_NAME}, - [PC_TEXT_GIVE_TO_MON] = {gText_GiveToAPkmn, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_PLACED_IN_BAG] = {gText_PlacedItemInBag, PC_TEXT_FMT_ITEM_NAME}, - [PC_TEXT_BAG_FULL] = {gText_BagIsFull2, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_PUT_IN_BAG] = {gText_PutItemInBag, PC_TEXT_FMT_NORMAL}, - [PC_TEXT_ITEM_IS_HELD] = {gText_ItemIsNowHeld, PC_TEXT_FMT_ITEM_NAME}, - [PC_TEXT_CHANGED_TO_ITEM] = {gText_ChangedToNewItem, PC_TEXT_FMT_ITEM_NAME}, - [PC_TEXT_CANT_STORE_MAIL] = {gText_MailCantBeStored, PC_TEXT_FMT_NORMAL}, -}; - -// Yes/No menu -static const struct WindowTemplate sYesNoWindowTemplate = { - .bg = 0, - .tilemapLeft = 24, - .tilemapTop = 11, - .width = 5, - .height = 4, - .paletteNum = 15, - .baseBlock = 0x05c -}; - -static const struct OamData gUnknown_83CEB88 = { - .y = 0, - .affineMode = ST_OAM_AFFINE_OFF, - .objMode = ST_OAM_OBJ_NORMAL, - .mosaic = FALSE, - .bpp = ST_OAM_4BPP, - .shape = SPRITE_SHAPE(64x64), - .x = 0, - .matrixNum = 0, - .size = SPRITE_SIZE(64x64), - .tileNum = 0x000, - .priority = 0, - .paletteNum = 0 -}; - -// Waveform - -static const struct OamData gUnknown_83CEB90 = { - .y = 0, - .affineMode = ST_OAM_AFFINE_OFF, - .objMode = ST_OAM_OBJ_NORMAL, - .mosaic = FALSE, - .bpp = ST_OAM_4BPP, - .shape = SPRITE_SHAPE(16x8), - .x = 0, - .matrixNum = 0, - .size = SPRITE_SIZE(16x8), - .tileNum = 0x000, - .priority = 0, - .paletteNum = 0 -}; - -static const union AnimCmd gUnknown_83CEB98[] = { - ANIMCMD_FRAME(0, 5), - ANIMCMD_END -}; - -static const union AnimCmd gUnknown_83CEBA0[] = { - ANIMCMD_FRAME(2, 8), - ANIMCMD_FRAME(4, 8), - ANIMCMD_FRAME(6, 8), - ANIMCMD_JUMP(0) -}; - -static const union AnimCmd gUnknown_83CEBB0[] = { - ANIMCMD_FRAME(8, 5), - ANIMCMD_END -}; - -static const union AnimCmd gUnknown_83CEBB8[] = { - ANIMCMD_FRAME(10, 8), - ANIMCMD_FRAME(4, 8), - ANIMCMD_FRAME(12, 8), - ANIMCMD_JUMP(0) -}; - -static const union AnimCmd *const gUnknown_83CEBC8[] = { - gUnknown_83CEB98, - gUnknown_83CEBA0, - gUnknown_83CEBB0, - gUnknown_83CEBB8 -}; - -static const struct SpriteTemplate sSpriteTemplate_Waveform = { - .tileTag = TAG_TILE_WAVEFORM, - .paletteTag = TAG_PAL_WAVEFORM, - .oam = &gUnknown_83CEB90, - .anims = gUnknown_83CEBC8, - .images = NULL, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = SpriteCallbackDummy, -}; - -static void VblankCb_PSS(void) -{ - LoadOam(); - ProcessSpriteCopyRequests(); - UnkUtil_Run(); - TransferPlttBuffer(); - SetGpuReg(REG_OFFSET_BG2HOFS, gPSSData->bg2_X); -} - -static void Cb2_PSS(void) -{ - RunTasks(); - DoScheduledBgTilemapCopiesToVram(); - ScrollBackground(); - sub_808F99C(); - AnimateSprites(); - BuildOamBuffer(); -} - -void Cb2_EnterPSS(u8 boxOption) -{ - ResetTasks(); - sCurrentBoxOption = boxOption; - gPSSData = Alloc(sizeof(struct PokemonStorageSystemData)); - if (gPSSData == NULL) - SetMainCallback2(CB2_ExitPokeStorage); - else - { - gPSSData->boxOption = boxOption; - gPSSData->isReshowingPSS = FALSE; - gUnknown_20397BA = 0; - gPSSData->state = 0; - gPSSData->taskId = CreateTask(Cb_InitPSS, 3); - SetHelpContext(HELPCONTEXT_BILLS_PC); - sLastUsedBox = StorageGetCurrentBox(); - SetMainCallback2(Cb2_PSS); - } -} - -void Cb2_ReturnToPSS(void) -{ - ResetTasks(); - gPSSData = Alloc(sizeof(struct PokemonStorageSystemData)); - if (gPSSData == NULL) - SetMainCallback2(CB2_ExitPokeStorage); - else - { - gPSSData->boxOption = sCurrentBoxOption; - gPSSData->isReshowingPSS = TRUE; - gPSSData->state = 0; - gPSSData->taskId = CreateTask(Cb_InitPSS, 3); - SetHelpContext(HELPCONTEXT_BILLS_PC); - SetMainCallback2(Cb2_PSS); - } -} - -static void ResetAllBgCoords(void) -{ - SetGpuReg(REG_OFFSET_BG0HOFS, 0); - SetGpuReg(REG_OFFSET_BG0VOFS, 0); - SetGpuReg(REG_OFFSET_BG1HOFS, 0); - SetGpuReg(REG_OFFSET_BG1VOFS, 0); - SetGpuReg(REG_OFFSET_BG2HOFS, 0); - SetGpuReg(REG_OFFSET_BG2VOFS, 0); - SetGpuReg(REG_OFFSET_BG3HOFS, 0); - SetGpuReg(REG_OFFSET_BG3VOFS, 0); -} - -static void sub_808CF10(void) -{ - ResetPaletteFade(); - ResetSpriteData(); - FreeSpriteTileRanges(); - FreeAllSpritePalettes(); - ClearDma3Requests(); - gReservedSpriteTileCount = 0x280; - UnkUtil_Init(&gPSSData->unkUtil, gPSSData->unkUtilData, 8); - gKeyRepeatStartDelay = 20; - ClearScheduledBgCopiesToVram(); - AllocBoxPartyPokemonDropdowns(3); - SetBoxPartyPokemonDropdownMap2(0, 1, gUnknown_83CE6F8, 8, 4); - SetBoxPartyPokemonDropdownMap2Pos(0, 1, 0); - gPSSData->closeBoxFlashing = FALSE; -} - -static void sub_808CF94(void) -{ - sub_8092B50(); - sInPartyMenu = gPSSData->boxOption == OPTION_DEPOSIT; - gUnknown_20397B6 = 0; -} - -static void sub_808CFC4(void) -{ - if (gPSSData->boxOption == OPTION_MOVE_ITEMS) - { - SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT2_ALL); - SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(7, 11)); - } - SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG_ALL_ON | DISPCNT_OBJ_1D_MAP); -} - -static void SetPSSCallback(TaskFunc newFunc) -{ - gTasks[gPSSData->taskId].func = newFunc; - gPSSData->state = 0; -} - -static void Cb_InitPSS(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - SetVBlankCallback(NULL); - SetGpuReg(REG_OFFSET_DISPCNT, 0); - sub_808CF10(); - if (gPSSData->isReshowingPSS) - { - switch (sWhichToReshow) - { - case 1: - sub_8093660(); - break; - case 0: - sub_80937B4(); - break; - case 2: - GiveChosenBagItem(); - break; - } - } - LoadPSSMenuGfx(); - LoadWaveformSpritePalette(); - break; - case 1: - if (!InitPSSWindows()) - { - SetPSSCallback(Cb_ChangeScreen); - return; - } - break; - case 2: - PutWindowTilemap(0); - ClearWindowTilemap(1); - CpuFill32(0, (void *)VRAM, 0x200); - TextWindow_SetUserSelectedFrame(1, 0xB, 0xE0); - break; - case 3: - ResetAllBgCoords(); - if (!gPSSData->isReshowingPSS) - sub_808CF94(); - break; - case 4: - sub_808FFAC(); - if (!gPSSData->isReshowingPSS) - sub_80922C0(); - else - sub_8092340(); - break; - case 5: - if (!sub_8095050()) - { - SetPSSCallback(Cb_ChangeScreen); - return; - } - else - { - SetScrollingBackground(); - sub_808FB68(); - } - break; - case 6: - sub_808F078(); - break; - case 7: - sub_808F68C(); - break; - case 8: - sub_80913DC(StorageGetCurrentBox()); - break; - case 9: - if (sub_809140C()) - return; - - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - { - gPSSData->markMenu.baseTileTag = TAG_TILE_D; - gPSSData->markMenu.basePaletteTag = TAG_PAL_DACE; - InitMonMarkingsMenu(&gPSSData->markMenu); - BufferMonMarkingsMenuTiles(); - } - else - { - CreateItemIconSprites(); - sub_808FDFC(); - } - break; - case 10: - sub_808CFC4(); - if (!gPSSData->isReshowingPSS) - { - BlendPalettes(PALETTES_ALL, 0x10, RGB_BLACK); - SetPSSCallback(Cb_ShowPSS); - } - else - { - BlendPalettes(PALETTES_ALL, 0x10, RGB_BLACK); - SetPSSCallback(Cb_ReshowPSS); - } - SetVBlankCallback(VblankCb_PSS); - return; - default: - return; - } - - gPSSData->state++; -} - -static void Cb_ShowPSS(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - PlaySE(SE_PC_LOGIN); - BeginPCScreenEffect_TurnOn(20, 0, 1); - gPSSData->state++; - break; - case 1: - if (!IsPCScreenEffectRunning_TurnOn()) - SetPSSCallback(Cb_MainPSS); - break; - } -} - -static void Cb_ReshowPSS(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - BeginNormalPaletteFade(PALETTES_ALL, -1, 0x10, 0, RGB_BLACK); - gPSSData->state++; - break; - case 1: - if (!UpdatePaletteFade()) - { - SetPSSCallback(Cb_MainPSS); - } - break; - } -} - -static void Cb_MainPSS(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - switch (HandleInput()) - { - case 1: - PlaySE(SE_SELECT); - gPSSData->state = 1; - break; - case 5: - if (gPSSData->boxOption != OPTION_MOVE_MONS && gPSSData->boxOption != OPTION_MOVE_ITEMS) - { - PrintStorageActionText(PC_TEXT_WHICH_ONE_WILL_TAKE); - gPSSData->state = 3; - } - else - { - sub_8092B50(); - SetPSSCallback(Cb_ShowPartyPokemon); - } - break; - case 6: - if (gPSSData->boxOption == OPTION_MOVE_MONS) - { - if (IsMonBeingMoved() && ItemIsMail(gPSSData->displayMonItemId)) - gPSSData->state = 5; - else - SetPSSCallback(Cb_HidePartyPokemon); - } - else if (gPSSData->boxOption == OPTION_MOVE_ITEMS) - { - SetPSSCallback(Cb_HidePartyPokemon); - } - break; - case 4: - SetPSSCallback(Cb_OnCloseBoxPressed); - break; - case 19: - SetPSSCallback(Cb_OnBPressed); - break; - case 7: - PlaySE(SE_SELECT); - SetPSSCallback(Cb_HandleBoxOptions); - break; - case 8: - SetPSSCallback(Cb_OnSelectedMon); - break; - case 9: - PlaySE(SE_SELECT); - gPSSData->newCurrBoxId = StorageGetCurrentBox() + 1; - if (gPSSData->newCurrBoxId >= TOTAL_BOXES_COUNT) - gPSSData->newCurrBoxId = 0; - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - { - SetUpScrollToBox(gPSSData->newCurrBoxId); - gPSSData->state = 2; - } - else - { - sub_8094D60(); - gPSSData->state = 10; - } - break; - case 10: - PlaySE(SE_SELECT); - gPSSData->newCurrBoxId = StorageGetCurrentBox() - 1; - if (gPSSData->newCurrBoxId < 0) - gPSSData->newCurrBoxId = TOTAL_BOXES_COUNT - 1; - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - { - SetUpScrollToBox(gPSSData->newCurrBoxId); - gPSSData->state = 2; - } - else - { - sub_8094D60(); - gPSSData->state = 10; - } - break; - case 11: - if (!CanMovePartyMon()) - { - if (ItemIsMail(gPSSData->displayMonItemId)) - { - gPSSData->state = 5; - } - else - { - PlaySE(SE_SELECT); - SetPSSCallback(Cb_DepositMenu); - } - } - else - { - gPSSData->state = 4; - } - break; - case 13: - if (CanMovePartyMon()) - { - gPSSData->state = 4; - } - else - { - PlaySE(SE_SELECT); - SetPSSCallback(Cb_MoveMon); - } - break; - case 14: - if (!CanShiftMon()) - { - gPSSData->state = 4; - } - else - { - PlaySE(SE_SELECT); - SetPSSCallback(Cb_ShiftMon); - } - break; - case 12: - PlaySE(SE_SELECT); - SetPSSCallback(Cb_WithdrawMon); - break; - case 15: - PlaySE(SE_SELECT); - SetPSSCallback(Cb_PlaceMon); - break; - case 16: - PlaySE(SE_SELECT); - SetPSSCallback(Cb_TakeItemForMoving); - break; - case 17: - PlaySE(SE_SELECT); - SetPSSCallback(Cb_GiveMovingItemToMon); - break; - case 18: - PlaySE(SE_SELECT); - SetPSSCallback(Cb_SwitchSelectedItem); - break; - case 20: - PlaySE(SE_SELECT); - sub_80950BC(0); - gPSSData->state = 7; - break; - case 22: - sub_80950BC(1); - gPSSData->state = 8; - break; - case 21: - PlaySE(SE_SELECT); - sub_80950BC(2); - gPSSData->state = 9; - break; - case 23: - sub_80950BC(3); - gPSSData->state = 7; - break; - case 25: - PlaySE(SE_SELECT); - sub_80950BC(4); - gPSSData->state = 9; - break; - case 26: - PlaySE(SE_SELECT); - sub_808FE54(3); - sub_80950BC(5); - gPSSData->state = 7; - break; - case 24: - PlaySE(SE_FAILURE); - break; - } - break; - case 1: - if (!sub_80924A8()) - { - if (IsCursorOnCloseBox()) - sub_808F948(); - else - sub_808F974(); - - if (gPSSData->setMosaic) - BoxSetMosaic(); - gPSSData->state = 0; - } - break; - case 2: - if (!ScrollToBox()) - { - SetCurrentBox(gPSSData->newCurrBoxId); - if (!sInPartyMenu && !IsMonBeingMoved()) - { - sub_8092F54(); - BoxSetMosaic(); - } - - if (gPSSData->boxOption == OPTION_MOVE_ITEMS) - { - sub_8094D84(); - gPSSData->state = 11; - } - else - { - gPSSData->state = 0; - } - } - break; - case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - ClearBottomWindow(); - gPSSData->state = 0; - } - break; - case 4: - PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_LAST_POKE); - gPSSData->state = 6; - break; - case 5: - PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_PLEASE_REMOVE_MAIL); - gPSSData->state = 6; - break; - case 6: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); - } - break; - case 7: - if (!sub_80950D0()) - gPSSData->state = 0; - break; - case 8: - if (!sub_80950D0()) - SetPSSCallback(Cb_MoveMon); - break; - case 9: - if (!sub_80950D0()) - { - if (gPSSData->setMosaic) - BoxSetMosaic(); - gPSSData->state = 0; - } - break; - case 10: - if (!sub_809610C()) - { - SetUpScrollToBox(gPSSData->newCurrBoxId); - gPSSData->state = 2; - } - break; - case 11: - if (!sub_809610C()) - gPSSData->state = 0; - break; - } -} - -static void Cb_ShowPartyPokemon(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - SetUpDoShowPartyMenu(); - gPSSData->state++; - break; - case 1: - if (!DoShowPartyMenu()) - SetPSSCallback(Cb_MainPSS); - break; - } -} - -static void Cb_HidePartyPokemon(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - PlaySE(SE_SELECT); - SetUpHidePartyMenu(); - gPSSData->state++; - break; - case 1: - if (!HidePartyMenu()) - { - sub_8092B3C(sub_8092B70()); - gPSSData->state++; - } - break; - case 2: - if (!sub_80924A8()) - { - if (gPSSData->setMosaic) - BoxSetMosaic(); - SetPSSCallback(Cb_MainPSS); - } - break; - } -} - -static void Cb_OnSelectedMon(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - if (!BoxGetMosaic()) - { - PlaySE(SE_SELECT); - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - PrintStorageActionText(PC_TEXT_IS_SELECTED); - else if (IsActiveItemMoving() || gPSSData->displayMonItemId != 0) - PrintStorageActionText(PC_TEXT_IS_SELECTED2); - else - PrintStorageActionText(PC_TEXT_GIVE_TO_MON); - - AddMenu(); - gPSSData->state = 1; - } - break; - case 1: // debug? - if (!sub_8094F90()) - gPSSData->state = 2; - break; - case 2: - switch (sub_8094F94()) - { - case -1: - case 0: - ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); - break; - case 3: - if (CanMovePartyMon()) - { - gPSSData->state = 3; - } - else - { - PlaySE(SE_SELECT); - ClearBottomWindow(); - SetPSSCallback(Cb_MoveMon); - } - break; - case 5: - PlaySE(SE_SELECT); - ClearBottomWindow(); - SetPSSCallback(Cb_PlaceMon); - break; - case 4: - if (!CanShiftMon()) - { - gPSSData->state = 3; - } - else - { - PlaySE(SE_SELECT); - ClearBottomWindow(); - SetPSSCallback(Cb_ShiftMon); - } - break; - case 2: - PlaySE(SE_SELECT); - ClearBottomWindow(); - SetPSSCallback(Cb_WithdrawMon); - break; - case 1: - if (CanMovePartyMon()) - { - gPSSData->state = 3; - } - else if (ItemIsMail(gPSSData->displayMonItemId)) - { - gPSSData->state = 4; - } - else - { - PlaySE(SE_SELECT); - ClearBottomWindow(); - SetPSSCallback(Cb_DepositMenu); - } - break; - case 7: - if (CanMovePartyMon()) - { - gPSSData->state = 3; - } - else if (gPSSData->displayMonIsEgg) - { - gPSSData->state = 5; // Cannot release an Egg. - } - else if (ItemIsMail(gPSSData->displayMonItemId)) - { - gPSSData->state = 4; - } - else - { - PlaySE(SE_SELECT); - SetPSSCallback(Cb_ReleaseMon); - } - break; - case 6: - PlaySE(SE_SELECT); - SetPSSCallback(Cb_ShowMonSummary); - break; - case 8: - PlaySE(SE_SELECT); - SetPSSCallback(Cb_ShowMarkMenu); - break; - case 12: - PlaySE(SE_SELECT); - SetPSSCallback(Cb_TakeItemForMoving); - break; - case 13: - PlaySE(SE_SELECT); - SetPSSCallback(Cb_GiveMovingItemToMon); - break; - case 16: - SetPSSCallback(Cb_ItemToBag); - break; - case 15: - SetPSSCallback(Cb_SwitchSelectedItem); - break; - case 14: - SetPSSCallback(Cb_GiveItemFromBag); - break; - case 17: - SetPSSCallback(Cb_ShowItemInfo); - break; - } - break; - case 3: - PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_LAST_POKE); - gPSSData->state = 6; - break; - case 5: - PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_CANT_RELEASE_EGG); - gPSSData->state = 6; - break; - case 4: - PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_PLEASE_REMOVE_MAIL); - gPSSData->state = 6; - break; - case 6: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); - } - break; - } -} - -static void Cb_MoveMon(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - InitMonPlaceChange(0); - gPSSData->state++; - break; - case 1: - if (!DoMonPlaceChange()) - { - if (sInPartyMenu) - SetPSSCallback(Cb_HandleMovingMonFromParty); - else - SetPSSCallback(Cb_MainPSS); - } - break; - } -} - -static void Cb_PlaceMon(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - sub_808FE54(1); - InitMonPlaceChange(1); - gPSSData->state++; - break; - case 1: - if (!DoMonPlaceChange()) - { - if (sInPartyMenu) - SetPSSCallback(Cb_HandleMovingMonFromParty); - else - SetPSSCallback(Cb_MainPSS); - } - break; - } -} - -static void Cb_ShiftMon(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - sub_808FE54(0); - InitMonPlaceChange(2); - gPSSData->state++; - break; - case 1: - if (!DoMonPlaceChange()) - { - BoxSetMosaic(); - SetPSSCallback(Cb_MainPSS); - } - break; - } -} - -static void Cb_WithdrawMon(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - if (CalculatePlayerPartyCount() == PARTY_SIZE) - { - PrintStorageActionText(PC_TEXT_PARTY_FULL); - gPSSData->state = 1; - } - else - { - sub_8092B5C(); - InitMonPlaceChange(0); - gPSSData->state = 2; - } - break; - case 1: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); - } - break; - case 2: - if (!DoMonPlaceChange()) - { - SetMovingMonPriority(1); - SetUpDoShowPartyMenu(); - gPSSData->state++; - } - break; - case 3: - if (!DoShowPartyMenu()) - { - sub_808FE54(1); - InitMonPlaceChange(1); - gPSSData->state++; - } - break; - case 4: - if (!DoMonPlaceChange()) - { - sub_808FAA8(); - gPSSData->state++; - } - break; - case 5: - SetPSSCallback(Cb_HidePartyPokemon); - break; - } -} - -static void Cb_DepositMenu(u8 taskId) -{ - u8 boxId; - - switch (gPSSData->state) - { - case 0: - PrintStorageActionText(PC_TEXT_DEPOSIT_IN_WHICH_BOX); - LoadChooseBoxMenuGfx(&gPSSData->field_1E5C, TAG_TILE_A, TAG_PAL_DAC7, 3, FALSE); - sub_808C940(gUnknown_20397B6); - gPSSData->state++; - break; - case 1: - boxId = HandleBoxChooseSelectionInput(); - if (boxId == 200) - { - // no box chosen yet - } - else if (boxId == 201) - { - ClearBottomWindow(); - sub_808C950(); - FreeBoxSelectionPopupSpriteGfx(); - SetPSSCallback(Cb_MainPSS); - } - else - { - if (TryStorePartyMonInBox(boxId)) - { - gUnknown_20397B6 = boxId; - sub_808FE54(2); - ClearBottomWindow(); - sub_808C950(); - FreeBoxSelectionPopupSpriteGfx(); - gPSSData->state = 2; - } - else - { - PrintStorageActionText(PC_TEXT_BOX_IS_FULL); - gPSSData->state = 4; - } - } - break; - case 2: - CompactPartySlots(); - sub_80909F4(); - gPSSData->state++; - break; - case 3: - if (!sub_8090A60()) - { - sub_8093174(); - BoxSetMosaic(); - sub_808FAA8(); - SetPSSCallback(Cb_MainPSS); - } - break; - case 4: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - PrintStorageActionText(PC_TEXT_DEPOSIT_IN_WHICH_BOX); - gPSSData->state = 1; - } - break; - } -} - -static void Cb_ReleaseMon(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - PrintStorageActionText(PC_TEXT_RELEASE_POKE); - ShowYesNoWindow(1); - gPSSData->state++; - // fallthrough - case 1: - switch (Menu_ProcessInputNoWrapClearOnChoose()) - { - case MENU_B_PRESSED: - case 1: - ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); - break; - case 0: - ClearBottomWindow(); - InitCanReleaseMonVars(); - sub_8093194(); - gPSSData->state++; - break; - } - break; - case 2: - RunCanReleaseMon(); - if (!sub_80931EC()) - { - while (1) - { - s8 r0 = RunCanReleaseMon(); - if (r0 == 1) - { - gPSSData->state++; - break; - } - else if (r0 == 0) - { - gPSSData->state = 8; // Can't release the mon. - break; - } - } - } - break; - case 3: - ReleaseMon(); - RefreshCursorMonData(); - PrintStorageActionText(PC_TEXT_WAS_RELEASED); - gPSSData->state++; - break; - case 4: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - PrintStorageActionText(PC_TEXT_BYE_BYE); - gPSSData->state++; - } - break; - case 5: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - ClearBottomWindow(); - if (sInPartyMenu) - { - CompactPartySlots(); - sub_80909F4(); - gPSSData->state++; - } - else - { - gPSSData->state = 7; - } - } - break; - case 6: - if (!sub_8090A60()) - { - sub_8092F54(); - BoxSetMosaic(); - sub_808FAA8(); - gPSSData->state++; - } - break; - case 7: - SetPSSCallback(Cb_MainPSS); - break; - case 8: - PrintStorageActionText(PC_TEXT_WAS_RELEASED); - gPSSData->state++; - break; - case 9: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - PrintStorageActionText(PC_TEXT_SURPRISE); - gPSSData->state++; - } - break; - case 10: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - ClearBottomWindow(); - sub_8091114(); - gPSSData->state++; - } - break; - case 11: - if (!sub_8091150()) - { - sub_8093264(); - PrintStorageActionText(PC_TEXT_CAME_BACK); - gPSSData->state++; - } - break; - case 12: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - PrintStorageActionText(PC_TEXT_WORRIED); - gPSSData->state++; - } - break; - case 13: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); - } - break; - } -} - -static void Cb_ShowMarkMenu(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - PrintStorageActionText(PC_TEXT_MARK_POKE); - gPSSData->markMenu.markings = gPSSData->displayMonMarkings; - OpenMonMarkingsMenu(gPSSData->displayMonMarkings, 0xb0, 0x10); - gPSSData->state++; - break; - case 1: - if (!HandleMonMarkingsMenuInput()) - { - FreeMonMarkingsMenu(); - ClearBottomWindow(); - SetMonMarkings(gPSSData->markMenu.markings); - RefreshCursorMonData(); - SetPSSCallback(Cb_MainPSS); - } - break; - } -} - -static void Cb_TakeItemForMoving(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - if (!ItemIsMail(gPSSData->displayMonItemId)) - { - ClearBottomWindow(); - gPSSData->state++; - } - else - { - SetPSSCallback(Cb_PrintCantStoreMail); - } - break; - case 1: - sub_8094D14(2); - Item_FromMonToMoving(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); - gPSSData->state++; - break; - case 2: - if (!sub_809610C()) - { - sub_8094D14(3); - ClearBottomWindow(); - sub_8092F54(); - PrintCursorMonInfo(); - gPSSData->state++; - } - break; - case 3: - if (!IsDma3ManagerBusyWithBgCopy()) - SetPSSCallback(Cb_MainPSS); - break; - } -} - -static void Cb_GiveMovingItemToMon(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - ClearBottomWindow(); - gPSSData->state++; - break; - case 1: - sub_8094D14(2); - Item_GiveMovingToMon(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); - gPSSData->state++; - break; - case 2: - if (!sub_809610C()) - { - sub_8094D14(0); - sub_8092F54(); - PrintCursorMonInfo(); - PrintStorageActionText(PC_TEXT_ITEM_IS_HELD); - gPSSData->state++; - } - break; - case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - ClearBottomWindow(); - gPSSData->state++; - } - break; - case 4: - if (!IsDma3ManagerBusyWithBgCopy()) - SetPSSCallback(Cb_MainPSS); - break; - } -} - -static void Cb_ItemToBag(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - if (!AddBagItem(gPSSData->displayMonItemId, 1)) - { - PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_BAG_FULL); - gPSSData->state = 3; - } - else - { - PlaySE(SE_SELECT); - Item_TakeMons(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); - gPSSData->state = 1; - } - break; - case 1: - if (!sub_809610C()) - { - PrintStorageActionText(PC_TEXT_PLACED_IN_BAG); - gPSSData->state = 2; - } - break; - case 2: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - ClearBottomWindow(); - sub_8092F54(); - PrintCursorMonInfo(); - gPSSData->state = 4; - } - break; - case 4: - if (!IsDma3ManagerBusyWithBgCopy()) - SetPSSCallback(Cb_MainPSS); - break; - case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); - } - break; - } -} - -static void Cb_SwitchSelectedItem(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - if (!ItemIsMail(gPSSData->displayMonItemId)) - { - ClearBottomWindow(); - gPSSData->state++; - } - else - { - SetPSSCallback(Cb_PrintCantStoreMail); - } - break; - case 1: - sub_8094D14(2); - Item_SwitchMonsWithMoving(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); - gPSSData->state++; - break; - case 2: - if (!sub_809610C()) - { - sub_8094D14(3); - sub_8092F54(); - PrintCursorMonInfo(); - PrintStorageActionText(PC_TEXT_CHANGED_TO_ITEM); - gPSSData->state++; - } - break; - case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - ClearBottomWindow(); - gPSSData->state++; - } - break; - case 4: - if (!IsDma3ManagerBusyWithBgCopy()) - SetPSSCallback(Cb_MainPSS); - break; - } -} - -static void Cb_ShowItemInfo(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - ClearBottomWindow(); - gPSSData->state++; - break; - case 1: - if (!IsDma3ManagerBusyWithBgCopy()) - { - PlaySE(SE_WIN_OPEN); - PrintItemDescription(); - InitItemInfoWindow(); - gPSSData->state++; - } - break; - case 2: - if (!UpdateItemInfoWindowSlideIn()) - gPSSData->state++; - break; - case 3: - if (!IsDma3ManagerBusyWithBgCopy()) - gPSSData->state++; - break; - case 4: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - PlaySE(SE_WIN_OPEN); - gPSSData->state++; - } - break; - case 5: - if (!UpdateItemInfoWindowSlideOut()) - gPSSData->state++; - break; - case 6: - if (!IsDma3ManagerBusyWithBgCopy()) - SetPSSCallback(Cb_MainPSS); - break; - } -} - -static void Cb_CloseBoxWhileHoldingItem(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - PlaySE(SE_SELECT); - PrintStorageActionText(PC_TEXT_PUT_IN_BAG); - ShowYesNoWindow(0); - gPSSData->state = 1; - break; - case 1: - switch (Menu_ProcessInputNoWrapClearOnChoose()) - { - case MENU_B_PRESSED: - case 1: - ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); - break; - case 0: - if (AddBagItem(gPSSData->movingItemId, 1) == TRUE) - { - ClearBottomWindow(); - gPSSData->state = 3; - } - else - { - PrintStorageActionText(PC_TEXT_BAG_FULL); - gPSSData->state = 2; - } - break; - } - break; - case 2: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - ClearBottomWindow(); - gPSSData->state = 5; - } - break; - case 3: - sub_8096088(); - gPSSData->state = 4; - break; - case 4: - if (!sub_809610C()) - { - sub_8094D14(0); - SetPSSCallback(Cb_MainPSS); - } - break; - case 5: - if (!IsDma3ManagerBusyWithBgCopy()) - SetPSSCallback(Cb_MainPSS); - break; - } -} - -static void Cb_HandleMovingMonFromParty(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - CompactPartySlots(); - sub_80909F4(); - gPSSData->state++; - break; - case 1: - if (!sub_8090A60()) - { - sub_808FAA8(); - SetPSSCallback(Cb_MainPSS); - } - break; - } -} - -static void Cb_PrintCantStoreMail(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - PrintStorageActionText(PC_TEXT_CANT_STORE_MAIL); - gPSSData->state++; - break; - case 1: - if (!IsDma3ManagerBusyWithBgCopy()) - gPSSData->state++; - break; - case 2: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - ClearBottomWindow(); - gPSSData->state++; - } - break; - case 3: - if (!IsDma3ManagerBusyWithBgCopy()) - SetPSSCallback(Cb_MainPSS); - break; - } -} - -static void Cb_HandleBoxOptions(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - PrintStorageActionText(PC_TEXT_WHAT_YOU_DO); - AddMenu(); - gPSSData->state++; - break; - case 1: - if (sub_8094F90()) - return; - gPSSData->state++; - case 2: - switch (sub_8094F94()) - { - case -1: - case 0: - AnimateBoxScrollArrows(TRUE); - ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); - break; - case 11: - PlaySE(SE_SELECT); - SetPSSCallback(Cb_NameBox); - break; - case 10: - PlaySE(SE_SELECT); - ClearBottomWindow(); - SetPSSCallback(Cb_HandleWallpapers); - break; - case 9: - PlaySE(SE_SELECT); - ClearBottomWindow(); - SetPSSCallback(Cb_JumpBox); - break; - } - break; - } -} - -static void Cb_HandleWallpapers(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - AddWallpaperSetsMenu(); - PrintStorageActionText(PC_TEXT_PICK_A_THEME); - gPSSData->state++; - break; - case 1: - if (!sub_8094F90()) - gPSSData->state++; - break; - case 2: - gPSSData->wallpaperSetId = sub_8094F94(); - switch (gPSSData->wallpaperSetId) - { - case -1: - AnimateBoxScrollArrows(TRUE); - ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); - break; - case 18 ... 21: - PlaySE(SE_SELECT); - sub_8095024(); - gPSSData->wallpaperSetId -= 18; - gPSSData->state++; - break; - } - break; - case 3: - if (!IsDma3ManagerBusyWithBgCopy()) - { - AddWallpapersMenu(gPSSData->wallpaperSetId); - PrintStorageActionText(PC_TEXT_PICK_A_WALLPAPER); - gPSSData->state++; - } - break; - case 4: - gPSSData->wallpaperId = sub_8094F94(); - switch (gPSSData->wallpaperId) - { - case MENU_NOTHING_CHOSEN: - break; - case MENU_B_PRESSED: - ClearBottomWindow(); - gPSSData->state = 0; - break; - default: - PlaySE(SE_SELECT); - ClearBottomWindow(); - gPSSData->wallpaperId -= 22; - SetWallpaperForCurrentBox(gPSSData->wallpaperId); - gPSSData->state++; - break; - } - break; - case 5: - if (!DoWallpaperGfxChange()) - { - AnimateBoxScrollArrows(TRUE); - SetPSSCallback(Cb_MainPSS); - } - break; - } -} - -static void Cb_JumpBox(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - PrintStorageActionText(PC_TEXT_JUMP_TO_WHICH_BOX); - LoadChooseBoxMenuGfx(&gPSSData->field_1E5C, TAG_TILE_A, TAG_PAL_DAC7, 3, FALSE); - sub_808C940(StorageGetCurrentBox()); - gPSSData->state++; - break; - case 1: - gPSSData->newCurrBoxId = HandleBoxChooseSelectionInput(); - switch (gPSSData->newCurrBoxId) - { - case 200: - break; - default: - ClearBottomWindow(); - sub_808C950(); - FreeBoxSelectionPopupSpriteGfx(); - if (gPSSData->newCurrBoxId == 201 || gPSSData->newCurrBoxId == StorageGetCurrentBox()) - { - AnimateBoxScrollArrows(TRUE); - SetPSSCallback(Cb_MainPSS); - } - else - { - gPSSData->state++; - } - break; - } - break; - case 2: - SetUpScrollToBox(gPSSData->newCurrBoxId); - gPSSData->state++; - break; - case 3: - if (!ScrollToBox()) - { - SetCurrentBox(gPSSData->newCurrBoxId); - SetPSSCallback(Cb_MainPSS); - } - break; - } -} - -static void Cb_NameBox(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - sub_8093630(); - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - gPSSData->state++; - break; - case 1: - if (!UpdatePaletteFade()) - { - sWhichToReshow = 1; - gPSSData->screenChangeType = SCREEN_CHANGE_NAME_BOX; - SetPSSCallback(Cb_ChangeScreen); - } - break; - } -} - -static void Cb_ShowMonSummary(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - sub_80936B8(); - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - gPSSData->state++; - break; - case 1: - if (!UpdatePaletteFade()) - { - sWhichToReshow = 0; - gPSSData->screenChangeType = SCREEN_CHANGE_SUMMARY_SCREEN; - SetPSSCallback(Cb_ChangeScreen); - } - break; - } -} - -static void Cb_GiveItemFromBag(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - gPSSData->state++; - break; - case 1: - if (!UpdatePaletteFade()) - { - sWhichToReshow = 2; - gPSSData->screenChangeType = SCREEN_CHANGE_ITEM_FROM_BAG; - SetPSSCallback(Cb_ChangeScreen); - } - break; - } -} - -static void Cb_OnCloseBoxPressed(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - if (IsMonBeingMoved()) - { - PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_HOLDING_POKE); - gPSSData->state = 1; - } - else if (IsActiveItemMoving()) - { - SetPSSCallback(Cb_CloseBoxWhileHoldingItem); - } - else - { - PlaySE(SE_SELECT); - PrintStorageActionText(PC_TEXT_EXIT_BOX); - ShowYesNoWindow(0); - gPSSData->state = 2; - } - break; - case 1: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); - } - break; - case 2: - switch (Menu_ProcessInputNoWrapClearOnChoose()) - { - case MENU_B_PRESSED: - case 1: - ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); - break; - case 0: - PlaySE(SE_PC_OFF); - ClearBottomWindow(); - gPSSData->state++; - break; - } - break; - case 3: - BeginPCScreenEffect_TurnOff(20, 0, 1); - gPSSData->state++; - break; - case 4: - if (!IsPCScreenEffectRunning_TurnOff()) - { - sub_808FF70(); - gPlayerPartyCount = CalculatePlayerPartyCount(); - gPSSData->screenChangeType = SCREEN_CHANGE_EXIT_BOX; - SetPSSCallback(Cb_ChangeScreen); - } - break; - } -} - -static void Cb_OnBPressed(u8 taskId) -{ - switch (gPSSData->state) - { - case 0: - if (IsMonBeingMoved()) - { - PlaySE(SE_FAILURE); - PrintStorageActionText(PC_TEXT_HOLDING_POKE); - gPSSData->state = 1; - } - else if (IsActiveItemMoving()) - { - SetPSSCallback(Cb_CloseBoxWhileHoldingItem); - } - else - { - PlaySE(SE_SELECT); - PrintStorageActionText(PC_TEXT_CONTINUE_BOX); - ShowYesNoWindow(0); - gPSSData->state = 2; - } - break; - case 1: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) - { - ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); - } - break; - case 2: - switch (Menu_ProcessInputNoWrapClearOnChoose()) - { - case 0: - ClearBottomWindow(); - SetPSSCallback(Cb_MainPSS); - break; - case 1: - case MENU_B_PRESSED: - PlaySE(SE_PC_OFF); - ClearBottomWindow(); - gPSSData->state++; - break; - } - break; - case 3: - BeginPCScreenEffect_TurnOff(20, 0, 0); - gPSSData->state++; - break; - case 4: - if (!IsPCScreenEffectRunning_TurnOff()) - { - sub_808FF70(); - gPlayerPartyCount = CalculatePlayerPartyCount(); - gPSSData->screenChangeType = SCREEN_CHANGE_EXIT_BOX; - SetPSSCallback(Cb_ChangeScreen); - } - break; - } -} - -static void Cb_ChangeScreen(u8 taskId) -{ - struct Pokemon * partyMon; - u8 mode, monIndex, maxMonIndex; - u8 screenChangeType = gPSSData->screenChangeType; - - if (gPSSData->boxOption == OPTION_MOVE_ITEMS && IsActiveItemMoving() == TRUE) - gUnknown_20397BA = GetMovingItem(); - else - gUnknown_20397BA = ITEM_NONE; - - switch (screenChangeType) - { - case SCREEN_CHANGE_EXIT_BOX: - default: - FreePSSData(); - SetMainCallback2(CB2_ExitPokeStorage); - break; - case SCREEN_CHANGE_SUMMARY_SCREEN: - partyMon = gPSSData->field_218C.mon; - monIndex = gPSSData->field_2187; - maxMonIndex = gPSSData->field_2186; - mode = gPSSData->summaryScreenMode; - FreePSSData(); - ShowPokemonSummaryScreen(partyMon, monIndex, maxMonIndex, Cb2_ReturnToPSS, mode); - break; - case SCREEN_CHANGE_NAME_BOX: - FreePSSData(); - DoNamingScreen(NAMING_SCREEN_BOX, GetBoxNamePtr(StorageGetCurrentBox()), 0, 0, 0, Cb2_ReturnToPSS); - break; - case SCREEN_CHANGE_ITEM_FROM_BAG: - FreePSSData(); - GoToBagMenu(ITEMMENULOCATION_PCBOX, OPEN_BAG_ITEMS, Cb2_ReturnToPSS); - break; - } - - DestroyTask(taskId); -} - -static void GiveChosenBagItem(void) -{ - u16 item = gSpecialVar_ItemId; - - if (item != ITEM_NONE) - { - u8 id = GetBoxCursorPosition(); - - if (sInPartyMenu) - SetMonData(&gPlayerParty[id], MON_DATA_HELD_ITEM, &item); - else - SetCurrentBoxMonData(id, MON_DATA_HELD_ITEM, &item); - - RemoveBagItem(item, 1); - } -} - -static void FreePSSData(void) -{ - FreeBoxPartyPokemonDropdowns(); - sub_80950A4(); - FREE_AND_SET_NULL(gPSSData); - FreeAllWindowBuffers(); -} - -// ****************************************************************** -// Graphics util -// ****************************************************************** - -static void SetScrollingBackground(void) -{ - SetGpuReg(REG_OFFSET_BG3CNT, BGCNT_PRIORITY(3) | BGCNT_CHARBASE(3) | BGCNT_16COLOR | BGCNT_SCREENBASE(31)); - DecompressAndLoadBgGfxUsingHeap(3, sPokemonStorageScrollingBGTileset, 0, 0, 0); - LZ77UnCompVram(sPokemonStorageScrollingBGTilemap, (void *)BG_SCREEN_ADDR(31)); -} - -static void ScrollBackground(void) -{ - ChangeBgX(3, 128, 1); - ChangeBgY(3, 128, 2); -} - -static void LoadPSSMenuGfx(void) -{ - InitBgsFromTemplates(0, gUnknown_83CEA50, NELEMS(gUnknown_83CEA50)); - DecompressAndLoadBgGfxUsingHeap(1, gPSSMenu_Gfx, 0, 0, 0); - LZ77UnCompWram(gUnknown_83CE5FC, gPSSData->field_5AC4); - SetBgTilemapBuffer(1, gPSSData->field_5AC4); - ShowBg(1); - ScheduleBgCopyTilemapToVram(1); -} - -static bool8 InitPSSWindows(void) -{ - if (!InitWindows(gUnknown_83CEA30)) - { - return FALSE; - } - else - { - DeactivateAllTextPrinters(); - return TRUE; - } -} - -static void LoadWaveformSpritePalette(void) -{ - LoadSpritePalette(&sWaveformSpritePalette); -} - -static void sub_808F078(void) -{ - LoadPalette(gUnknown_8E9C3F8, 0, 0x20); - LoadPalette(gUnknown_8E9C418, 0x20, 0x20); - LoadPalette(gUnknown_83CEA10, 0xF0, 0x20); - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - LoadPalette(gUnknown_83CE738, 0x30, 0x20); - else - LoadPalette(gUnknown_83CE758, 0x30, 0x20); - - SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(1) | BGCNT_CHARBASE(1) | BGCNT_16COLOR | BGCNT_SCREENBASE(30)); - LoadCursorMonSprite(); - PSS_CreateMonMarkingSprite(); - CreateWaveformSprites(); - RefreshCursorMonData(); -} - -static void PSS_CreateMonMarkingSprite(void) -{ - gPSSData->markingComboSprite = CreateMonMarkingComboSprite(TAG_TILE_10, TAG_PAL_DAC8, NULL); - gPSSData->markingComboSprite->oam.priority = 1; - gPSSData->markingComboSprite->subpriority = 1; - gPSSData->markingComboSprite->x = 40; - gPSSData->markingComboSprite->y = 150; - gPSSData->markingComboTilesPtr = (void *)OBJ_VRAM0 + 32 * GetSpriteTileStartByTag(TAG_TILE_10); -} - -static void CreateWaveformSprites(void) -{ - u16 i; - struct SpriteSheet sheet = sWaveformSpriteSheet; - - LoadSpriteSheet(&sheet); - for (i = 0; i < 2; i++) - { - u8 spriteId = CreateSprite(&sSpriteTemplate_Waveform, i * 63 + 8, 9, 2); - gPSSData->waveformSprites[i] = &gSprites[spriteId]; - } -} - -static void RefreshCursorMonData(void) -{ - LoadCursorMonGfx(gPSSData->displayMonSpecies, gPSSData->displayMonPersonality); - PrintCursorMonInfo(); - sub_808F5E8(); - ScheduleBgCopyTilemapToVram(0); -} - -static void BoxSetMosaic(void) -{ - RefreshCursorMonData(); - if (gPSSData->cursorMonSprite) - { - gPSSData->cursorMonSprite->oam.mosaic = TRUE; - gPSSData->cursorMonSprite->data[0] = 10; - gPSSData->cursorMonSprite->data[1] = 1; - gPSSData->cursorMonSprite->callback = SpriteCB_CursorMon_Mosaic; - SetGpuReg(REG_OFFSET_MOSAIC, (gPSSData->cursorMonSprite->data[0] << 12) | (gPSSData->cursorMonSprite->data[0] << 8)); - } -} - -static u8 BoxGetMosaic(void) -{ - return gPSSData->cursorMonSprite->oam.mosaic; -} - -static void SpriteCB_CursorMon_Mosaic(struct Sprite *sprite) -{ - sprite->data[0] -= sprite->data[1]; - if (sprite->data[0] < 0) - sprite->data[0] = 0; - SetGpuReg(REG_OFFSET_MOSAIC, (sprite->data[0] << 12) | (sprite->data[0] << 8)); - if (sprite->data[0] == 0) - { - sprite->oam.mosaic = FALSE; - sprite->callback = SpriteCallbackDummy; - } -} - -static void LoadCursorMonSprite(void) -{ - u16 i; - u16 tileStart; - u8 palSlot; - u8 spriteId; - struct SpriteSheet sheet = {gPSSData->field_22C4, 0x800, TAG_TILE_2}; - struct SpritePalette palette = {gPSSData->field_2244, TAG_PAL_DAC6}; - struct SpriteTemplate template = sSpriteTemplate_CursorMon; - - for (i = 0; i < 0x800; i++) - gPSSData->field_22C4[i] = 0; - for (i = 0; i < 0x10; i++) - gPSSData->field_2244[i] = 0; - - gPSSData->cursorMonSprite = NULL; - - do - { - tileStart = LoadSpriteSheet(&sheet); - if (tileStart == 0) - break; - - palSlot = LoadSpritePalette(&palette); - if (palSlot == 0xFF) - break; - - spriteId = CreateSprite(&template, 40, 48, 0); - if (spriteId == MAX_SPRITES) - break; - - gPSSData->cursorMonSprite = &gSprites[spriteId]; - gPSSData->field_223A = palSlot * 16 + 0x100; - gPSSData->field_223C = (void *)OBJ_VRAM0 + tileStart * 32; - } while (0); - - if (gPSSData->cursorMonSprite == NULL) - { - FreeSpriteTilesByTag(TAG_TILE_2); - FreeSpritePaletteByTag(TAG_PAL_DAC6); - } -} - -static void LoadCursorMonGfx(u16 species, u32 pid) -{ - if (gPSSData->cursorMonSprite == NULL) - return; - - if (species != SPECIES_NONE) - { - HandleLoadSpecialPokePic(&gMonFrontPicTable[species], gPSSData->field_22C4, species, pid); - LZ77UnCompWram(gPSSData->displayMonPalette, gPSSData->field_2244); - CpuCopy32(gPSSData->field_22C4, gPSSData->field_223C, 0x800); - LoadPalette(gPSSData->field_2244, gPSSData->field_223A, 0x20); - gPSSData->cursorMonSprite->invisible = FALSE; - } - else - { - gPSSData->cursorMonSprite->invisible = TRUE; - } -} - -static void PrintCursorMonInfo(void) -{ - u16 i; - u16 y; - FillWindowPixelBuffer(0, PIXEL_FILL(1)); - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - { - for (i = 0, y = 0; i < 3; i++, y += 14) - { - AddTextPrinterParameterized(0, FONT_2, gPSSData->displayMonTexts[i], i == 2 ? 10 : 6, y, TEXT_SKIP_DRAW, NULL); - } - AddTextPrinterParameterized(0, FONT_0, gPSSData->displayMonTexts[3], 6, y + 2, TEXT_SKIP_DRAW, NULL); - } - else - { - AddTextPrinterParameterized(0, FONT_0, gPSSData->displayMonTexts[3], 6, 0, TEXT_SKIP_DRAW, NULL); - for (i = 0, y = 15; i < 3; i++, y += 14) - { - AddTextPrinterParameterized(0, FONT_2, gPSSData->displayMonTexts[i], i == 2 ? 10 : 6, y, TEXT_SKIP_DRAW, NULL); - } - } - - CopyWindowToVram(0, COPYWIN_GFX); - if (gPSSData->displayMonSpecies != SPECIES_NONE) - { - UpdateMonMarkingTiles(gPSSData->displayMonMarkings, gPSSData->markingComboTilesPtr); - gPSSData->markingComboSprite->invisible = FALSE; - } - else - { - gPSSData->markingComboSprite->invisible = TRUE; - } -} - -static void sub_808F5E8(void) -{ - u16 i; - - if (gPSSData->displayMonSpecies != SPECIES_NONE) - { - SetBoxPartyPokemonDropdownMap2Rect(0, 0, 0, 8, 2); - for (i = 0; i < 2; i++) - StartSpriteAnimIfDifferent(gPSSData->waveformSprites[i], i * 2 + 1); - } - else - { - SetBoxPartyPokemonDropdownMap2Rect(0, 0, 2, 8, 2); - for (i = 0; i < 2; i++) - StartSpriteAnim(gPSSData->waveformSprites[i], i * 2); - } - - CopyBoxPartyPokemonDropdownToBgTilemapBuffer(0); - ScheduleBgCopyTilemapToVram(1); -} - -static void sub_808F68C(void) -{ - LZ77UnCompWram(gUnknown_8E9CAEC, gPSSData->partyMenuTilemapBuffer); - LoadPalette(gPSSMenu_Pal, 0x10, 0x20); - SetBoxPartyPokemonDropdownMap2(1, 1, gPSSData->partyMenuTilemapBuffer, 12, 22); - SetBoxPartyPokemonDropdownMap2(2, 1, gUnknown_83CE778, 9, 4); - SetBoxPartyPokemonDropdownMap2Pos(1, 10, 0); - SetBoxPartyPokemonDropdownMap2Pos(2, 21, 0); - sub_808F9FC(); - if (sInPartyMenu) - { - sub_808F90C(TRUE); - CreatePartyMonsSprites(TRUE); - CopyBoxPartyPokemonDropdownToBgTilemapBuffer(2); - CopyBoxPartyPokemonDropdownToBgTilemapBuffer(1); - } - else - { - SetBoxPartyPokemonDropdownMap2Rect(1, 0, 20, 12, 2); - sub_808F90C(TRUE); - CopyBoxPartyPokemonDropdownToBgTilemapBuffer(1); - CopyBoxPartyPokemonDropdownToBgTilemapBuffer(2); - } - - ScheduleBgCopyTilemapToVram(1); - gPSSData->closeBoxFlashing = FALSE; -} - -static void SetUpShowPartyMenu(void) -{ - gPSSData->partyMenuUnused1 = 20; - gPSSData->partyMenuY = 2; - gPSSData->partyMenuMoveTimer = 0; - CreatePartyMonsSprites(FALSE); -} - -static bool8 ShowPartyMenu(void) -{ - if (gPSSData->partyMenuMoveTimer == 20) - return FALSE; - - gPSSData->partyMenuUnused1--; - gPSSData->partyMenuY++; - AdjustBoxPartyPokemonDropdownPos(1, 3, 1); - CopyBoxPartyPokemonDropdownToBgTilemapBuffer(1); - ScheduleBgCopyTilemapToVram(1); - sub_8090B98(8); - if (++gPSSData->partyMenuMoveTimer == 20) - { - sInPartyMenu = TRUE; - return FALSE; - } - else - { - return TRUE; - } -} - -static void SetUpHidePartyMenu(void) -{ - gPSSData->partyMenuUnused1 = 0; - gPSSData->partyMenuY = 22; - gPSSData->partyMenuMoveTimer = 0; - if (gPSSData->boxOption == OPTION_MOVE_ITEMS) - sub_80960C0(); -} - -static bool8 HidePartyMenu(void) -{ - if (gPSSData->partyMenuMoveTimer != 20) - { - gPSSData->partyMenuUnused1++; - gPSSData->partyMenuY--; - AdjustBoxPartyPokemonDropdownPos(1, 3, -1); - CopyBoxPartyPokemonDropdownToBgTilemapBuffer(1); - FillBgTilemapBufferRect_Palette0(1, 0x100, 10, gPSSData->partyMenuY, 12, 1); - sub_8090B98(-8); - if (++gPSSData->partyMenuMoveTimer != 20) - { - ScheduleBgCopyTilemapToVram(1); - return TRUE; - } - else - { - sInPartyMenu = FALSE; - DestroyAllPartyMonIcons(); - CompactPartySlots(); - SetBoxPartyPokemonDropdownMap2Rect(2, 0, 0, 9, 2); - CopyBoxPartyPokemonDropdownToBgTilemapBuffer(2); - ScheduleBgCopyTilemapToVram(1); - return FALSE; - } - } - - return FALSE; -} - -static void sub_808F90C(bool8 arg0) -{ - if (arg0) - SetBoxPartyPokemonDropdownMap2Rect(2, 0, 0, 9, 2); - else - SetBoxPartyPokemonDropdownMap2Rect(2, 0, 2, 9, 2); - - CopyBoxPartyPokemonDropdownToBgTilemapBuffer(2); - ScheduleBgCopyTilemapToVram(1); -} - -static void sub_808F948(void) -{ - gPSSData->closeBoxFlashing = TRUE; - gPSSData->closeBoxFlashTimer = 30; - gPSSData->closeBoxFlashState = TRUE; -} - -static void sub_808F974(void) -{ - if (gPSSData->closeBoxFlashing) - { - gPSSData->closeBoxFlashing = FALSE; - sub_808F90C(TRUE); - } -} - -static void sub_808F99C(void) -{ - if (gPSSData->closeBoxFlashing && ++gPSSData->closeBoxFlashTimer > 30) - { - gPSSData->closeBoxFlashTimer = 0; - gPSSData->closeBoxFlashState = (gPSSData->closeBoxFlashState == FALSE); - sub_808F90C(gPSSData->closeBoxFlashState); - } -} - -static void sub_808F9FC(void) -{ - u8 i; - - for (i = 1; i < PARTY_SIZE; i++) - { - s32 species = GetMonData(gPlayerParty + i, MON_DATA_SPECIES); - sub_808FA30(i, (species != SPECIES_NONE)); - } -} - -static void sub_808FA30(u8 pos, bool8 isPartyMon) -{ - u16 i, j, index; - const u16 *data; - - if (isPartyMon) - data = gUnknown_83CE7C0; - else - data = gUnknown_83CE7D8; - - index = 3 * (3 * (pos - 1) + 1); - index *= 4; - index += 7; - for (i = 0; i < 3; i++) - { - for (j = 0; j < 4; j++) - { - gPSSData->partyMenuTilemapBuffer[index + j] = data[j]; - } - data += 4; - index += 12; - } -} - -static void sub_808FAA8(void) -{ - sub_808F9FC(); - SetBoxPartyPokemonDropdownMap2Rect(1, 0, 0, 12, 22); - CopyBoxPartyPokemonDropdownToBgTilemapBuffer(1); - ScheduleBgCopyTilemapToVram(1); -} - -static void SetUpDoShowPartyMenu(void) -{ - gPSSData->showPartyMenuState = 0; - PlaySE(SE_WIN_OPEN); - SetUpShowPartyMenu(); -} - -static bool8 DoShowPartyMenu(void) -{ - switch (gPSSData->showPartyMenuState) - { - case 0: - if (!ShowPartyMenu()) - { - sub_8092AE4(); - gPSSData->showPartyMenuState++; - } - break; - case 1: - if (!sub_80924A8()) - { - if (gPSSData->setMosaic) - BoxSetMosaic(); - gPSSData->showPartyMenuState++; - } - break; - case 2: - return FALSE; - } - return TRUE; -} - -static void sub_808FB68(void) -{ - SetGpuReg(REG_OFFSET_BG0CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(29)); - TextWindow_SetStdFrame0_WithPal(1, 2, 208); - FillBgTilemapBufferRect(0, 0, 0, 0, 32, 20, 17); - CopyBgTilemapBufferToVram(0); -} - -static void PrintStorageActionText(u8 id) -{ - u8 *txtPtr; - - DynamicPlaceholderTextUtil_Reset(); - switch (sPCStorageActionTexts[id].format) - { - case PC_TEXT_FMT_NORMAL: - break; - case PC_TEXT_FMT_MON_NAME_1: - case PC_TEXT_FMT_MON_NAME_2: - case PC_TEXT_FMT_MON_NAME_3: - DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, gPSSData->displayMonName); - break; - case PC_TEXT_FMT_MON_NAME_4: - case PC_TEXT_FMT_MON_NAME_5: - case PC_TEXT_FMT_MON_NAME_6: - DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, gPSSData->field_21E0); - break; - case PC_TEXT_FMT_ITEM_NAME: - if (IsActiveItemMoving()) - txtPtr = StringCopy(gPSSData->itemName, GetMovingItemName()); - else - txtPtr = StringCopy(gPSSData->itemName, gPSSData->displayMonTexts[3]); - - while (*(txtPtr - 1) == CHAR_SPACE) - txtPtr--; - - *txtPtr = EOS; - DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, gPSSData->itemName); - break; - } - - DynamicPlaceholderTextUtil_ExpandPlaceholders(gPSSData->field_2190, sPCStorageActionTexts[id].text); - FillWindowPixelBuffer(1, PIXEL_FILL(1)); - AddTextPrinterParameterized(1, FONT_1, gPSSData->field_2190, 0, 2, TEXT_SKIP_DRAW, NULL); - DrawTextBorderOuter(1, 2, 13); - PutWindowTilemap(1); - CopyWindowToVram(1, COPYWIN_GFX); - ScheduleBgCopyTilemapToVram(0); -} - -static void ShowYesNoWindow(s8 cursorPos) -{ - CreateYesNoMenu(&sYesNoWindowTemplate, FONT_1, 0, 2, 0x00b, 14, 1); - Menu_MoveCursorNoWrapAround(cursorPos); -} - -static void ClearBottomWindow(void) -{ - ClearStdWindowAndFrameToTransparent(1, FALSE); - ScheduleBgCopyTilemapToVram(0); -} - -static void AddWallpaperSetsMenu(void) -{ - InitMenu(); - SetMenuText(PC_TEXT_SCENERY1); - SetMenuText(PC_TEXT_SCENERY2); - SetMenuText(PC_TEXT_SCENERY3); - SetMenuText(PC_TEXT_ETCETERA); - AddMenu(); -} - -static void AddWallpapersMenu(u8 wallpaperSet) -{ - InitMenu(); - switch (wallpaperSet) - { - case 0: - SetMenuText(PC_TEXT_FOREST); - SetMenuText(PC_TEXT_CITY); - SetMenuText(PC_TEXT_DESERT); - SetMenuText(PC_TEXT_SAVANNA); - break; - case 1: - SetMenuText(PC_TEXT_CRAG); - SetMenuText(PC_TEXT_VOLCANO); - SetMenuText(PC_TEXT_SNOW); - SetMenuText(PC_TEXT_CAVE); - break; - case 2: - SetMenuText(PC_TEXT_BEACH); - SetMenuText(PC_TEXT_SEAFLOOR); - SetMenuText(PC_TEXT_RIVER); - SetMenuText(PC_TEXT_SKY); - break; - case 3: - SetMenuText(PC_TEXT_POLKADOT); - SetMenuText(PC_TEXT_POKECENTER); - SetMenuText(PC_TEXT_MACHINE); - SetMenuText(PC_TEXT_SIMPLE); - break; - } - AddMenu(); -} - -u8 GetCurrentBoxOption(void) -{ - return sCurrentBoxOption; -} - -static void sub_808FDFC(void) -{ - if (!IsCursorOnBoxTitle()) - { - if (sInPartyMenu) - sub_8095C84(CURSOR_AREA_IN_PARTY, GetBoxCursorPosition()); - else - sub_8095C84(CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); - } - - if (gUnknown_20397BA != ITEM_NONE) - { - sub_8095E2C(gUnknown_20397BA); - sub_8094D14(3); - } -} - -static void sub_808FE54(u8 action) -{ - u16 event; - u8 fromBox = sub_8094D34(); - u16 species = gPSSData->displayMonSpecies; - u16 species2; - u8 toBox; - struct PssQuestLogBuffer * qlogBuffer; - if (sInPartyMenu) - { - toBox = TOTAL_BOXES_COUNT; - species2 = GetMonData(&gPlayerParty[GetBoxCursorPosition()], MON_DATA_SPECIES2); - } - else - { - toBox = StorageGetCurrentBox(); - species2 = GetCurrentBoxMonData(GetBoxCursorPosition(), MON_DATA_SPECIES2); - } - qlogBuffer = &gPSSData->qlogBuffer; - - switch (action) - { - default: - return; - case 0: - if (sInPartyMenu) - { - if (fromBox == TOTAL_BOXES_COUNT) - return; - else - event = QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON; - } - else - { - if (fromBox == TOTAL_BOXES_COUNT) - // Should upmerge but doesn't - event = QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON; - else - event = fromBox != toBox ? QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES : QL_EVENT_SWITCHED_MONS_WITHIN_BOX; - } - qlogBuffer->species = species; - qlogBuffer->species2 = species2; - qlogBuffer->fromBox = fromBox; - qlogBuffer->toBox = toBox; - break; - case 1: - qlogBuffer->species = species; - qlogBuffer->species2 = SPECIES_NONE; - qlogBuffer->fromBox = fromBox; - qlogBuffer->toBox = 0xFF; - if (sInPartyMenu) - { - if (fromBox == TOTAL_BOXES_COUNT) - return; - else - event = QL_EVENT_WITHDREW_MON_PC; - } - else - { - if (fromBox == TOTAL_BOXES_COUNT) - { - event = QL_EVENT_DEPOSITED_MON_PC; - qlogBuffer->fromBox = toBox; - } - else if (fromBox != toBox) - { - event = QL_EVENT_MOVED_MON_BETWEEN_BOXES; - qlogBuffer->toBox = toBox; - } - else - event = QL_EVENT_MOVED_MON_WITHIN_BOX; - } - break; - case 2: - event = QL_EVENT_DEPOSITED_MON_PC; - qlogBuffer->species = species; - qlogBuffer->species2 = SPECIES_NONE; - qlogBuffer->fromBox = gUnknown_20397B6; - qlogBuffer->toBox = 0xFF; - break; - case 3: - event = QL_EVENT_SWITCHED_MULTIPLE_MONS; - qlogBuffer->species = SPECIES_NONE; - qlogBuffer->species2 = SPECIES_NONE; - qlogBuffer->fromBox = fromBox; - qlogBuffer->toBox = toBox; - break; - } - SetQuestLogEvent(event, (const void *)qlogBuffer); -} - -static void sub_808FF70(void) -{ - if (sLastUsedBox != StorageGetCurrentBox()) - { - FlagClear(FLAG_SHOWN_BOX_WAS_FULL_MESSAGE); - VarSet(VAR_PC_BOX_TO_SEND_MON, StorageGetCurrentBox()); - } -} diff --git a/src/pokemon_storage_system_4.c b/src/pokemon_storage_system_4.c deleted file mode 100644 index cbd2f1b9c..000000000 --- a/src/pokemon_storage_system_4.c +++ /dev/null @@ -1,1504 +0,0 @@ -#include "global.h" -#include "gflib.h" -#include "event_data.h" -#include "graphics.h" -#include "new_menu_helpers.h" -#include "pokemon_icon.h" -#include "pokemon_storage_system_internal.h" -#include "strings.h" -#include "task.h" -#include "trig.h" - -static void sub_8090324(struct Sprite *sprite); -static void SetBoxSpeciesAndPersonalities(u8 boxId); -static void sub_8090A74(struct Sprite *sprite, u16 idx); -static void sub_8090AE0(struct Sprite *sprite); -static void DestroyBoxMonIcon(struct Sprite *sprite); -static void sub_80911B0(struct Sprite *sprite); -static void sub_8091420(u8 taskId); -static s8 sub_80916F4(u8 boxId); -static void LoadWallpaperGfx(u8 wallpaperId, s8 direction); -static bool32 WaitForWallpaperGfxLoad(void); -static void sub_8091984(void *buffer, const void *buffer2, s8 direction, u8 baseBlock); -static void sub_8091A24(void *buffer); -static void sub_8091A94(u8 wallpaperId); -static void sub_8091C48(u8 wallpaperId, s8 direction); -static void sub_8091E84(struct Sprite *sprite); -static void sub_8091EB8(struct Sprite *sprite); -static s16 GetBoxTitleBaseX(const u8 *boxName); -static void sub_8091E34(void); -static void CycleBoxTitleColor(void); -static void CreateBoxScrollArrows(void); -static void StartBoxScrollArrowsSlide(s8 direction); -static void StopBoxScrollArrowsSlide(void); -static void SpriteCB_Arrow(struct Sprite *sprite); - -static const struct OamData gUnknown_83CEC08; - -static const struct SpriteTemplate gUnknown_83CEBF0 = { - .tileTag = TAG_TILE_12, - .paletteTag = TAG_PAL_DAC0, - .oam = &gUnknown_83CEC08, - .anims = gDummySpriteAnimTable, - .images = NULL, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = SpriteCallbackDummy -}; - -static const struct OamData gUnknown_83CEC08 = { - .y = 0, - .affineMode = ST_OAM_AFFINE_OFF, - .objMode = ST_OAM_OBJ_NORMAL, - .mosaic = FALSE, - .bpp = ST_OAM_4BPP, - .shape = SPRITE_SHAPE(32x32), - .x = 0, - .matrixNum = 0, - .size = SPRITE_SIZE(32x32), - .tileNum = 0x000, - .priority = 0, - .paletteNum = 0 -}; - -static const union AffineAnimCmd gUnknown_83CEC10[] = { - AFFINEANIMCMD_FRAME(-2, -2, 0, 120), - AFFINEANIMCMD_END -}; - -static const union AffineAnimCmd gUnknown_83CEC20[] = { - AFFINEANIMCMD_FRAME(16, 16, 0, 0), - AFFINEANIMCMD_FRAME(16, 16, 0, 15), - AFFINEANIMCMD_END -}; - -static const union AffineAnimCmd *const gUnknown_83CEC38[] = { - gUnknown_83CEC10, - gUnknown_83CEC20 -}; - -static const u16 gUnknown_83CEC40[] = INCBIN_U16("graphics/interface/pss_unk_83CEC40.gbapal"); -static const u32 gUnknown_83CEC80[] = INCBIN_U32("graphics/interface/pss_unk_83CEC80.4bpp.lz"); -static const u32 gUnknown_83CF050[] = INCBIN_U32("graphics/interface/pss_unk_83CF050.bin.lz"); -static const u16 gUnknown_83CF12C[] = INCBIN_U16("graphics/interface/pss_unk_83CF12C.gbapal"); -static const u32 gUnknown_83CF16C[] = INCBIN_U32("graphics/interface/pss_unk_83CF16C.4bpp.lz"); -static const u32 gUnknown_83CF374[] = INCBIN_U32("graphics/interface/pss_unk_83CF374.bin.lz"); -static const u16 gUnknown_83CF424[] = INCBIN_U16("graphics/interface/pss_unk_83CF424.gbapal"); -static const u32 gUnknown_83CF464[] = INCBIN_U32("graphics/interface/pss_unk_83CF464.4bpp.lz"); -static const u32 gUnknown_83CF750[] = INCBIN_U32("graphics/interface/pss_unk_83CF750.bin.lz"); -static const u16 gUnknown_83CF834[] = INCBIN_U16("graphics/interface/pss_unk_83CF834.gbapal"); -static const u32 gUnknown_83CF874[] = INCBIN_U32("graphics/interface/pss_unk_83CF874.4bpp.lz"); -static const u32 gUnknown_83CFA94[] = INCBIN_U32("graphics/interface/pss_unk_83CFA94.bin.lz"); -static const u16 gUnknown_83CFB60[] = INCBIN_U16("graphics/interface/pss_unk_83CFB60.gbapal"); -static const u32 gUnknown_83CFBA0[] = INCBIN_U32("graphics/interface/pss_unk_83CFBA0.4bpp.lz"); -static const u32 gUnknown_83CFEF0[] = INCBIN_U32("graphics/interface/pss_unk_83CFEF0.bin.lz"); -static const u16 gUnknown_83CFFC8[] = INCBIN_U16("graphics/interface/pss_unk_83CFFC8.gbapal"); -static const u32 gUnknown_83D0008[] = INCBIN_U32("graphics/interface/pss_unk_83D0008.4bpp.lz"); -static const u8 sSpace_83D0338[4] = {}; -static const u32 gUnknown_83D033C[] = INCBIN_U32("graphics/interface/pss_unk_83D033C.bin.lz"); -static const u16 gUnknown_83D0414[] = INCBIN_U16("graphics/interface/pss_unk_83D0414.gbapal"); -static const u32 gUnknown_83D0454[] = INCBIN_U32("graphics/interface/pss_unk_83D0454.4bpp.lz"); -static const u32 gUnknown_83D070C[] = INCBIN_U32("graphics/interface/pss_unk_83D070C.bin.lz"); -static const u16 gUnknown_83D07D8[] = INCBIN_U16("graphics/interface/pss_unk_83D07D8.gbapal"); -static const u32 gUnknown_83D0818[] = INCBIN_U32("graphics/interface/pss_unk_83D0818.4bpp.lz"); -static const u32 gUnknown_83D0B5C[] = INCBIN_U32("graphics/interface/pss_unk_83D0B5C.bin.lz"); -static const u16 gUnknown_83D0C38[] = INCBIN_U16("graphics/interface/pss_unk_83D0C38.gbapal"); -static const u32 gUnknown_83D0C78[] = INCBIN_U32("graphics/interface/pss_unk_83D0C78.4bpp.lz"); -static const u32 gUnknown_83D0FFC[] = INCBIN_U32("graphics/interface/pss_unk_83D0FFC.bin.lz"); -static const u16 gUnknown_83D10E4[] = INCBIN_U16("graphics/interface/pss_unk_83D10E4.gbapal"); -static const u32 gUnknown_83D1124[] = INCBIN_U32("graphics/interface/pss_unk_83D1124.4bpp.lz"); -static const u32 gUnknown_83D13D8[] = INCBIN_U32("graphics/interface/pss_unk_83D13D8.bin.lz"); -static const u16 gUnknown_83D14B4[] = INCBIN_U16("graphics/interface/pss_unk_83D14B4.gbapal"); -static const u32 gUnknown_83D14F4[] = INCBIN_U32("graphics/interface/pss_unk_83D14F4.4bpp.lz"); -static const u32 gUnknown_83D1788[] = INCBIN_U32("graphics/interface/pss_unk_83D1788.bin.lz"); -static const u16 gUnknown_83D1874[] = INCBIN_U16("graphics/interface/pss_unk_83D1874.gbapal"); -static const u32 gUnknown_83D18B4[] = INCBIN_U32("graphics/interface/pss_unk_83D18B4.4bpp.lz"); -static const u32 gUnknown_83D1B4C[] = INCBIN_U32("graphics/interface/pss_unk_83D1B4C.bin.lz"); -static const u16 gUnknown_83D1C2C[] = INCBIN_U16("graphics/interface/pss_unk_83D1C2C.gbapal"); -static const u8 sSpace_83D1C6C[32] = {}; -static const u32 gUnknown_83D1C8C[] = INCBIN_U32("graphics/interface/pss_unk_83D1C8C.4bpp.lz"); -static const u32 gUnknown_83D1EC4[] = INCBIN_U32("graphics/interface/pss_unk_83D1EC4.bin.lz"); -static const u16 gUnknown_83D1F94[] = INCBIN_U16("graphics/interface/pss_unk_83D1F94.gbapal"); -static const u32 gUnknown_83D1FD4[] = INCBIN_U32("graphics/interface/pss_unk_83D1FD4.4bpp.lz"); -static const u32 gUnknown_83D22B8[] = INCBIN_U32("graphics/interface/pss_unk_83D22B8.bin.lz"); -static const u16 gUnknown_83D239C[] = INCBIN_U16("graphics/interface/pss_unk_83D239C.gbapal"); -static const u32 gUnknown_83D23DC[] = INCBIN_U32("graphics/interface/pss_unk_83D23DC.4bpp.lz"); -static const u32 gUnknown_83D256C[] = INCBIN_U32("graphics/interface/pss_unk_83D256C.bin.lz"); -static const u16 gUnknown_83D2614[] = INCBIN_U16("graphics/interface/pss_unk_83D2614.gbapal"); -static const u32 gUnknown_83D2654[] = INCBIN_U32("graphics/interface/pss_unk_83D2654.4bpp.lz"); -static const u32 gUnknown_83D277C[] = INCBIN_U32("graphics/interface/pss_unk_83D277C.bin.lz"); -static const u16 gUnknown_83D2820[] = INCBIN_U16("graphics/interface/pss_unk_83D2820.bin"); - -static const u16 sBoxTitleColors[][2] = { - {RGB( 7, 7, 7), RGB(31, 31, 31)}, - {RGB( 7, 7, 7), RGB(31, 31, 31)}, - {RGB( 7, 7, 7), RGB(31, 31, 31)}, - {RGB( 7, 7, 7), RGB(31, 31, 31)}, - {RGB( 7, 7, 7), RGB(31, 31, 31)}, - {RGB( 7, 7, 7), RGB(31, 31, 31)}, - {RGB( 7, 7, 7), RGB(31, 31, 31)}, - {RGB( 7, 7, 7), RGB(31, 31, 31)}, - {RGB( 7, 7, 7), RGB(31, 31, 31)}, - {RGB( 7, 7, 7), RGB(31, 31, 31)}, - {RGB( 7, 7, 7), RGB(31, 31, 31)}, - {RGB( 7, 7, 7), RGB(31, 31, 31)}, - {RGB( 7, 7, 7), RGB(31, 31, 31)}, - {RGB( 7, 7, 7), RGB(31, 31, 31)}, - {RGB( 7, 7, 7), RGB(31, 31, 31)}, - {RGB( 7, 7, 7), RGB(31, 31, 31)} -}; - -static const struct WallpaperTable sWallpaperTable[] = { - {gUnknown_83CEC80, gUnknown_83CF050, gUnknown_83CEC40}, - {gUnknown_83CF16C, gUnknown_83CF374, gUnknown_83CF12C}, - {gUnknown_83CF464, gUnknown_83CF750, gUnknown_83CF424}, - {gUnknown_83CF874, gUnknown_83CFA94, gUnknown_83CF834}, - {gUnknown_83CFBA0, gUnknown_83CFEF0, gUnknown_83CFB60}, - {gUnknown_83D0008, gUnknown_83D033C, gUnknown_83CFFC8}, - {gUnknown_83D0454, gUnknown_83D070C, gUnknown_83D0414}, - {gUnknown_83D0818, gUnknown_83D0B5C, gUnknown_83D07D8}, - {gUnknown_83D0C78, gUnknown_83D0FFC, gUnknown_83D0C38}, - {gUnknown_83D1124, gUnknown_83D13D8, gUnknown_83D10E4}, - {gUnknown_83D14F4, gUnknown_83D1788, gUnknown_83D14B4}, - {gUnknown_83D18B4, gUnknown_83D1B4C, gUnknown_83D1874}, - {gUnknown_83D1C8C, gUnknown_83D1EC4, gUnknown_83D1C2C}, - {gUnknown_83D1FD4, gUnknown_83D22B8, gUnknown_83D1F94}, - {gUnknown_83D23DC, gUnknown_83D256C, gUnknown_83D239C}, - {gUnknown_83D2654, gUnknown_83D277C, gUnknown_83D2614}, -}; - -static const u16 gUnknown_83D2AD0[] = INCBIN_U16("graphics/interface/pss_unk_83D2AD0.4bpp"); -static const u8 sUnref_83D2B50[] = {0xba, 0x23}; - -static const struct SpriteSheet sSpriteSheet_Arrow = { - gUnknown_83D2AD0, 0x0080, TAG_TILE_6 -}; - -static const struct OamData gUnknown_83D2B5C = { - .y = 0, - .affineMode = ST_OAM_AFFINE_OFF, - .objMode = ST_OAM_OBJ_NORMAL, - .mosaic = FALSE, - .bpp = ST_OAM_4BPP, - .shape = SPRITE_SHAPE(32x16), - .x = 0, - .matrixNum = 0, - .size = SPRITE_SIZE(32x16), - .tileNum = 0, - .priority = 2, - .paletteNum = 0 -}; - -static const union AnimCmd gUnknown_83D2B64[] = { - ANIMCMD_FRAME(0, 5), - ANIMCMD_END -}; - -static const union AnimCmd gUnknown_83D2B6C[] = { - ANIMCMD_FRAME(8, 5), - ANIMCMD_END -}; - -static const union AnimCmd *const gUnknown_83D2B74[] = { - gUnknown_83D2B64, - gUnknown_83D2B6C -}; - -static const struct SpriteTemplate gUnknown_83D2B7C = { - .tileTag = TAG_TILE_3, - .paletteTag = TAG_PAL_DAC9, - .oam = &gUnknown_83D2B5C, - .anims = gUnknown_83D2B74, - .images = NULL, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = SpriteCallbackDummy -}; - -static const struct OamData gUnknown_83D2B94 = { - .y = 0, - .affineMode = ST_OAM_AFFINE_OFF, - .objMode = ST_OAM_OBJ_NORMAL, - .mosaic = FALSE, - .bpp = ST_OAM_4BPP, - .shape = SPRITE_SHAPE(8x16), - .x = 0, - .matrixNum = 0, - .size = SPRITE_SIZE(8x16), - .tileNum = 0x000, - .priority = 2, - .paletteNum = 0 -}; - -static const union AnimCmd gUnknown_83D2B9C[] = { - ANIMCMD_FRAME(0, 5), - ANIMCMD_END -}; - -static const union AnimCmd gUnknown_83D2BA4[] = { - ANIMCMD_FRAME(2, 5), - ANIMCMD_END -}; - -static const union AnimCmd *const gUnknown_83D2BAC[] = { - gUnknown_83D2B9C, - gUnknown_83D2BA4 -}; - -static const struct SpriteTemplate sSpriteTemplate_Arrow = { - .tileTag = TAG_TILE_6, - .paletteTag = TAG_PAL_WAVEFORM, - .oam = &gUnknown_83D2B94, - .anims = gUnknown_83D2BAC, - .images = NULL, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = SpriteCB_Arrow -}; - -void sub_808FFAC(void) -{ - u16 i; - - LoadMonIconPalettes(); - for (i = 0; i < MAX_MON_ICONS; i++) - gPSSData->numIconsPerSpecies[i] = 0; - for (i = 0; i < MAX_MON_ICONS; i++) - gPSSData->iconSpeciesList[i] = 0; - for (i = 0; i < PARTY_SIZE; i++) - gPSSData->partySprites[i] = NULL; - for (i = 0; i < IN_BOX_COUNT; i++) - gPSSData->boxMonsSprites[i] = NULL; - - gPSSData->movingMonSprite = NULL; - gPSSData->unkUnused1 = 0; -} - -static u8 sub_8090058(void) -{ - return (IsCursorInBox() ? 2 : 1); -} - -void CreateMovingMonIcon(void) -{ - u32 personality = GetMonData(&gPSSData->movingMon, MON_DATA_PERSONALITY); - u16 species = GetMonData(&gPSSData->movingMon, MON_DATA_SPECIES2); - u8 priority = sub_8090058(); - - gPSSData->movingMonSprite = CreateMonIconSprite(species, personality, 0, 0, priority, 7); - gPSSData->movingMonSprite->callback = sub_80911B0; -} - -static void sub_80900D4(u8 boxId) -{ - u8 boxPosition; - u16 i, j, count; - u16 species; - u32 personality; - - count = 0; - boxPosition = 0; - for (i = 0; i < IN_BOX_COLUMNS; i++) - { - for (j = 0; j < IN_BOX_ROWS; j++) - { - species = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_SPECIES2); - if (species != SPECIES_NONE) - { - personality = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_PERSONALITY); - gPSSData->boxMonsSprites[count] = CreateMonIconSprite(species, personality, 8 * (3 * j) + 100, 8 * (3 * i) + 44, 2, 19 - j); - } - else - { - gPSSData->boxMonsSprites[count] = NULL; - } - boxPosition++; - count++; - } - } - - if (gPSSData->boxOption == OPTION_MOVE_ITEMS) - { - for (boxPosition = 0; boxPosition < IN_BOX_COUNT; boxPosition++) - { - if (GetBoxMonDataAt(boxId, boxPosition, MON_DATA_HELD_ITEM) == 0) - gPSSData->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; - } - } -} - -void sub_80901EC(u8 boxPosition) -{ - u16 species = GetCurrentBoxMonData(boxPosition, MON_DATA_SPECIES2); - - if (species != SPECIES_NONE) - { - s16 x = 8 * (3 * (boxPosition % IN_BOX_ROWS)) + 100; - s16 y = 8 * (3 * (boxPosition / IN_BOX_ROWS)) + 44; - u32 personality = GetCurrentBoxMonData(boxPosition, MON_DATA_PERSONALITY); - - gPSSData->boxMonsSprites[boxPosition] = CreateMonIconSprite(species, personality, x, y, 2, 19 - (boxPosition % IN_BOX_ROWS)); - if (gPSSData->boxOption == OPTION_MOVE_ITEMS) - gPSSData->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; - } -} - -static void sub_809029C(s16 arg0) -{ - u16 i; - - for (i = 0; i < IN_BOX_COUNT; i++) - { - if (gPSSData->boxMonsSprites[i] != NULL) - { - gPSSData->boxMonsSprites[i]->data[2] = arg0; - gPSSData->boxMonsSprites[i]->data[4] = 1; - gPSSData->boxMonsSprites[i]->callback = sub_8090324; - } - } -} - -static void sub_80902E0(struct Sprite *sprite) -{ - if (sprite->data[1] != 0) - { - sprite->data[1]--; - sprite->x += sprite->data[2]; - } - else - { - gPSSData->iconScrollNumIncoming--; - sprite->x = sprite->data[3]; - sprite->callback = SpriteCallbackDummy; - } -} - -static void sub_8090324(struct Sprite *sprite) -{ - if (sprite->data[4] != 0) - { - sprite->data[4]--; - } - else - { - sprite->x += sprite->data[2]; - sprite->data[5] = sprite->x + sprite->x2; - if (sprite->data[5] <= 68 || sprite->data[5] >= 252) - sprite->callback = SpriteCallbackDummy; - } -} - -static void DestroyAllIconsInRow(u8 row) -{ - u16 column; - u8 boxPosition = row; - - for (column = 0; column < IN_BOX_COLUMNS; column++) - { - if (gPSSData->boxMonsSprites[boxPosition] != NULL) - { - DestroyBoxMonIcon(gPSSData->boxMonsSprites[boxPosition]); - gPSSData->boxMonsSprites[boxPosition] = NULL; - } - boxPosition += IN_BOX_ROWS; - } -} - -static u8 sub_80903A4(u8 row, u16 times, s16 xDelta) -{ - s32 i; - u16 y = 44; - s16 xDest = 8 * (3 * row) + 100; - u16 x = xDest - ((times + 1) * xDelta); - u8 subpriority = 19 - row; - u8 count = 0; - u8 boxPosition = row; - - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - { - for (i = 0; i < IN_BOX_COLUMNS; i++) - { - if (gPSSData->boxSpecies[boxPosition] != SPECIES_NONE) - { - gPSSData->boxMonsSprites[boxPosition] = CreateMonIconSprite(gPSSData->boxSpecies[boxPosition], - gPSSData->boxPersonalities[boxPosition], - x, y, 2, subpriority); - if (gPSSData->boxMonsSprites[boxPosition] != NULL) - { - gPSSData->boxMonsSprites[boxPosition]->data[1] = times; - gPSSData->boxMonsSprites[boxPosition]->data[2] = xDelta; - gPSSData->boxMonsSprites[boxPosition]->data[3] = xDest; - gPSSData->boxMonsSprites[boxPosition]->callback = sub_80902E0; - count++; - } - } - boxPosition += IN_BOX_ROWS; - y += 24; - } - } - else - { - for (i = 0; i < IN_BOX_COLUMNS; i++) - { - if (gPSSData->boxSpecies[boxPosition] != SPECIES_NONE) - { - gPSSData->boxMonsSprites[boxPosition] = CreateMonIconSprite(gPSSData->boxSpecies[boxPosition], - gPSSData->boxPersonalities[boxPosition], - x, y, 2, subpriority); - if (gPSSData->boxMonsSprites[boxPosition] != NULL) - { - gPSSData->boxMonsSprites[boxPosition]->data[1] = times; - gPSSData->boxMonsSprites[boxPosition]->data[2] = xDelta; - gPSSData->boxMonsSprites[boxPosition]->data[3] = xDest; - gPSSData->boxMonsSprites[boxPosition]->callback = sub_80902E0; - if (GetBoxMonDataAt(gPSSData->incomingBoxId, boxPosition, MON_DATA_HELD_ITEM) == 0) - gPSSData->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; - count++; - } - } - boxPosition += IN_BOX_ROWS; - y += 24; - } - } - - return count; -} - -static void sub_8090574(u8 boxId, s8 direction) -{ - gPSSData->iconScrollState = 0; - gPSSData->iconScrollToBoxId = boxId; - gPSSData->iconScrollDirection = direction; - gPSSData->iconScrollDistance = 32; - gPSSData->iconScrollSpeed = -(6 * direction); - gPSSData->iconScrollNumIncoming = 0; - SetBoxSpeciesAndPersonalities(boxId); - if (direction > 0) - gPSSData->iconScrollCurColumn = 0; - else - gPSSData->iconScrollCurColumn = IN_BOX_ROWS - 1; - - gPSSData->iconScrollPos = (24 * gPSSData->iconScrollCurColumn) + 100; - sub_809029C(gPSSData->iconScrollSpeed); -} - -static bool8 sub_809062C(void) -{ - if (gPSSData->iconScrollDistance != 0) - gPSSData->iconScrollDistance--; - - switch (gPSSData->iconScrollState) - { - case 0: - gPSSData->iconScrollPos += gPSSData->iconScrollSpeed; - if (gPSSData->iconScrollPos <= 64 || gPSSData->iconScrollPos >= 252) - { - DestroyAllIconsInRow(gPSSData->iconScrollCurColumn); - gPSSData->iconScrollPos += gPSSData->iconScrollDirection * 24; - gPSSData->iconScrollState++; - } - break; - case 1: - gPSSData->iconScrollPos += gPSSData->iconScrollSpeed; - gPSSData->iconScrollNumIncoming += sub_80903A4(gPSSData->iconScrollCurColumn, gPSSData->iconScrollDistance, gPSSData->iconScrollSpeed); - if ((gPSSData->iconScrollDirection > 0 && gPSSData->iconScrollCurColumn == IN_BOX_ROWS - 1) - || (gPSSData->iconScrollDirection < 0 && gPSSData->iconScrollCurColumn == 0)) - { - gPSSData->iconScrollState++; - } - else - { - gPSSData->iconScrollCurColumn += gPSSData->iconScrollDirection; - gPSSData->iconScrollState = 0; - } - break; - case 2: - if (gPSSData->iconScrollNumIncoming == 0) - { - gPSSData->iconScrollDistance++; - return FALSE; - } - break; - default: - return FALSE; - } - - return TRUE; -} - -static void SetBoxSpeciesAndPersonalities(u8 boxId) -{ - s32 i, j, boxPosition; - - boxPosition = 0; - for (i = 0; i < IN_BOX_COLUMNS; i++) - { - for (j = 0; j < IN_BOX_ROWS; j++) - { - gPSSData->boxSpecies[boxPosition] = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_SPECIES2); - if (gPSSData->boxSpecies[boxPosition] != SPECIES_NONE) - gPSSData->boxPersonalities[boxPosition] = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_PERSONALITY); - boxPosition++; - } - } - - gPSSData->incomingBoxId = boxId; -} - -void DestroyBoxMonIconAtPosition(u8 boxPosition) -{ - if (gPSSData->boxMonsSprites[boxPosition] != NULL) - { - DestroyBoxMonIcon(gPSSData->boxMonsSprites[boxPosition]); - gPSSData->boxMonsSprites[boxPosition] = NULL; - } -} - -void SetBoxMonIconObjMode(u8 boxPosition, u8 objMode) -{ - if (gPSSData->boxMonsSprites[boxPosition] != NULL) - { - gPSSData->boxMonsSprites[boxPosition]->oam.objMode = objMode; - } -} - -void CreatePartyMonsSprites(bool8 arg0) -{ - u16 i, count; - u16 species = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES2); - u32 personality = GetMonData(&gPlayerParty[0], MON_DATA_PERSONALITY); - - gPSSData->partySprites[0] = CreateMonIconSprite(species, personality, 104, 64, 1, 12); - count = 1; - for (i = 1; i < PARTY_SIZE; i++) - { - species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); - if (species != SPECIES_NONE) - { - personality = GetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY); - gPSSData->partySprites[i] = CreateMonIconSprite(species, personality, 152, 8 * (3 * (i - 1)) + 16, 1, 12); - count++; - } - else - { - gPSSData->partySprites[i] = NULL; - } - } - - if (!arg0) - { - for (i = 0; i < count; i++) - { - gPSSData->partySprites[i]->y -= 160; - gPSSData->partySprites[i]->invisible = TRUE; - } - } - - if (gPSSData->boxOption == OPTION_MOVE_ITEMS) - { - for (i = 0; i < PARTY_SIZE; i++) - { - if (gPSSData->partySprites[i] != NULL && GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM) == 0) - gPSSData->partySprites[i]->oam.objMode = ST_OAM_OBJ_BLEND; - } - } -} - -void sub_80909F4(void) -{ - u16 i, count; - - gPSSData->numPartyToCompact = 0; - for (i = 0, count = 0; i < PARTY_SIZE; i++) - { - if (gPSSData->partySprites[i] != NULL) - { - if (i != count) - { - sub_8090A74(gPSSData->partySprites[i], count); - gPSSData->partySprites[i] = NULL; - gPSSData->numPartyToCompact++; - } - count++; - } - } -} - -u8 sub_8090A60(void) -{ - return gPSSData->numPartyToCompact; -} - -static void sub_8090A74(struct Sprite *sprite, u16 partyId) -{ - s16 x, y; - - sprite->data[1] = partyId; - if (partyId == 0) - x = 104, y = 64; - else - x = 152, y = 8 * (3 * (partyId - 1)) + 16; - - sprite->data[2] = (u16)(sprite->x) * 8; - sprite->data[3] = (u16)(sprite->y) * 8; - sprite->data[4] = ((x * 8) - sprite->data[2]) / 8; - sprite->data[5] = ((y * 8) - sprite->data[3]) / 8; - sprite->data[6] = 8; - sprite->callback = sub_8090AE0; -} - -static void sub_8090AE0(struct Sprite *sprite) -{ - if (sprite->data[6] != 0) - { - s16 x = sprite->data[2] += sprite->data[4]; - s16 y = sprite->data[3] += sprite->data[5]; - sprite->x = x / 8u; - sprite->y = y / 8u; - sprite->data[6]--; - } - else - { - if (sprite->data[1] == 0) - { - sprite->x = 104; - sprite->y = 64; - } - else - { - sprite->x = 152; - sprite->y = 8 * (3 * (sprite->data[1] - 1)) + 16; - } - sprite->callback = SpriteCallbackDummy; - gPSSData->partySprites[sprite->data[1]] = sprite; - gPSSData->numPartyToCompact--; - } -} - -void DestroyMovingMonIcon(void) -{ - if (gPSSData->movingMonSprite != NULL) - { - DestroyBoxMonIcon(gPSSData->movingMonSprite); - gPSSData->movingMonSprite = NULL; - } -} - -void sub_8090B98(s16 yDelta) -{ - u16 i, posY; - - for (i = 0; i < PARTY_SIZE; i++) - { - if (gPSSData->partySprites[i] != NULL) - { - gPSSData->partySprites[i]->y += yDelta; - posY = gPSSData->partySprites[i]->y + gPSSData->partySprites[i]->y2 + gPSSData->partySprites[i]->centerToCornerVecY; - posY += 16; - if (posY > 192) - gPSSData->partySprites[i]->invisible = TRUE; - else - gPSSData->partySprites[i]->invisible = FALSE; - } - } -} - -void DestroyPartyMonIcon(u8 partyId) -{ - if (gPSSData->partySprites[partyId] != NULL) - { - DestroyBoxMonIcon(gPSSData->partySprites[partyId]); - gPSSData->partySprites[partyId] = NULL; - } -} - -void DestroyAllPartyMonIcons(void) -{ - u16 i; - - for (i = 0; i < PARTY_SIZE; i++) - { - if (gPSSData->partySprites[i] != NULL) - { - DestroyBoxMonIcon(gPSSData->partySprites[i]); - gPSSData->partySprites[i] = NULL; - } - } -} - -void SetPartyMonIconObjMode(u8 partyId, u8 objMode) -{ - if (gPSSData->partySprites[partyId] != NULL) - { - gPSSData->partySprites[partyId]->oam.objMode = objMode; - } -} - -void sub_8090CC0(u8 mode, u8 id) -{ - if (mode == MODE_PARTY) - { - gPSSData->movingMonSprite = gPSSData->partySprites[id]; - gPSSData->partySprites[id] = NULL; - } - else if (mode == MODE_BOX) - { - gPSSData->movingMonSprite = gPSSData->boxMonsSprites[id]; - gPSSData->boxMonsSprites[id] = NULL; - } - else - { - return; - } - - gPSSData->movingMonSprite->callback = sub_80911B0; - gPSSData->movingMonSprite->oam.priority = sub_8090058(); - gPSSData->movingMonSprite->subpriority = 7; -} - -void sub_8090D58(u8 boxId, u8 position) -{ - if (boxId == TOTAL_BOXES_COUNT) // party mon - { - gPSSData->partySprites[position] = gPSSData->movingMonSprite; - gPSSData->partySprites[position]->oam.priority = 1; - gPSSData->partySprites[position]->subpriority = 12; - } - else - { - gPSSData->boxMonsSprites[position] = gPSSData->movingMonSprite; - gPSSData->boxMonsSprites[position]->oam.priority = 2; - gPSSData->boxMonsSprites[position]->subpriority = 19 - (position % IN_BOX_ROWS); - } - gPSSData->movingMonSprite->callback = SpriteCallbackDummy; - gPSSData->movingMonSprite = NULL; -} - -void sub_8090E08(u8 boxId, u8 position) -{ - if (boxId == TOTAL_BOXES_COUNT) // party mon - gPSSData->shiftMonSpritePtr = &gPSSData->partySprites[position]; - else - gPSSData->shiftMonSpritePtr = &gPSSData->boxMonsSprites[position]; - - gPSSData->movingMonSprite->callback = SpriteCallbackDummy; - gPSSData->shiftTimer = 0; -} - -bool8 sub_8090E74(void) -{ - if (gPSSData->shiftTimer == 16) - return FALSE; - - gPSSData->shiftTimer++; - if (gPSSData->shiftTimer & 1) - { - (*gPSSData->shiftMonSpritePtr)->y--; - gPSSData->movingMonSprite->y++; - } - - (*gPSSData->shiftMonSpritePtr)->x2 = gSineTable[gPSSData->shiftTimer * 8] / 16; - gPSSData->movingMonSprite->x2 = -(gSineTable[gPSSData->shiftTimer * 8] / 16); - if (gPSSData->shiftTimer == 8) - { - gPSSData->movingMonSprite->oam.priority = (*gPSSData->shiftMonSpritePtr)->oam.priority; - gPSSData->movingMonSprite->subpriority = (*gPSSData->shiftMonSpritePtr)->subpriority; - (*gPSSData->shiftMonSpritePtr)->oam.priority = sub_8090058(); - (*gPSSData->shiftMonSpritePtr)->subpriority = 7; - } - - if (gPSSData->shiftTimer == 16) - { - struct Sprite *sprite = gPSSData->movingMonSprite; - gPSSData->movingMonSprite = (*gPSSData->shiftMonSpritePtr); - *gPSSData->shiftMonSpritePtr = sprite; - - gPSSData->movingMonSprite->callback = sub_80911B0; - (*gPSSData->shiftMonSpritePtr)->callback = SpriteCallbackDummy; - } - - return TRUE; -} - -void sub_8090FC4(u8 mode, u8 position) -{ - switch (mode) - { - case MODE_PARTY: - gPSSData->releaseMonSpritePtr = &gPSSData->partySprites[position]; - break; - case MODE_BOX: - gPSSData->releaseMonSpritePtr = &gPSSData->boxMonsSprites[position]; - break; - case MODE_2: - gPSSData->releaseMonSpritePtr = &gPSSData->movingMonSprite; - break; - default: - return; - } - - if (*gPSSData->releaseMonSpritePtr != NULL) - { - InitSpriteAffineAnim(*gPSSData->releaseMonSpritePtr); - (*gPSSData->releaseMonSpritePtr)->oam.affineMode = ST_OAM_AFFINE_NORMAL; - (*gPSSData->releaseMonSpritePtr)->affineAnims = gUnknown_83CEC38; - StartSpriteAffineAnim(*gPSSData->releaseMonSpritePtr, 0); - } -} - -bool8 sub_8091084(void) -{ - if (*gPSSData->releaseMonSpritePtr == NULL || (*gPSSData->releaseMonSpritePtr)->invisible) - return FALSE; - - if ((*gPSSData->releaseMonSpritePtr)->affineAnimEnded) - (*gPSSData->releaseMonSpritePtr)->invisible = TRUE; - - return TRUE; -} - -void sub_80910CC(void) -{ - if (*gPSSData->releaseMonSpritePtr != NULL) - { - FreeOamMatrix((*gPSSData->releaseMonSpritePtr)->oam.matrixNum); - DestroyBoxMonIcon(*gPSSData->releaseMonSpritePtr); - *gPSSData->releaseMonSpritePtr = NULL; - } -} - -void sub_8091114(void) -{ - if (*gPSSData->releaseMonSpritePtr != NULL) - { - (*gPSSData->releaseMonSpritePtr)->invisible = FALSE; - StartSpriteAffineAnim(*gPSSData->releaseMonSpritePtr, 1); - } -} - -bool8 sub_8091150(void) -{ - if (gPSSData->releaseMonSpritePtr == NULL) - return FALSE; - - if ((*gPSSData->releaseMonSpritePtr)->affineAnimEnded) - gPSSData->releaseMonSpritePtr = NULL; - - return TRUE; -} - -void SetMovingMonPriority(u8 priority) -{ - gPSSData->movingMonSprite->oam.priority = priority; -} - -static void sub_80911B0(struct Sprite *sprite) -{ - sprite->x = gPSSData->cursorSprite->x; - sprite->y = gPSSData->cursorSprite->y + gPSSData->cursorSprite->y2 + 4; -} - -static u16 sub_80911D4(u16 species) -{ - u16 i, var; - - // Find the currently-allocated slot - for (i = 0; i < MAX_MON_ICONS; i++) - { - if (gPSSData->iconSpeciesList[i] == species) - break; - } - - if (i == MAX_MON_ICONS) - { - // Find the first empty slot - for (i = 0; i < MAX_MON_ICONS; i++) - { - if (gPSSData->iconSpeciesList[i] == SPECIES_NONE) - break; - } - if (i == MAX_MON_ICONS) - return 0xFFFF; - } - - gPSSData->iconSpeciesList[i] = species; - gPSSData->numIconsPerSpecies[i]++; - var = 16 * i; - CpuCopy32(GetMonIconTiles(species, TRUE), (void *)(OBJ_VRAM0) + var * 32, 0x200); - - return var; -} - -static void sub_8091290(u16 species) -{ - u16 i; - - for (i = 0; i < MAX_MON_ICONS; i++) - { - if (gPSSData->iconSpeciesList[i] == species) - { - if (--gPSSData->numIconsPerSpecies[i] == 0) - gPSSData->iconSpeciesList[i] = 0; - break; - } - } -} - -struct Sprite *CreateMonIconSprite(u16 species, u32 personality, s16 x, s16 y, u8 oamPriority, u8 subpriority) -{ - u16 tileNum; - u8 spriteId; - struct SpriteTemplate template = gUnknown_83CEBF0; - - species = GetIconSpecies(species, personality); - template.paletteTag = 0xDAC0 + gMonIconPaletteIndices[species]; - tileNum = sub_80911D4(species); - if (tileNum == 0xFFFF) - return NULL; - - spriteId = CreateSprite(&template, x, y, subpriority); - if (spriteId == MAX_SPRITES) - { - sub_8091290(species); - return NULL; - } - - gSprites[spriteId].oam.tileNum = tileNum; - gSprites[spriteId].oam.priority = oamPriority; - gSprites[spriteId].data[0] = species; - return &gSprites[spriteId]; -} - -static void DestroyBoxMonIcon(struct Sprite *sprite) -{ - sub_8091290(sprite->data[0]); - DestroySprite(sprite); -} - -void sub_80913DC(u8 boxId) -{ - u8 taskId = CreateTask(sub_8091420, 2); - - gTasks[taskId].data[2] = boxId; -} - -bool8 sub_809140C(void) -{ - return FuncIsActiveTask(sub_8091420); -} - -static void sub_8091420(u8 taskId) -{ - struct Task *task = &gTasks[taskId]; - - switch (task->data[0]) - { - case 0: - gPSSData->wallpaperOffset = 0; - gPSSData->bg2_X = 0; - task->data[1] = RequestDma3Fill(0, gPSSData->field_4AC4, 0x1000, DMA3_32BIT); - break; - case 1: - if (WaitDma3Request(task->data[1]) == -1) - return; - - SetBgTilemapBuffer(2, gPSSData->field_4AC4); - ShowBg(2); - break; - case 2: - LoadWallpaperGfx(task->data[2], 0); - break; - case 3: - if (!WaitForWallpaperGfxLoad()) - return; - - sub_8091A94(task->data[2]); - CreateBoxScrollArrows(); - sub_80900D4(task->data[2]); - SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(2) | BGCNT_CHARBASE(2) | BGCNT_SCREENBASE(27) | BGCNT_TXT512x256); - break; - case 4: - DestroyTask(taskId); - break; - default: - task->data[0] = 0; - return; - } - - task->data[0]++; -} - -void SetUpScrollToBox(u8 boxId) -{ - s8 direction = sub_80916F4(boxId); - - gPSSData->scrollSpeed = (direction > 0) ? 6 : -6; - gPSSData->scrollUnused1 = (direction > 0) ? 1 : 2; - gPSSData->scrollTimer = 32; - gPSSData->scrollToBoxIdUnused = boxId; - gPSSData->scrollUnused2 = (direction <= 0) ? 5 : 0; - gPSSData->scrollDirectionUnused = direction; - gPSSData->scrollUnused3 = (direction > 0) ? 264 : 56; - gPSSData->scrollUnused4 = (direction <= 0) ? 5 : 0; - gPSSData->scrollUnused5 = 0; - gPSSData->scrollUnused6 = 2; - gPSSData->scrollToBoxId = boxId; - gPSSData->scrollDirection = direction; - gPSSData->scrollState = 0; -} - -bool8 ScrollToBox(void) -{ - bool8 var; - - switch (gPSSData->scrollState) - { - case 0: - LoadWallpaperGfx(gPSSData->scrollToBoxId, gPSSData->scrollDirection); - gPSSData->scrollState++; - case 1: - if (!WaitForWallpaperGfxLoad()) - return TRUE; - - sub_8090574(gPSSData->scrollToBoxId, gPSSData->scrollDirection); - sub_8091C48(gPSSData->scrollToBoxId, gPSSData->scrollDirection); - StartBoxScrollArrowsSlide(gPSSData->scrollDirection); - break; - case 2: - var = sub_809062C(); - if (gPSSData->scrollTimer != 0) - { - gPSSData->bg2_X += gPSSData->scrollSpeed; - if (--gPSSData->scrollTimer != 0) - return TRUE; - sub_8091E34(); - StopBoxScrollArrowsSlide(); - } - return var; - } - - gPSSData->scrollState++; - return TRUE; -} - -static s8 sub_80916F4(u8 boxId) -{ - u8 i; - u8 currentBox = StorageGetCurrentBox(); - - for (i = 0; currentBox != boxId; i++) - { - currentBox++; - if (currentBox >= TOTAL_BOXES_COUNT) - currentBox = 0; - } - - return (i < TOTAL_BOXES_COUNT / 2) ? 1 : -1; -} - -void SetWallpaperForCurrentBox(u8 wallpaperId) -{ - u8 boxId = StorageGetCurrentBox(); - SetBoxWallpaper(boxId, wallpaperId); - gPSSData->wallpaperChangeState = 0; -} - -bool8 DoWallpaperGfxChange(void) -{ - switch (gPSSData->wallpaperChangeState) - { - case 0: - BeginNormalPaletteFade(gPSSData->wallpaperPalBits, 1, 0, 16, RGB_WHITEALPHA); - gPSSData->wallpaperChangeState++; - break; - case 1: - if (!UpdatePaletteFade()) - { - u8 curBox = StorageGetCurrentBox(); - LoadWallpaperGfx(curBox, 0); - gPSSData->wallpaperChangeState++; - } - break; - case 2: - if (WaitForWallpaperGfxLoad() == TRUE) - { - CycleBoxTitleColor(); - BeginNormalPaletteFade(gPSSData->wallpaperPalBits, 1, 16, 0, RGB_WHITEALPHA); - gPSSData->wallpaperChangeState++; - } - break; - case 3: - if (!UpdatePaletteFade()) - gPSSData->wallpaperChangeState++; - break; - case 4: - return FALSE; - } - - return TRUE; -} - -static void LoadWallpaperGfx(u8 boxId, s8 direction) -{ - u8 wallpaperId; - const struct WallpaperTable *wallpaperGfx; - void *iconGfx; - u32 size1, size2; - - gPSSData->wallpaperLoadState = 0; - gPSSData->wallpaperLoadBoxId = boxId; - gPSSData->wallpaperLoadDir = direction; - if (gPSSData->wallpaperLoadDir != 0) - { - gPSSData->wallpaperOffset = (gPSSData->wallpaperOffset == 0); - sub_8091A24(gPSSData->field_4AC4); - } - - wallpaperId = GetBoxWallpaper(gPSSData->wallpaperLoadBoxId); - wallpaperGfx = &sWallpaperTable[wallpaperId]; - LZ77UnCompWram(wallpaperGfx->tileMap, gPSSData->wallpaperTilemap); - sub_8091984(gPSSData->field_4AC4, gPSSData->wallpaperTilemap, gPSSData->wallpaperLoadDir, gPSSData->wallpaperOffset); - - if (gPSSData->wallpaperLoadDir != 0) - LoadPalette(wallpaperGfx->palettes, (gPSSData->wallpaperOffset * 32) + 0x40, 0x40); - else - CpuCopy16(wallpaperGfx->palettes, &gPlttBufferUnfaded[(gPSSData->wallpaperOffset * 32) + 0x40], 0x40); - - DecompressAndLoadBgGfxUsingHeap(2, wallpaperGfx->tiles, 0, 256 * gPSSData->wallpaperOffset, 0); - - CopyBgTilemapBufferToVram(2); -} - -static bool32 WaitForWallpaperGfxLoad(void) -{ - if (IsDma3ManagerBusyWithBgCopy() == TRUE) - return FALSE; - - return TRUE; -} - -static void sub_8091984(void *buffer, const void *tilemap, s8 direction, u8 arg2) -{ - s16 var = (arg2 * 2) + 3; - s16 x = ((gPSSData->bg2_X / 8 + 10) + (direction * 24)) & 0x3F; - - CopyRectToBgTilemapBufferRect(2, tilemap, 0, 0, 0x14, 0x12, x, 2, 0x14, 0x12, 0x11, arg2 << 8, var); - - if (direction == 0) - return; - else if (direction > 0) - x *= 1, x += 0x14; // x * 1 is needed to match, but can be safely removed as it makes no functional difference - else - x -= 4; - - FillBgTilemapBufferRect(2, 0, x, 2, 4, 0x12, 0x11); -} - -static void sub_8091A24(void *arg0) -{ - u16 i; - u16 *dest = arg0; - s16 r3 = ((gPSSData->bg2_X / 8) + 30) & 0x3F; - - if (r3 <= 31) - dest += r3 + 0x260; - else - dest += r3 + 0x640; - - for (i = 0; i < 0x2C; i++) - { - *dest++ = 0; - r3 = (r3 + 1) & 0x3F; - if (r3 == 0) - dest -= 0x420; - if (r3 == 0x20) - dest += 0x3e0; - } -} - -static void sub_8091A94(u8 boxId) -{ - u8 tagIndex; - s16 r6; - u16 i; - - struct SpriteSheet spriteSheet = {gPSSData->field_2F8, 0x200, TAG_TILE_3}; - struct SpritePalette palettes[] = { - {gPSSData->boxTitlePal, TAG_PAL_DAC9}, - {} - }; - - u16 wallpaperId = GetBoxWallpaper(boxId); - - gPSSData->boxTitlePal[14] = sBoxTitleColors[wallpaperId][0]; - gPSSData->boxTitlePal[15] = sBoxTitleColors[wallpaperId][1]; - LoadSpritePalettes(palettes); - gPSSData->wallpaperPalBits = 0x3f0; - - tagIndex = IndexOfSpritePaletteTag(TAG_PAL_DAC9); - gPSSData->boxTitlePalOffset = 0x10e + 16 * tagIndex; - gPSSData->wallpaperPalBits |= 0x10000 << tagIndex; - - tagIndex = IndexOfSpritePaletteTag(TAG_PAL_DAC9); - gPSSData->boxTitleAltPalOffset = 0x10e + 16 * tagIndex; - gPSSData->wallpaperPalBits |= 0x10000 << tagIndex; - - StringCopyPadded(gPSSData->field_21B8, GetBoxNamePtr(boxId), 0, 8); - DrawTextWindowAndBufferTiles(gPSSData->field_21B8, gPSSData->field_2F8, 0, 0, gPSSData->field_4F8, 2); - LoadSpriteSheet(&spriteSheet); - r6 = GetBoxTitleBaseX(GetBoxNamePtr(boxId)); - - for (i = 0; i < 2; i++) - { - u8 spriteId = CreateSprite(&gUnknown_83D2B7C, r6 + i * 32, 28, 24); - gPSSData->curBoxTitleSprites[i] = &gSprites[spriteId]; - StartSpriteAnim(gPSSData->curBoxTitleSprites[i], i); - } - gPSSData->boxTitleCycleId = 0; -} - -static void sub_8091C48(u8 boxId, s8 direction) -{ - u16 r8; - s16 x, x2; - u16 i; - struct SpriteSheet spriteSheet = {gPSSData->field_2F8, 0x200, TAG_TILE_3}; - struct SpriteTemplate template = gUnknown_83D2B7C; - - gPSSData->boxTitleCycleId = (gPSSData->boxTitleCycleId == 0); - if (gPSSData->boxTitleCycleId == 0) - { - spriteSheet.tag = TAG_TILE_3; - r8 = gPSSData->boxTitlePalOffset; - } - else - { - spriteSheet.tag = TAG_TILE_4; - r8 = gPSSData->boxTitlePalOffset; - template.tileTag = TAG_TILE_4; - template.paletteTag = TAG_PAL_DAC9; - } - - StringCopyPadded(gPSSData->field_21B8, GetBoxNamePtr(boxId), 0, 8); - DrawTextWindowAndBufferTiles(gPSSData->field_21B8, gPSSData->field_2F8, 0, 0, gPSSData->field_4F8, 2); - LoadSpriteSheet(&spriteSheet); - LoadPalette(sBoxTitleColors[GetBoxWallpaper(boxId)], r8, 4); - x = GetBoxTitleBaseX(GetBoxNamePtr(boxId)); - x2 = x; - x2 += direction * 192; - - for (i = 0; i < 2; i++) - { - u8 spriteId = CreateSprite(&template, i * 32 + x2, 28, 24); - - gPSSData->nextBoxTitleSprites[i] = &gSprites[spriteId]; - gPSSData->nextBoxTitleSprites[i]->data[0] = (-direction) * 6; - gPSSData->nextBoxTitleSprites[i]->data[1] = i * 32 + x; - gPSSData->nextBoxTitleSprites[i]->data[2] = 0; - gPSSData->nextBoxTitleSprites[i]->callback = sub_8091E84; - StartSpriteAnim(gPSSData->nextBoxTitleSprites[i], i); - - gPSSData->curBoxTitleSprites[i]->data[0] = (-direction) * 6; - gPSSData->curBoxTitleSprites[i]->data[1] = 1; - gPSSData->curBoxTitleSprites[i]->callback = sub_8091EB8; - } -} - -static void sub_8091E34(void) -{ - if (gPSSData->boxTitleCycleId == 0) - FreeSpriteTilesByTag(TAG_TILE_4); - else - FreeSpriteTilesByTag(TAG_TILE_3); - - gPSSData->curBoxTitleSprites[0] = gPSSData->nextBoxTitleSprites[0]; - gPSSData->curBoxTitleSprites[1] = gPSSData->nextBoxTitleSprites[1]; -} - -static void sub_8091E84(struct Sprite *sprite) -{ - if (sprite->data[2] != 0) - sprite->data[2]--; - else if ((sprite->x += sprite->data[0]) == sprite->data[1]) - sprite->callback = SpriteCallbackDummy; -} - -static void sub_8091EB8(struct Sprite *sprite) -{ - if (sprite->data[1] != 0) - { - sprite->data[1]--; - } - else - { - sprite->x += sprite->data[0]; - sprite->data[2] = sprite->x + sprite->x2; - if (sprite->data[2] < 0x40 || sprite->data[2] > 0x100) - DestroySprite(sprite); - } -} - -static void CycleBoxTitleColor(void) -{ - u8 boxId = StorageGetCurrentBox(); - u8 wallpaperId = GetBoxWallpaper(boxId); - if (gPSSData->boxTitleCycleId == 0) - CpuCopy16(sBoxTitleColors[wallpaperId], gPlttBufferUnfaded + gPSSData->boxTitlePalOffset, 4); - else - CpuCopy16(sBoxTitleColors[wallpaperId], gPlttBufferUnfaded + gPSSData->boxTitleAltPalOffset, 4); -} - -static s16 GetBoxTitleBaseX(const u8 *string) -{ - return DISPLAY_WIDTH - 64 - GetStringWidth(FONT_1, string, 0) / 2; -} - - -//------------------------------------------------------------------------------ -// SECTION: Scroll arrows -//------------------------------------------------------------------------------ - - -// Sprite data for box scroll arrows -#define sState data[0] -#define sTimer data[1] -#define sSpeed data[3] - -static void CreateBoxScrollArrows(void) -{ - u16 i; - - LoadSpriteSheet(&sSpriteSheet_Arrow); - for (i = 0; i < 2; i++) - { - u8 spriteId = CreateSprite(&sSpriteTemplate_Arrow, 92 + i * 136, 28, 22); - if (spriteId != MAX_SPRITES) - { - struct Sprite *sprite = &gSprites[spriteId]; - StartSpriteAnim(sprite, i); - sprite->data[3] = (i == 0) ? -1 : 1; - gPSSData->arrowSprites[i] = sprite; - } - } - if (IsCursorOnBoxTitle()) - AnimateBoxScrollArrows(TRUE); -} - -// Slide box scroll arrows horizontally for box change -static void StartBoxScrollArrowsSlide(s8 direction) -{ - u16 i; - - for (i = 0; i < 2; i++) - { - gPSSData->arrowSprites[i]->x2 = 0; - gPSSData->arrowSprites[i]->sState = 2; - } - if (direction < 0) - { - gPSSData->arrowSprites[0]->sTimer = 29; - gPSSData->arrowSprites[1]->sTimer = 5; - gPSSData->arrowSprites[0]->data[2] = 72; - gPSSData->arrowSprites[1]->data[2] = 72; - } - else - { - gPSSData->arrowSprites[0]->sTimer = 5; - gPSSData->arrowSprites[1]->sTimer = 29; - gPSSData->arrowSprites[0]->data[2] = DISPLAY_WIDTH + 8; - gPSSData->arrowSprites[1]->data[2] = DISPLAY_WIDTH + 8; - } - gPSSData->arrowSprites[0]->data[7] = 0; - gPSSData->arrowSprites[1]->data[7] = 1; -} - -// New box's scroll arrows have entered, stop sliding and set their position -static void StopBoxScrollArrowsSlide(void) -{ - u16 i; - - for (i = 0; i < 2; i++) - { - gPSSData->arrowSprites[i]->x = 136 * i + 92; - gPSSData->arrowSprites[i]->x2 = 0; - gPSSData->arrowSprites[i]->invisible = FALSE; - } - AnimateBoxScrollArrows(TRUE); -} - -// Bounce scroll arrows while title is selected -void AnimateBoxScrollArrows(bool8 animate) -{ - u16 i; - - if (animate) - { - // Start arrows moving - for (i = 0; i < 2; i++) - { - gPSSData->arrowSprites[i]->sState = 1; - gPSSData->arrowSprites[i]->sTimer = 0; - gPSSData->arrowSprites[i]->data[2] = 0; - gPSSData->arrowSprites[i]->data[4] = 0; - } - } - else - { - // Stop arrows moving - for (i = 0; i < 2; i++) - gPSSData->arrowSprites[i]->sState = 0; - } -} - -static void SpriteCB_Arrow(struct Sprite *sprite) -{ - switch (sprite->sState) - { - case 0: - sprite->x2 = 0; - break; - case 1: - if (++sprite->sTimer > 3) - { - sprite->sTimer = 0; - sprite->x2 += sprite->sSpeed; - if (++sprite->data[2] > 5) - { - sprite->data[2] = 0; - sprite->x2 = 0; - } - } - break; - case 2: - sprite->sState = 3; - break; - case 3: - sprite->x -= gPSSData->scrollSpeed; - if (sprite->x <= 72 || sprite->x >= DISPLAY_WIDTH + 8) - sprite->invisible = TRUE; - if (--sprite->sTimer == 0) - { - sprite->x = sprite->data[2]; - sprite->invisible = FALSE; - sprite->sState = 4; - } - break; - case 4: - sprite->x -= gPSSData->scrollSpeed; - break; - } -} - -#undef sState -#undef sSpeed - -// Arrows for Deposit/Jump Box selection -struct Sprite *CreateChooseBoxArrows(u16 x, u16 y, u8 animId, u8 priority, u8 subpriority) -{ - u8 spriteId = CreateSprite(&sSpriteTemplate_Arrow, x, y, subpriority); - if (spriteId == MAX_SPRITES) - return NULL; - - animId %= 2; - StartSpriteAnim(&gSprites[spriteId], animId); - gSprites[spriteId].oam.priority = priority; - gSprites[spriteId].callback = SpriteCallbackDummy; - return &gSprites[spriteId]; -} diff --git a/src/pokemon_storage_system_5.c b/src/pokemon_storage_system_5.c deleted file mode 100644 index 8074b57c4..000000000 --- a/src/pokemon_storage_system_5.c +++ /dev/null @@ -1,2036 +0,0 @@ -#include "global.h" -#include "gflib.h" -#include "data.h" -#include "item.h" -#include "mail_data.h" -#include "pokemon_storage_system_internal.h" -#include "pokemon_summary_screen.h" -#include "strings.h" -#include "constants/items.h" -#include "constants/moves.h" - -static EWRAM_DATA struct Pokemon sMonBeingCarried = {}; -static EWRAM_DATA s8 sBoxCursorArea = 0; -static EWRAM_DATA s8 sBoxCursorPosition = 0; -static EWRAM_DATA bool8 sIsMonBeingMoved = FALSE; -static EWRAM_DATA u8 sMovingMonOrigBoxId = 0; -static EWRAM_DATA u8 sMovingMonOrigBoxPos = 0; -static EWRAM_DATA bool8 sCanOnlyMove = FALSE; -static EWRAM_DATA u8 gUnknown_2039826 = 0; - -static void sub_80929B0(void); -static bool8 MonPlaceChange_Move(void); -static bool8 MonPlaceChange_Place(void); -static bool8 MonPlaceChange_Shift(void); -static bool8 sub_8092E00(void); -static bool8 sub_8092E10(void); -static bool8 sub_8092E20(void); -static bool8 sub_8092E54(void); -static void MoveMon(void); -static void PlaceMon(void); -static void SetMovedMonData(u8 boxId, u8 cursorPos); -static void SetPlacedMonData(u8 boxId, u8 cursorPos); -static void PurgeMonOrBoxMon(u8 boxId, u8 cursorPos); -static void SetShiftedMonData(u8 boxId, u8 cursorPos); -static void sub_8093A10(void); -static void SetCursorMonData(void *cursorMon, u8 mode); -static void sub_8093AAC(void); -static u8 InBoxInput_Normal(void); -static u8 InBoxInput_GrabbingMultiple(void); -static u8 InBoxInput_MovingMultiple(void); -static void AddBoxMenu(void); -static bool8 sub_8094924(void); -static bool8 sub_809494C(void); -static bool8 sub_8094A0C(void); -static void sub_8094AD8(void); -static void sub_8094C84(void); - -static const u16 sHandCursorPalette[] = INCBIN_U16("graphics/interface/pss_unk_83D2BCC.gbapal"); -static const u16 sHandCursorTiles[] = INCBIN_U16("graphics/interface/pss_unk_83D2BEC.4bpp"); -static const u16 sHandCursorShadowTiles[] = INCBIN_U16("graphics/interface/pss_unk_83D33EC.4bpp"); - -void sub_80922C0(void) -{ - if (gPSSData->boxOption != OPTION_DEPOSIT) - sBoxCursorArea = CURSOR_AREA_IN_BOX; - else - sBoxCursorArea = CURSOR_AREA_IN_PARTY; - - sBoxCursorPosition = 0; - sIsMonBeingMoved = FALSE; - sMovingMonOrigBoxId = 0; - sMovingMonOrigBoxPos = 0; - sCanOnlyMove = FALSE; - sub_8092B50(); - sub_8094AD8(); - gPSSData->cursorPrevHorizPos = 1; - gPSSData->inBoxMovingMode = 0; - sub_8093A10(); -} - -void sub_8092340(void) -{ - sub_8094AD8(); - sub_8093AAC(); - gPSSData->cursorPrevHorizPos = 1; - gPSSData->inBoxMovingMode = 0; - if (sIsMonBeingMoved) - { - gPSSData->movingMon = sMonBeingCarried; - CreateMovingMonIcon(); - } -} - -static void sub_8092398(u8 cursorArea, u8 cursorPosition, u16 *x, u16 *y) -{ - switch (cursorArea) - { - case CURSOR_AREA_IN_BOX: - *x = (cursorPosition % IN_BOX_ROWS) * 24 + 100; - *y = (cursorPosition / IN_BOX_ROWS) * 24 + 32; - break; - case CURSOR_AREA_IN_PARTY: - if (cursorPosition == 0) - { - *x = 0x68; - *y = 0x34; - } - else if (cursorPosition == PARTY_SIZE) - { - *x = 0x98; - *y = 0x84; - } - else - { - *x = 0x98; - *y = (cursorPosition - 1) * 24 + 4; - } - break; - case CURSOR_AREA_BOX: - *x = 0xa2; - *y = 0x0c; - break; - case CURSOR_AREA_BUTTONS: - *y = sIsMonBeingMoved ? 8 : 14; - *x = cursorPosition * 0x58 + 0x78; - break; - case 4: - *x = 0xa0; - *y = 0x60; - break; - } -} - -static u16 sub_8092458(void) -{ - switch (sBoxCursorArea) - { - case CURSOR_AREA_IN_PARTY: - return GetMonData(&gPlayerParty[sBoxCursorPosition], MON_DATA_SPECIES); - case CURSOR_AREA_IN_BOX: - return GetCurrentBoxMonData(sBoxCursorPosition, MON_DATA_SPECIES); - default: - return SPECIES_NONE; - } -} - -bool8 sub_80924A8(void) -{ - s16 tmp; - - if (gPSSData->cursorMoveSteps == 0) - { - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - return FALSE; - else - return sub_809610C(); - } - else if (--gPSSData->cursorMoveSteps != 0) - { - gPSSData->cursorNewX += gPSSData->cursorSpeedX; - gPSSData->cursorNewY += gPSSData->cursorSpeedY; - gPSSData->cursorSprite->x = gPSSData->cursorNewX >> 8; - gPSSData->cursorSprite->y = gPSSData->cursorNewY >> 8; - if (gPSSData->cursorSprite->x > 0x100) - { - tmp = gPSSData->cursorSprite->x - 0x100; - gPSSData->cursorSprite->x = tmp + 0x40; - } - if (gPSSData->cursorSprite->x < 0x40) - { - tmp = 0x40 - gPSSData->cursorSprite->x; - gPSSData->cursorSprite->x = 0x100 - tmp; - } - if (gPSSData->cursorSprite->y > 0xb0) - { - tmp = gPSSData->cursorSprite->y - 0xb0; - gPSSData->cursorSprite->y = tmp - 0x10; - } - if (gPSSData->cursorSprite->y < -0x10) - { - tmp = -0x10 - gPSSData->cursorSprite->y; - gPSSData->cursorSprite->y = 0xb0 - tmp; - } - if (gPSSData->cursorFlipTimer && --gPSSData->cursorFlipTimer == 0) - gPSSData->cursorSprite->vFlip = (gPSSData->cursorSprite->vFlip == FALSE); - } - else - { - gPSSData->cursorSprite->x = gPSSData->cursorTargetX; - gPSSData->cursorSprite->y = gPSSData->cursorTargetY; - sub_80929B0(); - } - - return TRUE; -} - -static void sub_8092604(u8 newCurosrArea, u8 newCursorPosition) -{ - u16 x, y; - - sub_8092398(newCurosrArea, newCursorPosition, &x, &y); - gPSSData->newCursorArea = newCurosrArea; - gPSSData->newCursorPosition = newCursorPosition; - gPSSData->cursorTargetX = x; - gPSSData->cursorTargetY = y; -} - -static void sub_8092660(void) -{ - int r7, r0; - - if (gPSSData->cursorVerticalWrap != 0 || gPSSData->cursorHorizontalWrap != 0) - gPSSData->cursorMoveSteps = 12; - else - gPSSData->cursorMoveSteps = 6; - - if (gPSSData->cursorFlipTimer) - gPSSData->cursorFlipTimer = gPSSData->cursorMoveSteps >> 1; - - switch (gPSSData->cursorVerticalWrap) - { - default: - r7 = gPSSData->cursorTargetY - gPSSData->cursorSprite->y; - break; - case -1: - r7 = gPSSData->cursorTargetY - 0xc0 - gPSSData->cursorSprite->y; - break; - case 1: - r7 = gPSSData->cursorTargetY + 0xc0 - gPSSData->cursorSprite->y; - break; - } - - switch (gPSSData->cursorHorizontalWrap) - { - default: - r0 = gPSSData->cursorTargetX - gPSSData->cursorSprite->x; - break; - case -1: - r0 = gPSSData->cursorTargetX - 0xc0 - gPSSData->cursorSprite->x; - break; - case 1: - r0 = gPSSData->cursorTargetX + 0xc0 - gPSSData->cursorSprite->x; - break; - } - - r7 <<= 8; - r0 <<= 8; - gPSSData->cursorSpeedX = r0 / gPSSData->cursorMoveSteps; - gPSSData->cursorSpeedY = r7 / gPSSData->cursorMoveSteps; - gPSSData->cursorNewX = gPSSData->cursorSprite->x << 8; - gPSSData->cursorNewY = gPSSData->cursorSprite->y << 8; -} - -static void sub_80927E8(u8 newCurosrArea, u8 newCursorPosition) -{ - sub_8092604(newCurosrArea, newCursorPosition); - sub_8092660(); - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - { - if (gPSSData->inBoxMovingMode == 0 && !sIsMonBeingMoved) - StartSpriteAnim(gPSSData->cursorSprite, 1); - } - else - { - if (!IsActiveItemMoving()) - StartSpriteAnim(gPSSData->cursorSprite, 1); - } - - if (gPSSData->boxOption == OPTION_MOVE_ITEMS) - { - if (sBoxCursorArea == CURSOR_AREA_IN_BOX) - sub_8095D44(CURSOR_AREA_IN_BOX, sBoxCursorPosition); - else if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) - sub_8095D44(CURSOR_AREA_IN_PARTY, sBoxCursorPosition); - - if (newCurosrArea == CURSOR_AREA_IN_BOX) - sub_8095C84(newCurosrArea, newCursorPosition); - else if (newCurosrArea == CURSOR_AREA_IN_PARTY) - sub_8095C84(newCurosrArea, newCursorPosition); - } - - if (newCurosrArea == CURSOR_AREA_IN_PARTY && sBoxCursorArea != CURSOR_AREA_IN_PARTY) - { - gPSSData->cursorPrevHorizPos = newCurosrArea; - gPSSData->cursorShadowSprite->invisible = TRUE; - } - - switch (newCurosrArea) - { - case CURSOR_AREA_IN_PARTY: - case CURSOR_AREA_BOX: - case CURSOR_AREA_BUTTONS: - gPSSData->cursorSprite->oam.priority = 1; - gPSSData->cursorShadowSprite->invisible = TRUE; - gPSSData->cursorShadowSprite->oam.priority = 1; - break; - case CURSOR_AREA_IN_BOX: - if (gPSSData->inBoxMovingMode != 0) - { - gPSSData->cursorSprite->oam.priority = 0; - gPSSData->cursorShadowSprite->invisible = TRUE; - } - else - { - gPSSData->cursorSprite->oam.priority = 2; - if (sBoxCursorArea == CURSOR_AREA_IN_BOX && sIsMonBeingMoved) - SetMovingMonPriority(2); - } - break; - } -} - -static void sub_80929B0(void) -{ - sBoxCursorArea = gPSSData->newCursorArea; - sBoxCursorPosition = gPSSData->newCursorPosition; - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - { - if (gPSSData->inBoxMovingMode == 0 && !sIsMonBeingMoved) - StartSpriteAnim(gPSSData->cursorSprite, 1); - } - else - { - if (!IsActiveItemMoving()) - StartSpriteAnim(gPSSData->cursorSprite, 1); - } - - sub_8093A10(); - switch (sBoxCursorArea) - { - case CURSOR_AREA_BUTTONS: - SetMovingMonPriority(1); - break; - case CURSOR_AREA_BOX: - AnimateBoxScrollArrows(TRUE); - break; - case CURSOR_AREA_IN_PARTY: - gPSSData->cursorShadowSprite->subpriority = 13; - SetMovingMonPriority(1); - break; - case CURSOR_AREA_IN_BOX: - if (gPSSData->inBoxMovingMode == 0) - { - gPSSData->cursorSprite->oam.priority = 1; - gPSSData->cursorShadowSprite->oam.priority = 2; - gPSSData->cursorShadowSprite->subpriority = 21; - gPSSData->cursorShadowSprite->invisible = FALSE; - SetMovingMonPriority(2); - } - break; - } -} - -void sub_8092AE4(void) -{ - u8 partyCount; - - if (!sIsMonBeingMoved) - { - partyCount = 0; - } - else - { - partyCount = CalculatePlayerPartyCount(); - if (partyCount >= PARTY_SIZE) - partyCount = PARTY_SIZE - 1; - } - if (gPSSData->cursorSprite->vFlip) - gPSSData->cursorFlipTimer = 1; - sub_80927E8(CURSOR_AREA_IN_PARTY, partyCount); -} - -void sub_8092B3C(u8 cursorBoxPosition) -{ - sub_80927E8(CURSOR_AREA_IN_BOX, cursorBoxPosition); -} - -void sub_8092B50(void) -{ - gUnknown_2039826 = 0; -} - -void sub_8092B5C(void) -{ - gUnknown_2039826 = sBoxCursorPosition; -} - -u8 sub_8092B70(void) -{ - return gUnknown_2039826; -} - -void InitMonPlaceChange(u8 a0) -{ - static bool8 (*const placeChangeFuncs[])(void) = { - MonPlaceChange_Move, - MonPlaceChange_Place, - MonPlaceChange_Shift, - }; - - gPSSData->monPlaceChangeFunc = placeChangeFuncs[a0]; - gPSSData->monPlaceChangeState = 0; -} - -void sub_8092BAC(bool8 arg0) -{ - if (!arg0) - gPSSData->monPlaceChangeFunc = sub_8092E00; - else - gPSSData->monPlaceChangeFunc = sub_8092E10; - - gPSSData->monPlaceChangeState = 0; -} - -bool8 DoMonPlaceChange(void) -{ - return gPSSData->monPlaceChangeFunc(); -} - -static bool8 MonPlaceChange_Move(void) -{ - switch (gPSSData->monPlaceChangeState) - { - case 0: - if (sIsMonBeingMoved) - return FALSE; - StartSpriteAnim(gPSSData->cursorSprite, 2); - gPSSData->monPlaceChangeState++; - break; - case 1: - if (!sub_8092E20()) - { - StartSpriteAnim(gPSSData->cursorSprite, 3); - MoveMon(); - gPSSData->monPlaceChangeState++; - } - break; - case 2: - if (!sub_8092E54()) - gPSSData->monPlaceChangeState++; - break; - case 3: - return FALSE; - } - - return TRUE; -} - -static bool8 MonPlaceChange_Place(void) -{ - switch (gPSSData->monPlaceChangeState) - { - case 0: - if (!sub_8092E20()) - { - StartSpriteAnim(gPSSData->cursorSprite, 2); - PlaceMon(); - gPSSData->monPlaceChangeState++; - } - break; - case 1: - if (!sub_8092E54()) - { - StartSpriteAnim(gPSSData->cursorSprite, 0); - gPSSData->monPlaceChangeState++; - } - break; - case 2: - return FALSE; - } - - return TRUE; -} - -static bool8 MonPlaceChange_Shift(void) -{ - switch (gPSSData->monPlaceChangeState) - { - case 0: - switch (sBoxCursorArea) - { - case CURSOR_AREA_IN_PARTY: - gPSSData->shiftBoxId = TOTAL_BOXES_COUNT; - break; - case CURSOR_AREA_IN_BOX: - gPSSData->shiftBoxId = StorageGetCurrentBox(); - break; - default: - return FALSE; - } - StartSpriteAnim(gPSSData->cursorSprite, 2); - sub_8090E08(gPSSData->shiftBoxId, sBoxCursorPosition); - gPSSData->monPlaceChangeState++; - break; - case 1: - if (!sub_8090E74()) - { - StartSpriteAnim(gPSSData->cursorSprite, 3); - SetShiftedMonData(gPSSData->shiftBoxId, sBoxCursorPosition); - gPSSData->monPlaceChangeState++; - } - break; - case 2: - return FALSE; - } - - return TRUE; -} - -static bool8 sub_8092E00(void) -{ - return sub_8092E20(); -} - -static bool8 sub_8092E10(void) -{ - return sub_8092E54(); -} - -static bool8 sub_8092E20(void) -{ - switch (gPSSData->cursorSprite->y2) - { - default: - gPSSData->cursorSprite->y2++; - break; - case 0: - gPSSData->cursorSprite->y2++; - break; - case 8: - return FALSE; - } - - return TRUE; -} - -static bool8 sub_8092E54(void) -{ - switch (gPSSData->cursorSprite->y2) - { - case 0: - return FALSE; - default: - gPSSData->cursorSprite->y2--; - break; - } - - return TRUE; -} - -static void MoveMon(void) -{ - switch (sBoxCursorArea) - { - case CURSOR_AREA_IN_PARTY: - SetMovedMonData(TOTAL_BOXES_COUNT, sBoxCursorPosition); - sub_8090CC0(MODE_PARTY, sBoxCursorPosition); - break; - case CURSOR_AREA_IN_BOX: - if (gPSSData->inBoxMovingMode == 0) - { - SetMovedMonData(StorageGetCurrentBox(), sBoxCursorPosition); - sub_8090CC0(MODE_BOX, sBoxCursorPosition); - } - break; - default: - return; - } - - sIsMonBeingMoved = TRUE; -} - -static void PlaceMon(void) -{ - u8 boxId; - - switch (sBoxCursorArea) - { - case CURSOR_AREA_IN_PARTY: - SetPlacedMonData(TOTAL_BOXES_COUNT, sBoxCursorPosition); - sub_8090D58(TOTAL_BOXES_COUNT, sBoxCursorPosition); - break; - case CURSOR_AREA_IN_BOX: - boxId = StorageGetCurrentBox(); - SetPlacedMonData(boxId, sBoxCursorPosition); - sub_8090D58(boxId, sBoxCursorPosition); - break; - default: - return; - } - - sIsMonBeingMoved = FALSE; -} - -void sub_8092F54(void) -{ - sub_8093A10(); -} - -static void SetMovedMonData(u8 boxId, u8 position) -{ - if (boxId == TOTAL_BOXES_COUNT) - gPSSData->movingMon = gPlayerParty[sBoxCursorPosition]; - else - BoxMonAtToMon(boxId, position, &gPSSData->movingMon); - - PurgeMonOrBoxMon(boxId, position); - sMovingMonOrigBoxId = boxId; - sMovingMonOrigBoxPos = position; -} - -static void SetPlacedMonData(u8 boxId, u8 position) -{ - if (boxId == TOTAL_BOXES_COUNT) - { - gPlayerParty[position] = gPSSData->movingMon; - } - else - { - BoxMonRestorePP(&gPSSData->movingMon.box); - SetBoxMonAt(boxId, position, &gPSSData->movingMon.box); - } -} - -static void PurgeMonOrBoxMon(u8 boxId, u8 position) -{ - if (boxId == TOTAL_BOXES_COUNT) - ZeroMonData(&gPlayerParty[position]); - else - ZeroBoxMonAt(boxId, position); -} - -static void SetShiftedMonData(u8 boxId, u8 position) -{ - if (boxId == TOTAL_BOXES_COUNT) - gPSSData->field_2108 = gPlayerParty[position]; - else - BoxMonAtToMon(boxId, position, &gPSSData->field_2108); - - SetPlacedMonData(boxId, position); - gPSSData->movingMon = gPSSData->field_2108; - SetCursorMonData(&gPSSData->movingMon, MODE_PARTY); - sMovingMonOrigBoxId = boxId; - sMovingMonOrigBoxPos = position; -} - -bool8 TryStorePartyMonInBox(u8 boxId) -{ - s16 boxPosition = GetFirstFreeBoxSpot(boxId); - if (boxPosition == -1) - return FALSE; - - if (sIsMonBeingMoved) - { - SetPlacedMonData(boxId, boxPosition); - DestroyMovingMonIcon(); - sIsMonBeingMoved = FALSE; - } - else - { - SetMovedMonData(TOTAL_BOXES_COUNT, sBoxCursorPosition); - SetPlacedMonData(boxId, boxPosition); - DestroyPartyMonIcon(sBoxCursorPosition); - } - - if (boxId == StorageGetCurrentBox()) - sub_80901EC(boxPosition); - - StartSpriteAnim(gPSSData->cursorSprite, 1); - return TRUE; -} - -void sub_8093174(void) -{ - StartSpriteAnim(gPSSData->cursorSprite, 0); - sub_8093A10(); -} - -void sub_8093194(void) -{ - u8 mode; - - if (sIsMonBeingMoved) - mode = MODE_2; - else if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) - mode = MODE_PARTY; - else - mode = MODE_BOX; - - sub_8090FC4(mode, sBoxCursorPosition); - StringCopy(gPSSData->field_21E0, gPSSData->displayMonName); -} - -bool8 sub_80931EC(void) -{ - if (!sub_8091084()) - { - StartSpriteAnim(gPSSData->cursorSprite, 0); - return FALSE; - } - else - { - return TRUE; - } -} - -void ReleaseMon(void) -{ - u8 boxId; - - sub_80910CC(); - if (sIsMonBeingMoved) - { - sIsMonBeingMoved = FALSE; - } - else - { - if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) - boxId = TOTAL_BOXES_COUNT; - else - boxId = StorageGetCurrentBox(); - - PurgeMonOrBoxMon(boxId, sBoxCursorPosition); - } - sub_8093A10(); -} - -void sub_8093264(void) -{ - if (sIsMonBeingMoved) - StartSpriteAnim(gPSSData->cursorSprite, 3); -} - -void InitCanReleaseMonVars(void) -{ - u16 knownIdx; - if (sIsMonBeingMoved) - { - gPSSData->field_2108 = gPSSData->movingMon; - gPSSData->field_2170 = -1; - gPSSData->field_2171 = -1; - } - else - { - if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) - { - gPSSData->field_2108 = gPlayerParty[sBoxCursorPosition]; - gPSSData->field_2170 = TOTAL_BOXES_COUNT; - } - else - { - BoxMonAtToMon(StorageGetCurrentBox(), sBoxCursorPosition, &gPSSData->field_2108); - gPSSData->field_2170 = StorageGetCurrentBox(); - } - gPSSData->field_2171 = sBoxCursorPosition; - } - - gPSSData->isSurfMon = FALSE; - gPSSData->isDiveMon = FALSE; - gPSSData->field_2176[0] = MOVE_SURF; - gPSSData->field_2176[1] = MOVE_DIVE; - gPSSData->field_2176[2] = MOVES_COUNT; - knownIdx = GetMonData(&gPSSData->field_2108, MON_DATA_KNOWN_MOVES, (u8 *)gPSSData->field_2176); - gPSSData->isSurfMon = knownIdx & 1; - gPSSData->isDiveMon = (knownIdx >> 1) & 1; - if (gPSSData->isSurfMon || gPSSData->isDiveMon) - { - gPSSData->field_216D = 0; - } - else - { - gPSSData->field_216D = 1; - gPSSData->field_216C = 1; - } - - gPSSData->field_2172 = 0; -} - -s8 RunCanReleaseMon(void) -{ - u16 i; - u16 knownMoves; - - if (gPSSData->field_216D) - return gPSSData->field_216C; - - switch (gPSSData->field_2172) - { - case 0: - for (i = 0; i < PARTY_SIZE; i++) - { - if (gPSSData->field_2170 != TOTAL_BOXES_COUNT || gPSSData->field_2171 != i) - { - knownMoves = GetMonData(gPlayerParty + i, MON_DATA_KNOWN_MOVES, (u8 *)gPSSData->field_2176); - if (knownMoves & 1) - gPSSData->isSurfMon = FALSE; - if (knownMoves & 2) - gPSSData->isDiveMon = FALSE; - } - } - if (!(gPSSData->isSurfMon || gPSSData->isDiveMon)) - { - gPSSData->field_216D = 1; - gPSSData->field_216C = 1; - } - else - { - gPSSData->field_216E = 0; - gPSSData->field_216F = 0; - gPSSData->field_2172++; - } - break; - case 1: - for (i = 0; i < 5; i++) - { - knownMoves = GetAndCopyBoxMonDataAt(gPSSData->field_216E, gPSSData->field_216F, MON_DATA_KNOWN_MOVES, (u8 *)gPSSData->field_2176); - if (knownMoves != 0 - && !(gPSSData->field_2170 == gPSSData->field_216E && gPSSData->field_2171 == gPSSData->field_216F)) - { - if (knownMoves & 1) - gPSSData->isSurfMon = FALSE; - if (knownMoves & 2) - gPSSData->isDiveMon = FALSE; - } - if (++gPSSData->field_216F >= IN_BOX_COUNT) - { - gPSSData->field_216F = 0; - if (++gPSSData->field_216E >= TOTAL_BOXES_COUNT) - { - gPSSData->field_216D = 1; - gPSSData->field_216C = 0; - break; - } - } - } - if (!(gPSSData->isSurfMon || gPSSData->isDiveMon)) - { - gPSSData->field_216D = 1; - gPSSData->field_216C = 1; - } - break; - } - - return -1; -} - -void sub_8093630(void) -{ - if (sIsMonBeingMoved) - sMonBeingCarried = gPSSData->movingMon; -} - -void sub_8093660(void) -{ - if (sIsMonBeingMoved) - { - if (sMovingMonOrigBoxId == TOTAL_BOXES_COUNT) - gPSSData->movingMon = sMonBeingCarried; - else - gPSSData->movingMon.box = sMonBeingCarried.box; - } -} - -void sub_80936B8(void) -{ - if (sIsMonBeingMoved) - { - sub_8093630(); - gPSSData->field_218C.mon = &sMonBeingCarried; - gPSSData->field_2187 = 0; - gPSSData->field_2186 = 0; - gPSSData->summaryScreenMode = PSS_MODE_NORMAL; - } - else if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) - { - gPSSData->field_218C.mon = gPlayerParty; - gPSSData->field_2187 = sBoxCursorPosition; - gPSSData->field_2186 = CountPartyMons() - 1; - gPSSData->summaryScreenMode = PSS_MODE_NORMAL; - } - else - { - gPSSData->field_218C.box = GetBoxedMonPtr(StorageGetCurrentBox(), 0); - gPSSData->field_2187 = sBoxCursorPosition; - gPSSData->field_2186 = IN_BOX_COUNT - 1; - gPSSData->summaryScreenMode = PSS_MODE_BOX; - } -} - -void sub_80937B4(void) -{ - if (sIsMonBeingMoved) - sub_8093660(); - else - sBoxCursorPosition = GetLastViewedMonIndex(); -} - -// file boundary maybe? - -s16 CompactPartySlots(void) -{ - s16 retVal = -1; - u16 i, last; - - for (i = 0, last = 0; i < PARTY_SIZE; i++) - { - u16 species = GetMonData(gPlayerParty + i, MON_DATA_SPECIES); - if (species != SPECIES_NONE) - { - if (i != last) - gPlayerParty[last] = gPlayerParty[i]; - last++; - } - else if (retVal == -1) - { - retVal = i; - } - } - for (; last < PARTY_SIZE; last++) - ZeroMonData(gPlayerParty + last); - - return retVal; -} - -void SetMonMarkings(u8 markings) -{ - gPSSData->displayMonMarkings = markings; - if (sIsMonBeingMoved) - { - SetMonData(&gPSSData->movingMon, MON_DATA_MARKINGS, &markings); - } - else - { - if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) - SetMonData(gPlayerParty + sBoxCursorPosition, MON_DATA_MARKINGS, &markings); - if (sBoxCursorArea == CURSOR_AREA_IN_BOX) - SetCurrentBoxMonData(sBoxCursorPosition, MON_DATA_MARKINGS, &markings); - } -} - -bool8 CanMovePartyMon(void) -{ - if (sBoxCursorArea == CURSOR_AREA_IN_PARTY && !sIsMonBeingMoved && CountPartyAliveNonEggMonsExcept(sBoxCursorPosition) == 0) - return TRUE; - else - return FALSE; -} - -bool8 CanShiftMon(void) -{ - if (sIsMonBeingMoved) - { - if (sBoxCursorArea == CURSOR_AREA_IN_PARTY && CountPartyAliveNonEggMonsExcept(sBoxCursorPosition) == 0) - { - if (gPSSData->displayMonIsEgg || GetMonData(&gPSSData->movingMon, MON_DATA_HP) == 0) - return FALSE; - } - return TRUE; - } - return FALSE; -} - -bool8 IsMonBeingMoved(void) -{ - return sIsMonBeingMoved; -} - -bool8 IsCursorOnBoxTitle(void) -{ - return (sBoxCursorArea == CURSOR_AREA_BOX); -} - -bool8 IsCursorOnCloseBox(void) -{ - return (sBoxCursorArea == CURSOR_AREA_BUTTONS && sBoxCursorPosition == 1); -} - -bool8 IsCursorInBox(void) -{ - return (sBoxCursorArea == CURSOR_AREA_IN_BOX); -} - -static void sub_8093A10(void) -{ - gPSSData->setMosaic = (sIsMonBeingMoved == FALSE); - if (!sIsMonBeingMoved) - { - switch (sBoxCursorArea) - { - case CURSOR_AREA_IN_PARTY: - if (sBoxCursorPosition < PARTY_SIZE) - { - SetCursorMonData(&gPlayerParty[sBoxCursorPosition], MODE_PARTY); - break; - } - // fallthrough - case CURSOR_AREA_BUTTONS: - case CURSOR_AREA_BOX: - SetCursorMonData(NULL, MODE_2); - break; - case CURSOR_AREA_IN_BOX: - SetCursorMonData(GetBoxedMonPtr(StorageGetCurrentBox(), sBoxCursorPosition), MODE_BOX); - break; - } - } -} - -static void sub_8093AAC(void) -{ - if (sIsMonBeingMoved) - SetCursorMonData(&sMonBeingCarried, MODE_PARTY); - else - sub_8093A10(); -} - -static void SetCursorMonData(void *pokemon, u8 mode) -{ - u8 *txtPtr; - u16 gender; - bool8 sanityIsBagEgg; - - gPSSData->displayMonItemId = 0; - gender = MON_MALE; - sanityIsBagEgg = FALSE; - if (mode == MODE_PARTY) - { - struct Pokemon *mon = (struct Pokemon *)pokemon; - - gPSSData->displayMonSpecies = GetMonData(mon, MON_DATA_SPECIES2); - if (gPSSData->displayMonSpecies != SPECIES_NONE) - { - sanityIsBagEgg = GetMonData(mon, MON_DATA_SANITY_IS_BAD_EGG); - if (sanityIsBagEgg) - gPSSData->displayMonIsEgg = TRUE; - else - gPSSData->displayMonIsEgg = GetMonData(mon, MON_DATA_IS_EGG); - - GetMonData(mon, MON_DATA_NICKNAME, gPSSData->displayMonName); - StringGet_Nickname(gPSSData->displayMonName); - gPSSData->displayMonLevel = GetMonData(mon, MON_DATA_LEVEL); - gPSSData->displayMonMarkings = GetMonData(mon, MON_DATA_MARKINGS); - gPSSData->displayMonPersonality = GetMonData(mon, MON_DATA_PERSONALITY); - gPSSData->displayMonPalette = GetMonFrontSpritePal(mon); - gender = GetMonGender(mon); - gPSSData->displayMonItemId = GetMonData(mon, MON_DATA_HELD_ITEM); - } - } - else if (mode == MODE_BOX) - { - struct BoxPokemon *boxMon = (struct BoxPokemon *)pokemon; - - gPSSData->displayMonSpecies = GetBoxMonData(pokemon, MON_DATA_SPECIES2); - if (gPSSData->displayMonSpecies != SPECIES_NONE) - { - u32 otId = GetBoxMonData(boxMon, MON_DATA_OT_ID); - sanityIsBagEgg = GetBoxMonData(boxMon, MON_DATA_SANITY_IS_BAD_EGG); - if (sanityIsBagEgg) - gPSSData->displayMonIsEgg = TRUE; - else - gPSSData->displayMonIsEgg = GetBoxMonData(boxMon, MON_DATA_IS_EGG); - - - GetBoxMonData(boxMon, MON_DATA_NICKNAME, gPSSData->displayMonName); - StringGet_Nickname(gPSSData->displayMonName); - gPSSData->displayMonLevel = GetLevelFromBoxMonExp(boxMon); - gPSSData->displayMonMarkings = GetBoxMonData(boxMon, MON_DATA_MARKINGS); - gPSSData->displayMonPersonality = GetBoxMonData(boxMon, MON_DATA_PERSONALITY); - gPSSData->displayMonPalette = GetMonSpritePalFromSpeciesAndPersonality(gPSSData->displayMonSpecies, otId, gPSSData->displayMonPersonality); - gender = GetGenderFromSpeciesAndPersonality(gPSSData->displayMonSpecies, gPSSData->displayMonPersonality); - gPSSData->displayMonItemId = GetBoxMonData(boxMon, MON_DATA_HELD_ITEM); - } - } - else - { - gPSSData->displayMonSpecies = SPECIES_NONE; - gPSSData->displayMonItemId = 0; - } - - if (gPSSData->displayMonSpecies == SPECIES_NONE) - { - StringFill(gPSSData->displayMonName, CHAR_SPACE, 5); - StringFill(gPSSData->displayMonTexts[0], CHAR_SPACE, 8); - StringFill(gPSSData->displayMonTexts[1], CHAR_SPACE, 8); - StringFill(gPSSData->displayMonTexts[2], CHAR_SPACE, 8); - StringFill(gPSSData->displayMonTexts[3], CHAR_SPACE, 8); - } - else if (gPSSData->displayMonIsEgg) - { - if (sanityIsBagEgg) - StringCopyPadded(gPSSData->displayMonTexts[0], gPSSData->displayMonName, CHAR_SPACE, 5); - else - StringCopyPadded(gPSSData->displayMonTexts[0], gText_EggNickname, CHAR_SPACE, 8); - - StringFill(gPSSData->displayMonTexts[1], CHAR_SPACE, 8); - StringFill(gPSSData->displayMonTexts[2], CHAR_SPACE, 8); - StringFill(gPSSData->displayMonTexts[3], CHAR_SPACE, 8); - } - else - { - if (gPSSData->displayMonSpecies == SPECIES_NIDORAN_F || gPSSData->displayMonSpecies == SPECIES_NIDORAN_M) - gender = MON_GENDERLESS; - - StringCopyPadded(gPSSData->displayMonTexts[0], gPSSData->displayMonName, CHAR_SPACE, 5); - - txtPtr = gPSSData->displayMonTexts[1]; - *(txtPtr)++ = CHAR_SLASH; - StringCopyPadded(txtPtr, gSpeciesNames[gPSSData->displayMonSpecies], CHAR_SPACE, 5); - - txtPtr = gPSSData->displayMonTexts[2]; - *(txtPtr)++ = EXT_CTRL_CODE_BEGIN; - *(txtPtr)++ = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; - switch (gender) - { - case MON_MALE: - *(txtPtr)++ = TEXT_COLOR_RED; - *(txtPtr)++ = TEXT_COLOR_WHITE; - *(txtPtr)++ = TEXT_COLOR_LIGHT_RED; - *(txtPtr)++ = CHAR_MALE; - break; - case MON_FEMALE: - *(txtPtr)++ = TEXT_COLOR_GREEN; - *(txtPtr)++ = TEXT_COLOR_WHITE; - *(txtPtr)++ = TEXT_COLOR_LIGHT_GREEN; - *(txtPtr)++ = CHAR_FEMALE; - break; - default: - *(txtPtr)++ = TEXT_COLOR_DARK_GRAY; - *(txtPtr)++ = TEXT_COLOR_WHITE; - *(txtPtr)++ = TEXT_COLOR_LIGHT_GRAY; - *(txtPtr)++ = CHAR_SPACE; - break; - } - - *(txtPtr++) = EXT_CTRL_CODE_BEGIN; - *(txtPtr++) = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; - *(txtPtr++) = TEXT_COLOR_DARK_GRAY; - *(txtPtr++) = TEXT_COLOR_WHITE; - *(txtPtr++) = TEXT_COLOR_LIGHT_GRAY; - *(txtPtr++) = CHAR_SPACE; - *(txtPtr++) = CHAR_EXTRA_SYMBOL; - *(txtPtr++) = 5; // LV_2 - - txtPtr = ConvertIntToDecimalStringN(txtPtr, gPSSData->displayMonLevel, STR_CONV_MODE_LEFT_ALIGN, 3); - txtPtr[0] = CHAR_SPACE; - txtPtr[1] = EOS; - - if (gPSSData->displayMonItemId != 0) - StringCopyPadded(gPSSData->displayMonTexts[3], ItemId_GetName(gPSSData->displayMonItemId), CHAR_SPACE, 8); - else - StringFill(gPSSData->displayMonTexts[3], CHAR_SPACE, 8); - } -} - -static u8 HandleInput_InBox(void) -{ - switch (gPSSData->inBoxMovingMode) - { - case 0: - default: - return InBoxInput_Normal(); - case 1: - return InBoxInput_GrabbingMultiple(); - case 2: - return InBoxInput_MovingMultiple(); - } -} - -static u8 InBoxInput_Normal(void) -{ - u8 retVal; - s8 cursorArea; - s8 cursorPosition; - - do - { - cursorArea = sBoxCursorArea; - cursorPosition = sBoxCursorPosition; - gPSSData->cursorVerticalWrap = 0; - gPSSData->cursorHorizontalWrap = 0; - gPSSData->cursorFlipTimer = 0; - if (JOY_REPT(DPAD_UP)) - { - retVal = TRUE; - if (sBoxCursorPosition >= IN_BOX_ROWS) - { - cursorPosition -= IN_BOX_ROWS; - } - else - { - cursorArea = CURSOR_AREA_BOX; - cursorPosition = 0; - } - break; - } - else if (JOY_REPT(DPAD_DOWN)) - { - retVal = TRUE; - cursorPosition += IN_BOX_ROWS; - if (cursorPosition >= IN_BOX_COUNT) - { - cursorArea = CURSOR_AREA_BUTTONS; - cursorPosition -= IN_BOX_COUNT; - cursorPosition /= 3; - gPSSData->cursorVerticalWrap = 1; - gPSSData->cursorFlipTimer = 1; - } - break; - } - else if (JOY_REPT(DPAD_LEFT)) - { - retVal = TRUE; - if (sBoxCursorPosition % IN_BOX_ROWS != 0) - { - cursorPosition--; - } - else - { - gPSSData->cursorHorizontalWrap = -1; - cursorPosition += (IN_BOX_ROWS - 1); - } - break; - } - else if (JOY_REPT(DPAD_RIGHT)) - { - retVal = TRUE; - if ((sBoxCursorPosition + 1) % IN_BOX_ROWS != 0) - { - cursorPosition++; - } - else - { - gPSSData->cursorHorizontalWrap = 1; - cursorPosition -= (IN_BOX_ROWS - 1); - } - break; - } - else if (JOY_NEW(START_BUTTON)) - { - retVal = TRUE; - cursorArea = CURSOR_AREA_BOX; - cursorPosition = 0; - break; - } - - if ((JOY_NEW(A_BUTTON)) && sub_8094924()) - { - if (!sCanOnlyMove) - return 8; - - if (gPSSData->boxOption != OPTION_MOVE_MONS || sIsMonBeingMoved == TRUE) - { - switch (sub_8094E50(0)) - { - case PC_TEXT_STORE: - return 11; - case PC_TEXT_WITHDRAW: - return 12; - case PC_TEXT_MOVE: - return 13; - case PC_TEXT_SHIFT: - return 14; - case PC_TEXT_PLACE: - return 15; - case PC_TEXT_TAKE: - return 16; - case PC_TEXT_GIVE: - return 17; - case PC_TEXT_SWITCH: - return 18; - } - } - else - { - gPSSData->inBoxMovingMode = 1; - return 20; - } - } - - if (JOY_NEW(B_BUTTON)) - return 19; - - if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) - { - if (JOY_HELD(L_BUTTON)) - return 10; - if (JOY_HELD(R_BUTTON)) - return 9; - } - - if (JOY_NEW(SELECT_BUTTON)) - { - sub_8094C84(); - return 0; - } - - retVal = 0; - - } while (0); - - if (retVal) - sub_80927E8(cursorArea, cursorPosition); - - return retVal; -} - -static u8 InBoxInput_GrabbingMultiple(void) -{ - if (JOY_HELD(A_BUTTON)) - { - if (JOY_REPT(DPAD_UP)) - { - if (sBoxCursorPosition / IN_BOX_ROWS != 0) - { - sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition - IN_BOX_ROWS); - return 21; - } - else - { - return 24; - } - } - else if (JOY_REPT(DPAD_DOWN)) - { - if (sBoxCursorPosition + IN_BOX_ROWS < IN_BOX_COUNT) - { - sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition + IN_BOX_ROWS); - return 21; - } - else - { - return 24; - } - } - else if (JOY_REPT(DPAD_LEFT)) - { - if (sBoxCursorPosition % IN_BOX_ROWS != 0) - { - sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition - 1); - return 21; - } - else - { - return 24; - } - } - else if (JOY_REPT(DPAD_RIGHT)) - { - if ((sBoxCursorPosition + 1) % IN_BOX_ROWS != 0) - { - sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition + 1); - return 21; - } - else - { - return 24; - } - } - else - { - return 0; - } - } - else - { - if (sub_8095AA0() == sBoxCursorPosition) - { - gPSSData->inBoxMovingMode = 0; - gPSSData->cursorShadowSprite->invisible = FALSE; - return 22; - } - else - { - sIsMonBeingMoved = (gPSSData->displayMonSpecies != SPECIES_NONE); - gPSSData->inBoxMovingMode = 2; - sMovingMonOrigBoxId = StorageGetCurrentBox(); - return 23; - } - } -} - -static u8 InBoxInput_MovingMultiple(void) -{ - if (JOY_REPT(DPAD_UP)) - { - if (sub_8095474(0)) - { - sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition - IN_BOX_ROWS); - return 25; - } - else - { - return 24; - } - } - else if (JOY_REPT(DPAD_DOWN)) - { - if (sub_8095474(1)) - { - sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition + IN_BOX_ROWS); - return 25; - } - else - { - return 24; - } - } - else if (JOY_REPT(DPAD_LEFT)) - { - if (sub_8095474(2)) - { - sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition - 1); - return 25; - } - else - { - return 10; - } - } - else if (JOY_REPT(DPAD_RIGHT)) - { - if (sub_8095474(3)) - { - sub_80927E8(CURSOR_AREA_IN_BOX, sBoxCursorPosition + 1); - return 25; - } - else - { - return 9; - } - } - else if (JOY_NEW(A_BUTTON)) - { - if (sub_8095ABC()) - { - sIsMonBeingMoved = FALSE; - gPSSData->inBoxMovingMode = 0; - return 26; - } - else - { - return 24; - } - } - else if (JOY_NEW(B_BUTTON)) - { - return 24; - } - else - { - if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) - { - if (JOY_HELD(L_BUTTON)) - return 10; - if (JOY_HELD(R_BUTTON)) - return 9; - } - - return 0; - } -} - -static u8 HandleInput_InParty(void) -{ - u8 retVal; - bool8 gotoBox; - s8 cursorArea; - s8 cursorPosition; - - do - { - cursorArea = sBoxCursorArea; - cursorPosition = sBoxCursorPosition; - gPSSData->cursorHorizontalWrap = 0; - gPSSData->cursorVerticalWrap = 0; - gPSSData->cursorFlipTimer = 0; - gotoBox = FALSE; - retVal = 0; - - if (JOY_REPT(DPAD_UP)) - { - if (--cursorPosition < 0) - cursorPosition = PARTY_SIZE; - if (cursorPosition != sBoxCursorPosition) - retVal = 1; - break; - } - else if (JOY_REPT(DPAD_DOWN)) - { - if (++cursorPosition > PARTY_SIZE) - cursorPosition = 0; - if (cursorPosition != sBoxCursorPosition) - retVal = 1; - break; - } - else if (JOY_REPT(DPAD_LEFT) && sBoxCursorPosition != 0) - { - retVal = 1; - gPSSData->cursorPrevHorizPos = sBoxCursorPosition; - cursorPosition = 0; - break; - } - else if (JOY_REPT(DPAD_RIGHT)) - { - if (sBoxCursorPosition == 0) - { - retVal = 1; - cursorPosition = gPSSData->cursorPrevHorizPos; - } - else - { - retVal = 6; - cursorArea = CURSOR_AREA_IN_BOX; - cursorPosition = 0; - } - break; - } - - if (JOY_NEW(A_BUTTON)) - { - if (sBoxCursorPosition == PARTY_SIZE) - { - if (gPSSData->boxOption == OPTION_DEPOSIT) - return 4; - - gotoBox = TRUE; - } - else if (sub_8094924()) - { - if (!sCanOnlyMove) - return 8; - - switch (sub_8094E50(0)) - { - case PC_TEXT_STORE: - return 11; - case PC_TEXT_WITHDRAW: - return 12; - case PC_TEXT_MOVE: - return 13; - case PC_TEXT_SHIFT: - return 14; - case PC_TEXT_PLACE: - return 15; - case PC_TEXT_TAKE: - return 16; - case PC_TEXT_GIVE: - return 17; - case PC_TEXT_SWITCH: - return 18; - } - } - } - - if (JOY_NEW(B_BUTTON)) - { - if (gPSSData->boxOption == OPTION_DEPOSIT) - return 19; - - gotoBox = TRUE; - } - - if (gotoBox) - { - retVal = 6; - cursorArea = CURSOR_AREA_IN_BOX; - cursorPosition = 0; - } - else if (JOY_NEW(SELECT_BUTTON)) - { - sub_8094C84(); - return 0; - } - - } while (0); - - if (retVal != 0) - { - if (retVal != 6) - sub_80927E8(cursorArea, cursorPosition); - } - - return retVal; -} - -static u8 HandleInput_OnBox(void) -{ - u8 retVal; - s8 cursorArea; - s8 cursorPosition; - - do - { - gPSSData->cursorHorizontalWrap = 0; - gPSSData->cursorVerticalWrap = 0; - gPSSData->cursorFlipTimer = 0; - - if (JOY_REPT(DPAD_UP)) - { - retVal = 1; - cursorArea = CURSOR_AREA_BUTTONS; - cursorPosition = 0; - gPSSData->cursorFlipTimer = 1; - break; - } - else if (JOY_REPT(DPAD_DOWN)) - { - retVal = 1; - cursorArea = CURSOR_AREA_IN_BOX; - cursorPosition = 2; - break; - } - - if (JOY_HELD(DPAD_LEFT)) - return 10; - if (JOY_HELD(DPAD_RIGHT)) - return 9; - - if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) - { - if (JOY_HELD(L_BUTTON)) - return 10; - if (JOY_HELD(R_BUTTON)) - return 9; - } - - if (JOY_NEW(A_BUTTON)) - { - AnimateBoxScrollArrows(FALSE); - AddBoxMenu(); - return 7; - } - - if (JOY_NEW(B_BUTTON)) - return 19; - - if (JOY_NEW(SELECT_BUTTON)) - { - sub_8094C84(); - return 0; - } - - retVal = 0; - - } while (0); - - if (retVal) - { - if (cursorArea != CURSOR_AREA_BOX) - AnimateBoxScrollArrows(FALSE); - sub_80927E8(cursorArea, cursorPosition); - } - - return retVal; -} - -static u8 HandleInput_OnButtons(void) -{ - u8 retVal; - s8 cursorArea; - s8 cursorPosition; - s8 prevPos; - - do - { - cursorArea = sBoxCursorArea; - cursorPosition = sBoxCursorPosition; - gPSSData->cursorHorizontalWrap = 0; - gPSSData->cursorVerticalWrap = 0; - gPSSData->cursorFlipTimer = 0; - - if (JOY_REPT(DPAD_UP)) - { - retVal = 1; - cursorArea = CURSOR_AREA_IN_BOX; - gPSSData->cursorVerticalWrap = -1; - if (sBoxCursorPosition == 0) - cursorPosition = IN_BOX_COUNT - 1 - 5; - else - cursorPosition = IN_BOX_COUNT - 1; - gPSSData->cursorFlipTimer = 1; - break; - } - else if (JOY_REPT(DPAD_DOWN | START_BUTTON)) - { - retVal = 1; - cursorArea = CURSOR_AREA_BOX; - cursorPosition = 0; - gPSSData->cursorFlipTimer = 1; - break; - } - - if (JOY_REPT(DPAD_LEFT)) - { - retVal = 1; - if (--cursorPosition < 0) - cursorPosition = 1; - break; - } - else if (JOY_REPT(DPAD_RIGHT)) - { - retVal = 1; - if (++cursorPosition > 1) - cursorPosition = 0; - break; - } - - if (JOY_NEW(A_BUTTON)) - { - return cursorPosition == 0 ? 5 : 4; - } - if (JOY_NEW(B_BUTTON)) - return 19; - - if (JOY_NEW(SELECT_BUTTON)) - { - sub_8094C84(); - return 0; - } - - retVal = 0; - } while (0); - - if (retVal != 0) - sub_80927E8(cursorArea, cursorPosition); - - return retVal; -} - -u8 HandleInput(void) -{ - struct - { - u8 (*func)(void); - s8 area; - } - static const inputFuncs[] = { - {HandleInput_InBox, CURSOR_AREA_IN_BOX}, - {HandleInput_InParty, CURSOR_AREA_IN_PARTY}, - {HandleInput_OnBox, CURSOR_AREA_BOX}, - {HandleInput_OnButtons, CURSOR_AREA_BUTTONS}, - {NULL, 0}, - }; - - u16 i = 0; - while (inputFuncs[i].func != NULL) - { - if (inputFuncs[i].area == sBoxCursorArea) - return inputFuncs[i].func(); - i++; - } - - return 0; -} - -static void AddBoxMenu(void) -{ - InitMenu(); - SetMenuText(PC_TEXT_JUMP); - SetMenuText(PC_TEXT_WALLPAPER); - SetMenuText(PC_TEXT_NAME); - SetMenuText(PC_TEXT_CANCEL); -} - -static bool8 sub_8094924(void) -{ - InitMenu(); - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - return sub_809494C(); - else - return sub_8094A0C(); -} - -static bool8 sub_809494C(void) -{ - u16 var0 = sub_8092458(); - - switch (gPSSData->boxOption) - { - case OPTION_DEPOSIT: - if (var0) - SetMenuText(PC_TEXT_STORE); - else - return FALSE; - break; - case OPTION_WITHDRAW: - if (var0) - SetMenuText(PC_TEXT_WITHDRAW); - else - return FALSE; - break; - case OPTION_MOVE_MONS: - if (sIsMonBeingMoved) - { - if (var0) - SetMenuText(PC_TEXT_SHIFT); - else - SetMenuText(PC_TEXT_PLACE); - } - else - { - if (var0) - SetMenuText(PC_TEXT_MOVE); - else - return FALSE; - } - break; - case OPTION_MOVE_ITEMS: - default: - return FALSE; - } - - SetMenuText(PC_TEXT_SUMMARY); - if (gPSSData->boxOption == OPTION_MOVE_MONS) - { - if (!sBoxCursorArea) - SetMenuText(PC_TEXT_WITHDRAW); - else - SetMenuText(PC_TEXT_STORE); - } - - SetMenuText(PC_TEXT_MARK); - SetMenuText(PC_TEXT_RELEASE); - SetMenuText(PC_TEXT_CANCEL); - return TRUE; -} - -static bool8 sub_8094A0C(void) -{ - if (gPSSData->displayMonSpecies == SPECIES_EGG) - return FALSE; - - if (!IsActiveItemMoving()) - { - if (gPSSData->displayMonItemId == ITEM_NONE) - { - if (gPSSData->displayMonSpecies == SPECIES_NONE) - return FALSE; - - SetMenuText(PC_TEXT_GIVE2); - } - else - { - if (!ItemIsMail(gPSSData->displayMonItemId)) - { - SetMenuText(PC_TEXT_TAKE); - SetMenuText(PC_TEXT_BAG); - } - SetMenuText(PC_TEXT_INFO); - } - } - else - { - if (gPSSData->displayMonItemId == ITEM_NONE) - { - if (gPSSData->displayMonSpecies == SPECIES_NONE) - return FALSE; - - SetMenuText(PC_TEXT_GIVE); - } - else - { - if (ItemIsMail(gPSSData->displayMonItemId) == TRUE) - return FALSE; - - SetMenuText(PC_TEXT_SWITCH); - } - } - - SetMenuText(PC_TEXT_CANCEL); - return TRUE; -} - -static void sub_8094AB8(struct Sprite *sprite) -{ - sprite->x = gPSSData->cursorSprite->x; - sprite->y = gPSSData->cursorSprite->y + 20; -} - -static void sub_8094AD8(void) -{ - u16 x, y; - u8 spriteId; - u8 priority, subpriority; - struct SpriteSheet spriteSheets[] = { - {sHandCursorTiles, 0x800, TAG_TILE_0}, - {sHandCursorShadowTiles, 0x80, TAG_TILE_1}, - {} - }; - - struct SpritePalette spritePalettes[] = { - {sHandCursorPalette, TAG_PAL_DAC7}, - {} - }; - - static const struct OamData sOamData_857BA0C = { - .shape = SPRITE_SHAPE(32x32), - .size = SPRITE_SIZE(32x32), - .priority = 1, - }; - static const struct OamData sOamData_857BA14 = { - .shape = SPRITE_SHAPE(16x16), - .size = SPRITE_SIZE(16x16), - .priority = 1, - }; - - static const union AnimCmd sSpriteAnim_857BA1C[] = { - ANIMCMD_FRAME(0, 30), - ANIMCMD_FRAME(16, 30), - ANIMCMD_JUMP(0) - }; - static const union AnimCmd sSpriteAnim_857BA28[] = { - ANIMCMD_FRAME(0, 5), - ANIMCMD_END - }; - static const union AnimCmd sSpriteAnim_857BA30[] = { - ANIMCMD_FRAME(32, 5), - ANIMCMD_END - }; - static const union AnimCmd sSpriteAnim_857BA38[] = { - ANIMCMD_FRAME(48, 5), - ANIMCMD_END - }; - - static const union AnimCmd *const sSpriteAnimTable_857BA40[] = { - sSpriteAnim_857BA1C, - sSpriteAnim_857BA28, - sSpriteAnim_857BA30, - sSpriteAnim_857BA38 - }; - - static const struct SpriteTemplate gSpriteTemplate_857BA50 = { - .tileTag = TAG_TILE_0, - .paletteTag = TAG_PAL_WAVEFORM, - .oam = &sOamData_857BA0C, - .anims = sSpriteAnimTable_857BA40, - .images = NULL, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = SpriteCallbackDummy, - }; - - static const struct SpriteTemplate gSpriteTemplate_857BA68 = { - .tileTag = TAG_TILE_1, - .paletteTag = TAG_PAL_WAVEFORM, - .oam = &sOamData_857BA14, - .anims = gDummySpriteAnimTable, - .images = NULL, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_8094AB8, - }; - - LoadSpriteSheets(spriteSheets); - LoadSpritePalettes(spritePalettes); - gPSSData->cursorPalNums[0] = IndexOfSpritePaletteTag(TAG_PAL_WAVEFORM); - gPSSData->cursorPalNums[1] = IndexOfSpritePaletteTag(TAG_PAL_DAC7); - - sub_8092398(sBoxCursorArea, sBoxCursorPosition, &x, &y); - spriteId = CreateSprite(&gSpriteTemplate_857BA50, x, y, 6); - if (spriteId != MAX_SPRITES) - { - gPSSData->cursorSprite = &gSprites[spriteId]; - gPSSData->cursorSprite->oam.paletteNum = gPSSData->cursorPalNums[sCanOnlyMove]; - gPSSData->cursorSprite->oam.priority = 1; - if (sIsMonBeingMoved) - StartSpriteAnim(gPSSData->cursorSprite, 3); - } - else - { - gPSSData->cursorSprite = NULL; - } - - if (sBoxCursorArea == CURSOR_AREA_IN_PARTY) - { - subpriority = 13; - priority = 1; - } - else - { - subpriority = 21; - priority = 2; - } - - spriteId = CreateSprite(&gSpriteTemplate_857BA68, 0, 0, subpriority); - if (spriteId != MAX_SPRITES) - { - gPSSData->cursorShadowSprite = &gSprites[spriteId]; - gPSSData->cursorShadowSprite->oam.priority = priority; - if (sBoxCursorArea) - gPSSData->cursorShadowSprite->invisible = 1; - } - else - { - gPSSData->cursorShadowSprite = NULL; - } -} - -static void sub_8094C84(void) -{ - sCanOnlyMove = !sCanOnlyMove; - gPSSData->cursorSprite->oam.paletteNum = gPSSData->cursorPalNums[sCanOnlyMove]; -} - -u8 GetBoxCursorPosition(void) -{ - return sBoxCursorPosition; -} - -void sub_8094CD4(u8 *arg0, u8 *arg1) -{ - if (sBoxCursorArea == CURSOR_AREA_IN_BOX) - { - *arg0 = sBoxCursorPosition % IN_BOX_ROWS; - *arg1 = sBoxCursorPosition / IN_BOX_ROWS; - } - else - { - *arg0 = 0; - *arg1 = 0; - } -} - -void sub_8094D14(u8 animNum) -{ - StartSpriteAnim(gPSSData->cursorSprite, animNum); -} - -u8 sub_8094D34(void) -{ - return sMovingMonOrigBoxId; -} - -void sub_8094D40(void) -{ - gPSSData->cursorSprite->oam.priority = 1; -} - -void sub_8094D60(void) -{ - if (sBoxCursorArea == CURSOR_AREA_IN_BOX) - sub_8095D44(CURSOR_AREA_IN_BOX, sBoxCursorPosition); -} - -void sub_8094D84(void) -{ - if (sBoxCursorArea == CURSOR_AREA_IN_BOX) - sub_8095C84(CURSOR_AREA_IN_BOX, sBoxCursorPosition); -} diff --git a/src/pokemon_storage_system_6.c b/src/pokemon_storage_system_6.c deleted file mode 100644 index 6b8b4f67d..000000000 --- a/src/pokemon_storage_system_6.c +++ /dev/null @@ -1,147 +0,0 @@ -#include "global.h" -#include "gflib.h" -#include "menu.h" -#include "new_menu_helpers.h" -#include "pokemon_storage_system_internal.h" -#include "strings.h" -#include "constants/songs.h" - -void InitMenu(void) -{ - gPSSData->menuItemsCount = 0; - gPSSData->menuWidth = 0; - gPSSData->menuWindow.bg = 0; - gPSSData->menuWindow.paletteNum = 15; - gPSSData->menuWindow.baseBlock = 92; -} - -static const u8 *const sMenuTexts[] = { - [PC_TEXT_CANCEL] = gPCText_Cancel, - [PC_TEXT_STORE] = gPCText_Store, - [PC_TEXT_WITHDRAW] = gPCText_Withdraw, - [PC_TEXT_MOVE] = gPCText_Move, - [PC_TEXT_SHIFT] = gPCText_Shift, - [PC_TEXT_PLACE] = gPCText_Place, - [PC_TEXT_SUMMARY] = gPCText_Summary, - [PC_TEXT_RELEASE] = gPCText_Release, - [PC_TEXT_MARK] = gPCText_Mark, - [PC_TEXT_JUMP] = gPCText_Jump, - [PC_TEXT_WALLPAPER] = gPCText_Wallpaper, - [PC_TEXT_NAME] = gPCText_Name, - [PC_TEXT_TAKE] = gPCText_Take, - [PC_TEXT_GIVE] = gPCText_Give, - [PC_TEXT_GIVE2] = gPCText_Give, - [PC_TEXT_SWITCH] = gPCText_Switch, - [PC_TEXT_BAG] = gPCText_Bag, - [PC_TEXT_INFO] = gPCText_Info, - [PC_TEXT_SCENERY1] = gPCText_Scenery1, - [PC_TEXT_SCENERY2] = gPCText_Scenery2, - [PC_TEXT_SCENERY3] = gPCText_Scenery3, - [PC_TEXT_ETCETERA] = gPCText_Etcetera, - [PC_TEXT_FOREST] = gPCText_Forest, - [PC_TEXT_CITY] = gPCText_City, - [PC_TEXT_DESERT] = gPCText_Desert, - [PC_TEXT_SAVANNA] = gPCText_Savanna, - [PC_TEXT_CRAG] = gPCText_Crag, - [PC_TEXT_VOLCANO] = gPCText_Volcano, - [PC_TEXT_SNOW] = gPCText_Snow, - [PC_TEXT_CAVE] = gPCText_Cave, - [PC_TEXT_BEACH] = gPCText_Beach, - [PC_TEXT_SEAFLOOR] = gPCText_Seafloor, - [PC_TEXT_RIVER] = gPCText_River, - [PC_TEXT_SKY] = gPCText_Sky, - [PC_TEXT_POLKADOT] = gPCText_PolkaDot, - [PC_TEXT_POKECENTER] = gPCText_Pokecenter, - [PC_TEXT_MACHINE] = gPCText_Machine, - [PC_TEXT_SIMPLE] = gPCText_Simple, -}; - -void SetMenuText(u8 textId) -{ - if (gPSSData->menuItemsCount < ARRAY_COUNT(gPSSData->menuItems)) - { - u8 len; - struct StorageMenu *menu = &gPSSData->menuItems[gPSSData->menuItemsCount]; - - menu->text = sMenuTexts[textId]; - menu->textId = textId; - len = StringLength(menu->text); - if (len > gPSSData->menuWidth) - gPSSData->menuWidth = len; - - gPSSData->menuItemsCount++; - } -} - -s8 sub_8094E50(u8 arg0) -{ - if (arg0 >= gPSSData->menuItemsCount) - return -1; - else - return gPSSData->menuItems[arg0].textId; -} - -void AddMenu(void) -{ - gPSSData->menuWindow.width = gPSSData->menuWidth + 2; - gPSSData->menuWindow.height = 2 * gPSSData->menuItemsCount; - gPSSData->menuWindow.tilemapLeft = 29 - gPSSData->menuWindow.width; - gPSSData->menuWindow.tilemapTop = 15 - gPSSData->menuWindow.height; - gPSSData->menuWindowId = AddWindow(&gPSSData->menuWindow); - ClearWindowTilemap(gPSSData->menuWindowId); - DrawStdFrameWithCustomTileAndPalette(gPSSData->menuWindowId, FALSE, 0x00b, 14); - PrintTextArray(gPSSData->menuWindowId, FONT_1, 8, 2, 16, gPSSData->menuItemsCount, (void *)gPSSData->menuItems); - Menu_InitCursor(gPSSData->menuWindowId, FONT_1, 0, 2, 16, gPSSData->menuItemsCount, 0); - ScheduleBgCopyTilemapToVram(0); - gPSSData->menuUnusedField = 0; -} - -bool8 sub_8094F90(void) -{ - // Some debug flag? - return FALSE; -} - -s16 sub_8094F94(void) -{ - s32 textId = -2; - - do - { - if (JOY_NEW(A_BUTTON)) - { - textId = Menu_GetCursorPos(); - break; - } - else if (JOY_NEW(B_BUTTON)) - { - PlaySE(SE_SELECT); - textId = -1; - } - - if (JOY_NEW(DPAD_UP)) - { - PlaySE(SE_SELECT); - Menu_MoveCursor(-1); - } - else if (JOY_NEW(DPAD_DOWN)) - { - PlaySE(SE_SELECT); - Menu_MoveCursor(1); - } - } while (0); - - if (textId != -2) - sub_8095024(); - - if (textId >= 0) - textId = gPSSData->menuItems[textId].textId; - - return textId; -} - -void sub_8095024(void) -{ - ClearStdWindowAndFrameToTransparent(gPSSData->menuWindowId, TRUE); - RemoveWindow(gPSSData->menuWindowId); -} diff --git a/src/pokemon_storage_system_7.c b/src/pokemon_storage_system_7.c deleted file mode 100644 index 95d199172..000000000 --- a/src/pokemon_storage_system_7.c +++ /dev/null @@ -1,586 +0,0 @@ -#include // to declare abs -#include "global.h" -#include "gflib.h" -#include "pokemon_icon.h" -#include "pokemon_storage_system_internal.h" -#include "text_window.h" - -struct MoveMons -{ - u8 field_0; - u8 state; - u8 fromRow; - u8 fromColumn; - u8 toRow; - u8 toColumn; - u8 field_6; - u8 field_7; - u8 minRow; - u8 minColumn; - u8 rowsTotal; - u8 columsTotal; - u16 bgX; - u16 bgY; - u16 field_10; - struct BoxPokemon boxMons[IN_BOX_COUNT]; -}; - -static EWRAM_DATA struct MoveMons *sMoveMonsPtr = NULL; - -static bool8 sub_8095138(void); -static bool8 sub_8095234(void); -static bool8 sub_80952A0(void); -static bool8 sub_8095314(void); -static bool8 sub_8095394(void); -static bool8 sub_80953BC(void); -static void sub_8095520(void); -static void sub_80955C4(u8 arg0, u8 arg1, u8 arg2); -static void sub_80955FC(u8 arg0, u8 arg1, u8 arg2); -static void sub_8095634(u8 arg0, u8 arg1, u8 arg2); -static void sub_809566C(u8 arg0, u8 arg1, u8 arg2); -static void sub_80956A4(u8 x, u8 y); -static void sub_809572C(u8 x, u8 y); -static void sub_8095780(u16 bgX, u16 bgY, u16 duration); -static u8 sub_8095790(void); -static void sub_80957C8(void); -static void sub_80958A0(void); -static void sub_8095918(void); -static void sub_80959A8(void); -static void sub_8095A58(void); - -static const struct WindowTemplate gUnknown_83D35D4 = { - .bg = 0, - .tilemapLeft = 10, - .tilemapTop = 3, - .width = 20, - .height = 18, - .paletteNum = 9, - .baseBlock = 0x00a -}; - -bool8 sub_8095050(void) -{ - sMoveMonsPtr = Alloc(sizeof(*sMoveMonsPtr)); - if (sMoveMonsPtr != NULL) - { - gPSSData->field_2200 = AddWindow8Bit(&gUnknown_83D35D4); - if (gPSSData->field_2200 != 0xFF) - { - FillWindowPixelBuffer(gPSSData->field_2200, PIXEL_FILL(0)); - return TRUE; - } - } - - return FALSE; -} - -void sub_80950A4(void) -{ - if (sMoveMonsPtr != NULL) - Free(sMoveMonsPtr); -} - -void sub_80950BC(u8 arg0) -{ - sMoveMonsPtr->field_0 = arg0; - sMoveMonsPtr->state = 0; -} - -bool8 sub_80950D0(void) -{ - switch (sMoveMonsPtr->field_0) - { - case 0: - return sub_8095138(); - case 1: - return sub_8095234(); - case 2: - return sub_80952A0(); - case 3: - return sub_8095314(); - case 4: - return sub_8095394(); - case 5: - return sub_80953BC(); - } - - return FALSE; -} - -static bool8 sub_8095138(void) -{ - switch (sMoveMonsPtr->state) - { - case 0: - HideBg(0); - LoadMonIconPalettesAt(0x80); - sMoveMonsPtr->state++; - break; - case 1: - sub_8094CD4(&sMoveMonsPtr->fromRow, &sMoveMonsPtr->fromColumn); - sMoveMonsPtr->toRow = sMoveMonsPtr->fromRow; - sMoveMonsPtr->toColumn = sMoveMonsPtr->fromColumn; - ChangeBgX(0, -1024, 0); - ChangeBgY(0, -1024, 0); - FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 0x20, 0x20); - FillWindowPixelBuffer8Bit(gPSSData->field_2200, PIXEL_FILL(0)); - sub_80956A4(sMoveMonsPtr->fromRow, sMoveMonsPtr->fromColumn); - SetBgAttribute(0, BG_ATTR_PALETTEMODE, 1); - PutWindowTilemap(gPSSData->field_2200); - CopyWindowToVram8Bit(gPSSData->field_2200, COPYWIN_FULL); - BlendPalettes(0x3F00, 8, RGB_WHITE); - sub_8094D14(2); - SetGpuRegBits(REG_OFFSET_BG0CNT, BGCNT_256COLOR); - sMoveMonsPtr->state++; - break; - case 2: - if (!IsDma3ManagerBusyWithBgCopy()) - { - ShowBg(0); - return FALSE; - } - break; - } - - return TRUE; -} - -static bool8 sub_8095234(void) -{ - switch (sMoveMonsPtr->state) - { - case 0: - HideBg(0); - sMoveMonsPtr->state++; - break; - case 1: - sub_8095A58(); - sub_8094D14(0); - sMoveMonsPtr->state++; - break; - case 2: - if (!IsDma3ManagerBusyWithBgCopy()) - { - sub_8094D40(); - LoadPalette(stdpal_get(3), 0xD0, 0x20); - ShowBg(0); - return FALSE; - } - break; - } - - return TRUE; -} - -static bool8 sub_80952A0(void) -{ - switch (sMoveMonsPtr->state) - { - case 0: - if (!sub_80924A8()) - { - sub_8094CD4(&sMoveMonsPtr->field_6, &sMoveMonsPtr->field_7); - sub_8095520(); - sMoveMonsPtr->toRow = sMoveMonsPtr->field_6; - sMoveMonsPtr->toColumn = sMoveMonsPtr->field_7; - CopyWindowToVram8Bit(gPSSData->field_2200, COPYWIN_GFX); - sMoveMonsPtr->state++; - } - break; - case 1: - return IsDma3ManagerBusyWithBgCopy(); - } - - return TRUE; -} - -static bool8 sub_8095314(void) -{ - u8 var1, var2; - - switch (sMoveMonsPtr->state) - { - case 0: - sub_80957C8(); - sub_80958A0(); - sub_8092BAC(FALSE); - sMoveMonsPtr->state++; - break; - case 1: - if (!DoMonPlaceChange()) - { - sub_8094D14(3); - sub_8095780(0, 256, 8); - sub_8092BAC(TRUE); - sMoveMonsPtr->state++; - } - break; - case 2: - var1 = sub_8095790(); - var2 = DoMonPlaceChange(); - if (!var1 && !var2) - return FALSE; - break; - } - - return TRUE; -} - -static bool8 sub_8095394(void) -{ - u8 var1 = sub_80924A8(); - u8 var2 = sub_8095790(); - - if (!var1 && !var2) - return FALSE; - else - return TRUE; -} - -static bool8 sub_80953BC(void) -{ - switch (sMoveMonsPtr->state) - { - case 0: - sub_80959A8(); - sub_8095780(0, -256, 8); - sub_8092BAC(FALSE); - sMoveMonsPtr->state++; - break; - case 1: - if (!DoMonPlaceChange() && !sub_8095790()) - { - sub_8095918(); - sub_8094D14(2); - sub_8092BAC(TRUE); - HideBg(0); - sMoveMonsPtr->state++; - } - break; - case 2: - if (!DoMonPlaceChange()) - { - sub_8094D14(0); - sub_8095A58(); - sMoveMonsPtr->state++; - } - break; - case 3: - if (!IsDma3ManagerBusyWithBgCopy()) - { - LoadPalette(stdpal_get(3), 0xD0, 0x20); - sub_8094D40(); - ShowBg(0); - return FALSE; - } - break; - } - - return TRUE; -} - -bool8 sub_8095474(u8 arg0) -{ - switch (arg0) - { - case 0: // up - if (sMoveMonsPtr->minColumn == 0) - return FALSE; - sMoveMonsPtr->minColumn--; - sub_8095780(0, 1024, 6); - break; - case 1: // down - if (sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal >= 5) - return FALSE; - sMoveMonsPtr->minColumn++; - sub_8095780(0, -1024, 6); - break; - case 2: // left - if (sMoveMonsPtr->minRow == 0) - return FALSE; - sMoveMonsPtr->minRow--; - sub_8095780(1024, 0, 6); - break; - case 3: // right - if (sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal > 5) - return FALSE; - sMoveMonsPtr->minRow++; - sub_8095780(-1024, 0, 6); - break; - } - - return TRUE; -} - -static void sub_8095520(void) -{ - s16 var = (abs(sMoveMonsPtr->fromRow - sMoveMonsPtr->field_6)) - (abs(sMoveMonsPtr->fromRow - sMoveMonsPtr->toRow)); - s16 var2 = (abs(sMoveMonsPtr->fromColumn - sMoveMonsPtr->field_7)) - (abs(sMoveMonsPtr->fromColumn - sMoveMonsPtr->toColumn)); - - if (var > 0) - sub_80955C4(sMoveMonsPtr->field_6, sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn); - - if (var < 0) - { - sub_8095634(sMoveMonsPtr->toRow, sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn); - sub_80955C4(sMoveMonsPtr->field_6, sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn); - } - - if (var2 > 0) - sub_80955FC(sMoveMonsPtr->field_7, sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); - - if (var2 < 0) - { - sub_809566C(sMoveMonsPtr->toColumn, sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); - sub_80955FC(sMoveMonsPtr->field_7, sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); - } -} - -static void sub_80955C4(u8 arg0, u8 arg1, u8 arg2) -{ - u8 var1 = arg1; - - if (arg1 > arg2) - { - arg1 = arg2; - arg2 = var1; - } - - while (arg1 <= arg2) - sub_80956A4(arg0, arg1++); -} - -static void sub_80955FC(u8 arg0, u8 arg1, u8 arg2) -{ - u8 var1 = arg1; - - if (arg1 > arg2) - { - arg1 = arg2; - arg2 = var1; - } - - while (arg1 <= arg2) - sub_80956A4(arg1++, arg0); -} - -static void sub_8095634(u8 arg0, u8 arg1, u8 arg2) -{ - u8 var1 = arg1; - - if (arg1 > arg2) - { - arg1 = arg2; - arg2 = var1; - } - - while (arg1 <= arg2) - sub_809572C(arg0, arg1++); -} - -static void sub_809566C(u8 arg0, u8 arg1, u8 arg2) -{ - u8 var1 = arg1; - - if (arg1 > arg2) - { - arg1 = arg2; - arg2 = var1; - } - - while (arg1 <= arg2) - sub_809572C(arg1++, arg0); -} - -static void sub_80956A4(u8 x, u8 y) -{ - u8 position = x + (IN_BOX_ROWS * y); - u16 species = GetCurrentBoxMonData(position, MON_DATA_SPECIES2); - u32 personality = GetCurrentBoxMonData(position, MON_DATA_PERSONALITY); - - if (species != SPECIES_NONE) - { - const u8 *iconGfx = GetMonIconPtr(species, personality, 1); - u8 index = GetValidMonIconPalIndex(species) + 8; - - BlitBitmapRectToWindow4BitTo8Bit(gPSSData->field_2200, - iconGfx, - 0, - 0, - 32, - 32, - 24 * x, - 24 * y, - 32, - 32, - index); - } -} - -static void sub_809572C(u8 x, u8 y) -{ - u8 position = x + (IN_BOX_ROWS * y); - u16 species = GetCurrentBoxMonData(position, MON_DATA_SPECIES2); - - if (species != SPECIES_NONE) - { - FillWindowPixelRect8Bit(gPSSData->field_2200, - PIXEL_FILL(0), - 24 * x, - 24 * y, - 32, - 32); - } -} - -static void sub_8095780(u16 bgX, u16 bgY, u16 duration) -{ - sMoveMonsPtr->bgX = bgX; - sMoveMonsPtr->bgY = bgY; - sMoveMonsPtr->field_10 = duration; -} - -static u8 sub_8095790(void) -{ - if (sMoveMonsPtr->field_10 != 0) - { - ChangeBgX(0, sMoveMonsPtr->bgX, 1); - ChangeBgY(0, sMoveMonsPtr->bgY, 1); - sMoveMonsPtr->field_10--; - } - - return sMoveMonsPtr->field_10; -} - -static void sub_80957C8(void) -{ - s32 i, j; - s32 rowCount, columnCount; - u8 boxId; - u8 monArrayId; - - sMoveMonsPtr->minRow = min(sMoveMonsPtr->fromRow, sMoveMonsPtr->toRow); - sMoveMonsPtr->minColumn = min(sMoveMonsPtr->fromColumn, sMoveMonsPtr->toColumn); - sMoveMonsPtr->rowsTotal = abs(sMoveMonsPtr->fromRow - sMoveMonsPtr->toRow) + 1; - sMoveMonsPtr->columsTotal = abs(sMoveMonsPtr->fromColumn - sMoveMonsPtr->toColumn) + 1; - boxId = StorageGetCurrentBox(); - monArrayId = 0; - rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal; - columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal; - for (i = sMoveMonsPtr->minColumn; i < columnCount; i++) - { - u8 boxPosition = (IN_BOX_ROWS * i) + sMoveMonsPtr->minRow; - for (j = sMoveMonsPtr->minRow; j < rowCount; j++) - { - struct BoxPokemon *boxMon = GetBoxedMonPtr(boxId, boxPosition); - // UB: possible null dereference -#ifdef UBFIX - if (boxMon != NULL) - sMoveMonsPtr->boxMons[monArrayId] = *boxMon; -#else - sMoveMonsPtr->boxMons[monArrayId] = *boxMon; -#endif - monArrayId++; - boxPosition++; - } - } -} - -static void sub_80958A0(void) -{ - s32 i, j; - s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal; - s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal; - u8 boxId = StorageGetCurrentBox(); - - for (i = sMoveMonsPtr->minColumn; i < columnCount; i++) - { - u8 boxPosition = (IN_BOX_ROWS * i) + sMoveMonsPtr->minRow; - for (j = sMoveMonsPtr->minRow; j < rowCount; j++) - { - DestroyBoxMonIconAtPosition(boxPosition); - ZeroBoxMonAt(boxId, boxPosition); - boxPosition++; - } - } -} - -static void sub_8095918(void) -{ - s32 i, j; - s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal; - s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal; - u8 monArrayId = 0; - - for (i = sMoveMonsPtr->minColumn; i < columnCount; i++) - { - u8 boxPosition = (IN_BOX_ROWS * i) + sMoveMonsPtr->minRow; - for (j = sMoveMonsPtr->minRow; j < rowCount; j++) - { - if (GetBoxMonData(&sMoveMonsPtr->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES)) - sub_80901EC(boxPosition); - monArrayId++; - boxPosition++; - } - } -} - -static void sub_80959A8(void) -{ - s32 i, j; - s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal; - s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal; - u8 boxId = StorageGetCurrentBox(); - u8 monArrayId = 0; - - for (i = sMoveMonsPtr->minColumn; i < columnCount; i++) - { - u8 boxPosition = (IN_BOX_ROWS * i) + sMoveMonsPtr->minRow; - for (j = sMoveMonsPtr->minRow; j < rowCount; j++) - { - if (GetBoxMonData(&sMoveMonsPtr->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES)) - SetBoxMonAt(boxId, boxPosition, &sMoveMonsPtr->boxMons[monArrayId]); - boxPosition++; - monArrayId++; - } - } -} - -static void sub_8095A58(void) -{ - ChangeBgX(0, 0, 0); - ChangeBgY(0, 0, 0); - SetBgAttribute(0, BG_ATTR_PALETTEMODE, 0); - ClearGpuRegBits(REG_OFFSET_BG0CNT, BGCNT_256COLOR); - FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 32, 32); - CopyBgTilemapBufferToVram(0); -} - -u8 sub_8095AA0(void) -{ - return (IN_BOX_ROWS * sMoveMonsPtr->fromColumn) + sMoveMonsPtr->fromRow; -} - -bool8 sub_8095ABC(void) -{ - s32 i, j; - s32 rowCount = sMoveMonsPtr->minRow + sMoveMonsPtr->rowsTotal; - s32 columnCount = sMoveMonsPtr->minColumn + sMoveMonsPtr->columsTotal; - u8 monArrayId = 0; - - for (i = sMoveMonsPtr->minColumn; i < columnCount; i++) - { - u8 boxPosition = (IN_BOX_ROWS * i) + sMoveMonsPtr->minRow; - for (j = sMoveMonsPtr->minRow; j < rowCount; j++) - { - if (GetBoxMonData(&sMoveMonsPtr->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES) - && GetCurrentBoxMonData(boxPosition, MON_DATA_SANITY_HAS_SPECIES)) - return FALSE; - - monArrayId++; - boxPosition++; - } - } - - return TRUE; -} diff --git a/src/pokemon_storage_system_8.c b/src/pokemon_storage_system_8.c deleted file mode 100644 index cdd7728a2..000000000 --- a/src/pokemon_storage_system_8.c +++ /dev/null @@ -1,877 +0,0 @@ -#include "global.h" -#include "gflib.h" -#include "decompress.h" -#include "item.h" -#include "item_menu_icons.h" -#include "menu.h" -#include "new_menu_helpers.h" -#include "pokemon_storage_system_internal.h" -#include "trig.h" -#include "constants/items.h" - -// IDs for the item icon sprite callbacks -enum { - ITEM_CB_WAIT_ANIM, - ITEM_CB_TO_HAND, - ITEM_CB_TO_MON, - ITEM_CB_SWAP_TO_HAND, - ITEM_CB_SWAP_TO_MON, - ITEM_CB_UNUSED_1, - ITEM_CB_UNUSED_2, - ITEM_CB_HIDE_PARTY, -}; - -static u8 GetNewItemIconIdx(void); -static bool32 IsItemIconAtPosition(u8 cursorArea, u8 cursorPos); -static u8 GetItemIconIdxByPosition(u8 cursorArea, u8 cursorPos); -static void SetItemIconPosition(u8 id, u8 cursorArea, u8 cursorPos); -static void LoadItemIconGfx(u8 id, const u32 * tiles, const u32 * pal); -static void SetItemIconAffineAnim(u8 id, u8 affineAnimNo); -static void SetItemIconCallback(u8 id, u8 command, u8 cursorArea, u8 cursorPos); -static void SetItemIconActive(u8 id, bool8 show); -static const u32 *GetItemIconPic(u16 itemId); -static const u32 *GetItemIconPalette(u16 itemId); -static void DrawItemInfoWindow(u32 x); -static void SpriteCB_ItemIcon_WaitAnim(struct Sprite *sprite); -static void SpriteCB_ItemIcon_ToHand(struct Sprite *sprite); -static void SpriteCB_ItemIcon_SetPosToCursor(struct Sprite *sprite); -static void SpriteCB_ItemIcon_ToMon(struct Sprite *sprite); -static void SpriteCB_ItemIcon_SwapToHand(struct Sprite *sprite); -static void SpriteCB_ItemIcon_SwapToMon(struct Sprite *sprite); -static void SpriteCB_ItemIcon_HideParty(struct Sprite *sprite); - -static const u32 sItemInfoFrame_Gfx[] = INCBIN_U32("graphics/interface/pss_unk_83D35DC.4bpp"); - -static const struct OamData gUnknown_83D365C = { - .y = 0, - .affineMode = ST_OAM_AFFINE_NORMAL, - .objMode = ST_OAM_OBJ_NORMAL, - .mosaic = FALSE, - .bpp = ST_OAM_4BPP, - .shape = SPRITE_SHAPE(32x32), - .x = 0, - .matrixNum = 0, - .size = SPRITE_SIZE(32x32), - .tileNum = 0x000, - .priority = 1, - .paletteNum = 0, - .affineParam = 0 -}; - -static const union AffineAnimCmd gUnknown_83D3664[] = { - AFFINEANIMCMD_FRAME(128, 128, 0, 0), - AFFINEANIMCMD_END -}; - -static const union AffineAnimCmd gUnknown_83D3674[] = { - AFFINEANIMCMD_FRAME(88, 88, 0, 0), - AFFINEANIMCMD_FRAME(5, 5, 0, 8), - AFFINEANIMCMD_END -}; - -static const union AffineAnimCmd gUnknown_83D368C[] = { - AFFINEANIMCMD_FRAME(128, 128, 0, 0), - AFFINEANIMCMD_FRAME(-5, -5, 0, 8), - AFFINEANIMCMD_END -}; - -static const union AffineAnimCmd gUnknown_83D36A4[] = { - AFFINEANIMCMD_FRAME(128, 128, 0, 0), - AFFINEANIMCMD_FRAME(10, 10, 0, 12), - AFFINEANIMCMD_FRAME(256, 256, 0, 0), - AFFINEANIMCMD_END -}; - -static const union AffineAnimCmd gUnknown_83D36C4[] = { - AFFINEANIMCMD_FRAME(256, 256, 0, 0), - AFFINEANIMCMD_FRAME(-10, -10, 0, 12), - AFFINEANIMCMD_FRAME(128, 128, 0, 0), - AFFINEANIMCMD_END -}; - -static const union AffineAnimCmd gUnknown_83D36E4[] = { - AFFINEANIMCMD_FRAME(256, 256, 0, 0), - AFFINEANIMCMD_FRAME(-5, -5, 0, 16), - AFFINEANIMCMD_END -}; - -static const union AffineAnimCmd gUnknown_83D36FC[] = { - AFFINEANIMCMD_FRAME(256, 256, 0, 0), - AFFINEANIMCMD_END -}; - -static const union AffineAnimCmd *const gUnknown_83D370C[] = { - gUnknown_83D3664, - gUnknown_83D3674, - gUnknown_83D368C, - gUnknown_83D36A4, - gUnknown_83D36C4, - gUnknown_83D36E4, - gUnknown_83D36FC -}; - -static const struct SpriteTemplate sSpriteTemplate_ItemIcon = { - .tileTag = TAG_TILE_7, - .paletteTag = TAG_PAL_DACB, - .oam = &gUnknown_83D365C, - .anims = gDummySpriteAnimTable, - .images = NULL, - .affineAnims = gUnknown_83D370C, - .callback = SpriteCallbackDummy, -}; - -void CreateItemIconSprites(void) -{ - s32 i; - u8 spriteId; - struct CompressedSpriteSheet spriteSheet; - struct SpriteTemplate spriteTemplate; - static u32 sItemIconGfxBuffer[0x61]; - - if (gPSSData->boxOption == OPTION_MOVE_ITEMS) - { - spriteSheet.data = sItemIconGfxBuffer; - spriteSheet.size = 0x200; - spriteTemplate = sSpriteTemplate_ItemIcon; - - for (i = 0; i < MAX_ITEM_ICONS; i++) - { - spriteSheet.tag = TAG_TILE_7 + i; - LoadCompressedSpriteSheet(&spriteSheet); - gPSSData->itemIcons[i].tiles = GetSpriteTileStartByTag(spriteSheet.tag) * TILE_SIZE_4BPP + (void *)(OBJ_VRAM0); - gPSSData->itemIcons[i].palIndex = AllocSpritePalette(TAG_PAL_DACB + i); - gPSSData->itemIcons[i].palIndex *= 16; - gPSSData->itemIcons[i].palIndex += 0x100; - spriteTemplate.tileTag = TAG_TILE_7 + i; - spriteTemplate.paletteTag = TAG_PAL_DACB + i; - spriteId = CreateSprite(&spriteTemplate, 0, 0, 11); - gPSSData->itemIcons[i].sprite = &gSprites[spriteId]; - gPSSData->itemIcons[i].sprite->invisible = TRUE; - gPSSData->itemIcons[i].active = FALSE; - } - } - gPSSData->movingItemId = ITEM_NONE; -} - -void sub_8095C84(u8 cursorArea, u8 cursorPos) -{ - u16 heldItem; - - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - return; - if (IsItemIconAtPosition(cursorArea, cursorPos)) - return; - - switch (cursorArea) - { - case CURSOR_AREA_IN_BOX: - if (!GetCurrentBoxMonData(cursorPos, MON_DATA_SANITY_HAS_SPECIES)) - return; - heldItem = GetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM); - break; - case CURSOR_AREA_IN_PARTY: - if (!GetMonData(&gPlayerParty[cursorPos], MON_DATA_SANITY_HAS_SPECIES)) - return; - heldItem = GetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM); - break; - default: - return; - } - - if (heldItem != ITEM_NONE) - { - const u32 *tiles = GetItemIconPic(heldItem); - const u32 *pal = GetItemIconPalette(heldItem); - u8 id = GetNewItemIconIdx(); - - SetItemIconPosition(id, cursorArea, cursorPos); - LoadItemIconGfx(id, tiles, pal); - SetItemIconAffineAnim(id, 1); - SetItemIconActive(id, TRUE); - } -} - -void sub_8095D44(u8 cursorArea, u8 cursorPos) -{ - u8 id; - - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - return; - - id = GetItemIconIdxByPosition(cursorArea, cursorPos); - SetItemIconAffineAnim(id, 2); - SetItemIconCallback(id, 0, cursorArea, cursorPos); -} - -void Item_FromMonToMoving(u8 cursorArea, u8 cursorPos) -{ - u8 id; - u16 item; - - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - return; - - id = GetItemIconIdxByPosition(cursorArea, cursorPos); - item = 0; - SetItemIconAffineAnim(id, 3); - SetItemIconCallback(id, 1, cursorArea, cursorPos); - SetItemIconPosition(id, 2, 0); - if (cursorArea == CURSOR_AREA_IN_BOX) - { - SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &item); - SetBoxMonIconObjMode(cursorPos, ST_OAM_OBJ_BLEND); - } - else - { - SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &item); - SetPartyMonIconObjMode(cursorPos, ST_OAM_OBJ_BLEND); - } - - gPSSData->movingItemId = gPSSData->displayMonItemId; -} - -void sub_8095E2C(u16 item) -{ - const u32 *tiles = GetItemIconPic(item); - const u32 *pal = GetItemIconPalette(item); - u8 id = GetNewItemIconIdx(); - - LoadItemIconGfx(id, tiles, pal); - SetItemIconAffineAnim(id, 6); - SetItemIconCallback(id, 1, CURSOR_AREA_IN_BOX, 0); - SetItemIconPosition(id, CURSOR_AREA_BOX, 0); - SetItemIconActive(id, TRUE); - gPSSData->movingItemId = item; -} - -void Item_SwitchMonsWithMoving(u8 cursorArea, u8 cursorPos) -{ - u8 id; - u16 item; - - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - return; - - id = GetItemIconIdxByPosition(cursorArea, cursorPos); - SetItemIconAffineAnim(id, 3); - SetItemIconCallback(id, 3, CURSOR_AREA_BOX, 0); - if (cursorArea == CURSOR_AREA_IN_BOX) - { - item = GetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM); - SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &gPSSData->movingItemId); - gPSSData->movingItemId = item; - } - else - { - item = GetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM); - SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &gPSSData->movingItemId); - gPSSData->movingItemId = item; - } - - id = GetItemIconIdxByPosition(2, 0); - SetItemIconAffineAnim(id, 4); - SetItemIconCallback(id, 4, cursorArea, cursorPos); -} - -void Item_GiveMovingToMon(u8 cursorArea, u8 cursorPos) -{ - u8 id; - - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - return; - - id = GetItemIconIdxByPosition(2, 0); - SetItemIconAffineAnim(id, 4); - SetItemIconCallback(id, 2, cursorArea, cursorPos); - if (cursorArea == CURSOR_AREA_IN_BOX) - { - SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &gPSSData->movingItemId); - SetBoxMonIconObjMode(cursorPos, ST_OAM_OBJ_NORMAL); - } - else - { - SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &gPSSData->movingItemId); - SetPartyMonIconObjMode(cursorPos, ST_OAM_OBJ_NORMAL); - } -} - -void Item_TakeMons(u8 cursorArea, u8 cursorPos) -{ - u8 id; - u16 item; - - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - return; - - item = 0; - id = GetItemIconIdxByPosition(cursorArea, cursorPos); - SetItemIconAffineAnim(id, 2); - SetItemIconCallback(id, 0, cursorArea, cursorPos); - if (cursorArea == CURSOR_AREA_IN_BOX) - { - SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &item); - SetBoxMonIconObjMode(cursorPos, ST_OAM_OBJ_BLEND); - } - else - { - SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &item); - SetPartyMonIconObjMode(cursorPos, ST_OAM_OBJ_BLEND); - } -} - -void sub_8096088(void) -{ - if (gPSSData->boxOption == OPTION_MOVE_ITEMS) - { - u8 id = GetItemIconIdxByPosition(2, 0); - SetItemIconAffineAnim(id, 5); - SetItemIconCallback(id, 0, CURSOR_AREA_BOX, 0); - } -} - -void sub_80960C0(void) -{ - s32 i; - - if (gPSSData->boxOption != OPTION_MOVE_ITEMS) - return; - - for (i = 0; i < MAX_ITEM_ICONS; i++) - { - if (gPSSData->itemIcons[i].active && gPSSData->itemIcons[i].cursorArea == CURSOR_AREA_IN_PARTY) - SetItemIconCallback(i, 7, CURSOR_AREA_BOX, 0); - } -} - -bool8 sub_809610C(void) -{ - s32 i; - - for (i = 0; i < MAX_ITEM_ICONS; i++) - { - if (gPSSData->itemIcons[i].active) - { - if (!gPSSData->itemIcons[i].sprite->affineAnimEnded && gPSSData->itemIcons[i].sprite->affineAnimBeginning) - return TRUE; - if (gPSSData->itemIcons[i].sprite->callback != SpriteCallbackDummy && gPSSData->itemIcons[i].sprite->callback != SpriteCB_ItemIcon_SetPosToCursor) - return TRUE; - } - } - - return FALSE; -} - -bool8 IsActiveItemMoving(void) -{ - s32 i; - - if (gPSSData->boxOption == OPTION_MOVE_ITEMS) - { - for (i = 0; i < MAX_ITEM_ICONS; i++) - { - if (gPSSData->itemIcons[i].active && gPSSData->itemIcons[i].cursorArea == CURSOR_AREA_BOX) - return TRUE; - } - } - - return FALSE; -} - -const u8 *GetMovingItemName(void) -{ - return ItemId_GetName(gPSSData->movingItemId); -} - -u16 GetMovingItem(void) -{ - return gPSSData->movingItemId; -} - -static u8 GetNewItemIconIdx(void) -{ - u8 i; - - for (i = 0; i < MAX_ITEM_ICONS; i++) - { - if (!gPSSData->itemIcons[i].active) - { - gPSSData->itemIcons[i].active = TRUE; - return i; - } - } - - return MAX_ITEM_ICONS; -} - -static bool32 IsItemIconAtPosition(u8 cursorArea, u8 cursorPos) -{ - s32 i; - - for (i = 0; i < MAX_ITEM_ICONS; i++) - { - if (gPSSData->itemIcons[i].active - && gPSSData->itemIcons[i].cursorArea == cursorArea - && gPSSData->itemIcons[i].cursorPos == cursorPos) - return TRUE; - } - - return FALSE; -} - -static u8 GetItemIconIdxByPosition(u8 cursorArea, u8 cursorPos) -{ - u8 i; - - for (i = 0; i < MAX_ITEM_ICONS; i++) - { - if (gPSSData->itemIcons[i].active - && gPSSData->itemIcons[i].cursorArea == cursorArea - && gPSSData->itemIcons[i].cursorPos == cursorPos) - return i; - } - - return MAX_ITEM_ICONS; -} - -static u8 GetItemIconIdxBySprite(struct Sprite *sprite) -{ - u8 i; - - for (i = 0; i < MAX_ITEM_ICONS; i++) - { - if (gPSSData->itemIcons[i].active - && gPSSData->itemIcons[i].sprite == sprite) - return i; - } - - return MAX_ITEM_ICONS; -} - -static void SetItemIconPosition(u8 id, u8 cursorArea, u8 cursorPos) -{ - u8 row, column; - - if (id >= MAX_ITEM_ICONS) - return; - - switch (cursorArea) - { - case CURSOR_AREA_IN_BOX: - row = cursorPos % IN_BOX_ROWS; - column = cursorPos / IN_BOX_ROWS; - gPSSData->itemIcons[id].sprite->x = (24 * row) + 112; - gPSSData->itemIcons[id].sprite->y = (24 * column) + 56; - gPSSData->itemIcons[id].sprite->oam.priority = 2; - break; - case CURSOR_AREA_IN_PARTY: - if (cursorPos == 0) - { - gPSSData->itemIcons[id].sprite->x = 116; - gPSSData->itemIcons[id].sprite->y = 76; - } - else - { - gPSSData->itemIcons[id].sprite->x = 164; - gPSSData->itemIcons[id].sprite->y = 24 * (cursorPos - 1) + 28; - } - gPSSData->itemIcons[id].sprite->oam.priority = 1; - break; - } - - gPSSData->itemIcons[id].cursorArea = cursorArea; - gPSSData->itemIcons[id].cursorPos = cursorPos; -} - -static void LoadItemIconGfx(u8 id, const u32 *itemTiles, const u32 *itemPal) -{ - s32 i; - - if (id >= MAX_ITEM_ICONS) - return; - - CpuFastFill(0, gPSSData->itemIconBuffer, 0x200); - LZ77UnCompWram(itemTiles, gPSSData->field_22C4); - for (i = 0; i < 3; i++) - CpuFastCopy(gPSSData->field_22C4 + (i * 0x60), gPSSData->itemIconBuffer + (i * 0x80), 0x60); - - CpuFastCopy(gPSSData->itemIconBuffer, gPSSData->itemIcons[id].tiles, 0x200); - LZ77UnCompWram(itemPal, gPSSData->itemIconBuffer); - LoadPalette(gPSSData->itemIconBuffer, gPSSData->itemIcons[id].palIndex, 0x20); -} - -static void SetItemIconAffineAnim(u8 id, u8 animNum) -{ - if (id >= MAX_ITEM_ICONS) - return; - - StartSpriteAffineAnim(gPSSData->itemIcons[id].sprite, animNum); -} - -#define sItemIconId data[0] -#define sState data[0] -#define sCursorArea data[6] -#define sCursorPos data[7] - -static void SetItemIconCallback(u8 id, u8 callbackId, u8 cursorArea, u8 cursorPos) -{ - if (id >= MAX_ITEM_ICONS) - return; - - switch (callbackId) - { - case ITEM_CB_WAIT_ANIM: - gPSSData->itemIcons[id].sprite->sItemIconId = id; - gPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_WaitAnim; - break; - case ITEM_CB_TO_HAND: - gPSSData->itemIcons[id].sprite->sState = 0; - gPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_ToHand; - break; - case ITEM_CB_TO_MON: - gPSSData->itemIcons[id].sprite->sState = 0; - gPSSData->itemIcons[id].sprite->sCursorArea = cursorArea; - gPSSData->itemIcons[id].sprite->sCursorPos = cursorPos; - gPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_ToMon; - break; - case ITEM_CB_SWAP_TO_HAND: - gPSSData->itemIcons[id].sprite->sState = 0; - gPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_SwapToHand; - gPSSData->itemIcons[id].sprite->sCursorArea = cursorArea; - gPSSData->itemIcons[id].sprite->sCursorPos = cursorPos; - break; - case ITEM_CB_SWAP_TO_MON: - gPSSData->itemIcons[id].sprite->sState = 0; - gPSSData->itemIcons[id].sprite->sCursorArea = cursorArea; - gPSSData->itemIcons[id].sprite->sCursorPos = cursorPos; - gPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_SwapToMon; - break; - case ITEM_CB_HIDE_PARTY: - // If cursor is on a Pokémon with a held item and - // the player closes the party menu, have the held - // item follow the Pokémon as the menu slides out - gPSSData->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_HideParty; - break; - } -} - -static void SetItemIconActive(u8 id, bool8 show) -{ - if (id >= MAX_ITEM_ICONS) - return; - - gPSSData->itemIcons[id].active = show; - gPSSData->itemIcons[id].sprite->invisible = (show == FALSE); -} - -static const u32 *GetItemIconPic(u16 itemId) -{ - return GetItemIconGfxPtr(itemId, 0); -} - -static const u32 *GetItemIconPalette(u16 itemId) -{ - return GetItemIconGfxPtr(itemId, 1); -} - -void PrintItemDescription(void) -{ - const u8 *description; - - if (IsActiveItemMoving()) - description = ItemId_GetDescription(gPSSData->movingItemId); - else - description = ItemId_GetDescription(gPSSData->displayMonItemId); - - FillWindowPixelBuffer(2, PIXEL_FILL(1)); - AddTextPrinterParameterized5(2, FONT_2, description, 2, 0, 0, NULL, 0, 0); -} - -void InitItemInfoWindow(void) -{ - gPSSData->itemInfoWindowOffset = 25; - LoadBgTiles(0, sItemInfoFrame_Gfx, 0x80, 0x1A4); - DrawItemInfoWindow(0); -} - -bool8 UpdateItemInfoWindowSlideIn(void) -{ - s32 i, pos; - - if (gPSSData->itemInfoWindowOffset == 0) - return FALSE; - - gPSSData->itemInfoWindowOffset--; - pos = 25 - gPSSData->itemInfoWindowOffset; - for (i = 0; i < pos; i++) - { - WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + gPSSData->itemInfoWindowOffset + i, i, 12, 1, 8, 15, 25); - } - - DrawItemInfoWindow(pos); - return (gPSSData->itemInfoWindowOffset != 0); -} - -bool8 UpdateItemInfoWindowSlideOut(void) -{ - s32 i, pos; - - if (gPSSData->itemInfoWindowOffset == 25) - return FALSE; - - if (gPSSData->itemInfoWindowOffset == 0) - FillBgTilemapBufferRect(0, 0, 25, 11, 1, 10, 17); - - gPSSData->itemInfoWindowOffset++; - pos = 25 - gPSSData->itemInfoWindowOffset; - for (i = 0; i < pos; i++) - { - WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + gPSSData->itemInfoWindowOffset + i, i, 12, 1, 8, 15, 25); - } - - DrawItemInfoWindow(pos); - - FillBgTilemapBufferRect(0, 0, pos, 11, 1, 10, 0x11); - return (gPSSData->itemInfoWindowOffset != 25); -} - -static void DrawItemInfoWindow(u32 x) -{ - if (x != 0) - { - FillBgTilemapBufferRect(0, 0x1A4, 0, 0xB, x, 1, 0xFu); - FillBgTilemapBufferRect(0, 0x9A4, 0, 0x14, x, 1, 0xFu); - } - FillBgTilemapBufferRect(0, 0x1A5, x, 0xC, 1, 8, 0xFu); - FillBgTilemapBufferRect(0, 0x1A6, x, 0xB, 1, 1, 0xFu); - FillBgTilemapBufferRect(0, 0x1A7, x, 0x14, 1, 1, 0xFu); - ScheduleBgCopyTilemapToVram(0); -} - -static void SpriteCB_ItemIcon_WaitAnim(struct Sprite *sprite) -{ - if (sprite->affineAnimEnded) - { - SetItemIconActive(sprite->data[0], FALSE); - sprite->callback = SpriteCallbackDummy; - } -} - -static void SpriteCB_ItemIcon_ToHand(struct Sprite *sprite) -{ - switch (sprite->data[0]) - { - case 0: - sprite->data[1] = sprite->x << 4; - sprite->data[2] = sprite->y << 4; - sprite->data[3] = 10; - sprite->data[4] = 21; - sprite->data[5] = 0; - sprite->data[0]++; - case 1: - sprite->data[1] -= sprite->data[3]; - sprite->data[2] -= sprite->data[4]; - sprite->x = sprite->data[1] >> 4; - sprite->y = sprite->data[2] >> 4; - if (++sprite->data[5] > 11) - sprite->callback = SpriteCB_ItemIcon_SetPosToCursor; - break; - } -} - -static void SpriteCB_ItemIcon_SetPosToCursor(struct Sprite *sprite) -{ - sprite->x = gPSSData->cursorSprite->x + 4; - sprite->y = gPSSData->cursorSprite->y + gPSSData->cursorSprite->y2 + 8; - sprite->oam.priority = gPSSData->cursorSprite->oam.priority; -} - -static void SpriteCB_ItemIcon_ToMon(struct Sprite *sprite) -{ - switch (sprite->data[0]) - { - case 0: - sprite->data[1] = sprite->x << 4; - sprite->data[2] = sprite->y << 4; - sprite->data[3] = 10; - sprite->data[4] = 21; - sprite->data[5] = 0; - sprite->data[0]++; - case 1: - sprite->data[1] += sprite->data[3]; - sprite->data[2] += sprite->data[4]; - sprite->x = sprite->data[1] >> 4; - sprite->y = sprite->data[2] >> 4; - if (++sprite->data[5] > 11) - { - SetItemIconPosition(GetItemIconIdxBySprite(sprite), sprite->data[6], sprite->data[7]); - sprite->callback = SpriteCallbackDummy; - } - break; - } -} - -static void SpriteCB_ItemIcon_SwapToHand(struct Sprite *sprite) -{ - switch (sprite->data[0]) - { - case 0: - sprite->data[1] = sprite->x << 4; - sprite->data[2] = sprite->y << 4; - sprite->data[3] = 10; - sprite->data[4] = 21; - sprite->data[5] = 0; - sprite->data[0]++; - case 1: - sprite->data[1] -= sprite->data[3]; - sprite->data[2] -= sprite->data[4]; - sprite->x = sprite->data[1] >> 4; - sprite->y = sprite->data[2] >> 4; - sprite->x2 = gSineTable[sprite->data[5] * 8] >> 4; - if (++sprite->data[5] > 11) - { - SetItemIconPosition(GetItemIconIdxBySprite(sprite), sprite->data[6], sprite->data[7]); - sprite->x2 = 0; - sprite->callback = SpriteCB_ItemIcon_SetPosToCursor; - } - break; - } -} - -static void SpriteCB_ItemIcon_SwapToMon(struct Sprite *sprite) -{ - switch (sprite->data[0]) - { - case 0: - sprite->data[1] = sprite->x << 4; - sprite->data[2] = sprite->y << 4; - sprite->data[3] = 10; - sprite->data[4] = 21; - sprite->data[5] = 0; - sprite->data[0]++; - case 1: - sprite->data[1] += sprite->data[3]; - sprite->data[2] += sprite->data[4]; - sprite->x = sprite->data[1] >> 4; - sprite->y = sprite->data[2] >> 4; - sprite->x2 = -(gSineTable[sprite->data[5] * 8] >> 4); - if (++sprite->data[5] > 11) - { - SetItemIconPosition(GetItemIconIdxBySprite(sprite), sprite->data[6], sprite->data[7]); - sprite->callback = SpriteCallbackDummy; - sprite->x2 = 0; - } - break; - } -} - -static void SpriteCB_ItemIcon_HideParty(struct Sprite *sprite) -{ - sprite->y -= 8; - if (sprite->y + sprite->y2 < -16) - { - sprite->callback = SpriteCallbackDummy; - SetItemIconActive(GetItemIconIdxBySprite(sprite), FALSE); - } -} - -#undef sState -#undef sItemIconId -#undef sCursorArea -#undef sCursorPos - - -//------------------------------------------------------------------------------ -// SECTION: UnkUtil -// -// Some data transfer utility that goes functionally unused. -// It gets initialized with UnkUtil_Init, and run every vblank in Pokémon -// Storage with UnkUtil_Run, but neither of the Add functions are ever used, -// so UnkUtil_Run performs no actions. -//------------------------------------------------------------------------------ - - -static EWRAM_DATA struct UnkUtil *sUnkUtil = NULL; - -static void UnkUtil_CpuRun(struct UnkUtilData *unkStruct); -static void UnkUtil_DmaRun(struct UnkUtilData *unkStruct); - -void UnkUtil_Init(struct UnkUtil *util, struct UnkUtilData *data, u32 max) -{ - sUnkUtil = util; - util->data = data; - util->max = max; - util->numActive = 0; -} - -void UnkUtil_Run(void) -{ - u16 i; - if (sUnkUtil->numActive) - { - for (i = 0; i < sUnkUtil->numActive; i++) - { - struct UnkUtilData *data = &sUnkUtil->data[i]; - data->func(data); - } - sUnkUtil->numActive = 0; - } -} - -// Unused -static bool8 UnkUtil_CpuAdd(u8 *dest, u16 dLeft, u16 dTop, const u8 *src, u16 sLeft, u16 sTop, u16 width, u16 height, u16 unkArg) -{ - struct UnkUtilData *data; - - if (sUnkUtil->numActive >= sUnkUtil->max) - return FALSE; - - data = &sUnkUtil->data[sUnkUtil->numActive++]; - data->size = width * 2; - data->dest = dest + 2 * (dTop * 32 + dLeft); - data->src = src + 2 * (sTop * unkArg + sLeft); - data->height = height; - data->unk = unkArg; - data->func = UnkUtil_CpuRun; - return TRUE; -} - -// Functionally unused -static void UnkUtil_CpuRun(struct UnkUtilData *data) -{ - u16 i; - - for (i = 0; i < data->height; i++) - { - CpuCopy16(data->src, data->dest, data->size); - data->dest += 64; - data->src += (data->unk * 2); - } -} - -// Unused -static bool8 UnkUtil_DmaAdd(void *dest, u16 dLeft, u16 dTop, u16 width, u16 height) -{ - struct UnkUtilData *data; - - if (sUnkUtil->numActive >= sUnkUtil->max) - return FALSE; - - data = &sUnkUtil->data[sUnkUtil->numActive++]; - data->size = width * 2; - data->dest = dest + ((dTop * 32) + dLeft) * 2; - data->height = height; - data->func = UnkUtil_DmaRun; - return TRUE; -} - -// Functionally unused -static void UnkUtil_DmaRun(struct UnkUtilData *data) -{ - u16 i; - - for (i = 0; i < data->height; i++) - { - Dma3FillLarge_(0, data->dest, data->size, 16); - data->dest += 64; - } -} diff --git a/src/pokemon_storage_system_data.c b/src/pokemon_storage_system_data.c new file mode 100644 index 000000000..dfe34330a --- /dev/null +++ b/src/pokemon_storage_system_data.c @@ -0,0 +1,2165 @@ +#include "global.h" +#include "gflib.h" +#include "data.h" +#include "item.h" +#include "mail_data.h" +#include "menu.h" +#include "new_menu_helpers.h" +#include "pokemon_storage_system_internal.h" +#include "pokemon_summary_screen.h" +#include "strings.h" +#include "constants/items.h" +#include "constants/moves.h" +#include "constants/songs.h" + +static EWRAM_DATA struct Pokemon sMonBeingCarried = {}; +static EWRAM_DATA s8 sCursorArea = 0; +static EWRAM_DATA s8 sCursorPosition = 0; +static EWRAM_DATA bool8 sIsMonBeingMoved = FALSE; +static EWRAM_DATA u8 sMovingMonOrigBoxId = 0; +static EWRAM_DATA u8 sMovingMonOrigBoxPos = 0; +static EWRAM_DATA bool8 sInMultiMoveMode = FALSE; +static EWRAM_DATA u8 sSavedCursorPosition = 0; + +static void DoCursorNewPosUpdate(void); +static bool8 MonPlaceChange_Grab(void); +static bool8 MonPlaceChange_Place(void); +static bool8 MonPlaceChange_Shift(void); +static bool8 MonPlaceChange_DoMoveCursorDown(void); +static bool8 MonPlaceChange_DoMoveCursorUp(void); +static bool8 MonPlaceChange_MoveCursorDown(void); +static bool8 MonPlaceChange_MoveCursorUp(void); +static void MoveMon(void); +static void PlaceMon(void); +static void SetMovedMonData(u8 boxId, u8 cursorPos); +static void SetPlacedMonData(u8 boxId, u8 cursorPos); +static void PurgeMonOrBoxMon(u8 boxId, u8 cursorPos); +static void SetShiftedMonData(u8 boxId, u8 cursorPos); +static void TrySetDisplayMonData(void); +static void SetDisplayMonData(void *pokemon, u8 mode); +static void ReshowDisplayMon(void); +static u8 HandleInput_InBox_Normal(void); +static u8 HandleInput_InBox_GrabbingMultiple(void); +static u8 HandleInput_InBox_MovingMultiple(void); +static void AddBoxMenu(void); +static bool8 SetSelectionMenuTexts(void); +static bool8 SetMenuTextsForMon(void); +static bool8 SetMenuTextsForItem(void); +static void CreateCursorSprites(void); +static void ToggleCursorMultiMoveMode(void); + +static const u16 sPokeStorageMisc1Pal[] = INCBIN_U16("graphics/pokemon_storage/misc1.gbapal"); +static const u16 sHandCursorTiles[] = INCBIN_U16("graphics/pokemon_storage/cursor.4bpp"); +static const u16 sHandCursorShadowTiles[] = INCBIN_U16("graphics/pokemon_storage/cursor_shadow.4bpp"); + +// Modes for selecting and moving Pokémon in the box. Multiple Pokémon can be +// selected by pressing the Select button to change the cursor, then holding +// down the A button while moving the cursor around. This is +// MOVE_MODE_MULTIPLE_SELECTING. After releasing the A button, those Pokémon +// will be picked up and can be moved around as a single unit. This is +// MOVE_MODE_MULTIPLE_MOVING. +enum +{ + MOVE_MODE_NORMAL, + MOVE_MODE_MULTIPLE_SELECTING, + MOVE_MODE_MULTIPLE_MOVING, +}; + +void InitCursor(void) +{ + if (gStorage->boxOption != OPTION_DEPOSIT) + sCursorArea = CURSOR_AREA_IN_BOX; + else + sCursorArea = CURSOR_AREA_IN_PARTY; + + sCursorPosition = 0; + sIsMonBeingMoved = FALSE; + sMovingMonOrigBoxId = 0; + sMovingMonOrigBoxPos = 0; + sInMultiMoveMode = FALSE; + ClearSavedCursorPos(); + CreateCursorSprites(); + gStorage->cursorPrevPartyPos = 1; + gStorage->inBoxMovingMode = MOVE_MODE_NORMAL; + TrySetDisplayMonData(); +} + +void InitCursorOnReopen(void) +{ + CreateCursorSprites(); + ReshowDisplayMon(); + gStorage->cursorPrevPartyPos = 1; + gStorage->inBoxMovingMode = MOVE_MODE_NORMAL; + if (sIsMonBeingMoved) + { + gStorage->movingMon = sMonBeingCarried; + CreateMovingMonIcon(); + } +} + +static void GetCursorCoordsByPos(u8 cursorArea, u8 cursorPosition, u16 *x, u16 *y) +{ + switch (cursorArea) + { + case CURSOR_AREA_IN_BOX: + *x = (cursorPosition % IN_BOX_COLUMNS) * 24 + 100; + *y = (cursorPosition / IN_BOX_COLUMNS) * 24 + 32; + break; + case CURSOR_AREA_IN_PARTY: + if (cursorPosition == 0) + { + *x = 104; + *y = 52; + } + else if (cursorPosition == PARTY_SIZE) + { + *x = 152; + *y = 132; + } + else + { + *x = 152; + *y = (cursorPosition - 1) * 24 + 4; + } + break; + case CURSOR_AREA_BOX_TITLE: + *x = 162; + *y = 12; + break; + case CURSOR_AREA_BUTTONS: + *y = sIsMonBeingMoved ? 8 : 14; + *x = cursorPosition * 88 + 120; + break; + case 4: + *x = 160; + *y = 96; + break; + } +} + +static u16 GetSpeciesAtCursorPosition(void) +{ + switch (sCursorArea) + { + case CURSOR_AREA_IN_PARTY: + return GetMonData(&gPlayerParty[sCursorPosition], MON_DATA_SPECIES); + case CURSOR_AREA_IN_BOX: + return GetCurrentBoxMonData(sCursorPosition, MON_DATA_SPECIES); + default: + return SPECIES_NONE; + } +} + +bool8 UpdateCursorPos(void) +{ + s16 tmp; + + if (gStorage->cursorMoveSteps == 0) + { + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + return FALSE; + else + return IsItemIconAnimActive(); + } + else if (--gStorage->cursorMoveSteps != 0) + { + // Update position toward target + gStorage->cursorNewX += gStorage->cursorSpeedX; + gStorage->cursorNewY += gStorage->cursorSpeedY; + gStorage->cursorSprite->x = gStorage->cursorNewX >> 8; + gStorage->cursorSprite->y = gStorage->cursorNewY >> 8; + + // Limit cursor on right + if (gStorage->cursorSprite->x > DISPLAY_WIDTH + 16) + { + tmp = gStorage->cursorSprite->x - (DISPLAY_WIDTH + 16); + gStorage->cursorSprite->x = tmp + 64; + } + + // Limit cursor on left + if (gStorage->cursorSprite->x < 64) + { + tmp = 64 - gStorage->cursorSprite->x; + gStorage->cursorSprite->x = DISPLAY_WIDTH + 16 - tmp; + } + + // Limit cursor on bottom + if (gStorage->cursorSprite->y > DISPLAY_HEIGHT + 16) + { + tmp = gStorage->cursorSprite->y - (DISPLAY_HEIGHT + 16); + gStorage->cursorSprite->y = tmp - 16; + } + + // Limit cursor on top + if (gStorage->cursorSprite->y < -16) + { + tmp = -16 - gStorage->cursorSprite->y; + gStorage->cursorSprite->y = DISPLAY_HEIGHT + 16 - tmp; + } + + // Cursor flips vertically when moving on/off the top buttons + if (gStorage->cursorFlipTimer && --gStorage->cursorFlipTimer == 0) + gStorage->cursorSprite->vFlip = (gStorage->cursorSprite->vFlip == FALSE); + } + else + { + // Time is up for cursor movement, make sure it's exactly at target + gStorage->cursorSprite->x = gStorage->cursorTargetX; + gStorage->cursorSprite->y = gStorage->cursorTargetY; + DoCursorNewPosUpdate(); + } + + return TRUE; +} + +static void InitNewCursorPos(u8 newCursorArea, u8 newCursorPosition) +{ + u16 x, y; + + GetCursorCoordsByPos(newCursorArea, newCursorPosition, &x, &y); + gStorage->newCursorArea = newCursorArea; + gStorage->newCursorPosition = newCursorPosition; + gStorage->cursorTargetX = x; + gStorage->cursorTargetY = y; +} + +static void InitCursorMove(void) +{ + int yDistance, xDistance; + + if (gStorage->cursorVerticalWrap != 0 || gStorage->cursorHorizontalWrap != 0) + gStorage->cursorMoveSteps = 12; + else + gStorage->cursorMoveSteps = 6; + + if (gStorage->cursorFlipTimer) + gStorage->cursorFlipTimer = gStorage->cursorMoveSteps / 2; + + switch (gStorage->cursorVerticalWrap) + { + default: + yDistance = gStorage->cursorTargetY - gStorage->cursorSprite->y; + break; + case -1: + yDistance = gStorage->cursorTargetY - 192 - gStorage->cursorSprite->y; + break; + case 1: + yDistance = gStorage->cursorTargetY + 192 - gStorage->cursorSprite->y; + break; + } + + switch (gStorage->cursorHorizontalWrap) + { + default: + xDistance = gStorage->cursorTargetX - gStorage->cursorSprite->x; + break; + case -1: + xDistance = gStorage->cursorTargetX - 192 - gStorage->cursorSprite->x; + break; + case 1: + xDistance = gStorage->cursorTargetX + 192 - gStorage->cursorSprite->x; + break; + } + + yDistance <<= 8; + xDistance <<= 8; + gStorage->cursorSpeedX = xDistance / gStorage->cursorMoveSteps; + gStorage->cursorSpeedY = yDistance / gStorage->cursorMoveSteps; + gStorage->cursorNewX = gStorage->cursorSprite->x << 8; + gStorage->cursorNewY = gStorage->cursorSprite->y << 8; +} + +static void SetCursorPosition(u8 newCursorArea, u8 newCursorPosition) +{ + InitNewCursorPos(newCursorArea, newCursorPosition); + InitCursorMove(); + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + { + if (gStorage->inBoxMovingMode == MOVE_MODE_NORMAL && !sIsMonBeingMoved) + StartSpriteAnim(gStorage->cursorSprite, 1); + } + else + { + if (!IsActiveItemMoving()) + StartSpriteAnim(gStorage->cursorSprite, 1); + } + + if (gStorage->boxOption == OPTION_MOVE_ITEMS) + { + if (sCursorArea == CURSOR_AREA_IN_BOX) + TryHideItemIconAtPos(CURSOR_AREA_IN_BOX, sCursorPosition); + else if (sCursorArea == CURSOR_AREA_IN_PARTY) + TryHideItemIconAtPos(CURSOR_AREA_IN_PARTY, sCursorPosition); + + if (newCursorArea == CURSOR_AREA_IN_BOX) + TryLoadItemIconAtPos(newCursorArea, newCursorPosition); + else if (newCursorArea == CURSOR_AREA_IN_PARTY) + TryLoadItemIconAtPos(newCursorArea, newCursorPosition); + } + + if (newCursorArea == CURSOR_AREA_IN_PARTY && sCursorArea != CURSOR_AREA_IN_PARTY) + { + gStorage->cursorPrevPartyPos = 1; + gStorage->cursorShadowSprite->invisible = TRUE; + } + + switch (newCursorArea) + { + case CURSOR_AREA_IN_PARTY: + case CURSOR_AREA_BOX_TITLE: + case CURSOR_AREA_BUTTONS: + gStorage->cursorSprite->oam.priority = 1; + gStorage->cursorShadowSprite->invisible = TRUE; + gStorage->cursorShadowSprite->oam.priority = 1; + break; + case CURSOR_AREA_IN_BOX: + if (gStorage->inBoxMovingMode != MOVE_MODE_NORMAL) + { + gStorage->cursorSprite->oam.priority = 0; + gStorage->cursorShadowSprite->invisible = TRUE; + } + else + { + gStorage->cursorSprite->oam.priority = 2; + if (sCursorArea == CURSOR_AREA_IN_BOX && sIsMonBeingMoved) + SetMovingMonPriority(2); + } + break; + } +} + +static void DoCursorNewPosUpdate(void) +{ + sCursorArea = gStorage->newCursorArea; + sCursorPosition = gStorage->newCursorPosition; + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + { + if (gStorage->inBoxMovingMode == MOVE_MODE_NORMAL && !sIsMonBeingMoved) + StartSpriteAnim(gStorage->cursorSprite, 1); + } + else if (!IsActiveItemMoving()) + StartSpriteAnim(gStorage->cursorSprite, 1); + + TrySetDisplayMonData(); + switch (sCursorArea) + { + case CURSOR_AREA_BUTTONS: + SetMovingMonPriority(1); + break; + case CURSOR_AREA_BOX_TITLE: + AnimateBoxScrollArrows(TRUE); + break; + case CURSOR_AREA_IN_PARTY: + gStorage->cursorShadowSprite->subpriority = 13; + SetMovingMonPriority(1); + break; + case CURSOR_AREA_IN_BOX: + if (gStorage->inBoxMovingMode == MOVE_MODE_NORMAL) + { + gStorage->cursorSprite->oam.priority = 1; + gStorage->cursorShadowSprite->oam.priority = 2; + gStorage->cursorShadowSprite->subpriority = 21; + gStorage->cursorShadowSprite->invisible = FALSE; + SetMovingMonPriority(2); + } + break; + } +} + +void SetCursorInParty(void) +{ + u8 partyCount; + + if (!sIsMonBeingMoved) + partyCount = 0; + else + { + partyCount = CalculatePlayerPartyCount(); + if (partyCount >= PARTY_SIZE) + partyCount = PARTY_SIZE - 1; + } + if (gStorage->cursorSprite->vFlip) + gStorage->cursorFlipTimer = 1; + SetCursorPosition(CURSOR_AREA_IN_PARTY, partyCount); +} + +void SetCursorBoxPosition(u8 cursorBoxPosition) +{ + SetCursorPosition(CURSOR_AREA_IN_BOX, cursorBoxPosition); +} + +void ClearSavedCursorPos(void) +{ + sSavedCursorPosition = 0; +} + +void SaveCursorPos(void) +{ + sSavedCursorPosition = sCursorPosition; +} + +u8 GetSavedCursorPos(void) +{ + return sSavedCursorPosition; +} + +void InitMonPlaceChange(u8 type) +{ + static bool8 (*const placeChangeFuncs[])(void) = { + [CHANGE_GRAB] = MonPlaceChange_Grab, + [CHANGE_PLACE] = MonPlaceChange_Place, + [CHANGE_SHIFT] = MonPlaceChange_Shift, + }; + + gStorage->monPlaceChangeFunc = placeChangeFuncs[type]; + gStorage->monPlaceChangeState = 0; +} + +void InitMultiMonPlaceChange(bool8 moveCursorUp) +{ + if (!moveCursorUp) + gStorage->monPlaceChangeFunc = MonPlaceChange_DoMoveCursorDown; + else + gStorage->monPlaceChangeFunc = MonPlaceChange_DoMoveCursorUp; + + gStorage->monPlaceChangeState = 0; +} + +bool8 DoMonPlaceChange(void) +{ + return gStorage->monPlaceChangeFunc(); +} + +static bool8 MonPlaceChange_Grab(void) +{ + switch (gStorage->monPlaceChangeState) + { + case 0: + if (sIsMonBeingMoved) + return FALSE; + StartSpriteAnim(gStorage->cursorSprite, 2); + gStorage->monPlaceChangeState++; + break; + case 1: + if (!MonPlaceChange_MoveCursorDown()) + { + StartSpriteAnim(gStorage->cursorSprite, 3); + MoveMon(); + gStorage->monPlaceChangeState++; + } + break; + case 2: + if (!MonPlaceChange_MoveCursorUp()) + gStorage->monPlaceChangeState++; + break; + case 3: + return FALSE; + } + + return TRUE; +} + +static bool8 MonPlaceChange_Place(void) +{ + switch (gStorage->monPlaceChangeState) + { + case 0: + if (!MonPlaceChange_MoveCursorDown()) + { + StartSpriteAnim(gStorage->cursorSprite, 2); + PlaceMon(); + gStorage->monPlaceChangeState++; + } + break; + case 1: + if (!MonPlaceChange_MoveCursorUp()) + { + StartSpriteAnim(gStorage->cursorSprite, 0); + gStorage->monPlaceChangeState++; + } + break; + case 2: + return FALSE; + } + + return TRUE; +} + +static bool8 MonPlaceChange_Shift(void) +{ + switch (gStorage->monPlaceChangeState) + { + case 0: + switch (sCursorArea) + { + case CURSOR_AREA_IN_PARTY: + gStorage->shiftBoxId = TOTAL_BOXES_COUNT; + break; + case CURSOR_AREA_IN_BOX: + gStorage->shiftBoxId = StorageGetCurrentBox(); + break; + default: + return FALSE; + } + StartSpriteAnim(gStorage->cursorSprite, 2); + SetShiftMonSpritePtr(gStorage->shiftBoxId, sCursorPosition); + gStorage->monPlaceChangeState++; + break; + case 1: + if (!ShiftMons()) + { + StartSpriteAnim(gStorage->cursorSprite, 3); + SetShiftedMonData(gStorage->shiftBoxId, sCursorPosition); + gStorage->monPlaceChangeState++; + } + break; + case 2: + return FALSE; + } + + return TRUE; +} + +static bool8 MonPlaceChange_DoMoveCursorDown(void) +{ + return MonPlaceChange_MoveCursorDown(); +} + +static bool8 MonPlaceChange_DoMoveCursorUp(void) +{ + return MonPlaceChange_MoveCursorUp(); +} + +static bool8 MonPlaceChange_MoveCursorDown(void) +{ + switch (gStorage->cursorSprite->y2) + { + default: + gStorage->cursorSprite->y2++; + break; + case 0: + gStorage->cursorSprite->y2++; + break; + case 8: // Cursor has reached bottom + return FALSE; + } + + return TRUE; +} + +static bool8 MonPlaceChange_MoveCursorUp(void) +{ + switch (gStorage->cursorSprite->y2) + { + case 0: // Cursor has reached top + return FALSE; + default: + gStorage->cursorSprite->y2--; + break; + } + + return TRUE; +} + +static void MoveMon(void) +{ + switch (sCursorArea) + { + case CURSOR_AREA_IN_PARTY: + SetMovedMonData(TOTAL_BOXES_COUNT, sCursorPosition); + SetMovingMonSprite(MODE_PARTY, sCursorPosition); + break; + case CURSOR_AREA_IN_BOX: + if (gStorage->inBoxMovingMode == MOVE_MODE_NORMAL) + { + SetMovedMonData(StorageGetCurrentBox(), sCursorPosition); + SetMovingMonSprite(MODE_BOX, sCursorPosition); + } + break; + default: + return; + } + + sIsMonBeingMoved = TRUE; +} + +static void PlaceMon(void) +{ + u8 boxId; + + switch (sCursorArea) + { + case CURSOR_AREA_IN_PARTY: + SetPlacedMonData(TOTAL_BOXES_COUNT, sCursorPosition); + SetPlacedMonSprite(TOTAL_BOXES_COUNT, sCursorPosition); + break; + case CURSOR_AREA_IN_BOX: + boxId = StorageGetCurrentBox(); + SetPlacedMonData(boxId, sCursorPosition); + SetPlacedMonSprite(boxId, sCursorPosition); + break; + default: + return; + } + + sIsMonBeingMoved = FALSE; +} + +void DoTrySetDisplayMonData(void) +{ + TrySetDisplayMonData(); +} + +static void SetMovedMonData(u8 boxId, u8 position) +{ + if (boxId == TOTAL_BOXES_COUNT) + gStorage->movingMon = gPlayerParty[sCursorPosition]; + else + BoxMonAtToMon(boxId, position, &gStorage->movingMon); + + PurgeMonOrBoxMon(boxId, position); + sMovingMonOrigBoxId = boxId; + sMovingMonOrigBoxPos = position; +} + +static void SetPlacedMonData(u8 boxId, u8 position) +{ + if (boxId == TOTAL_BOXES_COUNT) + gPlayerParty[position] = gStorage->movingMon; + else + { + BoxMonRestorePP(&gStorage->movingMon.box); + SetBoxMonAt(boxId, position, &gStorage->movingMon.box); + } +} + +static void PurgeMonOrBoxMon(u8 boxId, u8 position) +{ + if (boxId == TOTAL_BOXES_COUNT) + ZeroMonData(&gPlayerParty[position]); + else + ZeroBoxMonAt(boxId, position); +} + +static void SetShiftedMonData(u8 boxId, u8 position) +{ + if (boxId == TOTAL_BOXES_COUNT) + gStorage->tempMon = gPlayerParty[position]; + else + BoxMonAtToMon(boxId, position, &gStorage->tempMon); + + SetPlacedMonData(boxId, position); + gStorage->movingMon = gStorage->tempMon; + SetDisplayMonData(&gStorage->movingMon, MODE_PARTY); + sMovingMonOrigBoxId = boxId; + sMovingMonOrigBoxPos = position; +} + +bool8 TryStorePartyMonInBox(u8 boxId) +{ + s16 boxPosition = GetFirstFreeBoxSpot(boxId); + if (boxPosition == -1) + return FALSE; + + if (sIsMonBeingMoved) + { + SetPlacedMonData(boxId, boxPosition); + DestroyMovingMonIcon(); + sIsMonBeingMoved = FALSE; + } + else + { + SetMovedMonData(TOTAL_BOXES_COUNT, sCursorPosition); + SetPlacedMonData(boxId, boxPosition); + DestroyPartyMonIcon(sCursorPosition); + } + + if (boxId == StorageGetCurrentBox()) + CreateBoxMonIconAtPos(boxPosition); + + StartSpriteAnim(gStorage->cursorSprite, 1); + return TRUE; +} + +void ResetSelectionAfterDeposit(void) +{ + StartSpriteAnim(gStorage->cursorSprite, 0); + TrySetDisplayMonData(); +} + +void InitReleaseMon(void) +{ + u8 mode; + + if (sIsMonBeingMoved) + mode = MODE_MOVE; + else if (sCursorArea == CURSOR_AREA_IN_PARTY) + mode = MODE_PARTY; + else + mode = MODE_BOX; + + DoReleaseMonAnim(mode, sCursorPosition); + StringCopy(gStorage->releaseMonName, gStorage->displayMonNickname); +} + +bool8 TryHideReleaseMon(void) +{ + if (!TryHideReleaseMonSprite()) + { + StartSpriteAnim(gStorage->cursorSprite, 0); + return FALSE; + } + else + return TRUE; +} + +void ReleaseMon(void) +{ + u8 boxId; + + DestroyReleaseMonIcon(); + if (sIsMonBeingMoved) + sIsMonBeingMoved = FALSE; + else + { + if (sCursorArea == CURSOR_AREA_IN_PARTY) + boxId = TOTAL_BOXES_COUNT; + else + boxId = StorageGetCurrentBox(); + + PurgeMonOrBoxMon(boxId, sCursorPosition); + } + TrySetDisplayMonData(); +} + +void TrySetCursorFistAnim(void) +{ + if (sIsMonBeingMoved) + StartSpriteAnim(gStorage->cursorSprite, 3); +} + +void InitCanReleaseMonVars(void) +{ + u16 knownMoveFlags; + if (sIsMonBeingMoved) + { + gStorage->tempMon = gStorage->movingMon; + gStorage->releaseBoxId = -1; + gStorage->releaseBoxPos = -1; + } + else + { + if (sCursorArea == CURSOR_AREA_IN_PARTY) + { + gStorage->tempMon = gPlayerParty[sCursorPosition]; + gStorage->releaseBoxId = TOTAL_BOXES_COUNT; + } + else + { + BoxMonAtToMon(StorageGetCurrentBox(), sCursorPosition, &gStorage->tempMon); + gStorage->releaseBoxId = StorageGetCurrentBox(); + } + gStorage->releaseBoxPos = sCursorPosition; + } + + gStorage->isSurfMon = FALSE; + gStorage->isDiveMon = FALSE; + gStorage->restrictedMoveList[0] = MOVE_SURF; + gStorage->restrictedMoveList[1] = MOVE_DIVE; + gStorage->restrictedMoveList[2] = MOVES_COUNT; + knownMoveFlags = GetMonData(&gStorage->tempMon, MON_DATA_KNOWN_MOVES, (u8 *)gStorage->restrictedMoveList); + gStorage->isSurfMon = knownMoveFlags & 1; + gStorage->isDiveMon = (knownMoveFlags >> 1) & 1; + if (gStorage->isSurfMon || gStorage->isDiveMon) + gStorage->releaseMonStatusResolved = FALSE; + else + { + gStorage->releaseMonStatusResolved = TRUE; + gStorage->releaseMonStatus = RELEASE_MON_ALLOWED; + } + + gStorage->releaseCheckState = 0; +} + +s8 RunCanReleaseMon(void) +{ + u16 i; + u16 knownMoveFlags; + + if (gStorage->releaseMonStatusResolved) + return gStorage->releaseMonStatus; + + switch (gStorage->releaseCheckState) + { + case 0: + for (i = 0; i < PARTY_SIZE; i++) + { + if (gStorage->releaseBoxId != TOTAL_BOXES_COUNT || gStorage->releaseBoxPos != i) + { + knownMoveFlags = GetMonData(&gPlayerParty[i], MON_DATA_KNOWN_MOVES, (u8 *)gStorage->restrictedMoveList); + if (knownMoveFlags & 1) + gStorage->isSurfMon = FALSE; + if (knownMoveFlags & 2) + gStorage->isDiveMon = FALSE; + } + } + if (!(gStorage->isSurfMon || gStorage->isDiveMon)) + { + gStorage->releaseMonStatusResolved = TRUE; + gStorage->releaseMonStatus = RELEASE_MON_ALLOWED; + } + else + { + gStorage->releaseCheckBoxId = 0; + gStorage->releaseCheckBoxPos = 0; + gStorage->releaseCheckState++; + } + break; + case 1: + // for some reason, check only 5 mons in box each time this function is called + for (i = 0; i < 5; i++) + { + knownMoveFlags = GetAndCopyBoxMonDataAt(gStorage->releaseCheckBoxId, gStorage->releaseCheckBoxPos, MON_DATA_KNOWN_MOVES, (u8 *)gStorage->restrictedMoveList); + if (knownMoveFlags != 0 + && !(gStorage->releaseBoxId == gStorage->releaseCheckBoxId && gStorage->releaseBoxPos == gStorage->releaseCheckBoxPos)) + { + if (knownMoveFlags & 1) + gStorage->isSurfMon = FALSE; + if (knownMoveFlags & 2) + gStorage->isDiveMon = FALSE; + } + if (++gStorage->releaseCheckBoxPos >= IN_BOX_COUNT) + { + gStorage->releaseCheckBoxPos = 0; + if (++gStorage->releaseCheckBoxId >= TOTAL_BOXES_COUNT) + { + gStorage->releaseMonStatusResolved = TRUE; + gStorage->releaseMonStatus = RELEASE_MON_NOT_ALLOWED; + break; + } + } + } + if (!(gStorage->isSurfMon || gStorage->isDiveMon)) + { + gStorage->releaseMonStatusResolved = TRUE; + gStorage->releaseMonStatus = RELEASE_MON_ALLOWED; + } + break; + } + + return RELEASE_MON_UNDETERMINED; +} + +void SaveMovingMon(void) +{ + if (sIsMonBeingMoved) + sMonBeingCarried = gStorage->movingMon; +} + +void LoadSavedMovingMon(void) +{ + if (sIsMonBeingMoved) + { + if (sMovingMonOrigBoxId == TOTAL_BOXES_COUNT) + gStorage->movingMon = sMonBeingCarried; + else + gStorage->movingMon.box = sMonBeingCarried.box; + } +} + +void InitSummaryScreenData(void) +{ + if (sIsMonBeingMoved) + { + SaveMovingMon(); + gStorage->summaryMonPtr.mon = &sMonBeingCarried; + gStorage->summaryCursorPos = 0; + gStorage->summaryLastIndex = 0; + gStorage->summaryScreenMode = PSS_MODE_NORMAL; + } + else if (sCursorArea == CURSOR_AREA_IN_PARTY) + { + gStorage->summaryMonPtr.mon = gPlayerParty; + gStorage->summaryCursorPos = sCursorPosition; + gStorage->summaryLastIndex = CountPartyMons() - 1; + gStorage->summaryScreenMode = PSS_MODE_NORMAL; + } + else + { + gStorage->summaryMonPtr.box = GetBoxedMonPtr(StorageGetCurrentBox(), 0); + gStorage->summaryCursorPos = sCursorPosition; + gStorage->summaryLastIndex = IN_BOX_COUNT - 1; + gStorage->summaryScreenMode = PSS_MODE_BOX; + } +} + +void SetSelectionAfterSummaryScreen(void) +{ + if (sIsMonBeingMoved) + LoadSavedMovingMon(); + else + sCursorPosition = GetLastViewedMonIndex(); +} + +s16 CompactPartySlots(void) +{ + s16 retVal = -1; + u16 i, last; + + for (i = 0, last = 0; i < PARTY_SIZE; i++) + { + u16 species = GetMonData(gPlayerParty + i, MON_DATA_SPECIES); + if (species != SPECIES_NONE) + { + if (i != last) + gPlayerParty[last] = gPlayerParty[i]; + last++; + } + else if (retVal == -1) + retVal = i; + } + for (; last < PARTY_SIZE; last++) + ZeroMonData(gPlayerParty + last); + + return retVal; +} + +void SetMonMarkings(u8 markings) +{ + gStorage->displayMonMarkings = markings; + if (sIsMonBeingMoved) + SetMonData(&gStorage->movingMon, MON_DATA_MARKINGS, &markings); + else + { + if (sCursorArea == CURSOR_AREA_IN_PARTY) + SetMonData(gPlayerParty + sCursorPosition, MON_DATA_MARKINGS, &markings); + if (sCursorArea == CURSOR_AREA_IN_BOX) + SetCurrentBoxMonData(sCursorPosition, MON_DATA_MARKINGS, &markings); + } +} + +bool8 CanMovePartyMon(void) +{ + if (sCursorArea == CURSOR_AREA_IN_PARTY && !sIsMonBeingMoved && CountPartyAliveNonEggMonsExcept(sCursorPosition) == 0) + return TRUE; + else + return FALSE; +} + +bool8 CanShiftMon(void) +{ + if (sIsMonBeingMoved) + { + if (sCursorArea == CURSOR_AREA_IN_PARTY && CountPartyAliveNonEggMonsExcept(sCursorPosition) == 0) + { + if (gStorage->displayMonIsEgg || GetMonData(&gStorage->movingMon, MON_DATA_HP) == 0) + return FALSE; + } + return TRUE; + } + return FALSE; +} + +bool8 IsMonBeingMoved(void) +{ + return sIsMonBeingMoved; +} + +bool8 IsCursorOnBoxTitle(void) +{ + return (sCursorArea == CURSOR_AREA_BOX_TITLE); +} + +bool8 IsCursorOnCloseBox(void) +{ + return (sCursorArea == CURSOR_AREA_BUTTONS && sCursorPosition == 1); +} + +bool8 IsCursorInBox(void) +{ + return (sCursorArea == CURSOR_AREA_IN_BOX); +} + +static void TrySetDisplayMonData(void) +{ + gStorage->setMosaic = (sIsMonBeingMoved == FALSE); + if (!sIsMonBeingMoved) + { + switch (sCursorArea) + { + case CURSOR_AREA_IN_PARTY: + if (sCursorPosition < PARTY_SIZE) + { + SetDisplayMonData(&gPlayerParty[sCursorPosition], MODE_PARTY); + break; + } + // fallthrough + case CURSOR_AREA_BUTTONS: + case CURSOR_AREA_BOX_TITLE: + SetDisplayMonData(NULL, MODE_MOVE); + break; + case CURSOR_AREA_IN_BOX: + SetDisplayMonData(GetBoxedMonPtr(StorageGetCurrentBox(), sCursorPosition), MODE_BOX); + break; + } + } +} + +static void ReshowDisplayMon(void) +{ + if (sIsMonBeingMoved) + SetDisplayMonData(&sMonBeingCarried, MODE_PARTY); + else + TrySetDisplayMonData(); +} + +#define displayMonNicknameText displayMonTexts[0] +#define displayMonSpeciesNameText displayMonTexts[1] +#define displayMonGenderAndLevelText displayMonTexts[2] +#define displayMonItemNameText displayMonTexts[3] + +static void SetDisplayMonData(void *pokemon, u8 mode) +{ + u8 *txtPtr; + u16 gender; + bool8 sanityIsBagEgg; + + gStorage->displayMonItemId = ITEM_NONE; + gender = MON_MALE; + sanityIsBagEgg = FALSE; + if (mode == MODE_PARTY) + { + struct Pokemon *mon = (struct Pokemon *)pokemon; + + gStorage->displayMonSpecies = GetMonData(mon, MON_DATA_SPECIES2); + if (gStorage->displayMonSpecies != SPECIES_NONE) + { + sanityIsBagEgg = GetMonData(mon, MON_DATA_SANITY_IS_BAD_EGG); + if (sanityIsBagEgg) + gStorage->displayMonIsEgg = TRUE; + else + gStorage->displayMonIsEgg = GetMonData(mon, MON_DATA_IS_EGG); + + GetMonData(mon, MON_DATA_NICKNAME, gStorage->displayMonNickname); + StringGet_Nickname(gStorage->displayMonNickname); + gStorage->displayMonLevel = GetMonData(mon, MON_DATA_LEVEL); + gStorage->displayMonMarkings = GetMonData(mon, MON_DATA_MARKINGS); + gStorage->displayMonPersonality = GetMonData(mon, MON_DATA_PERSONALITY); + gStorage->displayMonPalette = GetMonFrontSpritePal(mon); + gender = GetMonGender(mon); + gStorage->displayMonItemId = GetMonData(mon, MON_DATA_HELD_ITEM); + } + } + else if (mode == MODE_BOX) + { + struct BoxPokemon *boxMon = (struct BoxPokemon *)pokemon; + + gStorage->displayMonSpecies = GetBoxMonData(pokemon, MON_DATA_SPECIES2); + if (gStorage->displayMonSpecies != SPECIES_NONE) + { + u32 otId = GetBoxMonData(boxMon, MON_DATA_OT_ID); + sanityIsBagEgg = GetBoxMonData(boxMon, MON_DATA_SANITY_IS_BAD_EGG); + if (sanityIsBagEgg) + gStorage->displayMonIsEgg = TRUE; + else + gStorage->displayMonIsEgg = GetBoxMonData(boxMon, MON_DATA_IS_EGG); + + GetBoxMonData(boxMon, MON_DATA_NICKNAME, gStorage->displayMonNickname); + StringGet_Nickname(gStorage->displayMonNickname); + gStorage->displayMonLevel = GetLevelFromBoxMonExp(boxMon); + gStorage->displayMonMarkings = GetBoxMonData(boxMon, MON_DATA_MARKINGS); + gStorage->displayMonPersonality = GetBoxMonData(boxMon, MON_DATA_PERSONALITY); + gStorage->displayMonPalette = GetMonSpritePalFromSpeciesAndPersonality(gStorage->displayMonSpecies, otId, gStorage->displayMonPersonality); + gender = GetGenderFromSpeciesAndPersonality(gStorage->displayMonSpecies, gStorage->displayMonPersonality); + gStorage->displayMonItemId = GetBoxMonData(boxMon, MON_DATA_HELD_ITEM); + } + } + else + { + gStorage->displayMonSpecies = SPECIES_NONE; + gStorage->displayMonItemId = ITEM_NONE; + } + + if (gStorage->displayMonSpecies == SPECIES_NONE) + { + StringFill(gStorage->displayMonNickname, CHAR_SPACE, 5); + StringFill(gStorage->displayMonNicknameText, CHAR_SPACE, 8); + StringFill(gStorage->displayMonSpeciesNameText, CHAR_SPACE, 8); + StringFill(gStorage->displayMonGenderAndLevelText, CHAR_SPACE, 8); + StringFill(gStorage->displayMonItemNameText, CHAR_SPACE, 8); + } + else if (gStorage->displayMonIsEgg) + { + if (sanityIsBagEgg) + StringCopyPadded(gStorage->displayMonNicknameText, gStorage->displayMonNickname, CHAR_SPACE, 5); + else + StringCopyPadded(gStorage->displayMonNicknameText, gText_EggNickname, CHAR_SPACE, 8); + + StringFill(gStorage->displayMonSpeciesNameText, CHAR_SPACE, 8); + StringFill(gStorage->displayMonGenderAndLevelText, CHAR_SPACE, 8); + StringFill(gStorage->displayMonItemNameText, CHAR_SPACE, 8); + } + else + { + if (gStorage->displayMonSpecies == SPECIES_NIDORAN_F || gStorage->displayMonSpecies == SPECIES_NIDORAN_M) + gender = MON_GENDERLESS; + + // Buffer nickname + StringCopyPadded(gStorage->displayMonNicknameText, gStorage->displayMonNickname, CHAR_SPACE, 5); + + // Buffer species name + txtPtr = gStorage->displayMonSpeciesNameText; + *(txtPtr)++ = CHAR_SLASH; + StringCopyPadded(txtPtr, gSpeciesNames[gStorage->displayMonSpecies], CHAR_SPACE, 5); + + // Buffer gender and level + txtPtr = gStorage->displayMonGenderAndLevelText; + *(txtPtr)++ = EXT_CTRL_CODE_BEGIN; + *(txtPtr)++ = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; + switch (gender) + { + case MON_MALE: + *(txtPtr)++ = TEXT_COLOR_RED; + *(txtPtr)++ = TEXT_COLOR_WHITE; + *(txtPtr)++ = TEXT_COLOR_LIGHT_RED; + *(txtPtr)++ = CHAR_MALE; + break; + case MON_FEMALE: + *(txtPtr)++ = TEXT_COLOR_GREEN; + *(txtPtr)++ = TEXT_COLOR_WHITE; + *(txtPtr)++ = TEXT_COLOR_LIGHT_GREEN; + *(txtPtr)++ = CHAR_FEMALE; + break; + default: + *(txtPtr)++ = TEXT_COLOR_DARK_GRAY; + *(txtPtr)++ = TEXT_COLOR_WHITE; + *(txtPtr)++ = TEXT_COLOR_LIGHT_GRAY; + *(txtPtr)++ = CHAR_SPACE; + break; + } + + *(txtPtr++) = EXT_CTRL_CODE_BEGIN; + *(txtPtr++) = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; + *(txtPtr++) = TEXT_COLOR_DARK_GRAY; + *(txtPtr++) = TEXT_COLOR_WHITE; + *(txtPtr++) = TEXT_COLOR_LIGHT_GRAY; + *(txtPtr++) = CHAR_SPACE; + *(txtPtr++) = CHAR_EXTRA_SYMBOL; + *(txtPtr++) = CHAR_LV_2; + + txtPtr = ConvertIntToDecimalStringN(txtPtr, gStorage->displayMonLevel, STR_CONV_MODE_LEFT_ALIGN, 3); + txtPtr[0] = CHAR_SPACE; + txtPtr[1] = EOS; + + // Buffer item name + if (gStorage->displayMonItemId != ITEM_NONE) + StringCopyPadded(gStorage->displayMonItemNameText, ItemId_GetName(gStorage->displayMonItemId), CHAR_SPACE, 8); + else + StringFill(gStorage->displayMonItemNameText, CHAR_SPACE, 8); + } +} + +#undef displayMonNicknameText +#undef displayMonSpeciesNameText +#undef displayMonGenderAndLevelText +#undef displayMonItemNameText + +static u8 HandleInput_InBox(void) +{ + switch (gStorage->inBoxMovingMode) + { + case MOVE_MODE_NORMAL: + default: + return HandleInput_InBox_Normal(); + case MOVE_MODE_MULTIPLE_SELECTING: + return HandleInput_InBox_GrabbingMultiple(); + case MOVE_MODE_MULTIPLE_MOVING: + return HandleInput_InBox_MovingMultiple(); + } +} + +static u8 HandleInput_InBox_Normal(void) +{ + u8 input; + s8 cursorArea; + s8 cursorPosition; + + do + { + cursorArea = sCursorArea; + cursorPosition = sCursorPosition; + gStorage->cursorVerticalWrap = 0; + gStorage->cursorHorizontalWrap = 0; + gStorage->cursorFlipTimer = 0; + if (JOY_REPT(DPAD_UP)) + { + input = INPUT_MOVE_CURSOR; + if (sCursorPosition >= IN_BOX_COLUMNS) + cursorPosition -= IN_BOX_COLUMNS; + else + { + cursorArea = CURSOR_AREA_BOX_TITLE; + cursorPosition = 0; + } + break; + } + else if (JOY_REPT(DPAD_DOWN)) + { + input = INPUT_MOVE_CURSOR; + cursorPosition += IN_BOX_COLUMNS; + if (cursorPosition >= IN_BOX_COUNT) + { + cursorArea = CURSOR_AREA_BUTTONS; + cursorPosition -= IN_BOX_COUNT; + cursorPosition /= 3; + gStorage->cursorVerticalWrap = 1; + gStorage->cursorFlipTimer = 1; + } + break; + } + else if (JOY_REPT(DPAD_LEFT)) + { + input = INPUT_MOVE_CURSOR; + if (sCursorPosition % IN_BOX_COLUMNS != 0) + cursorPosition--; + else + { + gStorage->cursorHorizontalWrap = -1; + cursorPosition += (IN_BOX_COLUMNS - 1); + } + break; + } + else if (JOY_REPT(DPAD_RIGHT)) + { + input = INPUT_MOVE_CURSOR; + if ((sCursorPosition + 1) % IN_BOX_COLUMNS != 0) + cursorPosition++; + else + { + gStorage->cursorHorizontalWrap = 1; + cursorPosition -= (IN_BOX_COLUMNS - 1); + } + break; + } + else if (JOY_NEW(START_BUTTON)) + { + input = INPUT_MOVE_CURSOR; + cursorArea = CURSOR_AREA_BOX_TITLE; + cursorPosition = 0; + break; + } + + if ((JOY_NEW(A_BUTTON)) && SetSelectionMenuTexts()) + { + if (!sInMultiMoveMode) + return INPUT_IN_MENU; + + if (gStorage->boxOption != OPTION_MOVE_MONS || sIsMonBeingMoved == TRUE) + { + switch (GetMenuItemTextId(0)) + { + case MENU_TEXT_STORE: + return INPUT_DEPOSIT; + case MENU_TEXT_WITHDRAW: + return INPUT_WITHDRAW; + case MENU_TEXT_MOVE: + return INPUT_MOVE_MON; + case MENU_TEXT_SHIFT: + return INPUT_SHIFT_MON; + case MENU_TEXT_PLACE: + return INPUT_PLACE_MON; + case MENU_TEXT_TAKE: + return INPUT_TAKE_ITEM; + case MENU_TEXT_GIVE: + return INPUT_GIVE_ITEM; + case MENU_TEXT_SWITCH: + return INPUT_SWITCH_ITEMS; + } + } + else + { + gStorage->inBoxMovingMode = MOVE_MODE_MULTIPLE_SELECTING; + return INPUT_MULTIMOVE_START; + } + } + + if (JOY_NEW(B_BUTTON)) + return INPUT_PRESSED_B; + + if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) + { + if (JOY_HELD(L_BUTTON)) + return INPUT_SCROLL_LEFT; + if (JOY_HELD(R_BUTTON)) + return INPUT_SCROLL_RIGHT; + } + + if (JOY_NEW(SELECT_BUTTON)) + { + ToggleCursorMultiMoveMode(); + return INPUT_NONE; + } + + input = INPUT_NONE; + + } while (FALSE); + + if (input != INPUT_NONE) + SetCursorPosition(cursorArea, cursorPosition); + + return input; +} + +static u8 HandleInput_InBox_GrabbingMultiple(void) +{ + if (JOY_HELD(A_BUTTON)) + { + if (JOY_REPT(DPAD_UP)) + { + if (sCursorPosition / IN_BOX_COLUMNS != 0) + { + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition - IN_BOX_COLUMNS); + return INPUT_MULTIMOVE_CHANGE_SELECTION; + } + else + return INPUT_MULTIMOVE_UNABLE; + } + else if (JOY_REPT(DPAD_DOWN)) + { + if (sCursorPosition + IN_BOX_COLUMNS < IN_BOX_COUNT) + { + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition + IN_BOX_COLUMNS); + return INPUT_MULTIMOVE_CHANGE_SELECTION; + } + else + return INPUT_MULTIMOVE_UNABLE; + } + else if (JOY_REPT(DPAD_LEFT)) + { + if (sCursorPosition % IN_BOX_COLUMNS != 0) + { + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition - 1); + return INPUT_MULTIMOVE_CHANGE_SELECTION; + } + else + return INPUT_MULTIMOVE_UNABLE; + } + else if (JOY_REPT(DPAD_RIGHT)) + { + if ((sCursorPosition + 1) % IN_BOX_COLUMNS != 0) + { + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition + 1); + return INPUT_MULTIMOVE_CHANGE_SELECTION; + } + else + return INPUT_MULTIMOVE_UNABLE; + } + else + return INPUT_NONE; + } + else + { + if (MultiMove_GetOriginPosition() == sCursorPosition) + { + gStorage->inBoxMovingMode = MOVE_MODE_NORMAL; + gStorage->cursorShadowSprite->invisible = FALSE; + return INPUT_MULTIMOVE_SINGLE; + } + else + { + sIsMonBeingMoved = (gStorage->displayMonSpecies != SPECIES_NONE); + gStorage->inBoxMovingMode = MOVE_MODE_MULTIPLE_MOVING; + sMovingMonOrigBoxId = StorageGetCurrentBox(); + return INPUT_MULTIMOVE_GRAB_SELECTION; + } + } +} + +static u8 HandleInput_InBox_MovingMultiple(void) +{ + if (JOY_REPT(DPAD_UP)) + { + if (MultiMove_TryMoveGroup(0)) + { + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition - IN_BOX_COLUMNS); + return INPUT_MULTIMOVE_MOVE_MONS; + } + else + return INPUT_MULTIMOVE_UNABLE; + } + else if (JOY_REPT(DPAD_DOWN)) + { + if (MultiMove_TryMoveGroup(1)) + { + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition + IN_BOX_COLUMNS); + return INPUT_MULTIMOVE_MOVE_MONS; + } + else + return INPUT_MULTIMOVE_UNABLE; + } + else if (JOY_REPT(DPAD_LEFT)) + { + if (MultiMove_TryMoveGroup(2)) + { + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition - 1); + return INPUT_MULTIMOVE_MOVE_MONS; + } + else + return INPUT_SCROLL_LEFT; + } + else if (JOY_REPT(DPAD_RIGHT)) + { + if (MultiMove_TryMoveGroup(3)) + { + SetCursorPosition(CURSOR_AREA_IN_BOX, sCursorPosition + 1); + return INPUT_MULTIMOVE_MOVE_MONS; + } + else + return INPUT_SCROLL_RIGHT; + } + else if (JOY_NEW(A_BUTTON)) + { + if (MultiMove_CanPlaceSelection()) + { + sIsMonBeingMoved = FALSE; + gStorage->inBoxMovingMode = MOVE_MODE_NORMAL; + return INPUT_MULTIMOVE_PLACE_MONS; + } + else + return INPUT_MULTIMOVE_UNABLE; + } + else if (JOY_NEW(B_BUTTON)) + return INPUT_MULTIMOVE_UNABLE; + + else + { + if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) + { + if (JOY_HELD(L_BUTTON)) + return INPUT_SCROLL_LEFT; + if (JOY_HELD(R_BUTTON)) + return INPUT_SCROLL_RIGHT; + } + + return INPUT_NONE; + } +} + +static u8 HandleInput_InParty(void) +{ + u8 input; + bool8 gotoBox; + s8 cursorArea; + s8 cursorPosition; + + do + { + cursorArea = sCursorArea; + cursorPosition = sCursorPosition; + gStorage->cursorHorizontalWrap = 0; + gStorage->cursorVerticalWrap = 0; + gStorage->cursorFlipTimer = 0; + gotoBox = FALSE; + input = INPUT_NONE; + + if (JOY_REPT(DPAD_UP)) + { + if (--cursorPosition < 0) + cursorPosition = PARTY_SIZE; + if (cursorPosition != sCursorPosition) + input = INPUT_MOVE_CURSOR; + break; + } + else if (JOY_REPT(DPAD_DOWN)) + { + if (++cursorPosition > PARTY_SIZE) + cursorPosition = 0; + if (cursorPosition != sCursorPosition) + input = INPUT_MOVE_CURSOR; + break; + } + else if (JOY_REPT(DPAD_LEFT) && sCursorPosition != 0) + { + input = INPUT_MOVE_CURSOR; + gStorage->cursorPrevPartyPos = sCursorPosition; + cursorPosition = 0; + break; + } + else if (JOY_REPT(DPAD_RIGHT)) + { + if (sCursorPosition == 0) + { + input = INPUT_MOVE_CURSOR; + cursorPosition = gStorage->cursorPrevPartyPos; + } + else + { + input = INPUT_HIDE_PARTY; + cursorArea = CURSOR_AREA_IN_BOX; + cursorPosition = 0; + } + break; + } + + if (JOY_NEW(A_BUTTON)) + { + if (sCursorPosition == PARTY_SIZE) + { + if (gStorage->boxOption == OPTION_DEPOSIT) + return INPUT_CLOSE_BOX; + + gotoBox = TRUE; + } + else if (SetSelectionMenuTexts()) + { + if (!sInMultiMoveMode) + return INPUT_IN_MENU; + + switch (GetMenuItemTextId(0)) + { + case MENU_TEXT_STORE: + return INPUT_DEPOSIT; + case MENU_TEXT_WITHDRAW: + return INPUT_WITHDRAW; + case MENU_TEXT_MOVE: + return INPUT_MOVE_MON; + case MENU_TEXT_SHIFT: + return INPUT_SHIFT_MON; + case MENU_TEXT_PLACE: + return INPUT_PLACE_MON; + case MENU_TEXT_TAKE: + return INPUT_TAKE_ITEM; + case MENU_TEXT_GIVE: + return INPUT_GIVE_ITEM; + case MENU_TEXT_SWITCH: + return INPUT_SWITCH_ITEMS; + } + } + } + + if (JOY_NEW(B_BUTTON)) + { + if (gStorage->boxOption == OPTION_DEPOSIT) + return INPUT_PRESSED_B; + + gotoBox = TRUE; + } + + if (gotoBox) + { + input = INPUT_HIDE_PARTY; + cursorArea = CURSOR_AREA_IN_BOX; + cursorPosition = 0; + } + else if (JOY_NEW(SELECT_BUTTON)) + { + ToggleCursorMultiMoveMode(); + return INPUT_NONE; + } + + } while (FALSE); + + if (input != INPUT_NONE && input != INPUT_HIDE_PARTY) + SetCursorPosition(cursorArea, cursorPosition); + + return input; +} + +static u8 HandleInput_BoxTitle(void) +{ + u8 input; + s8 cursorArea; + s8 cursorPosition; + + do + { + gStorage->cursorHorizontalWrap = 0; + gStorage->cursorVerticalWrap = 0; + gStorage->cursorFlipTimer = 0; + + if (JOY_REPT(DPAD_UP)) + { + input = INPUT_MOVE_CURSOR; + cursorArea = CURSOR_AREA_BUTTONS; + cursorPosition = 0; + gStorage->cursorFlipTimer = 1; + break; + } + else if (JOY_REPT(DPAD_DOWN)) + { + input = INPUT_MOVE_CURSOR; + cursorArea = CURSOR_AREA_IN_BOX; + cursorPosition = 2; + break; + } + + if (JOY_HELD(DPAD_LEFT)) + return INPUT_SCROLL_LEFT; + if (JOY_HELD(DPAD_RIGHT)) + return INPUT_SCROLL_RIGHT; + + if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) + { + if (JOY_HELD(L_BUTTON)) + return INPUT_SCROLL_LEFT; + if (JOY_HELD(R_BUTTON)) + return INPUT_SCROLL_RIGHT; + } + + if (JOY_NEW(A_BUTTON)) + { + AnimateBoxScrollArrows(FALSE); + AddBoxMenu(); + return INPUT_BOX_OPTIONS; + } + + if (JOY_NEW(B_BUTTON)) + return INPUT_PRESSED_B; + + if (JOY_NEW(SELECT_BUTTON)) + { + ToggleCursorMultiMoveMode(); + return INPUT_NONE; + } + + input = INPUT_NONE; + + } while (FALSE); + + if (input != INPUT_NONE) + { + if (cursorArea != CURSOR_AREA_BOX_TITLE) + AnimateBoxScrollArrows(FALSE); + SetCursorPosition(cursorArea, cursorPosition); + } + + return input; +} + +static u8 HandleInput_OnButtons(void) +{ + u8 input; + s8 cursorArea; + s8 cursorPosition; + s8 prevPos; + + do + { + cursorArea = sCursorArea; + cursorPosition = sCursorPosition; + gStorage->cursorHorizontalWrap = 0; + gStorage->cursorVerticalWrap = 0; + gStorage->cursorFlipTimer = 0; + + if (JOY_REPT(DPAD_UP)) + { + input = INPUT_MOVE_CURSOR; + cursorArea = CURSOR_AREA_IN_BOX; + gStorage->cursorVerticalWrap = -1; + if (sCursorPosition == 0) + cursorPosition = IN_BOX_COUNT - 1 - 5; + else + cursorPosition = IN_BOX_COUNT - 1; + gStorage->cursorFlipTimer = 1; + break; + } + else if (JOY_REPT(DPAD_DOWN | START_BUTTON)) + { + input = INPUT_MOVE_CURSOR; + cursorArea = CURSOR_AREA_BOX_TITLE; + cursorPosition = 0; + gStorage->cursorFlipTimer = 1; + break; + } + + if (JOY_REPT(DPAD_LEFT)) + { + input = INPUT_MOVE_CURSOR; + if (--cursorPosition < 0) + cursorPosition = 1; + break; + } + else if (JOY_REPT(DPAD_RIGHT)) + { + input = INPUT_MOVE_CURSOR; + if (++cursorPosition > 1) + cursorPosition = 0; + break; + } + + if (JOY_NEW(A_BUTTON)) + return cursorPosition == 0 ? INPUT_SHOW_PARTY : INPUT_CLOSE_BOX; + + if (JOY_NEW(B_BUTTON)) + return INPUT_PRESSED_B; + + if (JOY_NEW(SELECT_BUTTON)) + { + ToggleCursorMultiMoveMode(); + return INPUT_NONE; + } + + input = INPUT_NONE; + } while (FALSE); + + if (input != INPUT_NONE) + SetCursorPosition(cursorArea, cursorPosition); + + return input; +} + +u8 HandleInput(void) +{ + struct + { + u8 (*func)(void); + s8 area; + } + static const inputFuncs[] = { + {HandleInput_InBox, CURSOR_AREA_IN_BOX}, + {HandleInput_InParty, CURSOR_AREA_IN_PARTY}, + {HandleInput_BoxTitle, CURSOR_AREA_BOX_TITLE}, + {HandleInput_OnButtons, CURSOR_AREA_BUTTONS}, + {NULL, 0}, + }; + + u16 i = 0; + while (inputFuncs[i].func != NULL) + { + if (inputFuncs[i].area == sCursorArea) + return inputFuncs[i].func(); + i++; + } + + return INPUT_NONE; +} + +static void AddBoxMenu(void) +{ + InitMenu(); + SetMenuText(MENU_TEXT_JUMP); + SetMenuText(MENU_TEXT_WALLPAPER); + SetMenuText(MENU_TEXT_NAME); + SetMenuText(MENU_TEXT_CANCEL); +} + +static bool8 SetSelectionMenuTexts(void) +{ + InitMenu(); + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + return SetMenuTextsForMon(); + else + return SetMenuTextsForItem(); +} + +static bool8 SetMenuTextsForMon(void) +{ + u16 species = GetSpeciesAtCursorPosition(); + + switch (gStorage->boxOption) + { + case OPTION_DEPOSIT: + if (species != SPECIES_NONE) + SetMenuText(MENU_TEXT_STORE); + else + return FALSE; + break; + case OPTION_WITHDRAW: + if (species != SPECIES_NONE) + SetMenuText(MENU_TEXT_WITHDRAW); + else + return FALSE; + break; + case OPTION_MOVE_MONS: + if (sIsMonBeingMoved) + { + if (species != SPECIES_NONE) + SetMenuText(MENU_TEXT_SHIFT); + else + SetMenuText(MENU_TEXT_PLACE); + } + else + { + if (species != SPECIES_NONE) + SetMenuText(MENU_TEXT_MOVE); + else + return FALSE; + } + break; + case OPTION_MOVE_ITEMS: + default: + return FALSE; + } + + SetMenuText(MENU_TEXT_SUMMARY); + if (gStorage->boxOption == OPTION_MOVE_MONS) + { + if (!sCursorArea) + SetMenuText(MENU_TEXT_WITHDRAW); + else + SetMenuText(MENU_TEXT_STORE); + } + + SetMenuText(MENU_TEXT_MARK); + SetMenuText(MENU_TEXT_RELEASE); + SetMenuText(MENU_TEXT_CANCEL); + return TRUE; +} + +static bool8 SetMenuTextsForItem(void) +{ + if (gStorage->displayMonSpecies == SPECIES_EGG) + return FALSE; + + if (!IsActiveItemMoving()) + { + if (gStorage->displayMonItemId == ITEM_NONE) + { + if (gStorage->displayMonSpecies == SPECIES_NONE) + return FALSE; + + SetMenuText(MENU_TEXT_GIVE2); + } + else + { + if (!ItemIsMail(gStorage->displayMonItemId)) + { + SetMenuText(MENU_TEXT_TAKE); + SetMenuText(MENU_TEXT_BAG); + } + SetMenuText(MENU_TEXT_INFO); + } + } + else + { + if (gStorage->displayMonItemId == ITEM_NONE) + { + if (gStorage->displayMonSpecies == SPECIES_NONE) + return FALSE; + + SetMenuText(MENU_TEXT_GIVE); + } + else + { + if (ItemIsMail(gStorage->displayMonItemId) == TRUE) + return FALSE; + + SetMenuText(MENU_TEXT_SWITCH); + } + } + + SetMenuText(MENU_TEXT_CANCEL); + return TRUE; +} + +static void SpriteCB_CursorShadow(struct Sprite *sprite) +{ + sprite->x = gStorage->cursorSprite->x; + sprite->y = gStorage->cursorSprite->y + 20; +} + +static void CreateCursorSprites(void) +{ + u16 x, y; + u8 spriteId; + u8 priority, subpriority; + struct SpriteSheet spriteSheets[] = { + {sHandCursorTiles, 0x800, GFXTAG_CURSOR}, + {sHandCursorShadowTiles, 0x80, GFXTAG_CURSOR_SHADOW}, + {} + }; + + struct SpritePalette spritePalettes[] = { + {sPokeStorageMisc1Pal, PALTAG_MISC_1}, + {} + }; + + static const struct OamData sOamData_Cursor = { + .shape = SPRITE_SHAPE(32x32), + .size = SPRITE_SIZE(32x32), + .priority = 1, + }; + static const struct OamData sOamData_CursorShadow = { + .shape = SPRITE_SHAPE(16x16), + .size = SPRITE_SIZE(16x16), + .priority = 1, + }; + + static const union AnimCmd sAnim_Cursor_Bouncing[] = { + ANIMCMD_FRAME(0, 30), + ANIMCMD_FRAME(16, 30), + ANIMCMD_JUMP(0) + }; + static const union AnimCmd sAnim_Cursor_Still[] = { + ANIMCMD_FRAME(0, 5), + ANIMCMD_END + }; + static const union AnimCmd sAnim_Cursor_Open[] = { + ANIMCMD_FRAME(32, 5), + ANIMCMD_END + }; + static const union AnimCmd sAnim_Cursor_Fist[] = { + ANIMCMD_FRAME(48, 5), + ANIMCMD_END + }; + + static const union AnimCmd *const sAnims_Cursor[] = { + [CURSOR_ANIM_BOUNCE] = sAnim_Cursor_Bouncing, + [CURSOR_ANIM_STILL] = sAnim_Cursor_Still, + [CURSOR_ANIM_OPEN] = sAnim_Cursor_Open, + [CURSOR_ANIM_FIST] = sAnim_Cursor_Fist, + }; + + static const struct SpriteTemplate sSpriteTemplate_Cursor = { + .tileTag = GFXTAG_CURSOR, + .paletteTag = PALTAG_MISC_2, + .oam = &sOamData_Cursor, + .anims = sAnims_Cursor, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy, + }; + + static const struct SpriteTemplate sSpriteTemplate_CursorShadow = { + .tileTag = GFXTAG_CURSOR_SHADOW, + .paletteTag = PALTAG_MISC_2, + .oam = &sOamData_CursorShadow, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCB_CursorShadow, + }; + + LoadSpriteSheets(spriteSheets); + LoadSpritePalettes(spritePalettes); + gStorage->cursorPalNums[0] = IndexOfSpritePaletteTag(PALTAG_MISC_2); + gStorage->cursorPalNums[1] = IndexOfSpritePaletteTag(PALTAG_MISC_1); + + GetCursorCoordsByPos(sCursorArea, sCursorPosition, &x, &y); + spriteId = CreateSprite(&sSpriteTemplate_Cursor, x, y, 6); + if (spriteId != MAX_SPRITES) + { + gStorage->cursorSprite = &gSprites[spriteId]; + gStorage->cursorSprite->oam.paletteNum = gStorage->cursorPalNums[sInMultiMoveMode]; + gStorage->cursorSprite->oam.priority = 1; + if (sIsMonBeingMoved) + StartSpriteAnim(gStorage->cursorSprite, 3); + } + else + gStorage->cursorSprite = NULL; + + + if (sCursorArea == CURSOR_AREA_IN_PARTY) + { + subpriority = 13; + priority = 1; + } + else + { + subpriority = 21; + priority = 2; + } + + spriteId = CreateSprite(&sSpriteTemplate_CursorShadow, 0, 0, subpriority); + if (spriteId != MAX_SPRITES) + { + gStorage->cursorShadowSprite = &gSprites[spriteId]; + gStorage->cursorShadowSprite->oam.priority = priority; + if (sCursorArea) + gStorage->cursorShadowSprite->invisible = 1; + } + else + gStorage->cursorShadowSprite = NULL; +} + +static void ToggleCursorMultiMoveMode(void) +{ + sInMultiMoveMode = !sInMultiMoveMode; + gStorage->cursorSprite->oam.paletteNum = gStorage->cursorPalNums[sInMultiMoveMode]; +} + +u8 GetBoxCursorPosition(void) +{ + return sCursorPosition; +} + +void GetCursorBoxColumnAndRow(u8 *column, u8 *row) +{ + if (sCursorArea == CURSOR_AREA_IN_BOX) + { + *column = sCursorPosition % IN_BOX_COLUMNS; + *row = sCursorPosition / IN_BOX_COLUMNS; + } + else + { + *column = 0; + *row = 0; + } +} + +void StartCursorAnim(u8 animNum) +{ + StartSpriteAnim(gStorage->cursorSprite, animNum); +} + +u8 GetMovingMonOriginalBoxId(void) +{ + return sMovingMonOrigBoxId; +} + +void SetCursorPriorityTo1(void) +{ + gStorage->cursorSprite->oam.priority = 1; +} + +void TryHideItemAtCursor(void) +{ + if (sCursorArea == CURSOR_AREA_IN_BOX) + TryHideItemIconAtPos(CURSOR_AREA_IN_BOX, sCursorPosition); +} + +void TryShowItemAtCursor(void) +{ + if (sCursorArea == CURSOR_AREA_IN_BOX) + TryLoadItemIconAtPos(CURSOR_AREA_IN_BOX, sCursorPosition); +} + +static const u8 *const sMenuTexts[] = { + [MENU_TEXT_CANCEL] = gPCText_Cancel, + [MENU_TEXT_STORE] = gPCText_Store, + [MENU_TEXT_WITHDRAW] = gPCText_Withdraw, + [MENU_TEXT_MOVE] = gPCText_Move, + [MENU_TEXT_SHIFT] = gPCText_Shift, + [MENU_TEXT_PLACE] = gPCText_Place, + [MENU_TEXT_SUMMARY] = gPCText_Summary, + [MENU_TEXT_RELEASE] = gPCText_Release, + [MENU_TEXT_MARK] = gPCText_Mark, + [MENU_TEXT_JUMP] = gPCText_Jump, + [MENU_TEXT_WALLPAPER] = gPCText_Wallpaper, + [MENU_TEXT_NAME] = gPCText_Name, + [MENU_TEXT_TAKE] = gPCText_Take, + [MENU_TEXT_GIVE] = gPCText_Give, + [MENU_TEXT_GIVE2] = gPCText_Give, + [MENU_TEXT_SWITCH] = gPCText_Switch, + [MENU_TEXT_BAG] = gPCText_Bag, + [MENU_TEXT_INFO] = gPCText_Info, + [MENU_TEXT_SCENERY_1] = gPCText_Scenery1, + [MENU_TEXT_SCENERY_2] = gPCText_Scenery2, + [MENU_TEXT_SCENERY_3] = gPCText_Scenery3, + [MENU_TEXT_ETCETERA] = gPCText_Etcetera, + [MENU_TEXT_FOREST] = gPCText_Forest, + [MENU_TEXT_CITY] = gPCText_City, + [MENU_TEXT_DESERT] = gPCText_Desert, + [MENU_TEXT_SAVANNA] = gPCText_Savanna, + [MENU_TEXT_CRAG] = gPCText_Crag, + [MENU_TEXT_VOLCANO] = gPCText_Volcano, + [MENU_TEXT_SNOW] = gPCText_Snow, + [MENU_TEXT_CAVE] = gPCText_Cave, + [MENU_TEXT_BEACH] = gPCText_Beach, + [MENU_TEXT_SEAFLOOR] = gPCText_Seafloor, + [MENU_TEXT_RIVER] = gPCText_River, + [MENU_TEXT_SKY] = gPCText_Sky, + [MENU_TEXT_POLKADOT] = gPCText_PolkaDot, + [MENU_TEXT_POKECENTER] = gPCText_Pokecenter, + [MENU_TEXT_MACHINE] = gPCText_Machine, + [MENU_TEXT_SIMPLE] = gPCText_Simple, +}; + +void InitMenu(void) +{ + gStorage->menuItemsCount = 0; + gStorage->menuWidth = 0; + gStorage->menuWindow.bg = 0; + gStorage->menuWindow.paletteNum = 15; + gStorage->menuWindow.baseBlock = 92; +} + +void SetMenuText(u8 textId) +{ + if (gStorage->menuItemsCount < ARRAY_COUNT(gStorage->menuItems)) + { + u8 len; + struct StorageMenu *menu = &gStorage->menuItems[gStorage->menuItemsCount]; + + menu->text = sMenuTexts[textId]; + menu->textId = textId; + len = StringLength(menu->text); + if (len > gStorage->menuWidth) + gStorage->menuWidth = len; + + gStorage->menuItemsCount++; + } +} + +s8 GetMenuItemTextId(u8 menuIndex) +{ + if (menuIndex >= gStorage->menuItemsCount) + return MENU_B_PRESSED; + else + return gStorage->menuItems[menuIndex].textId; +} + +void AddMenu(void) +{ + gStorage->menuWindow.width = gStorage->menuWidth + 2; + gStorage->menuWindow.height = 2 * gStorage->menuItemsCount; + gStorage->menuWindow.tilemapLeft = 29 - gStorage->menuWindow.width; + gStorage->menuWindow.tilemapTop = 15 - gStorage->menuWindow.height; + gStorage->menuWindowId = AddWindow(&gStorage->menuWindow); + ClearWindowTilemap(gStorage->menuWindowId); + DrawStdFrameWithCustomTileAndPalette(gStorage->menuWindowId, FALSE, 11, 14); + PrintTextArray(gStorage->menuWindowId, FONT_1, 8, 2, 16, gStorage->menuItemsCount, (void *)gStorage->menuItems); + Menu_InitCursor(gStorage->menuWindowId, FONT_1, 0, 2, 16, gStorage->menuItemsCount, 0); + ScheduleBgCopyTilemapToVram(0); + gStorage->menuUnusedField = 0; +} + +bool8 IsMenuLoading(void) +{ + // Possibly stubbed out debug code? + return FALSE; +} + +s16 HandleMenuInput(void) +{ + s32 input = MENU_NOTHING_CHOSEN; + + do + { + if (JOY_NEW(A_BUTTON)) + { + input = Menu_GetCursorPos(); + break; + } + else if (JOY_NEW(B_BUTTON)) + { + PlaySE(SE_SELECT); + input = MENU_B_PRESSED; + } + + if (JOY_NEW(DPAD_UP)) + { + PlaySE(SE_SELECT); + Menu_MoveCursor(-1); + } + else if (JOY_NEW(DPAD_DOWN)) + { + PlaySE(SE_SELECT); + Menu_MoveCursor(1); + } + } while (FALSE); + + if (input != MENU_NOTHING_CHOSEN) + RemoveMenu(); + + if (input >= 0) + input = gStorage->menuItems[input].textId; + + return input; +} + +void RemoveMenu(void) +{ + ClearStdWindowAndFrameToTransparent(gStorage->menuWindowId, TRUE); + RemoveWindow(gStorage->menuWindowId); +} diff --git a/src/pokemon_storage_system_graphics.c b/src/pokemon_storage_system_graphics.c new file mode 100644 index 000000000..c6b45194a --- /dev/null +++ b/src/pokemon_storage_system_graphics.c @@ -0,0 +1,1594 @@ +#include "global.h" +#include "gflib.h" +#include "event_data.h" +#include "graphics.h" +#include "new_menu_helpers.h" +#include "pokemon_icon.h" +#include "pokemon_storage_system_internal.h" +#include "strings.h" +#include "task.h" +#include "trig.h" + +static void SpriteCB_BoxMonIconScrollOut(struct Sprite *sprite); +static void SetBoxSpeciesAndPersonalities(u8 boxId); +static void MovePartySpriteToNextSlot(struct Sprite *sprite, u16 idx); +static void SpriteCB_MovePartySpriteToNextSlot(struct Sprite *sprite); +static void DestroyBoxMonIcon(struct Sprite *sprite); +static void SpriteCB_HeldMon(struct Sprite *sprite); +static void Task_InitBox(u8 taskId); +static s8 DetermineBoxScrollDirection(u8 boxId); +static void LoadWallpaperGfx(u8 wallpaperId, s8 direction); +static bool32 WaitForWallpaperGfxLoad(void); +static void DrawWallpaper(void *unused, const void *tilemap, s8 direction, u8 offset); +static void TrimOldWallpaper(void *buffer); +static void InitBoxTitle(u8 wallpaperId); +static void CreateIncomingBoxTitle(u8 wallpaperId, s8 direction); +static void SpriteCB_IncomingBoxTitle(struct Sprite *sprite); +static void SpriteCB_OutgoingBoxTitle(struct Sprite *sprite); +static s16 GetBoxTitleBaseX(const u8 *boxName); +static void CycleBoxTitleSprites(void); +static void CycleBoxTitleColor(void); +static void CreateBoxScrollArrows(void); +static void StartBoxScrollArrowsSlide(s8 direction); +static void StopBoxScrollArrowsSlide(void); +static void SpriteCB_BoxScrollArrow(struct Sprite *sprite); + +static const struct OamData sOamData_MonIcon; + +static const struct SpriteTemplate sSpriteTemplate_MonIcon = { + .tileTag = GFXTAG_MON_ICON, + .paletteTag = PALTAG_MON_ICON_0, + .oam = &sOamData_MonIcon, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy +}; + +static const struct OamData sOamData_MonIcon = { + .y = 0, + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = SPRITE_SHAPE(32x32), + .x = 0, + .matrixNum = 0, + .size = SPRITE_SIZE(32x32), + .tileNum = 0x000, + .priority = 0, + .paletteNum = 0 +}; + +static const union AffineAnimCmd sAffineAnim_ReleaseMon_Release[] = { + AFFINEANIMCMD_FRAME(-2, -2, 0, 120), + AFFINEANIMCMD_END +}; + +static const union AffineAnimCmd sAffineAnim_ReleaseMon_ComeBack[] = { + AFFINEANIMCMD_FRAME(16, 16, 0, 0), + AFFINEANIMCMD_FRAME(16, 16, 0, 15), + AFFINEANIMCMD_END +}; + +static const union AffineAnimCmd *const sAffineAnims_ReleaseMon[] = { + [RELEASE_ANIM_RELEASE] = sAffineAnim_ReleaseMon_Release, + [RELEASE_ANIM_COME_BACK] = sAffineAnim_ReleaseMon_ComeBack, +}; + +static const u16 sWallpaperPalettes_Forest[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/forest/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/forest/box.gbapal"), +}; +static const u32 sWallpaperTiles_Forest[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/forest/tiles.4bpp.lz"); +static const u32 sWallpaperTilemap_Forest[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/forest/tilemap.bin.lz"); + +static const u16 sWallpaperPalettes_City[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/city/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/city/box.gbapal"), +}; +static const u32 sWallpaperTiles_City[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/city/tiles.4bpp.lz"); +static const u32 sWallpaperTilemap_City[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/city/tilemap.bin.lz"); + +static const u16 sWallpaperPalettes_Desert[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/desert/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/desert/box.gbapal"), +}; +static const u32 sWallpaperTiles_Desert[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/desert/tiles.4bpp.lz"); +static const u32 sWallpaperTilemap_Desert[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/desert/tilemap.bin.lz"); + +static const u16 sWallpaperPalettes_Savanna[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/savanna/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/savanna/box.gbapal"), +}; +static const u32 sWallpaperTiles_Savanna[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/savanna/tiles.4bpp.lz"); +static const u32 sWallpaperTilemap_Savanna[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/savanna/tilemap.bin.lz"); + +static const u16 sWallpaperPalettes_Crag[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/crag/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/crag/box.gbapal"), +}; +static const u32 sWallpaperTiles_Crag[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/crag/tiles.4bpp.lz"); +static const u32 sWallpaperTilemap_Crag[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/crag/tilemap.bin.lz"); + +static const u16 sWallpaperPalettes_Volcano[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/volcano/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/volcano/box.gbapal"), +}; +static const u32 sWallpaperTiles_Volcano[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/volcano/tiles.4bpp.lz"); +static const u8 sUnusedSpace1[4] = {}; +static const u32 sWallpaperTilemap_Volcano[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/volcano/tilemap.bin.lz"); + +static const u16 sWallpaperPalettes_Snow[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/snow/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/snow/box.gbapal"), +}; +static const u32 sWallpaperTiles_Snow[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/snow/tiles.4bpp.lz"); +static const u32 sWallpaperTilemap_Snow[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/snow/tilemap.bin.lz"); + +static const u16 sWallpaperPalettes_Cave[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/cave/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/cave/box.gbapal"), +}; +static const u32 sWallpaperTiles_Cave[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/cave/tiles.4bpp.lz"); +static const u32 sWallpaperTilemap_Cave[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/cave/tilemap.bin.lz"); + +static const u16 sWallpaperPalettes_Beach[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/beach/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/beach/box.gbapal"), +}; +static const u32 sWallpaperTiles_Beach[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/beach/tiles.4bpp.lz"); +static const u32 sWallpaperTilemap_Beach[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/beach/tilemap.bin.lz"); + +static const u16 sWallpaperPalettes_Seafloor[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/seafloor/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/seafloor/box.gbapal"), +}; +static const u32 sWallpaperTiles_Seafloor[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/seafloor/tiles.4bpp.lz"); +static const u32 sWallpaperTilemap_Seafloor[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/seafloor/tilemap.bin.lz"); + +static const u16 sWallpaperPalettes_River[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/river/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/river/box.gbapal"), +}; +static const u32 sWallpaperTiles_River[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/river/tiles.4bpp.lz"); +static const u32 sWallpaperTilemap_River[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/river/tilemap.bin.lz"); + +static const u16 sWallpaperPalettes_Sky[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/sky/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/sky/box.gbapal"), +}; +static const u32 sWallpaperTiles_Sky[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/sky/tiles.4bpp.lz"); +static const u32 sWallpaperTilemap_Sky[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/sky/tilemap.bin.lz"); + +static const u16 sWallpaperPalettes_Stars[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/stars/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/stars/box.gbapal"), +}; +static const u8 sUnusedSpace2[32] = {}; +static const u32 sWallpaperTiles_Stars[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/stars/tiles.4bpp.lz"); +static const u32 sWallpaperTilemap_Stars[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/stars/tilemap.bin.lz"); + +static const u16 sWallpaperPalettes_Pokecenter[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/pokecenter/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/pokecenter/box.gbapal"), +}; +static const u32 sWallpaperTiles_Pokecenter[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/pokecenter/tiles.4bpp.lz"); +static const u32 sWallpaperTilemap_Pokecenter[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/pokecenter/tilemap.bin.lz"); + +static const u16 sWallpaperPalettes_Tiles[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/tiles/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/tiles/box.gbapal"), +}; +static const u32 sWallpaperTiles_Tiles[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/tiles/tiles.4bpp.lz"); +static const u32 sWallpaperTilemap_Tiles[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/tiles/tilemap.bin.lz"); + +static const u16 sWallpaperPalettes_Simple[][16] = { + INCBIN_U16("graphics/pokemon_storage/wallpapers/simple/title.gbapal"), + INCBIN_U16("graphics/pokemon_storage/wallpapers/simple/box.gbapal"), +}; +static const u32 sWallpaperTiles_Simple[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/simple/tiles.4bpp.lz"); +static const u32 sWallpaperTilemap_Simple[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/simple/tilemap.bin.lz"); + +// Unused +static const u16 sWallpaperTilemap_Unused[] = INCBIN_U16("graphics/pokemon_storage/wallpapers/unused.bin"); + +// Shadow color, text color +static const u16 sBoxTitleColors[][2] = { + {RGB( 7, 7, 7), RGB_WHITE}, + {RGB( 7, 7, 7), RGB_WHITE}, + {RGB( 7, 7, 7), RGB_WHITE}, + {RGB( 7, 7, 7), RGB_WHITE}, + {RGB( 7, 7, 7), RGB_WHITE}, + {RGB( 7, 7, 7), RGB_WHITE}, + {RGB( 7, 7, 7), RGB_WHITE}, + {RGB( 7, 7, 7), RGB_WHITE}, + {RGB( 7, 7, 7), RGB_WHITE}, + {RGB( 7, 7, 7), RGB_WHITE}, + {RGB( 7, 7, 7), RGB_WHITE}, + {RGB( 7, 7, 7), RGB_WHITE}, + {RGB( 7, 7, 7), RGB_WHITE}, + {RGB( 7, 7, 7), RGB_WHITE}, + {RGB( 7, 7, 7), RGB_WHITE}, + {RGB( 7, 7, 7), RGB_WHITE} +}; + +static const struct Wallpaper sWallpapers[] = { + {sWallpaperTiles_Forest, sWallpaperTilemap_Forest, *sWallpaperPalettes_Forest }, + {sWallpaperTiles_City, sWallpaperTilemap_City, *sWallpaperPalettes_City }, + {sWallpaperTiles_Desert, sWallpaperTilemap_Desert, *sWallpaperPalettes_Desert }, + {sWallpaperTiles_Savanna, sWallpaperTilemap_Savanna, *sWallpaperPalettes_Savanna }, + {sWallpaperTiles_Crag, sWallpaperTilemap_Crag, *sWallpaperPalettes_Crag }, + {sWallpaperTiles_Volcano, sWallpaperTilemap_Volcano, *sWallpaperPalettes_Volcano }, + {sWallpaperTiles_Snow, sWallpaperTilemap_Snow, *sWallpaperPalettes_Snow }, + {sWallpaperTiles_Cave, sWallpaperTilemap_Cave, *sWallpaperPalettes_Cave }, + {sWallpaperTiles_Beach, sWallpaperTilemap_Beach, *sWallpaperPalettes_Beach }, + {sWallpaperTiles_Seafloor, sWallpaperTilemap_Seafloor, *sWallpaperPalettes_Seafloor }, + {sWallpaperTiles_River, sWallpaperTilemap_River, *sWallpaperPalettes_River }, + {sWallpaperTiles_Sky, sWallpaperTilemap_Sky, *sWallpaperPalettes_Sky }, + {sWallpaperTiles_Stars, sWallpaperTilemap_Stars, *sWallpaperPalettes_Stars }, + {sWallpaperTiles_Pokecenter, sWallpaperTilemap_Pokecenter, *sWallpaperPalettes_Pokecenter}, + {sWallpaperTiles_Tiles, sWallpaperTilemap_Tiles, *sWallpaperPalettes_Tiles }, + {sWallpaperTiles_Simple, sWallpaperTilemap_Simple, *sWallpaperPalettes_Simple }, +}; + +static const u16 sBoxScrollArrow_Gfx[] = INCBIN_U16("graphics/pokemon_storage/box_scroll_arrow.4bpp"); + +static const u16 sUnusedColor = RGB(26, 29, 8); + +static const struct SpriteSheet sSpriteSheet_BoxScrollArrow = { + sBoxScrollArrow_Gfx, 0x0080, GFXTAG_BOX_SCROLL_ARROW +}; + +static const struct OamData sOamData_BoxTitle = { + .y = 0, + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = SPRITE_SHAPE(32x16), + .x = 0, + .matrixNum = 0, + .size = SPRITE_SIZE(32x16), + .tileNum = 0, + .priority = 2, + .paletteNum = 0 +}; + +static const union AnimCmd sAnim_BoxTitle_Left[] = { + ANIMCMD_FRAME(0, 5), + ANIMCMD_END +}; + +static const union AnimCmd sAnim_BoxTitle_Right[] = { + ANIMCMD_FRAME(8, 5), + ANIMCMD_END +}; + +static const union AnimCmd *const sAnims_BoxTitle[] = { + sAnim_BoxTitle_Left, + sAnim_BoxTitle_Right, +}; + +static const struct SpriteTemplate sSpriteTemplate_BoxTitle = { + .tileTag = GFXTAG_BOX_TITLE, + .paletteTag = PALTAG_BOX_TITLE, + .oam = &sOamData_BoxTitle, + .anims = sAnims_BoxTitle, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy +}; + +static const struct OamData sOamData_BoxScrollArrow = { + .y = 0, + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = SPRITE_SHAPE(8x16), + .x = 0, + .matrixNum = 0, + .size = SPRITE_SIZE(8x16), + .tileNum = 0x000, + .priority = 2, + .paletteNum = 0 +}; + +static const union AnimCmd sAnim_BoxScrollArrow_Left[] = { + ANIMCMD_FRAME(0, 5), + ANIMCMD_END +}; + +static const union AnimCmd sAnim_BoxScrollArrow_Right[] = { + ANIMCMD_FRAME(2, 5), + ANIMCMD_END +}; + +static const union AnimCmd *const sAnims_BoxScrollArrow[] = { + sAnim_BoxScrollArrow_Left, + sAnim_BoxScrollArrow_Right, +}; + +static const struct SpriteTemplate sSpriteTemplate_BoxScrollArrow = { + .tileTag = GFXTAG_BOX_SCROLL_ARROW, + .paletteTag = PALTAG_MISC_2, + .oam = &sOamData_BoxScrollArrow, + .anims = sAnims_BoxScrollArrow, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCB_BoxScrollArrow, +}; + +void InitMonIconFields(void) +{ + u16 i; + + LoadMonIconPalettes(); + for (i = 0; i < MAX_MON_ICONS; i++) + gStorage->numIconsPerSpecies[i] = 0; + for (i = 0; i < MAX_MON_ICONS; i++) + gStorage->iconSpeciesList[i] = SPECIES_NONE; + for (i = 0; i < PARTY_SIZE; i++) + gStorage->partySprites[i] = NULL; + for (i = 0; i < IN_BOX_COUNT; i++) + gStorage->boxMonsSprites[i] = NULL; + + gStorage->movingMonSprite = NULL; + gStorage->unusedField1 = 0; +} + +static u8 GetMonIconPriorityByCursorArea(void) +{ + return (IsCursorInBox() ? 2 : 1); +} + +void CreateMovingMonIcon(void) +{ + u32 personality = GetMonData(&gStorage->movingMon, MON_DATA_PERSONALITY); + u16 species = GetMonData(&gStorage->movingMon, MON_DATA_SPECIES2); + u8 priority = GetMonIconPriorityByCursorArea(); + + gStorage->movingMonSprite = CreateMonIconSprite(species, personality, 0, 0, priority, 7); + gStorage->movingMonSprite->callback = SpriteCB_HeldMon; +} + +static void InitBoxMonSprites(u8 boxId) +{ + u8 boxPosition; + u16 i, j, count; + u16 species; + u32 personality; + + count = 0; + boxPosition = 0; + for (i = 0; i < IN_BOX_ROWS; i++) + { + for (j = 0; j < IN_BOX_COLUMNS; j++) + { + species = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_SPECIES2); + if (species != SPECIES_NONE) + { + personality = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_PERSONALITY); + gStorage->boxMonsSprites[count] = CreateMonIconSprite(species, personality, 8 * (3 * j) + 100, 8 * (3 * i) + 44, 2, 19 - j); + } + else + gStorage->boxMonsSprites[count] = NULL; + + boxPosition++; + count++; + } + } + + if (gStorage->boxOption == OPTION_MOVE_ITEMS) + { + for (boxPosition = 0; boxPosition < IN_BOX_COUNT; boxPosition++) + { + if (GetBoxMonDataAt(boxId, boxPosition, MON_DATA_HELD_ITEM) == 0) + gStorage->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; + } + } +} + +void CreateBoxMonIconAtPos(u8 boxPosition) +{ + u16 species = GetCurrentBoxMonData(boxPosition, MON_DATA_SPECIES2); + + if (species != SPECIES_NONE) + { + s16 x = 8 * (3 * (boxPosition % IN_BOX_COLUMNS)) + 100; + s16 y = 8 * (3 * (boxPosition / IN_BOX_COLUMNS)) + 44; + u32 personality = GetCurrentBoxMonData(boxPosition, MON_DATA_PERSONALITY); + + gStorage->boxMonsSprites[boxPosition] = CreateMonIconSprite(species, personality, x, y, 2, 19 - (boxPosition % IN_BOX_COLUMNS)); + if (gStorage->boxOption == OPTION_MOVE_ITEMS) + gStorage->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; + } +} + +#define sDistance data[1] +#define sSpeed data[2] +#define sDestX data[3] +#define sDelay data[4] +#define sPosX data[5] + +static void StartBoxMonIconsScrollOut(s16 speed) +{ + u16 i; + + for (i = 0; i < IN_BOX_COUNT; i++) + { + if (gStorage->boxMonsSprites[i] != NULL) + { + gStorage->boxMonsSprites[i]->sSpeed = speed; + gStorage->boxMonsSprites[i]->sDelay = 1; + gStorage->boxMonsSprites[i]->callback = SpriteCB_BoxMonIconScrollOut; + } + } +} + +static void SpriteCB_BoxMonIconScrollIn(struct Sprite *sprite) +{ + if (sprite->sDistance != 0) + { + sprite->sDistance--; + sprite->x += sprite->sSpeed; + } + else + { + gStorage->iconScrollNumIncoming--; + sprite->x = sprite->sDestX; + sprite->callback = SpriteCallbackDummy; + } +} + +static void SpriteCB_BoxMonIconScrollOut(struct Sprite *sprite) +{ + if (sprite->sDelay != 0) + sprite->sDelay--; + else + { + sprite->x += sprite->sSpeed; + sprite->sPosX = sprite->x + sprite->x2; + + // Check if mon icon has scrolled out of view of the box area + if (sprite->sPosX <= 68 || sprite->sPosX >= 252) + sprite->callback = SpriteCallbackDummy; + } +} + +static void DestroyAllIconsInColumn(u8 column) +{ + u16 row; + u8 boxPosition = column; + + for (row = 0; row < IN_BOX_ROWS; row++) + { + if (gStorage->boxMonsSprites[boxPosition] != NULL) + { + DestroyBoxMonIcon(gStorage->boxMonsSprites[boxPosition]); + gStorage->boxMonsSprites[boxPosition] = NULL; + } + boxPosition += IN_BOX_COLUMNS; + } +} + +static u8 CreateBoxMonIconsInColumn(u8 column, u16 distance, s16 speed) +{ + s32 i; + u16 y = 44; + s16 xDest = 8 * (3 * column) + 100; + u16 x = xDest - ((distance + 1) * speed); + u8 subpriority = 19 - column; + u8 count = 0; + u8 boxPosition = column; + + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + { + for (i = 0; i < IN_BOX_ROWS; i++) + { + if (gStorage->boxSpecies[boxPosition] != SPECIES_NONE) + { + gStorage->boxMonsSprites[boxPosition] = CreateMonIconSprite(gStorage->boxSpecies[boxPosition], + gStorage->boxPersonalities[boxPosition], + x, y, 2, subpriority); + if (gStorage->boxMonsSprites[boxPosition] != NULL) + { + gStorage->boxMonsSprites[boxPosition]->sDistance = distance; + gStorage->boxMonsSprites[boxPosition]->sSpeed = speed; + gStorage->boxMonsSprites[boxPosition]->sDestX = xDest; + gStorage->boxMonsSprites[boxPosition]->callback = SpriteCB_BoxMonIconScrollIn; + count++; + } + } + boxPosition += IN_BOX_COLUMNS; + y += 24; + } + } + else + { + for (i = 0; i < IN_BOX_ROWS; i++) + { + if (gStorage->boxSpecies[boxPosition] != SPECIES_NONE) + { + gStorage->boxMonsSprites[boxPosition] = CreateMonIconSprite(gStorage->boxSpecies[boxPosition], + gStorage->boxPersonalities[boxPosition], + x, y, 2, subpriority); + if (gStorage->boxMonsSprites[boxPosition] != NULL) + { + gStorage->boxMonsSprites[boxPosition]->sDistance = distance; + gStorage->boxMonsSprites[boxPosition]->sSpeed = speed; + gStorage->boxMonsSprites[boxPosition]->sDestX = xDest; + gStorage->boxMonsSprites[boxPosition]->callback = SpriteCB_BoxMonIconScrollIn; + if (GetBoxMonDataAt(gStorage->incomingBoxId, boxPosition, MON_DATA_HELD_ITEM) == 0) + gStorage->boxMonsSprites[boxPosition]->oam.objMode = ST_OAM_OBJ_BLEND; + count++; + } + } + boxPosition += IN_BOX_COLUMNS; + y += 24; + } + } + + return count; +} + +#undef sDistance +#undef sSpeed +#undef sDestX +#undef sDelay +#undef sPosX + +static void InitBoxMonIconScroll(u8 boxId, s8 direction) +{ + gStorage->iconScrollState = 0; + gStorage->iconScrollToBoxId = boxId; + gStorage->iconScrollDirection = direction; + gStorage->iconScrollDistance = 32; + gStorage->iconScrollSpeed = -(6 * direction); + gStorage->iconScrollNumIncoming = 0; + SetBoxSpeciesAndPersonalities(boxId); + if (direction > 0) + gStorage->iconScrollCurColumn = 0; + else + gStorage->iconScrollCurColumn = IN_BOX_COLUMNS - 1; + + gStorage->iconScrollPos = (24 * gStorage->iconScrollCurColumn) + 100; + StartBoxMonIconsScrollOut(gStorage->iconScrollSpeed); +} + +static bool8 UpdateBoxMonIconScroll(void) +{ + if (gStorage->iconScrollDistance != 0) + gStorage->iconScrollDistance--; + + switch (gStorage->iconScrollState) + { + case 0: + gStorage->iconScrollPos += gStorage->iconScrollSpeed; + if (gStorage->iconScrollPos <= 64 || gStorage->iconScrollPos >= 252) + { + // A column of icons has gone offscreen, destroy them + DestroyAllIconsInColumn(gStorage->iconScrollCurColumn); + gStorage->iconScrollPos += gStorage->iconScrollDirection * 24; + gStorage->iconScrollState++; + } + break; + case 1: + // Create the new incoming column of icons + gStorage->iconScrollPos += gStorage->iconScrollSpeed; + gStorage->iconScrollNumIncoming += CreateBoxMonIconsInColumn(gStorage->iconScrollCurColumn, gStorage->iconScrollDistance, gStorage->iconScrollSpeed); + if ((gStorage->iconScrollDirection > 0 && gStorage->iconScrollCurColumn == IN_BOX_COLUMNS - 1) + || (gStorage->iconScrollDirection < 0 && gStorage->iconScrollCurColumn == 0)) + { + // Scroll has reached final column + gStorage->iconScrollState++; + } + else + { + // Continue scrolling + gStorage->iconScrollCurColumn += gStorage->iconScrollDirection; + gStorage->iconScrollState = 0; + } + break; + case 2: + // Wait to make sure all icons have arrived + if (gStorage->iconScrollNumIncoming == 0) + { + gStorage->iconScrollDistance++; + return FALSE; + } + break; + default: + return FALSE; + } + + return TRUE; +} + +static void SetBoxSpeciesAndPersonalities(u8 boxId) +{ + s32 i, j, boxPosition; + + boxPosition = 0; + for (i = 0; i < IN_BOX_ROWS; i++) + { + for (j = 0; j < IN_BOX_COLUMNS; j++) + { + gStorage->boxSpecies[boxPosition] = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_SPECIES2); + if (gStorage->boxSpecies[boxPosition] != SPECIES_NONE) + gStorage->boxPersonalities[boxPosition] = GetBoxMonDataAt(boxId, boxPosition, MON_DATA_PERSONALITY); + boxPosition++; + } + } + + gStorage->incomingBoxId = boxId; +} + +void DestroyBoxMonIconAtPosition(u8 boxPosition) +{ + if (gStorage->boxMonsSprites[boxPosition] != NULL) + { + DestroyBoxMonIcon(gStorage->boxMonsSprites[boxPosition]); + gStorage->boxMonsSprites[boxPosition] = NULL; + } +} + +void SetBoxMonIconObjMode(u8 boxPosition, u8 objMode) +{ + if (gStorage->boxMonsSprites[boxPosition] != NULL) + { + gStorage->boxMonsSprites[boxPosition]->oam.objMode = objMode; + } +} + +void CreatePartyMonsSprites(bool8 visible) +{ + u16 i, count; + u16 species = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES2); + u32 personality = GetMonData(&gPlayerParty[0], MON_DATA_PERSONALITY); + + gStorage->partySprites[0] = CreateMonIconSprite(species, personality, 104, 64, 1, 12); + count = 1; + for (i = 1; i < PARTY_SIZE; i++) + { + species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); + if (species != SPECIES_NONE) + { + personality = GetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY); + gStorage->partySprites[i] = CreateMonIconSprite(species, personality, 152, 8 * (3 * (i - 1)) + 16, 1, 12); + count++; + } + else + gStorage->partySprites[i] = NULL; + } + + if (!visible) + { + for (i = 0; i < count; i++) + { + gStorage->partySprites[i]->y -= 160; + gStorage->partySprites[i]->invisible = TRUE; + } + } + + if (gStorage->boxOption == OPTION_MOVE_ITEMS) + { + for (i = 0; i < PARTY_SIZE; i++) + { + if (gStorage->partySprites[i] != NULL && GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM) == 0) + gStorage->partySprites[i]->oam.objMode = ST_OAM_OBJ_BLEND; + } + } +} + +void CompactPartySprites(void) +{ + u16 i, targetPartyId; + + gStorage->numPartySpritesToCompact = 0; + for (i = 0, targetPartyId = 0; i < PARTY_SIZE; i++) + { + if (gStorage->partySprites[i] != NULL) + { + if (i != targetPartyId) + { + MovePartySpriteToNextSlot(gStorage->partySprites[i], targetPartyId); + gStorage->partySprites[i] = NULL; + gStorage->numPartySpritesToCompact++; + } + targetPartyId++; + } + } +} + +u8 GetNumPartySpritesCompacting(void) +{ + return gStorage->numPartySpritesToCompact; +} + +#define sPartyId data[1] +#define sMonX data[2] +#define sMonY data[3] +#define sSpeedX data[4] +#define sSpeedY data[5] +#define sMoveSteps data[6] + +static void MovePartySpriteToNextSlot(struct Sprite *sprite, u16 partyId) +{ + s16 x, y; + + sprite->sPartyId = partyId; + if (partyId == 0) + x = 104, y = 64; + else + x = 152, y = 8 * (3 * (partyId - 1)) + 16; + + sprite->sMonX = (u16)(sprite->x) * 8; + sprite->sMonY = (u16)(sprite->y) * 8; + sprite->sSpeedX = ((x * 8) - sprite->sMonX) / 8; + sprite->sSpeedY = ((y * 8) - sprite->sMonY) / 8; + sprite->sMoveSteps = 8; + sprite->callback = SpriteCB_MovePartySpriteToNextSlot; +} + +static void SpriteCB_MovePartySpriteToNextSlot(struct Sprite *sprite) +{ + if (sprite->sMoveSteps != 0) + { + s16 x = sprite->sMonX += sprite->sSpeedX; + s16 y = sprite->sMonY += sprite->sSpeedY; + sprite->x = x / 8u; + sprite->y = y / 8u; + sprite->sMoveSteps--; + } + else + { + if (sprite->sPartyId == 0) + { + sprite->x = 104; + sprite->y = 64; + } + else + { + sprite->x = 152; + sprite->y = 8 * (3 * (sprite->sPartyId - 1)) + 16; + } + sprite->callback = SpriteCallbackDummy; + gStorage->partySprites[sprite->sPartyId] = sprite; + gStorage->numPartySpritesToCompact--; + } +} + +#undef sPartyId +#undef sMonX +#undef sMonY +#undef sSpeedX +#undef sSpeedY +#undef sMoveSteps + +void DestroyMovingMonIcon(void) +{ + if (gStorage->movingMonSprite != NULL) + { + DestroyBoxMonIcon(gStorage->movingMonSprite); + gStorage->movingMonSprite = NULL; + } +} + +void MovePartySprites(s16 yDelta) +{ + u16 i, posY; + + for (i = 0; i < PARTY_SIZE; i++) + { + if (gStorage->partySprites[i] != NULL) + { + gStorage->partySprites[i]->y += yDelta; + posY = gStorage->partySprites[i]->y + gStorage->partySprites[i]->y2 + gStorage->partySprites[i]->centerToCornerVecY; + posY += 16; + if (posY > 192) + gStorage->partySprites[i]->invisible = TRUE; + else + gStorage->partySprites[i]->invisible = FALSE; + } + } +} + +void DestroyPartyMonIcon(u8 partyId) +{ + if (gStorage->partySprites[partyId] != NULL) + { + DestroyBoxMonIcon(gStorage->partySprites[partyId]); + gStorage->partySprites[partyId] = NULL; + } +} + +void DestroyAllPartyMonIcons(void) +{ + u16 i; + + for (i = 0; i < PARTY_SIZE; i++) + { + if (gStorage->partySprites[i] != NULL) + { + DestroyBoxMonIcon(gStorage->partySprites[i]); + gStorage->partySprites[i] = NULL; + } + } +} + +void SetPartyMonIconObjMode(u8 partyId, u8 objMode) +{ + if (gStorage->partySprites[partyId] != NULL) + gStorage->partySprites[partyId]->oam.objMode = objMode; +} + +void SetMovingMonSprite(u8 mode, u8 id) +{ + if (mode == MODE_PARTY) + { + gStorage->movingMonSprite = gStorage->partySprites[id]; + gStorage->partySprites[id] = NULL; + } + else if (mode == MODE_BOX) + { + gStorage->movingMonSprite = gStorage->boxMonsSprites[id]; + gStorage->boxMonsSprites[id] = NULL; + } + else + return; + + gStorage->movingMonSprite->callback = SpriteCB_HeldMon; + gStorage->movingMonSprite->oam.priority = GetMonIconPriorityByCursorArea(); + gStorage->movingMonSprite->subpriority = 7; +} + +void SetPlacedMonSprite(u8 boxId, u8 position) +{ + if (boxId == TOTAL_BOXES_COUNT) // party mon + { + gStorage->partySprites[position] = gStorage->movingMonSprite; + gStorage->partySprites[position]->oam.priority = 1; + gStorage->partySprites[position]->subpriority = 12; + } + else + { + gStorage->boxMonsSprites[position] = gStorage->movingMonSprite; + gStorage->boxMonsSprites[position]->oam.priority = 2; + gStorage->boxMonsSprites[position]->subpriority = 19 - (position % IN_BOX_COLUMNS); + } + gStorage->movingMonSprite->callback = SpriteCallbackDummy; + gStorage->movingMonSprite = NULL; +} + +void SetShiftMonSpritePtr(u8 boxId, u8 position) +{ + if (boxId == TOTAL_BOXES_COUNT) // party mon + gStorage->shiftMonSpritePtr = &gStorage->partySprites[position]; + else + gStorage->shiftMonSpritePtr = &gStorage->boxMonsSprites[position]; + + gStorage->movingMonSprite->callback = SpriteCallbackDummy; + gStorage->shiftTimer = 0; +} + +bool8 ShiftMons(void) +{ + if (gStorage->shiftTimer == 16) + return FALSE; + + gStorage->shiftTimer++; + if (gStorage->shiftTimer & 1) + { + (*gStorage->shiftMonSpritePtr)->y--; + gStorage->movingMonSprite->y++; + } + + (*gStorage->shiftMonSpritePtr)->x2 = gSineTable[gStorage->shiftTimer * 8] / 16; + gStorage->movingMonSprite->x2 = -(gSineTable[gStorage->shiftTimer * 8] / 16); + if (gStorage->shiftTimer == 8) + { + gStorage->movingMonSprite->oam.priority = (*gStorage->shiftMonSpritePtr)->oam.priority; + gStorage->movingMonSprite->subpriority = (*gStorage->shiftMonSpritePtr)->subpriority; + (*gStorage->shiftMonSpritePtr)->oam.priority = GetMonIconPriorityByCursorArea(); + (*gStorage->shiftMonSpritePtr)->subpriority = 7; + } + + if (gStorage->shiftTimer == 16) + { + struct Sprite *sprite = gStorage->movingMonSprite; + gStorage->movingMonSprite = (*gStorage->shiftMonSpritePtr); + *gStorage->shiftMonSpritePtr = sprite; + + gStorage->movingMonSprite->callback = SpriteCB_HeldMon; + (*gStorage->shiftMonSpritePtr)->callback = SpriteCallbackDummy; + } + + return TRUE; +} + +void DoReleaseMonAnim(u8 mode, u8 position) +{ + switch (mode) + { + case MODE_PARTY: + gStorage->releaseMonSpritePtr = &gStorage->partySprites[position]; + break; + case MODE_BOX: + gStorage->releaseMonSpritePtr = &gStorage->boxMonsSprites[position]; + break; + case MODE_MOVE: + gStorage->releaseMonSpritePtr = &gStorage->movingMonSprite; + break; + default: + return; + } + + if (*gStorage->releaseMonSpritePtr != NULL) + { + InitSpriteAffineAnim(*gStorage->releaseMonSpritePtr); + (*gStorage->releaseMonSpritePtr)->oam.affineMode = ST_OAM_AFFINE_NORMAL; + (*gStorage->releaseMonSpritePtr)->affineAnims = sAffineAnims_ReleaseMon; + StartSpriteAffineAnim(*gStorage->releaseMonSpritePtr, RELEASE_ANIM_RELEASE); + } +} + +bool8 TryHideReleaseMonSprite(void) +{ + if (*gStorage->releaseMonSpritePtr == NULL || (*gStorage->releaseMonSpritePtr)->invisible) + return FALSE; + + if ((*gStorage->releaseMonSpritePtr)->affineAnimEnded) + (*gStorage->releaseMonSpritePtr)->invisible = TRUE; + + return TRUE; +} + +void DestroyReleaseMonIcon(void) +{ + if (*gStorage->releaseMonSpritePtr != NULL) + { + FreeOamMatrix((*gStorage->releaseMonSpritePtr)->oam.matrixNum); + DestroyBoxMonIcon(*gStorage->releaseMonSpritePtr); + *gStorage->releaseMonSpritePtr = NULL; + } +} + +void DoReleaseMonComeBackAnim(void) +{ + if (*gStorage->releaseMonSpritePtr != NULL) + { + (*gStorage->releaseMonSpritePtr)->invisible = FALSE; + StartSpriteAffineAnim(*gStorage->releaseMonSpritePtr, RELEASE_ANIM_COME_BACK); + } +} + +bool8 ResetReleaseMonSpritePtr(void) +{ + if (gStorage->releaseMonSpritePtr == NULL) + return FALSE; + + if ((*gStorage->releaseMonSpritePtr)->affineAnimEnded) + gStorage->releaseMonSpritePtr = NULL; + + return TRUE; +} + +void SetMovingMonPriority(u8 priority) +{ + gStorage->movingMonSprite->oam.priority = priority; +} + +static void SpriteCB_HeldMon(struct Sprite *sprite) +{ + sprite->x = gStorage->cursorSprite->x; + sprite->y = gStorage->cursorSprite->y + gStorage->cursorSprite->y2 + 4; +} + +static u16 TryLoadMonIconTiles(u16 species) +{ + u16 i, offset; + + // Find the currently-allocated slot + for (i = 0; i < MAX_MON_ICONS; i++) + { + if (gStorage->iconSpeciesList[i] == species) + break; + } + + if (i == MAX_MON_ICONS) + { + // Find the first empty slot + for (i = 0; i < MAX_MON_ICONS; i++) + { + if (gStorage->iconSpeciesList[i] == SPECIES_NONE) + break; + } + if (i == MAX_MON_ICONS) + return 0xFFFF; + } + + gStorage->iconSpeciesList[i] = species; + gStorage->numIconsPerSpecies[i]++; + offset = 16 * i; + CpuCopy32(GetMonIconTiles(species, TRUE), (void *)(OBJ_VRAM0) + offset * 32, 0x200); + + return offset; +} + +static void RemoveSpeciesFromIconList(u16 species) +{ + u16 i; + + for (i = 0; i < MAX_MON_ICONS; i++) + { + if (gStorage->iconSpeciesList[i] == species) + { + if (--gStorage->numIconsPerSpecies[i] == 0) + gStorage->iconSpeciesList[i] = SPECIES_NONE; + break; + } + } +} + +struct Sprite *CreateMonIconSprite(u16 species, u32 personality, s16 x, s16 y, u8 oamPriority, u8 subpriority) +{ + u16 tileNum; + u8 spriteId; + struct SpriteTemplate template = sSpriteTemplate_MonIcon; + + species = GetIconSpecies(species, personality); + template.paletteTag = PALTAG_MON_ICON_0 + gMonIconPaletteIndices[species]; + tileNum = TryLoadMonIconTiles(species); + if (tileNum == 0xFFFF) + return NULL; + + spriteId = CreateSprite(&template, x, y, subpriority); + if (spriteId == MAX_SPRITES) + { + RemoveSpeciesFromIconList(species); + return NULL; + } + + gSprites[spriteId].oam.tileNum = tileNum; + gSprites[spriteId].oam.priority = oamPriority; + gSprites[spriteId].data[0] = species; + return &gSprites[spriteId]; +} + +static void DestroyBoxMonIcon(struct Sprite *sprite) +{ + RemoveSpeciesFromIconList(sprite->data[0]); + DestroySprite(sprite); +} + +#define tState data[0] +#define tDmaIdx data[1] +#define tBoxId data[2] + +void CreateInitBoxTask(u8 boxId) +{ + u8 taskId = CreateTask(Task_InitBox, 2); + + gTasks[taskId].tBoxId = boxId; +} + +bool8 IsInitBoxActive(void) +{ + return FuncIsActiveTask(Task_InitBox); +} + +static void Task_InitBox(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + + switch (task->tState) + { + case 0: + gStorage->wallpaperOffset = 0; + gStorage->bg2_X = 0; + task->tDmaIdx = RequestDma3Fill(0, gStorage->wallpaperBgTilemapBuffer, sizeof(gStorage->wallpaperBgTilemapBuffer), DMA3_32BIT); + break; + case 1: + if (WaitDma3Request(task->tDmaIdx) == -1) + return; + + SetBgTilemapBuffer(2, gStorage->wallpaperBgTilemapBuffer); + ShowBg(2); + break; + case 2: + LoadWallpaperGfx(task->tBoxId, 0); + break; + case 3: + if (!WaitForWallpaperGfxLoad()) + return; + + InitBoxTitle(task->tBoxId); + CreateBoxScrollArrows(); + InitBoxMonSprites(task->tBoxId); + SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(2) | BGCNT_CHARBASE(2) | BGCNT_SCREENBASE(27) | BGCNT_TXT512x256); + break; + case 4: + DestroyTask(taskId); + break; + default: + task->tState = 0; + return; + } + + task->tState++; +} + +#undef tState +#undef tDmaIdx +#undef tBoxId + +void SetUpScrollToBox(u8 boxId) +{ + s8 direction = DetermineBoxScrollDirection(boxId); + + gStorage->scrollSpeed = (direction > 0) ? 6 : -6; + gStorage->scrollUnused1 = (direction > 0) ? 1 : 2; + gStorage->scrollTimer = 32; + gStorage->scrollToBoxIdUnused = boxId; + gStorage->scrollUnused2 = (direction <= 0) ? 5 : 0; + gStorage->scrollDirectionUnused = direction; + gStorage->scrollUnused3 = (direction > 0) ? 264 : 56; + gStorage->scrollUnused4 = (direction <= 0) ? 5 : 0; + gStorage->scrollUnused5 = 0; + gStorage->scrollUnused6 = 2; + gStorage->scrollToBoxId = boxId; + gStorage->scrollDirection = direction; + gStorage->scrollState = 0; +} + +bool8 ScrollToBox(void) +{ + bool8 isStillScrolling; + + switch (gStorage->scrollState) + { + case 0: + LoadWallpaperGfx(gStorage->scrollToBoxId, gStorage->scrollDirection); + gStorage->scrollState++; + case 1: + if (!WaitForWallpaperGfxLoad()) + return TRUE; + + InitBoxMonIconScroll(gStorage->scrollToBoxId, gStorage->scrollDirection); + CreateIncomingBoxTitle(gStorage->scrollToBoxId, gStorage->scrollDirection); + StartBoxScrollArrowsSlide(gStorage->scrollDirection); + break; + case 2: + isStillScrolling = UpdateBoxMonIconScroll(); + if (gStorage->scrollTimer != 0) + { + gStorage->bg2_X += gStorage->scrollSpeed; + if (--gStorage->scrollTimer != 0) + return TRUE; + CycleBoxTitleSprites(); + StopBoxScrollArrowsSlide(); + } + return isStillScrolling; + } + + gStorage->scrollState++; + return TRUE; +} + +static s8 DetermineBoxScrollDirection(u8 boxId) +{ + u8 i; + u8 currentBox = StorageGetCurrentBox(); + + for (i = 0; currentBox != boxId; i++) + { + currentBox++; + if (currentBox >= TOTAL_BOXES_COUNT) + currentBox = 0; + } + + return (i < TOTAL_BOXES_COUNT / 2) ? 1 : -1; +} + +void SetWallpaperForCurrentBox(u8 wallpaperId) +{ + SetBoxWallpaper(StorageGetCurrentBox(), wallpaperId); + gStorage->wallpaperChangeState = 0; +} + +bool8 DoWallpaperGfxChange(void) +{ + switch (gStorage->wallpaperChangeState) + { + case 0: + BeginNormalPaletteFade(gStorage->wallpaperPalBits, 1, 0, 16, RGB_WHITEALPHA); + gStorage->wallpaperChangeState++; + break; + case 1: + if (!UpdatePaletteFade()) + { + u8 curBox = StorageGetCurrentBox(); + LoadWallpaperGfx(curBox, 0); + gStorage->wallpaperChangeState++; + } + break; + case 2: + if (WaitForWallpaperGfxLoad() == TRUE) + { + CycleBoxTitleColor(); + BeginNormalPaletteFade(gStorage->wallpaperPalBits, 1, 16, 0, RGB_WHITEALPHA); + gStorage->wallpaperChangeState++; + } + break; + case 3: + if (!UpdatePaletteFade()) + gStorage->wallpaperChangeState++; + break; + case 4: + return FALSE; + } + + return TRUE; +} + +static void LoadWallpaperGfx(u8 boxId, s8 direction) +{ + u8 wallpaperId; + const struct Wallpaper *wallpaper; + + gStorage->wallpaperLoadState = 0; + gStorage->wallpaperLoadBoxId = boxId; + gStorage->wallpaperLoadDir = direction; + if (gStorage->wallpaperLoadDir != 0) + { + gStorage->wallpaperOffset = !gStorage->wallpaperOffset; + TrimOldWallpaper(gStorage->wallpaperBgTilemapBuffer); + } + + wallpaperId = GetBoxWallpaper(gStorage->wallpaperLoadBoxId); + wallpaper = &sWallpapers[wallpaperId]; + LZ77UnCompWram(wallpaper->tileMap, gStorage->wallpaperTilemap); + DrawWallpaper(gStorage->wallpaperBgTilemapBuffer, gStorage->wallpaperTilemap, gStorage->wallpaperLoadDir, gStorage->wallpaperOffset); + + if (gStorage->wallpaperLoadDir != 0) + LoadPalette(wallpaper->palettes, (gStorage->wallpaperOffset * 32) + 0x40, 0x40); + else + CpuCopy16(wallpaper->palettes, &gPlttBufferUnfaded[(gStorage->wallpaperOffset * 32) + 0x40], 0x40); + + DecompressAndLoadBgGfxUsingHeap(2, wallpaper->tiles, 0, 256 * gStorage->wallpaperOffset, 0); + + CopyBgTilemapBufferToVram(2); +} + +static bool32 WaitForWallpaperGfxLoad(void) +{ + if (IsDma3ManagerBusyWithBgCopy() == TRUE) + return FALSE; + + return TRUE; +} + +static void DrawWallpaper(void *unused, const void *tilemap, s8 direction, u8 offset) +{ + s16 paletteNum = (offset * 2) + 3; + s16 x = ((gStorage->bg2_X / 8 + 10) + (direction * 24)) & 0x3F; + + CopyRectToBgTilemapBufferRect(2, tilemap, 0, 0, 20, 18, x, 2, 20, 18, 17, offset << 8, paletteNum); + + if (direction == 0) + return; + else if (direction > 0) + x *= 1, x += 20; // x * 1 is needed to match + else + x -= 4; + + FillBgTilemapBufferRect(2, 0, x, 2, 4, 18, 17); +} + +static void TrimOldWallpaper(void *tilemapBuffer) +{ + u16 i; + u16 *dest = tilemapBuffer; + s16 right = ((gStorage->bg2_X / 8 + 10) + 20) & 0x3F; + + if (right < 32) + dest += right + 0x260; + else + dest += right + 0x640; + + for (i = 0; i < 44; i++) + { + *dest++ = 0; + right = (right + 1) & 0x3F; + if (right == 0) + dest -= 0x420; + if (right == 32) + dest += 0x3e0; + } +} + +static void InitBoxTitle(u8 boxId) +{ + u8 tagIndex; + s16 x; + u16 i; + + struct SpriteSheet spriteSheet = {gStorage->boxTitleTiles, 0x200, GFXTAG_BOX_TITLE}; + struct SpritePalette palettes[] = { + {gStorage->boxTitlePal, PALTAG_BOX_TITLE}, + {} + }; + + u16 wallpaperId = GetBoxWallpaper(boxId); + + gStorage->boxTitlePal[14] = sBoxTitleColors[wallpaperId][0]; + gStorage->boxTitlePal[15] = sBoxTitleColors[wallpaperId][1]; + LoadSpritePalettes(palettes); + gStorage->wallpaperPalBits = 0x3F0; + + tagIndex = IndexOfSpritePaletteTag(PALTAG_BOX_TITLE); + gStorage->boxTitlePalOffset = 0x10e + 16 * tagIndex; + gStorage->wallpaperPalBits |= 0x10000 << tagIndex; + + tagIndex = IndexOfSpritePaletteTag(PALTAG_BOX_TITLE); + gStorage->boxTitleAltPalOffset = 0x10e + 16 * tagIndex; + gStorage->wallpaperPalBits |= 0x10000 << tagIndex; + + StringCopyPadded(gStorage->boxTitleText, GetBoxNamePtr(boxId), 0, 8); + DrawTextWindowAndBufferTiles(gStorage->boxTitleText, gStorage->boxTitleTiles, 0, 0, gStorage->boxTitleUnused, 2); + LoadSpriteSheet(&spriteSheet); + x = GetBoxTitleBaseX(GetBoxNamePtr(boxId)); + + for (i = 0; i < 2; i++) + { + u8 spriteId = CreateSprite(&sSpriteTemplate_BoxTitle, x + i * 32, 28, 24); + gStorage->curBoxTitleSprites[i] = &gSprites[spriteId]; + StartSpriteAnim(gStorage->curBoxTitleSprites[i], i); + } + gStorage->boxTitleCycleId = 0; +} + +static void CreateIncomingBoxTitle(u8 boxId, s8 direction) +{ + u16 palOffset; + s16 x, adjustedX; + u16 i; + struct SpriteSheet spriteSheet = {gStorage->boxTitleTiles, 0x200, GFXTAG_BOX_TITLE}; + struct SpriteTemplate template = sSpriteTemplate_BoxTitle; + + gStorage->boxTitleCycleId = !gStorage->boxTitleCycleId; + if (gStorage->boxTitleCycleId == 0) + { + spriteSheet.tag = GFXTAG_BOX_TITLE; + palOffset = gStorage->boxTitlePalOffset; + } + else + { + spriteSheet.tag = GFXTAG_BOX_TITLE_ALT; + palOffset = gStorage->boxTitlePalOffset; + template.tileTag = GFXTAG_BOX_TITLE_ALT; + template.paletteTag = PALTAG_BOX_TITLE; + } + + StringCopyPadded(gStorage->boxTitleText, GetBoxNamePtr(boxId), 0, BOX_NAME_LENGTH); + DrawTextWindowAndBufferTiles(gStorage->boxTitleText, gStorage->boxTitleTiles, 0, 0, gStorage->boxTitleUnused, 2); + LoadSpriteSheet(&spriteSheet); + LoadPalette(sBoxTitleColors[GetBoxWallpaper(boxId)], palOffset, sizeof(sBoxTitleColors[0])); + x = GetBoxTitleBaseX(GetBoxNamePtr(boxId)); + adjustedX = x; + adjustedX += direction * 192; + + // Title is split across two sprites + for (i = 0; i < 2; i++) + { + u8 spriteId = CreateSprite(&template, i * 32 + adjustedX, 28, 24); + + gStorage->nextBoxTitleSprites[i] = &gSprites[spriteId]; + gStorage->nextBoxTitleSprites[i]->data[0] = (-direction) * 6; + gStorage->nextBoxTitleSprites[i]->data[1] = i * 32 + x; + gStorage->nextBoxTitleSprites[i]->data[2] = 0; + gStorage->nextBoxTitleSprites[i]->callback = SpriteCB_IncomingBoxTitle; + StartSpriteAnim(gStorage->nextBoxTitleSprites[i], i); + + gStorage->curBoxTitleSprites[i]->data[0] = (-direction) * 6; + gStorage->curBoxTitleSprites[i]->data[1] = 1; + gStorage->curBoxTitleSprites[i]->callback = SpriteCB_OutgoingBoxTitle; + } +} + +static void CycleBoxTitleSprites(void) +{ + if (gStorage->boxTitleCycleId == 0) + FreeSpriteTilesByTag(GFXTAG_BOX_TITLE_ALT); + else + FreeSpriteTilesByTag(GFXTAG_BOX_TITLE); + + gStorage->curBoxTitleSprites[0] = gStorage->nextBoxTitleSprites[0]; + gStorage->curBoxTitleSprites[1] = gStorage->nextBoxTitleSprites[1]; +} + +static void SpriteCB_IncomingBoxTitle(struct Sprite *sprite) +{ + if (sprite->data[2] != 0) + sprite->data[2]--; + else if ((sprite->x += sprite->data[0]) == sprite->data[1]) + sprite->callback = SpriteCallbackDummy; +} + +static void SpriteCB_OutgoingBoxTitle(struct Sprite *sprite) +{ + if (sprite->data[1] != 0) + sprite->data[1]--; + else + { + sprite->x += sprite->data[0]; + sprite->data[2] = sprite->x + sprite->x2; + if (sprite->data[2] < 0x40 || sprite->data[2] > 0x100) + DestroySprite(sprite); + } +} + +static void CycleBoxTitleColor(void) +{ + u8 boxId = StorageGetCurrentBox(); + u8 wallpaperId = GetBoxWallpaper(boxId); + if (gStorage->boxTitleCycleId == 0) + CpuCopy16(sBoxTitleColors[wallpaperId], gPlttBufferUnfaded + gStorage->boxTitlePalOffset, 4); + else + CpuCopy16(sBoxTitleColors[wallpaperId], gPlttBufferUnfaded + gStorage->boxTitleAltPalOffset, 4); +} + +static s16 GetBoxTitleBaseX(const u8 *string) +{ + return DISPLAY_WIDTH - 64 - GetStringWidth(FONT_1, string, 0) / 2; +} + +// Sprite data for box scroll arrows +#define sState data[0] +#define sTimer data[1] +#define sSpeed data[3] + +static void CreateBoxScrollArrows(void) +{ + u16 i; + + LoadSpriteSheet(&sSpriteSheet_BoxScrollArrow); + for (i = 0; i < 2; i++) + { + u8 spriteId = CreateSprite(&sSpriteTemplate_BoxScrollArrow, 92 + i * 136, 28, 22); + if (spriteId != MAX_SPRITES) + { + struct Sprite *sprite = &gSprites[spriteId]; + StartSpriteAnim(sprite, i); + sprite->sSpeed = (i == 0) ? -1 : 1; + gStorage->arrowSprites[i] = sprite; + } + } + if (IsCursorOnBoxTitle()) + AnimateBoxScrollArrows(TRUE); +} + +// Slide box scroll arrows horizontally for box change +static void StartBoxScrollArrowsSlide(s8 direction) +{ + u16 i; + + for (i = 0; i < 2; i++) + { + gStorage->arrowSprites[i]->x2 = 0; + gStorage->arrowSprites[i]->sState = 2; + } + if (direction < 0) + { + gStorage->arrowSprites[0]->sTimer = 29; + gStorage->arrowSprites[1]->sTimer = 5; + gStorage->arrowSprites[0]->data[2] = 72; + gStorage->arrowSprites[1]->data[2] = 72; + } + else + { + gStorage->arrowSprites[0]->sTimer = 5; + gStorage->arrowSprites[1]->sTimer = 29; + gStorage->arrowSprites[0]->data[2] = DISPLAY_WIDTH + 8; + gStorage->arrowSprites[1]->data[2] = DISPLAY_WIDTH + 8; + } + gStorage->arrowSprites[0]->data[7] = 0; + gStorage->arrowSprites[1]->data[7] = 1; +} + +// New box's scroll arrows have entered, stop sliding and set their position +static void StopBoxScrollArrowsSlide(void) +{ + u16 i; + + for (i = 0; i < 2; i++) + { + gStorage->arrowSprites[i]->x = 136 * i + 92; + gStorage->arrowSprites[i]->x2 = 0; + gStorage->arrowSprites[i]->invisible = FALSE; + } + AnimateBoxScrollArrows(TRUE); +} + +// Bounce scroll arrows while title is selected +void AnimateBoxScrollArrows(bool8 animate) +{ + u16 i; + + if (animate) + { + // Start arrows moving + for (i = 0; i < 2; i++) + { + gStorage->arrowSprites[i]->sState = 1; + gStorage->arrowSprites[i]->sTimer = 0; + gStorage->arrowSprites[i]->data[2] = 0; + gStorage->arrowSprites[i]->data[4] = 0; + } + } + else + { + // Stop arrows moving + for (i = 0; i < 2; i++) + gStorage->arrowSprites[i]->sState = 0; + } +} + +static void SpriteCB_BoxScrollArrow(struct Sprite *sprite) +{ + switch (sprite->sState) + { + case 0: + sprite->x2 = 0; + break; + case 1: + if (++sprite->sTimer > 3) + { + sprite->sTimer = 0; + sprite->x2 += sprite->sSpeed; + if (++sprite->data[2] > 5) + { + sprite->data[2] = 0; + sprite->x2 = 0; + } + } + break; + case 2: + sprite->sState = 3; + break; + case 3: + sprite->x -= gStorage->scrollSpeed; + if (sprite->x <= 72 || sprite->x >= DISPLAY_WIDTH + 8) + sprite->invisible = TRUE; + if (--sprite->sTimer == 0) + { + sprite->x = sprite->data[2]; + sprite->invisible = FALSE; + sprite->sState = 4; + } + break; + case 4: + sprite->x -= gStorage->scrollSpeed; + break; + } +} + +#undef sState +#undef sTimer +#undef sSpeed + +// Arrows for Deposit/Jump Box selection +struct Sprite *CreateChooseBoxArrows(u16 x, u16 y, u8 animId, u8 priority, u8 subpriority) +{ + u8 spriteId = CreateSprite(&sSpriteTemplate_BoxScrollArrow, x, y, subpriority); + if (spriteId == MAX_SPRITES) + return NULL; + + animId %= 2; + StartSpriteAnim(&gSprites[spriteId], animId); + gSprites[spriteId].oam.priority = priority; + gSprites[spriteId].callback = SpriteCallbackDummy; + return &gSprites[spriteId]; +} diff --git a/src/pokemon_storage_system_2.c b/src/pokemon_storage_system_menu.c similarity index 61% rename from src/pokemon_storage_system_2.c rename to src/pokemon_storage_system_menu.c index 1f9c7a4e5..298659efc 100644 --- a/src/pokemon_storage_system_2.c +++ b/src/pokemon_storage_system_menu.c @@ -16,22 +16,20 @@ #include "constants/help_system.h" static EWRAM_DATA u8 sPreviousBoxOption = 0; -static EWRAM_DATA struct ChooseBoxMenu *sBoxSelectionPopupSpriteManager = NULL; +static EWRAM_DATA struct ChooseBoxMenu *sChooseBoxMenu = NULL; -static void PSS_CreatePCMenu(u8 whichMenu, s16 *windowIdPtr); +static void CreatePCMainMenu(u8 whichMenu, s16 *windowIdPtr); static void ChooseBoxMenu_CreateSprites(u8 curBox); -static void sub_808CBA4(void); -static void UpdateBoxNameAndCountSprite_WraparoundRight(void); -static void UpdateBoxNameAndCountSprite_WraparoundLeft(void); -static void PrintBoxNameAndCountToSprite(void); -static void PrintToSpriteWithTagUnk0240(const u8 *a0, u16 x, u16 y); -static void sub_808CD64(struct Sprite *sprite); +static void ChooseBoxMenu_DestroySprites(void); +static void ChooseBoxMenu_MoveRight(void); +static void ChooseBoxMenu_MoveLeft(void); +static void ChooseBoxMenu_PrintBoxNameAndCount(void); +static void ChooseBoxMenu_PrintTextToSprite(const u8 *a0, u16 x, u16 y); +static void SpriteCB_ChooseBoxArrow(struct Sprite *sprite); -// Forward declarations - -static const u16 sBoxSelectionPopupPalette[]; -static const u16 sBoxSelectionPopupCenterTiles[]; -static const u16 sBoxSelectionPopupSidesTiles[]; +static const u16 sChooseBoxMenu_Pal[]; +static const u8 sChooseBoxMenuCenter_Gfx[]; +static const u8 sChooseBoxMenuCorners_Gfx[]; struct { const u8 *text; @@ -44,7 +42,7 @@ struct { [OPTION_EXIT] = {gText_SeeYa, gText_SeeYaDescription} }; -void DrawTextWindowAndBufferTiles(const u8 *string, void *dst, u8 zero1, u8 zero2, u8 *buffer, s32 bytesToBuffer) +void DrawTextWindowAndBufferTiles(const u8 *string, void *dst, u8 zero1, u8 zero2, u8 *unused, s32 bytesToBuffer) { s32 i, tileBytesToBuffer, remainingBytes; u16 windowId; @@ -90,7 +88,7 @@ void DrawTextWindowAndBufferTiles(const u8 *string, void *dst, u8 zero1, u8 zero RemoveWindow(windowId); } -static void PrintStringToBufferCopyNow(const u8 *string, void *dst, u16 rise, u8 bgClr, u8 fgClr, u8 shClr, u8 *buffer) +static void PrintStringToBufferCopyNow(const u8 *string, void *dst, u16 offset, u8 bgColor, u8 fgColor, u8 shadowColor, u8 *unused) { u32 var; u8 windowId; @@ -102,15 +100,15 @@ static void PrintStringToBufferCopyNow(const u8 *string, void *dst, u16 rise, u8 winTemplate.height = 2; var = winTemplate.width * 32; windowId = AddWindow(&winTemplate); - FillWindowPixelBuffer(windowId, PIXEL_FILL(bgClr)); + FillWindowPixelBuffer(windowId, PIXEL_FILL(bgColor)); tileData1 = (u8 *)GetWindowAttribute(windowId, WINDOW_TILE_DATA); tileData2 = (winTemplate.width * 32) + tileData1; - txtColor[0] = bgClr; - txtColor[1] = fgClr; - txtColor[2] = shClr; + txtColor[0] = bgColor; + txtColor[1] = fgColor; + txtColor[2] = shadowColor; AddTextPrinterParameterized4(windowId, FONT_1, 0, 2, 0, 0, txtColor, -1, string); CpuCopy16(tileData1, dst, var); - CpuCopy16(tileData2, dst + rise, var); + CpuCopy16(tileData2, dst + offset, var); RemoveWindow(windowId); } @@ -147,10 +145,8 @@ u8 CountPartyNonEggMons(void) for (i = 0, count = 0; i < PARTY_SIZE; i++) { if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) != SPECIES_NONE - && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)) - { + && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)) count++; - } } return count; @@ -163,12 +159,10 @@ u8 CountPartyAliveNonEggMonsExcept(u8 slotToIgnore) for (i = 0, count = 0; i < PARTY_SIZE; i++) { if (i != slotToIgnore - && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) != SPECIES_NONE - && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG) - && GetMonData(&gPlayerParty[i], MON_DATA_HP) != 0) - { + && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) != SPECIES_NONE + && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG) + && GetMonData(&gPlayerParty[i], MON_DATA_HP) != 0) count++; - } } return count; @@ -186,9 +180,7 @@ u8 CountPartyMons(void) for (i = 0, count = 0; i < PARTY_SIZE; i++) { if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) != SPECIES_NONE) - { count++; - } } return count; @@ -205,7 +197,8 @@ static u8 *StringCopyAndFillWithSpaces(u8 *dst, const u8 *src, u16 n) return str; } -static void sub_808C25C(u16 *dest, u16 dest_left, u16 dest_top, const u16 *src, u16 src_left, u16 src_top, u16 dest_width, u16 dest_height, u16 src_width) +// Unused +static void UnusedWriteRectCpu(u16 *dest, u16 dest_left, u16 dest_top, const u16 *src, u16 src_left, u16 src_top, u16 dest_width, u16 dest_height, u16 src_width) { u16 i; @@ -231,16 +224,6 @@ static void UnusedWriteRectDma(u16 *dest, u16 dest_left, u16 dest_top, u16 width Dma3FillLarge16_(0, dest, width); } - -//------------------------------------------------------------------------------ -// SECTION: Main menu -// -// The below functions generally handle the PC main menu where the main -// options can be selected (Withdraw, Deposit, etc.), as well as exiting -// Pokémon Storage back to this menu. -//------------------------------------------------------------------------------ - - enum { STATE_LOAD, STATE_FADE_IN, @@ -263,7 +246,7 @@ static void Task_PCMainMenu(u8 taskId) { case STATE_LOAD: SetHelpContext(HELPCONTEXT_BILLS_PC); - PSS_CreatePCMenu(task->tSelectedOption, &task->tWindowId); + CreatePCMainMenu(task->tSelectedOption, &task->tWindowId); LoadStdWindowFrameGfx(); DrawDialogueFrame(0, FALSE); FillWindowPixelBuffer(0, PIXEL_FILL(1)); @@ -274,9 +257,8 @@ static void Task_PCMainMenu(u8 taskId) break; case STATE_FADE_IN: if (IsWeatherNotFadingIn()) - { task->tState++; - } + break; case STATE_HANDLE_INPUT: task->tInput = Menu_ProcessInput(); @@ -305,14 +287,14 @@ static void Task_PCMainMenu(u8 taskId) DestroyTask(taskId); break; default: - if (task->tInput == 0 && CountPartyMons() == PARTY_SIZE) + if (task->tInput == OPTION_WITHDRAW && CountPartyMons() == PARTY_SIZE) { // Can't withdraw FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, FONT_2, gText_PartyFull, 0, NULL, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY); - task->tState = 3; + task->tState = STATE_ERROR_MSG; } - else if (task->tInput == 1 && CountPartyMons() == 1) + else if (task->tInput == OPTION_DEPOSIT && CountPartyMons() == 1) { // Can't deposit FillWindowPixelBuffer(0, PIXEL_FILL(1)); @@ -362,7 +344,7 @@ static void Task_PCMainMenu(u8 taskId) if (!gPaletteFade.active) { CleanupOverworldWindowsAndTilemaps(); - Cb2_EnterPSS(task->tInput); + EnterPokeStorage(task->tInput); DestroyTask(taskId); } break; @@ -372,7 +354,7 @@ static void Task_PCMainMenu(u8 taskId) void ShowPokemonStorageSystemPC(void) { u8 taskId = CreateTask(Task_PCMainMenu, 80); - gTasks[taskId].tState = 0; + gTasks[taskId].tState = STATE_LOAD; gTasks[taskId].tSelectedOption = 0; LockPlayerFieldControls(); } @@ -384,14 +366,14 @@ static void FieldTask_ReturnToPcMenu(void) SetVBlankCallback(NULL); taskId = CreateTask(Task_PCMainMenu, 80); - gTasks[taskId].tState = 0; + gTasks[taskId].tState = STATE_LOAD; gTasks[taskId].tSelectedOption = sPreviousBoxOption; Task_PCMainMenu(taskId); SetVBlankCallback(vblankCb); FadeInFromBlack(); } -static const struct WindowTemplate sUnknown_83CDA48 = { +static const struct WindowTemplate sWindowTemplate_MainMenu = { .bg = 0, .tilemapLeft = 1, .tilemapTop = 1, @@ -401,14 +383,13 @@ static const struct WindowTemplate sUnknown_83CDA48 = { .baseBlock = 0x001 }; -static void PSS_CreatePCMenu(u8 whichMenu, s16 *windowIdPtr) +static void CreatePCMainMenu(u8 whichMenu, s16 *windowIdPtr) { - s16 windowId; - windowId = AddWindow(&sUnknown_83CDA48); + s16 windowId = AddWindow(&sWindowTemplate_MainMenu); DrawStdWindowFrame(windowId, FALSE); - PrintTextArray(windowId, FONT_2, GetMenuCursorDimensionByFont(FONT_2, 0), 2, 16, NELEMS(sMainMenuTexts), (void *)sMainMenuTexts); - Menu_InitCursor(windowId, FONT_2, 0, 2, 16, NELEMS(sMainMenuTexts), whichMenu); + PrintTextArray(windowId, FONT_2, GetMenuCursorDimensionByFont(FONT_2, 0), 2, 16, ARRAY_COUNT(sMainMenuTexts), (void *)sMainMenuTexts); + Menu_InitCursor(windowId, FONT_2, 0, 2, 16, ARRAY_COUNT(sMainMenuTexts), whichMenu); *windowIdPtr = windowId; } @@ -439,54 +420,44 @@ void ResetPokemonStorageSystem(void) SetBoxWallpaper(boxId, boxId % (MAX_DEFAULT_WALLPAPER + 1)); } - -//------------------------------------------------------------------------------ -// SECTION: Choose Box menu -// -// The below functions handle the popup menu that allows the player to cycle -// through the boxes and select one. Used when storing Pokémon in Deposit mode -// and for the Jump feature. -//------------------------------------------------------------------------------ - - -void LoadChooseBoxMenuGfx(struct ChooseBoxMenu *a0, u16 tileTag, u16 palTag, u8 a3, bool32 loadPal) +void LoadChooseBoxMenuGfx(struct ChooseBoxMenu *menu, u16 tileTag, u16 palTag, u8 subpriority, bool32 loadPal) { struct SpritePalette palette = { - sBoxSelectionPopupPalette, palTag + sChooseBoxMenu_Pal, palTag }; struct SpriteSheet sheets[] = { - {sBoxSelectionPopupCenterTiles, 0x800, tileTag}, - {sBoxSelectionPopupSidesTiles, 0x180, tileTag + 1}, + {sChooseBoxMenuCenter_Gfx, 0x800, tileTag}, + {sChooseBoxMenuCorners_Gfx, 0x180, tileTag + 1}, {} }; - if (loadPal) + if (loadPal) // Always false LoadSpritePalette(&palette); LoadSpriteSheets(sheets); - sBoxSelectionPopupSpriteManager = a0; - a0->tileTag = tileTag; - a0->paletteTag = palTag; - a0->subpriority = a3; - a0->loadedPalette = loadPal; + sChooseBoxMenu = menu; + menu->tileTag = tileTag; + menu->paletteTag = palTag; + menu->subpriority = subpriority; + menu->loadedPalette = loadPal; } void FreeBoxSelectionPopupSpriteGfx(void) { - if (sBoxSelectionPopupSpriteManager->loadedPalette) - FreeSpritePaletteByTag(sBoxSelectionPopupSpriteManager->paletteTag); - FreeSpriteTilesByTag(sBoxSelectionPopupSpriteManager->tileTag); - FreeSpriteTilesByTag(sBoxSelectionPopupSpriteManager->tileTag + 1); + if (sChooseBoxMenu->loadedPalette) + FreeSpritePaletteByTag(sChooseBoxMenu->paletteTag); + FreeSpriteTilesByTag(sChooseBoxMenu->tileTag); + FreeSpriteTilesByTag(sChooseBoxMenu->tileTag + 1); } -void sub_808C940(u8 curBox) +void CreateChooseBoxMenuSprites(u8 curBox) { ChooseBoxMenu_CreateSprites(curBox); } -void sub_808C950(void) +void DestroyChooseBoxMenuSprites(void) { - sub_808CBA4(); + ChooseBoxMenu_DestroySprites(); } u8 HandleBoxChooseSelectionInput(void) @@ -494,60 +465,61 @@ u8 HandleBoxChooseSelectionInput(void) if (JOY_NEW(B_BUTTON)) { PlaySE(SE_SELECT); - return 201; + return BOXID_CANCELED; } if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); - return sBoxSelectionPopupSpriteManager->curBox; + return sChooseBoxMenu->curBox; } if (JOY_NEW(DPAD_LEFT)) { PlaySE(SE_SELECT); - UpdateBoxNameAndCountSprite_WraparoundLeft(); + ChooseBoxMenu_MoveLeft(); } else if (JOY_NEW(DPAD_RIGHT)) { PlaySE(SE_SELECT); - UpdateBoxNameAndCountSprite_WraparoundRight(); + ChooseBoxMenu_MoveRight(); } - return 200; + return BOXID_NONE_CHOSEN; } -static const union AnimCmd gUnknown_83CDA50[] = { +static const union AnimCmd sAnim_ChooseBoxMenu_TopLeft[] = { ANIMCMD_FRAME( 0, 5), ANIMCMD_END }; -static const union AnimCmd gUnknown_83CDA58[] = { +static const union AnimCmd sAnim_ChooseBoxMenu_BottomLeft[] = { ANIMCMD_FRAME( 4, 5), ANIMCMD_END }; -static const union AnimCmd gUnknown_83CDA60[] = { +static const union AnimCmd sAnim_ChooseBoxMenu_TopRight[] = { ANIMCMD_FRAME( 6, 5), ANIMCMD_END }; -static const union AnimCmd gUnknown_83CDA68[] = { +static const union AnimCmd sAnim_ChooseBoxMenu_BottomRight[] = { ANIMCMD_FRAME(10, 5), ANIMCMD_END }; -static const union AnimCmd *const gUnknown_83CDA70[] = { - gUnknown_83CDA50, - gUnknown_83CDA58, - gUnknown_83CDA60, - gUnknown_83CDA68 +static const union AnimCmd *const sAnims_ChooseBoxMenu[] = { + sAnim_ChooseBoxMenu_TopLeft, + sAnim_ChooseBoxMenu_BottomLeft, + sAnim_ChooseBoxMenu_TopRight, + sAnim_ChooseBoxMenu_BottomRight, }; -static const union AffineAnimCmd gUnknown_83CDA80[] = { +static const union AffineAnimCmd sAffineAnim_ChooseBoxMenu[] = { AFFINEANIMCMD_FRAME(224, 224, 0, 0), AFFINEANIMCMD_END }; -static const union AffineAnimCmd *const gUnknown_83CDA90[] = { - gUnknown_83CDA80 +// Unused +static const union AffineAnimCmd *const sAffineAnims_ChooseBoxMenu[] = { + sAffineAnim_ChooseBoxMenu }; static void ChooseBoxMenu_CreateSprites(u8 curBox) @@ -562,112 +534,112 @@ static void ChooseBoxMenu_CreateSprites(u8 curBox) 0, 0, &oamData, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy }; { - const u8 gUnknown_83CDA94[] = _("/30"); + const u8 sText_OutOf30[] = _("/30"); - sBoxSelectionPopupSpriteManager->curBox = curBox; - template.tileTag = sBoxSelectionPopupSpriteManager->tileTag; - template.paletteTag = sBoxSelectionPopupSpriteManager->paletteTag; + sChooseBoxMenu->curBox = curBox; + template.tileTag = sChooseBoxMenu->tileTag; + template.paletteTag = sChooseBoxMenu->paletteTag; spriteId = CreateSprite(&template, 160, 96, 0); - sBoxSelectionPopupSpriteManager->menuSprite = gSprites + spriteId; + sChooseBoxMenu->menuSprite = gSprites + spriteId; - // Manual subsprites oamData.shape = SPRITE_SHAPE(8x32); oamData.size = SPRITE_SIZE(8x32); - template.tileTag = sBoxSelectionPopupSpriteManager->tileTag + 1; - template.anims = gUnknown_83CDA70; - for (i = 0; i < 4; i++) + template.tileTag = sChooseBoxMenu->tileTag + 1; + template.anims = sAnims_ChooseBoxMenu; + for (i = 0; i < ARRAY_COUNT(sChooseBoxMenu->menuCornerSprites); i++) { - u16 r5; - spriteId = CreateSprite(&template, 124, 80, sBoxSelectionPopupSpriteManager->subpriority); - sBoxSelectionPopupSpriteManager->menuSideSprites[i] = gSprites + spriteId; - r5 = 0; + // corner sprites are created in order of top left, bottom left, top right, bottom right + u16 animNum; + spriteId = CreateSprite(&template, 124, 80, sChooseBoxMenu->subpriority); // place at top left + sChooseBoxMenu->menuCornerSprites[i] = &gSprites[spriteId]; + animNum = 0; if (i & 2) { - sBoxSelectionPopupSpriteManager->menuSideSprites[i]->x = 196; - r5 = 2; + sChooseBoxMenu->menuCornerSprites[i]->x = 196; // move to bottom + animNum = 2; } if (i & 1) { - sBoxSelectionPopupSpriteManager->menuSideSprites[i]->y = 112; - sBoxSelectionPopupSpriteManager->menuSideSprites[i]->oam.size = SPRITE_SIZE(8x16); - r5++; + sChooseBoxMenu->menuCornerSprites[i]->y = 112; // move to right + sChooseBoxMenu->menuCornerSprites[i]->oam.size = SPRITE_SIZE(8x16); + animNum++; } - StartSpriteAnim(sBoxSelectionPopupSpriteManager->menuSideSprites[i], r5); + StartSpriteAnim(sChooseBoxMenu->menuCornerSprites[i], animNum); } - for (i = 0; i < 2; i++) + for (i = 0; i < ARRAY_COUNT(sChooseBoxMenu->arrowSprites); i++) { - sBoxSelectionPopupSpriteManager->arrowSprites[i] = CreateChooseBoxArrows(72 * i + 0x7c, 0x58, i, 0, sBoxSelectionPopupSpriteManager->subpriority); - if (sBoxSelectionPopupSpriteManager->arrowSprites[i]) + sChooseBoxMenu->arrowSprites[i] = CreateChooseBoxArrows(72 * i + 124, 88, i, 0, sChooseBoxMenu->subpriority); + if (sChooseBoxMenu->arrowSprites[i]) { - sBoxSelectionPopupSpriteManager->arrowSprites[i]->data[0] = (i == 0 ? -1 : 1); - sBoxSelectionPopupSpriteManager->arrowSprites[i]->callback = sub_808CD64; + sChooseBoxMenu->arrowSprites[i]->data[0] = (i == 0 ? -1 : 1); + sChooseBoxMenu->arrowSprites[i]->callback = SpriteCB_ChooseBoxArrow; } } - PrintBoxNameAndCountToSprite(); - PrintToSpriteWithTagUnk0240(gUnknown_83CDA94, 5, 3); + ChooseBoxMenu_PrintBoxNameAndCount(); + ChooseBoxMenu_PrintTextToSprite(sText_OutOf30, 5, 3); } } -static void sub_808CBA4(void) +static void ChooseBoxMenu_DestroySprites(void) { u16 i; - if (sBoxSelectionPopupSpriteManager->menuSprite) + if (sChooseBoxMenu->menuSprite) { - DestroySprite(sBoxSelectionPopupSpriteManager->menuSprite); - sBoxSelectionPopupSpriteManager->menuSprite = NULL; + DestroySprite(sChooseBoxMenu->menuSprite); + sChooseBoxMenu->menuSprite = NULL; } - for (i = 0; i < 4; i++) + for (i = 0; i < ARRAY_COUNT(sChooseBoxMenu->menuCornerSprites); i++) { - if (sBoxSelectionPopupSpriteManager->menuSideSprites[i]) + if (sChooseBoxMenu->menuCornerSprites[i]) { - DestroySprite(sBoxSelectionPopupSpriteManager->menuSideSprites[i]); - sBoxSelectionPopupSpriteManager->menuSideSprites[i] = NULL; + DestroySprite(sChooseBoxMenu->menuCornerSprites[i]); + sChooseBoxMenu->menuCornerSprites[i] = NULL; } } - for (i = 0; i < 2; i++) + for (i = 0; i < ARRAY_COUNT(sChooseBoxMenu->arrowSprites); i++) { - if (sBoxSelectionPopupSpriteManager->arrowSprites[i]) - DestroySprite(sBoxSelectionPopupSpriteManager->arrowSprites[i]); + if (sChooseBoxMenu->arrowSprites[i]) + DestroySprite(sChooseBoxMenu->arrowSprites[i]); } } -static void UpdateBoxNameAndCountSprite_WraparoundRight(void) +static void ChooseBoxMenu_MoveRight(void) { - if (++sBoxSelectionPopupSpriteManager->curBox >= TOTAL_BOXES_COUNT) - sBoxSelectionPopupSpriteManager->curBox = 0; - PrintBoxNameAndCountToSprite(); + if (++sChooseBoxMenu->curBox >= TOTAL_BOXES_COUNT) + sChooseBoxMenu->curBox = 0; + ChooseBoxMenu_PrintBoxNameAndCount(); } -static void UpdateBoxNameAndCountSprite_WraparoundLeft(void) +static void ChooseBoxMenu_MoveLeft(void) { - sBoxSelectionPopupSpriteManager->curBox = (sBoxSelectionPopupSpriteManager->curBox == 0 ? TOTAL_BOXES_COUNT - 1 : sBoxSelectionPopupSpriteManager->curBox - 1); - PrintBoxNameAndCountToSprite(); + sChooseBoxMenu->curBox = (sChooseBoxMenu->curBox == 0 ? TOTAL_BOXES_COUNT - 1 : sChooseBoxMenu->curBox - 1); + ChooseBoxMenu_PrintBoxNameAndCount(); } -static void PrintBoxNameAndCountToSprite(void) +static void ChooseBoxMenu_PrintBoxNameAndCount(void) { - u8 nPokemonInBox = CountMonsInBox(sBoxSelectionPopupSpriteManager->curBox); - u8 *boxName = StringCopy(sBoxSelectionPopupSpriteManager->strbuf, GetBoxNamePtr(sBoxSelectionPopupSpriteManager->curBox)); + u8 numMonInBox = CountMonsInBox(sChooseBoxMenu->curBox); + u8 *boxName = StringCopy(sChooseBoxMenu->strbuf, GetBoxNamePtr(sChooseBoxMenu->curBox)); - while (boxName < sBoxSelectionPopupSpriteManager->strbuf + BOX_NAME_LENGTH) + while (boxName < sChooseBoxMenu->strbuf + BOX_NAME_LENGTH) *boxName++ = CHAR_SPACE; *boxName = EOS; - PrintToSpriteWithTagUnk0240(sBoxSelectionPopupSpriteManager->strbuf, 0, 1); + ChooseBoxMenu_PrintTextToSprite(sChooseBoxMenu->strbuf, 0, 1); - ConvertIntToDecimalStringN(sBoxSelectionPopupSpriteManager->strbuf, nPokemonInBox, STR_CONV_MODE_RIGHT_ALIGN, 2); + ConvertIntToDecimalStringN(sChooseBoxMenu->strbuf, numMonInBox, STR_CONV_MODE_RIGHT_ALIGN, 2); - PrintToSpriteWithTagUnk0240(sBoxSelectionPopupSpriteManager->strbuf, 3, 3); + ChooseBoxMenu_PrintTextToSprite(sChooseBoxMenu->strbuf, 3, 3); } -static void PrintToSpriteWithTagUnk0240(const u8 *str, u16 x, u16 y) +static void ChooseBoxMenu_PrintTextToSprite(const u8 *str, u16 x, u16 y) { - u16 tileStart = GetSpriteTileStartByTag(sBoxSelectionPopupSpriteManager->tileTag); - PrintStringToBufferCopyNow(str, (void *)(OBJ_VRAM0 + tileStart * 32 + 256 * y + 32 * x), 0x100, TEXT_COLOR_RED, TEXT_DYNAMIC_COLOR_6, TEXT_DYNAMIC_COLOR_5, sBoxSelectionPopupSpriteManager->buffer); + void *dst = (void *)(OBJ_VRAM0 + GetSpriteTileStartByTag(sChooseBoxMenu->tileTag) * 32 + 256 * y + 32 * x); + PrintStringToBufferCopyNow(str, dst, 0x100, TEXT_COLOR_RED, TEXT_DYNAMIC_COLOR_6, TEXT_DYNAMIC_COLOR_5, sChooseBoxMenu->buffer); } -static void sub_808CD64(struct Sprite *sprite) +static void SpriteCB_ChooseBoxArrow(struct Sprite *sprite) { if (++sprite->data[1] > 3) { @@ -681,8 +653,8 @@ static void sub_808CD64(struct Sprite *sprite) } } -// Forward-declared rodata +// Unused, since LoadChooseBoxMenuGfx is always called with `loadPal` as false +static const u16 sChooseBoxMenu_Pal[] = INCBIN_U16("graphics/pokemon_storage/unused_choose_box_menu.gbapal"); -static const u16 sBoxSelectionPopupPalette[] = INCBIN_U16("graphics/interface/pss_unk_83CDA98.gbapal"); -static const u16 sBoxSelectionPopupCenterTiles[] = INCBIN_U16("graphics/interface/pss_unk_83CDAB8.4bpp"); -static const u16 sBoxSelectionPopupSidesTiles[] = INCBIN_U16("graphics/interface/pss_unk_83CE2B8.4bpp"); +static const u8 sChooseBoxMenuCenter_Gfx[] = INCBIN_U8("graphics/pokemon_storage/choose_box_menu_center.4bpp"); +static const u8 sChooseBoxMenuCorners_Gfx[] = INCBIN_U8("graphics/pokemon_storage/choose_box_menu_corners.4bpp"); diff --git a/src/pokemon_storage_system_misc.c b/src/pokemon_storage_system_misc.c new file mode 100644 index 000000000..2cfa98152 --- /dev/null +++ b/src/pokemon_storage_system_misc.c @@ -0,0 +1,1431 @@ +#include // to declare abs +#include "global.h" +#include "gflib.h" +#include "decompress.h" +#include "item.h" +#include "item_menu_icons.h" +#include "menu.h" +#include "new_menu_helpers.h" +#include "pokemon_icon.h" +#include "pokemon_storage_system_internal.h" +#include "text_window.h" +#include "trig.h" +#include "constants/items.h" + +static EWRAM_DATA struct +{ + u8 funcId; + u8 state; + u8 fromColumn; + u8 fromRow; + u8 toColumn; + u8 toRow; + u8 cursorColumn; + u8 cursorRow; + u8 minColumn; + u8 minRow; + u8 columnsTotal; + u8 rowsTotal; + u16 bgX; + u16 bgY; + u16 bgMoveSteps; + struct BoxPokemon boxMons[IN_BOX_COUNT]; +} *sMultiMove = NULL; + +static bool8 MultiMove_Function_Start(void); +static bool8 MultiMove_Function_Single(void); +static bool8 MultiMove_Function_ChangeSelection(void); +static bool8 MultiMove_Function_GrabSelection(void); +static bool8 MultiMove_Function_MoveMons(void); +static bool8 MultiMove_Function_PlaceMons(void); +static void MultiMove_UpdateSelectedIcons(void); +static void MultiMove_SelectColumn(u8 column, u8 minRow, u8 maxRow); +static void MultiMove_SelectRow(u8 row, u8 minColumn, u8 maxColumn); +static void MultiMove_DeselectColumn(u8 arg0, u8 minRow, u8 maxRow); +static void MultiMove_DeselectRow(u8 row, u8 minColumn, u8 maxColumn); +static void MultiMove_SetIconToBg(u8 x, u8 y); +static void MultiMove_ClearIconFromBg(u8 x, u8 y); +static void MultiMove_InitBg(u16 bgX, u16 bgY, u16 duration); +static u8 MultiMove_UpdateBg(void); +static void MultiMove_GetMonsFromSelection(void); +static void MultiMove_RemoveMonsFromBox(void); +static void MultiMove_CreatePlacedMonIcons(void); +static void MultiMove_SetPlacedMonData(void); +static void MultiMove_ResetBg(void); + +static const struct WindowTemplate sWindowTemplate_MultiMove = { + .bg = 0, + .tilemapLeft = 10, + .tilemapTop = 3, + .width = 20, + .height = 18, + .paletteNum = 9, + .baseBlock = 0x00a +}; + +bool8 MultiMove_Init(void) +{ + sMultiMove = Alloc(sizeof(*sMultiMove)); + if (sMultiMove != NULL) + { + gStorage->multiMoveWindowId = AddWindow8Bit(&sWindowTemplate_MultiMove); + if (gStorage->multiMoveWindowId != WINDOW_NONE) + { + FillWindowPixelBuffer(gStorage->multiMoveWindowId, PIXEL_FILL(0)); + return TRUE; + } + } + + return FALSE; +} + +void MultiMove_Free(void) +{ + if (sMultiMove != NULL) + Free(sMultiMove); +} + +void MultiMove_SetFunction(u8 funcId) +{ + sMultiMove->funcId = funcId; + sMultiMove->state = 0; +} + +bool8 MultiMove_RunFunction(void) +{ + switch (sMultiMove->funcId) + { + case MULTIMOVE_START: + return MultiMove_Function_Start(); + case MULTIMOVE_SINGLE: + return MultiMove_Function_Single(); + case MULTIMOVE_CHANGE_SELECTION: + return MultiMove_Function_ChangeSelection(); + case MULTIMOVE_GRAB_SELECTION: + return MultiMove_Function_GrabSelection(); + case MULTIMOVE_MOVE_MONS: + return MultiMove_Function_MoveMons(); + case MULTIMOVE_PLACE_MONS: + return MultiMove_Function_PlaceMons(); + } + + return FALSE; +} + +static bool8 MultiMove_Function_Start(void) +{ + switch (sMultiMove->state) + { + case 0: + HideBg(0); + LoadMonIconPalettesAt(0x80); + sMultiMove->state++; + break; + case 1: + GetCursorBoxColumnAndRow(&sMultiMove->fromColumn, &sMultiMove->fromRow); + sMultiMove->toColumn = sMultiMove->fromColumn; + sMultiMove->toRow = sMultiMove->fromRow; + ChangeBgX(0, -1024, BG_COORD_SET); + ChangeBgY(0, -1024, BG_COORD_SET); + FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 32, 32); + FillWindowPixelBuffer8Bit(gStorage->multiMoveWindowId, PIXEL_FILL(0)); + MultiMove_SetIconToBg(sMultiMove->fromColumn, sMultiMove->fromRow); + SetBgAttribute(0, BG_ATTR_PALETTEMODE, 1); + PutWindowTilemap(gStorage->multiMoveWindowId); + CopyWindowToVram8Bit(gStorage->multiMoveWindowId, COPYWIN_FULL); + BlendPalettes(0x3F00, 8, RGB_WHITE); + StartCursorAnim(CURSOR_ANIM_OPEN); + SetGpuRegBits(REG_OFFSET_BG0CNT, BGCNT_256COLOR); + sMultiMove->state++; + break; + case 2: + if (!IsDma3ManagerBusyWithBgCopy()) + { + ShowBg(0); + return FALSE; + } + break; + } + + return TRUE; +} + +static bool8 MultiMove_Function_Single(void) +{ + switch (sMultiMove->state) + { + case 0: + HideBg(0); + sMultiMove->state++; + break; + case 1: + MultiMove_ResetBg(); + StartCursorAnim(CURSOR_ANIM_BOUNCE); + sMultiMove->state++; + break; + case 2: + if (!IsDma3ManagerBusyWithBgCopy()) + { + SetCursorPriorityTo1(); + LoadPalette(stdpal_get(3), 0xD0, 0x20); + ShowBg(0); + return FALSE; + } + break; + } + + return TRUE; +} + +static bool8 MultiMove_Function_ChangeSelection(void) +{ + switch (sMultiMove->state) + { + case 0: + if (!UpdateCursorPos()) + { + GetCursorBoxColumnAndRow(&sMultiMove->cursorColumn, &sMultiMove->cursorRow); + MultiMove_UpdateSelectedIcons(); + sMultiMove->toColumn = sMultiMove->cursorColumn; + sMultiMove->toRow = sMultiMove->cursorRow; + CopyWindowToVram8Bit(gStorage->multiMoveWindowId, COPYWIN_GFX); + sMultiMove->state++; + } + break; + case 1: + return IsDma3ManagerBusyWithBgCopy(); + } + + return TRUE; +} + +static bool8 MultiMove_Function_GrabSelection(void) +{ + u8 movingBg, movingMon; + + switch (sMultiMove->state) + { + case 0: + MultiMove_GetMonsFromSelection(); + MultiMove_RemoveMonsFromBox(); + InitMultiMonPlaceChange(FALSE); + sMultiMove->state++; + break; + case 1: + if (!DoMonPlaceChange()) + { + StartCursorAnim(CURSOR_ANIM_FIST); + MultiMove_InitBg(0, 256, 8); + InitMultiMonPlaceChange(TRUE); + sMultiMove->state++; + } + break; + case 2: + movingBg = MultiMove_UpdateBg(); + movingMon = DoMonPlaceChange(); + if (!movingBg && !movingMon) + return FALSE; + break; + } + + return TRUE; +} + +static bool8 MultiMove_Function_MoveMons(void) +{ + u8 movingCursor = UpdateCursorPos(); + u8 movingBg = MultiMove_UpdateBg(); + + if (!movingCursor && !movingBg) + return FALSE; + else + return TRUE; +} + +static bool8 MultiMove_Function_PlaceMons(void) +{ + switch (sMultiMove->state) + { + case 0: + MultiMove_SetPlacedMonData(); + MultiMove_InitBg(0, -256, 8); + InitMultiMonPlaceChange(FALSE); + sMultiMove->state++; + break; + case 1: + if (!DoMonPlaceChange() && !MultiMove_UpdateBg()) + { + MultiMove_CreatePlacedMonIcons(); + StartCursorAnim(CURSOR_ANIM_OPEN); + InitMultiMonPlaceChange(TRUE); + HideBg(0); + sMultiMove->state++; + } + break; + case 2: + if (!DoMonPlaceChange()) + { + StartCursorAnim(CURSOR_ANIM_BOUNCE); + MultiMove_ResetBg(); + sMultiMove->state++; + } + break; + case 3: + if (!IsDma3ManagerBusyWithBgCopy()) + { + LoadPalette(stdpal_get(3), 0xD0, 0x20); + SetCursorPriorityTo1(); + ShowBg(0); + return FALSE; + } + break; + } + + return TRUE; +} + +bool8 MultiMove_TryMoveGroup(u8 dir) +{ + switch (dir) + { + case 0: // up + if (sMultiMove->minRow == 0) + return FALSE; + sMultiMove->minRow--; + MultiMove_InitBg(0, 1024, 6); + break; + case 1: // down + if (sMultiMove->minRow + sMultiMove->rowsTotal >= 5) + return FALSE; + sMultiMove->minRow++; + MultiMove_InitBg(0, -1024, 6); + break; + case 2: // left + if (sMultiMove->minColumn == 0) + return FALSE; + sMultiMove->minColumn--; + MultiMove_InitBg(1024, 0, 6); + break; + case 3: // right + if (sMultiMove->minColumn + sMultiMove->columnsTotal > 5) + return FALSE; + sMultiMove->minColumn++; + MultiMove_InitBg(-1024, 0, 6); + break; + } + + return TRUE; +} + +static void MultiMove_UpdateSelectedIcons(void) +{ + s16 columnChange = (abs(sMultiMove->fromColumn - sMultiMove->cursorColumn)) - (abs(sMultiMove->fromColumn - sMultiMove->toColumn)); + s16 rowChange = (abs(sMultiMove->fromRow - sMultiMove->cursorRow)) - (abs(sMultiMove->fromRow - sMultiMove->toRow)); + + if (columnChange > 0) + MultiMove_SelectColumn(sMultiMove->cursorColumn, sMultiMove->fromRow, sMultiMove->toRow); + + if (columnChange < 0) + { + MultiMove_DeselectColumn(sMultiMove->toColumn, sMultiMove->fromRow, sMultiMove->toRow); + MultiMove_SelectColumn(sMultiMove->cursorColumn, sMultiMove->fromRow, sMultiMove->toRow); + } + + if (rowChange > 0) + MultiMove_SelectRow(sMultiMove->cursorRow, sMultiMove->fromColumn, sMultiMove->toColumn); + + if (rowChange < 0) + { + MultiMove_DeselectRow(sMultiMove->toRow, sMultiMove->fromColumn, sMultiMove->toColumn); + MultiMove_SelectRow(sMultiMove->cursorRow, sMultiMove->fromColumn, sMultiMove->toColumn); + } +} + +static void MultiMove_SelectColumn(u8 column, u8 minRow, u8 maxRow) +{ + u8 tmp = minRow; + + if (minRow > maxRow) + { + minRow = maxRow; + maxRow = tmp; + } + + while (minRow <= maxRow) + MultiMove_SetIconToBg(column, minRow++); +} + +static void MultiMove_SelectRow(u8 row, u8 minColumn, u8 maxColumn) +{ + u8 tmp = minColumn; + + if (minColumn > maxColumn) + { + minColumn = maxColumn; + maxColumn = tmp; + } + + while (minColumn <= maxColumn) + MultiMove_SetIconToBg(minColumn++, row); +} + +static void MultiMove_DeselectColumn(u8 column, u8 minRow, u8 maxRow) +{ + u8 tmp = minRow; + + if (minRow > maxRow) + { + minRow = maxRow; + maxRow = tmp; + } + + while (minRow <= maxRow) + MultiMove_ClearIconFromBg(column, minRow++); +} + +static void MultiMove_DeselectRow(u8 row, u8 minColumn, u8 maxColumn) +{ + u8 tmp = minColumn; + + if (minColumn > maxColumn) + { + minColumn = maxColumn; + maxColumn = tmp; + } + + while (minColumn <= maxColumn) + MultiMove_ClearIconFromBg(minColumn++, row); +} + +static void MultiMove_SetIconToBg(u8 x, u8 y) +{ + u8 position = x + (IN_BOX_COLUMNS * y); + u16 species = GetCurrentBoxMonData(position, MON_DATA_SPECIES2); + u32 personality = GetCurrentBoxMonData(position, MON_DATA_PERSONALITY); + + if (species != SPECIES_NONE) + { + const u8 *iconGfx = GetMonIconPtr(species, personality, 1); + u8 palNum = GetValidMonIconPalIndex(species) + 8; + BlitBitmapRectToWindow4BitTo8Bit(gStorage->multiMoveWindowId, iconGfx, 0, 0, 32, 32, 24 * x, 24 * y, 32, 32, palNum); + } +} + +static void MultiMove_ClearIconFromBg(u8 x, u8 y) +{ + u8 position = x + (IN_BOX_COLUMNS * y); + u16 species = GetCurrentBoxMonData(position, MON_DATA_SPECIES2); + + if (species != SPECIES_NONE) + FillWindowPixelRect8Bit(gStorage->multiMoveWindowId, PIXEL_FILL(0), 24 * x, 24 * y, 32, 32); +} + +static void MultiMove_InitBg(u16 bgX, u16 bgY, u16 duration) +{ + sMultiMove->bgX = bgX; + sMultiMove->bgY = bgY; + sMultiMove->bgMoveSteps = duration; +} + +static u8 MultiMove_UpdateBg(void) +{ + if (sMultiMove->bgMoveSteps != 0) + { + ChangeBgX(0, sMultiMove->bgX, BG_COORD_ADD); + ChangeBgY(0, sMultiMove->bgY, BG_COORD_ADD); + sMultiMove->bgMoveSteps--; + } + + return sMultiMove->bgMoveSteps; +} + +static void MultiMove_GetMonsFromSelection(void) +{ + s32 i, j; + s32 columnCount, rowCount; + u8 boxId; + u8 monArrayId; + + sMultiMove->minColumn = min(sMultiMove->fromColumn, sMultiMove->toColumn); + sMultiMove->minRow = min(sMultiMove->fromRow, sMultiMove->toRow); + sMultiMove->columnsTotal = abs(sMultiMove->fromColumn - sMultiMove->toColumn) + 1; + sMultiMove->rowsTotal = abs(sMultiMove->fromRow - sMultiMove->toRow) + 1; + boxId = StorageGetCurrentBox(); + monArrayId = 0; + columnCount = sMultiMove->minColumn + sMultiMove->columnsTotal; + rowCount = sMultiMove->minRow + sMultiMove->rowsTotal; + for (i = sMultiMove->minRow; i < rowCount; i++) + { + u8 boxPosition = (IN_BOX_COLUMNS * i) + sMultiMove->minColumn; + for (j = sMultiMove->minColumn; j < columnCount; j++) + { + struct BoxPokemon *boxMon = GetBoxedMonPtr(boxId, boxPosition); + // UB: possible null dereference +#ifdef UBFIX + if (boxMon != NULL) + sMultiMove->boxMons[monArrayId] = *boxMon; +#else + sMultiMove->boxMons[monArrayId] = *boxMon; +#endif + monArrayId++; + boxPosition++; + } + } +} + +static void MultiMove_RemoveMonsFromBox(void) +{ + s32 i, j; + s32 columnCount = sMultiMove->minColumn + sMultiMove->columnsTotal; + s32 rowCount = sMultiMove->minRow + sMultiMove->rowsTotal; + u8 boxId = StorageGetCurrentBox(); + + for (i = sMultiMove->minRow; i < rowCount; i++) + { + u8 boxPosition = (IN_BOX_COLUMNS * i) + sMultiMove->minColumn; + for (j = sMultiMove->minColumn; j < columnCount; j++) + { + DestroyBoxMonIconAtPosition(boxPosition); + ZeroBoxMonAt(boxId, boxPosition); + boxPosition++; + } + } +} + +static void MultiMove_CreatePlacedMonIcons(void) +{ + s32 i, j; + s32 columnCount = sMultiMove->minColumn + sMultiMove->columnsTotal; + s32 rowCount = sMultiMove->minRow + sMultiMove->rowsTotal; + u8 monArrayId = 0; + + for (i = sMultiMove->minRow; i < rowCount; i++) + { + u8 boxPosition = (IN_BOX_COLUMNS * i) + sMultiMove->minColumn; + for (j = sMultiMove->minColumn; j < columnCount; j++) + { + if (GetBoxMonData(&sMultiMove->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES)) + CreateBoxMonIconAtPos(boxPosition); + monArrayId++; + boxPosition++; + } + } +} + +static void MultiMove_SetPlacedMonData(void) +{ + s32 i, j; + s32 columnCount = sMultiMove->minColumn + sMultiMove->columnsTotal; + s32 rowCount = sMultiMove->minRow + sMultiMove->rowsTotal; + u8 boxId = StorageGetCurrentBox(); + u8 monArrayId = 0; + + for (i = sMultiMove->minRow; i < rowCount; i++) + { + u8 boxPosition = (IN_BOX_COLUMNS * i) + sMultiMove->minColumn; + for (j = sMultiMove->minColumn; j < columnCount; j++) + { + if (GetBoxMonData(&sMultiMove->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES)) + SetBoxMonAt(boxId, boxPosition, &sMultiMove->boxMons[monArrayId]); + boxPosition++; + monArrayId++; + } + } +} + +static void MultiMove_ResetBg(void) +{ + ChangeBgX(0, 0, BG_COORD_SET); + ChangeBgY(0, 0, BG_COORD_SET); + SetBgAttribute(0, BG_ATTR_PALETTEMODE, 0); + ClearGpuRegBits(REG_OFFSET_BG0CNT, BGCNT_256COLOR); + FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 32, 32); + CopyBgTilemapBufferToVram(0); +} + +u8 MultiMove_GetOriginPosition(void) +{ + return (IN_BOX_COLUMNS * sMultiMove->fromRow) + sMultiMove->fromColumn; +} + +bool8 MultiMove_CanPlaceSelection(void) +{ + s32 i, j; + s32 columnCount = sMultiMove->minColumn + sMultiMove->columnsTotal; + s32 rowCount = sMultiMove->minRow + sMultiMove->rowsTotal; + u8 monArrayId = 0; + + for (i = sMultiMove->minRow; i < rowCount; i++) + { + u8 boxPosition = (IN_BOX_COLUMNS * i) + sMultiMove->minColumn; + for (j = sMultiMove->minColumn; j < columnCount; j++) + { + if (GetBoxMonData(&sMultiMove->boxMons[monArrayId], MON_DATA_SANITY_HAS_SPECIES) + && GetCurrentBoxMonData(boxPosition, MON_DATA_SANITY_HAS_SPECIES)) + return FALSE; + + monArrayId++; + boxPosition++; + } + } + + return TRUE; +} + +// IDs for the item icon sprite callbacks +enum { + ITEM_CB_WAIT_ANIM, + ITEM_CB_TO_HAND, + ITEM_CB_TO_MON, + ITEM_CB_SWAP_TO_HAND, + ITEM_CB_SWAP_TO_MON, + ITEM_CB_UNUSED_1, + ITEM_CB_UNUSED_2, + ITEM_CB_HIDE_PARTY, +}; + +static u8 GetNewItemIconIdx(void); +static bool32 IsItemIconAtPosition(u8 cursorArea, u8 cursorPos); +static u8 GetItemIconIdxByPosition(u8 cursorArea, u8 cursorPos); +static void SetItemIconPosition(u8 id, u8 cursorArea, u8 cursorPos); +static void LoadItemIconGfx(u8 id, const u32 * tiles, const u32 * pal); +static void SetItemIconAffineAnim(u8 id, u8 affineAnimNo); +static void SetItemIconCallback(u8 id, u8 command, u8 cursorArea, u8 cursorPos); +static void SetItemIconActive(u8 id, bool8 show); +static const u32 *GetItemIconPic(u16 itemId); +static const u32 *GetItemIconPalette(u16 itemId); +static void DrawItemInfoWindow(u32 x); +static void SpriteCB_ItemIcon_WaitAnim(struct Sprite *sprite); +static void SpriteCB_ItemIcon_ToHand(struct Sprite *sprite); +static void SpriteCB_ItemIcon_SetPosToCursor(struct Sprite *sprite); +static void SpriteCB_ItemIcon_ToMon(struct Sprite *sprite); +static void SpriteCB_ItemIcon_SwapToHand(struct Sprite *sprite); +static void SpriteCB_ItemIcon_SwapToMon(struct Sprite *sprite); +static void SpriteCB_ItemIcon_HideParty(struct Sprite *sprite); + +static const u32 sItemInfoFrame_Gfx[] = INCBIN_U32("graphics/pokemon_storage/item_info_frame.4bpp"); + +static const struct OamData sOamData_ItemIcon = { + .y = 0, + .affineMode = ST_OAM_AFFINE_NORMAL, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = SPRITE_SHAPE(32x32), + .x = 0, + .matrixNum = 0, + .size = SPRITE_SIZE(32x32), + .tileNum = 0x000, + .priority = 1, + .paletteNum = 0, + .affineParam = 0 +}; + +static const union AffineAnimCmd sAffineAnim_ItemIcon_Small[] = { + AFFINEANIMCMD_FRAME(128, 128, 0, 0), + AFFINEANIMCMD_END +}; + +static const union AffineAnimCmd sAffineAnim_ItemIcon_Appear[] = { + AFFINEANIMCMD_FRAME(88, 88, 0, 0), + AFFINEANIMCMD_FRAME(5, 5, 0, 8), + AFFINEANIMCMD_END +}; + +static const union AffineAnimCmd sAffineAnim_ItemIcon_Disappear[] = { + AFFINEANIMCMD_FRAME(128, 128, 0, 0), + AFFINEANIMCMD_FRAME(-5, -5, 0, 8), + AFFINEANIMCMD_END +}; + +static const union AffineAnimCmd sAffineAnim_ItemIcon_PickUp[] = { + AFFINEANIMCMD_FRAME(128, 128, 0, 0), + AFFINEANIMCMD_FRAME(10, 10, 0, 12), + AFFINEANIMCMD_FRAME(256, 256, 0, 0), + AFFINEANIMCMD_END +}; + +static const union AffineAnimCmd sAffineAnim_ItemIcon_PutDown[] = { + AFFINEANIMCMD_FRAME(256, 256, 0, 0), + AFFINEANIMCMD_FRAME(-10, -10, 0, 12), + AFFINEANIMCMD_FRAME(128, 128, 0, 0), + AFFINEANIMCMD_END +}; + +static const union AffineAnimCmd sAffineAnim_ItemIcon_PutAway[] = { + AFFINEANIMCMD_FRAME(256, 256, 0, 0), + AFFINEANIMCMD_FRAME(-5, -5, 0, 16), + AFFINEANIMCMD_END +}; + +static const union AffineAnimCmd sAffineAnim_ItemIcon_Large[] = { + AFFINEANIMCMD_FRAME(256, 256, 0, 0), + AFFINEANIMCMD_END +}; + +static const union AffineAnimCmd *const sAffineAnims_ItemIcon[] = { + [ITEM_ANIM_NONE] = sAffineAnim_ItemIcon_Small, + [ITEM_ANIM_APPEAR] = sAffineAnim_ItemIcon_Appear, + [ITEM_ANIM_DISAPPEAR] = sAffineAnim_ItemIcon_Disappear, + [ITEM_ANIM_PICK_UP] = sAffineAnim_ItemIcon_PickUp, + [ITEM_ANIM_PUT_DOWN] = sAffineAnim_ItemIcon_PutDown, + [ITEM_ANIM_PUT_AWAY] = sAffineAnim_ItemIcon_PutAway, + [ITEM_ANIM_LARGE] = sAffineAnim_ItemIcon_Large, +}; + +static const struct SpriteTemplate sSpriteTemplate_ItemIcon = { + .tileTag = GFXTAG_ITEM_ICON_0, + .paletteTag = PALTAG_ITEM_ICON_0, + .oam = &sOamData_ItemIcon, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = sAffineAnims_ItemIcon, + .callback = SpriteCallbackDummy, +}; + +void CreateItemIconSprites(void) +{ + s32 i; + u8 spriteId; + struct CompressedSpriteSheet spriteSheet; + struct SpriteTemplate spriteTemplate; + static u32 sItemIconGfxBuffer[0x61]; + + if (gStorage->boxOption == OPTION_MOVE_ITEMS) + { + spriteSheet.data = sItemIconGfxBuffer; + spriteSheet.size = 0x200; + spriteTemplate = sSpriteTemplate_ItemIcon; + + for (i = 0; i < MAX_ITEM_ICONS; i++) + { + spriteSheet.tag = GFXTAG_ITEM_ICON_0 + i; + LoadCompressedSpriteSheet(&spriteSheet); + gStorage->itemIcons[i].tiles = GetSpriteTileStartByTag(spriteSheet.tag) * TILE_SIZE_4BPP + (void *)(OBJ_VRAM0); + gStorage->itemIcons[i].palIndex = AllocSpritePalette(PALTAG_ITEM_ICON_0 + i); + gStorage->itemIcons[i].palIndex *= 16; + gStorage->itemIcons[i].palIndex += 0x100; + spriteTemplate.tileTag = GFXTAG_ITEM_ICON_0 + i; + spriteTemplate.paletteTag = PALTAG_ITEM_ICON_0 + i; + spriteId = CreateSprite(&spriteTemplate, 0, 0, 11); + gStorage->itemIcons[i].sprite = &gSprites[spriteId]; + gStorage->itemIcons[i].sprite->invisible = TRUE; + gStorage->itemIcons[i].active = FALSE; + } + } + gStorage->movingItemId = ITEM_NONE; +} + +void TryLoadItemIconAtPos(u8 cursorArea, u8 cursorPos) +{ + u16 heldItem; + + if ((gStorage->boxOption != OPTION_MOVE_ITEMS) || IsItemIconAtPosition(cursorArea, cursorPos)) + return; + + switch (cursorArea) + { + case CURSOR_AREA_IN_BOX: + if (!GetCurrentBoxMonData(cursorPos, MON_DATA_SANITY_HAS_SPECIES)) + return; + heldItem = GetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM); + break; + case CURSOR_AREA_IN_PARTY: + if (!GetMonData(&gPlayerParty[cursorPos], MON_DATA_SANITY_HAS_SPECIES)) + return; + heldItem = GetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM); + break; + default: + return; + } + + if (heldItem != ITEM_NONE) + { + const u32 *tiles = GetItemIconPic(heldItem); + const u32 *pal = GetItemIconPalette(heldItem); + u8 id = GetNewItemIconIdx(); + + SetItemIconPosition(id, cursorArea, cursorPos); + LoadItemIconGfx(id, tiles, pal); + SetItemIconAffineAnim(id, ITEM_ANIM_APPEAR); + SetItemIconActive(id, TRUE); + } +} + +void TryHideItemIconAtPos(u8 cursorArea, u8 cursorPos) +{ + u8 id; + + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + return; + + id = GetItemIconIdxByPosition(cursorArea, cursorPos); + SetItemIconAffineAnim(id, ITEM_ANIM_DISAPPEAR); + SetItemIconCallback(id, ITEM_CB_WAIT_ANIM, cursorArea, cursorPos); +} + +void Item_FromMonToMoving(u8 cursorArea, u8 cursorPos) +{ + u8 id; + u16 item; + + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + return; + + id = GetItemIconIdxByPosition(cursorArea, cursorPos); + item = 0; + SetItemIconAffineAnim(id, ITEM_ANIM_PICK_UP); + SetItemIconCallback(id, ITEM_CB_TO_HAND, cursorArea, cursorPos); + SetItemIconPosition(id, CURSOR_AREA_IN_HAND, 0); + if (cursorArea == CURSOR_AREA_IN_BOX) + { + SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &item); + SetBoxMonIconObjMode(cursorPos, ST_OAM_OBJ_BLEND); + } + else + { + SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &item); + SetPartyMonIconObjMode(cursorPos, ST_OAM_OBJ_BLEND); + } + + gStorage->movingItemId = gStorage->displayMonItemId; +} + +void InitItemIconInCursor(u16 item) +{ + const u32 *tiles = GetItemIconPic(item); + const u32 *pal = GetItemIconPalette(item); + u8 id = GetNewItemIconIdx(); + + LoadItemIconGfx(id, tiles, pal); + SetItemIconAffineAnim(id, ITEM_ANIM_LARGE); + SetItemIconCallback(id, ITEM_CB_TO_HAND, 0, 0); + SetItemIconPosition(id, CURSOR_AREA_IN_HAND, 0); + SetItemIconActive(id, TRUE); + gStorage->movingItemId = item; +} + +void Item_SwitchMonsWithMoving(u8 cursorArea, u8 cursorPos) +{ + u8 id; + u16 item; + + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + return; + + id = GetItemIconIdxByPosition(cursorArea, cursorPos); + SetItemIconAffineAnim(id, ITEM_ANIM_PICK_UP); + SetItemIconCallback(id, ITEM_CB_SWAP_TO_HAND, CURSOR_AREA_IN_HAND, 0); + if (cursorArea == CURSOR_AREA_IN_BOX) + { + item = GetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM); + SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &gStorage->movingItemId); + gStorage->movingItemId = item; + } + else + { + item = GetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM); + SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &gStorage->movingItemId); + gStorage->movingItemId = item; + } + + id = GetItemIconIdxByPosition(2, 0); + SetItemIconAffineAnim(id, ITEM_ANIM_PUT_DOWN); + SetItemIconCallback(id, ITEM_CB_SWAP_TO_MON, cursorArea, cursorPos); +} + +void Item_GiveMovingToMon(u8 cursorArea, u8 cursorPos) +{ + u8 id; + + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + return; + + id = GetItemIconIdxByPosition(2, 0); + SetItemIconAffineAnim(id, ITEM_ANIM_PUT_DOWN); + SetItemIconCallback(id, ITEM_CB_TO_MON, cursorArea, cursorPos); + if (cursorArea == CURSOR_AREA_IN_BOX) + { + SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &gStorage->movingItemId); + SetBoxMonIconObjMode(cursorPos, ST_OAM_OBJ_NORMAL); + } + else + { + SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &gStorage->movingItemId); + SetPartyMonIconObjMode(cursorPos, ST_OAM_OBJ_NORMAL); + } +} + +void Item_TakeMons(u8 cursorArea, u8 cursorPos) +{ + u8 id; + u16 item; + + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + return; + + item = ITEM_NONE; + id = GetItemIconIdxByPosition(cursorArea, cursorPos); + SetItemIconAffineAnim(id, ITEM_ANIM_DISAPPEAR); + SetItemIconCallback(id, ITEM_CB_WAIT_ANIM, cursorArea, cursorPos); + if (cursorArea == CURSOR_AREA_IN_BOX) + { + SetCurrentBoxMonData(cursorPos, MON_DATA_HELD_ITEM, &item); + SetBoxMonIconObjMode(cursorPos, ST_OAM_OBJ_BLEND); + } + else + { + SetMonData(&gPlayerParty[cursorPos], MON_DATA_HELD_ITEM, &item); + SetPartyMonIconObjMode(cursorPos, ST_OAM_OBJ_BLEND); + } +} + +void MoveItemFromCursorToBag(void) +{ + if (gStorage->boxOption == OPTION_MOVE_ITEMS) + { + u8 id = GetItemIconIdxByPosition(CURSOR_AREA_IN_HAND, 0); + SetItemIconAffineAnim(id, ITEM_ANIM_PUT_AWAY); + SetItemIconCallback(id, ITEM_CB_WAIT_ANIM, 2, 0); + } +} + +// The party menu is being closed, if the cursor is on +// a Pokémon that has a held item make sure it slides +// up along with the closing menu. +void MoveHeldItemWithPartyMenu(void) +{ + s32 i; + + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + return; + + for (i = 0; i < MAX_ITEM_ICONS; i++) + { + if (gStorage->itemIcons[i].active && gStorage->itemIcons[i].cursorArea == CURSOR_AREA_IN_PARTY) + SetItemIconCallback(i, ITEM_CB_HIDE_PARTY, 2, 0); + } +} + +bool8 IsItemIconAnimActive(void) +{ + s32 i; + + for (i = 0; i < MAX_ITEM_ICONS; i++) + { + if (gStorage->itemIcons[i].active) + { + if (!gStorage->itemIcons[i].sprite->affineAnimEnded && gStorage->itemIcons[i].sprite->affineAnimBeginning) + return TRUE; + if (gStorage->itemIcons[i].sprite->callback != SpriteCallbackDummy && gStorage->itemIcons[i].sprite->callback != SpriteCB_ItemIcon_SetPosToCursor) + return TRUE; + } + } + + return FALSE; +} + +bool8 IsActiveItemMoving(void) +{ + s32 i; + + if (gStorage->boxOption == OPTION_MOVE_ITEMS) + { + for (i = 0; i < MAX_ITEM_ICONS; i++) + { + if (gStorage->itemIcons[i].active && gStorage->itemIcons[i].cursorArea == CURSOR_AREA_BOX_TITLE) + return TRUE; + } + } + + return FALSE; +} + +const u8 *GetMovingItemName(void) +{ + return ItemId_GetName(gStorage->movingItemId); +} + +u16 GetMovingItem(void) +{ + return gStorage->movingItemId; +} + +static u8 GetNewItemIconIdx(void) +{ + u8 i; + + for (i = 0; i < MAX_ITEM_ICONS; i++) + { + if (!gStorage->itemIcons[i].active) + { + gStorage->itemIcons[i].active = TRUE; + return i; + } + } + + return MAX_ITEM_ICONS; +} + +static bool32 IsItemIconAtPosition(u8 cursorArea, u8 cursorPos) +{ + s32 i; + + for (i = 0; i < MAX_ITEM_ICONS; i++) + { + if (gStorage->itemIcons[i].active + && gStorage->itemIcons[i].cursorArea == cursorArea + && gStorage->itemIcons[i].cursorPos == cursorPos) + return TRUE; + } + + return FALSE; +} + +static u8 GetItemIconIdxByPosition(u8 cursorArea, u8 cursorPos) +{ + u8 i; + + for (i = 0; i < MAX_ITEM_ICONS; i++) + { + if (gStorage->itemIcons[i].active + && gStorage->itemIcons[i].cursorArea == cursorArea + && gStorage->itemIcons[i].cursorPos == cursorPos) + return i; + } + + return MAX_ITEM_ICONS; +} + +static u8 GetItemIconIdxBySprite(struct Sprite *sprite) +{ + u8 i; + + for (i = 0; i < MAX_ITEM_ICONS; i++) + { + if (gStorage->itemIcons[i].active + && gStorage->itemIcons[i].sprite == sprite) + return i; + } + + return MAX_ITEM_ICONS; +} + +static void SetItemIconPosition(u8 id, u8 cursorArea, u8 cursorPos) +{ + u8 row, column; + + if (id >= MAX_ITEM_ICONS) + return; + + switch (cursorArea) + { + case CURSOR_AREA_IN_BOX: + row = cursorPos % IN_BOX_COLUMNS; + column = cursorPos / IN_BOX_COLUMNS; + gStorage->itemIcons[id].sprite->x = (24 * row) + 112; + gStorage->itemIcons[id].sprite->y = (24 * column) + 56; + gStorage->itemIcons[id].sprite->oam.priority = 2; + break; + case CURSOR_AREA_IN_PARTY: + if (cursorPos == 0) + { + gStorage->itemIcons[id].sprite->x = 116; + gStorage->itemIcons[id].sprite->y = 76; + } + else + { + gStorage->itemIcons[id].sprite->x = 164; + gStorage->itemIcons[id].sprite->y = 24 * (cursorPos - 1) + 28; + } + gStorage->itemIcons[id].sprite->oam.priority = 1; + break; + } + + gStorage->itemIcons[id].cursorArea = cursorArea; + gStorage->itemIcons[id].cursorPos = cursorPos; +} + +static void LoadItemIconGfx(u8 id, const u32 *itemTiles, const u32 *itemPal) +{ + s32 i; + + if (id >= MAX_ITEM_ICONS) + return; + + CpuFastFill(0, gStorage->itemIconBuffer, 0x200); + LZ77UnCompWram(itemTiles, gStorage->tileBuffer); + for (i = 0; i < 3; i++) + CpuFastCopy(gStorage->tileBuffer + (i * 0x60), gStorage->itemIconBuffer + (i * 0x80), 0x60); + + CpuFastCopy(gStorage->itemIconBuffer, gStorage->itemIcons[id].tiles, 0x200); + LZ77UnCompWram(itemPal, gStorage->itemIconBuffer); + LoadPalette(gStorage->itemIconBuffer, gStorage->itemIcons[id].palIndex, 0x20); +} + +static void SetItemIconAffineAnim(u8 id, u8 animNum) +{ + if (id >= MAX_ITEM_ICONS) + return; + + StartSpriteAffineAnim(gStorage->itemIcons[id].sprite, animNum); +} + +#define sItemIconId data[0] +#define sState data[0] +#define sCursorArea data[6] +#define sCursorPos data[7] + +static void SetItemIconCallback(u8 id, u8 callbackId, u8 cursorArea, u8 cursorPos) +{ + if (id >= MAX_ITEM_ICONS) + return; + + switch (callbackId) + { + case ITEM_CB_WAIT_ANIM: + gStorage->itemIcons[id].sprite->sItemIconId = id; + gStorage->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_WaitAnim; + break; + case ITEM_CB_TO_HAND: + gStorage->itemIcons[id].sprite->sState = 0; + gStorage->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_ToHand; + break; + case ITEM_CB_TO_MON: + gStorage->itemIcons[id].sprite->sState = 0; + gStorage->itemIcons[id].sprite->sCursorArea = cursorArea; + gStorage->itemIcons[id].sprite->sCursorPos = cursorPos; + gStorage->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_ToMon; + break; + case ITEM_CB_SWAP_TO_HAND: + gStorage->itemIcons[id].sprite->sState = 0; + gStorage->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_SwapToHand; + gStorage->itemIcons[id].sprite->sCursorArea = cursorArea; + gStorage->itemIcons[id].sprite->sCursorPos = cursorPos; + break; + case ITEM_CB_SWAP_TO_MON: + gStorage->itemIcons[id].sprite->sState = 0; + gStorage->itemIcons[id].sprite->sCursorArea = cursorArea; + gStorage->itemIcons[id].sprite->sCursorPos = cursorPos; + gStorage->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_SwapToMon; + break; + case ITEM_CB_HIDE_PARTY: + // If cursor is on a Pokémon with a held item and + // the player closes the party menu, have the held + // item follow the Pokémon as the menu slides out + gStorage->itemIcons[id].sprite->callback = SpriteCB_ItemIcon_HideParty; + break; + } +} + +static void SetItemIconActive(u8 id, bool8 show) +{ + if (id >= MAX_ITEM_ICONS) + return; + + gStorage->itemIcons[id].active = show; + gStorage->itemIcons[id].sprite->invisible = (show == FALSE); +} + +static const u32 *GetItemIconPic(u16 itemId) +{ + return GetItemIconGfxPtr(itemId, 0); +} + +static const u32 *GetItemIconPalette(u16 itemId) +{ + return GetItemIconGfxPtr(itemId, 1); +} + +void PrintItemDescription(void) +{ + const u8 *description; + + if (IsActiveItemMoving()) + description = ItemId_GetDescription(gStorage->movingItemId); + else + description = ItemId_GetDescription(gStorage->displayMonItemId); + + FillWindowPixelBuffer(2, PIXEL_FILL(1)); + AddTextPrinterParameterized5(2, FONT_2, description, 2, 0, 0, NULL, 0, 0); +} + +void InitItemInfoWindow(void) +{ + gStorage->itemInfoWindowOffset = 25; + LoadBgTiles(0, sItemInfoFrame_Gfx, 0x80, 0x1A4); + DrawItemInfoWindow(0); +} + +bool8 UpdateItemInfoWindowSlideIn(void) +{ + s32 i, pos; + + if (gStorage->itemInfoWindowOffset == 0) + return FALSE; + + gStorage->itemInfoWindowOffset--; + pos = 25 - gStorage->itemInfoWindowOffset; + for (i = 0; i < pos; i++) + WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + gStorage->itemInfoWindowOffset + i, i, 12, 1, 8, 15, 25); + + DrawItemInfoWindow(pos); + return (gStorage->itemInfoWindowOffset != 0); +} + +bool8 UpdateItemInfoWindowSlideOut(void) +{ + s32 i, pos; + + if (gStorage->itemInfoWindowOffset == 25) + return FALSE; + + if (gStorage->itemInfoWindowOffset == 0) + FillBgTilemapBufferRect(0, 0, 25, 11, 1, 10, 17); + + gStorage->itemInfoWindowOffset++; + pos = 25 - gStorage->itemInfoWindowOffset; + for (i = 0; i < pos; i++) + WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + gStorage->itemInfoWindowOffset + i, i, 12, 1, 8, 15, 25); + + DrawItemInfoWindow(pos); + + FillBgTilemapBufferRect(0, 0, pos, 11, 1, 10, 17); + return (gStorage->itemInfoWindowOffset != 25); +} + +static void DrawItemInfoWindow(u32 x) +{ + if (x != 0) + { + FillBgTilemapBufferRect(0, 0x1A4, 0, 0xB, x, 1, 15); + FillBgTilemapBufferRect(0, 0x9A4, 0, 0x14, x, 1, 15); + } + FillBgTilemapBufferRect(0, 0x1A5, x, 0xC, 1, 8, 15); + FillBgTilemapBufferRect(0, 0x1A6, x, 0xB, 1, 1, 15); + FillBgTilemapBufferRect(0, 0x1A7, x, 0x14, 1, 1, 15); + ScheduleBgCopyTilemapToVram(0); +} + +static void SpriteCB_ItemIcon_WaitAnim(struct Sprite *sprite) +{ + if (sprite->affineAnimEnded) + { + SetItemIconActive(sprite->sItemIconId, FALSE); + sprite->callback = SpriteCallbackDummy; + } +} + +static void SpriteCB_ItemIcon_ToHand(struct Sprite *sprite) +{ + switch (sprite->sState) + { + case 0: + sprite->data[1] = sprite->x << 4; + sprite->data[2] = sprite->y << 4; + sprite->data[3] = 10; + sprite->data[4] = 21; + sprite->data[5] = 0; + sprite->sState++; + case 1: + sprite->data[1] -= sprite->data[3]; + sprite->data[2] -= sprite->data[4]; + sprite->x = sprite->data[1] >> 4; + sprite->y = sprite->data[2] >> 4; + if (++sprite->data[5] > 11) + sprite->callback = SpriteCB_ItemIcon_SetPosToCursor; + break; + } +} + +static void SpriteCB_ItemIcon_SetPosToCursor(struct Sprite *sprite) +{ + sprite->x = gStorage->cursorSprite->x + 4; + sprite->y = gStorage->cursorSprite->y + gStorage->cursorSprite->y2 + 8; + sprite->oam.priority = gStorage->cursorSprite->oam.priority; +} + +static void SpriteCB_ItemIcon_ToMon(struct Sprite *sprite) +{ + switch (sprite->sState) + { + case 0: + sprite->data[1] = sprite->x << 4; + sprite->data[2] = sprite->y << 4; + sprite->data[3] = 10; + sprite->data[4] = 21; + sprite->data[5] = 0; + sprite->sState++; + case 1: + sprite->data[1] += sprite->data[3]; + sprite->data[2] += sprite->data[4]; + sprite->x = sprite->data[1] >> 4; + sprite->y = sprite->data[2] >> 4; + if (++sprite->data[5] > 11) + { + SetItemIconPosition(GetItemIconIdxBySprite(sprite), sprite->sCursorArea, sprite->sCursorPos); + sprite->callback = SpriteCallbackDummy; + } + break; + } +} + +static void SpriteCB_ItemIcon_SwapToHand(struct Sprite *sprite) +{ + switch (sprite->sState) + { + case 0: + sprite->data[1] = sprite->x << 4; + sprite->data[2] = sprite->y << 4; + sprite->data[3] = 10; + sprite->data[4] = 21; + sprite->data[5] = 0; + sprite->sState++; + case 1: + sprite->data[1] -= sprite->data[3]; + sprite->data[2] -= sprite->data[4]; + sprite->x = sprite->data[1] >> 4; + sprite->y = sprite->data[2] >> 4; + sprite->x2 = gSineTable[sprite->data[5] * 8] >> 4; + if (++sprite->data[5] > 11) + { + SetItemIconPosition(GetItemIconIdxBySprite(sprite), sprite->sCursorArea, sprite->sCursorPos); + sprite->x2 = 0; + sprite->callback = SpriteCB_ItemIcon_SetPosToCursor; + } + break; + } +} + +static void SpriteCB_ItemIcon_SwapToMon(struct Sprite *sprite) +{ + switch (sprite->sState) + { + case 0: + sprite->data[1] = sprite->x << 4; + sprite->data[2] = sprite->y << 4; + sprite->data[3] = 10; + sprite->data[4] = 21; + sprite->data[5] = 0; + sprite->sState++; + case 1: + sprite->data[1] += sprite->data[3]; + sprite->data[2] += sprite->data[4]; + sprite->x = sprite->data[1] >> 4; + sprite->y = sprite->data[2] >> 4; + sprite->x2 = -(gSineTable[sprite->data[5] * 8] >> 4); + if (++sprite->data[5] > 11) + { + SetItemIconPosition(GetItemIconIdxBySprite(sprite), sprite->sCursorArea, sprite->sCursorPos); + sprite->callback = SpriteCallbackDummy; + sprite->x2 = 0; + } + break; + } +} + +static void SpriteCB_ItemIcon_HideParty(struct Sprite *sprite) +{ + sprite->y -= 8; + if (sprite->y + sprite->y2 < -16) + { + sprite->callback = SpriteCallbackDummy; + SetItemIconActive(GetItemIconIdxBySprite(sprite), FALSE); + } +} + +#undef sState +#undef sItemIconId +#undef sCursorArea +#undef sCursorPos + +// Some data transfer utility that goes functionally unused. +// It gets initialized with UnkUtil_Init, and run every vblank in Pokémon +// Storage with UnkUtil_Run, but neither of the Add functions are ever used, +// so UnkUtil_Run performs no actions. + +static EWRAM_DATA struct UnkUtil *sUnkUtil = NULL; + +static void UnkUtil_CpuRun(struct UnkUtilData *unkStruct); +static void UnkUtil_DmaRun(struct UnkUtilData *unkStruct); + +void UnkUtil_Init(struct UnkUtil *util, struct UnkUtilData *data, u32 max) +{ + sUnkUtil = util; + util->data = data; + util->max = max; + util->numActive = 0; +} + +void UnkUtil_Run(void) +{ + u16 i; + if (sUnkUtil->numActive) + { + for (i = 0; i < sUnkUtil->numActive; i++) + { + struct UnkUtilData *data = &sUnkUtil->data[i]; + data->func(data); + } + sUnkUtil->numActive = 0; + } +} + +// Unused +static bool8 UnkUtil_CpuAdd(u8 *dest, u16 dLeft, u16 dTop, const u8 *src, u16 sLeft, u16 sTop, u16 width, u16 height, u16 unkArg) +{ + struct UnkUtilData *data; + + if (sUnkUtil->numActive >= sUnkUtil->max) + return FALSE; + + data = &sUnkUtil->data[sUnkUtil->numActive++]; + data->size = width * 2; + data->dest = dest + 2 * (dTop * 32 + dLeft); + data->src = src + 2 * (sTop * unkArg + sLeft); + data->height = height; + data->unk = unkArg; + data->func = UnkUtil_CpuRun; + return TRUE; +} + +// Functionally unused +static void UnkUtil_CpuRun(struct UnkUtilData *data) +{ + u16 i; + + for (i = 0; i < data->height; i++) + { + CpuCopy16(data->src, data->dest, data->size); + data->dest += 64; + data->src += (data->unk * 2); + } +} + +// Unused +static bool8 UnkUtil_DmaAdd(void *dest, u16 dLeft, u16 dTop, u16 width, u16 height) +{ + struct UnkUtilData *data; + + if (sUnkUtil->numActive >= sUnkUtil->max) + return FALSE; + + data = &sUnkUtil->data[sUnkUtil->numActive++]; + data->size = width * 2; + data->dest = dest + ((dTop * 32) + dLeft) * 2; + data->height = height; + data->func = UnkUtil_DmaRun; + return TRUE; +} + +// Functionally unused +static void UnkUtil_DmaRun(struct UnkUtilData *data) +{ + u16 i; + + for (i = 0; i < data->height; i++) + { + Dma3FillLarge_(0, data->dest, data->size, 16); + data->dest += 64; + } +} diff --git a/src/pokemon_storage_system_tasks.c b/src/pokemon_storage_system_tasks.c new file mode 100644 index 000000000..bad54118e --- /dev/null +++ b/src/pokemon_storage_system_tasks.c @@ -0,0 +1,2770 @@ +#include "global.h" +#include "gflib.h" +#include "data.h" +#include "decompress.h" +#include "dynamic_placeholder_text_util.h" +#include "event_data.h" +#include "graphics.h" +#include "help_system.h" +#include "item.h" +#include "item_menu.h" +#include "mail_data.h" +#include "menu.h" +#include "naming_screen.h" +#include "new_menu_helpers.h" +#include "pc_screen_effect.h" +#include "pokemon_icon.h" +#include "pokemon_storage_system_internal.h" +#include "pokemon_summary_screen.h" +#include "quest_log.h" +#include "strings.h" +#include "task.h" +#include "text_window.h" +#include "tilemap_util.h" +#include "trig.h" +#include "constants/items.h" +#include "constants/help_system.h" +#include "constants/songs.h" + +EWRAM_DATA struct PokemonStorageSystemData *gStorage = NULL; +static EWRAM_DATA bool8 sInPartyMenu = 0; +static EWRAM_DATA u8 sCurrentBoxOption = 0; +static EWRAM_DATA u8 sDepositBoxId = 0; +static EWRAM_DATA u8 sWhichToReshow = 0; +static EWRAM_DATA u8 sLastUsedBox = 0; +static EWRAM_DATA u16 sMovingItemId = ITEM_NONE; + +static void Task_InitPokeStorage(u8 taskId); +static void Task_ShowPokeStorage(u8 taskId); +static void Task_ReshowPokeStorage(u8 taskId); +static void Task_PokeStorageMain(u8 taskId); +static void Task_ShowPartyPokemon(u8 taskId); +static void Task_HidePartyPokemon(u8 taskId); +static void Task_OnSelectedMon(u8 taskId); +static void Task_MoveMon(u8 taskId); +static void Task_PlaceMon(u8 taskId); +static void Task_ShiftMon(u8 taskId); +static void Task_WithdrawMon(u8 taskId); +static void Task_DepositMenu(u8 taskId); +static void Task_ReleaseMon(u8 taskId); +static void Task_ShowMarkMenu(u8 taskId); +static void Task_TakeItemForMoving(u8 taskId); +static void Task_GiveMovingItemToMon(u8 taskId); +static void Task_ItemToBag(u8 taskId); +static void Task_SwitchSelectedItem(u8 taskId); +static void Task_ShowItemInfo(u8 taskId); +static void Task_HandleMovingMonFromParty(u8 taskId); +static void Task_PrintCantStoreMail(u8 taskId); +static void Task_HandleBoxOptions(u8 taskId); +static void Task_HandleWallpapers(u8 taskId); +static void Task_JumpBox(u8 taskId); +static void Task_NameBox(u8 taskId); +static void Task_ShowMonSummary(u8 taskId); +static void Task_GiveItemFromBag(u8 taskId); +static void Task_OnCloseBoxPressed(u8 taskId); +static void Task_OnBPressed(u8 taskId); +static void Task_ChangeScreen(u8 taskId); +static void GiveChosenBagItem(void); +static void FreePokeStorageData(void); +static void SetScrollingBackground(void); +static void ScrollBackground(void); +static void LoadPokeStorageMenuGfx(void); +static bool8 InitPokeStorageWindows(void); +static void LoadsMiscSpritePalette(void); +static void InitPalettesAndSprites(void); +static void CreateMarkingComboSprite(void); +static void CreateWaveformSprites(void); +static void RefreshDisplayMonData(void); +static void StartDisplayMonMosaic(void); +static void SpriteCB_DisplayMonMosaic(struct Sprite *sprite); +static bool8 IsDisplayMonMosaicActive(void); +static void CreateDisplayMonSprite(void); +static void LoadDisplayMonGfx(u16 species, u32 personality); +static void PrintDisplayMonInfo(void); +static void UpdateWaveformAnimation(void); +static void InitSupplementalTilemaps(void); +static void SetUpHidePartyMenu(void); +static bool8 HidePartyMenu(void); +static void UpdateCloseBoxButtonTilemap(bool8 normal); +static void StartFlashingCloseBoxButton(void); +static void StopFlashingCloseBoxButton(void); +static void UpdateCloseBoxButtonFlash(void); +static void SetPartySlotTilemaps(void); +static void SetPartySlotTilemap(u8 pos, bool8 isPartyMon); +static void UpdatePartySlotColors(void); +static void SetUpDoShowPartyMenu(void); +static bool8 DoShowPartyMenu(void); +static void InitPokeStorageBg0(void); +static void PrintStorageMessage(u8 textId); +static void ShowYesNoWindow(s8 cursorPos); +static void ClearBottomWindow(void); +static void AddWallpaperSetsMenu(void); +static void AddWallpapersMenu(u8 wallpaperSet); +static void InitCursorItemIcon(void); +static void SetPokeStorageQuestLogEvent(u8 species); +static void UpdateBoxToSendMons(void); + +enum { + TILEMAP_PKMN_DATA, // The "Pkmn Data" text at the top of the display + TILEMAP_PARTY_MENU, + TILEMAP_CLOSE_BUTTON, + TILEMAP_COUNT +}; + +enum +{ + SCREEN_CHANGE_EXIT_BOX, + SCREEN_CHANGE_SUMMARY_SCREEN, + SCREEN_CHANGE_NAME_BOX, + SCREEN_CHANGE_ITEM_FROM_BAG, +}; + +enum +{ + MSG_EXIT_BOX, + MSG_WHAT_YOU_DO, + MSG_PICK_A_THEME, + MSG_PICK_A_WALLPAPER, + MSG_IS_SELECTED, + MSG_JUMP_TO_WHICH_BOX, + MSG_DEPOSIT_IN_WHICH_BOX, + MSG_WAS_DEPOSITED, + MSG_BOX_IS_FULL, + MSG_RELEASE_POKE, + MSG_WAS_RELEASED, + MSG_BYE_BYE, + MSG_MARK_POKE, + MSG_LAST_POKE, + MSG_PARTY_FULL, + MSG_HOLDING_POKE, + MSG_WHICH_ONE_WILL_TAKE, + MSG_CANT_RELEASE_EGG, + MSG_CONTINUE_BOX, + MSG_CAME_BACK, + MSG_WORRIED, + MSG_SURPRISE, + MSG_PLEASE_REMOVE_MAIL, + MSG_IS_SELECTED2, + MSG_GIVE_TO_MON, + MSG_PLACED_IN_BAG, + MSG_BAG_FULL, + MSG_PUT_IN_BAG, + MSG_ITEM_IS_HELD, + MSG_CHANGED_TO_ITEM, + MSG_CANT_STORE_MAIL, +}; + +enum +{ + MSG_FMT_NONE, + MSG_FMT_MON_NAME_1, + MSG_FMT_MON_NAME_2, + MSG_FMT_MON_NAME_3, + MSG_FMT_RELEASE_MON_1, + MSG_FMT_RELEASE_MON_2, + MSG_FMT_RELEASE_MON_3, + MSG_FMT_ITEM_NAME, +}; + +static const u32 sScrollingBg_Gfx[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.4bpp.lz"); +static const u32 sScrollingBg_Tilemap[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.bin.lz"); + +// Unused +static const u16 sMenu_Pal[] = INCBIN_U16("graphics/pokemon_storage/menu.gbapal"); + +static const u32 sMenu_Tilemap[] = INCBIN_U32("graphics/pokemon_storage/menu.bin.lz"); +static const u16 sPkmnData_Tilemap[] = INCBIN_U16("graphics/pokemon_storage/pkmn_data.bin"); +static const u16 sScrollingBg_Pal[] = INCBIN_U16("graphics/pokemon_storage/scrolling_bg.gbapal"); +static const u16 sScrollingBgMoveItems_Pal[] = INCBIN_U16("graphics/pokemon_storage/scrolling_bg_move_items.gbapal"); +static const u16 sCloseBoxButton_Tilemap[] = INCBIN_U16("graphics/pokemon_storage/close_box_button.bin"); +static const u16 sPartySlotFilled_Tilemap[] = INCBIN_U16("graphics/pokemon_storage/party_slot_filled.bin"); +static const u16 sPartySlotEmpty_Tilemap[] = INCBIN_U16("graphics/pokemon_storage/party_slot_empty.bin"); +static const u16 sPokeStorageMisc2Pal[] = INCBIN_U16("graphics/pokemon_storage/misc2.gbapal"); +static const u16 sWaveform_Gfx[] = INCBIN_U16("graphics/pokemon_storage/waveform.4bpp"); + +// Unused +static const u16 sUnused_Pal[] = INCBIN_U16("graphics/pokemon_storage/unused.gbapal"); + +static const u16 sItemInfoFrame_Pal[] = INCBIN_U16("graphics/pokemon_storage/item_info_frame.gbapal"); + +static const struct WindowTemplate sWindowTemplates[] = { + { + .bg = 1, + .tilemapLeft = 0, + .tilemapTop = 11, + .width = 9, + .height = 7, + .paletteNum = 3, + .baseBlock = 0x0c0 + }, { + .bg = 0, + .tilemapLeft = 11, + .tilemapTop = 17, + .width = 18, + .height = 2, + .paletteNum = 13, + .baseBlock = 0x014 + }, { + .bg = 0, + .tilemapLeft = 0, + .tilemapTop = 12, + .width = 25, + .height = 8, + .paletteNum = 15, + .baseBlock = 0x014 + }, + DUMMY_WIN_TEMPLATE +}; + +static const struct BgTemplate sBgTemplates[] = { + { + .bg = 0, + .charBaseIndex = 0, + .mapBaseIndex = 29, + .screenSize = 0, + .paletteMode = 0, + .priority = 0, + .baseTile = 0x000 + }, { + .bg = 1, + .charBaseIndex = 1, + .mapBaseIndex = 30, + .screenSize = 0, + .paletteMode = 0, + .priority = 1, + .baseTile = 0x100 + }, { + .bg = 2, + .charBaseIndex = 2, + .mapBaseIndex = 27, + .screenSize = 1, + .paletteMode = 0, + .priority = 2, + .baseTile = 0x000 + }, { + .bg = 3, + .charBaseIndex = 3, + .mapBaseIndex = 31, + .screenSize = 0, + .paletteMode = 0, + .priority = 3, + .baseTile = 0x000 + } +}; + +static const struct SpritePalette sMiscSpritePalette = { + sPokeStorageMisc2Pal, PALTAG_MISC_2 +}; + +static const struct SpriteSheet sWaveformSpriteSheet = { + sWaveform_Gfx, 0x01C0, GFXTAG_WAVEFORM +}; + +static const struct OamData sOamData_DisplayMon; + +static const struct SpriteTemplate sSpriteTemplate_DisplayMon = { + .tileTag = GFXTAG_DISPLAY_MON, + .paletteTag = PALTAG_DISPLAY_MON, + .oam = &sOamData_DisplayMon, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy +}; + +static const struct StorageMessage sMessages[] = { + [MSG_EXIT_BOX] = {gText_ExitFromBox, MSG_FMT_NONE}, + [MSG_WHAT_YOU_DO] = {gText_WhatDoYouWantToDo, MSG_FMT_NONE}, + [MSG_PICK_A_THEME] = {gText_PleasePickATheme, MSG_FMT_NONE}, + [MSG_PICK_A_WALLPAPER] = {gText_PickTheWallpaper, MSG_FMT_NONE}, + [MSG_IS_SELECTED] = {gText_PkmnIsSelected, MSG_FMT_MON_NAME_1}, + [MSG_JUMP_TO_WHICH_BOX] = {gText_JumpToWhichBox, MSG_FMT_NONE}, + [MSG_DEPOSIT_IN_WHICH_BOX] = {gText_DepositInWhichBox, MSG_FMT_NONE}, + [MSG_WAS_DEPOSITED] = {gText_PkmnWasDeposited, MSG_FMT_MON_NAME_1}, + [MSG_BOX_IS_FULL] = {gText_BoxIsFull2, MSG_FMT_NONE}, + [MSG_RELEASE_POKE] = {gText_ReleaseThisPokemon, MSG_FMT_NONE}, + [MSG_WAS_RELEASED] = {gText_PkmnWasReleased, MSG_FMT_RELEASE_MON_1}, + [MSG_BYE_BYE] = {gText_ByeByePkmn, MSG_FMT_RELEASE_MON_3}, + [MSG_MARK_POKE] = {gText_MarkYourPkmn, MSG_FMT_NONE}, + [MSG_LAST_POKE] = {gText_ThatsYourLastPkmn, MSG_FMT_NONE}, + [MSG_PARTY_FULL] = {gText_YourPartysFull, MSG_FMT_NONE}, + [MSG_HOLDING_POKE] = {gText_YoureHoldingAPkmn, MSG_FMT_NONE}, + [MSG_WHICH_ONE_WILL_TAKE] = {gText_WhichOneWillYouTake, MSG_FMT_NONE}, + [MSG_CANT_RELEASE_EGG] = {gText_YouCantReleaseAnEgg, MSG_FMT_NONE}, + [MSG_CONTINUE_BOX] = {gText_ContinueBoxOperations, MSG_FMT_NONE}, + [MSG_CAME_BACK] = {gText_PkmnCameBack, MSG_FMT_MON_NAME_1}, + [MSG_WORRIED] = {gText_WasItWorriedAboutYou, MSG_FMT_NONE}, + [MSG_SURPRISE] = {gText_FourEllipsesExclamation, MSG_FMT_NONE}, + [MSG_PLEASE_REMOVE_MAIL] = {gText_PleaseRemoveTheMail, MSG_FMT_NONE}, + [MSG_IS_SELECTED2] = {gText_PkmnIsSelected, MSG_FMT_ITEM_NAME}, + [MSG_GIVE_TO_MON] = {gText_GiveToAPkmn, MSG_FMT_NONE}, + [MSG_PLACED_IN_BAG] = {gText_PlacedItemInBag, MSG_FMT_ITEM_NAME}, + [MSG_BAG_FULL] = {gText_BagIsFull2, MSG_FMT_NONE}, + [MSG_PUT_IN_BAG] = {gText_PutItemInBag, MSG_FMT_NONE}, + [MSG_ITEM_IS_HELD] = {gText_ItemIsNowHeld, MSG_FMT_ITEM_NAME}, + [MSG_CHANGED_TO_ITEM] = {gText_ChangedToNewItem, MSG_FMT_ITEM_NAME}, + [MSG_CANT_STORE_MAIL] = {gText_MailCantBeStored, MSG_FMT_NONE}, +}; + +static const struct WindowTemplate sYesNoWindowTemplate = { + .bg = 0, + .tilemapLeft = 24, + .tilemapTop = 11, + .width = 5, + .height = 4, + .paletteNum = 15, + .baseBlock = 0x05c +}; + +static const struct OamData sOamData_DisplayMon = { + .y = 0, + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = SPRITE_SHAPE(64x64), + .x = 0, + .matrixNum = 0, + .size = SPRITE_SIZE(64x64), + .tileNum = 0x000, + .priority = 0, + .paletteNum = 0 +}; + +// Waveform + +static const struct OamData sOamData_Waveform = { + .y = 0, + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = SPRITE_SHAPE(16x8), + .x = 0, + .matrixNum = 0, + .size = SPRITE_SIZE(16x8), + .tileNum = 0x000, + .priority = 0, + .paletteNum = 0 +}; + +static const union AnimCmd sAnim_Waveform_LeftOff[] = { + ANIMCMD_FRAME(0, 5), + ANIMCMD_END +}; + +static const union AnimCmd sAnim_Waveform_LeftOn[] = { + ANIMCMD_FRAME(2, 8), + ANIMCMD_FRAME(4, 8), + ANIMCMD_FRAME(6, 8), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd sAnim_Waveform_RightOff[] = { + ANIMCMD_FRAME(8, 5), + ANIMCMD_END +}; + +static const union AnimCmd sAnim_Waveform_RightOn[] = { + ANIMCMD_FRAME(10, 8), + ANIMCMD_FRAME(4, 8), + ANIMCMD_FRAME(12, 8), + ANIMCMD_JUMP(0) +}; + +static const union AnimCmd *const sAnims_Waveform[] = { + sAnim_Waveform_LeftOff, + sAnim_Waveform_LeftOn, + sAnim_Waveform_RightOff, + sAnim_Waveform_RightOn +}; + +static const struct SpriteTemplate sSpriteTemplate_Waveform = { + .tileTag = GFXTAG_WAVEFORM, + .paletteTag = PALTAG_MISC_2, + .oam = &sOamData_Waveform, + .anims = sAnims_Waveform, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy, +}; + +static void VBlankCB_PokeStorage(void) +{ + LoadOam(); + ProcessSpriteCopyRequests(); + UnkUtil_Run(); + TransferPlttBuffer(); + SetGpuReg(REG_OFFSET_BG2HOFS, gStorage->bg2_X); +} + +static void CB2_PokeStorage(void) +{ + RunTasks(); + DoScheduledBgTilemapCopiesToVram(); + ScrollBackground(); + UpdateCloseBoxButtonFlash(); + AnimateSprites(); + BuildOamBuffer(); +} + +void EnterPokeStorage(u8 boxOption) +{ + ResetTasks(); + sCurrentBoxOption = boxOption; + gStorage = Alloc(sizeof(struct PokemonStorageSystemData)); + if (gStorage == NULL) + SetMainCallback2(CB2_ExitPokeStorage); + else + { + gStorage->boxOption = boxOption; + gStorage->isReopening = FALSE; + sMovingItemId = 0; + gStorage->state = 0; + gStorage->taskId = CreateTask(Task_InitPokeStorage, 3); + SetHelpContext(HELPCONTEXT_BILLS_PC); + sLastUsedBox = StorageGetCurrentBox(); + SetMainCallback2(CB2_PokeStorage); + } +} + +void CB2_ReturnToPokeStorage(void) +{ + ResetTasks(); + gStorage = Alloc(sizeof(struct PokemonStorageSystemData)); + if (gStorage == NULL) + SetMainCallback2(CB2_ExitPokeStorage); + else + { + gStorage->boxOption = sCurrentBoxOption; + gStorage->isReopening = TRUE; + gStorage->state = 0; + gStorage->taskId = CreateTask(Task_InitPokeStorage, 3); + SetHelpContext(HELPCONTEXT_BILLS_PC); + SetMainCallback2(CB2_PokeStorage); + } +} + +static void ResetAllBgCoords(void) +{ + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + SetGpuReg(REG_OFFSET_BG1HOFS, 0); + SetGpuReg(REG_OFFSET_BG1VOFS, 0); + SetGpuReg(REG_OFFSET_BG2HOFS, 0); + SetGpuReg(REG_OFFSET_BG2VOFS, 0); + SetGpuReg(REG_OFFSET_BG3HOFS, 0); + SetGpuReg(REG_OFFSET_BG3VOFS, 0); +} + +static void ResetForPokeStorage(void) +{ + ResetPaletteFade(); + ResetSpriteData(); + FreeSpriteTileRanges(); + FreeAllSpritePalettes(); + ClearDma3Requests(); + gReservedSpriteTileCount = 0x280; + UnkUtil_Init(&gStorage->unkUtil, gStorage->unkUtilData, ARRAY_COUNT(gStorage->unkUtilData)); + gKeyRepeatStartDelay = 20; + ClearScheduledBgCopiesToVram(); + TilemapUtil_Init(TILEMAP_COUNT); + TilemapUtil_SetTilemap(TILEMAP_PKMN_DATA, 1, sPkmnData_Tilemap, 8, 4); + TilemapUtil_SetPos(TILEMAP_PKMN_DATA, 1, 0); + gStorage->closeBoxFlashing = FALSE; +} + +static void InitStartingPosData(void) +{ + ClearSavedCursorPos(); + sInPartyMenu = gStorage->boxOption == OPTION_DEPOSIT; + sDepositBoxId = 0; +} + +static void SetMonIconTransparency(void) +{ + if (gStorage->boxOption == OPTION_MOVE_ITEMS) + { + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT2_ALL); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(7, 11)); + } + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG_ALL_ON | DISPCNT_OBJ_1D_MAP); +} + +static void SetPokeStorageTask(TaskFunc newFunc) +{ + gTasks[gStorage->taskId].func = newFunc; + gStorage->state = 0; +} + +static void Task_InitPokeStorage(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + SetVBlankCallback(NULL); + SetGpuReg(REG_OFFSET_DISPCNT, 0); + ResetForPokeStorage(); + if (gStorage->isReopening) + { + switch (sWhichToReshow) + { + case SCREEN_CHANGE_NAME_BOX - 1: + LoadSavedMovingMon(); + break; + case SCREEN_CHANGE_SUMMARY_SCREEN - 1: + SetSelectionAfterSummaryScreen(); + break; + case SCREEN_CHANGE_ITEM_FROM_BAG - 1: + GiveChosenBagItem(); + break; + } + } + LoadPokeStorageMenuGfx(); + LoadsMiscSpritePalette(); + break; + case 1: + if (!InitPokeStorageWindows()) + { + SetPokeStorageTask(Task_ChangeScreen); + return; + } + break; + case 2: + PutWindowTilemap(0); + ClearWindowTilemap(1); + CpuFill32(0, (void *)VRAM, 0x200); + TextWindow_SetUserSelectedFrame(1, 0xB, 0xE0); + break; + case 3: + ResetAllBgCoords(); + if (!gStorage->isReopening) + InitStartingPosData(); + break; + case 4: + InitMonIconFields(); + if (!gStorage->isReopening) + InitCursor(); + else + InitCursorOnReopen(); + break; + case 5: + if (!MultiMove_Init()) + { + SetPokeStorageTask(Task_ChangeScreen); + return; + } + else + { + SetScrollingBackground(); + InitPokeStorageBg0(); + } + break; + case 6: + InitPalettesAndSprites(); + break; + case 7: + InitSupplementalTilemaps(); + break; + case 8: + CreateInitBoxTask(StorageGetCurrentBox()); + break; + case 9: + if (IsInitBoxActive()) + return; + + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + { + gStorage->markMenu.baseTileTag = GFXTAG_MARKING_MENU; + gStorage->markMenu.basePaletteTag = PALTAG_MARKING_MENU; + InitMonMarkingsMenu(&gStorage->markMenu); + BufferMonMarkingsMenuTiles(); + } + else + { + CreateItemIconSprites(); + InitCursorItemIcon(); + } + break; + case 10: + SetMonIconTransparency(); + if (!gStorage->isReopening) + { + BlendPalettes(PALETTES_ALL, 16, RGB_BLACK); + SetPokeStorageTask(Task_ShowPokeStorage); + } + else + { + BlendPalettes(PALETTES_ALL, 16, RGB_BLACK); + SetPokeStorageTask(Task_ReshowPokeStorage); + } + SetVBlankCallback(VBlankCB_PokeStorage); + return; + default: + return; + } + + gStorage->state++; +} + +static void Task_ShowPokeStorage(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + PlaySE(SE_PC_LOGIN); + BeginPCScreenEffect_TurnOn(20, 0, 1); + gStorage->state++; + break; + case 1: + if (!IsPCScreenEffectRunning_TurnOn()) + SetPokeStorageTask(Task_PokeStorageMain); + break; + } +} + +static void Task_ReshowPokeStorage(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + BeginNormalPaletteFade(PALETTES_ALL, -1, 0x10, 0, RGB_BLACK); + gStorage->state++; + break; + case 1: + if (!UpdatePaletteFade()) + SetPokeStorageTask(Task_PokeStorageMain); + break; + } +} + +static void Task_PokeStorageMain(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + switch (HandleInput()) + { + case INPUT_MOVE_CURSOR: + PlaySE(SE_SELECT); + gStorage->state = 1; + break; + case INPUT_SHOW_PARTY: + if (gStorage->boxOption != OPTION_MOVE_MONS && gStorage->boxOption != OPTION_MOVE_ITEMS) + { + PrintStorageMessage(MSG_WHICH_ONE_WILL_TAKE); + gStorage->state = 3; + } + else + { + ClearSavedCursorPos(); + SetPokeStorageTask(Task_ShowPartyPokemon); + } + break; + case INPUT_HIDE_PARTY: + if (gStorage->boxOption == OPTION_MOVE_MONS) + { + if (IsMonBeingMoved() && ItemIsMail(gStorage->displayMonItemId)) + gStorage->state = 5; + else + SetPokeStorageTask(Task_HidePartyPokemon); + } + else if (gStorage->boxOption == OPTION_MOVE_ITEMS) + SetPokeStorageTask(Task_HidePartyPokemon); + break; + case INPUT_CLOSE_BOX: + SetPokeStorageTask(Task_OnCloseBoxPressed); + break; + case INPUT_PRESSED_B: + SetPokeStorageTask(Task_OnBPressed); + break; + case INPUT_BOX_OPTIONS: + PlaySE(SE_SELECT); + SetPokeStorageTask(Task_HandleBoxOptions); + break; + case INPUT_IN_MENU: + SetPokeStorageTask(Task_OnSelectedMon); + break; + case INPUT_SCROLL_RIGHT: + PlaySE(SE_SELECT); + gStorage->newCurrBoxId = StorageGetCurrentBox() + 1; + if (gStorage->newCurrBoxId >= TOTAL_BOXES_COUNT) + gStorage->newCurrBoxId = 0; + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + { + SetUpScrollToBox(gStorage->newCurrBoxId); + gStorage->state = 2; + } + else + { + TryHideItemAtCursor(); + gStorage->state = 10; + } + break; + case INPUT_SCROLL_LEFT: + PlaySE(SE_SELECT); + gStorage->newCurrBoxId = StorageGetCurrentBox() - 1; + if (gStorage->newCurrBoxId < 0) + gStorage->newCurrBoxId = TOTAL_BOXES_COUNT - 1; + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + { + SetUpScrollToBox(gStorage->newCurrBoxId); + gStorage->state = 2; + } + else + { + TryHideItemAtCursor(); + gStorage->state = 10; + } + break; + case INPUT_DEPOSIT: + if (!CanMovePartyMon()) + { + if (ItemIsMail(gStorage->displayMonItemId)) + gStorage->state = 5; + else + { + PlaySE(SE_SELECT); + SetPokeStorageTask(Task_DepositMenu); + } + } + else + gStorage->state = 4; + break; + case INPUT_MOVE_MON: + if (CanMovePartyMon()) + gStorage->state = 4; + + else + { + PlaySE(SE_SELECT); + SetPokeStorageTask(Task_MoveMon); + } + break; + case INPUT_SHIFT_MON: + if (!CanShiftMon()) + gStorage->state = 4; + else + { + PlaySE(SE_SELECT); + SetPokeStorageTask(Task_ShiftMon); + } + break; + case INPUT_WITHDRAW: + PlaySE(SE_SELECT); + SetPokeStorageTask(Task_WithdrawMon); + break; + case INPUT_PLACE_MON: + PlaySE(SE_SELECT); + SetPokeStorageTask(Task_PlaceMon); + break; + case INPUT_TAKE_ITEM: + PlaySE(SE_SELECT); + SetPokeStorageTask(Task_TakeItemForMoving); + break; + case INPUT_GIVE_ITEM: + PlaySE(SE_SELECT); + SetPokeStorageTask(Task_GiveMovingItemToMon); + break; + case INPUT_SWITCH_ITEMS: + PlaySE(SE_SELECT); + SetPokeStorageTask(Task_SwitchSelectedItem); + break; + case INPUT_MULTIMOVE_START: + PlaySE(SE_SELECT); + MultiMove_SetFunction(MULTIMOVE_START); + gStorage->state = 7; + break; + case INPUT_MULTIMOVE_SINGLE: + MultiMove_SetFunction(MULTIMOVE_SINGLE); + gStorage->state = 8; + break; + case INPUT_MULTIMOVE_CHANGE_SELECTION: + PlaySE(SE_SELECT); + MultiMove_SetFunction(MULTIMOVE_CHANGE_SELECTION); + gStorage->state = 9; + break; + case INPUT_MULTIMOVE_GRAB_SELECTION: + MultiMove_SetFunction(MULTIMOVE_GRAB_SELECTION); + gStorage->state = 7; + break; + case INPUT_MULTIMOVE_MOVE_MONS: + PlaySE(SE_SELECT); + MultiMove_SetFunction(MULTIMOVE_MOVE_MONS); + gStorage->state = 9; + break; + case INPUT_MULTIMOVE_PLACE_MONS: + PlaySE(SE_SELECT); + SetPokeStorageQuestLogEvent(3); + MultiMove_SetFunction(MULTIMOVE_PLACE_MONS); + gStorage->state = 7; + break; + case INPUT_MULTIMOVE_UNABLE: + PlaySE(SE_FAILURE); + break; + } + break; + case 1: + if (!UpdateCursorPos()) + { + if (IsCursorOnCloseBox()) + StartFlashingCloseBoxButton(); + else + StopFlashingCloseBoxButton(); + + if (gStorage->setMosaic) + StartDisplayMonMosaic(); + gStorage->state = 0; + } + break; + case 2: + if (!ScrollToBox()) + { + SetCurrentBox(gStorage->newCurrBoxId); + if (!sInPartyMenu && !IsMonBeingMoved()) + { + DoTrySetDisplayMonData(); + StartDisplayMonMosaic(); + } + + if (gStorage->boxOption == OPTION_MOVE_ITEMS) + { + TryShowItemAtCursor(); + gStorage->state = 11; + } + else + gStorage->state = 0; + } + break; + case 3: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + ClearBottomWindow(); + gStorage->state = 0; + } + break; + case 4: + PlaySE(SE_FAILURE); + PrintStorageMessage(MSG_LAST_POKE); + gStorage->state = 6; + break; + case 5: + PlaySE(SE_FAILURE); + PrintStorageMessage(MSG_PLEASE_REMOVE_MAIL); + gStorage->state = 6; + break; + case 6: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + ClearBottomWindow(); + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + case 7: + if (!MultiMove_RunFunction()) + gStorage->state = 0; + break; + case 8: + if (!MultiMove_RunFunction()) + SetPokeStorageTask(Task_MoveMon); + break; + case 9: + if (!MultiMove_RunFunction()) + { + if (gStorage->setMosaic) + StartDisplayMonMosaic(); + gStorage->state = 0; + } + break; + case 10: + if (!IsItemIconAnimActive()) + { + SetUpScrollToBox(gStorage->newCurrBoxId); + gStorage->state = 2; + } + break; + case 11: + if (!IsItemIconAnimActive()) + gStorage->state = 0; + break; + } +} + +static void Task_ShowPartyPokemon(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + SetUpDoShowPartyMenu(); + gStorage->state++; + break; + case 1: + if (!DoShowPartyMenu()) + SetPokeStorageTask(Task_PokeStorageMain); + break; + } +} + +static void Task_HidePartyPokemon(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + PlaySE(SE_SELECT); + SetUpHidePartyMenu(); + gStorage->state++; + break; + case 1: + if (!HidePartyMenu()) + { + SetCursorBoxPosition(GetSavedCursorPos()); + gStorage->state++; + } + break; + case 2: + if (!UpdateCursorPos()) + { + if (gStorage->setMosaic) + StartDisplayMonMosaic(); + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + } +} + +static void Task_OnSelectedMon(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + if (!IsDisplayMonMosaicActive()) + { + PlaySE(SE_SELECT); + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + PrintStorageMessage(MSG_IS_SELECTED); + else if (IsActiveItemMoving() || gStorage->displayMonItemId != 0) + PrintStorageMessage(MSG_IS_SELECTED2); + else + PrintStorageMessage(MSG_GIVE_TO_MON); + + AddMenu(); + gStorage->state = 1; + } + break; + case 1: + if (!IsMenuLoading()) + gStorage->state = 2; + break; + case 2: + switch (HandleMenuInput()) + { + case MENU_B_PRESSED: + case MENU_TEXT_CANCEL: + ClearBottomWindow(); + SetPokeStorageTask(Task_PokeStorageMain); + break; + case MENU_TEXT_MOVE: + if (CanMovePartyMon()) + gStorage->state = 3; + else + { + PlaySE(SE_SELECT); + ClearBottomWindow(); + SetPokeStorageTask(Task_MoveMon); + } + break; + case MENU_TEXT_PLACE: + PlaySE(SE_SELECT); + ClearBottomWindow(); + SetPokeStorageTask(Task_PlaceMon); + break; + case MENU_TEXT_SHIFT: + if (!CanShiftMon()) + gStorage->state = 3; + else + { + PlaySE(SE_SELECT); + ClearBottomWindow(); + SetPokeStorageTask(Task_ShiftMon); + } + break; + case MENU_TEXT_WITHDRAW: + PlaySE(SE_SELECT); + ClearBottomWindow(); + SetPokeStorageTask(Task_WithdrawMon); + break; + case MENU_TEXT_STORE: + if (CanMovePartyMon()) + gStorage->state = 3; + else if (ItemIsMail(gStorage->displayMonItemId)) + gStorage->state = 4; + else + { + PlaySE(SE_SELECT); + ClearBottomWindow(); + SetPokeStorageTask(Task_DepositMenu); + } + break; + case MENU_TEXT_RELEASE: + if (CanMovePartyMon()) + gStorage->state = 3; + else if (gStorage->displayMonIsEgg) + gStorage->state = 5; + else if (ItemIsMail(gStorage->displayMonItemId)) + gStorage->state = 4; + else + { + PlaySE(SE_SELECT); + SetPokeStorageTask(Task_ReleaseMon); + } + break; + case MENU_TEXT_SUMMARY: + PlaySE(SE_SELECT); + SetPokeStorageTask(Task_ShowMonSummary); + break; + case MENU_TEXT_MARK: + PlaySE(SE_SELECT); + SetPokeStorageTask(Task_ShowMarkMenu); + break; + case MENU_TEXT_TAKE: + PlaySE(SE_SELECT); + SetPokeStorageTask(Task_TakeItemForMoving); + break; + case MENU_TEXT_GIVE: + PlaySE(SE_SELECT); + SetPokeStorageTask(Task_GiveMovingItemToMon); + break; + case MENU_TEXT_BAG: + SetPokeStorageTask(Task_ItemToBag); + break; + case MENU_TEXT_SWITCH: + SetPokeStorageTask(Task_SwitchSelectedItem); + break; + case MENU_TEXT_GIVE2: + SetPokeStorageTask(Task_GiveItemFromBag); + break; + case MENU_TEXT_INFO: + SetPokeStorageTask(Task_ShowItemInfo); + break; + } + break; + case 3: + PlaySE(SE_FAILURE); + PrintStorageMessage(MSG_LAST_POKE); + gStorage->state = 6; + break; + case 5: + PlaySE(SE_FAILURE); + PrintStorageMessage(MSG_CANT_RELEASE_EGG); + gStorage->state = 6; + break; + case 4: + PlaySE(SE_FAILURE); + PrintStorageMessage(MSG_PLEASE_REMOVE_MAIL); + gStorage->state = 6; + break; + case 6: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + ClearBottomWindow(); + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + } +} + +static void Task_MoveMon(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + InitMonPlaceChange(CHANGE_GRAB); + gStorage->state++; + break; + case 1: + if (!DoMonPlaceChange()) + { + if (sInPartyMenu) + SetPokeStorageTask(Task_HandleMovingMonFromParty); + else + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + } +} + +static void Task_PlaceMon(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + SetPokeStorageQuestLogEvent(1); + InitMonPlaceChange(CHANGE_PLACE); + gStorage->state++; + break; + case 1: + if (!DoMonPlaceChange()) + { + if (sInPartyMenu) + SetPokeStorageTask(Task_HandleMovingMonFromParty); + else + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + } +} + +static void Task_ShiftMon(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + SetPokeStorageQuestLogEvent(0); + InitMonPlaceChange(CHANGE_SHIFT); + gStorage->state++; + break; + case 1: + if (!DoMonPlaceChange()) + { + StartDisplayMonMosaic(); + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + } +} + +static void Task_WithdrawMon(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + if (CalculatePlayerPartyCount() == PARTY_SIZE) + { + PrintStorageMessage(MSG_PARTY_FULL); + gStorage->state = 1; + } + else + { + SaveCursorPos(); + InitMonPlaceChange(CHANGE_GRAB); + gStorage->state = 2; + } + break; + case 1: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + ClearBottomWindow(); + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + case 2: + if (!DoMonPlaceChange()) + { + SetMovingMonPriority(1); + SetUpDoShowPartyMenu(); + gStorage->state++; + } + break; + case 3: + if (!DoShowPartyMenu()) + { + SetPokeStorageQuestLogEvent(1); + InitMonPlaceChange(CHANGE_PLACE); + gStorage->state++; + } + break; + case 4: + if (!DoMonPlaceChange()) + { + UpdatePartySlotColors(); + gStorage->state++; + } + break; + case 5: + SetPokeStorageTask(Task_HidePartyPokemon); + break; + } +} + +static void Task_DepositMenu(u8 taskId) +{ + u8 boxId; + + switch (gStorage->state) + { + case 0: + PrintStorageMessage(MSG_DEPOSIT_IN_WHICH_BOX); + LoadChooseBoxMenuGfx(&gStorage->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU_CENTER, PALTAG_MISC_1, 3, FALSE); + CreateChooseBoxMenuSprites(sDepositBoxId); + gStorage->state++; + break; + case 1: + boxId = HandleBoxChooseSelectionInput(); + switch (boxId) + { + case BOXID_NONE_CHOSEN: + break; + case BOXID_CANCELED: + ClearBottomWindow(); + DestroyChooseBoxMenuSprites(); + FreeBoxSelectionPopupSpriteGfx(); + SetPokeStorageTask(Task_PokeStorageMain); + break; + default: + if (TryStorePartyMonInBox(boxId)) + { + sDepositBoxId = boxId; + SetPokeStorageQuestLogEvent(2); + ClearBottomWindow(); + DestroyChooseBoxMenuSprites(); + FreeBoxSelectionPopupSpriteGfx(); + gStorage->state = 2; + } + else + { + PrintStorageMessage(MSG_BOX_IS_FULL); + gStorage->state = 4; + } + break; + } + break; + case 2: + CompactPartySlots(); + CompactPartySprites(); + gStorage->state++; + break; + case 3: + if (GetNumPartySpritesCompacting() == 0) + { + ResetSelectionAfterDeposit(); + StartDisplayMonMosaic(); + UpdatePartySlotColors(); + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + case 4: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + PrintStorageMessage(MSG_DEPOSIT_IN_WHICH_BOX); + gStorage->state = 1; + } + break; + } +} + +static void Task_ReleaseMon(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + PrintStorageMessage(MSG_RELEASE_POKE); + ShowYesNoWindow(1); + gStorage->state++; + // fallthrough + case 1: + switch (Menu_ProcessInputNoWrapClearOnChoose()) + { + case MENU_B_PRESSED: + case 1: + ClearBottomWindow(); + SetPokeStorageTask(Task_PokeStorageMain); + break; + case 0: + ClearBottomWindow(); + InitCanReleaseMonVars(); + InitReleaseMon(); + gStorage->state++; + break; + } + break; + case 2: + RunCanReleaseMon(); + if (!TryHideReleaseMon()) + { + while (TRUE) + { + // keep checking until status is no longer RELEASE_MON_UNDETERMINED + s8 canReleaseStatus = RunCanReleaseMon(); + if (canReleaseStatus == RELEASE_MON_ALLOWED) + { + gStorage->state++; + break; + } + else if (canReleaseStatus == RELEASE_MON_NOT_ALLOWED) + { + gStorage->state = 8; // Can't release the mon. + break; + } + } + } + break; + case 3: + ReleaseMon(); + RefreshDisplayMonData(); + PrintStorageMessage(MSG_WAS_RELEASED); + gStorage->state++; + break; + case 4: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + PrintStorageMessage(MSG_BYE_BYE); + gStorage->state++; + } + break; + case 5: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + ClearBottomWindow(); + if (sInPartyMenu) + { + CompactPartySlots(); + CompactPartySprites(); + gStorage->state++; + } + else + gStorage->state = 7; + } + break; + case 6: + if (GetNumPartySpritesCompacting() == 0) + { + DoTrySetDisplayMonData(); + StartDisplayMonMosaic(); + UpdatePartySlotColors(); + gStorage->state++; + } + break; + case 7: + SetPokeStorageTask(Task_PokeStorageMain); + break; + case 8: + // Start "can't release" sequence + PrintStorageMessage(MSG_WAS_RELEASED); + gStorage->state++; + break; + case 9: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + PrintStorageMessage(MSG_SURPRISE); + gStorage->state++; + } + break; + case 10: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + ClearBottomWindow(); + DoReleaseMonComeBackAnim(); + gStorage->state++; + } + break; + case 11: + if (!ResetReleaseMonSpritePtr()) + { + TrySetCursorFistAnim(); + PrintStorageMessage(MSG_CAME_BACK); + gStorage->state++; + } + break; + case 12: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + PrintStorageMessage(MSG_WORRIED); + gStorage->state++; + } + break; + case 13: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + ClearBottomWindow(); + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + } +} + +static void Task_ShowMarkMenu(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + PrintStorageMessage(MSG_MARK_POKE); + gStorage->markMenu.markings = gStorage->displayMonMarkings; + OpenMonMarkingsMenu(gStorage->displayMonMarkings, 176, 16); + gStorage->state++; + break; + case 1: + if (!HandleMonMarkingsMenuInput()) + { + FreeMonMarkingsMenu(); + ClearBottomWindow(); + SetMonMarkings(gStorage->markMenu.markings); + RefreshDisplayMonData(); + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + } +} + +static void Task_TakeItemForMoving(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + if (!ItemIsMail(gStorage->displayMonItemId)) + { + ClearBottomWindow(); + gStorage->state++; + } + else + SetPokeStorageTask(Task_PrintCantStoreMail); + break; + case 1: + StartCursorAnim(CURSOR_ANIM_OPEN); + Item_FromMonToMoving(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); + gStorage->state++; + break; + case 2: + if (!IsItemIconAnimActive()) + { + StartCursorAnim(CURSOR_ANIM_FIST); + ClearBottomWindow(); + DoTrySetDisplayMonData(); + PrintDisplayMonInfo(); + gStorage->state++; + } + break; + case 3: + if (!IsDma3ManagerBusyWithBgCopy()) + SetPokeStorageTask(Task_PokeStorageMain); + break; + } +} + +static void Task_GiveMovingItemToMon(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + ClearBottomWindow(); + gStorage->state++; + break; + case 1: + StartCursorAnim(CURSOR_ANIM_OPEN); + Item_GiveMovingToMon(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); + gStorage->state++; + break; + case 2: + if (!IsItemIconAnimActive()) + { + StartCursorAnim(CURSOR_ANIM_BOUNCE); + DoTrySetDisplayMonData(); + PrintDisplayMonInfo(); + PrintStorageMessage(MSG_ITEM_IS_HELD); + gStorage->state++; + } + break; + case 3: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + ClearBottomWindow(); + gStorage->state++; + } + break; + case 4: + if (!IsDma3ManagerBusyWithBgCopy()) + SetPokeStorageTask(Task_PokeStorageMain); + break; + } +} + +static void Task_ItemToBag(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + if (!AddBagItem(gStorage->displayMonItemId, 1)) + { + PlaySE(SE_FAILURE); + PrintStorageMessage(MSG_BAG_FULL); + gStorage->state = 3; + } + else + { + PlaySE(SE_SELECT); + Item_TakeMons(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); + gStorage->state = 1; + } + break; + case 1: + if (!IsItemIconAnimActive()) + { + PrintStorageMessage(MSG_PLACED_IN_BAG); + gStorage->state = 2; + } + break; + case 2: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + ClearBottomWindow(); + DoTrySetDisplayMonData(); + PrintDisplayMonInfo(); + gStorage->state = 4; + } + break; + case 4: + if (!IsDma3ManagerBusyWithBgCopy()) + SetPokeStorageTask(Task_PokeStorageMain); + break; + case 3: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + ClearBottomWindow(); + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + } +} + +static void Task_SwitchSelectedItem(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + if (!ItemIsMail(gStorage->displayMonItemId)) + { + ClearBottomWindow(); + gStorage->state++; + } + else + SetPokeStorageTask(Task_PrintCantStoreMail); + break; + case 1: + StartCursorAnim(CURSOR_ANIM_OPEN); + Item_SwitchMonsWithMoving(sInPartyMenu ? CURSOR_AREA_IN_PARTY : CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); + gStorage->state++; + break; + case 2: + if (!IsItemIconAnimActive()) + { + StartCursorAnim(CURSOR_ANIM_FIST); + DoTrySetDisplayMonData(); + PrintDisplayMonInfo(); + PrintStorageMessage(MSG_CHANGED_TO_ITEM); + gStorage->state++; + } + break; + case 3: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + ClearBottomWindow(); + gStorage->state++; + } + break; + case 4: + if (!IsDma3ManagerBusyWithBgCopy()) + SetPokeStorageTask(Task_PokeStorageMain); + break; + } +} + +static void Task_ShowItemInfo(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + ClearBottomWindow(); + gStorage->state++; + break; + case 1: + if (!IsDma3ManagerBusyWithBgCopy()) + { + PlaySE(SE_WIN_OPEN); + PrintItemDescription(); + InitItemInfoWindow(); + gStorage->state++; + } + break; + case 2: + if (!UpdateItemInfoWindowSlideIn()) + gStorage->state++; + break; + case 3: + if (!IsDma3ManagerBusyWithBgCopy()) + gStorage->state++; + break; + case 4: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + PlaySE(SE_WIN_OPEN); + gStorage->state++; + } + break; + case 5: + if (!UpdateItemInfoWindowSlideOut()) + gStorage->state++; + break; + case 6: + if (!IsDma3ManagerBusyWithBgCopy()) + SetPokeStorageTask(Task_PokeStorageMain); + break; + } +} + +static void Task_CloseBoxWhileHoldingItem(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + PlaySE(SE_SELECT); + PrintStorageMessage(MSG_PUT_IN_BAG); + ShowYesNoWindow(0); + gStorage->state = 1; + break; + case 1: + switch (Menu_ProcessInputNoWrapClearOnChoose()) + { + case MENU_B_PRESSED: + case 1: + ClearBottomWindow(); + SetPokeStorageTask(Task_PokeStorageMain); + break; + case 0: + if (AddBagItem(gStorage->movingItemId, 1) == TRUE) + { + ClearBottomWindow(); + gStorage->state = 3; + } + else + { + PrintStorageMessage(MSG_BAG_FULL); + gStorage->state = 2; + } + break; + } + break; + case 2: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + ClearBottomWindow(); + gStorage->state = 5; + } + break; + case 3: + MoveItemFromCursorToBag(); + gStorage->state = 4; + break; + case 4: + if (!IsItemIconAnimActive()) + { + StartCursorAnim(CURSOR_ANIM_BOUNCE); + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + case 5: + if (!IsDma3ManagerBusyWithBgCopy()) + SetPokeStorageTask(Task_PokeStorageMain); + break; + } +} + +static void Task_HandleMovingMonFromParty(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + CompactPartySlots(); + CompactPartySprites(); + gStorage->state++; + break; + case 1: + if (GetNumPartySpritesCompacting() == 0) + { + UpdatePartySlotColors(); + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + } +} + +static void Task_PrintCantStoreMail(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + PrintStorageMessage(MSG_CANT_STORE_MAIL); + gStorage->state++; + break; + case 1: + if (!IsDma3ManagerBusyWithBgCopy()) + gStorage->state++; + break; + case 2: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + ClearBottomWindow(); + gStorage->state++; + } + break; + case 3: + if (!IsDma3ManagerBusyWithBgCopy()) + SetPokeStorageTask(Task_PokeStorageMain); + break; + } +} + +static void Task_HandleBoxOptions(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + PrintStorageMessage(MSG_WHAT_YOU_DO); + AddMenu(); + gStorage->state++; + break; + case 1: + if (IsMenuLoading()) + return; + gStorage->state++; + case 2: + switch (HandleMenuInput()) + { + case MENU_B_PRESSED: + case MENU_TEXT_CANCEL: + AnimateBoxScrollArrows(TRUE); + ClearBottomWindow(); + SetPokeStorageTask(Task_PokeStorageMain); + break; + case MENU_TEXT_NAME: + PlaySE(SE_SELECT); + SetPokeStorageTask(Task_NameBox); + break; + case MENU_TEXT_WALLPAPER: + PlaySE(SE_SELECT); + ClearBottomWindow(); + SetPokeStorageTask(Task_HandleWallpapers); + break; + case MENU_TEXT_JUMP: + PlaySE(SE_SELECT); + ClearBottomWindow(); + SetPokeStorageTask(Task_JumpBox); + break; + } + break; + } +} + +static void Task_HandleWallpapers(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + AddWallpaperSetsMenu(); + PrintStorageMessage(MSG_PICK_A_THEME); + gStorage->state++; + break; + case 1: + if (!IsMenuLoading()) + gStorage->state++; + break; + case 2: + gStorage->wallpaperSetId = HandleMenuInput(); + switch (gStorage->wallpaperSetId) + { + case MENU_B_PRESSED: + AnimateBoxScrollArrows(TRUE); + ClearBottomWindow(); + SetPokeStorageTask(Task_PokeStorageMain); + break; + case MENU_TEXT_SCENERY_1: + case MENU_TEXT_SCENERY_2: + case MENU_TEXT_SCENERY_3: + case MENU_TEXT_ETCETERA: + PlaySE(SE_SELECT); + RemoveMenu(); + gStorage->wallpaperSetId -= MENU_TEXT_SCENERY_1; + gStorage->state++; + break; + } + break; + case 3: + if (!IsDma3ManagerBusyWithBgCopy()) + { + AddWallpapersMenu(gStorage->wallpaperSetId); + PrintStorageMessage(MSG_PICK_A_WALLPAPER); + gStorage->state++; + } + break; + case 4: + gStorage->wallpaperId = HandleMenuInput(); + switch (gStorage->wallpaperId) + { + case MENU_NOTHING_CHOSEN: + break; + case MENU_B_PRESSED: + ClearBottomWindow(); + gStorage->state = 0; + break; + default: + PlaySE(SE_SELECT); + ClearBottomWindow(); + gStorage->wallpaperId -= MENU_TEXT_FOREST; + SetWallpaperForCurrentBox(gStorage->wallpaperId); + gStorage->state++; + break; + } + break; + case 5: + if (!DoWallpaperGfxChange()) + { + AnimateBoxScrollArrows(TRUE); + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + } +} + +static void Task_JumpBox(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + PrintStorageMessage(MSG_JUMP_TO_WHICH_BOX); + LoadChooseBoxMenuGfx(&gStorage->chooseBoxMenu, GFXTAG_CHOOSE_BOX_MENU_CENTER, PALTAG_MISC_1, 3, FALSE); + CreateChooseBoxMenuSprites(StorageGetCurrentBox()); + gStorage->state++; + break; + case 1: + gStorage->newCurrBoxId = HandleBoxChooseSelectionInput(); + switch (gStorage->newCurrBoxId) + { + case BOXID_NONE_CHOSEN: + break; + default: + ClearBottomWindow(); + DestroyChooseBoxMenuSprites(); + FreeBoxSelectionPopupSpriteGfx(); + if (gStorage->newCurrBoxId == BOXID_CANCELED || gStorage->newCurrBoxId == StorageGetCurrentBox()) + { + AnimateBoxScrollArrows(TRUE); + SetPokeStorageTask(Task_PokeStorageMain); + } + else + gStorage->state++; + break; + } + break; + case 2: + SetUpScrollToBox(gStorage->newCurrBoxId); + gStorage->state++; + break; + case 3: + if (!ScrollToBox()) + { + SetCurrentBox(gStorage->newCurrBoxId); + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + } +} + +static void Task_NameBox(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + SaveMovingMon(); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); + gStorage->state++; + break; + case 1: + if (!UpdatePaletteFade()) + { + sWhichToReshow = SCREEN_CHANGE_NAME_BOX - 1; + gStorage->screenChangeType = SCREEN_CHANGE_NAME_BOX; + SetPokeStorageTask(Task_ChangeScreen); + } + break; + } +} + +static void Task_ShowMonSummary(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + InitSummaryScreenData(); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); + gStorage->state++; + break; + case 1: + if (!UpdatePaletteFade()) + { + sWhichToReshow = SCREEN_CHANGE_SUMMARY_SCREEN - 1; + gStorage->screenChangeType = SCREEN_CHANGE_SUMMARY_SCREEN; + SetPokeStorageTask(Task_ChangeScreen); + } + break; + } +} + +static void Task_GiveItemFromBag(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); + gStorage->state++; + break; + case 1: + if (!UpdatePaletteFade()) + { + sWhichToReshow = SCREEN_CHANGE_ITEM_FROM_BAG - 1; + gStorage->screenChangeType = SCREEN_CHANGE_ITEM_FROM_BAG; + SetPokeStorageTask(Task_ChangeScreen); + } + break; + } +} + +static void Task_OnCloseBoxPressed(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + if (IsMonBeingMoved()) + { + PlaySE(SE_FAILURE); + PrintStorageMessage(MSG_HOLDING_POKE); + gStorage->state = 1; + } + else if (IsActiveItemMoving()) + SetPokeStorageTask(Task_CloseBoxWhileHoldingItem); + else + { + PlaySE(SE_SELECT); + PrintStorageMessage(MSG_EXIT_BOX); + ShowYesNoWindow(0); + gStorage->state = 2; + } + break; + case 1: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + ClearBottomWindow(); + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + case 2: + switch (Menu_ProcessInputNoWrapClearOnChoose()) + { + case MENU_B_PRESSED: + case 1: + ClearBottomWindow(); + SetPokeStorageTask(Task_PokeStorageMain); + break; + case 0: + PlaySE(SE_PC_OFF); + ClearBottomWindow(); + gStorage->state++; + break; + } + break; + case 3: + BeginPCScreenEffect_TurnOff(20, 0, 1); + gStorage->state++; + break; + case 4: + if (!IsPCScreenEffectRunning_TurnOff()) + { + UpdateBoxToSendMons(); + gPlayerPartyCount = CalculatePlayerPartyCount(); + gStorage->screenChangeType = SCREEN_CHANGE_EXIT_BOX; + SetPokeStorageTask(Task_ChangeScreen); + } + break; + } +} + +static void Task_OnBPressed(u8 taskId) +{ + switch (gStorage->state) + { + case 0: + if (IsMonBeingMoved()) + { + PlaySE(SE_FAILURE); + PrintStorageMessage(MSG_HOLDING_POKE); + gStorage->state = 1; + } + else if (IsActiveItemMoving()) + SetPokeStorageTask(Task_CloseBoxWhileHoldingItem); + else + { + PlaySE(SE_SELECT); + PrintStorageMessage(MSG_CONTINUE_BOX); + ShowYesNoWindow(0); + gStorage->state = 2; + } + break; + case 1: + if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + { + ClearBottomWindow(); + SetPokeStorageTask(Task_PokeStorageMain); + } + break; + case 2: + switch (Menu_ProcessInputNoWrapClearOnChoose()) + { + case 0: + ClearBottomWindow(); + SetPokeStorageTask(Task_PokeStorageMain); + break; + case 1: + case MENU_B_PRESSED: + PlaySE(SE_PC_OFF); + ClearBottomWindow(); + gStorage->state++; + break; + } + break; + case 3: + BeginPCScreenEffect_TurnOff(20, 0, 0); + gStorage->state++; + break; + case 4: + if (!IsPCScreenEffectRunning_TurnOff()) + { + UpdateBoxToSendMons(); + gPlayerPartyCount = CalculatePlayerPartyCount(); + gStorage->screenChangeType = SCREEN_CHANGE_EXIT_BOX; + SetPokeStorageTask(Task_ChangeScreen); + } + break; + } +} + +static void Task_ChangeScreen(u8 taskId) +{ + struct Pokemon *party; + u8 mode, cursorPos, lastIndex; + u8 screenChangeType = gStorage->screenChangeType; + + if (gStorage->boxOption == OPTION_MOVE_ITEMS && IsActiveItemMoving() == TRUE) + sMovingItemId = GetMovingItem(); + else + sMovingItemId = ITEM_NONE; + + switch (screenChangeType) + { + case SCREEN_CHANGE_EXIT_BOX: + default: + FreePokeStorageData(); + SetMainCallback2(CB2_ExitPokeStorage); + break; + case SCREEN_CHANGE_SUMMARY_SCREEN: + party = gStorage->summaryMonPtr.mon; + cursorPos = gStorage->summaryCursorPos; + lastIndex = gStorage->summaryLastIndex; + mode = gStorage->summaryScreenMode; + FreePokeStorageData(); + ShowPokemonSummaryScreen(party, cursorPos, lastIndex, CB2_ReturnToPokeStorage, mode); + break; + case SCREEN_CHANGE_NAME_BOX: + FreePokeStorageData(); + DoNamingScreen(NAMING_SCREEN_BOX, GetBoxNamePtr(StorageGetCurrentBox()), 0, 0, 0, CB2_ReturnToPokeStorage); + break; + case SCREEN_CHANGE_ITEM_FROM_BAG: + FreePokeStorageData(); + GoToBagMenu(ITEMMENULOCATION_PCBOX, OPEN_BAG_ITEMS, CB2_ReturnToPokeStorage); + break; + } + + DestroyTask(taskId); +} + +static void GiveChosenBagItem(void) +{ + u16 item = gSpecialVar_ItemId; + + if (item != ITEM_NONE) + { + u8 id = GetBoxCursorPosition(); + + if (sInPartyMenu) + SetMonData(&gPlayerParty[id], MON_DATA_HELD_ITEM, &item); + else + SetCurrentBoxMonData(id, MON_DATA_HELD_ITEM, &item); + + RemoveBagItem(item, 1); + } +} + +static void FreePokeStorageData(void) +{ + TilemapUtil_Free(); + MultiMove_Free(); + FREE_AND_SET_NULL(gStorage); + FreeAllWindowBuffers(); +} + +static void SetScrollingBackground(void) +{ + SetGpuReg(REG_OFFSET_BG3CNT, BGCNT_PRIORITY(3) | BGCNT_CHARBASE(3) | BGCNT_16COLOR | BGCNT_SCREENBASE(31)); + DecompressAndLoadBgGfxUsingHeap(3, sScrollingBg_Gfx, 0, 0, 0); + LZ77UnCompVram(sScrollingBg_Tilemap, (void *)BG_SCREEN_ADDR(31)); +} + +static void ScrollBackground(void) +{ + ChangeBgX(3, 128, 1); + ChangeBgY(3, 128, 2); +} + +static void LoadPokeStorageMenuGfx(void) +{ + InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates)); + DecompressAndLoadBgGfxUsingHeap(1, gPokeStorageMenu_Gfx, 0, 0, 0); + LZ77UnCompWram(sMenu_Tilemap, gStorage->menuTilemapBuffer); + SetBgTilemapBuffer(1, gStorage->menuTilemapBuffer); + ShowBg(1); + ScheduleBgCopyTilemapToVram(1); +} + +static bool8 InitPokeStorageWindows(void) +{ + if (!InitWindows(sWindowTemplates)) + return FALSE; + + DeactivateAllTextPrinters(); + return TRUE; +} + +static void LoadsMiscSpritePalette(void) +{ + LoadSpritePalette(&sMiscSpritePalette); +} + +static void InitPalettesAndSprites(void) +{ + LoadPalette(gPokeStorageInterface_Pal, 0, 0x20); + LoadPalette(gPokeStorageInterface_NoDisplayMon_Pal, 0x20, 0x20); + LoadPalette(sItemInfoFrame_Pal, 0xF0, 0x20); + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + LoadPalette(sScrollingBg_Pal, 0x30, sizeof(sScrollingBg_Pal)); + else + LoadPalette(sScrollingBgMoveItems_Pal, 0x30, sizeof(sScrollingBgMoveItems_Pal)); + + SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(1) | BGCNT_CHARBASE(1) | BGCNT_16COLOR | BGCNT_SCREENBASE(30)); + CreateDisplayMonSprite(); + CreateMarkingComboSprite(); + CreateWaveformSprites(); + RefreshDisplayMonData(); +} + +static void CreateMarkingComboSprite(void) +{ + gStorage->markingComboSprite = CreateMonMarkingComboSprite(GFXTAG_MARKING_COMBO, PALTAG_MARKING_COMBO, NULL); + gStorage->markingComboSprite->oam.priority = 1; + gStorage->markingComboSprite->subpriority = 1; + gStorage->markingComboSprite->x = 40; + gStorage->markingComboSprite->y = 150; + gStorage->markingComboTilesPtr = (void *)OBJ_VRAM0 + 32 * GetSpriteTileStartByTag(GFXTAG_MARKING_COMBO); +} + +static void CreateWaveformSprites(void) +{ + u16 i; + struct SpriteSheet sheet = sWaveformSpriteSheet; + + LoadSpriteSheet(&sheet); + for (i = 0; i < 2; i++) + { + u8 spriteId = CreateSprite(&sSpriteTemplate_Waveform, i * 63 + 8, 9, 2); + gStorage->waveformSprites[i] = &gSprites[spriteId]; + } +} + +static void RefreshDisplayMonData(void) +{ + LoadDisplayMonGfx(gStorage->displayMonSpecies, gStorage->displayMonPersonality); + PrintDisplayMonInfo(); + UpdateWaveformAnimation(); + ScheduleBgCopyTilemapToVram(0); +} + +static void StartDisplayMonMosaic(void) +{ + RefreshDisplayMonData(); + if (gStorage->displayMonSprite) + { + gStorage->displayMonSprite->oam.mosaic = TRUE; + gStorage->displayMonSprite->data[0] = 10; + gStorage->displayMonSprite->data[1] = 1; + gStorage->displayMonSprite->callback = SpriteCB_DisplayMonMosaic; + SetGpuReg(REG_OFFSET_MOSAIC, (gStorage->displayMonSprite->data[0] << 12) | (gStorage->displayMonSprite->data[0] << 8)); + } +} + +static u8 IsDisplayMonMosaicActive(void) +{ + return gStorage->displayMonSprite->oam.mosaic; +} + +static void SpriteCB_DisplayMonMosaic(struct Sprite *sprite) +{ + sprite->data[0] -= sprite->data[1]; + if (sprite->data[0] < 0) + sprite->data[0] = 0; + SetGpuReg(REG_OFFSET_MOSAIC, (sprite->data[0] << 12) | (sprite->data[0] << 8)); + if (sprite->data[0] == 0) + { + sprite->oam.mosaic = FALSE; + sprite->callback = SpriteCallbackDummy; + } +} + +static void CreateDisplayMonSprite(void) +{ + u16 i; + u16 tileStart; + u8 palSlot; + u8 spriteId; + struct SpriteSheet sheet = {gStorage->tileBuffer, MON_PIC_SIZE, GFXTAG_DISPLAY_MON}; + struct SpritePalette palette = {gStorage->displayMonPalBuffer, PALTAG_DISPLAY_MON}; + struct SpriteTemplate template = sSpriteTemplate_DisplayMon; + + for (i = 0; i < MON_PIC_SIZE; i++) + gStorage->tileBuffer[i] = 0; + for (i = 0; i < 0x10; i++) + gStorage->displayMonPalBuffer[i] = 0; + + gStorage->displayMonSprite = NULL; + + do + { + tileStart = LoadSpriteSheet(&sheet); + if (tileStart == 0) + break; + + palSlot = LoadSpritePalette(&palette); + if (palSlot == 0xFF) + break; + + spriteId = CreateSprite(&template, 40, 48, 0); + if (spriteId == MAX_SPRITES) + break; + + gStorage->displayMonSprite = &gSprites[spriteId]; + gStorage->displayMonPalOffset = palSlot * 16 + 0x100; + gStorage->displayMonTilePtr = (void *)OBJ_VRAM0 + tileStart * 32; + } while (FALSE); + + if (gStorage->displayMonSprite == NULL) + { + FreeSpriteTilesByTag(GFXTAG_DISPLAY_MON); + FreeSpritePaletteByTag(PALTAG_DISPLAY_MON); + } +} + +static void LoadDisplayMonGfx(u16 species, u32 personality) +{ + if (gStorage->displayMonSprite == NULL) + return; + + if (species != SPECIES_NONE) + { + HandleLoadSpecialPokePic(&gMonFrontPicTable[species], gStorage->tileBuffer, species, personality); + LZ77UnCompWram(gStorage->displayMonPalette, gStorage->displayMonPalBuffer); + CpuCopy32(gStorage->tileBuffer, gStorage->displayMonTilePtr, 0x800); + LoadPalette(gStorage->displayMonPalBuffer, gStorage->displayMonPalOffset, 0x20); + gStorage->displayMonSprite->invisible = FALSE; + } + else + gStorage->displayMonSprite->invisible = TRUE; +} + +static void PrintDisplayMonInfo(void) +{ + u16 i; + u16 y; + FillWindowPixelBuffer(0, PIXEL_FILL(1)); + if (gStorage->boxOption != OPTION_MOVE_ITEMS) + { + for (i = 0, y = 0; i < 3; i++, y += 14) + AddTextPrinterParameterized(0, FONT_2, gStorage->displayMonTexts[i], i == 2 ? 10 : 6, y, TEXT_SKIP_DRAW, NULL); + + AddTextPrinterParameterized(0, FONT_0, gStorage->displayMonTexts[3], 6, y + 2, TEXT_SKIP_DRAW, NULL); + } + else + { + AddTextPrinterParameterized(0, FONT_0, gStorage->displayMonTexts[3], 6, 0, TEXT_SKIP_DRAW, NULL); + for (i = 0, y = 15; i < 3; i++, y += 14) + AddTextPrinterParameterized(0, FONT_2, gStorage->displayMonTexts[i], i == 2 ? 10 : 6, y, TEXT_SKIP_DRAW, NULL); + } + + CopyWindowToVram(0, COPYWIN_GFX); + if (gStorage->displayMonSpecies != SPECIES_NONE) + { + UpdateMonMarkingTiles(gStorage->displayMonMarkings, gStorage->markingComboTilesPtr); + gStorage->markingComboSprite->invisible = FALSE; + } + else + gStorage->markingComboSprite->invisible = TRUE; +} + +static void UpdateWaveformAnimation(void) +{ + u16 i; + + if (gStorage->displayMonSpecies != SPECIES_NONE) + { + TilemapUtil_SetRect(TILEMAP_PKMN_DATA, 0, 0, 8, 2); + for (i = 0; i < 2; i++) + StartSpriteAnimIfDifferent(gStorage->waveformSprites[i], i * 2 + 1); + } + else + { + TilemapUtil_SetRect(TILEMAP_PKMN_DATA, 0, 2, 8, 2); + for (i = 0; i < 2; i++) + StartSpriteAnim(gStorage->waveformSprites[i], i * 2); + } + + TilemapUtil_Update(TILEMAP_PKMN_DATA); + ScheduleBgCopyTilemapToVram(1); +} + +static void InitSupplementalTilemaps(void) +{ + LZ77UnCompWram(gPokeStoragePartyMenu_Tilemap, gStorage->partyMenuTilemapBuffer); + LoadPalette(gPokeStoragePartyMenu_Pal, 0x10, 0x20); + TilemapUtil_SetTilemap(TILEMAP_PARTY_MENU, 1, gStorage->partyMenuTilemapBuffer, 12, 22); + TilemapUtil_SetTilemap(TILEMAP_CLOSE_BUTTON, 1, sCloseBoxButton_Tilemap, 9, 4); + TilemapUtil_SetPos(TILEMAP_PARTY_MENU, 10, 0); + TilemapUtil_SetPos(TILEMAP_CLOSE_BUTTON, 21, 0); + SetPartySlotTilemaps(); + if (sInPartyMenu) + { + UpdateCloseBoxButtonTilemap(TRUE); + CreatePartyMonsSprites(TRUE); + TilemapUtil_Update(TILEMAP_CLOSE_BUTTON); + TilemapUtil_Update(TILEMAP_PARTY_MENU); + } + else + { + TilemapUtil_SetRect(TILEMAP_PARTY_MENU, 0, 20, 12, 2); + UpdateCloseBoxButtonTilemap(TRUE); + TilemapUtil_Update(TILEMAP_PARTY_MENU); + TilemapUtil_Update(TILEMAP_CLOSE_BUTTON); + } + + ScheduleBgCopyTilemapToVram(1); + gStorage->closeBoxFlashing = FALSE; +} + +static void SetUpShowPartyMenu(void) +{ + gStorage->partyMenuUnused1 = 20; + gStorage->partyMenuY = 2; + gStorage->partyMenuMoveTimer = 0; + CreatePartyMonsSprites(FALSE); +} + +static bool8 ShowPartyMenu(void) +{ + if (gStorage->partyMenuMoveTimer == 20) + return FALSE; + + gStorage->partyMenuUnused1--; + gStorage->partyMenuY++; + TilemapUtil_Move(TILEMAP_PARTY_MENU, 3, 1); + TilemapUtil_Update(TILEMAP_PARTY_MENU); + ScheduleBgCopyTilemapToVram(1); + MovePartySprites(8); + if (++gStorage->partyMenuMoveTimer == 20) + { + sInPartyMenu = TRUE; + return FALSE; + } + else + return TRUE; +} + +static void SetUpHidePartyMenu(void) +{ + gStorage->partyMenuUnused1 = 0; + gStorage->partyMenuY = 22; + gStorage->partyMenuMoveTimer = 0; + if (gStorage->boxOption == OPTION_MOVE_ITEMS) + MoveHeldItemWithPartyMenu(); +} + +static bool8 HidePartyMenu(void) +{ + if (gStorage->partyMenuMoveTimer != 20) + { + gStorage->partyMenuUnused1++; + gStorage->partyMenuY--; + TilemapUtil_Move(TILEMAP_PARTY_MENU, 3, -1); + TilemapUtil_Update(TILEMAP_PARTY_MENU); + FillBgTilemapBufferRect_Palette0(1, 0x100, 10, gStorage->partyMenuY, 12, 1); + MovePartySprites(-8); + if (++gStorage->partyMenuMoveTimer != 20) + { + ScheduleBgCopyTilemapToVram(1); + return TRUE; + } + else + { + sInPartyMenu = FALSE; + DestroyAllPartyMonIcons(); + CompactPartySlots(); + TilemapUtil_SetRect(TILEMAP_CLOSE_BUTTON, 0, 0, 9, 2); + TilemapUtil_Update(TILEMAP_CLOSE_BUTTON); + ScheduleBgCopyTilemapToVram(1); + return FALSE; + } + } + + return FALSE; +} + +static void UpdateCloseBoxButtonTilemap(bool8 normal) +{ + if (normal) + TilemapUtil_SetRect(TILEMAP_CLOSE_BUTTON, 0, 0, 9, 2); + else + TilemapUtil_SetRect(TILEMAP_CLOSE_BUTTON, 0, 2, 9, 2); + + TilemapUtil_Update(TILEMAP_CLOSE_BUTTON); + ScheduleBgCopyTilemapToVram(1); +} + +static void StartFlashingCloseBoxButton(void) +{ + gStorage->closeBoxFlashing = TRUE; + gStorage->closeBoxFlashTimer = 30; + gStorage->closeBoxFlashState = TRUE; +} + +static void StopFlashingCloseBoxButton(void) +{ + if (gStorage->closeBoxFlashing) + { + gStorage->closeBoxFlashing = FALSE; + UpdateCloseBoxButtonTilemap(TRUE); + } +} + +static void UpdateCloseBoxButtonFlash(void) +{ + if (gStorage->closeBoxFlashing && ++gStorage->closeBoxFlashTimer > 30) + { + gStorage->closeBoxFlashTimer = 0; + gStorage->closeBoxFlashState = (gStorage->closeBoxFlashState == FALSE); + UpdateCloseBoxButtonTilemap(gStorage->closeBoxFlashState); + } +} + +static void SetPartySlotTilemaps(void) +{ + u8 i; + + // Skips first party slot, it should always be drawn + // as if it has a Pokémon in it + for (i = 1; i < PARTY_SIZE; i++) + { + s32 species = GetMonData(gPlayerParty + i, MON_DATA_SPECIES); + SetPartySlotTilemap(i, (species != SPECIES_NONE)); + } +} + +static void SetPartySlotTilemap(u8 pos, bool8 isFilled) +{ + u16 i, j, index; + const u16 *tilemap; + + if (isFilled) + tilemap = sPartySlotFilled_Tilemap; + else + tilemap = sPartySlotEmpty_Tilemap; + + index = 3 * (3 * (pos - 1) + 1); + index *= 4; + index += 7; + for (i = 0; i < 3; i++) + { + for (j = 0; j < 4; j++) + gStorage->partyMenuTilemapBuffer[index + j] = tilemap[j]; + + tilemap += 4; + index += 12; + } +} + +static void UpdatePartySlotColors(void) +{ + SetPartySlotTilemaps(); + TilemapUtil_SetRect(TILEMAP_PARTY_MENU, 0, 0, 12, 22); + TilemapUtil_Update(TILEMAP_PARTY_MENU); + ScheduleBgCopyTilemapToVram(1); +} + +static void SetUpDoShowPartyMenu(void) +{ + gStorage->showPartyMenuState = 0; + PlaySE(SE_WIN_OPEN); + SetUpShowPartyMenu(); +} + +static bool8 DoShowPartyMenu(void) +{ + switch (gStorage->showPartyMenuState) + { + case 0: + if (!ShowPartyMenu()) + { + SetCursorInParty(); + gStorage->showPartyMenuState++; + } + break; + case 1: + if (!UpdateCursorPos()) + { + if (gStorage->setMosaic) + StartDisplayMonMosaic(); + gStorage->showPartyMenuState++; + } + break; + case 2: + return FALSE; + } + return TRUE; +} + +static void InitPokeStorageBg0(void) +{ + SetGpuReg(REG_OFFSET_BG0CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(29)); + TextWindow_SetStdFrame0_WithPal(1, 2, 0xD0); + FillBgTilemapBufferRect(0, 0, 0, 0, 32, 20, 17); + CopyBgTilemapBufferToVram(0); +} + +static void PrintStorageMessage(u8 id) +{ + u8 *txtPtr; + + DynamicPlaceholderTextUtil_Reset(); + switch (sMessages[id].format) + { + case MSG_FMT_NONE: + break; + case MSG_FMT_MON_NAME_1: + case MSG_FMT_MON_NAME_2: + case MSG_FMT_MON_NAME_3: + DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, gStorage->displayMonNickname); + break; + case MSG_FMT_RELEASE_MON_1: + case MSG_FMT_RELEASE_MON_2: + case MSG_FMT_RELEASE_MON_3: + DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, gStorage->releaseMonName); + break; + case MSG_FMT_ITEM_NAME: + if (IsActiveItemMoving()) + txtPtr = StringCopy(gStorage->itemName, GetMovingItemName()); + else + txtPtr = StringCopy(gStorage->itemName, gStorage->displayMonTexts[3]); + + while (*(txtPtr - 1) == CHAR_SPACE) + txtPtr--; + + *txtPtr = EOS; + DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, gStorage->itemName); + break; + } + + DynamicPlaceholderTextUtil_ExpandPlaceholders(gStorage->actionText, sMessages[id].text); + FillWindowPixelBuffer(1, PIXEL_FILL(1)); + AddTextPrinterParameterized(1, FONT_1, gStorage->actionText, 0, 2, TEXT_SKIP_DRAW, NULL); + DrawTextBorderOuter(1, 2, 13); + PutWindowTilemap(1); + CopyWindowToVram(1, COPYWIN_GFX); + ScheduleBgCopyTilemapToVram(0); +} + +static void ShowYesNoWindow(s8 cursorPos) +{ + CreateYesNoMenu(&sYesNoWindowTemplate, FONT_1, 0, 2, 11, 14, 1); + Menu_MoveCursorNoWrapAround(cursorPos); +} + +static void ClearBottomWindow(void) +{ + ClearStdWindowAndFrameToTransparent(1, FALSE); + ScheduleBgCopyTilemapToVram(0); +} + +static void AddWallpaperSetsMenu(void) +{ + InitMenu(); + SetMenuText(MENU_TEXT_SCENERY_1); + SetMenuText(MENU_TEXT_SCENERY_2); + SetMenuText(MENU_TEXT_SCENERY_3); + SetMenuText(MENU_TEXT_ETCETERA); + AddMenu(); +} + +static void AddWallpapersMenu(u8 wallpaperSet) +{ + InitMenu(); + switch (wallpaperSet) + { + case 0: // SCENERY_1 + SetMenuText(MENU_TEXT_FOREST); + SetMenuText(MENU_TEXT_CITY); + SetMenuText(MENU_TEXT_DESERT); + SetMenuText(MENU_TEXT_SAVANNA); + break; + case 1: // SCENERY_2 + SetMenuText(MENU_TEXT_CRAG); + SetMenuText(MENU_TEXT_VOLCANO); + SetMenuText(MENU_TEXT_SNOW); + SetMenuText(MENU_TEXT_CAVE); + break; + case 2: // SCENERY_3 + SetMenuText(MENU_TEXT_BEACH); + SetMenuText(MENU_TEXT_SEAFLOOR); + SetMenuText(MENU_TEXT_RIVER); + SetMenuText(MENU_TEXT_SKY); + break; + case 3: // ETCETERA + SetMenuText(MENU_TEXT_POLKADOT); + SetMenuText(MENU_TEXT_POKECENTER); + SetMenuText(MENU_TEXT_MACHINE); + SetMenuText(MENU_TEXT_SIMPLE); + break; + } + AddMenu(); +} + +u8 GetCurrentBoxOption(void) +{ + return sCurrentBoxOption; +} + +static void InitCursorItemIcon(void) +{ + if (!IsCursorOnBoxTitle()) + { + if (sInPartyMenu) + TryLoadItemIconAtPos(CURSOR_AREA_IN_PARTY, GetBoxCursorPosition()); + else + TryLoadItemIconAtPos(CURSOR_AREA_IN_BOX, GetBoxCursorPosition()); + } + + if (sMovingItemId != ITEM_NONE) + { + InitItemIconInCursor(sMovingItemId); + StartCursorAnim(CURSOR_ANIM_FIST); + } +} + +static void SetPokeStorageQuestLogEvent(u8 action) +{ + u16 event; + struct PokeStorageQuestLogData *questLogData; + u8 box1 = GetMovingMonOriginalBoxId(); + u16 species1 = gStorage->displayMonSpecies; + u16 species2; + u8 box2; + if (sInPartyMenu) + { + box2 = TOTAL_BOXES_COUNT; + species2 = GetMonData(&gPlayerParty[GetBoxCursorPosition()], MON_DATA_SPECIES2); + } + else + { + box2 = StorageGetCurrentBox(); + species2 = GetCurrentBoxMonData(GetBoxCursorPosition(), MON_DATA_SPECIES2); + } + questLogData = &gStorage->pokeStorageQuestLogData; + + switch (action) + { + default: + return; + case 0: + if (sInPartyMenu) + { + if (box1 == TOTAL_BOXES_COUNT) + return; + else + event = QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON; + } + else + { + if (box1 == TOTAL_BOXES_COUNT) + // Should upmerge but doesn't + event = QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON; + else + event = box1 != box2 ? QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES : QL_EVENT_SWITCHED_MONS_WITHIN_BOX; + } + questLogData->species1 = species1; + questLogData->species2 = species2; + questLogData->box1 = box1; + questLogData->box2 = box2; + break; + case 1: + questLogData->species1 = species1; + questLogData->species2 = SPECIES_NONE; + questLogData->box1 = box1; + questLogData->box2 = 0xFF; + if (sInPartyMenu) + { + if (box1 == TOTAL_BOXES_COUNT) + return; + else + event = QL_EVENT_WITHDREW_MON_PC; + } + else + { + if (box1 == TOTAL_BOXES_COUNT) + { + event = QL_EVENT_DEPOSITED_MON_PC; + questLogData->box1 = box2; + } + else if (box1 != box2) + { + event = QL_EVENT_MOVED_MON_BETWEEN_BOXES; + questLogData->box2 = box2; + } + else + event = QL_EVENT_MOVED_MON_WITHIN_BOX; + } + break; + case 2: + event = QL_EVENT_DEPOSITED_MON_PC; + questLogData->species1 = species1; + questLogData->species2 = SPECIES_NONE; + questLogData->box1 = sDepositBoxId; + questLogData->box2 = 0xFF; + break; + case 3: + event = QL_EVENT_SWITCHED_MULTIPLE_MONS; + questLogData->species1 = SPECIES_NONE; + questLogData->species2 = SPECIES_NONE; + questLogData->box1 = box1; + questLogData->box2 = box2; + break; + } + SetQuestLogEvent(event, (const u16 *)questLogData); +} + +static void UpdateBoxToSendMons(void) +{ + if (sLastUsedBox != StorageGetCurrentBox()) + { + FlagClear(FLAG_SHOWN_BOX_WAS_FULL_MESSAGE); + VarSet(VAR_PC_BOX_TO_SEND_MON, StorageGetCurrentBox()); + } +} diff --git a/src/tilemap_util.c b/src/tilemap_util.c new file mode 100644 index 000000000..fe2f34866 --- /dev/null +++ b/src/tilemap_util.c @@ -0,0 +1,238 @@ +#include "global.h" +#include "bg.h" +#include "tilemap_util.h" +#include "malloc.h" + +// Handles 3 particular tilemaps ("PKMN Data" text, party menu, close box +// button) used for Pokémon Storage System in a somewhat unusual way. +// For example, while the cursor is on the Close Box button it flashes between +// two states alternately. Both these states are their own part of the same +// tilemap that's always present. The utility shifts the tilemap up and down +// to show/hide the states, and limits the view with a rectangle that only +// reveals one at a time. + +struct TilemapUtil_RectData +{ + s16 x; + s16 y; + u16 width; + u16 height; + s16 destX; + s16 destY; +}; + +struct TilemapUtil +{ + struct TilemapUtil_RectData prev; // Only read in unused function + struct TilemapUtil_RectData cur; + const void *savedTilemap; // Only written in unused function + const void *tilemap; + u16 altWidth; // Never read + u16 altHeight; // Never read + u16 width; + u16 height; + u16 rowSize; // Never read + u8 tileSize; + u8 bg; + bool8 active; // Only read in unused function +}; + +static EWRAM_DATA struct TilemapUtil *sTilemapUtil = NULL; +static EWRAM_DATA u16 sNumTilemapUtilIds = 0; + +static void TilemapUtil_DrawPrev(u8 tilemapId); +static void TilemapUtil_Draw(u8 tilemapId); + +static const struct { + u16 width; + u16 height; +} sTilemapDimensions[2][4] = { + { + { 256, 256}, + { 512, 256}, + { 256, 512}, + { 512, 512} + }, { + { 128, 128}, + { 256, 256}, + { 512, 512}, + {1024, 1024} + } +}; + +void TilemapUtil_Init(u8 numTilemapIds) +{ + u16 i; + sTilemapUtil = Alloc(numTilemapIds * sizeof(struct TilemapUtil)); + sNumTilemapUtilIds = sTilemapUtil == NULL ? 0 : numTilemapIds; + for (i = 0; i < sNumTilemapUtilIds; i++) + { + sTilemapUtil[i].savedTilemap = NULL; + sTilemapUtil[i].active = FALSE; + } +} + +void TilemapUtil_Free(void) +{ + Free(sTilemapUtil); +} + +// Unused +void TilemapUtil_UpdateAll(void) +{ + int i; + + for (i = 0; i < sNumTilemapUtilIds; i++) + { + if (sTilemapUtil[i].active == TRUE) + TilemapUtil_Update(i); + } +} + +void TilemapUtil_SetTilemap(u8 tilemapId, u8 bg, const void *tilemap, u16 width, u16 height) +{ + u16 screenSize; + u16 bgType; + + if (tilemapId < sNumTilemapUtilIds) + { + sTilemapUtil[tilemapId].savedTilemap = NULL; + sTilemapUtil[tilemapId].tilemap = tilemap; + sTilemapUtil[tilemapId].bg = bg; + sTilemapUtil[tilemapId].width = width; + sTilemapUtil[tilemapId].height = height; + + screenSize = GetBgAttribute(bg, BG_ATTR_SCREENSIZE); + bgType = GetBgAttribute(bg, BG_ATTR_BGTYPE); + sTilemapUtil[tilemapId].altWidth = sTilemapDimensions[bgType][screenSize].width; + sTilemapUtil[tilemapId].altHeight = sTilemapDimensions[bgType][screenSize].height; + if (bgType != 0) + sTilemapUtil[tilemapId].tileSize = 1; + else + sTilemapUtil[tilemapId].tileSize = 2; + sTilemapUtil[tilemapId].rowSize = width * sTilemapUtil[tilemapId].tileSize; + sTilemapUtil[tilemapId].cur.width = width; + sTilemapUtil[tilemapId].cur.height = height; + sTilemapUtil[tilemapId].cur.x = 0; + sTilemapUtil[tilemapId].cur.y = 0; + sTilemapUtil[tilemapId].cur.destX = 0; + sTilemapUtil[tilemapId].cur.destY = 0; + sTilemapUtil[tilemapId].prev = sTilemapUtil[tilemapId].cur; + sTilemapUtil[tilemapId].active = TRUE; + } +} + +// Unused +void TilemapUtil_SetSavedMap(u8 tilemapId, const void *tilemap) +{ + if (tilemapId < sNumTilemapUtilIds) + { + sTilemapUtil[tilemapId].savedTilemap = tilemap; + sTilemapUtil[tilemapId].active = TRUE; + } +} + +void TilemapUtil_SetPos(u8 tilemapId, u16 destX, u16 destY) +{ + if (tilemapId < sNumTilemapUtilIds) + { + sTilemapUtil[tilemapId].cur.destX = destX; + sTilemapUtil[tilemapId].cur.destY = destY; + sTilemapUtil[tilemapId].active = TRUE; + } +} + +void TilemapUtil_SetRect(u8 tilemapId, u16 x, u16 y, u16 width, u16 height) +{ + if (tilemapId < sNumTilemapUtilIds) + { + sTilemapUtil[tilemapId].cur.x = x; + sTilemapUtil[tilemapId].cur.y = y; + sTilemapUtil[tilemapId].cur.width = width; + sTilemapUtil[tilemapId].cur.height = height; + sTilemapUtil[tilemapId].active = TRUE; + } +} + +void TilemapUtil_Move(u8 tilemapId, u8 mode, s8 param) +{ + if (tilemapId < sNumTilemapUtilIds) + { + switch (mode) + { + case 0: + sTilemapUtil[tilemapId].cur.destX += param; + sTilemapUtil[tilemapId].cur.width -= param; + break; + case 1: + sTilemapUtil[tilemapId].cur.x += param; + sTilemapUtil[tilemapId].cur.width += param; + break; + case 2: + sTilemapUtil[tilemapId].cur.destY += param; + sTilemapUtil[tilemapId].cur.height -= param; + break; + case 3: // this is the only mode ever used + sTilemapUtil[tilemapId].cur.y -= param; + sTilemapUtil[tilemapId].cur.height += param; + break; + case 4: + sTilemapUtil[tilemapId].cur.destX += param; + break; + case 5: + sTilemapUtil[tilemapId].cur.destY += param; + break; + } + sTilemapUtil[tilemapId].active = TRUE; + } +} + +void TilemapUtil_Update(u8 tilemapId) +{ + if (tilemapId < sNumTilemapUtilIds) + { + if (sTilemapUtil[tilemapId].savedTilemap != NULL) // Always false + TilemapUtil_DrawPrev(tilemapId); + TilemapUtil_Draw(tilemapId); + sTilemapUtil[tilemapId].prev = sTilemapUtil[tilemapId].cur; + } +} + +// Never called, see TilemapUtil_Update +static void TilemapUtil_DrawPrev(u8 tilemapId) +{ + int i; + int rowSize = sTilemapUtil[tilemapId].tileSize * sTilemapUtil[tilemapId].altWidth; + const void *tiles = sTilemapUtil[tilemapId].savedTilemap + + rowSize * sTilemapUtil[tilemapId].prev.destY + + sTilemapUtil[tilemapId].prev.destX * sTilemapUtil[tilemapId].tileSize; + for (i = 0; i < sTilemapUtil[tilemapId].prev.height; i++) + { + CopyToBgTilemapBufferRect(sTilemapUtil[tilemapId].bg, + tiles, + sTilemapUtil[tilemapId].prev.destX, + sTilemapUtil[tilemapId].prev.destY + i, + sTilemapUtil[tilemapId].prev.width, + 1); + tiles += rowSize; + } +} + +static void TilemapUtil_Draw(u8 tilemapId) +{ + int i; + int rowSize = sTilemapUtil[tilemapId].tileSize * sTilemapUtil[tilemapId].width; + const void *tiles = sTilemapUtil[tilemapId].tilemap + + rowSize * sTilemapUtil[tilemapId].cur.y + + sTilemapUtil[tilemapId].cur.x * sTilemapUtil[tilemapId].tileSize; + for (i = 0; i < sTilemapUtil[tilemapId].cur.height; i++) + { + CopyToBgTilemapBufferRect(sTilemapUtil[tilemapId].bg, + tiles, + sTilemapUtil[tilemapId].cur.destX, + sTilemapUtil[tilemapId].cur.destY + i, + sTilemapUtil[tilemapId].cur.width, + 1); + tiles += rowSize; + } +} diff --git a/src/tm_case.c b/src/tm_case.c index 43d590c40..8b77972ab 100644 --- a/src/tm_case.c +++ b/src/tm_case.c @@ -953,7 +953,7 @@ static void Task_SelectTMAction_Type3(u8 taskId) if (!itemid_is_unique(BagGetItemIdByPocketPosition(POCKET_TM_CASE, data[1]))) { - sTMCaseDynamicResources->savedCallback = Cb2_ReturnToPSS; + sTMCaseDynamicResources->savedCallback = CB2_ReturnToPokeStorage; Task_BeginFadeOutFromTMCase(taskId); } else diff --git a/sym_bss.txt b/sym_bss.txt index 63a52555c..9f50fd0a7 100644 --- a/sym_bss.txt +++ b/sym_bss.txt @@ -16,7 +16,7 @@ .include "src/tileset_anims.o" .include "src/sound.o" .include "src/field_effect.o" - .include "src/pokemon_storage_system_8.o" + .include "src/pokemon_storage_system_misc.o" .include "src/easy_chat.o" .include "src/link_rfu_2.o" .include "src/link_rfu_3.o" diff --git a/sym_ewram.txt b/sym_ewram.txt index a3766873e..ef48abffa 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -38,11 +38,10 @@ .include "src/scanline_effect.o" .include "src/option_menu.o" .include "src/trainer_card.o" - .include "src/pokemon_storage_system_2.o" - .include "src/pokemon_storage_system_3.o" - .include "src/pokemon_storage_system_5.o" - .include "src/pokemon_storage_system_7.o" - .include "src/pokemon_storage_system_8.o" + .include "src/pokemon_storage_system_menu.o" + .include "src/pokemon_storage_system_tasks.o" + .include "src/pokemon_storage_system_data.o" + .include "src/pokemon_storage_system_misc.o" .include "src/script_movement.o" .include "src/fldeff_cut.o" .include "src/item_menu_icons.o" @@ -84,7 +83,7 @@ .include "src/save_failed_screen.o" .include "src/clear_save_data_screen.o" .include "src/new_menu_helpers.o" - .include "src/box_party_pokemon_dropdown.o" + .include "src/tilemap_util.o" .include "src/map_preview_screen.o" .include "src/link_rfu_2.o" .include "src/link_rfu_3.o"