ThemeManger.js 6.6 KB

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