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