TurnTable.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. cc.Class({
  2. extends: cc.BaseClass,
  3. ctor: function () {
  4. this.m_LastIndex = 0;
  5. this.m_LastRotation = 0;
  6. this.m_BaseTurns = 5;
  7. this.m_BaseRate = 60;
  8. this.m_BaseItemCnt = 6;
  9. this.m_CurIndex = 0;
  10. this.m_TotalCnt = 0;
  11. this.m_UserCnt = 0;
  12. this.m_ResInfo = null;
  13. },
  14. onLoad: function () {
  15. this.m_BasicSound = new Array();
  16. this.m_BasicSound[0] = ['TURN','Audio/turn'];
  17. this.m_BasicSound[1] = ['AWARD','Audio/award'];
  18. cc.gSoundRes.LoadSoundArr(this.m_BasicSound,'TurnTable');
  19. this.m_TurnNode = this.$('bg/wheel');
  20. this.m_LabShareInfo = this.$('textContent/ShareInfo@Label');
  21. this.m_LabSignInfo = this.$('textContent/SignInfo@Label');
  22. this.m_LabGameCntInfo = this.$('textContent/GameCntInfo@Label');
  23. this.m_LabCnt = this.$('turnNode/LeftCnt@Label');
  24. this.m_pointer = this.$('turnNode/pointer@SpineAnimationCtrl');
  25. this.m_BtTurn = this.$('turnNode/BtTurn@Button');
  26. this.m_selectEffect = this.$('turnNode/selectEffect@SpineAnimationCtrl');
  27. this.m_turnEffect = this.$('turnNode/turnEffect');
  28. this.m_clickEffect = this.$('turnNode/BtTurn/clickEffect@SpineAnimationCtrl');
  29. this.m_showLight = this.$('turnNode/showLight');
  30. this.m_AwardRes = this.$('AwardNode');
  31. },
  32. ShowView: function () {
  33. this.m_TotalCnt = 0;
  34. var webUrl = window.PHP_HOME + '/Lottery.php?&GetMark=0';
  35. var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  36. webUrl += '&dwUserID=' + pGlobalUserData.dwUserID;
  37. WebCenter.GetData(webUrl, 0, function (data) {
  38. var res = JSON.parse(data);
  39. console.log(res);
  40. this.m_TotalCnt += res.IsShare == 0 ? 0 : 1;
  41. this.m_TotalCnt += res.IsSign == 0 ? 0 : 1;
  42. this.m_TotalCnt += res.GameCnt == 0 ? 0 : Math.floor(res.GameCnt / 10);
  43. this.m_TotalCnt += res.FreeCnt ? res.FreeCnt : 0;
  44. this.m_UserCnt = res.UserCnt;
  45. this.initView(res);
  46. }.bind(this));
  47. this.node.active = true;
  48. this.m_AwardRes.active = false;
  49. this.m_showLight.active = true;
  50. this.m_clickEffect.playAnimation("idle", true);
  51. this.m_pointer.playAnimation("idle", true);
  52. this.m_selectEffect.playAnimation("idle", true);
  53. this.m_turnEffect.active = false;
  54. this.m_selectEffect.node.active = false;
  55. this.isSet = true;
  56. this.m_turning = false;
  57. this.isFirst = true;
  58. },
  59. initView: function (res) {
  60. /**
  61. * 1.每日分享一次游藏,可得一次轉盤抽獎。
  62. * 2.每日登錄可獲得一次轉盤抽獎。
  63. * 3.每日進行10局遊戲,可参與一次轉盤抽獎。(今日已进行1局,再去打9局即可抽獎)
  64. */
  65. const PlayCount = 10;
  66. this.m_LabShareInfo.node.color = res.IsShare == 0 ? cc.color(97, 65, 16) : cc.color(0, 255, 0);
  67. this.m_LabSignInfo.node.color = res.IsSign == 0 ? cc.color(97, 65, 16) : cc.color(0, 255, 0);
  68. this.m_LabGameCntInfo.node.color = res.GameCnt < PlayCount ? cc.color(97, 65, 16) : cc.color(0, 255, 0);
  69. this.m_LabShareInfo.string = `1.每日分享一次游藏,可得一次轉盤抽獎。${res.IsShare != 0 ? "√" : ""}`;
  70. this.m_LabSignInfo.string = `2.每日登錄可獲得一次轉盤抽獎。${res.IsSign != 0 ? "√" : ""}`;
  71. this.m_LabGameCntInfo.string = `3.每日進行10局遊戲,可参與一次轉盤抽獎。(${res.GameCnt}/${PlayCount})${res.GameCnt >= PlayCount ? "√" : ""}`
  72. this._updateLeftDrawCount();
  73. this._updateTurnStatus();
  74. },
  75. _setView() {
  76. if (this.isSet) {
  77. return;
  78. }
  79. this.isSet = true;
  80. this.m_pointer.playAnimation("idle", true);
  81. this.m_selectEffect.playAnimation("idle", true);
  82. this.m_turnEffect.active = false;
  83. this.m_selectEffect.node.active = false;
  84. },
  85. onBtTurn: function () {
  86. // if (this.m_turning) {
  87. // return;
  88. // }
  89. // this._setView();
  90. // this.m_turning = true;
  91. // this.m_clickEffect.playAnimation("touch", false, true, "idle", true);
  92. // this.m_showLight.active = false;
  93. // this.TurnAcion();
  94. // return
  95. if (this.m_turning) {
  96. return;
  97. }
  98. this._setView();
  99. if (this.m_TotalCnt - this.m_UserCnt == 0) {
  100. this.ShowAlert('次数已用完,不能抽奖');
  101. return;
  102. }
  103. this.m_turning = true;
  104. this.m_clickEffect.playAnimation("touch", false, true, "idle", true);
  105. this.m_showLight.active = false;
  106. var webUrl = window.PHP_HOME + '/Lottery.php?&GetMark=1';
  107. var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  108. webUrl += '&dwUserID=' + pGlobalUserData.dwUserID;
  109. WebCenter.GetData(webUrl, 0, function (data) {
  110. var res = JSON.parse(data);
  111. if (res.resCode == 1) {
  112. this.ShowAlert('抽奖失败,请联系管理员');
  113. this.m_turning = false;
  114. return;
  115. }
  116. this.m_ResInfo = res.resLottery;
  117. console.log(res);
  118. this.m_CurIndex = res.resLottery[0];
  119. this.TurnAcion();
  120. this.m_UserCnt++;
  121. this.m_LastIndex = this.m_CurIndex;
  122. }.bind(this));
  123. },
  124. TurnAcion: function () {
  125. this.isSet = false;
  126. this.m_turnEffect.active = true;
  127. this.m_turnEffect.opacity = 0;
  128. cc.tween(this.m_turnEffect)
  129. .to(1/6, { opacity: 255 })
  130. .start();
  131. console.log('m_LastIndex:'+this.m_LastIndex);
  132. console.log('m_LastIndex:'+this.m_CurIndex);
  133. var totalRotation = -360 * this.m_BaseTurns - (this.isFirst ? 30 : 0);
  134. var offsetR = 0;
  135. if (this.m_CurIndex > this.m_LastIndex) {
  136. offsetR = this.m_BaseItemCnt + this.m_LastIndex - this.m_CurIndex ;
  137. } else {
  138. offsetR = this.m_LastIndex - this.m_CurIndex;
  139. }
  140. console.log('offsetR:'+offsetR);
  141. totalRotation -= offsetR * this.m_BaseRate;
  142. cc.gSoundRes.PlaySound('TURN');
  143. let turnCallback = () => {
  144. console.log('finish!!!');
  145. this.isFirst = false;
  146. this._showGotEffect();
  147. this._updateTurnStatus();
  148. this._updateLeftDrawCount();
  149. var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  150. pGlobalUserData.llUserIngot = parseInt(pGlobalUserData.llUserIngot) + parseInt(this.m_ResInfo[2]);
  151. this.m_Hook.OnUpdateCard();
  152. this.onShowAward();
  153. this.m_turning = false;
  154. };
  155. cc.tween(this.m_TurnNode)
  156. .by(5, { angle: totalRotation }, { easing: 'quadInOut' })
  157. .call(turnCallback)
  158. .start();
  159. },
  160. _showGotEffect() {
  161. cc.tween(this.m_turnEffect)
  162. .to(1/6, { opacity: 0 })
  163. .set({ opacity: 255, active: false })
  164. .start();
  165. this.m_selectEffect.playAnimation("touch", true);
  166. this.m_pointer.playAnimation("touch", true);
  167. },
  168. _updateLeftDrawCount() {
  169. let leftCount = this.m_TotalCnt - this.m_UserCnt;
  170. if (leftCount < 0) {
  171. leftCount = 0;
  172. }
  173. this.m_LabCnt.string = `今日剩餘抽獎次數:${leftCount}次`;
  174. },
  175. _updateTurnStatus() {
  176. this.m_BtTurn.interactable = (this.m_TotalCnt - this.m_UserCnt) > 0;
  177. },
  178. onShowAward: function () {
  179. this.m_AwardRes.active = true;
  180. var ani = this.$('AwardNode/AniNode').getComponent(dragonBones.ArmatureDisplay);
  181. cc.gSoundRes.PlaySound('AWARD');
  182. if (this.m_ResInfo[1] == 0) {
  183. ani.armatureName = 'xiexiecanyu';
  184. this.$('AwardNode/AwardItem').active = false;
  185. this.$('AwardNode/AwardInfo').active = false;
  186. this.$('AwardNode/NoAwardInfo').active = true;
  187. } else {
  188. ani.armatureName = 'gognxihuode';
  189. var Item = this.$('AwardNode/AwardItem@Sprite');
  190. var LabInfo = this.$('AwardNode/AwardInfo@Label');
  191. this.$('AwardNode/NoAwardInfo').active = false;
  192. cc.gPreLoader.LoadRes('Image_Item' +(this.m_ResInfo[0]+1) ,'TurnTable', function (sf) {
  193. Item.spriteFrame = sf;
  194. Item.node.active = true;
  195. }.bind(this));
  196. LabInfo.node.active = true;
  197. LabInfo.string = `恭喜您获得"${this.m_ResInfo[2]}钻石"`;
  198. }
  199. ani.playAnimation('newAnimation', 1);
  200. },
  201. OnBtAwardHide: function () {
  202. this.m_AwardRes.active = false;
  203. },
  204. });