summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2006-11-22 18:17:58 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2006-11-22 18:17:58 +0000
commit5f1be66956e19f339f4baef51bb11fef105a127f (patch)
treebc080f09d9493d53814b6dfdc28d02abef9f6d9f
parent83d3cb73a826d442277adf0814e3440fd9e70cae (diff)
downloadcrawl-ref-5f1be66956e19f339f4baef51bb11fef105a127f.tar.gz
crawl-ref-5f1be66956e19f339f4baef51bb11fef105a127f.zip
Implemented 1601230: sort_menus can now be of the form auto:5 (the default),
in which case categories with >= 5 items will be sorted. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@476 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/docs/crawl_options.txt8
-rw-r--r--crawl-ref/source/clua.cc1
-rw-r--r--crawl-ref/source/externs.h3
-rw-r--r--crawl-ref/source/initfile.cc25
-rw-r--r--crawl-ref/source/invent.cc3
5 files changed, 33 insertions, 7 deletions
diff --git a/crawl-ref/docs/crawl_options.txt b/crawl-ref/docs/crawl_options.txt
index 2555b0fd3b..505dbb0e49 100644
--- a/crawl-ref/docs/crawl_options.txt
+++ b/crawl-ref/docs/crawl_options.txt
@@ -632,10 +632,14 @@ default_autoprayer = false
Also note the option safe_zero_exp (see 4-a) decides whether zero
experience monsters (like plants) are considered hostile.
-sort_menus = false
+sort_menus = auto:5
When set to true, items are sorted by description in inventory and
pickup menus. When set to false (default), items are ordered by
- equipment slot.
+ equipment slot. When set to a number - using a syntax of the form
+ sort_menus = auto:5 - items are sorted by their description if
+ the total number of items in that category is at least that
+ number; in the default case, having 4 kinds of potions would not
+ sort them, but having 5 would.
4-i Messages and Display Enhancements.
diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc
index 9885fc05d3..18d0a92af2 100644
--- a/crawl-ref/source/clua.cc
+++ b/crawl-ref/source/clua.cc
@@ -1894,7 +1894,6 @@ static option_handler handlers[] =
option_hboolean },
{ "pickup_thrown", &Options.pickup_thrown, option_hboolean },
{ "pickup_dropped", &Options.pickup_dropped, option_hboolean },
- { "sort_menus", &Options.sort_menus, option_hboolean },
{ "show_waypoints", &Options.show_waypoints, option_hboolean },
{ "item_colour", &Options.item_colour, option_hboolean },
{ "target_zero_exp", &Options.target_zero_exp, option_hboolean },
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index 51288baa43..7ff9054ed6 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -813,7 +813,8 @@ public:
std::vector<sound_mapping> sound_mappings;
std::vector<colour_mapping> menu_colour_mappings;
- bool sort_menus;
+ int sort_menus; // 0 = always, -1 = never, number = beyond
+ // that size.
int dump_kill_places; // How to dump place information for kills.
int dump_message_count; // How many old messages to dump
diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc
index a797100754..61e05b9aa6 100644
--- a/crawl-ref/source/initfile.cc
+++ b/crawl-ref/source/initfile.cc
@@ -322,6 +322,27 @@ static bool read_bool( const std::string &field, bool def_value )
return (ret);
}
+// read a value which can be either a boolean (in which case return
+// 0 for true, -1 for false), or a string of the form PREFIX:NUMBER
+// (e.g., auto:7), in which case return NUMBER as an int.
+static int read_bool_or_number( const std::string &field, int def_value,
+ const std::string& num_prefix)
+{
+ int ret = def_value;
+
+ if (field == "true" || field == "1" || field == "yes")
+ ret = 0;
+
+ if (field == "false" || field == "0" || field == "no")
+ ret = -1;
+
+ if ( field.find(num_prefix) == 0 )
+ ret = atoi(field.c_str() + num_prefix.size());
+
+ return (ret);
+}
+
+
static unsigned curses_attribute(const std::string &field)
{
if (field == "standout") // probably reverses
@@ -547,7 +568,7 @@ void game_options::reset_options()
travel_stair_cost = 500;
travel_exclude_radius2 = 68;
- sort_menus = false;
+ sort_menus = 5;
tc_reachable = BLUE;
tc_excluded = LIGHTMAGENTA;
@@ -1643,7 +1664,7 @@ void game_options::read_option_line(const std::string &str, bool runscript)
#endif // WIZARD
else if (key == "sort_menus")
{
- sort_menus = read_bool(field, sort_menus);
+ sort_menus = read_bool_or_number(field, sort_menus, "auto:");
}
else if (key == "travel_delay")
{
diff --git a/crawl-ref/source/invent.cc b/crawl-ref/source/invent.cc
index f8545bb11c..8302728722 100644
--- a/crawl-ref/source/invent.cc
+++ b/crawl-ref/source/invent.cc
@@ -291,7 +291,8 @@ void InvMenu::load_items(const std::vector<const item_def*> &mitems,
items_in_class.push_back( new InvEntry(*mitems[j]) );
}
- if (Options.sort_menus)
+ if (Options.sort_menus != -1 &&
+ (int)items_in_class.size() >= Options.sort_menus)
std::sort( items_in_class.begin(), items_in_class.end(),
compare_menu_entries );