From d67f41ebf91d23eabe1640a2910cdae40358b77c Mon Sep 17 00:00:00 2001 From: haranp Date: Fri, 19 Oct 2007 22:30:42 +0000 Subject: Menus are now tagged. Menu colours now only apply to a menu with a matching tag, unless the menu colour tag is empty or "any". Menu colours are specified as tag:colour:pattern, where the "tag:" part is optional (default is empty tag, i.e., all menus.) The following menu tags exist: ability, description, equip, help, inventory, notes, resists, spell, stash. Default .crawlrc should probably be changed (and the docs, too...) git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2493 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/abl-show.cc | 2 +- crawl-ref/source/chardump.cc | 2 ++ crawl-ref/source/command.cc | 26 ++++++++++++++++---------- crawl-ref/source/externs.h | 1 + crawl-ref/source/initfile.cc | 31 +++++++++++++++++++++++-------- crawl-ref/source/invent.h | 5 +++-- crawl-ref/source/menu.cc | 20 +++++++++++++------- crawl-ref/source/menu.h | 10 +++++++--- crawl-ref/source/output.cc | 1 + crawl-ref/source/spl-cast.cc | 1 + crawl-ref/source/stash.cc | 2 ++ 11 files changed, 70 insertions(+), 31 deletions(-) diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc index 02b30258c2..4af232ce3b 100644 --- a/crawl-ref/source/abl-show.cc +++ b/crawl-ref/source/abl-show.cc @@ -1829,7 +1829,7 @@ static void pay_ability_costs(const ability_def& abil) int choose_ability_menu(const std::vector& talents) { - Menu abil_menu(MF_SINGLESELECT | MF_ANYPRINTABLE); + Menu abil_menu(MF_SINGLESELECT | MF_ANYPRINTABLE, "ability"); abil_menu.set_highlighter(NULL); abil_menu.set_title( new MenuEntry(" Ability " diff --git a/crawl-ref/source/chardump.cc b/crawl-ref/source/chardump.cc index 08cdfd212b..5af5ea01d2 100644 --- a/crawl-ref/source/chardump.cc +++ b/crawl-ref/source/chardump.cc @@ -1169,6 +1169,7 @@ static bool write_dump( void display_notes() { Menu scr; + scr.set_tag("notes"); scr.set_title( new MenuEntry("Turn | Place | Note")); for ( unsigned int i = 0; i < note_list.size(); ++i ) { @@ -1201,6 +1202,7 @@ void resists_screen() textcolor(LIGHTGREY); formatted_scroller scr; + scr.set_tag("resists"); for ( unsigned i = 0; i < vfs.size(); ++i ) scr.add_item_formatted_string(vfs[i]); diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc index 12007ac69c..2075188735 100644 --- a/crawl-ref/source/command.cc +++ b/crawl-ref/source/command.cc @@ -385,7 +385,8 @@ void list_armour() { estr << you.inv[armour_id].name(DESC_INVENTORY); colour = menu_colour(estr.str(), - menu_colour_item_prefix(you.inv[armour_id])); + menu_colour_item_prefix(you.inv[armour_id]), + "equip"); } else if (!you_can_wear(i,true)) estr << " (unavailable)"; @@ -397,7 +398,7 @@ void list_armour() estr << " none"; if (colour == MSGCOL_BLACK) - colour = menu_colour(estr.str()); + colour = menu_colour(estr.str(), "", "equip"); mpr( estr.str().c_str(), MSGCH_EQUIPMENT, colour); } @@ -426,7 +427,7 @@ void list_jewellery(void) jstr << you.inv[jewellery_id].name(DESC_INVENTORY); std::string prefix = menu_colour_item_prefix(you.inv[jewellery_id]); - colour = menu_colour(jstr.str(), prefix); + colour = menu_colour(jstr.str(), prefix, "equip"); } else if (!you_tran_can_wear(i)) jstr << " (currently unavailable)"; @@ -434,7 +435,7 @@ void list_jewellery(void) jstr << " none"; if (colour == MSGCOL_BLACK) - colour = menu_colour(jstr.str()); + colour = menu_colour(jstr.str(), "", "equip"); mpr( jstr.str().c_str(), MSGCH_EQUIPMENT, colour); } @@ -455,7 +456,8 @@ void list_weapons(void) { wstring += you.inv[weapon_id].name(DESC_INVENTORY_EQUIP); colour = menu_colour(wstring, - menu_colour_item_prefix(you.inv[weapon_id])); + menu_colour_item_prefix(you.inv[weapon_id]), + "equip"); } else { @@ -465,7 +467,7 @@ void list_weapons(void) wstring += " (currently unavailable)"; else wstring += " empty hands"; - colour = menu_colour(wstring); + colour = menu_colour(wstring, "", "equip"); } mpr(wstring.c_str(), MSGCH_EQUIPMENT, colour); @@ -491,13 +493,14 @@ void list_weapons(void) { wstring += you.inv[i].name(DESC_INVENTORY_EQUIP); colour = menu_colour(wstring, - menu_colour_item_prefix(you.inv[i])); + menu_colour_item_prefix(you.inv[i]), + "equip"); } else wstring += " none"; if (colour == MSGCOL_BLACK) - colour = menu_colour(wstring); + colour = menu_colour(wstring, "", "equip"); mpr(wstring.c_str(), MSGCH_EQUIPMENT, colour); } @@ -514,11 +517,12 @@ void list_weapons(void) { wstring += you.inv[item].name(DESC_INVENTORY_EQUIP); colour = menu_colour(wstring, - menu_colour_item_prefix(you.inv[item])); + menu_colour_item_prefix(you.inv[item]), + "equip"); } if (colour == MSGCOL_BLACK) - colour = menu_colour(wstring); + colour = menu_colour(wstring, "", "equip"); mpr( wstring.c_str(), MSGCH_EQUIPMENT, colour ); } // end list_weapons() @@ -1041,6 +1045,7 @@ static bool find_description() DescMenu desc_menu(MF_SINGLESELECT | MF_ANYPRINTABLE | MF_ALWAYS_SHOW_MORE | MF_ALLOW_FORMATTING, doing_mons); + desc_menu.set_tag("description"); std::list monster_types; for (unsigned int i = 0, size = key_list.size(); i < size; i++) { @@ -1146,6 +1151,7 @@ static void show_keyhelp_menu(const std::vector &lines, if (easy_exit) flags |= MF_EASY_EXIT; cmd_help.set_flags(flags, false); + cmd_help.set_tag("help"); // FIXME: Allow for hiding Page down when at the end of the listing, ditto // for page up at start of listing. diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index 7fc2a7870a..081a65fd4d 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -1348,6 +1348,7 @@ struct sound_mapping struct colour_mapping { + std::string tag; text_pattern pattern; int colour; }; diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index c8f011d40a..404bd8704b 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -2453,16 +2453,31 @@ void game_options::read_option_line(const std::string &str, bool runscript) std::vector seg = split_string(",", field); 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) + // format: tag:string:colour + // FIXME: arrange so that you can use ':' inside a pattern + std::vector subseg = split_string(":", seg[i]); + std::string tagname, patname, colname; + if ( subseg.size() < 2 ) + continue; + if ( subseg.size() >= 3 ) + { + tagname = subseg[0]; + colname = subseg[1]; + patname = subseg[2]; + } + else { - colour_mapping mapping; - mapping.pattern = sub.substr(cpos + 1); - mapping.colour = str_to_colour(sub.substr(0, cpos)); - if (mapping.colour != -1) - menu_colour_mappings.push_back(mapping); + colname = subseg[0]; + patname = subseg[1]; } + + colour_mapping mapping; + mapping.tag = tagname; + mapping.pattern = patname; + mapping.colour = str_to_colour(colname); + + if (mapping.colour != -1) + menu_colour_mappings.push_back(mapping); } } else if (key == "menu_colour_prefix_class" || diff --git a/crawl-ref/source/invent.h b/crawl-ref/source/invent.h index 46b30a33c2..74386687f0 100644 --- a/crawl-ref/source/invent.h +++ b/crawl-ref/source/invent.h @@ -89,7 +89,8 @@ public: virtual int highlight_colour() const { return menu_colour(get_text(), - menu_colour_item_prefix( *( (item_def*) item) ) ); + menu_colour_item_prefix( *( (item_def*) item) ), + tag ); } @@ -108,7 +109,7 @@ class InvMenu : public Menu { public: InvMenu(int mflags = MF_MULTISELECT) - : Menu(mflags), type(MT_INVLIST), pre_select(NULL), + : Menu(mflags, "inventory"), type(MT_INVLIST), pre_select(NULL), title_annotate(NULL) { } diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index 6b368433cb..f9afedac4c 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -16,12 +16,13 @@ #include "view.h" #include "initfile.h" -Menu::Menu( int _flags ) +Menu::Menu( int _flags, const std::string& tagname ) : f_selitem(NULL), f_drawitem(NULL), f_keyfilter(NULL), title(NULL), flags(_flags), + tag(tagname), first_entry(0), y_offset(0), pagesize(0), @@ -92,6 +93,7 @@ void Menu::set_title( MenuEntry *e ) void Menu::add_entry( MenuEntry *entry ) { + entry->tag = tag; items.push_back( entry ); } @@ -1028,15 +1030,19 @@ bool slider_menu::line_up() // Menu colouring // -int menu_colour(const std::string &text, const std::string &prefix) +int menu_colour(const std::string &text, const std::string &prefix, + const std::string &tag) { - std::string tmp_text = prefix + text; + const std::string tmp_text = prefix + text; - for (int i = 0, size = Options.menu_colour_mappings.size(); i < size; ++i) + for (unsigned int i = 0; i < Options.menu_colour_mappings.size(); ++i) { - colour_mapping &cm = Options.menu_colour_mappings[i]; - if (cm.pattern.matches(tmp_text)) + const colour_mapping &cm = Options.menu_colour_mappings[i]; + if ( (cm.tag.empty() || cm.tag == "any" || cm.tag == tag) && + cm.pattern.matches(tmp_text) ) + { return (cm.colour); + } } return (-1); } @@ -1411,7 +1417,7 @@ bool formatted_scroller::page_up() bool formatted_scroller::line_down() { - if (first_entry + pagesize < (int) items.size() && + if (first_entry + pagesize < static_cast(items.size()) && items[first_entry + pagesize]->level != MEL_TITLE ) { ++first_entry; diff --git a/crawl-ref/source/menu.h b/crawl-ref/source/menu.h index f2fbc5b359..f7a57f0834 100644 --- a/crawl-ref/source/menu.h +++ b/crawl-ref/source/menu.h @@ -48,10 +48,12 @@ struct menu_letter struct item_def; int menu_colour(const std::string &itemtext, - const std::string &prefix = ""); + const std::string &prefix = "", + const std::string &tag = ""); struct MenuEntry { + std::string tag; std::string text; int quantity, selected_qty; int colour; @@ -108,7 +110,7 @@ struct MenuEntry virtual int highlight_colour() const { - return (menu_colour(get_text())); + return (menu_colour(get_text(), "", tag)); } virtual bool selected() const @@ -176,7 +178,7 @@ enum MenuFlag class Menu { public: - Menu( int flags = MF_MULTISELECT ); + Menu( int flags = MF_MULTISELECT, const std::string& tagname = "" ); virtual ~Menu(); // Remove all items from the Menu, leave title intact. @@ -187,6 +189,7 @@ public: void set_flags(int new_flags, bool use_options = true); int get_flags() const { return flags; } virtual bool is_set( int flag ) const; + void set_tag(const std::string& t) { tag = t; } bool draw_title_suffix( const std::string &s, bool titlefirst = true ); void update_title(); @@ -226,6 +229,7 @@ public: protected: MenuEntry *title; int flags; + std::string tag; int first_entry, y_offset; int pagesize, max_pagesize; diff --git a/crawl-ref/source/output.cc b/crawl-ref/source/output.cc index cf601eb4a1..9239f3bffc 100644 --- a/crawl-ref/source/output.cc +++ b/crawl-ref/source/output.cc @@ -998,6 +998,7 @@ void print_overview_screen() cmd_help.set_flags(MF_NOSELECT | MF_ALWAYS_SHOW_MORE | MF_NOWRAP, false); cmd_help.set_more( formatted_string::parse_string( "[ + : Page down. - : Page up. Esc exits.]")); + cmd_help.set_tag("help"); std::string text; char title[50]; diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc index e8199ad043..e665d1d4d1 100644 --- a/crawl-ref/source/spl-cast.cc +++ b/crawl-ref/source/spl-cast.cc @@ -205,6 +205,7 @@ int list_spells() spell_menu.set_highlighter(NULL); spell_menu.set_more(formatted_string("Press '!' to toggle spell view.")); spell_menu.add_toggle_key('!'); + spell_menu.set_tag("spell"); for ( int i = 0; i < 52; ++i ) { diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc index 89c2106cb4..b0555abe6a 100644 --- a/crawl-ref/source/stash.cc +++ b/crawl-ref/source/stash.cc @@ -394,6 +394,7 @@ public: StashMenu() : InvMenu(MF_SINGLESELECT), can_travel(false) { set_type(MT_PICKUP); + set_tag("stash"); // override "inventory" tag } unsigned char getkey() const; public: @@ -1541,6 +1542,7 @@ void StashTracker::display_search_results( bool travelable = can_travel_interlevel(); StashSearchMenu stashmenu; + stashmenu.set_tag("stash"); stashmenu.can_travel = travelable; std::string title = "match"; -- cgit v1.2.3-54-g00ecf