1-- NW4C Node Tool (2011/02/15)
2-- Version 1.0.0
3-- (c)2010-2011 Nintendo
4
5rollout nw4cNodeRollout "NW4C Set No Compress Node" width:320 height:348
6(
7	groupBox grp1 "Selected Nodes" pos:[8,8] width:304 height:188
8	--label lblSelectedNode "" pos:[16,24] width:288 height:64
9	dotNetControl lv_mtl "System.Windows.Forms.ListView" pos:[16,24] width:288 height:164
10	groupBox grp2 "Set" pos:[8,204] width:304 height:48
11	dropDownList ddlSetCompress "" pos:[16,220] width:200 height:22 items:#("Compress this node if possible","Don't compress this node")
12	groupBox grp3 "Search" pos:[8,260] width:304 height:52
13	radioButtons rdoSearch "" pos:[16,276] width:208 height:16 labels:#("Compress If Possible", "Don't Compress") columns:1
14	button btnSearch "Search" pos:[226,284] width:80 height:24
15	button btnClose "Close" pos:[8,320] width:304 height:24
16
17	local donotRedraw
18	local nodes = #()
19
20	fn initListView =
21	(
22		lv_mtl.gridLines = true
23		lv_mtl.View = (dotNetClass "System.Windows.Forms.View").Details
24		lv_mtl.fullRowSelect = true
25		lv_mtl.AutoSize = true
26		lv_mtl.MultiSelect = false
27		lv_mtl.Columns.add "Node Name        "
28		lv_mtl.Columns.add "Compress"
29		lv_mtl.sorting = (dotNetClass "System.Windows.Forms.SortOrder").Ascending
30		lv_mtl.AutoResizeColumns ((dotNetClass "System.Windows.Forms.ColumnHeaderAutoResizeStyle").HeaderSize)
31	)
32
33	fn getNodeAttribute n create =
34	(
35		local attrib = n.custAttributes["NW4C Node Custom Attribute"]
36		if attrib == undefined then
37		(
38			if not create do return undefined
39			attrib = nw4c_node_custom_attribute()
40			append n.custAttributes attrib
41		)
42		return attrib
43	)
44
45	fn setNodeNoCompress n flag =
46	(
47		local attrib = getNodeAttribute n true
48		if attrib == undefined do return undefined
49		attrib.noCompress = flag
50	)
51
52	fn getNodeNoCompress n =
53	(
54		local attrib = getNodeAttribute n false
55		if attrib == undefined do return false
56		return attrib.noCompress
57	)
58
59	fn updateSelection =
60	(
61		if donotRedraw do return()
62		lv_mtl.Items.Clear()
63		local lvItems =#()
64
65		local str = ""
66		for n in nodes do
67		(
68			local flag = getNodeNoCompress n
69
70			local li = dotNetObject "System.Windows.Forms.ListViewItem" n.name
71			local sub_li
72
73			str = case flag of
74				(
75					true: "Don't compress"
76					default: "If possible"
77				)
78			sub_li = li.SubItems.add str
79			append lvItems li
80		)
81		lv_mtl.Items.AddRange lvItems
82
83		if nodes.count > 0 then
84		(
85			ddlSetCompress.enabled = true
86			ddlSetCompress.selection =  case getNodeNoCompress nodes[1] of
87			(
88				true: 2
89				false: 1
90			)
91		)
92		else
93		(
94			ddlSetCompress.enabled = false
95		)
96	)
97
98
99	on ddlSetCompress selected i do
100	(
101		local v = case i of
102		(
103			1: false
104			2: true
105		)
106		for n in nodes do
107		(
108			setNodeNoCompress n v
109		)
110		updateSelection()
111	)
112
113	fn selectionCallback =
114	(
115		nodes = #()
116		for n in selection do appendIfUnique nodes n
117		updateSelection()
118	)
119
120	on nw4cNodeRollout open  do
121	(
122		donotRedraw = false
123		initListView()
124		nodes = #()
125		callbacks.addScript #selectionSetChanged "nw4cNodeRollout.selectionCallback()" id:#nw4cNodeSelectionChange
126		selectionCallback()
127	)
128	on nw4cNodeRollout close  do
129	(
130		callbacks.removeScripts id:#nw4cNodeSelectionChange
131	)
132	on btnSearch pressed  do
133	(
134		donotRedraw = true
135		clearSelection()
136		nodes = #()
137		local flag = (rdoSearch.state == 2)
138		for n in objects do
139		(
140			if (getNodeNoCompress n) == flag do
141			(
142				selectMore n
143				appendIfUnique nodes n
144			)
145		)
146		donotRedraw = false
147		updateSelection()
148	)
149	on btnClose pressed  do DestroyDialog nw4cNodeRollout
150)-- node rollout
151
152rollout nw4cBillboardRollout "NW4C Set Billboard" width:320 height:400
153(
154	groupBox grp1 "Selected Nodes" pos:[8,8] width:304 height:188
155	--label lblSelectedNode "" pos:[16,24] width:288 height:64
156	dotNetControl lv_mtl "System.Windows.Forms.ListView" pos:[16,24] width:288 height:164
157	groupBox grp2 "Set" pos:[8,204] width:304 height:48
158	dropDownList ddlSetBillboard "" pos:[16,220] width:200 height:22 \
159		items:#("Off","World","World Viewpoint","Screen","Screen Viewpoint","Y Axial","Y Axial Viewpoint")
160	groupBox grp3 "Search" pos:[8,260] width:304 height:100
161	--radioButtons rdoSearch "" pos:[16,276] width:208 height:16 labels:#("Compress If Possible", "Don't Compress") columns:1
162	checkbox chkWorld "World" pos:[16,276] width:80 height:16
163	checkbox chkWorldView "World Viewpoint" pos:[100,276] width:120 height:16
164	checkbox chkScreen "Screen" pos:[16,294] width:80 height:16
165	checkbox chkScreenView "Screen Viewpoint" pos:[100,294] width:120 height:16
166	checkbox chkYAxial "Y Axial" pos:[16,312] width:80 height:16
167	checkbox chkYAxialView "Y Axial Viewpoint" pos:[100,312] width:120 height:16
168
169	button btnSearch "Search" pos:[226,284] width:80 height:24
170	button btnClose "Close" pos:[8,370] width:304 height:24
171
172	local donotRedraw
173	local nodes = #()
174
175	fn initListView =
176	(
177		lv_mtl.gridLines = true
178		lv_mtl.View = (dotNetClass "System.Windows.Forms.View").Details
179		lv_mtl.fullRowSelect = true
180		lv_mtl.AutoSize = true
181		lv_mtl.MultiSelect = false
182		lv_mtl.Columns.add "Node Name        "
183		lv_mtl.Columns.add "Billboard Type"
184		lv_mtl.sorting = (dotNetClass "System.Windows.Forms.SortOrder").Ascending
185		lv_mtl.AutoResizeColumns ((dotNetClass "System.Windows.Forms.ColumnHeaderAutoResizeStyle").HeaderSize)
186	)
187
188	fn getNodeAttribute n create =
189	(
190		local attrib = n.custAttributes["NW4C Node Custom Attribute"]
191		if attrib == undefined then
192		(
193			if not create do return undefined
194			attrib = nw4c_node_custom_attribute()
195			append n.custAttributes attrib
196		)
197		return attrib
198	)
199
200	fn setNodeBillboardType n flag =
201	(
202		local attrib = getNodeAttribute n true
203		if attrib == undefined do return undefined
204		attrib.billboardType = flag
205	)
206
207	fn getNodeBillboardType n =
208	(
209		local attrib = getNodeAttribute n false
210		if attrib == undefined do return 0
211		return attrib.billboardType
212	)
213
214	fn updateSelection =
215	(
216		if donotRedraw do return()
217		lv_mtl.Items.Clear()
218		local lvItems =#()
219
220		local str = ""
221		for n in nodes do
222		(
223			local type = getNodeBillboardType n
224
225			local li = dotNetObject "System.Windows.Forms.ListViewItem" n.name
226			local sub_li
227
228			str = case type of
229				(
230					1: "World"
231					2: "World Viewpoint"
232					3: "Screen"
233					4: "Screen Viewpoint"
234					5: "Y Axial"
235					6: "Y Axial Viewpoint"
236					default: "Off"
237				)
238			sub_li = li.SubItems.add str
239			append lvItems li
240		)
241		lv_mtl.Items.AddRange lvItems
242
243		if nodes.count > 0 then
244		(
245			ddlSetBillboard.enabled = true
246			ddlSetBillboard.selection =  getNodeBillboardType nodes[1]  + 1
247		)
248		else
249		(
250			ddlSetBillboard.enabled = false
251		)
252	)
253
254	on ddlSetBillboard selected i do
255	(
256		local v = i - 1
257		for n in nodes do
258		(
259			setNodeBillboardType n v
260		)
261		updateSelection()
262	)
263
264	fn selectionCallback =
265	(
266		nodes = #()
267		for n in selection do appendIfUnique nodes n
268		updateSelection()
269	)
270
271	on nw4cBillboardRollout open  do
272	(
273		donotRedraw = false
274		initListView()
275		nodes = #()
276		for n in selection do appendIfUnique nodes n
277		callbacks.addScript #selectionSetChanged "nw4cBillboardRollout.selectionCallback()" id:#nw4cBillboardSelectionChange
278		updateSelection()
279	)
280	on nw4cBillboardRollout close  do
281	(
282		callbacks.removeScripts id:#nw4cBillboardSelectionChange
283	)
284	on btnSearch pressed  do
285	(
286		donotRedraw = true
287		clearSelection()
288		nodes = #()
289		for n in objects do
290		(
291			local flag = case (getNodeBillboardType n) of
292			(
293				1: chkWorld.checked--"World"
294				2: chkWorldView.checked --"World Viewpoint"
295				3: chkScreen.checked --"Screen"
296				4: chkScreenView.checked --"Screen Viewpoint"
297				5: chkYAxial.checked --"Y Axial"
298				6: chkYAxialView.checked --"Y Axial Viewpoint"
299				default: false --"Off"
300			)
301			if flag do
302			(
303				selectMore n
304				appendIfUnique nodes n
305			)
306		)
307		donotRedraw = false
308		updateSelection()
309	)
310	on btnClose pressed  do DestroyDialog nw4cBillboardRollout
311	on lv_mtl SelectedIndexChanged e do
312	(
313		local numItems = lv_mtl.Items.Count
314		for i = 0 to (numItems - 1) do
315		(
316			lv_mtl.Items.Item[i].Selected = false
317		)
318	)
319)-- billboard rollout
320
321rollout nw4cCombineRollout "NW4C Set Combine Group" width:320 height:386
322(
323
324	groupBox grp1 "Selected Node" pos:[8,8] width:304 height:188
325	dotNetControl lv_mtl "System.Windows.Forms.ListView" pos:[16,24] width:288 height:164
326	groupBox grp2 "Set" pos:[8,204] width:304 height:64
327	label lbl6 "Combine Group:" pos:[16,220] width:104 height:16
328	radioButtons rdoSetCombineType "" pos:[100,220] width:87 height:32 labels:#("Don't care", "") columns:1 default:1
329	spinner spnSetCombine "" pos:[124,236] width:56 height:16 range:[0,255,0] type:#integer scale:1 enabled:false
330	button btnSequential "Set Sequential" pos:[188,236] width:112 height:24
331
332	groupBox grp3 "Search" pos:[8,276] width:304 height:80
333	label lbl8 "Combine Group:" pos:[16,292] width:104 height:16
334	radioButtons rdoSearchCombineType "" pos:[100,292] width:89 height:48
335			labels:#("Don't care", "Condition") columns:1 default:1 \
336	dropDownList ddlSearchConditionType "" pos:[180,304] width:80 height:22 default:1 \ --enabled:false \
337			items:#("< : under", "<= : below", "= : exactly", ">= : above", "> : over")
338	spinner spnSearchCombine "" pos:[260,306] width:48 height:16 range:[0,255,0] type:#integer scale:1 --enabled:false
339	button btnSearch "Search" pos:[180,328] width:112 height:24
340
341	button btnClose "Close" pos:[8,360] width:304 height:24
342
343	local donotRedraw
344	local nodes = #()
345	fn initListView =
346	(
347		lv_mtl.gridLines = true
348		lv_mtl.View = (dotNetClass "System.Windows.Forms.View").Details
349		lv_mtl.fullRowSelect = true
350		lv_mtl.AutoSize = true
351		lv_mtl.MultiSelect = false
352		lv_mtl.Columns.add "Node Name        "
353		lv_mtl.Columns.add "Combine Group"
354		lv_mtl.sorting = (dotNetClass "System.Windows.Forms.SortOrder").Ascending
355		lv_mtl.AutoResizeColumns ((dotNetClass "System.Windows.Forms.ColumnHeaderAutoResizeStyle").HeaderSize)
356	)
357
358	fn getNodeAttribute n create =
359	(
360		local attrib = n.custAttributes["NW4C Node Custom Attribute"]
361		if attrib == undefined then
362		(
363			if not create do return undefined
364			attrib = nw4c_node_custom_attribute()
365			append n.custAttributes attrib
366		)
367		return attrib
368	)
369
370	fn setNodeCombineGroup n id =
371	(
372		local attrib = getNodeAttribute n true
373		if attrib == undefined do return undefined
374		attrib.combineGroup = id
375	)
376
377	fn getNodeCombineGroup n =
378	(
379		local attrib = getNodeAttribute n false
380		if attrib == undefined do return -1
381		return attrib.combineGroup
382	)
383
384	fn updateSelection =
385	(
386		if donotRedraw do return()
387		lv_mtl.Items.Clear()
388		local lvItems =#()
389
390		local str = ""
391		for n in nodes do
392		(
393			local id = getNodeCombineGroup n
394
395			local li = dotNetObject "System.Windows.Forms.ListViewItem" n.name
396			local sub_li
397
398			str = if (id < 0) then "Don't care"
399					else str = (id as string)
400			sub_li = li.SubItems.add str
401			append lvItems li
402		)
403		lv_mtl.Items.AddRange lvItems
404
405		if nodes.count > 0 then
406		(
407			id = getNodeCombineGroup nodes[1]
408			--print nodes
409			if (id < 0) then
410			(
411				rdoSetCombineType.state =  1
412				spnSetCombine.enabled = false
413			)
414			else
415			(
416				rdoSetCombineType.state =  2
417				spnSetCombine.enabled = true
418				spnSetCombine.value = id
419			)
420		)
421	)
422
423	fn setNodesAttribute =
424	(
425		--local mtls = getSelMtls selection
426		local attr
427		undo "Edit Combine Group" on
428		(
429			spnSetCombine.enabled = (rdoSetCombineType.state == 2)
430			for n in nodes do
431			(
432				attr = getNodeAttribute n true
433				local val = 0
434				if rdoSetCombineType.state == 1 then
435				(
436					attr.combineGroup = -1
437				)
438				else
439				(
440					attr.combineGroup = spnSetCombine.value
441				)
442			)
443		)
444		updateSelection()
445	)
446
447	fn nodeNameCompare v1 v2 =
448	(
449		if (v1.name > v2.name) then 1 else -1
450	)
451
452	fn addCallback =
453	(
454		callbacks.addScript #selectionSetChanged "nw4cCombineRollout.selectionCallback()" \
455			id:#nw4cCombineSelectionChange
456	)
457	fn removeCallback =
458	(
459		callbacks.removeScripts id:#nw4cCombineSelectionChange
460	)
461
462	fn selectionCallback =
463	(
464		--print "selectionCallback"
465		nodes = #()
466		for n in selection do appendIfUnique nodes n
467		qsort nodes nodeNameCompare
468		updateSelection()
469	)
470
471	fn sequenceCompare v1 v2 =
472	(
473		local ret = 0
474		if(v1[1] > v2[1]) then
475		(
476			ret = 1
477		)
478		else if (v1[1] < v2[1]) then
479		(
480			ret = -1
481		)
482		else
483		(
484			ret = if (v1[2].name > v2[2].name) then 1 else -1
485		)
486		ret
487	)
488
489	on btnSequential pressed do
490	(
491		local seqnodes = #()
492		local id = spnSetCombine.value
493		-- �O���[�vID��255������ꍇ�̓G���[
494		if (id + nodes.count - 1) > 255 then
495		(
496			messageBox "Combine Group will be greater than 255"
497			return()
498		)
499
500		for n in nodes do
501		(
502			local depth = 0
503			local p = n
504			do
505			(
506				depth += 1
507				p = p.parent
508			)
509			while (p != undefined)
510			append seqnodes #(depth, n)
511		)
512		qsort seqnodes sequenceCompare
513		--print seqnodes
514		for a in seqnodes do
515		(
516			setNodeCombineGroup a[2] id
517			id += 1
518		)
519		updateSelection()
520	)
521
522	on btnSearch pressed  do
523	(
524		removeCallback()
525		clearSelection()
526		nodes = #()
527		for n in objects do
528		(
529			--local attr = getNodeAttribute n false
530			local id = getNodeCombineGroup n
531			local ret= false
532
533			case rdoSearchCombineType.state of
534			(
535				1: ( -- Don't care
536					if id < 0 do
537					(
538						ret = true
539					)
540				)
541				2: ( -- condition
542					if id >=0 do
543					(
544						local v = spnSearchCombine.value
545						case ddlSearchConditionType.selection of
546						(
547							1: ( -- under
548								ret = (id < v)
549							)
550							2: ( -- below
551								ret = (id <= v)
552							)
553							3: ( -- exactly
554								ret = (id == v)
555							)
556							4: ( -- above
557								ret = (id >= v)
558							)
559							5: ( -- over
560								ret = (id > v)
561							)
562						)
563					)
564				)
565				default: ret = false
566			)
567
568			-- �����������΃}�e���A����z��ɒlj�
569			if ret do
570			(
571				appendIfUnique nodes n
572			)
573		)
574
575		for n in nodes do
576		(
577			selectMore n
578		)
579
580		updateSelection()
581		addCallback()
582	)
583
584	on rdoSetCombineType changed i do setNodesAttribute()
585	on spnSetCombine changed i do setNodesAttribute()
586
587	on nw4cCombineRollout open  do
588	(
589		donotRedraw = false
590		initListView()
591		nodes = #()
592		addCallback()
593		selectionCallback()
594	)
595	on nw4cCombineRollout close  do
596	(
597		removeCallback()
598	)
599
600	on btnClose pressed  do DestroyDialog nw4cCombineRollout
601)-- combine rollout
602
603rollout nw4cForceKeyRollout "NW4C Set Force Export Key" width:320 height:450
604(
605	group "Selected Nodes"
606	(
607		dotNetControl lv_nodes "System.Windows.Forms.ListView" width:288 height:164
608	)
609	group "Set"
610	(
611		checkbox chkExportTrans "Force Export Translate Key" width:280 height:16 offset:[0,-4]
612		checkbox chkExportRotate "Force Export Rotate Key" width:280 height:16 offset:[0,-4]
613		checkbox chkExportScale "Force Export Scale Key" width:280 height:16 offset:[0,-4]
614		checkbox chkExportVisibility "Force Export Visibility Key" width:280 height:16 offset:[0,-4]
615	)
616	group "Search"
617	(
618		label lblExportTrans "Force Export Translate Key" align:#left  across:4
619		label lblDummy3 ""
620		checkbox chkS_ExportTransOFF "Off"
621		checkbox chkS_ExportTransON "On"
622		label lblExportRotate "Force Export Rotate Key"  align:#left  across:4
623		label lblDummy2 ""
624		checkbox chkS_ExportRotateOFF "Off"
625		checkbox chkS_ExportRotateON "On"
626		label lblExportScale "Force Export Scale Key" align:#left across:4
627		label lblDummy1 ""
628		checkbox chkS_ExportScaleOFF "Off"
629		checkbox chkS_ExportScaleON "On"
630		label lblExportVis "Force Export Visibility Key" align:#left across:4
631		label lblDummy4 ""
632		checkbox chkS_ExportVisOFF "Off"
633		checkbox chkS_ExportVisON "On"
634
635		radioButtons rdoSearchType "" width:98 height:16 labels:#("AND", "OR") columns:2 offset:[0,4] across:2
636		button btnSearch "Search" width:112 height:24
637	)
638
639	button btnClose "Close" width:304 height:24
640
641	local donotRedraw
642	local nodes = #()
643	fn initListView =
644	(
645		lv_nodes.gridLines = true
646		lv_nodes.View = (dotNetClass "System.Windows.Forms.View").Details
647		lv_nodes.fullRowSelect = true
648		lv_nodes.AutoSize = true
649		lv_nodes.MultiSelect = false
650		lv_nodes.Columns.add "Node Name  "
651		lv_nodes.Columns.add "Translate"
652		lv_nodes.Columns.add "Rotate"
653		lv_nodes.Columns.add "Scale"
654		lv_nodes.Columns.add "Visibility"
655		lv_nodes.sorting = (dotNetClass "System.Windows.Forms.SortOrder").Ascending
656		lv_nodes.AutoResizeColumns ((dotNetClass "System.Windows.Forms.ColumnHeaderAutoResizeStyle").HeaderSize)
657	)
658
659	fn getNodeAttribute n create =
660	(
661		local attrib = n.custAttributes["NW4C Node Custom Attribute"]
662		if attrib == undefined then
663		(
664			if not create do return undefined
665			attrib = nw4c_node_custom_attribute()
666			append n.custAttributes attrib
667		)
668		return attrib
669	)
670
671	fn setExportScale n flag =
672	(
673		local attrib = getNodeAttribute n true
674		if attrib == undefined do return undefined
675		attrib.exportScaleKey = flag
676	)
677	fn setExportRotate n flag =
678	(
679		local attrib = getNodeAttribute n true
680		if attrib == undefined do return undefined
681		attrib.exportRotateKey = flag
682	)
683	fn setExportTrans n flag =
684	(
685		local attrib = getNodeAttribute n true
686		if attrib == undefined do return undefined
687		attrib.exportTranslateKey = flag
688	)
689	fn setExportVis n flag =
690	(
691		local attrib = getNodeAttribute n true
692		if attrib == undefined do return undefined
693		attrib.exportVisibilityKey = flag
694	)
695
696	fn getExportScale n =
697	(
698		local attrib = getNodeAttribute n false
699		if attrib == undefined do return false
700		return attrib.exportScaleKey
701	)
702	fn getExportRotate n =
703	(
704		local attrib = getNodeAttribute n false
705		if attrib == undefined do return false
706		return attrib.exportRotateKey
707	)
708	fn getExportTrans n =
709	(
710		local attrib = getNodeAttribute n false
711		if attrib == undefined do return false
712		return attrib.exportTranslateKey
713	)
714	fn getExportVis n =
715	(
716		local attrib = getNodeAttribute n false
717		if attrib == undefined do return false
718		return attrib.exportVisibilityKey
719	)
720
721	fn updateSelection =
722	(
723		if donotRedraw do return()
724		lv_nodes.Items.Clear()
725		local lvItems =#()
726
727		local str = ""
728		for n in nodes do
729		(
730			local li = dotNetObject "System.Windows.Forms.ListViewItem" n.name
731			local sub_li
732			local attr = getNodeAttribute n false
733			if attr != undefined then --�A�g���r���[�g������ꍇ
734			(
735				sub_li = li.SubItems.add (attr.exportTranslateKey as string)
736				sub_li = li.SubItems.add (attr.exportRotateKey as string)
737				sub_li = li.SubItems.add (attr.exportScaleKey as string)
738				sub_li = li.SubItems.add (attr.exportVisibilityKey as string)
739			)
740			else -- �A�g���r���[�g���Ȃ��ꍇ
741			(
742				sub_li = li.SubItems.add "false"
743				sub_li = li.SubItems.add "false"
744				sub_li = li.SubItems.add "false"
745				sub_li = li.SubItems.add "false"
746			)
747			append lvItems li
748		)
749		lv_nodes.Items.AddRange lvItems
750
751		if nodes.count > 0 then
752		(
753			chkExportScale.enabled = true
754			chkExportRotate.enabled = true
755			chkExportTrans.enabled = true
756			chkExportVisibility.enabled = true
757			chkExportScale.checked = getExportScale nodes[1]
758			chkExportRotate.checked = getExportRotate nodes[1]
759			chkExportTrans.checked = getExportTrans nodes[1]
760			chkExportVisibility.checked = getExportVis nodes[1]
761		)
762		else
763		(
764			chkExportScale.enabled = false
765			chkExportRotate.enabled = false
766			chkExportTrans.enabled = false
767			chkExportVisibility.enabled = false
768		)
769	)
770
771
772	on chkExportScale changed v do
773	(
774		for n in nodes do
775		(
776			setExportScale n v
777		)
778		updateSelection()
779	)
780	on chkExportRotate changed v do
781	(
782		for n in nodes do
783		(
784			setExportRotate n v
785		)
786		updateSelection()
787	)
788	on chkExportTrans changed v do
789	(
790		for n in nodes do
791		(
792			setExportTrans n v
793		)
794		updateSelection()
795	)
796	on chkExportVisibility changed v do
797	(
798		for n in nodes do
799		(
800			setExportVis n v
801		)
802		updateSelection()
803	)
804
805	fn addCallback =
806	(
807		callbacks.addScript #selectionSetChanged "nw4cForceKeyRollout.selectionCallback()" \
808			id:#nw4cForceKeySelectionChange
809	)
810	fn removeCallback =
811	(
812		callbacks.removeScripts id:#nw4cForceKeySelectionChange
813	)
814	fn selectionCallback =
815	(
816		nodes = #()
817		for n in selection do appendIfUnique nodes n
818		updateSelection()
819	)
820
821	on nw4cForceKeyRollout open  do
822	(
823		donotRedraw = false
824		initListView()
825		nodes = #()
826		addCallback()
827		selectionCallback()
828	)
829	on nw4cForceKeyRollout close  do
830	(
831		removeCallback()
832	)
833	on btnSearch pressed  do
834	(
835		removeCallback()
836		clearSelection()
837		nodes = #()
838		local bScaleON = chkS_ExportScaleON.checked
839		local bScaleOFF = chkS_ExportScaleOFF.checked
840		local bRotON = chkS_ExportRotateON.checked
841		local bRotOFF = chkS_ExportRotateOFF.checked
842		local bTransON = chkS_ExportTransON.checked
843		local bTransOFF = chkS_ExportTransOFF.checked
844		local bVisON = chkS_ExportVisON.checked
845		local bVisOFF = chkS_ExportVisOFF.checked
846
847		local scaleKey, rotKey, transKey, visKey
848
849		local isSearchAnd = if rdoSearchType.state == 1 then true else false
850		local isSearchOr = not isSearchAnd
851
852		for n in objects do
853		(
854			local attr = getNodeAttribute n false
855			if attr == undefined then
856			(
857				scaleKey = rotKey = transKey = visKey = false
858			)
859			else
860			(
861				scaleKey = attr.exportScaleKey
862				rotKey = attr.exportRotateKey
863				transKey = attr.exportTranslateKey
864				visKey = attr.exportVisibilityKey
865			)
866
867			local compare = true -- ���̏����Ŕ�r�����邩�ǂ����H
868			local ret =false -- ���̃m�[�h����r���������������ǂ���
869
870			-- scale
871			if (bScaleON or bScaleOFF) and compare do
872			(
873				ret = (scaleKey == bScaleON) or ((not scaleKey) == bScaleOFF)
874				if ret and isSearchOr then compare = false
875				else if (not ret) and isSearchAnd do compare = false
876			)
877			-- rotate
878			if (bRotON or bRotOFF) and compare do
879			(
880				ret = (rotKey == bRotON) or ((not rotKey) == bRotOFF)
881				if ret and isSearchOr then compare = false
882				else if (not ret) and isSearchAnd do compare = false
883			)
884			-- translate
885			if (bTransON or bTransOFF) and compare do
886			(
887				ret = (transKey == bTransON) or ((not transKey) == bTransOFF)
888				if ret and isSearchOr then compare = false
889				else if (not ret) and isSearchAnd do compare = false
890			)
891			-- visibility
892			if (bVisON or bVisOFF) and compare do
893			(
894				ret = (visKey == bVisON) or ((not visKey) == bVisOFF)
895				if ret and isSearchOr then compare = false
896				else if (not ret) and isSearchAnd do compare = false
897			)
898
899			-- �����������΃m�[�h��z��ɒlj�
900			if ret do
901			(
902				appendIfUnique nodes n
903			)
904		)
905
906		for n in nodes do
907		(
908			selectMore n
909		)
910		updateSelection()
911		addCallback()
912	)
913
914	on btnClose pressed  do DestroyDialog nw4cForceKeyRollout
915)-- Set Force Export Key rollout
916
917rollout nw4cNodeUserDataRollout "NW4C Set User Data" width:480 height:290
918(
919	group "Selected Node"
920	(
921		label lblNode
922		--dotNetControl lv_nodes "System.Windows.Forms.ListView" width:288 height:164
923	)
924	group "Edit Data"
925	(
926		button btnUp "Move Up" across:5
927		button btnDown "Move Down"
928		button btnAdd "Add..."
929		button btnDelete "Delete"
930		button btnEdit "Edit..."
931		dotNetControl lv_data "System.Windows.Forms.ListView" width:450 height:164
932	)
933	button btnClose "Close" width:474 height:24
934
935	local utils = nw4c_utils()
936	local donotRedraw
937	local nodes = #()
938	local dataset = undefined
939
940	fn getNodeAttribute n create =
941	(
942		local attrib = n.custAttributes["NW4C Node Custom Attribute"]
943		if attrib == undefined then
944		(
945			if not create do return undefined
946			attrib = nw4c_node_custom_attribute()
947			append n.custAttributes attrib
948		)
949		return attrib
950	)
951
952	fn initListView =
953	(
954		lv_data.gridLines = true
955		lv_data.View = (dotNetClass "System.Windows.Forms.View").Details
956		lv_data.fullRowSelect = true
957		lv_data.AutoSize = true
958		lv_data.MultiSelect = false
959		lv_data.Columns.add " Name   "
960		lv_data.Columns.add " Type   "
961		lv_data.Columns.add " Size"
962		lv_data.Columns.add " Value"
963		--lv_data.sorting = (dotNetClass "System.Windows.Forms.SortOrder").Ascending
964		lv_data.AutoResizeColumns ((dotNetClass "System.Windows.Forms.ColumnHeaderAutoResizeStyle").HeaderSize)
965	)
966
967	fn saveData =
968	(
969		-- 1�‚����I�����ꂽ�Ƃ�������������
970		if nodes.count != 1 do return()
971
972		local n = nodes[1]
973		local attr = getNodeAttribute n true
974		if attr != undefined do
975		(
976			attr.userSettings = dataset.toString()
977		)
978	)
979
980	fn updateSelection =
981	(
982		if donotRedraw do return()
983		lv_data.Items.Clear()
984		dataset = nw4c_userDataSet()
985
986		local lvItems =#()
987
988		-- 1�‚����I�����ꂽ�Ƃ�������������
989		if nodes.count == 1 then
990		(
991			lblNode.text = nodes[1].name
992			btnUp.enabled = true
993			btnDown.enabled  = true
994			btnAdd.enabled  = true
995			btnDelete.enabled  = true
996			btnEdit.enabled  = true
997		)
998		else
999		(
1000			lblNode.text = ""
1001			btnUp.enabled = false
1002			btnDown.enabled  = false
1003			btnAdd.enabled  = false
1004			btnDelete.enabled  = false
1005			btnEdit.enabled  = false
1006			return ()
1007		)
1008
1009		local n = nodes[1]
1010		local attr = getNodeAttribute n false
1011		if attr != undefined then --�A�g���r���[�g������ꍇ
1012		(
1013			local str = attr.userSettings
1014			if (classof str) == String do
1015			(
1016				local ret = dataset.fromString str
1017				if ret do
1018				(
1019					for i = 1 to dataset.list.count do
1020					(
1021						local data = dataset.list[i]
1022						local li = dotNetObject "System.Windows.Forms.ListViewItem" data.dataname
1023						local sub_li
1024						sub_li = li.SubItems.add (data.type as String)
1025						sub_li = li.SubItems.add ((data.valueCount()) as string)
1026						sub_li = li.SubItems.add ((data.valueToString oneline:true) as string)
1027						append lvItems li
1028					)
1029				)
1030			)
1031		)
1032		else -- �A�g���r���[�g���Ȃ��ꍇ
1033		(
1034		)
1035		lv_data.Items.AddRange lvItems
1036	)
1037
1038
1039
1040	fn addCallback =
1041	(
1042		callbacks.addScript #selectionSetChanged "nw4cNodeUserDataRollout.selectionCallback()" \
1043			id:#nw4cNodeUserDataSelectionChange
1044	)
1045	fn removeCallback =
1046	(
1047		callbacks.removeScripts id:#nw4cNodeUserDataSelectionChange
1048	)
1049	fn selectionCallback =
1050	(
1051		nodes = #()
1052		for n in selection do appendIfUnique nodes n
1053		updateSelection()
1054	)
1055
1056	fn EditData data add =
1057	(
1058		nw4cEditUserDataRollout_ValueSet = dataset
1059		nw4cEditUserDataRollout_Value = data
1060		CreateDialog  nw4cEditUserDataRollout modal:true
1061		if nw4cEditUserDataRollout_Value != undefined do
1062		(
1063			if add do dataset.appendData nw4cEditUserDataRollout_Value
1064			saveData()
1065			updateSelection()
1066		)
1067	)
1068
1069	on nw4cNodeUserDataRollout open  do
1070	(
1071		donotRedraw = false
1072		initListView()
1073		nodes = #()
1074		addCallback()
1075		selectionCallback()
1076	)
1077	on nw4cNodeUserDataRollout close  do
1078	(
1079		removeCallback()
1080	)
1081
1082	on btnUp pressed do
1083	(
1084		if lv_data.SelectedIndices.Count > 0 do
1085		(
1086			local id = lv_data.SelectedIndices.Item[0]
1087			local maxid = id + 1
1088			if id > 0 do
1089			(
1090				local tmp = dataset.list[maxid]
1091				deleteItem dataset.list (maxid)
1092				insertItem tmp dataset.list (maxid - 1)
1093				saveData()
1094				updateSelection()
1095				lv_data.Items.Item[id-1].Selected = true
1096			)
1097			lv_data.Focus()
1098		)
1099	)
1100	on btnDown pressed do
1101	(
1102		if lv_data.SelectedIndices.Count > 0 do
1103		(
1104			local id = lv_data.SelectedIndices.Item[0]
1105			local maxid = id + 1
1106			if maxid < dataset.list.count do
1107			(
1108				local tmp = dataset.list[maxid]
1109				deleteItem dataset.list (maxid)
1110				insertItem tmp dataset.list (maxid + 1)
1111				saveData()
1112				updateSelection()
1113				lv_data.Items.Item[id+1].Selected = true
1114			)
1115			lv_data.Focus()
1116		)
1117	)
1118
1119	on btnDelete pressed do
1120	(
1121		if lv_data.SelectedIndices.Count > 0 do
1122		(
1123			local id = lv_data.SelectedIndices.Item[0]
1124			local maxid = id + 1
1125			(
1126				deleteItem dataset.list (maxid)
1127				saveData()
1128				updateSelection()
1129			)
1130			lv_data.Focus()
1131		)
1132	)
1133
1134	on btnAdd pressed do
1135	(
1136		if (classof dataset) == nw4c_userDataSet do
1137		(
1138			editData (nw4c_userData()) true
1139		)
1140	)
1141
1142	on btnEdit pressed do
1143	(
1144		if (classof dataset) == nw4c_userDataSet do
1145		(
1146			if lv_data.SelectedIndices.Count > 0 do
1147			(
1148				local id = lv_data.SelectedIndices.Item[0]
1149				local maxid = id + 1
1150				editData (dataset.list[maxid]) false
1151			)
1152		)
1153	)
1154
1155	on btnClose pressed  do DestroyDialog nw4cNodeUserDataRollout
1156)-- Set User Data
1157
1158