diff options
author | Charles Otto <ottochar@gmail.com> | 2009-10-31 20:54:58 -0400 |
---|---|---|
committer | Charles Otto <ottochar@gmail.com> | 2009-10-31 20:55:48 -0400 |
commit | 16f4be755988dd1fb4b4918ab5c2e43fe721d4b9 (patch) | |
tree | c156cb9632048878e58ed0842ddeac2155565462 /crawl-ref/source/describe.h | |
parent | ada7f5b32b5b783b272e744082865f6f506b5bd2 (diff) | |
download | crawl-ref-16f4be755988dd1fb4b4918ab5c2e43fe721d4b9.tar.gz crawl-ref-16f4be755988dd1fb4b4918ab5c2e43fe721d4b9.zip |
Fix bug [2874237] monster info display corruption
Examining monsters with ctrl-X can lead to message corruption if the
title and body fields of the describe_info struct used by
process_description take up lines than fit in the message area.
This patch avoid the problem by allowing process_description to print
just the title field if title + body would take up too many lines.
Also make view_desc_proc start one line later since it seemed to be
trying to print the first line it was given one line above where it
should have been.
Diffstat (limited to 'crawl-ref/source/describe.h')
-rw-r--r-- | crawl-ref/source/describe.h | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/crawl-ref/source/describe.h b/crawl-ref/source/describe.h index 9e71c2a337..5751678335 100644 --- a/crawl-ref/source/describe.h +++ b/crawl-ref/source/describe.h @@ -136,22 +136,34 @@ inline void process_description(T &proc, const describe_info &inf) std::string desc; - if (inf.title.empty()) - desc = inf.body.str(); - else - { - desc = inf.title + "$$"; - desc += inf.body.str(); - } - - int num_lines = count_desc_lines(desc, line_width) + 1; + // How mnay lines is the title, we also seem to be adding 1 to + // start with. + int num_lines = count_desc_lines(inf.title, line_width) + 1; + int body_lines = count_desc_lines(inf.body.str(), line_width); const int suffix_lines = count_desc_lines(inf.suffix, line_width); const int prefix_lines = count_desc_lines(inf.prefix, line_width); const int footer_lines = count_desc_lines(inf.footer, line_width) + (inf.footer.empty() ? 0 : 1); const int quote_lines = count_desc_lines(inf.quote, line_width); + // Maybe skip the body if body + title would be too many lines + if(inf.title.empty()) + { + desc = inf.body.str(); + // There is a default 1 line addition for some reason + num_lines = body_lines + 1; + } + else if(body_lines + num_lines + 2 <= height) + { + desc = inf.title + "$$"; + desc += inf.body.str(); + // Got 2 lines from the two $s that weren't counted yet + num_lines += body_lines + 2; + } + else + desc = inf.title + "$"; + // Prefer the footer over the suffix. if (num_lines + suffix_lines + footer_lines <= height) { |