From 7c5e54508666b65c7890ddc45880f64b38f887cb Mon Sep 17 00:00:00 2001 From: dshaligram Date: Thu, 31 May 2007 19:25:30 +0000 Subject: sort_menus now allows the user to choose what menus to sort, and how to sort items, at the cost of obfuscating the sort_menus option massively. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1494 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/externs.h | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'crawl-ref/source/externs.h') diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index 065a2961ca..05adcbe314 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -442,7 +442,8 @@ public: *this = item_def(); } private: - std::string name_aux( bool terse, bool ident ) const; + std::string name_aux( description_level_type desc, + bool terse, bool ident ) const; }; class input_history @@ -1241,6 +1242,43 @@ struct feature_override feature_def override; }; +class InvEntry; +typedef int (*item_sort_fn)(const InvEntry *a, const InvEntry *b); +struct item_comparator +{ + item_sort_fn cmpfn; + bool negated; + + item_comparator(item_sort_fn cfn, bool neg = false) + : cmpfn(cfn), negated(neg) + { + } + int compare(const InvEntry *a, const InvEntry *b) const + { + return (negated? -cmpfn(a, b) : cmpfn(a, b)); + } +}; +typedef std::vector item_sort_comparators; + +struct menu_sort_condition +{ +public: + menu_type mtype; + int sort; + item_sort_comparators cmp; + +public: + menu_sort_condition(menu_type mt = MT_INVLIST, int sort = 0); + menu_sort_condition(const std::string &s); + + bool matches(menu_type mt) const; + +private: + void set_menu_type(std::string &s); + void set_sort(std::string &s); + void set_comparators(std::string &s); +}; + class InitLineInput; struct game_options { @@ -1394,8 +1432,7 @@ public: std::vector menu_colour_mappings; std::vector message_colour_mappings; - int sort_menus; // 0 = always, -1 = never, number = beyond - // that size. + std::vector sort_menus; int dump_kill_places; // How to dump place information for kills. int dump_message_count; // How many old messages to dump @@ -1522,6 +1559,7 @@ private: const std::string &interrupt_names, bool append_interrupts, bool remove_interrupts); + void set_menu_sort(std::string field); void new_dump_fields(const std::string &text, bool add = true); void do_kill_map(const std::string &from, const std::string &to); int read_explore_stop_conditions(const std::string &) const; -- cgit v1.2.3-54-g00ecf