| 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 | // BriefManage.cpp : implementation file |
| 20 | // |
| 21 | |
| 22 | #include "stdafx.h" |
| 23 | #include "BriefManage.h" |
| 24 | #include "editor.h" |
| 25 | #include "ddio.h" |
| 26 | #include "manage.h" |
| 27 | #include "pserror.h" |
| 28 | #include "pstypes.h" |
| 29 | #include "gamefile.h" |
| 30 | #include "soundpage.h" |
| 31 | #include "editlinedialog.h" |
| 32 | |
| 33 | #ifdef _DEBUG |
| 34 | #define new DEBUG_NEW |
| 35 | #undef THIS_FILE |
| 36 | static char THIS_FILE[] = __FILE__; |
| 37 | #endif |
| 38 | |
| 39 | ///////////////////////////////////////////////////////////////////////////// |
| 40 | // CBriefManage dialog |
| 41 | |
| 42 | CBriefManage::CBriefManage(CWnd *pParent /*=NULL*/) : CDialog(CBriefManage::IDD, pParent) { |
| 43 | //{{AFX_DATA_INIT(CBriefManage) |
| 44 | // NOTE: the ClassWizard will add member initialization here |
| 45 | //}}AFX_DATA_INIT |
| 46 | } |
| 47 | |
| 48 | void CBriefManage::DoDataExchange(CDataExchange *pDX) { |
| 49 | CDialog::DoDataExchange(pDX); |
| 50 | //{{AFX_DATA_MAP(CBriefManage) |
| 51 | DDX_Control(pDX, IDC_LIST, m_List); |
| 52 | //}}AFX_DATA_MAP |
| 53 | } |
| 54 | |
| 55 | BEGIN_MESSAGE_MAP(CBriefManage, CDialog) |
| 56 | //{{AFX_MSG_MAP(CBriefManage) |
| 57 | ON_BN_CLICKED(IDC_ADD, OnAdd) |
| 58 | //}}AFX_MSG_MAP |
| 59 | END_MESSAGE_MAP() |
| 60 | |
| 61 | ///////////////////////////////////////////////////////////////////////////// |
| 62 | // CBriefManage message handlers |
| 63 | bool AddNewGameFile(char *fullpath, char *directory); |
| 64 | bool CheckInGamefile(char *tempbuffer, bool show_ok_confirmation); |
| 65 | void CBriefManage::OnAdd() { |
| 66 | if (!Network_up) { |
| 67 | MessageBox("You need to say YES on the data update when starting the editor"); |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | int sel = m_List.GetCurSel(); |
| 72 | if (sel == LB_ERR) { |
| 73 | MessageBox("Please select the file you want to add"); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | char full_buffer[_MAX_PATH + 100]; |
| 78 | m_List.GetText(sel, full_buffer); |
| 79 | |
| 80 | int page_type = -1; |
| 81 | char *ptr; |
| 82 | |
| 83 | // break it down |
| 84 | ptr = full_buffer + strlen(full_buffer); |
| 85 | |
| 86 | while (ptr > full_buffer && (*ptr) != '|') |
| 87 | ptr--; |
| 88 | |
| 89 | if (*ptr != '|') { |
| 90 | MessageBox("Internal Error"); |
| 91 | Int3(); // get jeff; |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | *ptr = '\0'; |
| 96 | ptr++; |
| 97 | |
| 98 | if (page_type == -1 && strstr(ptr, "[sound]")) |
| 99 | page_type = PAGETYPE_SOUND; |
| 100 | if (page_type == -1 && strstr(ptr, "[file]")) |
| 101 | page_type = PAGETYPE_GAMEFILE; |
| 102 | |
| 103 | if (page_type == -1) { |
| 104 | MessageBox("Internal Error"); |
| 105 | Int3(); // get Jeff |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | if (page_type == PAGETYPE_SOUND) { |
| 110 | MessageBox("You must add sounds in the sound dialog"); |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | switch (page_type) { |
| 115 | case PAGETYPE_GAMEFILE: { |
| 116 | char filename[255]; |
| 117 | char real_filename[_MAX_PATH]; |
| 118 | |
| 119 | strcpy(filename, full_buffer); |
| 120 | |
| 121 | // Get the filename of the representing image |
| 122 | CString filter = ""; |
| 123 | |
| 124 | if (!OpenFileDialog(this, (LPCTSTR)filter, filename, Current_files_dir, sizeof(Current_files_dir))) |
| 125 | return; |
| 126 | |
| 127 | char directory[32], ext[32]; |
| 128 | bool know_dir = false; |
| 129 | |
| 130 | ddio_SplitPath(filename, NULL, real_filename, ext); |
| 131 | strcat(real_filename, ext); |
| 132 | |
| 133 | if (!know_dir && !stricmp(ext, ".ogf")) { |
| 134 | know_dir = true; |
| 135 | strcpy(directory, "graphics"); |
| 136 | } |
| 137 | |
| 138 | if (!know_dir && !stricmp(ext, ".tga")) { |
| 139 | know_dir = true; |
| 140 | strcpy(directory, "graphics"); |
| 141 | } |
| 142 | |
| 143 | if (!know_dir && !stricmp(ext, ".pcx")) { |
| 144 | know_dir = true; |
| 145 | strcpy(directory, "graphics"); |
| 146 | } |
| 147 | |
| 148 | if (!know_dir && !stricmp(ext, ".oof")) { |
| 149 | know_dir = true; |
| 150 | strcpy(directory, "models"); |
| 151 | } |
| 152 | |
| 153 | if (!know_dir) { |
| 154 | CEditLineDialog dlg("What directory does this belong in?", "Directory", "graphics", false, this); |
| 155 | if (dlg.DoModal() != IDOK) |
| 156 | return; |
| 157 | |
| 158 | strcpy(directory, dlg.GetText()); |
| 159 | |
| 160 | bool is_ok = false; |
| 161 | |
| 162 | if (!is_ok && !stricmp(directory, "briefings")) |
| 163 | is_ok = true; |
| 164 | |
| 165 | if (!is_ok && !stricmp(directory, "graphics")) |
| 166 | is_ok = true; |
| 167 | |
| 168 | if (!is_ok && !stricmp(directory, "levels")) |
| 169 | is_ok = true; |
| 170 | |
| 171 | if (!is_ok && !stricmp(directory, "misc")) |
| 172 | is_ok = true; |
| 173 | |
| 174 | if (!is_ok && !stricmp(directory, "models")) |
| 175 | is_ok = true; |
| 176 | |
| 177 | if (!is_ok && !stricmp(directory, "music")) |
| 178 | is_ok = true; |
| 179 | |
| 180 | if (!is_ok && !stricmp(directory, "scripts")) |
| 181 | is_ok = true; |
| 182 | |
| 183 | if (!is_ok && !stricmp(directory, "sounds")) |
| 184 | is_ok = true; |
| 185 | |
| 186 | if (!is_ok) { |
| 187 | MessageBox("Invalid directory"); |
| 188 | return; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | if (!AddNewGameFile(filename, directory)) { |
| 193 | char buffer[_MAX_PATH * 2]; |
| 194 | sprintf(buffer, "Unable to add:\r\n%s\r\nto %s", filename, directory); |
| 195 | MessageBox(buffer); |
| 196 | return; |
| 197 | } |
| 198 | |
| 199 | // auto checkin |
| 200 | if (!mng_MakeLocker()) { |
| 201 | return; |
| 202 | } |
| 203 | |
| 204 | if (!CheckInGamefile(real_filename, true)) { |
| 205 | MessageBox("Unable to auto-checkin"); |
| 206 | } |
| 207 | |
| 208 | mng_EraseLocker(); |
| 209 | } break; |
| 210 | } |
| 211 | |
| 212 | UpdateDialog(); |
| 213 | } |
| 214 | |
| 215 | BOOL CBriefManage::OnInitDialog() { |
| 216 | CDialog::OnInitDialog(); |
| 217 | |
| 218 | UpdateDialog(); |
| 219 | |
| 220 | return TRUE; |
| 221 | } |
| 222 | |
| 223 | void CBriefManage::AddString(char *filename, int pagetype) { |
| 224 | char buffer[_MAX_PATH + 100]; |
| 225 | char real_filename[_MAX_PATH]; |
| 226 | char page_type[100]; |
| 227 | char *pagename = filename; |
| 228 | |
| 229 | switch (pagetype) { |
| 230 | case PAGETYPE_SOUND: { |
| 231 | // look for the page in the manage system |
| 232 | bool found; |
| 233 | |
| 234 | found = false; |
| 235 | |
| 236 | mngs_sound_page page; |
| 237 | |
| 238 | if (mng_FindSpecificSoundPage(filename, &page) > 0) { |
| 239 | found = true; |
| 240 | } |
| 241 | |
| 242 | if (!found) { |
| 243 | // ok there wasn't one in the gamefiles make sure there isn't a tracklocked |
| 244 | if (mng_FindTrackLock(filename, PAGETYPE_SOUND) != -1) { |
| 245 | // there isn't one in the track lock...this is our first compile! |
| 246 | found = true; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | if (found) { |
| 251 | // we already have this in the manage system |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | strcpy(page_type, "[sound]"); |
| 256 | } break; |
| 257 | case PAGETYPE_GAMEFILE: { |
| 258 | // look for the page in the manage system |
| 259 | bool found; |
| 260 | int i; |
| 261 | |
| 262 | char ext[32]; |
| 263 | ddio_SplitPath(filename, NULL, real_filename, ext); |
| 264 | strcat(real_filename, ext); |
| 265 | pagename = real_filename; |
| 266 | |
| 267 | found = false; |
| 268 | for (i = 0; i < MAX_GAMEFILES; i++) { |
| 269 | if (Gamefiles[i].used && (!stricmp(real_filename, Gamefiles[i].name))) { |
| 270 | found = true; |
| 271 | break; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | if (!found) { |
| 276 | // ok there wasn't one in the gamefiles make sure there isn't a tracklocked |
| 277 | if (mng_FindTrackLock(real_filename, PAGETYPE_GAMEFILE) != -1) { |
| 278 | // there isn't one in the track lock...this is our first compile! |
| 279 | found = true; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | if (found) { |
| 284 | // we already have this in the manage system |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | strcpy(page_type, "[file]"); |
| 289 | } break; |
| 290 | default: |
| 291 | Int3(); |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | sprintf(buffer, "%s|%s", pagename, page_type); |
| 296 | |
| 297 | // see if it's already in the list |
| 298 | if (m_List.FindStringExact(-1, buffer) == LB_ERR) { |
| 299 | m_List.AddString(buffer); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | void CBriefManage::UpdateDialog(void) { |
| 304 | m_List.ResetContent(); |
| 305 | |
| 306 | int curr_screen = Briefing_root_screen; |
| 307 | int curr_effect; |
| 308 | tBriefScreen *screen; |
| 309 | tBriefEffect *effect; |
| 310 | |
| 311 | // go through and see what we have |
| 312 | while (curr_screen != -1) { |
| 313 | screen = &Briefing_screens[curr_screen]; |
| 314 | |
| 315 | ASSERT(screen->used); |
| 316 | |
| 317 | if (screen->layout[0] != '\0') { |
| 318 | // add the layout screen |
| 319 | AddString(screen->layout); |
| 320 | } |
| 321 | |
| 322 | // go through all the effects for this screen |
| 323 | curr_effect = screen->root_effect; |
| 324 | while (curr_effect != -1) { |
| 325 | effect = &screen->effects[curr_effect]; |
| 326 | ASSERT(effect->used); |
| 327 | |
| 328 | switch (effect->type) { |
| 329 | case BE_MOVIE: |
| 330 | case BE_TEXT: |
| 331 | case BE_BKG: |
| 332 | break; // no files in here |
| 333 | |
| 334 | case BE_BMP: |
| 335 | if (*effect->bmp_desc.filename) { |
| 336 | AddString(effect->bmp_desc.filename); |
| 337 | } |
| 338 | break; |
| 339 | |
| 340 | case BE_POLY: |
| 341 | if (*effect->poly_desc.polyname) { |
| 342 | AddString(effect->poly_desc.polyname); |
| 343 | } |
| 344 | break; |
| 345 | case BE_SND: |
| 346 | if (*effect->snd_desc.filename) { |
| 347 | AddString(effect->snd_desc.filename, PAGETYPE_SOUND); |
| 348 | } |
| 349 | break; |
| 350 | case BE_BUTTON: |
| 351 | if (*effect->button_desc.filename) { |
| 352 | AddString(effect->button_desc.filename); |
| 353 | } |
| 354 | |
| 355 | if (*effect->button_desc.filename_focus) { |
| 356 | AddString(effect->button_desc.filename_focus); |
| 357 | } |
| 358 | |
| 359 | if (*effect->button_desc.flash_filename) { |
| 360 | AddString(effect->button_desc.flash_filename); |
| 361 | } |
| 362 | |
| 363 | if (*effect->button_desc.flash_filename_focus) { |
| 364 | AddString(effect->button_desc.flash_filename_focus); |
| 365 | } |
| 366 | |
| 367 | break; |
| 368 | default: |
| 369 | break; |
| 370 | } |
| 371 | |
| 372 | curr_effect = effect->next; |
| 373 | } |
| 374 | |
| 375 | curr_screen = screen->next; |
| 376 | } |
| 377 | |
| 378 | m_List.SetCurSel(0); |
| 379 | } |