OSDN Git Service

Merge pull request #982 from backwardsEric/nopch-target-setter
[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 "system/player-type-definition.h"
14 #include "term/gameterm.h"
15 #include "term/screen-processor.h"
16 #include "term/term-color-types.h"
17 #include "util/int-char-converter.h"
18 #include "util/string-processor.h"
19 #include "view/display-messages.h"
20 #include "view/display-player.h" // 暫定。後で消す.
21 #include "world/world.h"
22
23 /*!
24  * @brief 画面を再描画するコマンドのメインルーチン
25  * Hack -- redraw the screen
26  * @param creature_ptr プレーヤーへの参照ポインタ
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  */
74 void do_cmd_player_status(player_type *creature_ptr)
75 {
76         int mode = 0;
77         char tmp[160];
78         screen_save();
79         while (TRUE)
80         {
81                 update_playtime();
82                 display_player(creature_ptr, mode);
83
84                 if (mode == 5)
85                 {
86                         mode = 0;
87                         display_player(creature_ptr, mode);
88                 }
89
90                 term_putstr(2, 23, -1, TERM_WHITE,
91                         _("['c'で名前変更, 'f'でファイルへ書出, 'h'でモード変更, ESCで終了]", "['c' to change name, 'f' to file, 'h' to change mode, or ESC]"));
92                 char c = inkey();
93                 if (c == ESCAPE) break;
94
95                 if (c == 'c')
96                 {
97                         get_name(creature_ptr);
98                         process_player_name(creature_ptr);
99                 }
100                 else if (c == 'f')
101                 {
102                         sprintf(tmp, "%s.txt", creature_ptr->base_name);
103                         if (get_string(_("ファイル名: ", "File name: "), tmp, 80))
104                         {
105                                 if (tmp[0] && (tmp[0] != ' '))
106                                 {
107                                         update_playtime();
108                                         file_character(creature_ptr, tmp, display_player);
109                                 }
110                         }
111                 }
112                 else if (c == 'h')
113                 {
114                         mode++;
115                 }
116                 else
117                 {
118                         bell();
119                 }
120
121                 msg_erase();
122         }
123
124         screen_load();
125         creature_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
126         handle_stuff(creature_ptr);
127 }
128
129
130 /*!
131  * @brief 最近表示されたメッセージを再表示するコマンドのメインルーチン
132  * Recall the most recent message
133  */
134 void do_cmd_message_one(void)
135 {
136         prt(format("> %s", message_str(0)), 0, 0);
137 }
138
139
140 /*!
141  * @brief メッセージのログを表示するコマンドのメインルーチン
142  * Recall the most recent message
143  * @details
144  * <pre>
145  * Show previous messages to the user   -BEN-
146  *
147  * The screen format uses line 0 and 23 for headers and prompts,
148  * skips line 1 and 22, and uses line 2 thru 21 for old messages.
149  *
150  * This command shows you which commands you are viewing, and allows
151  * you to "search" for strings in the recall.
152  *
153  * Note that messages may be longer than 80 characters, but they are
154  * displayed using "infinite" length, with a special sub-command to
155  * "slide" the virtual display to the left or right.
156  *
157  * Attempt to only hilite the matching portions of the string.
158  * </pre>
159  */
160 void do_cmd_messages(int num_now)
161 {
162         char shower_str[81];
163         char finder_str[81];
164         char back_str[81];
165         concptr shower = NULL;
166         int wid, hgt;
167         term_get_size(&wid, &hgt);
168         int num_lines = hgt - 4;
169         strcpy(finder_str, "");
170         strcpy(shower_str, "");
171         int n = message_num();
172         int i = 0;
173         screen_save();
174         term_clear();
175         while (TRUE)
176         {
177                 int j;
178                 int skey;
179                 for (j = 0; (j < num_lines) && (i + j < n); j++)
180                 {
181                         concptr msg = message_str(i + j);
182                         c_prt((i + j < num_now ? TERM_WHITE : TERM_SLATE), msg, num_lines + 1 - j, 0);
183                         if (!shower || !shower[0]) continue;
184
185                         concptr str = msg;
186                         while ((str = angband_strstr(str, shower)) != NULL)
187                         {
188                                 int len = strlen(shower);
189                                 term_putstr(str - msg, num_lines + 1 - j, len, TERM_YELLOW, shower);
190                                 str += len;
191                         }
192                 }
193
194                 for (; j < num_lines; j++)
195                         term_erase(0, num_lines + 1 - j, 255);
196
197                 prt(format(_("以前のメッセージ %d-%d 全部で(%d)", "Message Recall (%d-%d of %d)"),
198                         i, i + j - 1, n), 0, 0);
199                 prt(_("[ 'p' で更に古いもの, 'n' で更に新しいもの, '/' で検索, ESC で中断 ]",
200                         "[Press 'p' for older, 'n' for newer, ..., or ESCAPE]"), hgt - 1, 0);
201                 skey = inkey_special(TRUE);
202                 if (skey == ESCAPE) break;
203
204                 j = i;
205                 switch (skey)
206                 {
207                 case '=':
208                         prt(_("強調: ", "Show: "), hgt - 1, 0);
209                         strcpy(back_str, shower_str);
210                         if (askfor(shower_str, 80))
211                                 shower = shower_str[0] ? shower_str : NULL;
212                         else
213                                 strcpy(shower_str, back_str);
214
215                         continue;
216                 case '/':
217                 case KTRL('s'):
218                 {
219                         prt(_("検索: ", "Find: "), hgt - 1, 0);
220                         strcpy(back_str, finder_str);
221                         if (!askfor(finder_str, 80))
222                         {
223                                 strcpy(finder_str, back_str);
224                                 continue;
225                         }
226                         else if (!finder_str[0])
227                         {
228                                 shower = NULL;
229                                 continue;
230                         }
231
232                         shower = finder_str;
233                         for (int z = i + 1; z < n; z++)
234                         {
235                                 concptr msg = message_str(z);
236                                 if (angband_strstr(msg, finder_str))
237                                 {
238                                         i = z;
239                                         break;
240                                 }
241                         }
242                 }
243
244                 break;
245
246                 case SKEY_TOP:
247                         i = n - num_lines;
248                         break;
249                 case SKEY_BOTTOM:
250                         i = 0;
251                         break;
252                 case '8':
253                 case SKEY_UP:
254                 case '\n':
255                 case '\r':
256                         i = MIN(i + 1, n - num_lines);
257                         break;
258                 case '+':
259                         i = MIN(i + 10, n - num_lines);
260                         break;
261                 case 'p':
262                 case KTRL('P'):
263                 case ' ':
264                 case SKEY_PGUP:
265                         i = MIN(i + num_lines, n - num_lines);
266                         break;
267                 case 'n':
268                 case KTRL('N'):
269                 case SKEY_PGDOWN:
270                         i = MAX(0, i - num_lines);
271                         break;
272                 case '-':
273                         i = MAX(0, i - 10);
274                         break;
275                 case '2':
276                 case SKEY_DOWN:
277                         i = MAX(0, i - 1);
278                         break;
279                 }
280
281                 if (i == j) bell();
282         }
283
284         screen_load();
285 }