
import AppFacade from "../AppFacade";
import LayerMgr from "../Manager/LayerMgr";
import UIUtil from "../Util/UIUtil";
import View from "./View";

/**
 * @param 全屏界面
 * 1.需要有Bottom Top Left Right 四个二级节点对齐
 * 2.最高级父节点Size=0,0
 * 3.【应该只有一级界面是Fullview，内曾是Fullview没意义，middle等节点并不会展开】
 */
export default abstract class FullView extends View{
    
    public widget:cc.Widget=null
    public top:cc.Node=null
    public bottom:cc.Node=null
    public left:cc.Node
    public leftTop:cc.Node
    public leftBottom:cc.Node
    public right:cc.Node
    public rightBottom:cc.Node
    public rightTop:cc.Node
    public middle:cc.Node
    public topWidget:cc.Widget=null
    public bottomWidget:cc.Widget=null
    public leftWidget:cc.Widget=null
    public leftTopWidget:cc.Widget
    public leftBottomWidget:cc.Widget
    public rightWidget:cc.Widget=null
    public rightTopWidget:cc.Widget
    public rightBottomWidget:cc.Widget
    public middleWidth:cc.Widget=null

    public abstract getTypeName():string

    protected setLayer(){
        let layer=AppFacade.getMgr(LayerMgr)
        // widget 安装上后，left的值等没有根据父亲更新 
        this.widget=UIUtil.autoFitCanvas(this.node,layer.bangScreenTopOffset())
        this.top=this.getChildNode("Top")
        if(this.top){
            this.top.setContentSize(cc.view.getDesignResolutionSize())
            this.topWidget=this.addCCComp<cc.Widget>(this.top,cc.Widget)
            this.topWidget.isAlignTop=true
        }
        this.bottom=this.getChildNode("Bottom")
        if(this.bottom){
            this.bottom.setContentSize(cc.view.getDesignResolutionSize())
            this.bottomWidget=this.addCCComp<cc.Widget>(this.bottom,cc.Widget)
            this.bottomWidget.isAlignBottom=true
        }
        this.left=this.getChildNode("Left")
        if(this.left){
            this.left.setContentSize(cc.view.getDesignResolutionSize())
            this.leftWidget=this.addCCComp<cc.Widget>(this.left,cc.Widget)
            this.leftWidget.isAlignLeft=true
        }
        this.leftTop=this.getChildNode("LeftTop")
        if(this.leftTop){
            this.leftTop.setContentSize(cc.view.getDesignResolutionSize())
            this.leftTopWidget=this.addCCComp<cc.Widget>(this.leftTop,cc.Widget)
            this.leftTopWidget.isAlignLeft=true
            this.leftTopWidget.isAlignTop=true
        }
        this.leftBottom=this.getChildNode("LeftBottom")
        if(this.leftBottom){
            this.leftBottom.setContentSize(cc.view.getDesignResolutionSize())
            this.leftBottomWidget=this.addCCComp<cc.Widget>(this.leftBottom,cc.Widget)
            this.leftBottomWidget.isAlignLeft=true
            this.leftBottomWidget.isAlignBottom=true
            this.leftBottomWidget.updateAlignment()
        }
        this.right=this.getChildNode("Right")
        if(this.right){
            this.right.setContentSize(cc.view.getDesignResolutionSize())
            this.rightWidget=this.addCCComp<cc.Widget>(this.right,cc.Widget)
            this.rightWidget.isAlignRight=true
        }
        this.rightTop=this.getChildNode("RightTop")
        if(this.rightTop){
            this.rightTop.setContentSize(cc.view.getDesignResolutionSize())
            this.rightTopWidget=this.addCCComp<cc.Widget>(this.rightTop,cc.Widget)
            this.rightTopWidget.isAlignRight=true
            this.rightTopWidget.isAlignTop=true
        }
        this.rightBottom=this.getChildNode("RightBottom")
        if(this.rightBottom){
            this.rightBottom.setContentSize(cc.view.getDesignResolutionSize())
            this.rightBottomWidget=this.addCCComp<cc.Widget>(this.rightBottom,cc.Widget)
            this.rightBottomWidget.isAlignRight=true
            this.rightBottomWidget.isAlignBottom=true
        }
        this.middle=this.getChildNode("Middle")
        if(this.middle){
            this.middleWidth=UIUtil.autoFitCanvas(this.middle)
        }
    }

    protected updateAligment(){
        this.topWidget&&this.topWidget.updateAlignment()
        this.bottomWidget&&this.bottomWidget.updateAlignment()
        this.leftWidget&&this.leftWidget.updateAlignment()
        this.leftTopWidget&&this.leftTopWidget.updateAlignment()
        this.leftBottomWidget&&this.leftBottomWidget.updateAlignment()
        this.rightTopWidget&&this.rightTopWidget.updateAlignment()
        this.rightBottomWidget&&this.rightBottomWidget.updateAlignment()
        this.rightWidget&&this.rightWidget.updateAlignment()
        this.middleWidth&&this.middleWidth.updateAlignment()
    }
}