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/>.
21 // located_properties.cpp : implementation file
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
;
47 m_DisgradeWithLOD
= FALSE
;
48 m_ParametricIntegration
= FALSE
;
49 m_ParametricMotion
= FALSE
;
50 m_TriggerOnDeath
= FALSE
;
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();
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
);
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
)
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
);
131 MoveWindow(x
, y
, r
.right
, r
.bottom
);
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();
198 updateTriggerOnDeath();
203 //****************************************************************************************************************
204 void CLocatedProperties::updateTriggerOnDeath(void)
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()
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
)
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;
252 if (_Located
->setLastForever())
254 _LifeDialog
->EnableWindow(FALSE
);
259 mess
.LoadString(IDS_PS_NO_FINITE_DURATION
);
261 errorStr
.LoadString(IDS_ERROR
);
262 MessageBox((LPCTSTR
) mess
, (LPCTSTR
) errorStr
, MB_ICONEXCLAMATION
);
263 m_LimitedLifeTime
= TRUE
;
269 _Located
->setInitialLife(_Located
->getInitialLife());
270 _LifeDialog
->EnableWindow(TRUE
);
272 updateTriggerOnDeath();
273 _ParticleDlg
->StartStopDlg
->resetAutoCount(_Node
);
277 //****************************************************************************************************************
278 void CLocatedProperties::OnDisgradeWithLod()
281 _Located
->forceLODDegradation(m_DisgradeWithLOD
? true : false /* to avoid warning from MSVC */);
285 //****************************************************************************************************************
286 void CLocatedProperties::OnParametricMotion()
289 _Located
->enableParametricMotion(m_ParametricMotion
? true : false);
293 //****************************************************************************************************************
294 void CLocatedProperties::OnEditTriggerOnDeath()
297 CLBExternIDDlg
dlg(_Located
->getTriggerEmitterID());
298 INT_PTR res
= dlg
.DoModal();
301 if (dlg
.getNewID() != _Located
->getTriggerEmitterID())
303 _Located
->setTriggerEmitterID( dlg
.getNewID() );
309 //****************************************************************************************************************
310 void CLocatedProperties::OnTriggerOnDeath()
313 _Located
->enableTriggerOnDeath(m_TriggerOnDeath
? true : false /* MSVC6 wraning */);
314 updateTriggerOnDeath();
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();
339 //****************************************************************************************************************
340 void CLocatedProperties::OnSelchangeMatrixMode()
344 _Located
->setMatrixMode((NL3D::TPSMatrixMode
) m_MatrixMode
);
350 //****************************************************************************************************************
351 void CLocatedProperties::touchPSState()
353 if (_Node
) _Node
->setModified(true);