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.3 2002/06/09 04:41:23 relnev
19 * added copyright header
21 * Revision 1.2 2002/05/07 03:16:46 theoddone33
22 * The Great Newline Fix
24 * Revision 1.1.1.1 2002/05/03 03:28:10 root
28 * 4 9/06/99 9:44p Jefff
29 * break out of loop support
31 * 3 9/06/99 6:38p Dave
32 * Improved CD detection code.
34 * 2 8/27/99 12:04a Dave
35 * Campaign loop screen.
41 #include "missionloopbrief.h"
42 #include "missionscreencommon.h"
46 #include "eventmusic.h"
49 #include "gamesequence.h"
50 #include "missioncampaign.h"
52 #include "freespace.h"
54 // ---------------------------------------------------------------------------------------------------------------------------------------
55 // MISSION LOOP BRIEF DEFINES/VARS
58 char *Loop_brief_fname[GR_NUM_RESOLUTIONS] = {
59 "LoopBrief", // GR_640
60 "2_LoopBrief", // GR_1024
63 char *Loop_brief_mask[GR_NUM_RESOLUTIONS] = {
64 "LoopBrief-m", // GR_640
65 "2_Loopbrief-m", // GR_1024
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] = {
73 ui_button_info("LBB_00", 529, 437, -1, -1, 0),
74 ui_button_info("LBB_01", 575, 433, -1, -1, 1),
77 ui_button_info("2_LBB_00", 846, 699, -1, -1, 0),
78 ui_button_info("2_LBB_01", 920, 693, -1, -1, 1),
82 #define NUM_LOOP_TEXT 2
83 UI_XSTR Loop_text[GR_NUM_RESOLUTIONS][NUM_LOOP_TEXT] = {
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 },
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 },
95 int Loop_brief_anim_coords[GR_NUM_RESOLUTIONS][2] = {
104 // text window coords
105 int Loop_brief_text_coords[GR_NUM_RESOLUTIONS][4] = {
114 UI_WINDOW Loop_brief_window;
115 int Loop_brief_bitmap;
118 anim_instance *Loop_anim_instance;
122 // ---------------------------------------------------------------------------------------------------------------------------------------
123 // MISSION LOOP BRIEF FUNCTIONS
127 void loop_brief_button_pressed(int i)
130 case LOOP_BRIEF_DECLINE:
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);
136 gameseq_post_event(GS_EVENT_MAIN_MENU);
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;
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);
151 gameseq_post_event(GS_EVENT_MAIN_MENU);
158 void loop_brief_init()
163 // load the background bitmap
164 Loop_brief_bitmap = bm_load(Loop_brief_fname[gr_screen.res]);
165 Assert(Loop_brief_bitmap != -1);
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]);
172 for (idx=0; idx<NUM_LOOP_BRIEF_BUTTONS; idx++) {
173 b = &Loop_buttons[gr_screen.res][idx];
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);
182 for(idx=0; idx<NUM_LOOP_TEXT; idx++){
183 Loop_brief_window.add_XSTR(&Loop_text[gr_screen.res][idx]);
186 // load animation if any
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);
192 Loop_anim = anim_load("CB_default");
195 // fire up an anim instance
196 if(Loop_anim != NULL){
197 anim_play_struct aps;
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;
202 aps.screen_id = GS_STATE_LOOP_BRIEF;
203 Loop_anim_instance = anim_play(&aps);
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]);
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);
215 if(Loop_sound != -1){
216 audiostream_play(Loop_sound, Master_voice_volume, 0);
221 common_music_init(SCORE_BRIEFING);
231 k = Loop_brief_window.process();
235 gameseq_post_event(GS_EVENT_MAIN_MENU);
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);
249 GR_MAYBE_CLEAR_RES(Loop_brief_bitmap);
250 if (Loop_brief_bitmap >= 0) {
251 gr_set_bitmap(Loop_brief_bitmap);
256 Loop_brief_window.draw();
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);
262 anim_render_all(GS_STATE_LOOP_BRIEF, flFrametime);
268 void loop_brief_close()
270 // this makes sure that we're all cool no matter how the user decides to exit
271 mission_campaign_mission_over();
274 if (Loop_brief_bitmap >= 0){
275 bm_unload(Loop_brief_bitmap);
277 Loop_brief_bitmap = -1;
279 // destroy the window
280 Loop_brief_window.destroy();
282 // free up anim stuff
283 if(Loop_anim_instance != NULL){
284 anim_release_render_instance(Loop_anim_instance);
285 Loop_anim_instance = NULL;
287 if(Loop_anim != NULL){
288 anim_free(Loop_anim);
293 if(Loop_sound != -1){
294 audiostream_stop(Loop_sound);
295 audiostream_close_file(Loop_sound);
300 common_music_close();