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 279 280 281 282 283 284 285
|
/*
* 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/>.
*/
// DallasUserTypesDlg.cpp : implementation file
//
#include "stdafx.h"
#include "cfile.h"
#ifdef NEWEDITOR
#include "NewEditor.h"
#else
#include "editor.h"
#endif
#include "DallasMainDlg.h"
#include "DallasGenericPromptDlg.h"
#include "DallasUserTypesDlg.h"
CDallasMainDlg *GetDallasDialogPtr(void);
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString last_type_selected;
/////////////////////////////////////////////////////////////////////////////
// CDallasUserTypesDlg dialog
CDallasUserTypesDlg::CDallasUserTypesDlg(CWnd *pParent /*=NULL*/) : CDialog(CDallasUserTypesDlg::IDD, pParent) {
//{{AFX_DATA_INIT(CDallasUserTypesDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDallasUserTypesDlg::DoDataExchange(CDataExchange *pDX) {
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDallasUserTypesDlg)
DDX_Control(pDX, IDC_VALUES_LIST, m_ValuesListBox);
DDX_Control(pDX, IDC_UTYPE_COMBO, m_UserTypeCombo);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDallasUserTypesDlg, CDialog)
//{{AFX_MSG_MAP(CDallasUserTypesDlg)
ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
ON_BN_CLICKED(IDC_CHANGE_BUTTON, OnChangeButton)
ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton)
ON_CBN_SELCHANGE(IDC_UTYPE_COMBO, OnSelchangeUtypeCombo)
ON_LBN_DBLCLK(IDC_VALUES_LIST, OnDblclkValuesList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDallasUserTypesDlg message handlers
BOOL CDallasUserTypesDlg::OnInitDialog() {
CDialog::OnInitDialog();
CDallasMainDlg *m_DallasModelessDlgPtr;
m_DallasModelessDlgPtr = GetDallasDialogPtr();
// If Dallas is up, fill in the user type and value boxes
if (m_DallasModelessDlgPtr != NULL) {
m_DallasModelessDlgPtr->FillUserTypeBox(&m_UserTypeCombo);
if (!last_type_selected.IsEmpty()) {
m_UserTypeCombo.SelectString(-1, last_type_selected.GetBuffer(0));
}
OnSelchangeUtypeCombo();
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDallasUserTypesDlg::OnAddButton() {
CDallasGenericPromptDlg dlg;
int index;
CString name;
CDallasMainDlg *m_DallasModelessDlgPtr;
m_DallasModelessDlgPtr = GetDallasDialogPtr();
if (m_DallasModelessDlgPtr == NULL)
return;
// Get the name of the user type
index = m_UserTypeCombo.GetCurSel();
if (index == CB_ERR)
return;
m_UserTypeCombo.GetLBText(index, name);
if (name.IsEmpty())
return;
// Display the prompt dialog
dlg.m_DialogTitle = "Value Name Prompt";
dlg.m_PromptText = "Enter a name for the new value:";
dlg.m_PromptData = "";
dlg.m_MaxDataLength = MAX_MESSAGE_NAME_LEN;
if (dlg.DoModal() == IDCANCEL)
return;
// Check if the message name is valid
char *valname = dlg.m_PromptData.GetBuffer(0);
if (strlen(valname) == 0)
return;
for (uint32_t j = 0; j < strlen(valname); j++)
if (!isalnum(valname[j]) && valname[j] != '_' && valname[j] != ' ') {
MessageBox("That name is invalid!\n\nA value name may only contain letters and numbers", "Invalid Name Error",
MB_OK | MB_ICONEXCLAMATION);
return;
}
// Check if the message name already exists in the list
int pos;
if (m_DallasModelessDlgPtr->GetEnumValue(name.GetBuffer(0), valname, pos)) {
MessageBox("That value name is already in use!\n\nYou must enter a UNIQUE name.", "Invalid Value Name",
MB_OK | MB_ICONEXCLAMATION);
return;
}
// Add the value to the enum database
pos = m_DallasModelessDlgPtr->AddUserTypeValue(name.GetBuffer(0), valname);
if (pos == 0)
return;
if (pos == -1) {
MessageBox("The value could not be added.\n\nThe list may be full.", "Value Not Added", MB_OK | MB_ICONEXCLAMATION);
return;
}
// Add the value to the list
m_ValuesListBox.InsertString(pos - 1, valname);
}
void CDallasUserTypesDlg::OnChangeButton() {
CDallasGenericPromptDlg dlg;
int index;
CString type_name, value_name;
CDallasMainDlg *m_DallasModelessDlgPtr;
m_DallasModelessDlgPtr = GetDallasDialogPtr();
if (m_DallasModelessDlgPtr == NULL)
return;
// Get the name of the user type
index = m_UserTypeCombo.GetCurSel();
if (index == CB_ERR)
return;
m_UserTypeCombo.GetLBText(index, type_name);
if (type_name.IsEmpty())
return;
// Get the name of the selected value
index = m_ValuesListBox.GetCurSel();
if (index == LB_ERR)
return;
m_ValuesListBox.GetText(index, value_name);
if (value_name.IsEmpty())
return;
// Display the prompt dialog
dlg.m_DialogTitle = "Value Name Prompt";
dlg.m_PromptText = "Enter a new name for this value:";
dlg.m_PromptData = value_name;
dlg.m_MaxDataLength = MAX_MESSAGE_NAME_LEN;
if (dlg.DoModal() == IDCANCEL)
return;
// Check if the value name is valid
char *valname = dlg.m_PromptData.GetBuffer(0);
if (strlen(valname) == 0)
return;
for (uint32_t j = 0; j < strlen(valname); j++)
if (!isalnum(valname[j]) && valname[j] != '_' && valname[j] != ' ') {
MessageBox("That name is invalid!\n\nA value name may only contain letters and numbers", "Invalid Name Error",
MB_OK | MB_ICONEXCLAMATION);
return;
}
// Check if the value name already exists in the list
int pos;
if (m_DallasModelessDlgPtr->GetEnumValue(type_name.GetBuffer(0), valname, pos) &&
strcmp(valname, value_name.GetBuffer(0)) != 0) {
MessageBox("That value name is already in use!\n\nYou must enter a UNIQUE name.", "Invalid Value Name",
MB_OK | MB_ICONEXCLAMATION);
return;
}
// Change the name of the value
if (m_DallasModelessDlgPtr->ChangeValueName(type_name.GetBuffer(0), value_name.GetBuffer(0), valname)) {
m_ValuesListBox.DeleteString(index);
m_ValuesListBox.InsertString(index, valname);
m_ValuesListBox.SetCurSel(index);
}
}
void CDallasUserTypesDlg::OnDeleteButton() {
int index;
CString type_name, value_name;
CDallasMainDlg *m_DallasModelessDlgPtr;
m_DallasModelessDlgPtr = GetDallasDialogPtr();
if (m_DallasModelessDlgPtr == NULL)
return;
// Get the name of the user type
index = m_UserTypeCombo.GetCurSel();
if (index == CB_ERR)
return;
m_UserTypeCombo.GetLBText(index, type_name);
if (type_name.IsEmpty())
return;
// Get the name of the selected value
index = m_ValuesListBox.GetCurSel();
if (index == LB_ERR)
return;
m_ValuesListBox.GetText(index, value_name);
if (value_name.IsEmpty())
return;
if (m_DallasModelessDlgPtr->DeleteUserTypeValue(type_name.GetBuffer(0), value_name.GetBuffer(0))) {
m_ValuesListBox.DeleteString(index);
}
}
void CDallasUserTypesDlg::OnOK() {
// TODO: Add extra validation here
CDialog::OnOK();
}
void CDallasUserTypesDlg::OnSelchangeUtypeCombo() {
int index;
CString name;
CDallasMainDlg *m_DallasModelessDlgPtr;
m_DallasModelessDlgPtr = GetDallasDialogPtr();
index = m_UserTypeCombo.GetCurSel();
if (index == CB_ERR)
return;
m_UserTypeCombo.GetLBText(index, name);
if (name.IsEmpty())
return;
last_type_selected = name;
// If Dallas is up, fill in the user type and value boxes
if (m_DallasModelessDlgPtr != NULL) {
m_DallasModelessDlgPtr->FillValuesBox(&m_ValuesListBox, name.GetBuffer(0));
}
}
void CDallasUserTypesDlg::OnDblclkValuesList() { OnChangeButton(); }
|