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
|
/*
* 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 "ReinforcementEditorDlg.h"
#include "mission/missionparse.h"
#include "globalincs/linklist.h"
#include "ship/ship.h"
#include "FREDDoc.h"
#include "Management.h"
#include "mission/missionmessage.h"
#define ID_WING_DATA 9000
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// reinforcement_editor_dlg dialog
reinforcement_editor_dlg::reinforcement_editor_dlg(CWnd* pParent /*=NULL*/)
: CDialog(reinforcement_editor_dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(reinforcement_editor_dlg)
m_uses = 0;
m_delay = 0;
//}}AFX_DATA_INIT
cur = -1;
}
void reinforcement_editor_dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(reinforcement_editor_dlg)
DDX_Control(pDX, IDC_DELAY_SPIN, m_delay_spin);
DDX_Control(pDX, IDC_USES_SPIN, m_uses_spin);
DDX_Text(pDX, IDC_USES, m_uses);
DDX_Text(pDX, IDC_DELAY, m_delay);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(reinforcement_editor_dlg, CDialog)
//{{AFX_MSG_MAP(reinforcement_editor_dlg)
ON_LBN_SELCHANGE(IDC_LIST, OnSelchangeList)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// reinforcement_editor_dlg message handlers
BOOL reinforcement_editor_dlg::OnInitDialog()
{
int i;
CListBox *box;
CDialog::OnInitDialog();
theApp.init_window(&Reinforcement_wnd_data, this);
box = (CListBox *) GetDlgItem(IDC_LIST);
for (i=0; i<Num_reinforcements; i++) {
m_reinforcements[i] = Reinforcements[i];
box->AddString(Reinforcements[i].name);
}
m_num_reinforcements = Num_reinforcements;
m_uses_spin.SetRange(1, 99);
m_delay_spin.SetRange(0, 1000);
update_data();
if (Num_reinforcements == MAX_REINFORCEMENTS)
GetDlgItem(IDC_ADD) -> EnableWindow(FALSE);
return TRUE;
}
void reinforcement_editor_dlg::update_data()
{
object *objp;
int enable = TRUE;
if (cur < 0) {
m_uses = 0;
m_delay = 0;
enable = FALSE;
} else {
m_uses = m_reinforcements[cur].uses;
m_delay = m_reinforcements[cur].arrival_delay;
}
UpdateData(FALSE);
GetDlgItem(IDC_USES)->EnableWindow(enable);
GetDlgItem(IDC_USES_SPIN)->EnableWindow(enable);
GetDlgItem(IDC_DELAY)->EnableWindow(enable);
GetDlgItem(IDC_DELAY_SPIN)->EnableWindow(enable);
if (cur < 0)
return;
// disable the uses entries if the reinforcement is a ship
objp = GET_FIRST(&obj_used_list);
while (objp != END_OF_LIST(&obj_used_list)) {
if (objp->type == OBJ_SHIP) {
if ( !stricmp( Ships[objp->instance].ship_name, m_reinforcements[cur].name) ) {
GetDlgItem(IDC_USES)->EnableWindow(FALSE);
GetDlgItem(IDC_USES_SPIN)->EnableWindow(FALSE);
break;
}
}
objp = GET_NEXT(objp);
}
}
void reinforcement_editor_dlg::OnSelchangeList()
{
save_data();
cur = ((CListBox *) GetDlgItem(IDC_LIST))->GetCurSel();
GetDlgItem(IDC_DELETE) -> EnableWindow(cur != -1);
update_data();
}
void reinforcement_editor_dlg::save_data()
{
UpdateData(TRUE);
UpdateData(TRUE);
if (cur >= 0) {
Assert(cur < m_num_reinforcements);
m_reinforcements[cur].uses = m_uses;
m_reinforcements[cur].arrival_delay = m_delay;
// save the message information to the reinforcement structure. First clear out the string
// entires in the Reinforcement structure
memset( m_reinforcements[cur].no_messages, 0, MAX_REINFORCEMENT_MESSAGES * NAME_LENGTH );
memset( m_reinforcements[cur].yes_messages, 0, MAX_REINFORCEMENT_MESSAGES * NAME_LENGTH );
}
}
int reinforcement_editor_dlg::query_modified()
{
int i, j;
save_data();
if (Num_reinforcements != m_num_reinforcements)
return 1;
for (i=0; i<Num_reinforcements; i++) {
if (stricmp(m_reinforcements[i].name, Reinforcements[i].name))
return 1;
if (m_reinforcements[i].uses != Reinforcements[i].uses)
return 1;
if ( m_reinforcements[i].arrival_delay != Reinforcements[i].arrival_delay )
return 1;
// determine if the message content has changed
for ( j = 0; j < MAX_REINFORCEMENT_MESSAGES; j++ ) {
if ( stricmp(m_reinforcements[i].no_messages[j], Reinforcements[i].no_messages[j]) )
return 1;
}
for ( j = 0; j < MAX_REINFORCEMENT_MESSAGES; j++ ) {
if ( stricmp(m_reinforcements[i].yes_messages[j], Reinforcements[i].yes_messages[j]) )
return 1;
}
}
return 0;
}
void reinforcement_editor_dlg::OnOK()
{
int i, j;
save_data();
// clear arrival cues for any new reinforcements to the list
for (i=0; i<m_num_reinforcements; i++) {
for (j=0; j<Num_reinforcements; j++)
if (!stricmp(m_reinforcements[i].name, Reinforcements[j].name))
break;
if (j == Num_reinforcements) {
for (j=0; j<MAX_SHIPS; j++)
if ((Ships[j].objnum != -1) && !stricmp(m_reinforcements[i].name, Ships[j].ship_name)) {
//free_sexp2(Ships[j].arrival_cue);
//Ships[j].arrival_cue = Locked_sexp_false;
break;
}
if (j == MAX_SHIPS) {
for (j=0; j<MAX_WINGS; j++)
if (Wings[j].wave_count && !stricmp(m_reinforcements[i].name, Wings[j].name)) {
//free_sexp2(Wings[j].arrival_cue);
//Wings[j].arrival_cue = Locked_sexp_false;
break;
}
Assert(j < MAX_WINGS);
}
}
}
if (Num_reinforcements != m_num_reinforcements)
set_modified();
Num_reinforcements = m_num_reinforcements;
for (i=0; i<m_num_reinforcements; i++) {
if (memcmp((void *) &Reinforcements[i], (void *) &m_reinforcements[i], sizeof(reinforcements)))
set_modified();
Reinforcements[i] = m_reinforcements[i];
set_reinforcement( Reinforcements[i].name, 1 ); // this call should
}
Update_ship = Update_wing = 1;
theApp.record_window_data(&Reinforcement_wnd_data, this);
CDialog::OnOK();
}
void reinforcement_editor_dlg::OnCancel()
{
theApp.record_window_data(&Reinforcement_wnd_data, this);
CDialog::OnCancel();
}
/////////////////////////////////////////////////////////////////////////////
// reinforcement_select dialog
reinforcement_select::reinforcement_select(CWnd* pParent /*=NULL*/)
: CDialog(reinforcement_select::IDD, pParent)
{
//{{AFX_DATA_INIT(reinforcement_select)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
cur = -1;
}
void reinforcement_select::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(reinforcement_select)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(reinforcement_select, CDialog)
//{{AFX_MSG_MAP(reinforcement_select)
ON_LBN_SELCHANGE(IDC_LIST, OnSelchangeList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// reinforcement_select message handlers
BOOL reinforcement_select::OnInitDialog()
{
int i, z;
CListBox *box;
object *ptr;
CDialog::OnInitDialog();
box = (CListBox *) GetDlgItem(IDC_LIST);
ptr = GET_FIRST(&obj_used_list);
while (ptr != END_OF_LIST(&obj_used_list)) {
if (ptr->type == OBJ_SHIP && Ships[ptr->instance].wingnum < 0) {
z = box->AddString(Ships[ptr->instance].ship_name);
box->SetItemData(z, OBJ_INDEX(ptr));
}
ptr = GET_NEXT(ptr);
}
for (i=0; i<Num_wings; i++) {
z = box->AddString(Wings[i].name);
box->SetItemData(z, ID_WING_DATA + i);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void reinforcement_select::OnSelchangeList()
{
cur = ((CListBox *) GetDlgItem(IDC_LIST))->GetCurSel();
GetDlgItem(IDOK)->EnableWindow(cur != -1);
}
void reinforcement_select::OnOK()
{
cur = ((CListBox *) GetDlgItem(IDC_LIST))->GetCurSel();
Assert(cur != -1);
((CListBox *) GetDlgItem(IDC_LIST)) -> GetText(cur, name);
CDialog::OnOK();
}
void reinforcement_select::OnCancel()
{
cur = -1;
CDialog::OnCancel();
}
void reinforcement_editor_dlg::OnAdd()
{
int i, wing_index;
reinforcement_select dlg;
CString name_check;
dlg.DoModal();
if (dlg.cur != -1) {
// if we've run out of reinforcement slots
if (m_num_reinforcements == MAX_REINFORCEMENTS) {
MessageBox("Reached limit on reinforcements. Can't add more!");
return;
}
// if this is a wing, make sure its a valid wing (no mixed ship teams)
wing_index = wing_lookup((char*)dlg.name);
if(wing_index >= 0){
if(wing_has_conflicting_teams(wing_index)){
MessageBox("Cannot have a reinforcement wing with mixed teams, sucka!");
return;
}
}
i = m_num_reinforcements++;
strcpy_s(m_reinforcements[i].name, dlg.name);
((CListBox *) GetDlgItem(IDC_LIST)) -> AddString(dlg.name);
m_reinforcements[i].type = 0;
m_reinforcements[i].uses = 1;
m_reinforcements[i].arrival_delay = 0;
memset( m_reinforcements[i].no_messages, 0, MAX_REINFORCEMENT_MESSAGES * NAME_LENGTH );
memset( m_reinforcements[i].yes_messages, 0, MAX_REINFORCEMENT_MESSAGES * NAME_LENGTH );
if (m_num_reinforcements == MAX_REINFORCEMENTS){
GetDlgItem(IDC_ADD) -> EnableWindow(FALSE);
}
}
}
void reinforcement_editor_dlg::OnDelete()
{
int i;
if (cur != -1) {
((CListBox *) GetDlgItem(IDC_LIST)) -> DeleteString(cur);
for (i=cur; i<m_num_reinforcements-1; i++)
m_reinforcements[i] = m_reinforcements[i + 1];
}
m_num_reinforcements--;
cur = -1;
if (!m_reinforcements)
GetDlgItem(IDC_DELETE) -> EnableWindow(FALSE);
}
void reinforcement_editor_dlg::OnClose()
{
int z;
if (query_modified()) {
z = MessageBox("Do you want to keep your changes?", "Close", MB_ICONQUESTION | MB_YESNOCANCEL);
if (z == IDCANCEL)
return;
if (z == IDYES) {
OnOK();
return;
}
}
CDialog::OnClose();
}
|