1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 class CVehicleModificationDialog
: public CDialog
5 DECLARE_DYNAMIC(CVehicleModificationDialog
)
8 CVehicleModificationDialog(CWnd
* pParent
= NULL
); // standard constructor
9 virtual ~CVehicleModificationDialog(){}
11 virtual BOOL
OnInitDialog();
13 void SetVariable(IVariable
* pVar
);
14 IVariable
* GetVariable() { return m_pVar
; }
17 enum { IDD
= IDD_VEED_MODS
};
20 virtual void DoDataExchange(CDataExchange
* pDX
); // DDX/DDV support
23 afx_msg
void OnSize(UINT nType
, int cx
, int cy
);
25 afx_msg
void OnCancelClicked();
26 afx_msg
void OnOkClicked();
27 afx_msg
void OnSelChanged();
28 afx_msg
void OnModNew();
29 afx_msg
void OnModClone();
30 afx_msg
void OnModDelete();
33 void SelectMod(IVariable
* pMod
);
34 IVariable
* GetSelectedVar();
36 CPropertyCtrl m_propsCtrl
;
40 int m_propsLeft
, m_propsTop
;
44 //////////////////////////////////////////////////////////////////////////////
45 // CVehicleModificationDialog implementation
46 //////////////////////////////////////////////////////////////////////////////
48 IMPLEMENT_DYNAMIC(CVehicleModificationDialog
, CDialog
)
50 CVehicleModificationDialog::CVehicleModificationDialog(CWnd
* pParent
/*=NULL*/)
51 : CDialog(CVehicleModificationDialog::IDD
, pParent
)
56 BEGIN_MESSAGE_MAP(CVehicleModificationDialog
, CDialog
)
58 ON_BN_CLICKED(IDC_VEEDMOD_CLOSE
, OnCancelClicked
)
59 ON_BN_CLICKED(IDC_VEEDMOD_SAVE
, OnOkClicked
)
60 ON_LBN_SELCHANGE(IDC_VEEDMOD_LIST
, OnSelChanged
)
61 ON_BN_CLICKED(IDC_VEEDMOD_NEW
, OnModNew
)
62 ON_BN_CLICKED(IDC_VEEDMOD_CLONE
, OnModClone
)
63 ON_BN_CLICKED(IDC_VEEDMOD_DELETE
, OnModDelete
)
66 //////////////////////////////////////////////////////////////////////////////
67 void CVehicleModificationDialog::DoDataExchange(CDataExchange
* pDX
)
69 CDialog::DoDataExchange(pDX
);
70 DDX_Control(pDX
, IDC_VEEDMOD_LIST
, m_modList
);
73 //////////////////////////////////////////////////////////////////////////////
74 void CVehicleModificationDialog::OnCancelClicked()
79 //////////////////////////////////////////////////////////////////////////////
80 void CVehicleModificationDialog::OnOkClicked()
85 #define WND_PROPS_LEFT 282
86 #define WND_PROPS_TOP 27
88 //////////////////////////////////////////////////////////////////////////////
89 BOOL
CVehicleModificationDialog::OnInitDialog()
91 CDialog::OnInitDialog();
94 GetWindowPlacement(&wp
);
96 int width
= wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
;
97 int height
= wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
;
101 if (wnd
= GetDlgItem(IDC_VEEDMOD_NEW
))
103 WINDOWPLACEMENT wpNew
;
104 wnd
->GetWindowPlacement(&wpNew
);
106 //m_propsLeft = width - wpNew.rcNormalPosition.right + 20;
107 // fixme: the above delivers obviously oversized values, dunno why
110 m_propsTop
= wpNew
.rcNormalPosition
.top
;
114 GetClientRect(clientRect
);
116 CRect
rc(m_propsLeft
, m_propsTop
, clientRect
.right
- 20, clientRect
.bottom
- 15);
117 m_propsCtrl
.Create(WS_CHILD
| WS_VISIBLE
| WS_BORDER
, rc
, this);
124 //////////////////////////////////////////////////////////////////////////////
125 void CVehicleModificationDialog::SetVariable(IVariable
* pVar
)
128 m_pVar
= pVar
->Clone(true);
131 m_pVar
= new CVariableArray();
132 m_pVar
->SetName("Modifications");
136 //////////////////////////////////////////////////////////////////////////////
137 void CVehicleModificationDialog::OnSelChanged()
140 int idx
= m_modList
.GetCurSel();
143 IVariable
* pModVar
= (IVariable
*)m_modList
.GetItemDataPtr(idx
);
145 // update props panel
146 _smart_ptr
<CVarBlock
> block
= new CVarBlock();
147 block
->AddVariable(pModVar
);
149 m_propsCtrl
.DeleteAllItems();
150 m_propsCtrl
.AddVarBlock(block
);
152 m_propsCtrl
.ExpandAll();
154 if (IVariable
* pElems
= GetChildVar(pModVar
, "Elems"))
156 m_propsCtrl
.ExpandVariableAndChilds(pElems
, false);
158 CPropertyItem
* pItem
= m_propsCtrl
.FindItemByVar(pElems
);
160 // expand Elems children
161 for (int i
= 0; i
< pItem
->GetChildCount(); ++i
)
163 CPropertyItem
* pElem
= pItem
->GetChild(i
);
164 m_propsCtrl
.Expand(pElem
, true);
166 if (IVariable
* pId
= GetChildVar(pElem
->GetVariable(), "idRef"))
168 pId
->SetFlags(pId
->GetFlags() | IVariable::UI_DISABLED
);
175 //////////////////////////////////////////////////////////////////////////////
176 void CVehicleModificationDialog::OnModNew()
178 IVariable
* pMod
= new CVariableArray();
179 pMod
->SetName("Modification");
181 IVariable
* pName
= new CVariable
<string
>;
182 pName
->SetName("name");
183 pName
->Set("new modification");
185 pMod
->AddVariable(pName
);
186 m_pVar
->AddVariable(pMod
);
192 //////////////////////////////////////////////////////////////////////////////
193 void CVehicleModificationDialog::OnModClone()
195 IVariable
* pMod
= GetSelectedVar();
199 IVariable
* pClone
= pMod
->Clone(true);
200 m_pVar
->AddVariable(pClone
);
206 //////////////////////////////////////////////////////////////////////////////
207 void CVehicleModificationDialog::OnModDelete()
209 int idx
= m_modList
.GetCurSel();
211 IVariable
* pMod
= GetSelectedVar();
214 m_modList
.DeleteString(m_modList
.GetCurSel());
215 m_pVar
->DeleteVariable(pMod
);
218 m_propsCtrl
.DeleteAllItems();
222 m_modList
.SetCurSel(idx
- 1);
227 //////////////////////////////////////////////////////////////////////////////
228 void CVehicleModificationDialog::ReloadModList()
232 // fill mods into listbox
233 m_modList
.ResetContent();
235 for (int i
= 0; i
< m_pVar
->GetNumVariables(); ++i
)
237 IVariable
* pMod
= m_pVar
->GetVariable(i
);
238 if (IVariable
* pName
= GetChildVar(pMod
, "name"))
242 int idx
= m_modList
.AddString(name
);
243 m_modList
.SetItemDataPtr(idx
, pMod
);
249 //////////////////////////////////////////////////////////////////////////////
250 void CVehicleModificationDialog::SelectMod(IVariable
* pMod
)
252 for (int i
= 0; i
< m_modList
.GetCount(); ++i
)
254 if (m_modList
.GetItemDataPtr(i
) == pMod
)
256 m_modList
.SetCurSel(i
);
263 //////////////////////////////////////////////////////////////////////////////
264 IVariable
* CVehicleModificationDialog::GetSelectedVar()
266 int idx
= m_modList
.GetCurSel();
268 return (IVariable
*)m_modList
.GetItemDataPtr(idx
);
273 //////////////////////////////////////////////////////////////////////////
274 void CVehicleModificationDialog::OnSize(UINT nType
, int cx
, int cy
)
276 __super::OnSize(nType
, cx
, cy
);
278 if (m_propsCtrl
.GetSafeHwnd())
281 rect
.left
= m_propsLeft
;
282 rect
.top
= m_propsTop
;
283 rect
.right
= cx
- 20;
284 rect
.bottom
= cy
- 20;
285 m_propsCtrl
.MoveWindow(rect
, TRUE
);
288 int Buttons
[] = { IDC_VEEDMOD_CLOSE
, IDC_VEEDMOD_SAVE
};
293 GetWindowPlacement(&wp
);
295 for (int i
= 0; i
< CRY_ARRAY_COUNT(Buttons
); ++i
)
297 if (wnd
= GetDlgItem(Buttons
[i
]))
300 wnd
->GetWindowPlacement(&wp2
);
301 int dy
= wp2
.rcNormalPosition
.bottom
- wp2
.rcNormalPosition
.top
;
304 wnd
->GetWindowRect(rect
); // rel to parent
305 ScreenToClient(rect
);
307 //rect.left = wp2.rcNormalPosition.left - wp.rcNormalPosition.left;
308 //rect.right = wp2.rcNormalPosition.right - wp.rcNormalPosition.left;
309 rect
.top
= cy
- 15 - dy
;
310 rect
.bottom
= cy
- 15;
311 wnd
->MoveWindow(rect
, TRUE
);