!XT (BREAK-16) (Sandbox) Remove double-newlines at the end of files.
[CRYENGINE.git] / Code / Sandbox / Plugins / VehicleEditor / VehicleModificationDialog.h
blob02482eafe7583266d6fde9b996bf0a6a4579ed83
1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 class CVehicleModificationDialog : public CDialog
5 DECLARE_DYNAMIC(CVehicleModificationDialog)
7 public:
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; }
16 // Dialog Data
17 enum { IDD = IDD_VEED_MODS };
19 protected:
20 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
21 DECLARE_MESSAGE_MAP()
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();
32 void ReloadModList();
33 void SelectMod(IVariable* pMod);
34 IVariable* GetSelectedVar();
36 CPropertyCtrl m_propsCtrl;
37 CListBox m_modList;
38 IVariable* m_pVar;
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)
53 m_pVar = 0;
56 BEGIN_MESSAGE_MAP(CVehicleModificationDialog, CDialog)
57 ON_WM_SIZE()
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)
64 END_MESSAGE_MAP()
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()
76 EndDialog(IDCANCEL);
79 //////////////////////////////////////////////////////////////////////////////
80 void CVehicleModificationDialog::OnOkClicked()
82 EndDialog(IDOK);
85 #define WND_PROPS_LEFT 282
86 #define WND_PROPS_TOP 27
88 //////////////////////////////////////////////////////////////////////////////
89 BOOL CVehicleModificationDialog::OnInitDialog()
91 CDialog::OnInitDialog();
93 WINDOWPLACEMENT wp;
94 GetWindowPlacement(&wp);
96 int width = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
97 int height = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top;
99 CWnd* wnd;
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
108 m_propsLeft = 280;
110 m_propsTop = wpNew.rcNormalPosition.top;
113 CRect clientRect;
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);
119 ReloadModList();
121 return TRUE;
124 //////////////////////////////////////////////////////////////////////////////
125 void CVehicleModificationDialog::SetVariable(IVariable* pVar)
127 if (pVar)
128 m_pVar = pVar->Clone(true);
129 else
131 m_pVar = new CVariableArray();
132 m_pVar->SetName("Modifications");
136 //////////////////////////////////////////////////////////////////////////////
137 void CVehicleModificationDialog::OnSelChanged()
139 UpdateData(TRUE);
140 int idx = m_modList.GetCurSel();
141 if (idx != LB_ERR)
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);
188 ReloadModList();
189 SelectMod(pMod);
192 //////////////////////////////////////////////////////////////////////////////
193 void CVehicleModificationDialog::OnModClone()
195 IVariable* pMod = GetSelectedVar();
196 if (!pMod)
197 return;
199 IVariable* pClone = pMod->Clone(true);
200 m_pVar->AddVariable(pClone);
202 ReloadModList();
203 SelectMod(pClone);
206 //////////////////////////////////////////////////////////////////////////////
207 void CVehicleModificationDialog::OnModDelete()
209 int idx = m_modList.GetCurSel();
211 IVariable* pMod = GetSelectedVar();
212 if (pMod)
214 m_modList.DeleteString(m_modList.GetCurSel());
215 m_pVar->DeleteVariable(pMod);
218 m_propsCtrl.DeleteAllItems();
220 if (idx > 0)
222 m_modList.SetCurSel(idx - 1);
223 OnSelChanged();
227 //////////////////////////////////////////////////////////////////////////////
228 void CVehicleModificationDialog::ReloadModList()
230 if (m_pVar)
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"))
240 string name;
241 pName->Get(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);
257 OnSelChanged();
258 break;
263 //////////////////////////////////////////////////////////////////////////////
264 IVariable* CVehicleModificationDialog::GetSelectedVar()
266 int idx = m_modList.GetCurSel();
267 if (idx != LB_ERR)
268 return (IVariable*)m_modList.GetItemDataPtr(idx);
270 return NULL;
273 //////////////////////////////////////////////////////////////////////////
274 void CVehicleModificationDialog::OnSize(UINT nType, int cx, int cy)
276 __super::OnSize(nType, cx, cy);
278 if (m_propsCtrl.GetSafeHwnd())
280 CRect rect;
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 };
290 CWnd* wnd;
291 WINDOWPLACEMENT wp;
293 GetWindowPlacement(&wp);
295 for (int i = 0; i < CRY_ARRAY_COUNT(Buttons); ++i)
297 if (wnd = GetDlgItem(Buttons[i]))
299 WINDOWPLACEMENT wp2;
300 wnd->GetWindowPlacement(&wp2);
301 int dy = wp2.rcNormalPosition.bottom - wp2.rcNormalPosition.top;
303 CRect rect;
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);