import Panel from "../views/Panel";
import { GCache } from "../../libs/tc/util/GCache";
import PanelCtrl from "../ctrls/panelCtrl";
import { ModuleTypes } from "../types/sceneTypes";

export default class GuideBuyPanel extends Panel{
    protected get skinKey(){ return 'GuideBuy' }

    public goodsList:eui.Scroller;
    public goodGroup:eui.Group;
    public desk1Group:eui.Group;
    public desk2Group:eui.Group;
    public desk3Group:eui.Group;
    public coffee1Group:eui.Group;
    public coffee2Group:eui.Group;
    public coffee3Group:eui.Group;
    public cash1Group:eui.Group;
    public cash2Group:eui.Group;
    public cash3Group:eui.Group;
    public oven1Group:eui.Group;
    public oven2Group:eui.Group;
    public oven3Group:eui.Group;
    public frige1Group:eui.Group;
    public frige2Group:eui.Group;
    public frige3Group:eui.Group;
    public wait1Group:eui.Group;
    public wait2Group:eui.Group;
    public wait3Group:eui.Group;

    public desk1rihgt:eui.Image;
    public desk2rihgt:eui.Image;
    public desk3rihgt:eui.Image;
    public coffee1rihgt:eui.Image;
    public coffee2rihgt:eui.Image;
    public coffee3rihgt:eui.Image;
    public cash1rihgt:eui.Image;
    public cash2rihgt:eui.Image;
    public cash3rihgt:eui.Image;
    public oven1rihgt:eui.Image;
    public oven2rihgt:eui.Image;
    public oven3rihgt:eui.Image;
    public frige1rihgt:eui.Image;
    public frige2rihgt:eui.Image;
    public frige3rihgt:eui.Image;
    public wait1rihgt:eui.Image;
    public wait2rihgt:eui.Image;
    public wait3rihgt:eui.Image;


    public closeBtn:eui.Button;


    private func1:any;
    private func2:any;
    private func3:any;
    private func4:any;
    private func5:any;
    private func6:any;
    private func7:any;
    private func8:any;
    private func9:any;
    private func10:any;
    private func11:any;
    private func12:any;
    private func13:any;
    private func14:any;
    private func15:any;
    private func16:any;
    private func17:any;
    private func18:any;
    
    
    constructor(data){
        super();
    }

