// Copyright (C) 1997-2004 Alias Systems Corp.
// 
// The information in this file is provided for the exclusive use of the
// licensees of Alias.  Such users have the right to use, modify,
// and incorporate this code into other products for purposes authorized
// by the Alias license agreement, without fee.
// 
// ALIAS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
// INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
// EVENT SHALL ALIAS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
// DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

//
//  Alias Script File
//
//  Creation Date:	May 7, 1997
//
//  Procedure Name:
//	AEspotLightTemplate
//
//  Description:
//	Creates the attribute editor controls for the spotLight Node
//
//  Input Value:
//	nodeName
//
//  Output Value:
//	None
//



//
//  Procedure Name:
//	AEspotLightPreviewPortNew
//
//

global proc AEspotLightPreviewPortNew (string $nodeName, string $coneAngle)
{
	global int $gAENameTextFieldIndex;
	setParent swatchDisplayForm;

	string $lightName[];
	tokenize($coneAngle, ".", $lightName);
	
	text -l "Light Shape" lightEffectText;
	spotLightPreviewPort -wh 64 64 -sl $lightName[0] spotLightPreviewPort1;
	
	formLayout -e 
		-aoc lightEffectText right (-$gAENameTextFieldIndex) swatchLabel
		-af lightEffectText top 0 
		-af lightEffectText bottom 0 
		-an lightEffectText left
		 
		-ac spotLightPreviewPort1 left 5 lightEffectText
		-af spotLightPreviewPort1 top 0
		-af spotLightPreviewPort1 bottom 0
		-an spotLightPreviewPort1 right 
		swatchDisplayForm;
}

//
//  Procedure Name:
//	AEspotLightPreviewPortReplace
//
//

global proc AEspotLightPreviewPortReplace (string $nodeName, string $coneAngle)
{
	string $lightName[];
	tokenize($coneAngle, ".", $lightName);

	spotLightPreviewPort -edit -sl $lightName[0] spotLightPreviewPort1;
}

//
//  Procedure Name:
//	AEspotLightFogNew
//
//

global proc AEspotLightFogNew (string $fogGeometry)
//
// Description:
//		Setup up button that makes fog.
//
{
	setUITemplate -pst attributeEditorTemplate;

	attrNavigationControlGrp -l "Light Fog"
		-at $fogGeometry
		-ignoreNotSupported
		lightFogControl;

	setUITemplate -ppt;
}

//
//  Procedure Name:
//	AEspotLightFogReplace
//
//

global proc AEspotLightFogReplace (string $fogGeometry)
//
// Description:
//		Replace the button with the command to create fog
//		for the new light.
//
{
	attrNavigationControlGrp -edit
		-at $fogGeometry
		-ignoreNotSupported
		lightFogControl;
}

//
//  Procedure Name:
//	AEdecayRegionNew
//
//

global proc AEdecayRegionNew (string $intensity)
//
// Description:
//		Setup up button that makes decay regions.
//
{
	setUITemplate -pst attributeEditorTemplate;
	rowLayout -nc 2;
	    	text -l "Create Intensity Curve";
		button -l "Create" -c ("AEmakeDecayRegion " + $intensity) dr;
		setParent ..;
	setUITemplate -ppt;
}

//
//  Procedure Name:
//	AEdecayRegionReplace
//
//

global proc AEdecayRegionReplace (string $intensity)
//
// Description:
//		Replace the button with the command to create 
//		decay regions for the new light.
//
{
	button -e -c ("AEmakeDecayRegion " + $intensity) dr;
}

//
//  Procedure Name:
//	AEmakeDecayRegion
//
//

global proc AEmakeDecayRegion (string $intensity)
//
// Description:
//		Make a decay region for this light.
//
{
	// get the name of the light.
	string $lightName[];
	tokenize($intensity, ".", $lightName);

	string $newCurve = makeCurve("IntensityCurve");
	string $attr = $newCurve + ".output";

	// connect the param curve to the intensity
	connectAttr $attr $intensity;

	// create a lightInfo node.
	string $lightInfoNode = `createNode lightInfo -n lightInfo`;

	// connect the light to the lightInfo node.	
	$attr = 	$lightName[0] + ".worldMatrix";
	$attr2 = 	$lightInfoNode + ".worldMatrix";
	connectAttr $attr $attr2;

	// connect the lightInfoNode to the curve.
	$attr = 	$lightInfoNode + ".sampleDistance";
	$attr2=		$newCurve + ".input";
	connectAttr $attr $attr2;
}

//
//  Procedure Name:
//	checkUseDecayRegions
//

