123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- const DWTool = require("../utils/DWTool");
- const HomeApi = require("../net/HomeApi");
- const { GameNotificationKey } = require("../utils/GameEnum");
- const Base64 = require("../lib/Base64").Base64;
- const AlertManager = require("../utils/AlertManager");
- cc.Class({
- extends: cc.Component,
- properties: {
- content: cc.Node,
- scrollView: cc.ScrollView,
- talentBtn: cc.Button,
- confirmBtn: cc.Button,
- },
- init(buildingInfo, uid, isSelf) {
- this.buildingInfo = buildingInfo;
- this.uid = uid;
- this.isSelf = isSelf;
- },
-
- onLoad() {
- this.node.height = cc.view.getVisibleSize().height;
- this.contentY = this.content.y = (this.content.height - this.node.height) / 2;
- this._residentList = [];
- this._itemScripts = [];
- this._currentResidentArtist = null;
- this.getNetworkData();
- GameEvent.on(GameNotificationKey.RefreshResidentArtistList, this, () => {
- for (let child of this.scrollView.content.children) {
- child.destroy();
- }
- this.getNetworkData();
- });
- this.confirmEvent = _.debounce(() => {
- if (this._currentResidentArtist && !this._currentResidentArtist.isStationed) {
- let reportFormInfo = {};
- reportFormInfo["artistUid"] = this._currentResidentArtist.uid;
- reportFormInfo["buildingId"] = this.buildingInfo.buildingId;
- reportFormInfo["buildingLevel"] = this.buildingInfo.level;
- reportFormInfo["targetUid"] = this.uid;
- HomeApi.friendStation(JSON.stringify(reportFormInfo), (responseData) => {
- this.close();
-
- GameEvent.fire(GameNotificationKey.ResidentArtist, this.uid, this.buildingInfo.buildingId);
-
- GameEvent.fire(GameNotificationKey.NoticeRoleOpt, this.uid, 5)
- }, (code, msg) => {
-
- if (code === 814) {
- AlertManager.showIntimacyBotEnough();
- }
- console.log(msg);
- });
- } else {
- this.node.destroy();
- }
- }, 1000, true);
- this.showTalentEvent = _.debounce(() => {
- this.close();
- AlertManager.showTalentAlert();
- }, 1000, true);
- },
- onDestroy() {
- GameEvent.off(GameNotificationKey.RefreshResidentArtistList, this);
- },
- start() {
- this.content.y = -cc.view.getVisibleSize().height;
- let s = cc.sequence(cc.moveTo(0.2, 0, this.contentY + 20).easing(cc.easeCubicActionOut()), cc.moveBy(0.05, 0, -20));
- this.content.runAction(s);
- },
- getNetworkData() {
- HomeApi.friendGetArtistsByBuildingId(this.uid, this.buildingInfo.buildingId, (responseData) => {
- this._residentList = responseData.list || [];
- this.canBeStationedList = this._residentList.filter(item => item.canBeStationed == 1);
- this.cannotBeStationedList = this._residentList.filter(item => item.canBeStationed == 0);
- if (this.canBeStationedList.length === 0) {
- this.talentBtn.node.active = true;
- this.confirmBtn.node.active = false;
- } else {
- this.talentBtn.node.active = false;
- this.confirmBtn.node.active = true;
- }
- this.layout();
- }, (err) => {
- console.log(err);
- });
- },
- layout() {
- if (this._residentList.length === 0) {
-
- this.loadTaletPrefab()
- .then((result) => {
- let item = cc.instantiate(result);
- this.scrollView.content.addChild(item);
- });
- } else {
- if (this.canBeStationedList.length === 0) {
-
- this.loadTaletPrefab()
- .then((talent) => {
- let item = cc.instantiate(talent);
- this.scrollView.content.addChild(item);
- return this.loadDashPrefab();
- })
- .then((dash) => {
- let item = cc.instantiate(dash);
- this.scrollView.content.addChild(item);
- return this.loadPlaceholderItemPrefab();
- })
- .then((cannotBeStationedItem) => {
- for (let i = 0; i < this.cannotBeStationedList.length; i++) {
- let item = cc.instantiate(cannotBeStationedItem);
- let itemScript = item.getComponent(`ArtistResidentItemPlaceholder`);
- itemScript.init(this.cannotBeStationedList[i]);
- this.scrollView.content.addChild(item);
- }
- }).catch((err) => {
- console.log(err);
- });
- } else {
- this.loadItemPrefab()
- .then((canBeStationedItem) => {
- for (let i = 0; i < this.canBeStationedList.length; i++) {
- let item = cc.instantiate(canBeStationedItem);
- let itemScript = item.getComponent(`ArtistResidentItem`);
- this._itemScripts.push(itemScript)
- itemScript.init(this.uid, this.buildingInfo, this.isSelf, this.canBeStationedList[i], (artistData) => {
- this._currentResidentArtist = artistData;
- this._itemScripts.forEach(itemScript => {
- itemScript.setStyle(this._currentResidentArtist.uid);
- });
- });
- this.scrollView.content.addChild(item);
- }
- if (this.cannotBeStationedList.length > 0) {
- return this.loadDashPrefab();
- }
- return;
- })
- .then((dash) => {
- if (!dash) { return; }
- let item = cc.instantiate(dash);
- this.scrollView.content.addChild(item);
- return this.loadPlaceholderItemPrefab();
- })
- .then((cannotBeStationedItem) => {
- if (!cannotBeStationedItem) { return; }
- for (let i = 0; i < this.cannotBeStationedList.length; i++) {
- let item = cc.instantiate(cannotBeStationedItem);
- let itemScript = item.getComponent(`ArtistResidentItemPlaceholder`);
- itemScript.init(this.cannotBeStationedList[i]);
- this.scrollView.content.addChild(item);
- }
- }).catch((err) => {
- console.log(err);
- });
- }
- }
- },
- guide() {
- if (this._itemScripts.length > 0) {
- let itemScript = this._itemScripts[0];
- itemScript.selectItem();
- }
- },
-
- loadTaletPrefab() {
- return new Promise((resolve, reject) => {
- cc.loader.loadRes('./prefabs/artist_resident_talent', cc.Prefab, (error, prefab) => {
- if (error) {
- reject(error);
- } else {
- resolve(prefab)
- }
- });
- });
- },
-
- loadDashPrefab() {
- return new Promise((resolve, reject) => {
- cc.loader.loadRes('./prefabs/artist_resident_dash', cc.Prefab, (error, prefab) => {
- if (error) {
- reject(error);
- } else {
- resolve(prefab)
- }
- });
- });
- },
- loadItemPrefab() {
- return new Promise((resolve, reject) => {
- cc.loader.loadRes('./prefabs/artist_resident_item', cc.Prefab, (error, prefab) => {
- if (error) {
- reject(error);
- } else {
- resolve(prefab)
- }
- });
- });
- },
- loadPlaceholderItemPrefab() {
- return new Promise((resolve, reject) => {
- cc.loader.loadRes('./prefabs/artist_resident_item_placeholder', cc.Prefab, (error, prefab) => {
- if (error) {
- reject(error);
- } else {
- resolve(prefab)
- }
- });
- });
- },
- confirm() {
- this.confirmEvent();
- },
- showTalent() {
- this.showTalentEvent();
- },
- close() {
- let finish = cc.callFunc(() => {
- this.node.destroy();
- }, this)
- this.content.runAction(cc.sequence(cc.moveTo(0.2, 0, -cc.view.getVisibleSize().height).easing(cc.easeCubicActionIn()), finish));
-
- },
-
- });
|