From 8e2692d7dcf7a55e083413e2eca110b7d5919976 Mon Sep 17 00:00:00 2001 From: j-p-e-g Date: Mon, 18 Feb 2008 17:06:11 +0000 Subject: Finally implemented by applying Paul Du Bois' latest patch. :) git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3442 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/menu.cc | 23 +++++++++++++++++++---- crawl-ref/source/menu.h | 8 +++++--- crawl-ref/source/output.cc | 38 ++++++++++++++++++++++++++++++-------- 3 files changed, 54 insertions(+), 15 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index ab8f493432..e7a527a972 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -181,10 +181,13 @@ std::vector Menu::show(bool reuse_selections) { cursor_control cs(false); - if (reuse_selections) + if (reuse_selections) { get_selected(&sel); - else + } else { deselect_all(false); + sel.clear(); + } + // Lose lines for the title + room for -more- line. pagesize = get_number_of_lines() - !!title - 1; @@ -1275,8 +1278,10 @@ void formatted_scroller::add_item_formatted_string(const formatted_string& fs, { MenuEntry* me = new MenuEntry; me->data = new formatted_string(fs); - if ( hotkey ) + if ( hotkey ) { me->add_hotkey(hotkey); + me->quantity = 1; + } add_entry(me); } @@ -1571,7 +1576,17 @@ bool formatted_scroller::process_key( int keyin ) break; } default: - repaint = jump_to_hotkey(keyin); + if (is_set(MF_SINGLESELECT)) + { + select_items( keyin, -1 ); + get_selected( &sel ); + if (sel.size() >= 1) + return false; + } + else + { + repaint = jump_to_hotkey(keyin); + } break; } diff --git a/crawl-ref/source/menu.h b/crawl-ref/source/menu.h index de060b354f..2e84cfd59d 100644 --- a/crawl-ref/source/menu.h +++ b/crawl-ref/source/menu.h @@ -413,9 +413,11 @@ private: }; // This class is for when (some of) your items are formatted, and -// selection is impossible...in other words, you just want a browser. -// Hotkeys can be set on menu items, in which case you can jump -// to them by pressing the appropriate key. +// you want mostly a browser. +// +// If MF_NOSELECT, hotkeys jump to menu items. +// If MF_SINGLESELECT, hotkeys end the menu immediately. +// MF_MULTISELECT is not supported. class formatted_scroller : public Menu { public: diff --git a/crawl-ref/source/output.cc b/crawl-ref/source/output.cc index 585ca6d078..e03f15cbfb 100644 --- a/crawl-ref/source/output.cc +++ b/crawl-ref/source/output.cc @@ -1121,7 +1121,7 @@ void print_overview_screen() bool calc_unid = false; formatted_scroller cmd_help; // Set flags, and don't use easy exit. - cmd_help.set_flags(MF_NOSELECT | MF_ALWAYS_SHOW_MORE | MF_NOWRAP, false); + cmd_help.set_flags(MF_SINGLESELECT | 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("resists"); @@ -1363,6 +1363,7 @@ void print_overview_screen() determine_color_string(rcfli), itosym1(rcfli)); cols.add_formatted(1, buf, false); + std::vector equip_chars; { const int e_order[] = { @@ -1377,11 +1378,14 @@ void print_overview_screen() if ( you.equip[ e_order[i] ] != -1) { - const item_def& item = you.inv[you.equip[e_order[i]]]; + const int item_idx = you.equip[e_order[i]]; + const item_def& item = you.inv[item_idx]; const char* colname = colour_to_str(item.colour); - snprintf(buf, sizeof buf, "%-7s: <%s>%s", - slot, colname, - item.name(DESC_PLAIN).substr(0,37).c_str(), colname); + const char equip_char = index_to_letter(item_idx); + snprintf(buf, sizeof buf, "%-7s: %c - <%s>%s", + slot, equip_char, colname, + item.name(DESC_PLAIN).substr(0,33).c_str(), colname); + equip_chars.push_back(equip_char); } else { @@ -1429,12 +1433,30 @@ void print_overview_screen() blines = cols.formatted_lines(); for (i = 0; i < blines.size(); ++i ) - cmd_help.add_item_formatted_string(blines[i]); + { + // Kind of a hack -- we don't care really what items these + // hotkeys go to. So just pick the first few. + const char hotkey = (i < equip_chars.size()) ? equip_chars[i] : 0; + cmd_help.add_item_formatted_string(blines[i], hotkey); + } cmd_help.add_text(" "); cmd_help.add_text(status_mut_abilities()); - cmd_help.show(); - redraw_screen(); + + while (true) + { + std::vector results = cmd_help.show(); + if (results.size() == 0) + { + redraw_screen(); + break; + } + + const char c = results[0]->hotkeys[0]; + item_def& item = you.inv[letter_to_index(c)]; + describe_item(item, false); + // loop around for another go. + } } // creates rows of short descriptions for current -- cgit v1.2.3-54-g00ecf