OSDN Git Service

Merge branch 'master' of git.osdn.net:/gitroot/hengband/hengband
[hengband/hengband.git] / src / io-dump / dump-util.c
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, (int)c - 10)) (*char_left_ptr)--;
127                 if ((ddx[d] > 0) && *char_left_ptr + eff_width < MIN(0xff, (int)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  * @return なし
167  */
168 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)
169 {
170         for (int i = 0; i < per_page && (grp_idx[i] >= 0); i++)
171         {
172                 int grp = grp_idx[grp_top + i];
173                 TERM_COLOR attr = (grp_top + i == grp_cur) ? TERM_L_BLUE : TERM_WHITE;
174                 term_erase(col, row + i, wid);
175                 c_put_str(attr, group_text[grp], row + i, col);
176         }
177 }
178
179
180 /*
181  * Display visuals.
182  */
183 void display_visual_list(int col, int row, int height, int width, TERM_COLOR attr_top, byte char_left)
184 {
185         for (int i = 0; i < height; i++)
186         {
187                 term_erase(col, row + i, width);
188         }
189
190         if (use_bigtile) width /= 2;
191
192         for (int i = 0; i < height; i++)
193         {
194                 for (int j = 0; j < width; j++)
195                 {
196                         TERM_LEN x = col + j;
197                         TERM_LEN y = row + i;
198                         if (use_bigtile) x += j;
199
200                         int ia = attr_top + i;
201                         int ic = char_left + j;
202                         if (ia > 0x7f || ic > 0xff || ic < ' ' ||
203                                 (!use_graphics && ic > 0x7f))
204                                 continue;
205
206                         TERM_COLOR a = (TERM_COLOR)ia;
207                         SYMBOL_CODE c = (SYMBOL_CODE)ic;
208                         if (c & 0x80) a |= 0x80;
209
210                         term_queue_bigchar(x, y, a, c, 0, 0);
211                 }
212         }
213 }
214
215
216 /*
217  * Place the cursor at the collect position for visual mode
218  */
219 void place_visual_list_cursor(TERM_LEN col, TERM_LEN row, TERM_COLOR a, byte c, TERM_COLOR attr_top, byte char_left)
220 {
221         int i = (a & 0x7f) - attr_top;
222         int j = c - char_left;
223
224         TERM_LEN x = col + j;
225         TERM_LEN y = row + i;
226         if (use_bigtile) x += j;
227
228         term_gotoxy(x, y);
229 }
230
231
232 /*
233  * Move the cursor in a browser window
234  */
235 void browser_cursor(char ch, int *column, IDX *grp_cur, int grp_cnt, IDX *list_cur, int list_cnt)
236 {
237         int d;
238         int col = *column;
239         IDX grp = *grp_cur;
240         IDX list = *list_cur;
241         if (ch == ' ')
242                 d = 3;
243         else if (ch == '-')
244                 d = 9;
245         else
246                 d = get_keymap_dir(ch);
247
248         if (!d) return;
249
250         if ((ddx[d] > 0) && ddy[d])
251         {
252                 int browser_rows;
253                 int wid, hgt;
254                 term_get_size(&wid, &hgt);
255                 browser_rows = hgt - 8;
256                 if (!col)
257                 {
258                         int old_grp = grp;
259                         grp += ddy[d] * (browser_rows - 1);
260                         if (grp >= grp_cnt)     grp = grp_cnt - 1;
261                         if (grp < 0) grp = 0;
262                         if (grp != old_grp)     list = 0;
263                 }
264                 else
265                 {
266                         list += ddy[d] * browser_rows;
267                         if (list >= list_cnt) list = list_cnt - 1;
268                         if (list < 0) list = 0;
269                 }
270
271                 (*grp_cur) = grp;
272                 (*list_cur) = list;
273                 return;
274         }
275
276         if (ddx[d])
277         {
278                 col += ddx[d];
279                 if (col < 0) col = 0;
280                 if (col > 1) col = 1;
281
282                 (*column) = col;
283                 return;
284         }
285
286         if (!col)
287         {
288                 int old_grp = grp;
289                 grp += (IDX)ddy[d];
290                 if (grp >= grp_cnt)     grp = grp_cnt - 1;
291                 if (grp < 0) grp = 0;
292                 if (grp != old_grp)     list = 0;
293         }
294         else
295         {
296                 list += (IDX)ddy[d];
297                 if (list >= list_cnt) list = list_cnt - 1;
298                 if (list < 0) list = 0;
299         }
300
301         (*grp_cur) = grp;
302         (*list_cur) = list;
303 }