Skip to content

Commit a56bded

Browse files
committed
convert debriefing editor to modeless; add focus_sexp(); fix bugs
Convert `debriefing_editor_dlg` from a modal stack-allocated dialog to a modeless heap-allocated dialog, matching the pattern of the briefing editor. Update FRED infrastructure accordingly. Add `focus_sexp(int node)` to `debriefing_editor_dlg`, mirroring the existing method in `briefing_editor_dlg`. Fix both `focus_sexp()` implementations to search all team debriefings/briefings instead of only the currently selected team, so nodes in non-zero teams are found correctly in TVT missions. Fix `debriefing set_modified()` calls to only set the flag if the debriefing data actually changes, rather than every time the editor was opened.
1 parent 05054f8 commit a56bded

8 files changed

Lines changed: 97 additions & 48 deletions

File tree

fred2/bgbitmapdlg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ void bg_bitmap_dlg::OnClose()
530530
// close window stuff
531531
theApp.record_window_data(&Bg_wnd_data, this);
532532
delete Bg_bitmap_dialog;
533-
Bg_bitmap_dialog = NULL;
533+
Bg_bitmap_dialog = nullptr;
534534

535535
FREDDoc_ptr->autosave("background editor");
536536
}

fred2/briefingeditordlg.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -253,19 +253,23 @@ void briefing_editor_dlg::create()
253253

