File: ObjectPropertiesDialog.cpp

package info (click to toggle)
descent3 1.5.0%2Bds-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 35,256 kB
  • sloc: cpp: 416,147; ansic: 3,233; sh: 10; makefile: 8
file content (323 lines) | stat: -rw-r--r-- 9,646 bytes parent folder | download | duplicates (3)
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
/*
 * 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/>.
 */

// ObjectPropertiesDialog.cpp : implementation file
//

#include "stdafx.h"
#include "editor.h"
#include "PropertyAIDlg.h"
#include "PropertyPhysicsDlg.h"
#include "ObjectPropertiesDialog.h"
#include "pserror.h"
#include "ddio.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CObjectPropertiesDialog dialog

CObjectPropertiesDialog::CObjectPropertiesDialog(CWnd *pParent /*=NULL*/)
    : CDialog(CObjectPropertiesDialog::IDD, pParent) {
  //{{AFX_DATA_INIT(CObjectPropertiesDialog)
  // NOTE: the ClassWizard will add member initialization here
  //}}AFX_DATA_INIT
  m_Parent = pParent;
  m_Initializing = FALSE;
  m_KeypadTabDialog = NULL;
  m_PropPhysicsDlg = NULL;
  m_current_tab = 0;
}

void CObjectPropertiesDialog::DoDataExchange(CDataExchange *pDX) {
  CDialog::DoDataExchange(pDX);
  //{{AFX_DATA_MAP(CObjectPropertiesDialog)
  // NOTE: the ClassWizard will add DDX and DDV calls here
  //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CObjectPropertiesDialog, CDialog)
//{{AFX_MSG_MAP(CObjectPropertiesDialog)
ON_WM_SHOWWINDOW()
ON_WM_SIZE()
ON_WM_MOVE()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CObjectPropertiesDialog message handlers

BOOL CObjectPropertiesDialog::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT &rect,
                                     CWnd *pParentWnd, UINT nID, CCreateContext *pContext) {
  // TODO: Add your specialized code here and/or call the base class

  return CDialog::Create(IDD, pParentWnd);
}

BOOL CObjectPropertiesDialog::OnInitDialog() {
  CDialog::OnInitDialog();

  CTabCtrl *tab_ctrl;
  TC_ITEM tc_item;

  m_current_tab = 0;

  tab_ctrl = (CTabCtrl *)GetDlgItem(IDC_PROPERTYTAB);

  //	Add tabs to tabcontrol in the keypad dialog bar.
  tc_item.mask = TCIF_TEXT;
  tc_item.pszText = "Physics";
  tc_item.cchTextMax = lstrlen(tc_item.pszText) + 1;
  tab_ctrl->InsertItem(TAB_PHYSICS, &tc_item);

  tc_item.mask = TCIF_TEXT;
  tc_item.pszText = "AI";
  tc_item.cchTextMax = lstrlen(tc_item.pszText) + 1;
  tab_ctrl->InsertItem(TAB_AI, &tc_item);

  //	fit keypad dialogs in tab control
  RECT tab_rect, tab_winrect;
  int tx, ty, tw, th;

  tab_ctrl->GetWindowRect(&tab_winrect);
  ::CopyRect(&tab_rect, &tab_winrect);
  tab_ctrl->AdjustRect(FALSE, &tab_rect);
  tx = tab_rect.left - tab_winrect.left;
  ty = tab_rect.top - tab_winrect.top;
  tw = tab_rect.right - tab_rect.left;
  th = tab_rect.bottom - tab_rect.top;

  //	Create tab dialogs
  //	resize them to fit the tab control
  //	set scroll bars accordingly
  m_PropAIDlg = new CPropertyAIDlg(tab_ctrl);
  m_PropAIDlg->Create();
  m_PropAIDlg->SetWindowPos(tab_ctrl, tx, ty, tw, th, SWP_NOZORDER);

  m_PropPhysicsDlg = new CPropertyPhysicsDlg(tab_ctrl);
  m_PropPhysicsDlg->Create();
  m_PropPhysicsDlg->SetWindowPos(tab_ctrl, tx, ty, tw, th, SWP_NOZORDER);

  //	Display current tab dialog
  switch (m_current_tab) {
  case TAB_PHYSICS:
    m_KeypadTabDialog = m_PropPhysicsDlg;
    break;
  case TAB_AI:
    m_KeypadTabDialog = m_PropAIDlg;
    break;
  default:
    Int3();
  }

  tab_ctrl->SetCurSel(m_current_tab);

  return TRUE; // return TRUE unless you set the focus to a control
               // EXCEPTION: OCX Property Pages should return FALSE
}

