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 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
|
/*
* Copyright (C) Volition, Inc. 1999. All rights reserved.
*
* All source code herein is the property of Volition, Inc. You may not sell
* or otherwise commercially exploit the source or things you created based on the
* source.
*
*/
#include "stdafx.h"
#include "FRED.h"
#include "JumpnodeDlg.h"
#include "Management.h"
#include "MainFrm.h"
#include "object/object.h"
#include "jumpnode/jumpnode.h"
#define ID_JUMP_NODE_MENU 8000
#define ID_WAYPOINT_MENU 9000
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// waypoint_path_dlg dialog
jumpnode_dlg::jumpnode_dlg(CWnd* pParent /*=NULL*/)
: CDialog(jumpnode_dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(jumpnode_dlg)
m_name = _T("");
m_display = _T("");
m_filename = _T("");
m_color_r = 0;
m_color_g = 0;
m_color_b = 0;
m_color_a = 0;
m_hidden = FALSE;
//}}AFX_DATA_INIT
bypass_errors = 0;
}
void jumpnode_dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(jumpnode_dlg)
DDX_Text(pDX, IDC_NAME, m_name);
DDX_Text(pDX, IDC_ALT_NAME, m_display);
DDX_Text(pDX, IDC_MODEL_FILENAME, m_filename);
DDX_Text(pDX, IDC_NODE_R, m_color_r);
DDV_MinMaxInt(pDX, m_color_r, 0, 255);
DDX_Text(pDX, IDC_NODE_G, m_color_g);
DDV_MinMaxInt(pDX, m_color_g, 0, 255);
DDX_Text(pDX, IDC_NODE_B, m_color_b);
DDV_MinMaxInt(pDX, m_color_b, 0, 255);
DDX_Text(pDX, IDC_NODE_A, m_color_a);
DDV_MinMaxInt(pDX, m_color_a, 0, 255);
DDX_Check(pDX, IDC_NODE_HIDDEN, m_hidden);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(jumpnode_dlg, CDialog)
//{{AFX_MSG_MAP(jumpnode_dlg)
ON_BN_CLICKED(IDC_NODE_HIDDEN, OnHidden)
ON_WM_CLOSE()
ON_WM_INITMENU()
ON_EN_KILLFOCUS(IDC_NAME, OnKillfocusName)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// jumpnode_dlg message handlers
BOOL jumpnode_dlg::Create()
{
BOOL r;
r = CDialog::Create(IDD, Fred_main_wnd);
initialize_data(1);
return r;
}
void jumpnode_dlg::OnInitMenu(CMenu* pMenu)
{
int i;
SCP_list<CJumpNode>::iterator jnp;
CMenu *m;
m = pMenu->GetSubMenu(0);
clear_menu(m);
i = 0;
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
m->AppendMenu(MF_ENABLED | MF_STRING, ID_JUMP_NODE_MENU + i, jnp->GetName());
if (jnp->GetSCPObjectNumber() == cur_object_index) {
m->CheckMenuItem(ID_JUMP_NODE_MENU + i, MF_BYCOMMAND | MF_CHECKED);
}
i++;
}
m->DeleteMenu(ID_PLACEHOLDER, MF_BYCOMMAND);
CDialog::OnInitMenu(pMenu);
}
void jumpnode_dlg::OnOK() {
}
void jumpnode_dlg::OnClose()
{
UpdateData(TRUE);
if (update_data()) {
SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
bypass_errors = 0;
return;
}
SetWindowPos(Fred_main_wnd, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW);
Fred_main_wnd->SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
void jumpnode_dlg::initialize_data(int full_update)
{
int enable = TRUE;
SCP_list<CJumpNode>::iterator jnp;
if (!GetSafeHwnd())
return;
if (Objects[cur_object_index].type == OBJ_JUMP_NODE) {
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
if(jnp->GetSCPObject() == &Objects[cur_object_index])
break;
}
m_name = _T(jnp->GetName());
m_display = _T(jnp->GetDisplayName());
int model = jnp->GetModelNumber();
polymodel* pm = model_get(model);
m_filename = _T(pm->filename);
const auto &jn_color = jnp->GetColor();
m_color_r = jn_color.red;
m_color_g = jn_color.green;
m_color_b = jn_color.blue;
m_color_a = jn_color.alpha;
m_hidden = (int)jnp->IsHidden();
} else {
m_name = _T("");
m_display = _T("");
m_filename = _T("");
m_color_r = 0;
m_color_g = 0;
m_color_b = 0;
m_color_a = 0;
m_hidden = FALSE;
enable = FALSE;
}
if (full_update)
UpdateData(FALSE);
GetDlgItem(IDC_NAME)->EnableWindow(enable);
}
int jumpnode_dlg::update_data()
{
const char *str;
char old_name[255];
int i, z;
object *ptr;
SCP_list<CJumpNode>::iterator jnp;
if (!GetSafeHwnd())
return 0;
if (query_valid_object() && Objects[cur_object_index].type == OBJ_JUMP_NODE) {
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
if(jnp->GetSCPObject() == &Objects[cur_object_index])
break;
}
for (i=0; i<MAX_WINGS; i++)
{
if (!stricmp(Wings[i].name, m_name)) {
if (bypass_errors)
return 1;
bypass_errors = 1;
z = MessageBox("This jump node name is already being used by a wing\n"
"Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
if (z == IDCANCEL)
return -1;
m_name = _T(jnp->GetName());
UpdateData(FALSE);
}
}
ptr = GET_FIRST(&obj_used_list);
while (ptr != END_OF_LIST(&obj_used_list)) {
if ((ptr->type == OBJ_SHIP) || (ptr->type == OBJ_START)) {
if (!stricmp(m_name, Ships[ptr->instance].ship_name)) {
if (bypass_errors)
return 1;
bypass_errors = 1;
z = MessageBox("This jump node name is already being used by a ship\n"
"Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
if (z == IDCANCEL)
return -1;
m_name = _T(jnp->GetName());
UpdateData(FALSE);
}
}
ptr = GET_NEXT(ptr);
}
// We don't need to check teams. "Unknown" is a valid name and also an IFF.
for ( i=0; i < (int)Ai_tp_list.size(); i++) {
if (!stricmp(m_name, Ai_tp_list[i].name)) {
if (bypass_errors)
return 1;
bypass_errors = 1;
z = MessageBox("This jump node name is already being used by a target priority group.\n"
"Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
if (z == IDCANCEL)
return -1;
m_name = _T(jnp->GetName());
UpdateData(FALSE);
}
}
if (find_matching_waypoint_list((LPCSTR) m_name) != NULL)
{
if (bypass_errors)
return 1;
bypass_errors = 1;
z = MessageBox("This jump node name is already being used by a waypoint path\n"
"Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
if (z == IDCANCEL)
return -1;
m_name = _T(jnp->GetName());
UpdateData(FALSE);
}
if (!stricmp(m_name.Left(1), "<")) {
if (bypass_errors)
return 1;
bypass_errors = 1;
z = MessageBox("Jump node names not allowed to begin with <\n"
"Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
if (z == IDCANCEL)
return -1;
m_name = _T(jnp->GetName());
UpdateData(FALSE);
}
CJumpNode* found = jumpnode_get_by_name(m_name);
if(found != NULL && &(*jnp) != found)
{
if (bypass_errors)
return 1;
bypass_errors = 1;
z = MessageBox("This jump node name is already being used by another jump node\n"
"Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
if (z == IDCANCEL)
return -1;
m_name = _T(jnp->GetName());
UpdateData(FALSE);
}
strcpy_s(old_name, jnp->GetName());
jnp->SetName((LPCSTR) m_name);
jnp->SetDisplayName((LPCSTR) m_display);
int model = jnp->GetModelNumber();
polymodel* pm = model_get(model);
CString old_filename = _T(pm->filename);
// Does that pof file exist?
if (cf_exists_full((LPCSTR)m_filename, CF_TYPE_MODELS)) {
if (stricmp((LPCSTR)m_filename, JN_DEFAULT_MODEL)) {
jnp->SetModel((LPCSTR)m_filename);
}
} else {
if (bypass_errors)
return 1;
bypass_errors = 1;
z = MessageBox("This jump node pof file does not exist\n"
"Press OK to restore old file", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
if (z == IDCANCEL)
return -1;
m_filename = old_filename;
UpdateData(FALSE);
}
jnp->SetAlphaColor(m_color_r, m_color_g, m_color_b, m_color_a);
jnp->SetVisibility(!(bool)m_hidden);
str = (LPCTSTR) m_name;
if (strcmp(old_name, str)) {
update_sexp_references(old_name, str);
}
}
update_map_window();
return 0;
}
BOOL jumpnode_dlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
int id, point;
object *ptr;
id = LOWORD(wParam);
if ((id >= ID_JUMP_NODE_MENU) && (id < ID_JUMP_NODE_MENU + (int) Jump_nodes.size())) {
if (!update_data()) {
point = id - ID_JUMP_NODE_MENU;
unmark_all();
ptr = GET_FIRST(&obj_used_list);
while ((ptr != END_OF_LIST(&obj_used_list)) && (point > -1)) {
if (ptr->type == OBJ_JUMP_NODE) {
if (point == 0) {
mark_object(OBJ_INDEX(ptr));
}
point--;
}
ptr = GET_NEXT(ptr);
}
return 1;
}
}
return CDialog::OnCommand(wParam, lParam);
}
void jumpnode_dlg::OnHidden()
{
if (m_hidden == 1)
m_hidden = 0;
else
m_hidden = 1;
((CButton*)GetDlgItem(IDC_NODE_HIDDEN))->SetCheck(m_hidden);
}
void jumpnode_dlg::OnKillfocusName()
{
char buffer[NAME_LENGTH];
// Note, in this dialog, UpdateData(TRUE) is not used to move data from controls to variables until the dialog is closed, so we edit the control text directly
// grab the name
GetDlgItemText(IDC_NAME, buffer, NAME_LENGTH);
// if this name has a hash, truncate it for the display name
if (get_pointer_to_first_hash_symbol(buffer))
end_string_at_first_hash_symbol(buffer);
// set the display name derived from this name
SetDlgItemText(IDC_ALT_NAME, buffer);
}
|