OSDN Git Service

Merge pull request #1767 from Hourier/Change-Tval-Type-To-Enum-Class
[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 "object/item-tester-hooker.h"
10 #include "object/item-use-flags.h"
11 #include "object/object-info.h"
12 #include "object/object-kind.h"
13 #include "system/object-type-definition.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 "player/player-status-flags.h"
19
20 /*!
21  * @brief メインウィンドウの右上に装備アイテムの表示させる
22  * Display the equipment.
23  * @param target_item アイテムの選択処理を行うか否か。
24  * @return 選択したアイテムのタグ
25  */
26 COMMAND_CODE show_equipment(player_type *player_ptr, int target_item, BIT_FLAGS mode, const ItemTester& item_tester)
27 {
28     COMMAND_CODE i;
29     int j, k, l;
30     object_type *o_ptr;
31     char tmp_val[80];
32     GAME_TEXT o_name[MAX_NLEN];
33     COMMAND_CODE out_index[23];
34     TERM_COLOR out_color[23];
35     char out_desc[23][MAX_NLEN];
36     COMMAND_CODE target_item_label = 0;
37     TERM_LEN wid, hgt;
38     char equip_label[52 + 1];
39     int col = command_gap;
40     term_get_size(&wid, &hgt);
41     int len = wid - col - 1;
42     for (k = 0, i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
43         o_ptr = &player_ptr->inventory_list[i];
44         if (!(player_ptr->select_ring_slot ? is_ring_slot(i) : item_tester.okay(o_ptr) || (mode & USE_FULL))
45             && (!((((i == INVEN_MAIN_HAND) && can_attack_with_sub_hand(player_ptr)) || ((i == INVEN_SUB_HAND) && can_attack_with_main_hand(player_ptr)))
46                     && has_two_handed_weapons(player_ptr))
47                 || (mode & IGNORE_BOTHHAND_SLOT)))
48             continue;
49
50         describe_flavor(player_ptr, o_name, o_ptr, 0);
51         if ((((i == INVEN_MAIN_HAND) && can_attack_with_sub_hand(player_ptr)) || ((i == INVEN_SUB_HAND) && can_attack_with_main_hand(player_ptr)))
52             && 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->tval) % 128];
58         }
59
60         out_index[k] = i;
61         if (o_ptr->timeout)
62             out_color[k] = TERM_L_DARK;
63         l = strlen(out_desc[k]) + (2 + _(1, 3));
64
65         if (show_labels)
66             l += (_(7, 14) + 2);
67
68         if (show_weights)
69             l += 9;
70
71         if (show_item_graph)
72             l += 2;
73
74         if (l > len)
75             len = l;
76
77         k++;
78     }
79
80     col = (len > wid - _(6, 4)) ? 0 : (wid - len - 1);
81     prepare_label_string(player_ptr, equip_label, USE_EQUIP, item_tester);
82     for (j = 0; j < k; j++) {
83         i = out_index[j];
84         o_ptr = &player_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_MAIN_HAND)
93             sprintf(tmp_val, "%c)", equip_label[i - INVEN_MAIN_HAND]);
94         else
95             sprintf(tmp_val, "%c)", index_to_label(i));
96
97         put_str(tmp_val, j + 1, col);
98         int 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         if (show_labels) {
110             (void)sprintf(tmp_val, _("%-7s: ", "%-14s: "), mention_use(player_ptr, i));
111             put_str(tmp_val, j + 1, cur_col);
112             c_put_str(out_color[j], out_desc[j], j + 1, _(cur_col + 9, cur_col + 16));
113         } else
114             c_put_str(out_color[j], out_desc[j], j + 1, cur_col);
115
116         if (!show_weights)
117             continue;
118
119         int wgt = o_ptr->weight * o_ptr->number;
120         (void)sprintf(tmp_val, _("%3d.%1d kg", "%3d.%d lb"), _(lbtokg1(wgt), wgt / 10), _(lbtokg2(wgt), wgt % 10));
121         prt(tmp_val, j + 1, wid - 9);
122     }
123
124     if (j && (j < 23))
125         prt("", j + 1, col ? col - 2 : col);
126
127     command_gap = col;
128     return target_item_label;
129 }