2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
10 * $Logfile: /Freespace2/code/MissionUI/MissionLoopBrief.cpp $
15 * Campaign Loop briefing screen
18 * Revision 1.4 2004/09/20 01:31:44 theoddone33
21 * Revision 1.3 2002/06/09 04:41:23 relnev
22 * added copyright header
24 * Revision 1.2 2002/05/07 03:16:46 theoddone33
25 * The Great Newline Fix
27 * Revision 1.1.1.1 2002/05/03 03:28:10 root
31 * 4 9/06/99 9:44p Jefff
32 * break out of loop support
34 * 3 9/06/99 6:38p Dave
35 * Improved CD detection code.
37 * 2 8/27/99 12:04a Dave
38 * Campaign loop screen.
44 #include "missionloopbrief.h"
45 #include "missionscreencommon.h"
49 #include "eventmusic.h"
52 #include "gamesequence.h"
53 #include "missioncampaign.h"
55 #include "freespace.h"
57 // ---------------------------------------------------------------------------------------------------------------------------------------
58 // MISSION LOOP BRIEF DEFINES/VARS
61 const char *Loop_brief_fname[GR_NUM_RESOLUTIONS] = {
62 "LoopBrief", // GR_640
63 "2_LoopBrief", // GR_1024
66 const char *Loop_brief_mask[GR_NUM_RESOLUTIONS] = {
67 "LoopBrief-m", // GR_640
68 "2_Loopbrief-m", // GR_1024
71 #define NUM_LOOP_BRIEF_BUTTONS 2
72 #define LOOP_BRIEF_DECLINE 0
73 #define LOOP_BRIEF_ACCEPT 1
74 ui_button_info Loop_buttons[GR_NUM_RESOLUTIONS][NUM_LOOP_BRIEF_BUTTONS] = {
76 ui_button_info("LBB_00", 529, 437, -1, -1, 0),
77 ui_button_info("LBB_01", 575, 433, -1, -1, 1),
80 ui_button_info("2_LBB_00", 846, 699, -1, -1, 0),
81 ui_button_info("2_LBB_01", 920, 693, -1, -1, 1),
85 #define NUM_LOOP_TEXT 2
86 UI_XSTR Loop_text[GR_NUM_RESOLUTIONS][NUM_LOOP_TEXT] = {
88 { "Decline", 1467, 514, 413, UI_XSTR_COLOR_PINK, -1, &Loop_buttons[0][LOOP_BRIEF_DECLINE].button },
89 { "Accept", 1035, 573, 413, UI_XSTR_COLOR_PINK, -1, &Loop_buttons[0][LOOP_BRIEF_ACCEPT].button },
92 { "Decline", 1467, 855, 670, UI_XSTR_COLOR_PINK, -1, &Loop_buttons[1][LOOP_BRIEF_DECLINE].button },
93 { "Accept", 1035, 928, 670, UI_XSTR_COLOR_PINK, -1, &Loop_buttons[1][LOOP_BRIEF_ACCEPT].button },
98 int Loop_brief_anim_coords[GR_NUM_RESOLUTIONS][2] = {
107 // text window coords
108 int Loop_brief_text_coords[GR_NUM_RESOLUTIONS][4] = {
117 UI_WINDOW Loop_brief_window;
118 int Loop_brief_bitmap;
121 anim_instance *Loop_anim_instance;
125 // ---------------------------------------------------------------------------------------------------------------------------------------
126 // MISSION LOOP BRIEF FUNCTIONS
130 void loop_brief_button_pressed(int i)
133 case LOOP_BRIEF_DECLINE:
134 gameseq_post_event(GS_EVENT_START_GAME);
135 gamesnd_play_iface(SND_USER_SELECT);
138 case LOOP_BRIEF_ACCEPT:
139 // select the loop mission
140 Campaign.loop_enabled = 1;
141 Campaign.loop_reentry = Campaign.next_mission; // save reentry pt, so we can break out of loop
142 Campaign.next_mission = Campaign.loop_mission;
144 gameseq_post_event(GS_EVENT_START_GAME);
145 gamesnd_play_iface(SND_USER_SELECT);
151 void loop_brief_init()
156 // load the background bitmap
157 Loop_brief_bitmap = bm_load(Loop_brief_fname[gr_screen.res]);
158 SDL_assert(Loop_brief_bitmap != -1);
161 Loop_brief_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);
162 Loop_brief_window.set_mask_bmap(Loop_brief_mask[gr_screen.res]);
165 for (idx=0; idx<NUM_LOOP_BRIEF_BUTTONS; idx++) {
166 b = &Loop_buttons[gr_screen.res][idx];
168 b->button.create(&Loop_brief_window, "", b->x, b->y, 60, 30, 0, 1);
169 b->button.set_highlight_action(common_play_highlight_sound);
170 b->button.set_bmaps(b->filename);
171 b->button.link_hotspot(b->hotspot);
175 for(idx=0; idx<NUM_LOOP_TEXT; idx++){
176 Loop_brief_window.add_XSTR(&Loop_text[gr_screen.res][idx]);
179 // load animation if any
181 Loop_anim_instance = NULL;
182 if(Campaign.missions[Campaign.current_mission].mission_loop_brief_anim != NULL){
183 Loop_anim = anim_load(Campaign.missions[Campaign.current_mission].mission_loop_brief_anim);
185 Loop_anim = anim_load("CB_default");
188 // fire up an anim instance
189 if(Loop_anim != NULL){
190 anim_play_struct aps;
192 anim_play_init(&aps, Loop_anim, Loop_brief_anim_coords[gr_screen.res][0], Loop_brief_anim_coords[gr_screen.res][1]);
193 aps.framerate_independent = 1;
195 aps.screen_id = GS_STATE_LOOP_BRIEF;
196 Loop_anim_instance = anim_play(&aps);
200 if(Campaign.missions[Campaign.current_mission].mission_loop_desc != NULL){
201 brief_color_text_init(Campaign.missions[Campaign.current_mission].mission_loop_desc, Loop_brief_text_coords[gr_screen.res][2]);
205 if(Campaign.missions[Campaign.current_mission].mission_loop_brief_sound != NULL){
206 Loop_sound = audiostream_open(Campaign.missions[Campaign.current_mission].mission_loop_brief_sound, ASF_VOICE);
208 if(Loop_sound != -1){
209 audiostream_play(Loop_sound, Master_voice_volume, 0);
214 common_music_init(SCORE_BRIEFING);
224 k = Loop_brief_window.process();
228 gameseq_post_event(GS_EVENT_MAIN_MENU);
232 // process button presses
233 for (idx=0; idx<NUM_LOOP_BRIEF_BUTTONS; idx++){
234 if (Loop_buttons[gr_screen.res][idx].button.pressed()){
235 loop_brief_button_pressed(idx);
242 GR_MAYBE_CLEAR_RES(Loop_brief_bitmap);
243 if (Loop_brief_bitmap >= 0) {
244 gr_set_bitmap(Loop_brief_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
249 Loop_brief_window.draw();
251 // render the briefing text
252 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);
255 anim_render_all(GS_STATE_LOOP_BRIEF, flFrametime);
261 void loop_brief_close()
263 // this makes sure that we're all cool no matter how the user decides to exit
264 mission_campaign_mission_over();
267 if (Loop_brief_bitmap >= 0){
268 bm_unload(Loop_brief_bitmap);
270 Loop_brief_bitmap = -1;
272 // destroy the window
273 Loop_brief_window.destroy();
275 // free up anim stuff
276 if(Loop_anim_instance != NULL){
277 anim_release_render_instance(Loop_anim_instance);
278 Loop_anim_instance = NULL;
280 if(Loop_anim != NULL){
281 anim_free(Loop_anim);
286 if(Loop_sound != -1){
287 audiostream_stop(Loop_sound);
288 audiostream_close_file(Loop_sound);
293 common_music_close();