1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "nel/3d/particle_system.h"
24 #include "object_viewer.h"
25 #include "located_target_dlg.h"
26 #include "collision_zone_dlg.h"
27 #include "editable_range.h"
28 #include "attrib_dlg.h"
29 #include "direction_attr.h"
31 /////////////////////////////////////////////////////////////////////////////
32 // CLocatedTargetDlg dialog
35 CLocatedTargetDlg::CLocatedTargetDlg(CParticleWorkspace::CNode
*ownerNode
,
36 NL3D::CPSTargetLocatedBindable
*lbTarget
,
37 CParticleDlg
*particleDlg
) : _Node(ownerNode
), _LBTarget(lbTarget
), _ParticleDlg(particleDlg
)
39 nlassert(particleDlg
);
40 //{{AFX_DATA_INIT(CLocatedTargetDlg)
41 // NOTE: the ClassWizard will add member initialization here
46 void CLocatedTargetDlg::DoDataExchange(CDataExchange
* pDX
)
48 CDialog::DoDataExchange(pDX
);
49 //{{AFX_DATA_MAP(CLocatedTargetDlg)
50 DDX_Control(pDX
, IDC_AVAILABLE_TARGET
, m_AvailableTargets
);
51 DDX_Control(pDX
, IDC_TARGET
, m_Targets
);
56 BEGIN_MESSAGE_MAP(CLocatedTargetDlg
, CDialog
)
57 //{{AFX_MSG_MAP(CLocatedTargetDlg)
58 ON_BN_CLICKED(IDC_ADD_TARGET
, OnAddTarget
)
59 ON_BN_CLICKED(IDC_REMOVE_TARGET
, OnRemoveTarget
)
63 /////////////////////////////////////////////////////////////////////////////
64 // CLocatedTargetDlg message handlers
67 void CLocatedTargetDlg::init(CWnd
* pParent
)
69 Create(IDD_LOCATED_TARGET_DLG
, pParent
);
74 void CLocatedTargetDlg::OnAddTarget()
77 int totalCount
= m_AvailableTargets
.GetCount();
79 std::vector
<int> indexs
;
80 indexs
.resize(totalCount
);
81 int selCount
= m_AvailableTargets
.GetSelItems(totalCount
, &indexs
[0]);
83 std::sort(indexs
.begin(), indexs
.begin() + selCount
); // we never know ...
85 // check that force isn't applied on a forever lasting object
86 if (dynamic_cast<NL3D::CPSForce
*>(_LBTarget
))
88 bool forEverLastingTarget
= false;
89 for (int k
= 0; k
< selCount
; ++k
)
91 NL3D::CPSLocated
*loc
= (NL3D::CPSLocated
*) m_AvailableTargets
.GetItemData(indexs
[k
] - k
);
93 if (loc
->getLastForever())
95 forEverLastingTarget
= true;
99 if (forEverLastingTarget
)
103 warningStr
.LoadString(IDS_WARNING
);
104 messStr
.LoadString(IDS_FORCE_APPLIED_ON_OBJECT_THAT_LAST_FOREVER
);
105 if (MessageBox((LPCTSTR
) messStr
, (LPCTSTR
) warningStr
, MB_OKCANCEL
) != IDOK
)
112 for (int k
= 0; k
< selCount
; ++k
)
114 NL3D::CPSLocated
*loc
= (NL3D::CPSLocated
*) m_AvailableTargets
.GetItemData(indexs
[k
] - k
);
116 _LBTarget
->attachTarget(loc
);
117 m_AvailableTargets
.DeleteString(indexs
[k
] - k
);
118 int l
= m_Targets
.AddString(nlUtf8ToTStr(loc
->getName()));
119 m_Targets
.SetItemData(l
, (DWORD_PTR
) loc
);
123 updateModifiedFlag();
126 void CLocatedTargetDlg::OnRemoveTarget()
129 int totalCount
= m_Targets
.GetCount();
130 nlassert(totalCount
);
131 std::vector
<int> indexs
;
132 indexs
.resize(totalCount
);
133 int selCount
= m_Targets
.GetSelItems(totalCount
, &indexs
[0]);
134 std::sort(indexs
.begin(), indexs
.begin() + selCount
); // we never know ...
135 for (int k
= 0; k
< selCount
; ++k
)
137 NL3D::CPSLocated
*loc
= (NL3D::CPSLocated
*) m_Targets
.GetItemData(indexs
[k
] - k
);
139 _LBTarget
->detachTarget(loc
);
140 m_Targets
.DeleteString(indexs
[k
] - k
);
141 int l
= m_AvailableTargets
.AddString(nlUtf8ToTStr(loc
->getName()));
143 m_AvailableTargets
.SetItemData(l
, (DWORD_PTR
) loc
);
146 updateModifiedFlag();
149 BOOL
CLocatedTargetDlg::OnInitDialog()
151 CDialog::OnInitDialog();
156 uint nbTarg
= _LBTarget
->getNbTargets();
158 m_Targets
.InitStorage(nbTarg
, 128);
160 std::set
<NL3D::CPSLocated
*> targetSet
;
162 // fill the box thta tells us what the target are
163 for(k
= 0; k
< nbTarg
; ++k
)
165 m_Targets
.AddString(nlUtf8ToTStr(_LBTarget
->getTarget(k
)->getName()));
166 m_Targets
.SetItemData(k
, (DWORD_PTR
) _LBTarget
->getTarget(k
));
167 targetSet
.insert(_LBTarget
->getTarget(k
));
170 // fill abox with the available targets
171 NL3D::CParticleSystem
*ps
= _LBTarget
->getOwner()->getOwner();
173 uint nbLocated
= ps
->getNbProcess();
177 m_AvailableTargets
.InitStorage(nbTarg
, 128);
178 for (k
= 0; k
< nbLocated
; ++k
)
180 NL3D::CPSLocated
*loc
= dynamic_cast<NL3D::CPSLocated
*>(ps
->getProcess(k
));
183 if (targetSet
.find(loc
) == targetSet
.end())
185 int l
= m_AvailableTargets
.AddString(nlUtf8ToTStr(loc
->getName()));
186 m_AvailableTargets
.SetItemData(l
, (DWORD_PTR
) loc
);
194 // collision zone case
196 if (dynamic_cast<NL3D::CPSZone
*>(_LBTarget
))
198 CCollisionZoneDlg
*czd
= new CCollisionZoneDlg(_Node
, dynamic_cast<NL3D::CPSZone
*>(_LBTarget
), _ParticleDlg
);
200 czd
->init(posX
, posY
, this);
204 // force with intensity case
206 if (dynamic_cast<NL3D::CPSForceIntensity
*>(_LBTarget
))
208 _ForceIntensityWrapper
.F
= dynamic_cast<NL3D::CPSForceIntensity
*>(_LBTarget
);
209 CAttribDlgFloat
*fi
= new CAttribDlgFloat(std::string("FORCE INTENSITY"), _Node
, 0, 100);
211 fi
->setWrapper(&_ForceIntensityWrapper
);
212 fi
->setSchemeWrapper(&_ForceIntensityWrapper
);
214 HBITMAP bmh
= LoadBitmap(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_FORCE_INTENSITY
));
215 fi
->init(bmh
, posX
, posY
, this);
218 fi
->GetClientRect(&r
);
219 posY
+= r
.bottom
+ 3;
222 // vortex (to tune viscosity)
223 if (dynamic_cast<NL3D::CPSCylindricVortex
*>(_LBTarget
))
225 CEditableRangeFloat
*rv
= new CEditableRangeFloat(std::string("RADIAL_VISCOSITY"), _Node
, 0, 1);
227 _RadialViscosityWrapper
.V
= dynamic_cast<NL3D::CPSCylindricVortex
*>(_LBTarget
);
228 rv
->setWrapper(&_RadialViscosityWrapper
);
229 rv
->init(posX
+ 140, posY
, this);
230 CStatic
*s
= new CStatic
;
232 s
->Create(_T("Radial viscosity : "), SS_LEFT
, CRect(posX
, posY
, posX
+ 139, posY
+ 32), this);
233 s
->SetFont(CFont::FromHandle((HFONT
) GetStockObject(DEFAULT_GUI_FONT
)));
234 s
->ShowWindow(SW_SHOW
);
237 rv
->GetClientRect(&r
);
238 posY
+= r
.bottom
+ 3;
240 CEditableRangeFloat
*tv
= new CEditableRangeFloat(std::string("TANGENTIAL_VISCOSITY"), _Node
, 0, 1);
242 _TangentialViscosityWrapper
.V
= dynamic_cast<NL3D::CPSCylindricVortex
*>(_LBTarget
);
243 tv
->setWrapper(&_TangentialViscosityWrapper
);
244 tv
->init(posX
+ 140, posY
, this);
248 s
->Create(_T("Tangential Viscosity : "), SS_LEFT
, CRect(posX
, posY
, posX
+ 139, posY
+ 32), this);
249 s
->ShowWindow(SW_SHOW
);
251 tv
->GetClientRect(&r
);
252 posY
+= r
.bottom
+ 3;
255 // deals with emitters that have a direction
256 if (dynamic_cast<NL3D::CPSDirection
*>(_LBTarget
))
258 CDirectionAttr
*da
= new CDirectionAttr(std::string("DIRECTION"));
260 _DirectionWrapper
.E
= dynamic_cast<NL3D::CPSDirection
*>(_LBTarget
);
261 da
->setWrapper(&_DirectionWrapper
);
262 da
->setDirectionWrapper(dynamic_cast<NL3D::CPSDirection
*>(_LBTarget
));
263 da
->init(posX
, posY
, this);
264 da
->GetClientRect(&r
);
268 // Brownian (to tune parametric factor)
269 if (dynamic_cast<NL3D::CPSBrownianForce
*>(_LBTarget
))
271 CEditableRangeFloat
*rv
= new CEditableRangeFloat(std::string("PARAMETRIC_FACTOR"), _Node
, 0, 64);
273 _ParamFactorWrapper
.F
= static_cast<NL3D::CPSBrownianForce
*>(_LBTarget
);
274 rv
->setWrapper(&_ParamFactorWrapper
);
275 rv
->init(posX
+ 140, posY
, this);
276 CStatic
*s
= new CStatic
;
278 s
->Create(_T("Parametric factor : "), SS_LEFT
, CRect(posX
, posY
, posX
+ 139, posY
+ 40), this);
279 s
->SetFont(CFont::FromHandle((HFONT
) GetStockObject(DEFAULT_GUI_FONT
)));
280 s
->ShowWindow(SW_SHOW
);
282 rv
->GetClientRect(&r
);
283 posY
+= r
.bottom
+ 3;
290 return TRUE
; // return TRUE unless you set the focus to a control
291 // EXCEPTION: OCX Property Pages should return FALSE