void CObjectPropertiesDialog::RunKeypadFunction(int code) {
  if (m_KeypadTabDialog)
    m_KeypadTabDialog->RunKeypadFunction(code);
}

void CObjectPropertiesDialog::Activate() {
  if (m_KeypadTabDialog)
    m_KeypadTabDialog->Activate();
}

void CObjectPropertiesDialog::Deactivate() {
  if (m_KeypadTabDialog)
    m_KeypadTabDialog->Deactivate();
}

void CObjectPropertiesDialog::OnShowWindow(BOOL bShow, UINT nStatus) {
  CDialog::OnShowWindow(bShow, nStatus);

  m_Initializing = FALSE;

  if (bShow)
    m_KeypadTabDialog->ShowWindow(SW_SHOW);
}

BOOL CObjectPropertiesDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT *pResult) {
  // TODO: Add your specialized code here and/or call the base class
  //	Perform notification requests on the keypad tab dialog bar and other
  //	custom control bars.
  NMHDR *nmhdr;

  assert(lParam != 0);

  nmhdr = (NMHDR *)lParam;

  switch (wParam) {
  case IDC_PROPERTYTAB:
    DoKeypadTabNotify(nmhdr);
    break;
  }

  return CDialog::OnNotify(wParam, lParam, pResult);
}

void CObjectPropertiesDialog::OnSize(UINT nType, int cx, int cy) {
  RECT rect;
  CTabCtrl *tab_ctrl;

  CDialog::OnSize(nType, cx, cy);

  if (m_Initializing)
    return;

  SetRect(&rect, 0, 0, cx, cy);
  ::AdjustWindowRect(&rect, GetStyle(), FALSE);

  m_keypad_w = rect.right - rect.left;
  m_keypad_h = rect.bottom - rect.top;

  SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);

  //	Resize tab to fit current modeless dialog size
  RECT tab_rect, tab_winrect;
  int tx, ty, tw, th;

  tab_ctrl = (CTabCtrl *)GetDlgItem(IDC_PROPERTYTAB);

  GetClientRect(&tab_rect);
  tab_ctrl->MoveWindow(&tab_rect);

  tab_ctrl->GetWindowRect(&tab_winrect);
  ::CopyRect(&tab_rect, &tab_winrect);
  tab_ctrl->AdjustRect(FALSE, &tab_rect);
  tx = tab_rect.left - tab_winrect.left;
  ty = tab_rect.top - tab_winrect.top;
  tw = tab_rect.right - tab_rect.left;
  th = tab_rect.bottom - tab_rect.top;

  m_PropAIDlg->SetWindowPos(tab_ctrl, tx, ty, tw, th, SWP_NOZORDER);
  m_PropPhysicsDlg->SetWindowPos(tab_ctrl, tx, ty, tw, th, SWP_NOZORDER);
}

void CObjectPropertiesDialog::OnMove(int x, int y) {
  CDialog::OnMove(x, y);

  // TODO: Add your message handler code here
  //	if we haven't placed this dialog anywhere, wait till parent does it for us.
  if (m_Initializing)
    return;

  RECT rect;
  GetWindowRect(&rect);
  GetParent()->ScreenToClient(&rect);
  m_keypad_x = rect.left;
  m_keypad_y = rect.top;

  SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
}

int CObjectPropertiesDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) {
  if (CDialog::OnCreate(lpCreateStruct) == -1)
    return -1;

  // TODO: Add your specialized creation code here
  m_Initializing = TRUE;

  return 0;
}

