window.task = {

    taskPrefab: [
        "prefab/taskPrefab",
        "prefab/taskPrefabfinger",
        "prefab/taskPrefabLuckInfo",
        "prefab/taskPrefabEveyDay",
        "prefab/taskPrefabreturn",
        "prefab/taskPrefabAdministration",
        "prefab/taskPrefabBuilding",
        "prefab/taskPrefabEnd",
    ],


    sharePrefab: [
        "prefab/share",
        "prefab/sharepublic",
    ],

    returnPrefab: [
        "prefab/taskPrefabreturnLuck",
        "prefab/taskPrefabreturnEveyDay",
        "prefab/taskPrefabreturnAdministration",
        "prefab/taskPrefabreturnBuilding",
    ],
    //建筑物的那个新手教学
    novice: [
        "prefab/taskPrefabnovice1",
        "prefab/taskPrefabnovice2",
        "prefab/taskPrefabnovice3",
        "prefab/taskPrefabnovice4",
    ],

    taskCursorName: [
        //提示 去点击转盘 的dialog
        "taskCursor1",
        //场景转盘按钮 上面的提示光圈
        "taskCursor2",
        //提示去点签到
        "taskCursor3",
        //提示去点签到
        "taskCursor4",
        //提示去点签到
        "taskCursor5",

    ],


    newTaskName: [
        //0黑背景0
        "prefab/taskPrefabAgb",
        //1欢迎来到《首富小镇》
        "prefab/taskPrefabStart",
        //2您新招聘的员工已经到位了
        "prefab/taskPrefabbuy",
        //3 5块钱买地
        "prefab/taskPrefabbuyBuyinggrain",
        //4
        "prefab/taskPrefabbuyBuyinggrainwait",
        //5每一个员工都需要有个休息的地方来回复体力
        "prefab/task/taskPrefab1",
        //6多开坑土地初期是一个赚钱的好办法
        "prefab/task/taskPrefab2",
        //7种下农田后
        "prefab/task/taskPrefab3",
        //8 哎呀！好像赚钱的速度好慢啊！这样什么时候可以成为《首富》
        "prefab/task/taskPrefab4",
        //9 再盖一个农舍吧
        "prefab/task/taskPrefabFarmhouse",
        //10 地里面有钻石
        "prefab/task/taskPrefab5",
        //11 收钻石 之后的提示
        "prefab/task/taskPrefab6",
        //12 去每日签到
        "prefab/task/taskPrefab7",
        //13 欢乐大转盘，抽奖抽到手软。
        "prefab/task/taskPrefab8",
        //14 先完成一个小目标 存款50W
        "prefab/task/taskPrefab9",
        //15 恭喜您的财富累计到达50W
        "prefab/task/taskPrefab10",
        //16 有了加工厂后，我们试试开出您的第一个商店
        "prefab/task/taskPrefab11",
        //17 有了加工厂后，我们试试开出您的第一个商店
        "prefab/task/taskPrefab12",
        //18 有了加工厂后，我们试试开出您的第一个商店
        "prefab/task/taskPrefab13",
        //19
        "prefab/task/taskPrefabVideo",

    ],
    //农舍  农田 的 虚影
    TiledTile: [
        "prefab/taskPrefabTiledTileFarmhouse",
        "prefab/taskPrefabTiledTileFarmland",
    ],

    //必须建造在虚影上面
    //如果为true 的话，就是进入虚影建造状态
    isMushBuildState: false,
    //虚影所在的位置
    virtualShadowPos: null,
    //虚影所在的位置的终点坐标
    virtualShadowPosEnd: null,

    TaskIconCount: [
        "prefab/taskPrefabTiledTileFarmhouse",
    ],

    itemPrefab: [
        "prefab/item/taskPrefabItem0",
        "prefab/item/taskPrefabItem1",
        "prefab/item/taskPrefabItemFarmhouse",
        "prefab/item/taskPrefabItem2",
        "prefab/item/taskPrefabItem3",
        "prefab/item/taskPrefabItem4",
        "prefab/item/taskPrefabItem5",
        "prefab/item/taskPrefabItem6",
        "prefab/item/taskPrefabItem7",
        "prefab/item/taskPrefabItem8",
        "prefab/item/taskPrefabItem9",
        "prefab/item/taskPrefabItem10",
        "prefab/item/taskPrefabItemShare",
    ],
    publicGive: [
        //种下田地
        200,
    ],

    managerUi: null,

    //农田人物购买，只能触发一次
    taskGotoBuyOnly: false,

    // LIFE-CYCLE CALLBACKS:

    taskOnLoad() {
        this._init();
        //点钻石 之后的进入限定
        this.taskZSTag = false;
        this.taskCount = 0;
        this.taskCursor = this.taskCount;
        this.taskNodes = [];
        task.setOnClickTaskIcon(function () {
            task.showtaskPrefabView(task.taskCallBack);
        }.bind(this));


    },
    taskOnLoadno() {

        this.taskNodes = [];
        task.setOnClickTaskIcon(function () {
            task.showtaskPrefabView(task.taskCallBack);
        }.bind(this));

    },

    _init: function () {
        this.Canvas = cc.find("Canvas/UICamera");
        //管理建造 股市 转盘 什么的父类
        this.BelowTheMask = cc.find("Canvas/UICamera/BelowTheMask/TopButton");

        //外面管理的node
        this.personnelview = cc.find("Canvas/UICamera/BelowTheMask/BottomButton/personnel");
        //外面建造的node
        this.Buildingview = cc.find("Canvas/UICamera/BelowTheMask/BottomButton/Building");
        //外面股市的node
        this.EquityMarketview = cc.find("Canvas/UICamera/BelowTheMask/TopButton/EquityMarket");
        //外面转盘的node
        this.LuckDrawview = cc.find("Canvas/UICamera/BelowTheMask/TopButton/LuckDraw");
        //外面签到的node
        this.EveryDaySignview = cc.find("Canvas/UICamera/BelowTheMask/TopButton/EveryDaySign");

        //人才管理里面的招聘按钮
        this.RecruitButton = cc.find("Canvas/UICamera/PersonnelContainer/PersonnelView/WorkerASaleManage/Worker/Recruit/RecruitBtn");

        //里面的 住宅
        this.Env = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/Menu/Env");
        //里面的 劳动
        this.Labour = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/Menu/Labour");
        //里面的 商铺
        this.Shop = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/Menu/Shop");
        //里面的 特殊
        this.SpeBuilding = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/Menu/SpeBuilding");

        //todo 住宅
        //建造里面的农舍1
        this.Farmhouse = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/EnvContent/Farmhouse");
        //建造里面的农舍2
        this.Apartment = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/EnvContent/Apartment");
        //建造里面的农舍3
        this.Villa = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/EnvContent/Villa");
        //建造里面的道路
        this.Road = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/EnvContent/Road");
        //建造里面的铲子
        this.Shovel = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/EnvContent/Shovel");
        //建造里面的拆迁
        this.Hammer = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/EnvContent/Hammer");

        //todo 劳动
        //农田
        this.FamerLand = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/LabourContent/FamerLand");
        //树木
        this.LoggingYard = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/LabourContent/LoggingYard");
        //矿石
        this.MineField = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/LabourContent/MineField");
        //加工厂
        this.Factory = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/LabourContent/Factory");

        //todo 商铺
        //shop 1
        this.ConvenienceStore = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/ShopContent/ConvenienceStore");
        //shop 2
        this.FlowerShop = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/ShopContent/FlowerShop");
        //shop 3
        this.DessertShop = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/ShopContent/DessertShop");
        //shop 4
        this.FastFoodShop = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/ShopContent/FastFoodShop");
        //shop 5
        this.CoffeeShop = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/ShopContent/CoffeeShop");
        //shop 6
        this.DressShop = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/ShopContent/DressShop");
        //shop 7
        this.Bar = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/ShopContent/Bar");

        //todo 特殊
        //樱花树
        this.GreenBelt = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/SpeBuildingContent/GreenBelt");
        //喷泉
        this.Fountain = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/SpeBuildingContent/Fountain");
        //游乐场
        this.Playground = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/SpeBuildingContent/Playground");
        //医院
        this.Hospital = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/SpeBuildingContent/Hospital");
        //警察局
        this.PoliceOffice = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/SpeBuildingContent/PoliceOffice");
        //警察局
        this.Bank = cc.find("Canvas/UICamera/BuildingContainer/BuildingView/ScrollContent/view/content/SpeBuildingContent/Bank");


        this.ManagerViews = [];
        //0
        this.ManagerViews.push(this.personnelview);
        this.ManagerViews.push(this.Buildingview);
        this.ManagerViews.push(this.EquityMarketview);
        this.ManagerViews.push(this.LuckDrawview);
        this.ManagerViews.push(this.EveryDaySignview);
        //5
        this.ManagerViews.push(this.Env);
        this.ManagerViews.push(this.Labour);
        this.ManagerViews.push(this.Shop);
        this.ManagerViews.push(this.SpeBuilding);

        //住宅
        //9
        this.ManagerViews.push(this.Farmhouse);
        //10
        this.ManagerViews.push(this.Apartment);
        //11
        this.ManagerViews.push(this.Villa);
        //12
        this.ManagerViews.push(this.Road);
        //13
        this.ManagerViews.push(this.Shovel);
        //14
        this.ManagerViews.push(this.Hammer);

        //劳动
        //15 农舍
        this.ManagerViews.push(this.FamerLand);
        //16
        this.ManagerViews.push(this.LoggingYard);
        //17
        this.ManagerViews.push(this.MineField);
        //18
        this.ManagerViews.push(this.Factory);

        //商店
        //19
        this.ManagerViews.push(this.ConvenienceStore);
        //20
        this.ManagerViews.push(this.FlowerShop);
        //21
        this.ManagerViews.push(this.DessertShop);
        //22
        this.ManagerViews.push(this.FastFoodShop);
        //23
        this.ManagerViews.push(this.CoffeeShop);
        //24
        this.ManagerViews.push(this.DressShop);
        //25
        this.ManagerViews.push(this.Bar);


        //特殊
        //26 绿化带
        this.ManagerViews.push(this.GreenBelt);
        //27
        this.ManagerViews.push(this.Fountain);
        //28
        this.ManagerViews.push(this.Playground);
        //29
        this.ManagerViews.push(this.Hospital);
        //30
        this.ManagerViews.push(this.PoliceOffice);
        //31
        this.ManagerViews.push(this.Bank);

        this.taskTags = false;

        this.sharetime = 2000;
        this.addTaskCountClicktime = 2000;
    },


    //显示手
    showPointer: function (type, x, y, sc) {

        var s = 1;
        if (sc != null) {
            s = sc;
        }
        var height = this.ManagerViews[type].height / 2;
        var width = this.ManagerViews[type].width / 2;
        if (this.showPointerNode == null) {
            this.addTaskTipsNoArr(this.ManagerViews[type], task.taskPrefab[1], x, y, this.ManagerViews[type].name, function (nodePrefabs) {
                nodePrefabs.parent = this.ManagerViews[type];
                this.showPointerNode = nodePrefabs;
                this.showPointerNode.active = true;
                this.showPointerNode.scale = s;
                this.showPointerNode.x = x;
                this.showPointerNode.y = y;
                this.showPointerNode.y -= height - 30;
                this.showPointerNode.x += width - 30;
            }.bind(this));
        } else {
            this.showPointerNode.parent = this.ManagerViews[type];
            this.showPointerNode.active = true;
            this.showPointerNode.scale = s;
            this.showPointerNode.x = x;
            this.showPointerNode.y = y;
            this.showPointerNode.y -= height - 30;
            this.showPointerNode.x += width - 30;
        }
        // console.log("现在里面的数据是",this.showPointerNode);
    },
    //隐藏 手
    hidePointer: function () {
        if (this.showPointerNode != null) {
            this.showPointerNode.active = false;
        }
    },

    //重置一下建造的虚影的初始参数
    onShadowArchitectureReset() {
        task.isMushBuildState = false;
        task.virtualShadowPos = null;
        task.virtualShadowPosEnd = null;
    },
    //260,-860
    //可以显示虚影建筑提示
    showTiledTile: function (type, myx, myy, x, y) {

        task.isMushBuildState = true;
        task.virtualShadowPos = cc.v2(x + 1, y + 1);

        var MyMapNode = cc.find("Canvas/MyMapNode");

        //移动camera 对应位置
        cc.find('GameNode/ManageTask').getComponent('ManageTask').onMoveToTiledTile(x, y);
        //引导 农舍
        task.addTaskTips(MyMapNode, task.TiledTile[type], myx, myy, task.taskCursorName[4], function (nodePrefabs1) {
            // console.log("现在里面的数据是", nodePrefabs1);
            // var nodePrefabss = UtilsPrefabs.getNode("nodes", nodePrefabs1);
            var TiledTile = nodePrefabs1.getComponent("TiledTile");
            TiledTile.setTiledTilePos(x, y);
        }.bind(this));
    },


    showManagerhide: function () {
        this.removeTaskNodes();
    },

    //点击任务按钮时候，显示 任务列表
    showtaskPrefabView: function (onclick) {

        if (task.TaskIconCountClick >= 13) {
            task.SeneceTaskIconNode
                .getChildByName("SureBtn")
                .getChildByName("redtips").active = false;
            return;
        }
        this.addTaskTips(this.Canvas, "prefab/taskPrefabView", 0, 0, "taskPrefabView", function (nodePrefabs) {
            this.taskPrefabView = nodePrefabs;
            // 任务条目
            this.addItemtaskView(this.TaskIconCountClick, onclick);
            UtilsPrefabs.setOn(nodePrefabs.getChildByName("close"), function () {
                this.hidetaskPrefabView();
            }.bind(this))
        }.bind(this));
    },


    //任务按钮调用
    taskCallBack: function () {

        console.log('taskCallBack:', task.TaskIconCountClick);

        if (task.TaskIconCountClick == -1) {

            task._setTaskCount(0);
            //开始任务教程
            dialogmanager.init(task.Canvas, function () {
                dialogmanager.Buildingdormitory1();
            }.bind(this));
            dialogmanager.setOnCloseDialog(function () {
                // task.CreatorBtnHelp();
                // task.tasksstartBuildingview();
                //建造农舍
                task.showTiledTile(0, 0, 0, 17, 19);
                task.onTaskBuildAHouseMask();
            }.bind(this));

        } else if (task.TaskIconCountClick == 0) {

            dialogmanager.init(task.Canvas, function () {
                dialogmanager.creatorFarming();
            }.bind(this));
            dialogmanager.setOnCloseDialog(function () {
                //创建 农田 引导 去点建造
                task.showManagerhide();
                task.showTiledTile(1, 0, -50, 18, 17);
                task.onTaskFarmlandMask();
            }.bind(this));

        } else if (task.TaskIconCountClick == 1) {
            //去点管理 外部手提示
            dialogmanager.init(task.Canvas, function () {
                console.log('Recruit1');
                dialogmanager.Recruit();
            }.bind(this));
            dialogmanager.setOnCloseDialog(function () {
                console.log('Recruit');
                let _taskNodes = [];
                _taskNodes.push(task.personnelview);
                _taskNodes.push(task.RecruitButton);
                task.onInitTaskMask(_taskNodes);
            }.bind(this));

        } else if (task.TaskIconCountClick == 2) {
            dialogmanager.init(task.Canvas, function () {
                dialogmanager.Buildingdormitorytoo();
            }.bind(this));
            dialogmanager.setOnCloseDialog(function () {
                task.tasksstartBuildingview();
            }.bind(this));

        } else if (task.TaskIconCountClick == 3) {
            dialogmanager.init(task.Canvas, function () {
                dialogmanager.getDiamonds();
            }.bind(this));
            dialogmanager.setOnCloseDialog(function () {
            }.bind(this));
        } else if (task.TaskIconCountClick == 4) {
            //去点每日签到 外部手提示
            dialogmanager.init(task.Canvas, function () {
                dialogmanager.EveryDay();
            }.bind(this));
            dialogmanager.setOnCloseDialog(function () {
                task.tasksEveryDaySignview();
            }.bind(this));

        } else if (task.TaskIconCountClick == 5) {
            //去点转盘 的外部 手 提示
            dialogmanager.init(task.Canvas, function () {
                dialogmanager.goodluck();
            }.bind(this));
            dialogmanager.setOnCloseDialog(function () {
                task.tasksLuckDrawview();
            }.bind(this));

        } else if (task.TaskIconCountClick == 6) {
            dialogmanager.init(task.Canvas, function () {
                dialogmanager.get3K();
            }.bind(this));

        } else if (task.TaskIconCountClick == 7) {
            //创建一个加工厂
            dialogmanager.init(task.Canvas, function () {
                dialogmanager.creatorProcessingfactory();
            }.bind(this));
            dialogmanager.setOnCloseDialog(function () {
                // task.tasksBuildingview();
            }.bind(this));

        } else if (task.TaskIconCountClick == 8) {
            //创建一个便利店
            dialogmanager.init(task.Canvas, function () {
                dialogmanager.creatorShop();
            }.bind(this));
            dialogmanager.setOnCloseDialog(function () {
                // task.tasksBuildingview();
            }.bind(this));

        } else if (task.TaskIconCountClick == 9) {
            //创建一个绿化带
            dialogmanager.init(task.Canvas, function () {
                dialogmanager.creatorGreen();
            }.bind(this));
            dialogmanager.setOnCloseDialog(function () {
                // task.tasksBuildingview();
            }.bind(this));

        } else if (task.TaskIconCountClick == 10) {

            dialogmanager.init(task.Canvas, function () {
                dialogmanager.pave();
                // task.setListView(18);
            }.bind(this));
            dialogmanager.setOnCloseDialog(function () {
                task.showManagerhide();
                cc.loader.loadRes("prefab/taskPrefabTiledTileHighway", function (err, texture) {
                    let _taskMask = cc.instantiate(texture);

                    //添加进控制数组
                    task.pushTaskNodes(_taskMask);
                    //设置生成遮罩的节点
                    _taskMask.parent = cc.find('Canvas/MyMapNode');
                    let _tiled = GlobalD.TiledMap._tilePosFromLocation(_taskMask.getPosition());
                    //移动camera 对应位置
                    cc.find('GameNode/ManageTask').getComponent('ManageTask').onMoveToTiledTile(_tiled.x, _tiled.y);

                    task.isMushBuildState = true;
                    task.virtualShadowPos = cc.v2(_tiled.x, _tiled.y);

                    let _taskNodes = [];
                    _taskNodes.push(task.Buildingview);
                    _taskNodes.push(task.Road);
                    task.onInitTaskMask(_taskNodes);

                }.bind(this));
            }.bind(this));
        } else if (task.TaskIconCountClick == 12) {
            //最后分享任务
            dialogmanager.init(task.Canvas, function () {
                dialogmanager.Share1();
                // task.SeneceTaskIconNode
                //     .getChildByName("SureBtn")
                //     .getChildByName("redtips").active = false;

            }.bind(this));
            dialogmanager.setOnCloseDialog(function () {
                task._setTaskIconCountClick(13);
                setTimeout(() => {
                    task.taskCallBack();
                }, 500);
                // UtilsPrefabs.startSharePrefab(function () {
                //     task._setTaskIconCountClick(14);
                //     setTimeout(() => {
                //         task.taskCallBack();
                //     }, 500);
                // }.bind(this), function () {
                //     // task._setTaskIconCountClick(13);
                //     task._setTaskIconCountClick(14);
                //     setTimeout(() => {
                //         task.taskCallBack();
                //     }, 500);
                // }.bind(this));
            }.bind(this));
        } else if (task.TaskIconCountClick == 13) {
            //商人去农田购买，新手任务最后一步  todo...
            task._setTaskCount(2);

        } else if (task.TaskIconCountClick == 14) {
            //结束任务调用
            task.onSetTaskEnd();

        }

    },


    onSetTaskEnd() {
        if (task.SeneceTaskIconNode)
            task.SeneceTaskIconNode.getChildByName("SureBtn").getChildByName("redtips").active = false;
        //农田购买
        if (task.TaskIconCountClick < 13) {
            task.TaskIconCountClick = 13;
            return;
        }

        //如果是商人部分，直接设置结束
        //没有任务
        task.taskCursor = -1;
        //跳过教程的时候，设置商人为最后一步
        task.TaskIconCountClick = 14
        task.onShadowArchitectureReset();
    },
    //农田模板
    onTaskFarmlandMask() {
        let _taskNodes = [];
        _taskNodes.push(task.Buildingview);
        _taskNodes.push(task.Labour);
        _taskNodes.push(task.FamerLand);
        task.onInitTaskMask(_taskNodes);
    },
    //农舍模板
    onTaskBuildAHouseMask() {
        let _taskNodes = [];
        _taskNodes.push(task.Buildingview);
        _taskNodes.push(task.Farmhouse);
        task.onInitTaskMask(_taskNodes);
    },
    //铺路模板
    onTaskPaveRoadsMask() {

        let _taskMask = task.getTaskNode('taskPrefabTiledTileHighway');

        if (!_taskMask || !task.isMushBuildState) return;

        let _tiled = GlobalD.TiledMap._tilePosFromLocation(_taskMask.getPosition());
        //移动camera 对应位置
        cc.find('GameNode/ManageTask').getComponent('ManageTask').onMoveToTiledTile(_tiled.x, _tiled.y);

        task.isMushBuildState = true;
        task.virtualShadowPos = cc.v2(_tiled.x, _tiled.y);

        let _taskNodes = [];
        _taskNodes.push(task.Buildingview);
        _taskNodes.push(task.Road);
        task.onInitTaskMask(_taskNodes);

    },

    setListView: function (num) {
        task.addTaskTips(this.Canvas, task.newTaskName[num], 0, 0, task.taskCursorName[0], function (nodePrefabs) {
            // console.log("是什么呢",nodePrefabs);
            this.ListView = nodePrefabs;
            this.addListView();

        }.bind(this));
    },

    addListView: function (ListView, callback) {
        var nodePrefabs = null;
        if (ListView != null) {
            nodePrefabs = ListView;
        } else {
            nodePrefabs = this.ListView;
        }

        var count = 0;

        this.layout = nodePrefabs.getChildByName("layout");

        // console.log("是什么呢", nodePrefabs);
        for (var i = 0; i < this.layout.children.length; i++) {
            var children = this.layout.children[i];
            children.active = false;
        }

        this.layout.children[count].active = true;
        // console.log("是什么呢",this.layout.children[count]);

        //黑底
        // this.nodePrefabsbg = nodePrefabs;
        UtilsPrefabs.setOn(nodePrefabs.getChildByName("SureBtn"), function () {
            count++;
            if (this.layout.children[count] == null) {
                if (callback != null) {
                    callback();
                } else {
                    task.removeTaskNode(task.taskCursorName[0]);
                    this.startSharePrefab();
                }

                return;
            }

            for (var i = 0; i < this.layout.children.length; i++) {
                var children = this.layout.children[i];
                children.active = false;
            }
            this.layout.children[count].active = true;
            this.layout.children[count].getChildByName("curr").getComponent(cc.Label).string = "(" + (count + 1) + '/' + this.layout.children.length + ")";

        }.bind(this))
    },

    //显示 任务View
    hidetaskPrefabView: function () {
        this.removeNode(this.taskPrefabView);
    },

    addItemtaskView: function (num, onclick) {
        this.addTaskTips(this.taskPrefabView, this.itemPrefab[num], 0, 130, "taskPrefabItem", function (nodePrefabs) {
            // console.log("条目",nodePrefabs);
            var guideview = UtilsPrefabs.getNode("guideview", nodePrefabs);
            var guide = UtilsPrefabs.getNode("guide", guideview);
            UtilsPrefabs.setOn(guide, function () {
                // console.log("数组是很么",nodePrefabs);
                this.hidetaskPrefabView();
                if (onclick != null) {
                    onclick(nodePrefabs);
                }
            }.bind(this))
        }.bind(this));
    },


    //页面上增加任务按钮
    addSeneceTaskIcon: function (callback) {

        if (callback)
            callback();
        return;
        this.addTaskTipsNoArr(this.BelowTheMask, "prefab/SeneceTaskIcon", 279, 271, "SeneceTaskIcon", function (nodePrefabs) {
            this.SeneceTaskIconNode = nodePrefabs;
            nodePrefabs.parent = this.BelowTheMask;

            //如果没有任务，去掉提示
            if (task.TaskIconCountClick >= 13) {
                this.SeneceTaskIconNode
                    .getChildByName("SureBtn")
                    .getChildByName("redtips").active = false;
            }

            UtilsPrefabs.setOn(nodePrefabs.getChildByName("SureBtn"), function () {
                // console.log("调用了么",this.BelowTheMask);
                if (this.onClickTaskIcon != null) {
                    this.onClickTaskIcon(this.SeneceTaskIconNode);
                }

            }.bind(this));
            if (callback)
                callback();

        }.bind(this));

    },

    //点击了 任务按钮
    setOnClickTaskIcon: function (onClickTaskIcon) {
        this.onClickTaskIcon = onClickTaskIcon;
    },
    onClickTaskIcon: function () {

    },

    addTaskTips: function (node, PrefabsName, x, y, name, callback) {
        var _x = 0;
        var _y = 0;
        if (x != null) {
            _x = x;
        }
        if (y != null) {
            _y = y;
        }
        UtilsPrefabs
            .init(node)
            .addPrefabs(PrefabsName, null, function (nodePrefabs) {
                if (name != null) {
                    nodePrefabs.name = name;
                }
                nodePrefabs.x = _x;
                nodePrefabs.y = _y;

                this.pushTaskNodes(nodePrefabs);

                if (callback != null) {
                    callback(nodePrefabs);
                }

            }.bind(this));
    },
    addTaskTipsNoArr: function (node, PrefabsName, x, y, name, callback) {
        var _x = 0;
        var _y = 0;
        if (x != null) {
            _x = x;
        }
        if (y != null) {
            _y = y;
        }
        UtilsPrefabs
            .init(node)
            .addPrefabs(PrefabsName, null, function (nodePrefabs) {
                if (name != null) {
                    nodePrefabs.name = name;
                }
                nodePrefabs.x = _x;
                nodePrefabs.y = _y;


                if (callback != null) {
                    callback(nodePrefabs);
                }

            }.bind(this));
    },
    addTaskCount: function () {
        //0 提示 需要 去点 转盘
        //1 提示转盘 外框
        //2 删除手 和 提示转盘 外框
        this.taskCount++;
        this.taskCursor = this.taskCount;
    },
    //直接设置人物点
    _setTaskCount(num) {
        this.taskCount = num;
        this.taskCursor = this.taskCount;
    },

    //任务 增加索引
    addTaskIconCountClick: function () {
        //0 提示 需要 去点 转盘
        //1 提示转盘 外框
        //2 删除手 和 提示转盘 外框
        this.TaskIconCountClick++;
        cc.sys.localStorage.setItem('TaskIconCountClick', this.TaskIconCountClick);
        task.hidePointer();

        if (this.TaskIconCountClick != 4
            || this.TaskIconCountClick != 5
        ) {
            task.showtaskPrefabView(task.taskCallBack);
        }
        switch (this.TaskIconCountClick) {
            case 4:
                this.EveryDaySignview.active = true;
                break;
        }
    },

    _setTaskIconCountClick(num) {
        this.TaskIconCountClick = num;
        cc.sys.localStorage.setItem('TaskIconCountClick', this.TaskIconCountClick);
        // task.hidePointer();
        // if (this.TaskIconCountClick != 4 || this.TaskIconCountClick != 5) {
        //     task.showtaskPrefabView(task.taskCallBack);
        // }

        if (this.TaskIconCountClick == 4) {
            this.EveryDaySignview.active = true;
        }

    },
    pushTaskNodes: function (node) {
        if (node != null) {
            // console.log("數組",task);
            this.taskNodes.push(node)
        }
    },
    removeTaskNodes: function () {
        for (var i = 0; i < this.taskNodes.length; i++) {
            if (cc.isValid(this.taskNodes[i])) {
                this.taskNodes[i].destroy();
            }
        }


        this.taskNodes = [];

    },
    removeTaskNode: function (name) {
        for (var i = 0; i < this.taskNodes.length; i++) {
            if (this.taskNodes[i].name == name) {
                if (cc.isValid(this.taskNodes[i])) {
                    this.taskNodes[i].destroy();
                }
            }
        }
    },
    getTaskNode(name) {
        for (var i = 0; i < this.taskNodes.length; i++) {
            if (this.taskNodes[i].name == name) {
                if (cc.isValid(this.taskNodes[i])) {
                    return this.taskNodes[i];
                }
            }
        }
    },
    removeNode: function (node) {
        if (node != null) {
            node.destroy();

        }
    },
    isShowTaskNode: function (name, b) {
        if (this.taskNodes.length <= 0) return;
        for (var i = 0; i < this.taskNodes.length; i++) {
            if (this.taskNodes[i].name == name) {
                this.taskNodes[i].active = b;
            }

        }
    },
    // 公用 提示框
    tipsNode: function (num, x, y, callback) {
        var _x = 0;
        var _y = 0;

        if (x != null) {
            _x = x;
        }
        if (y != null) {
            _y = y;
        }
        task.removeTaskNode(task.taskCursorName[0]);
        task.addTaskTips(this.Canvas, task.newTaskName[num], _x, _y, task.taskCursorName[0], function (nodePrefabs) {
            // console.log("是什么呢",nodePrefabs);

            //黑底
            // this.nodePrefabsbg = nodePrefabs;
            UtilsPrefabs.setOn(nodePrefabs.getChildByName("SureBtn"), function () {

                task.removeTaskNode(task.taskCursorName[0]);

                if (callback != null) {
                    callback(nodePrefabs);
                }

            }.bind(this))
        }.bind(this));
    },

    // 万元户 50W
    task50W: function () {
        //50W 万元户任务
        if (task.TaskIconCountClick == 6) {
            if (this.task50wtag == null) {
                if (GlobalD.GameData.Golden >= 3000) {
                    this.task50wtag = true;
                    let Index = 9
                    var BuildingStateArray = GlobalD.GameData.GetBuildingStateArray();
                    BuildingStateArray[Index] = 1;
                    let Building = this.managerUi.getComponent('ManageBuildings').BuildingArray[Index];
                    Building.active = true;
                    GlobalD.GameData.SetBuildingStateArray(BuildingStateArray);
                    this.startSharePrefab(function (node) {
                    }.bind(this));
                }
            }

        }
    },
    //弹出分享对话框
    startSharePrefab: function (callbackNode) {
        this.taskTags = false;

        UtilsPrefabs.startSharePrefab(function () {
            this.addTaskIconCountClick();
        }.bind(this), function () {
            this.addTaskIconCountClick();
        }.bind(this), function (node) {
            var anim = node.getComponent(cc.Animation);
            anim.play();
            var arr2 = [
                "SharePic",
                "Recruit",
                "Ribbon-cutting",
            ];
            //招聘
            if (this.TaskIconCountClick == 1) {
                node.getChildByName("SharePicBG").getChildByName(arr2[1]).zIndex = 10000;
                node.getChildByName("LittleTitleLabel").getComponent(cc.Label).string = "恭喜你又获得一名新员工！快邀请好友来帮忙审核！";
                node.getChildByName("gosharebtn").getChildByName("Btn_Share_Recruit").zIndex = 10000;
            }
            //获得房屋
            //恭喜获得幸运奖励！离首富又近了一步！
            else if (this.TaskIconCountClick == 2) {
                node.getChildByName("SharePicBG").getChildByName(arr2[0]).zIndex = 10000;
                node.getChildByName("LittleTitleLabel").getComponent(cc.Label).string = "乔迁之喜！让朋友来参观一下吧！";
                node.getChildByName("gosharebtn").getChildByName("Btn_Share_Other").zIndex = 10000;
            }
            //商店开业
            else if (this.TaskIconCountClick == 8) {

                node.getChildByName("SharePicBG").getChildByName(arr2[2]).zIndex = 10000;
                node.getChildByName("LittleTitleLabel").getComponent(cc.Label).string = "新店开张！快邀请好友一起来剪彩吧！";
                node.getChildByName("gosharebtn").getChildByName("Btn_Share_Cutting").zIndex = 10000;
            }

        }.bind(this));
    },


    taskShowBuildingView: function () {
        if (task.TaskIconCountClick == 7) {
            var BuildingView = cc.find("Canvas/UICamera/BuildingContainer/BuildingView");
            if (this.nodeHand != null) {
                task.removeNode(this.nodeHand)
            }
            task.addTaskTips(BuildingView, task.taskPrefab[1], -100, 350, task.taskCursorName[2], function (nodePrefabs) {
                //手指
                this.nodeHand = nodePrefabs;
            }.bind(this));
        }
    },
    //商铺 提示
    taskshops: function () {
        if (task.TaskIconCountClick == 8) {
            var BuildingView = cc.find("Canvas/UICamera/BuildingContainer/BuildingView");
            if (this.nodeHandshops != null) {
                task.removeNode(this.nodeHandshops)
            }
            task.addTaskTips(BuildingView, task.taskPrefab[1], 0, 330, task.taskCursorName[2], function (nodePrefabs) {
                //手指
                this.nodeHandshops = nodePrefabs;
            }.bind(this));
        }
    },
    //特殊 提示
    taskspecial: function () {
        if (task.TaskIconCountClick == 9) {
            var BuildingView = cc.find("Canvas/UICamera/BuildingContainer/BuildingView");
            if (this.nodeHandspecial != null) {
                task.removeNode(this.nodeHandspecial)
                task.removeNode(this.nodeHandspecial)
            }
            task.addTaskTips(BuildingView, task.taskPrefab[1], 100, 330, task.taskCursorName[2], function (nodePrefabs) {
                //手指
                this.nodeHandspecial = nodePrefabs;
            }.bind(this));
        }
    },




    taskGreenBeltShare: function () {
        //任务
        if (task.TaskIconCountClick == 9) {
            task.removeTaskNode(task.taskCursorName[4]);
            task.removeTaskNodes();
            //开始分享
            this.startSharePrefab();
        }
    },

    taskShare: function () {

        console.log('task.taskCursor = ', task.taskCursor);
        // console.log("走着了吗");
        if (task.taskCursor == 0) {
            task.clearNodeHandnodePrefabsnoviceend();
            task.addTaskCount();
        }

        //任务
        if (task.taskCursor == 1) {
            // cc.log("建筑物创建");
            task.removeTaskNode(task.taskCursorName[4]);
            task.removeTaskNodes();

            //新手引导第一部分，创建完房子之后
            //slam todo
            //直接设置增加农田(现在为果树)
            task._setTaskCount(3);
            task.addSeneceTaskIcon();
            task._setTaskIconCountClick(0);
            task.taskCallBack();

        }
    },

    //旅行者 第一次 买农田
    buyFarming: function (callback) {

        dialogmanager.init(this.Canvas, function () {
            dialogmanager.buyFarming();

            //结束任务调用
            task.onSetTaskEnd();
        }.bind(this), function () {
            //任务结束
            task.onSetTaskEnd();

        }.bind(this), function () {
            //结束按钮
            if (callback != null) {
                callback();
            }
        }.bind(this));
        dialogmanager.setOnCloseDialog(function () {
            //对话结束回调
            if (callback != null) {
                callback();
            }
        }.bind(this));
    },

    //放置农田(现在为果树)之后
    Farming: function () {
        if (task.taskCursor == -1) return;
        // 种田之后
        task.showManagerhide();
        setTimeout(() => {
            //直接结束
            this._setTaskIconCountClick(12);
            task.taskCallBack();
        }, 300);
    },

    //建造建工厂
    taskfactory: function () {
        if (task.TaskIconCountClick == 7) {
            // console.log("农田创建完毕");
            task.showManagerhide();
            // GlobalD.GameData.PlusGolden(task.publicGive[0]);
            this.startSharePrefab();
        }
    },

    clearNodeHandLabour: function () {
        if (this.nodeHandLabour != null) {
            task.removeNode(this.nodeHandLabour)
        }
    },
    clearNodeHandnodePrefabsnoviceend: function () {
        if (this.nodePrefabsnoviceend != null) {
            task.removeNode(this.nodePrefabsnoviceend)
        }
    },
    clearNodeHandshopsshow: function () {
        if (this.nodeHandshopsshow != null) {
            task.removeNode(this.nodeHandshopsshow)
        }
    },
    clearNodeHandGreenBelt: function () {
        if (this.nodeHandGreenBelt != null) {
            task.removeNode(this.nodeHandGreenBelt)
        }
    },


    taskZS: function () {
        if (task.TaskIconCountClick == 3 && !this.taskZSTag) {
            this.taskZSTag = true;
            task.showManagerhide();

            this.startSharePrefab();
        }
    },
    //盖完了 农舍之后
    taskFarmhouse: function () {
        if (task.TaskIconCountClick == 2) {
            // //开始分享
            this.startSharePrefab();
        }
    },
    //便利店 提示
    taskConvenienceStore: function () {
        if (task.TaskIconCountClick == 8) {
            // console.log("农田创建完毕");
            task.showManagerhide();
            this.startSharePrefab();
        }
    },

    //视频教程
    videoTutorial: function () {
        var Canvas = cc.find("Canvas/UICamera");
        task.addTaskTips(Canvas, task.newTaskName[18], 0, 0, task.taskCursorName[3], function (node) {

            UtilsWX.getSystemInfo(function (obj) {
                this.width = 0 - obj.windowWidth + 100;
                this.height = obj.windowHeight - 150;
                node.getChildByName("SureBtn").y = node.getChildByName("SureBtn").y + this.height;
                node.getChildByName("SureBtn").x = this.width;
                console.log("关闭按钮", node.getChildByName("SureBtn"));

                UtilsWX.createVideo();
            }.bind(this));
            UtilsPrefabs.setOn(node.getChildByName("SureBtn"), function () {


                task.removeTaskNode(task.taskCursorName[3]);

                UtilsWX.removeVideo();
            }.bind(this))


        }.bind(this));
    },
    showvideoTutorial: function () {
        var node = cc.find("Canvas/UICamera/taskPrefab13");
        node.x = 0;
        node.y = 0;
        UtilsWX.createVideo();
        UtilsPrefabs.setOn(node.getChildByName("SureBtn"), function () {
            UtilsWX.removeVideo();
            // node.active = false;

            node.x = -2000;
            node.y = 0;

        }.bind(this))

    },


    //视频教程
    videoTutorialCreatorBtn: function () {
        task.addTaskTipsNoArr(this.BelowTheMask, "prefab/videoTutorialCreatorBtn", -300, -360, "videoTutorialCreatorBtn", function (node) {
            node.parent = this.BelowTheMask;

            UtilsPrefabs.setOn(node.getChildByName("SureBtn"), function () {

                task.showvideoTutorial();
            }.bind(this))


        }.bind(this));
    },
    //创建 帮助
    CreatorBtnHelp: function (BelowTheMask) {

        task.addTaskTipsNoArr(this.BelowTheMask, "prefab/videoTutorialCreatorBtn", -300, 300, "videoTutorialCreatorBtn", function (node) {
            node.parent = this.BelowTheMask;//this.BelowTheMask;
            // node.active = false;
            this.BtnHelp = node;
            UtilsPrefabs.setOn(node.getChildByName("SureBtn"), function () {

                task.openHelp();
            }.bind(this))
        }.bind(this));


    },

    openHelp: function () {
        // console.log("打开帮助");
        task.addTaskTipsNoArr(this.Canvas, "prefab/help/taskPrefabViewhelp", 0, 0, "videoTutorialCreatorBtn", function (node) {
            node.parent = this.Canvas;
            // console.log("打开帮助node",node);
            UtilsPrefabs.setOn(node.getChildByName("layout").getChildByName("close"), function () {
                task.removeNode(node);
            }.bind(this))


        }.bind(this));
    },

    //初始化模板遮罩
    onInitTaskMask(_taskNodes, _offset, _Count) {

        cc.loader.loadRes("prefab/task/Scene/TaskMask", function (err, texture) {
            let _taskMask = cc.instantiate(texture);

            //设置生成遮罩的节点
            _taskMask.parent = cc.find('Canvas/UICamera');
            //设置遮罩的适配目标
            let _widget = _taskMask.getChildByName('Mask').getChildByName('Bg').getComponent(cc.Widget);
            _widget.target = cc.find('Canvas');

            let taskMaskScript = _taskMask.getComponent('TaskMask');

            if (_offset != undefined)
                taskMaskScript.offset = _offset;
            if (_Count != undefined)
                taskMaskScript.offsetCount = _Count;

            // console.log('_offset =', _offset, _Count, '=taskMaskScript.offsetCount', taskMaskScript.offsetCount);
            taskMaskScript.onInitTaskMask(_taskNodes);


        }.bind(this));
    },
};
