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