OSDN Git Service

f1a2efcf139f955ebda04f65239d857c5c4dc895
[hengbandforosx/hengbandosx.git] / src / core / window-redrawer.cpp
1 /*!
2  * @brief ウィンドウの再描画処理
3  * @date 2020/06/27
4  * @author Hourier
5  */
6 #include "core/window-redrawer.h"
7 #include "core/player-redraw-types.h"
8 #include "core/stuff-handler.h"
9 #include "floor/floor-util.h"
10 #include "game-option/option-flags.h"
11 #include "object/item-tester-hooker.h"
12 #include "player-info/race-info.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/bit-flags-calculator.h"
18 #include "view/display-messages.h"
19 #include "view/display-player.h"
20 #include "window/display-sub-window-spells.h"
21 #include "window/display-sub-windows.h"
22 #include "window/main-window-left-frame.h"
23 #include "window/main-window-row-column.h"
24 #include "window/main-window-stat-poster.h"
25 #include "window/main-window-util.h"
26 #include "world/world-turn-processor.h"
27 #include "world/world.h"
28
29 /*!
30  * @brief コンソールを再描画する /
31  * Redraw a term when it is resized
32  * @todo ここにplayer_type を追加するとz-termに影響が行くので保留
33  */
34 void redraw_window(void)
35 {
36     if (!w_ptr->character_dungeon)
37         return;
38
39     p_ptr->window_flags = PW_ALL;
40
41     handle_stuff(p_ptr);
42     term_redraw();
43 }
44
45 /*!
46  * @brief 現在のマップ名を描画する / Print dungeon
47  * @param player_ptr プレイヤーへの参照ポインタ
48  */
49 static void print_dungeon(player_type *player_ptr)
50 {
51     c_put_str(TERM_WHITE, "             ", ROW_DUNGEON, COL_DUNGEON);
52     concptr dungeon_name = map_name(player_ptr);
53     TERM_LEN col = COL_DUNGEON + 6 - strlen(dungeon_name) / 2;
54     if (col < 0)
55         col = 0;
56
57     c_put_str(TERM_L_UMBER, format("%s", dungeon_name), ROW_DUNGEON, col);
58 }
59
60 /*!
61  * @brief redraw のフラグに応じた更新をまとめて行う / Handle "redraw"
62  * @details 更新処理の対象はゲーム中の全描画処理
63  */
64 void redraw_stuff(player_type *player_ptr)
65 {
66     if (!player_ptr->redraw)
67         return;
68
69     if (!w_ptr->character_generated)
70         return;
71
72     if (w_ptr->character_icky_depth > 0)
73         return;
74
75     if (player_ptr->redraw & (PR_WIPE)) {
76         player_ptr->redraw &= ~(PR_WIPE);
77         msg_print(nullptr);
78         term_clear();
79     }
80
81     if (player_ptr->redraw & (PR_MAP)) {
82         player_ptr->redraw &= ~(PR_MAP);
83         print_map(player_ptr);
84     }
85
86     if (player_ptr->redraw & (PR_BASIC)) {
87         player_ptr->redraw &= ~(PR_BASIC);
88         player_ptr->redraw &= ~(PR_MISC | PR_TITLE | PR_STATS);
89         player_ptr->redraw &= ~(PR_LEV | PR_EXP | PR_GOLD);
90         player_ptr->redraw &= ~(PR_ARMOR | PR_HP | PR_MANA);
91         player_ptr->redraw &= ~(PR_DEPTH | PR_HEALTH | PR_UHEALTH);
92         print_frame_basic(player_ptr);
93         WorldTurnProcessor(player_ptr).print_time();
94         print_dungeon(player_ptr);
95     }
96
97     if (player_ptr->redraw & (PR_EQUIPPY)) {
98         player_ptr->redraw &= ~(PR_EQUIPPY);
99         display_player_equippy(player_ptr, ROW_EQUIPPY, COL_EQUIPPY, 0);
100     }
101
102     if (player_ptr->redraw & (PR_MISC)) {
103         player_ptr->redraw &= ~(PR_MISC);
104         print_field(rp_ptr->title, ROW_RACE, COL_RACE);
105     }
106
107     if (player_ptr->redraw & (PR_TITLE)) {
108         player_ptr->redraw &= ~(PR_TITLE);
109         print_title(player_ptr);
110     }
111
112     if (player_ptr->redraw & (PR_LEV)) {
113         player_ptr->redraw &= ~(PR_LEV);
114         print_level(player_ptr);
115     }
116
117     if (player_ptr->redraw & (PR_EXP)) {
118         player_ptr->redraw &= ~(PR_EXP);
119         print_exp(player_ptr);
120     }
121
122     if (player_ptr->redraw & (PR_STATS)) {
123         player_ptr->redraw &= ~(PR_STATS);
124         print_stat(player_ptr, A_STR);
125         print_stat(player_ptr, A_INT);
126         print_stat(player_ptr, A_WIS);
127         print_stat(player_ptr, A_DEX);
128         print_stat(player_ptr, A_CON);
129         print_stat(player_ptr, A_CHR);
130     }
131
132     if (player_ptr->redraw & (PR_STATUS)) {
133         player_ptr->redraw &= ~(PR_STATUS);
134         print_status(player_ptr);
135     }
136
137     if (player_ptr->redraw & (PR_ARMOR)) {
138         player_ptr->redraw &= ~(PR_ARMOR);
139         print_ac(player_ptr);
140     }
141
142     if (player_ptr->redraw & (PR_HP)) {
143         player_ptr->redraw &= ~(PR_HP);
144         print_hp(player_ptr);
145     }
146
147     if (player_ptr->redraw & (PR_MANA)) {
148         player_ptr->redraw &= ~(PR_MANA);
149         print_sp(player_ptr);
150     }
151
152     if (player_ptr->redraw & (PR_GOLD)) {
153         player_ptr->redraw &= ~(PR_GOLD);
154         print_gold(player_ptr);
155     }
156
157     if (player_ptr->redraw & (PR_DEPTH)) {
158         player_ptr->redraw &= ~(PR_DEPTH);
159         print_depth(player_ptr);
160     }
161
162     if (player_ptr->redraw & (PR_HEALTH)) {
163         player_ptr->redraw &= ~(PR_HEALTH);
164         health_redraw(player_ptr, false);
165     }
166
167     if (player_ptr->redraw & (PR_UHEALTH)) {
168         player_ptr->redraw &= ~(PR_UHEALTH);
169         health_redraw(player_ptr, true);
170     }
171
172     if (player_ptr->redraw & (PR_EXTRA)) {
173         player_ptr->redraw &= ~(PR_EXTRA);
174         player_ptr->redraw &= ~(PR_CUT | PR_STUN);
175         player_ptr->redraw &= ~(PR_HUNGER);
176         player_ptr->redraw &= ~(PR_STATE | PR_SPEED | PR_STUDY | PR_IMITATION | PR_STATUS);
177         print_frame_extra(player_ptr);
178     }
179
180     if (player_ptr->redraw & (PR_CUT)) {
181         player_ptr->redraw &= ~(PR_CUT);
182         print_cut(player_ptr);
183     }
184
185     if (player_ptr->redraw & (PR_STUN)) {
186         player_ptr->redraw &= ~(PR_STUN);
187         print_stun(player_ptr);
188     }
189
190     if (player_ptr->redraw & (PR_HUNGER)) {
191         player_ptr->redraw &= ~(PR_HUNGER);
192         print_hunger(player_ptr);
193     }
194
195     if (player_ptr->redraw & (PR_STATE)) {
196         player_ptr->redraw &= ~(PR_STATE);
197         print_state(player_ptr);
198     }
199
200     if (player_ptr->redraw & (PR_SPEED)) {
201         player_ptr->redraw &= ~(PR_SPEED);
202         print_speed(player_ptr);
203     }
204
205     if (player_ptr->pclass == CLASS_IMITATOR) {
206         if (player_ptr->redraw & (PR_IMITATION)) {
207             player_ptr->redraw &= ~(PR_IMITATION);
208             print_imitation(player_ptr);
209         }
210
211         return;
212     }
213
214     if (player_ptr->redraw & (PR_STUDY)) {
215         player_ptr->redraw &= ~(PR_STUDY);
216         print_study(player_ptr);
217     }
218 }
219
220 /*!
221  * @brief player_ptr->window のフラグに応じた更新をまとめて行う / Handle "player_ptr->window"
222  * @param player_ptr プレイヤーへの参照ポインタ
223  * @details 更新処理の対象はサブウィンドウ全般
224  */
225 void window_stuff(player_type *player_ptr)
226 {
227     if (!player_ptr->window_flags)
228         return;
229
230     BIT_FLAGS mask = 0L;
231     for (int j = 0; j < 8; j++) {
232         if (angband_term[j] && !angband_term[j]->never_fresh)
233             mask |= window_flag[j];
234     }
235     BIT_FLAGS window_flags = player_ptr->window_flags & mask;
236
237     if (window_flags & (PW_INVEN)) {
238         player_ptr->window_flags &= ~(PW_INVEN);
239         fix_inventory(player_ptr);
240     }
241
242     if (window_flags & (PW_EQUIP)) {
243         player_ptr->window_flags &= ~(PW_EQUIP);
244         fix_equip(player_ptr);
245     }
246
247     if (window_flags & (PW_SPELL)) {
248         player_ptr->window_flags &= ~(PW_SPELL);
249         fix_spell(player_ptr);
250     }
251
252     if (window_flags & (PW_PLAYER)) {
253         player_ptr->window_flags &= ~(PW_PLAYER);
254         fix_player(player_ptr);
255     }
256
257     // モンスターBGM対応のため、視界内モンスター表示のサブウインドウなし時も処理を行う
258     if (player_ptr->window_flags & (PW_MONSTER_LIST)) {
259         player_ptr->window_flags &= ~(PW_MONSTER_LIST);
260         fix_monster_list(player_ptr);
261     }
262
263     if (window_flags & (PW_MESSAGE)) {
264         player_ptr->window_flags &= ~(PW_MESSAGE);
265         fix_message();
266     }
267
268     if (window_flags & (PW_OVERHEAD)) {
269         player_ptr->window_flags &= ~(PW_OVERHEAD);
270         fix_overhead(player_ptr);
271     }
272
273     if (window_flags & (PW_DUNGEON)) {
274         player_ptr->window_flags &= ~(PW_DUNGEON);
275         fix_dungeon(player_ptr);
276     }
277
278     if (window_flags & (PW_MONSTER)) {
279         player_ptr->window_flags &= ~(PW_MONSTER);
280         fix_monster(player_ptr);
281     }
282
283     if (window_flags & (PW_OBJECT)) {
284         player_ptr->window_flags &= ~(PW_OBJECT);
285         fix_object(player_ptr);
286     }
287
288     if (any_bits(window_flags, PW_FLOOR_ITEM_LIST)) {
289         reset_bits(player_ptr->window_flags, PW_FLOOR_ITEM_LIST);
290         // ウィンドウサイズ変更に対応できず。カーソル位置を取る必要がある。
291         fix_floor_item_list(player_ptr, player_ptr->y, player_ptr->x);
292     }
293 }