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 char *Loop_brief_fname[GR_NUM_RESOLUTIONS] = {
62 "LoopBrief", // GR_640
63 "2_LoopBrief", // GR_1024
66 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:
135 if(game_do_cd_mission_check(Game_current_mission_filename)){
136 gameseq_post_event(GS_EVENT_START_GAME);
137 gamesnd_play_iface(SND_USER_SELECT);
139 gameseq_post_event(GS_EVENT_MAIN_MENU);
143 case LOOP_BRIEF_ACCEPT:
144 // select the loop mission
145 Campaign.loop_enabled = 1;
146 Campaign.loop_reentry = Campaign.next_mission; // save reentry pt, so we can break out of loop
147 Campaign.next_mission = Campaign.loop_mission;
150 if(game_do_cd_mission_check(Game_current_mission_filename)){
151 gameseq_post_event(GS_EVENT_START_GAME);
152 gamesnd_play_iface(SND_USER_SELECT);
154 gameseq_post_event(GS_EVENT_MAIN_MENU);
161 void loop_brief_init()
166 // load the background bitmap
167 Loop_brief_bitmap = bm_load(Loop_brief_fname[gr_screen.res]);
168 Assert(Loop_brief_bitmap != -1);
171 Loop_brief_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);
172 Loop_brief_window.set_mask_bmap(Loop_brief_mask[gr_screen.res]);
175 for (idx=0; idx<NUM_LOOP_BRIEF_BUTTONS; idx++) {
176 b = &Loop_buttons[gr_screen.res][idx];
178 b->button.create(&Loop_brief_window, "", b->x, b->y, 60, 30, 0, 1);
179 b->button.set_highlight_action(common_play_highlight_sound);
180 b->button.set_bmaps(b->filename);
181 b->button.link_hotspot(b->hotspot);
185 for(idx=0; idx<NUM_LOOP_TEXT; idx++){
186 Loop_brief_window.add_XSTR(&Loop_text[gr_screen.res][idx]);
189 // load animation if any
191 Loop_anim_instance = NULL;
192 if(Campaign.missions[Campaign.current_mission].mission_loop_brief_anim != NULL){
193 Loop_anim = anim_load(Campaign.missions[Campaign.current_mission].mission_loop_brief_anim);
195 Loop_anim = anim_load("CB_default");
198 // fire up an anim instance
199 if(Loop_anim != NULL){
200 anim_play_struct aps;
202 anim_play_init(&aps, Loop_anim, Loop_brief_anim_coords[gr_screen.res][0], Loop_brief_anim_coords[gr_screen.res][1]);
203 aps.framerate_independent = 1;
205 aps.screen_id = GS_STATE_LOOP_BRIEF;
206 Loop_anim_instance = anim_play(&aps);
210 if(Campaign.missions[Campaign.current_mission].mission_loop_desc != NULL){
211 brief_color_text_init(Campaign.missions[Campaign.current_mission].mission_loop_desc, Loop_brief_text_coords[gr_screen.res][2]);
215 if(Campaign.missions[Campaign.current_mission].mission_loop_brief_sound != NULL){
216 Loop_sound = audiostream_open(Campaign.missions[Campaign.current_mission].mission_loop_brief_sound, ASF_VOICE);
218 if(Loop_sound != -1){
219 audiostream_play(Loop_sound, Master_voice_volume, 0);
224 common_music_init(SCORE_BRIEFING);
234 k = Loop_brief_window.process();
238 gameseq_post_event(GS_EVENT_MAIN_MENU);
242 // process button presses
243 for (idx=0; idx<NUM_LOOP_BRIEF_BUTTONS; idx++){
244 if (Loop_buttons[gr_screen.res][idx].button.pressed()){
245 loop_brief_button_pressed(idx);
252 GR_MAYBE_CLEAR_RES(Loop_brief_bitmap);
253 if (Loop_brief_bitmap >= 0) {
254 gr_set_bitmap(Loop_brief_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
259 Loop_brief_window.draw();
261 // render the briefing text
262 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);
265 anim_render_all(GS_STATE_LOOP_BRIEF, flFrametime);
271 void loop_brief_close()
273 // this makes sure that we're all cool no matter how the user decides to exit
274 mission_campaign_mission_over();
277 if (Loop_brief_bitmap >= 0){
278 bm_unload(Loop_brief_bitmap);
280 Loop_brief_bitmap = -1;
282 // destroy the window
283 Loop_brief_window.destroy();
285 // free up anim stuff
286 if(Loop_anim_instance != NULL){
287 anim_release_render_instance(Loop_anim_instance);
288 Loop_anim_instance = NULL;
290 if(Loop_anim != NULL){
291 anim_free(Loop_anim);
296 if(Loop_sound != -1){
297 audiostream_stop(Loop_sound);
298 audiostream_close_file(Loop_sound);
303 common_music_close();