123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- var cityList = require('../data/city');
- var cityIncomeList = require('../data/cityIncome');
- var GameModule = require('../utils/GameModule');
- const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- const DWTool = require("../utils/DWTool");
- const CityMapApi = require('../net/CityMapApi');
- const CityState = {
- lock: 0,
- dev: 1,
- unlock: 2
- }
- cc.Class({
- extends: cc.Component,
- properties: {
- scrollView: cc.ScrollView,
- view: cc.Node,
- mapbg: cc.Node,
- content: cc.Node,
- cityItemPrefab: cc.Prefab,
- myMoneyLayout: cc.Node,
- coinNode: cc.Node,
- coinSkeleton: sp.Skeleton,
- myMoneyLabel: cc.Label,
- moneyCatNode: cc.Node,
- moneyCatSkeleton: sp.Skeleton,
- backNode: cc.Node,
- myCompanyNode: cc.Node,
- companyText: cc.RichText,
- incomeText: cc.RichText,
- incomSpeedLabel: cc.Label,
- incomeLimitLabel: cc.Label,
- progressBar: cc.ProgressBar,
- currentIncomeLabel: cc.Label,
- // airplane: cc.Node,
- coinPrefab: cc.Prefab,
- topBg: cc.Node,
- grossIncome: {
- get: function () {
- return this._grossIncome;
- },
- set: function (value) {
- this._grossIncome = value;
- this.myMoneyLabel.string = DWTool.coinParse(this._grossIncome);
- }
- },
- cover: cc.Node,
- },
- onLoad() {
- this.moneyCatNode.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
- this.showCollectAnim(30);
- }, 1000, true), this);
- this.cityScriptList = [];
- let scaleSize = cc.view.getVisibleSize().height / this.mapbg.height;
- this.mapbg.height = this.node.height = cc.view.getVisibleSize().height;
- this.view.height = this.scrollView.node.height = this.node.height - 440;
- this.scrollView.node.y = this.node.height / 2 - this.scrollView.node.height;
- // if (this.node.height >= 1624) {
- // this.view.height = this.scrollView.node.height = this.node.height - 240;
- // } else {
- // this.view.height = this.scrollView.node.height = this.node.height - 440;
- // }
- // this.scrollView.node.height = this.view.height = cc.view.getVisibleSize().height;
- // this.topBg.y = this.topBg.y * scaleSize;
- this.myMoneyLayout.y = scaleSize * this.myMoneyLayout.y;
- this.moneyCatNode.y = scaleSize * this.moneyCatNode.y;
- this.backNode.y = scaleSize * this.backNode.y;
- this.myCompanyNode.y = scaleSize * this.myCompanyNode.y;
- this.myCompanyNode.active = false;
- for (let i = 0; i < cityList.length; i++) {
- let cityInfo = cityList[i];
- // if (cityInfo.id < Global.devCityId) {
- // cityInfo.state = CityState.unlock;
- // } else if (cityInfo.id === Global.devCityId) {
- // cityInfo.state = CityState.dev;
- // } else {
- // cityInfo.state = CityState.lock;
- // }
- let item = cc.instantiate(this.cityItemPrefab);
- item.x = i % 2 === 0 ? 110 : -110;
- /**
- * 暂时取消城市点击跳转功能
- */
- // item.on(cc.Node.EventType.TOUCH_END, () => {
- // if (cityInfo.id <= Global.devCityId) {
- // this.gameFSM.visitcity(cityInfo.id);
- // }
- // }, this);
- let cityScript = item.getComponent('CityItem');
- // cityScript.init(cityInfo);
- this.content.addChild(item);
- this.cityScriptList.push(cityScript);
- }
- },
- init(game) {
- this.game = game
- this.gameFSM = game.gameFSM
- console.log(this.gameFSM);
- },
- show(move, devCityId) {
- if (devCityId) {
- this.devCityId = devCityId;
- } else {
- this.devCityId = Global.devCityId;
- }
- this.node.x = 400;
- this.node.active = true;
- let finish = cc.callFunc(() => {
- // if (move) {
- // this._showMoveAnimation();
- // }
- });
- this.node.runAction(cc.sequence(cc.moveTo(0.3, 0, 0).easing(cc.easeBackOut()), finish));
- let totalIncomeSpeed = 0;
- for (let i = 0; i < cityList.length; i++) {
- let cityInfo = cityList[i];
- let cityScript = this.cityScriptList[i];
- let incomeSpeed = 0;
- if (cityInfo.id < this.devCityId) {
- cityInfo.state = CityState.unlock;
- incomeSpeed = cityIncomeList[i].income;
- totalIncomeSpeed += incomeSpeed;
- this.incomeMax = cityIncomeList[i].incomeLimit;
- this.incomSpeedLabel.string = DWTool.coinParse(totalIncomeSpeed) + "/天";
- this.incomSpeedSeconds = totalIncomeSpeed / 86400;
- this.incomeLimitLabel.string = DWTool.coinParse(this.incomeMax);
- } else if (cityInfo.id === this.devCityId) {
- cityInfo.state = CityState.dev;
- } else {
- cityInfo.state = CityState.lock;
- }
- cityScript.init(cityInfo, incomeSpeed);
- }
- if (move) {
- this.myCompanyNode.active = false;
- this.cover.active = true;
- this.backNode.active = false;
- } else {
- this.myCompanyNode.active = false;
- this.cover.active = false;
- this.backNode.active = true;
- this.moneyCatSkeleton.setAnimation(0, 'maomi', true);
- }
- let mapself = this;
- CityMapApi.getMapInfo(
- (response) => {
- this.income = Math.round(response.cityIncomeTime * this.incomSpeedSeconds) / 1000;
- mapself._setProgressbar();
- if (move) {
- this._showMoveAnimation();
- }
- this.timer = setInterval(() => {
- mapself.progressBarRunning();
- }, 1000);
- }
- , (code, msg) => {
- });
- this.myMoneyLabel.string = GameModule.userInfo.grossIncomeLabel.string;
- },
- _setProgressbar() {
- if (this.income > this.incomeMax) {
- this.income = this.incomeMax;
- }
- this.currentIncomeLabel.string = DWTool.coinParse(this.income);
- this.progressBar.progress = this.income / this.incomeMax;
- },
- progressBarRunning() {
- this.income = Math.round((this.income + this.incomSpeedSeconds) * 1000) / 1000;
- this._setProgressbar();
- },
- _showMoveAnimation() {
- this.showCollectAnim(30);
- for (let i = 0; i < this.cityScriptList.length; i++) {
- let cityInfo = cityList[i];
- if (cityInfo.id == this.devCityId) {
- let lastCity = this.cityScriptList[i];
- let currentCity = this.cityScriptList[i + 1];
- var lastPosition = this.getPositionInView(lastCity.node);
- let scrollOffset = this.scrollView.getScrollOffset().y - lastPosition.y + 300;
- let scrollTime = Math.abs(Math.round((this.content.height - scrollOffset) / 50) * 0.04);
- this.scrollView.scrollToOffset(cc.v2(0, scrollOffset), scrollTime);
- this.scheduleOnce(() => {
- this.startMoveAnimation(lastCity, currentCity);
- this.scrollView.vertical = false;
- }, scrollTime);
- }
- }
- },
- startMoveAnimation(lastCity, currentCity) {
- let self = this;
- lastCity.showFinishAnimation(() => {
- currentCity.setState(CityState.dev);
- self.scrollView.vertical = true;
- self.scheduleOnce(() => {
- this.devCityId++;
- self.gameFSM.visitcity(this.devCityId);
- }, 1);
- });
- },
- getPositionInView(item) { // get item position in scrollview's node space
- let worldPos = item.parent.convertToWorldSpaceAR(item.position);
- let viewPos = this.scrollView.node.convertToNodeSpaceAR(worldPos);
- return viewPos;
- },
- // airplaneAnimation(position1, position2, cb) {
- // var angle = this.getAngle(position1, position2);
- // this.airplane.setRotation(angle);
- // this.airplane.setPosition(position1);
- // let end = cc.callFunc(cb, this);
- // this.airplane.runAction(cc.sequence(cc.moveTo(3, position2), end));
- // },
- close() {
- clearInterval(this.timer);
- this.gameFSM.historyBack();
- },
- getAngle(p1, p2) {
- // 直角的边长
- var x = p2.x - p1.x;
- var y = p2.y - p1.y;
- // 斜边长
- var z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
- // 余弦
- var cos = y / z;
- // 弧度
- var radina = Math.acos(cos);
- // 角度
- var angle = 180 / (Math.PI / radina);
- if (x < 0) {
- angle = - angle;
- }
- return angle;
- },
- showCollectAnim(colNums) {
- if (this.income > 0) {
- this.moneyCatSkeleton.setAnimation(0, 'maomi_hit', false);
- this.moneyCatSkeleton.setCompleteListener(() => {
- this.moneyCatSkeleton.setAnimation(0, 'maomi', true);
- })
- GameModule.userInfo.grossIncome += this.income;
- this.grossIncome = GameModule.userInfo.grossIncome;
- this.income = 0;
- this._setProgressbar();
- CityMapApi.reportCityIncome().then(() => {
- });
- let canvasNode = cc.find("Canvas");
- let coinNode = this.coinNode;
- let grossCoinPos = coinNode.convertToWorldSpace(cc.v2(coinNode.width / 2, coinNode.height / 2));
- let pos = this.moneyCatNode.convertToWorldSpace(cc.v2(this.moneyCatNode.width / 2, this.moneyCatNode.height / 2 - 80));
- // let colNums = 5
- let vSize = cc.view.getVisibleSize();
- let target = cc.v2(grossCoinPos.x - vSize.width / 2, grossCoinPos.y - vSize.height / 2);
- let i = 0;
- let runSt = setInterval(() => {
- if (i == colNums) {
- clearInterval(runSt)
- } else {
- let ranX = (Math.random() - 0.5) * 2 * 8;
- let ranY = (Math.random() - 0.5) * 2 * 3;
- let newCoin = cc.instantiate(this.coinPrefab);
- let posX = pos.x - vSize.width / 2;
- let posY = pos.y - vSize.height / 2;
- canvasNode.addChild(newCoin)
- newCoin.x = posX + ranX * 15;
- newCoin.y = posY + 30 + ranY * 15;
- newCoin.active = true;
- newCoin = newCoin.getComponent("LevelHomeCoin")
- newCoin.initAnim()
- let cbNotiStart = cc.callFunc(() => {
- this.coinSkeleton.setAnimation(0, 'jinbi_huoqu2', false);
- })
- let cbDestroy = cc.callFunc(() => {
- newCoin.node.destroy();
- })
- let act = cc.sequence(cc.moveTo(1, target), cbDestroy, cbNotiStart)
- newCoin.node.runAction(act.easing(cc.easeIn(2.1)));
- i++
- }
- }, 25);
- }
- },
- });
|