summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/message.cc
diff options
context:
space:
mode:
authorpauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573>2008-02-29 09:32:40 +0000
committerpauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573>2008-02-29 09:32:40 +0000
commit32ed1823706542ae3cc6bb8086beca1d81e46caf (patch)
tree4d8ef01bb9d49149d6d82986e66f41a412551f20 /crawl-ref/source/message.cc
parent683b4d9a7073c1d5204eadfe7f5959e99b13a24b (diff)
downloadcrawl-ref-32ed1823706542ae3cc6bb8086beca1d81e46caf.tar.gz
crawl-ref-32ed1823706542ae3cc6bb8086beca1d81e46caf.zip
Cleaned up and applied 1895117: formatted_string and tutorial polish.
- formatted_message_history handles linebreaks within color spans properly, and now makes print_formatted_paragraph redundant. (changed tutorial.cc to take advantage of this) - formatted_string handles <color></color> properly (with nesting) instead of reverting to lightgrey. (changed tutorial.cc to take advantage of this, too) - The part of 1895117 that dealt with dec glyphs was already addressed in a previous patch, in a more robust way, so that got cut. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3481 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/message.cc')
-rw-r--r--crawl-ref/source/message.cc55
1 files changed, 41 insertions, 14 deletions
diff --git a/crawl-ref/source/message.cc b/crawl-ref/source/message.cc
index 75e1a46df1..dfb421c8b2 100644
--- a/crawl-ref/source/message.cc
+++ b/crawl-ref/source/message.cc
@@ -18,6 +18,7 @@
#include <cstdarg>
#include <cstring>
+#include <sstream>
#ifdef DOS
#include <conio.h>
@@ -40,6 +41,7 @@
#include "travel.h"
#include "tutorial.h"
#include "view.h"
+#include "menu.h"
// circular buffer for keeping past messages
message_item Store_Message[ NUM_STORED_MESSAGES ]; // buffer of old messages
@@ -672,11 +674,15 @@ void formatted_mpr(const formatted_string& fs, msg_channel_type channel,
mpr_store_messages(imsg, channel, param);
}
-// output given string as formatted message, but check patterns
-// for string stripped of tags and store original tagged string
-// for message history
-void formatted_message_history(const std::string &st, msg_channel_type channel,
- int param)
+// output given string as formatted message(s), but check patterns
+// for string stripped of tags and store the original tagged string
+// for message history. Newlines break the string into multiple
+// messages.
+//
+// If wrap_col > 0, text is wrapped at that column.
+//
+void formatted_message_history(const std::string &st_nocolor, msg_channel_type channel,
+ int param, int wrap_col)
{
if (suppress_messages)
return;
@@ -685,20 +691,41 @@ void formatted_message_history(const std::string &st, msg_channel_type channel,
if (colour == MSGCOL_MUTED)
return;
- formatted_string fs = formatted_string::parse_string(st);
+ // Apply channel color explicitly, so "foo <w>bar</w> baz"
+ // renders "baz" correctly
+ std::string st;
+ {
+ std::ostringstream text;
+ const std::string colour_str = colour_to_str(colour);
+ text << "<" << colour_str << ">"
+ << st_nocolor
+ << "</" << colour_str << ">";
+ text.str().swap(st);
+ }
- mpr_check_patterns(fs.tostring(), channel, param);
+ if (wrap_col)
+ {
+ linebreak_string2(st, wrap_col);
+ }
- flush_input_buffer( FLUSH_ON_MESSAGE );
+ std::vector<formatted_string> fss;
+ formatted_string::parse_string_to_multiple(st, fss);
- const int num_lines = crawl_view.msgsz.y;
+ for (int i=0; i<fss.size(); i++)
+ {
+ const formatted_string& fs = fss[i];
+ mpr_check_patterns(fs.tostring(), channel, param);
- if (New_Message_Count == num_lines - 1)
- more();
+ flush_input_buffer( FLUSH_ON_MESSAGE );
- mpr_formatted_output(fs, colour);
+ const int num_lines = crawl_view.msgsz.y;
+
+ if (New_Message_Count == num_lines - 1)
+ more();
- mpr_store_messages(st, channel, param);
+ mpr_formatted_output(fs, colour);
+ mpr_store_messages(fs.to_colour_string(), channel, param);
+ }
}
bool any_messages(void)
@@ -874,7 +901,7 @@ void replay_messages(void)
// allow formatted output of tagged messages
if (Store_Message[ line ].channel == MSGCH_TUTORIAL)
{
- formatted_string fs = formatted_string::parse_string(text);
+ formatted_string fs = formatted_string::parse_string(text, true);
int curcol = 1;
for ( unsigned int j = 0; j < fs.ops.size(); ++j )
{