FS2_Open
Open source remastering of the Freespace 2 engine
debriefingeditordlg.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 "stdafx.h"
13 #include "FRED.h"
14 #include "DebriefingEditorDlg.h"
15 #include "FREDDoc.h"
17 #include "mission/missionparse.h"
18 #include "globalincs/linklist.h"
19 #include "parse/sexp.h"
20 #include "gamesnd/eventmusic.h"
21 #include "cfile/cfile.h"
22 #include "sound/audiostr.h"
23 #include "localization/localize.h"
24 #include "jumpnode/jumpnode.h"
25 
26 
27 #ifdef _DEBUG
28 #undef THIS_FILE
29 static char THIS_FILE[] = __FILE__;
30 #endif
31 
33 // debriefing_editor_dlg dialog
34 
36  : CDialog(debriefing_editor_dlg::IDD, pParent)
37 {
38  //{{AFX_DATA_INIT(debriefing_editor_dlg)
39  m_text = _T("");
40  m_voice = _T("");
41  m_stage_title = _T("");
42  m_rec_text = _T("");
47  //}}AFX_DATA_INIT
48 
49  modified = 0;
50  m_cur_stage = 0;
51  m_last_stage = -1;
52  m_voice_id = -1;
53  select_sexp_node = -1;
54 }
55 
56 void debriefing_editor_dlg::DoDataExchange(CDataExchange* pDX)
57 {
58  CDialog::DoDataExchange(pDX);
59  //{{AFX_DATA_MAP(debriefing_editor_dlg)
60  DDX_Control(pDX, IDC_TREE, m_tree);
61  DDX_Text(pDX, IDC_TEXT, m_text);
62  DDX_Text(pDX, IDC_VOICE, m_voice);
63  DDX_Text(pDX, IDC_STAGE_TITLE, m_stage_title);
64  DDX_Text(pDX, IDC_REC_TEXT, m_rec_text);
66  DDX_CBIndex(pDX, IDC_DEBRIEFING_TRACK, m_debriefAvg_music);
68  //}}AFX_DATA_MAP
69 
70  DDV_MaxChars(pDX, m_voice, MAX_FILENAME_LEN - 1);
71 }
72 
73 BEGIN_MESSAGE_MAP(debriefing_editor_dlg, CDialog)
74  //{{AFX_MSG_MAP(debriefing_editor_dlg)
75  ON_BN_CLICKED(IDC_NEXT, OnNext)
76  ON_BN_CLICKED(IDC_PREV, OnPrev)
77  ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
78  ON_BN_CLICKED(IDC_ADD_STAGE, OnAddStage)
79  ON_BN_CLICKED(IDC_DELETE_STAGE, OnDeleteStage)
80  ON_BN_CLICKED(IDC_INSERT_STAGE, OnInsertStage)
81  ON_NOTIFY(NM_RCLICK, IDC_TREE, OnRclickTree)
82  ON_NOTIFY(TVN_BEGINLABELEDIT, IDC_TREE, OnBeginlabeleditTree)
83  ON_NOTIFY(TVN_ENDLABELEDIT, IDC_TREE, OnEndlabeleditTree)
84  ON_WM_CLOSE()
85  ON_WM_INITMENU()
86  ON_BN_CLICKED(IDC_PLAY, OnPlay)
87  //}}AFX_MSG_MAP
88 END_MESSAGE_MAP()
89 
91 // debriefing_editor_dlg message handlers
92 
93 void debriefing_editor_dlg::OnInitMenu(CMenu* pMenu)
94 {
95  int i;
96  CMenu *m;
97 
98  // disable any items we should disable
99  m = pMenu->GetSubMenu(0);
100 
101  // uncheck all menu items
102  for (i = 0; i < Num_teams; i++ )
103  m->CheckMenuItem( i, MF_BYPOSITION | MF_UNCHECKED );
104 
105  for ( i = Num_teams; i < MAX_TVT_TEAMS; i++ )
106  m->EnableMenuItem(i, MF_BYPOSITION | MF_GRAYED);
107 
108 
109  // put a check next to the currently selected item
110  m->CheckMenuItem(m_current_debriefing, MF_BYPOSITION | MF_CHECKED );
111 
112  // Karajorma - it might be nice to autobalance the briefings and debriefings but I'm not doing anything till I
113  // understand how the how system works better. disabling the option for now.
114  m = pMenu->GetSubMenu(1);
115  m->EnableMenuItem(ID_AUTOBALANCE, MF_GRAYED);
116 
117  CDialog::OnInitMenu(pMenu);
118 }
119 
121 {
122  int i, n;
123 
124  CDialog::OnInitDialog();
125  m_play_bm.LoadBitmap(IDB_PLAY);
126  ((CButton *) GetDlgItem(IDC_PLAY)) -> SetBitmap(m_play_bm);
127  CComboBox *box;
128  box = (CComboBox *) GetDlgItem(IDC_ICON_IMAGE);
129 
131  UpdateData(FALSE);
132 
134 
135  box = (CComboBox *) GetDlgItem(IDC_SUCCESSFUL_MISSION_TRACK);
136  box->AddString("None");
137  for (i=0; i<Num_music_files; i++)
138  box->AddString(Spooled_music[i].name);
139 
140  box = (CComboBox *) GetDlgItem(IDC_DEBRIEFING_TRACK);
141  box->AddString("None");
142  for (i=0; i<Num_music_files; i++)
143  box->AddString(Spooled_music[i].name);
144 
145  box = (CComboBox *) GetDlgItem(IDC_FAILED_MISSION_TRACK);
146  box->AddString("None");
147  for (i=0; i<Num_music_files; i++)
148  box->AddString(Spooled_music[i].name);
149 
153 
154  m_tree.link_modified(&modified); // provide way to indicate trees are modified in dialog
156  select_sexp_node = -1;
157  if (n != -1) {
158  for (i=0; i<Debriefing->num_stages; i++)
160  break;
161 
162  if (i < Debriefing->num_stages) {
163  m_cur_stage = i;
164  update_data();
165  GetDlgItem(IDC_TREE) -> SetFocus();
167  set_modified();
168  return FALSE;
169  }
170  }
171 
172  CDialog::OnInitDialog();
173  update_data();
174  set_modified();
175 
176  // hard coded stuff to deal with the multiple briefings per mission.
177 
178  return TRUE;
179 }
180 
182 {
183  int enable, save_debriefing;
184  debrief_stage *ptr;
185 
186  save_debriefing = m_current_debriefing;
187 
188  if (update)
189  UpdateData(TRUE);
190 
191  // based on the game type, enable the multiple briefings combo box (or disable it)
192 
193  // set up the pointer to the briefing that we are editing
194  if ( save_debriefing != m_current_debriefing )
195  Debriefing = &Debriefings[save_debriefing];
196  else
198 
199  if (m_last_stage >= 0) {
200  ptr = &Debriefing->stages[m_last_stage];
201  if (ptr->formula >= 0)
202  free_sexp2(ptr->formula);
203 
204  ptr->formula = m_tree.save_tree();
210  }
211 
212  // now get new stage data
213  if ((m_cur_stage >= 0) && (m_cur_stage < Debriefing->num_stages)) {
214  ptr = &Debriefing->stages[m_cur_stage];
215  m_stage_title.Format("Stage %d of %d", m_cur_stage + 1, Debriefing->num_stages);
216  m_tree.load_tree(ptr->formula);
219  m_voice = ptr->voice;
220  enable = TRUE;
221 
222  } else {
223  m_stage_title = _T("No stages");
224  m_tree.clear_tree();
225  m_text = _T("");
226  m_rec_text = _T("");
227  m_voice = _T("");
228  enable = FALSE;
229  m_cur_stage = -1;
230  }
231 
232  if (m_cur_stage == Debriefing->num_stages - 1)
233  GetDlgItem(IDC_NEXT) -> EnableWindow(FALSE);
234  else
235  GetDlgItem(IDC_NEXT) -> EnableWindow(enable);
236 
237  if (m_cur_stage)
238  GetDlgItem(IDC_PREV) -> EnableWindow(enable);
239  else
240  GetDlgItem(IDC_PREV) -> EnableWindow(FALSE);
241 
243  GetDlgItem(IDC_ADD_STAGE) -> EnableWindow(FALSE);
244  else
245  GetDlgItem(IDC_ADD_STAGE) -> EnableWindow(TRUE);
246 
247  if (Debriefing->num_stages) {
248  GetDlgItem(IDC_DELETE_STAGE) -> EnableWindow(enable);
249  GetDlgItem(IDC_INSERT_STAGE) -> EnableWindow(enable);
250 
251  } else {
252  GetDlgItem(IDC_DELETE_STAGE) -> EnableWindow(FALSE);
253  GetDlgItem(IDC_INSERT_STAGE) -> EnableWindow(FALSE);
254  }
255 
256  GetDlgItem(IDC_VOICE) -> EnableWindow(enable);
257  GetDlgItem(IDC_BROWSE) -> EnableWindow(enable);
258  GetDlgItem(IDC_TEXT) -> EnableWindow(enable);
259  GetDlgItem(IDC_REC_TEXT) -> EnableWindow(enable);
260  GetDlgItem(IDC_TREE) -> EnableWindow(enable);
261 
263  UpdateData(FALSE);
264 
265  #ifndef NDEBUG
267  #endif
268 }
269 
271 {
273  m_voice_id = -1;
274 
275  m_cur_stage++;
276  update_data();
277 }
278 
280 {
282  m_voice_id = -1;
283 
284  m_cur_stage--;
285  update_data();
286 }
287 
289 {
290  int z;
291  CString name;
292 
294  m_voice_id = -1;
295 
296  UpdateData(TRUE);
297 
300  else
302 
303  CFileDialog dlg(TRUE, "wav", NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR,
304  "Voice Files (*.ogg, *.wav)|*.ogg;*.wav|Ogg Vorbis Files (*.ogg)|*.ogg|Wave Files (*.wav)|*.wav||");
305 
306  if (dlg.DoModal() == IDOK) {
307  m_voice = dlg.GetFileName();
308  UpdateData(FALSE);
309  }
310 
311  if (!z)
312  cfile_pop_dir();
313 }
314 
316 {
317  int i;
318 
320  return;
321 
323  m_voice_id = -1;
324 
326  copy_stage(i - 1, i, 1);
327  update_data(1);
328 }
329 
331 {
332  int i, z;
333 
334  if (m_cur_stage < 0)
335  return;
336 
338  m_voice_id = -1;
339 
341  z = m_cur_stage;
342  m_cur_stage = -1;
343  update_data(1);
344  for (i=z+1; i<Debriefing->num_stages; i++) {
345  copy_stage(i, i - 1);
346  }
347 
349  m_cur_stage = z;
352 
353  update_data(0);
354 }
355 
357 {
358  int i, z;
359 
361  return;
362 
363  if (!Debriefing->num_stages) {
364  OnAddStage();
365  return;
366  }
367 
369  m_voice_id = -1;
370 
371  z = m_cur_stage;
372  m_cur_stage = -1;
373  update_data(1);
374  for (i=Debriefing->num_stages; i>z; i--) {
375  copy_stage(i - 1, i);
376  }
377 
379  copy_stage(z, z + 1);
380  Debriefing->stages[z].formula = -1;
381  m_cur_stage = z;
382  update_data(0);
383 }
384 
385 void debriefing_editor_dlg::copy_stage(int from, int to, int clear_formula)
386 {
387  if ((from < 0) || (from >= Debriefing->num_stages)) {
388  Debriefing->stages[to].text = "<Text here>";
389  strcpy_s(Debriefing->stages[to].voice, "none.wav");
390  Debriefing->stages[to].formula = -1;
391  return;
392  }
393 
394  if (clear_formula)
395  Debriefing->stages[to].formula = -1;
396  else
398 
399  Debriefing->stages[to].text = Debriefing->stages[from].text;
402 }
403 
404 void debriefing_editor_dlg::OnRclickTree(NMHDR* pNMHDR, LRESULT* pResult)
405 {
407  *pResult = 0;
408 }
409 
411 {
412  TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
413 
414  if (m_tree.edit_label(pTVDispInfo->item.hItem) == 1) {
415  *pResult = 0;
416  modified = 1;
417 
418  } else
419  *pResult = 1;
420 }
421 
423 {
424  TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
425 
426  *pResult = m_tree.end_label_edit(pTVDispInfo->item);
427 }
428 
430 {
432  m_voice_id = -1;
433  m_cur_stage = -1;
434  update_data(1);
435 
439 
440  CDialog::OnClose();
441 }
442 
444 {
445 }
446 
448 {
449  int id;
450 
451  // deal with figuring out menu stuff
452  id = LOWORD(wParam);
453  if ( (id >= ID_TEAM_1) && (id < ID_TEAM_3) ) {
454  update_data(1);
455 
456  // set the current debriefing
458 
459  // put user back at first stage for this team (or no current stage is there are none).
461  if ( Debriefing->num_stages > 0 )
462  m_cur_stage = 0;
463  else
464  m_cur_stage = -1;
465 
466  m_last_stage = -1;
467  update_data(0);
468  }
469 
470  return CDialog::OnCommand(wParam, lParam);
471 }
472 
474 {
476  m_play_bm.DeleteObject();
477  return CDialog::DestroyWindow();
478 }
479 
481 {
482  GetDlgItem(IDC_VOICE)->GetWindowText(m_voice);
483 
484  if (m_voice_id >= 0) {
486  m_voice_id = -1;
487  return;
488  }
489 
490  // we use ASF_EVENTMUSIC here so that it will keep the extension in place
491  m_voice_id = audiostream_open((char *)(LPCSTR) m_voice, ASF_EVENTMUSIC);
492 
493  if (m_voice_id >= 0) {
494  audiostream_play(m_voice_id, 1.0f, 0);
495  }
496 }
#define MAX_FILENAME_LEN
Definition: pstypes.h:324
int i
Definition: multi_pxo.cpp:466
debriefing_editor_dlg(CWnd *pParent=NULL)
int count_free_sexp_nodes()
Definition: sexp.cpp:1176
#define ID_AUTOBALANCE
Definition: resource.h:1462
#define CF_TYPE_VOICE_DEBRIEFINGS
Definition: cfile.h:57
int game_type
Definition: missionparse.h:138
int Mission_music[NUM_SCORES]
Definition: eventmusic.cpp:253
SCP_string recommendation_text
#define ASF_EVENTMUSIC
Definition: audiostr.h:19
#define IDC_DELETE_STAGE
Definition: resource.h:568
Assert(pm!=NULL)
virtual void DoDataExchange(CDataExchange *pDX)
int cfile_pop_dir()
Definition: cfile.cpp:381
GLclampf f
Definition: Glext.h:7097
void link_modified(int *ptr)
Definition: sexp_tree.cpp:3156
#define TRUE
Definition: pstypes.h:399
UINT WPARAM wParam
Definition: msacm.h:1064
#define ID_TEAM_1
Definition: resource.h:1428
#define IDC_TEXT
Definition: resource.h:771
#define IDC_BROWSE
Definition: resource.h:729
int edit_label(HTREEITEM h)
Definition: sexp_tree.cpp:1349
UINT WPARAM LPARAM lParam
Definition: msacm.h:1064
#define IDC_FAILED_MISSION_TRACK
Definition: resource.h:138
void deconvert_multiline_string(char *dest, const CString &str, int max_len)
Definition: management.cpp:184
afx_msg void OnBeginlabeleditTree(NMHDR *pNMHDR, LRESULT *pResult)
void right_clicked(int mode=0)
Definition: sexp_tree.cpp:570
long LPARAM
Definition: config.h:101
#define SCORE_DEBRIEF_FAIL
Definition: eventmusic.h:54
int cfile_push_chdir(int type)
Push current directory onto a 'stack' and change to a new directory.
Definition: cfile.cpp:342
int Num_music_files
Definition: eventmusic.cpp:250
void convert_multiline_string(CString &dest, const SCP_string &src)
Definition: management.cpp:169
#define IDC_TREE
Definition: resource.h:704
#define SCORE_DEBRIEF_AVERAGE
Definition: eventmusic.h:53
int end_label_edit(TVITEMA &item)
Definition: sexp_tree.cpp:1412
GLdouble GLdouble z
Definition: Glext.h:5451
int free_sexp2(int num)
Definition: sexp.cpp:1321
afx_msg void OnRclickTree(NMHDR *pNMHDR, LRESULT *pResult)
int Num_teams
#define IDC_VOICE
Definition: resource.h:800
GLenum GLuint id
Definition: Glext.h:5156
char name[NAME_LENGTH]
Definition: eventmusic.h:65
char voice[MAX_FILENAME_LEN]
GLclampd n
Definition: Glext.h:7286
void string_copy(char *dest, const CString &src, int max_len, int modify)
Definition: management.cpp:142
void update_data(int update=1)
#define IDC_REC_TEXT
Definition: resource.h:908
#define IDC_STAGE_TITLE
Definition: resource.h:849
int query_node_in_sexp(int node, int sexp)
Definition: sexp.cpp:1437
#define IDC_SUCCESSFUL_MISSION_TRACK
Definition: resource.h:141
#define IDC_PREV
Definition: resource.h:851
menu_music Spooled_music[MAX_SPOOLED_MUSIC]
Definition: eventmusic.cpp:249
void set_modified(BOOL arg)
Definition: freddoc.cpp:676
GLuint const GLchar * name
Definition: Glext.h:5608
GLboolean enable
Definition: Glext.h:10591
int BOOL
Definition: config.h:80
#define MISSION_TYPE_TRAINING
Definition: missionparse.h:63
afx_msg void OnEndlabeleditTree(NMHDR *pNMHDR, LRESULT *pResult)
void audiostream_close_file(int i, int fade)
Definition: audiostr.cpp:1772
debrief_stage stages[MAX_DEBRIEF_STAGES]
#define ID_TEAM_3
Definition: resource.h:1430
#define IDC_PLAY
Definition: resource.h:333
#define IDC_DEBRIEFING_TRACK
Definition: resource.h:147
int save_tree(int node=-1)
Definition: sexp_tree.cpp:237
long LRESULT
Definition: config.h:100
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam)
void audiostream_play(int i, float volume, int looping)
Definition: audiostr.cpp:1803
const GLfloat * m
Definition: Glext.h:10319
void load_tree(int index, const char *deflt="true")
Definition: sexp_tree.cpp:124
#define MAX_TVT_TEAMS
Definition: globals.h:57
debriefing Debriefings[MAX_TVT_TEAMS]
#define SCORE_DEBRIEF_SUCCESS
Definition: eventmusic.h:52
void hilite_item(int node)
Definition: sexp_tree.cpp:3139
#define IDB_PLAY
Definition: resource.h:87
int audiostream_open(const char *filename, int type)
Definition: audiostr.cpp:1713
#define IDC_INSERT_STAGE
Definition: resource.h:853
#define IDC_ICON_IMAGE
Definition: resource.h:524
int select_sexp_node
Definition: sexp_tree.h:283
mission The_mission
#define IDC_ADD_STAGE
Definition: resource.h:845
#define CF_TYPE_VOICE_TRAINING
Definition: cfile.h:60
#define FALSE
Definition: pstypes.h:400
void lcl_fred_replace_stuff(char *text, size_t max_len)
Definition: localize.cpp:610
void copy_stage(int from, int to, int clear_formula=0)
debriefing * Debriefing
void clear_tree(const char *op=NULL)
Definition: sexp_tree.cpp:99
#define MAX_DEBRIEF_STAGES
#define strcpy_s(...)
Definition: safe_strings.h:67
#define IDC_NEXT
Definition: resource.h:844