import UIFullView from "../Core/BaseView/UIFullView";
import { ViewConst } from "../Core/ConstDefine/ViewConst";
import UIButton from "../Core/UI/UIButton";
import GameUtil from "../Core/Util/GameUtil";
import UIUtil from "../Core/Util/UIUtil";
import MenuModel from "./MenuModel";

export default class MenuView extends UIFullView{


    private paint:cc.Node;        //游戏画板
    private resultPaint:cc.Node;  //结束画板
    public paint1:cc.Node;      //游戏色块父节点
    public paint2:cc.Node;      //结束面板色块父节点
    // public palette:cc.Node;      //调色板
    public choiceColor:cc.Node;  //色彩选择框
    public roleAnimation:dragonBones.ArmatureDisplay;//动画角色猫龙骨骼
    public btnSubmit:UIButton  //提交按钮*取消
    public btnColors:UIButton[]   //色彩按钮
    public colorItems1:cc.Node[];    //要涂的色块对象。每个色块为一个节点。对节点进行改色    
    public colorItems2:cc.Node[];    //结束面板色块对象。每个色块为一个节点。对节点进行改色    
    public btnRole:UIButton

    public getTypeName(): string {
        return ViewConst.MenuView;
    }

    protected async getChilds(){
        this.paint=this.getChildNode("main_area/paint");                
        this.paint1=this.getChildNode("main_area/paint/alligator");
        this.paint1.destroyAllChildren();

        // this.colorItems=new Array();
        // for(let i=0;i<colorArea.childrenCount;i++){
        //     let item=colorArea.children[i];
        //     this.colorItems[i]=item;
        // }

        this.resultPaint=this.getChildNode("paint2");
        this.paint2=this.getChildNode("paint2/alligator");
        this.paint2.destroyAllChildren();

        let palette=this.getChildNode("color_area");
        this.choiceColor=this.getChildNode("color_area/icon_choose");
        this.roleAnimation=this.getChildComp("bottom_area/coolcat",dragonBones.ArmatureDisplay);
        this.btnRole=new UIButton();
        this.btnRole.loadViewClone(this.getChildNode("bottom_area/BtnCoolCat"),false);
        this.btnSubmit=new UIButton();
        this.btnSubmit.loadViewClone(this.getChildNode("bottom_area/btn_submit"),false);
        this.btnColors=new Array();
        for(let i=0;i<palette.childrenCount;i++){
            let btn_node=palette.children[i];
            if(btn_node.active){
                let btnColor=new UIButton();
                btnColor.loadViewClone(btn_node,false);
                this.btnColors.push(btnColor);
            }
        }
    }    

    public showPaint2(){
        this.paint.active=false;
        this.resultPaint.active=true;
    }

    protected async onUpdateData(model:MenuModel){
        let images:{img:string}[]=model.getImages();

        let bg1=this.getChildComp("main_area/paint/bg_img",cc.Sprite);
        let bg2=this.getChildComp("paint2/bg_img",cc.Sprite);
        bg1.spriteFrame=await UIUtil.getSpriteByUrl(model.getBG());
        bg2.spriteFrame=await UIUtil.getSpriteByUrl(model.getBG());

        //要涂的色块
        this.colorItems1 = new Array();
        let colorArea1=this.paint1;

        this.colorItems2 = new Array();
        let colorArea2=this.paint2;

        // let gameData=model.getItem(model.stageIdx);        
        // let words=gameData.words.split("");
        // let pos=gameData.pos;

        for (let i = 0; i < images.length; i++) {
            let spriteFrame = await UIUtil.getSpriteByUrl({url:images[i].img})

            let item1=GameUtil.createNode("img"+1,colorArea1);
            item1.group="camera";
            let sprite1:cc.Sprite=this.addCCComp(item1,cc.Sprite);
            sprite1.spriteFrame=spriteFrame;
            // let wordNode1=GameUtil.createNode("word",item1);
            // wordNode1.x= pos[i][0];
            // wordNode1.y=pos[i][1];
            // wordNode1.color=cc.Color.BLACK;
            // let label1:cc.Label=this.addCCComp(wordNode1,cc.Label);
            // label1.string=words[i];
            // label1.font=model.getFont();
            // label1.fontSize=80;
            // label1.lineHeight=80;
            this.colorItems1[i] = sprite1.node;

            let item2=GameUtil.createNode("img"+1,colorArea2);
            item2.group="camera"
            let sprite2:cc.Sprite=this.addCCComp(item2,cc.Sprite);
            sprite2.spriteFrame=spriteFrame;
            // let wordNode2=GameUtil.createNode("word",item2);
            // wordNode2.x=pos[i][0];
            // wordNode2.y=pos[i][1];
            // wordNode2.color=cc.Color.BLACK;
            // let label2:cc.Label=this.addCCComp(wordNode2,cc.Label);
            // label2.string=words[i];
            // label2.font=model.getFont();
            // label2.fontSize=80;
            // label2.lineHeight=80;
            this.colorItems2[i] = sprite2.node;
        }
    }

    protected onOpen(){
    }
    protected onClose(){
    }
}