| 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 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/editor/ScriptWizard.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003-08-26 03:57:39 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * Script Wizard |
| 26 | * |
| 27 | * $Log: not supported by cvs2svn $ |
| 28 | * |
| 29 | * 20 11/06/98 12:34p Jason |
| 30 | * more speedups for manage system |
| 31 | * |
| 32 | * 19 10/08/98 4:24p Kevin |
| 33 | * Changed code to comply with memory library usage. Always use mem_malloc |
| 34 | * , mem_free and mem_strdup |
| 35 | * |
| 36 | * 18 8/31/98 4:12p Samir |
| 37 | * select level script by default in listbox. |
| 38 | * |
| 39 | * 17 6/23/98 3:04p Samir |
| 40 | * sped up script list generation. |
| 41 | * |
| 42 | * 16 6/23/98 2:43p Matt |
| 43 | * Changed calls to OutrageMessageBox() & Debug_MessageBox() to deal with |
| 44 | * int return value (instead of bool). |
| 45 | * |
| 46 | * 15 4/14/98 7:31p Matt |
| 47 | * Changed code to use ddio_MakePath() instead of sprintf() to create file |
| 48 | * spec |
| 49 | * |
| 50 | * 14 1/23/98 4:45p Samir |
| 51 | * Make level.scr be the default. |
| 52 | * |
| 53 | * 13 9/26/97 4:15p Samir |
| 54 | * Mostly working system to go to a certain script in a file. |
| 55 | * |
| 56 | * 12 9/25/97 5:28p Samir |
| 57 | * Even newer script code due to more changes in ObjCScript.cpp |
| 58 | * |
| 59 | * 11 9/24/97 6:18p Samir |
| 60 | * Fix some memory leakage probs. |
| 61 | * |
| 62 | * 10 9/24/97 2:57p Samir |
| 63 | * New ScriptWizard functionality, without extra commenting in files. |
| 64 | * |
| 65 | * 9 9/22/97 5:59p Samir |
| 66 | * Changed ObjCScript system, so everything is broken, but it shouldn't |
| 67 | * crash the game. |
| 68 | * |
| 69 | * 8 9/10/97 1:58p Samir |
| 70 | * Fixed up some code to select multiple script files. |
| 71 | * |
| 72 | * 7 9/04/97 4:39p Matt |
| 73 | * Added includes needed as a result of removing includes from d3edit.h |
| 74 | * |
| 75 | * 6 9/02/97 3:28p Matt |
| 76 | * Got rid of warnings |
| 77 | * |
| 78 | * 5 8/21/97 6:00p Samir |
| 79 | * A whole lot of script editing stuff added for ScriptWizard. |
| 80 | * |
| 81 | * 4 8/20/97 3:35p Samir |
| 82 | * Enhanced ScriptStudio to use tabs! Use new ScriptStudio instead of |
| 83 | * ScriptEditor. |
| 84 | * |
| 85 | * $NoKeywords: $ |
| 86 | */ |
| 87 | |
| 88 | // ScriptWizard.cpp : implementation file |
| 89 | // |
| 90 | |
| 91 | #include "stdafx.h" |
| 92 | #include "editor.h" |
| 93 | #include "ScriptWizard.h" |
| 94 | #include "ObjCScript.h" |
| 95 | #include "manage.h" |
| 96 | #include "EditLineDialog.h" |
| 97 | #include "ScriptEditorDlg.h" |
| 98 | #include "gamefile.h" |
| 99 | #include "manage\gamefilepage.h" |
| 100 | #include "ScriptStudio.h" |
| 101 | #include "AddScriptDialog.h" |
| 102 | #include "pserror.h" |
| 103 | #include "ddio.h" |
| 104 | #include "mem.h" |
| 105 | |
| 106 | #ifdef _DEBUG |
| 107 | #define new DEBUG_NEW |
| 108 | #undef THIS_FILE |
| 109 | static char THIS_FILE[] = __FILE__; |
| 110 | #endif |
| 111 | |
| 112 | #define MAX_SCREVTS 15 |
| 113 | |
| 114 | ///////////////////////////////////////////////////////////////////////////// |
| 115 | // CScriptWizard dialog |
| 116 | |
| 117 | CScriptWizard::CScriptWizard(CWnd *pParent /*=NULL*/) : CDialog(CScriptWizard::IDD, pParent) { |
| 118 | //{{AFX_DATA_INIT(CScriptWizard) |
| 119 | // NOTE: the ClassWizard will add member initialization here |
| 120 | //}}AFX_DATA_INIT |
| 121 | |
| 122 | m_ScriptSource = NULL; |
| 123 | m_ScriptCode = NULL; |
| 124 | } |
| 125 | |
| 126 | void CScriptWizard::DoDataExchange(CDataExchange *pDX) { |
| 127 | CDialog::DoDataExchange(pDX); |
| 128 | //{{AFX_DATA_MAP(CScriptWizard) |
| 129 | // NOTE: the ClassWizard will add DDX and DDV calls here |
| 130 | //}}AFX_DATA_MAP |
| 131 | } |
| 132 | |
| 133 | BEGIN_MESSAGE_MAP(CScriptWizard, CDialog) |
| 134 | //{{AFX_MSG_MAP(CScriptWizard) |
| 135 | ON_BN_CLICKED(IDC_ADDSCRIPT, OnAddScript) |
| 136 | ON_BN_CLICKED(IDC_LOCK, OnLock) |
| 137 | ON_BN_CLICKED(IDC_UNLOCK, OnUnlock) |
| 138 | ON_BN_CLICKED(IDC_EDITSCRIPT, OnEditScript) |
| 139 | ON_LBN_SELCHANGE(IDC_SCR_LISTBOX, OnSelChangeScrListbox) |
| 140 | ON_BN_CLICKED(IDC_ADDEVENT, OnAddEvent) |
| 141 | ON_LBN_SELCHANGE(IDC_SCREVT_LISTBOX, OnSelchangeScrevtListbox) |
| 142 | ON_CBN_SELCHANGE(IDC_SCRMOD_BOX, OnSelchangeScrmodBox) |
| 143 | ON_WM_DESTROY() |
| 144 | //}}AFX_MSG_MAP |
| 145 | END_MESSAGE_MAP() |
| 146 | |
| 147 | ///////////////////////////////////////////////////////////////////////////// |
| 148 | // CScriptWizard message handlers |
| 149 | |
| 150 | BOOL CScriptWizard::OnInitDialog() { |
| 151 | CDialog::OnInitDialog(); |
| 152 | |
| 153 | // Place all valid script files into the module combo box, then |
| 154 | // place all script names relating to the current script file into the script |
| 155 | // listbox. |
| 156 | CComboBox *modcbox = (CComboBox *)GetDlgItem(IDC_SCRMOD_BOX); |
| 157 | |
| 158 | // m_ScriptCode = D3XReallocProgram(NULL, 0, 0, 0); // LGT: undefined |
| 159 | ResetScriptList(); |
| 160 | |
| 161 | // place all filenames of scripts into combo box |
| 162 | char scrfilename[64]; |
| 163 | char *filename; |
| 164 | scrfilename[0] = 0; |
| 165 | filename = StartScriptFileList(); |
| 166 | while (filename) { |
| 167 | strcpy(scrfilename, filename); |
| 168 | modcbox->AddString(filename); |
| 169 | filename = GetNextScriptFile(); |
| 170 | } |
| 171 | EndScriptFileList(); |
| 172 | |
| 173 | modcbox->SelectString(-1, LEVEL_SCRIPT_NAME); |
| 174 | |
| 175 | // update listboxes accordingly to current script module |
| 176 | ScriptFileName[0] = 0; |
| 177 | ScriptCodeName[0] = 0; |
| 178 | CScriptWizard::LoadCurrentModule(); |
| 179 | |
| 180 | // Updates the buttons |
| 181 | UpdateDialogButtons(); |
| 182 | |
| 183 | return TRUE; // return TRUE unless you set the focus to a control |
| 184 | // EXCEPTION: OCX Property Pages should return FALSE |
| 185 | } |
| 186 | |
| 187 | void CScriptWizard::OnDestroy() { |
| 188 | CDialog::OnDestroy(); |
| 189 | |
| 190 | if (m_ScriptCode) |
| 191 | // D3XFreeProgram(m_ScriptCode); // LGT: undefined |
| 192 | ResetScriptList(); |
| 193 | } |
| 194 | |
| 195 | // We save whatever was added to the script. This does not include text added via edit |
| 196 | // (that's done in the internal script editor.) It does include text added from operations like |
| 197 | // Add Script, Add Event, etc. |
| 198 | void CScriptWizard::OnOK() { |
| 199 | SaveScript(ScriptFileName, m_ScriptSource); |
| 200 | FreeScript(m_ScriptSource); |
| 201 | |
| 202 | CDialog::OnOK(); |
| 203 | } |
| 204 | |
| 205 | // We just don't save anything. We free the script, if there is one |
| 206 | void CScriptWizard::OnCancel() { |
| 207 | FreeScript(m_ScriptSource); |
| 208 | |
| 209 | CDialog::OnCancel(); |
| 210 | } |
| 211 | |
| 212 | // Adds a script to the current editable script. We will not allow this if the script is not locked, |
| 213 | // so we should allow then to unlock it at this point. |
| 214 | void CScriptWizard::OnAddScript() { |
| 215 | char scrname[MAX_SCRNAME]; |
| 216 | |
| 217 | scrname[0] = 0; |
| 218 | |
| 219 | if (strlen(ScriptFileName) == 0) { |
| 220 | OutrageMessageBox("There is no script file to add a script to! You must make one."); |
| 221 | return; |
| 222 | } |
| 223 | |
| 224 | // check if current module is locked by us. |
| 225 | if (mng_FindTrackLock(ScriptFileName, PAGETYPE_GAMEFILE) == -1) |
| 226 | OutrageMessageBox("Warning: This script is not locked by you.\nAny changes you make will not be permanent."); |
| 227 | |
| 228 | // request a name for this new script! |
| 229 | CAddScriptDialog dlg(this); |
| 230 | if (dlg.DoModal() == IDOK) { |
| 231 | // add script to listbox, then select it, then run editor |
| 232 | CListBox *lb = (CListBox *)GetDlgItem(IDC_SCR_LISTBOX); |
| 233 | char *tempstr = AddScriptBlockToScript(m_ScriptSource, (LPCSTR)dlg.m_Name, (LPCSTR)dlg.m_TypeName); |
| 234 | mem_free(m_ScriptSource); |
| 235 | m_ScriptSource = tempstr; |
| 236 | UpdateScriptListbox(); |
| 237 | lb->SelectString(-1, (LPCSTR)dlg.m_Name); |
| 238 | OnEditScript(); |
| 239 | } else { |
| 240 | OutrageMessageBox("A script name is required to continue. Cancelling action."); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | void CScriptWizard::OnAddEvent() { |
| 245 | CListBox *listbox = (CListBox *)GetDlgItem(IDC_SCREVT_LISTBOX); |
| 246 | CListBox *scrlb = (CListBox *)GetDlgItem(IDC_SCR_LISTBOX); |
| 247 | char *tempstr; |
| 248 | |
| 249 | char evtname[MAX_EVTNAME]; |
| 250 | char scrname[MAX_SCRNAME]; |
| 251 | |
| 252 | ASSERT(listbox->GetCurSel() != LB_ERR); |
| 253 | ASSERT(scrlb->GetCurSel() != LB_ERR); |
| 254 | |
| 255 | scrlb->GetText(scrlb->GetCurSel(), scrname); |
| 256 | listbox->GetText(listbox->GetCurSel(), evtname); |
| 257 | |
| 258 | tempstr = AddEventBlockToScript(m_ScriptSource, evtname, scrname); |
| 259 | |
| 260 | if (!tempstr) { |
| 261 | OutrageMessageBox("Failed to add event to script.\nScript text possibly corrupted."); |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | mem_free(m_ScriptSource); |
| 266 | m_ScriptSource = tempstr; |
| 267 | } |
| 268 | |
| 269 | // This code invokes the original OSIRIS editor dialog with the currently loaded script file. |
| 270 | void CScriptWizard::OnEditScript() { |
| 271 | CScriptStudio studio; |
| 272 | CScriptEditorDlg editor; |
| 273 | |
| 274 | if (strlen(ScriptFileName) == 0) { |
| 275 | OutrageMessageBox("There is no script file to add a script to! You must make one."); |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | // check if current module is locked by us. |
| 280 | if (FindGamefileName(ScriptFileName) != -1) { |
| 281 | if (mng_FindTrackLock(ScriptFileName, PAGETYPE_GAMEFILE) == -1) { |
| 282 | OutrageMessageBox("Warning: This script is not locked by you.\nAny changes you make will not be permanent."); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | //@@** |
| 287 | //@@**// Do default external editor stuff. Jeff Slutter's code. |
| 288 | //@@** if(strlen(Default_external_editor)==0) |
| 289 | //@@** { |
| 290 | //@@** char buffer[256]; |
| 291 | //@@** CString default_path; |
| 292 | //@@** int size=GetWindowsDirectory(buffer,256); |
| 293 | //@@** ASSERT(size<256); |
| 294 | //@@** buffer[size]='\\'; |
| 295 | //@@** buffer[size+1]='\0'; |
| 296 | //@@** |
| 297 | //@@** default_path=buffer; |
| 298 | //@@** default_path+="Notepad.exe"; |
| 299 | //@@** editor.SetExternalEditor(default_path.GetBuffer(1)); |
| 300 | //@@** } |
| 301 | //@@** else |
| 302 | //@@** { |
| 303 | //@@** editor.SetExternalEditor(Default_external_editor); |
| 304 | //@@** } |
| 305 | |
| 306 | // Now just set the current source loaded as the editor's source |
| 307 | // Also create a program so that the compiler can |
| 308 | char buf[64]; |
| 309 | CListBox *scrlistbox = (CListBox *)GetDlgItem(IDC_SCR_LISTBOX); |
| 310 | |
| 311 | scrlistbox->GetText(scrlistbox->GetCurSel(), buf); |
| 312 | studio.SelectText(buf); |
| 313 | studio.SetD3XObject(m_ScriptCode); |
| 314 | studio.SetText(CString(m_ScriptSource)); |
| 315 | |
| 316 | if (studio.DoModal() == IDOK) { |
| 317 | // Try and compile now |
| 318 | CString tempstr; |
| 319 | |
| 320 | FreeScript(m_ScriptSource); |
| 321 | studio.GetText(tempstr); |
| 322 | m_ScriptSource = (char *)mem_malloc(tempstr.GetLength() + 1); |
| 323 | |
| 324 | if (m_ScriptSource) { |
| 325 | strcpy(m_ScriptSource, (LPCSTR)tempstr); |
| 326 | SaveScript(ScriptFileName, m_ScriptSource); |
| 327 | FreeScript(m_ScriptSource); |
| 328 | m_ScriptSource = LoadScript(ScriptFileName); // After this, Source_script has new edited script. |
| 329 | |
| 330 | if (!CompileScript(studio.GetD3XObject(), m_ScriptSource)) { |
| 331 | OutrageMessageBox("Your script did not compile. Unless you fix it, the script will not work."); |
| 332 | } else { |
| 333 | SaveScriptCode(ScriptCodeName, studio.GetD3XObject()); |
| 334 | } |
| 335 | } else { |
| 336 | OutrageMessageBox("Couldn't allocate memory to save script!"); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | m_ScriptCode = studio.GetD3XObject(); |
| 341 | |
| 342 | // rebuild list of scripts from changes in source code that may have happened. |
| 343 | ResetScriptList(); |
| 344 | if (stricmp(ScriptFileName, DEFAULT_SCRIPT_NAME) == 0) |
| 345 | GenerateScriptWizardInfo(m_ScriptSource, false); |
| 346 | else |
| 347 | GenerateScriptWizardInfo(m_ScriptSource, true); |
| 348 | |
| 349 | UpdateScriptListbox(); |
| 350 | |
| 351 | //@@** if(strcmp(editor.m_ExternalEditor,Default_external_editor)) |
| 352 | //@@** { |
| 353 | //@@** strcpy(Default_external_editor,editor.m_ExternalEditor.GetBuffer(1)); |
| 354 | //@@** } |
| 355 | } |
| 356 | |
| 357 | // Uses gamefile locking code! |
| 358 | // This is taken from FilePageDialog.cpp, with some modifications to the outputted text, but uses the GameFile |
| 359 | // page scheme, emulating a script page. |
| 360 | void CScriptWizard::OnLock() { |
| 361 | int n, r; |
| 362 | mngs_Pagelock temp_pl; |
| 363 | mngs_gamefile_page gamefilepage; |
| 364 | |
| 365 | n = FindGamefileName(ScriptFileName); |
| 366 | if (n == -1) { |
| 367 | OutrageMessageBox("Unable to find script file page in the table file.\nOperation can't be completed."); |
| 368 | return; |
| 369 | } |
| 370 | |
| 371 | // start the really involved locking process. |
| 372 | if (!mng_MakeLocker()) |
| 373 | return; |
| 374 | |
| 375 | // Make sure it can be locked |
| 376 | strcpy(temp_pl.name, Gamefiles[n].name); |
| 377 | temp_pl.pagetype = PAGETYPE_GAMEFILE; |
| 378 | |
| 379 | r = mng_CheckIfPageLocked(&temp_pl); |
| 380 | if (r == 2) { |
| 381 | int answer = |
| 382 | OutrageMessageBox(MBOX_YESNO, "This script is not even in the table file, or the database maybe corrupt. " |
| 383 | "Override to 'Unlocked'? (Select NO if you don't know what you're doing)"); |
| 384 | if (answer == IDYES) { |
| 385 | strcpy(temp_pl.holder, "UNLOCKED"); |
| 386 | if (!mng_ReplacePagelock(temp_pl.name, &temp_pl)) |
| 387 | MessageBox(ErrorString, "Error!"); |
| 388 | } |
| 389 | } else if (r < 0) |
| 390 | OutrageMessageBox(ErrorString); |
| 391 | else if (r == 1) |
| 392 | OutrageMessageBox(InfoString); |
| 393 | else { |
| 394 | // Everything is ok. Tell the network we're locking it and get a copy to |
| 395 | // our local drive |
| 396 | |
| 397 | strcpy(temp_pl.holder, TableUser); |
| 398 | if (!mng_ReplacePagelock(temp_pl.name, &temp_pl)) { |
| 399 | MessageBox(ErrorString, "Error!"); |
| 400 | mng_EraseLocker(); |
| 401 | return; |
| 402 | } else { |
| 403 | // Search thru the net pagefile and get a new copy in RAM in case anyone |
| 404 | // changed it since we started the editor |
| 405 | if (mng_FindSpecificGamefilePage(temp_pl.name, &gamefilepage, 0)) { |
| 406 | if (mng_AssignGamefilePageToGamefile(&gamefilepage, n)) { |
| 407 | if (!mng_ReplacePage(Gamefiles[n].name, Gamefiles[n].name, n, PAGETYPE_GAMEFILE, 1)) { |
| 408 | OutrageMessageBox("There was problem writing that page locally!"); |
| 409 | mng_EraseLocker(); |
| 410 | return; |
| 411 | } |
| 412 | OutrageMessageBox("Script locked."); |
| 413 | } else |
| 414 | OutrageMessageBox( |
| 415 | "There was a problem loading this script. You might encounter problems in dealing with it. Good luck!"); |
| 416 | |
| 417 | mng_AllocTrackLock(Gamefiles[n].name, PAGETYPE_GAMEFILE); |
| 418 | UpdateDialogButtons(); |
| 419 | } else |
| 420 | OutrageMessageBox("Couldn't find that script in the table file!"); |
| 421 | } |
| 422 | } |
| 423 | mng_EraseLocker(); |
| 424 | } |
| 425 | |
| 426 | // Uses gamefile unlocking code! |
| 427 | void CScriptWizard::OnUnlock() { |
| 428 | int n, r; |
| 429 | mngs_Pagelock temp_pl; |
| 430 | |
| 431 | n = FindGamefileName(ScriptFileName); |
| 432 | if (n == -1) { |
| 433 | OutrageMessageBox("Unable to find script file page in the table file.\nOperation can't be completed."); |
| 434 | return; |
| 435 | } |
| 436 | |
| 437 | if (!mng_MakeLocker()) |
| 438 | return; |
| 439 | |
| 440 | // Make sure we own this gamefile |
| 441 | strcpy(temp_pl.name, Gamefiles[n].name); |
| 442 | temp_pl.pagetype = PAGETYPE_GAMEFILE; |
| 443 | |
| 444 | r = mng_CheckIfPageOwned(&temp_pl, TableUser); |
| 445 | if (r < 0) |
| 446 | OutrageMessageBox(ErrorString); |
| 447 | else if (r == 0) |
| 448 | OutrageMessageBox(InfoString); |
| 449 | else { |
| 450 | // Change the pagelock state to UNLOCKED |
| 451 | strcpy(temp_pl.holder, "UNLOCKED"); |
| 452 | if (!mng_ReplacePagelock(temp_pl.name, &temp_pl)) { |
| 453 | MessageBox(ErrorString, "Error!"); |
| 454 | mng_EraseLocker(); |
| 455 | return; |
| 456 | } else { |
| 457 | // Now actually replace the copy on the net with our local one |
| 458 | if (!mng_ReplacePage(Gamefiles[n].name, Gamefiles[n].name, n, PAGETYPE_GAMEFILE, 0)) |
| 459 | OutrageMessageBox(ErrorString); |
| 460 | else { |
| 461 | // Save this gamefile file to the network for all |
| 462 | // Force the save of the current script file so this actually works |
| 463 | char destname[100], srcname[100]; |
| 464 | |
| 465 | SaveScript(ScriptFileName, m_ScriptSource); |
| 466 | |
| 467 | ddio_MakePath(srcname, LocalD3Dir, "data", Gamefiles[n].dir_name, Gamefiles[n].name, NULL); |
| 468 | ddio_MakePath(destname, NetD3Dir, "data", Gamefiles[n].dir_name, Gamefiles[n].name, NULL); |
| 469 | |
| 470 | cf_CopyFile(destname, srcname); |
| 471 | |
| 472 | OutrageMessageBox("Script checked in."); |
| 473 | |
| 474 | // Delete it from local pagefile if its there |
| 475 | int dret = mng_DeletePage(Gamefiles[n].name, PAGETYPE_GAMEFILE, 1); |
| 476 | ASSERT(dret == 1); |
| 477 | mng_EraseLocker(); |
| 478 | |
| 479 | // Free the tracklock |
| 480 | int p = mng_FindTrackLock(Gamefiles[n].name, PAGETYPE_GAMEFILE); |
| 481 | ASSERT(p != -1); |
| 482 | mng_FreeTrackLock(p); |
| 483 | UpdateDialogButtons(); |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | void CScriptWizard::OnSelChangeScrListbox() { |
| 490 | CListBox *lb = (CListBox *)GetDlgItem(IDC_SCR_LISTBOX); |
| 491 | |
| 492 | m_CurScriptSel = lb->GetCurSel(); |
| 493 | if (m_CurScriptSel == LB_ERR) |
| 494 | m_CurScriptSel = -1; |
| 495 | } |
| 496 | |
| 497 | void CScriptWizard::OnSelchangeScrevtListbox() { |
| 498 | CListBox *lb = (CListBox *)GetDlgItem(IDC_SCREVT_LISTBOX); |
| 499 | |
| 500 | m_CurEventSel = lb->GetCurSel(); |
| 501 | UpdateDialogButtons(); |
| 502 | } |
| 503 | |
| 504 | // User Interface Update Controllers |
| 505 | // ListBox |
| 506 | // ComboBox |
| 507 | |
| 508 | void CScriptWizard::LoadCurrentModule() { |
| 509 | CComboBox *modcbox = (CComboBox *)GetDlgItem(IDC_SCRMOD_BOX); |
| 510 | char str[MAX_SCRNAME]; |
| 511 | |
| 512 | // Get current module select and load it in. |
| 513 | if (m_ScriptSource) |
| 514 | FreeScript(m_ScriptSource); |
| 515 | |
| 516 | m_ScriptSource = NULL; |
| 517 | |
| 518 | if (modcbox->GetLBText(modcbox->GetCurSel(), str) != CB_ERR) { |
| 519 | char *ptr; |
| 520 | m_ScriptSource = LoadScript(str); |
| 521 | strcpy(ScriptFileName, str); |
| 522 | strcpy(ScriptCodeName, str); |
| 523 | ptr = strtok(ScriptCodeName, "."); |
| 524 | strcat(ptr, ".d3x"); |
| 525 | } |
| 526 | |
| 527 | // new script file, set current script to 0 |
| 528 | m_CurScriptSel = 0; |
| 529 | |
| 530 | // compile and generate list of script names. |
| 531 | ResetScriptList(); |
| 532 | if (m_ScriptSource) { |
| 533 | if (stricmp(ScriptFileName, DEFAULT_SCRIPT_NAME) == 0) |
| 534 | GenerateScriptWizardInfo(m_ScriptSource, false); |
| 535 | else |
| 536 | GenerateScriptWizardInfo(m_ScriptSource, true); |
| 537 | } |
| 538 | |
| 539 | UpdateScriptListbox(); |
| 540 | } |
| 541 | |
| 542 | void CScriptWizard::UpdateScriptListbox() { |
| 543 | CListBox *scrlistbox = (CListBox *)GetDlgItem(IDC_SCR_LISTBOX); |
| 544 | int i; |
| 545 | |
| 546 | // Add script names to list box |
| 547 | scrlistbox->ResetContent(); |
| 548 | for (i = 0; i < MAX_SCRIPTS; i++) { |
| 549 | if (Script_names[i].used) |
| 550 | if (!stricmp(ScriptFileName, DEFAULT_SCRIPT_NAME) && !Script_names[i].iscustom) |
| 551 | scrlistbox->AddString(Script_names[i].name); |
| 552 | else if (stricmp(ScriptFileName, DEFAULT_SCRIPT_NAME) && Script_names[i].iscustom) |
| 553 | scrlistbox->AddString(Script_names[i].name); |
| 554 | } |
| 555 | |
| 556 | // make sure we reselect the current string. |
| 557 | if (scrlistbox->GetCount() > 0) |
| 558 | scrlistbox->SetCurSel(m_CurScriptSel); |
| 559 | else |
| 560 | m_CurScriptSel = -1; |
| 561 | |
| 562 | m_CurEventSel = 0; |
| 563 | |
| 564 | UpdateEventListbox(); |
| 565 | } |
| 566 | |
| 567 | void CScriptWizard::UpdateEventListbox() { |
| 568 | CListBox *listbox = (CListBox *)GetDlgItem(IDC_SCREVT_LISTBOX); |
| 569 | CListBox *scrlistbox = (CListBox *)GetDlgItem(IDC_SCR_LISTBOX); |
| 570 | int i, id; |
| 571 | char scrname[MAX_SCRNAME]; |
| 572 | |
| 573 | // Add script names to list box |
| 574 | listbox->ResetContent(); |
| 575 | |
| 576 | if (m_CurScriptSel > -1) { |
| 577 | // get text from listbox, then get script ID from that name, since names are sorted alphabetically |
| 578 | // in the listbox. |
| 579 | scrlistbox->GetText(m_CurScriptSel, scrname); |
| 580 | id = FindScriptIDFromName(scrname); |
| 581 | |
| 582 | for (i = 0; i < MAX_SCREVTS; i++) |
| 583 | listbox->AddString(Script_evt_names[i]); |
| 584 | |
| 585 | listbox->SetCurSel(m_CurEventSel); |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | void CScriptWizard::OnSelchangeScrmodBox() { |
| 590 | LoadCurrentModule(); |
| 591 | UpdateDialogButtons(); |
| 592 | } |
| 593 | |
| 594 | void CScriptWizard::UpdateDialogButtons() { |
| 595 | CButton *btnunlock = (CButton *)GetDlgItem(IDC_UNLOCK); |
| 596 | CButton *btnlock = (CButton *)GetDlgItem(IDC_LOCK); |
| 597 | CButton *btnedit = (CButton *)GetDlgItem(IDC_EDITSCRIPT); |
| 598 | CButton *btnevt = (CButton *)GetDlgItem(IDC_ADDEVENT); |
| 599 | CButton *btnundolock = (CButton *)GetDlgItem(IDC_UNDOLOCK); |
| 600 | CListBox *evtlb = (CListBox *)GetDlgItem(IDC_SCREVT_LISTBOX); |
| 601 | |
| 602 | int n; |
| 603 | char str[128]; |
| 604 | |
| 605 | // take care of script locking and unlocking buttons |
| 606 | if (stricmp(ScriptFileName, DEFAULT_SCRIPT_NAME) == 0) |
| 607 | n = FindGamefileName(ScriptFileName); |
| 608 | else |
| 609 | n = -1; |
| 610 | |
| 611 | if (n == -1) { |
| 612 | btnunlock->EnableWindow(FALSE); |
| 613 | btnlock->EnableWindow(FALSE); |
| 614 | btnundolock->EnableWindow(FALSE); |
| 615 | } else if (mng_FindTrackLock(Gamefiles[n].name, PAGETYPE_GAMEFILE) == -1) { |
| 616 | btnunlock->EnableWindow(FALSE); |
| 617 | btnlock->EnableWindow(TRUE); |
| 618 | btnundolock->EnableWindow(FALSE); |
| 619 | } else { |
| 620 | btnunlock->EnableWindow(TRUE); |
| 621 | btnlock->EnableWindow(FALSE); |
| 622 | btnundolock->EnableWindow(TRUE); |
| 623 | } |
| 624 | |
| 625 | // take care of Editing buttons |
| 626 | if (evtlb->GetCurSel() == LB_ERR) |
| 627 | btnevt->EnableWindow(FALSE); |
| 628 | else { |
| 629 | evtlb->GetText(m_CurEventSel, str); |
| 630 | btnevt->EnableWindow(TRUE); |
| 631 | } |
| 632 | |
| 633 | if (strlen(ScriptFileName) > 0) |
| 634 | btnedit->EnableWindow(TRUE); |
| 635 | else |
| 636 | btnedit->EnableWindow(FALSE); |
| 637 | } |