00001
00002
00003
00004
00005
00006
00007
00008 #ifndef INVENT_H
00009 #define INVENT_H
00010
00011 #include <stddef.h>
00012 #include <vector>
00013 #include "menu.h"
00014 #include "enum.h"
00015 #include "itemname.h"
00016
00017 enum object_selector
00018 {
00019 OSEL_ANY = -1,
00020 OSEL_WIELD = -2,
00021 OSEL_UNIDENT = -3,
00022 OSEL_EQUIP = -4,
00023 OSEL_RECHARGE = -5,
00024 OSEL_ENCH_ARM = -6,
00025 OSEL_VAMP_EAT = -7,
00026 OSEL_DRAW_DECK = -8,
00027 OSEL_THROWABLE = -9,
00028 OSEL_BUTCHERY = -10,
00029 OSEL_EVOKABLE = -11,
00030 OSEL_WORN_ARMOUR = -12,
00031 OSEL_FRUIT = -13,
00032 OSEL_PONDER_ARM = -14,
00033 OSEL_CURSED_WORN = -15,
00034 };
00035
00036 #define PROMPT_ABORT -1
00037 #define PROMPT_GOT_SPECIAL -2
00038 #define PROMPT_NOTHING -3
00039 #define PROMPT_INAPPROPRIATE -4
00040
00041 struct SelItem
00042 {
00043 int slot;
00044 int quantity;
00045 const item_def *item;
00046
00047 SelItem() : slot(0), quantity(0), item(NULL) { }
00048 SelItem(int s, int q, const item_def *it = NULL)
00049 : slot(s), quantity(q), item(it)
00050 {
00051 }
00052 };
00053
00054 typedef std::string (*invtitle_annotator)(
00055 const Menu *m, const std::string &oldtitle);
00056
00057 class InvTitle : public MenuEntry
00058 {
00059 public:
00060 InvTitle(Menu *mn, const std::string &title,
00061 invtitle_annotator tfn);
00062
00063 std::string get_text(const bool = false) const;
00064
00065 private:
00066 Menu *m;
00067 invtitle_annotator titlefn;
00068 };
00069
00070 class InvShowPrices;
00071 class InvEntry : public MenuEntry
00072 {
00073 private:
00074 static bool show_prices;
00075 static bool show_glyph;
00076 static bool show_cursor;
00077 static void set_show_prices(bool doshow);
00078
00079 mutable std::string basename;
00080 mutable std::string qualname;
00081
00082 friend class InvShowPrices;
00083
00084 public:
00085 const item_def *item;
00086
00087 InvEntry(const item_def &i);
00088 std::string get_text(const bool need_cursor = false) const;
00089 void set_show_glyph(bool doshow);
00090 static void set_show_cursor(bool doshow);
00091
00092 const std::string &get_basename() const;
00093 const std::string &get_qualname() const;
00094 const std::string &get_fullname() const;
00095 bool is_item_cursed() const;
00096 bool is_item_glowing() const;
00097 bool is_item_ego() const;
00098 bool is_item_art() const;
00099 bool is_item_equipped() const;
00100 int item_freshness() const;
00101
00102 virtual int highlight_colour() const
00103 {
00104 return menu_colour(get_text(), menu_colour_item_prefix(*item), tag);
00105 }
00106
00107 virtual void select(int qty = -1);
00108
00109 virtual std::string get_filter_text() const;
00110
00111 #ifdef USE_TILE
00112 virtual bool get_tiles(std::vector<tile_def>& tiles) const;
00113 #endif
00114
00115 private:
00116 void add_class_hotkeys(const item_def &i);
00117 };
00118
00119 class InvShowPrices
00120 {
00121 public:
00122 InvShowPrices(bool doshow = true);
00123 ~InvShowPrices();
00124 };
00125
00126 class InvMenu : public Menu
00127 {
00128 public:
00129 InvMenu(int mflags = MF_MULTISELECT);
00130
00131 public:
00132 unsigned char getkey() const;
00133
00134 void set_preselect(const std::vector<SelItem> *pre);
00135 void set_type(menu_type t);
00136
00137
00138
00139
00140 void set_title_annotator(invtitle_annotator fn);
00141
00142 void set_title(MenuEntry *title, bool first = true);
00143 void set_title(const std::string &s);
00144
00145
00146
00147
00148 void load_items(const std::vector<const item_def*> &items,
00149 MenuEntry *(*procfn)(MenuEntry *me) = NULL);
00150
00151
00152
00153
00154 void load_inv_items(int item_selector = OSEL_ANY, int excluded_slot = -1,
00155 MenuEntry *(*procfn)(MenuEntry *me) = NULL);
00156
00157 std::vector<SelItem> get_selitems() const;
00158
00159
00160
00161
00162 static std::vector<const item_def*> xlat_itemvect(
00163 const std::vector<item_def> &);
00164 const menu_sort_condition *find_menu_sort_condition() const;
00165 void sort_menu(std::vector<InvEntry*> &items,
00166 const menu_sort_condition *cond);
00167
00168 protected:
00169 bool process_key(int key);
00170 void do_preselect(InvEntry *ie);
00171 virtual bool is_selectable(int index) const;
00172
00173 protected:
00174 menu_type type;
00175 const std::vector<SelItem> *pre_select;
00176
00177 invtitle_annotator title_annotate;
00178 };
00179
00180 bool any_items_to_select(int type_expect, bool msg = false);
00181
00182 int prompt_invent_item(const char *prompt,
00183 menu_type type,
00184 int type_expect,
00185 bool must_exist = true,
00186 bool allow_auto_list = true,
00187 bool allow_easy_quit = true,
00188 const char other_valid_char = '\0',
00189 int excluded_slot = -1,
00190 int *const count = NULL,
00191 operation_types oper = OPER_ANY,
00192 bool allow_list_known = false);
00193
00194 std::vector<SelItem> select_items(
00195 const std::vector<const item_def*> &items,
00196 const char *title, bool noselect = false,
00197 menu_type mtype = MT_PICKUP);
00198
00199 std::vector<SelItem> prompt_invent_items(
00200 const char *prompt,
00201 menu_type type,
00202 int type_expect,
00203 invtitle_annotator titlefn = NULL,
00204 bool allow_auto_list = true,
00205 bool allow_easy_quit = true,
00206 const char other_valid_char = '\0',
00207 std::vector<text_pattern> *filter = NULL,
00208 Menu::selitem_tfn fn = NULL,
00209 const std::vector<SelItem> *pre_select = NULL);
00210
00211
00212 unsigned char invent_select(
00213
00214 const char *title = NULL,
00215
00216 menu_type type = MT_INVLIST,
00217 int item_selector = OSEL_ANY,
00218 int excluded_slot = -1,
00219 int menu_select_flags = MF_NOSELECT,
00220 invtitle_annotator titlefn = NULL,
00221 std::vector<SelItem> *sels = NULL,
00222 std::vector<text_pattern> *filter = NULL,
00223 Menu::selitem_tfn fn = NULL,
00224 const std::vector<SelItem> *pre_select = NULL);
00225
00226 void browse_inventory(bool show_price);
00227 unsigned char get_invent(int invent_type);
00228
00229 bool in_inventory(const item_def &i);
00230
00231 std::string item_class_name(int type, bool terse = false);
00232
00233 bool check_old_item_warning(const item_def& item, operation_types oper);
00234 bool check_warning_inscriptions(const item_def& item, operation_types oper);
00235
00236 void init_item_sort_comparators(item_sort_comparators &list,
00237 const std::string &set);
00238
00239 bool prompt_failed(int retval, std::string msg = "");
00240
00241 bool item_is_evokable(const item_def &item, bool known = false,
00242 bool all_wands = false, bool msg = false);
00243 bool needs_handle_warning(const item_def &item, operation_types oper);
00244 #endif