1
0

ThemeManger.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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/textures/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(roomId, buildSprite) {
  39. if (Global.buildRes) {
  40. let picId = 30100 + parseInt(roomId);
  41. buildSprite.spriteFrame = this.getSpriteFrameByPath(`${picId}`);
  42. } else {
  43. DWTool.loadResSpriteFrame(`./textures/building/${picId}`)
  44. .then((spriteFrame) => {
  45. buildSprite.spriteFrame = spriteFrame;
  46. }).catch((err) => {
  47. console.log(err);
  48. });
  49. }
  50. }
  51. // 外墙顶部
  52. static setItemPillarTopSpriteFrame(cityId, pillar) {
  53. if (Global.buildRes) {
  54. let spriteFrame = this.getSpriteFrameByPath(`30${cityId}33`);
  55. pillar.spriteFrame = spriteFrame;
  56. } else {
  57. DWTool.loadResSpriteFrame(`./textures/building/30${cityId}33`)
  58. .then((spriteFrame) => {
  59. pillar.spriteFrame = spriteFrame;
  60. }).catch((err) => {
  61. console.log(err);
  62. });
  63. }
  64. }
  65. // 外墙底部
  66. static setItemPillarBottomSpriteFrame(cityId, pillar) {
  67. if (Global.buildRes) {
  68. let spriteFrame = this.getSpriteFrameByPath(`30${cityId}34`);
  69. pillar.spriteFrame = spriteFrame;
  70. } else {
  71. DWTool.loadResSpriteFrame(`./textures/building/30${cityId}34`)
  72. .then((spriteFrame) => {
  73. pillar.spriteFrame = spriteFrame;
  74. }).catch((err) => {
  75. console.log(err);
  76. });
  77. }
  78. }
  79. // 外墙右边
  80. static setItemPillarRightSpriteFrame(cityId, pillar) {
  81. if (Global.buildRes) {
  82. let spriteFrame = this.getSpriteFrameByPath(`30${cityId}35`);
  83. pillar.spriteFrame = spriteFrame;
  84. } else {
  85. DWTool.loadResSpriteFrame(`./textures/building/30${cityId}35`)
  86. .then((spriteFrame) => {
  87. pillar.spriteFrame = spriteFrame;
  88. }).catch((err) => {
  89. console.log(err);
  90. });
  91. }
  92. }
  93. // 外墙左边
  94. static setItemPillarLeftSpriteFrame(cityId, pillar) {
  95. if (Global.buildRes) {
  96. let spriteFrame = this.getSpriteFrameByPath(`30${cityId}36`);
  97. pillar.spriteFrame = spriteFrame;
  98. } else {
  99. DWTool.loadResSpriteFrame(`./textures/building/30${cityId}36`)
  100. .then((spriteFrame) => {
  101. pillar.spriteFrame = spriteFrame;
  102. }).catch((err) => {
  103. console.log(err);
  104. });
  105. }
  106. }
  107. static setItemPillarSpriteFrame(cityId, pillars) {
  108. if (Global.buildRes) {
  109. let spriteFrame = this.getSpriteFrameByPath(`${cityId}_pillar`);
  110. for (let i = 0; i < pillars.length; i++) {
  111. let sprite = pillars[i];
  112. sprite.spriteFrame = spriteFrame;
  113. }
  114. } else {
  115. DWTool.loadResSpriteFrame(`./textures/building/${cityId}_pillar`)
  116. .then((spriteFrame) => {
  117. for (let i = 0; i < pillars.length; i++) {
  118. let sprite = pillars[i];
  119. sprite.spriteFrame = spriteFrame;
  120. }
  121. }).catch((err) => {
  122. console.log(err);
  123. });
  124. }
  125. }
  126. static setItemDownSpriteFrame(cityId, lockBottomBg) {
  127. if (Global.buildRes) {
  128. lockBottomBg.spriteFrame = this.getSpriteFrameByPath(`30${cityId}16`);
  129. } else {
  130. DWTool.loadResSpriteFrame(`./textures/building/30${cityId}16`)
  131. .then((spriteFrame) => {
  132. lockBottomBg.spriteFrame = spriteFrame;
  133. }).catch((err) => {
  134. console.log(err);
  135. });
  136. }
  137. }
  138. static setItemLockDownSpriteFrame(lockBottomBg) {
  139. if (Global.buildRes) {
  140. lockBottomBg.spriteFrame = this.getSpriteFrameByPath(`30137`);
  141. } else {
  142. DWTool.loadResSpriteFrame(`./textures/building/30137`)
  143. .then((spriteFrame) => {
  144. lockBottomBg.spriteFrame = spriteFrame;
  145. }).catch((err) => {
  146. console.log(err);
  147. });
  148. }
  149. }
  150. // LevelHome最底层一楼样式变化
  151. static setBottomBuildSpriteFrame(cityId, buildSprite) {
  152. if (Global.buildRes) {
  153. buildSprite.spriteFrame = this.getSpriteFrameByPath(`30${cityId}38`);
  154. } else {
  155. DWTool.loadResSpriteFrame(`./textures/building/30${cityId}38`)
  156. .then((spriteFrame) => {
  157. buildSprite.spriteFrame = spriteFrame;
  158. }).catch((err) => {
  159. console.log(err);
  160. });
  161. }
  162. }
  163. // LevelHome最顶层楼顶样式变化
  164. static setTopBgBuildSpriteFrame(cityId, buildSprite) {
  165. if (Global.buildRes) {
  166. buildSprite.spriteFrame = this.getSpriteFrameByPath(`30${cityId}31`);
  167. } else {
  168. DWTool.loadResSpriteFrame(`./textures/building/30${cityId}31`)
  169. .then((spriteFrame) => {
  170. buildSprite.spriteFrame = spriteFrame;
  171. }).catch((err) => {
  172. console.log(err);
  173. });
  174. }
  175. }
  176. static setTopCoverSpriteFrame(cityId, coverSprite) {
  177. if (Global.buildRes) {
  178. coverSprite.spriteFrame = this.getSpriteFrameByPath(`30${cityId}32`);
  179. } else {
  180. DWTool.loadResSpriteFrame(`./textures/building/30${cityId}32`)
  181. .then((spriteFrame) => {
  182. coverSprite.spriteFrame = spriteFrame;
  183. }).catch((err) => {
  184. console.log(err);
  185. });
  186. }
  187. }
  188. }
  189. module.exports = ThemeManager;