2 * $Logfile: /Freespace2/code/FRED2/DebriefingEditorDlg.cpp $
7 * Debriefing editor dialog. Used to edit mission debriefings of course.
10 * Revision 1.1 2002/05/03 03:28:08 root
14 * 2 10/07/98 6:28p Dave
15 * Initial checkin. Renamed all relevant stuff to be Fred2 instead of
16 * Fred. Globalized mission and campaign file extensions. Removed Silent
17 * Threat specific code.
19 * 1 10/07/98 3:01p Dave
21 * 1 10/07/98 3:00p Dave
23 * 20 7/07/98 2:09p Hoffoss
24 * Fixed bug where sexp for debriefing stages get cleared when inserting
27 * 19 4/30/98 8:23p John
28 * Fixed some bugs with Fred caused by my new cfile code.
30 * 18 4/22/98 9:56a Sandeep
32 * 17 4/20/98 4:40p Hoffoss
33 * Added a button to 4 editors to play the chosen wave file.
35 * 16 4/17/98 1:41p Allender
36 * took out function calls in NDEBUG mode
38 * 15 4/06/98 10:43a John
39 * Fixed bugs with inserting/deleting stages
41 * 14 4/03/98 12:39p Hoffoss
42 * Changed starting directory for browse buttons in several editors.
44 * 13 4/03/98 11:34a John
45 * Fixed the stuff I broke in Fred from the new breifing
47 * 12 3/17/98 2:06p Hoffoss
48 * Made enter key not close the dialog box (default windows behavior, even
49 * when no ok button. Talk about stupid. :)
51 * 11 2/09/98 9:25p Allender
52 * team v team support. multiple pools and breifings
54 * 10 2/04/98 4:32p Allender
55 * support for multiple briefings and debriefings. Changes to mission
56 * type (now a bitfield). Bitfield defs for multiplayer modes
58 * 9 1/02/98 3:29p Duncan
59 * Fixed bug with sexp tree freeing.
61 * 8 11/10/97 12:09p Johnson
62 * Fixed sexp free error in debriefing editor.
64 * 7 11/10/97 11:58a Johnson
65 * Added support to debriefing editor for "press cancel to go to reference
68 * 6 10/28/97 6:07p Jasen
69 * Added some debugging code to detect sexp leaks. Looks there are some I
70 * will need to investigate more.
72 * 5 10/27/97 2:06p Hoffoss
73 * Fixed editor to allow correct character limit for recommendation text.
75 * 4 10/14/97 12:06p Hoffoss
76 * Recoded debriefing editor to utilize new format.
78 * 3 10/14/97 10:35a Hoffoss
79 * Hacked the hell out of this file to allow Fred to compile for now.
80 * Next step is to fix it all.
82 * 2 7/08/97 2:03p Hoffoss
83 * Debriefing editor coded and implemented.
91 #include "debriefingeditordlg.h"
93 #include "missionbriefcommon.h"
100 static char THIS_FILE[] = __FILE__;
103 /////////////////////////////////////////////////////////////////////////////
104 // debriefing_editor_dlg dialog
106 debriefing_editor_dlg::debriefing_editor_dlg(CWnd* pParent /*=NULL*/)
107 : CDialog(debriefing_editor_dlg::IDD, pParent)
109 //{{AFX_DATA_INIT(debriefing_editor_dlg)
112 m_stage_title = _T("");
114 m_current_debriefing = -1;
120 select_sexp_node = -1;
123 void debriefing_editor_dlg::DoDataExchange(CDataExchange* pDX)
125 CDialog::DoDataExchange(pDX);
126 //{{AFX_DATA_MAP(debriefing_editor_dlg)
127 DDX_Control(pDX, IDC_TREE, m_tree);
128 DDX_Text(pDX, IDC_TEXT, m_text);
129 DDX_Text(pDX, IDC_VOICE, m_voice);
130 DDX_Text(pDX, IDC_STAGE_TITLE, m_stage_title);
131 DDX_Text(pDX, IDC_REC_TEXT, m_rec_text);
134 DDV_MaxChars(pDX, m_text, MAX_BRIEF_LEN - 1);
135 DDV_MaxChars(pDX, m_voice, MAX_FILENAME_LEN - 1);
136 DDV_MaxChars(pDX, m_rec_text, MAX_RECOMMENDATION_LEN - 1);
139 BEGIN_MESSAGE_MAP(debriefing_editor_dlg, CDialog)
140 //{{AFX_MSG_MAP(debriefing_editor_dlg)
141 ON_BN_CLICKED(IDC_NEXT, OnNext)
142 ON_BN_CLICKED(IDC_PREV, OnPrev)
143 ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
144 ON_BN_CLICKED(IDC_ADD_STAGE, OnAddStage)
145 ON_BN_CLICKED(IDC_DELETE_STAGE, OnDeleteStage)
146 ON_BN_CLICKED(IDC_INSERT_STAGE, OnInsertStage)
147 ON_NOTIFY(NM_RCLICK, IDC_TREE, OnRclickTree)
148 ON_NOTIFY(TVN_BEGINLABELEDIT, IDC_TREE, OnBeginlabeleditTree)
149 ON_NOTIFY(TVN_ENDLABELEDIT, IDC_TREE, OnEndlabeleditTree)
152 ON_BN_CLICKED(IDC_PLAY, OnPlay)
156 /////////////////////////////////////////////////////////////////////////////
157 // debriefing_editor_dlg message handlers
159 void debriefing_editor_dlg::OnInitMenu(CMenu* pMenu)
164 // disable any items we should disable
165 m = pMenu->GetSubMenu(0);
167 // uncheck all menu items
168 for (i = 0; i < Num_teams; i++ )
169 m->CheckMenuItem( i, MF_BYPOSITION | MF_UNCHECKED );
171 for ( i = Num_teams; i < MAX_TEAMS; i++ )
172 m->EnableMenuItem(i, MF_BYPOSITION | MF_GRAYED);
175 // put a check next to the currently selected item
176 m->CheckMenuItem(m_current_debriefing, MF_BYPOSITION | MF_CHECKED );
178 CDialog::OnInitMenu(pMenu);
181 BOOL debriefing_editor_dlg::OnInitDialog()
185 CDialog::OnInitDialog();
186 m_play_bm.LoadBitmap(IDB_PLAY);
187 ((CButton *) GetDlgItem(IDC_PLAY)) -> SetBitmap(m_play_bm);
189 m_current_debriefing = 0;
192 Debriefing = &Debriefings[m_current_debriefing];
194 m_tree.link_modified(&modified); // provide way to indicate trees are modified in dialog
195 n = m_tree.select_sexp_node = select_sexp_node;
196 select_sexp_node = -1;
198 for (i=0; i<Debriefing->num_stages; i++)
199 if (query_node_in_sexp(n, Debriefing->stages[i].formula))
202 if (i < Debriefing->num_stages) {
205 GetDlgItem(IDC_TREE) -> SetFocus();
206 m_tree.hilite_item(m_tree.select_sexp_node);
215 // hard coded stuff to deal with the multiple briefings per mission.
220 void debriefing_editor_dlg::update_data(int update)
222 int enable, save_debriefing;
225 save_debriefing = m_current_debriefing;
230 // based on the game type, enable the multiple briefings combo box (or disable it)
232 // set up the pointer to the briefing that we are editing
233 if ( save_debriefing != m_current_debriefing )
234 Debriefing = &Debriefings[save_debriefing];
236 Debriefing = &Debriefings[m_current_debriefing];
238 if (m_last_stage >= 0) {
239 ptr = &Debriefing->stages[m_last_stage];
240 if (ptr->formula >= 0)
241 free_sexp2(ptr->formula);
243 ptr->formula = m_tree.save_tree();
244 deconvert_multiline_string(ptr->new_text, m_text, MAX_DEBRIEF_LEN);
245 deconvert_multiline_string(ptr->new_recommendation_text, m_rec_text, MAX_RECOMMENDATION_LEN);
246 string_copy(ptr->voice, m_voice, MAX_FILENAME_LEN);
249 // now get new stage data
250 if ((m_cur_stage >= 0) && (m_cur_stage < Debriefing->num_stages)) {
251 ptr = &Debriefing->stages[m_cur_stage];
252 m_stage_title.Format("Stage %d of %d", m_cur_stage + 1, Debriefing->num_stages);
253 m_tree.load_tree(ptr->formula);
254 m_text = convert_multiline_string(ptr->new_text);
255 m_rec_text = convert_multiline_string(ptr->new_recommendation_text);
256 m_voice = ptr->voice;
260 m_stage_title = _T("No stages");
269 if (m_cur_stage == Debriefing->num_stages - 1)
270 GetDlgItem(IDC_NEXT) -> EnableWindow(FALSE);
272 GetDlgItem(IDC_NEXT) -> EnableWindow(enable);
275 GetDlgItem(IDC_PREV) -> EnableWindow(enable);
277 GetDlgItem(IDC_PREV) -> EnableWindow(FALSE);
279 if (Debriefing->num_stages >= MAX_DEBRIEF_STAGES)
280 GetDlgItem(IDC_ADD_STAGE) -> EnableWindow(FALSE);
282 GetDlgItem(IDC_ADD_STAGE) -> EnableWindow(TRUE);
284 if (Debriefing->num_stages) {
285 GetDlgItem(IDC_DELETE_STAGE) -> EnableWindow(enable);
286 GetDlgItem(IDC_INSERT_STAGE) -> EnableWindow(enable);
289 GetDlgItem(IDC_DELETE_STAGE) -> EnableWindow(FALSE);
290 GetDlgItem(IDC_INSERT_STAGE) -> EnableWindow(FALSE);
293 GetDlgItem(IDC_VOICE) -> EnableWindow(enable);
294 GetDlgItem(IDC_BROWSE) -> EnableWindow(enable);
295 GetDlgItem(IDC_TEXT) -> EnableWindow(enable);
296 GetDlgItem(IDC_REC_TEXT) -> EnableWindow(enable);
297 GetDlgItem(IDC_TREE) -> EnableWindow(enable);
299 m_last_stage = m_cur_stage;
303 count_free_sexp_nodes();
307 void debriefing_editor_dlg::OnNext()
313 void debriefing_editor_dlg::OnPrev()
319 void debriefing_editor_dlg::OnBrowse()
326 if (The_mission.game_type & MISSION_TYPE_TRAINING)
327 z = cfile_push_chdir(CF_TYPE_VOICE_TRAINING);
329 z = cfile_push_chdir(CF_TYPE_VOICE_DEBRIEFINGS);
331 CFileDialog dlg(TRUE, "wav", NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR,
332 "Wave Files (*.wav)|*.wav||");
334 if (dlg.DoModal() == IDOK) {
335 m_voice = dlg.GetFileName();
343 void debriefing_editor_dlg::OnAddStage()
347 if (Debriefing->num_stages >= MAX_DEBRIEF_STAGES)
350 m_cur_stage = i = Debriefing->num_stages++;
351 copy_stage(i - 1, i, 1);
355 void debriefing_editor_dlg::OnDeleteStage()
362 Assert(Debriefing->num_stages);
366 for (i=z+1; i<Debriefing->num_stages; i++) {
367 copy_stage(i, i - 1);
370 Debriefing->num_stages--;
372 if (m_cur_stage >= Debriefing->num_stages)
373 m_cur_stage = Debriefing->num_stages - 1;
378 void debriefing_editor_dlg::OnInsertStage()
382 if (Debriefing->num_stages >= MAX_DEBRIEF_STAGES)
385 if (!Debriefing->num_stages) {
393 for (i=Debriefing->num_stages; i>z; i--) {
394 copy_stage(i - 1, i);
397 Debriefing->num_stages++;
398 copy_stage(z, z + 1);
399 Debriefing->stages[z].formula = -1;
404 void debriefing_editor_dlg::copy_stage(int from, int to, int clear_formula)
406 if ((from < 0) || (from >= Debriefing->num_stages)) {
407 strcpy(Debriefing->stages[to].new_text, "<Text here>");
408 strcpy(Debriefing->stages[to].voice, "none.wav");
409 Debriefing->stages[to].formula = -1;
415 Debriefing->stages[to].formula = -1;
417 Debriefing->stages[to].formula = Debriefing->stages[from].formula;
419 strcpy( Debriefing->stages[to].new_text, Debriefing->stages[from].new_text );
420 strcpy( Debriefing->stages[to].voice, Debriefing->stages[from].voice );
421 strcpy( Debriefing->stages[to].new_recommendation_text, Debriefing->stages[from].new_recommendation_text );
424 void debriefing_editor_dlg::OnRclickTree(NMHDR* pNMHDR, LRESULT* pResult)
426 m_tree.right_clicked();
430 void debriefing_editor_dlg::OnBeginlabeleditTree(NMHDR* pNMHDR, LRESULT* pResult)
432 TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
434 if (m_tree.edit_label(pTVDispInfo->item.hItem) == 1) {
442 void debriefing_editor_dlg::OnEndlabeleditTree(NMHDR* pNMHDR, LRESULT* pResult)
444 TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
446 *pResult = m_tree.end_label_edit(pTVDispInfo->item.hItem, pTVDispInfo->item.pszText);
449 void debriefing_editor_dlg::OnClose()
456 void debriefing_editor_dlg::OnOK()
460 BOOL debriefing_editor_dlg::OnCommand(WPARAM wParam, LPARAM lParam)
464 // deal with figuring out menu stuff
466 if ( (id >= ID_TEAM_1) && (id < ID_TEAM_3) ) {
469 // set the current debriefing
470 m_current_debriefing = id - ID_TEAM_1;
472 // put user back at first stage for this team (or no current stage is there are none).
473 Debriefing = &Debriefings[m_current_debriefing];
474 if ( Debriefing->num_stages > 0 )
483 return CDialog::OnCommand(wParam, lParam);
486 BOOL debriefing_editor_dlg::DestroyWindow()
488 m_play_bm.DeleteObject();
489 return CDialog::DestroyWindow();
492 void debriefing_editor_dlg::OnPlay()
494 char path[MAX_PATH_LEN + 1];
495 GetDlgItem(IDC_VOICE)->GetWindowText(m_voice);
498 cf_find_file_location((char *) (LPCSTR) m_voice, CF_TYPE_ANY, path, &size, &offset );
500 PlaySound(path, NULL, SND_ASYNC | SND_FILENAME);