ThemeManger.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. const DWTool = require("./DWTool");
  2. class ThemeManager {
  3. static setBuildItemColor(cityId, node) {
  4. var color;
  5. switch (cityId) {
  6. case 1:
  7. color = new cc.color('#41b3e9');
  8. break;
  9. case 2:
  10. color = new cc.color('#81f9c8');
  11. break;
  12. case 3:
  13. color = new cc.color('#ffffc0');
  14. break;
  15. case 4:
  16. color = new cc.color('#360f5a');
  17. break;
  18. default:
  19. color = new cc.color('#41b3e9');
  20. break;
  21. }
  22. node.color = color;
  23. }
  24. static getSpriteFrameByPath(path) {
  25. let filePath = `resources/building/${path}`;
  26. let uuid = cc.loader._getResUuid(filePath.slice(10), cc.Texture2D, true);
  27. let result = Global.buildRes.filter((item) => { return item._uuid === uuid });
  28. if (result != null && result.length != undefined) {
  29. let texture = result[0];
  30. return new cc.SpriteFrame(texture);
  31. }
  32. return null;
  33. }
  34. // LevelHomeItem 样式变化
  35. static setItemBuildSpriteFrame(cityId, buildSprite, index) {
  36. cityId = cityId >= 5 ? 1 : cityId
  37. if (Global.buildRes) {
  38. buildSprite.spriteFrame = this.getSpriteFrameByPath(`30${cityId}0${index}`);
  39. } else {
  40. DWTool.loadResSpriteFrame(`./building/30${cityId}0${index}`)
  41. .then((spriteFrame) => {
  42. buildSprite.spriteFrame = spriteFrame;
  43. }).catch((err) => {
  44. console.log(err);
  45. });
  46. }
  47. }
  48. // 外墙顶部
  49. static setItemPillarTopSpriteFrame(cityId, pillar) {
  50. cityId = cityId >= 5 ? 1 : cityId
  51. if (Global.buildRes) {
  52. let spriteFrame = this.getSpriteFrameByPath(`30${cityId}08`);
  53. pillar.spriteFrame = spriteFrame;
  54. } else {
  55. DWTool.loadResSpriteFrame(`./building/30${cityId}08`)
  56. .then((spriteFrame) => {
  57. pillar.spriteFrame = spriteFrame;
  58. }).catch((err) => {
  59. console.log(err);
  60. });
  61. }
  62. }
  63. // 外墙底部
  64. static setItemPillarBottomSpriteFrame(cityId, pillar) {
  65. cityId = cityId >= 5 ? 1 : cityId
  66. if (Global.buildRes) {
  67. let spriteFrame = this.getSpriteFrameByPath(`30${cityId}09`);
  68. pillar.spriteFrame = spriteFrame;
  69. } else {
  70. DWTool.loadResSpriteFrame(`./building/30${cityId}09`)
  71. .then((spriteFrame) => {
  72. pillar.spriteFrame = spriteFrame;
  73. }).catch((err) => {
  74. console.log(err);
  75. });
  76. }
  77. }
  78. // 外墙右边
  79. static setItemPillarRightSpriteFrame(cityId, pillar) {
  80. cityId = cityId >= 5 ? 1 : cityId
  81. if (Global.buildRes) {
  82. let spriteFrame = this.getSpriteFrameByPath(`30${cityId}10`);
  83. pillar.spriteFrame = spriteFrame;
  84. } else {
  85. DWTool.loadResSpriteFrame(`./building/30${cityId}10`)
  86. .then((spriteFrame) => {
  87. pillar.spriteFrame = spriteFrame;
  88. }).catch((err) => {
  89. console.log(err);
  90. });
  91. }
  92. }
  93. // 外墙左边
  94. static setItemPillarLeftSpriteFrame(cityId, pillar) {
  95. cityId = cityId >= 5 ? 1 : cityId
  96. if (Global.buildRes) {
  97. let spriteFrame = this.getSpriteFrameByPath(`30${cityId}11`);
  98. pillar.spriteFrame = spriteFrame;
  99. } else {
  100. DWTool.loadResSpriteFrame(`./building/30${cityId}11`)
  101. .then((spriteFrame) => {
  102. pillar.spriteFrame = spriteFrame;
  103. }).catch((err) => {
  104. console.log(err);
  105. });
  106. }
  107. }
  108. static setItemPillarSpriteFrame(cityId, pillars) {
  109. cityId = cityId >= 5 ? 1 : cityId
  110. if (Global.buildRes) {
  111. let spriteFrame = this.getSpriteFrameByPath(`${cityId}_pillar`);
  112. for (let i = 0; i < pillars.length; i++) {
  113. let sprite = pillars[i];
  114. sprite.spriteFrame = spriteFrame;
  115. }
  116. } else {
  117. DWTool.loadResSpriteFrame(`./building/${cityId}_pillar`)
  118. .then((spriteFrame) => {
  119. for (let i = 0; i < pillars.length; i++) {
  120. let sprite = pillars[i];
  121. sprite.spriteFrame = spriteFrame;
  122. }
  123. }).catch((err) => {
  124. console.log(err);
  125. });
  126. }
  127. }
  128. static setItemDownSpriteFrame(cityId, lockBottomBg) {
  129. cityId = cityId >= 5 ? 1 : cityId
  130. if (Global.buildRes) {
  131. lockBottomBg.spriteFrame = this.getSpriteFrameByPath(`30${cityId}16`);
  132. } else {
  133. DWTool.loadResSpriteFrame(`./building/30${cityId}16`)
  134. .then((spriteFrame) => {
  135. lockBottomBg.spriteFrame = spriteFrame;
  136. }).catch((err) => {
  137. console.log(err);
  138. });
  139. }
  140. }
  141. static setItemLockDownSpriteFrame(cityId, lockBottomBg) {
  142. cityId = cityId >= 5 ? 1 : cityId
  143. if (Global.buildRes) {
  144. lockBottomBg.spriteFrame = this.getSpriteFrameByPath(`30${cityId}12`);
  145. } else {
  146. DWTool.loadResSpriteFrame(`./building/30${cityId}12`)
  147. .then((spriteFrame) => {
  148. lockBottomBg.spriteFrame = spriteFrame;
  149. }).catch((err) => {
  150. console.log(err);
  151. });
  152. }
  153. }
  154. // LevelHomeBottom 样式变化
  155. static setBottomBuildSpriteFrame(cityId, buildSprite) {
  156. cityId = cityId >= 5 ? 1 : cityId
  157. if (Global.buildRes) {
  158. buildSprite.spriteFrame = this.getSpriteFrameByPath(`30${cityId}13`);
  159. } else {
  160. DWTool.loadResSpriteFrame(`./building/30${cityId}13`)
  161. .then((spriteFrame) => {
  162. buildSprite.spriteFrame = spriteFrame;
  163. }).catch((err) => {
  164. console.log(err);
  165. });
  166. }
  167. }
  168. // LevelHomeTop 样式变化
  169. static setTopBgBuildSpriteFrame(cityId, buildSprite) {
  170. cityId = cityId >= 5 ? 1 : cityId
  171. if (Global.buildRes) {
  172. buildSprite.spriteFrame = this.getSpriteFrameByPath(`30${cityId}06`);
  173. } else {
  174. DWTool.loadResSpriteFrame(`./building/30${cityId}06`)
  175. .then((spriteFrame) => {
  176. buildSprite.spriteFrame = spriteFrame;
  177. }).catch((err) => {
  178. console.log(err);
  179. });
  180. }
  181. }
  182. static setTopCoverSpriteFrame(cityId, coverSprite) {
  183. cityId = cityId >= 5 ? 1 : cityId
  184. if (Global.buildRes) {
  185. coverSprite.spriteFrame = this.getSpriteFrameByPath(`30${cityId}07`);
  186. } else {
  187. DWTool.loadResSpriteFrame(`./building/30${cityId}07`)
  188. .then((spriteFrame) => {
  189. coverSprite.spriteFrame = spriteFrame;
  190. }).catch((err) => {
  191. console.log(err);
  192. });
  193. }
  194. }
  195. }
  196. module.exports = ThemeManager;