123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- const DWTool = require('../utils/DWTool');
- cc.Class({
- extends: cc.Component,
- properties: {
- cityPic: cc.Sprite,
- incomeSpeedLabel: cc.Label,
- indexLabel: cc.Label,
- stateSprite: cc.Sprite,
- incomeLayout: cc.Node,
- line: cc.Node,
- currentIndicator: cc.Node,
- stateSelected: cc.SpriteFrame,
- stateLock: cc.SpriteFrame,
- stateUnlock: cc.SpriteFrame,
- },
-
- init(info, incomeSpeed) {
- this.info = info;
- this.indexLabel.string = info.id;
- switch (info.state) {
- case 1:
- this.stateFrame = this.stateSelected;
- this.picPath = info.picId + '_';
- this.indexLabel.node.active = true;
- this.currentIndicator.active = true;
- break;
- case 2:
- this.stateFrame = this.stateUnlock;
- this.picPath = info.picId + '_';
- this.indexLabel.node.active = true;
- this.currentIndicator.active = false;
- break;
- default:
- this.stateFrame = this.stateLock;
- this.picPath = info.picId;
- this.indexLabel.node.active = false;
- this.currentIndicator.active = false;
- break;
- }
- cc.loader.loadRes('./map/' + this.picPath, cc.SpriteFrame, (err, spriteFrame) => {
- this.cityPic.spriteFrame = spriteFrame;
- this.currentIndicator.y = this.cityPic.node.height / 2 - this.currentIndicator.height / 2;
- });
- this.stateSprite.spriteFrame = this.stateFrame;
- if (incomeSpeed > 0) {
- this.incomeLayout.active = true;
- this.incomeSpeedLabel.string = `${DWTool.coinParse(incomeSpeed)}/天`;
- } else {
- this.incomeLayout.active = false;
- }
- if (this.node.x === -110) {
- this.line.x = -60;
- this.line.scaleX = 1;
- } else {
- this.line.x = 60;
- this.line.scaleX = -1;
- }
- if (info.state == 2) {
- this.line.active = true;
- } else {
- this.line.active = false;
- }
- },
- start() {
- },
- setState(state) {
- switch (state) {
- case 1:
- this.stateFrame = this.stateSelected;
- this.picPath = this.info.picId + '_';
- this.indexLabel.node.active = true;
- break;
- case 2:
- this.stateFrame = this.stateUnlock;
- this.picPath = this.info.picId + '_';
- this.indexLabel.node.active = true;
- break;
- default:
- this.stateFrame = this.stateLock;
- this.picPath = this.info.picId;
- this.indexLabel.node.active = false;
- break;
- }
- let end = cc.callFunc(() => {
- this.stateSprite.spriteFrame = this.stateFrame;
- });
- this.stateSprite.node.runAction(cc.sequence(cc.scaleTo(0.2, 0, 0), end, cc.scaleTo(0.2, 1, 1)));
- cc.loader.loadRes('./map/' + this.picPath, cc.SpriteFrame, (err, spriteFrame) => {
- this.cityPic.spriteFrame = spriteFrame;
- });
- if (state == 2) {
- this.line.active = true;
- } else {
- this.line.active = false;
- }
- },
- showFinishAnimation(cb) {
- this.line.active = true;
- this.line.getComponent('LineCtrl').showAnimation(() => {
- cc.loader.loadRes('./map/' + this.info.picId + '_', cc.SpriteFrame, (err, spriteFrame) => {
- this.cityPic.spriteFrame = spriteFrame;
- });
- this.stateSprite.spriteFrame = this.stateUnlock;
- cb();
- });
- },
-
- });
|