@@ -53,6 +53,35 @@ debriefing_editor_dlg::debriefing_editor_dlg(CWnd* pParent /*=NULL*/)
5353 select_sexp_node = -1 ;
5454}
5555
56+ void debriefing_editor_dlg::create ()
57+ {
58+ CDialog::Create (IDD);
59+ theApp.init_window (&Debriefing_wnd_data, this );
60+ }
61+
62+ void debriefing_editor_dlg::focus_sexp (int node)
63+ {
64+ int i, t, n;
65+
66+ n = m_tree.select_sexp_node = node;
67+ if (n == -1 )
68+ return ;
69+
70+ for (t = 0 ; t < Num_teams; t++) {
71+ for (i = 0 ; i < Debriefings[t].num_stages ; i++) {
72+ if (query_node_in_sexp (n, Debriefings[t].stages [i].formula )) {
73+ m_current_debriefing = t;
74+ Debriefing = &Debriefings[t];
75+ m_cur_stage = i;
76+ update_data ();
77+ GetDlgItem (IDC_TREE)->SetFocus ();
78+ m_tree.hilite_item (m_tree.select_sexp_node );
79+ return ;
80+ }
81+ }
82+ }
83+ }
84+
5685void debriefing_editor_dlg::DoDataExchange (CDataExchange* pDX)
5786{
5887 CDialog::DoDataExchange (pDX);
@@ -118,8 +147,6 @@ void debriefing_editor_dlg::OnInitMenu(CMenu* pMenu)
118147
119148BOOL debriefing_editor_dlg::OnInitDialog ()
120149{
121- int i, n;
122-
123150 CDialog::OnInitDialog ();
124151 m_play_bm.LoadBitmap (IDB_PLAY);
125152 ((CButton *) GetDlgItem (IDC_PLAY)) -> SetBitmap (m_play_bm);
@@ -151,28 +178,15 @@ BOOL debriefing_editor_dlg::OnInitDialog()
151178 m_debriefFail_music = Mission_music[SCORE_DEBRIEFING_FAILURE] + 1 ;
152179
153180 m_tree.link_modified (&modified); // provide way to indicate trees are modified in dialog
154- n = m_tree.select_sexp_node = select_sexp_node;
155- select_sexp_node = -1 ;
156- if (n != -1 ) {
157- for (i=0 ; i<Debriefing->num_stages ; i++)
158- if (query_node_in_sexp (n, Debriefing->stages [i].formula ))
159- break ;
160-
161- if (i < Debriefing->num_stages ) {
162- m_cur_stage = i;
163- update_data ();
164- GetDlgItem (IDC_TREE) -> SetFocus ();
165- m_tree.hilite_item (m_tree.select_sexp_node );
166- set_modified ();
167- return FALSE ;
168- }
169- }
170181
171182 CDialog::OnInitDialog ();
172183 update_data ();
173- set_modified ();
174184
175- // hard coded stuff to deal with the multiple briefings per mission.
185+ if (select_sexp_node != -1 ) {
186+ focus_sexp (select_sexp_node);
187+ select_sexp_node = -1 ;
188+ return FALSE ;
189+ }
176190
177191 return TRUE ;
178192}
@@ -201,10 +215,20 @@ void debriefing_editor_dlg::update_data(int update)
201215 free_sexp2 (ptr->formula );
202216
203217 ptr->formula = m_tree.save_tree ();
204- deconvert_multiline_string (ptr->text , m_text);
205- lcl_fred_replace_stuff (ptr->text );
206- deconvert_multiline_string (ptr->recommendation_text , m_rec_text);
207- lcl_fred_replace_stuff (ptr->recommendation_text );
218+
219+ SCP_string new_text, new_rec_text;
220+ deconvert_multiline_string (new_text, m_text);
221+ lcl_fred_replace_stuff (new_text);
222+ deconvert_multiline_string (new_rec_text, m_rec_text);
223+ lcl_fred_replace_stuff (new_rec_text);
224+
225+ if (modified || ptr->text != new_text || ptr->recommendation_text != new_rec_text
226+ || stricmp (ptr->voice , m_voice) != 0 )
227+ set_modified ();
228+
229+ modified = 0 ;
230+ ptr->text = new_text;
231+ ptr->recommendation_text = new_rec_text;
208232 string_copy (ptr->voice , m_voice, MAX_FILENAME_LEN - 1 );
209233 }
210234
@@ -425,7 +449,7 @@ void debriefing_editor_dlg::OnEndlabeleditTree(NMHDR* pNMHDR, LRESULT* pResult)
425449 *pResult = m_tree.end_label_edit (pTVDispInfo->item );
426450}
427451
428- void debriefing_editor_dlg::OnClose ()
452+ void debriefing_editor_dlg::OnClose ()
429453{
430454 audiostream_close_file (m_voice_id, 0 );
431455 m_voice_id = -1 ;
@@ -436,7 +460,10 @@ void debriefing_editor_dlg::OnClose()
436460 Mission_music[SCORE_DEBRIEFING_AVERAGE] = m_debriefAvg_music - 1 ;
437461 Mission_music[SCORE_DEBRIEFING_FAILURE] = m_debriefFail_music - 1 ;
438462
439- CDialog::OnClose ();
463+ theApp.record_window_data (&Debriefing_wnd_data, this );
464+ debriefing_editor_dlg *ptr = Debriefing_dialog;
465+ Debriefing_dialog = nullptr ;
466+ delete ptr;
440467
441468 FREDDoc_ptr->autosave (" debriefing editor" );
442469}
0 commit comments