From c84a0cdc401d416c5a366395953011f9b0d91057 Mon Sep 17 00:00:00 2001 From: CosmosXIII Date: Sat, 5 Oct 2024 19:37:11 +0900 Subject: [PATCH] Improved text box auto-resize to take into account lenght of character names --- src/ff7.h | 1 + src/ff7/japanese_text.cpp | 16 +++++++++++++--- src/ff7_data.h | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ff7.h b/src/ff7.h index 32e18ad4..22ed4507 100644 --- a/src/ff7.h +++ b/src/ff7.h @@ -3170,6 +3170,7 @@ struct ff7_externals uint32_t field_text_box_window_create_631586; void (*field_text_box_window_opening_6317A9)(short); void (*field_text_box_window_paging_631945)(short); + byte* (*sub_6CB9B8)(int a1); uint32_t field_text_box_window_reverse_paging_632CAA; uint32_t field_text_box_window_closing_632EB8; char* field_entity_id_list; // 0xCC0960 diff --git a/src/ff7/japanese_text.cpp b/src/ff7/japanese_text.cpp index b4c01149..f6a528ea 100644 --- a/src/ff7/japanese_text.cpp +++ b/src/ff7/japanese_text.cpp @@ -2213,11 +2213,21 @@ void auto_resize_text_box(int16_t WINDOW_ID, int16_t* pOutW, int16_t* pOutH) } // character names - // add constant width for now if(character >= 0xEA && character <= 0xF5) { - charWidth = 16 * 6; - leftPadding = 0; + auto name_buffer = ff7_externals.sub_6CB9B8(character - 0xEA); + for (int j = 0; j < 9; ++j) + { + auto name_char = name_buffer[j]; + + if (name_char == 0xFF) break; + + charWidth = charWidthData[0][name_char] & 0x1F; + leftPadding = charWidthData[0][name_char] >> 5; + W += leftPadding + std::ceil(0.5f * charWidth); + } + + continue; } if(character == 0xE7) diff --git a/src/ff7_data.h b/src/ff7_data.h index 976b9174..702e49b1 100644 --- a/src/ff7_data.h +++ b/src/ff7_data.h @@ -533,6 +533,7 @@ inline void ff7_find_externals(struct ff7_game_obj* game_object) ff7_externals.field_text_box_window_create_631586 = get_relative_call(ff7_externals.field_opcode_message_update_loop_630D50, 0x39); ff7_externals.field_text_box_window_opening_6317A9 = (void (*)(short))get_relative_call(ff7_externals.field_opcode_message_update_loop_630D50, 0x5A); ff7_externals.field_text_box_window_paging_631945 = (void (*)(short))get_relative_call(ff7_externals.field_opcode_message_update_loop_630D50, 0x6D);; + ff7_externals.sub_6CB9B8 = (byte* (*)(int))get_relative_call((uint32_t)ff7_externals.field_text_box_window_paging_631945, 0x693); ff7_externals.field_text_box_window_reverse_paging_632CAA = get_relative_call(ff7_externals.field_opcode_message_update_loop_630D50, 0x80); ff7_externals.field_text_box_window_closing_632EB8 = get_relative_call(ff7_externals.field_opcode_message_update_loop_630D50, 0x235); ff7_externals.opcode_message_loop_code = (WORD*)get_absolute_value(ff7_externals.field_opcode_message_update_loop_630D50, 0x12);