OSDN Git Service

Merge pull request #2939 from backwardsEric/sprintf-simple-replacements
[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/string-processor.h"
22
23 /*!
24  * @brief メインウィンドウの右上に装備アイテムの表示させる
25  * Display the equipment.
26  * @param target_item アイテムの選択処理を行うか否か。
27  * @return 選択したアイテムのタグ
28  */
29 COMMAND_CODE show_equipment(PlayerType *player_ptr, int target_item, BIT_FLAGS mode, const ItemTester &item_tester)
30 {
31     COMMAND_CODE i;
32     int j, k, l;
33     ItemEntity *o_ptr;
34     char tmp_val[80];
35     GAME_TEXT o_name[MAX_NLEN];
36     COMMAND_CODE out_index[23];
37     TERM_COLOR out_color[23];
38     char out_desc[23][MAX_NLEN];
39     COMMAND_CODE target_item_label = 0;
40     TERM_LEN wid, hgt;
41     char equip_label[52 + 1];
42     int col = command_gap;
43     term_get_size(&wid, &hgt);
44     int len = wid - col - 1;
45     for (k = 0, i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
46         o_ptr = &player_ptr->inventory_list[i];
47         if (!(player_ptr->select_ring_slot ? is_ring_slot(i) : item_tester.okay(o_ptr) || (mode & USE_FULL)) && (!((((i == INVEN_MAIN_HAND) && can_attack_with_sub_hand(player_ptr)) || ((i == INVEN_SUB_HAND) && can_attack_with_main_hand(player_ptr))) && has_two_handed_weapons(player_ptr)) || (mode & IGNORE_BOTHHAND_SLOT))) {
48             continue;
49         }
50
51         describe_flavor(player_ptr, o_name, o_ptr, 0);
52         if ((((i == INVEN_MAIN_HAND) && can_attack_with_sub_hand(player_ptr)) || ((i == INVEN_SUB_HAND) && can_attack_with_main_hand(player_ptr))) && has_two_handed_weapons(player_ptr)) {
53             (void)strcpy(out_desc[k], _("(武器を両手持ち)", "(wielding with two-hands)"));
54             out_color[k] = TERM_WHITE;
55         } else {
56             (void)strcpy(out_desc[k], o_name);
57             out_color[k] = tval_to_attr[enum2i(o_ptr->bi_key.tval()) % 128];
58         }
59
60         out_index[k] = i;
61         if (o_ptr->timeout) {
62             out_color[k] = TERM_L_DARK;
63         }
64         l = strlen(out_desc[k]) + (2 + _(1, 3));
65
66         if (show_labels) {
67             l += (_(7, 14) + 2);
68         }
69
70         if (show_weights) {
71             l += 9;
72         }
73
74         if (show_item_graph) {
75             l += 2;
76         }
77
78         if (l > len) {
79             len = l;
80         }
81
82         k++;
83     }
84
85     col = (len > wid - _(6, 4)) ? 0 : (wid - len - 1);
86     prepare_label_string(player_ptr, equip_label, USE_EQUIP, item_tester);
87     for (j = 0; j < k; j++) {
88         i = out_index[j];
89         o_ptr = &player_ptr->inventory_list[i];
90         prt("", j + 1, col ? col - 2 : col);
91         if (use_menu && target_item) {
92             if (j == (target_item - 1)) {
93                 angband_strcpy(tmp_val, _("》", "> "), sizeof(tmp_val));
94                 target_item_label = i;
95             } else {
96                 angband_strcpy(tmp_val, "  ", sizeof(tmp_val));
97             }
98         } else if (i >= INVEN_MAIN_HAND) {
99             strnfmt(tmp_val, sizeof(tmp_val), "%c)", equip_label[i - INVEN_MAIN_HAND]);
100         } else {
101             strnfmt(tmp_val, sizeof(tmp_val), "%c)", index_to_label(i));
102         }
103
104         put_str(tmp_val, j + 1, col);
105         int cur_col = col + 3;
106         if (show_item_graph) {
107             const auto a = o_ptr->get_color();
108             const auto c = o_ptr->get_symbol();
109             term_queue_bigchar(cur_col, j + 1, a, c, 0, 0);
110             if (use_bigtile) {
111                 cur_col++;
112             }
113
114             cur_col += 2;
115         }
116
117         if (show_labels) {
118             strnfmt(tmp_val, sizeof(tmp_val), _("%-7s: ", "%-14s: "), mention_use(player_ptr, i));
119             put_str(tmp_val, j + 1, cur_col);
120             c_put_str(out_color[j], out_desc[j], j + 1, _(cur_col + 9, cur_col + 16));
121         } else {
122             c_put_str(out_color[j], out_desc[j], j + 1, cur_col);
123         }
124
125         if (!show_weights) {
126             continue;
127         }
128
129         int wgt = o_ptr->weight * o_ptr->number;
130         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));
131         prt(tmp_val, j + 1, wid - 9);
132     }
133
134     if (j && (j < 23)) {
135         prt("", j + 1, col ? col - 2 : col);
136     }
137
138     command_gap = col;
139     return target_item_label;
140 }