OSDN Git Service

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