/******************************************************************************
	NINTENDO NITRO-System Maya Plugin

	File:         NNS_ShowLighting.mel
	Description:  show lighting
	Date:         2004/11/29
	Author:       T.Endo

	Copyright 2003-2006 Nintendo. All rights reserved.
******************************************************************************/

/******************************************************************************
	show	
******************************************************************************/
global proc nnsShowLighting_Show(int $light_mode)
{
	int $sg_count = 0;
	select -cl;
	string $sgs[] = `ls -typ shadingEngine`;
	for ($sg in $sgs) {
		if ($sg == "initialParticleSE" || $sg == "swatchShadingGroup")
			continue;

		int $light0 = (`attributeQuery -n $sg -ex "nns_lighting"`) ?
			`getAttr ($sg + ".nns_lighting")` : 1;
		int $light1 = (`attributeQuery -n $sg -ex "nns_lighting1"`) ?
			`getAttr ($sg + ".nns_lighting1")` : 0;
		int $light2 = (`attributeQuery -n $sg -ex "nns_lighting2"`) ?
			`getAttr ($sg + ".nns_lighting2")` : 0;
		int $light3 = (`attributeQuery -n $sg -ex "nns_lighting3"`) ?
			`getAttr ($sg + ".nns_lighting3")` : 0;

		int $match_flag = 0;
		if ($light_mode == -1) // off
			$match_flag = (!$light0 && !$light1 && !$light2 && !$light3);
		else if ($light_mode == 0)
			$match_flag = $light0;
		else if ($light_mode == 1)
			$match_flag = $light1;
		else if ($light_mode == 2)
			$match_flag = $light2;
		else if ($light_mode == 3)
			$match_flag = $light3;
		else // any
			$match_flag = ($light0 || $light1 || $light2 || $light3);

		if ($match_flag) {
			select -add $sg;		// face
			select -add -ne $sg;	// shadingEngine
			++$sg_count;
		}
	}

	if ($sg_count == 0)
		print "Not found\n";
	else {
		string $msg = "Found: " + $sg_count + " shadingEngine node";
		if ($sg_count >= 2)
			$msg += "s";
		print ($msg + "\n");
	}
}

/******************************************************************************
	main
******************************************************************************/
global proc NNS_ShowLighting()
{

//-----------------------------------------------------------------------------
// backup selection
	string $sel_bak[] = `ls -sl`;
	string $sel_bak_str;
	for ($sel in $sel_bak)
		$sel_bak_str += ($sel + " ");
	select -cl;
	
//-----------------------------------------------------------------------------
// create window
	int $wd = 300;
	int $ht = 245;
	if (!`window -exists nnsShowLighting_Win`) {
		string $close_cmd = "deleteUI nnsShowLighting_Win";
		string $remain_cmd = "if (!`checkBoxGrp -q -v1 nnsShowLighting_KeepSelecion`) {"
			+ "select -cl;select -ne " + $sel_bak_str + ";}";

		window -t "NITRO Show Lighting" -wh $wd $ht -mxb 0
			nnsShowLighting_Win;

		columnLayout -adj 1 -cat "both" 4 -cal "center" -rs 15;
			columnLayout -adj 1 -cat "both" 4 -cal "center" -rs 4;

				radioButtonGrp -nrb 1 -l "Lighting"
					-l1 "Off"
					-cw2 100 90
					-on1 "nnsShowLighting_Show -1"
					nnsShowLighting_LightOff;
				radioButtonGrp -nrb 1 -l ""
					-l1 "Light0 On"
					-cw2 100 90
					-on1 "nnsShowLighting_Show 0"
					-scl "nnsShowLighting_LightOff"
					nnsShowLighting_Light0;
				radioButtonGrp -nrb 1 -l ""
					-l1 "Light1 On"
					-cw2 100 90
					-on1 "nnsShowLighting_Show 1"
					-scl "nnsShowLighting_LightOff"
					nnsShowLighting_Light1;
				radioButtonGrp -nrb 1 -l ""
					-l1 "Light2 On"
					-cw2 100 90
					-on1 "nnsShowLighting_Show 2"
					-scl "nnsShowLighting_LightOff"
					nnsShowLighting_Light2;
				radioButtonGrp -nrb 1 -l ""
					-l1 "Light3 On"
					-cw2 100 90
					-on1 "nnsShowLighting_Show 3"
					-scl "nnsShowLighting_LightOff"
					nnsShowLighting_Light3;
				radioButtonGrp -nrb 1 -l ""
					-l1 "Any Light On"
					-cw2 100 90
					-on1 "nnsShowLighting_Show 16"
					-scl "nnsShowLighting_LightOff"
					nnsShowLighting_LightAny;

				/*
				checkBoxGrp -ncb 1 -l "" -l1 "Lighting" -v1 1
					-cw2 150 100
					-cc "nnsShowLighting_Show(#1)"
					nnsShowLighting_Lighting;
				*/

			setParent ..;	// columnLayout

			checkBoxGrp -ncb 1 -l "" -l1 "Keep Selection" -v1 1
				-cw 1 100
				nnsShowLighting_KeepSelecion;
			button -h 26 -l "Close"
				-c ($remain_cmd + $close_cmd);
		setParent ..;	// columnLayout
	}
	window -e -wh $wd $ht nnsShowLighting_Win;

//-----------------------------------------------------------------------------
// show window
	showWindow nnsShowLighting_Win;
}