    initUI(data){
        this.desk1rihgt.visible = false;
        this.desk2rihgt.visible = false;
        this.desk3rihgt.visible = false;
        this.coffee1rihgt.visible = false;
        this.coffee2rihgt.visible = false;
        this.coffee3rihgt.visible = false;
        this.cash1rihgt.visible = false;
        this.cash2rihgt.visible = false;
        this.cash3rihgt.visible = false;
        this.oven1rihgt.visible = false;
        this.oven2rihgt.visible = false;
        this.oven3rihgt.visible = false;
        this.frige1rihgt.visible = false;
        this.frige2rihgt.visible = false;
        this.frige3rihgt.visible = false;
        this.wait1rihgt.visible = false;
        this.wait2rihgt.visible = false;
        this.wait3rihgt.visible = false;
        //是否第一次进游戏
        if(data.first){
            


        }else{
            //--have拥有最高1,2,3  --use正在使用1,2,3
            if(data.deskhave){
                if(data.deskhave == 1){
                    this.setColor(this.desk3Group);
                    this.desk3Group.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.func3,this);
                    this.clearTap(this.desk3Group,this.func3);
                    this.desk1rihgt.visible = true;
                }else if(data.deskhave == 2){
                    this.desk2rihgt.visible = true;
                }else if(data.deskhave == 3){
                    this.desk3rihgt.visible = true;
                }

            }else{
                this.setColor(this.desk2Group);
                this.setColor(this.desk3Group);
                this.clearTap(this.desk2Group,this.func2);
                this.clearTap(this.desk3Group,this.func3);
            }

        }


    }

    public setColor(group) {
        let colorMatrix = [
            0.3, 0.3, 0.3, 0, 0,
            0.3, 0.3, 0.3, 0, 0,
            0.3, 0.3, 0.3, 0, 0,
            0, 0, 0, 1, 0
        ];
        let colorFilter = new egret.ColorMatrixFilter(colorMatrix);
    
        group.filters = [colorFilter];
        
    }
    initEvents(){
        super.initEvents();
        this.onTap(this.desk1Group,this.func1);
        this.onTap(this.desk2Group,this.func2);
        this.onTap(this.desk3Group,this.func3);

        this.onTap(this.coffee1Group,this.func4);
        this.onTap(this.coffee2Group,this.func5);
        this.onTap(this.coffee3Group,this.func6);

        this.onTap(this.cash1Group,this.func7);
        this.onTap(this.cash2Group,this.func8);
        this.onTap(this.cash3Group,this.func9);

        this.onTap(this.oven1Group,this.func10);
        this.onTap(this.oven2Group,this.func11);
        this.onTap(this.oven3Group,this.func12);

        this.onTap(this.frige1Group,this.func13);
        this.onTap(this.frige2Group,this.func14);
        this.onTap(this.frige3Group,this.func15);

        this.onTap(this.wait1Group,this.func16);
        this.onTap(this.wait2Group,this.func17);
        this.onTap(this.wait3Group,this.func18);

    }
    bindData(data){
        this.func1 = this.onTap_Message.bind(this,"desk",1,5000);
        this.func2 = this.onTap_Message.bind(this,"desk",2,20000);
        this.func3 = this.onTap_Message.bind(this,"desk",3,50000);
        this.func4 = this.onTap_Message.bind(this,"coffe",1,30000);
        this.func5 = this.onTap_Message.bind(this,"coffe",2,100000);
        this.func6 = this.onTap_Message.bind(this,"coffe",3,300000);
        this.func7 = this.onTap_Message.bind(this,"cash",1,50000);
        this.func8 = this.onTap_Message.bind(this,"cash",2,200000);
        this.func9 = this.onTap_Message.bind(this,"cash",3,500000);
        this.func10 = this.onTap_Message.bind(this,"oven",1,10000);
        this.func11 = this.onTap_Message.bind(this,"oven",2,30000);
        this.func12 = this.onTap_Message.bind(this,"oven",3,100000);
        this.func13 = this.onTap_Message.bind(this,"frige",1,20000);
        this.func14 = this.onTap_Message.bind(this,"frige",2,50000);
        this.func15 = this.onTap_Message.bind(this,"frige",3,200000);
        this.func16 = this.onTap_Message.bind(this,"wait",1,100000);
        this.func17 = this.onTap_Message.bind(this,"wait",2,500000);
        this.func18 = this.onTap_Message.bind(this,"wait",3,1000000);

    }

    onTap_Message(str,num,cost){
        this.hidePanel();
        let data = {name:str,number:num,cost:cost};
        PanelCtrl.instance.show(ModuleTypes.GUIDESURE_PANEL,data);
    }

    removeEvents(){
        super.removeEvents();
        this.clearTap(this.desk1Group,this.func1);
        this.clearTap(this.desk2Group,this.func2);
        this.clearTap(this.desk3Group,this.func3);

        this.clearTap(this.coffee1Group,this.func4);
        this.clearTap(this.coffee2Group,this.func5);
        this.clearTap(this.coffee3Group,this.func6);

        this.clearTap(this.cash1Group,this.func7);
        this.clearTap(this.cash2Group,this.func8);
        this.clearTap(this.cash3Group,this.func9);

        this.clearTap(this.oven1Group,this.func10);
        this.clearTap(this.oven2Group,this.func11);
        this.clearTap(this.oven3Group,this.func12);

        this.clearTap(this.frige1Group,this.func13);
        this.clearTap(this.frige2Group,this.func14);
        this.clearTap(this.frige3Group,this.func15);

        this.clearTap(this.wait1Group,this.func16);
        this.clearTap(this.wait2Group,this.func17);
        this.clearTap(this.wait3Group,this.func18);
    }
}