mirror of
https://github.com/GearsProgress/Poke_Transporter_GB.git
synced 2026-03-21 17:34:42 -05:00
Add a binary table format and convert the text entries into this format in text_helper/main.py. It then gets compressed with zx0. The new text_data_table and streamed_data_table classes exist to read the various entries from this binary table. streamed_data_table specifically exists to use a decompression buffer that is smaller than the actual binary table. But it requires a decompression buffer that is still larger than ZX0_DEFAULT_WINDOW_SIZE (default: 2048 bytes) and will only be able to decompress in chunks of (<decompression_buffer_size> - <ZX0_DEFAULT_WINDOW_SIZE>) bytes Try to keep the binary text tables sufficiently small though, because since zx0 doesn't actually support random access, getting to the last entry is significantly more expensive than reading the first one. And unless you use streamed_data_table, it also requires <uncompressed_size> bytes of stack space, therefore IWRAM to decompress them. I also had to rework script_array because it can no longer reference the strings directly. Instead we now reference the DIA_* "enum" values. We also no longer store an array of script_obj instances, because these were getting stored in IWRAM since they're non-const global variables originally. Instead we now have const arrays of script_obj_params structs, which should end up in .rodata -> therefore EWRAM. Right now, script_obj only supports the PTGB text table (originally the dialogue array). But if the need arises to support other tables as well, I'd consider adding a separate enum to script_obj_params to indicate the specific table. The compilation process will also output .su files in the build folder from now on. These files indicate the stack frame size for every function in every compilation unit, so be sure to check them from time to time. Note that they will only show the stack consumption for that specific function. So to get the worst case stack consumption, you need to manually add all the functions in a certain stack flow.
152 lines
3.9 KiB
C++
152 lines
3.9 KiB
C++
#include "select_menu.h"
|
|
#include "sprite_data.h"
|
|
#include "translated_text.h"
|
|
#include "text_data_table.h"
|
|
|
|
#define TEXT_HEIGHT 10
|
|
#define TEXT_WIDTH 8
|
|
#define TILE_HEIGHT 8
|
|
#define TILE_WIDTH 8
|
|
|
|
Select_Menu::Select_Menu(bool enable_cancel, u8 nMenu_type, int nStartTileX, int nStartTileY)
|
|
{
|
|
cancel_enabled = enable_cancel;
|
|
menu_type = nMenu_type;
|
|
startTileX = nStartTileX;
|
|
startTileY = nStartTileY;
|
|
}
|
|
|
|
void Select_Menu::add_option(const u8 option, u8 return_value)
|
|
{
|
|
menu_options.push_back(option);
|
|
return_values.push_back(return_value);
|
|
}
|
|
|
|
int Select_Menu::select_menu_main()
|
|
{
|
|
show_menu();
|
|
curr_selection = 0;
|
|
|
|
key_poll(); // Reset the buttons
|
|
|
|
bool update;
|
|
bool first = true;
|
|
while (true)
|
|
{
|
|
update = false;
|
|
if (key_hit(KEY_DOWN))
|
|
{
|
|
curr_selection = ((curr_selection + 1) % menu_options.size());
|
|
update = true;
|
|
}
|
|
else if (key_hit(KEY_UP))
|
|
{
|
|
curr_selection = ((curr_selection + (menu_options.size() - 1)) % menu_options.size());
|
|
update = true;
|
|
}
|
|
else if (key_hit(KEY_A))
|
|
{
|
|
hide_menu();
|
|
return return_values[curr_selection];
|
|
}
|
|
else if (cancel_enabled && key_hit(KEY_B))
|
|
{
|
|
hide_menu();
|
|
return -1;
|
|
}
|
|
else if (first)
|
|
{
|
|
update = true;
|
|
first = false;
|
|
}
|
|
update_y_offset();
|
|
obj_set_pos(
|
|
point_arrow,
|
|
(startTileX + 1) * TEXT_WIDTH,
|
|
(startTileY + 1) * TILE_HEIGHT + (curr_selection * TEXT_HEIGHT) + 2);
|
|
global_next_frame();
|
|
|
|
if (update)
|
|
{
|
|
if (return_values[curr_selection] == UINT8_MAX)
|
|
{
|
|
switch (menu_type)
|
|
{
|
|
case CART_MENU:
|
|
obj_hide(cart_shell);
|
|
obj_hide(cart_label);
|
|
break;
|
|
case LANG_MENU:
|
|
obj_hide(flag);
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
switch (menu_type)
|
|
{
|
|
case CART_MENU:
|
|
load_select_sprites(return_values[curr_selection], lang);
|
|
obj_unhide(cart_shell, 0);
|
|
obj_unhide(cart_label, 0);
|
|
break;
|
|
case LANG_MENU:
|
|
load_select_sprites(0, return_values[curr_selection]);
|
|
obj_unhide(flag, 0);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void Select_Menu::show_menu()
|
|
{
|
|
u8 decompression_buffer[2048];
|
|
text_data_table text_data(decompression_buffer);
|
|
text_data.decompress(get_compressed_general_table());
|
|
|
|
add_menu_box(menu_options.size(), startTileX, startTileY);
|
|
for (unsigned int i = 0; i < menu_options.size(); i++)
|
|
{
|
|
tte_set_pos((startTileX + 2) * TEXT_WIDTH, (startTileY + 1) * TILE_HEIGHT + (i * TEXT_HEIGHT));
|
|
ptgb_write(text_data.get_text_entry(menu_options[i]), true);
|
|
}
|
|
obj_unhide(point_arrow, 0);
|
|
// obj_set_pos(point_arrow, startTileX + (2 * TEXT_WIDTH), (1 + i) * TEXT_HEIGHT);
|
|
}
|
|
|
|
void Select_Menu::hide_menu()
|
|
{
|
|
obj_hide(point_arrow);
|
|
tte_erase_rect(
|
|
startTileX * TILE_WIDTH,
|
|
startTileY * TILE_HEIGHT,
|
|
(startTileX + 10 + 1) * TEXT_WIDTH,
|
|
((startTileY + 2) * TILE_HEIGHT) + (menu_options.size() * TEXT_HEIGHT));
|
|
reload_textbox_background();
|
|
clear_options();
|
|
obj_hide(point_arrow);
|
|
switch (menu_type)
|
|
{
|
|
case CART_MENU:
|
|
obj_hide(cart_shell);
|
|
obj_hide(cart_label);
|
|
break;
|
|
case LANG_MENU:
|
|
obj_hide(flag);
|
|
break;
|
|
}
|
|
}
|
|
|
|
void Select_Menu::clear_options()
|
|
{
|
|
menu_options.clear();
|
|
return_values.clear();
|
|
}
|
|
|
|
void Select_Menu::set_lang(u8 nLang)
|
|
{
|
|
lang = nLang;
|
|
} |