| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944 |
- // const constants = require('Constants');
- // var reGameStates = require('GameStates');
- var AConfig = require('../Config');
- cc.Class({
- extends: cc.Component,
- properties: {
- //左上角按钮列表
- LeftMenu: cc.Node,
- //编辑建筑物时候的ui显示
- EditorialBuildings: cc.Node,
- //记录编辑按钮的父对象
- _thisEditBuildingsParent: cc.Node,
- _Cancellation: cc.Button,
- _Comfirmation: cc.Button,
- _buildTarget: 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_Synopsis: cc.Label,
- //人才面板
- PersonnelView: cc.Node,
- //股票面板
- StockView: cc.Node,
- //幸运转盘
- LuckView: cc.Node,
- // 底部的菜单栏
- BottomView: 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,
- //显示的库存总量,人才界面
- cropContent: cc.Label,
- woodContent: cc.Label,
- mineContent: cc.Label,
- inviteNode: cc.Node,
- },
- onLoad() {
- cc.game.setFrameRate(30);
- cc.director.preloadScene('Login', function () {
- }.bind(this));
- if (this.EditorialBuildings) {
- this._thisEditBuildingsParent = this.EditorialBuildings.parent;
- this._Cancellation = this.EditorialBuildings.getChildByName('Cancellation').getComponent(cc.Button);
- this._Comfirmation = this.EditorialBuildings.getChildByName('Confirmation').getComponent(cc.Button);
- }
- task.managerUi = this;
- var data1 = {
- name: "Whoareyou",
- openId: userData.openId,
- }
- UtilsWX.postMessage(data1);
- UtilsWX.shareMenu();
- UtilsWX.initWXSubContextView(cc.find("Canvas/UICamera/wx"));
- UtilsWX.openWXSubContextView(false);
- },
- 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 当手按下滑动后 抬起时
- */
- if (this._Cancellation) this._Cancellation.node.on(cc.Node.EventType.TOUCH_END, this.onCancellationEditor, this);
- if (this._Comfirmation) this._Comfirmation.node.on(cc.Node.EventType.TOUCH_END, this.onConfirmationEditor, this);
- },
- Init() {
- this._setLockBuildingColor();
- let BuildingStateArray = GlobalD.GameData.GetBuildingLockStateArray();
- for (let i = 0; i < BuildingStateArray.length; i++) {
- if (BuildingStateArray[i] == 1) {
- if (this.BuildingFrameArray[i])
- this.OpenBuildingUILock(i, false);
- }
- if (this.BuildingFrameArray[i])
- this.BuildingFrameArray[i].getChildByName('Lock').getChildByName('PriceBG').getChildByName('label').getComponent(cc.Label).string = this.FormatMoney(AConfig.BuildingUnlockMoneyArray[i]);
- }
- // *********** todo *************
- //初始化,面板信息
- //运营费用数组
- let _runningCostArray = AConfig.RunningCostArray;
- for (let i = 0; i < _runningCostArray.length; i++) {
- if(this.BuildingFrameArray[i]){
- let _contentButton = this.BuildingFrameArray[i].getComponent('Content_Button');
- _contentButton.Price = AConfig.RunningCostArray[i]; //运营费用
- //设置新的钻石价格
- let _DiamondNumArray = GlobalD.GameData.GetDiamondNumArray();
- _contentButton.DiamondPrice = _DiamondNumArray[i]; //钻石费用
- }
-
- }
- },
- _setLockBuildingColor() {
- let BuildingStateArray = GlobalD.GameData.GetBuildingLockStateArray();
- for (let index = 0; index < BuildingStateArray.length; index++) {
- if (this.BuildingFrameArray[index] && BuildingStateArray[index] == 0 ) {
- this.BuildingFrameArray[index].color = new cc.Color(150, 150, 150, 150);
- this.BuildingFrameArray[index].getChildByName('New Sprite(Splash)').color = new cc.Color(0, 0, 0, 255);
- this.BuildingFrameArray[index].getChildByName('Name').active = false;
- }
- }
- },
- OpenBuildingUILock(Index, BLock) {
- let Lock = this.BuildingFrameArray[Index].getChildByName('Lock').active = BLock;
- let BuildingStateArray = GlobalD.GameData.GetBuildingLockStateArray();
- if (!BLock && BuildingStateArray[Index] == 0) {
- BuildingStateArray[Index] = 1;
- this.BuildingFrameArray[Index].color = new cc.Color(255, 255, 255, 255);
- this.BuildingFrameArray[Index].getChildByName('New Sprite(Splash)').color = new cc.Color(255, 255, 255, 255);
- this.BuildingFrameArray[Index].getChildByName('Name').active = true;
- GlobalD.GameData.SetBuildingLockStateArray(BuildingStateArray);
- }
- },
- OnUnLockBuilding(event, CustomEventData, callback) {
- cc.loader.loadRes("prefab/UnlockBuiding", function (err, texture) {
- this.UnlockBuildingDialogView = cc.instantiate(texture);
- this.BuildView.addChild(this.UnlockBuildingDialogView);
- {
- //CloseBtn
- let close = this.UnlockBuildingDialogView.getChildByName("close");
- let clickEventHandler = new cc.Component.EventHandler();
- clickEventHandler.target = this.node;
- clickEventHandler.component = "ManageUI";
- clickEventHandler.handler = "onClickCloseInUnlockBuilding";
- let button = close.getComponent(cc.Button);
- button.clickEvents.push(clickEventHandler);
- }
- {
- //NoBtn
- let NoBTN = this.UnlockBuildingDialogView.getChildByName("NoBTN");
- let clickEventHandler = new cc.Component.EventHandler();
- clickEventHandler.target = this.node;
- clickEventHandler.component = "ManageUI";
- clickEventHandler.handler = "onClickNoBTNInUnlockBuilding";
- let button = NoBTN.getComponent(cc.Button);
- button.clickEvents.push(clickEventHandler);
- }
- {
- //YesBtn
- let YesBTN = this.UnlockBuildingDialogView.getChildByName("YesBTN");
- let clickEventHandler = new cc.Component.EventHandler();
- clickEventHandler.target = this.node;
- clickEventHandler.component = "ManageUI";
- clickEventHandler.handler = "onClickYesBTNInUnlockBuilding";
- clickEventHandler.customEventData = CustomEventData;
- let button = YesBTN.getComponent(cc.Button);
- button.clickEvents.push(clickEventHandler);
- }
- //Close
- if (callback != null) {
- callback(this.UnlockBuildingDialogView);
- }
- }.bind(this));
- },
- onClickCloseInUnlockBuilding(event) {
- this.UnlockBuildingDialogView.destroy();
- },
- onClickNoBTNInUnlockBuilding(event) {
- this.UnlockBuildingDialogView.destroy();
- },
- onClickYesBTNInUnlockBuilding(event, CustomEventData) {
- this.UnlockBuildingDialogView.destroy();
- let Index = parseInt(CustomEventData);
- let CostCoin = AConfig.BuildingUnlockMoneyArray[Index];
- if (GlobalD.GameData.GetDiamond() > CostCoin || GlobalD.GameData.GetDiamond() == CostCoin) {
- GlobalD.GameData.PlusDiamond(-CostCoin);
- this.OpenBuildingUILock(Index, false);
- cc.loader.loadRes("prefab/show", function (err, texture) {
- this.ShowRewardsView = cc.instantiate(texture);
- this.BuildView.addChild(this.ShowRewardsView);
- let Rewards = this.ShowRewardsView.getChildByName('GivePrize').getChildByName('Rewards');
- Rewards.getComponent(cc.Sprite).spriteFrame = this.BuildingFrameArray[Index].getChildByName('New Sprite(Splash)').getComponent(cc.Sprite).spriteFrame;
- var Sunshine = this.ShowRewardsView.getChildByName('GivePrize').getChildByName('Sunshine');
- var GivePrize = this.ShowRewardsView.getChildByName('GivePrize');
- Sunshine.scaleX = 0;
- Sunshine.scaleY = 0;
- GivePrize.scaleX = 0;
- GivePrize.scaleY = 0;
- Sunshine.stopAllActions();
- GivePrize.stopAllActions();
- this.scheduleOnce(function () {
- var sc2 = cc.scaleTo(0.5, 0.8, 0.8);
- Sunshine.runAction(sc2);
- var sc3 = cc.scaleTo(0.5, 1.3, 1.3);
- GivePrize.runAction(sc3);
- var repeat = cc.repeatForever(cc.rotateBy(5.0, 360));
- Sunshine.runAction(repeat);
- }, 0.1);
- //CloseBtn
- let close = this.ShowRewardsView.getChildByName("close");
- let clickEventHandler = new cc.Component.EventHandler();
- clickEventHandler.target = this.node;
- clickEventHandler.component = "ManageUI";
- clickEventHandler.handler = "OnShowRewardsViewClose";
- let button = close.getComponent(cc.Button);
- button.clickEvents.push(clickEventHandler);
- }.bind(this));
- return;
- }
- //No Enough Diamond
- cc.loader.loadRes("prefab/ShowNoMoney", function (err, texture) {
- this.ShowNoMoneyView = cc.instantiate(texture);
- this.BuildView.addChild(this.ShowNoMoneyView);
- let DetailLabel = this.ShowNoMoneyView.getChildByName('DetailLabel');
- DetailLabel.getComponent(cc.Label).string = '钻石不够!'
- this.scheduleOnce(function () {
- this.ShowNoMoneyView.destroy();
- }.bind(this), 1);
- }.bind(this));
- },
- OnShowRewardsViewClose(event, CustomEventData) {
- this.ShowRewardsView.destroy();
- },
- //弹出购买提示
- onPurchaseTips(_contentButton) {
- // cc.log('是否用钻石购买建筑', _contentButton.node.name);
- if (this.TipViewPrefab) {
- let _TipView;
- _TipView = cc.instantiate(this.TipViewPrefab);
- _TipView.parent = this.TipView;
- _TipView.setPosition(cc.v2(0, 0));
- _TipView.getComponent('TipView').onShowTip({ ContentButton: _contentButton, TipViewNode: this.TipView });
- // cc.log(_TipView.name);
- }
- },
- //点击了建造列表里面的按钮时候改变样式
- onSetButtonState(Data, Synopsis) {
- cc.Component.EventHandler.emitEvents(Data.Target.clickEvents);
- },
- onSetButtonInfoState(Data, Synopsis) {
- if (Synopsis) {
- this.onSetButtonInfo(Synopsis.Name, Synopsis.Price, Synopsis.Synopsis)
- }
- },
- //设置介绍信息
- onSetButtonInfo(_Name, _Price, _Synopsis) {
- this.BuildContent_Name.string = _Name;
- this.BuildContent_Price.string = _Price;
- this.BuildContent_Synopsis.string = _Synopsis;
- },
- //编辑对应的建筑
- onEditorialBuildings(mUI_buildTarget) {
- if (!this.EditorialBuildings) {
- cc.warn('EditorialBuildings is Null!')
- return;
- }
- this.EditorialBuildings.active = true;
- //重置上一个编辑建筑的状态
- if (this._buildTarget && this._buildTarget.getComponent('buildingsTouch')) {
- this._buildTarget.getComponent('buildingsTouch').onCancelEdit();
- }
- this._buildTarget = mUI_buildTarget;
- this.EditorialBuildings.parent = mUI_buildTarget;
- this.EditorialBuildings.setPosition(cc.v2(0, 0));
- },
- //取消编辑
- onCancellationEditor() {
- //获取建筑物上的组件
- let buildTouch = this._buildTarget.getComponent('buildingsTouch');
- let isTaskNext = buildTouch.onTaskBuild();
- if (!isTaskNext) return;
- if (task.isMushBuildState) {
- cc.loader.loadRes('resUI/ShowNotEnoughMoney', function (err, texture) {
- var prefab = cc.instantiate(texture);
- prefab.getComponent('ShowNotEnoughMoney').Text("请点击'√'号");
- this._buildTarget.addChild(prefab);
- }.bind(this));
- return;
- }
- // if (buildTouch) {
- buildTouch.onCancelEdit();
- // }
- this.EditorialBuildings.active = false;
- this.EditorialBuildings.parent = this._thisEditBuildingsParent;
- this.EditorialBuildings.setPosition(cc.v2(10000, 100));
- this._buildTarget = null;
- },
- //确定编辑(创建建筑物 对号)
- onConfirmationEditor() {
- //获取建筑物上的组件
- let buildTouch = this._buildTarget.getComponent('buildingsTouch');
- let isTaskNext = buildTouch.onTaskBuild();
- if (!isTaskNext) return;
- // if (buildTouch) {
- buildTouch.onFinishEdit();
- // }
- this.EditorialBuildings.active = false;
- this.EditorialBuildings.parent = this._thisEditBuildingsParent;
- this.EditorialBuildings.setPosition(cc.v2(10000, 100));
- this._buildTarget = null;
- },
- //如果相等的话返回true
- verctor3IsEqual(vector1, vector2) {
- let isEqual = false;
- let out = new cc.Vec3();
- out.x = vector2.x - vector1.x;
- out.y = vector2.y - vector1.y;
- out.z = vector2.z - vector1.z;
- if (out.x == 0 && out.y == 0 && out.z == 0) {
- isEqual = true;
- }
- return isEqual;
- },
- //收起全部菜单
- 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;
- },
- //开启信息显示
- 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();
- },
- //音效设置界面
- 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(this.Evn.getComponent(cc.Button), 0);
- },
- //商城界面
- 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 data1 = {
- // name: "Whoareyou",
- // openId : userData.openId
- // }
- // UtilsWX.postMessage(data1);
- 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;
- },
- 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.Diamondlabel.getComponent(cc.Label).string = this.FormatMoney(CurrentMoney);
- return;
- }
- this.Diamondlabel.getComponent(cc.Label).string = result;
- AnimTimes++;
- }, 0.05, Times);
- },
- CNTChangeCallBack: function (Num) {
- this.CNTlabel.getComponent(cc.Label).string = this.FormatMoney(Num);
- },
- SNBChangeCallBack: function (Num) {
- this.SNBlabel.getComponent(cc.Label).string = this.FormatMoney(Num);
- },
- 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;
- }
- });
|