WealthPanel.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. import { WealthData } from "../datas/WealthData";
  2. import AdM from "../manager/AdM";
  3. import { GameController } from "../manager/GameController";
  4. import GameM, { AUDIO_TYPE, VIDEO_TYPE } from "../manager/GameM";
  5. import GuideMng from "../manager/GuideMng";
  6. import WealthMng from "../manager/WealthMng";
  7. import MyExtends from "../tools/MyExtends";
  8. import Time from "../tools/Time";
  9. import BasePanel from "../uiFrames/BasePanel";
  10. import Sciencen_M from "../utils/Sciencen_M";
  11. import EffectNode from "./EffectNode";
  12. const { ccclass, property } = cc._decorator;
  13. @ccclass
  14. export default class WealthPanel extends BasePanel {
  15. @property(cc.Node)
  16. panelNode: cc.Node = null;
  17. @property(cc.Node)
  18. redrain: cc.Node = null;
  19. @property(sp.Skeleton)
  20. cloudSpine: sp.Skeleton = null;
  21. @property(sp.Skeleton)
  22. wealthSpine: sp.Skeleton = null;
  23. @property(sp.Skeleton)
  24. shield: sp.Skeleton = null;
  25. @property(cc.Node)
  26. qipao: cc.Node = null;
  27. @property(cc.Node)
  28. qipaoTxts: cc.Node[] = [];
  29. @property(cc.Node)
  30. stateReadyAndCool: cc.Node = null;
  31. @property(cc.Node)
  32. tipReady: cc.Node = null;
  33. @property(cc.Node)
  34. tipCool: cc.Node = null;
  35. @property(cc.Label)
  36. txtReady: cc.Label = null;
  37. @property(cc.Label)
  38. txtCoolTimer: cc.Label = null;
  39. @property(cc.Label)
  40. txtshieldQipao: cc.Label = null;
  41. @property(cc.Node)
  42. stateShield: cc.Node = null;
  43. @property(cc.Node)
  44. shieldTip: cc.Node = null;
  45. @property(cc.Label)
  46. txtShieldTimer: cc.Label = null;
  47. @property(cc.Label)
  48. txtLeaveTimer: cc.Label = null;
  49. @property(cc.Node)
  50. stateGift: cc.Node = null;
  51. @property(cc.Node)
  52. giftTitle: cc.Node = null;
  53. @property(cc.Node)
  54. giftBox: cc.Node = null;
  55. @property(cc.Node)
  56. giftBtn: cc.Node = null;
  57. @property(cc.Label)
  58. txtGift: cc.Label = null;
  59. @property(cc.Node)
  60. stateEnd: cc.Node = null;
  61. @property(cc.Node)
  62. stateWealthing: cc.Node = null;
  63. @property(cc.Label)
  64. txtWealthCoin: cc.Label = null;
  65. @property(cc.Label)
  66. txtWealthingTimer: cc.Label = null;
  67. @property(cc.Node)
  68. stateGifting: cc.Node = null;
  69. @property(cc.Label)
  70. txtGiftingCoin: cc.Label = null;
  71. @property(cc.Label)
  72. txtGiftingProgress: cc.Label = null;
  73. @property(cc.Node)
  74. btnClose: cc.Node = null;
  75. /**界面类型 1 ready 2 cool 3 shield 4 gift 5 end*/
  76. private type: number = 1;
  77. isCanClick: boolean = true;
  78. giftingUpdateTimer: number = 0;
  79. /**进入界面
  80. * @param type:界面类型 1 ready 2 cool 3 shield 4 gift 5 end 6 wealthing 降临中 7 gifting 献礼进度
  81. */
  82. OnEnter(type: number) {
  83. if (type != 4) {
  84. this.panelNode.scale = 0;
  85. cc.tween(this.panelNode).to(0.2, { scale: 1 }, { easing: "backOut" })
  86. .call(() => {
  87. if (GuideMng.Ins.CurGuideId == 18) {
  88. GuideMng.Ins.ResumeGuide();
  89. }
  90. })
  91. .start();
  92. } else {
  93. this.panelNode.scale = 1;
  94. }
  95. this.node.active = true;
  96. this.isCanClick = true;
  97. this.type = type;
  98. this.btnClose.active = true;
  99. this.cloudSpine.node.active = false;
  100. this.shield.node.active = false;
  101. this.stateReadyAndCool.active = false;
  102. this.stateShield.active = false;
  103. this.stateGift.active = false;
  104. this.stateEnd.active = false;
  105. this.stateWealthing.active = false;
  106. this.stateGifting.active = false;
  107. this.qipaoTxts.forEach(element => {
  108. element.active = false;
  109. });
  110. this.qipaoTxts[type - 1].active = true;
  111. this.redrain.active = false;
  112. switch (type) {
  113. case 1:
  114. this.stateReadyAndCool.active = true;
  115. this.tipReady.active = true;
  116. this.tipCool.active = false;
  117. this.txtReady.string = WealthData.Ins.GetBloodGold() + "+" + WealthData.Ins.GetGiftGold();// "888亿+122亿";
  118. break;
  119. case 2:
  120. this.stateReadyAndCool.active = true;
  121. this.tipReady.active = false;
  122. this.tipCool.active = true;
  123. this.txtReady.string = WealthData.Ins.GetBloodGold() + "+" + WealthData.Ins.GetGiftGold();// "888亿+122亿";
  124. break;
  125. case 3:
  126. this.stateShield.active = true;
  127. this.txtshieldQipao.string = WealthData.Ins.GetGiftGold(false);
  128. this.shield.node.active = true;
  129. this.shield.setAnimation(0, "animation", true);
  130. break;
  131. case 4:
  132. this.giftTitle.active = false;
  133. this.giftBox.active = false;
  134. this.giftBtn.active = false;
  135. this.redrain.active = false;
  136. this.stateGift.active = true;
  137. console.log("+++++++1");
  138. this.node.stopAllActions();
  139. let a1 = cc.delayTime(1);
  140. let a2 = cc.callFunc(() => { this.giftTitle.active = true; console.log("+++++++2"); });
  141. let a3 = cc.delayTime(0.1);
  142. let a4 = cc.callFunc(() => { this.giftBox.active = true; console.log("+++++++3"); });
  143. let a5 = cc.delayTime(0.1);
  144. let a6 = cc.callFunc(() => { this.giftBtn.active = true; console.log("+++++++4"); });
  145. let a7 = cc.delayTime(0.1);
  146. let a8 = cc.callFunc(() => { this.redrain.active = true; console.log("+++++++5"); });
  147. this.node.runAction(cc.sequence(a1, a2, a3, a4, a5, a6, a7, a8));
  148. //this.redrain.active = true;
  149. this.txtGift.string = WealthData.Ins.GetGiftGold(false);
  150. GameM.audioM.setPauseMusic();
  151. GameM.audioM.playMateEffect(AUDIO_TYPE.fiveluckbgm);
  152. this.btnClose.active = false;
  153. AdM.onSendEvent('caishen_award', '财神献礼触发', 'caishen');
  154. break;
  155. case 5:
  156. this.stateEnd.active = true;
  157. this.cloudSpine.node.active = true;
  158. break;
  159. case 6:
  160. this.stateWealthing.active = true;
  161. this.txtWealthCoin.string = WealthData.Ins.GetBloodGold() + "+" + WealthData.Ins.GetGiftGold();
  162. break;
  163. case 7:
  164. this.stateGifting.active = true;
  165. this.txtGiftingCoin.string = WealthData.Ins.GetGiftGold(false);
  166. this.giftingUpdateTimer = 0;
  167. this.txtGiftingProgress.string = ((1 - Number(Sciencen_M.instance.accDiv(WealthData.Ins.blood, WealthData.Ins.bloodValue))) * 100).toFixed(2) + "%";
  168. break;
  169. }
  170. if (GuideMng.Ins.CurGuideId == 18) {
  171. this.scheduleOnce(() => {
  172. GuideMng.Ins.ResumeGuide()
  173. }, 0.6)
  174. } //this.unschedule(this.DisplayCloseBtn);
  175. //this.scheduleOnce(this.DisplayCloseBtn, 3);
  176. }
  177. OnExit() {
  178. this.node.active = false;
  179. if (this.type == 4) {
  180. GameController.Ins.SwitchAudio(1);
  181. }
  182. }
  183. DisplayCloseBtn() {
  184. this.btnClose.active = true;
  185. }
  186. update(dt) {
  187. if (this.type == 2) {
  188. this.StateCooling();
  189. } else if (this.type == 3) {
  190. this.StateShield();
  191. } else if (this.type == 6) {
  192. this.StateWealthing();
  193. } else if (this.type == 7) {
  194. this.StateGifting(dt);
  195. }
  196. }
  197. StateCooling() {
  198. if (WealthData.Ins.isCooling) {
  199. this.txtCoolTimer.string = MyExtends.TimeToFormat(WealthData.Ins.coolingTimer, 3);
  200. }
  201. else {
  202. this.txtCoolTimer.string = "";
  203. this.OnEnter(1);
  204. this.btnClose.active = true;
  205. }
  206. }
  207. StateShield() {
  208. if (WealthData.Ins.shieldTimer > 0) {
  209. if (!this.shieldTip.active) this.shieldTip.active = true;
  210. this.txtShieldTimer.string = Math.floor(WealthData.Ins.shieldTimer) + "s";
  211. }
  212. else {
  213. if (this.shieldTip.active) {
  214. this.shieldTip.active = false;
  215. this.CloseShield();
  216. }
  217. this.txtShieldTimer.string = "";
  218. }
  219. if (WealthData.Ins.lifeTimer > 0) {
  220. this.txtLeaveTimer.string = MyExtends.TimeToFormat(WealthData.Ins.lifeTimer) + "秒后财神离去";
  221. }
  222. else {
  223. this.txtLeaveTimer.string = ""
  224. }
  225. }
  226. StateWealthing() {
  227. if (WealthData.Ins.isTriggerWealth) {
  228. this.txtWealthingTimer.string = MyExtends.TimeToFormat(WealthData.Ins.lifeTimer, 3);
  229. }
  230. else {
  231. this.txtWealthingTimer.string = "";
  232. this.OnExit();
  233. this.btnClose.active = true;
  234. }
  235. }
  236. StateGifting(dt) {
  237. if (WealthData.Ins.isTriggerWealth) {
  238. this.giftingUpdateTimer += dt;
  239. if (this.giftingUpdateTimer > 1) {
  240. this.giftingUpdateTimer = 0;
  241. this.txtGiftingProgress.string = ((1 - Number(Sciencen_M.instance.accDiv(WealthData.Ins.blood, WealthData.Ins.bloodValue))) * 100).toFixed(2) + "%";
  242. }
  243. }
  244. else {
  245. this.txtGiftingProgress.string = "";
  246. this.OnExit();
  247. this.btnClose.active = true;
  248. }
  249. }
  250. Click_ClearShieldBtn() {
  251. if (!this.isCanClick) return;
  252. AdM.Instance.watchVideo(VIDEO_TYPE.clearShield);
  253. AdM.onSendEvent(`video_init_15`, `看视频清除金钟罩`, 'video_init');
  254. }
  255. AdEndClearShield() {
  256. this.isCanClick = false;
  257. WealthMng.Ins.ClearShield();
  258. this.CloseShield();
  259. AdM.onSendEvent(`video_end_15`, `看视频清除金钟罩`, 'video_end');
  260. AdM.onSendEvent('caishen_skill_over', '财神金钟罩技能消除', 'caishen');
  261. }
  262. async CloseShield() {
  263. this.shield.setAnimation(0, "animation2", false);
  264. await Time.WaitForSeconds(this.shield.findAnimation("animation2").duration);
  265. this.shield.node.active = false;
  266. this.isCanClick = true;
  267. this.OnExit();
  268. }
  269. Click_GetGiftBtn() {
  270. GameM.audioM.playEffect(AUDIO_TYPE.button);
  271. GameM.commonData.updateGold(WealthData.Ins.giftValue);
  272. this.OnExit();
  273. EffectNode.instance.PlayCoinAnim(0, 20, cc.v2(0, -300));
  274. EffectNode.instance.PlayScreenCoin();
  275. GuideMng.Ins.CheckWealthGiftGuide18();
  276. }
  277. Click_CloseBtn() {
  278. GameM.audioM.playEffect(AUDIO_TYPE.button);
  279. this.OnExit();
  280. }
  281. }