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