Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / 3d / object_viewer / located_properties.cpp
blob8189cf3fe03fb2526598578bc85171c8785790d7
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
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/>.
21 // located_properties.cpp : implementation file
24 #include "std_afx.h"
25 #include "object_viewer.h"
26 #include "located_properties.h"
27 #include "particle_dlg.h"
28 #include "particle_tree_ctrl.h"
29 #include "attrib_dlg.h"
30 #include "lb_extern_id_dlg.h"
31 #include "object_viewer.h"
33 #include "nel/3d/ps_located.h"
34 #include "nel/3d/particle_system.h"
36 using NL3D::CPSLocated;
38 //****************************************************************************************************************
39 /////////////////////////////////////////////////////////////////////////////
40 // CLocatedProperties dialog
41 CLocatedProperties::CLocatedProperties(CParticleWorkspace::CNode *node, NL3D::CPSLocated *loc, CParticleDlg *pdlg)
42 : CDialog(CLocatedProperties::IDD, pdlg), _Node(node), _Located(loc), _ParticleDlg(pdlg), _MassDialog(NULL), _LifeDialog(NULL)
44 //{{AFX_DATA_INIT(CLocatedProperties)
45 m_LimitedLifeTime = FALSE;
46 m_MatrixMode = 0;
47 m_DisgradeWithLOD = FALSE;
48 m_ParametricIntegration = FALSE;
49 m_ParametricMotion = FALSE;
50 m_TriggerOnDeath = FALSE;
51 m_MatrixMode = -1;
52 //}}AFX_DATA_INIT
54 nlassert(pdlg->getObjectViewer());
55 pdlg->getObjectViewer()->registerMainLoopCallBack(this);
58 _MaxNbParticles = new CEditableRangeUInt("MAX_NB_PARTICLES", _Node, 1, 501);
59 _MaxNbParticles->enableUpperBound(30000, false);
63 //****************************************************************************************************************
64 CLocatedProperties::~CLocatedProperties()
66 nlassert(_ParticleDlg && _ParticleDlg->getObjectViewer());
67 _ParticleDlg->getObjectViewer()->removeMainLoopCallBack(this);
69 _MassDialog->DestroyWindow();
70 _LifeDialog->DestroyWindow();
71 _MaxNbParticles->DestroyWindow();
73 delete _LifeDialog;
74 delete _MassDialog;
75 delete _MaxNbParticles;
79 //****************************************************************************************************************
80 void CLocatedProperties::DoDataExchange(CDataExchange* pDX)
82 CDialog::DoDataExchange(pDX);
83 //{{AFX_DATA_MAP(CLocatedProperties)
84 DDX_Control(pDX, IDC_EDIT_TRIGGER_ON_DEATH, m_EditTriggerOnDeath);
85 DDX_Control(pDX, IDC_TRIGGER_ON_DEATH, m_TriggerOnDeathCtrl);
86 DDX_Control(pDX, IDC_PARAMETRIC_MOTION, m_ParametricMotionCtrl);
87 DDX_Control(pDX, IDC_PARTICLE_NUMBER_POS, m_MaxNbParticles);
88 DDX_Check(pDX, IDC_LIMITED_LIFE_TIME, m_LimitedLifeTime);
89 DDX_Check(pDX, IDC_DISGRADE_WITH_LOD, m_DisgradeWithLOD);
90 DDX_Check(pDX, IDC_PARAMETRIC_MOTION, m_ParametricMotion);
91 DDX_Check(pDX, IDC_TRIGGER_ON_DEATH, m_TriggerOnDeath);
92 DDX_CBIndex(pDX, IDC_MATRIX_MODE, m_MatrixMode);
93 //}}AFX_DATA_MAP
97 BEGIN_MESSAGE_MAP(CLocatedProperties, CDialog)
98 //{{AFX_MSG_MAP(CLocatedProperties)
99 ON_BN_CLICKED(IDC_LIMITED_LIFE_TIME, OnLimitedLifeTime)
100 ON_BN_CLICKED(IDC_DISGRADE_WITH_LOD, OnDisgradeWithLod)
101 ON_BN_CLICKED(IDC_PARAMETRIC_MOTION, OnParametricMotion)
102 ON_BN_CLICKED(IDC_EDIT_TRIGGER_ON_DEATH, OnEditTriggerOnDeath)
103 ON_BN_CLICKED(IDC_TRIGGER_ON_DEATH, OnTriggerOnDeath)
104 ON_BN_CLICKED(IDC_ASSIGN_COUNT, OnAssignCount)
105 ON_CBN_SELCHANGE(IDC_MATRIX_MODE, OnSelchangeMatrixMode)
106 //}}AFX_MSG_MAP
107 END_MESSAGE_MAP()
109 //****************************************************************************************************************
110 /////////////////////////////////////////////////////////////////////////////
111 // CLocatedProperties message handlers
112 BOOL CLocatedProperties::OnInitDialog()
114 CDialog::OnInitDialog();
117 return TRUE; // return TRUE unless you set the focus to a control
118 // EXCEPTION: OCX Property Pages should return FALSE
121 ///////////////////////////////////////////
124 //****************************************************************************************************************
125 void CLocatedProperties::init(uint32 x, uint32 y)
128 Create(IDD_LOCATED_PROPERTIES, (CWnd *) _ParticleDlg);
129 RECT r, pr;
130 GetClientRect(&r);
131 MoveWindow(x, y, r.right, r.bottom);
133 GetWindowRect(&pr);
136 const sint xPos = 0;
137 sint yPos = 100;
139 _LifeDialog = new CAttribDlgFloat("LIFETIME", _Node);
140 _LifeDialog->enableMemoryScheme(false);
142 _LifeWrapper.Located = _Located;
143 _LifeWrapper.Node = _Node;
144 _LifeWrapper.SSPS = _ParticleDlg->StartStopDlg;
146 _LifeDialog->setWrapper(&_LifeWrapper);
148 _LifeDialog->setSchemeWrapper(&_LifeWrapper);
150 HBITMAP bmh = LoadBitmap(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_LIFE_TIME));
152 _LifeDialog->init(bmh, xPos, yPos, this);
155 _LifeDialog->GetClientRect(&r);
156 yPos += r.bottom + 3;
158 if (_Located->getLastForever())
160 _LifeDialog->EnableWindow(FALSE);
164 _MassDialog = new CAttribDlgFloat("PARTICLE_MASS", _Node, 0.001f, 10);
165 _MassDialog->enableLowerBound(0, true); // 0 is disallowed
166 _MassDialog->enableMemoryScheme(false);
167 _MassWrapper.Located = _Located;
168 _MassDialog->setWrapper(&_MassWrapper);
169 _MassDialog->setSchemeWrapper(&_MassWrapper);
170 bmh = LoadBitmap(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_WEIGHT));
171 _MassDialog->init(bmh, xPos, yPos, this);
172 _MassDialog->GetClientRect(&r);
173 yPos += r.bottom + 3;
177 m_MaxNbParticles.GetWindowRect(&r);
178 _MaxNbParticlesWrapper.TreeCtrl = _ParticleDlg->ParticleTreeCtrl;
179 _MaxNbParticlesWrapper.Located = _Located;
180 _MaxNbParticlesWrapper.Node = _Node;
181 _MaxNbParticles->setWrapper(&_MaxNbParticlesWrapper);
182 _MaxNbParticles->init(r.left - pr.left, r.top - pr.top, this);
184 if (_Located->getOwner())
186 _MaxNbParticles->EnableWindow(_Located->getOwner()->getAutoCountFlag() ? FALSE : TRUE);
190 m_MatrixMode = (int) _Located->getMatrixMode();
191 m_LimitedLifeTime = _Located->getLastForever() ? FALSE : TRUE;
192 m_TriggerOnDeath = _Located->isTriggerOnDeathEnabled();
193 updateTriggerOnDeath();
196 m_DisgradeWithLOD = _Located->hasLODDegradation();
197 updateIntegrable();
198 updateTriggerOnDeath();
199 UpdateData(FALSE);
200 ShowWindow(SW_SHOW);
203 //****************************************************************************************************************
204 void CLocatedProperties::updateTriggerOnDeath(void)
206 nlassert(_Located);
207 BOOL enable = !_Located->getLastForever();
208 m_TriggerOnDeathCtrl.EnableWindow(enable);
209 m_EditTriggerOnDeath.EnableWindow(( (enable ? true : false /* MSVC6 warning */ )
210 && _Located->isTriggerOnDeathEnabled())
214 //****************************************************************************************************************
215 void CLocatedProperties::updateIntegrable(void)
217 m_ParametricMotion = _Located->isParametricMotionEnabled();
218 m_ParametricMotionCtrl.EnableWindow(_Located->supportParametricMotion());
221 //****************************************************************************************************************
222 void CLocatedProperties::OnLimitedLifeTime()
224 UpdateData();
225 if (!m_LimitedLifeTime)
227 bool forceApplied = false;
228 // check that no force are applied on the located
229 std::vector<NL3D::CPSTargetLocatedBindable *> targeters;
230 _Located->getOwner()->getTargeters(_Located, targeters);
231 for(uint k = 0; k < targeters.size(); ++k)
233 if (targeters[k]->getType() == NL3D::PSForce)
235 forceApplied = true;
236 break;
239 if (forceApplied)
241 CString caption;
242 CString mess;
243 caption.LoadString(IDS_WARNING);
244 mess.LoadString(IDS_HAS_FORCE_APPLIED);
245 if (MessageBox((LPCTSTR) mess, (LPCTSTR) caption, MB_OKCANCEL) != IDOK)
247 m_LimitedLifeTime = true;
248 UpdateData(FALSE);
249 return;
252 if (_Located->setLastForever())
254 _LifeDialog->EnableWindow(FALSE);
256 else
258 CString mess;
259 mess.LoadString(IDS_PS_NO_FINITE_DURATION);
260 CString errorStr;
261 errorStr.LoadString(IDS_ERROR);
262 MessageBox((LPCTSTR) mess, (LPCTSTR) errorStr, MB_ICONEXCLAMATION);
263 m_LimitedLifeTime = TRUE;
264 UpdateData(FALSE);
267 else
269 _Located->setInitialLife(_Located->getInitialLife());
270 _LifeDialog->EnableWindow(TRUE);
272 updateTriggerOnDeath();
273 _ParticleDlg->StartStopDlg->resetAutoCount(_Node);
274 touchPSState();
277 //****************************************************************************************************************
278 void CLocatedProperties::OnDisgradeWithLod()
280 UpdateData();
281 _Located->forceLODDegradation(m_DisgradeWithLOD ? true : false /* to avoid warning from MSVC */);
282 touchPSState();
285 //****************************************************************************************************************
286 void CLocatedProperties::OnParametricMotion()
288 UpdateData();
289 _Located->enableParametricMotion(m_ParametricMotion ? true : false);
290 touchPSState();
293 //****************************************************************************************************************
294 void CLocatedProperties::OnEditTriggerOnDeath()
296 UpdateData();
297 CLBExternIDDlg dlg(_Located->getTriggerEmitterID());
298 INT_PTR res = dlg.DoModal();
299 if ( res == IDOK )
301 if (dlg.getNewID() != _Located->getTriggerEmitterID())
303 _Located->setTriggerEmitterID( dlg.getNewID() );
304 touchPSState();
309 //****************************************************************************************************************
310 void CLocatedProperties::OnTriggerOnDeath()
312 UpdateData();
313 _Located->enableTriggerOnDeath(m_TriggerOnDeath ? true : false /* MSVC6 wraning */);
314 updateTriggerOnDeath();
315 touchPSState();
318 //****************************************************************************************************************
319 void CLocatedProperties::goPostRender()
321 nlassert(_ParticleDlg);
322 if (_Located->getOwner()->getAutoCountFlag())
324 // update number of particle from ps
325 _MaxNbParticles->update();
327 // in all cases, show the current number of particles being used
328 GetDlgItem(IDC_CURR_NUM_PARTS)->SetWindowText(nlUtf8ToTStr(NLMISC::toString(_Located->getSize())));
331 //****************************************************************************************************************
332 void CLocatedProperties::OnAssignCount()
334 _Located->resize(_Located->getSize()); // set new max size
335 _MaxNbParticles->update();
336 touchPSState();
339 //****************************************************************************************************************
340 void CLocatedProperties::OnSelchangeMatrixMode()
342 UpdateData();
343 nlassert(_Located);
344 _Located->setMatrixMode((NL3D::TPSMatrixMode) m_MatrixMode);
345 updateIntegrable();
346 UpdateData(FALSE);
347 touchPSState();
350 //****************************************************************************************************************
351 void CLocatedProperties::touchPSState()
353 if (_Node) _Node->setModified(true);