]> icculus.org git repositories - taylor/freespace2.git/blob - src/missionui/missionpause.cpp
added copyright header
[taylor/freespace2.git] / src / missionui / missionpause.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/MissionUI/MissionPause.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  * 
15  *
16  * $Log$
17  * Revision 1.3  2002/06/09 04:41:23  relnev
18  * added copyright header
19  *
20  * Revision 1.2  2002/05/07 03:16:46  theoddone33
21  * The Great Newline Fix
22  *
23  * Revision 1.1.1.1  2002/05/03 03:28:10  root
24  * Initial import.
25  *
26  * 
27  * 7     7/29/99 10:48p Dave
28  * Multiplayer pause screen.
29  * 
30  * 6     6/29/99 7:39p Dave
31  * Lots of small bug fixes.
32  * 
33  * 5     6/09/99 2:17p Dave
34  * Fixed up pleasewait bitmap rendering.
35  * 
36  *
37  * $NoKeywords: $
38  */
39
40 #include "missionpause.h"
41 #include "ui.h"
42 #include "multi_pause.h"
43 #include "popup.h"
44 #include "2d.h"
45 #include "bmpman.h"
46 #include "key.h"
47 #include "audiostr.h"
48 #include "gamesequence.h"
49 #include "freespace.h"
50 #include "hud.h"
51 #include "object.h"
52 #include "font.h"
53 #include "alphacolors.h"
54 #include "beam.h"
55
56 // ----------------------------------------------------------------------------------------------------------------
57 // PAUSE DEFINES/VARS
58 //
59
60 // pause bitmap name
61 char *Pause_bmp_name[GR_NUM_RESOLUTIONS] = {
62         "PleaseWait",
63         "2_PleaseWait"
64 };
65
66 // pause bitmap display stuff
67 int Please_wait_coords[GR_NUM_RESOLUTIONS][4] = {
68         { // GR_640
69                 152, 217, 316, 26
70         },
71         { // GR_1024
72                 247, 346, 510, 36
73         }       
74 };
75
76 char *Pause_multi_fname[GR_NUM_RESOLUTIONS] = {
77         "MPPause",
78         "2_MPPause"
79 };
80 char *Pause_multi_mask[GR_NUM_RESOLUTIONS] = {
81         "MPPause-m",
82         "2_MPPause-m"
83 };
84
85 // pause window objects
86 UI_WINDOW Pause_win;
87 UI_CHECKBOX Pause_single_step;
88 UI_CHECKBOX Pause_physics;
89 UI_CHECKBOX Pause_ai;
90 UI_CHECKBOX Pause_ai_render;
91 UI_CHECKBOX Pause_firing;
92 UI_CHECKBOX Pause_external_view_mode_check;
93 UI_BUTTON Pause_continue;
94
95 // if we're already paused
96 int Paused = 0;
97
98 // background screen (for the chatbox)
99 int Pause_background_bitmap = -1;
100
101 // saved background screen
102 int Pause_saved_screen = -1;
103
104 // if we're in external vie wmode
105 int Pause_external_view_mode = 0;
106
107 // externs
108 extern int Player_attacking_enabled;
109 extern int Ai_render_debug_flag;
110 extern int Ai_firing_enabled;
111 extern int physics_paused;
112 extern int ai_paused;
113 extern int last_single_step;
114 extern int game_single_step;
115
116 // ----------------------------------------------------------------------------------------------------------------
117 // PAUSE FUNCTIONS
118 //
119
120 // initialize the pause screen
121 void pause_init(int multi)
122 {
123         // if we're already paused. do nothing
124         if ( Paused ) {
125                 return;
126         }       
127
128         // pause all beam weapon sounds
129         beam_pause_sounds();
130
131         if(!(Game_mode & GM_STANDALONE_SERVER)){
132                 Pause_saved_screen = gr_save_screen();
133
134                 // pause all game music
135                 audiostream_pause_all();
136
137                 //JAS: REMOVED CALL TO SET INTERFACE PALETTE TO GET RID OF SCREEN CLEAR WHEN PAUSING
138                 //common_set_interface_palette();  // set the interface palette
139                 Pause_win.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);    
140
141                 if (multi) {
142                         Pause_win.set_mask_bmap(Pause_multi_mask[gr_screen.res]);
143                         Pause_background_bitmap = bm_load(Pause_multi_fname[gr_screen.res]);
144
145                         multi_pause_init(&Pause_win);           
146                 } else {
147                         Pause_background_bitmap = bm_load(Pause_bmp_name[gr_screen.res]);
148                 }
149         } else {
150                 multi_pause_init(NULL);
151         }
152
153         Paused = 1;
154 }
155
156 // pause do frame - will handle running multiplayer operations if necessary
157 void pause_do(int multi)
158 {
159         int k;
160         char *pause_str = XSTR("Paused", 767);
161         int str_w, str_h;
162
163         if(Game_mode & GM_STANDALONE_SERVER){
164                 multi_pause_do();
165         } else {                
166                 //      RENDER A GAME FRAME HERE AS THE BACKGROUND
167                 gr_restore_screen(Pause_saved_screen);
168                 if (Pause_background_bitmap >= 0) {
169                         gr_set_bitmap(Pause_background_bitmap);
170                         if(multi){
171                                 gr_bitmap(0,0);
172                         } else {
173                                 // draw the bitmap
174                                 gr_bitmap(Please_wait_coords[gr_screen.res][0], Please_wait_coords[gr_screen.res][1]);
175
176                                 // draw "Paused" on it
177                                 gr_set_color_fast(&Color_normal);
178                                 gr_set_font(FONT2);
179                                 gr_get_string_size(&str_w, &str_h, pause_str);
180                                 gr_string((gr_screen.max_w - str_w) / 2, (gr_screen.max_h - str_h) / 2, pause_str);
181                                 gr_set_font(FONT1);
182                         }
183                 }
184         
185                 // the multi paused screen will do its own window processing
186                 if (multi) {
187                         multi_pause_do();
188                 }
189                 // otherwise process the ui window here
190                 else {
191                         k = Pause_win.process() & ~KEY_DEBUGGED;
192                         switch (k) {                    
193                         case KEY_ESC:
194                         case KEY_PAUSE:
195                                 gameseq_post_event(GS_EVENT_PREVIOUS_STATE);            
196                                 break;
197                         }       // end switch
198                 }
199         
200                 // draw the background window
201                 Pause_win.draw();               
202
203                 // a very unique case where we shouldn't be doing the page flip because we're inside of popup code
204                 if(!popup_active()){
205                         gr_flip();
206                 } else {
207                         // this should only be happening in a very unique multiplayer case
208                         Assert(Game_mode & GM_MULTIPLAYER);
209                 }
210         }
211 }
212
213 // close the pause screen
214 void pause_close(int multi)
215 {
216         // if we're not paused - do nothing
217         if ( !Paused ) {
218                 return;
219         }
220
221         // unpause all beam weapon sounds
222         beam_unpause_sounds();
223
224         // deinit stuff
225         if(Game_mode & GM_STANDALONE_SERVER){
226                 multi_pause_close();
227         } else {
228                 gr_free_screen(Pause_saved_screen);     
229
230                 if (Pause_background_bitmap){
231                         bm_unload(Pause_background_bitmap);
232                 }
233
234                 Pause_win.destroy();            
235                 game_flush();
236                 if (multi) {
237                         multi_pause_close();
238                 }
239
240                 // unpause all the music
241                 audiostream_unpause_all();              
242         }
243
244         Paused = 0;
245 }
246
247 // debug pause init
248 void pause_debug_init()
249 {
250         Pause_win.create( 100,100,400,300, WIN_DIALOG );
251
252         Pause_physics.create( &Pause_win, NOX("Physics Pause <P>"), 200, 150, physics_paused );
253         Pause_ai.create( &Pause_win, NOX("AI Pause <A>"), 200, 175, ai_paused );
254         #ifndef NDEBUG
255         Pause_ai_render.create( &Pause_win, NOX("AI Render Stuff <R>"), 200, 200, Ai_render_debug_flag);
256         #endif
257         Pause_firing.create( &Pause_win, NOX("AI firing <F>"), 200, 225, Ai_firing_enabled);
258         Pause_external_view_mode_check.create( &Pause_win, NOX("External View <E>"), 200, 250, Pause_external_view_mode);
259         Pause_single_step.create( &Pause_win, NOX("Single Step <S>"), 200, 290, game_single_step );
260         Pause_continue.create( &Pause_win, NOX("Leave Pause"), 200, 350, 200, 40 );
261
262         Pause_single_step.set_hotkey( KEY_S );
263         Pause_physics.set_hotkey( KEY_P );
264         Pause_ai.set_hotkey( KEY_A );
265         Pause_ai_render.set_hotkey( KEY_R );
266         Pause_firing.set_hotkey( KEY_F );
267         Pause_external_view_mode_check.set_hotkey( KEY_E );
268         Pause_continue.set_hotkey( KEY_ESC );
269
270         Pause_continue.set_focus();
271 }
272
273 // debug pause do frame
274 void pause_debug_do()
275 {
276         int key;
277
278         key = Pause_win.process();
279         if ( Pause_single_step.changed())       {
280                 game_single_step = Pause_single_step.checked();
281         }
282
283         if ( Pause_physics.changed())   {
284                 physics_paused = Pause_physics.checked();
285         }
286
287         if ( Pause_ai.changed())        {
288                 ai_paused = Pause_ai.checked();
289                 if (ai_paused){
290                         obj_init_all_ships_physics();
291                 }
292         }
293
294         if ( Pause_ai_render.changed()) {
295                 Ai_render_debug_flag = Pause_ai_render.checked();
296         }
297
298         if ( Pause_firing.changed())    {
299                 Ai_firing_enabled = Pause_firing.checked();
300         }
301
302         if ( Pause_external_view_mode_check.changed())  {
303                 Pause_external_view_mode = Pause_external_view_mode_check.checked();
304                 if (Pause_external_view_mode){
305                         HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "External view of player ship.", 182));
306                 } else {
307                         HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "View from inside player ship.", 183));
308                 }
309         }
310
311         if ( Pause_continue.pressed() || (key == KEY_PAUSE) )   {       //      Changed, MK, 11/9/97, only Pause break pause.
312                 gameseq_post_event(GS_EVENT_PREVIOUS_STATE);
313         }
314
315         gr_clear();
316         Pause_win.draw();
317
318         gr_flip();
319 }
320
321 // debug pause close
322 void pause_debug_close()
323 {
324         last_single_step = 0;   // Make so single step waits a frame before stepping
325         Pause_win.destroy();
326         game_flush();
327 }
328