254254
void briefing_editor_dlg::focus_sexp(int select_sexp_node)
255255
{
256-
int i, n;
256+
int i, t, n;
257257

258258
n = m_tree.select_sexp_node = select_sexp_node;
259-
if (n != -1) {
260-
for (i=0; i<Briefing->num_stages; i++)
261-
if (query_node_in_sexp(n, Briefing->stages[i].formula))
262-
break;
259+
if (n == -1)
260+
return;
263261

264-
if (i < Briefing->num_stages) {
265-
m_cur_stage = i;
266-
update_data();
267-
GetDlgItem(IDC_TREE) -> SetFocus();
268-
m_tree.hilite_item(m_tree.select_sexp_node);
262+
for (t = 0; t < Num_teams; t++) {
263+
for (i = 0; i < Briefings[t].num_stages; i++) {
264+
if (query_node_in_sexp(n, Briefings[t].stages[i].formula)) {
265+
m_current_briefing = t;
266+
Briefing = &Briefings[t];
267+
m_cur_stage = i;
268+
update_data();
269+
GetDlgItem(IDC_TREE)->SetFocus();
270+
m_tree.hilite_item(m_tree.select_sexp_node);
271+
return;
272+
}
269273
}
270274
}
271275
}
@@ -307,7 +311,7 @@ void briefing_editor_dlg::OnClose()
307311

308312
theApp.record_window_data(&Briefing_wnd_data, this);
309313
ptr = Briefing_dialog; // this juggling prevents a crash in certain situations
310-
Briefing_dialog = NULL;
314+
Briefing_dialog = nullptr;
311315
delete ptr;
312316

313317
FREDDoc_ptr->autosave("briefing editor");

fred2/debriefingeditordlg.cpp

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
5685
void debriefing_editor_dlg::DoDataExchange(CDataExchange* pDX)
5786
{
5887
CDialog::DoDataExchange(pDX);
@@ -118,8 +147,6 @@ void debriefing_editor_dlg::OnInitMenu(CMenu* pMenu)
118147

119148
BOOL 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
}

fred2/debriefingeditordlg.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
22
* Copyright (C) Volition, Inc. 1999. All rights reserved.
33
*
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
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
66
* source.
77
*
88
*/
99

10+
#pragma once
1011

1112
#include "mission/missionbriefcommon.h"
1213

@@ -18,6 +19,8 @@ class debriefing_editor_dlg : public CDialog
1819
// Construction
1920
public:
2021
void OnOK();
22+
void create();
23+
void focus_sexp(int node);
2124
void update_data(int update = 1);
2225
debriefing_editor_dlg(CWnd* pParent = NULL); // standard constructor
2326
int select_sexp_node;

fred2/fred.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ wing_editor Wing_editor_dialog;
121121
waypoint_path_dlg Waypoint_editor_dialog;
122122
jumpnode_dlg Jumpnode_editor_dialog;
123123
music_player_dlg Music_player_dialog;
124-
bg_bitmap_dlg* Bg_bitmap_dialog = NULL;
125-
briefing_editor_dlg* Briefing_dialog = NULL;
124+
bg_bitmap_dlg* Bg_bitmap_dialog = nullptr;
125+
briefing_editor_dlg* Briefing_dialog = nullptr;
126+
debriefing_editor_dlg* Debriefing_dialog = nullptr;
126127

127128
window_data Main_wnd_data;
128129
window_data Ship_wnd_data;
@@ -136,6 +137,7 @@ window_data Player_wnd_data;
136137
window_data Events_wnd_data;
137138
window_data Bg_wnd_data;
138139
window_data Briefing_wnd_data;
140+
window_data Debriefing_wnd_data;
139141
window_data Reinforcement_wnd_data;
140142
window_data Waypoint_wnd_data;
141143
window_data Jumpnode_wnd_data;

fred2/fred.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "BgBitmapDlg.h"
1919
#include "BriefingEditorDlg.h"
20+
#include "DebriefingEditorDlg.h"
2021
#include "resource.h"
2122
#include "ShipEditorDlg.h"
2223
#include "propdlg.h"
@@ -187,7 +188,8 @@ extern waypoint_path_dlg Waypoint_editor_dialog; //!< The waypoint editor ins
187188
extern jumpnode_dlg Jumpnode_editor_dialog; //!< The jumpnode editor instance
188189
extern music_player_dlg Music_player_dialog; //!< The music player instance
189190
extern bg_bitmap_dlg* Bg_bitmap_dialog; //!< The bitmap dialog instance
190-
extern briefing_editor_dlg* Briefing_dialog; //!< The briefing editor instance
191+
extern briefing_editor_dlg* Briefing_dialog; //!< The briefing editor instance
192+
extern debriefing_editor_dlg* Debriefing_dialog; //!< The debriefing editor instance
191193

192194
extern CFREDApp theApp; //!< The application instance
193195

@@ -203,6 +205,7 @@ extern window_data Player_wnd_data;
203205
extern window_data Events_wnd_data;
204206
extern window_data Bg_wnd_data;
205207
extern window_data Briefing_wnd_data;
208+
extern window_data Debriefing_wnd_data;
206209
extern window_data Reinforcement_wnd_data;
207210
extern window_data Waypoint_wnd_data;
208211
extern window_data Jumpnode_wnd_data;

fred2/fredview.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,9 +4213,14 @@ void CFREDView::OnEditorsBriefing()
42134213

42144214
void CFREDView::OnEditorsDebriefing()
42154215
{
4216-
debriefing_editor_dlg dlg;
4216+
if (!Debriefing_dialog) {
4217+
Debriefing_dialog = new debriefing_editor_dlg;
4218+
Debriefing_dialog->create();
4219+
}
42174220

4218-
dlg.DoModal();
4221+
Debriefing_dialog->SetWindowPos(&wndTop, 0, 0, 0, 0,
4222+
SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
4223+
Debriefing_dialog->ShowWindow(SW_RESTORE);
42194224
}
42204225

42214226
void CFREDView::OnSaveCamera()

fred2/management.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,10 +2283,15 @@ int sexp_reference_handler(int node, sexp_src source, int source_index, char *ms
22832283
}
22842284

22852285
case sexp_src::DEBRIEFING: {
2286-
debriefing_editor_dlg dlg;
2286+
if (!Debriefing_dialog) {
2287+
Debriefing_dialog = new debriefing_editor_dlg;
2288+
Debriefing_dialog->create();
2289+
}
22872290

2288-
dlg.select_sexp_node = node;
2289-
dlg.DoModal();
2291+
Debriefing_dialog->SetWindowPos(&CWnd::wndTop, 0, 0, 0, 0,
2292+
SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
2293+
Debriefing_dialog->ShowWindow(SW_RESTORE);
2294+
Debriefing_dialog->focus_sexp(node);
22902295
break;
22912296
}
22922297

0 commit comments

Comments
 (0)