2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
10 * $Logfile: /Freespace2/code/FRED2/CmdBrief.cpp $
15 * Command Briefing Editor
18 * Revision 1.3 2002/06/09 04:41:16 relnev
19 * added copyright header
21 * Revision 1.2 2002/05/07 03:16:44 theoddone33
22 * The Great Newline Fix
24 * Revision 1.1.1.1 2002/05/03 03:28:08 root
28 * 2 10/07/98 6:28p Dave
29 * Initial checkin. Renamed all relevant stuff to be Fred2 instead of
30 * Fred. Globalized mission and campaign file extensions. Removed Silent
31 * Threat specific code.
33 * 1 10/07/98 3:01p Dave
35 * 1 10/07/98 3:00p Dave
37 * 8 4/30/98 8:23p John
38 * Fixed some bugs with Fred caused by my new cfile code.
40 * 7 4/22/98 9:56a Sandeep
42 * 6 4/20/98 4:40p Hoffoss
43 * Added a button to 4 editors to play the chosen wave file.
45 * 5 4/03/98 12:39p Hoffoss
46 * Changed starting directory for browse buttons in several editors.
48 * 4 3/19/98 4:24p Hoffoss
49 * Added remaining support for command brief screen (ANI and WAVE file
52 * 3 3/06/98 2:36p Hoffoss
53 * Placed correct text size limits on edit boxes.
55 * 2 3/05/98 3:59p Hoffoss
56 * Added a bunch of new command brief stuff, and asteroid initialization
71 static char THIS_FILE[] = __FILE__;
74 /////////////////////////////////////////////////////////////////////////////
75 // cmd_brief_dlg dialog
77 cmd_brief_dlg::cmd_brief_dlg(CWnd* pParent /*=NULL*/)
78 : CDialog(cmd_brief_dlg::IDD, pParent)
80 //{{AFX_DATA_INIT(cmd_brief_dlg)
81 m_ani_filename = _T("");
83 m_stage_title = _T("");
84 m_wave_filename = _T("");
88 void cmd_brief_dlg::DoDataExchange(CDataExchange* pDX)
90 CDialog::DoDataExchange(pDX);
91 //{{AFX_DATA_MAP(cmd_brief_dlg)
92 DDX_Text(pDX, IDC_ANI_FILENAME, m_ani_filename);
93 DDX_Text(pDX, IDC_TEXT, m_text);
94 DDX_Text(pDX, IDC_STAGE_TITLE, m_stage_title);
95 DDX_Text(pDX, IDC_WAVE_FILENAME, m_wave_filename);
98 DDV_MaxChars(pDX, m_text, CMD_BRIEF_TEXT_MAX - 1);
99 DDV_MaxChars(pDX, m_ani_filename, MAX_FILENAME_LEN - 1);
100 DDV_MaxChars(pDX, m_wave_filename, MAX_FILENAME_LEN - 1);
103 BEGIN_MESSAGE_MAP(cmd_brief_dlg, CDialog)
104 //{{AFX_MSG_MAP(cmd_brief_dlg)
105 ON_BN_CLICKED(IDC_NEXT, OnNext)
106 ON_BN_CLICKED(IDC_PREV, OnPrev)
107 ON_BN_CLICKED(IDC_ADD_STAGE, OnAddStage)
108 ON_BN_CLICKED(IDC_INSERT_STAGE, OnInsertStage)
109 ON_BN_CLICKED(IDC_DELETE_STAGE, OnDeleteStage)
110 ON_BN_CLICKED(IDC_BROWSE_ANI, OnBrowseAni)
111 ON_BN_CLICKED(IDC_BROWSE_WAVE, OnBrowseWave)
112 ON_BN_CLICKED(IDC_PLAY, OnPlay)
116 /////////////////////////////////////////////////////////////////////////////
117 // cmd_brief_dlg message handlers
119 BOOL cmd_brief_dlg::OnInitDialog()
121 Cur_cmd_brief = Cmd_briefs; // default to first cmd briefing
123 last_cmd_brief = NULL;
125 CDialog::OnInitDialog();
126 m_play_bm.LoadBitmap(IDB_PLAY);
127 ((CButton *) GetDlgItem(IDC_PLAY)) -> SetBitmap(m_play_bm);
133 void cmd_brief_dlg::update_data(int update)
140 // save previously editing data before we load over it.
141 if (last_cmd_brief && m_last_stage >= 0 && m_last_stage < last_cmd_brief->num_stages) {
142 char buf[CMD_BRIEF_TEXT_MAX];
144 if (last_cmd_brief->stage[m_last_stage].text)
145 free(last_cmd_brief->stage[m_last_stage].text);
147 deconvert_multiline_string(buf, m_text, CMD_BRIEF_TEXT_MAX);
148 last_cmd_brief->stage[m_last_stage].text = strdup(buf);
149 string_copy(last_cmd_brief->stage[m_last_stage].ani_filename, m_ani_filename, MAX_FILENAME_LEN);
150 string_copy(last_cmd_brief->stage[m_last_stage].wave_filename, m_wave_filename, MAX_FILENAME_LEN);
153 // load data of new stage into dialog
154 if (Cur_cmd_brief && Cur_cmd_brief->num_stages > 0) {
155 if (m_cur_stage < 0 || m_cur_stage >= Cur_cmd_brief->num_stages)
158 m_stage_title.Format("Stage %d of %d", m_cur_stage + 1, Cur_cmd_brief->num_stages);
159 m_text = convert_multiline_string(Cur_cmd_brief->stage[m_cur_stage].text);
160 m_ani_filename = Cur_cmd_brief->stage[m_cur_stage].ani_filename;
161 m_wave_filename = Cur_cmd_brief->stage[m_cur_stage].wave_filename;
165 m_stage_title = _T("No stages");
167 m_ani_filename = _T("");
168 m_wave_filename = _T("");
173 if (m_cur_stage < Cur_cmd_brief->num_stages - 1)
174 GetDlgItem(IDC_NEXT) -> EnableWindow(enable);
176 GetDlgItem(IDC_NEXT) -> EnableWindow(FALSE);
179 GetDlgItem(IDC_PREV) -> EnableWindow(enable);
181 GetDlgItem(IDC_PREV) -> EnableWindow(FALSE);
183 if (Cur_cmd_brief->num_stages >= CMD_BRIEF_STAGES_MAX)
184 GetDlgItem(IDC_ADD_STAGE) -> EnableWindow(FALSE);
186 GetDlgItem(IDC_ADD_STAGE) -> EnableWindow(TRUE);
188 if (Cur_cmd_brief->num_stages) {
189 GetDlgItem(IDC_DELETE_STAGE) -> EnableWindow(enable);
190 GetDlgItem(IDC_INSERT_STAGE) -> EnableWindow(enable);
193 GetDlgItem(IDC_DELETE_STAGE) -> EnableWindow(FALSE);
194 GetDlgItem(IDC_INSERT_STAGE) -> EnableWindow(FALSE);
197 GetDlgItem(IDC_WAVE_FILENAME) -> EnableWindow(enable);
198 GetDlgItem(IDC_ANI_FILENAME) -> EnableWindow(enable);
199 GetDlgItem(IDC_BROWSE_ANI) -> EnableWindow(enable);
200 GetDlgItem(IDC_BROWSE_WAVE) -> EnableWindow(enable);
201 GetDlgItem(IDC_TEXT) -> EnableWindow(enable);
205 last_cmd_brief = Cur_cmd_brief;
206 m_last_stage = m_cur_stage;
209 void cmd_brief_dlg::OnOK()
215 void cmd_brief_dlg::OnNext()
221 void cmd_brief_dlg::OnPrev()
227 void cmd_brief_dlg::OnAddStage()
231 if (Cur_cmd_brief->num_stages >= CMD_BRIEF_STAGES_MAX)
234 m_cur_stage = i = Cur_cmd_brief->num_stages++;
235 copy_stage(i - 1, i);
239 void cmd_brief_dlg::OnInsertStage()
243 if (Cur_cmd_brief->num_stages >= CMD_BRIEF_STAGES_MAX)
246 if (!Cur_cmd_brief->num_stages) {
254 for (i=Cur_cmd_brief->num_stages; i>z; i--)
255 Cur_cmd_brief->stage[i] = Cur_cmd_brief->stage[i - 1];
257 Cur_cmd_brief->num_stages++;
258 copy_stage(z, z + 1);
263 void cmd_brief_dlg::OnDeleteStage()
270 Assert(Cur_cmd_brief->num_stages);
274 if (Cur_cmd_brief->stage[z].text)
275 free(Cur_cmd_brief->stage[z].text);
277 for (i=z+1; i<Cur_cmd_brief->num_stages; i++)
278 Cur_cmd_brief->stage[i-1] = Cur_cmd_brief->stage[i];
280 Cur_cmd_brief->num_stages--;
282 if (m_cur_stage >= Cur_cmd_brief->num_stages)
283 m_cur_stage = Cur_cmd_brief->num_stages - 1;
288 void cmd_brief_dlg::copy_stage(int from, int to)
290 if ((from < 0) || (from >= Cur_cmd_brief->num_stages)) {
291 Cur_cmd_brief->stage[to].text = strdup("<Text here>");
292 strcpy(Cur_cmd_brief->stage[to].ani_filename, "<default>");
293 strcpy(Cur_cmd_brief->stage[to].wave_filename, "none");
297 Cur_cmd_brief->stage[to] = Cur_cmd_brief->stage[from];
298 Cur_cmd_brief->stage[to].text = strdup(Cur_cmd_brief->stage[from].text);
301 void cmd_brief_dlg::OnBrowseAni()
307 z = cfile_push_chdir(CF_TYPE_INTERFACE);
308 CFileDialog dlg(TRUE, "ani", NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR,
309 "Ani Files (*.ani)|*.ani|Avi Files (*.avi)|*.avi|Both (*.ani, *.avi)|*.ani;*.avi||");
311 if (dlg.DoModal() == IDOK) {
312 m_ani_filename = dlg.GetFileName();
320 void cmd_brief_dlg::OnBrowseWave()
326 z = cfile_push_chdir(CF_TYPE_VOICE_CMD_BRIEF);
327 CFileDialog dlg(TRUE, "wav", NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR,
328 "Wave Files (*.wav)|*.wav||");
330 if (dlg.DoModal() == IDOK) {
331 m_wave_filename = dlg.GetFileName();
339 BOOL cmd_brief_dlg::DestroyWindow()
341 m_play_bm.DeleteObject();
342 return CDialog::DestroyWindow();
345 void cmd_brief_dlg::OnPlay()
347 char path[MAX_PATH_LEN + 1];
348 GetDlgItem(IDC_WAVE_FILENAME)->GetWindowText(m_wave_filename);
351 cf_find_file_location((char *) (LPCSTR) m_wave_filename, CF_TYPE_ANY, path, &size, &offset );
353 PlaySound(path, NULL, SND_ASYNC | SND_FILENAME);