1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
/*
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// ScriptSelect.cpp : implementation file
//
#include "stdafx.h"
#include "editor.h"
#include "ScriptSelect.h"
#include "AddScriptDialog.h"
#include "ScriptStudio.h"
#include "pserror.h"
#include "d3x.h"
#include "ObjCScript.h"
#include "ScriptWizard.h"
#include "ScriptParmDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CScriptSelect dialog
CScriptSelect::CScriptSelect(uint16_t scr_type, int custom_type, CWnd *pParent /*=NULL*/)
: CDialog(CScriptSelect::IDD, pParent) {
//{{AFX_DATA_INIT(CScriptSelect)
m_ScriptName = _T("");
//}}AFX_DATA_INIT
m_ScriptCode = NULL;
m_CurScriptSel = -1;
m_ScriptType = (uint16_t)scr_type;
m_NumParms = 0;
m_CustomType = custom_type;
}
void CScriptSelect::DoDataExchange(CDataExchange *pDX) {
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CScriptSelect)
DDX_LBString(pDX, IDC_SCRIPTSEL_LISTBOX, m_ScriptName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CScriptSelect, CDialog)
//{{AFX_MSG_MAP(CScriptSelect)
ON_LBN_DBLCLK(IDC_SCRIPTSEL_LISTBOX, OnDblclkScriptselListbox)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_PARAMETERS, OnParameters)
ON_LBN_SELCHANGE(IDC_SCRIPTSEL_LISTBOX, OnSelchangeScriptselListbox)
ON_BN_CLICKED(IDC_SCRIPTSEL_ADD, OnScriptselAdd)
ON_BN_CLICKED(IDC_EDITSCRIPT, OnEditScript)
ON_BN_CLICKED(IDC_SCRTYPE, OnScrtype)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScriptSelect message handlers
BOOL CScriptSelect::OnInitDialog() {
CListBox *scrlistbox = (CListBox *)GetDlgItem(IDC_SCRIPTSEL_LISTBOX);
CDialog::OnInitDialog();
// update names of scripts into listbox
// m_ScriptCode = D3XReallocProgram(NULL, 0, 0, 0); LGT- undefined
UpdateScriptListbox();
if (m_ScriptName.IsEmpty())
scrlistbox->SelectString(-1, "null");
else
scrlistbox->SelectString(-1, m_ScriptName);
OnSelchangeScriptselListbox();
// update script list selector
CButton *btn = (CButton *)GetDlgItem(IDC_SCRTYPE);
if (m_CustomType & DEFAULT_SCRIPT_MASK) {
btn->SetWindowText("Custom List");
} else if (m_CustomType & CUSTOM_SCRIPT_MASK) {
btn->SetWindowText("Default List");
} else {
btn->EnableWindow(FALSE);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CScriptSelect::OnDestroy() {
CDialog::OnDestroy();
// if (m_ScriptCode) D3XFreeProgram(m_ScriptCode); LGT- undefined
}
//////////////////////////////////////////////////////////////////////////////
// CONTROL HANDLERS
void CScriptSelect::OnOK() {
// DDX takes care of returning the script name selected
CDialog::OnOK();
}
void CScriptSelect::OnDblclkScriptselListbox() { OnOK(); }
//@@void CScriptSelect::OnScriptselScriptWiz()
//@@{
//@@ CListBox *scrlistbox = (CListBox *)GetDlgItem(IDC_SCRIPTSEL_LISTBOX);
//@@ CString str;
//@@ int sel;
//@@
//@@ sel = scrlistbox->GetCurSel();
//@@ if (sel != LB_ERR) {
//@@ scrlistbox->GetText(sel, str);
//@@ }
//@@
//@@ CScriptWizard dlg;
//@@ dlg.DoModal();
//@@ UpdateScriptListbox();
//@@
//@@ if (sel != LB_ERR)
//@@ scrlistbox->SelectString(-1, str);
//@@}
void CScriptSelect::OnSelchangeScriptselListbox() {
CListBox *scrlistbox = (CListBox *)GetDlgItem(IDC_SCRIPTSEL_LISTBOX);
CButton *btn = (CButton *)GetDlgItem(IDC_PARAMETERS);
CButton *btn2 = (CButton *)GetDlgItem(IDC_EDITSCRIPT);
CString str;
int sel, id;
sel = scrlistbox->GetCurSel();
if (sel != LB_ERR) {
scrlistbox->GetText(sel, str);
id = FindScriptIDFromName(str);
if (id > -1) {
btn2->EnableWindow(TRUE);
m_NumParms = Script_names[id].nparms;
if (Script_names[id].nparms) {
btn->EnableWindow(TRUE);
return;
}
} else {
m_NumParms = 0;
btn2->EnableWindow(FALSE);
}
}
btn->EnableWindow(FALSE);
}
void CScriptSelect::OnParameters() {
// search list of script names for match with listbox. Then use this index
// to look in the m_SciptCode program to see if that script has parameters
CListBox *scrlistbox = (CListBox *)GetDlgItem(IDC_SCRIPTSEL_LISTBOX);
CString str;
int sel, id;
sel = scrlistbox->GetCurSel();
if (sel != LB_ERR) {
scrlistbox->GetText(sel, str);
id = FindScriptIDFromName(str);
if (id > -1) {
CScriptParmDialog dlg;
// grab parameter information.
SETUP_SCRIPTPARM_DIALOG(&dlg, Script_names[id].parameters, m_Parm);
if (dlg.DoModal() == IDOK) {
RETURN_SCRIPTPARM_DIALOG(m_Parm, &dlg, Script_names[id].paramtypes);
}
} else {
Int3();
}
}
}
//////////////////////////////////////////////////////////////////////////////
// INTERNAL FUNCTIONS
void CScriptSelect::UpdateScriptListbox() {
CListBox *scrlistbox = (CListBox *)GetDlgItem(IDC_SCRIPTSEL_LISTBOX);
int i;
GenerateScriptListFromAllFiles(m_CustomType);
// Add script names to list box
scrlistbox->ResetContent();
for (i = 0; i < MAX_SCRIPTS; i++) {
if (Script_names[i].used)
if (m_ScriptType == 0xffff || Script_names[i].type == m_ScriptType)
if ((Script_names[i].iscustom && (m_CustomType & CUSTOM_SCRIPT_MASK)) ||
(!Script_names[i].iscustom && (m_CustomType & DEFAULT_SCRIPT_MASK)))
scrlistbox->AddString(Script_names[i].name);
}
scrlistbox->AddString("null");
// make sure we reselect the current string.
if (scrlistbox->GetCount() > 0)
scrlistbox->SetCurSel(0);
}
void CScriptSelect::OnScriptselAdd() {
CAddScriptDialog dlg(this);
// in this case, load the script source file level.scr and add to it.
if (dlg.DoModal() == IDOK) {
char *source;
source = LoadScript(LEVEL_SCRIPT_NAME);
if (!source) {
OutrageMessageBox("Unable to find script for level. Something is wrong!");
return;
}
source = AddScriptBlockToScript(source, (LPCSTR)dlg.m_Name, (LPCSTR)dlg.m_TypeName);
SaveScript(LEVEL_SCRIPT_NAME, source);
FreeScript(source);
EditScript(LEVEL_SCRIPT_NAME, dlg.m_Name);
}
}
void CScriptSelect::OnEditScript() {
CListBox *scrlistbox = (CListBox *)GetDlgItem(IDC_SCRIPTSEL_LISTBOX);
CString str;
int sel, id;
sel = scrlistbox->GetCurSel();
if (sel != LB_ERR) {
scrlistbox->GetText(sel, str);
id = FindScriptIDFromName(str);
if (id > -1)
EditScript(Script_names[id].iscustom ? LEVEL_SCRIPT_NAME : DEFAULT_SCRIPT_NAME, str);
}
}
void CScriptSelect::EditScript(const char *filename, const char *scrname) {
if (InvokeScriptStudio(filename, scrname))
UpdateScriptListbox();
}
void CScriptSelect::OnScrtype() {
CListBox *scrlistbox = (CListBox *)GetDlgItem(IDC_SCRIPTSEL_LISTBOX);
CButton *btn = (CButton *)GetDlgItem(IDC_SCRTYPE);
if (m_CustomType & DEFAULT_SCRIPT_MASK) {
m_CustomType = CUSTOM_SCRIPT_MASK;
btn->SetWindowText("Default List");
} else if (m_CustomType & CUSTOM_SCRIPT_MASK) {
m_CustomType = DEFAULT_SCRIPT_MASK;
btn->SetWindowText("Custom List");
}
UpdateScriptListbox();
if (m_ScriptName.IsEmpty())
scrlistbox->SelectString(-1, "null");
else
scrlistbox->SelectString(-1, m_ScriptName);
}
|