Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / 3d / object_viewer / scheme_bank_dlg.cpp
blob2225d32bc10e9dbcf56dc6eff3eae8f438a837ee
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 #include "std_afx.h"
22 #include "object_viewer.h"
23 #include "scheme_bank_dlg.h"
24 #include "scheme_manager.h"
25 #include "choose_name.h"
26 #include <nel/misc/file.h>
29 /////////////////////////////////////////////////////////////////////////////
30 // CSchemeBankDlg dialog
33 CSchemeBankDlg::CSchemeBankDlg(const std::string &type, CWnd* pParent /*=NULL*/)
34 : CDialog(CSchemeBankDlg::IDD, pParent), _Type(type), _CurrScheme(NULL)
36 //{{AFX_DATA_INIT(CSchemeBankDlg)
37 //}}AFX_DATA_INIT
41 void CSchemeBankDlg::DoDataExchange(CDataExchange* pDX)
43 CDialog::DoDataExchange(pDX);
44 //{{AFX_DATA_MAP(CSchemeBankDlg)
45 DDX_Control(pDX, IDC_SCHEME_LIST, m_SchemeList);
46 //}}AFX_DATA_MAP
50 BEGIN_MESSAGE_MAP(CSchemeBankDlg, CDialog)
51 //{{AFX_MSG_MAP(CSchemeBankDlg)
52 ON_LBN_SELCHANGE(IDC_SCHEME_LIST, OnSelchangeSchemeList)
53 ON_BN_CLICKED(IDC_SAVE_BANK, OnSaveBank)
54 ON_BN_CLICKED(IDC_LOAD_BANK, OnLoadBank)
55 ON_BN_CLICKED(IDC_REMOVE, OnRemove)
56 ON_BN_CLICKED(IDC_RENAME, OnRename)
57 //}}AFX_MSG_MAP
58 END_MESSAGE_MAP()
60 /////////////////////////////////////////////////////////////////////////////
61 // CSchemeBankDlg message handlers
63 BOOL CSchemeBankDlg::OnInitDialog()
65 CDialog::OnInitDialog();
66 buildList();
67 return TRUE; // return TRUE unless you set the focus to a control
68 // EXCEPTION: OCX Property Pages should return FALSE
71 void CSchemeBankDlg::OnSelchangeSchemeList()
73 UpdateData();
74 if (m_SchemeList.GetCurSel() == LB_ERR)
76 _CurrScheme = NULL;
77 return;
79 _CurrScheme = (NL3D::CPSAttribMakerBase *) m_SchemeList.GetItemData(m_SchemeList.GetCurSel());
82 void CSchemeBankDlg::buildList()
84 m_SchemeList.ResetContent();
85 typedef std::vector<CSchemeManager::TSchemeInfo> TSchemeVect;
86 static TSchemeVect schemes;
87 SchemeManager.getSchemes(_Type, schemes);
88 for (TSchemeVect::const_iterator it = schemes.begin(); it != schemes.end(); ++it)
90 int index = m_SchemeList.AddString(nlUtf8ToTStr(it->first));
91 m_SchemeList.SetItemData(index, (DWORD_PTR) it->second);
94 UpdateData(FALSE);
97 void CSchemeBankDlg::OnSaveBank()
99 static TCHAR BASED_CODE szFilter[] = _T("scheme bank files(*.scb)|*.scb||");
100 CFileDialog fd( FALSE, NULL, _T("default.scb"), 0, szFilter);
102 if (fd.DoModal() == IDOK)
104 // Add search path for the texture
105 NLMISC::CPath::addSearchPath(NLMISC::CFile::getPath(NLMISC::tStrToUtf8(fd.GetPathName())));
109 NLMISC::COFile iF;
110 iF.open(NLMISC::tStrToUtf8(fd.GetFileName()));
111 iF.serial(SchemeManager);
113 catch (const std::exception &e)
115 std::string message = NLMISC::toString("Error saving scheme bank : %s", e.what());
116 MessageBox(nlUtf8ToTStr(message), _T("Object viewer"), MB_ICONEXCLAMATION | MB_OK);
117 return;
122 void CSchemeBankDlg::OnLoadBank()
124 static TCHAR BASED_CODE szFilter[] = _T("scheme bank files(*.scb)|*.scb||");
125 CFileDialog fd( TRUE, NULL, _T("*.scb"), 0, szFilter);
127 if (fd.DoModal() == IDOK)
129 // Add search path for the texture
130 NLMISC::CPath::addSearchPath(NLMISC::CFile::getPath(NLMISC::tStrToUtf8(fd.GetPathName())));
132 CSchemeManager sm;
135 NLMISC::CIFile iF;
136 iF.open(NLMISC::CPath::lookup(NLMISC::tStrToUtf8(fd.GetFileName())));
137 iF.serial(sm);
138 SchemeManager.swap(sm);
140 catch (const std::exception &e)
142 std::string message = NLMISC::toString("Error loading scheme bank : %s", e.what());
143 MessageBox(nlUtf8ToTStr(message), _T("Object viewer"), MB_ICONEXCLAMATION | MB_OK);
144 return;
146 buildList();
151 void CSchemeBankDlg::OnRemove()
153 UpdateData();
154 if (m_SchemeList.GetCurSel() == LB_ERR) return;
155 SchemeManager.remove((NL3D::CPSAttribMakerBase *) m_SchemeList.GetItemData(m_SchemeList.GetCurSel()));
156 m_SchemeList.DeleteString(m_SchemeList.GetCurSel());
157 _CurrScheme = NULL;
160 void CSchemeBankDlg::OnRename()
162 UpdateData();
163 if (m_SchemeList.GetCurSel() == LB_ERR) return;
164 CString name;
165 m_SchemeList.GetText(m_SchemeList.GetCurSel(), name);
166 CChooseName cn((LPCTSTR) name, this);
167 if (cn.DoModal() == IDOK)
169 NL3D::CPSAttribMakerBase *scheme = (NL3D::CPSAttribMakerBase *) m_SchemeList.GetItemData(m_SchemeList.GetCurSel());
170 SchemeManager.rename(scheme, cn.getName());
171 int curSel = m_SchemeList.GetCurSel();
172 m_SchemeList.DeleteString(curSel);
173 int insertedPos = m_SchemeList.InsertString(curSel, nlUtf8ToTStr(cn.getName()));
174 m_SchemeList.SetCurSel(insertedPos);
175 m_SchemeList.Invalidate();