OSDN Git Service

bd2fb14fe4c1271c3e37d8d82c91eedd5f292d37
[hengbandforosx/hengbandosx.git] / src / cmd-visual / cmd-draw.cpp
1 #include "cmd-visual/cmd-draw.h"
2 #include "core/asking-player.h"
3 #include "core/player-redraw-types.h"
4 #include "core/player-update-types.h"
5 #include "core/stuff-handler.h"
6 #include "core/window-redrawer.h"
7 #include "io/files-util.h"
8 #include "io/input-key-acceptor.h"
9 #include "main/sound-of-music.h"
10 #include "player/player-race-types.h"
11 #include "player/process-name.h"
12 #include "racial/racial-android.h"
13 #include "term/gameterm.h"
14 #include "term/screen-processor.h"
15 #include "term/term-color-types.h"
16 #include "util/int-char-converter.h"
17 #include "util/string-processor.h"
18 #include "view/display-messages.h"
19 #include "view/display-player.h" // 暫定。後で消す.
20 #include "world/world.h"
21
22 /*!
23  * @brief 画面を再描画するコマンドのメインルーチン
24  * Hack -- redraw the screen
25  * @param creature_ptr プレーヤーへの参照ポインタ
26  * @return なし
27  * @details
28  * <pre>
29  * This command performs various low level updates, clears all the "extra"
30  * windows, does a total redraw of the main window, and requests all of the
31  * interesting updates and redraws that I can think of.
32  *
33  * This command is also used to "instantiate" the results of the user
34  * selecting various things, such as graphics mode, so it must call
35  * the "TERM_XTRA_REACT" hook before redrawing the windows.
36  * </pre>
37  */
38 void do_cmd_redraw(player_type *creature_ptr)
39 {
40         term_xtra(TERM_XTRA_REACT, 0);
41
42         creature_ptr->update |= (PU_COMBINE | PU_REORDER);
43         creature_ptr->update |= (PU_TORCH);
44         creature_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
45         creature_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
46         creature_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
47         creature_ptr->update |= (PU_MONSTERS);
48
49         creature_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
50
51         creature_ptr->window_flags |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
52         creature_ptr->window_flags |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
53
54         update_playtime();
55         handle_stuff(creature_ptr);
56         if (creature_ptr->prace == RACE_ANDROID) calc_android_exp(creature_ptr);
57
58         term_type *old = Term;
59         for (int j = 0; j < 8; j++)
60         {
61                 if (!angband_term[j]) continue;
62
63                 term_activate(angband_term[j]);
64                 term_redraw();
65                 term_fresh();
66                 term_activate(old);
67         }
68 }
69
70
71 /*!
72  * @brief プレイヤーのステータス表示
73  * @return なし
74  */
75 void do_cmd_player_status(player_type *creature_ptr)
76 {
77         int mode = 0;
78         char tmp[160];
79         screen_save();
80         while (TRUE)
81         {
82                 update_playtime();
83                 display_player(creature_ptr, mode);
84
85                 if (mode == 5)
86                 {
87                         mode = 0;
88                         display_player(creature_ptr, mode);
89                 }
90
91                 term_putstr(2, 23, -1, TERM_WHITE,
92                         _("['c'で名前変更, 'f'でファイルへ書出, 'h'でモード変更, ESCで終了]", "['c' to change name, 'f' to file, 'h' to change mode, or ESC]"));
93                 char c = inkey();
94                 if (c == ESCAPE) break;
95
96                 if (c == 'c')
97                 {
98                         get_name(creature_ptr);
99                         process_player_name(creature_ptr);
100                 }
101                 else if (c == 'f')
102                 {
103                         sprintf(tmp, "%s.txt", creature_ptr->base_name);
104                         if (get_string(_("ファイル名: ", "File name: "), tmp, 80))
105                         {
106                                 if (tmp[0] && (tmp[0] != ' '))
107                                 {
108                                         update_playtime();
109                                         file_character(creature_ptr, tmp, display_player);
110                                 }
111                         }
112                 }
113                 else if (c == 'h')
114                 {
115                         mode++;
116                 }
117                 else
118                 {
119                         bell();
120                 }
121
122                 msg_erase();
123         }
124
125         screen_load();
126         creature_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
127         handle_stuff(creature_ptr);
128 }
129
130
131 /*!
132  * @brief 最近表示されたメッセージを再表示するコマンドのメインルーチン
133  * Recall the most recent message
134  * @return なし
135  */
136 void do_cmd_message_one(void)
137 {
138         prt(format("> %s", message_str(0)), 0, 0);
139 }
140
141
142 /*!
143  * @brief メッセージのログを表示するコマンドのメインルーチン
144  * Recall the most recent message
145  * @return なし
146  * @details
147  * <pre>
148  * Show previous messages to the user   -BEN-
149  *
150  * The screen format uses line 0 and 23 for headers and prompts,
151  * skips line 1 and 22, and uses line 2 thru 21 for old messages.
152  *
153  * This command shows you which commands you are viewing, and allows
154  * you to "search" for strings in the recall.
155  *
156  * Note that messages may be longer than 80 characters, but they are
157  * displayed using "infinite" length, with a special sub-command to
158  * "slide" the virtual display to the left or right.
159  *
160  * Attempt to only hilite the matching portions of the string.
161  * </pre>
162  */
163 void do_cmd_messages(int num_now)
164 {
165         char shower_str[81];
166         char finder_str[81];
167         char back_str[81];
168         concptr shower = NULL;
169         int wid, hgt;
170         term_get_size(&wid, &hgt);
171         int num_lines = hgt - 4;
172         strcpy(finder_str, "");
173         strcpy(shower_str, "");
174         int n = message_num();
175         int i = 0;
176         screen_save();
177         term_clear();
178         while (TRUE)
179         {
180                 int j;
181                 int skey;
182                 for (j = 0; (j < num_lines) && (i + j < n); j++)
183                 {
184                         concptr msg = message_str(i + j);
185                         c_prt((i + j < num_now ? TERM_WHITE : TERM_SLATE), msg, num_lines + 1 - j, 0);
186                         if (!shower || !shower[0]) continue;
187
188                         concptr str = msg;
189                         while ((str = angband_strstr(str, shower)) != NULL)
190                         {
191                                 int len = strlen(shower);
192                                 term_putstr(str - msg, num_lines + 1 - j, len, TERM_YELLOW, shower);
193                                 str += len;
194                         }
195                 }
196
197                 for (; j < num_lines; j++)
198                         term_erase(0, num_lines + 1 - j, 255);
199
200                 prt(format(_("以前のメッセージ %d-%d 全部で(%d)", "Message Recall (%d-%d of %d)"),
201                         i, i + j - 1, n), 0, 0);
202                 prt(_("[ 'p' で更に古いもの, 'n' で更に新しいもの, '/' で検索, ESC で中断 ]",
203                         "[Press 'p' for older, 'n' for newer, ..., or ESCAPE]"), hgt - 1, 0);
204                 skey = inkey_special(TRUE);
205                 if (skey == ESCAPE) break;
206
207                 j = i;
208                 switch (skey)
209                 {
210                 case '=':
211                         prt(_("強調: ", "Show: "), hgt - 1, 0);
212                         strcpy(back_str, shower_str);
213                         if (askfor(shower_str, 80))
214                                 shower = shower_str[0] ? shower_str : NULL;
215                         else
216                                 strcpy(shower_str, back_str);
217
218                         continue;
219                 case '/':
220                 case KTRL('s'):
221                 {
222                         prt(_("検索: ", "Find: "), hgt - 1, 0);
223                         strcpy(back_str, finder_str);
224                         if (!askfor(finder_str, 80))
225                         {
226                                 strcpy(finder_str, back_str);
227                                 continue;
228                         }
229                         else if (!finder_str[0])
230                         {
231                                 shower = NULL;
232                                 continue;
233                         }
234
235                         shower = finder_str;
236                         for (int z = i + 1; z < n; z++)
237                         {
238                                 concptr msg = message_str(z);
239                                 if (angband_strstr(msg, finder_str))
240                                 {
241                                         i = z;
242                                         break;
243                                 }
244                         }
245                 }
246
247                 break;
248
249                 case SKEY_TOP:
250                         i = n - num_lines;
251                         break;
252                 case SKEY_BOTTOM:
253                         i = 0;
254                         break;
255                 case '8':
256                 case SKEY_UP:
257                 case '\n':
258                 case '\r':
259                         i = MIN(i + 1, n - num_lines);
260                         break;
261                 case '+':
262                         i = MIN(i + 10, n - num_lines);
263                         break;
264                 case 'p':
265                 case KTRL('P'):
266                 case ' ':
267                 case SKEY_PGUP:
268                         i = MIN(i + num_lines, n - num_lines);
269                         break;
270                 case 'n':
271                 case KTRL('N'):
272                 case SKEY_PGDOWN:
273                         i = MAX(0, i - num_lines);
274                         break;
275                 case '-':
276                         i = MAX(0, i - 10);
277                         break;
278                 case '2':
279                 case SKEY_DOWN:
280                         i = MAX(0, i - 1);
281                         break;
282                 }
283
284                 if (i == j) bell();
285         }
286
287         screen_load();
288 }