void CObjectPropertiesDialog::DoKeypadTabNotify(NMHDR *nmhdr) // take care of tab control notifications
{
  CTabCtrl *tab_ctrl;

  tab_ctrl = (CTabCtrl *)GetDlgItem(IDC_PROPERTYTAB);

  switch (nmhdr->code) {
  case TCN_SELCHANGE:
    // Tab control changed. So update the controls currently displayed.
    m_current_tab = (int)tab_ctrl->GetCurSel();
    assert(m_current_tab > -1);

    switch (m_current_tab) {
    case TAB_AI:
      if (m_KeypadTabDialog)
        m_KeypadTabDialog->ShowWindow(SW_HIDE);
      m_KeypadTabDialog = m_PropAIDlg;
      m_KeypadTabDialog->ShowWindow(SW_SHOW);
      break;

    case TAB_PHYSICS:
      if (m_KeypadTabDialog)
        m_KeypadTabDialog->ShowWindow(SW_HIDE);
      m_KeypadTabDialog = m_PropPhysicsDlg;
      m_KeypadTabDialog->ShowWindow(SW_SHOW);
      break;
    }
    break;
  }
}

void CObjectPropertiesDialog::OnOK() {
  // TODO: Add extra validation here
  ddio_KeyFlush();
  m_PropPhysicsDlg->UpdateData(true);
  CDialog::OnOK();
  m_bBounce = m_PropPhysicsDlg->m_bBounce;
  m_fDrag = m_PropPhysicsDlg->m_fDrag;
  m_fFullRotThrust = m_PropPhysicsDlg->m_fFullRotThrust;
  m_fFullThrust = m_PropPhysicsDlg->m_fFullThrust;
  m_bGravity = m_PropPhysicsDlg->m_bGravity;
  m_bLevelling = m_PropPhysicsDlg->m_bLevelling;
  m_bMagnetism = m_PropPhysicsDlg->m_bMagnetism;
  m_fMass = m_PropPhysicsDlg->m_fMass;
  m_fMaxTurnrollrate = m_PropPhysicsDlg->m_fMaxTurnrollrate;
  m_iNumBounces = m_PropPhysicsDlg->m_iNumBounces;
  m_bPersistent = m_PropPhysicsDlg->m_bPersistent;
  m_fRotDrag = m_PropPhysicsDlg->m_fRotDrag;
  m_fRotThrustX = m_PropPhysicsDlg->m_fRotThrustX;
  m_fRotThrustY = m_PropPhysicsDlg->m_fRotThrustY;
  m_fRotThrustZ = m_PropPhysicsDlg->m_fRotThrustZ;
  m_fRotVelX = m_PropPhysicsDlg->m_fRotVelX;
  m_fRotVelY = m_PropPhysicsDlg->m_fRotVelY;
  m_fRotVelZ = m_PropPhysicsDlg->m_fRotVelZ;
  m_bSticks = m_PropPhysicsDlg->m_bSticks;
  m_fThrustX = m_PropPhysicsDlg->m_fThrustX;
  m_fThrustY = m_PropPhysicsDlg->m_fThrustY;
  m_fThrustZ = m_PropPhysicsDlg->m_fThrustZ;
  m_bTurnroll = m_PropPhysicsDlg->m_bTurnroll;
  m_fTurnrollRatio = m_PropPhysicsDlg->m_fTurnrollRatio;
  m_sTurnrollAngle = m_PropPhysicsDlg->m_sTurnrollAngle;
  m_bUsesThrust = m_PropPhysicsDlg->m_bUsesThrust;
  m_fVelocityX = m_PropPhysicsDlg->m_fVelocityX;
  m_fVelocityY = m_PropPhysicsDlg->m_fVelocityY;
  m_fVelocityZ = m_PropPhysicsDlg->m_fVelocityZ;
  m_bWiggle = m_PropPhysicsDlg->m_bWiggle;
  m_fWiggleAmplitude = m_PropPhysicsDlg->m_fWiggleAmplitude;
  m_fWigglesPerSecond = m_PropPhysicsDlg->m_fWigglesPerSecond;
  m_bWind = m_PropPhysicsDlg->m_bWind;
  m_bUnlimitedBounce = m_PropPhysicsDlg->m_bUnlimitedBounce;
}

void CObjectPropertiesDialog::OnCancel() {
  // TODO: Add extra cleanup here
  ddio_KeyFlush();
  CDialog::OnCancel();
}