diff options
author | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-04-04 09:05:29 +0000 |
---|---|---|
committer | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-04-04 09:05:29 +0000 |
commit | 9f14773ca23414d094abfa3bab763641da183371 (patch) | |
tree | c8b296f4bc49df471fc6204a7f65f3a33fff2d35 /crawl-ref/source/message.cc | |
parent | c9b7d443bf6acf3514a6374a3f84200aee48959b (diff) | |
download | crawl-ref-9f14773ca23414d094abfa3bab763641da183371.tar.gz crawl-ref-9f14773ca23414d094abfa3bab763641da183371.zip |
Allow "mute" as a colour in message_colour, which means the message
will be muted (duh.)
message_colour can now override channel mutings (e.g., if you want
to mute the pray channel except for a specific message.)
Factored out some common code from {base,formatted}_mpr.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1211 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/message.cc')
-rw-r--r-- | crawl-ref/source/message.cc | 82 |
1 files changed, 39 insertions, 43 deletions
diff --git a/crawl-ref/source/message.cc b/crawl-ref/source/message.cc index 8872f7b226..5b4285a21f 100644 --- a/crawl-ref/source/message.cc +++ b/crawl-ref/source/message.cc @@ -310,7 +310,8 @@ void mpr(const char *inf, int channel, int param) // checks whether a given message contains patterns relevant for // notes, stop_running or sounds and handles these cases -static void mpr_check_patterns(std::string message, int channel, int param) +static void mpr_check_patterns(const std::string& message, int channel, + int param) { for (unsigned i = 0; i < Options.note_messages.size(); ++i) { @@ -354,7 +355,8 @@ static void mpr_check_patterns(std::string message, int channel, int param) } // adds a given message to the message history -static void mpr_store_messages(std::string message, int channel, int param) +static void mpr_store_messages(const std::string& message, + int channel, int param) { const int num_lines = get_message_window_height(); @@ -374,7 +376,7 @@ static void mpr_store_messages(std::string message, int channel, int param) if (channel != MSGCH_EQUIPMENT) { // Put the message into Store_Message, and move the '---' line forward - Store_Message[ Next_Message ].text = message.c_str(); + Store_Message[ Next_Message ].text = message; Store_Message[ Next_Message ].channel = channel; Store_Message[ Next_Message ].param = param; Next_Message++; @@ -385,42 +387,50 @@ static void mpr_store_messages(std::string message, int channel, int param) } static bool need_prefix = false; -static void base_mpr(const char *inf, int channel, int param) + +// Does the work common to base_mpr and formatted_mpr. +// Returns the default colour of the message, or MSGCOL_MUTED if +// the message should be suppressed. +static int prepare_message(const std::string& imsg, int channel, int param) { if (suppress_messages) - return; + return MSGCOL_MUTED; int colour = channel_to_colour( channel, param ); - if (colour == MSGCOL_MUTED) - return; - std::string imsg = inf; - - mpr_check_patterns(imsg, channel, param); - - if (!Options.message_colour_mappings.empty()) + const std::vector<message_colour_mapping>& mcm = + Options.message_colour_mappings; + typedef std::vector<message_colour_mapping>::const_iterator mcmci; + + for ( mcmci ci = mcm.begin(); ci != mcm.end(); ++ci ) { - std::string message = inf; - for (int i = 0, size = Options.message_colour_mappings.size(); - i < size; ++i) + if (ci->message.is_filtered(channel, imsg)) { - const message_colour_mapping &m = - Options.message_colour_mappings[i]; - if (m.message.is_filtered(channel, message)) - { - colour = m.colour; - break; - } + colour = ci->colour; + break; } } - flush_input_buffer( FLUSH_ON_MESSAGE ); - - const int num_lines = get_message_window_height(); + if ( colour != MSGCOL_MUTED ) + { + mpr_check_patterns(imsg, channel, param); + flush_input_buffer( FLUSH_ON_MESSAGE ); + const int num_lines = get_message_window_height(); - if (New_Message_Count == num_lines - 1) - more(); + if (New_Message_Count == num_lines - 1) + more(); + } + return colour; +} + +static void base_mpr(const char *inf, int channel, int param) +{ + const std::string imsg = inf; + const int colour = prepare_message( imsg, channel, param ); + if ( colour == MSGCOL_MUTED ) + return; + if (need_prefix) { message_out( Message_Line, colour, "-", 1, false ); @@ -472,26 +482,12 @@ static void mpr_formatted_output(formatted_string fs, int colour) // way to do this. void formatted_mpr(const formatted_string& fs, int channel, int param) { - if (suppress_messages) - return; - - int colour = channel_to_colour( channel, param ); + const std::string imsg = fs.tostring(); + const int colour = prepare_message(imsg, channel, param); if (colour == MSGCOL_MUTED) return; - const std::string imsg = fs.tostring(); - - mpr_check_patterns(imsg, channel, param); - - flush_input_buffer( FLUSH_ON_MESSAGE ); - - const int num_lines = get_message_window_height(); - - if (New_Message_Count == num_lines - 1) - more(); - mpr_formatted_output(fs, colour); - mpr_store_messages(imsg, channel, param); } |