summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/command.cc5
-rw-r--r--crawl-ref/source/decks.cc5
-rw-r--r--crawl-ref/source/effects.cc5
-rw-r--r--crawl-ref/source/food.cc5
-rw-r--r--crawl-ref/source/invent.cc132
-rw-r--r--crawl-ref/source/invent.h3
-rw-r--r--crawl-ref/source/item_use.cc51
-rw-r--r--crawl-ref/source/spells1.cc5
-rw-r--r--crawl-ref/source/spl-book.cc5
9 files changed, 104 insertions, 112 deletions
diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc
index a50b5d0ac7..98847ab7ea 100644
--- a/crawl-ref/source/command.cc
+++ b/crawl-ref/source/command.cc
@@ -330,11 +330,8 @@ static void _adjust_item(void)
}
from_slot = prompt_invent_item( "Adjust which item?", MT_INVLIST, -1 );
- if (from_slot == PROMPT_ABORT)
- {
- canned_msg( MSG_OK );
+ if (prompt_failed(from_slot))
return;
- }
mpr(you.inv[from_slot].name(DESC_INVENTORY_EQUIP).c_str());
diff --git a/crawl-ref/source/decks.cc b/crawl-ref/source/decks.cc
index 532674e323..ff4fecc5f2 100644
--- a/crawl-ref/source/decks.cc
+++ b/crawl-ref/source/decks.cc
@@ -712,11 +712,8 @@ static int _choose_inventory_deck( const char* prompt )
true, true, true, 0, NULL,
OPER_EVOKE );
- if ( slot == PROMPT_ABORT )
- {
- canned_msg(MSG_OK);
+ if (prompt_failed(slot))
return -1;
- }
if ( !is_deck(you.inv[slot]) )
{
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index 254f3fc7f0..d680b97445 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -1763,11 +1763,8 @@ bool recharge_wand(int item_slot)
OSEL_RECHARGE, true, true, false );
}
- if (item_slot == PROMPT_ABORT)
- {
- canned_msg( MSG_OK );
+ if (prompt_failed(item_slot))
return (false);
- }
item_def &wand = you.inv[ item_slot ];
diff --git a/crawl-ref/source/food.cc b/crawl-ref/source/food.cc
index 5f69c4f1ec..81c2d16a18 100644
--- a/crawl-ref/source/food.cc
+++ b/crawl-ref/source/food.cc
@@ -720,11 +720,8 @@ bool prompt_eat_from_inventory(int slot)
OPER_EAT );
}
- if (which_inventory_slot == PROMPT_ABORT)
- {
- canned_msg( MSG_OK );
+ if (prompt_failed(which_inventory_slot))
return (false);
- }
// This conditional can later be merged into food::can_ingest() when
// expanded to handle more than just OBJ_FOOD 16mar200 {dlb}
diff --git a/crawl-ref/source/invent.cc b/crawl-ref/source/invent.cc
index 165440baca..3a3f6169d6 100644
--- a/crawl-ref/source/invent.cc
+++ b/crawl-ref/source/invent.cc
@@ -45,6 +45,7 @@
#include "menu.h"
#include "mon-util.h"
#include "randart.h"
+#include "state.h"
#include "tiles.h"
@@ -325,6 +326,42 @@ void InvMenu::set_title(const std::string &s)
set_title(new InvTitle(this, stitle, title_annotate));
}
+static std::string _no_selectables_message(int item_selector)
+{
+ switch (item_selector)
+ {
+ case OSEL_ANY:
+ return("You aren't carrying anything.");
+ case OSEL_WIELD:
+ case OBJ_WEAPONS:
+ return("You aren't carrying any weapons.");
+ case OSEL_UNIDENT:
+ return("You don't have any unidentified items.");
+ case OSEL_MEMORISE:
+ return("You aren't carrying any spellbooks.");
+ case OSEL_RECHARGE:
+ return("You aren't carrying any rechargable items.");
+ case OSEL_ENCH_ARM:
+ case OBJ_ARMOUR:
+ return("You aren't carrying any armour which can be enchanted "
+ "further.");
+ case OBJ_CORPSES:
+ case OSEL_VAMP_EAT:
+ return("You aren't carrying any corpses which you can drain.");
+ case OSEL_DRAW_DECK:
+ return("You aren't carrying any decks from which to draw.");
+ case OBJ_FOOD:
+ return("You aren't carrying any food.");
+ case OBJ_SCROLLS:
+ case OBJ_BOOKS:
+ return("You aren't carrying any books or scrolls.");
+ case OBJ_WANDS:
+ return("You aren't carrying any wands.");
+ }
+
+ return("You aren't carrying any such object.");
+}
+
void InvMenu::load_inv_items(int item_selector,
MenuEntry *(*procfn)(MenuEntry *me))
{
@@ -334,52 +371,7 @@ void InvMenu::load_inv_items(int item_selector,
load_items(tobeshown, procfn);
if (!item_count())
{
- std::string s;
- switch (item_selector)
- {
- case OSEL_ANY:
- s = "You aren't carrying anything.";
- break;
- case OSEL_WIELD:
- case OBJ_WEAPONS:
- s = "You aren't carrying any weapons.";
- break;
- case OSEL_UNIDENT:
- s = "You don't have any unidentified items.";
- break;
- case OSEL_MEMORISE:
- s = "You aren't carrying any spellbooks.";
- break;
- case OSEL_RECHARGE:
- s = "You aren't carrying any rechargable items.";
- break;
- case OSEL_ENCH_ARM:
- case OBJ_ARMOUR:
- s = "You aren't carrying any armour which can be enchanted "
- "further.";
- break;
- case OBJ_CORPSES:
- case OSEL_VAMP_EAT:
- s = "You aren't carrying any corpses which you can drain.";
- break;
- case OSEL_DRAW_DECK:
- s = "You aren't carrying any decks from which to draw.";
- break;
- case OBJ_FOOD:
- s = "You aren't carrying any food.";
- break;
- case OBJ_SCROLLS:
- case OBJ_BOOKS:
- s = "You aren't carrying any books or scrolls.";
- break;
- case OBJ_WANDS:
- s = "You aren't carrying any wands.";
- break;
- default:
- s = "You aren't carrying any such object.";
- break;
- }
- set_title(s);
+ set_title(_no_selectables_message(item_selector));
}
else
{
@@ -873,6 +865,19 @@ static void _get_inv_items_to_show(std::vector<const item_def*> &v, int selector
}
}
+static bool _any_items_to_select(int selector)
+{
+ for (int i = 0; i < ENDOFPACK; i++)
+ {
+ if (is_valid_item(you.inv[i])
+ && _is_item_selected(you.inv[i], selector))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
unsigned char invent_select(
const char *title,
menu_type type,
@@ -1282,6 +1287,7 @@ bool check_warning_inscriptions( const item_def& item,
//
// It returns PROMPT_ABORT if the player hits escape.
// It returns PROMPT_GOT_SPECIAL if the player hits the "other_valid_char".
+// It retursn PROMPT_NOTHING if there's no matching items
//
// Note: This function never checks if the item is appropriate.
int prompt_invent_item( const char *prompt,
@@ -1292,8 +1298,16 @@ int prompt_invent_item( const char *prompt,
int *const count,
operation_types oper )
{
+ if (!_any_items_to_select(type_expect) && type_expect != OSEL_WIELD
+ && mtype == MT_INVLIST)
+ {
+ mprf(MSGCH_PROMPT, "%s",
+ _no_selectables_message(type_expect).c_str());
+ return (PROMPT_NOTHING);
+ }
+
unsigned char keyin = 0;
- int ret = PROMPT_ABORT;
+ int ret = PROMPT_ABORT;
bool need_redraw = false;
bool need_prompt = true;
@@ -1303,7 +1317,11 @@ int prompt_invent_item( const char *prompt,
if (auto_list)
{
need_prompt = need_getch = false;
- keyin = '?';
+
+ if (_any_items_to_select(type_expect))
+ keyin = '?';
+ else
+ keyin = '*';
}
while (true)
@@ -1410,3 +1428,21 @@ int prompt_invent_item( const char *prompt,
return (ret);
}
+
+bool prompt_failed(int retval, std::string msg)
+{
+ if (retval != PROMPT_ABORT && retval != PROMPT_NOTHING)
+ return false;
+
+ if (msg.empty())
+ {
+ if (retval == PROMPT_ABORT)
+ canned_msg(MSG_OK);
+ }
+ else
+ mprf(MSGCH_PROMPT, msg.c_str());
+
+ crawl_state.cancel_cmd_repeat();
+
+ return true;
+}
diff --git a/crawl-ref/source/invent.h b/crawl-ref/source/invent.h
index 46a3ead180..f11916107e 100644
--- a/crawl-ref/source/invent.h
+++ b/crawl-ref/source/invent.h
@@ -35,6 +35,7 @@ enum object_selector
#define PROMPT_ABORT -1
#define PROMPT_GOT_SPECIAL -2
+#define PROMPT_NOTHING -3
struct SelItem
{
@@ -231,4 +232,6 @@ bool has_warning_inscription(const item_def& item, operation_types oper);
void init_item_sort_comparators(item_sort_comparators &list,
const std::string &set);
+bool prompt_failed(int retval, std::string msg = "");
+
#endif
diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc
index 220aaefc69..ccc7e73915 100644
--- a/crawl-ref/source/item_use.cc
+++ b/crawl-ref/source/item_use.cc
@@ -273,11 +273,8 @@ bool wield_weapon(bool auto_wield, int slot, bool show_weff_messages)
item_slot = PROMPT_GOT_SPECIAL;
}
- if (item_slot == PROMPT_ABORT)
- {
- canned_msg( MSG_OK );
+ if (prompt_failed(item_slot))
return (false);
- }
else if (item_slot == you.equip[EQ_WEAPON])
{
mpr("You are already wielding that!");
@@ -789,9 +786,7 @@ bool armour_prompt( const std::string & mesg, int *index, operation_types oper)
true, true, true, 0, NULL,
oper );
- if (slot == PROMPT_ABORT)
- canned_msg(MSG_OK);
- else
+ if (!prompt_failed(slot))
{
*index = slot;
succeeded = true;
@@ -1499,7 +1494,7 @@ static int _fire_prompt_for_item(std::string& err)
MT_INVLIST,
OBJ_MISSILES, true, true, true, 0, NULL,
OPER_FIRE );
- if (slot == PROMPT_ABORT)
+ if (slot == PROMPT_ABORT || slot == PROMPT_NOTHING)
{
err = "Nothing selected.";
return -1;
@@ -3109,11 +3104,8 @@ bool puton_ring(int slot, bool prompt_finger)
MT_INVLIST, OBJ_JEWELLERY, true, true, true, 0, NULL,
OPER_PUTON );
- if (item_slot == PROMPT_ABORT)
- {
- canned_msg( MSG_OK );
+ if (prompt_failed(item_slot))
return (false);
- }
return puton_item(item_slot, prompt_finger);
} // end puton_ring()
@@ -3259,11 +3251,8 @@ bool remove_ring(int slot, bool announce)
0, NULL, OPER_REMOVE)
: slot;
- if (equipn == PROMPT_ABORT)
- {
- canned_msg( MSG_OK );
+ if (prompt_failed(equipn))
return (false);
- }
if (you.inv[equipn].base_type != OBJ_JEWELLERY)
{
@@ -3370,11 +3359,8 @@ void zap_wand( int slot )
OPER_ZAP );
}
- if (item_slot == PROMPT_ABORT)
- {
- canned_msg( MSG_OK );
+ if (prompt_failed(item_slot))
return;
- }
item_def& wand = you.inv[item_slot];
if (wand.base_type != OBJ_WANDS)
@@ -3538,11 +3524,8 @@ void prompt_inscribe_item()
}
item_slot = prompt_invent_item("Inscribe which item? ",
MT_INVLIST, OSEL_ANY );
- if (item_slot == PROMPT_ABORT)
- {
- canned_msg( MSG_OK );
+ if (prompt_failed(item_slot))
return;
- }
inscribe_item(you.inv[item_slot], true);
}
@@ -3595,11 +3578,8 @@ void drink( int slot )
OPER_QUAFF );
}
- if (item_slot == PROMPT_ABORT)
- {
- canned_msg( MSG_OK );
+ if (prompt_failed(item_slot))
return;
- }
if (you.inv[item_slot].base_type != OBJ_POTIONS)
{
@@ -4120,11 +4100,8 @@ static bool scroll_modify_item(const scroll_type scroll)
int item_slot = prompt_invent_item( "Use on which item?", MT_INVLIST,
OSEL_ANY, true, true, false );
- if (item_slot == PROMPT_ABORT)
- {
- canned_msg( MSG_OK );
+ if (prompt_failed(item_slot))
return (false);
- }
item_def &item = you.inv[item_slot];
@@ -4203,11 +4180,8 @@ void read_scroll( int slot )
true, true, true, 0, NULL,
OPER_READ );
- if (item_slot == PROMPT_ABORT)
- {
- canned_msg( MSG_OK );
+ if (prompt_failed(item_slot))
return;
- }
item_def& scroll = you.inv[item_slot];
@@ -4581,11 +4555,8 @@ void examine_object(void)
MT_INVLIST, -1,
true, true, true, 0, NULL,
OPER_EXAMINE );
- if (item_slot == PROMPT_ABORT)
- {
- canned_msg( MSG_OK );
+ if (prompt_failed(item_slot))
return;
- }
describe_item( you.inv[item_slot], true );
redraw_screen();
diff --git a/crawl-ref/source/spells1.cc b/crawl-ref/source/spells1.cc
index e52f5fb894..98607bb14c 100644
--- a/crawl-ref/source/spells1.cc
+++ b/crawl-ref/source/spells1.cc
@@ -434,11 +434,8 @@ void identify(int power, int item_slot)
item_slot = prompt_invent_item( "Identify which item?", MT_INVLIST,
OSEL_UNIDENT, true, true, false );
}
- if (item_slot == PROMPT_ABORT)
- {
- canned_msg( MSG_OK );
+ if (prompt_failed(item_slot))
return;
- }
item_def& item(you.inv[item_slot]);
diff --git a/crawl-ref/source/spl-book.cc b/crawl-ref/source/spl-book.cc
index 74c20c092c..0ad951587b 100644
--- a/crawl-ref/source/spl-book.cc
+++ b/crawl-ref/source/spl-book.cc
@@ -976,11 +976,8 @@ static int _which_spellbook( void )
book = prompt_invent_item("Memorise from which spellbook?", MT_INVLIST,
OSEL_MEMORISE );
- if (book == PROMPT_ABORT)
- {
- canned_msg( MSG_OK );
+ if (prompt_failed(book))
return (-1);
- }
if (you.inv[book].base_type != OBJ_BOOKS
|| you.inv[book].sub_type == BOOK_MANUAL)