summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-03-16 15:48:28 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-03-16 15:48:28 +0000
commit54bfc8f5f26243e68353eeedb959864e6565de4c (patch)
treec7b82c5f497ab9f3bbfc5da435f60305738863ee /crawl-ref/source
parenteff8860c8c5cf24ffb3ff64e4b44af416d72b3d4 (diff)
downloadcrawl-ref-54bfc8f5f26243e68353eeedb959864e6565de4c.tar.gz
crawl-ref-54bfc8f5f26243e68353eeedb959864e6565de4c.zip
Added message_colour option to allow custom-colouring individual messages. This
does not affect formatted_mpr. Moved low magic warning to the danger channel and added a message_colour option to colour it lightcyan in the stock init.txt. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1050 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/enum.h1
-rw-r--r--crawl-ref/source/externs.h11
-rw-r--r--crawl-ref/source/initfile.cc55
-rw-r--r--crawl-ref/source/libutil.cc37
-rw-r--r--crawl-ref/source/libutil.h8
-rw-r--r--crawl-ref/source/message.cc22
-rw-r--r--crawl-ref/source/player.cc2
7 files changed, 112 insertions, 24 deletions
diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h
index 9d77b12e49..efce88b640 100644
--- a/crawl-ref/source/enum.h
+++ b/crawl-ref/source/enum.h
@@ -1754,7 +1754,6 @@ enum msg_channel_type
MSGCH_MULTITURN_ACTION, // delayed action messages
MSGCH_DIAGNOSTICS, // various diagnostic messages
MSGCH_TUTORIAL, // messages for tutorial
- MSGCH_DANGER_MAGIC, // low magic warning
NUM_MESSAGE_CHANNELS // always last
};
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index 4d0e817632..cd7002855c 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -1092,6 +1092,12 @@ struct colour_mapping
int colour;
};
+struct message_colour_mapping
+{
+ message_filter message;
+ int colour;
+};
+
struct feature_def
{
unsigned short symbol; // symbol used for seen terrain
@@ -1256,6 +1262,7 @@ public:
std::vector<sound_mapping> sound_mappings;
std::vector<colour_mapping> menu_colour_mappings;
+ std::vector<message_colour_mapping> message_colour_mappings;
int sort_menus; // 0 = always, -1 = never, number = beyond
// that size.
@@ -1371,6 +1378,10 @@ private:
void add_cset_override(char_set_type set, dungeon_char_type dc,
unsigned char symbol);
void add_feature_override(const std::string &);
+
+ void add_message_colour_mappings(const std::string &);
+ void add_message_colour_mapping(const std::string &);
+ message_filter parse_message_filter(const std::string &s);
void set_default_activity_interrupts();
void clear_activity_interrupts(FixedVector<bool, NUM_AINTERRUPTS> &eints);
diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc
index 84ac50bb1f..78da3c3519 100644
--- a/crawl-ref/source/initfile.cc
+++ b/crawl-ref/source/initfile.cc
@@ -148,8 +148,7 @@ static const std::string message_channel_names[ NUM_MESSAGE_CHANNELS ] =
"plain", "prompt", "god", "pray", "duration", "danger", "warning", "food",
"recovery", "sound", "talk", "intrinsic_gain", "mutation", "monster_spell",
"monster_enchant", "monster_damage", "monster_target",
- "rotten_meat", "equipment", "floor", "multiturn", "diagnostic","tutorial",
- "magic_warning",
+ "rotten_meat", "equipment", "floor", "multiturn", "diagnostic","tutorial"
};
// returns -1 if unmatched else returns 0--(NUM_MESSAGE_CHANNELS-1)
@@ -758,6 +757,7 @@ void game_options::reset_options()
travel_stop_message.clear();
sound_mappings.clear();
menu_colour_mappings.clear();
+ message_colour_mappings.clear();
drop_filter.clear();
map_file_name.clear();
named_options.clear();
@@ -1257,6 +1257,46 @@ std::string game_options::unalias(const std::string &key) const
return (i == aliases.end()? key : i->second);
}
+void game_options::add_message_colour_mappings(const std::string &field)
+{
+ std::vector<std::string> fragments = split_string(",", field);
+ for (int i = 0, count = fragments.size(); i < count; ++i)
+ add_message_colour_mapping(fragments[i]);
+}
+
+message_filter game_options::parse_message_filter(const std::string &filter)
+{
+ std::string::size_type pos = filter.find(":");
+ if (pos && pos != std::string::npos)
+ {
+ std::string prefix = filter.substr(0, pos);
+ int channel = str_to_channel( prefix );
+ if (channel != -1 || prefix == "any")
+ {
+ std::string s = filter.substr( pos + 1 );
+ trim_string( s );
+ return message_filter( channel, s );
+ }
+ }
+
+ return message_filter( filter );
+}
+
+void game_options::add_message_colour_mapping(const std::string &field)
+{
+ std::vector<std::string> cmap = split_string(":", field, true, true, 1);
+
+ if (cmap.size() != 2)
+ return;
+
+ const int col = str_to_colour( cmap[0] );
+ if (col == -1)
+ return;
+
+ message_colour_mapping m = { parse_message_filter( cmap[1] ), col };
+ message_colour_mappings.push_back( m );
+}
+
void game_options::read_option_line(const std::string &str, bool runscript)
{
std::string key = "";
@@ -1333,6 +1373,7 @@ void game_options::read_option_line(const std::string &str, bool runscript)
&& key.find("cset") != 0 && key != "dungeon"
&& key != "feature" && key != "fire_items_start"
&& key != "menu_colour" && key != "menu_color"
+ && key != "message_colour" && key != "message_color"
&& key != "levels" && key != "level" && key != "entries")
{
tolower_string( field );
@@ -2158,10 +2199,12 @@ void game_options::read_option_line(const std::string &str, bool runscript)
else if (key == "menu_colour" || key == "menu_color")
{
std::vector<std::string> seg = split_string(",", field);
- for (int i = 0, count = seg.size(); i < count; ++i) {
+ for (int i = 0, count = seg.size(); i < count; ++i)
+ {
const std::string &sub = seg[i];
std::string::size_type cpos = sub.find(":", 0);
- if (cpos != std::string::npos) {
+ if (cpos != std::string::npos)
+ {
colour_mapping mapping;
mapping.pattern = sub.substr(cpos + 1);
mapping.colour = str_to_colour(sub.substr(0, cpos));
@@ -2170,6 +2213,10 @@ void game_options::read_option_line(const std::string &str, bool runscript)
}
}
}
+ else if (key == "message_colour" || key == "message_color")
+ {
+ add_message_colour_mappings(field);
+ }
else if (key == "dump_order")
{
if (!plus_equal)
diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc
index 096eeffc8a..0b7772b531 100644
--- a/crawl-ref/source/libutil.cc
+++ b/crawl-ref/source/libutil.cc
@@ -380,30 +380,43 @@ std::string & trim_string( std::string &str )
return (str);
}
+static void add_segment(std::vector<std::string> &segs,
+ std::string s,
+ bool trim,
+ bool accept_empty)
+{
+ if (trim && !s.empty())
+ trim_string(s);
+
+ if (accept_empty || !s.empty())
+ segs.push_back(s);
+}
+
std::vector<std::string> split_string(
const char *sep,
std::string s,
bool trim_segments,
- bool accept_empty_segments)
+ bool accept_empty_segments,
+ int nsplits)
{
std::vector<std::string> segments;
int separator_length = strlen(sep);
std::string::size_type pos;
- while ((pos = s.find(sep, 0)) != std::string::npos)
+ while (nsplits && (pos = s.find(sep)) != std::string::npos)
{
- if (pos > 0 || accept_empty_segments)
- segments.push_back(s.substr(0, pos));
+ add_segment(segments, s.substr(0, pos),
+ trim_segments, accept_empty_segments);
+
s.erase(0, pos + separator_length);
+
+ if (nsplits > 0)
+ --nsplits;
}
- if (s.length() > 0)
- segments.push_back(s);
-
- if (trim_segments)
- {
- for (int i = 0, count = segments.size(); i < count; ++i)
- trim_string(segments[i]);
- }
+
+ if (!s.empty())
+ add_segment(segments, s, trim_segments, accept_empty_segments);
+
return segments;
}
diff --git a/crawl-ref/source/libutil.h b/crawl-ref/source/libutil.h
index d5b7bf081e..6baf428aa0 100644
--- a/crawl-ref/source/libutil.h
+++ b/crawl-ref/source/libutil.h
@@ -71,11 +71,17 @@ int cancelable_get_line( char *buf,
std::string & trim_string( std::string &str );
std::string trimmed_string( std::string s );
+// Splits string 's' on the separator 'sep'. If trim == true, trims each
+// segment. If accept_empties == true, accepts empty segments. If nsplits >= 0,
+// splits on the first nsplits occurrences of the separator, and stores the
+// remainder of the string as the last segment; negative values of nsplits
+// split on all occurrences of the separator.
std::vector<std::string> split_string(
const char *sep,
std::string s,
bool trim = true,
- bool accept_empties = false);
+ bool accept_empties = false,
+ int nsplits = -1);
inline std::string lowercase_first(std::string s)
{
diff --git a/crawl-ref/source/message.cc b/crawl-ref/source/message.cc
index 62fa88ea1c..4bad0ce3d1 100644
--- a/crawl-ref/source/message.cc
+++ b/crawl-ref/source/message.cc
@@ -190,10 +190,6 @@ int channel_to_colour( int channel, int param )
ret = CYAN;
break;
- case MSGCH_DANGER_MAGIC:
- ret = LIGHTCYAN;
- break;
-
case MSGCH_DIAGNOSTICS:
case MSGCH_MULTITURN_ACTION:
ret = DARKGREY; // makes it easier to ignore at times -- bwr
@@ -350,7 +346,7 @@ static void base_mpr(const char *inf, int channel, int param)
}
}
- if (Options.sound_mappings.size() > 0)
+ if (!Options.sound_mappings.empty())
{
std::string message = inf;
for (unsigned i = 0; i < Options.sound_mappings.size(); i++)
@@ -365,6 +361,22 @@ static void base_mpr(const char *inf, int channel, int param)
}
}
+ if (!Options.message_colour_mappings.empty())
+ {
+ std::string message = inf;
+ for (int i = 0, size = Options.message_colour_mappings.size();
+ i < size; ++i)
+ {
+ const message_colour_mapping &m =
+ Options.message_colour_mappings[i];
+ if (m.message.is_filtered(channel, message))
+ {
+ colour = m.colour;
+ break;
+ }
+ }
+ }
+
flush_input_buffer( FLUSH_ON_MESSAGE );
const int num_lines = get_message_window_height();
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index 892f09678b..de0c29872b 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -3821,7 +3821,7 @@ void dec_mp(int mp_loss)
&& you.magic_points < (you.max_magic_points
* Options.magic_point_warning) / 100)
{
- mpr( "* * * LOW MAGIC WARNING * * *", MSGCH_DANGER_MAGIC );
+ mpr( "* * * LOW MAGIC WARNING * * *", MSGCH_DANGER );
}
take_note(Note(NOTE_MP_CHANGE, you.magic_points, you.max_magic_points));