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