shrink talk text when it doesn't fit

This commit is contained in:
2025-08-04 18:12:55 -05:00
committed by Celtic Minstrel
parent edf33686f1
commit 8ba606056e
2 changed files with 17 additions and 6 deletions

View File

@@ -662,15 +662,16 @@ std::vector<std::string> preset_words = {
"Ask About...",
};
std::vector<location> 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<location> 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;

View File

@@ -1014,6 +1014,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<location> 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<rectangle> word_rects = draw_string_hilite(talk_gworld(), word_place_rect, str, style, hilites, color ? CUSTOM_WORD_ON : CUSTOM_WORD_OFF);
if(!talk_end_forced) {