123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- const { LevelHomeArtistItemStyle, ArtistOperation } = require('../utils/GameEnum')
- const Api = require('../net/Api');
- const DWTool = require('../utils/DWTool');
- const AlertManager = require('../utils/AlertManager');
- const GameModule = require("../utils/GameModule");
- cc.Class({
- extends: cc.Component,
- properties: {
-
-
- artistBgSpriteFrames: [cc.SpriteFrame],
-
- bgSprite: cc.Sprite,
- addBtn: cc.Button,
- artistNode: cc.Node,
- headSprite: cc.Sprite,
- tipNode: cc.Node,
- topSprite: cc.Sprite,
- bototomSprite: cc.Sprite,
- },
-
- initWithBuildingInfo(buildingInfo, uid, isSelf, showTop = false, showBottom = false) {
- this.setStyle(LevelHomeArtistItemStyle.Add);
- this.buildingInfo = buildingInfo;
- this.uid = uid;
- this.isSelf = isSelf;
- this.topSprite.node.active = showTop;
- this.bototomSprite.node.active = showBottom;
- },
-
-
- initWithArtistData(buildingInfo, uid, isSelf, artistData, showTop = false, showBottom = false) {
-
- this.setStyle(LevelHomeArtistItemStyle.Artist);
- this.artistData = artistData;
- this.buildingInfo = buildingInfo;
- this.uid = uid;
- this.isSelf = isSelf;
-
- if (this.artistData.role === 2) {
- this.bgSprite.spriteFrame = this.artistBgSpriteFrames[0];
- } else {
- this.bgSprite.spriteFrame = this.artistBgSpriteFrames[1];
- }
-
- Api.createImageFromUrl(this.artistData.head, (spriteFrame) => {
- this.headSprite.spriteFrame = spriteFrame;
- }, null);
- this.topSprite.node.active = showTop;
- this.bototomSprite.node.active = showBottom;
- },
- onLoad () {
- this.artistNode.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
-
- if (!this.isSelf && this.artistData.role === 2) { return; }
-
- if (this.isSelf && this.artistData.role === 2) {
- AlertManager.showArtistResident(this.buildingInfo, this.uid, this.isSelf);
- } else {
-
-
- let guide = GameModule.homeGuide.getComponent('HomeGuide')
- let guidePass = guide.guideState.state35.pass
- if(!guidePass) {
-
-
- guide.handleState('state35');
-
-
- GameModule.homeGuide.on('Fire_state35', () => {
- AlertManager.showArtistOperationAlert(this.buildingInfo, this.uid, this.isSelf, this.artistData);
-
- setTimeout(() => {
- guide.handleState('state36');
- }, 400);
- })
- } else {
-
-
- AlertManager.showArtistOperationAlert(this.buildingInfo, this.uid, this.isSelf, this.artistData);
- }
- }
-
- }, 1000, true), this);
- this.handleAddArtist = _.debounce(() => {
- AlertManager.showArtistResident(this.buildingInfo, this.uid, this.isSelf);
- }, 1000, true);
- },
- setStyle(style) {
- if (this.style === style) {
- return;
- }
- switch (style) {
- case LevelHomeArtistItemStyle.Add:
- this.addBtn.node.active = true;
- this.artistNode.active = false;
- break;
- case LevelHomeArtistItemStyle.Artist:
- this.addBtn.node.active = false;
- this.artistNode.active = true;
- break;
- default:
- break;
- }
- this.style = style;
- },
- addArtist() {
- this.handleAddArtist();
- },
- update (dt) {
- if (this.style === LevelHomeArtistItemStyle.Artist
- && this.artistData
- && this.artistData.role === 4
- && this.isSelf) {
-
- let time = (Date.parse(new Date()) - this.artistData.stationTime) / 1000;
- if (time < 900) {
- this.tipNode.active = false;
- } else {
- this.tipNode.active = true;
- }
- }
- },
- });
|