OSDN Git Service

Merge remote-tracking branch 'remotes/hengbandosx/english-knowledge-edits' into featu...
[hengband/hengband.git] / src / view / display-inventory.c
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 "object/item-tester-hooker.h"
9 #include "object/item-use-flags.h"
10 #include "object/object-info.h"
11 #include "object/object-kind.h"
12 #include "system/object-type-definition.h"
13 #include "term/gameterm.h"
14 #include "term/screen-processor.h"
15 #include "term/term-color-types.h"
16
17 /*!
18  * @brief 所持アイテムの表示を行う /
19  * Display the inventory.
20  * @param target_item アイテムの選択処理を行うか否か。
21  * @return 選択したアイテムのタグ
22  * @details
23  * Hack -- do not display "trailing" empty slots
24  */
25 COMMAND_CODE show_inventory(player_type *owner_ptr, int target_item, BIT_FLAGS mode, tval_type tval)
26 {
27     COMMAND_CODE i;
28     int k, l, z = 0;
29     object_type *o_ptr;
30     GAME_TEXT o_name[MAX_NLEN];
31     char tmp_val[80];
32     COMMAND_CODE out_index[23];
33     TERM_COLOR out_color[23];
34     char out_desc[23][MAX_NLEN];
35     COMMAND_CODE target_item_label = 0;
36     char inven_label[52 + 1];
37
38     int col = command_gap;
39     TERM_LEN wid, hgt;
40     term_get_size(&wid, &hgt);
41     int len = wid - col - 1;
42     for (i = 0; i < INVEN_PACK; i++) {
43         o_ptr = &owner_ptr->inventory_list[i];
44         if (!o_ptr->k_idx)
45             continue;
46
47         z = i + 1;
48     }
49
50     prepare_label_string(owner_ptr, inven_label, USE_INVEN, tval);
51     for (k = 0, i = 0; i < z; i++) {
52         o_ptr = &owner_ptr->inventory_list[i];
53         if (!item_tester_okay(owner_ptr, o_ptr, tval) && !(mode & USE_FULL))
54             continue;
55
56         describe_flavor(owner_ptr, o_name, o_ptr, 0);
57         out_index[k] = i;
58         out_color[k] = tval_to_attr[o_ptr->tval % 128];
59         if (o_ptr->timeout)
60             out_color[k] = TERM_L_DARK;
61
62         (void)strcpy(out_desc[k], o_name);
63         l = strlen(out_desc[k]) + 5;
64         if (show_weights)
65             l += 9;
66
67         if (show_item_graph) {
68             l += 2;
69             if (use_bigtile)
70                 l++;
71         }
72
73         if (l > len)
74             len = l;
75
76         k++;
77     }
78
79     col = (len > wid - 4) ? 0 : (wid - len - 1);
80     int cur_col;
81     int j;
82     for (j = 0; j < k; j++) {
83         i = out_index[j];
84         o_ptr = &owner_ptr->inventory_list[i];
85         prt("", j + 1, col ? col - 2 : col);
86         if (use_menu && target_item) {
87             if (j == (target_item - 1)) {
88                 strcpy(tmp_val, _("》", "> "));
89                 target_item_label = i;
90             } else
91                 strcpy(tmp_val, "  ");
92         } else if (i <= INVEN_PACK)
93             sprintf(tmp_val, "%c)", inven_label[i]);
94         else
95             sprintf(tmp_val, "%c)", index_to_label(i));
96
97         put_str(tmp_val, j + 1, col);
98         cur_col = col + 3;
99         if (show_item_graph) {
100             TERM_COLOR a = object_attr(o_ptr);
101             SYMBOL_CODE c = object_char(o_ptr);
102             term_queue_bigchar(cur_col, j + 1, a, c, 0, 0);
103             if (use_bigtile)
104                 cur_col++;
105
106             cur_col += 2;
107         }
108
109         c_put_str(out_color[j], out_desc[j], j + 1, cur_col);
110         if (show_weights) {
111             int wgt = o_ptr->weight * o_ptr->number;
112             (void)sprintf(tmp_val, _("%3d.%1d kg", "%3d.%1d lb"), _(lbtokg1(wgt), wgt / 10), _(lbtokg2(wgt), wgt % 10));
113             prt(tmp_val, j + 1, wid - 9);
114         }
115     }
116
117     if (j && (j < 23))
118         prt("", j + 1, col ? col - 2 : col);
119
120     command_gap = col;
121     return target_item_label;
122 }
123
124 /*!
125  * @brief 所持アイテム一覧を表示する /
126  * Choice window "shadow" of the "show_inven()" function
127  * @return なし
128  */
129 void display_inventory(player_type *owner_ptr, tval_type tval)
130 {
131     register int i, n, z = 0;
132     object_type *o_ptr;
133     TERM_COLOR attr = TERM_WHITE;
134     char tmp_val[80];
135     GAME_TEXT o_name[MAX_NLEN];
136     TERM_LEN wid, hgt;
137
138     if (!owner_ptr || !owner_ptr->inventory_list)
139         return;
140
141     term_get_size(&wid, &hgt);
142     for (i = 0; i < INVEN_PACK; i++) {
143         o_ptr = &owner_ptr->inventory_list[i];
144         if (!o_ptr->k_idx)
145             continue;
146         z = i + 1;
147     }
148
149     for (i = 0; i < z; i++) {
150         o_ptr = &owner_ptr->inventory_list[i];
151         tmp_val[0] = tmp_val[1] = tmp_val[2] = ' ';
152         if (item_tester_okay(owner_ptr, o_ptr, tval)) {
153             tmp_val[0] = index_to_label(i);
154             tmp_val[1] = ')';
155         }
156
157         term_putstr(0, i, 3, TERM_WHITE, tmp_val);
158         describe_flavor(owner_ptr, o_name, o_ptr, 0);
159         n = strlen(o_name);
160         attr = tval_to_attr[o_ptr->tval % 128];
161         if (o_ptr->timeout) {
162             attr = TERM_L_DARK;
163         }
164
165         term_putstr(3, i, n, attr, o_name);
166         term_erase(3 + n, i, 255);
167
168         if (show_weights) {
169             int wgt = o_ptr->weight * o_ptr->number;
170             sprintf(tmp_val, _("%3d.%1d kg", "%3d.%1d lb"), _(lbtokg1(wgt), wgt / 10), _(lbtokg2(wgt), wgt % 10));
171             prt(tmp_val, i, wid - 9);
172         }
173     }
174
175     for (i = z; i < hgt; i++)
176         term_erase(0, i, 255);
177 }