# -*- coding: utf-8 -*-
import mtoa.ui.ae.utils as aeUtils
import pymel.core as pm
from mtoa.ui.ae.shaderTemplate import ShaderAETemplate

class AEaiLightDecayTemplate(ShaderAETemplate):
    def checkNearAtten(self, nodeName):
        fullAttr = '%s.%s'%(nodeName, "use_near_atten")
        rawValue = pm.getAttr(fullAttr)
        
        dim = not rawValue
        pm.editorTemplate(dimControl=(nodeName, "nearStart", dim))
        pm.editorTemplate(dimControl=(nodeName, "nearEnd", dim))

    def checkFarAtten(self, nodeName):
        fullAttr = '%s.%s'%(nodeName, "use_far_atten")
        rawValue = pm.getAttr(fullAttr)
        
        dim = not rawValue
        pm.editorTemplate(dimControl=(nodeName, "farStart", dim))
        pm.editorTemplate(dimControl=(nodeName, "farEnd", dim))

    def setup(self):
        self.addSwatch()
        self.beginScrollLayout()
        
        self.beginLayout('衰减', collapse=False)

        self.addControl('useNearAtten', changeCommand=self.checkNearAtten, label='使用近距衰减')
        self.addControl('nearStart', label='衰减开始')
        self.addControl('nearEnd', label='衰减结束')

        self.addSeparator()
        
        self.addControl('useFarAtten', changeCommand=self.checkFarAtten, label='使用远距衰减')
        self.addControl('farStart', label='衰减开始')
        self.addControl('farEnd', label='衰减结束')
        
        self.endLayout()
        
        pm.mel.AEdependNodeTemplate(self.nodeName)

        self.addExtraControls()
        self.endScrollLayout()

