OSDN Git Service

[Refactor] io-dump ディレクトリ内のコメントを Doxygen 向けに整理.
[hengbandforosx/hengbandosx.git] / src / io-dump / dump-util.cpp
1 #include "io-dump/dump-util.h"
2 #include "floor/geometry.h"
3 #include "game-option/keymap-directory-getter.h"
4 #include "game-option/special-options.h"
5 #include "term/term-color-types.h"
6 #include "term/screen-processor.h"
7 #include "util/angband-files.h"
8 #include "util/int-char-converter.h"
9 #include "view/display-messages.h"
10
11 TERM_COLOR attr_idx = 0;
12 SYMBOL_CODE char_idx = 0;
13
14 TERM_COLOR attr_idx_feat[F_LIT_MAX];
15 SYMBOL_CODE char_idx_feat[F_LIT_MAX];
16
17 /*!
18  * @brief シンボル変更処理 / Do visual mode command -- Change symbols
19  * @param ch
20  * @param visual_list_ptr
21  * @param height
22  * @param width
23  * @param attr_ptr_ptr
24  * @param char_left_ptr
25  * @param cur_attr_ptr
26  * @param cur_char_ptr
27  * @param need_redraw
28  * @return 何かコマンドを入れたらTRUE
29  */
30 bool visual_mode_command(char ch, bool *visual_list_ptr,
31         int height, int width,
32         TERM_COLOR *attr_top_ptr, byte *char_left_ptr,
33         TERM_COLOR *cur_attr_ptr, SYMBOL_CODE *cur_char_ptr, bool *need_redraw)
34 {
35         static TERM_COLOR attr_old = 0;
36         static SYMBOL_CODE char_old = 0;
37
38         switch (ch)
39         {
40         case ESCAPE:
41         {
42                 if (!*visual_list_ptr) return false;
43
44                 *cur_attr_ptr = attr_old;
45                 *cur_char_ptr = char_old;
46                 *visual_list_ptr = false;
47                 return true;
48         }
49         case '\n':
50         case '\r':
51         {
52                 if (!*visual_list_ptr) return false;
53
54                 *visual_list_ptr = false;
55                 *need_redraw = true;
56                 return true;
57         }
58         case 'V':
59         case 'v':
60         {
61                 if (*visual_list_ptr) return false;
62
63                 *visual_list_ptr = true;
64                 *attr_top_ptr = MAX(0, (*cur_attr_ptr & 0x7f) - 5);
65                 *char_left_ptr = MAX(0, *cur_char_ptr - 10);
66                 attr_old = *cur_attr_ptr;
67                 char_old = *cur_char_ptr;
68                 return true;
69         }
70         case 'C':
71         case 'c':
72         {
73                 attr_idx = *cur_attr_ptr;
74                 char_idx = *cur_char_ptr;
75                 for (int i = 0; i < F_LIT_MAX; i++)
76                 {
77                         attr_idx_feat[i] = 0;
78                         char_idx_feat[i] = 0;
79                 }
80
81                 return true;
82         }
83         case 'P':
84         case 'p':
85         {
86                 if (attr_idx || (!(char_idx & 0x80) && char_idx))
87                 {
88                         *cur_attr_ptr = attr_idx;
89                         *attr_top_ptr = MAX(0, (*cur_attr_ptr & 0x7f) - 5);
90                         if (!*visual_list_ptr) *need_redraw = true;
91                 }
92
93                 if (char_idx)
94                 {
95                         /* Set the char */
96                         *cur_char_ptr = char_idx;
97                         *char_left_ptr = MAX(0, *cur_char_ptr - 10);
98                         if (!*visual_list_ptr) *need_redraw = true;
99                 }
100
101                 return true;
102         }
103         default:
104         {
105                 if (!*visual_list_ptr) return false;
106
107                 int eff_width;
108                 int d = get_keymap_dir(ch);
109                 TERM_COLOR a = (*cur_attr_ptr & 0x7f);
110                 SYMBOL_CODE c = *cur_char_ptr;
111
112                 if (use_bigtile) eff_width = width / 2;
113                 else eff_width = width;
114
115                 if ((a == 0) && (ddy[d] < 0)) d = 0;
116                 if ((c == 0) && (ddx[d] < 0)) d = 0;
117                 if ((a == 0x7f) && (ddy[d] > 0)) d = 0;
118                 if (((byte)c == 0xff) && (ddx[d] > 0)) d = 0;
119
120                 a += (TERM_COLOR)ddy[d];
121                 c += (SYMBOL_CODE)ddx[d];
122                 if (c & 0x80) a |= 0x80;
123
124                 *cur_attr_ptr = a;
125                 *cur_char_ptr = c;
126                 if ((ddx[d] < 0) && *char_left_ptr > MAX(0, (unsigned char)c - 10)) (*char_left_ptr)--;
127                 if ((ddx[d] > 0) && *char_left_ptr + eff_width < MIN(0xff, (unsigned char)c + 10)) (*char_left_ptr)++;
128                 if ((ddy[d] < 0) && *attr_top_ptr > MAX(0, (int)(a & 0x7f) - 4)) (*attr_top_ptr)--;
129                 if ((ddy[d] > 0) && *attr_top_ptr + height < MIN(0x7f, (a & 0x7f) + 4)) (*attr_top_ptr)++;
130
131                 return true;
132         }
133         }
134 }
135
136
137 /*!
138  * @brief ダンプ用の一時ファイルを開く
139  * @param fff 一時ファイルへの参照ポインタ
140  * @param file_name ファイル名
141  * @return ファイルを開けたらTRUE、開けなかったらFALSE
142  * @details 
143  */
144 bool open_temporary_file(FILE **fff, char *file_name)
145 {
146         *fff = angband_fopen_temp(file_name, FILE_NAME_SIZE);
147         if (*fff != NULL) return true;
148
149         msg_format(_("一時ファイル %s を作成できませんでした。", "Failed to create temporary file %s."), file_name);
150         msg_print(NULL);
151         return false;
152 }
153
154
155 /*!
156  * @brief モンスター情報リスト中のグループを表示する /
157  * Display the object groups.
158  * @param col 開始行
159  * @param row 開始列
160  * @param wid 表示文字数幅
161  * @param per_page リストの表示行
162  * @param grp_idx グループのID配列
163  * @param group_text グループ名の文字列配列
164  * @param grp_cur 現在の選択ID
165  * @param grp_top 現在の選択リスト最上部ID
166  */
167 void display_group_list(int col, int row, int wid, int per_page, IDX grp_idx[], concptr group_text[], int grp_cur, int grp_top)
168 {
169         for (int i = 0; i < per_page && (grp_idx[i] >= 0); i++)
170         {
171                 int grp = grp_idx[grp_top + i];
172                 TERM_COLOR attr = (grp_top + i == grp_cur) ? TERM_L_BLUE : TERM_WHITE;
173                 term_erase(col, row + i, wid);
174                 c_put_str(attr, group_text[grp], row + i, col);
175         }
176 }
177
178
179 /*!
180  * @brief Display visuals.
181  */
182 void display_visual_list(int col, int row, int height, int width, TERM_COLOR attr_top, byte char_left)
183 {
184         for (int i = 0; i < height; i++)
185         {
186                 term_erase(col, row + i, width);
187         }
188
189         if (use_bigtile) width /= 2;
190
191         for (int i = 0; i < height; i++)
192         {
193                 for (int j = 0; j < width; j++)
194                 {
195                         TERM_LEN x = col + j;
196                         TERM_LEN y = row + i;
197                         if (use_bigtile) x += j;
198
199                         int ia = attr_top + i;
200                         int ic = char_left + j;
201                         if (ia > 0x7f || ic > 0xff || ic < ' ' ||
202                                 (!use_graphics && ic > 0x7f))
203                                 continue;
204
205                         TERM_COLOR a = (TERM_COLOR)ia;
206                         SYMBOL_CODE c = (SYMBOL_CODE)ic;
207                         if (c & 0x80) a |= 0x80;
208
209                         term_queue_bigchar(x, y, a, c, 0, 0);
210                 }
211         }
212 }
213
214
215 /*!
216  * @brief Place the cursor at the collect position for visual mode
217  */
218 void place_visual_list_cursor(TERM_LEN col, TERM_LEN row, TERM_COLOR a, byte c, TERM_COLOR attr_top, byte char_left)
219 {
220         int i = (a & 0x7f) - attr_top;
221         int j = c - char_left;
222
223         TERM_LEN x = col + j;
224         TERM_LEN y = row + i;
225         if (use_bigtile) x += j;
226
227         term_gotoxy(x, y);
228 }
229
230
231 /*!
232  * @brief Move the cursor in a browser window
233  */
234 void browser_cursor(char ch, int *column, IDX *grp_cur, int grp_cnt, IDX *list_cur, int list_cnt)
235 {
236         int d;
237         int col = *column;
238         IDX grp = *grp_cur;
239         IDX list = *list_cur;
240         if (ch == ' ')
241                 d = 3;
242         else if (ch == '-')
243                 d = 9;
244         else
245                 d = get_keymap_dir(ch);
246
247         if (!d) return;
248
249         if ((ddx[d] > 0) && ddy[d])
250         {
251                 int browser_rows;
252                 int wid, hgt;
253                 term_get_size(&wid, &hgt);
254                 browser_rows = hgt - 8;
255                 if (!col)
256                 {
257                         int old_grp = grp;
258                         grp += ddy[d] * (browser_rows - 1);
259                         if (grp >= grp_cnt)     grp = grp_cnt - 1;
260                         if (grp < 0) grp = 0;
261                         if (grp != old_grp)     list = 0;
262                 }
263                 else
264                 {
265                         list += ddy[d] * browser_rows;
266                         if (list >= list_cnt) list = list_cnt - 1;
267                         if (list < 0) list = 0;
268                 }
269
270                 (*grp_cur) = grp;
271                 (*list_cur) = list;
272                 return;
273         }
274
275         if (ddx[d])
276         {
277                 col += ddx[d];
278                 if (col < 0) col = 0;
279                 if (col > 1) col = 1;
280
281                 (*column) = col;
282                 return;
283         }
284
285         if (!col)
286         {
287                 int old_grp = grp;
288                 grp += (IDX)ddy[d];
289                 if (grp >= grp_cnt)     grp = grp_cnt - 1;
290                 if (grp < 0) grp = 0;
291                 if (grp != old_grp)     list = 0;
292         }
293         else
294         {
295                 list += (IDX)ddy[d];
296                 if (list >= list_cnt) list = list_cnt - 1;
297                 if (list < 0) list = 0;
298         }
299
300         (*grp_cur) = grp;
301         (*list_cur) = list;
302 }