From a56bded91946aa5b74e6ac9ee79db33aa0c671d2 Mon Sep 17 00:00:00 2001 From: Goober5000 Date: Sat, 21 Mar 2026 01:23:01 -0400 Subject: [PATCH] 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. --- fred2/bgbitmapdlg.cpp | 2 +- fred2/briefingeditordlg.cpp | 26 +++++++----- fred2/debriefingeditordlg.cpp | 79 +++++++++++++++++++++++------------ fred2/debriefingeditordlg.h | 7 +++- fred2/fred.cpp | 6 ++- fred2/fred.h | 5 ++- fred2/fredview.cpp | 9 +++- fred2/management.cpp | 11 +++-- 8 files changed, 97 insertions(+), 48 deletions(-) diff --git a/fred2/bgbitmapdlg.cpp b/fred2/bgbitmapdlg.cpp index bcf1df20c37..0f64c8627df 100644 --- a/fred2/bgbitmapdlg.cpp +++ b/fred2/bgbitmapdlg.cpp @@ -530,7 +530,7 @@ void bg_bitmap_dlg::OnClose() // close window stuff theApp.record_window_data(&Bg_wnd_data, this); delete Bg_bitmap_dialog; - Bg_bitmap_dialog = NULL; + Bg_bitmap_dialog = nullptr; FREDDoc_ptr->autosave("background editor"); } diff --git a/fred2/briefingeditordlg.cpp b/fred2/briefingeditordlg.cpp index 1f62d1c798f..bbcae42c5ff 100644 --- a/fred2/briefingeditordlg.cpp +++ b/fred2/briefingeditordlg.cpp @@ -253,19 +253,23 @@ void briefing_editor_dlg::create() void briefing_editor_dlg::focus_sexp(int select_sexp_node) { - int i, n; + int i, t, n; n = m_tree.select_sexp_node = select_sexp_node; - if (n != -1) { - for (i=0; inum_stages; i++) - if (query_node_in_sexp(n, Briefing->stages[i].formula)) - break; + if (n == -1) + return; - if (i < Briefing->num_stages) { - m_cur_stage = i; - update_data(); - GetDlgItem(IDC_TREE) -> SetFocus(); - m_tree.hilite_item(m_tree.select_sexp_node); + for (t = 0; t < Num_teams; t++) { + for (i = 0; i < Briefings[t].num_stages; i++) { + if (query_node_in_sexp(n, Briefings[t].stages[i].formula)) { + m_current_briefing = t; + Briefing = &Briefings[t]; + m_cur_stage = i; + update_data(); + GetDlgItem(IDC_TREE)->SetFocus(); + m_tree.hilite_item(m_tree.select_sexp_node); + return; + } } } } @@ -307,7 +311,7 @@ void briefing_editor_dlg::OnClose() theApp.record_window_data(&Briefing_wnd_data, this); ptr = Briefing_dialog; // this juggling prevents a crash in certain situations - Briefing_dialog = NULL; + Briefing_dialog = nullptr; delete ptr; FREDDoc_ptr->autosave("briefing editor"); diff --git a/fred2/debriefingeditordlg.cpp b/fred2/debriefingeditordlg.cpp index 33471699ebd..d9dfea4e6a9 100644 --- a/fred2/debriefingeditordlg.cpp +++ b/fred2/debriefingeditordlg.cpp @@ -53,6 +53,35 @@ debriefing_editor_dlg::debriefing_editor_dlg(CWnd* pParent /*=NULL*/) select_sexp_node = -1; } +void debriefing_editor_dlg::create() +{ + CDialog::Create(IDD); + theApp.init_window(&Debriefing_wnd_data, this); +} + +void debriefing_editor_dlg::focus_sexp(int node) +{ + int i, t, n; + + n = m_tree.select_sexp_node = node; + if (n == -1) + return; + + for (t = 0; t < Num_teams; t++) { + for (i = 0; i < Debriefings[t].num_stages; i++) { + if (query_node_in_sexp(n, Debriefings[t].stages[i].formula)) { + m_current_debriefing = t; + Debriefing = &Debriefings[t]; + m_cur_stage = i; + update_data(); + GetDlgItem(IDC_TREE)->SetFocus(); + m_tree.hilite_item(m_tree.select_sexp_node); + return; + } + } + } +} + void debriefing_editor_dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); @@ -118,8 +147,6 @@ void debriefing_editor_dlg::OnInitMenu(CMenu* pMenu) BOOL debriefing_editor_dlg::OnInitDialog() { - int i, n; - CDialog::OnInitDialog(); m_play_bm.LoadBitmap(IDB_PLAY); ((CButton *) GetDlgItem(IDC_PLAY)) -> SetBitmap(m_play_bm); @@ -151,28 +178,15 @@ BOOL debriefing_editor_dlg::OnInitDialog() m_debriefFail_music = Mission_music[SCORE_DEBRIEFING_FAILURE] + 1; m_tree.link_modified(&modified); // provide way to indicate trees are modified in dialog - n = m_tree.select_sexp_node = select_sexp_node; - select_sexp_node = -1; - if (n != -1) { - for (i=0; inum_stages; i++) - if (query_node_in_sexp(n, Debriefing->stages[i].formula)) - break; - - if (i < Debriefing->num_stages) { - m_cur_stage = i; - update_data(); - GetDlgItem(IDC_TREE) -> SetFocus(); - m_tree.hilite_item(m_tree.select_sexp_node); - set_modified(); - return FALSE; - } - } CDialog::OnInitDialog(); update_data(); - set_modified(); - // hard coded stuff to deal with the multiple briefings per mission. + if (select_sexp_node != -1) { + focus_sexp(select_sexp_node); + select_sexp_node = -1; + return FALSE; + } return TRUE; } @@ -201,10 +215,20 @@ void debriefing_editor_dlg::update_data(int update) free_sexp2(ptr->formula); ptr->formula = m_tree.save_tree(); - deconvert_multiline_string(ptr->text, m_text); - lcl_fred_replace_stuff(ptr->text); - deconvert_multiline_string(ptr->recommendation_text, m_rec_text); - lcl_fred_replace_stuff(ptr->recommendation_text); + + SCP_string new_text, new_rec_text; + deconvert_multiline_string(new_text, m_text); + lcl_fred_replace_stuff(new_text); + deconvert_multiline_string(new_rec_text, m_rec_text); + lcl_fred_replace_stuff(new_rec_text); + + if (modified || ptr->text != new_text || ptr->recommendation_text != new_rec_text + || stricmp(ptr->voice, m_voice) != 0) + set_modified(); + + modified = 0; + ptr->text = new_text; + ptr->recommendation_text = new_rec_text; string_copy(ptr->voice, m_voice, MAX_FILENAME_LEN - 1); } @@ -425,7 +449,7 @@ void debriefing_editor_dlg::OnEndlabeleditTree(NMHDR* pNMHDR, LRESULT* pResult) *pResult = m_tree.end_label_edit(pTVDispInfo->item); } -void debriefing_editor_dlg::OnClose() +void debriefing_editor_dlg::OnClose() { audiostream_close_file(m_voice_id, 0); m_voice_id = -1; @@ -436,7 +460,10 @@ void debriefing_editor_dlg::OnClose() Mission_music[SCORE_DEBRIEFING_AVERAGE] = m_debriefAvg_music - 1; Mission_music[SCORE_DEBRIEFING_FAILURE] = m_debriefFail_music - 1; - CDialog::OnClose(); + theApp.record_window_data(&Debriefing_wnd_data, this); + debriefing_editor_dlg *ptr = Debriefing_dialog; + Debriefing_dialog = nullptr; + delete ptr; FREDDoc_ptr->autosave("debriefing editor"); } diff --git a/fred2/debriefingeditordlg.h b/fred2/debriefingeditordlg.h index 020ec382915..949d580bacf 100644 --- a/fred2/debriefingeditordlg.h +++ b/fred2/debriefingeditordlg.h @@ -1,12 +1,13 @@ /* * Copyright (C) Volition, Inc. 1999. All rights reserved. * - * All source code herein is the property of Volition, Inc. You may not sell - * or otherwise commercially exploit the source or things you created based on the + * All source code herein is the property of Volition, Inc. You may not sell + * or otherwise commercially exploit the source or things you created based on the * source. * */ +#pragma once #include "mission/missionbriefcommon.h" @@ -18,6 +19,8 @@ class debriefing_editor_dlg : public CDialog // Construction public: void OnOK(); + void create(); + void focus_sexp(int node); void update_data(int update = 1); debriefing_editor_dlg(CWnd* pParent = NULL); // standard constructor int select_sexp_node; diff --git a/fred2/fred.cpp b/fred2/fred.cpp index 9b2d906928b..e176125c30f 100644 --- a/fred2/fred.cpp +++ b/fred2/fred.cpp @@ -121,8 +121,9 @@ wing_editor Wing_editor_dialog; waypoint_path_dlg Waypoint_editor_dialog; jumpnode_dlg Jumpnode_editor_dialog; music_player_dlg Music_player_dialog; -bg_bitmap_dlg* Bg_bitmap_dialog = NULL; -briefing_editor_dlg* Briefing_dialog = NULL; +bg_bitmap_dlg* Bg_bitmap_dialog = nullptr; +briefing_editor_dlg* Briefing_dialog = nullptr; +debriefing_editor_dlg* Debriefing_dialog = nullptr; window_data Main_wnd_data; window_data Ship_wnd_data; @@ -136,6 +137,7 @@ window_data Player_wnd_data; window_data Events_wnd_data; window_data Bg_wnd_data; window_data Briefing_wnd_data; +window_data Debriefing_wnd_data; window_data Reinforcement_wnd_data; window_data Waypoint_wnd_data; window_data Jumpnode_wnd_data; diff --git a/fred2/fred.h b/fred2/fred.h index 99e240c4932..d7e90184f09 100644 --- a/fred2/fred.h +++ b/fred2/fred.h @@ -17,6 +17,7 @@ #include "BgBitmapDlg.h" #include "BriefingEditorDlg.h" +#include "DebriefingEditorDlg.h" #include "resource.h" #include "ShipEditorDlg.h" #include "propdlg.h" @@ -187,7 +188,8 @@ extern waypoint_path_dlg Waypoint_editor_dialog; //!< The waypoint editor ins extern jumpnode_dlg Jumpnode_editor_dialog; //!< The jumpnode editor instance extern music_player_dlg Music_player_dialog; //!< The music player instance extern bg_bitmap_dlg* Bg_bitmap_dialog; //!< The bitmap dialog instance -extern briefing_editor_dlg* Briefing_dialog; //!< The briefing editor instance +extern briefing_editor_dlg* Briefing_dialog; //!< The briefing editor instance +extern debriefing_editor_dlg* Debriefing_dialog; //!< The debriefing editor instance extern CFREDApp theApp; //!< The application instance @@ -203,6 +205,7 @@ extern window_data Player_wnd_data; extern window_data Events_wnd_data; extern window_data Bg_wnd_data; extern window_data Briefing_wnd_data; +extern window_data Debriefing_wnd_data; extern window_data Reinforcement_wnd_data; extern window_data Waypoint_wnd_data; extern window_data Jumpnode_wnd_data; diff --git a/fred2/fredview.cpp b/fred2/fredview.cpp index 352a98e86e5..77495c11db5 100644 --- a/fred2/fredview.cpp +++ b/fred2/fredview.cpp @@ -4213,9 +4213,14 @@ void CFREDView::OnEditorsBriefing() void CFREDView::OnEditorsDebriefing() { - debriefing_editor_dlg dlg; + if (!Debriefing_dialog) { + Debriefing_dialog = new debriefing_editor_dlg; + Debriefing_dialog->create(); + } - dlg.DoModal(); + Debriefing_dialog->SetWindowPos(&wndTop, 0, 0, 0, 0, + SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE); + Debriefing_dialog->ShowWindow(SW_RESTORE); } void CFREDView::OnSaveCamera() diff --git a/fred2/management.cpp b/fred2/management.cpp index 1d8e7179cd2..befffd80a44 100644 --- a/fred2/management.cpp +++ b/fred2/management.cpp @@ -2283,10 +2283,15 @@ int sexp_reference_handler(int node, sexp_src source, int source_index, char *ms } case sexp_src::DEBRIEFING: { - debriefing_editor_dlg dlg; + if (!Debriefing_dialog) { + Debriefing_dialog = new debriefing_editor_dlg; + Debriefing_dialog->create(); + } - dlg.select_sexp_node = node; - dlg.DoModal(); + Debriefing_dialog->SetWindowPos(&CWnd::wndTop, 0, 0, 0, 0, + SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE); + Debriefing_dialog->ShowWindow(SW_RESTORE); + Debriefing_dialog->focus_sexp(node); break; }