# -*- coding: utf-8 -*-
import pymel.core as pm
import mtoa.ui.ae.lightTemplate as lightTemplate
import mtoa.ui.ae.aiSwatchDisplay as aiSwatchDisplay
import mtoa.ui.ae.templates as templates

class AEaiSkyDomeLightTemplate(lightTemplate.LightTemplate):
    def addSwatch(self):
        self.addCustom("message", aiSwatchDisplay.aiSwatchDisplayNew, aiSwatchDisplay.aiSwatchDisplayReplace)
        
    def makeLightExclusive(self, attr):
        lightName = attr.split(".")[0]
        pm.rowLayout(nc=2, cal=[2, 'left'])
        pm.text(label="")
        pm.exclusiveLightCheckBox('exclusiveButton', light=lightName, label="默认照明")
        pm.setParent('..')
        
    def replaceLightExclusive(self, attr):
        lightName = attr.split(".")[0]
        pm.exclusiveLightCheckBox('exclusiveButton', edit=True, light=lightName)
        
    def setup(self):
        self.addSwatch()
        self.beginScrollLayout()
        
        self.beginLayout('环境光属性', collapse=False)        
        self.addControl('color', label='颜色')
        self.addControl('intensity', label='强度')
        self.addControl('resolution', label='分辨率')
        self.addSeparator()
        self.setupColorTemperature("ArnoldSkyDome")
        self.addCustom("instObjGroups", self.makeLightExclusive, self.replaceLightExclusive)
        self.addSeparator()
        self.addControl('format', label='格式')
        self.addControl('aiExposure', label='曝光')
        self.addControl('aiSamples', label='采样')
        self.addControl('aiNormalize', label='统一化')
        self.addSeparator()
        self.addControl('aiCastShadows', label='投射阴影')
        self.addControl('aiShadowColor', label='阴影颜色')
        self.addSeparator()
        self.addControl('portalMode', label='天空模式')
        self.addSeparator()

        self.commonLightAttributes(addVisibility = True)
        self.endLayout()
        
        self.beginLayout('硬件纹理', collapse=True)
        self.addControl('sampling', label='纹理分辨率')
        self.addControl('hwtexalpha', label='不透明度')
        self.endLayout()
        
        self.beginLayout('窗口', collapse=True)
        self.addControl('skyRadius', label='天空半径')
        self.addControl('skyFacing', label='朝向')
        self.endLayout()

        # Do not show extra attributes
        extras = ["visibility",
                  "intermediateObject",
                  "template",
                  "ghosting",
                  "instObjGroups",
                  "useObjectColor",
                  "objectColor",
                  "drawOverride",
                  "lodVisibility",
                  "renderInfo",
                  "renderLayerInfo",
                  "ghostingControl",
                  "ghostCustomSteps",
                  "ghostFrames",
                  "ghostRangeStart",
                  "ghostRangeEnd",
                  "ghostDriver",
                  "ghostColorPreA",
                  "ghostColorPre",
                  "ghostColorPostA",
                  "ghostColorPost",
                  "motionBlur",
                  "visibleInReflections",
                  "visibleInRefractions",
                  "castsShadows",
                  "receiveShadows",
                  "maxVisibilitySamplesOverride",
                  "maxVisibilitySamples",
                  "geometryAntialiasingOverride",
                  "antialiasingLevel",
                  "shadingSamplesOverride",
                  "shadingSamples",
                  "maxShadingSamples",
                  "volumeSamplesOverride",
                  "volumeSamples",
                  "depthJitter",
                  "ignoreSelfShadowing",
                  "primaryVisibility",
                  "compInstObjGroups",
                  "localPosition",
                  "localScale"]

        for extra in extras:
            self.suppress(extra)
        
        pm.mel.AEdependNodeTemplate(self.nodeName)

        self.addExtraControls()
        self.endScrollLayout()

