From 00bb42dc5e7570932126361340420b339c0e265c Mon Sep 17 00:00:00 2001 From: haranp Date: Tue, 3 Jul 2007 21:55:23 +0000 Subject: Coloured power display. This is, for now, a rather extreme hack. Note that some spells (e.g. Apportation) have no actual power limits, so they will always be 'red'. Suggestions welcome. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1736 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/format.cc | 5 +++++ crawl-ref/source/format.h | 2 ++ crawl-ref/source/menu.cc | 5 ++++- crawl-ref/source/menu.h | 1 + crawl-ref/source/spl-cast.cc | 17 +++++++++-------- crawl-ref/source/spl-cast.h | 4 +--- 6 files changed, 22 insertions(+), 12 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/format.cc b/crawl-ref/source/format.cc index 9eb82cb8d3..2b77fc0bab 100644 --- a/crawl-ref/source/format.cc +++ b/crawl-ref/source/format.cc @@ -315,6 +315,11 @@ void formatted_string::fs_op::display() const } } +void formatted_string::swap(formatted_string& other) +{ + ops.swap(other.ops); +} + int count_linebreaks(const formatted_string& fs) { std::string::size_type where = 0; diff --git a/crawl-ref/source/format.h b/crawl-ref/source/format.h index af0231e23b..8391c2cbb8 100644 --- a/crawl-ref/source/format.h +++ b/crawl-ref/source/format.h @@ -35,6 +35,8 @@ public: void clear(); + void swap(formatted_string& other); + std::string::size_type length() const; const formatted_string &operator += (const formatted_string &other); diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index 10573e0f6e..539d9bad17 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -572,7 +572,10 @@ void Menu::draw_index_item(int index, const MenuEntry *me) const void Menu::draw_stock_item(int index, const MenuEntry *me) const { textattr( item_colour(index, items[index]) ); - cprintf( "%s", items[index]->get_text().c_str() ); + if ( flags & MF_ALLOW_FORMATTING ) + formatted_string::parse_string(items[index]->get_text()).display(); + else + cprintf( "%s", items[index]->get_text().c_str() ); } bool Menu::page_down() diff --git a/crawl-ref/source/menu.h b/crawl-ref/source/menu.h index 6ee0a1551e..57670ba5b3 100644 --- a/crawl-ref/source/menu.h +++ b/crawl-ref/source/menu.h @@ -154,6 +154,7 @@ enum MenuFlag MF_ALLOW_FILTER = 0x0080, // Control-F will ask for regex and // select the appropriate items. + MF_ALLOW_FORMATTING = 0x0100, // Parse index for formatted-string MF_EASY_EXIT = 0x1000 }; diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc index 6d3e80eea5..f587595fe4 100644 --- a/crawl-ref/source/spl-cast.cc +++ b/crawl-ref/source/spl-cast.cc @@ -29,6 +29,7 @@ #include "fight.h" #include "food.h" #include "format.h" +#include "initfile.h" #include "it_use2.h" #include "itemname.h" #include "itemprop.h" @@ -171,7 +172,10 @@ static std::string spell_extra_description(spell_type spell) desc << std::setw(30) << spell_title(spell); // spell power, hunger level, level - desc << std::setw(30) << spell_power_string(spell).tostring() + const char* colstr = colour_to_str(spell_power_colour(spell)); + desc << '<' << colstr << '>' + << std::setw(30) << spell_power_string(spell) + << "' << std::setw(12) << spell_hunger_string(spell) << spell_difficulty(spell); @@ -181,7 +185,7 @@ static std::string spell_extra_description(spell_type spell) char list_spells() { ToggleableMenu spell_menu(MF_SINGLESELECT | MF_ANYPRINTABLE | - MF_ALWAYS_SHOW_MORE); + MF_ALWAYS_SHOW_MORE | MF_ALLOW_FORMATTING); spell_menu.set_title( new ToggleableMenuEntry( " Your Spells Type " @@ -3511,16 +3515,13 @@ const char* spell_hunger_string( spell_type spell ) return "Extreme"; } -formatted_string spell_power_string(spell_type spell) +std::string spell_power_string(spell_type spell) { - formatted_string result; - result.textcolor(spell_power_colour(spell)); const int numbars = spell_power_bars(spell); if ( numbars < 0 ) - result.cprintf("N/A"); + return "N/A"; else - result.cprintf(std::string(numbars, '#')); - return result; + return std::string(numbars, '#'); } int spell_power_colour(spell_type spell) diff --git a/crawl-ref/source/spl-cast.h b/crawl-ref/source/spl-cast.h index 7dad287b23..f69a70c72a 100644 --- a/crawl-ref/source/spl-cast.h +++ b/crawl-ref/source/spl-cast.h @@ -16,8 +16,6 @@ #include "enum.h" -class formatted_string; - char list_spells( void ); int spell_fail( spell_type spell ); int calc_spell_power(spell_type spell, bool apply_intel, @@ -59,7 +57,7 @@ const char* failure_rate_to_string( int fail ); int spell_power_colour(spell_type spell); int spell_power_bars(spell_type spell); -formatted_string spell_power_string(spell_type spell); +std::string spell_power_string(spell_type spell); const char* spell_hunger_string( spell_type spell ); -- cgit v1.2.3-54-g00ecf