doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DialogAFConstraint.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "../../sys/win32/rc/AFEditor_resource.h"
33 
34 #include "DialogAF.h"
35 #include "DialogAFName.h"
36 #include "DialogAFConstraint.h"
43 
44 #ifdef ID_DEBUG_MEMORY
45 #undef new
46 #undef DEBUG_NEW
47 #define DEBUG_NEW new
48 #endif
49 
50 
51 typedef struct {
53  const char *name;
54 } c_type_t;
55 
57  { DECLAF_CONSTRAINT_FIXED, "fixed" },
58  { DECLAF_CONSTRAINT_BALLANDSOCKETJOINT, "ball and socket" },
59  { DECLAF_CONSTRAINT_UNIVERSALJOINT, "universal" },
60  { DECLAF_CONSTRAINT_HINGE, "hinge" },
61  { DECLAF_CONSTRAINT_SLIDER, "slider" },
62  { DECLAF_CONSTRAINT_SPRING, "spring" },
64 };
65 
66 
68  for ( int i = 0; constraintTypes[i].name; i++ ) {
69  if ( constraintTypes[i].type == type ) {
70  return constraintTypes[i].name;
71  }
72  }
73  return "";
74 }
75 
77  for ( int i = 0; constraintTypes[i].name; i++ ) {
78  if ( idStr::Icmp( constraintTypes[i].name, str ) == 0 ) {
79  return constraintTypes[i].type;
80  }
81  }
83 }
84 
85 
86 // DialogAFConstraint dialog
87 
89  { IDC_COMBO_CONSTRAINTS, "select contraint for editing" },
90  { IDC_BUTTON_NEWCONSTRAINT, "create a new constraint" },
91  { IDC_BUTTON_RENAMECONSTRAINT, "rename the selected constraint" },
92  { IDC_BUTTON_DELETECONSTRAINT, "delete the selected constraint" },
93  { IDC_COMBO_CONSTRAINT_TYPE, "constraint type" },
94  { IDC_COMBO_CONSTRAINT_BODY1, "first constrained body" },
95  { IDC_COMBO_CONSTRAINT_BODY2, "second constrained body" },
96  { IDC_EDIT_CONSTRAINT_FRICTION, "constraint friction" },
97  { 0, NULL }
98 };
99 
100 IMPLEMENT_DYNAMIC(DialogAFConstraint, CDialog)
101 
102 /*
103 ================
104 DialogAFConstraint::DialogAFConstraint
105 ================
106 */
107 DialogAFConstraint::DialogAFConstraint( CWnd* pParent /*=NULL*/ )
108  : CDialog(DialogAFConstraint::IDD, pParent)
109  , m_friction(0)
110  , constraint(NULL)
111  , file(NULL)
112  , constraintDlg(NULL)
113 {
114  Create( IDD_DIALOG_AF_CONSTRAINT, pParent );
115  EnableToolTips( TRUE );
116 }
117 
118 /*
119 ================
120 DialogAFConstraint::~DialogAFConstraint
121 ================
122 */
124 }
125 
126 /*
127 ================
128 DialogAFConstraint::DoDataExchange
129 ================
130 */
131 void DialogAFConstraint::DoDataExchange( CDataExchange* pDX ) {
132  CDialog::DoDataExchange(pDX);
133  //{{AFX_DATA_MAP(DialogAFConstraint)
134  DDX_Control(pDX, IDC_COMBO_CONSTRAINTS, m_comboConstraintList);
136  DDX_Control(pDX, IDC_COMBO_CONSTRAINT_BODY1, m_comboBody1List);
137  DDX_Control(pDX, IDC_COMBO_CONSTRAINT_BODY2, m_comboBody2List);
139  //}}AFX_DATA_MAP
140 }
141 
142 /*
143 ================
144 DialogAFConstraint::InitConstraintList
145 ================
146 */
148  CString str;
149 
150  m_comboConstraintList.ResetContent();
151  if ( !file ) {
152  return;
153  }
154  for ( int i = 0; i < file->constraints.Num(); i++ ) {
155  m_comboConstraintList.AddString( file->constraints[i]->name.c_str() );
156  }
157  if ( m_comboConstraintList.GetCount() != 0 ) {
158  m_comboConstraintList.SetCurSel( 0 );
159  m_comboConstraintList.GetLBText( 0, str );
160  LoadConstraint( str );
161  }
162 }
163 
164 /*
165 ================
166 DialogAFConstraint::InitConstraintTypeDlg
167 ================
168 */
170  CString str;
171  RECT rect;
172 
173  if ( !file || !constraint ) {
174  return;
175  }
176 
177  UpdateData( TRUE );
178 
179  if ( constraintDlg ) {
180  constraintDlg->ShowWindow( SW_HIDE );
181  }
182 
184  switch( StringToConstraintType( str ) ) {
188  break;
192  break;
196  break;
200  break;
204  break;
208  break;
209  }
210 
211  if ( constraintDlg ) {
212  constraintDlg->ShowWindow( SW_SHOW );
213  constraintDlg->GetWindowRect( &rect );
214  constraintDlg->MoveWindow( 0, 117, rect.right - rect.left, rect.bottom - rect.top );
215  }
216 }
217 
218 /*
219 ================
220 DialogAFConstraint::InitBodyLists
221 ================
222 */
224  m_comboBody1List.ResetContent();
225  m_comboBody2List.ResetContent();
226  if ( !file ) {
227  return;
228  }
229  for ( int i = 0; i < file->bodies.Num(); i++ ) {
230  m_comboBody1List.AddString( file->bodies[i]->name );
231  m_comboBody2List.AddString( file->bodies[i]->name );
232  }
233  // the second body may also be the world
234  m_comboBody2List.AddString( "world" ); // FIXME: we currently assume this is the last body in the list
235 }
236 
237 /*
238 ================
239 DialogAFConstraint::InitNewRenameDeleteButtons
240 ================
241 */
243  if ( file && file->bodies.Num() >= 1 ) {
244  GetDlgItem( IDC_BUTTON_NEWCONSTRAINT )->EnableWindow( true );
245  }
246  else {
247  GetDlgItem( IDC_BUTTON_NEWCONSTRAINT )->EnableWindow( false );
248  }
249 
250  if ( file && m_comboConstraintList.GetCount() >= 1 ) {
251  GetDlgItem( IDC_BUTTON_RENAMECONSTRAINT )->EnableWindow( true );
252  GetDlgItem( IDC_BUTTON_DELETECONSTRAINT )->EnableWindow( true );
253  }
254  else {
255  GetDlgItem( IDC_BUTTON_RENAMECONSTRAINT )->EnableWindow( false );
256  GetDlgItem( IDC_BUTTON_DELETECONSTRAINT )->EnableWindow( false );
257  }
258 }
259 
260 /*
261 ================
262 DialogAFConstraint::LoadFile
263 ================
264 */
266  file = af;
267  constraint = NULL;
268  ballAndSocketDlg->LoadFile( af );
269  universalDlg->LoadFile( af );
270  hingeDlg->LoadFile( af );
271  sliderDlg->LoadFile( af );
272  springDlg->LoadFile( af );
273  InitBodyLists();
276 }
277 
278 /*
279 ================
280 DialogAFConstraint::SaveFile
281 ================
282 */
284  SaveConstraint();
285 }
286 
287 /*
288 ================
289 DialogAFConstraint::LoadConstraint
290 ================
291 */
293  int i, s1, s2;
294 
295  if ( !file ) {
296  return;
297  }
298  for ( i = 0; i < file->constraints.Num(); i++ ) {
299  if ( file->constraints[i]->name.Icmp( name ) == 0 ) {
300  break;
301  }
302  }
303  if ( i >= file->constraints.Num() ) {
304  return;
305  }
307 
308  // load the constraint type from the current idDeclAF_Constraint
310 
311  // load constrained bodies from the current idDeclAF_Constraint
314 
315  // load friction from the current idDeclAF_Constraint
317 
318  // update displayed values
319  UpdateData( FALSE );
320 
322 
323  if ( GetStyle() & WS_VISIBLE ) {
324  // highlight the current constraint ingame
325  cvarSystem->SetCVarString( "af_highlightConstraint", name );
326  }
327 }
328 
329 /*
330 ================
331 DialogAFConstraint::SaveConstraint
332 ================
333 */
335  int s1, s2;
336  CString str;
337 
338  if ( !file || !constraint ) {
339  return;
340  }
341  UpdateData( TRUE );
342 
343  // save constraint type to the current idDeclAF_Constraint
346 
347  // save constrained bodies to the current idDeclAF_Constraint
348  s1 = GetSafeComboBoxSelection( &m_comboBody1List, str, -1 );
349  constraint->body1 = str;
350  s2 = GetSafeComboBoxSelection( &m_comboBody2List, str, s1 );
351  constraint->body2 = str;
352 
353  // save friction to the current idDeclAF_Constraint
355 
357 }
358 
359 /*
360 ================
361 DialogAFConstraint::UpdateFile
362 ================
363 */
365  SaveConstraint();
366  if ( file ) {
368  }
369 }
370 
371 /*
372 ================
373 DialogAFConstraint::OnInitDialog
374 ================
375 */
377 
378  CDialog::OnInitDialog();
379 
380  // initialize the constraint types
381  m_comboConstraintType.ResetContent();
382  for ( int i = 0; constraintTypes[i].name; i++ ) {
383  m_comboConstraintType.AddString( constraintTypes[i].name );
384  }
385 
386  fixedDlg = new DialogAFConstraintFixed( this );
387  fixedDlg->ShowWindow( SW_HIDE );
388 
390  ballAndSocketDlg->ShowWindow( SW_HIDE );
391 
393  universalDlg->ShowWindow( SW_HIDE );
394 
395  hingeDlg = new DialogAFConstraintHinge( this );
396  hingeDlg->ShowWindow( SW_HIDE );
397 
398  sliderDlg = new DialogAFConstraintSlider( this );
399  sliderDlg->ShowWindow( SW_HIDE );
400 
401  springDlg = new DialogAFConstraintSpring( this );
402  springDlg->ShowWindow( SW_HIDE );
403 
405 
407 
408  return TRUE; // return TRUE unless you set the focus to a control
409  // EXCEPTION: OCX Property Pages should return FALSE
410 }
411 
412 /*
413 ================
414 DialogAFConstraint::OnToolHitTest
415 ================
416 */
417 int DialogAFConstraint::OnToolHitTest( CPoint point, TOOLINFO* pTI ) const {
418  CDialog::OnToolHitTest( point, pTI );
419  return DefaultOnToolHitTest( toolTips, this, point, pTI );
420 }
421 
422 BEGIN_MESSAGE_MAP(DialogAFConstraint, CDialog)
423  ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
424  ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
425  ON_WM_SHOWWINDOW()
426  ON_CBN_SELCHANGE(IDC_COMBO_CONSTRAINTS, OnCbnSelchangeComboConstraints)
427  ON_CBN_SELCHANGE(IDC_COMBO_CONSTRAINT_TYPE, OnCbnSelchangeComboConstraintType)
428  ON_CBN_SELCHANGE(IDC_COMBO_CONSTRAINT_BODY1, OnCbnSelchangeComboConstraintBody1)
429  ON_CBN_SELCHANGE(IDC_COMBO_CONSTRAINT_BODY2, OnCbnSelchangeComboConstraintBody2)
430  ON_EN_CHANGE(IDC_EDIT_CONSTRAINT_FRICTION, OnEnChangeEditConstraintFriction)
431  ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_CONSTRAINT_FRICTION, OnDeltaposSpinConstraintFriction)
432  ON_BN_CLICKED(IDC_BUTTON_NEWCONSTRAINT, OnBnClickedButtonNewconstraint)
433  ON_BN_CLICKED(IDC_BUTTON_RENAMECONSTRAINT, OnBnClickedButtonRenameconstraint)
434  ON_BN_CLICKED(IDC_BUTTON_DELETECONSTRAINT, OnBnClickedButtonDeleteconstraint)
435 END_MESSAGE_MAP()
436 
437 
438 // DialogAFConstraint message handlers
439 
440 BOOL DialogAFConstraint::OnToolTipNotify( UINT id, NMHDR *pNMHDR, LRESULT *pResult ) {
441  return DefaultOnToolTipNotify( toolTips, id, pNMHDR, pResult );
442 }
443 
445  if ( bShow && constraint ) {
446  cvarSystem->SetCVarString( "af_highlightConstraint", constraint->name.c_str() );
447  } else {
448  cvarSystem->SetCVarString( "af_highlightConstraint", "" );
449  }
450  CDialog::OnShowWindow( bShow, nStatus );
451 }
452 
454  CString str;
455 
457  LoadConstraint( str );
458 }
459 
461  DialogAFName nameDlg;
462  CString str;
463 
465  if ( nameDlg.DoModal() == IDOK ) {
466  nameDlg.GetName( str );
467  // create new constraint
468  file->NewConstraint( str );
469  m_comboConstraintList.SetCurSel( m_comboConstraintList.AddString( str ) );
470  LoadConstraint( str );
473  }
475 }
476 
478  int i;
479  CString name, newName;
480  DialogAFName nameDlg;
481 
482  if ( !file || !constraint ) {
483  return;
484  }
485 
486  i = m_comboConstraintList.GetCurSel();
487  if ( i != CB_ERR ) {
488  m_comboConstraintList.GetLBText( i, name );
489  nameDlg.SetName( name );
491  if ( nameDlg.DoModal() == IDOK ) {
492  nameDlg.GetName( newName );
493  // rename constraint;
494  file->RenameConstraint( name, newName );
495  m_comboConstraintList.DeleteString( i );
496  m_comboConstraintList.SetCurSel( m_comboConstraintList.AddString( newName ) );
497  LoadConstraint( newName );
500  }
501  }
502 }
503 
505  int i;
506  CString str;
507 
508  if ( !file || !constraint ) {
509  return;
510  }
511 
512  i = m_comboConstraintList.GetCurSel();
513  if ( i != CB_ERR ) {
514  if ( MessageBox( "Are you sure you want to delete this constraint ?", "Delete Constraint", MB_YESNO | MB_ICONQUESTION ) == IDYES ) {
515  m_comboConstraintList.GetLBText( i, str );
516  // delete current constraint
517  file->DeleteConstraint( str );
518  constraint = NULL;
519  m_comboConstraintList.DeleteString( i );
523  }
524  }
526 }
527 
530  UpdateFile();
531 }
532 
534  CString str;
537  UpdateFile();
538 }
539 
541  CString str;
544  UpdateFile();
545 }
546 
548  if ( EditControlEnterHit( (CEdit *) GetDlgItem( IDC_EDIT_CONSTRAINT_FRICTION ) ) ) {
549  UpdateFile();
550  }
551  else {
552  EditVerifyFloat( (CEdit *) GetDlgItem( IDC_EDIT_CONSTRAINT_FRICTION ), false );
553  }
554 }
555 
556 void DialogAFConstraint::OnDeltaposSpinConstraintFriction(NMHDR *pNMHDR, LRESULT *pResult) {
557  LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
558  m_friction = EditSpinFloat( (CEdit *)GetDlgItem( IDC_EDIT_CONSTRAINT_FRICTION ), pNMUpDown->iDelta < 0 );
559  UpdateFile();
560  *pResult = 0;
561 }
CComboBox m_comboConstraintList
BOOL DefaultOnToolTipNotify(const toolTip_t *toolTips, UINT id, NMHDR *pNMHDR, LRESULT *pResult)
Definition: StdAfx.cpp:104
DialogAFConstraintSpring * springDlg
void InitNewRenameDeleteButtons(void)
idList< idDeclAF_Constraint * > constraints
Definition: DeclAF.h:190
const char * ConstraintTypeToString(declAFConstraintType_t type)
#define IDC_COMBO_CONSTRAINTS
virtual void AF_UpdateEntities(const char *fileName)
Definition: AFEntity.cpp:2856
void LoadConstraint(idDeclAF_Constraint *c)
idCVarSystem * cvarSystem
Definition: CVarSystem.cpp:487
declAFConstraintType_t type
Definition: DeclAF.h:117
void GetName(CString &str)
#define IDD_DIALOG_AF_CONSTRAINT
int SetSafeComboBoxSelection(CComboBox *combo, const char *string, int skip)
Definition: StdAfx.cpp:319
declAFConstraintType_t
Definition: DeclAF.h:42
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
#define IDC_COMBO_CONSTRAINT_BODY2
afx_msg void OnBnClickedButtonNewconstraint()
afx_msg void OnCbnSelchangeComboConstraints()
virtual BOOL OnInitDialog()
void SetComboBox(CComboBox *combo)
const char * GetName(void) const
Definition: DeclManager.h:140
virtual void SetCVarString(const char *name, const char *value, int flags=0)=0
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
void LoadConstraint(idDeclAF_Constraint *c)
void DeleteConstraint(const char *name)
Definition: DeclAF.cpp:1716
int i
Definition: process.py:33
#define BOOL
Definition: mprintf.c:71
int Icmp(const char *text) const
Definition: Str.h:667
void NewConstraint(const char *name)
Definition: DeclAF.cpp:1686
idGameEdit * gameEdit
Definition: GameEdit.cpp:668
afx_msg void OnEnChangeEditConstraintFriction()
DialogAFConstraintFixed * fixedDlg
afx_msg void OnBnClickedButtonRenameconstraint()
afx_msg void OnDeltaposSpinConstraintFriction(NMHDR *pNMHDR, LRESULT *pResult)
void LoadConstraint(idDeclAF_Constraint *c)
static toolTip_t toolTips[]
afx_msg void OnCbnSelchangeComboConstraintBody2()
#define IDC_COMBO_CONSTRAINT_TYPE
void LoadConstraint(idDeclAF_Constraint *c)
#define NULL
Definition: Lib.h:88
void LoadConstraint(idDeclAF_Constraint *c)
afx_msg void OnBnClickedButtonDeleteconstraint()
void LoadFile(idDeclAF *af)
int DefaultOnToolHitTest(const toolTip_t *toolTips, const CDialog *dialog, CPoint point, TOOLINFO *pTI)
Definition: StdAfx.cpp:75
int UnsetSafeComboBoxSelection(CComboBox *combo, CString &string)
Definition: StdAfx.cpp:366
void RenameConstraint(const char *oldName, const char *newName)
Definition: DeclAF.cpp:1700
const char * name
bool EditControlEnterHit(CEdit *edit)
Definition: StdAfx.cpp:154
declAFConstraintType_t StringToConstraintType(const char *str)
afx_msg void OnShowWindow(BOOL bShow, UINT nStatus)
virtual int OnToolHitTest(CPoint point, TOOLINFO *pTI) const
#define IDC_EDIT_CONSTRAINT_FRICTION
DialogAFConstraintBallAndSocket * ballAndSocketDlg
void SetName(CString &str)
#define IDC_SPIN_CONSTRAINT_FRICTION
declAFConstraintType_t type
int GetSafeComboBoxSelection(CComboBox *combo, CString &string, int skip)
Definition: StdAfx.cpp:341
virtual void DoDataExchange(CDataExchange *pDX)
void AFDialogSetFileModified(void)
Definition: DialogAF.cpp:613
idList< idDeclAF_Body * > bodies
Definition: DeclAF.h:189
int Num(void) const
Definition: List.h:265
afx_msg void OnCbnSelchangeComboConstraintType()
const GLcharARB * name
Definition: glext.h:3629
#define IDC_BUTTON_NEWCONSTRAINT
float EditSpinFloat(CEdit *edit, bool up)
Definition: StdAfx.cpp:305
const char * c_str(void) const
Definition: Str.h:487
#define FALSE
Definition: mprintf.c:70
#define TRUE
Definition: mprintf.c:69
void LoadConstraint(const char *name)
CComboBox m_comboConstraintType
DialogAFConstraintHinge * hingeDlg
#define IDC_BUTTON_RENAMECONSTRAINT
DialogAFConstraintSlider * sliderDlg
idDeclAF_Constraint * constraint
DialogAFConstraintUniversal * universalDlg
afx_msg void OnCbnSelchangeComboConstraintBody1()
#define IDC_COMBO_CONSTRAINT_BODY1
#define IDC_BUTTON_DELETECONSTRAINT
c_type_t constraintTypes[]
float EditVerifyFloat(CEdit *edit, bool allowNegative)
Definition: StdAfx.cpp:175