global proc checkUseDecayRegions ( string $nodeName )
{
	string $nodeAttr = $nodeName + ".useDecayRegions";
	int $value = `getAttr $nodeAttr`;
	
	if ( $value == 1 ) {
		editorTemplate -dimControl $nodeName "startDistance1" false;
		editorTemplate -dimControl $nodeName "endDistance1" false;
		editorTemplate -dimControl $nodeName "startDistance2" false;
		editorTemplate -dimControl $nodeName "endDistance2" false;
		editorTemplate -dimControl $nodeName "startDistance3" false;
		editorTemplate -dimControl $nodeName "endDistance3" false;
	} else {
		editorTemplate -dimControl $nodeName "startDistance1" true;
		editorTemplate -dimControl $nodeName "endDistance1" true;
		editorTemplate -dimControl $nodeName "startDistance2" true;
		editorTemplate -dimControl $nodeName "endDistance2" true;
		editorTemplate -dimControl $nodeName "startDistance3" true;
		editorTemplate -dimControl $nodeName "endDistance3" true;
	}
}


//
//  Procedure Name:
//	checkBarnDoors
//

global proc checkBarnDoors ( string $nodeName )
{
	string $nodeAttr = $nodeName + ".barnDoors";
	int $value = `getAttr $nodeAttr`;
	
	if ( $value == 1 ) {
		editorTemplate -dimControl $nodeName "leftBarnDoor" false;
		editorTemplate -dimControl $nodeName "rightBarnDoor" false;
		editorTemplate -dimControl $nodeName "topBarnDoor" false;
		editorTemplate -dimControl $nodeName "bottomBarnDoor" false;
	} else {
		editorTemplate -dimControl $nodeName "leftBarnDoor" true;
		editorTemplate -dimControl $nodeName "rightBarnDoor" true;
		editorTemplate -dimControl $nodeName "topBarnDoor" true;
		editorTemplate -dimControl $nodeName "bottomBarnDoor" true;
	}
}


//
//  Procedure Name:
//	AEspotLightTemplate
//
//

global proc AEspotLightTemplate ( string $nodeName )
{
	AEswatchDisplay  $nodeName;
	editorTemplate -callCustom ("AEspotLightPreviewPortNew " + $nodeName )
			("AEspotLightPreviewPortReplace " + $nodeName )
			"coneAngle";

editorTemplate -beginScrollLayout;

	editorTemplate -beginLayout "Spot Light Attributes" -collapse 0;
		AElightCommon $nodeName;
		AEnonAmbientLightShapeNodeDecay $nodeName;

		editorTemplate -addControl "coneAngle";
		editorTemplate -addControl "penumbraAngle";
		editorTemplate -addControl "dropoff";
	editorTemplate -endLayout;
		
	editorTemplate -beginLayout "Light Effects";
		editorTemplate -callCustom 
			"AEspotLightFogNew" 
			"AEspotLightFogReplace"
			"fogGeometry";
		editorTemplate -addControl "fogSpread";
		editorTemplate -addControl "fogIntensity";

		editorTemplate -addSeparator;
		AEspotLightEffects $nodeName;

		editorTemplate -addSeparator;
		editorTemplate -addControl "barnDoors" "checkBarnDoors";
		editorTemplate -addControl "leftBarnDoor";
		editorTemplate -addControl "rightBarnDoor";
		editorTemplate -addControl "topBarnDoor";
		editorTemplate -addControl "bottomBarnDoor";

		editorTemplate -beginLayout "Decay Regions";
			editorTemplate -addControl "useDecayRegions" 
						"checkUseDecayRegions";
		
			editorTemplate -beginLayout "Region 1";
				editorTemplate -addControl "startDistance1";
				editorTemplate -addControl "endDistance1";
			editorTemplate -endLayout;
			editorTemplate -beginLayout "Region 2";
				editorTemplate -addControl "startDistance2";
				editorTemplate -addControl "endDistance2";
			editorTemplate -endLayout;
			editorTemplate -beginLayout "Region 3";
				editorTemplate -addControl "startDistance3";
				editorTemplate -addControl "endDistance3";
			editorTemplate -endLayout;
		editorTemplate -endLayout;
	editorTemplate -endLayout;

	editorTemplate -beginLayout "Shadows";
		editorTemplate -addControl "shadowColor";

		// include the depth part of the nonExtendedLightShapeNode
		AEnonExtendedLightShapeDepthMapAttr $nodeName;

		AElightCommonShadow1 $nodeName;
	
		// include the first part of the nonExtendedLightShapeNode
		AEnonExtendedLightShapeShadowAttr $nodeName;
	
		// include the last part of the lightNode
		AElightCommonShadow2 $nodeName;
	editorTemplate -endLayout;

	// mental ray light attributes
	AEmentalraySpotLight $nodeName;

	// include all other inherited attrs
	AEshapeTemplate $nodeName;

	//suppressed attributes
	
		editorTemplate -suppress "objectType";
		editorTemplate -suppress "pointWorld";
		editorTemplate -suppress "farPointWorld";
		editorTemplate -suppress "rayDirection";
		editorTemplate -suppress "fogGeometry";
		editorTemplate -suppress "lightGlow";
		editorTemplate -suppress "lightGlow";
		editorTemplate -suppress "psIllumSamples";
		editorTemplate -suppress "receiveShadows";

editorTemplate -addExtraControls;
editorTemplate -endScrollLayout;
}
