1-- NW4C Material Tool (2011/02/15)
2-- Version 1.0.0
3-- (c)2010-2011 Nintendo
4
5rollout nw4cMaterialRollout "NW4C Set Material Attribute" width:480 height:550
6(
7	groupBox grp1 "Selected Material" pos:[8,8] width:464 height:170
8	--label lblSelectedNode "" pos:[16,24] width:368 height:64
9	dotNetControl lv_mtl "System.Windows.Forms.ListView" pos:[16,24] width:450 height:150
10	--
11	groupBox grp2 "Set" pos:[8,184] width:464 height:126
12	dropDownList ddlSetFaceCulling "Face Culling" pos:[16,200] width:152 height:41 \
13			items:#("Back Face", "Front Face", "Always", "Never")
14	dropDownList ddlSetCompress "Compress" pos:[184,200] width:152 height:41 \
15			items:#("Compress if possible", "Don�ft compress")
16	checkbox chkSetFragmentLighting "Fragment Lighting" pos:[16,244] width:152 height:16
17	checkbox chkSetVertexLighting "Vertex Lighting" pos:[184,244] width:152 height:16
18	dropDownList ddlSetBlendMode "Blend Mode" pos:[16,264] width:152 height:41 \
19			items:#("Auto", "Opaque", "Alpha Test", "Translucent", "Add", "Sub", "Multiply")
20	--
21	groupBox grp3 "Search" pos:[8,318] width:464 height:200
22	label lbl2 "Face Culling" pos:[16,334] width:80 height:16
23	checkbox chkSFC_Front "Front Face" pos:[144,334] width:80 height:16
24	checkbox chkSFC_Back "Back Face" pos:[224,334] width:80 height:16
25	checkbox chkSFC_Always "Always" pos:[304,334] width:64 height:16
26	checkbox chkSFC_Never "Never" pos:[368,334] width:56 height:16
27	label lbl3 "Fragment Lighting" pos:[16,358] width:120 height:16
28	checkbox chkSFL_Off "off" pos:[144,358] width:48 height:16
29	checkbox chkSFL_On "on" pos:[192,358] width:40 height:16
30	label lbl4 "Vertex Lighting" pos:[16,382] width:120 height:16
31	checkbox chkSVL_Off "off" pos:[144,382] width:48 height:16
32	checkbox chkSVL_On "on" pos:[192,382] width:40 height:16
33	label lbl5 "Compress" pos:[16,406] width:120 height:16
34	checkbox chkSC_On "If possible" pos:[144,406] width:80 height:16
35	checkbox chkSC_Off "Don't" pos:[224,406] width:104 height:16
36
37
38	label lbl6 "Blend Mode" pos:[16,430] width:120 height:16
39	checkbox chkBM_Auto "Auto" pos:[144,430] width:80 height:16
40	checkbox chkBM_Opaque "Opaque" pos:[224,430] width:80 height:16
41	checkbox chkBM_AlphaTest "Alpha Test" pos:[304,430] width:80 height:16
42	checkbox chkBM_Translucent "Translucent" pos:[144,454] width:80 height:16
43	checkbox chkBM_Add "Add" pos:[234,454] width:60 height:16
44	checkbox chkBM_Sub "Sub" pos:[294,454] width:60 height:16
45	checkbox chkBM_Multiply "Multiply" pos:[358,454] width:80 height:16
46
47	--
48	radioButtons rdoSearchType "" pos:[192,494] width:98 height:16 labels:#("AND", "OR") columns:2
49	button btnSearch "Search" pos:[304,484] width:112 height:24
50	button btnClose "Close" pos:[8,522] width:464 height:24
51
52	local donotRedraw
53	local mtls = #()
54	local nodeCallbacks =#()
55	fn initListView =
56	(
57		lv_mtl.gridLines = true
58		lv_mtl.View = (dotNetClass "System.Windows.Forms.View").Details
59		lv_mtl.fullRowSelect = true
60		lv_mtl.AutoSize = true
61		lv_mtl.MultiSelect = false
62		lv_mtl.Columns.add "Material Name"
63		lv_mtl.Columns.add "Face Culling"
64		lv_mtl.Columns.add "Fragment"
65		lv_mtl.Columns.add "Vertex"
66		lv_mtl.Columns.add "Compress     "
67		lv_mtl.Columns.add "BlendMode"
68		lv_mtl.sorting = (dotNetClass "System.Windows.Forms.SortOrder").Ascending
69		lv_mtl.AutoResizeColumns ((dotNetClass "System.Windows.Forms.ColumnHeaderAutoResizeStyle").HeaderSize)
70	)
71
72	fn getMtlAttribute m create =
73	(
74		local attrib = m.custAttributes["NW4C Material Custom Attribute"]
75		if attrib == undefined then
76		(
77			--if not create do return undefined
78			attrib = nw4c_mtl_custom_attribute()
79			append m.custAttributes attrib
80		)
81		return attrib
82	)
83
84	fn getSelMtls sel =
85	(
86		local smtls = #()
87		for n in sel do
88		(
89			local mtl = n.material
90			if mtl != undefined do
91			(
92				appendIfUnique smtls mtl
93				if(classOf mtl == Multimaterial) do
94				(
95					for submtl in mtl.materialList do
96					(
97						appendIfUnique smtls submtl
98					)
99				)
100			)
101		)
102		return smtls
103	)
104
105	fn enableUI flag =
106	(
107		ddlSetFaceCulling.enabled = flag
108		ddlSetCompress.enabled = flag
109		chkSetFragmentLighting.enabled = flag
110		chkSetVertexLighting.enabled = flag
111		ddlSetBlendMode.enabled = flag
112	)
113
114	fn loadAttributeToUI attr =
115	(
116		if (classof attr) != nw4c_mtl_custom_attribute do return()
117
118		ddlSetFaceCulling.selection = attr.faceCulling + 1
119		ddlSetCompress.selection = attr.compress + 1
120		chkSetFragmentLighting.checked = attr.fragmentLighting
121		chkSetVertexLighting.checked = attr.vertexLighting
122		ddlSetBlendMode.selection = attr.blendMode + 1
123	)
124
125	fn updateSelection =
126	(
127		if donotRedraw do return()
128		lv_mtl.Items.Clear()
129		--print "updateSelection"
130		--print mtls
131
132		local str = ""
133		--local mtls = getSelMtls selection
134
135		local lvItems =#()
136		for m in mtls do
137		(
138			local attr = getMtlAttribute m true
139
140			local li = dotNetObject "System.Windows.Forms.ListViewItem" m.name
141			local sub_li
142			str = case attr.faceCulling of
143				(
144					0: "Back Face"
145					1: "Front Face"
146					2: "Always"
147					default: "Never"
148				)
149			sub_li = li.SubItems.add str
150
151			sub_li = li.SubItems.add (if attr.fragmentLighting then "on" else "off")
152			sub_li = li.SubItems.add (if attr.vertexLighting then "on" else "off")
153
154			str = case attr.compress of
155				(
156					0: "If possible"
157					default: "Don�ft"
158				)
159			sub_li = li.SubItems.add str
160
161			str = case attr.blendMode of
162				(
163					0: "Auto"
164					1: "Opaque"
165					2: "Alpha Test"
166					3: "Translucent"
167					4: "Add"
168					5: "Sub"
169					default: "Multiply"
170				)
171			sub_li = li.SubItems.add str
172
173			append lvItems li
174		)
175		--print lvItems
176		lv_mtl.Items.AddRange lvItems
177
178		--lblSelectedNode.text = str
179		if mtls.count > 0 then
180		(
181			enableUI  true
182			loadAttributeToUI (getMtlAttribute mtls[1] false)
183		)
184		else
185		(
186			enableUI false
187		)
188	)
189
190	fn mtlUpdateCallback ev nd =
191	(
192		format "mtlUpdateCallback %(%), %\n" (classof ev) (ev as string) (nd as string)
193		updateSelection()
194	)
195
196	fn updateNodeCallbacks =
197	(
198		local nodes =#()
199		nodeCallbacks =#()
200		gc()
201		for m in mtls do
202		(
203			local n = refs.dependentNodes m
204			if n != undefined do
205			(
206				if (appendIfUnique nodes n) do
207				(
208					local cb = NodeEventCallback mouseUp:true delay:1000 materialOtherEvent:mtlUpdateCallback
209					append nodeCallbacks cb
210				)
211			)
212		)
213	)
214
215	fn setMtlAttributes =
216	(
217		--local mtls = getSelMtls selection
218		local attr
219		for m in mtls do
220		(
221			attr = getMtlAttribute m true
222			attr.faceCulling = ddlSetFaceCulling.selection - 1
223			attr.compress = ddlSetCompress.selection - 1
224			attr.fragmentLighting = chkSetFragmentLighting.checked
225			attr.vertexLighting = chkSetVertexLighting.checked
226			attr.blendMode = ddlSetBlendMode.selection - 1
227		)
228		updateSelection()
229	)
230
231	fn selectionCallback =
232	(
233		mtls = getSelMtls selection
234		--updateNodeCallbacks()
235		updateSelection()
236	)
237
238	fn addCallback =
239	(
240		callbacks.addScript #selectionSetChanged "nw4cMaterialRollout.selectionCallback()" id:#nw4cMtlSelectionChange
241	)
242	fn removeCallback =
243	(
244		callbacks.removeScripts id:#nw4cMtlSelectionChange
245	)
246
247	-- �z����̑S�Ă�bool��False�Ȃ�true
248	fn isAllBoolFalse bools =
249	(
250		if classof bools != Array do return false
251		local allOn = true, allOff = false
252		for b in bools	do
253		(
254			allOn = allOn and b
255			allOff = allOff or b
256		)
257		local ret = if allOn or not allOff then true else false
258		--format "isAllBoolSame % \n"	ret
259		--return ret
260		return (not allOff)
261	)
262	on lv_mtl SelectedIndexChanged e do
263	(
264		local numItems = lv_mtl.Items.Count
265		for i = 0 to (numItems - 1) do
266		(
267			lv_mtl.Items.Item[i].Selected = false
268		)
269	)
270	on btnSearch pressed  do
271	(
272		removeCallback()
273		local allMtls = getSelMtls objects
274		mtls = #()
275		local searchFaceCull, searchFragLight, searchVtxLight, searchCompress, searchBlend
276		-- face
277		local fc_front = chkSFC_Front.checked
278		local fc_back = chkSFC_Back.checked
279		local fc_always = chkSFC_Always.checked
280		local fc_never = chkSFC_Never.checked
281		searchFaceCull = not (isAllBoolFalse #(fc_front, fc_back,fc_always,fc_never) )
282
283		local fl_on = chkSFL_On.checked
284		local fl_off = chkSFL_Off.checked
285		searchFragLight = not (isAllBoolFalse #(fl_on, fl_off) )
286
287		local vl_on = chkSVL_On.checked
288		local vl_off = chkSVL_Off.checked
289		searchVtxLight = not (isAllBoolFalse #(vl_on, vl_off) )
290
291		local comp_on = chkSC_On.checked
292		local comp_off = chkSC_Off.checked
293		searchCompress = not (isAllBoolFalse #(comp_on, comp_off) )
294
295		local bmAuto = chkBM_Auto.checked
296		local bmOpaque = chkBM_Opaque.checked
297		local bmAlphaTest = chkBM_AlphaTest.checked
298		local bmTranslucent = chkBM_Translucent.checked
299		local bmAdd = chkBM_Add.checked
300		local bmSub = chkBM_Sub.checked
301		local bmMultiply = chkBM_Multiply.checked
302		searchBlend = not (isAllBoolFalse #(bmAuto, bmOpaque, bmAlphaTest, bmTranslucent, bmAdd, bmSub, bmMultiply) )
303
304		local isSearchAnd = if rdoSearchType.state == 1 then true else false
305
306		for m in allMtls do
307		(
308			local compare = true -- ���̏����Ŕ�r�����邩�ǂ����H
309			local ret =false -- ���̃}�e���A������r���������������ǂ���
310			local attr = getMtlAttribute m true
311			if searchFaceCull and compare do
312			(
313				ret = case attr.faceCulling of
314				(
315					0: fc_back
316					1: fc_front
317					2: fc_always
318					3: fc_never
319				)
320				if ret and (not isSearchAnd) then compare = false -- ���̔�r�����������A���[�h��OR�Ȃ瑼�̔�r�͕s�v
321				else if (not ret) and isSearchAnd do compare = false -- ���̔�r�������������A���[�h��AND�Ȃ瑼�̔�r�͕s�v
322			)
323
324			if searchFragLight and compare do
325			(
326				ret = (attr.fragmentLighting == fl_on) or (attr.fragmentLighting == (not fl_off))
327				if ret and (not isSearchAnd) then compare = false
328				else if (not ret) and isSearchAnd do compare = false
329			)
330
331			if searchVtxLight and compare do
332			(
333				ret = (attr.vertexLighting == vl_on) or (attr.vertexLighting == (not vl_off))
334				if ret and (not isSearchAnd) then compare = false
335				else if (not ret) and isSearchAnd do compare = false
336			)
337
338			if searchCompress and compare do
339			(
340				local isComp = (attr.compress == 0)
341				ret = (isComp == comp_on) or (isComp == (not comp_off))
342				if ret and (not isSearchAnd) then compare = false
343				else if (not ret) and isSearchAnd do compare = false
344			)
345
346			if searchBlend and compare do
347			(
348				ret = case attr.blendMode of
349				(
350					0: bmAuto
351					1: bmOpaque
352					2: bmAlphaTest
353					3: bmTranslucent
354					4: bmAdd
355					5: bmSub
356					6: bmMultiply
357					default: bmAuto
358				)
359				if ret and (not isSearchAnd) then compare = false
360				else if (not ret) and isSearchAnd do compare = false
361			)
362
363			-- �����������΃}�e���A����z��ɒlj�
364			if ret do
365			(
366				append mtls m
367			)
368		)
369		--print mtls
370		clearSelection()
371		for m in mtls do
372		(
373			selectMore (refs.dependentNodes m)
374		)
375		--updateNodeCallbacks()
376		updateSelection()
377		addCallback()
378	)
379
380
381/*
382   	on lv_mtl ColumnClick evt do
383	(
384		if (lv_mtl.ListViewItemSorter.Column != evt.Column) then
385		(
386			lv_mtl.ListViewItemSorter.Column = evt.Column
387			lv_mtl.ListViewItemSorter.Reversed = false
388		)
389		else
390		(
391			lv_mtl.ListViewItemSorter.Reversed = (not lv_mtl.ListViewItemSorter.Reversed)
392		)
393		lv_mtl.Sort()
394	)
395*/
396	on ddlSetFaceCulling selected i do setMtlAttributes()
397	on ddlSetCompress selected i do setMtlAttributes()
398	on chkSetFragmentLighting changed i do setMtlAttributes()
399	on chkSetVertexLighting changed i do setMtlAttributes()
400	on ddlSetBlendMode selected i do setMtlAttributes()
401
402	on nw4cMaterialRollout open  do
403	(
404		donotRedraw = false
405		initListView()
406		addCallback()
407		--updateSelection()
408		selectionCallback()
409	)
410	on nw4cMaterialRollout close  do
411	(
412		removeCallback()
413	)
414	on btnClose pressed  do DestroyDialog nw4cMaterialRollout
415)-- mtl rollout
416
417rollout nw4cRenderPriorityRollout "NW4C Set Render Priority" width:480 height:400
418(
419	groupBox grp1 "Selected Material" pos:[8,8] width:464 height:170
420	dotNetControl lv_mtl "System.Windows.Forms.ListView" pos:[16,24] width:450 height:150
421
422	groupBox grp2 "Set" pos:[8,187] width:464 height:61
423	label lbl6 "Render Priority:" pos:[24,208] width:104 height:16
424	radioButtons rdoSetPriorityType "" pos:[128,208] width:87 height:32 labels:#("Don't care", "") columns:1 default:1
425	spinner spnSetPriority "" pos:[152,224] width:56 height:16 range:[1,255,1] type:#integer scale:1 enabled:false
426	label lbl7 "1(High Priority) - 255(Low Priority)" pos:[224,224] width:240 height:16
427
428	groupBox grp4 "Search" pos:[8,256] width:464 height:104
429	label lbl8 "Render Priority:" pos:[24,280] width:104 height:16
430	radioButtons rdoSearchPriorityType "" pos:[128,280] width:89 height:48
431			labels:#("Don't care", "Condition", "All Material") columns:1 default:1 \
432	dropDownList ddlSearchConditionType "" pos:[208,292] width:96 height:22 default:1 enabled:false \
433			items:#("< : under", "<= : below", "= : exactly", ">= : above", "> : over")
434	spinner spnSearchPriority "" pos:[312,294] width:48 height:16 range:[1,255,1] type:#integer scale:1 enabled:false
435
436	button btnSearch "Search" pos:[280,328] width:112 height:24
437	button btnClose "Close" pos:[8,368] width:464 height:24
438
439	local mtls =#()
440
441	fn getMtlAttribute m create =
442	(
443		local attrib = m.custAttributes["NW4C Material Custom Attribute"]
444		if attrib == undefined then
445		(
446			--if not create do return undefined
447			attrib = nw4c_mtl_custom_attribute()
448			append m.custAttributes attrib
449		)
450		return attrib
451	)
452
453	fn initListView =
454	(
455		lv_mtl.gridLines = true
456		lv_mtl.View = (dotNetClass "System.Windows.Forms.View").Details
457		lv_mtl.fullRowSelect = true
458		lv_mtl.AutoSize = true
459		lv_mtl.MultiSelect = false
460		lv_mtl.LabelEdit = true
461		lv_mtl.AllowColumnReorder = true
462		lv_mtl.Columns.add "Render Priority"
463		lv_mtl.Columns.add "Material Name"
464		lv_mtl.Columns.Item[0].DisplayIndex = 1
465		lv_mtl.Columns.Item[1].DisplayIndex = 0
466		--lv_mtl.sorting = (dotNetClass "System.Windows.Forms.SortOrder").Ascending
467		lv_mtl.AutoResizeColumns ((dotNetClass "System.Windows.Forms.ColumnHeaderAutoResizeStyle").HeaderSize)
468
469	)
470
471	fn getSelMtls sel =
472	(
473		local smtls = #()
474		for n in sel do
475		(
476			local mtl = n.material
477			if mtl != undefined do
478			(
479				appendIfUnique smtls mtl
480				if(classOf mtl == Multimaterial) do
481				(
482					for submtl in mtl.materialList do
483					(
484						appendIfUnique smtls submtl
485					)
486				)
487			)
488		)
489		return smtls
490	)
491
492	fn updateSelection =
493	(
494		lv_mtl.Items.Clear()
495
496		local str = ""
497		--local mtls = getSelMtls selection
498
499		local lvItems =#()
500		for m in mtls do
501		(
502			local attr = getMtlAttribute m true
503			local val = 0
504			if attr.renderPriorityType == 1 do
505			(
506				val = attr.renderPriority
507			)
508			local li = dotNetObject "System.Windows.Forms.ListViewItem" (val as string)
509			local sub_li = li.SubItems.add m.name
510			append lvItems li
511		)
512		lv_mtl.Items.AddRange lvItems
513	)
514
515	fn setMtlAttributes =
516	(
517		--local mtls = getSelMtls selection
518		local attr
519		undo "Edit render priority" on
520		(
521			spnSetPriority.enabled = (rdoSetPriorityType.state == 2)
522			for m in mtls do
523			(
524				attr = getMtlAttribute m true
525				local val = 0
526				if rdoSetPriorityType.state == 1 then
527				(
528					attr.renderPriorityType = 0
529				)
530				else
531				(
532					attr.renderPriorityType = 1
533					attr.renderPriority = spnSetPriority.value
534				)
535			)
536		)
537		updateSelection()
538	)
539
540	fn selectionCallback =
541	(
542		mtls = getSelMtls selection
543		updateSelection()
544	)
545
546	fn addCallback =
547	(
548		callbacks.addScript #selectionSetChanged "nw4cRenderPriorityRollout.selectionCallback()" \
549				id:#nw4cRenderPrioritySelectionChange
550	)
551	fn removeCallback =
552	(
553		callbacks.removeScripts id:#nw4cRenderPrioritySelectionChange
554	)
555
556	on btnSearch pressed  do
557	(
558		removeCallback()
559		local allMtls = getSelMtls objects
560		mtls = #()
561
562		for m in allMtls do
563		(
564			local attr = getMtlAttribute m true
565			local ret= false
566
567			case rdoSearchPriorityType.state of
568			(
569				1: ( -- Don't care
570					if attr.renderPriorityType == 0 do
571					(
572						ret = true
573					)
574				)
575				2: ( -- condition
576					if attr.renderPriorityType == 1 do
577					(
578						local v = spnSearchPriority.value
579						case ddlSearchConditionType.selection of
580						(
581							1: ( -- under
582								ret = (attr.renderPriority < v)
583							)
584							2: ( -- below
585								ret = (attr.renderPriority <= v)
586							)
587							3: ( -- exactly
588								ret = (attr.renderPriority == v)
589							)
590							4: ( -- above
591								ret = (attr.renderPriority >= v)
592							)
593							5: ( -- over
594								ret = (attr.renderPriority > v)
595							)
596						)
597					)
598				)
599				default: ret = true
600			)
601
602			-- �����������΃}�e���A����z��ɒlj�
603			if ret do
604			(
605				append mtls m
606			)
607		)
608
609		clearSelection()
610		for m in mtls do
611		(
612			selectMore (refs.dependentNodes m)
613		)
614
615		updateSelection()
616		addCallback()
617	)
618
619	on lv_mtl AfterLabelEdit ev do
620	(
621		local str = ev.Label
622		local cancel = true
623		if str != undefined do
624		(
625			local v = str as Integer
626			if v != undefined  do
627			(
628				if (1 <= v) and (v <= 255) do
629				(
630					local subItem = lv_mtl.Items.item[ev.Item].subitems
631					local eMtl = subItem.Item[1].Text
632					--format "set priority \"%\" = %\n" eMtl v
633					local attr = undefined
634					for m in sceneMaterials while attr == undefined do
635					(
636						if m.name == eMtl then
637						(
638							attr = getMtlAttribute m true
639						)
640						else if(classOf m == Multimaterial) do
641						(
642							for submtl in m.materialList while attr == undefined do
643							(
644								if submtl.name == eMtl then
645								(
646									attr = getMtlAttribute submtl true
647								)
648							)
649						)
650					)
651
652					if attr != undefined do
653					(
654						attr.renderPriorityType = if (v == 0) then 0 else 1
655						attr.renderPriority = v
656						cancel = false
657					)
658				)
659			)
660		)
661		ev.CancelEdit = cancel
662	)
663
664	on rdoSetPriorityType changed i do setMtlAttributes()
665	on spnSetPriority changed i do setMtlAttributes()
666
667	on rdoSearchPriorityType changed i do
668	(
669		ddlSearchConditionType.enabled = (i == 2)
670		spnSearchPriority.enabled = (i == 2)
671	)
672
673
674	on nw4cRenderPriorityRollout lbuttondown mp do
675	(
676		--print mp
677	)
678
679
680	on nw4cRenderPriorityRollout open  do
681	(
682		mtls = #()
683		--donotRedraw = false
684		initListView()
685		addCallback()
686		--updateSelection()
687		selectionCallback()
688	)
689	on nw4cRenderPriorityRollout close  do
690	(
691		removeCallback()
692	)
693	on btnClose pressed  do DestroyDialog nw4cRenderPriorityRollout
694)-- priority rollout
695
696rollout nw4cMtlUserDataRollout "NW4C Set Material User Data" width:480 height:290
697(
698	group "Selected Material"
699	(
700		label lblMtl
701	)
702	group "Edit Data"
703	(
704		button btnUp "Move Up" across:5
705		button btnDown "Move Down"
706		button btnAdd "Add..."
707		button btnDelete "Delete"
708		button btnEdit "Edit..."
709		dotNetControl lv_data "System.Windows.Forms.ListView" width:450 height:164
710	)
711	button btnClose "Close" width:474 height:24
712
713	local utils = nw4c_utils()
714	local dataset = undefined
715	local mtl = undefined
716
717	fn getMtlAttribute m create =
718	(
719		local attrib = m.custAttributes["NW4C Material Custom Attribute"]
720		if attrib == undefined then
721		(
722			if not create do return undefined
723			attrib = nw4c_mtl_custom_attribute()
724			append m.custAttributes attrib
725		)
726		return attrib
727	)
728
729	fn initListView =
730	(
731		lv_data.gridLines = true
732		lv_data.View = (dotNetClass "System.Windows.Forms.View").Details
733		lv_data.fullRowSelect = true
734		lv_data.AutoSize = true
735		lv_data.MultiSelect = false
736		lv_data.Columns.add " Name   "
737		lv_data.Columns.add " Type   "
738		lv_data.Columns.add " Size"
739		lv_data.Columns.add " Value"
740		lv_data.AutoResizeColumns ((dotNetClass "System.Windows.Forms.ColumnHeaderAutoResizeStyle").HeaderSize)
741	)
742
743	fn saveData =
744	(
745		-- 1�‚����I�����ꂽ�Ƃ�������������
746		if superClassOf mtl != material do return false
747
748		local attr = getMtlAttribute mtl true
749		if attr != undefined do
750		(
751			attr.userSettings = dataset.toString()
752		)
753	)
754
755	fn updateSelection =
756	(
757		lv_data.Items.Clear()
758		dataset = nw4c_userDataSet()
759
760		local lvItems =#()
761
762		-- 1�‚����I�����ꂽ�Ƃ�������������
763		if superClassOf mtl == material then
764		(
765			lblMtl.text = mtl.name
766			btnUp.enabled = true
767			btnDown.enabled  = true
768			btnAdd.enabled  = true
769			btnDelete.enabled  = true
770			btnEdit.enabled  = true
771		)
772		else
773		(
774			lblNode.text = ""
775			btnUp.enabled = false
776			btnDown.enabled  = false
777			btnAdd.enabled  = false
778			btnDelete.enabled  = false
779			btnEdit.enabled  = false
780			return ()
781		)
782
783		local attr = getMtlAttribute mtl false
784		if attr != undefined then --�A�g���r���[�g������ꍇ
785		(
786			local str = attr.userSettings
787			if (classof str) == String do
788			(
789				local ret = dataset.fromString str
790				if ret do
791				(
792					for i = 1 to dataset.list.count do
793					(
794						local data = dataset.list[i]
795						local li = dotNetObject "System.Windows.Forms.ListViewItem" data.dataname
796						local sub_li
797						sub_li = li.SubItems.add (data.type as String)
798						sub_li = li.SubItems.add ((data.valueCount()) as string)
799						sub_li = li.SubItems.add ((data.valueToString oneline:true) as string)
800						append lvItems li
801					)
802				)
803			)
804		)
805		lv_data.Items.AddRange lvItems
806	)
807
808	fn EditData data add =
809	(
810		nw4cEditUserDataRollout_ValueSet = dataset
811		nw4cEditUserDataRollout_Value = data
812		CreateDialog  nw4cEditUserDataRollout modal:true
813		if nw4cEditUserDataRollout_Value != undefined do
814		(
815			if add do dataset.appendData nw4cEditUserDataRollout_Value
816			saveData()
817			updateSelection()
818		)
819	)
820
821	on nw4cMtlUserDataRollout open  do
822	(
823		initListView()
824		mtl = medit.GetCurMtl()
825		updateSelection()
826	)
827	on nw4cMtlUserDataRollout close  do
828	(
829	)
830
831	on btnUp pressed do
832	(
833		if lv_data.SelectedIndices.Count > 0 do
834		(
835			local id = lv_data.SelectedIndices.Item[0]
836			local maxid = id + 1
837			if id > 0 do
838			(
839				local tmp = dataset.list[maxid]
840				deleteItem dataset.list (maxid)
841				insertItem tmp dataset.list (maxid - 1)
842				saveData()
843				updateSelection()
844				lv_data.Items.Item[id-1].Selected = true
845			)
846			lv_data.Focus()
847		)
848	)
849	on btnDown pressed do
850	(
851		if lv_data.SelectedIndices.Count > 0 do
852		(
853			local id = lv_data.SelectedIndices.Item[0]
854			local maxid = id + 1
855			if maxid < dataset.list.count do
856			(
857				local tmp = dataset.list[maxid]
858				deleteItem dataset.list (maxid)
859				insertItem tmp dataset.list (maxid + 1)
860				saveData()
861				updateSelection()
862				lv_data.Items.Item[id+1].Selected = true
863			)
864			lv_data.Focus()
865		)
866	)
867
868	on btnDelete pressed do
869	(
870		if lv_data.SelectedIndices.Count > 0 do
871		(
872			local id = lv_data.SelectedIndices.Item[0]
873			local maxid = id + 1
874			(
875				deleteItem dataset.list (maxid)
876				saveData()
877				updateSelection()
878			)
879			lv_data.Focus()
880		)
881	)
882
883	on btnAdd pressed do
884	(
885		if (classof dataset) == nw4c_userDataSet do
886		(
887			editData (nw4c_userData()) true
888		)
889	)
890
891	on btnEdit pressed do
892	(
893		if (classof dataset) == nw4c_userDataSet do
894		(
895			if lv_data.SelectedIndices.Count > 0 do
896			(
897				local id = lv_data.SelectedIndices.Item[0]
898				local maxid = id + 1
899				editData (dataset.list[maxid]) false
900			)
901		)
902	)
903
904	on btnClose pressed  do DestroyDialog nw4cMtlUserDataRollout
905
906)-- Set Mtl User Data
907
908
909-- Material editor menu
910macroScript AddMaterialAttribute category:"NW4C"
911(
912	local mtl = medit.GetCurMtl()
913	if (mtl != undefined) and (superClassOf mtl == material) do
914	(
915		nw4cMaterialRollout.getMtlAttribute mtl true
916	)
917)
918
919macroScript DeleteMaterialAttribute category:"NW4C"
920(
921	local mtl = medit.GetCurMtl()
922	if (mtl != undefined) and (superClassOf mtl == material) do
923	(
924		deleteItem mtl.custAttributes "NW4C Material Custom Attribute"
925	)
926)
927
928macroScript SetMaterialUserData category:"NW4C"
929(
930	local mtl = medit.GetCurMtl()
931	if (mtl != undefined) and (superClassOf mtl == material) do
932	(
933		CreateDialog  nw4cMtlUserDataRollout modal:true
934	)
935)
936
937fn getNw4cMtlMenu =
938(
939	local mtlMenuBar = nw4cmax.GetMtlEditorMenu()
940	for i = 1 to mtlMenuBar.numitems() do
941	(
942		local mi = mtlMenuBar.getItem i
943		if ( (mi.getTitle()) == "NW4C" ) do
944		(
945			return mi
946		)
947	)
948
949	-- NW4C���j���[�����o�^
950	local subMenu = menuMan.createMenu "NW4C"
951	local subMenuItem = menuMan.createSubMenuItem "Test Menu" subMenu
952	-- �T�u���j���[���Ōォ�� 2 �Ԗڂ̃X���b�g�ɒlj����܂��B
953	mtlMenuBar.addItem subMenuItem -1
954	return subMenuItem
955)
956
957fn resetMtlMenuActions mi =
958(
959	local menu = mi.getSubMenu()
960	-- �܂��o�^�ς݂̃T�u���j���[�A�C�e�����폜
961	while (menu.numItems() > 0) do
962	(
963		menu.removeItemByPosition 1
964	)
965
966	local dialogItem
967
968	dialogItem = menuMan.createActionItem "AddMaterialAttribute" "NW4C"
969	dialogItem.setTitle "Add Material Attribute"
970	dialogItem.setUseCustomTitle true
971	menu.addItem dialogItem -1
972
973	dialogItem = menuMan.createActionItem "DeleteMaterialAttribute" "NW4C"
974	dialogItem.setTitle "Delete Material Attribute"
975	dialogItem.setUseCustomTitle true
976	menu.addItem dialogItem -1
977
978	dialogItem = menuMan.createSeparatorItem()
979	menu.addItem dialogItem -1
980
981	dialogItem = menuMan.createActionItem "SetMaterialUserData" "NW4C"
982	dialogItem.setTitle "Set Material User Data"
983	dialogItem.setUseCustomTitle true
984	menu.addItem dialogItem -1
985)
986