123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- const DWTool = require('../utils/DWTool');
- const { GameNotificationKey } = require("../utils/GameEnum");
- const ThemeManager = require("../utils/ThemeManger");
- const HomeApi = require("../net/HomeApi");
- cc.Class({
- extends: cc.Component,
- properties: {
-
- bgNode: cc.Node,
-
-
- buildSprite: cc.Sprite,
-
- pillarTop: cc.Sprite,
- pillarBottom: cc.Sprite,
- pillarRight: cc.Sprite,
- pillarLeft: cc.Sprite,
- bottomBg: cc.Sprite,
-
- lockNode: cc.Node,
-
- buildNameLabel: cc.Label,
- lockBottomNode: cc.Node,
-
- levelProgressNode: cc.Node,
-
- levelProgressBar: cc.ProgressBar,
-
- levelProgressLabel: cc.Label,
-
- rateProgressNode: cc.Node,
-
- rateProgressBar: cc.ProgressBar,
-
- rateProgressLabel: cc.Label,
-
- countdownLabel: cc.Label,
- artistList: cc.Node,
- artistListItem: cc.Prefab,
- openDoorSprite: cc.Sprite,
-
- additionNode: cc.Node,
-
- additionLabel: cc.Label,
-
- additionSkeleton: sp.Skeleton,
-
- maxNode: cc.Node,
- addition: {
- get: function () {
- if (!this._addition) {
- this._addition = 0;
- }
- return this._addition;
- },
- set: function (value) {
- this._addition = value;
- if (this._addition === 0) {
- this.additionNode.active = false;
- this.additionSkeleton.setAnimation(0, 'jiasutiao_2', true);
- this.rateProgressBar.barSprite.node.active = true;
- } else {
- this.additionNode.active = true;
- this.additionLabel.string = `X${this._addition}`;
- this.additionSkeleton.setAnimation(0, 'jiasutiao_1', true);
- this.rateProgressBar.barSprite.node.active = false;
- }
- }
- },
- countDown: {
- get: function () {
- if (!this._countDown) {
- this._countDown = 0;
- }
- return this._countDown;
- },
- set: function (value) {
- this._countDown = value;
- this.countdownLabel.string = DWTool.calculateTime(this._countDown);
- this._preCountDown = this._countDown;
- }
- },
- rate: {
- get: function () {
- if (!this._rate) {
- this._rate = 0;
- }
- return this._rate;
- },
- set: function (value) {
- this._rate = value;
- if (this.addition > 0) {
- this._rate = this._rate * this.addition;
- }
- this.rateProgressLabel.string = DWTool.coinParse(this._rate);
- }
- },
- },
-
- onLoad() {
- this._currentTime = 0;
- this.humanList = [];
- this.isFirstLoad = true;
-
- this.setEventListener();
- },
-
- onDisable() {
- this.addition = 0;
- this.isFirstLoad = true;
- this.buildingInfo = null;
- for (let child of this.artistList.children) { child.destroy(); }
- for (let child of this.humanList) { child.destroy(); }
- this.countDown = 0;
- this.rate = 0;
- this._currentTime = 0;
- this.levelProgressBar.progress = 0;
- this.rateProgressBar.progress = 0;
- this.levelProgressLabel.string = "";
- },
- onDestroy() {
- GameEvent.off(GameNotificationKey.ResidentArtist, this);
- GameEvent.off(GameNotificationKey.RefreshLevelHomeArtistList, this);
- },
- setEventListener() {
-
- GameEvent.on(GameNotificationKey.ResidentArtist, this, (uid, buildingId) => {
- if (this.node.active && this.uid === uid && this.buildingInfo.buildingId === buildingId) {
- HomeApi.friendGetArtistsInBuilding(this.uid, this.buildingInfo.buildingId, (data) => {
- this.artists = data.list || [];
- this.artistListLayout();
-
- }, (code, msg) => {
- console.log(msg);
- })
- }
- });
-
- GameEvent.on(GameNotificationKey.RefreshLevelHomeArtistList, this, (uid, buildingId) => {
- if (this.node.active && this.uid === uid && this.buildingInfo.buildingId === buildingId) {
- HomeApi.friendGetArtistsInBuilding(this.uid, this.buildingInfo.buildingId, (data) => {
- this.artists = data.list || [];
- this.artistListLayout();
-
- }, (code, msg) => {
- console.log(msg);
- })
- }
- });
- },
-
- init(cityId, index) {
- if (arguments.length < 2) {
- throw new Error("init Missing parameter...");
- }
- this.cityId = cityId;
- this.index = index;
-
- ThemeManager.setBuildItemColor(this.cityId, this.bgNode);
- ThemeManager.setItemBuildSpriteFrame(this.cityId, this.buildSprite, index);
- ThemeManager.setItemPillarTopSpriteFrame(this.cityId, this.pillarTop);
- ThemeManager.setItemPillarBottomSpriteFrame(this.cityId, this.pillarBottom);
- ThemeManager.setItemPillarRightSpriteFrame(this.cityId, this.pillarRight);
- ThemeManager.setItemPillarLeftSpriteFrame(this.cityId, this.pillarLeft);
- ThemeManager.setItemDownSpriteFrame(this.cityId, this.bottomBg);
- let lockBottomSprite = this.lockBottomNode.getComponent(cc.Sprite);
- ThemeManager.setItemLockDownSpriteFrame(this.cityId, lockBottomSprite);
- },
-
- config(buildingInfo, uid) {
- if (arguments.length < 2) {
- throw new Error("Config Missing parameter...");
- }
- this.buildingInfo = buildingInfo;
- this.uid = uid;
- this.artists = this.buildingInfo.artists;
-
- this.countDown = buildingInfo.rateUnit;
- this.buildNameLabel.string = buildingInfo.name;
- this._notPickupCount = buildingInfo.coinCount;
- if (buildingInfo.coinCount === this.coinArrayMax * 10) {
- this.rateProgressBar.progress = 1;
- this.countdownLabel.string = DWTool.calculateTime(0);
- }
- this.levelProgressBar.progress = buildingInfo.level / Global.BuildingManager.getLevelCount(buildingInfo.buildingId);
- this.levelProgressLabel.string = `LV.${buildingInfo.level}`;
- if (this.isFirstLoad) {
- this.isFirstLoad = false;
- this.artistListLayout();
- }
- this.layout(buildingInfo);
- },
- artistListLayout() {
- for (let child of this.artistList.children) { child.destroy(); }
- for (let child of this.humanList) { child.destroy(); }
- let self = this;
- let addAddItemToList = function (showTop = false, showBottom = false) {
- let addArtistItem = cc.instantiate(self.artistListItem);
- self.artistList.addChild(addArtistItem);
- let addArtistScript = addArtistItem.getComponent('LevelHomeArtistItem');
- addArtistScript.initWithBuildingInfo(self.buildingInfo, self.uid, false, showTop, showBottom);
- }
- let addArtistItemToList = function (artist, showTop = false, showBottom = false) {
- let artistItem = cc.instantiate(self.artistListItem);
- self.artistList.addChild(artistItem);
- let artistScript = artistItem.getComponent('LevelHomeArtistItem');
- artistScript.initWithArtistData(self.buildingInfo, self.uid, false, artist, showTop, showBottom);
- }
- let addHuman = function (artist, index) {
- DWTool.loadResPrefab("./prefabs/artist_man")
- .then((prefab) => {
- let human = cc.instantiate(prefab);
- human.getComponent('ArtistMan').init(artist);
- human.getComponent('ArtistMan').direction = (index > 0) ? 1 : -1;
- self.node.addChild(human);
- self.humanList.push(human);
- });
- }
-
- if (this.artists.length === 0) {
- addAddItemToList(true);
-
- this.addition = 0;
- } else {
-
- this.additionNode.active = true;
- if (this.artists.length === 1) {
- let artist = this.artists[0];
- this.addition += artist.stationJobLevel + 1;
-
- if (artist.role === 2) {
- addArtistItemToList(artist, true, true);
- addHuman(artist, (Math.random() - 0.5) * 2);
- addAddItemToList();
-
- } else {
-
- addArtistItemToList(artist, true);
- addHuman(artist, (Math.random() - 0.5) * 2);
- }
- } else {
- for (let i = 0; i < this.artists.length; i++) {
- let artist = this.artists[i];
- this.addition += artist.stationJobLevel + 1;
- if (i === 0) {
- addArtistItemToList(artist, true, true);
- } else {
- addArtistItemToList(artist);
- }
- addHuman(artist, i);
- }
- }
- }
- },
- layout(buildingInfo) {
- this.rateProgressBar.progress = 1;
- if (buildingInfo.isUnlocked) {
- this.artistList.active = true;
- this.lockNode.active = false;
- this.rate = buildingInfo.rate;
- this.maxNode.active = (buildingInfo.hasNext != 1) ? true : false;
- } else {
- this.artistList.active = false;
- this.lockNode.active = true;
- this.countDown = 0;
-
- this.totalRate = 0;
- }
- },
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- });
|