OSDN Git Service

Merge pull request #3532 from sikabane-works/release/3.0.0.87-alpha
[hengbandforosx/hengbandosx.git] / src / view / display-inventory.cpp
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"
20
21 /*!
22  * @brief 所持アイテムの表示を行う /
23  * Display the inventory.
24  * @param target_item アイテムの選択処理を行うか否か。
25  * @return 選択したアイテムのタグ
26  * @details
27  * Hack -- do not display "trailing" empty slots
28  */
29 COMMAND_CODE show_inventory(PlayerType *player_ptr, int target_item, BIT_FLAGS mode, const ItemTester &item_tester)
30 {
31     COMMAND_CODE i;
32     int k, l, z = 0;
33     ItemEntity *o_ptr;
34     char tmp_val[80];
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];
40
41     int col = command_gap;
42     TERM_LEN wid, hgt;
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()) {
48             continue;
49         }
50
51         z = i + 1;
52     }
53
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)) {
58             continue;
59         }
60
61         out_index[k] = i;
62         out_color[k] = tval_to_attr[enum2i(o_ptr->bi_key.tval()) % 128];
63         if (o_ptr->timeout) {
64             out_color[k] = TERM_L_DARK;
65         }
66
67         out_desc[k] = describe_flavor(player_ptr, o_ptr, 0);
68         l = out_desc[k].length() + 5;
69         if (show_weights) {
70             l += 9;
71         }
72
73         if (show_item_graph) {
74             l += 2;
75             if (use_bigtile) {
76                 l++;
77             }
78         }
79
80         if (l > len) {
81             len = l;
82         }
83
84         k++;
85     }
86
87     col = (len > wid - 4) ? 0 : (wid - len - 1);
88     int cur_col;
89     int j;
90     for (j = 0; j < k; j++) {
91         i = out_index[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;
98             } else {
99                 angband_strcpy(tmp_val, "  ", sizeof(tmp_val));
100             }
101         } else if (i <= INVEN_PACK) {
102             strnfmt(tmp_val, sizeof(tmp_val), "%c)", inven_label[i]);
103         } else {
104             strnfmt(tmp_val, sizeof(tmp_val), "%c)", index_to_label(i));
105         }
106
107         put_str(tmp_val, j + 1, col);
108         cur_col = col + 3;
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);
113             if (use_bigtile) {
114                 cur_col++;
115             }
116
117             cur_col += 2;
118         }
119
120         c_put_str(out_color[j], out_desc[j], j + 1, cur_col);
121         if (show_weights) {
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);
125         }
126     }
127
128     if (j && (j < 23)) {
129         prt("", j + 1, col ? col - 2 : col);
130     }
131
132     command_gap = col;
133     return target_item_label;
134 }
135
136 /*!
137  * @brief 所持アイテム一覧を表示する /
138  * Choice window "shadow" of the "show_inven()" function
139  */
140 void display_inventory(PlayerType *player_ptr, const ItemTester &item_tester)
141 {
142     int i, z = 0;
143     TERM_COLOR attr = TERM_WHITE;
144     char tmp_val[80];
145     TERM_LEN wid, hgt;
146
147     if (!player_ptr || !player_ptr->inventory_list) {
148         return;
149     }
150
151     term_get_size(&wid, &hgt);
152
153     for (i = 0; i < INVEN_PACK; i++) {
154         auto o_ptr = &player_ptr->inventory_list[i];
155         if (!o_ptr->is_valid()) {
156             continue;
157         }
158         z = i + 1;
159     }
160
161     for (i = 0; i < z; i++) {
162         if (i >= hgt) {
163             break;
164         }
165
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));
169         if (do_disp) {
170             tmp_val[0] = index_to_label(i);
171             tmp_val[1] = ')';
172         }
173
174         int cur_col = 3;
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) {
180             attr = TERM_L_DARK;
181         }
182
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);
187             if (use_bigtile) {
188                 cur_col++;
189             }
190
191             cur_col += 2;
192         }
193
194         term_putstr(cur_col, i, item_name.length(), attr, item_name);
195
196         if (show_weights) {
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);
202         }
203     }
204
205     for (i = z; i < hgt; i++) {
206         term_erase(0, i, 255);
207     }
208 }