forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditLODDialog.cpp
More file actions
504 lines (433 loc) · 14.9 KB
/
EditLODDialog.cpp
File metadata and controls
504 lines (433 loc) · 14.9 KB
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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/*
** Command & Conquer Renegade(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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/>.
*/
// EditLODDialog.cpp : implementation file
//
#include "StdAfx.h"
#include "W3DView.h"
#include "EditLODDialog.h"
#include "distlod.h"
#include "Utils.h"
#include "rendobj.h"
#include "W3DViewDoc.h"
#ifdef RTS_DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////
//
// Local Constants
//
const int COL_NAME = 0;
const int COL_SWITCH_UP = 1;
const int COL_SWITCH_DN = 2;
/////////////////////////////////////////////////////////////
//
// CEditLODDialog
//
CEditLODDialog::CEditLODDialog(CWnd* pParent /*=NULL*/)
: m_spinIncrement (0.5F),
CDialog(CEditLODDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CEditLODDialog)
//}}AFX_DATA_INIT
return ;
}
/////////////////////////////////////////////////////////////
//
// DoDataExchange
//
void
CEditLODDialog::DoDataExchange (CDataExchange* pDX)
{
// Allow the base class to process this message
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEditLODDialog)
DDX_Control(pDX, IDC_SWITCH_UP_SPIN, m_switchUpSpin);
DDX_Control(pDX, IDC_SWITCH_DN_SPIN, m_switchDownSpin);
DDX_Control(pDX, IDC_HIERARCHY_LIST, m_hierarchyListCtrl);
//}}AFX_DATA_MAP
return ;
}
BEGIN_MESSAGE_MAP(CEditLODDialog, CDialog)
//{{AFX_MSG_MAP(CEditLODDialog)
ON_NOTIFY(UDN_DELTAPOS, IDC_SWITCH_UP_SPIN, OnDeltaposSwitchUpSpin)
ON_NOTIFY(UDN_DELTAPOS, IDC_SWITCH_DN_SPIN, OnDeltaposSwitchDnSpin)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_HIERARCHY_LIST, OnItemChangedHierarchyList)
ON_EN_UPDATE(IDC_SWITCH_DN_EDIT, OnUpdateSwitchDnEdit)
ON_EN_UPDATE(IDC_SWITCH_UP_EDIT, OnUpdateSwitchUpEdit)
ON_BN_CLICKED(IDC_RECALC, OnRecalc)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////
//
// OnInitDialog
//
BOOL
CEditLODDialog::OnInitDialog (void)
{
// Allow the base class to process this message
CDialog::OnInitDialog ();
// Center the dialog around the data tree view instead
// of the direct center of the screen
::CenterDialogAroundTreeView (m_hWnd);
// Get a pointer to the doc
CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
if (pCDoc)
{
// Get the current LOD from the doc
DistLODClass *pLOD = (DistLODClass *)pCDoc->GetDisplayedObject ();
ASSERT (pLOD);
if (pLOD)
{
int iSubObjects = pLOD->Get_Num_Sub_Objects ();
// Add the columns to the list control
m_hierarchyListCtrl.InsertColumn (COL_NAME, "Name");
m_hierarchyListCtrl.InsertColumn (COL_SWITCH_UP, "Switch Up");
m_hierarchyListCtrl.InsertColumn (COL_SWITCH_DN, "Switch Down");
RenderObjClass *pfirst_subobj = pLOD->Get_Sub_Object (0);
if (pfirst_subobj != NULL) {
m_spinIncrement = pfirst_subobj->Get_Bounding_Sphere ().Radius / 5.0F;
REF_PTR_RELEASE (pfirst_subobj);
}
// Loop through all the subobjects
for (int iObject = 0;
(iObject < iSubObjects);
iObject ++)
{
// Get this subobject
RenderObjClass *pCSubObject = pLOD->Get_Sub_Object (iObject);
if (pCSubObject)
{
// Add this object to the list
int iIndex = m_hierarchyListCtrl.InsertItem (COL_NAME, pCSubObject->Get_Name ());
CString stringTemp;
stringTemp.Format ("%.2f", pLOD->Get_Switch_Up_Dist (iObject));
m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_UP, stringTemp);
stringTemp.Format ("%.2f", pLOD->Get_Switch_Down_Dist (iObject));
m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_DN, stringTemp);
// Free this object
REF_PTR_RELEASE (pCSubObject);
}
}
m_switchUpSpin.SetRange (-20, UD_MAXVAL-20);
m_switchDownSpin.SetRange (-20, UD_MAXVAL-20);
// Resize the columns so they are wide enough to display the largest string
m_hierarchyListCtrl.SetColumnWidth (COL_NAME, LVSCW_AUTOSIZE);
m_hierarchyListCtrl.SetColumnWidth (COL_SWITCH_UP, LVSCW_AUTOSIZE_USEHEADER);
m_hierarchyListCtrl.SetColumnWidth (COL_SWITCH_DN, LVSCW_AUTOSIZE_USEHEADER);
// Select the first item in the list
m_hierarchyListCtrl.SetItemState (0, LVIS_SELECTED, LVIS_SELECTED);
}
}
return TRUE;
}
/////////////////////////////////////////////////////////////
//
// OnOK
//
void
CEditLODDialog::OnOK (void)
{
// Get a pointer to the doc
CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
if (pCDoc)
{
// Get the current LOD from the doc
DistLODClass *pLOD = (DistLODClass *)pCDoc->GetDisplayedObject ();
ASSERT (pLOD);
if (pLOD)
{
int iSubObjects = pLOD->Get_Num_Sub_Objects ();
// Loop through all the subobjects and add them to the list control
for (int iObject = 0;
(iObject < iSubObjects);
iObject ++)
{
// Get the switch up distance from the list control
CString stringTemp = m_hierarchyListCtrl.GetItemText (iObject, COL_SWITCH_UP);
// Convert the string to a float and pass this value
// onto the LOD manager
float switchDistance = ::atof (stringTemp);
pLOD->Set_Switch_Up_Dist (iObject, switchDistance);
// Get the switch down distance from the list control
stringTemp = m_hierarchyListCtrl.GetItemText (iObject, COL_SWITCH_DN);
// Convert the string to a float and pass this value
// onto the LOD manager
switchDistance = ::atof (stringTemp);
pLOD->Set_Switch_Down_Dist (iObject, switchDistance);
}
}
}
// Allow the base class to process this message
CDialog::OnOK ();
return ;
}
/////////////////////////////////////////////////////////////
//
// OnCancel
//
void
CEditLODDialog::OnCancel (void)
{
// Allow the base class to process this message
CDialog::OnCancel ();
return ;
}
/////////////////////////////////////////////////////////////
//
// OnDeltaposSwitchUpSpin
//
void
CEditLODDialog::OnDeltaposSwitchUpSpin
(
NMHDR* pNMHDR,
LRESULT* pResult
)
{
NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
if (pNMUpDown)
{
float newVal = float(pNMUpDown->iPos) / 10.00F;
// Change the switching distance in the edit control
CString stringTemp;
stringTemp.Format ("%.2f", newVal);
SetDlgItemText (IDC_SWITCH_UP_EDIT, stringTemp);
// Find the selected item in the list control
int iIndex = m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
if (iIndex != -1)
{
// Change the switching distance in the list control
m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_UP, stringTemp);
}
}
*pResult = 0;
return ;
}
/////////////////////////////////////////////////////////////
//
// OnDeltaposSwitchDnSpin
//
void
CEditLODDialog::OnDeltaposSwitchDnSpin
(
NMHDR* pNMHDR,
LRESULT* pResult
)
{
NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
if (pNMUpDown)
{
float newVal = float(pNMUpDown->iPos) / 10.00F;
// Change the switching distance in the edit control
CString stringTemp;
stringTemp.Format ("%.2f", newVal);
SetDlgItemText (IDC_SWITCH_DN_EDIT, stringTemp);
// Find the selected item in the list control
int iIndex = m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
if (iIndex != -1)
{
// Change the switching distance in the list control
m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_DN, stringTemp);
}
}
*pResult = 0;
return ;
}
/////////////////////////////////////////////////////////////
//
// OnItemChangedHierarchyList
//
void
CEditLODDialog::OnItemChangedHierarchyList
(
NMHDR* pNMHDR,
LRESULT* pResult
)
{
// Did the 'state' of the entry change?
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if (pNMListView &&
(pNMListView->uChanged & LVIF_STATE) == LVIF_STATE)
{
if ((pNMListView->uNewState & LVIS_SELECTED) != LVIS_SELECTED)
{
// Is there a selected item in the list control?
if (m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED) == -1)
{
// Disabled the edit and spin controls
EnableControls (FALSE);
}
}
else
{
// Enable the edit and spin controls
EnableControls (TRUE);
// Load the control with data for the selected item.
ResetControls (pNMListView->iItem);
}
}
*pResult = 0;
return ;
}
/////////////////////////////////////////////////////////////
//
// ResetControls
//
void
CEditLODDialog::ResetControls (int iIndex)
{
//
// Set the text of the group box
//
CString stringTemp = m_hierarchyListCtrl.GetItemText (iIndex, COL_NAME);
// Set the text of the group box
CString stringTitle;
stringTitle.Format ("Settings (%s)", (LPCTSTR)stringTemp);
SetDlgItemText (IDC_SETTINGS_GROUP, stringTitle);
//
// Reset the switch up controls
//
// Get the switch up distance from the list control
stringTemp = m_hierarchyListCtrl.GetItemText (iIndex, COL_SWITCH_UP);
// Set the text of the edit control to reflect the switching distance
SetDlgItemText (IDC_SWITCH_UP_EDIT, stringTemp);
// Set the current position of the spin control
float switchDistance = ::atof (stringTemp);
m_switchUpSpin.SetPos (int(switchDistance * 10.00F));
//
// Reset the switch down controls
//
// Get the switch down distance from the list control
stringTemp = m_hierarchyListCtrl.GetItemText (iIndex, COL_SWITCH_DN);
// Set the text of the edit control to reflect the switching distance
SetDlgItemText (IDC_SWITCH_DN_EDIT, stringTemp);
// Set the current position of the spin control
switchDistance = ::atof (stringTemp);
m_switchDownSpin.SetPos (int(switchDistance * 10.00F));
return ;
}
/////////////////////////////////////////////////////////////
//
// EnableControls
//
void
CEditLODDialog::EnableControls (BOOL bEnable)
{
// Enable or disable the windows
::EnableWindow (::GetDlgItem (m_hWnd, IDC_SETTINGS_GROUP), bEnable);
::EnableWindow (::GetDlgItem (m_hWnd, IDC_SWITCH_UP_SPIN), bEnable);
::EnableWindow (::GetDlgItem (m_hWnd, IDC_SWITCH_UP_EDIT), bEnable);
::EnableWindow (::GetDlgItem (m_hWnd, IDC_SWITCH_DN_SPIN), bEnable);
::EnableWindow (::GetDlgItem (m_hWnd, IDC_SWITCH_DN_EDIT), bEnable);
::EnableWindow (::GetDlgItem (m_hWnd, IDC_RECALC), bEnable);
return ;
}
/////////////////////////////////////////////////////////////
//
// OnUpdateSwitchDnEdit
//
void
CEditLODDialog::OnUpdateSwitchDnEdit (void)
{
// Get the switching distance from the edit control
CString stringTemp;
GetDlgItemText (IDC_SWITCH_DN_EDIT, stringTemp);
float newVal = ::atof (stringTemp);
// Change the switching distance in the spin control
m_switchDownSpin.SetPos (int(newVal * 10.00F));
// Find the selected item in the list control
int iIndex = m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
if (iIndex != -1)
{
// Change the switching distance in the list control
m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_DN, stringTemp);
}
return ;
}
/////////////////////////////////////////////////////////////
//
// OnUpdateSwitchUpEdit
//
void CEditLODDialog::OnUpdateSwitchUpEdit (void)
{
// Get the switching distance from the edit control
CString stringTemp;
GetDlgItemText (IDC_SWITCH_UP_EDIT, stringTemp);
float newVal = ::atof (stringTemp);
// Change the switching distance in the spin control
m_switchUpSpin.SetPos (int(newVal * 10.00F));
// Find the selected item in the list control
int iIndex = m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
if (iIndex != -1)
{
// Change the switching distance in the list control
m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_UP, stringTemp);
}
return ;
}
/////////////////////////////////////////////////////////////
//
// OnRecalc
//
void CEditLODDialog::OnRecalc (void)
{
// Get the up switching distance from the edit control
CString stringTemp;
GetDlgItemText (IDC_SWITCH_UP_EDIT, stringTemp);
float switchUp = ::atof (stringTemp);
// Get the down switching distance from the edit control
stringTemp;
GetDlgItemText (IDC_SWITCH_DN_EDIT, stringTemp);
float switchDown = ::atof (stringTemp);
if (switchUp < switchDown)
{
// Calculate the current range
float switchDelta = switchDown - switchUp;
float switchOverlap = switchDelta * 0.1F;
// Get a pointer to the doc
CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
if (pCDoc)
{
// Get the current LOD from the doc
DistLODClass *pLOD = (DistLODClass *)pCDoc->GetDisplayedObject ();
ASSERT (pLOD);
if (pLOD)
{
int iSubObjects = pLOD->Get_Num_Sub_Objects ();
switchUp = switchDown - switchOverlap;
// Loop through all the subobjects (following the highlighted one)
for (int iObject = m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED) + 1;
(iObject < iSubObjects);
iObject ++)
{
// Set the text of the switch up column
CString stringTemp;
stringTemp.Format ("%.2f", switchUp);
m_hierarchyListCtrl.SetItemText (iObject, COL_SWITCH_UP, stringTemp);
// Set the text of the switch dn column
stringTemp.Format ("%.2f", switchUp+switchDelta);
m_hierarchyListCtrl.SetItemText (iObject, COL_SWITCH_DN, stringTemp);
// Add the range to the switch up distance
switchUp += switchDelta-switchOverlap;
}
}
}
}
return ;
}