diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-01-28 14:22:11 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-01-28 14:22:11 +0000 |
commit | 14855516c12f34ae5d289631a665d61837563a7a (patch) | |
tree | fe926753c926a5f4cb3365a2c8e02f88ea84c905 /crawl-ref/source/menu.cc | |
parent | 1bbfa550c2f3a16c1a4964771e4905c90461442d (diff) | |
download | crawl-ref-14855516c12f34ae5d289631a665d61837563a7a.tar.gz crawl-ref-14855516c12f34ae5d289631a665d61837563a7a.zip |
Added add_glyph methods to formatted string to show a monster or item glyph as
displayed on screen. Still is a bit messy to use, and you must initialise the
formatted_string with a base colour before using add_glyph(), or the
formatted_string will reset to lightgrey after the glyph.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@897 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/menu.cc')
-rw-r--r-- | crawl-ref/source/menu.cc | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index d40564fad1..7420d543b2 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -930,12 +930,19 @@ int MenuHighlighter::entry_colour(const MenuEntry *entry) const // formatted_string // +formatted_string::formatted_string(int init_colour) + : ops() +{ + if (init_colour) + textcolor(init_colour); +} + formatted_string::formatted_string(const std::string &s, int init_colour) : ops() { if (init_colour) - ops.push_back(init_colour); - ops.push_back(s); + textcolor(init_colour); + cprintf(s); } int formatted_string::get_colour(const std::string &tag) @@ -1116,8 +1123,44 @@ void formatted_string::movexy(int x, int y) ops.push_back( fs_op(x, y, true) ); } +int formatted_string::find_last_colour() const +{ + if (!ops.empty()) + { + for (int i = ops.size() - 1; i >= 0; --i) + { + if (ops[i].type == FSOP_COLOUR) + return (ops[i].x); + } + } + return (LIGHTGREY); +} + +void formatted_string::add_glyph(const item_def *item) +{ + const int last_col = find_last_colour(); + unsigned short ch, col; + get_item_glyph(item, &ch, &col); + this->textcolor(col); + this->cprintf("%c", ch); + this->textcolor(last_col); +} + +void formatted_string::add_glyph(const monsters *mons) +{ + const int last_col = find_last_colour(); + unsigned short ch, col; + get_mons_glyph(mons, &ch, &col); + this->textcolor(col); + this->cprintf("%c", ch); + this->textcolor(last_col); +} + void formatted_string::textcolor(int color) { + if (!ops.empty() && ops[ ops.size() - 1 ].type == FSOP_COLOUR) + ops.erase( ops.end() - 1 ); + ops.push_back(color); } |