OSDN Git Service

Merge pull request #3079 from habu1010/feature/display-store-and-building-to-center
[hengbandforosx/hengbandosx.git] / src / window / main-window-equipments.cpp
1 #include "window/main-window-equipments.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-describer.h"
6 #include "inventory/inventory-slot-types.h"
7 #include "inventory/inventory-util.h"
8 #include "io/input-key-requester.h"
9 #include "locale/japanese.h"
10 #include "object/item-tester-hooker.h"
11 #include "object/item-use-flags.h"
12 #include "object/object-info.h"
13 #include "player/player-status-flags.h"
14 #include "system/baseitem-info.h"
15 #include "system/item-entity.h"
16 #include "system/player-type-definition.h"
17 #include "term/gameterm.h"
18 #include "term/screen-processor.h"
19 #include "term/term-color-types.h"
20 #include "term/z-form.h"
21 #include "util/bit-flags-calculator.h"
22 #include "util/string-processor.h"
23 #include <array>
24 #include <vector>
25
26 /*!
27  * @brief メインウィンドウの右上に装備アイテムの表示させる
28  * Display the equipment.
29  * @param target_item アイテムの選択処理を行うか否か。
30  * @return 選択したアイテムのタグ
31  */
32 COMMAND_CODE show_equipment(PlayerType *player_ptr, int target_item, BIT_FLAGS mode, const ItemTester &item_tester)
33 {
34     COMMAND_CODE i;
35     int j, k, l;
36     ItemEntity *o_ptr;
37     char tmp_val[80];
38     COMMAND_CODE out_index[23];
39     TERM_COLOR out_color[23];
40     std::array<std::string, 23> out_desc{};
41     COMMAND_CODE target_item_label = 0;
42     TERM_LEN wid, hgt;
43     char equip_label[52 + 1];
44     int col = command_gap;
45     term_get_size(&wid, &hgt);
46     int len = wid - col - 1;
47     for (k = 0, i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
48         o_ptr = &player_ptr->inventory_list[i];
49         auto only_slot = !(player_ptr->select_ring_slot ? is_ring_slot(i) : (item_tester.okay(o_ptr) || any_bits(mode, USE_FULL)));
50         auto is_any_hand = (i == INVEN_MAIN_HAND) && can_attack_with_sub_hand(player_ptr);
51         is_any_hand |= (i == INVEN_SUB_HAND) && can_attack_with_main_hand(player_ptr);
52         auto is_two_handed = is_any_hand && has_two_handed_weapons(player_ptr);
53         only_slot &= !is_two_handed || any_bits(mode, IGNORE_BOTHHAND_SLOT);
54         if (only_slot) {
55             continue;
56         }
57
58         GAME_TEXT item_name[MAX_NLEN]{};
59         describe_flavor(player_ptr, item_name, o_ptr, 0);
60         if (is_two_handed) {
61             out_desc[k] = _("(武器を両手持ち)", "(wielding with two-hands)");
62             out_color[k] = TERM_WHITE;
63         } else {
64             out_desc[k] = item_name;
65             out_color[k] = tval_to_attr[enum2i(o_ptr->bi_key.tval()) % 128];
66         }
67
68         out_index[k] = i;
69         if (o_ptr->timeout) {
70             out_color[k] = TERM_L_DARK;
71         }
72         l = out_desc[k].length() + (2 + _(1, 3));
73
74         if (show_labels) {
75             l += (_(7, 14) + 2);
76         }
77
78         if (show_weights) {
79             l += 9;
80         }
81
82         if (show_item_graph) {
83             l += 2;
84         }
85
86         if (l > len) {
87             len = l;
88         }
89
90         k++;
91     }
92
93     col = (len > wid - _(6, 4)) ? 0 : (wid - len - 1);
94     prepare_label_string(player_ptr, equip_label, USE_EQUIP, item_tester);
95     for (j = 0; j < k; j++) {
96         i = out_index[j];
97         o_ptr = &player_ptr->inventory_list[i];
98         prt("", j + 1, col ? col - 2 : col);
99         if (use_menu && target_item) {
100             if (j == (target_item - 1)) {
101                 angband_strcpy(tmp_val, _("》", "> "), sizeof(tmp_val));
102                 target_item_label = i;
103             } else {
104                 angband_strcpy(tmp_val, "  ", sizeof(tmp_val));
105             }
106         } else if (i >= INVEN_MAIN_HAND) {
107             strnfmt(tmp_val, sizeof(tmp_val), "%c)", equip_label[i - INVEN_MAIN_HAND]);
108         } else {
109             strnfmt(tmp_val, sizeof(tmp_val), "%c)", index_to_label(i));
110         }
111
112         put_str(tmp_val, j + 1, col);
113         int cur_col = col + 3;
114         if (show_item_graph) {
115             const auto a = o_ptr->get_color();
116             const auto c = o_ptr->get_symbol();
117             term_queue_bigchar(cur_col, j + 1, a, c, 0, 0);
118             if (use_bigtile) {
119                 cur_col++;
120             }
121
122             cur_col += 2;
123         }
124
125         if (show_labels) {
126             strnfmt(tmp_val, sizeof(tmp_val), _("%-7s: ", "%-14s: "), mention_use(player_ptr, i));
127             put_str(tmp_val, j + 1, cur_col);
128             c_put_str(out_color[j], out_desc[j], j + 1, _(cur_col + 9, cur_col + 16));
129         } else {
130             c_put_str(out_color[j], out_desc[j], j + 1, cur_col);
131         }
132
133         if (!show_weights) {
134             continue;
135         }
136
137         int wgt = o_ptr->weight * o_ptr->number;
138         strnfmt(tmp_val, sizeof(tmp_val), _("%3d.%1d kg", "%3d.%d lb"), _(lb_to_kg_integer(wgt), wgt / 10), _(lb_to_kg_fraction(wgt), wgt % 10));
139         prt(tmp_val, j + 1, wid - 9);
140     }
141
142     if (j && (j < 23)) {
143         prt("", j + 1, col ? col - 2 : col);
144     }
145
146     command_gap = col;
147     return target_item_label;
148 }