| 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 | // BriefEdit.cpp : implementation file |
| 20 | // |
| 21 | |
| 22 | #include "mfc_compatibility.h" |
| 23 | #include "editor.h" |
| 24 | #include "BriefEdit.h" |
| 25 | #include "mono.h" |
| 26 | #include "BriefingParse.h" |
| 27 | |
| 28 | #include "BriefBitmapEdit.h" |
| 29 | #include "BriefButtonEdit.h" |
| 30 | #include "BriefMovieEdit.h" |
| 31 | #include "BriefScreenEdit.h" |
| 32 | #include "BriefSoundEdit.h" |
| 33 | #include "BriefTextEdit.h" |
| 34 | #include "Telcom.h" |
| 35 | #include "BriefManage.h" |
| 36 | #include "mem.h" |
| 37 | #include "textaux.h" |
| 38 | #include "ddio.h" |
| 39 | |
| 40 | #ifdef _DEBUG |
| 41 | #define new DEBUG_NEW |
| 42 | #undef THIS_FILE |
| 43 | static char THIS_FILE[] = __FILE__; |
| 44 | #endif |
| 45 | |
| 46 | ///////////////////////////////////////////////////////////////////////////// |
| 47 | // CBriefEdit dialog |
| 48 | |
| 49 | tLayoutScreen *PBlayouts; |
| 50 | int *PBnum_layouts; |
| 51 | int TCx, TCy; |
| 52 | |
| 53 | CBriefEdit::CBriefEdit(CWnd *pParent /*=NULL*/) : CDialog(CBriefEdit::IDD, pParent) { |
| 54 | //{{AFX_DATA_INIT(CBriefEdit) |
| 55 | m_fGlitch = 0.0f; |
| 56 | m_fStatic = 0.0f; |
| 57 | m_sTitle = _T(""); |
| 58 | //}}AFX_DATA_INIT |
| 59 | layouts = NULL; |
| 60 | num_layouts = 0; |
| 61 | ParseLayoutScreenFile("BriefingLayouts.txt"); |
| 62 | PBlayouts = layouts; |
| 63 | PBnum_layouts = &num_layouts; |
| 64 | layout_bmp = -1; |
| 65 | TCx = TCy = 0; |
| 66 | |
| 67 | int bm_handle = bm_AllocLoadFileBitmap("TelCom.ogf", 0); |
| 68 | if (bm_handle > BAD_BITMAP_HANDLE) { |
| 69 | |
| 70 | menutga_LoadHotSpotMap(bm_handle, HOTSPOT_DISPLAY, &hotspotmap, &windowmap); |
| 71 | |
| 72 | TCx = windowmap.wm[MONITOR_MAIN].x; |
| 73 | TCy = windowmap.wm[MONITOR_MAIN].y; |
| 74 | |
| 75 | FreeHotSpotMapInternals(&hotspotmap); |
| 76 | FreeViewports(); |
| 77 | if (windowmap.wm) |
| 78 | mem_free(windowmap.wm); |
| 79 | bm_FreeBitmap(bm_handle); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | void CBriefEdit::DoDataExchange(CDataExchange *pDX) { |
| 84 | CDialog::DoDataExchange(pDX); |
| 85 | //{{AFX_DATA_MAP(CBriefEdit) |
| 86 | DDX_Text(pDX, IDC_BRIEF_GLITCH, m_fGlitch); |
| 87 | DDV_MinMaxFloat(pDX, m_fGlitch, 0.f, 1.f); |
| 88 | DDX_Text(pDX, IDC_BRIEF_STATIC, m_fStatic); |
| 89 | DDV_MinMaxFloat(pDX, m_fStatic, 0.f, 1.f); |
| 90 | DDX_Text(pDX, IDC_BRIEF_TITLE, m_sTitle); |
| 91 | //}}AFX_DATA_MAP |
| 92 | } |
| 93 | |
| 94 | BEGIN_MESSAGE_MAP(CBriefEdit, CDialog) |
| 95 | //{{AFX_MSG_MAP(CBriefEdit) |
| 96 | ON_BN_CLICKED(IDC_BRIEF_EFFECT_BITMAP, OnBriefEffectBitmap) |
| 97 | ON_BN_CLICKED(IDC_BRIEF_EFFECT_BUTTON, OnBriefEffectButton) |
| 98 | ON_BN_CLICKED(IDC_BRIEF_EFFECT_DEL, OnBriefEffectDel) |
| 99 | ON_BN_CLICKED(IDC_BRIEF_EFFECT_EDIT, OnBriefEffectEdit) |
| 100 | ON_BN_CLICKED(IDC_BRIEF_EFFECT_MOVIE, OnBriefEffectMovie) |
| 101 | ON_BN_CLICKED(IDC_BRIEF_EFFECT_SOUND, OnBriefEffectSound) |
| 102 | ON_BN_CLICKED(IDC_BRIEF_EFFECT_TEXT, OnBriefEffectText) |
| 103 | ON_BN_CLICKED(IDC_BRIEF_SCREEN_ADD, OnBriefScreenAdd) |
| 104 | ON_BN_CLICKED(IDC_BRIEF_SCREEN_DEL, OnBriefScreenDel) |
| 105 | ON_BN_CLICKED(IDC_BRIEF_SCREEN_EDIT, OnBriefScreenEdit) |
| 106 | ON_WM_DESTROY() |
| 107 | ON_CBN_SELCHANGE(IDC_BRIEF_SCREEN_LIST, OnSelchangeBriefScreenList) |
| 108 | ON_BN_CLICKED(IDC_BRIEF_SAVE, OnBriefSave) |
| 109 | ON_BN_CLICKED(IDC_LOAD, OnLoad) |
| 110 | ON_WM_TIMER() |
| 111 | ON_BN_CLICKED(IDC_MANAGE, OnManage) |
| 112 | //}}AFX_MSG_MAP |
| 113 | END_MESSAGE_MAP() |
| 114 | |
| 115 | /* |
| 116 | **************************************************************************** |
| 117 | * Functions to manipulate effects/screens in briefing editor * |
| 118 | **************************************************************************** |
| 119 | * |
| 120 | */ |
| 121 | bool Briefing_free_called = true; // if this is true it's ok to Init screens |
| 122 | int Briefing_root_screen; |
| 123 | tBriefScreen Briefing_screens[MAX_TELCOM_SCREENS]; |
| 124 | |
| 125 | // BriefEditInitScreens |
| 126 | // |
| 127 | // Initializes the briefing screens so they are empty |
| 128 | void BriefEditInitScreens(void) { |
| 129 | ASSERT(Briefing_free_called); |
| 130 | Briefing_free_called = false; |
| 131 | |
| 132 | Briefing_root_screen = -1; |
| 133 | |
| 134 | for (int scr = 0; scr < MAX_TELCOM_SCREENS; scr++) { |
| 135 | tBriefScreen *bscr = &Briefing_screens[scr]; |
| 136 | |
| 137 | bscr->used = false; |
| 138 | bscr->root_effect = -1; |
| 139 | bscr->next = -1; |
| 140 | bscr->prev = -1; |
| 141 | bscr->layout[0] = '\0'; |
| 142 | bscr->mission_mask_set = 0; |
| 143 | bscr->mission_mask_unset = 0; |
| 144 | |
| 145 | for (int eff = 0; eff < MAX_EFFECTS_PER_SCREEN; eff++) { |
| 146 | BriefEditInitEffect(&bscr->effects[eff]); |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | // BriefEditInitEffect |
| 152 | // |
| 153 | // Initializes an effect to empty |
| 154 | void BriefEditInitEffect(tBriefEffect *efx) { |
| 155 | ASSERT(efx); |
| 156 | |
| 157 | memset(efx, 0, sizeof(tBriefEffect)); |
| 158 | |
| 159 | efx->type = BE_NONE; |
| 160 | efx->used = false; |
| 161 | efx->id = 0; |
| 162 | efx->text = NULL; |
| 163 | efx->next = -1; |
| 164 | efx->prev = -1; |
| 165 | efx->w = efx->h = -1; |
| 166 | efx->description[0] = '\0'; |
| 167 | } |
| 168 | |
| 169 | // BriefEditFreeScreen |
| 170 | // |
| 171 | // Frees a screen |
| 172 | void BriefEditFreeScreen(tBriefScreen *bscr) { |
| 173 | bscr->used = false; |
| 174 | bscr->root_effect = -1; |
| 175 | bscr->prev = bscr->next = -1; |
| 176 | bscr->layout[0] = '\0'; |
| 177 | |
| 178 | for (int eff = 0; eff < MAX_EFFECTS_PER_SCREEN; eff++) { |
| 179 | if (bscr->effects[eff].used) { |
| 180 | BriefEditFreeEffect(&bscr->effects[eff]); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // BriefEditFreeScreens |
| 186 | // |
| 187 | // Closes down all the briefing screens, freeing memory |
| 188 | void BriefEditFreeScreens(void) { |
| 189 | ASSERT(!Briefing_free_called); |
| 190 | Briefing_free_called = true; |
| 191 | |
| 192 | for (int scr = 0; scr < MAX_TELCOM_SCREENS; scr++) { |
| 193 | if (Briefing_screens[scr].used) { |
| 194 | tBriefScreen *bscr = &Briefing_screens[scr]; |
| 195 | BriefEditFreeScreen(bscr); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | // BriefEditFreeEffect |
| 201 | // |
| 202 | // Frees up any memory allocated in an effect |
| 203 | void BriefEditFreeEffect(tBriefEffect *efx) { |
| 204 | switch (efx->type) { |
| 205 | case BE_TEXT: |
| 206 | case BE_BMP: |
| 207 | case BE_MOVIE: |
| 208 | case BE_BKG: |
| 209 | case BE_POLY: |
| 210 | case BE_SND: |
| 211 | case BE_BUTTON: |
| 212 | break; |
| 213 | default: |
| 214 | Int3(); // Get Jeff |
| 215 | }; |
| 216 | |
| 217 | if (efx->text) { |
| 218 | mem_free(efx->text); |
| 219 | efx->text = NULL; |
| 220 | } |
| 221 | |
| 222 | efx->used = false; |
| 223 | efx->next = efx->prev = -1; |
| 224 | efx->description[0] = '\0'; |
| 225 | efx->id = 0; |
| 226 | efx->type = BE_NONE; |
| 227 | } |
| 228 | |
| 229 | void BuildMissionFlagMask(uint32_t mask, char *string, uint8_t isset) { |
| 230 | int counter = 0; |
| 231 | int index = 0; |
| 232 | uint32_t bit = 0x01; |
| 233 | char temp[10]; |
| 234 | |
| 235 | for (index = 0; index < 32; index++) { |
| 236 | if (mask & bit) { |
| 237 | if (isset) |
| 238 | strcat(string, "isset "); |
| 239 | else |
| 240 | strcat(string, "isnset "); |
| 241 | sprintf(temp, "%d ", counter); |
| 242 | strcat(string, temp); |
| 243 | } |
| 244 | counter++; |
| 245 | bit = bit << 1; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | // BriefEditSaveScreens |
| 250 | // |
| 251 | // Saves out the screens to a briefing file |
| 252 | uint8_t BriefEditSaveScreens(char *filename, CComboBox *screen_combo, BriefGlobalValues *glob) { |
| 253 | CFILE *file = cfopen(filename, "wt"); |
| 254 | if (!file) |
| 255 | return 0; |
| 256 | |
| 257 | int curr_screen = Briefing_root_screen; |
| 258 | int curr_effect; |
| 259 | char buffer[9 * 1024]; |
| 260 | char tempbuffer[512]; |
| 261 | int screen_count = 0; |
| 262 | |
| 263 | // Write out global information |
| 264 | sprintf(buffer, "$title \"%s\"", glob->title); |
| 265 | cf_WriteString(file, buffer); |
| 266 | sprintf(buffer, "$glitch %.3f", glob->glitch_val); |
| 267 | cf_WriteString(file, buffer); |
| 268 | sprintf(buffer, "$static %.3f", glob->static_val); |
| 269 | cf_WriteString(file, buffer); |
| 270 | |
| 271 | cf_WriteString(file, "\n"); |
| 272 | |
| 273 | while (curr_screen != -1) { |
| 274 | ASSERT(curr_screen >= 0 && curr_screen < MAX_TELCOM_SCREENS); |
| 275 | ASSERT(Briefing_screens[curr_screen].used); |
| 276 | |
| 277 | curr_effect = Briefing_screens[curr_screen].root_effect; |
| 278 | tBriefEffect *effects = Briefing_screens[curr_screen].effects; |
| 279 | |
| 280 | char masksetstr[256], maskunsetstr[256]; |
| 281 | masksetstr[0] = '\0'; |
| 282 | maskunsetstr[0] = '\0'; |
| 283 | if (Briefing_screens[curr_screen].mission_mask_set) { |
| 284 | BuildMissionFlagMask(Briefing_screens[curr_screen].mission_mask_set, masksetstr, 1); |
| 285 | } |
| 286 | if (Briefing_screens[curr_screen].mission_mask_unset) { |
| 287 | BuildMissionFlagMask(Briefing_screens[curr_screen].mission_mask_unset, maskunsetstr, 0); |
| 288 | } |
| 289 | |
| 290 | // Write out start screen |
| 291 | screen_combo->GetLBText(screen_count, tempbuffer); |
| 292 | if (Briefing_screens[curr_screen].layout[0] != '\0') |
| 293 | sprintf(buffer, "$screen %d %s %s desc \"%s\" layout \"%s\" start", screen_count, masksetstr, maskunsetstr, |
| 294 | tempbuffer, Briefing_screens[curr_screen].layout); |
| 295 | else |
| 296 | sprintf(buffer, "$screen %d %s %s desc \"%s\" start", screen_count, masksetstr, maskunsetstr, tempbuffer); |
| 297 | cf_WriteString(file, buffer); |
| 298 | |
| 299 | while (curr_effect != -1) { |
| 300 | ASSERT(curr_effect >= 0 && curr_effect < MAX_EFFECTS_PER_SCREEN); |
| 301 | ASSERT(effects[curr_effect].used); |
| 302 | |
| 303 | // Write out effect data |
| 304 | switch (effects[curr_effect].type) { |
| 305 | case BE_TEXT: { |
| 306 | TCTEXTDESC *desc = &effects[curr_effect].text_desc; |
| 307 | |
| 308 | switch (desc->type) { |
| 309 | case TC_TEXT_STATIC: |
| 310 | strcpy(tempbuffer, "None"); |
| 311 | break; |
| 312 | case TC_TEXT_SCROLL: |
| 313 | switch (desc->flags) { |
| 314 | case TC_TEXTF_L2R: |
| 315 | strcpy(tempbuffer, "scroll_l2r"); |
| 316 | break; |
| 317 | case TC_TEXTF_R2L: |
| 318 | strcpy(tempbuffer, "scroll_r2l"); |
| 319 | break; |
| 320 | case TC_TEXTF_T2B: |
| 321 | strcpy(tempbuffer, "scroll_t2b"); |
| 322 | break; |
| 323 | case TC_TEXTF_B2T: |
| 324 | strcpy(tempbuffer, "scroll_b2t"); |
| 325 | break; |
| 326 | default: |
| 327 | strcpy(tempbuffer, "None"); |
| 328 | break; |
| 329 | } |
| 330 | break; |
| 331 | case TC_TEXT_FADE: |
| 332 | switch (desc->flags) { |
| 333 | case TC_TEXTF_IN: |
| 334 | strcpy(tempbuffer, "fade_in"); |
| 335 | break; |
| 336 | case TC_TEXTF_OUT: |
| 337 | strcpy(tempbuffer, "fade_out"); |
| 338 | break; |
| 339 | default: |
| 340 | strcpy(tempbuffer, "fade_in"); |
| 341 | break; |
| 342 | } |
| 343 | break; |
| 344 | case TC_TEXT_FLASH: |
| 345 | strcpy(tempbuffer, "flash"); |
| 346 | break; |
| 347 | default: |
| 348 | strcpy(tempbuffer, "None"); |
| 349 | } |
| 350 | |
| 351 | uint8_t red, green, blue; |
| 352 | red = GR_COLOR_RED(desc->color); |
| 353 | green = GR_COLOR_GREEN(desc->color); |
| 354 | blue = GR_COLOR_BLUE(desc->color); |
| 355 | |
| 356 | char font_str[20]; |
| 357 | switch (desc->font) { |
| 358 | case BBRIEF_FONT_INDEX: |
| 359 | strcpy(font_str, "lg_brief"); |
| 360 | break; |
| 361 | default: |
| 362 | strcpy(font_str, "sm_brief"); |
| 363 | break; |
| 364 | } |
| 365 | |
| 366 | char masksetstr[256], maskunsetstr[256]; |
| 367 | masksetstr[0] = '\0'; |
| 368 | maskunsetstr[0] = '\0'; |
| 369 | if (desc->mission_mask_set) { |
| 370 | BuildMissionFlagMask(desc->mission_mask_set, masksetstr, 1); |
| 371 | } |
| 372 | if (desc->mission_mask_unset) { |
| 373 | BuildMissionFlagMask(desc->mission_mask_unset, maskunsetstr, 0); |
| 374 | } |
| 375 | |
| 376 | sprintf(buffer, |
| 377 | "$text effect %s font %s %s speed %0.3f box %d,%d,%d,%d color %d,%d,%d desc \"%s\" id %d starttime " |
| 378 | "%0.3f %s %s show", |
| 379 | tempbuffer, font_str, (desc->caps & TCTD_TABSTOP) ? "tabstop" : "", desc->speed, desc->textbox.left, |
| 380 | desc->textbox.right, desc->textbox.top, desc->textbox.bottom, red, green, blue, |
| 381 | effects[curr_effect].description, effects[curr_effect].id, desc->waittime, masksetstr, maskunsetstr); |
| 382 | cf_WriteString(file, buffer); |
| 383 | |
| 384 | // now write out all the text |
| 385 | const char *p = effects[curr_effect].text; |
| 386 | while (p) { |
| 387 | p = textaux_CopyTextLine(p, buffer); |
| 388 | cf_WriteString(file, buffer); |
| 389 | } |
| 390 | |
| 391 | cf_WriteString(file, "$endtext"); |
| 392 | } break; |
| 393 | case BE_BMP: { |
| 394 | TCBMPDESC *desc = &effects[curr_effect].bmp_desc; |
| 395 | switch (desc->type) { |
| 396 | case TC_BMP_STATIC: |
| 397 | strcpy(tempbuffer, "None"); |
| 398 | break; |
| 399 | case TC_BMP_BLUR: |
| 400 | if (desc->flags == TC_BMPF_IN) |
| 401 | strcpy(tempbuffer, "Blur_in"); |
| 402 | else |
| 403 | strcpy(tempbuffer, "Blur_out"); |
| 404 | break; |
| 405 | case TC_BMP_SCANLINE: |
| 406 | if (desc->flags == TC_BMPF_IN) |
| 407 | strcpy(tempbuffer, "Scan_in"); |
| 408 | else |
| 409 | strcpy(tempbuffer, "Scan_out"); |
| 410 | break; |
| 411 | case TC_BMP_INVERT: |
| 412 | if (desc->flags == TC_BMPF_IN) |
| 413 | strcpy(tempbuffer, "Invert_in"); |
| 414 | else |
| 415 | strcpy(tempbuffer, "Invert_out"); |
| 416 | break; |
| 417 | case TC_BMP_STRETCH: |
| 418 | if (desc->flags == TC_BMPF_IN) |
| 419 | strcpy(tempbuffer, "Stretch_in"); |
| 420 | else |
| 421 | strcpy(tempbuffer, "Stretch_out"); |
| 422 | break; |
| 423 | default: |
| 424 | strcpy(tempbuffer, "None"); |
| 425 | break; |
| 426 | } |
| 427 | |
| 428 | char masksetstr[256], maskunsetstr[256]; |
| 429 | masksetstr[0] = '\0'; |
| 430 | maskunsetstr[0] = '\0'; |
| 431 | if (desc->mission_mask_set) { |
| 432 | BuildMissionFlagMask(desc->mission_mask_set, masksetstr, 1); |
| 433 | } |
| 434 | if (desc->mission_mask_unset) { |
| 435 | BuildMissionFlagMask(desc->mission_mask_unset, maskunsetstr, 0); |
| 436 | } |
| 437 | |
| 438 | char no_render[32]; |
| 439 | if (desc->flags & TC_NOEARLYRENDER) |
| 440 | strcpy(no_render, "no_early_rend"); |
| 441 | else |
| 442 | *no_render = '\0'; |
| 443 | |
| 444 | sprintf(buffer, "$bitmap effect %s starttime %.3f %s speed %.3f position %d,%d %s %s desc \"%s\" show \"%s\"", |
| 445 | tempbuffer, desc->waittime, no_render, desc->speed, desc->x, desc->y, masksetstr, maskunsetstr, |
| 446 | effects[curr_effect].description, desc->filename); |
| 447 | cf_WriteString(file, buffer); |
| 448 | } break; |
| 449 | case BE_MOVIE: { |
| 450 | TCMOVIEDESC *desc = &effects[curr_effect].movie_desc; |
| 451 | if (desc->looping) |
| 452 | strcpy(tempbuffer, "looping"); |
| 453 | else |
| 454 | tempbuffer[0] = '\0'; |
| 455 | |
| 456 | char masksetstr[256], maskunsetstr[256]; |
| 457 | masksetstr[0] = '\0'; |
| 458 | maskunsetstr[0] = '\0'; |
| 459 | if (desc->mission_mask_set) { |
| 460 | BuildMissionFlagMask(desc->mission_mask_set, masksetstr, 1); |
| 461 | } |
| 462 | if (desc->mission_mask_unset) { |
| 463 | BuildMissionFlagMask(desc->mission_mask_unset, maskunsetstr, 0); |
| 464 | } |
| 465 | |
| 466 | sprintf(buffer, "$movie position %d,%d fps %.3f %s starttime %.3f %s %s desc \"%s\" show \"%s\"", desc->x, |
| 467 | desc->y, desc->fps, tempbuffer, desc->waittime, masksetstr, maskunsetstr, |
| 468 | effects[curr_effect].description, desc->filename); |
| 469 | cf_WriteString(file, buffer); |
| 470 | } break; |
| 471 | case BE_BKG: { |
| 472 | Int3(); |
| 473 | } break; |
| 474 | case BE_POLY: { |
| 475 | Int3(); |
| 476 | } break; |
| 477 | case BE_SND: { |
| 478 | TCSNDDESC *desc = &effects[curr_effect].snd_desc; |
| 479 | if (desc->once) |
| 480 | strcpy(tempbuffer, "once"); |
| 481 | else |
| 482 | tempbuffer[0] = '\0'; |
| 483 | |
| 484 | char masksetstr[256], maskunsetstr[256]; |
| 485 | masksetstr[0] = '\0'; |
| 486 | maskunsetstr[0] = '\0'; |
| 487 | if (desc->mission_mask_set) { |
| 488 | BuildMissionFlagMask(desc->mission_mask_set, masksetstr, 1); |
| 489 | } |
| 490 | if (desc->mission_mask_unset) { |
| 491 | BuildMissionFlagMask(desc->mission_mask_unset, maskunsetstr, 0); |
| 492 | } |
| 493 | |
| 494 | sprintf(buffer, "$sound %s starttime %.3f %s %s desc \"%s\" play \"%s\"", tempbuffer, desc->waittime, |
| 495 | masksetstr, maskunsetstr, effects[curr_effect].description, desc->filename); |
| 496 | cf_WriteString(file, buffer); |
| 497 | } break; |
| 498 | case BE_BUTTON: { |
| 499 | TCBUTTONDESC *desc = &effects[curr_effect].button_desc; |
| 500 | char ctype[20]; |
| 501 | |
| 502 | switch (desc->click_type) { |
| 503 | case CLICKTYPE_CLICKDOWN: |
| 504 | strcpy(ctype, "ClickDown"); |
| 505 | break; |
| 506 | case CLICKTYPE_CLICKUP: |
| 507 | strcpy(ctype, "ClickUp"); |
| 508 | break; |
| 509 | case CLICKTYPE_DOWN: |
| 510 | strcpy(ctype, "HoldDown"); |
| 511 | break; |
| 512 | default: |
| 513 | strcpy(ctype, "ClickUp"); |
| 514 | break; |
| 515 | } |
| 516 | switch (desc->button_type) { |
| 517 | case BUTT_UPARROW: |
| 518 | strcpy(tempbuffer, "Up"); |
| 519 | break; |
| 520 | case BUTT_DOWNARROW: |
| 521 | strcpy(tempbuffer, "Down"); |
| 522 | break; |
| 523 | case BUTT_NEXTPAGE: |
| 524 | strcpy(tempbuffer, "Next"); |
| 525 | break; |
| 526 | case BUTT_PREVPAGE: |
| 527 | strcpy(tempbuffer, "Prev"); |
| 528 | break; |
| 529 | case BUTT_QUIT: |
| 530 | strcpy(tempbuffer, "Quit"); |
| 531 | break; |
| 532 | case BUTT_JUMP: |
| 533 | sprintf(tempbuffer, "Jump %d", desc->jump_page); |
| 534 | break; |
| 535 | default: |
| 536 | strcpy(tempbuffer, "Next"); |
| 537 | break; |
| 538 | } |
| 539 | |
| 540 | char flash_info[_MAX_PATH + 256]; |
| 541 | flash_info[0] = '\0'; |
| 542 | if (desc->osflags & OBF_FLASH) |
| 543 | sprintf(flash_info, "flash %.3f \"%s\" \"%s\"", desc->flash_time, desc->flash_filename, |
| 544 | desc->flash_filename_focus); |
| 545 | |
| 546 | char glow_fname[_MAX_PATH + 4]; |
| 547 | glow_fname[0] = '\0'; |
| 548 | if (desc->osflags == OBF_GLOW) |
| 549 | sprintf(glow_fname, "\"%s\" \"%s\"", desc->flash_filename, desc->flash_filename_focus); |
| 550 | |
| 551 | char glow_id[7]; |
| 552 | glow_id[0] = '\0'; |
| 553 | if (desc->osflags & OBF_GLOW) |
| 554 | strcpy(glow_id, "glow"); |
| 555 | |
| 556 | char masksetstr[256], maskunsetstr[256]; |
| 557 | masksetstr[0] = '\0'; |
| 558 | maskunsetstr[0] = '\0'; |
| 559 | if (desc->mission_mask_set) { |
| 560 | BuildMissionFlagMask(desc->mission_mask_set, masksetstr, 1); |
| 561 | } |
| 562 | if (desc->mission_mask_unset) { |
| 563 | BuildMissionFlagMask(desc->mission_mask_unset, maskunsetstr, 0); |
| 564 | } |
| 565 | |
| 566 | sprintf(buffer, |
| 567 | "$button %d,%d type %s %s %s click %s id %d desc \"%s\" parent_id %d sibling_id %d %s %s show \"%s\" " |
| 568 | "\"%s\" %s", |
| 569 | desc->x, desc->y, tempbuffer, flash_info, glow_id, ctype, effects[curr_effect].id, |
| 570 | effects[curr_effect].description, desc->parent_id, desc->sibling_id, masksetstr, maskunsetstr, |
| 571 | desc->filename, desc->filename_focus, glow_fname); |
| 572 | cf_WriteString(file, buffer); |
| 573 | } break; |
| 574 | default: |
| 575 | Int3(); |
| 576 | break; |
| 577 | } |
| 578 | |
| 579 | curr_effect = effects[curr_effect].next; |
| 580 | } |
| 581 | |
| 582 | // Write out End screen |
| 583 | cf_WriteString(file, "$endscreen\n"); |
| 584 | |
| 585 | curr_screen = Briefing_screens[curr_screen].next; |
| 586 | screen_count++; |
| 587 | } |
| 588 | |
| 589 | cfclose(file); |
| 590 | return 1; |
| 591 | } |
| 592 | |
| 593 | struct { |
| 594 | int current_screen; |
| 595 | char title[128]; |
| 596 | CComboBox *scombo, *ecombo; |
| 597 | BriefGlobalValues *glob; |
| 598 | } BEParseInfo; |
| 599 | |
| 600 | void BEGetCurScreenEffect(int *ret_screen, int *ret_effect) { |
| 601 | if (ret_screen) |
| 602 | *ret_screen = -1; |
| 603 | if (ret_effect) |
| 604 | *ret_effect = -1; |
| 605 | |
| 606 | // Get the current screen |
| 607 | int curr_screen = BEParseInfo.scombo->GetCurSel(); |
| 608 | if (curr_screen == CB_ERR) { |
| 609 | return; |
| 610 | } |
| 611 | |
| 612 | // now we need to get the real effect num |
| 613 | int node = Briefing_root_screen; |
| 614 | int count = curr_screen; |
| 615 | |
| 616 | while (node != -1 && count > 0) { |
| 617 | count--; |
| 618 | node = Briefing_screens[node].next; |
| 619 | } |
| 620 | |
| 621 | ASSERT(count == 0); // we better be at 0 here |
| 622 | ASSERT(node >= 0 && node < MAX_TELCOM_SCREENS); |
| 623 | ASSERT(Briefing_screens[node].used); |
| 624 | |
| 625 | if (count != 0) |
| 626 | return; |
| 627 | |
| 628 | if (ret_screen) |
| 629 | *ret_screen = node; |
| 630 | |
| 631 | if (!ret_effect) |
| 632 | return; |
| 633 | |
| 634 | // Get the current screen |
| 635 | int curr_effect = BEParseInfo.ecombo->GetCurSel(); |
| 636 | if (curr_effect == CB_ERR) { |
| 637 | return; |
| 638 | } |
| 639 | |
| 640 | // now we need to get the real effect num |
| 641 | node = Briefing_screens[curr_screen].root_effect; |
| 642 | count = curr_effect; |
| 643 | |
| 644 | while (node != -1 && count > 0) { |
| 645 | count--; |
| 646 | node = Briefing_screens[curr_screen].effects[node].next; |
| 647 | } |
| 648 | |
| 649 | ASSERT(count == 0); // we better be at 0 here |
| 650 | if (count != 0) |
| 651 | return; |
| 652 | |
| 653 | if (ret_effect) |
| 654 | *ret_effect = node; |
| 655 | } |
| 656 | |
| 657 | bool BEAllocEffect(int *ret_screen, int *ret_effect) { |
| 658 | // Get the current screen |
| 659 | int curr_screen; |
| 660 | BEGetCurScreenEffect(&curr_screen, NULL); |
| 661 | if (curr_screen == -1) { |
| 662 | return false; |
| 663 | } |
| 664 | |
| 665 | ASSERT(curr_screen >= 0 && curr_screen < MAX_TELCOM_SCREENS); |
| 666 | ASSERT(Briefing_screens[curr_screen].used); |
| 667 | |
| 668 | // Trace though the effect list and add the effect |
| 669 | int curr_effect = -1; |
| 670 | int node = Briefing_screens[curr_screen].root_effect; |
| 671 | tBriefScreen *bscr = &Briefing_screens[curr_screen]; |
| 672 | for (int i = 0; i < MAX_EFFECTS_PER_SCREEN; i++) { |
| 673 | if (!bscr->effects[i].used) { |
| 674 | curr_effect = i; |
| 675 | break; |
| 676 | } |
| 677 | } |
| 678 | if (curr_effect == -1) { |
| 679 | // no available effects |
| 680 | return false; |
| 681 | } |
| 682 | |
| 683 | bscr->effects[i].used = true; |
| 684 | if (node == -1) { |
| 685 | // first effect for screen |
| 686 | bscr->root_effect = curr_effect; |
| 687 | bscr->effects[curr_effect].prev = bscr->effects[curr_effect].next = -1; |
| 688 | *ret_screen = curr_screen; |
| 689 | *ret_effect = curr_effect; |
| 690 | return true; |
| 691 | } else { |
| 692 | // get to the end of effects for list |
| 693 | while (bscr->effects[node].next != -1) { |
| 694 | node = bscr->effects[node].next; |
| 695 | } |
| 696 | |
| 697 | // when we get here node should at the end of the list |
| 698 | bscr->effects[node].next = curr_effect; |
| 699 | bscr->effects[curr_effect].next = -1; |
| 700 | bscr->effects[curr_effect].prev = node; |
| 701 | *ret_screen = curr_screen; |
| 702 | *ret_effect = curr_effect; |
| 703 | return true; |
| 704 | } |
| 705 | |
| 706 | Int3(); |
| 707 | return false; // unknown error |
| 708 | } |
| 709 | |
| 710 | void BEAddTextEffect(TCTEXTDESC *desc, char *text, char *description, int id) { |
| 711 | int curr_screen, curr_effect; |
| 712 | if (!BEAllocEffect(&curr_screen, &curr_effect)) |
| 713 | return; |
| 714 | |
| 715 | tBriefScreen *bscr = &Briefing_screens[curr_screen]; |
| 716 | tBriefEffect *befx = &bscr->effects[curr_effect]; |
| 717 | TCTEXTDESC *dest = &befx->text_desc; |
| 718 | |
| 719 | if (strlen(description) == 0) |
| 720 | strcpy(description, "Text"); |
| 721 | befx->type = BE_TEXT; |
| 722 | strcpy(befx->description, description); |
| 723 | befx->id = id; |
| 724 | |
| 725 | dest->caps = desc->caps; |
| 726 | memcpy(&dest->textbox, &desc->textbox, sizeof(tc_text)); |
| 727 | dest->font = desc->font; |
| 728 | dest->color = desc->color; |
| 729 | dest->flags = desc->flags; |
| 730 | dest->speed = desc->speed; |
| 731 | dest->looping = desc->looping; |
| 732 | dest->waittime = desc->waittime; |
| 733 | dest->type = desc->type; |
| 734 | dest->mission_mask_set = desc->mission_mask_set; |
| 735 | dest->mission_mask_unset = desc->mission_mask_unset; |
| 736 | |
| 737 | if (befx->text) { |
| 738 | mem_free(befx->text); |
| 739 | befx->text = NULL; |
| 740 | } |
| 741 | befx->text = (char *)mem_malloc(strlen(text) + 1); |
| 742 | ASSERT(befx->text); |
| 743 | strcpy(befx->text, text); |
| 744 | |
| 745 | // Setup for items not set with caps |
| 746 | if (!(dest->caps & TCTD_FONT)) { |
| 747 | dest->caps |= TCTD_FONT; |
| 748 | dest->font = BRIEF_FONT_INDEX; |
| 749 | } |
| 750 | if (!(dest->caps & TCTD_COLOR)) { |
| 751 | dest->caps |= TCTD_COLOR; |
| 752 | dest->color = GR_GREEN; |
| 753 | } |
| 754 | if (!(dest->caps & TCTD_SPEED)) { |
| 755 | dest->caps |= TCTD_SPEED; |
| 756 | dest->speed = 1; |
| 757 | } |
| 758 | if (!(dest->caps & TCTD_LOOPING)) { |
| 759 | dest->caps |= TCTD_LOOPING; |
| 760 | dest->looping = false; |
| 761 | } |
| 762 | if (!(dest->caps & TCTD_WAITTIME)) { |
| 763 | dest->caps |= TCTD_WAITTIME; |
| 764 | dest->waittime = 0; |
| 765 | } |
| 766 | if (!(dest->caps & TCTD_TEXTBOX)) { |
| 767 | dest->caps |= TCTD_TEXTBOX; |
| 768 | dest->textbox.left = dest->textbox.top = 0; |
| 769 | dest->textbox.right = 639; |
| 770 | dest->textbox.bottom = 479; |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | void BEAddBmpEffect(TCBMPDESC *desc, char *description) { |
| 775 | int curr_screen, curr_effect; |
| 776 | if (!BEAllocEffect(&curr_screen, &curr_effect)) |
| 777 | return; |
| 778 | |
| 779 | tBriefScreen *bscr = &Briefing_screens[curr_screen]; |
| 780 | tBriefEffect *befx = &bscr->effects[curr_effect]; |
| 781 | TCBMPDESC *dest = &befx->bmp_desc; |
| 782 | |
| 783 | if (strlen(description) == 0) |
| 784 | strcpy(description, "Bitmap"); |
| 785 | befx->type = BE_BMP; |
| 786 | strcpy(befx->description, description); |
| 787 | |
| 788 | dest->type = desc->type; |
| 789 | dest->flags = desc->flags; |
| 790 | dest->caps = desc->caps; |
| 791 | dest->x = desc->x; |
| 792 | dest->y = desc->y; |
| 793 | dest->looping = desc->looping; |
| 794 | dest->waittime = desc->waittime; |
| 795 | dest->speed = desc->speed; |
| 796 | dest->mission_mask_set = desc->mission_mask_set; |
| 797 | dest->mission_mask_unset = desc->mission_mask_unset; |
| 798 | strcpy(dest->filename, desc->filename); |
| 799 | |
| 800 | // Setup values not set with caps |
| 801 | if (!(dest->caps & TCBD_XY)) { |
| 802 | dest->caps |= TCBD_XY; |
| 803 | dest->x = dest->y = 0; |
| 804 | } |
| 805 | if (!(dest->caps & TCBD_LOOPING)) { |
| 806 | dest->caps |= TCBD_LOOPING; |
| 807 | dest->looping = false; |
| 808 | } |
| 809 | if (!(dest->caps & TCBD_WAITTIME)) { |
| 810 | dest->caps |= TCBD_WAITTIME; |
| 811 | dest->waittime = 0; |
| 812 | } |
| 813 | if (!(dest->caps & TCBD_SPEED)) { |
| 814 | dest->caps |= TCBD_SPEED; |
| 815 | dest->speed = 2; |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | void BEAddMovieEffect(TCMOVIEDESC *desc, char *description) { |
| 820 | int curr_screen, curr_effect; |
| 821 | if (!BEAllocEffect(&curr_screen, &curr_effect)) |
| 822 | return; |
| 823 | |
| 824 | tBriefScreen *bscr = &Briefing_screens[curr_screen]; |
| 825 | tBriefEffect *befx = &bscr->effects[curr_effect]; |
| 826 | TCMOVIEDESC *dest = &befx->movie_desc; |
| 827 | |
| 828 | if (strlen(description) == 0) |
| 829 | strcpy(description, "Movie"); |
| 830 | befx->type = BE_MOVIE; |
| 831 | strcpy(befx->description, description); |
| 832 | |
| 833 | dest->caps = desc->caps; |
| 834 | dest->type = desc->type; |
| 835 | dest->x = desc->x; |
| 836 | dest->y = desc->y; |
| 837 | dest->mission_mask_set = desc->mission_mask_set; |
| 838 | dest->mission_mask_unset = desc->mission_mask_unset; |
| 839 | strcpy(dest->filename, desc->filename); |
| 840 | dest->looping = desc->looping; |
| 841 | dest->fps = desc->fps; |
| 842 | dest->waittime = desc->waittime; |
| 843 | |
| 844 | // Setup values without caps |
| 845 | if (!(dest->caps & TCMD_XY)) { |
| 846 | dest->caps |= TCMD_XY; |
| 847 | dest->x = dest->y = 0; |
| 848 | } |
| 849 | if (!(dest->caps & TCMD_LOOPING)) { |
| 850 | dest->caps |= TCMD_LOOPING; |
| 851 | dest->looping = false; |
| 852 | } |
| 853 | if (!(dest->caps & TCMD_WAITTIME)) { |
| 854 | dest->caps |= TCMD_WAITTIME; |
| 855 | dest->waittime = 0; |
| 856 | } |
| 857 | if (!(dest->caps & TCMD_FPS)) { |
| 858 | dest->caps |= TCMD_FPS; |
| 859 | dest->fps = 20; |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | void BEAddBkgEffect(TCBKGDESC *desc, char *description) { |
| 864 | int curr_screen, curr_effect; |
| 865 | if (!BEAllocEffect(&curr_screen, &curr_effect)) |
| 866 | return; |
| 867 | |
| 868 | tBriefScreen *bscr = &Briefing_screens[curr_screen]; |
| 869 | tBriefEffect *befx = &bscr->effects[curr_effect]; |
| 870 | TCBKGDESC *dest = &befx->bkg_desc; |
| 871 | |
| 872 | if (strlen(description) == 0) |
| 873 | strcpy(description, "Background"); |
| 874 | befx->type = BE_BKG; |
| 875 | strcpy(befx->description, description); |
| 876 | |
| 877 | dest->caps = desc->caps; |
| 878 | dest->type = desc->type; |
| 879 | dest->id = desc->id; |
| 880 | dest->color = desc->color; |
| 881 | dest->waittime = desc->waittime; |
| 882 | dest->mission_mask_set = desc->mission_mask_set; |
| 883 | dest->mission_mask_unset = desc->mission_mask_unset; |
| 884 | |
| 885 | // setup values without caps |
| 886 | if (!(dest->caps & TCBGD_ID)) { |
| 887 | dest->caps |= TCBGD_ID; |
| 888 | dest->id = 0; |
| 889 | } |
| 890 | if (!(dest->caps & TCBGD_WAITTIME)) { |
| 891 | dest->caps |= TCBGD_WAITTIME; |
| 892 | dest->waittime = 0; |
| 893 | } |
| 894 | if (!(dest->caps & TCBGD_COLOR)) { |
| 895 | dest->caps |= TCBGD_COLOR; |
| 896 | dest->color = GR_BLUE; |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | void BEAddPolyEffect(TCPOLYDESC *desc, char *description) { |
| 901 | int curr_screen, curr_effect; |
| 902 | if (!BEAllocEffect(&curr_screen, &curr_effect)) |
| 903 | return; |
| 904 | |
| 905 | tBriefScreen *bscr = &Briefing_screens[curr_screen]; |
| 906 | tBriefEffect *befx = &bscr->effects[curr_effect]; |
| 907 | TCPOLYDESC *dest = &befx->poly_desc; |
| 908 | |
| 909 | if (strlen(description) == 0) |
| 910 | strcpy(description, "PolyModel"); |
| 911 | befx->type = BE_POLY; |
| 912 | strcpy(befx->description, description); |
| 913 | |
| 914 | dest->caps = desc->caps; |
| 915 | dest->type = desc->type; |
| 916 | dest->pos_x = desc->pos_x; |
| 917 | dest->pos_y = desc->pos_y; |
| 918 | dest->pos_z = desc->pos_z; |
| 919 | dest->rot_x = desc->rot_x; |
| 920 | dest->rot_y = desc->rot_y; |
| 921 | dest->rot_z = desc->rot_z; |
| 922 | dest->ori_x = desc->ori_x; |
| 923 | dest->ori_y = desc->ori_y; |
| 924 | dest->ori_z = desc->ori_z; |
| 925 | dest->flags = desc->flags; |
| 926 | dest->waittime = desc->waittime; |
| 927 | dest->mission_mask_set = desc->mission_mask_set; |
| 928 | dest->mission_mask_unset = desc->mission_mask_unset; |
| 929 | strcpy(dest->polyname, desc->polyname); |
| 930 | |
| 931 | Int3(); // Why are we here!?!?!?? This effect isn't even in yet |
| 932 | if (!(dest->caps & TCPM_SPEED)) { |
| 933 | dest->caps |= TCPM_SPEED; |
| 934 | dest->waittime = 0; |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | void BEAddSoundEffect(TCSNDDESC *desc, char *description) { |
| 939 | int curr_screen, curr_effect; |
| 940 | if (!BEAllocEffect(&curr_screen, &curr_effect)) |
| 941 | return; |
| 942 | |
| 943 | tBriefScreen *bscr = &Briefing_screens[curr_screen]; |
| 944 | tBriefEffect *befx = &bscr->effects[curr_effect]; |
| 945 | TCSNDDESC *dest = &befx->snd_desc; |
| 946 | |
| 947 | if (strlen(description) == 0) |
| 948 | strcpy(description, "Sound"); |
| 949 | befx->type = BE_SND; |
| 950 | strcpy(befx->description, description); |
| 951 | |
| 952 | dest->caps = desc->caps; |
| 953 | dest->type = desc->type; |
| 954 | dest->once = desc->once; |
| 955 | dest->waittime = desc->waittime; |
| 956 | dest->mission_mask_set = desc->mission_mask_set; |
| 957 | dest->mission_mask_unset = desc->mission_mask_unset; |
| 958 | strcpy(dest->filename, desc->filename); |
| 959 | |
| 960 | // Setup values without caps |
| 961 | if (!(dest->caps & TCSD_WAITTIME)) { |
| 962 | dest->caps |= TCSD_WAITTIME; |
| 963 | dest->waittime = 0; |
| 964 | } |
| 965 | if (!(dest->caps & TCSD_ONCE)) { |
| 966 | dest->caps |= TCSD_ONCE; |
| 967 | dest->once = true; |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | void BEAddButtonEffect(TCBUTTONDESC *desc, char *description, int id) { |
| 972 | int curr_screen, curr_effect; |
| 973 | if (!BEAllocEffect(&curr_screen, &curr_effect)) |
| 974 | return; |
| 975 | |
| 976 | tBriefScreen *bscr = &Briefing_screens[curr_screen]; |
| 977 | tBriefEffect *befx = &bscr->effects[curr_effect]; |
| 978 | TCBUTTONDESC *dest = &befx->button_desc; |
| 979 | |
| 980 | if (strlen(description) == 0) |
| 981 | strcpy(description, "Button"); |
| 982 | befx->type = BE_BUTTON; |
| 983 | strcpy(befx->description, description); |
| 984 | befx->id = id; |
| 985 | |
| 986 | strcpy(dest->filename, desc->filename); |
| 987 | strcpy(dest->filename_focus, desc->filename_focus); |
| 988 | if (desc->flasher) { |
| 989 | strcpy(dest->flash_filename, desc->flash_filename); |
| 990 | strcpy(dest->flash_filename_focus, desc->flash_filename_focus); |
| 991 | } else { |
| 992 | dest->flash_filename[0] = '\0'; |
| 993 | dest->flash_filename_focus[0] = '\0'; |
| 994 | } |
| 995 | dest->sibling_id = desc->sibling_id; |
| 996 | dest->parent_id = desc->parent_id; |
| 997 | dest->x = desc->x; |
| 998 | dest->y = desc->y; |
| 999 | dest->w = desc->w; |
| 1000 | dest->h = desc->h; |
| 1001 | dest->osflags = desc->osflags; |
| 1002 | dest->flash_time = desc->flash_time; |
| 1003 | dest->button_type = desc->button_type; |
| 1004 | dest->click_type = desc->click_type; |
| 1005 | dest->flasher = desc->flasher; |
| 1006 | dest->mission_mask_set = desc->mission_mask_set; |
| 1007 | dest->mission_mask_unset = desc->mission_mask_unset; |
| 1008 | dest->jump_page = desc->jump_page; |
| 1009 | } |
| 1010 | |
| 1011 | void BEStartScreen(int screen_num, char *description, char *layout, uint32_t mask_set, uint32_t mask_unset) { |
| 1012 | int scr_to_add = -1; |
| 1013 | for (int i = 0; i < MAX_TELCOM_SCREENS; i++) { |
| 1014 | if (!Briefing_screens[i].used) { |
| 1015 | scr_to_add = i; |
| 1016 | break; |
| 1017 | } |
| 1018 | } |
| 1019 | if (scr_to_add == -1) { |
| 1020 | Int3(); // out of screens |
| 1021 | return; |
| 1022 | } |
| 1023 | |
| 1024 | if (strlen(description) == 0) { |
| 1025 | sprintf(description, "Screen %d", screen_num); |
| 1026 | } |
| 1027 | |
| 1028 | BEParseInfo.current_screen++; |
| 1029 | Briefing_screens[scr_to_add].used = true; |
| 1030 | Briefing_screens[scr_to_add].mission_mask_set = mask_set; |
| 1031 | Briefing_screens[scr_to_add].mission_mask_unset = mask_unset; |
| 1032 | |
| 1033 | if (layout) |
| 1034 | strcpy(Briefing_screens[scr_to_add].layout, layout); |
| 1035 | else |
| 1036 | Briefing_screens[scr_to_add].layout[0] = '\0'; |
| 1037 | |
| 1038 | if (Briefing_root_screen == -1) { |
| 1039 | Briefing_root_screen = scr_to_add; |
| 1040 | Briefing_screens[scr_to_add].prev = Briefing_screens[scr_to_add].next = -1; |
| 1041 | } else { |
| 1042 | int node = Briefing_root_screen; |
| 1043 | while (Briefing_screens[node].next != -1) { |
| 1044 | node = Briefing_screens[node].next; |
| 1045 | } |
| 1046 | Briefing_screens[node].next = scr_to_add; |
| 1047 | Briefing_screens[scr_to_add].prev = node; |
| 1048 | Briefing_screens[scr_to_add].next = -1; |
| 1049 | } |
| 1050 | int sel = BEParseInfo.scombo->AddString(description); |
| 1051 | ASSERT(sel >= 0); |
| 1052 | BEParseInfo.scombo->SetCurSel(sel); |
| 1053 | } |
| 1054 | |
| 1055 | void BEEndScreen() {} |
| 1056 | |
| 1057 | void BESetTitle(char *title) { strcpy(BEParseInfo.glob->title, title); } |
| 1058 | |
| 1059 | void BESetStatic(float amount) { BEParseInfo.glob->static_val = amount; } |
| 1060 | |
| 1061 | void BESetGlitch(float amount) { BEParseInfo.glob->glitch_val = amount; } |
| 1062 | |
| 1063 | void BEAddVoice(char *filename, int flags, char *description) {} |
| 1064 | |
| 1065 | // BriefEditLoadScreens |
| 1066 | // |
| 1067 | // Loads in screens from a briefing file |
| 1068 | uint8_t BriefEditLoadScreens(char *filename, CComboBox *screen_combo, CComboBox *effect_combo, |
| 1069 | BriefGlobalValues *glob) { |
| 1070 | BEParseInfo.current_screen = 0; |
| 1071 | BEParseInfo.title[0] = '\0'; |
| 1072 | BEParseInfo.scombo = screen_combo; |
| 1073 | BEParseInfo.ecombo = effect_combo; |
| 1074 | BEParseInfo.glob = glob; |
| 1075 | |
| 1076 | glob->title[0] = '\0'; |
| 1077 | glob->static_val = glob->glitch_val = 0; |
| 1078 | |
| 1079 | CBriefParse engine; |
| 1080 | tBriefParseCallbacks pb_callbacks; |
| 1081 | |
| 1082 | pb_callbacks.AddTextEffect = BEAddTextEffect; |
| 1083 | pb_callbacks.AddBmpEffect = BEAddBmpEffect; |
| 1084 | pb_callbacks.AddMovieEffect = BEAddMovieEffect; |
| 1085 | pb_callbacks.AddBkgEffect = BEAddBkgEffect; |
| 1086 | pb_callbacks.AddPolyEffect = BEAddPolyEffect; |
| 1087 | pb_callbacks.AddSoundEffect = BEAddSoundEffect; |
| 1088 | pb_callbacks.AddButtonEffect = BEAddButtonEffect; |
| 1089 | pb_callbacks.StartScreen = BEStartScreen; |
| 1090 | pb_callbacks.EndScreen = BEEndScreen; |
| 1091 | pb_callbacks.LoopCallback = NULL; |
| 1092 | pb_callbacks.SetTitle = BESetTitle; |
| 1093 | pb_callbacks.SetStatic = BESetStatic; |
| 1094 | pb_callbacks.SetGlitch = BESetGlitch; |
| 1095 | pb_callbacks.AddVoice = BEAddVoice; |
| 1096 | |
| 1097 | engine.SetCallbacks(&pb_callbacks); |
| 1098 | return engine.ParseBriefing(filename); |
| 1099 | } |
| 1100 | |
| 1101 | // BriefEditAllocateEffect |
| 1102 | // |
| 1103 | // Allocates an effect (links it and all) to be edited. Returns false on error |
| 1104 | bool CBriefEdit::BriefEditAllocateEffect(int *ret_screen, int *ret_effect) { |
| 1105 | UpdateData(true); |
| 1106 | |
| 1107 | // Get the current screen |
| 1108 | int curr_screen; |
| 1109 | BriefEditGetCurScreenEffect(&curr_screen, NULL); |
| 1110 | if (curr_screen == -1) { |
| 1111 | MessageBox("You Need To Create A Screen", "Error"); |
| 1112 | return false; |
| 1113 | } |
| 1114 | |
| 1115 | ASSERT(curr_screen >= 0 && curr_screen < MAX_TELCOM_SCREENS); |
| 1116 | ASSERT(Briefing_screens[curr_screen].used); |
| 1117 | |
| 1118 | // Trace though the effect list and add the effect |
| 1119 | int curr_effect = -1; |
| 1120 | int node = Briefing_screens[curr_screen].root_effect; |
| 1121 | tBriefScreen *bscr = &Briefing_screens[curr_screen]; |
| 1122 | for (int i = 0; i < MAX_EFFECTS_PER_SCREEN; i++) { |
| 1123 | if (!bscr->effects[i].used) { |
| 1124 | curr_effect = i; |
| 1125 | break; |
| 1126 | } |
| 1127 | } |
| 1128 | if (curr_effect == -1) { |
| 1129 | // no available effects |
| 1130 | MessageBox("No More Effects Available For This Screen", "Error"); |
| 1131 | return false; |
| 1132 | } |
| 1133 | |
| 1134 | bscr->effects[i].used = true; |
| 1135 | if (node == -1) { |
| 1136 | // first effect for screen |
| 1137 | bscr->root_effect = curr_effect; |
| 1138 | bscr->effects[curr_effect].prev = bscr->effects[curr_effect].next = -1; |
| 1139 | *ret_screen = curr_screen; |
| 1140 | *ret_effect = curr_effect; |
| 1141 | return true; |
| 1142 | } else { |
| 1143 | // get to the end of effects for list |
| 1144 | while (bscr->effects[node].next != -1) { |
| 1145 | node = bscr->effects[node].next; |
| 1146 | } |
| 1147 | |
| 1148 | // when we get here node should at the end of the list |
| 1149 | bscr->effects[node].next = curr_effect; |
| 1150 | bscr->effects[curr_effect].next = -1; |
| 1151 | bscr->effects[curr_effect].prev = node; |
| 1152 | *ret_screen = curr_screen; |
| 1153 | *ret_effect = curr_effect; |
| 1154 | return true; |
| 1155 | } |
| 1156 | |
| 1157 | Int3(); |
| 1158 | return false; // unknown error |
| 1159 | } |
| 1160 | |
| 1161 | // BriefEditGetCurScreenEffect |
| 1162 | // |
| 1163 | // Fills in the current screen and effect that is being worked on |
| 1164 | void CBriefEdit::BriefEditGetCurScreenEffect(int *ret_screen, int *ret_effect) { |
| 1165 | if (ret_screen) |
| 1166 | *ret_screen = -1; |
| 1167 | if (ret_effect) |
| 1168 | *ret_effect = -1; |
| 1169 | |
| 1170 | UpdateData(true); |
| 1171 | |
| 1172 | // Get the current screen |
| 1173 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_SCREEN_LIST); |
| 1174 | int curr_screen = combo->GetCurSel(); |
| 1175 | if (curr_screen == CB_ERR) { |
| 1176 | return; |
| 1177 | } |
| 1178 | |
| 1179 | // now we need to get the real effect num |
| 1180 | int node = Briefing_root_screen; |
| 1181 | int count = curr_screen; |
| 1182 | |
| 1183 | while (node != -1 && count > 0) { |
| 1184 | count--; |
| 1185 | node = Briefing_screens[node].next; |
| 1186 | } |
| 1187 | |
| 1188 | ASSERT(count == 0); // we better be at 0 here |
| 1189 | ASSERT(node >= 0 && node < MAX_TELCOM_SCREENS); |
| 1190 | ASSERT(Briefing_screens[node].used); |
| 1191 | |
| 1192 | if (count != 0) |
| 1193 | return; |
| 1194 | |
| 1195 | if (ret_screen) |
| 1196 | *ret_screen = node; |
| 1197 | |
| 1198 | if (!ret_effect) |
| 1199 | return; |
| 1200 | |
| 1201 | // Get the current screen |
| 1202 | combo = (CComboBox *)GetDlgItem(IDC_BRIEF_EFFECT_LIST); |
| 1203 | int curr_effect = combo->GetCurSel(); |
| 1204 | if (curr_effect == CB_ERR) { |
| 1205 | return; |
| 1206 | } |
| 1207 | |
| 1208 | // now we need to get the real effect num |
| 1209 | node = Briefing_screens[curr_screen].root_effect; |
| 1210 | count = curr_effect; |
| 1211 | |
| 1212 | while (node != -1 && count > 0) { |
| 1213 | count--; |
| 1214 | node = Briefing_screens[curr_screen].effects[node].next; |
| 1215 | } |
| 1216 | |
| 1217 | // ASSERT(count==0); //we better be at 0 here |
| 1218 | if (count != 0) |
| 1219 | return; |
| 1220 | |
| 1221 | if (ret_effect) |
| 1222 | *ret_effect = node; |
| 1223 | } |
| 1224 | |
| 1225 | ///////////////////////////////////////////////////////////////////////////// |
| 1226 | // CBriefEdit message handlers |
| 1227 | |
| 1228 | void CBriefEdit::OnOK() { |
| 1229 | if (has_changed) { |
| 1230 | // they've made changes but haven't saved |
| 1231 | if (MessageBox("You haven't saved your changes, are you sure you want to quit?", "Confirm", MB_YESNO) != IDYES) { |
| 1232 | return; |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | has_changed = false; |
| 1237 | |
| 1238 | if (layouts) |
| 1239 | mem_free(layouts); |
| 1240 | if (layout_bmp > BAD_BITMAP_HANDLE) |
| 1241 | bm_FreeBitmap(layout_bmp); |
| 1242 | CDialog::OnOK(); |
| 1243 | } |
| 1244 | |
| 1245 | void CBriefEdit::OnBriefEffectBitmap() { |
| 1246 | int curr; |
| 1247 | BriefEditGetCurScreenEffect(&curr, NULL); |
| 1248 | |
| 1249 | CBriefBitmapEdit dlg(curr); |
| 1250 | if (dlg.DoModal() == IDOK) { |
| 1251 | has_changed = true; |
| 1252 | int c_scr, c_eff; |
| 1253 | if (!BriefEditAllocateEffect(&c_scr, &c_eff)) |
| 1254 | return; |
| 1255 | |
| 1256 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_EFFECT_LIST); |
| 1257 | int sel = combo->AddString(dlg.m_sDesc); |
| 1258 | ASSERT(sel >= 0); // out of memory!? |
| 1259 | combo->SetCurSel(sel); |
| 1260 | Briefing_screens[c_scr].effects[c_eff].type = BE_BMP; |
| 1261 | strncpy(Briefing_screens[c_scr].effects[c_eff].description, dlg.m_sDesc.GetBuffer(1), 127); |
| 1262 | Briefing_screens[c_scr].effects[c_eff].description[127] = '\0'; |
| 1263 | |
| 1264 | // retrieve info |
| 1265 | TCBMPDESC *dest = &Briefing_screens[c_scr].effects[c_eff].bmp_desc; |
| 1266 | TCBMPDESC *src = &dlg.desc; |
| 1267 | |
| 1268 | dest->type = src->type; |
| 1269 | dest->flags = src->flags; |
| 1270 | dest->caps = src->caps; |
| 1271 | dest->x = src->x; |
| 1272 | dest->y = src->y; |
| 1273 | dest->looping = src->looping; |
| 1274 | dest->waittime = src->waittime; |
| 1275 | dest->speed = src->speed; |
| 1276 | dest->mission_mask_set = src->mission_mask_set; |
| 1277 | dest->mission_mask_unset = src->mission_mask_unset; |
| 1278 | strcpy(dest->filename, src->filename); |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | void CBriefEdit::OnBriefEffectButton() { |
| 1283 | CBriefButtonEdit dlg; |
| 1284 | if (dlg.DoModal() == IDOK) { |
| 1285 | has_changed = true; |
| 1286 | int c_scr, c_eff; |
| 1287 | if (!BriefEditAllocateEffect(&c_scr, &c_eff)) |
| 1288 | return; |
| 1289 | |
| 1290 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_EFFECT_LIST); |
| 1291 | int sel = combo->AddString(dlg.m_sDesc); |
| 1292 | ASSERT(sel >= 0); // out of memory!? |
| 1293 | combo->SetCurSel(sel); |
| 1294 | Briefing_screens[c_scr].effects[c_eff].type = BE_BUTTON; |
| 1295 | strncpy(Briefing_screens[c_scr].effects[c_eff].description, dlg.m_sDesc.GetBuffer(1), 127); |
| 1296 | Briefing_screens[c_scr].effects[c_eff].description[127] = '\0'; |
| 1297 | |
| 1298 | // retrieve info |
| 1299 | TCBUTTONDESC *dest = &Briefing_screens[c_scr].effects[c_eff].button_desc; |
| 1300 | TCBUTTONDESC *src = &dlg.desc; |
| 1301 | |
| 1302 | strcpy(dest->filename, src->filename); |
| 1303 | strcpy(dest->filename_focus, src->filename_focus); |
| 1304 | strcpy(dest->flash_filename, src->flash_filename); |
| 1305 | strcpy(dest->flash_filename_focus, src->flash_filename_focus); |
| 1306 | dest->sibling_id = src->sibling_id; |
| 1307 | dest->parent_id = src->parent_id; |
| 1308 | dest->x = src->x; |
| 1309 | dest->y = src->y; |
| 1310 | dest->w = src->w; |
| 1311 | dest->h = src->h; |
| 1312 | dest->osflags = src->osflags; |
| 1313 | dest->flash_time = src->flash_time; |
| 1314 | dest->button_type = src->button_type; |
| 1315 | dest->click_type = src->click_type; |
| 1316 | dest->flasher = src->flasher; |
| 1317 | dest->mission_mask_set = src->mission_mask_set; |
| 1318 | dest->mission_mask_unset = src->mission_mask_unset; |
| 1319 | dest->jump_page = src->jump_page; |
| 1320 | |
| 1321 | Briefing_screens[c_scr].effects[c_eff].id = dlg.m_iID; |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | void CBriefEdit::OnBriefEffectDel() { |
| 1326 | UpdateData(true); |
| 1327 | int curr_screen, curr_effect; |
| 1328 | BriefEditGetCurScreenEffect(&curr_screen, &curr_effect); |
| 1329 | if (curr_screen == -1 || curr_effect == -1) { |
| 1330 | MessageBox("No Effects To Delete", "Error"); |
| 1331 | return; |
| 1332 | } |
| 1333 | |
| 1334 | if (MessageBox("Are You Sure You Want To Delete Effect?", "Confirmation", MB_YESNO) != IDYES) |
| 1335 | return; |
| 1336 | |
| 1337 | ASSERT(curr_screen >= 0 && curr_screen < MAX_TELCOM_SCREENS); |
| 1338 | ASSERT(curr_effect >= 0 && curr_effect < MAX_EFFECTS_PER_SCREEN); |
| 1339 | |
| 1340 | tBriefScreen *bscr = &Briefing_screens[curr_screen]; |
| 1341 | int prev = bscr->effects[curr_effect].prev; |
| 1342 | int next = bscr->effects[curr_effect].next; |
| 1343 | |
| 1344 | if (prev == -1) |
| 1345 | bscr->root_effect = next; |
| 1346 | else |
| 1347 | bscr->effects[prev].next = next; |
| 1348 | |
| 1349 | if (next != -1) |
| 1350 | bscr->effects[next].prev = prev; |
| 1351 | |
| 1352 | BriefEditFreeEffect(&bscr->effects[curr_effect]); |
| 1353 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_EFFECT_LIST); |
| 1354 | combo->DeleteString(combo->GetCurSel()); |
| 1355 | combo->SetCurSel(0); |
| 1356 | has_changed = true; |
| 1357 | UpdateData(false); |
| 1358 | } |
| 1359 | |
| 1360 | void CBriefEdit::OnBriefEffectEdit() { |
| 1361 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_EFFECT_LIST); |
| 1362 | int curr_effect = combo->GetCurSel(); |
| 1363 | |
| 1364 | int efx_index, scr_index; |
| 1365 | BriefEditGetCurScreenEffect(&scr_index, &efx_index); |
| 1366 | |
| 1367 | if (scr_index == -1 || efx_index == -1) { |
| 1368 | MessageBox("No Effects To Edit", "Error"); |
| 1369 | return; |
| 1370 | } |
| 1371 | |
| 1372 | tBriefEffect *efx = &Briefing_screens[scr_index].effects[efx_index]; |
| 1373 | |
| 1374 | switch (efx->type) { |
| 1375 | case BE_TEXT: { |
| 1376 | CBriefTextEdit dlg(scr_index, &efx->text_desc, efx->text, efx->id); |
| 1377 | combo->GetLBText(curr_effect, dlg.m_sDesc); |
| 1378 | if (dlg.DoModal() == IDOK) { |
| 1379 | has_changed = true; |
| 1380 | // grab the information from the dialog |
| 1381 | combo->DeleteString(curr_effect); |
| 1382 | combo->InsertString(curr_effect, dlg.m_sDesc); |
| 1383 | combo->SetCurSel(curr_effect); |
| 1384 | strncpy(Briefing_screens[scr_index].effects[efx_index].description, dlg.m_sDesc.GetBuffer(1), 127); |
| 1385 | Briefing_screens[scr_index].effects[efx_index].description[127] = '\0'; |
| 1386 | |
| 1387 | // retrieve info |
| 1388 | TCTEXTDESC *dest = &Briefing_screens[scr_index].effects[efx_index].text_desc; |
| 1389 | TCTEXTDESC *src = &dlg.desc; |
| 1390 | |
| 1391 | dest->caps = src->caps; |
| 1392 | memcpy(&dest->textbox, &src->textbox, sizeof(tc_text)); |
| 1393 | dest->font = src->font; |
| 1394 | dest->color = src->color; |
| 1395 | dest->flags = src->flags; |
| 1396 | dest->speed = src->speed; |
| 1397 | dest->looping = src->looping; |
| 1398 | dest->waittime = src->waittime; |
| 1399 | dest->type = src->type; |
| 1400 | dest->mission_mask_set = src->mission_mask_set; |
| 1401 | dest->mission_mask_unset = src->mission_mask_unset; |
| 1402 | |
| 1403 | Briefing_screens[scr_index].effects[efx_index].id = dlg.m_iID; |
| 1404 | |
| 1405 | if (Briefing_screens[scr_index].effects[efx_index].text) |
| 1406 | mem_free(Briefing_screens[scr_index].effects[efx_index].text); |
| 1407 | |
| 1408 | Briefing_screens[scr_index].effects[efx_index].text = (char *)mem_malloc(dlg.m_Text.GetLength() + 1); |
| 1409 | ASSERT(Briefing_screens[scr_index].effects[efx_index].text); |
| 1410 | |
| 1411 | if (Briefing_screens[scr_index].effects[efx_index].text) { |
| 1412 | strcpy(Briefing_screens[scr_index].effects[efx_index].text, dlg.m_Text.GetBuffer(1)); |
| 1413 | } |
| 1414 | } |
| 1415 | } break; |
| 1416 | case BE_BMP: { |
| 1417 | CBriefBitmapEdit dlg(scr_index, &efx->bmp_desc); |
| 1418 | combo->GetLBText(curr_effect, dlg.m_sDesc); |
| 1419 | if (dlg.DoModal() == IDOK) { |
| 1420 | has_changed = true; |
| 1421 | // grab the information from the dialog |
| 1422 | combo->DeleteString(curr_effect); |
| 1423 | combo->InsertString(curr_effect, dlg.m_sDesc); |
| 1424 | combo->SetCurSel(curr_effect); |
| 1425 | strncpy(Briefing_screens[scr_index].effects[efx_index].description, dlg.m_sDesc.GetBuffer(1), 127); |
| 1426 | Briefing_screens[scr_index].effects[efx_index].description[127] = '\0'; |
| 1427 | |
| 1428 | // retrieve info |
| 1429 | TCBMPDESC *dest = &Briefing_screens[scr_index].effects[efx_index].bmp_desc; |
| 1430 | TCBMPDESC *src = &dlg.desc; |
| 1431 | |
| 1432 | dest->type = src->type; |
| 1433 | dest->flags = src->flags; |
| 1434 | dest->caps = src->caps; |
| 1435 | dest->x = src->x; |
| 1436 | dest->y = src->y; |
| 1437 | dest->looping = src->looping; |
| 1438 | dest->waittime = src->waittime; |
| 1439 | dest->speed = src->speed; |
| 1440 | dest->mission_mask_set = src->mission_mask_set; |
| 1441 | dest->mission_mask_unset = src->mission_mask_unset; |
| 1442 | |
| 1443 | strcpy(dest->filename, src->filename); |
| 1444 | } |
| 1445 | } break; |
| 1446 | case BE_MOVIE: { |
| 1447 | CBriefMovieEdit dlg(&efx->movie_desc); |
| 1448 | combo->GetLBText(curr_effect, dlg.m_sDesc); |
| 1449 | if (dlg.DoModal() == IDOK) { |
| 1450 | has_changed = true; |
| 1451 | // grab the information from the dialog |
| 1452 | combo->DeleteString(curr_effect); |
| 1453 | combo->InsertString(curr_effect, dlg.m_sDesc); |
| 1454 | combo->SetCurSel(curr_effect); |
| 1455 | strncpy(Briefing_screens[scr_index].effects[efx_index].description, dlg.m_sDesc.GetBuffer(1), 127); |
| 1456 | Briefing_screens[scr_index].effects[efx_index].description[127] = '\0'; |
| 1457 | |
| 1458 | // retrieve info |
| 1459 | TCMOVIEDESC *dest = &Briefing_screens[scr_index].effects[efx_index].movie_desc; |
| 1460 | TCMOVIEDESC *src = &dlg.desc; |
| 1461 | |
| 1462 | dest->caps = src->caps; |
| 1463 | dest->type = src->type; |
| 1464 | dest->x = src->x; |
| 1465 | dest->y = src->y; |
| 1466 | strcpy(dest->filename, src->filename); |
| 1467 | dest->looping = src->looping; |
| 1468 | dest->fps = src->fps; |
| 1469 | dest->waittime = src->waittime; |
| 1470 | dest->mission_mask_set = src->mission_mask_set; |
| 1471 | dest->mission_mask_unset = src->mission_mask_unset; |
| 1472 | } |
| 1473 | } break; |
| 1474 | case BE_BKG: |
| 1475 | break; |
| 1476 | case BE_POLY: |
| 1477 | break; |
| 1478 | case BE_SND: { |
| 1479 | CBriefSoundEdit dlg(&efx->snd_desc); |
| 1480 | combo->GetLBText(curr_effect, dlg.m_sDesc); |
| 1481 | if (dlg.DoModal() == IDOK) { |
| 1482 | has_changed = true; |
| 1483 | // grab the information from the dialog |
| 1484 | combo->DeleteString(curr_effect); |
| 1485 | combo->InsertString(curr_effect, dlg.m_sDesc); |
| 1486 | combo->SetCurSel(curr_effect); |
| 1487 | strncpy(Briefing_screens[scr_index].effects[efx_index].description, dlg.m_sDesc.GetBuffer(1), 127); |
| 1488 | Briefing_screens[scr_index].effects[efx_index].description[127] = '\0'; |
| 1489 | |
| 1490 | // retrieve info |
| 1491 | TCSNDDESC *dest = &Briefing_screens[scr_index].effects[efx_index].snd_desc; |
| 1492 | TCSNDDESC *src = &dlg.desc; |
| 1493 | |
| 1494 | dest->caps = src->caps; |
| 1495 | dest->type = src->type; |
| 1496 | dest->once = src->once; |
| 1497 | dest->waittime = src->waittime; |
| 1498 | dest->mission_mask_set = src->mission_mask_set; |
| 1499 | dest->mission_mask_unset = src->mission_mask_unset; |
| 1500 | strcpy(dest->filename, src->filename); |
| 1501 | } |
| 1502 | } break; |
| 1503 | case BE_BUTTON: { |
| 1504 | CBriefButtonEdit dlg(&efx->button_desc, efx->id); |
| 1505 | combo->GetLBText(curr_effect, dlg.m_sDesc); |
| 1506 | if (dlg.DoModal() == IDOK) { |
| 1507 | has_changed = true; |
| 1508 | // grab the information from the dialog |
| 1509 | combo->DeleteString(curr_effect); |
| 1510 | combo->InsertString(curr_effect, dlg.m_sDesc); |
| 1511 | combo->SetCurSel(curr_effect); |
| 1512 | strncpy(Briefing_screens[scr_index].effects[efx_index].description, dlg.m_sDesc.GetBuffer(1), 127); |
| 1513 | Briefing_screens[scr_index].effects[efx_index].description[127] = '\0'; |
| 1514 | |
| 1515 | // retrieve info |
| 1516 | TCBUTTONDESC *dest = &Briefing_screens[scr_index].effects[efx_index].button_desc; |
| 1517 | TCBUTTONDESC *src = &dlg.desc; |
| 1518 | |
| 1519 | strcpy(dest->filename, src->filename); |
| 1520 | strcpy(dest->filename_focus, src->filename_focus); |
| 1521 | strcpy(dest->flash_filename, src->flash_filename); |
| 1522 | strcpy(dest->flash_filename_focus, src->flash_filename_focus); |
| 1523 | dest->sibling_id = src->sibling_id; |
| 1524 | dest->parent_id = src->parent_id; |
| 1525 | dest->x = src->x; |
| 1526 | dest->y = src->y; |
| 1527 | dest->w = src->w; |
| 1528 | dest->h = src->h; |
| 1529 | dest->osflags = src->osflags; |
| 1530 | dest->flash_time = src->flash_time; |
| 1531 | dest->button_type = src->button_type; |
| 1532 | dest->click_type = src->click_type; |
| 1533 | dest->flasher = src->flasher; |
| 1534 | dest->mission_mask_set = src->mission_mask_set; |
| 1535 | dest->mission_mask_unset = src->mission_mask_unset; |
| 1536 | dest->jump_page = src->jump_page; |
| 1537 | |
| 1538 | Briefing_screens[scr_index].effects[efx_index].id = dlg.m_iID; |
| 1539 | } |
| 1540 | } break; |
| 1541 | default: |
| 1542 | Int3(); |
| 1543 | return; |
| 1544 | break; |
| 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | void CBriefEdit::OnBriefEffectMovie() { |
| 1549 | CBriefMovieEdit dlg; |
| 1550 | if (dlg.DoModal() == IDOK) { |
| 1551 | has_changed = true; |
| 1552 | int c_scr, c_eff; |
| 1553 | if (!BriefEditAllocateEffect(&c_scr, &c_eff)) |
| 1554 | return; |
| 1555 | |
| 1556 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_EFFECT_LIST); |
| 1557 | int sel = combo->AddString(dlg.m_sDesc); |
| 1558 | ASSERT(sel >= 0); // out of memory!? |
| 1559 | combo->SetCurSel(sel); |
| 1560 | Briefing_screens[c_scr].effects[c_eff].type = BE_MOVIE; |
| 1561 | strncpy(Briefing_screens[c_scr].effects[c_eff].description, dlg.m_sDesc.GetBuffer(1), 127); |
| 1562 | Briefing_screens[c_scr].effects[c_eff].description[127] = '\0'; |
| 1563 | |
| 1564 | // retrieve info |
| 1565 | TCMOVIEDESC *dest = &Briefing_screens[c_scr].effects[c_eff].movie_desc; |
| 1566 | TCMOVIEDESC *src = &dlg.desc; |
| 1567 | |
| 1568 | dest->caps = src->caps; |
| 1569 | dest->type = src->type; |
| 1570 | dest->x = src->x; |
| 1571 | dest->y = src->y; |
| 1572 | strcpy(dest->filename, src->filename); |
| 1573 | dest->looping = src->looping; |
| 1574 | dest->fps = src->fps; |
| 1575 | dest->waittime = src->waittime; |
| 1576 | dest->mission_mask_set = src->mission_mask_set; |
| 1577 | dest->mission_mask_unset = src->mission_mask_unset; |
| 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | void CBriefEdit::OnBriefEffectSound() { |
| 1582 | CBriefSoundEdit dlg; |
| 1583 | if (dlg.DoModal() == IDOK) { |
| 1584 | has_changed = true; |
| 1585 | int c_scr, c_eff; |
| 1586 | if (!BriefEditAllocateEffect(&c_scr, &c_eff)) |
| 1587 | return; |
| 1588 | |
| 1589 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_EFFECT_LIST); |
| 1590 | int sel = combo->AddString(dlg.m_sDesc); |
| 1591 | ASSERT(sel >= 0); // out of memory!? |
| 1592 | combo->SetCurSel(sel); |
| 1593 | Briefing_screens[c_scr].effects[c_eff].type = BE_SND; |
| 1594 | strncpy(Briefing_screens[c_scr].effects[c_eff].description, dlg.m_sDesc.GetBuffer(1), 127); |
| 1595 | Briefing_screens[c_scr].effects[c_eff].description[127] = '\0'; |
| 1596 | |
| 1597 | // retrieve info |
| 1598 | TCSNDDESC *dest = &Briefing_screens[c_scr].effects[c_eff].snd_desc; |
| 1599 | TCSNDDESC *src = &dlg.desc; |
| 1600 | |
| 1601 | dest->caps = src->caps; |
| 1602 | dest->type = src->type; |
| 1603 | dest->once = src->once; |
| 1604 | dest->waittime = src->waittime; |
| 1605 | dest->mission_mask_set = src->mission_mask_set; |
| 1606 | dest->mission_mask_unset = src->mission_mask_unset; |
| 1607 | |
| 1608 | strcpy(dest->filename, src->filename); |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | void CBriefEdit::OnBriefEffectText() { |
| 1613 | int curr; |
| 1614 | BriefEditGetCurScreenEffect(&curr, NULL); |
| 1615 | |
| 1616 | CBriefTextEdit dlg(curr); |
| 1617 | if (dlg.DoModal() == IDOK) { |
| 1618 | has_changed = true; |
| 1619 | int c_scr, c_eff; |
| 1620 | if (!BriefEditAllocateEffect(&c_scr, &c_eff)) |
| 1621 | return; |
| 1622 | |
| 1623 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_EFFECT_LIST); |
| 1624 | int sel = combo->AddString(dlg.m_sDesc); |
| 1625 | ASSERT(sel >= 0); // out of memory!? |
| 1626 | combo->SetCurSel(sel); |
| 1627 | Briefing_screens[c_scr].effects[c_eff].type = BE_TEXT; |
| 1628 | strncpy(Briefing_screens[c_scr].effects[c_eff].description, dlg.m_sDesc.GetBuffer(1), 127); |
| 1629 | Briefing_screens[c_scr].effects[c_eff].description[127] = '\0'; |
| 1630 | |
| 1631 | // retrieve info |
| 1632 | TCTEXTDESC *dest = &Briefing_screens[c_scr].effects[c_eff].text_desc; |
| 1633 | TCTEXTDESC *src = &dlg.desc; |
| 1634 | |
| 1635 | dest->caps = src->caps; |
| 1636 | memcpy(&dest->textbox, &src->textbox, sizeof(tc_text)); |
| 1637 | dest->font = src->font; |
| 1638 | dest->color = src->color; |
| 1639 | dest->flags = src->flags; |
| 1640 | dest->speed = src->speed; |
| 1641 | dest->looping = src->looping; |
| 1642 | dest->waittime = src->waittime; |
| 1643 | dest->type = src->type; |
| 1644 | dest->mission_mask_set = src->mission_mask_set; |
| 1645 | dest->mission_mask_unset = src->mission_mask_unset; |
| 1646 | |
| 1647 | Briefing_screens[c_scr].effects[c_eff].id = dlg.m_iID; |
| 1648 | |
| 1649 | if (Briefing_screens[c_scr].effects[c_eff].text) |
| 1650 | mem_free(Briefing_screens[c_scr].effects[c_eff].text); |
| 1651 | |
| 1652 | Briefing_screens[c_scr].effects[c_eff].text = (char *)mem_malloc(dlg.m_Text.GetLength() + 1); |
| 1653 | ASSERT(Briefing_screens[c_scr].effects[c_eff].text); |
| 1654 | |
| 1655 | if (Briefing_screens[c_scr].effects[c_eff].text) { |
| 1656 | strcpy(Briefing_screens[c_scr].effects[c_eff].text, dlg.m_Text.GetBuffer(1)); |
| 1657 | } |
| 1658 | } |
| 1659 | } |
| 1660 | |
| 1661 | void CBriefEdit::OnBriefScreenAdd() { |
| 1662 | CBriefScreenEdit dlg; |
| 1663 | |
| 1664 | if (dlg.DoModal() == IDOK) { |
| 1665 | has_changed = true; |
| 1666 | int scr_to_add = -1; |
| 1667 | |
| 1668 | for (int i = 0; i < MAX_TELCOM_SCREENS; i++) { |
| 1669 | if (!Briefing_screens[i].used) { |
| 1670 | scr_to_add = i; |
| 1671 | break; |
| 1672 | } |
| 1673 | } |
| 1674 | if (scr_to_add == -1) { |
| 1675 | MessageBox("Out of Screens", "Error"); |
| 1676 | return; |
| 1677 | } |
| 1678 | |
| 1679 | Briefing_screens[scr_to_add].used = true; |
| 1680 | strcpy(Briefing_screens[scr_to_add].layout, dlg.layout_str.GetBuffer(0)); |
| 1681 | Briefing_screens[scr_to_add].mission_mask_set = dlg.m_Set; |
| 1682 | Briefing_screens[scr_to_add].mission_mask_unset = dlg.m_UnSet; |
| 1683 | |
| 1684 | if (Briefing_root_screen == -1) { |
| 1685 | Briefing_root_screen = scr_to_add; |
| 1686 | Briefing_screens[scr_to_add].prev = Briefing_screens[scr_to_add].next = -1; |
| 1687 | } else { |
| 1688 | int node = Briefing_root_screen; |
| 1689 | while (Briefing_screens[node].next != -1) { |
| 1690 | node = Briefing_screens[node].next; |
| 1691 | } |
| 1692 | Briefing_screens[node].next = scr_to_add; |
| 1693 | Briefing_screens[scr_to_add].prev = node; |
| 1694 | Briefing_screens[scr_to_add].next = -1; |
| 1695 | } |
| 1696 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_SCREEN_LIST); |
| 1697 | int sel = combo->AddString(dlg.m_sDesc); |
| 1698 | ASSERT(sel >= 0); |
| 1699 | combo->SetCurSel(sel); |
| 1700 | OnSelchangeBriefScreenList(); |
| 1701 | UpdateLayoutBitmap(); |
| 1702 | mprintf(0, "Added a screen\n"); |
| 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | void CBriefEdit::OnBriefScreenDel() { |
| 1707 | UpdateData(true); |
| 1708 | int curr_screen; |
| 1709 | BriefEditGetCurScreenEffect(&curr_screen, NULL); |
| 1710 | if (curr_screen == -1) { |
| 1711 | MessageBox("No Screens To Delete", "Error"); |
| 1712 | return; |
| 1713 | } |
| 1714 | |
| 1715 | if (MessageBox("Are You Sure You Want To Delete Screen?", "Confirmation", MB_YESNO) != IDYES) |
| 1716 | return; |
| 1717 | |
| 1718 | has_changed = true; |
| 1719 | |
| 1720 | int next, prev; |
| 1721 | |
| 1722 | ASSERT(curr_screen >= 0 && curr_screen < MAX_TELCOM_SCREENS); |
| 1723 | next = Briefing_screens[curr_screen].next; |
| 1724 | prev = Briefing_screens[curr_screen].prev; |
| 1725 | |
| 1726 | if (prev == -1) { |
| 1727 | Briefing_root_screen = next; |
| 1728 | } else { |
| 1729 | Briefing_screens[prev].next = next; |
| 1730 | } |
| 1731 | |
| 1732 | if (next != -1) |
| 1733 | Briefing_screens[next].prev = prev; |
| 1734 | |
| 1735 | // free the screen |
| 1736 | BriefEditFreeScreen(&Briefing_screens[curr_screen]); |
| 1737 | |
| 1738 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_SCREEN_LIST); |
| 1739 | combo->DeleteString(combo->GetCurSel()); |
| 1740 | combo->SetCurSel(0); |
| 1741 | OnSelchangeBriefScreenList(); |
| 1742 | UpdateData(false); |
| 1743 | } |
| 1744 | |
| 1745 | void CBriefEdit::OnBriefScreenEdit() { |
| 1746 | UpdateData(true); |
| 1747 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_SCREEN_LIST); |
| 1748 | int curr_screen = combo->GetCurSel(); |
| 1749 | |
| 1750 | int scr_index; |
| 1751 | BriefEditGetCurScreenEffect(&scr_index, NULL); |
| 1752 | |
| 1753 | if (scr_index == -1) { |
| 1754 | MessageBox("No Screens To Edit", "Error"); |
| 1755 | return; |
| 1756 | } |
| 1757 | |
| 1758 | CBriefScreenEdit dlg(scr_index); |
| 1759 | combo->GetLBText(curr_screen, dlg.m_sDesc); |
| 1760 | |
| 1761 | if (dlg.DoModal() == IDOK) { |
| 1762 | has_changed = true; |
| 1763 | // grab the information from the dialog |
| 1764 | combo->DeleteString(curr_screen); |
| 1765 | combo->InsertString(curr_screen, dlg.m_sDesc); |
| 1766 | combo->SetCurSel(curr_screen); |
| 1767 | |
| 1768 | strcpy(Briefing_screens[scr_index].layout, dlg.layout_str.GetBuffer(1)); |
| 1769 | Briefing_screens[scr_index].mission_mask_set = dlg.m_Set; |
| 1770 | Briefing_screens[scr_index].mission_mask_unset = dlg.m_UnSet; |
| 1771 | UpdateLayoutBitmap(); |
| 1772 | } |
| 1773 | UpdateData(false); |
| 1774 | } |
| 1775 | |
| 1776 | void CBriefEdit::UpdateInfo() {} |
| 1777 | |
| 1778 | BOOL CBriefEdit::OnInitDialog() { |
| 1779 | CDialog::OnInitDialog(); |
| 1780 | |
| 1781 | // Start the timer |
| 1782 | CWnd::SetTimer(1, 50, NULL); |
| 1783 | |
| 1784 | BriefEditInitScreens(); |
| 1785 | |
| 1786 | UpdateInfo(); |
| 1787 | has_changed = false; |
| 1788 | |
| 1789 | return TRUE; |
| 1790 | } |
| 1791 | |
| 1792 | void CBriefEdit::OnDestroy() { |
| 1793 | CDialog::OnDestroy(); |
| 1794 | |
| 1795 | BriefEditFreeScreens(); |
| 1796 | } |
| 1797 | |
| 1798 | void CBriefEdit::OnSelchangeBriefScreenList() { |
| 1799 | CComboBox *scr_combo = (CComboBox *)GetDlgItem(IDC_BRIEF_SCREEN_LIST); |
| 1800 | CComboBox *eff_combo = (CComboBox *)GetDlgItem(IDC_BRIEF_EFFECT_LIST); |
| 1801 | eff_combo->ResetContent(); |
| 1802 | |
| 1803 | int curr_screen; |
| 1804 | |
| 1805 | BriefEditGetCurScreenEffect(&curr_screen, NULL); |
| 1806 | if (curr_screen == -1) |
| 1807 | return; |
| 1808 | |
| 1809 | // now go through the new screen and add effects |
| 1810 | int node = Briefing_screens[curr_screen].root_effect; |
| 1811 | tBriefScreen *bscr = &Briefing_screens[curr_screen]; |
| 1812 | while (node != -1) { |
| 1813 | switch (bscr->effects[node].type) { |
| 1814 | case BE_TEXT: |
| 1815 | case BE_BMP: |
| 1816 | case BE_MOVIE: |
| 1817 | case BE_BKG: |
| 1818 | case BE_POLY: |
| 1819 | case BE_SND: |
| 1820 | case BE_BUTTON: |
| 1821 | eff_combo->AddString(bscr->effects[node].description); |
| 1822 | break; |
| 1823 | default: |
| 1824 | eff_combo->AddString("Unknown"); |
| 1825 | break; |
| 1826 | } |
| 1827 | node = bscr->effects[node].next; |
| 1828 | } |
| 1829 | eff_combo->SetCurSel(0); |
| 1830 | |
| 1831 | UpdateLayoutBitmap(); |
| 1832 | } |
| 1833 | |
| 1834 | void CBriefEdit::OnBriefSave() { |
| 1835 | UpdateData(true); |
| 1836 | char szFilter[] = "Descent3 Briefing Files (*.brf)|*.brf||"; |
| 1837 | CFileDialog dlg(false, ".brf", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter); |
| 1838 | |
| 1839 | if (dlg.DoModal() == IDOK) { |
| 1840 | has_changed = false; |
| 1841 | m_GlobalValues.static_val = m_fStatic; |
| 1842 | m_GlobalValues.glitch_val = m_fGlitch; |
| 1843 | strcpy(m_GlobalValues.title, m_sTitle.GetBuffer(1)); |
| 1844 | |
| 1845 | BriefEditSaveScreens(dlg.GetPathName().GetBuffer(1), (CComboBox *)GetDlgItem(IDC_BRIEF_SCREEN_LIST), |
| 1846 | &m_GlobalValues); |
| 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | void CBriefEdit::OnLoad() { |
| 1851 | char szFilter[] = "Descent3 Briefing Files (*.brf)|*.brf||"; |
| 1852 | CFileDialog dlg(true, ".brf", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter); |
| 1853 | |
| 1854 | if (dlg.DoModal() == IDOK) { |
| 1855 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_SCREEN_LIST); |
| 1856 | combo->ResetContent(); |
| 1857 | BriefEditFreeScreens(); |
| 1858 | BriefEditInitScreens(); |
| 1859 | BriefEditLoadScreens(dlg.GetPathName().GetBuffer(1), combo, (CComboBox *)GetDlgItem(IDC_BRIEF_EFFECT_LIST), |
| 1860 | &m_GlobalValues); |
| 1861 | |
| 1862 | m_fStatic = m_GlobalValues.static_val; |
| 1863 | m_fGlitch = m_GlobalValues.glitch_val; |
| 1864 | m_sTitle = m_GlobalValues.title; |
| 1865 | |
| 1866 | UpdateData(false); |
| 1867 | UpdateInfo(); |
| 1868 | OnSelchangeBriefScreenList(); |
| 1869 | UpdateLayoutBitmap(); |
| 1870 | has_changed = false; |
| 1871 | } |
| 1872 | } |
| 1873 | |
| 1874 | void CBriefEdit::UpdateLayoutBitmap(void) { |
| 1875 | int scr; |
| 1876 | BriefEditGetCurScreenEffect(&scr, NULL); |
| 1877 | if (scr == -1) |
| 1878 | return; |
| 1879 | |
| 1880 | SetLayoutBitmap(Briefing_screens[scr].layout); |
| 1881 | } |
| 1882 | |
| 1883 | void CBriefEdit::SetLayoutBitmap(char *filename) { |
| 1884 | if (layout_bmp > BAD_BITMAP_HANDLE) |
| 1885 | bm_FreeBitmap(layout_bmp); |
| 1886 | |
| 1887 | layout_bmp = -1; |
| 1888 | |
| 1889 | if (filename[0] != '\0') |
| 1890 | layout_bmp = bm_AllocLoadFileBitmap(filename, 0); |
| 1891 | has_changed = true; |
| 1892 | } |
| 1893 | |
| 1894 | void CBriefEdit::ParseLayoutScreenFile(char *filename) { |
| 1895 | CFILE *file = cfopen(filename, "rt"); |
| 1896 | if (!file) |
| 1897 | return; |
| 1898 | |
| 1899 | num_layouts = 0; |
| 1900 | if (layouts) { |
| 1901 | mem_free(layouts); |
| 1902 | layouts = NULL; |
| 1903 | } |
| 1904 | |
| 1905 | char buffer[512]; |
| 1906 | |
| 1907 | cf_ReadString(buffer, 512, file); |
| 1908 | num_layouts = atoi(buffer); |
| 1909 | |
| 1910 | if (num_layouts <= 0) { |
| 1911 | cfclose(file); |
| 1912 | mprintf(0, "Zero or less Layout Screens in Layout File\n"); |
| 1913 | return; |
| 1914 | } |
| 1915 | |
| 1916 | layouts = (tLayoutScreen *)mem_malloc(sizeof(tLayoutScreen) * num_layouts); |
| 1917 | if (!layouts) { |
| 1918 | mprintf(0, "Out of memory loading layout screens...trying to load %d screens\n", num_layouts); |
| 1919 | num_layouts = 0; |
| 1920 | cfclose(file); |
| 1921 | return; |
| 1922 | } |
| 1923 | |
| 1924 | memset(layouts, 0, sizeof(tLayoutScreen) * num_layouts); |
| 1925 | |
| 1926 | // format of a layout def. |
| 1927 | //--filename |
| 1928 | //--number of text boxes |
| 1929 | //--number of bmp boxes |
| 1930 | //----textbox defs |
| 1931 | //-----lx ty rx by |
| 1932 | //----bmp defs |
| 1933 | //-----x y |
| 1934 | |
| 1935 | for (int i = 0; i < num_layouts; i++) { |
| 1936 | // read filename |
| 1937 | cf_ReadString(layouts[i].filename, _MAX_PATH, file); |
| 1938 | |
| 1939 | // read num of text boxes |
| 1940 | cf_ReadString(buffer, 512, file); |
| 1941 | layouts[i].num_texts = atoi(buffer); |
| 1942 | ASSERT(layouts[i].num_texts >= 0 && layouts[i].num_texts < MAX_LAYOUT_PREDEFS); |
| 1943 | |
| 1944 | // read num of bmp boxes |
| 1945 | cf_ReadString(buffer, 512, file); |
| 1946 | layouts[i].num_bmps = atoi(buffer); |
| 1947 | ASSERT(layouts[i].num_bmps >= 0 && layouts[i].num_bmps < MAX_LAYOUT_PREDEFS); |
| 1948 | |
| 1949 | // read textbox defs |
| 1950 | for (int j = 0; j < layouts[i].num_texts; j++) { |
| 1951 | cf_ReadString(buffer, 512, file); |
| 1952 | |
| 1953 | // now parse to pull out the individual values |
| 1954 | char *lxp, *rxp, *typ, *byp; |
| 1955 | lxp = rxp = typ = byp = NULL; |
| 1956 | |
| 1957 | char *p = buffer; |
| 1958 | |
| 1959 | while ((*p) && (*p == ' ')) |
| 1960 | p++; |
| 1961 | lxp = p; |
| 1962 | while ((*p) && (*p != ' ')) |
| 1963 | p++; |
| 1964 | *p = '\0'; |
| 1965 | p++; |
| 1966 | while ((*p) && (*p == ' ')) |
| 1967 | p++; |
| 1968 | typ = p; |
| 1969 | while ((*p) && (*p != ' ')) |
| 1970 | p++; |
| 1971 | *p = '\0'; |
| 1972 | p++; |
| 1973 | while ((*p) && (*p == ' ')) |
| 1974 | p++; |
| 1975 | rxp = p; |
| 1976 | while ((*p) && (*p != ' ')) |
| 1977 | p++; |
| 1978 | *p = '\0'; |
| 1979 | p++; |
| 1980 | while ((*p) && (*p == ' ')) |
| 1981 | p++; |
| 1982 | byp = p; |
| 1983 | |
| 1984 | ASSERT((*lxp != 0) && (*rxp != 0) && (*typ != 0) && (*byp != 0)); |
| 1985 | layouts[i].texts[j].lx = atoi(lxp); |
| 1986 | layouts[i].texts[j].rx = atoi(rxp); |
| 1987 | layouts[i].texts[j].ty = atoi(typ); |
| 1988 | layouts[i].texts[j].by = atoi(byp); |
| 1989 | } |
| 1990 | |
| 1991 | // read bmp defs |
| 1992 | for (j = 0; j < layouts[i].num_bmps; j++) { |
| 1993 | cf_ReadString(buffer, 512, file); |
| 1994 | |
| 1995 | // now parse to pull out the individual values |
| 1996 | char *xp, *yp; |
| 1997 | xp = yp = NULL; |
| 1998 | |
| 1999 | char *p = buffer; |
| 2000 | |
| 2001 | while ((*p) && (*p == ' ')) |
| 2002 | p++; |
| 2003 | xp = p; |
| 2004 | while ((*p) && (*p != ' ')) |
| 2005 | p++; |
| 2006 | *p = '\0'; |
| 2007 | p++; |
| 2008 | while ((*p) && (*p == ' ')) |
| 2009 | p++; |
| 2010 | yp = p; |
| 2011 | |
| 2012 | ASSERT((*xp != 0) && (*yp != 0)); |
| 2013 | layouts[i].bmps[j].x = atoi(xp); |
| 2014 | layouts[i].bmps[j].y = atoi(yp); |
| 2015 | } |
| 2016 | } |
| 2017 | cfclose(file); |
| 2018 | } |
| 2019 | |
| 2020 | int bmw, bmh; |
| 2021 | |
| 2022 | void CBriefEdit::DrawRect(ddgr_color color, int lx, int ty, int rx, int by, grViewport *vport) { |
| 2023 | if (lx < 0) |
| 2024 | lx = 0; |
| 2025 | if (lx > (bmw - 1)) |
| 2026 | lx = bmw - 1; |
| 2027 | if (rx < 0) |
| 2028 | rx = 0; |
| 2029 | if (rx > (bmw - 1)) |
| 2030 | rx = bmw - 1; |
| 2031 | if (ty < 0) |
| 2032 | ty = 0; |
| 2033 | if (ty > (bmh - 1)) |
| 2034 | ty = bmh - 1; |
| 2035 | if (by < 0) |
| 2036 | by = 0; |
| 2037 | if (by > (bmh - 1)) |
| 2038 | by = bmh - 1; |
| 2039 | |
| 2040 | // vport->fillrect(color,lx,ty,rx,by); |
| 2041 | vport->line(color, lx, ty, lx, by); |
| 2042 | vport->line(color, rx, ty, rx, by); |
| 2043 | vport->line(color, lx, ty, rx, ty); |
| 2044 | vport->line(color, lx, by, rx, by); |
| 2045 | } |
| 2046 | |
| 2047 | void CBriefEdit::UpdateView(void) { |
| 2048 | CWnd *objwnd; |
| 2049 | RECT rect; |
| 2050 | int x, y, w, h; |
| 2051 | |
| 2052 | objwnd = GetDlgItem(IDC_BRIEF_PICTURE); |
| 2053 | objwnd->GetWindowRect(&rect); |
| 2054 | ScreenToClient(&rect); |
| 2055 | |
| 2056 | if (layout_bmp > BAD_BITMAP_HANDLE) { |
| 2057 | bmw = bm_w(layout_bmp, 0); |
| 2058 | bmh = bm_h(layout_bmp, 0); |
| 2059 | } else { |
| 2060 | bmw = 640; |
| 2061 | bmh = 480; |
| 2062 | } |
| 2063 | |
| 2064 | static float age = 0; |
| 2065 | static bool on = false; |
| 2066 | static float last_time = 0; |
| 2067 | |
| 2068 | float t = timer_GetTime(); |
| 2069 | float frametime = t - last_time; |
| 2070 | last_time = t; |
| 2071 | |
| 2072 | age += frametime; |
| 2073 | |
| 2074 | if (age > 0.5) { |
| 2075 | on = !on; |
| 2076 | age = 0; |
| 2077 | } |
| 2078 | |
| 2079 | rend_StartFrame(0, 0, bmw, bmh); |
| 2080 | |
| 2081 | Desktop_surf->attach_to_window((unsigned)m_hWnd); |
| 2082 | |
| 2083 | w = rect.right - rect.left; |
| 2084 | h = rect.bottom - rect.top; |
| 2085 | |
| 2086 | static bool first_call = true; |
| 2087 | |
| 2088 | if (first_call) |
| 2089 | Desktop_surf->clear(rect.left, rect.top, w, h); |
| 2090 | |
| 2091 | m_ObjectSurf.create(bmw, bmh, BPP_16); |
| 2092 | |
| 2093 | if (layout_bmp > BAD_BITMAP_HANDLE) { |
| 2094 | m_ObjectSurf.load(layout_bmp); |
| 2095 | } else |
| 2096 | Desktop_surf->clear(rect.left, rect.top, w, h); |
| 2097 | |
| 2098 | grViewport *vport = new grViewport(&m_ObjectSurf); |
| 2099 | vport->lock(); |
| 2100 | |
| 2101 | // now we need to go through all the effects in the screen and draw a rep of em |
| 2102 | int curr_screen, curr_effect; |
| 2103 | int node; |
| 2104 | tBriefEffect *effects; |
| 2105 | BriefEditGetCurScreenEffect(&curr_screen, &curr_effect); |
| 2106 | |
| 2107 | if (curr_screen != -1) { |
| 2108 | node = Briefing_screens[curr_screen].root_effect; |
| 2109 | effects = Briefing_screens[curr_screen].effects; |
| 2110 | |
| 2111 | while (node != -1) { |
| 2112 | if (node == curr_effect && !on) { |
| 2113 | } else { |
| 2114 | switch (effects[node].type) { |
| 2115 | case BE_TEXT: |
| 2116 | DrawRect(GR_RGB(255, 40, 255), effects[node].text_desc.textbox.left, effects[node].text_desc.textbox.top, |
| 2117 | effects[node].text_desc.textbox.right, effects[node].text_desc.textbox.bottom, vport); |
| 2118 | break; |
| 2119 | case BE_BMP: { |
| 2120 | if (effects[node].w == -1) { |
| 2121 | // we need to set up values |
| 2122 | int handle = bm_AllocLoadFileBitmap(effects[node].bmp_desc.filename, 0); |
| 2123 | if (handle > BAD_BITMAP_HANDLE) { |
| 2124 | effects[node].w = bm_w(handle, 0); |
| 2125 | effects[node].h = bm_h(handle, 0); |
| 2126 | bm_FreeBitmap(handle); |
| 2127 | } else { |
| 2128 | effects[node].w = effects[node].h = 16; |
| 2129 | } |
| 2130 | } |
| 2131 | int x, y, w, h; |
| 2132 | x = effects[node].bmp_desc.x; |
| 2133 | y = effects[node].bmp_desc.y; |
| 2134 | w = effects[node].w - 1; |
| 2135 | h = effects[node].h - 1; |
| 2136 | DrawRect(GR_RGB(40, 255, 40), x, y, x + w, y + h, vport); |
| 2137 | } break; |
| 2138 | case BE_MOVIE: |
| 2139 | break; |
| 2140 | case BE_BKG: |
| 2141 | break; |
| 2142 | case BE_POLY: |
| 2143 | break; |
| 2144 | case BE_BUTTON: |
| 2145 | if (effects[node].w == -1) { |
| 2146 | // we need to set up values |
| 2147 | int handle = bm_AllocLoadFileBitmap(effects[node].button_desc.filename, 0); |
| 2148 | if (handle > BAD_BITMAP_HANDLE) { |
| 2149 | effects[node].w = bm_w(handle, 0); |
| 2150 | effects[node].h = bm_h(handle, 0); |
| 2151 | bm_FreeBitmap(handle); |
| 2152 | } else { |
| 2153 | effects[node].w = effects[node].h = 16; |
| 2154 | } |
| 2155 | } |
| 2156 | int x, y, w, h; |
| 2157 | x = effects[node].button_desc.x; |
| 2158 | y = effects[node].button_desc.y; |
| 2159 | w = effects[node].w - 1; |
| 2160 | h = effects[node].h - 1; |
| 2161 | DrawRect(GR_RGB(255, 255, 40), x, y, x + w, y + h, vport); |
| 2162 | break; |
| 2163 | } |
| 2164 | } |
| 2165 | node = effects[node].next; |
| 2166 | } |
| 2167 | } |
| 2168 | |
| 2169 | vport->unlock(); |
| 2170 | x = rect.left + (w / 2) - m_ObjectSurf.width() / 2; |
| 2171 | y = rect.top + (h / 2) - m_ObjectSurf.height() / 2; |
| 2172 | |
| 2173 | Desktop_surf->blt(x, y, &m_ObjectSurf); |
| 2174 | |
| 2175 | rend_EndFrame(); |
| 2176 | |
| 2177 | delete vport; |
| 2178 | m_ObjectSurf.free(); |
| 2179 | Desktop_surf->attach_to_window((unsigned)NULL); |
| 2180 | |
| 2181 | if (first_call) |
| 2182 | first_call = false; |
| 2183 | } |
| 2184 | |
| 2185 | void CBriefEdit::OnTimer(UINT nIDEvent) { |
| 2186 | UpdateView(); |
| 2187 | CDialog::OnTimer(nIDEvent); |
| 2188 | } |
| 2189 | |
| 2190 | void CBriefEdit::OnManage() { |
| 2191 | CBriefManage dlg; |
| 2192 | dlg.DoModal(); |
| 2193 | } |