diff --git a/include/text_engine.h b/include/text_engine.h index 4c55ff9..21e339f 100644 --- a/include/text_engine.h +++ b/include/text_engine.h @@ -6,10 +6,6 @@ #define H_MAX 240 #define V_MAX 160 -#define LEFT 8 -#define RIGHT (H_MAX - LEFT) -#define TOP 120 -#define BOTTOM V_MAX #define INK_WHITE 15 #define INK_ROM_COLOR 14 @@ -23,11 +19,11 @@ void init_text_engine(); int text_loop(int script); int text_next_obj_id(script_obj current_line); void set_text_exit(); -int ptgb_write_textbox(const byte *text, bool instant, int text_section, int text_key, bool eraseMainBox); +int ptgb_write_textbox(const byte *text, bool instant, bool waitForUser, int text_section, int text_key, bool eraseMainBox); int ptgb_write_simple(const byte *text, bool instant); -int ptgb_write(const byte *text, bool instant, int length); +int ptgb_write(const byte *text, bool instant, int length, int box_type); int ptgb_write_debug(const u16* charset, const char *text, bool instant); -void wait_for_user_to_continue(bool clear_text); -void scroll_text(bool instant, TTC *tc); +void wait_for_user_to_continue(); +void scroll_text(bool instant, TTC *tc, int left, int top, int right, int bottom); #endif \ No newline at end of file diff --git a/source/background_engine.cpp b/source/background_engine.cpp index 36b1366..bf2feb6 100644 --- a/source/background_engine.cpp +++ b/source/background_engine.cpp @@ -20,7 +20,8 @@ void background_frame(int global_frame_count) } void create_textbox(int startTileX, int startTileY, int text_space_width, int text_space_height, bool eraseMainBox) -{ // Empty function for compiling +{ + // Blank for compiling for now } // This could honestly be an object... might want to do that in the future, depending on how complex using this gets @@ -38,16 +39,17 @@ void create_textbox_new(int text_section, int text_key, bool eraseMainBox) add_menu_box(startTileX, startTileY, text_space_width + 16, text_space_height + 16); tte_set_pos((startTileX + 1) * 8, (startTileY + 1) * 8); tte_set_margins((startTileX + 1) * 8, (startTileY + 1) * 8, - (startTileX + text_space_width) * 8, (startTileY + text_space_height) * 8); + ((startTileX + 1) * 8) + text_space_width, ((startTileY + 1) * 8) + text_space_height); tte_erase_rect(0, 0, H_MAX, V_MAX); + show_textbox(); } void reset_textbox() { - tte_erase_rect(0, 0, H_MAX, V_MAX); + //tte_erase_rect(0, 0, H_MAX, V_MAX); reload_textbox_background(); - tte_set_pos(LEFT, TOP); - tte_set_margins(LEFT, TOP, RIGHT, BOTTOM); + //tte_set_pos(, TOP); + //tte_set_margins(LEFT, TOP, RIGHT, BOTTOM); } void show_textbox() diff --git a/source/button_menu.cpp b/source/button_menu.cpp index acead91..fffde84 100644 --- a/source/button_menu.cpp +++ b/source/button_menu.cpp @@ -30,7 +30,6 @@ void Button_Menu::set_xy_min_max(int nX_min, int nX_max, int nY_min, int nY_max) int Button_Menu::button_main() { - tte_set_pos(0, 0); organize_buttons(); show_buttons(); button_vector.at(curr_position).set_highlight(true); diff --git a/source/dbg/debug_menu.cpp b/source/dbg/debug_menu.cpp index e360ad1..3cfb535 100644 --- a/source/dbg/debug_menu.cpp +++ b/source/dbg/debug_menu.cpp @@ -30,7 +30,7 @@ void show_debug_menu() const vertical_menu_settings menu_settings = { .x = 20, .y = 0, - .width = 200, + .width = 208, .height = 155, .margin_top = 8, .margin_bottom = 8, diff --git a/source/flash_mem.cpp b/source/flash_mem.cpp index 498c733..c5d5da8 100644 --- a/source/flash_mem.cpp +++ b/source/flash_mem.cpp @@ -106,7 +106,7 @@ void print_mem_section() out[0] = get_char_from_charset(charset, mem_name); out[1] = get_char_from_charset(charset, '-'); out[2] = get_char_from_charset(charset, mem_id + 0xA1); // Kinda a dumb way to - tte_set_pos(0, 0); + //tte_set_pos(0, 0); ptgb_write_simple(out, true); */ } @@ -153,7 +153,7 @@ bool read_flag(u16 flag_id) { if (false) { - tte_set_pos(0, 0); + //tte_set_pos(0, 0); tte_write("#{cx:0xD000}Attempting to read byte "); tte_write(ptgb::to_string((curr_GBA_rom.offset_flags + (flag_id / 8)) % 0xF80)); tte_write(" of memory section "); diff --git a/source/gameboy_colour.cpp b/source/gameboy_colour.cpp index b7da21c..9815b4a 100644 --- a/source/gameboy_colour.cpp +++ b/source/gameboy_colour.cpp @@ -122,8 +122,7 @@ void print(const char *format, ...) npf_vsnprintf(spi_text_out_array[0], SPI_TEXT_OUT_ARRAY_ELEMENT_SIZE, format, args); va_end(args); - tte_erase_rect(LEFT, TOP, RIGHT, BOTTOM); - tte_set_pos(LEFT, 0); + tte_erase_rect(0, 0, H_MAX, V_MAX); for (int j = 0; j < 10; j++) { ptgb_write_simple(reinterpret_cast("#{cx:0xE000}"), true); @@ -162,15 +161,13 @@ void setup(const u16 *debug_charset) failed_packet = false; init_packet = true; end_of_data = false; - - create_textbox(5, 1, 128, 60, true); - { u8 general_text_table_buffer[2048]; text_data_table general_text(general_text_table_buffer); general_text.decompress(get_compressed_text_table(GENERAL_INDEX)); - ptgb_write_simple(general_text.get_text_entry(GENERAL_connecting), true); + ptgb_write_textbox(general_text.get_text_entry(GENERAL_connecting), true, true, + GENERAL_INDEX, GENERAL_connecting, true); } } @@ -222,8 +219,6 @@ byte handleIncomingByte(byte in, byte *box_data_storage, byte *curr_payload, GB_ { if (in == 0x60 || in == 0x61) { - tte_erase_rect(0, 0, H_MAX, V_MAX); - tte_set_pos(40, 24); { u8 general_text_table_buffer[2048]; text_data_table general_text(general_text_table_buffer); @@ -274,8 +269,6 @@ byte handleIncomingByte(byte in, byte *box_data_storage, byte *curr_payload, GB_ { if (in == 0xfd) { - tte_erase_rect(0, 0, H_MAX, V_MAX); - tte_set_pos(40, 24); { u8 general_text_table_buffer[2048]; text_data_table general_text(general_text_table_buffer); @@ -385,11 +378,8 @@ int loop(byte *box_data_storage, byte *curr_payload, GB_ROM *curr_gb_rom, PokeBo if (g_debug_options.print_link_data && !key_held(KEY_DOWN)) { - // tte_set_margins(0, 0, H_MAX, V_MAX); - // print("%d: [%d][%d][%" PRIu8 "][%" PRIu8 "]\n\n", counter, data_counter, state, in_data, out_data); for (int i = 0; i < NUM_LINES; i++) { - // ptgb_write_debug(debug_charset, "\n", true); for (int j = 0; j < LINE_WIDTH; j++) { stuff[i][j] = stuff[i + 1][j]; @@ -407,7 +397,7 @@ int loop(byte *box_data_storage, byte *curr_payload, GB_ROM *curr_gb_rom, PokeBo n2hexstr(&stuff[NUM_LINES - 1][18], out_data & 0xFF, 2); stuff[NUM_LINES - 1][20] = '\0'; - create_textbox(0, 0, 125, 80, false); + // create_textbox(0, 0, 125, 80, false); ptgb_write_debug(debug_charset, *stuff, true); } else if (g_debug_options.write_cable_data_to_save) @@ -616,7 +606,7 @@ byte exchange_boxes(byte curr_in, byte *box_data_storage, GB_ROM *curr_gb_rom, c n2hexstr(&outArr[currRow][14], init_packet, 2); outArr[currRow][16] = ' '; - create_textbox(0, 0, 125, 110, false); + //create_textbox(0, 0, 125, 110, false); link_animation_state(0); ptgb_write_debug(debug_charset, *outArr, true); diff --git a/source/global_frame_controller.cpp b/source/global_frame_controller.cpp index 87e4a1f..0e8c2c0 100644 --- a/source/global_frame_controller.cpp +++ b/source/global_frame_controller.cpp @@ -28,7 +28,7 @@ static void __attribute__((noinline)) show_pulled_cart_error() text_data_table general_text(general_text_table_buffer); general_text.decompress(get_compressed_text_table(GENERAL_INDEX)); - ptgb_write_textbox(general_text.get_text_entry(GENERAL_pulled_cart_error), true, + ptgb_write_textbox(general_text.get_text_entry(GENERAL_pulled_cart_error), true, true, GENERAL_INDEX, GENERAL_pulled_cart_error, true); } @@ -36,8 +36,6 @@ void global_next_frame() { key_poll(); rand_next_frame(); - // tte_set_pos(0, 0); - // tte_write(ptgb::to_string(get_rand_u32())); background_frame(global_frame_count); determine_fennel_blink(); if (missingno_enabled) @@ -53,7 +51,6 @@ void global_next_frame() { BG_BACKDROP = (BG_BACKDROP & ~BG_PRIO_MASK) | BG_PRIO(2); BG_TEXTBOX = (BG_TEXTBOX & ~BG_PRIO_MASK) | BG_PRIO(1); - tte_set_pos(40, 24); obj_hide_multi(ptgb_logo_l, num_sprites); show_pulled_cart_error(); diff --git a/source/main.cpp b/source/main.cpp index fa85de7..38a85a1 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -58,8 +58,7 @@ Button_Menu yes_no_menu(1, 2, 40, 24, false); void load_graphics() { - tte_erase_rect(0, 0, H_MAX, V_MAX); - // Load opening background first so it hides everything else + // Load opening background first so it hides everything else load_flex_background(FLEXBG_OPENING, 1); load_background(); load_textbox_background(); @@ -84,7 +83,7 @@ void initialization_script(void) irq_init(NULL); irq_enable(II_VBLANK); // This currently crashes when you try to transfer a Pokemon: - //sound_init(); + // sound_init(); // Graphics init oam_init(obj_buffer, 128); @@ -97,7 +96,6 @@ void initialization_script(void) rand_set_seed(0x1216); // Clean up the main screen quick - tte_erase_rect(0, 0, 240, 160); VBlankIntrWait(); REG_DISPCNT &= ~DCNT_BLANK; @@ -107,14 +105,13 @@ void game_load_error(void) { BG_TEXTBOX = (BG_TEXTBOX & ~BG_PRIO_MASK) | BG_PRIO(1); - create_textbox(4, 1, 152, 100, true); - { u8 general_text_table_buffer[2048]; text_data_table general_text(general_text_table_buffer); general_text.decompress(get_compressed_text_table(GENERAL_INDEX)); - ptgb_write_simple(general_text.get_text_entry(GENERAL_cart_load_error), true); + ptgb_write_textbox(general_text.get_text_entry(GENERAL_cart_load_error), true, true, + GENERAL_INDEX, GENERAL_cart_load_error, true); } key_poll(); @@ -123,8 +120,6 @@ void game_load_error(void) global_next_frame(); } while (!key_hit(KEY_A) && !key_hit(KEY_SELECT)); - tte_erase_rect(0, 0, H_MAX, V_MAX); - if (key_hit(KEY_SELECT)) { // We also want to give the option in this screen to upload the multiboot rom to another GBA. @@ -147,8 +142,6 @@ void game_load_error(void) void first_load_message(void) { - tte_set_margins(8, 8, H_MAX - 8, V_MAX); - tte_set_pos(8, 8); tte_set_ink(INK_ROM_COLOR); { @@ -163,7 +156,6 @@ void first_load_message(void) { global_next_frame(); } - tte_erase_rect(0, 0, H_MAX, V_MAX); } int credits() @@ -180,16 +172,16 @@ int credits() { if (update) { - create_textbox(1, 1, 200, 120, true); - show_textbox(); - ptgb_write_simple(credits_text_table.get_text_entry(curr_credits_num), true); + ptgb_write_textbox(credits_text_table.get_text_entry(curr_credits_num), true, false, + CREDITS_INDEX, curr_credits_num, false); update = false; } if (key_hit(KEY_B)) { + tte_erase_rect(0, 0, H_MAX, V_MAX); hide_textbox(); - reset_textbox(); + erase_textbox_tiles(); return 0; } if (key_hit(KEY_LEFT) && curr_credits_num > 0) @@ -225,7 +217,6 @@ int main_menu_loop() { if (update) { - tte_erase_rect(0, 80, 240, 160); for (int i = 0; i < NUM_MENU_OPTIONS; i++) { text_entry = general_text.get_text_entry(menu_options[i]); @@ -257,7 +248,6 @@ int main_menu_loop() else if (key_hit(KEY_A)) { tte_erase_rect(0, test, H_MAX, V_MAX); - ptgb_write_simple(reinterpret_cast("#{cx:0xF000}"), true); return return_values[curr_selection]; } else if ((key_held(KEY_L) && key_held(KEY_R))) @@ -273,28 +263,9 @@ int main_menu_loop() } } -// Legal stuff -static void show_legal_text(const u8 *intro_text) -{ - tte_set_margins(4, 0, H_MAX - 4, V_MAX); - tte_set_pos(4, 0); - tte_set_ink(INK_ROM_COLOR); - ptgb_write_simple(intro_text, true); - bool wait = true; - while (wait) - { - global_next_frame(); - if (key_hit(KEY_A)) - { - wait = false; - } - } -} - // Gears of Progress static void show_gears_of_progress() { - tte_erase_rect(0, 0, 240, 160); REG_BG1VOFS = 0; delay_counter = 0; while (delay_counter < (15 * 60)) @@ -316,20 +287,17 @@ static void __attribute__((noinline)) show_intro() { bool start_pressed = false; u8 general_text_table_buffer[2048]; - u8 press_start_text[32]; - u8 press_start_text_length; text_data_table general_text(general_text_table_buffer); const u8 *text_entry; general_text.decompress(get_compressed_text_table(GENERAL_INDEX)); - - text_entry = general_text.get_text_entry(GENERAL_press_start); - press_start_text_length = get_string_char_count(text_entry); - memcpy(press_start_text, text_entry, press_start_text_length + 1); text_entry = general_text.get_text_entry(GENERAL_intro_legal); - show_legal_text(text_entry); + tte_set_ink(INK_ROM_COLOR); + ptgb_write_textbox(text_entry, true, true, + GENERAL_INDEX, GENERAL_intro_legal, true); + show_gears_of_progress(); BG_FLEX = BG_FLEX | BG_PRIO(3); @@ -343,22 +311,12 @@ static void __attribute__((noinline)) show_intro() REG_BLDCNT = BLD_BUILD(BLD_BG3, BLD_BG0, 1); -#ifndef PTGB_BUILD_LANGUAGE - -#error PTGB_NOT_DEFINED -#endif -#ifndef JPN_ID -#error JPN_ID_NOT_DEFINED -#endif -#pragma message "PTGB_BUILD_LANGUAGE=" PTGB_BUILD_LANGUAGE -#pragma message "JPN_ID=" JPN_ID - - int char_width = (PTGB_BUILD_LANGUAGE == JPN_ID ? 8 : 6); - int x = ((240 - (press_start_text_length * char_width)) / 2); - tte_set_pos(x, 12 * 8); + general_text.decompress(get_compressed_text_table(GENERAL_INDEX)); + text_entry = general_text.get_text_entry(GENERAL_press_start); + tte_set_pos(0, 12 * 8); tte_set_ink(INK_DARK_GREY); - ptgb_write_simple(press_start_text, true); + ptgb_write_simple(text_entry, true); int fade = 0; while (!start_pressed) @@ -383,7 +341,6 @@ int main(void) { first_load_message(); }*/ - show_intro(); key_poll(); @@ -408,7 +365,6 @@ int main(void) } // Initialize memory and save data after loading the game - reset_textbox(); BG_TEXTBOX = BG_TEXTBOX | BG_PRIO(3); init_bank(); initialize_memory_locations(); @@ -462,11 +418,8 @@ int main(void) break; case (BTN_CREDITS): tte_set_ink(INK_DARK_GREY); - // create_textbox(0, 0, 160, 80, true); - // show_textbox(); BG_FLEX = (BG_FLEX & ~BG_PRIO_MASK) | BG_PRIO(3); - obj_set_pos(ptgb_logo_l, 56, 108); - obj_set_pos(ptgb_logo_r, 56 + 64, 108); + obj_hide_multi(ptgb_logo_l, 2); credits(); break; case (BTN_EVENTS): diff --git a/source/multiboot_upload.cpp b/source/multiboot_upload.cpp index e5c0cdc..101c5c7 100644 --- a/source/multiboot_upload.cpp +++ b/source/multiboot_upload.cpp @@ -9,7 +9,7 @@ static void multiboot_show_textbox() { - tte_erase_rect(0, 0, RIGHT, BOTTOM); + tte_erase_rect(0, 0, H_MAX, V_MAX); create_textbox(4, 1, 152, 100, true); } @@ -52,7 +52,6 @@ void multiboot_upload_screen() // (when this returns true, the transfer will be canceled) }); // show result - // clear_textbox(); multiboot_show_textbox(); if (multibootResult == LinkCableMultiboot::Result::SUCCESS) { diff --git a/source/rom_data.cpp b/source/rom_data.cpp index 3b5f905..8d03cf6 100644 --- a/source/rom_data.cpp +++ b/source/rom_data.cpp @@ -180,7 +180,6 @@ void rom_data::print_rom_info() npf_snprintf(buffer, sizeof(buffer), "%c-%d-%c", gameTypeChar, version, language); - tte_set_pos(0, 8); ptgb_write_simple(reinterpret_cast(buffer), true); } diff --git a/source/sprite_data.cpp b/source/sprite_data.cpp index 0e170e5..dc0deb1 100644 --- a/source/sprite_data.cpp +++ b/source/sprite_data.cpp @@ -275,37 +275,37 @@ void add_menu_box(int startTileX, int startTileY, int full_width, int full_heigh int SBB = 20; int start = (32 * startTileY) + startTileX; - int tiles = (full_height / 8) - 2; // For the extra 2 tiles - int rem = full_height % 8; - full_width /= 8; + int tiles = (full_height / 8) - 1; // For the flex edge + int vert_rem = full_height % 8; + full_width = (full_width / 8) - 1; // For the right edge // Corners se_mem[SBB][start] = TILE_NW; se_mem[SBB][start + full_width] = TILE_NE; - se_mem[SBB][start + (32 * (tiles + 1))] = TILE_SW_U_ARR[rem / 2]; - se_mem[SBB][start + (32 * (tiles + 2))] = TILE_SW_L_ARR[rem / 2]; - se_mem[SBB][start + (32 * (tiles + 1)) + full_width] = TILE_SE_U_ARR[rem / 2]; - se_mem[SBB][start + (32 * (tiles + 2)) + full_width] = TILE_SE_L_ARR[rem / 2]; + se_mem[SBB][start + (32 * (tiles))] = TILE_SW_U_ARR[vert_rem / 2]; + se_mem[SBB][start + (32 * (tiles + 1))] = TILE_SW_L_ARR[vert_rem / 2]; + se_mem[SBB][start + (32 * (tiles)) + full_width] = TILE_SE_U_ARR[vert_rem / 2]; + se_mem[SBB][start + (32 * (tiles + 1)) + full_width] = TILE_SE_L_ARR[vert_rem / 2]; // Top and bottom edge for (int i = 1; i < full_width; i++) { se_mem[SBB][start + i] = TILE_N; - se_mem[SBB][start + ((32 * (tiles + 1))) + i] = TILE_S_U_ARR[rem / 2]; - se_mem[SBB][start + ((32 * (tiles + 2))) + i] = TILE_S_L_ARR[rem / 2]; + se_mem[SBB][start + ((32 * (tiles))) + i] = TILE_S_U_ARR[vert_rem / 2]; + se_mem[SBB][start + ((32 * (tiles + 1))) + i] = TILE_S_L_ARR[vert_rem / 2]; } // Sides - for (int i = 0; i < tiles; i++) + for (int i = 1; i < tiles; i++) { - se_mem[SBB][start + (32 * (i + 1)) + full_width] = TILE_E; - se_mem[SBB][start + (32 * (i + 1))] = TILE_W; + se_mem[SBB][start + (32 * i) + full_width] = TILE_E; + se_mem[SBB][start + (32 * i)] = TILE_W; } // Middle for (int x = 1; x < full_width; x++) { - for (int y = 1; y < tiles + 1; y++) + for (int y = 1; y < tiles; y++) { se_mem[SBB][start + (32 * y) + x] = TILE_MID; } diff --git a/source/text_engine.cpp b/source/text_engine.cpp index 38f3923..e4a9b5c 100644 --- a/source/text_engine.cpp +++ b/source/text_engine.cpp @@ -125,17 +125,15 @@ int text_loop(int script) if (script != SCRIPT_DEBUG) { BG_FLEX = (BG_FLEX && !BG_PRIO_MASK) | BG_PRIO(2); // Show Fennel - show_textbox(); - while (true) // This loops through all the connected script objects + while (true) // This loops through all the connected script objects { if (curr_text != NULL && curr_text[char_index] != 0xFF && curr_text[char_index] != 0xFB) { - tte_set_pos(LEFT, TOP); - tte_erase_rect(LEFT, TOP, RIGHT, BOTTOM); - ptgb_write_simple(curr_text, false); + ptgb_write_textbox(curr_text, false, true, + PTGB_INDEX, curr_line.get_text_entry_index(), true); } - wait_for_user_to_continue(false); + // wait_for_user_to_continue(); line_char_index = 0; switch (script) @@ -154,7 +152,8 @@ int text_loop(int script) if (text_exit) { hide_textbox(); - tte_erase_rect(LEFT, TOP, RIGHT, BOTTOM); + // tte_erase_rect(LEFT, TOP, RIGHT, BOTTOM); + tte_erase_screen(); text_exit = false; return 0; } @@ -166,7 +165,7 @@ int text_loop(int script) load_localized_charset(debug_charset, 3, ENGLISH); int text_section = 0; - int text_identifier = 0; + int text_key = 0; while (true) { bool exit = false; @@ -177,12 +176,12 @@ int text_loop(int script) { if (key_hit(KEY_LEFT)) { - text_identifier = (text_identifier + (text_section_lengths[text_section] - 1)) % text_section_lengths[text_section]; + text_key = (text_key + (text_section_lengths[text_section] - 1)) % text_section_lengths[text_section]; update_text = true; } else if (key_hit(KEY_RIGHT)) { - text_identifier = (text_identifier + 1) % text_section_lengths[text_section]; + text_key = (text_key + 1) % text_section_lengths[text_section]; update_text = true; } else if (key_hit(KEY_UP)) @@ -199,12 +198,13 @@ int text_loop(int script) { instant_text = key_hit(KEY_START); // instant with start, not with select exit = true; + tte_erase_line(); } if (update_text) { - if (text_identifier > text_section_lengths[text_section]) + if (text_key > text_section_lengths[text_section]) { - text_identifier = text_section_lengths[text_section]; + text_key = text_section_lengths[text_section]; } if (text_section > NUM_TEXT_SECTIONS) { @@ -215,7 +215,7 @@ int text_loop(int script) ptgb_write_debug(debug_charset, "(", true); ptgb_write_debug(debug_charset, ptgb::to_string(text_section), true); ptgb_write_debug(debug_charset, ", ", true); - ptgb_write_debug(debug_charset, ptgb::to_string(text_identifier), true); + ptgb_write_debug(debug_charset, ptgb::to_string(text_key), true); ptgb_write_debug(debug_charset, ")", true); update_text = false; } @@ -223,27 +223,19 @@ int text_loop(int script) } line_char_index = 0; - curr_text = read_dialogue_text_entry(text_identifier, text_section, diag_entry_text_buffer); + curr_text = read_dialogue_text_entry(text_key, text_section, diag_entry_text_buffer); char_index = 0; if (curr_text != NULL && curr_text[char_index] != 0xFF && curr_text[char_index] != 0xFB) { - if (text_section == PTGB_INDEX) - { - reset_textbox(); - } - else - { - create_textbox(4, 1, 160, 80, true); - } - show_textbox(); - tte_erase_rect(0, 0, 240, 160); - ptgb_write_simple(curr_text, instant_text); + ptgb_write_textbox(curr_text, instant_text, true, + text_section, text_key, true); } - wait_for_user_to_continue(false); + // wait_for_user_to_continue(); update_text = true; hide_textbox(); + tte_erase_rect(0, 0, H_MAX, V_MAX); if (text_exit) { @@ -279,41 +271,60 @@ void set_text_exit() } // Implement a version that creates the textbox as well -int ptgb_write_textbox(const byte *text, bool instant, +int ptgb_write_textbox(const byte *text, bool instant, bool waitForUser, int text_section, int text_key, bool eraseMainBox) { create_textbox_new(text_section, text_key, eraseMainBox); - return ptgb_write(text, instant, 9999); // This is kinda silly but it'll work. + int out = ptgb_write(text, instant, 9999, text_box_type_tables[text_section][text_key]); // This is kinda silly but it'll work. + if (waitForUser) + { + wait_for_user_to_continue(); + } + if (eraseMainBox) + { + tte_erase_rect(0, 0, H_MAX, V_MAX); + hide_textbox(); + erase_textbox_tiles(); + } + return out; } // Implement a version that just writes the whole string int ptgb_write_simple(const byte *text, bool instant) { - return ptgb_write(text, instant, 9999); // This is kinda silly but it'll work. + return ptgb_write(text, instant, 9999, -1); // This is kinda silly but it'll work. } // Re-implementing TTE's "tte_write" to use the gen 3 character encoding chart -int ptgb_write(const byte *text, bool instant, int length) +int ptgb_write(const byte *text, bool instant, int length, int box_type) { + int left, top, right, bottom; + instant = instant || g_debug_options.instant_text_speed; if (text == NULL) return 0; + if (box_type == -1) + { + left = 0; + top = 0; + right = H_MAX; + bottom = V_MAX; + } + else + { + left = 8 * (box_type_info[box_type][BOX_TYPE_VAL_START_TILE_X] + 1); + top = 8 * (box_type_info[box_type][BOX_TYPE_VAL_START_TILE_Y] + 1); + right = left + box_type_info[box_type][BOX_TYPE_VAL_PIXELS_PER_LINE]; + bottom = top + box_type_info[box_type][BOX_TYPE_VAL_NUM_OF_LINES] * 16; + } + uint ch, gid; char *str = (char *)text; TTC *tc = tte_get_context(); TFont *font; int num = 0; - /* - if (curr_text[char_index] == 0xFB) // This will need to be moved - { - line_char_index += char_index; - line_char_index++; - // Low key kinda scuffed, but it works to split the string - curr_text = &curr_line.get_text()[line_char_index]; - } - */ while ((ch = *str) != 0xFF && num < length) { if (get_frame_count() % 2 == 0 || key_held(KEY_B) || key_held(KEY_A) || instant) @@ -326,17 +337,17 @@ int ptgb_write(const byte *text, bool instant, int length) { tc->drawgProc(0x79); } - wait_for_user_to_continue(false); - scroll_text(instant, tc); - tc->cursorY += tc->font->charH; - tc->cursorX = tc->marginLeft; + wait_for_user_to_continue(); + scroll_text(instant, tc, left, top, right, bottom); break; case 0xFB: if (g_debug_options.display_control_char) { tc->drawgProc(0xB9); } - wait_for_user_to_continue(true); + wait_for_user_to_continue(); + tte_erase_rect(left, top, right, bottom); + tte_set_pos(left, top); break; case 0xFC: ch = *str; @@ -373,13 +384,6 @@ int ptgb_write(const byte *text, bool instant, int length) // Character wrap int charW = font->widths ? font->widths[gid] : font->charW; - // We don't want this tbh- all of the newlines should deal with moving to the next line - /* if (tc->cursorX + charW > tc->marginRight) - { - tc->cursorY += 10; // font->charH; - tc->cursorX = tc->marginLeft; - } */ - // Draw and update position tc->drawgProc(gid); tc->cursorX += charW; @@ -423,7 +427,7 @@ int ptgb_write_debug(const u16 *charset, const char *text, bool instant) return ptgb_write_simple(temp_holding, instant); } -void wait_for_user_to_continue(bool clear_text) +void wait_for_user_to_continue() { if (get_curr_flex_background() == FLEXBG_FENNEL) { @@ -438,23 +442,18 @@ void wait_for_user_to_continue(bool clear_text) } } key_poll(); - while (!(key_hit(KEY_A) || key_hit(KEY_B) || curr_text == NULL)) + while (!(key_hit(KEY_A) || key_hit(KEY_B))) { global_next_frame(); } - if (clear_text) - { - tte_erase_rect(LEFT, TOP, RIGHT, BOTTOM); - tte_set_pos(LEFT, TOP); - } } -void scroll_text(bool instant, TTC *tc) +void scroll_text(bool instant, TTC *tc, int left, int top, int right, int bottom) { for (int i = 1; i <= tc->font->charH; i++) { REG_BG3VOFS = i; - tte_erase_rect(LEFT, TOP - tc->font->charH, RIGHT, TOP + i); + tte_erase_rect(left, top - tc->font->charH, right, top + i); if (!instant) { global_next_frame(); @@ -465,10 +464,13 @@ void scroll_text(bool instant, TTC *tc) // The map starts at tile 0 in the top left, increases by 1 as you go down, and then loops back at the top. for (int i = 0; i < 30; i++) { - tonccpy(&tile_mem[TEXT_CBB][14 + (i * 20)], &tile_mem[TEXT_CBB][16 + (i * 20)], 2 * 2 * 32); + tonccpy(&tile_mem[TEXT_CBB][0 + (i * 20)], &tile_mem[TEXT_CBB][2 + (i * 20)], 20 * 32); } // Remove text that went outside of the box and set the position - tte_erase_rect(LEFT, TOP + tc->font->charH, RIGHT, BOTTOM); - tte_set_pos(LEFT, BOTTOM - (8 + (2 * tc->font->charH))); // The newline will trigger after this and move it down a line -} + tte_erase_rect(left, top - tc->font->charH, right, top); + tte_set_pos(left, bottom - (8 + (2 * tc->font->charH))); // The newline will trigger after this and move it down a line + + tc->cursorY = bottom - tc->font->charH; + tc->cursorX = left; +} \ No newline at end of file diff --git a/tools/text_helper/text.xlsx b/tools/text_helper/text.xlsx index 64d5eea..fbb2cb7 100644 Binary files a/tools/text_helper/text.xlsx and b/tools/text_helper/text.xlsx differ