| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342 |
- // const constants = require('Constants');
- // var reGameStates = require('GameStates');
- var AConfig = require('../Config')
- cc.Class({
- extends: cc.Component,
- properties: {
- //左上角按钮列表
- LeftMenu: cc.Node,
- //显示建筑的详细信息
- //建筑面板
- BuildingInfoView: cc.Node,
- //ui Mask 对应的touch
- UITouch: {
- default: null,
- type: cc.Node,
- },
- //设置面板
- SettingInfoView: cc.Node,
- //建筑面板
- //建筑物列表.后面根据数据动态添加content的内容。
- //todo..
- BuildView: cc.Node,
- StoreView: cc.Node,
- BuildContent_Button: { default: null, type: cc.Button, visible: false },
- BuildContent_OldButton: { default: null, type: cc.Button, visible: false },
- BuildContent_Normal_Sprite: cc.SpriteFrame,
- BuildContent_Pressed_Sprite: cc.SpriteFrame,
- ButtonSelectedFrame: cc.Node,
- //建筑版面的介绍模板
- BuildContent_Name: cc.Label,
- BuildContent_Price: cc.Label,
- BuildContent_Mature: cc.Label,
- BuildContent_Synopsis: cc.Label,
- //人才面板
- PersonnelView: cc.Node,
- //股票面板
- StockView: cc.Node,
- //幸运转盘
- LuckView: cc.Node,
- // 底部的菜单栏
- BottomView: cc.Node,
- // 其他农场用户的界面节点
- OtherFarmerMask: cc.Node,
- Evn: cc.Node,
- Seed: cc.Node,
- EveryDaySignView: cc.Node,
- //提示面板
- TipView: cc.Node,
- //提示面板预制
- TipViewPrefab: cc.Prefab,
- ShowRewards: cc.Node,
- BuildingFrameArray: {
- default: [],
- type: [cc.Node],
- serializable: true,
- },
- Goldenlabel: cc.Node,
- Diamondlabel: cc.Node,
- CNTlabel: cc.Node,
- SNBlabel: cc.Node,
- TimesLabel: cc.Node,
- Strengthlabel: cc.Node,
- Luckylabel: cc.Node,
- //显示的库存总量,人才界面
- cropContent: cc.Label,
- woodContent: cc.Label,
- mineContent: cc.Label,
- //钻石兑换金币
- DiamondGapView: cc.Node,
- DiamondNowlabel: cc.Label,
- ExchangeBtn: cc.Button,
- //钻石足够获得种子
- DiamondSeedsView: cc.Node,
- LightRotate: cc.Node,
- DiamondSeeds_SureBtn: cc.Button,
- inviteNode: cc.Node,
- listUserInfoNode: cc.Node,
- integralInfo: cc.Node,
- //商店面的介绍模板
- mallContent_Name: cc.Label,
- mallContent_Price: cc.Label,
- mallContent_SNBPrice: cc.Label,
- mallContent_Mature: cc.Label,
- mallContent_Synopsis: cc.Label,
- seedBottomLineBg: {
- default: null,
- type: cc.Node,
- },
- seedBottomCntNode: {
- default: null,
- type: cc.Node,
- },
- seedBottomSnbNode: {
- default: null,
- type: cc.Node,
- },
- seedBottomOrLabelNode: {
- default: null,
- type: cc.Node,
- },
- //偷取成功生成一个提示
- StealViewSuccessPrefab: cc.Prefab,
- //场景开始时候,打开的黑色遮罩
- surroundingBlack: cc.Node,
- dogButtonNode: cc.Node,
- stickButtonNode: cc.Node,
- //村长领取snb
- VillageReceivesSNBView: cc.Node,
- VillageReceivesSNBButton: cc.Node,
- //灾害显示
- disaterShowPrefab: cc.Prefab,
- naturalButtonNode: cc.Node,
- beastButtonNode: cc.Node,
- /**
- * 生成工具
- */
- toolPrefab: cc.Prefab,
- toolParent: cc.Node,
- toolsNode: cc.Node,
- isShowTools: { default: false, visible: true, serializable: false },
- isShowTopLabel: { default: false, visible: true, serializable: false },
- isShowTopButton: { default: false, visible: true, serializable: false },
- },
- onLoad() {
- },
- isGame: function () {
- this.times = 0
- cc.game.on(
- cc.game.EVENT_HIDE,
- function () {
- console.log('游戏进入后台', this.getTime())
- if (UtilsWX.shareTag == 0) {
- // this.onHideGame();//处理游戏切到后台时的事件
- this.times = this.getTime()
- task.onLoad()
- // this.onShowGame();//处理游戏切回前台时的事件
- cc.director.loadScene(
- 'Login',
- function () {
- task.showPointerNode = null
- }.bind(this)
- )
- }
- },
- this
- )
- cc.game.on(
- cc.game.EVENT_SHOW,
- function () {
- console.log('重新返回游戏', this.getTime())
- // if (this.getTime()-this.times>=30000) {
- if (UtilsWX.shareTag == 0) {
- }
- UtilsWX.setShareTag(0)
- // }
- },
- this
- )
- },
- getTime: function () {
- return new Date().getTime()
- },
- // InitTask(BFirstLoadGame) {
- // // todo 新手教学 初始化
- // console.log("初始化真的假的", BFirstLoadGame);
- // if (!BFirstLoadGame) {
- // //首次初始化
- // task.onLoad();
- // //创建员工
- // cc.find('GameNode/ManageWorker').getComponent('ManageWorker').onRecruit();
- // cc.find('GameNode/ManageWorker').getComponent('ManageWorker').onRecruit();
- // } else {
- // task._init();
- // task.addSeneceTaskIcon();
- // task.onLoadno();
- // }
- // this.Init();
- // },
- start() {
- /*
- 其中第一个参数为捕捉的时间名,在官方文档中给出了几个选择,我们主要列举下触碰时间
- cc.Node.EventType.TOUCH_START 当手按下时触发
- cc.Node.EventType.TOUCH_END 当手抬起时候
- cc.Node.EventType.TOUCH_MOVE 当手按下滑动时
- cc.Node.EventType.TOUCH_CANCEL 当手按下滑动后 抬起时
- */
- /**
- * 绑定事件
- */
- this.onBindTiledMapTouchEnd();
- },
- Init() {
- //如果用户未租赁过土地且未用钻石兑换过种子,则显示
- GlobalD.GameData.getPlayerExchangeState((res, value) => {
- //warn 这里需要增加对结果的判断
- if (0 === value.code) {
- //没有兑换过和没有租赁过
- if (!value.data.isExchange && !value.data.isLeased) {
- // this.DiamondGapViewShow()
- }
- }
- })
- //显示背景
- this.surroundingBlack.active = true;
- //显示灾难
- this.onShowDisater();
- //获取防护包
- this.onUpdateProtectedState();
- //获取工具
- GlobalD.GameData.onGetTools((value) => {
- if (0 === value.code) {
- let _tools = value.data;
- for (let i = 0; i < _tools.length; i++) {
- if (i > 3) return;
- let _toolsPrefab = cc.instantiate(this.toolPrefab)
- _toolsPrefab.parent = this.toolParent
- _toolsPrefab.setPosition(cc.v2(0, 0))
- let _landTools = _toolsPrefab.getComponent('landTools');
- _landTools.setToolsSpriteFrame(_tools[i]);
- }
- }
- })
- },
- OnShowRewardsViewClose(event, CustomEventData) {
- this.ShowRewardsView.destroy()
- },
- //点击了建造列表里面的按钮时候改变样式
- onSetButtonState(Data, Synopsis) {
- cc.Component.EventHandler.emitEvents(Data.Target.clickEvents)
- },
- onSetButtonInfoState(Data, Synopsis) {
- if (Synopsis) {
- this.onSetButtonInfo(Synopsis.Name, Synopsis.Price, Synopsis.Mature, Synopsis.Synopsis)
- }
- },
- //设置介绍信息
- onSetButtonInfo(_Name, _Price, _Mature, _Synopsis) {
- this.BuildContent_Name.string = _Name
- this.BuildContent_Mature.string = _Mature
- this.BuildContent_Price.string = "x" + _Price
- this.BuildContent_Synopsis.string = _Synopsis.replace(/\n|\r/g, '')
- },
- /**
- * 设置商城信息
- * @param {}} Data
- * @param {*} Synopsis
- */
- onSetMallInfoState(Data, Synopsis) {
- if (Synopsis) {
- this.onSetMallInfo(
- Synopsis.Name,
- Synopsis.Mature,
- Synopsis.CNT,
- Synopsis.SNB,
- Synopsis.Synopsis,
- Synopsis.showConsumeType
- )
- }
- },
- //设置介绍信息
- onSetMallInfo(_Name, _mature, _CNT, _SNB, _Synopsis, showConsumeType) {
- this.mallContent_Name.string = _Name;
- this.mallContent_Price.string = _CNT;
- this.mallContent_SNBPrice.string = _SNB;
- this.mallContent_Mature.string = _mature;
- this.mallContent_Synopsis.string = _Synopsis.replace(/\n|\r/g, '');
- // CNTORSNB: 0,
- // CNT: 1,
- // SNB: 2
- if (0 === showConsumeType) {
- this.seedBottomLineBg.width = 376;
- this.seedBottomCntNode.active = true;
- this.seedBottomOrLabelNode.active = true;
- this.seedBottomSnbNode.active = true;
- } else if (1 === showConsumeType) {
- this.seedBottomLineBg.width = 188;
- this.seedBottomCntNode.active = true;
- this.seedBottomOrLabelNode.active = false;
- this.seedBottomSnbNode.active = false;
- } else if (2 === showConsumeType) {
- this.seedBottomLineBg.width = 188;
- this.seedBottomCntNode.active = false;
- this.seedBottomOrLabelNode.active = false;
- this.seedBottomSnbNode.active = true;
- }
- },
- //收起全部菜单
- onHideMenu() {
- // if (this.BuildView) {
- // this.BuildView.active = false;
- // }
- //音效设置界面
- if (this.SettingInfoView.active)
- this.onSetTouchStatus(this.SettingInfoView, false)
- //建造界面
- // if (this.BuildView.active) this.onSetTouchStatus(this.BuildView, false)
- //人才界面
- // if (this.PersonnelView.active)
- // this.onSetTouchStatus(this.PersonnelView, false)
- //股票界面
- // if (this.StockView.active) this.onSetTouchStatus(this.StockView, false)
- //转盘界面
- // if (this.LuckView.active) this.onSetTouchStatus(this.LuckView, false)
- //商城界面
- if (this.StoreView.active) this.onSetTouchStatus(this.StoreView, false)
- },
- //底部菜单栏
- onBottomMenuView(isActive) {
- if (this.BottomView) {
- this.BottomView.active = isActive
- }
- // cc.log('不能显示面板信息:');
- GlobalD.GameControl._isBuildingCanEdit = !isActive
- },
- //农场界面相关菜单
- onOtherFarmerView(isActive) {
- if (this.OtherFarmerMask) {
- this.OtherFarmerMask.active = isActive
- }
- },
- //开启信息显示
- onShowBuildingInfo(buildingInfo) {
- this.BuildingInfoView.active = true
- if (!this._buildingInfoViewScript)
- this._buildingInfoViewScript =
- this.BuildingInfoView.getComponent('buildingInfoView')
- //显示房屋信息
- this._buildingInfoViewScript.onSetBuildingInfoView(buildingInfo)
- },
- //关闭信息显示
- onCloseBuildingInfo() {
- this.BuildingInfoView.active = false
- },
- //进入编辑模式,
- onEnterEditing() { },
- onSetTouchStatus(target, isActive) {
- target.active = isActive
- if (this.UITouch) {
- this.UITouch.active = isActive
- }
- },
- /**
- * 绑定邀请
- */
- onInvite_Open() {
- this.inviteNode.getComponent('inviteInfo').onOpenInviteInfo()
- },
- onListUserInfo_Open() {
- this.listUserInfoNode.getComponent('userListInfo').onOpen()
- },
- onListUserInfo_Close() {
- this.listUserInfoNode.getComponent('userListInfo').onClose()
- },
- /**
- * 打开兑换积分界面
- * @returns
- */
- onIntegralInfo_Open() {
- this.integralInfo.getComponent('integralInfo').onOpenInfo();
- },
- //点击钻石兑换
- onButtonEvent_Exchange() {
- this.DiamondGapView.active = true
- // this.onSetTouchStatus(this.DiamondGapView, true)
- //判断钻石数量是否大于等于3万个
- if (GlobalD.GameData.GetDiamond() < 30000) {
- this.ExchangeBtn.interactable = false
- // GlobalD.GameData.showToast(
- // cc.find('Canvas/UICamera'),
- // '钻石数量不够,累积到30000个钻石即可免费兑换一包辣椒种子。',
- // 2
- // )
- return
- } else {
- this.ExchangeBtn.interactable = true
- }
- },
- //点击取消钻石兑换
- onButtonEvent_ExchangeCancel() {
- this.DiamondGapView.active = false
- },
- //点击确认钻石兑换辣椒种子
- onButtonEvent_ExchangeChili() {
- let diamonAmount = 30000
- //调用兑换接口
- GlobalD.GameData.exchangeSeed(diamonAmount, (value) => {
- return
- //兑换成功
- if (0 === value.code) {
- var BuildingView = cc
- .find('Canvas/UICamera/BuildingContainer/BuildingView')
- .getComponent('BuildingView')
- BuildingView.onUpdateList()
- this.DiamondGapView.active = false
- this.DiamondSeedsView.active = true
- //光芒旋转
- var rotate = cc.repeatForever(cc.rotateBy(2, -100, 0))
- this.LightRotate.runAction(rotate)
- } else {
- //兑换失败
- GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), value.msg, 2)
- }
- })
- },
- //点击钻石兑换的确认按钮
- onButtonEvent_DiamondSure() {
- this.DiamondSeedsView.active = false
- //停止光芒旋转
- this.LightRotate.stopAllActions()
- },
- /**
- * 村长领取snb
- */
- onSetSnbButtonActive(isShow) {
- this.VillageReceivesSNBButton.active = isShow
- },
- onButtonEvent_VillageSnbReceive() {
- this.VillageReceivesSNBView.active = true
- },
- onButtonEvent_VillageSnbReceive_Close() {
- this.VillageReceivesSNBView.active = false
- },
- onSetVillageReceivesSNBViewInfo(data) {
- this.onSetSnbButtonActive(true);
- this.VillageReceivesSNBView.getComponent('VillageReceivesSNBView').setVillageReceivesSnbInfo(data);
- },
- //音效设置界面
- onButtonEvent_Setting_OPen() {
- this.onHideMenu()
- this.onSetTouchStatus(this.SettingInfoView, true)
- },
- onButtonEvent_Setting_Close() {
- this.onSetTouchStatus(this.SettingInfoView, false)
- },
- //建造界面
- onButtonEvent_Building_OPen() {
- this.onHideMenu()
- this.onSetTouchStatus(this.BuildView, true)
- this.BuildView.getComponent('BuildingView').onSwitchBuildingContent(
- null, //this.Evn.getComponent(cc.Button)
- 4
- )
- },
- //商城界面
- onButtonEvent_Store_OPen() {
- this.onHideMenu()
- this.onSetTouchStatus(this.StoreView, true)
- this.StoreView.getComponent('StoreView').onSwitchBuildingContent(
- this.Seed.getComponent(cc.Button),
- 0
- )
- },
- novice: function () {
- var BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView')
- task.removeTaskNode(task.taskCursorName[2]) //左上
- task.addTaskTips(
- BuildingView,
- task.taskPrefab[1],
- -180,
- 180,
- task.taskCursorName[2],
- function (nodePrefabs) {
- //手指
- this.nodePrefabs = nodePrefabs
- }.bind(this)
- )
- },
- novice1: function () {
- var BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView')
- task.addTaskTips(
- BuildingView,
- task.novice[1],
- 0,
- 50,
- task.taskCursorName[3],
- function (node) {
- UtilsPrefabs.setOn(
- node.getChildByName('SureBtn'),
- function () {
- UtilsPrefabs.setOff(node.getChildByName('SureBtn'))
- var mt = cc.moveTo(1, 110, 180) //右上
- var finished = cc.callFunc(
- function () {
- task.removeTaskNode(task.taskCursorName[3])
- this.novice2()
- }.bind(this)
- )
- var sequence = cc.sequence(mt, finished)
- this.nodePrefabs.runAction(sequence)
- task.isShowTaskNode(task.taskCursorName[3], false)
- }.bind(this)
- )
- }.bind(this)
- )
- },
- novice2: function () {
- var BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView')
- task.addTaskTips(
- BuildingView,
- task.novice[2],
- 0,
- 50,
- task.taskCursorName[3],
- function (node) {
- UtilsPrefabs.setOn(
- node.getChildByName('SureBtn'),
- function () {
- UtilsPrefabs.setOff(node.getChildByName('SureBtn'))
- var mt = cc.moveTo(1, -200, 0) //
- var finished = cc.callFunc(
- function () {
- task.removeTaskNode(task.taskCursorName[3])
- this.novice3()
- }.bind(this)
- )
- var sequence = cc.sequence(mt, finished)
- this.nodePrefabs.runAction(sequence)
- task.isShowTaskNode(task.taskCursorName[3], false)
- }.bind(this)
- )
- }.bind(this)
- )
- },
- novice3: function () {
- var BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView')
- task.addTaskTips(
- BuildingView,
- task.novice[3],
- 0,
- -150,
- task.taskCursorName[3],
- function (node) {
- UtilsPrefabs.setOn(
- node.getChildByName('SureBtn'),
- function () {
- task.removeTaskNode(task.taskCursorName[3])
- }.bind(this)
- )
- }.bind(this)
- )
- },
- //外面管理的手指
- novicepersonnel: function () {
- task.removeTaskNode(task.taskCursorName[2]) //左上
- task.addTaskTips(
- task.personnelview,
- task.taskPrefab[1],
- 0,
- 0,
- task.taskCursorName[2],
- function (nodePrefabs) {
- //手指
- this.nodePrefabs = nodePrefabs
- }.bind(this)
- )
- },
- //外面的 建筑手指
- noviceBuilding: function () {
- //建造农舍指引
- task.showTiledTile(0, 0, 0, 23, 25)
- },
- novice4: function () {
- var BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView')
- task.addTaskTips(
- BuildingView,
- task.novice[4],
- 0,
- -200,
- task.taskCursorName[3],
- function (node) {
- UtilsPrefabs.setOn(
- node.getChildByName('SureBtn'),
- function () {
- task.removeTaskNode(task.taskCursorName[3])
- }.bind(this)
- )
- }.bind(this)
- )
- },
- //关闭 建造框
- onButtonEvent_Building_Close() {
- // cc.log(this.BuildView);
- this.onSetTouchStatus(this.BuildView, false)
- },
- //关闭 商城框
- onButtonEvent_Store_Close() {
- this.onSetTouchStatus(this.StoreView, false)
- },
- //人才界面
- onButtonEvent_Personnel_OPen() {
- this.onHideMenu()
- this.onSetTouchStatus(this.PersonnelView, true)
- },
- onButtonEvent_Personnel_Close() {
- this.onSetTouchStatus(this.PersonnelView, false)
- },
- //股票界面
- onButtonEvent_Stock_OPen() {
- this.onHideMenu()
- this.onSetTouchStatus(this.StockView, true)
- // console.log("所有建筑物数据", GlobalD.game.buildingsTiledMapUnit);
- UtilsWX.lookRankList(true)
- this.showFriend()
- },
- //限制
- returnDialog: function (cursor) {
- var num = 0
- // console.log("要创建什么提示呢数字", cursor);
- switch (cursor) {
- case 1:
- num = 0
- break
- case 4:
- num = 1
- break
- case 6:
- num = 2
- break
- }
- console.log('要创建什么提示呢', task.returnPrefab[num])
- var Canvas = cc.find('Canvas/UICamera')
- task.addTaskTips(
- Canvas,
- task.returnPrefab[num],
- 0,
- 0,
- task.taskCursorName[4],
- function (nodePrefabs) {
- UtilsPrefabs.setOn(
- nodePrefabs.getChildByName('SureBtn'),
- function () {
- task.removeTaskNode(task.taskCursorName[4])
- }.bind(this)
- )
- }.bind(this)
- )
- },
- showFriend: function () {
- var data = {
- name: 'showFriend',
- }
- UtilsWX.postMessage(data)
- },
- onButtonEvent_Stock_Close() {
- this.onSetTouchStatus(this.StockView, false)
- var data = {
- name: 'hideFriend',
- }
- UtilsWX.postMessage(data)
- setTimeout(
- function () {
- UtilsWX.lookRankList(false)
- }.bind(this),
- 200
- )
- },
- //转盘界面
- onButtonEvent_Luck_OPen() {
- this.onHideMenu()
- this.onSetTouchStatus(this.LuckView, true)
- if (this.nodePrefabsLuck != null) {
- task.removeNode(this.nodePrefabsLuck)
- }
- },
- isTask: function (obj) {
- var Canvas = cc.find('Canvas/UICamera')
- UtilsPrefabs.init(Canvas).addPrefabs(
- UtilsPrefabs.sharePrefab[1],
- null,
- function (node) {
- var gosharebtn = UtilsPrefabs.getNode('gosharebtn', node)
- var close = UtilsPrefabs.getNode('close', node)
- UtilsPrefabs.setOn(
- close,
- function () {
- UtilsPrefabs.removePrefabs(Canvas, node.name)
- if (task.TaskIconCountClick == 5) {
- if (obj.currentTarget.name == 'GetGift') {
- task.addTaskIconCountClick()
- task.removeTaskNodes()
- }
- }
- }.bind(this)
- )
- UtilsPrefabs.setOn(
- gosharebtn,
- function () {
- // console.log("点击分享按钮");
- UtilsWX.sharebtn(
- function () {
- UtilsPrefabs.setOff(gosharebtn)
- GlobalD.GameData.PlusGolden(GlobalD.GameData.shareGive[0])
- GlobalD.GameData.PlusDiamond(GlobalD.GameData.shareGive[1])
- if (task.TaskIconCountClick == 5) {
- if (obj.currentTarget.name == 'GetGift') {
- task.addTaskIconCountClick()
- task.removeTaskNodes()
- }
- }
- }.bind(this)
- )
- UtilsPrefabs.removePrefabs(Canvas, node.name)
- }.bind(this)
- )
- }.bind(this)
- )
- },
- isTask4: function () {
- if (task.TaskIconCountClick == 4) {
- task.addTaskIconCountClick()
- task.removeTaskNodes()
- }
- },
- onButtonEvent_Luck_Close(obj) {
- // console.log("现在是谁点的", obj);
- let Wheel = this.LuckView.getChildByName('Wheel').getComponent('Wheel')
- Wheel.node.active = true
- Wheel.ShowRewards.active = false
- this.onSetTouchStatus(this.LuckView, false)
- if (obj.target.name == 'GetGift') {
- this.isTask(obj)
- }
- },
- onButtonEvent_EveryDay_OPen() {
- this.onHideMenu()
- this.onSetTouchStatus(this.EveryDaySignView, true)
- //打开每日签到 外面的按钮
- if (task.TaskIconCountClick == 4) {
- var EveryDaySign = cc.find(
- 'Canvas/UICamera/OverTheMask/EveryDaySignContainer/EveryDaySignView'
- )
- // var Canvas = cc.find("Canvas/UICamera");
- // task.removeTaskNodes();
- task.removeTaskNode(task.taskCursorName[4])
- task.addTaskTips(
- EveryDaySign,
- task.taskPrefab[1],
- 20,
- -470,
- task.taskCursorName[4],
- function (nodePrefabs) { }.bind(this)
- )
- }
- },
- onButtonEvent_EveryDay_Close() {
- this.onSetTouchStatus(this.EveryDaySignView, false)
- },
- onShowRewards: function (Index) {
- let ManageBuildingScript = this.node.getComponent('ManageBuildings')
- console.log('走了吗', Index)
- let GivePrize = this.ShowRewards.getChildByName('GivePrize')
- let Rewards = GivePrize.getChildByName('Rewards')
- Rewards.getComponent(cc.Sprite).spriteFrame = this.BuildingFrameArray[
- Index
- ].getChildByName('New Sprite(Splash)').getComponent(cc.Sprite).spriteFrame
- //开始播放
- var Sunshine =
- this.ShowRewards.getChildByName('GivePrize').getChildByName('Sunshine')
- Sunshine.scaleX = 0
- Sunshine.scaleY = 0
- GivePrize.scaleX = 0
- GivePrize.scaleY = 0
- Sunshine.stopAllActions()
- GivePrize.stopAllActions()
- this.scheduleOnce(function () {
- this.ShowRewards.opacity = 255
- this.ShowRewards.active = true
- var sc2 = cc.scaleTo(1, 0.5, 0.5)
- Sunshine.runAction(sc2)
- var sc3 = cc.scaleTo(1, 1, 1)
- GivePrize.runAction(sc3)
- var repeat = cc.repeatForever(cc.rotateBy(5.0, 360))
- Sunshine.runAction(repeat)
- }, 0.1)
- },
- onCloseShowRewards: function () {
- this.ShowRewards.active = false
- },
- DiamondGapViewShow: function () {
- this.DiamondGapView.active = true
- },
- GoldenChangeCallBack: function (Num, LastMoney, CurrentMoney) {
- let Scale = 30
- let Index = -1
- // if(Num>10*Scale)
- // {
- // Index = 7;//伐木场
- // }
- // if(Num>30*Scale)
- // {
- // Index = 8;//矿坑
- // }
- // if(Num>70*Scale)
- // {
- // // Index = 9;//加工厂
- // }
- // if(Num>350*Scale && Num<450*Scale)
- // {
- // Index = 4;//单元楼
- // }
- if (Num > 4000 && Num < 4500) {
- Index = 4 //单元楼
- }
- // else if(Num>450*Scale && Num<550*Scale)
- // {
- // Index = 11;//鲜花店
- // }
- else if (Num > 4500 && Num < 5500) {
- Index = 11 //鲜花店
- } else if (Num > 550 * Scale && Num < 650 * Scale) {
- Index = 12 //甜品店
- }
- if (Num > 650 * Scale && Num < 750 * Scale) {
- Index = 7 //伐木场
- } else if (Num > 750 * Scale && Num < 950 * Scale) {
- Index = 13 //汉堡店
- }
- // else if(Num>850*Scale)
- // {
- // Index = 0;//公路
- // }
- else if (Num > 950 * Scale && Num < 1050 * Scale) {
- Index = 14 //咖啡店
- } else if (Num > 1050 * Scale && Num < 1150 * Scale) {
- Index = 5 //别墅
- } else if (Num > 1150 * Scale && Num < 1250 * Scale) {
- Index = 15 //洋装店
- }
- if (Num > 1250 * Scale && Num < 1350 * Scale) {
- Index = 8 //矿坑
- } else if (Num > 1350 * Scale) {
- Index = 16 //酒吧
- }
- // else if(Num>250*Scale)
- // {
- // Index = 4;//单元楼
- // }
- // else if(Num>600*Scale)
- // {
- // Index = 5;//别墅
- // }
- var BuildingStateArray = GlobalD.GameData.GetBuildingStateArray()
- if (Index == 0) {
- if (BuildingStateArray[Index] != 1) {
- BuildingStateArray[0] = 1 //公路
- BuildingStateArray[1] = 1 //路铲
- BuildingStateArray[2] = 1 //拆迁
- let Building0 =
- this.node.getComponent('ManageBuildings').BuildingArray[0]
- let Building1 =
- this.node.getComponent('ManageBuildings').BuildingArray[1]
- let Building2 =
- this.node.getComponent('ManageBuildings').BuildingArray[2]
- Building0.active = true
- Building1.active = true
- Building2.active = true
- GlobalD.GameData.SetBuildingStateArray(BuildingStateArray)
- this.onShowRewards(Index)
- }
- } else {
- if (BuildingStateArray[Index] != 1 && Index != -1) {
- cc.log('Index=' + Index)
- BuildingStateArray[Index] = 1
- let Building =
- this.node.getComponent('ManageBuildings').BuildingArray[Index]
- Building.active = true
- GlobalD.GameData.SetBuildingStateArray(BuildingStateArray)
- this.onShowRewards(Index)
- }
- }
- let Diff = CurrentMoney - LastMoney
- let InitMoneyNum = LastMoney
- let AnimTimes = 0
- let Times = 3
- this.schedule(
- function () {
- if (Diff > 0) {
- InitMoneyNum += parseInt((CurrentMoney - LastMoney) / Times)
- } else {
- InitMoneyNum -= parseInt((CurrentMoney - LastMoney) / Times)
- }
- let result = this.FormatMoney(InitMoneyNum)
- if (AnimTimes == Times - 1) {
- this.Goldenlabel.getComponent(cc.Label).string =
- this.FormatMoney(CurrentMoney)
- return
- }
- this.Goldenlabel.getComponent(cc.Label).string = result
- AnimTimes++
- },
- 0.05,
- Times
- )
- },
- DiamondChangeCallBack: function (Num, LastMoney, CurrentMoney) {
- let Diff = CurrentMoney - LastMoney
- let InitMoneyNum = LastMoney
- let AnimTimes = 0
- let Times = 3
- this.schedule(
- function () {
- if (Diff > 0) {
- InitMoneyNum += parseInt((CurrentMoney - LastMoney) / Times)
- } else {
- InitMoneyNum -= parseInt((CurrentMoney - LastMoney) / Times)
- }
- let result = this.FormatMoney(InitMoneyNum)
- if (AnimTimes == Times - 1) {
- // this.DiamondNowlabel.string = result + '/30000'
- this.Diamondlabel.getComponent(cc.Label).string =
- this.FormatMoney(CurrentMoney)
- return
- }
- // this.DiamondNowlabel.string = result + '/30000'
- this.Diamondlabel.getComponent(cc.Label).string = result
- AnimTimes++
- },
- 0.05,
- Times
- )
- },
- CNTChangeCallBack: function (Num) {
- this.CNTlabel.getComponent(cc.Label).string = this.formatPrice(Num)
- },
- SNBChangeCallBack: function (Num) {
- this.SNBlabel.getComponent(cc.Label).string = this.formatPrice(Num);
- },
- AnimalTimesChangeCallBack: function (Num) {
- this.TimesLabel.getComponent(cc.Label).string = this.formatPrice(Num);
- },
- formatPrice(price) {
- return String(price).replace(/\d(?=(?:\d{3})+\b)/g, '$&,');
- },
- FormatMoney(s, n) {
- n = n > 0 && n <= 20 ? n : 2
- s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(n) + ''
- var l = s.split('.')[0].split('').reverse(),
- r = s.split('.')[1]
- let t = ''
- for (let i = 0; i < l.length; i++) {
- t += l[i] + ((i + 1) % 3 == 0 && i + 1 != l.length ? ',' : '')
- }
- return t.split('').reverse().join('') //+ "." + r;
- },
- /**
- * 偷取果实
- */
- onStealAllFruit() {
- //todo 偷取之前本地判断下体力值
- if (GlobalD.PlayerAttribute.currentStrength <= 0) {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "体力不足,无法收取作物!", 1);
- return;
- }
- GlobalD.GameData.onStealAllFruit({ otherUserId: GlobalD.OtherUserInfo.userId }, (value) => {
- console.log(value);
- if (0 === value.code) {
- if (0 !== value.data.stealSum) {
- // if (this.StealViewSuccessPrefab) {
- // let _TipView = cc.instantiate(this.StealViewSuccessPrefab)
- // _TipView.parent = this.TipView
- // _TipView.setPosition(cc.v2(0, 0))
- // _TipView
- // .getComponent('StealViewSuccess')
- // .setInfo({ amount: value.data.stealSum });
- // }
- this.onInitStealViewSuccessPrefab(value.data);
- let BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView').getComponent('BuildingView');
- BuildingView.onUpdateList();
- //偷取成功后,关闭对应土地的提示图标
- let _landBuildingsInfo = cc.find("Canvas/MyMapNode").children;
- let _stealList = value.data.steals;
- for (let j = 0; j < _stealList.length; j++) {
- for (let i = _landBuildingsInfo.length - 1; i >= 0; i--) {
- let resetLandInfo = _landBuildingsInfo[i];
- if (resetLandInfo.name == "Labour_205_Holy_Farmland") {
- let leaseFarmlandInfoScript = resetLandInfo.getComponent("LeaseFarmlandInfo");
- if (leaseFarmlandInfoScript.leaseLandInfo && leaseFarmlandInfoScript.leaseLandInfo.configLandId == _stealList[j].landId) {
- leaseFarmlandInfoScript.onHideStealHarvest();
- }
- }
- }
- }
- } else {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "未偷取到果实!", 1);
- }
- } else {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 1);
- }
- });
- },
- /**
- * 生成一个提示面板
- * @param {偷取对象} stealObj
- */
- onInitStealViewSuccessPrefab(stealObj) {
- if (this.StealViewSuccessPrefab) {
- let _TipView = cc.instantiate(this.StealViewSuccessPrefab)
- _TipView.parent = this.TipView
- _TipView.setPosition(cc.v2(0, 0))
- _TipView
- .getComponent('StealViewSuccess')
- .setSingleStealInfo(stealObj);
- }
- },
- //体力值
- StrengthChangeCallBack: function (Num) {
- this.Strengthlabel.getComponent(cc.Label).string = Num
- },
- //幸运值
- LuckyChangeCallBack: function (Num) {
- this.Luckylabel.getComponent(cc.Label).string = Num
- },
- //小狗和木棒
- onSettingDogAlpha(opacity) {
- this.dogButtonNode.opacity = opacity;
- },
- onSettingStickAlpha(opacity) {
- this.stickButtonNode.opacity = opacity;
- },
- onDetectDog() {
- if (GlobalD.Dog) {
- if (GlobalD.Dog.remainingConsumption > 0) {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "已经拥有小狗。", 1);
- } else {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "需要点击狗盆购买狗粮。", 1);
- }
- } else {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "尚未拥有小狗。", 1);
- }
- },
- onDetectStick() {
- if (GlobalD.Stick) {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "已经装备打狗棒。", 1);
- } else {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "尚未购买打狗棒。", 1);
- }
- },
- onDetectNaturalPack() {
- if (GlobalD.NaturalPack) {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "自然灾害防御时间:" + GlobalD.NaturalPack.protectTime, 2);
- } else {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "尚未购买自然防护包。", 1);
- }
- },
- onDetectBeastPack() {
- if (GlobalD.BeastPack) {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "野兽灾害防御时间:" + GlobalD.BeastPack.protectTime, 2);
- } else {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "尚未购买野兽防护包", 1);
- }
- },
- /**
- * 刷新购买状态
- */
- onUpdateProtectedState() {
- //获取防护状态
- GlobalD.GameData.onGetDisasterProtected((value) => {
- if (0 === value.code) {
- // console.log("value:", value);
- this.onRunProtected(value);
- }
- })
- },
- onRunProtected(value) {
- GlobalD.NaturalPack = value.data.naturalProtected;
- if (GlobalD.NaturalPack != null) {
- this.naturalButtonNode.opacity = 255;
- } else {
- this.naturalButtonNode.opacity = 125;
- }
- GlobalD.BeastPack = value.data.beastProtected;
- if (GlobalD.BeastPack != null) {
- this.beastButtonNode.opacity = 255;
- } else {
- this.beastButtonNode.opacity = 125;
- }
- },
- onShowDisater() {
- GlobalD.GameData.onGetDisasterHistory((value) => {
- //warn 这里需要增加对结果的判断
- if (0 === value.code) {
- // console.log(value);
- let list = value.data;
- let showNatural = null, showBeast = null;
- //这里只显示两种类型灾难,不显示数量
- for (let i = 0; i < list.length; i++) {
- if (2 === list[i].dsasterType && showNatural == null) {
- showNatural = list[i];
- this.onInitDisaterShowPrefabPrefab(showNatural);
- } else if (3 === list[i].dsasterType && showBeast == null) {
- showBeast = list[i];
- this.onInitDisaterShowPrefabPrefab(showBeast);
- }
- }
- }
- })
- },
- /**
- * 生成一个灾害提示
- * @param {显示数据}} tipObj
- */
- onInitDisaterShowPrefabPrefab(tipObj) {
- // console.log('灾难:', tipObj);
- if (this.disaterShowPrefab) {
- let _TipView = cc.instantiate(this.disaterShowPrefab)
- _TipView.parent = this.TipView
- _TipView.setPosition(cc.v2(0, 0))
- _TipView
- .getComponent('disaterPanel')
- .onSetDisaterInfo(tipObj.dsasterType, tipObj.damage);
- }
- },
- /**
- * 动画处理ui
- */
- onBindTiledMapTouchEnd() {
- //TiledMap_Touch_End
- // console.log("onBindTiledMapTouchEnd*********");
- GlobalD.TiledMap.node.on('TiledMap_Touch_End', this.onResetUI, this);
- },
- onResetUI() {
- let _landBuildingsInfo = cc.find("Canvas/MyMapNode").children;
- for (let i = _landBuildingsInfo.length - 1; i >= 0; i--) {
- let resetLandInfo = _landBuildingsInfo[i];
- if (resetLandInfo.name == "Labour_205_Holy_Farmland") {
- let leaseFarmlandInfoScript = resetLandInfo.getComponent("LeaseFarmlandInfo");
- leaseFarmlandInfoScript.onSetInfoBoxActive(false);
-
- }
- }
- this.onHideSelectLeaseLandInfo();
- },
- onHideSelectLeaseLandInfo() {
- //记录当前选中的buildInfo
- GlobalD.game.onSetCurrentSelectLeaseLandInfo(null);
- this.onHideShowToolsAnimation();
- this.onHideTopLabelAnimation();
- this.onHideTopButtonAnimation();
- },
- onSwitchHideUI() {
- this.onPlayShowToolsAnimation();
- this.onPlayTopLabelAnimation();
- this.onPlayTopButtonAnimation();
- },
- //底部工具栏
- onPlayShowToolsAnimation() {
- if (this.isShowTools) return;
- this.isShowTools = true;
- let animation = this.BottomView.getChildByName('BottomButton').getComponent(cc.Animation);
- let state = animation.getAnimationState(animation.defaultClip.name);
- if (!state.isPlaying) {
- state.wrapMode = cc.WrapMode.Normal;
- animation.play();
- //播放之后设置一个状态
- }
- },
- onHideShowToolsAnimation() {
- if (!this.isShowTools) return;
- this.isShowTools = false;
- let animation = this.BottomView.getChildByName('BottomButton').getComponent(cc.Animation);
- let state = animation.getAnimationState(animation.defaultClip.name);
- if (!state.isPlaying) {
- state.wrapMode = cc.WrapMode.Reverse;
- animation.play();
- }
- },
- //顶部工具栏
- onPlayTopLabelAnimation() {
- if (this.isShowTopLabel) return;
- this.isShowTopLabel = true;
- let animation = this.BottomView.getChildByName('TopLabel').getComponent(cc.Animation);
- let state = animation.getAnimationState(animation.defaultClip.name);
- if (!state.isPlaying) {
- state.wrapMode = cc.WrapMode.Normal;
- animation.play();
- //播放之后设置一个状态
- }
- },
- onHideTopLabelAnimation() {
- if (!this.isShowTopLabel) return;
- this.isShowTopLabel = false;
- let animation = this.BottomView.getChildByName('TopLabel').getComponent(cc.Animation);
- let state = animation.getAnimationState(animation.defaultClip.name);
- if (!state.isPlaying) {
- state.wrapMode = cc.WrapMode.Reverse;
- animation.play();
- }
- },
- //右边按钮栏
- onPlayTopButtonAnimation() {
- if (this.isShowTopButton) return;
- this.isShowTopButton = true;
- let animation = this.BottomView.getChildByName('TopButton').getComponent(cc.Animation);
- let state = animation.getAnimationState(animation.defaultClip.name);
- if (!state.isPlaying) {
- state.wrapMode = cc.WrapMode.Normal;
- animation.play();
- //播放之后设置一个状态
- }
- },
- onHideTopButtonAnimation() {
- if (!this.isShowTopButton) return;
- this.isShowTopButton = false;
- let animation = this.BottomView.getChildByName('TopButton').getComponent(cc.Animation);
- let state = animation.getAnimationState(animation.defaultClip.name);
- if (!state.isPlaying) {
- state.wrapMode = cc.WrapMode.Reverse;
- animation.play();
- }
- },
- onDestroy() {
- GlobalD.TiledMap.node.off('TiledMap_Touch_End', this.onResetUI, this)
- }
- })
|