]> icculus.org git repositories - taylor/freespace2.git/blob - src/missionui/missionloopbrief.cpp
fixed demo dogfight multiplayer mission
[taylor/freespace2.git] / src / missionui / missionloopbrief.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/MissionLoopBrief.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Campaign Loop briefing screen
16  *
17  * $Log$
18  * Revision 1.3  2002/06/09 04:41:23  relnev
19  * added copyright header
20  *
21  * Revision 1.2  2002/05/07 03:16:46  theoddone33
22  * The Great Newline Fix
23  *
24  * Revision 1.1.1.1  2002/05/03 03:28:10  root
25  * Initial import.
26  *
27  * 
28  * 4     9/06/99 9:44p Jefff
29  * break out of loop support
30  * 
31  * 3     9/06/99 6:38p Dave
32  * Improved CD detection code.
33  * 
34  * 2     8/27/99 12:04a Dave
35  * Campaign loop screen.
36  *  
37  *
38  * $NoKeywords: $
39  */
40
41 #include "missionloopbrief.h"
42 #include "missionscreencommon.h"
43 #include "2d.h"
44 #include "bmpman.h"
45 #include "gamesnd.h"
46 #include "eventmusic.h"
47 #include "audiostr.h"
48 #include "key.h"
49 #include "gamesequence.h"
50 #include "missioncampaign.h"
51 #include "animplay.h"
52 #include "freespace.h"
53
54 // ---------------------------------------------------------------------------------------------------------------------------------------
55 // MISSION LOOP BRIEF DEFINES/VARS
56 //
57
58 char *Loop_brief_fname[GR_NUM_RESOLUTIONS] = {
59         "LoopBrief",            // GR_640
60         "2_LoopBrief",          // GR_1024
61 };
62
63 char *Loop_brief_mask[GR_NUM_RESOLUTIONS] = {
64         "LoopBrief-m",          // GR_640
65         "2_Loopbrief-m",        // GR_1024
66 };
67
68 #define NUM_LOOP_BRIEF_BUTTONS                          2
69 #define LOOP_BRIEF_DECLINE                                              0
70 #define LOOP_BRIEF_ACCEPT                                               1
71 ui_button_info Loop_buttons[GR_NUM_RESOLUTIONS][NUM_LOOP_BRIEF_BUTTONS] = {
72         { // GR_640
73                 ui_button_info("LBB_00",                529,    437,    -1,     -1,     0),
74                 ui_button_info("LBB_01",                575,    433,    -1,     -1,     1),
75         },
76         { // GR_1024
77                 ui_button_info("2_LBB_00",              846,    699,    -1,     -1,     0),
78                 ui_button_info("2_LBB_01",              920,    693,    -1,     -1,     1),
79         }
80 };
81
82 #define NUM_LOOP_TEXT                                                   2
83 UI_XSTR Loop_text[GR_NUM_RESOLUTIONS][NUM_LOOP_TEXT] = {
84         { // GR_640
85                 { "Decline",            1467,   514,    413,    UI_XSTR_COLOR_PINK,     -1,     &Loop_buttons[0][LOOP_BRIEF_DECLINE].button },
86                 { "Accept",                     1035,   573,    413,    UI_XSTR_COLOR_PINK,     -1,     &Loop_buttons[0][LOOP_BRIEF_ACCEPT].button },
87         },      
88         { // GR_1024
89                 { "Decline",            1467,   855,    670,    UI_XSTR_COLOR_PINK,     -1,     &Loop_buttons[1][LOOP_BRIEF_DECLINE].button },
90                 { "Accept",                     1035,   928,    670,    UI_XSTR_COLOR_PINK,     -1,     &Loop_buttons[1][LOOP_BRIEF_ACCEPT].button },
91         }
92 };
93
94 // loop brief anim
95 int Loop_brief_anim_coords[GR_NUM_RESOLUTIONS][2] = {
96         { // GR_640
97                 24, 267
98         },
99         { // GR_640
100                 167, 491
101         }
102 };
103
104 // text window coords
105 int Loop_brief_text_coords[GR_NUM_RESOLUTIONS][4] = {
106         { // GR_640
107                 25,     107,    591,    143
108         },
109         { // GR_1024
110                 40,     171,    945,    229
111         }
112 };
113
114 UI_WINDOW Loop_brief_window;
115 int Loop_brief_bitmap;
116
117 anim *Loop_anim;
118 anim_instance *Loop_anim_instance;
119
120 int Loop_sound;
121
122 // ---------------------------------------------------------------------------------------------------------------------------------------
123 // MISSION LOOP BRIEF FUNCTIONS
124 //
125
126 // button press
127 void loop_brief_button_pressed(int i)
128 {       
129         switch(i){
130         case LOOP_BRIEF_DECLINE:                
131                 // CD CHECK
132                 if(game_do_cd_mission_check(Game_current_mission_filename)){
133                         gameseq_post_event(GS_EVENT_START_GAME);
134                         gamesnd_play_iface(SND_USER_SELECT);
135                 } else {
136                         gameseq_post_event(GS_EVENT_MAIN_MENU);
137                 }               
138                 break;
139
140         case LOOP_BRIEF_ACCEPT:
141                 // select the loop mission              
142                 Campaign.loop_enabled = 1;
143                 Campaign.loop_reentry = Campaign.next_mission;                  // save reentry pt, so we can break out of loop
144                 Campaign.next_mission = Campaign.loop_mission;          
145                 
146                 // CD CHECK
147                 if(game_do_cd_mission_check(Game_current_mission_filename)){
148                         gameseq_post_event(GS_EVENT_START_GAME);
149                         gamesnd_play_iface(SND_USER_SELECT);
150                 } else {
151                         gameseq_post_event(GS_EVENT_MAIN_MENU);
152                 }               
153                 break;
154         }
155 }
156
157 // init
158 void loop_brief_init()
159 {
160         int idx;
161         ui_button_info *b;
162
163         // load the background bitmap
164         Loop_brief_bitmap = bm_load(Loop_brief_fname[gr_screen.res]);
165         Assert(Loop_brief_bitmap != -1);
166
167         // window
168         Loop_brief_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);
169         Loop_brief_window.set_mask_bmap(Loop_brief_mask[gr_screen.res]);        
170
171         // add the buttons
172         for (idx=0; idx<NUM_LOOP_BRIEF_BUTTONS; idx++) {
173                 b = &Loop_buttons[gr_screen.res][idx];
174
175                 b->button.create(&Loop_brief_window, "", b->x, b->y, 60, 30, 0, 1);             
176                 b->button.set_highlight_action(common_play_highlight_sound);
177                 b->button.set_bmaps(b->filename);
178                 b->button.link_hotspot(b->hotspot);
179         }
180
181         // add text
182         for(idx=0; idx<NUM_LOOP_TEXT; idx++){
183                 Loop_brief_window.add_XSTR(&Loop_text[gr_screen.res][idx]);
184         }
185
186         // load animation if any
187         Loop_anim = NULL;
188         Loop_anim_instance = NULL;
189         if(Campaign.missions[Campaign.current_mission].mission_loop_brief_anim != NULL){
190                 Loop_anim = anim_load(Campaign.missions[Campaign.current_mission].mission_loop_brief_anim);
191         } else {
192                 Loop_anim = anim_load("CB_default");
193         }
194
195         // fire up an anim instance
196         if(Loop_anim != NULL){
197                 anim_play_struct aps;
198
199                 anim_play_init(&aps, Loop_anim, Loop_brief_anim_coords[gr_screen.res][0], Loop_brief_anim_coords[gr_screen.res][1]);
200                 aps.framerate_independent = 1;
201                 aps.looped = 1;
202                 aps.screen_id = GS_STATE_LOOP_BRIEF;
203                 Loop_anim_instance = anim_play(&aps);
204         }
205
206         // init brief text
207         if(Campaign.missions[Campaign.current_mission].mission_loop_desc != NULL){
208                 brief_color_text_init(Campaign.missions[Campaign.current_mission].mission_loop_desc, Loop_brief_text_coords[gr_screen.res][2]);
209         }
210
211         // open sound
212         if(Campaign.missions[Campaign.current_mission].mission_loop_brief_sound != NULL){
213                 Loop_sound = audiostream_open(Campaign.missions[Campaign.current_mission].mission_loop_brief_sound, ASF_VOICE);
214
215                 if(Loop_sound != -1){
216                         audiostream_play(Loop_sound, Master_voice_volume, 0);
217                 }
218         }
219
220         // music
221         common_music_init(SCORE_BRIEFING);
222 }
223
224 // do
225 void loop_brief_do()
226 {
227         int k;
228         int idx;
229
230         // process keys
231         k = Loop_brief_window.process();        
232
233         switch (k) {
234         case KEY_ESC:           
235                 gameseq_post_event(GS_EVENT_MAIN_MENU);
236                 break;
237         }       
238
239         // process button presses
240         for (idx=0; idx<NUM_LOOP_BRIEF_BUTTONS; idx++){
241                 if (Loop_buttons[gr_screen.res][idx].button.pressed()){
242                         loop_brief_button_pressed(idx);
243                 }
244         }
245         
246         common_music_do();
247
248         // clear
249         GR_MAYBE_CLEAR_RES(Loop_brief_bitmap);
250         if (Loop_brief_bitmap >= 0) {
251                 gr_set_bitmap(Loop_brief_bitmap);
252                 gr_bitmap(0, 0);
253         } 
254         
255         // draw the window
256         Loop_brief_window.draw();               
257
258         // render the briefing text
259         brief_render_text(0, Loop_brief_text_coords[gr_screen.res][0], Loop_brief_text_coords[gr_screen.res][1], Loop_brief_text_coords[gr_screen.res][3], flFrametime);
260
261         // render all anims
262         anim_render_all(GS_STATE_LOOP_BRIEF, flFrametime);
263
264         gr_flip();
265 }
266
267 // close
268 void loop_brief_close()
269 {
270         // this makes sure that we're all cool no matter how the user decides to exit
271         mission_campaign_mission_over();
272
273         // free the bitmap
274         if (Loop_brief_bitmap >= 0){
275                 bm_unload(Loop_brief_bitmap);
276         }               
277         Loop_brief_bitmap = -1;
278
279         // destroy the window
280         Loop_brief_window.destroy();
281
282         // free up anim stuff
283         if(Loop_anim_instance != NULL){
284                 anim_release_render_instance(Loop_anim_instance);
285                 Loop_anim_instance = NULL;
286         }
287         if(Loop_anim != NULL){
288                 anim_free(Loop_anim);
289                 Loop_anim = NULL;
290         }
291
292         // stop voice
293         if(Loop_sound != -1){
294                 audiostream_stop(Loop_sound);
295                 audiostream_close_file(Loop_sound);
296                 Loop_sound = -1;
297         }
298
299         // stop music
300         common_music_close();
301 }