InviteFriends.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import Util from "../../../before/util/Util";
  2. import InviteItem from "./InviteItem";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class InviteFriends extends cc.Component{
  6. @property({displayName: '已有金额', type: cc.Label})
  7. private lbl_value: cc.Label = null;
  8. @property({displayName: '进度条', type: cc.Sprite})
  9. private sp_progress: cc.Sprite = null;
  10. @property({displayName: '邀请红点', type: cc.Node})
  11. private node_redPoint: cc.Node = null;
  12. @property({displayName: '气泡头像', type: cc.Node})
  13. private node_inviteItem: cc.Node[] = [];
  14. @property({displayName: '红包飞行终点节点', type: cc.Node})
  15. private node_end: cc.Node = null;
  16. private mat_progress: cc.MaterialVariant = null;
  17. private progress: number = 0.5;
  18. onLoad(){
  19. this.mat_progress = this.sp_progress.getMaterials()[0];
  20. this.progress = this.mat_progress.getProperty('offset', 0);
  21. cc.systemEvent.on('keydown', this.onKeyDown, this);
  22. }
  23. start(){
  24. let data = [{}, {}, {},{}, {}, {}, {}];
  25. let timeArray = [0.4, 0.6, 0.7, 0.9, 1, 1.2, 1.4];
  26. let length = this.node_inviteItem.length;
  27. for(let i = 0; i != length; ++i)
  28. {
  29. if(i < data.length)
  30. {
  31. let rand = Util.rnd(0, timeArray.length-1);
  32. let time = timeArray[rand];
  33. timeArray.splice(rand, 1);
  34. let item = this.node_inviteItem[i].getComponent(InviteItem);
  35. item.setItemData(data[i], this.node_end, time);
  36. }else{
  37. this.node_inviteItem[i].active = false;
  38. }
  39. }
  40. }
  41. //一键领取按钮
  42. private onClickGetAllRewardBtn()
  43. {
  44. mk.audio.playEffect("button");
  45. }
  46. //好友详情按钮
  47. private onClickFriendsBtn()
  48. {
  49. mk.audio.playEffect("button");
  50. }
  51. //规则说明按钮
  52. private onClickRuleBtn()
  53. {
  54. mk.audio.playEffect("button");
  55. }
  56. //邀请好友按钮
  57. private onClickInviteFriendsBtn()
  58. {
  59. mk.audio.playEffect("button");
  60. }
  61. //提现按钮
  62. private onClickCashOutBtn()
  63. {
  64. mk.audio.playEffect("button");
  65. }
  66. private onClickClose(){
  67. mk.audio.playEffect("button");
  68. }
  69. private onKeyDown(key: cc.Event.EventKeyboard)
  70. {
  71. if(key.keyCode == cc.macro.KEY.up)
  72. {
  73. this.progress -= 0.1;
  74. if(this.progress < 0)
  75. this.progress = 0;
  76. this.mat_progress.setProperty('offset', this.progress);
  77. }else if(key.keyCode == cc.macro.KEY.down)
  78. {
  79. this.progress += 0.1;
  80. if(this.progress> 1)
  81. this.progress = 1;
  82. this.mat_progress.setProperty('offset', this.progress);
  83. }
  84. }
  85. onDestroy(){
  86. cc.systemEvent.off('keydown', this.onKeyDown, this);
  87. }
  88. }