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) 2010-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/>.
25 #include "object_viewer.h"
26 #include "multi_tex_dlg.h"
27 #include "nel/3d/ps_particle_basic.h"
28 #include "nel/3d/texture_bump.h"
29 #include "popup_notify.h"
31 #include "texture_chooser.h"
34 /////////////////////////////////////////////////////////////////////////////
35 // CMultiTexDlg dialog
38 CMultiTexDlg::CMultiTexDlg(CParticleWorkspace::CNode
*ownerNode
, NL3D::CPSMultiTexturedParticle
*mtp
, IPopupNotify
* pn
, CWnd
*pParent
)
39 : CDialog(IDD_MULTITEX
, pParent
),
42 _MainTexDlg(NULL
), _AltTexDlg(NULL
),
46 //{{AFX_DATA_INIT(CMultiTexDlg)
47 m_ForceBasicCaps
= NL3D::CPSMultiTexturedParticle::areBasicCapsForced();
48 m_UseParticleDateAlt
= _MTP
->getUseLocalDateAlt();
49 m_UseParticleDate
= _MTP
->getUseLocalDate();
53 void CMultiTexDlg::init(CWnd
*pParent
)
55 Create(IDD_MULTITEX
, pParent
);
59 CMultiTexDlg::~CMultiTexDlg()
61 #define REMOVE_DLG(dlg) if (dlg) { (dlg)->DestroyWindow(); delete (dlg); }
62 REMOVE_DLG(_MainTexDlg
);
63 REMOVE_DLG(_AltTexDlg
);
67 void CMultiTexDlg::DoDataExchange(CDataExchange
* pDX
)
69 CDialog::DoDataExchange(pDX
);
70 //{{AFX_DATA_MAP(CMultiTexDlg)
71 DDX_Control(pDX
, IDC_USE_PARTICLE_DATE2
, m_UseParticleDateAltCtrl
);
72 DDX_Control(pDX
, IDC_USE_PARTICLE_DATE
, m_UseParticleDateCtrl
);
73 DDX_Control(pDX
, IDC_FORCE_BASIC_CAPS
, m_ForceBasicCapsCtrl
);
74 DDX_Control(pDX
, IDC_ENABLE_ALTERNATE_TEX
, m_AltTexCtrl
);
75 DDX_Control(pDX
, IDC_ALTERNATE_OP
, m_AlternateOpCtrl
);
76 DDX_Control(pDX
, IDC_MAIN_OP
, m_MainOpCtrl
);
77 DDX_Check(pDX
, IDC_FORCE_BASIC_CAPS
, m_ForceBasicCaps
);
78 DDX_Check(pDX
, IDC_USE_PARTICLE_DATE2
, m_UseParticleDateAlt
);
79 DDX_Check(pDX
, IDC_USE_PARTICLE_DATE
, m_UseParticleDate
);
84 BEGIN_MESSAGE_MAP(CMultiTexDlg
, CDialog
)
85 //{{AFX_MSG_MAP(CMultiTexDlg)
87 ON_BN_CLICKED(IDC_ENABLE_ALTERNATE_TEX
, OnEnableAlternate
)
88 ON_BN_CLICKED(IDC_UPDATE_SPEED
, OnUpdateSpeed
)
89 ON_BN_CLICKED(IDC_UPDATE_SPEED_ALTERNATE
, OnUpdateSpeedAlternate
)
90 ON_CBN_SELCHANGE(IDC_ALTERNATE_OP
, OnSelchangeAlternateOp
)
91 ON_CBN_SELCHANGE(IDC_MAIN_OP
, OnSelchangeMainOp
)
92 ON_BN_CLICKED(IDC_FORCE_BASIC_CAPS
, OnForceBasicCaps
)
93 ON_BN_CLICKED(IDC_USE_PARTICLE_DATE
, OnUseParticleDate
)
94 ON_BN_CLICKED(IDC_USE_PARTICLE_DATE2
, OnUseParticleDateAlt
)
98 /////////////////////////////////////////////////////////////////////////////
99 // CMultiTexDlg message handlers
101 BOOL
CMultiTexDlg::OnInitDialog()
103 CDialog::OnInitDialog();
105 _TexWrapper
.MTP
= _MTP
;
106 _AlternateTexWrapper
.MTP
= _MTP
;
110 _MainTexDlg
= new CTextureChooser(NULL
, _Node
);
111 _MainTexDlg
->setWrapper(&_TexWrapper
);
112 GetDlgItem(IDC_TEX_CHOOSER
)->GetWindowRect(&r
);
114 _MainTexDlg
->init(r
.left
, r
.top
, this);
116 _AltTexDlg
= new CTextureChooser(NULL
, _Node
);
117 _AltTexDlg
->setWrapper(&_AlternateTexWrapper
);
118 GetDlgItem(IDC_TEX_CHOOSER_ALTERNATE
)->GetWindowRect(&r
);
120 _AltTexDlg
->init(r
.left
, r
.top
, this);
126 if (_MTP
->isAlternateTexEnabled())
128 m_AltTexCtrl
.SetCheck(1);
134 return TRUE
; // return TRUE unless you set the focus to a control
135 // EXCEPTION: OCX Property Pages should return FALSE
138 //======================================================
142 NL3D::ITexture
*CMultiTexDlg::CMainTexWrapper::get(void)
144 return MTP
->getTexture2();
147 void CMultiTexDlg::CMainTexWrapper::set(NL3D::ITexture
*tex
)
149 MTP
->setTexture2(tex
);
152 NL3D::ITexture
*CMultiTexDlg::CAlternateTexWrapper::get(void)
154 return MTP
->getTexture2Alternate();
157 void CMultiTexDlg::CAlternateTexWrapper::set(NL3D::ITexture
*tex
)
159 MTP
->setTexture2Alternate(tex
);
163 //======================================================
165 void CMultiTexDlg::readValues(bool alternate
)
167 /// get the values, and put them in the dialog
171 GetDlgItem(IDC_U_SPEED_1
)->SetWindowText(nlUtf8ToTStr(NLMISC::toString("%.3f", _MTP
->getScrollSpeed(0).x
)));
172 GetDlgItem(IDC_V_SPEED_1
)->SetWindowText(nlUtf8ToTStr(NLMISC::toString("%.3f", _MTP
->getScrollSpeed(0).y
)));
173 GetDlgItem(IDC_U_SPEED_2
)->SetWindowText(nlUtf8ToTStr(NLMISC::toString("%.3f", _MTP
->getScrollSpeed(1).x
)));
174 GetDlgItem(IDC_V_SPEED_2
)->SetWindowText(nlUtf8ToTStr(NLMISC::toString("%.3f", _MTP
->getScrollSpeed(1).y
)));
178 if (_MTP
->isAlternateTexEnabled())
180 GetDlgItem(IDC_U_SPEED_1_ALTERNATE
)->SetWindowText(nlUtf8ToTStr(NLMISC::toString("%.3f", _MTP
->getAlternateScrollSpeed(0).x
)));
181 GetDlgItem(IDC_V_SPEED_1_ALTERNATE
)->SetWindowText(nlUtf8ToTStr(NLMISC::toString("%.3f", _MTP
->getAlternateScrollSpeed(0).y
)));
182 GetDlgItem(IDC_U_SPEED_2_ALTERNATE
)->SetWindowText(nlUtf8ToTStr(NLMISC::toString("%.3f", _MTP
->getAlternateScrollSpeed(1).x
)));
183 GetDlgItem(IDC_V_SPEED_2_ALTERNATE
)->SetWindowText(nlUtf8ToTStr(NLMISC::toString("%.3f", _MTP
->getAlternateScrollSpeed(1).y
)));
187 GetDlgItem(IDC_U_SPEED_1_ALTERNATE
)->SetWindowText(_T(""));
188 GetDlgItem(IDC_V_SPEED_1_ALTERNATE
)->SetWindowText(_T(""));
189 GetDlgItem(IDC_U_SPEED_2_ALTERNATE
)->SetWindowText(_T(""));
190 GetDlgItem(IDC_V_SPEED_2_ALTERNATE
)->SetWindowText(_T(""));
194 GetDlgItem(IDC_BUMP_FACTOR
)->SetWindowText(nlUtf8ToTStr(NLMISC::toString("%.3f", _MTP
->getBumpFactor())));
198 //======================================================
199 void CMultiTexDlg::updateBumpFactorEnabled()
201 BOOL bEnvBumpMapUsed
= _MTP
->getMainTexOp() == NL3D::CPSMultiTexturedParticle::EnvBumpMap
? TRUE
: FALSE
;
202 GetDlgItem(IDC_BUMP_FACTOR_TXT
)->EnableWindow(bEnvBumpMapUsed
);
203 GetDlgItem(IDC_BUMP_FACTOR
)->EnableWindow(bEnvBumpMapUsed
);
207 //======================================================
208 void CMultiTexDlg::writeValues(bool alternate
)
210 TCHAR u1
[10], u2
[10], v1
[10], v2
[10];
211 NLMISC::CVector2f vs1
, vs2
;
215 GetDlgItem(IDC_U_SPEED_1
)->GetWindowText(u1
, 10);
216 GetDlgItem(IDC_V_SPEED_1
)->GetWindowText(v1
, 10);
217 GetDlgItem(IDC_U_SPEED_2
)->GetWindowText(u2
, 10);
218 GetDlgItem(IDC_V_SPEED_2
)->GetWindowText(v2
, 10);
220 if (_stscanf(u1
, _T("%f"), &vs1
.x
) == 1 &&
221 _stscanf(v1
, _T("%f"), &vs1
.y
) == 1 &&
222 _stscanf(u2
, _T("%f"), &vs2
.x
) == 1 &&
223 _stscanf(v2
, _T("%f"), &vs2
.y
) == 1)
225 _MTP
->setScrollSpeed(0, vs1
);
226 _MTP
->setScrollSpeed(1, vs2
);
227 updateModifiedFlag();
231 MessageBox(_T("Invalid value(s)"), _T("Error"), MB_OK
| MB_ICONEXCLAMATION
);
236 if (_MTP
->isAlternateTexEnabled())
238 GetDlgItem(IDC_U_SPEED_1_ALTERNATE
)->GetWindowText(u1
, 10);
239 GetDlgItem(IDC_V_SPEED_1_ALTERNATE
)->GetWindowText(v1
, 10);
240 GetDlgItem(IDC_U_SPEED_2_ALTERNATE
)->GetWindowText(u2
, 10);
241 GetDlgItem(IDC_V_SPEED_2_ALTERNATE
)->GetWindowText(v2
, 10);
242 if (_stscanf(u1
, _T("%f"), &vs1
.x
) == 1 &&
243 _stscanf(v1
, _T("%f"), &vs1
.y
) == 1 &&
244 _stscanf(u2
, _T("%f"), &vs2
.x
) == 1 &&
245 _stscanf(v2
, _T("%f"), &vs2
.y
) == 1)
247 _MTP
->setAlternateScrollSpeed(0, vs1
);
248 _MTP
->setAlternateScrollSpeed(1, vs2
);
249 updateModifiedFlag();
254 TCHAR bumpFactorTxt
[10];
256 GetDlgItem(IDC_BUMP_FACTOR
)->GetWindowText(bumpFactorTxt
, 10);
257 if (_stscanf(bumpFactorTxt
, _T("%f"), &bumpFactor
) == 1)
259 _MTP
->setBumpFactor(bumpFactor
);
260 updateModifiedFlag();
264 //======================================================
265 void CMultiTexDlg::OnClose()
269 _PN
->childPopupClosed(this);
272 void CMultiTexDlg::OnEnableAlternate()
274 _MTP
->enableAlternateTex(!_MTP
->isAlternateTexEnabled());
276 updateModifiedFlag();
279 //======================================================
280 void CMultiTexDlg::updateAlternate()
282 BOOL bEnable
= _MTP
->isAlternateTexEnabled();
284 GetDlgItem(IDC_U_SPEED_1_ALTERNATE
)->EnableWindow(bEnable
);
285 GetDlgItem(IDC_V_SPEED_1_ALTERNATE
)->EnableWindow(bEnable
);
286 GetDlgItem(IDC_U_SPEED_2_ALTERNATE
)->EnableWindow(bEnable
);
287 GetDlgItem(IDC_V_SPEED_2_ALTERNATE
)->EnableWindow(bEnable
);
288 GetDlgItem(IDC_UPDATE_SPEED_ALTERNATE
)->EnableWindow(bEnable
);
289 GetDlgItem(IDC_ALTERNATE_OP
)->EnableWindow(bEnable
);
290 _AltTexDlg
->EnableWindow(bEnable
);
294 //======================================================
295 void CMultiTexDlg::OnUpdateSpeed()
300 //======================================================
301 void CMultiTexDlg::OnUpdateSpeedAlternate()
306 //======================================================
307 void CMultiTexDlg::updateTexOp()
309 m_MainOpCtrl
.SetCurSel((int) _MTP
->getMainTexOp());
310 m_AlternateOpCtrl
.SetCurSel((int) _MTP
->getAlternateTexOp());
312 updateBumpFactorEnabled();
315 //======================================================
316 void CMultiTexDlg::OnSelchangeAlternateOp()
319 _MTP
->setAlternateTexOp((NL3D::CPSMultiTexturedParticle::TOperator
) m_AlternateOpCtrl
.GetCurSel());
320 updateModifiedFlag();
323 //======================================================
324 void CMultiTexDlg::OnSelchangeMainOp()
327 _MTP
->setMainTexOp((NL3D::CPSMultiTexturedParticle::TOperator
) m_MainOpCtrl
.GetCurSel());
328 updateModifiedFlag();
329 updateBumpFactorEnabled();
332 //======================================================
333 void CMultiTexDlg::OnForceBasicCaps()
336 NL3D::CPSMultiTexturedParticle::forceBasicCaps(m_ForceBasicCaps
? true : false /* VC WARNING */);
340 //======================================================
341 void CMultiTexDlg::OnUseParticleDate()
344 _MTP
->setUseLocalDate(m_UseParticleDate
? true : false /* VC WARNING */);
345 updateModifiedFlag();
348 //======================================================
349 void CMultiTexDlg::OnUseParticleDateAlt()
352 _MTP
->setUseLocalDateAlt(m_UseParticleDateAlt
? true : false /* VC WARNING */);
353 updateModifiedFlag();