1 #include "view/display-inventory.h"
2 #include "flavor/flavor-describer.h"
3 #include "game-option/special-options.h"
4 #include "game-option/text-display-options.h"
5 #include "inventory/inventory-slot-types.h"
6 #include "inventory/inventory-util.h"
7 #include "io/input-key-requester.h"
8 #include "locale/japanese.h"
9 #include "object/item-tester-hooker.h"
10 #include "object/item-use-flags.h"
11 #include "object/object-info.h"
12 #include "system/baseitem-info.h"
13 #include "system/item-entity.h"
14 #include "system/player-type-definition.h"
15 #include "term/gameterm.h"
16 #include "term/screen-processor.h"
17 #include "term/term-color-types.h"
18 #include "term/z-form.h"
19 #include "util/string-processor.h"
22 * @brief 所持アイテムの表示を行う /
23 * Display the inventory.
24 * @param target_item アイテムの選択処理を行うか否か。
27 * Hack -- do not display "trailing" empty slots
29 COMMAND_CODE show_inventory(PlayerType *player_ptr, int target_item, BIT_FLAGS mode, const ItemTester &item_tester)
35 COMMAND_CODE out_index[23];
36 TERM_COLOR out_color[23];
37 std::array<std::string, 23> out_desc{};
38 COMMAND_CODE target_item_label = 0;
39 char inven_label[52 + 1];
41 int col = command_gap;
43 term_get_size(&wid, &hgt);
44 int len = wid - col - 1;
45 for (i = 0; i < INVEN_PACK; i++) {
46 o_ptr = &player_ptr->inventory_list[i];
47 if (!o_ptr->is_valid()) {
54 prepare_label_string(player_ptr, inven_label, USE_INVEN, item_tester);
55 for (k = 0, i = 0; i < z; i++) {
56 o_ptr = &player_ptr->inventory_list[i];
57 if (!item_tester.okay(o_ptr) && !(mode & USE_FULL)) {
62 out_color[k] = tval_to_attr[enum2i(o_ptr->bi_key.tval()) % 128];
64 out_color[k] = TERM_L_DARK;
67 out_desc[k] = describe_flavor(player_ptr, o_ptr, 0);
68 l = out_desc[k].length() + 5;
73 if (show_item_graph) {
87 col = (len > wid - 4) ? 0 : (wid - len - 1);
90 for (j = 0; j < k; j++) {
92 o_ptr = &player_ptr->inventory_list[i];
93 prt("", j + 1, col ? col - 2 : col);
94 if (use_menu && target_item) {
95 if (j == (target_item - 1)) {
96 angband_strcpy(tmp_val, _("》", "> "), sizeof(tmp_val));
97 target_item_label = i;
99 angband_strcpy(tmp_val, " ", sizeof(tmp_val));
101 } else if (i <= INVEN_PACK) {
102 strnfmt(tmp_val, sizeof(tmp_val), "%c)", inven_label[i]);
104 strnfmt(tmp_val, sizeof(tmp_val), "%c)", index_to_label(i));
107 put_str(tmp_val, j + 1, col);
109 if (show_item_graph) {
110 const auto a = o_ptr->get_color();
111 const auto c = o_ptr->get_symbol();
112 term_queue_bigchar(cur_col, j + 1, a, c, 0, 0);
120 c_put_str(out_color[j], out_desc[j], j + 1, cur_col);
122 int wgt = o_ptr->weight * o_ptr->number;
123 strnfmt(tmp_val, sizeof(tmp_val), _("%3d.%1d kg", "%3d.%1d lb"), _(lb_to_kg_integer(wgt), wgt / 10), _(lb_to_kg_fraction(wgt), wgt % 10));
124 prt(tmp_val, j + 1, wid - 9);
129 prt("", j + 1, col ? col - 2 : col);
133 return target_item_label;
137 * @brief 所持アイテム一覧を表示する /
138 * Choice window "shadow" of the "show_inven()" function
140 void display_inventory(PlayerType *player_ptr, const ItemTester &item_tester)
143 TERM_COLOR attr = TERM_WHITE;
147 if (!player_ptr || !player_ptr->inventory_list) {
151 term_get_size(&wid, &hgt);
153 for (i = 0; i < INVEN_PACK; i++) {
154 auto o_ptr = &player_ptr->inventory_list[i];
155 if (!o_ptr->is_valid()) {
161 for (i = 0; i < z; i++) {
166 auto o_ptr = &player_ptr->inventory_list[i];
167 auto do_disp = item_tester.okay(o_ptr);
168 angband_strcpy(tmp_val, " ", sizeof(tmp_val));
170 tmp_val[0] = index_to_label(i);
175 term_erase(cur_col, i, 255);
176 term_putstr(0, i, cur_col, TERM_WHITE, tmp_val);
177 const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
178 attr = tval_to_attr[enum2i(o_ptr->bi_key.tval()) % 128];
179 if (o_ptr->timeout) {
183 if (show_item_graph) {
184 const auto a = o_ptr->get_color();
185 const auto c = o_ptr->get_symbol();
186 term_queue_bigchar(cur_col, i, a, c, 0, 0);
194 term_putstr(cur_col, i, item_name.length(), attr, item_name);
197 int wgt = o_ptr->weight * o_ptr->number;
198 strnfmt(tmp_val, sizeof(tmp_val), _("%3d.%1d kg", "%3d.%1d lb"),
199 _(lb_to_kg_integer(wgt), wgt / 10),
200 _(lb_to_kg_fraction(wgt), wgt % 10));
201 prt(tmp_val, i, wid - 9);
205 for (i = z; i < hgt; i++) {
206 term_erase(0, i, 255);