ThemeManger.js 6.2 KB

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