FS2_Open
Open source remastering of the Freespace 2 engine
missionloopbrief.cpp
Go to the documentation of this file.
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 the
6  * source.
7  *
8 */
9 
10 
11 
12 #include "anim/animplay.h"
13 #include "freespace2/freespace.h"
15 #include "gamesnd/eventmusic.h"
16 #include "gamesnd/gamesnd.h"
17 #include "graphics/generic.h"
18 #include "io/key.h"
23 #include "popup/popup.h"
24 #include "sound/audiostr.h"
25 #include "sound/fsspeech.h"
26 
27 extern char default_loop_briefing_color; // Doesn't seem worth including alphacolors.h for -MageKing17
28 
29 
30 // ---------------------------------------------------------------------------------------------------------------------------------------
31 // MISSION LOOP BRIEF DEFINES/VARS
32 //
33 
35  "LoopBrief", // GR_640
36  "2_LoopBrief", // GR_1024
37 };
38 
40  "LoopBrief-m", // GR_640
41  "2_Loopbrief-m", // GR_1024
42 };
43 
44 #define NUM_LOOP_BRIEF_BUTTONS 2
45 #define LOOP_BRIEF_DECLINE 0
46 #define LOOP_BRIEF_ACCEPT 1
48  { // GR_640
49  ui_button_info("LBB_00", 529, 437, -1, -1, 0),
50  ui_button_info("LBB_01", 575, 433, -1, -1, 1),
51  },
52  { // GR_1024
53  ui_button_info("2_LBB_00", 846, 699, -1, -1, 0),
54  ui_button_info("2_LBB_01", 920, 693, -1, -1, 1),
55  }
56 };
57 
58 #define NUM_LOOP_TEXT 2
60  { // GR_640
61  { "Decline", 1467, 514, 413, UI_XSTR_COLOR_PINK, -1, &Loop_buttons[0][LOOP_BRIEF_DECLINE].button },
62  { "Accept", 1035, 573, 413, UI_XSTR_COLOR_PINK, -1, &Loop_buttons[0][LOOP_BRIEF_ACCEPT].button },
63  },
64  { // GR_1024
65  { "Decline", 1467, 855, 670, UI_XSTR_COLOR_PINK, -1, &Loop_buttons[1][LOOP_BRIEF_DECLINE].button },
66  { "Accept", 1035, 928, 670, UI_XSTR_COLOR_PINK, -1, &Loop_buttons[1][LOOP_BRIEF_ACCEPT].button },
67  }
68 };
69 
70 // Originally from missioncmdbrief.cpp
71 // center coordinates only
73 {
74  {
75  242, 367 // GR_640
76  },
77  {
78  392, 587 // GR_1024
79  }
80 };
81 
82 // text window coords
84  { // GR_640
85  25, 107, 591, 143
86  },
87  { // GR_1024
88  40, 171, 945, 229
89  }
90 };
91 
94 
96 
98 
99 // ---------------------------------------------------------------------------------------------------------------------------------------
100 // MISSION LOOP BRIEF FUNCTIONS
101 //
102 
103 // button press
105 {
106  switch(i){
107  case LOOP_BRIEF_DECLINE:
110  break;
111 
112  case LOOP_BRIEF_ACCEPT:
113  // select the loop mission
115  Campaign.loop_reentry = Campaign.next_mission; // save reentry pt, so we can break out of loop
117 
120  break;
121  }
122 }
123 
124 // init
126 {
127  int idx;
128  ui_button_info *b;
129 
130  // load the background bitmap
132  Assert(Loop_brief_bitmap != -1);
133 
134  // window
135  Loop_brief_window.create(0, 0, gr_screen.max_w_unscaled, gr_screen.max_h_unscaled, 0);
136  Loop_brief_window.set_mask_bmap(Loop_brief_mask[gr_screen.res]);
137 
138  // add the buttons
139  for (idx=0; idx<NUM_LOOP_BRIEF_BUTTONS; idx++) {
140  b = &Loop_buttons[gr_screen.res][idx];
141 
142  b->button.create(&Loop_brief_window, "", b->x, b->y, 60, 30, 0, 1);
144  b->button.set_bmaps(b->filename);
145  b->button.link_hotspot(b->hotspot);
146  }
147 
148  // add text
149  for(idx=0; idx<NUM_LOOP_TEXT; idx++){
150  Loop_brief_window.add_XSTR(&Loop_text[gr_screen.res][idx]);
151  }
152 
153  const char* anim_name;
154  // load animation if any
157  } else {
158  anim_name = "CB_default";
159  }
160 
161  int stream_result = generic_anim_init_and_stream(&Loop_anim, anim_name, bm_get_type(Loop_brief_bitmap), true);
162  // we've failed to load any animation
163  if (stream_result < 0) {
164  // load an image and treat it like a 1 frame animation
165  Loop_anim.first_frame = bm_load(anim_name); //if we fail here, the value is still -1
166  if(Loop_anim.first_frame != -1) {
167  Loop_anim.num_frames = 1;
168  }
169  }
170 
171  // init brief text
174  }
175 
176  bool sound_played = false;
177 
178 
179  // open sound
182 
183  if(Loop_sound != -1){
185  sound_played = true;
186  }
187  }
188 
189  if(sound_played == false) {
192 
193  }
194 
195  // music
197 }
198 
199 // do
200 void loop_brief_do(float frametime)
201 {
202  int k;
203  int idx;
204 
205  // process keys
206  k = Loop_brief_window.process();
207 
208  switch (k) {
209  case KEY_ESC:
210  int do_loop = 0;
211 
212  // this popup should be straight forward, and also not allow you to get out
213  // of it without actually picking one of the two options
214  do_loop = popup(PF_USE_NEGATIVE_ICON | PF_USE_AFFIRMATIVE_ICON | PF_IGNORE_ESC | PF_BODY_BIG, 2, XSTR("Decline", 1467), XSTR("Accept", 1035), XSTR("You must either Accept or Decline before returning to the Main Hall", 1618));
215 
216  // if we accepted moving into loop then set it up for the next time the user plays
217  if (do_loop == 1) {
218  // select the loop mission
220  Campaign.loop_reentry = Campaign.next_mission; // save reentry pt, so we can break out of loop
222  }
223 
225  return;
226  }
227 
228  // process button presses
229  for (idx=0; idx<NUM_LOOP_BRIEF_BUTTONS; idx++){
230  if (Loop_buttons[gr_screen.res][idx].button.pressed()){
232  }
233  }
234 
235  common_music_do();
236 
237  // clear
239  if (Loop_brief_bitmap >= 0) {
241  gr_bitmap(0, 0, GR_RESIZE_MENU);
242  }
243 
244  // draw the window
245  Loop_brief_window.draw();
246 
247  // render the briefing text
249 
250  if(Loop_anim.num_frames > 0) {
251  int x;
252  int y;
253 
254  bm_get_info((Loop_anim.streaming) ? Loop_anim.bitmap_id : Loop_anim.first_frame, &x, &y, NULL, NULL, NULL);
257  generic_anim_render(&Loop_anim, frametime, x, y, true);
258  }
259 
260  // render all anims
262 
263  gr_flip();
264 }
265 
266 // close
268 {
269  // this makes sure that we're all cool no matter how the user decides to exit
271 
272  // free the bitmap
273  if (Loop_brief_bitmap >= 0){
275  }
276  Loop_brief_bitmap = -1;
277 
278  // destroy the window
279  Loop_brief_window.destroy();
280 
281  if (Loop_anim.num_frames > 0)
282  {
283  generic_anim_unload(&Loop_anim);
284  }
285 
286  // stop voice
287  if(Loop_sound != -1){
290  Loop_sound = -1;
291  }
292 
293  fsspeech_stop();
294 
295  // stop music
297 }
void set_highlight_action(void(*_user_function)(void))
Definition: button.cpp:375
char default_loop_briefing_color
Definition: alphacolors.cpp:46
int i
Definition: multi_pxo.cpp:466
int bitmap_id
Definition: generic.h:46
void add_XSTR(char *string, int _xstr_id, int _x, int _y, UI_GADGET *_assoc, int _color_type, int _font_id=-1)
Definition: window.cpp:476
char * Loop_brief_fname[GR_NUM_RESOLUTIONS]
void fsspeech_stop()
Definition: fsspeech.h:45
void gr_flip()
Definition: 2d.cpp:2113
int x
Definition: ui.h:658
#define GR_RESIZE_MENU
Definition: 2d.h:684
float flFrametime
Definition: fredstubs.cpp:22
int y
Definition: ui.h:658
#define ASF_VOICE
Definition: audiostr.h:21
int brief_color_text_init(const char *src, int w, const char default_color, int instance, int max_lines, const bool append)
char * mission_branch_desc
int Loop_brief_text_coords[GR_NUM_RESOLUTIONS][4]
Assert(pm!=NULL)
#define GR_NUM_RESOLUTIONS
Definition: 2d.h:651
int Loop_sound
int res
Definition: 2d.h:370
int max_h_unscaled
Definition: 2d.h:361
int bm_get_info(int handle, int *w, int *h, ubyte *flags, int *nframes, int *fps)
Gets info on the bitmap indexed by handle.
Definition: bmpman.cpp:769
#define GR_MAYBE_CLEAR_RES(bmap)
Definition: 2d.h:639
void common_music_close()
void mission_campaign_mission_over(bool do_next_mission)
#define SCORE_BRIEFING
Definition: eventmusic.h:51
char * Loop_brief_mask[GR_NUM_RESOLUTIONS]
void gr_set_bitmap(int bitmap_num, int alphablend_mode, int bitblt_mode, float alpha)
Definition: 2d.cpp:2105
int max_w_unscaled
Definition: 2d.h:361
int bm_release(int handle, int clear_render_targets)
Frees both a bitmap's data and it's associated slot.
Definition: bmpman.cpp:2603
void generic_anim_unload(generic_anim *ga)
Definition: generic.cpp:291
void loop_brief_button_pressed(int i)
void destroy()
Definition: window.cpp:189
void loop_brief_init()
int num_frames
Definition: generic.h:20
void set_mask_bmap(char *fname)
Definition: window.cpp:75
int set_bmaps(char *ani_filename, int nframes=3, int start_frame=1)
Definition: gadget.cpp:71
ui_button_info Loop_buttons[GR_NUM_RESOLUTIONS][NUM_LOOP_BRIEF_BUTTONS]
int first_frame
Definition: generic.h:19
void audiostream_stop(int i, int rewind, int paused)
Definition: audiostr.cpp:1840
int hotspot
Definition: ui.h:659
int pressed()
Definition: button.cpp:325
void generic_anim_render(generic_anim *ga, float frametime, int x, int y, bool menu)
Definition: generic.cpp:437
UI_BUTTON button
Definition: ui.h:660
void fsspeech_play(int type, const char *text)
Definition: fsspeech.h:44
void anim_render_all(int screen_id, float frametime)
Display the frames for the currently playing anims.
Definition: animplay.cpp:67
char * mission_branch_brief_anim
int idx
Definition: multiui.cpp:761
#define LOOP_BRIEF_ACCEPT
GLint GLint GLint GLint GLint x
Definition: Glext.h:5182
const char * XSTR(const char *str, int index)
Definition: localize.cpp:851
user_click (mouse selects a control)
Definition: gamesnd.h:305
void common_music_do()
void loop_brief_do(float frametime)
char * mission_branch_brief_sound
int current_mission
int bm_load(const char *real_filename)
Loads a bitmap so we can draw with it later.
Definition: bmpman.cpp:1119
GLboolean GLboolean GLboolean b
Definition: Glext.h:5781
void audiostream_close_file(int i, int fade)
Definition: audiostr.cpp:1772
int Loop_brief_anim_center_coords[GR_NUM_RESOLUTIONS][2]
void link_hotspot(int num)
Definition: gadget.cpp:50
unsigned char streaming
Definition: generic.h:42
campaign Campaign
void create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _w, int _h, int do_repeat=0, int ignore_focus=0)
Definition: button.cpp:26
#define KEY_ESC
Definition: key.h:124
#define UI_XSTR_COLOR_PINK
Definition: ui.h:161
UI_WINDOW Loop_brief_window
void create(int _x, int _y, int _w, int _h, int _flags, int _f_id=-1)
Definition: window.cpp:140
Definition: ui.h:584
screen gr_screen
Definition: 2d.cpp:46
Definition: ui.h:162
void common_play_highlight_sound()
Definition: gamesnd.cpp:1151
BM_TYPE bm_get_type(int handle)
Returns the image type of the given bitmap handle.
Definition: bmpman.cpp:894
void audiostream_play(int i, float volume, int looping)
Definition: audiostr.cpp:1803
generic_anim Loop_anim
#define NUM_LOOP_BRIEF_BUTTONS
char * filename
Definition: ui.h:657
int brief_render_text(int line_offset, int x, int y, int h, float frametime, int instance, int line_spacing)
void gr_bitmap(int _x, int _y, int resize_mode)
Definition: 2d.cpp:1303
UI_XSTR Loop_text[GR_NUM_RESOLUTIONS][NUM_LOOP_TEXT]
void loop_brief_close()
int generic_anim_init_and_stream(generic_anim *ga, const char *anim_filename, BM_TYPE bg_type, bool attempt_hi_res)
Definition: generic.cpp:32
#define LOOP_BRIEF_DECLINE
int audiostream_open(const char *filename, int type)
Definition: audiostr.cpp:1713
void gamesnd_play_iface(int n)
Definition: gamesnd.cpp:260
void draw()
Definition: window.cpp:220
struct ui_button_info ui_button_info
int process(int key_in=-1, int process_mouse=1)
Definition: window.cpp:401
void gameseq_post_event(int event)
#define NUM_LOOP_TEXT
float Master_voice_volume
Definition: sound.cpp:54
cmission missions[MAX_CAMPAIGN_MISSIONS]
void common_music_init(int score_index)
GLint y
Definition: Gl.h:1505
int Loop_brief_bitmap