| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | // BriefButtonEdit.cpp : implementation file |
| 20 | // |
| 21 | |
| 22 | #include "stdafx.h" |
| 23 | #include "editor.h" |
| 24 | #include "BriefButtonEdit.h" |
| 25 | #include "CFile.h" |
| 26 | #include "BriefMissionFlagsDlg.h" |
| 27 | #include "briefedit.h" |
| 28 | |
| 29 | #ifdef _DEBUG |
| 30 | #define new DEBUG_NEW |
| 31 | #undef THIS_FILE |
| 32 | static char THIS_FILE[] = __FILE__; |
| 33 | #endif |
| 34 | |
| 35 | ///////////////////////////////////////////////////////////////////////////// |
| 36 | // CBriefButtonEdit dialog |
| 37 | |
| 38 | CBriefButtonEdit::CBriefButtonEdit(TCBUTTONDESC *d, int id, CWnd *pParent /*=NULL*/) |
| 39 | : CDialog(CBriefButtonEdit::IDD, pParent) { |
| 40 | //{{AFX_DATA_INIT(CBriefButtonEdit) |
| 41 | m_sFilename = _T(""); |
| 42 | m_sFlashFilename = _T(""); |
| 43 | m_bFlasher = FALSE; |
| 44 | m_fFlashStart = 0.0f; |
| 45 | m_bGlow = FALSE; |
| 46 | m_iID = 0; |
| 47 | m_iPID = 0; |
| 48 | m_iSID = 0; |
| 49 | m_iClickType = -1; |
| 50 | m_iButtonType = -1; |
| 51 | m_sDesc = _T(""); |
| 52 | m_sFilenameFocus = _T(""); |
| 53 | m_sFlashFilenameFocus = _T(""); |
| 54 | m_iX = 0; |
| 55 | m_iY = 0; |
| 56 | m_ScreenToJump = 0; |
| 57 | //}}AFX_DATA_INIT |
| 58 | |
| 59 | m_iID = id; |
| 60 | |
| 61 | memset(&desc, 0, sizeof(TCBUTTONDESC)); |
| 62 | |
| 63 | desc.mission_mask_set = 0; |
| 64 | desc.mission_mask_unset = 0; |
| 65 | |
| 66 | if (d) { |
| 67 | // initialize to what was passed in |
| 68 | strcpy(desc.filename, d->filename); |
| 69 | strcpy(desc.filename_focus, d->filename_focus); |
| 70 | if (d->flasher) { |
| 71 | desc.flasher = true; |
| 72 | desc.flash_time = d->flash_time; |
| 73 | strcpy(desc.flash_filename, d->flash_filename); |
| 74 | strcpy(desc.flash_filename_focus, d->flash_filename_focus); |
| 75 | } |
| 76 | desc.sibling_id = d->sibling_id; |
| 77 | desc.parent_id = d->parent_id; |
| 78 | desc.x = d->x; |
| 79 | desc.y = d->y; |
| 80 | desc.w = d->w; |
| 81 | desc.h = d->h; |
| 82 | desc.osflags = d->osflags; |
| 83 | desc.button_type = d->button_type; |
| 84 | desc.click_type = d->click_type; |
| 85 | desc.mission_mask_set = d->mission_mask_set; |
| 86 | desc.mission_mask_unset = d->mission_mask_unset; |
| 87 | desc.jump_page = d->jump_page; |
| 88 | |
| 89 | } else { |
| 90 | // set all defaults |
| 91 | desc.button_type = BUTT_NEXTPAGE; |
| 92 | desc.click_type = CLICKTYPE_CLICKDOWN; |
| 93 | } |
| 94 | |
| 95 | m_ScreenToJump = 0; |
| 96 | switch (desc.button_type) { |
| 97 | case BUTT_UPARROW: |
| 98 | m_iButtonType = 0; |
| 99 | break; |
| 100 | case BUTT_DOWNARROW: |
| 101 | m_iButtonType = 1; |
| 102 | break; |
| 103 | case BUTT_NEXTPAGE: |
| 104 | m_iButtonType = 2; |
| 105 | break; |
| 106 | case BUTT_PREVPAGE: |
| 107 | m_iButtonType = 3; |
| 108 | break; |
| 109 | case BUTT_QUIT: |
| 110 | m_iButtonType = 4; |
| 111 | break; |
| 112 | case BUTT_JUMP: |
| 113 | m_iButtonType = 5; |
| 114 | m_ScreenToJump = desc.jump_page; |
| 115 | break; |
| 116 | default: |
| 117 | m_iButtonType = 0; |
| 118 | break; |
| 119 | } |
| 120 | |
| 121 | switch (desc.click_type) { |
| 122 | case CLICKTYPE_CLICKUP: |
| 123 | m_iClickType = 0; |
| 124 | break; |
| 125 | case CLICKTYPE_CLICKDOWN: |
| 126 | m_iClickType = 1; |
| 127 | break; |
| 128 | case CLICKTYPE_DOWN: |
| 129 | m_iClickType = 2; |
| 130 | break; |
| 131 | default: |
| 132 | m_iClickType = 0; |
| 133 | break; |
| 134 | } |
| 135 | |
| 136 | m_sFilename = desc.filename; |
| 137 | m_sFilenameFocus = desc.filename_focus; |
| 138 | if (desc.flasher) { |
| 139 | m_sFlashFilename = desc.flash_filename; |
| 140 | m_sFlashFilenameFocus = desc.flash_filename_focus; |
| 141 | } |
| 142 | if (desc.osflags & OBF_GLOW) |
| 143 | m_bGlow = true; |
| 144 | else |
| 145 | m_bGlow = false; |
| 146 | if (desc.osflags & OBF_FLASH) { |
| 147 | m_bFlasher = true; |
| 148 | m_fFlashStart = desc.flash_time; |
| 149 | } else { |
| 150 | m_bFlasher = false; |
| 151 | m_fFlashStart = 0; |
| 152 | } |
| 153 | |
| 154 | m_iPID = desc.parent_id; |
| 155 | m_iSID = desc.sibling_id; |
| 156 | m_iX = desc.x; |
| 157 | m_iY = desc.y; |
| 158 | } |
| 159 | |
| 160 | void CBriefButtonEdit::DoDataExchange(CDataExchange *pDX) { |
| 161 | CDialog::DoDataExchange(pDX); |
| 162 | //{{AFX_DATA_MAP(CBriefButtonEdit) |
| 163 | DDX_Text(pDX, IDC_BRIEF_BT_FILENAME, m_sFilename); |
| 164 | DDX_Text(pDX, IDC_BRIEF_BT_FLASH_FILENAME, m_sFlashFilename); |
| 165 | DDX_Check(pDX, IDC_BRIEF_BT_FLASHER, m_bFlasher); |
| 166 | DDX_Text(pDX, IDC_BRIEF_BT_FLASHSTART, m_fFlashStart); |
| 167 | DDV_MinMaxFloat(pDX, m_fFlashStart, 0.f, 99999.f); |
| 168 | DDX_Check(pDX, IDC_BRIEF_BT_GLOW, m_bGlow); |
| 169 | DDX_Text(pDX, IDC_BRIEF_BT_ID, m_iID); |
| 170 | DDX_Text(pDX, IDC_BRIEF_BT_PID, m_iPID); |
| 171 | DDX_Text(pDX, IDC_BRIEF_BT_SID, m_iSID); |
| 172 | DDX_Radio(pDX, IDC_BRIEF_BT_MOUSEUP, m_iClickType); |
| 173 | DDX_Radio(pDX, IDC_BRIEF_BT_SCROLLUP, m_iButtonType); |
| 174 | DDX_Text(pDX, IDC_BRIEF_BT_DESC, m_sDesc); |
| 175 | DDX_Text(pDX, IDC_BRIEF_BT_FILENAME_FOCUS, m_sFilenameFocus); |
| 176 | DDX_Text(pDX, IDC_BRIEF_BT_FLASH_FILENAME_FOCUS, m_sFlashFilenameFocus); |
| 177 | DDX_Text(pDX, IDC_BRIEF_BT_X, m_iX); |
| 178 | DDX_Text(pDX, IDC_BRIEF_BT_Y, m_iY); |
| 179 | DDX_Text(pDX, IDC_BRIEF_BT_JUMP_SCREEN, m_ScreenToJump); |
| 180 | DDV_MinMaxInt(pDX, m_ScreenToJump, 0, 64); |
| 181 | //}}AFX_DATA_MAP |
| 182 | } |
| 183 | |
| 184 | BEGIN_MESSAGE_MAP(CBriefButtonEdit, CDialog) |
| 185 | //{{AFX_MSG_MAP(CBriefButtonEdit) |
| 186 | ON_BN_CLICKED(IDC_BRIEF_BT_CHOOSE, OnBriefBtChoose) |
| 187 | ON_BN_CLICKED(IDC_BRIEF_BT_FLASH_CHOOSE, OnBriefBtFlashChoose) |
| 188 | ON_BN_CLICKED(IDC_BRIEF_BT_FLASHER, OnBriefBtFlasher) |
| 189 | ON_BN_CLICKED(IDC_BRIEF_BT_GLOW, OnBriefBtGlow) |
| 190 | ON_BN_CLICKED(IDC_BRIEF_BT_CHOOSE_FOCUS, OnBriefBtChooseFocus) |
| 191 | ON_BN_CLICKED(IDC_BRIEF_BT_FLASH_CHOOSE_FOCUS, OnBriefBtFlashChooseFocus) |
| 192 | ON_BN_CLICKED(IDC_MISSIONFLAGS, OnMissionflags) |
| 193 | ON_BN_CLICKED(IDC_BRIEF_BT_JUMP, OnBriefBtJump) |
| 194 | ON_BN_CLICKED(IDC_BRIEF_BT_NEXTSCREEN, OnBriefBtNextscreen) |
| 195 | ON_BN_CLICKED(IDC_BRIEF_BT_PREVSCREEN, OnBriefBtPrevscreen) |
| 196 | ON_BN_CLICKED(IDC_BRIEF_BT_QUIT, OnBriefBtQuit) |
| 197 | ON_BN_CLICKED(IDC_BRIEF_BT_SCROLLDOWN, OnBriefBtScrolldown) |
| 198 | ON_BN_CLICKED(IDC_BRIEF_BT_SCROLLUP, OnBriefBtScrollup) |
| 199 | //}}AFX_MSG_MAP |
| 200 | END_MESSAGE_MAP() |
| 201 | |
| 202 | ///////////////////////////////////////////////////////////////////////////// |
| 203 | // CBriefButtonEdit message handlers |
| 204 | |
| 205 | void CBriefButtonEdit::OnBriefBtChoose() { |
| 206 | UpdateData(true); |
| 207 | char szFilter[] = "Outrage Graphic Files (*.ogf)|*.ogf|32bit Uncompressed Targa (*.tga)|*.tga|PCX (*.pcx)|*.pcx|All " |
| 208 | "Files (*.*)|*.*||"; |
| 209 | CFileDialog dlg(true, NULL, NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, szFilter); |
| 210 | |
| 211 | if (dlg.DoModal() == IDOK) { |
| 212 | // handle |
| 213 | m_sFilename = dlg.GetFileName(); |
| 214 | UpdateData(false); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | void CBriefButtonEdit::OnBriefBtFlashChoose() { |
| 219 | UpdateData(true); |
| 220 | char szFilter[] = "Outrage Graphic Files (*.ogf)|*.ogf|32bit Uncompressed Targa (*.tga)|*.tga|PCX (*.pcx)|*.pcx|All " |
| 221 | "Files (*.*)|*.*||"; |
| 222 | CFileDialog dlg(true, NULL, NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, szFilter); |
| 223 | |
| 224 | if (dlg.DoModal() == IDOK) { |
| 225 | // handle |
| 226 | m_sFlashFilename = dlg.GetFileName(); |
| 227 | UpdateData(false); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | void CBriefButtonEdit::OnOK() { |
| 232 | if (!VerifyData()) |
| 233 | return; |
| 234 | |
| 235 | desc.osflags = 0; |
| 236 | if (m_bFlasher || m_bGlow) { |
| 237 | desc.flasher = true; |
| 238 | if (m_bFlasher) |
| 239 | desc.osflags |= OBF_FLASH; |
| 240 | if (m_bGlow) |
| 241 | desc.osflags |= OBF_GLOW; |
| 242 | |
| 243 | } else { |
| 244 | desc.flasher = false; |
| 245 | } |
| 246 | |
| 247 | // If we got here then fill in all the data |
| 248 | if (desc.flasher) { |
| 249 | // we need to get flash information |
| 250 | strcpy(desc.flash_filename, m_sFlashFilename.GetBuffer(0)); |
| 251 | strcpy(desc.flash_filename_focus, m_sFlashFilenameFocus.GetBuffer(0)); |
| 252 | if (desc.osflags & OBF_FLASH) { |
| 253 | // get flash start time |
| 254 | desc.flash_time = m_fFlashStart; |
| 255 | } |
| 256 | } else { |
| 257 | desc.flash_filename[0] = '\0'; |
| 258 | desc.flash_filename_focus[0] = '\0'; |
| 259 | } |
| 260 | |
| 261 | desc.parent_id = m_iPID; |
| 262 | desc.sibling_id = m_iSID; |
| 263 | desc.x = m_iX; |
| 264 | desc.y = m_iY; |
| 265 | desc.jump_page = m_ScreenToJump; |
| 266 | |
| 267 | switch (m_iButtonType) { |
| 268 | case 0: |
| 269 | desc.button_type = BUTT_UPARROW; |
| 270 | break; |
| 271 | case 1: |
| 272 | desc.button_type = BUTT_DOWNARROW; |
| 273 | break; |
| 274 | case 2: |
| 275 | desc.button_type = BUTT_NEXTPAGE; |
| 276 | break; |
| 277 | case 3: |
| 278 | desc.button_type = BUTT_PREVPAGE; |
| 279 | break; |
| 280 | case 4: |
| 281 | desc.button_type = BUTT_QUIT; |
| 282 | break; |
| 283 | case 5: |
| 284 | desc.button_type = BUTT_JUMP; |
| 285 | break; |
| 286 | } |
| 287 | |
| 288 | switch (m_iClickType) { |
| 289 | case 0: |
| 290 | desc.click_type = CLICKTYPE_CLICKUP; |
| 291 | break; |
| 292 | case 1: |
| 293 | desc.click_type = CLICKTYPE_CLICKDOWN; |
| 294 | break; |
| 295 | case 2: |
| 296 | desc.click_type = CLICKTYPE_DOWN; |
| 297 | break; |
| 298 | } |
| 299 | |
| 300 | strcpy(desc.filename, m_sFilename.GetBuffer(0)); |
| 301 | strcpy(desc.filename_focus, m_sFilenameFocus.GetBuffer(0)); |
| 302 | |
| 303 | CDialog::OnOK(); |
| 304 | } |
| 305 | |
| 306 | BOOL CBriefButtonEdit::OnInitDialog() { |
| 307 | CDialog::OnInitDialog(); |
| 308 | |
| 309 | UpdateData(false); |
| 310 | |
| 311 | UpdateDialog(); |
| 312 | |
| 313 | return TRUE; // return TRUE unless you set the focus to a control |
| 314 | // EXCEPTION: OCX Property Pages should return FALSE |
| 315 | } |
| 316 | |
| 317 | void CBriefButtonEdit::UpdateDialog(void) { |
| 318 | CEdit *edit; |
| 319 | CButton *but; |
| 320 | edit = (CEdit *)GetDlgItem(IDC_BRIEF_BT_FLASH_FILENAME); |
| 321 | but = (CButton *)GetDlgItem(IDC_BRIEF_BT_FLASH_CHOOSE); |
| 322 | |
| 323 | if ((desc.osflags & OBF_FLASH) || (desc.osflags & OBF_GLOW)) { |
| 324 | // Enable the flash filename window |
| 325 | edit->EnableWindow(true); |
| 326 | but->EnableWindow(true); |
| 327 | |
| 328 | edit = (CEdit *)GetDlgItem(IDC_BRIEF_BT_FLASHSTART); |
| 329 | if (desc.osflags & OBF_FLASH) |
| 330 | edit->EnableWindow(true); |
| 331 | else |
| 332 | edit->EnableWindow(false); |
| 333 | |
| 334 | edit = (CEdit *)GetDlgItem(IDC_BRIEF_BT_FLASH_FILENAME_FOCUS); |
| 335 | edit->EnableWindow(true); |
| 336 | } else { |
| 337 | edit->EnableWindow(false); |
| 338 | but->EnableWindow(false); |
| 339 | edit = (CEdit *)GetDlgItem(IDC_BRIEF_BT_FLASHSTART); |
| 340 | edit->EnableWindow(false); |
| 341 | edit = (CEdit *)GetDlgItem(IDC_BRIEF_BT_FLASH_FILENAME_FOCUS); |
| 342 | edit->EnableWindow(false); |
| 343 | } |
| 344 | |
| 345 | OnBriefBtJump(); |
| 346 | } |
| 347 | |
| 348 | void CBriefButtonEdit::OnBriefBtFlasher() { |
| 349 | UpdateData(true); |
| 350 | if (m_bFlasher) |
| 351 | desc.osflags |= OBF_FLASH; |
| 352 | else |
| 353 | desc.osflags &= ~OBF_FLASH; |
| 354 | if (m_bFlasher || m_bGlow) |
| 355 | desc.flasher = true; |
| 356 | else |
| 357 | desc.flasher = false; |
| 358 | UpdateDialog(); |
| 359 | } |
| 360 | |
| 361 | void CBriefButtonEdit::OnBriefBtGlow() { |
| 362 | UpdateData(true); |
| 363 | if (m_bGlow) |
| 364 | desc.osflags |= OBF_GLOW; |
| 365 | else |
| 366 | desc.osflags &= ~OBF_GLOW; |
| 367 | if (m_bFlasher || m_bGlow) |
| 368 | desc.flasher = true; |
| 369 | else |
| 370 | desc.flasher = false; |
| 371 | UpdateDialog(); |
| 372 | } |
| 373 | |
| 374 | extern int Briefing_root_screen; |
| 375 | extern tBriefScreen Briefing_screens[MAX_TELCOM_SCREENS]; |
| 376 | |
| 377 | bool CBriefButtonEdit::VerifyData(void) { |
| 378 | UpdateData(true); |
| 379 | bool ret = true; |
| 380 | |
| 381 | if (desc.flasher) { |
| 382 | // flash filename should be specified |
| 383 | if (!cfexist(m_sFlashFilename.GetBuffer(0))) { |
| 384 | // file doesn't exist |
| 385 | MessageBox("Flash Filename Does Not Exist", "Error"); |
| 386 | ret = false; |
| 387 | } |
| 388 | // flash focus filename should be specified |
| 389 | if (!cfexist(m_sFlashFilenameFocus.GetBuffer(0))) { |
| 390 | // file doesn't exist |
| 391 | MessageBox("Flash Focus Filename Does Not Exist", "Error"); |
| 392 | ret = false; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | // filename should be specified |
| 397 | if (!cfexist(m_sFilename.GetBuffer(0))) { |
| 398 | // file doesn't exist |
| 399 | MessageBox("Filename Does Not Exist", "Error"); |
| 400 | ret = false; |
| 401 | } |
| 402 | |
| 403 | // focus filename should be specified |
| 404 | if (!cfexist(m_sFilenameFocus.GetBuffer(0))) { |
| 405 | // file doesn't exist |
| 406 | MessageBox("Focus Filename Does Not Exist", "Error"); |
| 407 | ret = false; |
| 408 | } |
| 409 | |
| 410 | if (desc.button_type == BUTT_JUMP) { |
| 411 | // verify the jump screen exists |
| 412 | int num_screens = 0; |
| 413 | int curr = Briefing_root_screen; |
| 414 | while (curr != -1) { |
| 415 | num_screens++; |
| 416 | curr = Briefing_screens[curr].next; |
| 417 | } |
| 418 | |
| 419 | if (m_ScreenToJump < 0 || m_ScreenToJump >= num_screens) { |
| 420 | // invalid screen |
| 421 | MessageBox("The Jump-To Screen Does Not Exist", "Error"); |
| 422 | ret = false; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | return ret; |
| 427 | } |
| 428 | void CBriefButtonEdit::OnBriefBtChooseFocus() { |
| 429 | UpdateData(true); |
| 430 | char szFilter[] = "Outrage Graphic Files (*.ogf)|*.ogf|32bit Uncompressed Targa (*.tga)|*.tga|PCX (*.pcx)|*.pcx|All " |
| 431 | "Files (*.*)|*.*||"; |
| 432 | CFileDialog dlg(true, NULL, NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, szFilter); |
| 433 | |
| 434 | if (dlg.DoModal() == IDOK) { |
| 435 | // handle |
| 436 | m_sFilenameFocus = dlg.GetFileName(); |
| 437 | UpdateData(false); |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | void CBriefButtonEdit::OnBriefBtFlashChooseFocus() { |
| 442 | UpdateData(true); |
| 443 | char szFilter[] = "Outrage Graphic Files (*.ogf)|*.ogf|32bit Uncompressed Targa (*.tga)|*.tga|PCX (*.pcx)|*.pcx|All " |
| 444 | "Files (*.*)|*.*||"; |
| 445 | CFileDialog dlg(true, NULL, NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, szFilter); |
| 446 | |
| 447 | if (dlg.DoModal() == IDOK) { |
| 448 | // handle |
| 449 | m_sFlashFilenameFocus = dlg.GetFileName(); |
| 450 | UpdateData(false); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | void CBriefButtonEdit::OnMissionflags() { |
| 455 | CBriefMissionFlagsDlg dlg(desc.mission_mask_set, desc.mission_mask_unset); |
| 456 | |
| 457 | if (dlg.DoModal()) { |
| 458 | desc.mission_mask_set = dlg.m_Set; |
| 459 | desc.mission_mask_unset = dlg.m_UnSet; |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | void CBriefButtonEdit::OnBriefBtJump() { |
| 464 | CButton *button = (CButton *)GetDlgItem(IDC_BRIEF_BT_JUMP); |
| 465 | CEdit *edit = (CEdit *)GetDlgItem(IDC_BRIEF_BT_JUMP_SCREEN); |
| 466 | |
| 467 | if ((button->GetState() & 0x03) != 0) |
| 468 | edit->EnableWindow(true); |
| 469 | else |
| 470 | edit->EnableWindow(false); |
| 471 | } |
| 472 | |
| 473 | void CBriefButtonEdit::OnBriefBtNextscreen() { OnBriefBtJump(); } |
| 474 | |
| 475 | void CBriefButtonEdit::OnBriefBtPrevscreen() { OnBriefBtJump(); } |
| 476 | |
| 477 | void CBriefButtonEdit::OnBriefBtQuit() { OnBriefBtJump(); } |
| 478 | |
| 479 | void CBriefButtonEdit::OnBriefBtScrolldown() { OnBriefBtJump(); } |
| 480 | |
| 481 | void CBriefButtonEdit::OnBriefBtScrollup() { OnBriefBtJump(); } |