From b72bf8f7a8135eb26949815feffa186dc4a11d44 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Mon, 4 Aug 2025 18:12:55 -0500 Subject: [PATCH] shrink talk text when it doesn't fit --- src/game/boe.dlgutil.cpp | 13 +++++++------ src/game/boe.newgraph.cpp | 10 ++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/game/boe.dlgutil.cpp b/src/game/boe.dlgutil.cpp index 5082be22..5fe3847e 100644 --- a/src/game/boe.dlgutil.cpp +++ b/src/game/boe.dlgutil.cpp @@ -662,15 +662,16 @@ std::vector preset_words = { "Ask About...", }; +std::vector preset_word_locs = { + {4, 366}, {70, 366}, {136, 366}, + {4, 389}, {70, 389}, {121, 389}, + {210, 389}, {190, 366}, + {4, 343} +}; + static void reset_talk_words() { // first initialise talk_words here talk_words.clear(); - static const std::vector preset_word_locs = { - {4, 366}, {70, 366}, {136, 366}, - {4, 389}, {70, 389}, {121, 389}, - {210, 389}, {190, 366}, - {4, 343} - }; TextStyle style; style.font = FONT_DUNGEON; style.pointSize = TALK_WORD_SIZE; diff --git a/src/game/boe.newgraph.cpp b/src/game/boe.newgraph.cpp index 096198ef..53d31ed0 100644 --- a/src/game/boe.newgraph.cpp +++ b/src/game/boe.newgraph.cpp @@ -1022,6 +1022,16 @@ void place_talk_str(std::string str_to_place,std::string str_to_place2,short col } } + // If the text will overflow onto the preset talk words, shrink it + extern std::vector preset_word_locs; + auto break_info = calculate_line_wrapping(word_place_rect, str, style); + short lines = break_info.size(); + short height = lines * (style.lineHeight+1); + if(height >= word_place_rect.height()){ + short overflow = height - preset_word_locs.back().y; + style.lineHeight -= ceil(overflow / (float) lines); + } + std::vector word_rects = draw_string_hilite(talk_gworld(), word_place_rect, str, style, hilites, color ? CUSTOM_WORD_ON : CUSTOM_WORD_OFF); if(!talk_end_forced) {