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