1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of LEXIExporter |
---|
4 | |
---|
5 | Copyright 2006 NDS Limited |
---|
6 | |
---|
7 | Author(s): |
---|
8 | Mark Folkenberg, |
---|
9 | Bo Krohn |
---|
10 | |
---|
11 | This program is free software; you can redistribute it and/or modify it under |
---|
12 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
13 | Foundation; either version 2 of the License, or (at your option) any later |
---|
14 | version. |
---|
15 | |
---|
16 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
18 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU Lesser General Public License along with |
---|
21 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
22 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
23 | http://www.gnu.org/copyleft/lesser.txt. |
---|
24 | ----------------------------------------------------------------------------- |
---|
25 | */ |
---|
26 | |
---|
27 | #include "LexiStdAfx.h" |
---|
28 | #include "LexiMaxExport.h" |
---|
29 | #include "LexiDialogSelectNode.h" |
---|
30 | |
---|
31 | #include "..\Res\resource.h" |
---|
32 | |
---|
33 | // |
---|
34 | |
---|
35 | CSelectNodeDlg::CSelectNodeDlg(Window* pParent, CExportObject* pObj) : Dialog(IDD_DIALOG_SELECTMAXNODE, DlgProc, pParent) |
---|
36 | { |
---|
37 | m_pObj = pObj; |
---|
38 | |
---|
39 | char temp[256]; |
---|
40 | sprintf(temp, "Select %s Node", m_pObj->GetTypeName()); |
---|
41 | m_sTitle = temp; |
---|
42 | |
---|
43 | m_iNode = m_pObj->GetMAXNodeID(); |
---|
44 | |
---|
45 | m_hImageList = ImageList_Create(16, 16, ILC_COLOR16 | ILC_MASK, 0, 64); |
---|
46 | |
---|
47 | std::vector<CExportObject::Desc> objlist; |
---|
48 | CExportObject::EnumObjects(objlist); |
---|
49 | |
---|
50 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_SCENEROOT))); |
---|
51 | |
---|
52 | m_ImageListMap[NULL] = 1; |
---|
53 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_UNKNOWN))); |
---|
54 | |
---|
55 | m_ImageListMap[LIGHT_CLASS_ID] = 2; |
---|
56 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_LIGHT))); |
---|
57 | |
---|
58 | m_ImageListMap[GEOMOBJECT_CLASS_ID] = 3; |
---|
59 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_MODEL))); |
---|
60 | |
---|
61 | // m_ImageListMap[IGAME_SPLINE] = 4; |
---|
62 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_UNKNOWN))); |
---|
63 | |
---|
64 | m_ImageListMap[CAMERA_CLASS_ID] = 5; |
---|
65 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_CAMERA))); |
---|
66 | |
---|
67 | m_ImageListMap[HELPER_CLASS_ID] = 6; |
---|
68 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_MODEL))); |
---|
69 | |
---|
70 | // m_ImageListMap[IGAME_BONE] = 7; |
---|
71 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_UNKNOWN))); |
---|
72 | |
---|
73 | // m_ImageListMap[IGAME_IKCHAIN] = 8; |
---|
74 | ImageList_AddIcon(m_hImageList, ::LoadIcon(CExporter::m_hInstance, MAKEINTRESOURCE(IDI_ICON_UNKNOWN))); |
---|
75 | } |
---|
76 | |
---|
77 | CSelectNodeDlg::~CSelectNodeDlg() |
---|
78 | { |
---|
79 | ImageList_Destroy(m_hImageList); |
---|
80 | } |
---|
81 | |
---|
82 | // |
---|
83 | |
---|
84 | INT_PTR CALLBACK CSelectNodeDlg::DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
---|
85 | { |
---|
86 | CSelectNodeDlg* pThis = (CSelectNodeDlg*)Window::GetMapping(hWnd); |
---|
87 | |
---|
88 | switch(message) |
---|
89 | { |
---|
90 | case WM_INITDIALOG: |
---|
91 | { |
---|
92 | pThis = (CSelectNodeDlg*)lParam; |
---|
93 | Window::AddMapping(pThis, hWnd); |
---|
94 | |
---|
95 | pThis->OnInitDialog(); |
---|
96 | |
---|
97 | } return 1; |
---|
98 | |
---|
99 | case WM_COMMAND: |
---|
100 | { |
---|
101 | switch(LOWORD(wParam)) |
---|
102 | { |
---|
103 | case IDOK: |
---|
104 | pThis->m_pObj->SetMAXNodeID(pThis->m_iNode); |
---|
105 | pThis->EndDialog(IDOK); |
---|
106 | return 0; |
---|
107 | |
---|
108 | case IDCANCEL: |
---|
109 | pThis->EndDialog(IDCANCEL); |
---|
110 | return 0; |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | case WM_CLOSE: |
---|
115 | { |
---|
116 | pThis->EndDialog(IDCANCEL); |
---|
117 | } break; |
---|
118 | |
---|
119 | case WM_NOTIFY: |
---|
120 | { |
---|
121 | const NMHDR* pHdr = (const NMHDR*)lParam; |
---|
122 | switch(pHdr->idFrom) |
---|
123 | { |
---|
124 | case IDC_TREE: |
---|
125 | if(pHdr->code == TVN_SELCHANGED) |
---|
126 | { |
---|
127 | pThis->UpdateStuff(); |
---|
128 | } if(pHdr->code == NM_DBLCLK) |
---|
129 | { |
---|
130 | TVHITTESTINFO ht = {0}; |
---|
131 | |
---|
132 | GetCursorPos(&ht.pt); |
---|
133 | pThis->m_Tree.ScreenToClient(ht.pt); |
---|
134 | |
---|
135 | HTREEITEM hItem=pThis->m_Tree.HitTest(&ht); |
---|
136 | if(hItem!=NULL) |
---|
137 | { |
---|
138 | pThis->m_Tree.SelectItem(hItem); |
---|
139 | pThis->UpdateStuff(); |
---|
140 | pThis->m_pObj->SetMAXNodeID(pThis->m_iNode); |
---|
141 | pThis->EndDialog(IDOK); |
---|
142 | } |
---|
143 | } |
---|
144 | break; |
---|
145 | } |
---|
146 | } break; |
---|
147 | } |
---|
148 | |
---|
149 | return 0; |
---|
150 | } |
---|
151 | |
---|
152 | // |
---|
153 | |
---|
154 | void CSelectNodeDlg::OnInitDialog() |
---|
155 | { |
---|
156 | CenterWindow(); |
---|
157 | |
---|
158 | SetWindowText(m_sTitle.c_str()); |
---|
159 | |
---|
160 | // |
---|
161 | |
---|
162 | Bind(IDC_TREE, m_Tree); |
---|
163 | m_Tree.SetImageList(m_hImageList, TVSIL_NORMAL); |
---|
164 | m_Tree.SetBkColor(::GetSysColor(COLOR_WINDOW)); |
---|
165 | |
---|
166 | // |
---|
167 | |
---|
168 | m_hRoot = m_Tree.InsertItem("<SceneRoot>", 0, 0, TVI_ROOT, TVI_LAST); |
---|
169 | m_Tree.SetItemData(m_hRoot, NULL); |
---|
170 | |
---|
171 | m_Tree.SelectItem(NULL); |
---|
172 | |
---|
173 | for(unsigned int x = 0; x < CExporter::GetMax()->GetRootNode()->NumberOfChildren(); x++) |
---|
174 | { |
---|
175 | BuildTree(CExporter::GetMax()->GetRootNode()->GetChildNode(x), m_hRoot); |
---|
176 | } |
---|
177 | |
---|
178 | ShaveTree(); |
---|
179 | |
---|
180 | // Check if there is any supported nodes |
---|
181 | if(!m_Tree.ItemHasChildren(m_hRoot)) |
---|
182 | { |
---|
183 | MessageBox("Could not find any compatible objects in scene", NDS_EXPORTER_TITLE, MB_ICONERROR); |
---|
184 | this->EndDialog(IDCANCEL); |
---|
185 | return; |
---|
186 | } |
---|
187 | |
---|
188 | m_Tree.Expand(m_hRoot, TVE_EXPAND); |
---|
189 | |
---|
190 | UpdateStuff(); |
---|
191 | } |
---|
192 | |
---|
193 | // |
---|
194 | |
---|
195 | void CSelectNodeDlg::UpdateStuff() |
---|
196 | { |
---|
197 | bool bOK = false; |
---|
198 | |
---|
199 | HTREEITEM hItem = m_Tree.GetSelectedItem(); |
---|
200 | if(hItem) |
---|
201 | { |
---|
202 | INode* pNode = (INode*)m_Tree.GetItemData(hItem); |
---|
203 | if(pNode) |
---|
204 | { |
---|
205 | if(m_pObj->SupportsMAXNode(pNode)) |
---|
206 | { |
---|
207 | m_iNode = pNode->GetHandle(); |
---|
208 | bOK = true; |
---|
209 | } |
---|
210 | } |
---|
211 | else |
---|
212 | { |
---|
213 | m_iNode = 0; |
---|
214 | bOK = false; |
---|
215 | } |
---|
216 | } |
---|
217 | |
---|
218 | GetDlgItem(IDOK)->EnableWindow(bOK); |
---|
219 | } |
---|
220 | |
---|
221 | // |
---|
222 | |
---|
223 | void CSelectNodeDlg::BuildTree(INode* pNode, HTREEITEM hTreeItem) |
---|
224 | { |
---|
225 | if(pNode->IsNodeHidden()) return; |
---|
226 | |
---|
227 | unsigned int iID = pNode->GetHandle(); |
---|
228 | const char* pszName = pNode->GetName(); |
---|
229 | |
---|
230 | unsigned int iIconIndex = m_ImageListMap[GetClassIDFromNode(pNode)]; |
---|
231 | |
---|
232 | HTREEITEM hItem = m_Tree.InsertItem(pszName, iIconIndex, iIconIndex, hTreeItem, TVI_SORT); |
---|
233 | m_Tree.SetItemData(hItem, (unsigned int)pNode); |
---|
234 | |
---|
235 | int iNumChildren = pNode->NumberOfChildren(); |
---|
236 | for(int x = 0; x < iNumChildren; x++) |
---|
237 | { |
---|
238 | BuildTree(pNode->GetChildNode(x), hItem); |
---|
239 | } |
---|
240 | |
---|
241 | if(iID == m_iNode) |
---|
242 | { |
---|
243 | m_Tree.EnsureVisible(hItem); |
---|
244 | m_Tree.SelectItem(hItem); |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|
248 | void CSelectNodeDlg::ShaveTree() |
---|
249 | { |
---|
250 | while(ShaveTree(m_hRoot)); |
---|
251 | } |
---|
252 | |
---|
253 | bool CSelectNodeDlg::ShaveTree(HTREEITEM hItem) |
---|
254 | { |
---|
255 | if(m_Tree.ItemHasChildren(hItem)) |
---|
256 | { |
---|
257 | HTREEITEM hChild = m_Tree.GetNextItem(hItem, TVGN_CHILD); |
---|
258 | while(hChild) |
---|
259 | { |
---|
260 | if(ShaveTree(hChild)) return true; |
---|
261 | hChild = m_Tree.GetNextItem(hChild, TVGN_NEXT); |
---|
262 | } |
---|
263 | } |
---|
264 | else |
---|
265 | { |
---|
266 | INode* pNode = (INode*)m_Tree.GetItemData(hItem); |
---|
267 | if(pNode) |
---|
268 | { |
---|
269 | if(!m_pObj->SupportsMAXNode(pNode)) |
---|
270 | { |
---|
271 | m_Tree.DeleteItem(hItem); |
---|
272 | return true; |
---|
273 | } |
---|
274 | } |
---|
275 | } |
---|
276 | |
---|
277 | return false; |
---|
278 | } |
---|
279 | |
---|
280 | // |
---|
281 | |
---|