123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- const DWTool = require("./DWTool");
- class ThemeManager {
- static setBuildItemColor(cityId, node) {
- var color;
- switch (cityId) {
- case 1:
- color = new cc.color('#41b3e9');
- break;
- case 2:
- color = new cc.color('#81f9c8');
- break;
- case 3:
- color = new cc.color('#ffffc0');
- break;
- case 4:
- color = new cc.color('#360f5a');
- break;
- case 5:
- color = new cc.color('#00ddf2');
- break;
- default:
- color = new cc.color('#41b3e9');
- break;
- }
- node.color = color;
- }
- static getSpriteFrameByPath(path) {
- let filePath = `resources/building/${path}`;
- let uuid = cc.loader._getResUuid(filePath.slice(10), cc.Texture2D, true);
-
- let result = Global.buildRes.filter((item) => { return item._uuid === uuid });
- if (result != null && result.length != undefined) {
- let texture = result[0];
- return new cc.SpriteFrame(texture);
- }
- return null;
- }
- // LevelHomeItem 样式变化
- static setItemBuildSpriteFrame(cityId, buildSprite, index) {
- if (Global.buildRes) {
- buildSprite.spriteFrame = this.getSpriteFrameByPath(`30${cityId}0${index}`);
- } else {
- DWTool.loadResSpriteFrame(`./building/30${cityId}0${index}`)
- .then((spriteFrame) => {
- buildSprite.spriteFrame = spriteFrame;
- }).catch((err) => {
- console.log(err);
- });
- }
- }
- // 外墙顶部
- static setItemPillarTopSpriteFrame(cityId, pillar) {
- if (Global.buildRes) {
- let spriteFrame = this.getSpriteFrameByPath(`30${cityId}08`);
- pillar.spriteFrame = spriteFrame;
- } else {
- DWTool.loadResSpriteFrame(`./building/30${cityId}08`)
- .then((spriteFrame) => {
- pillar.spriteFrame = spriteFrame;
- }).catch((err) => {
- console.log(err);
- });
- }
- }
- // 外墙底部
- static setItemPillarBottomSpriteFrame(cityId, pillar) {
- if (Global.buildRes) {
- let spriteFrame = this.getSpriteFrameByPath(`30${cityId}09`);
- pillar.spriteFrame = spriteFrame;
- } else {
- DWTool.loadResSpriteFrame(`./building/30${cityId}09`)
- .then((spriteFrame) => {
- pillar.spriteFrame = spriteFrame;
- }).catch((err) => {
- console.log(err);
- });
- }
- }
- // 外墙右边
- static setItemPillarRightSpriteFrame(cityId, pillar) {
- if (Global.buildRes) {
- let spriteFrame = this.getSpriteFrameByPath(`30${cityId}10`);
- pillar.spriteFrame = spriteFrame;
- } else {
- DWTool.loadResSpriteFrame(`./building/30${cityId}10`)
- .then((spriteFrame) => {
- pillar.spriteFrame = spriteFrame;
- }).catch((err) => {
- console.log(err);
- });
- }
- }
- // 外墙左边
- static setItemPillarLeftSpriteFrame(cityId, pillar) {
- if (Global.buildRes) {
- let spriteFrame = this.getSpriteFrameByPath(`30${cityId}11`);
- pillar.spriteFrame = spriteFrame;
- } else {
- DWTool.loadResSpriteFrame(`./building/30${cityId}11`)
- .then((spriteFrame) => {
- pillar.spriteFrame = spriteFrame;
- }).catch((err) => {
- console.log(err);
- });
- }
- }
- static setItemPillarSpriteFrame(cityId, pillars) {
- if (Global.buildRes) {
- let spriteFrame = this.getSpriteFrameByPath(`${cityId}_pillar`);
- for (let i = 0; i < pillars.length; i++) {
- let sprite = pillars[i];
- sprite.spriteFrame = spriteFrame;
- }
- } else {
- DWTool.loadResSpriteFrame(`./building/${cityId}_pillar`)
- .then((spriteFrame) => {
- for (let i = 0; i < pillars.length; i++) {
- let sprite = pillars[i];
- sprite.spriteFrame = spriteFrame;
- }
- }).catch((err) => {
- console.log(err);
- });
- }
- }
- static setItemDownSpriteFrame(cityId, lockBottomBg) {
- if (Global.buildRes) {
- lockBottomBg.spriteFrame = this.getSpriteFrameByPath(`30${cityId}16`);
- } else {
- DWTool.loadResSpriteFrame(`./building/30${cityId}16`)
- .then((spriteFrame) => {
- lockBottomBg.spriteFrame = spriteFrame;
- }).catch((err) => {
- console.log(err);
- });
- }
- }
- static setItemLockDownSpriteFrame(cityId, lockBottomBg) {
- if (Global.buildRes) {
- lockBottomBg.spriteFrame = this.getSpriteFrameByPath(`30${cityId}12`);
- } else {
- DWTool.loadResSpriteFrame(`./building/30${cityId}12`)
- .then((spriteFrame) => {
- lockBottomBg.spriteFrame = spriteFrame;
- }).catch((err) => {
- console.log(err);
- });
- }
- }
- // LevelHomeBottom 样式变化
- static setBottomBuildSpriteFrame(cityId, buildSprite) {
- if (Global.buildRes) {
- buildSprite.spriteFrame = this.getSpriteFrameByPath(`30${cityId}13`);
- } else {
- DWTool.loadResSpriteFrame(`./building/30${cityId}13`)
- .then((spriteFrame) => {
- buildSprite.spriteFrame = spriteFrame;
- }).catch((err) => {
- console.log(err);
- });
- }
- }
- // LevelHomeTop 样式变化
- static setTopBgBuildSpriteFrame(cityId, buildSprite) {
-
- if (Global.buildRes) {
- buildSprite.spriteFrame = this.getSpriteFrameByPath(`30${cityId}06`);
- } else {
- DWTool.loadResSpriteFrame(`./building/30${cityId}06`)
- .then((spriteFrame) => {
- buildSprite.spriteFrame = spriteFrame;
- }).catch((err) => {
- console.log(err);
- });
- }
- }
- static setTopCoverSpriteFrame(cityId, coverSprite) {
-
- if (Global.buildRes) {
- coverSprite.spriteFrame = this.getSpriteFrameByPath(`30${cityId}07`);
- } else {
- DWTool.loadResSpriteFrame(`./building/30${cityId}07`)
- .then((spriteFrame) => {
- coverSprite.spriteFrame = spriteFrame;
- }).catch((err) => {
- console.log(err);
- });
- }
- }
- }
- module.exports = ThemeManager;
|