RomanItem.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. var Global = require("Global");
  2. var GameProtocol = require("RomanGameProtocol");
  3. var LBItem = require("LBItem");
  4. const itemConfig = {
  5. "1": { //单个
  6. //框
  7. kw: 200,
  8. kh: 190,
  9. kx: -2,
  10. //遮罩
  11. mw: 168,
  12. mh: 142,
  13. mx: 14,
  14. my: -22,
  15. sx: 86,
  16. sy: -216,
  17. //动画
  18. bw: 168,
  19. bh: 182,
  20. bx: 14,
  21. by: 16,
  22. ax: 111,
  23. ay: -162
  24. },
  25. "2": { //两个
  26. //框
  27. kw: 200,
  28. kh: 339,
  29. kx: -2,
  30. //遮罩
  31. mw: 168,
  32. mh: 288,
  33. mx: 14,
  34. my: -22,
  35. sx: 86,
  36. sy: -216,
  37. //动画
  38. bw: 168,
  39. bh: 288,
  40. bx: 14,
  41. by: -22,
  42. ax: 111,
  43. ay: -169
  44. },
  45. "3": { //三个
  46. //框
  47. kw: 200,
  48. kh: 490,
  49. kx: -2,
  50. //遮罩
  51. mw: 168,
  52. mh: 440,
  53. mx: 14,
  54. my: -22,
  55. sx: 86,
  56. sy: -216,
  57. //动画
  58. bw: 168,
  59. bh: 440,
  60. bx: 14,
  61. by: -22,
  62. ax: 111,
  63. ay: -169
  64. },
  65. "6": { //六个
  66. //框
  67. kw: 423,
  68. kh: 490,
  69. kx: -7,
  70. //遮罩
  71. mw: 379,
  72. mh: 440,
  73. mx: 14,
  74. my: -22,
  75. sx: 200,
  76. sy: -216,
  77. //动画
  78. bw: 379,
  79. bh: 440,
  80. bx: 14,
  81. by: -22,
  82. ax: 200,
  83. ay: -169
  84. }
  85. }
  86. cc.Class({
  87. extends: LBItem,
  88. editor: {
  89. menu: 'Game/Roman/Item'
  90. },
  91. properties: {
  92. //特殊节点
  93. spNode: cc.Node,
  94. spAni: sp.Skeleton,
  95. kuang: cc.Node,
  96. mask: cc.Node,
  97. maskB: cc.Node,
  98. maskH: cc.Node,
  99. bAni: sp.Skeleton,
  100. hAni: sp.Skeleton,
  101. goldLabel: cc.Label,
  102. kuangAni: sp.Skeleton,
  103. _bBig: false,
  104. _totalCount: 1,
  105. config: null,
  106. aniFlag: false
  107. },
  108. // LIFE-CYCLE CALLBACKS:
  109. // onLoad () {
  110. // },
  111. setValue (_val, spineData, _sunV) {
  112. this._bBig = false//_val == GameProtocol.MAN_ICON || _val == GameProtocol.WOMAN_ICON;
  113. this.normalBG.active = true;//!this._bBig;
  114. // this.spNode.active = this._bBig;
  115. // this.spAni.skeletonData = spineData;
  116. this.aniNode.active = false;
  117. this.goldLabel.node.active = false;
  118. this.bSunCoin = _val == GameProtocol.SUN_ICON;
  119. if(this.bSunCoin) {
  120. this.setGoldLabel(_sunV);
  121. }
  122. if(_val>=0 && _val<=4){
  123. this.aniFlag = true;
  124. }else{
  125. this.aniFlag = false;
  126. }
  127. this._super(_val, spineData, _val == GameProtocol.SPECIAL_ICON);
  128. },
  129. getValue() {
  130. return this._value;
  131. },
  132. setGoldLabel(label) {
  133. // this.bSunCoin = true;
  134. this.goldLabel.node.active = true;
  135. this.goldLabel.string = Global.formatString2Score(label);
  136. },
  137. getGoldLabel() {
  138. return this.goldLabel.string;
  139. },
  140. playGoldCoinAni() {
  141. if(!this.bSunCoin) return;
  142. this.normalAni.setAnimation(0, "a4", false);
  143. this.normalAni.addAnimation(0, "a4", false);
  144. this.normalAni.addAnimation(0, "a4", false);
  145. this.normalAni.addAnimation(0, "a4", false);
  146. this.normalAni.addAnimation(0, "a1", true);
  147. this.goldLabel.node.stopAllActions();
  148. cc.tween(this.goldLabel.node)
  149. .sequence(
  150. cc.tween().to(0.3, {scaleX: 0, x:10}),
  151. cc.tween().to(0.6, {x:-10}),
  152. cc.tween().to(0.3, {scaleX: 1, x:0})
  153. )
  154. .repeat(4)
  155. // .to(0.3, {scaleX: 0, x:10})
  156. // .to(0.6, {x:-10})
  157. // .to(0.3, {scaleX: 1, x:0})
  158. .start()
  159. },
  160. playGetCoinAni() {
  161. if(!this.bSunCoin) return;
  162. this.normalAni.setAnimation(0, "a3", false);
  163. this.normalAni.addAnimation(0, "a1", true);
  164. cc.tween(this.goldLabel.node)
  165. .to(0.2, {scale: 1.5})
  166. .to(0.2, {scale: 1})
  167. .start()
  168. },
  169. showInSunGame() {
  170. this.normalBG.stopAllActions();
  171. this.normalBG.scale = 1;
  172. this.normalBG.active = true;
  173. // this.spNode.active = false;
  174. this.aniNode.active = false;
  175. this.normalAni.setAnimation(0, "a1", true);
  176. if(!this.bSunCoin) return;
  177. this.aniNode.active = true;
  178. this.kuangAni.setAnimation(0, "a2", true);
  179. },
  180. showGoldLight() {
  181. this.normalBG.stopAllActions();
  182. this.normalBG.scale = 1;
  183. this.normalBG.active = true;
  184. // this.spNode.active = false;
  185. this.aniNode.active = false;
  186. this.normalAni.setAnimation(0, "a2", false);
  187. this.normalAni.addAnimation(0, "a1", true);
  188. },
  189. setRowCount(_count) {
  190. this.node.active = true;
  191. return;
  192. _count = 1;
  193. this._totalCount = _count;
  194. this.config = null;
  195. this.node.active = _count >= 0;
  196. this.config = itemConfig[_count];
  197. this.setBigAniConfig();
  198. if(_count > 1) {
  199. // this.spAni.clearTracks();
  200. this.spAni.setAnimation(0, "a2", true);
  201. let name = "a2";
  202. if(this._value == GameProtocol.WOMAN_ICON) {
  203. name = "b2";
  204. }
  205. // this.bAni.clearTracks();
  206. this.bAni.setAnimation(0, name, true);
  207. // this.hAni.clearTracks();
  208. this.hAni.setAnimation(0, "c1", true);
  209. }
  210. },
  211. setBigAniConfig() {
  212. if(!this.config) return;
  213. this.spAni.node.x = this.config.sx;
  214. this.spAni.node.y = this.config.sy;
  215. if(this._value == GameProtocol.WOMAN_ICON) {
  216. this.spAni.node.x = this.config.ax;
  217. this.spAni.node.y = this.config.ay;
  218. }
  219. //框
  220. this.kuang.width = this.config.kw;
  221. this.kuang.height = this.config.kh;
  222. this.kuang.x = this.config.kx;
  223. //任务动画遮罩
  224. this.mask.width = this.config.bw;
  225. this.mask.height = this.config.bh;
  226. this.mask.x = this.config.bx;
  227. this.mask.y = this.config.by;
  228. //背景遮罩
  229. this.maskB.width = this.config.mw;
  230. this.maskB.height = this.config.mh;
  231. this.maskB.x = this.config.mx;
  232. this.maskB.y = this.config.my;
  233. //花瓣遮罩
  234. this.maskH.width = this.config.mw;
  235. this.maskH.height = this.config.mh;
  236. this.maskH.x = this.config.mx;
  237. this.maskH.y = this.config.my;
  238. this.bAni.node.x = this.config.sx;
  239. this.bAni.node.y = this.config.sy;
  240. this.hAni.node.x = this.config.sx;
  241. this.hAni.node.y = this.config.sy;
  242. // this.spAni.clearTracks();
  243. // this.spAni.setAnimation(0, "a2", true);
  244. },
  245. showAppearAction() {
  246. if(this._totalCount < 2) {
  247. return;
  248. }
  249. this.spNode.stopAllActions();
  250. this.spNode.scale = 0;
  251. cc.tween(this.spNode)
  252. .to(0.3, {scale: 1})
  253. .start()
  254. },
  255. resetShow() {
  256. if(this._totalCount > 1 || this._totalCount < 0) {
  257. return;
  258. }
  259. this.showNormal();
  260. },
  261. showNormal() {
  262. this.normalBG.stopAllActions();
  263. this.normalBG.scale = 1;
  264. this.aniNode.active = false;
  265. // this.normalAni.clearTracks();
  266. this.normalAni.setAnimation(0, "a1", true);
  267. this.node.getComponent(cc.Animation).setCurrentTime(0);
  268. this.node.getComponent(cc.Animation).stop();
  269. if(this._bBig) {
  270. this.showBigSingle();
  271. }
  272. },
  273. showBigSingle() {
  274. //动画
  275. // this.spAni.clearTracks();
  276. this.spAni.setAnimation(0, "a1", true);
  277. let name = "a1";
  278. if(this._value == GameProtocol.WOMAN_ICON) {
  279. name = "b1";
  280. }
  281. // this.bAni.clearTracks();
  282. this.bAni.setAnimation(0, name, true);
  283. // this.hAni.clearTracks();
  284. this.hAni.setAnimation(0, "c1", true);
  285. this._totalCount = 1;
  286. this.config = itemConfig[this._totalCount];
  287. this.setBigAniConfig();
  288. },
  289. showLightAni() {
  290. if(this._totalCount > 1) {
  291. return;
  292. }
  293. if(this._lineCount <= 0) {
  294. this.showNormal();
  295. return;
  296. }
  297. this.aniNode.active = false;
  298. this.normalBG.stopAllActions();
  299. // this.normalAni.clearTracks();
  300. this.normalAni.setAnimation(0, "a2", true);
  301. if(this.aniFlag)
  302. this.node.getComponent(cc.Animation).play();
  303. // this.spAni.clearTracks();
  304. // this.spAni.setAnimation(0, "a2", true);
  305. },
  306. showSpecialAni() {
  307. if(!this._bSpecial) {
  308. // this.showNormal();
  309. return;
  310. }
  311. this.normalBG.stopAllActions();
  312. // this.normalAni.clearTracks();
  313. this.normalAni.setAnimation(0, "a2", true);
  314. // this.spAni.clearTracks();
  315. // this.spAni.setAnimation(0, "a2", true);
  316. },
  317. // update (dt) {},
  318. });