import Util from "../../../before/util/Util"; import InviteItem from "./InviteItem"; const { ccclass, property } = cc._decorator; @ccclass export default class InviteFriends extends cc.Component{ @property({displayName: '已有金额', type: cc.Label}) private lbl_value: cc.Label = null; @property({displayName: '进度条', type: cc.Sprite}) private sp_progress: cc.Sprite = null; @property({displayName: '邀请红点', type: cc.Node}) private node_redPoint: cc.Node = null; @property({displayName: '气泡头像', type: cc.Node}) private node_inviteItem: cc.Node[] = []; @property({displayName: '红包飞行终点节点', type: cc.Node}) private node_end: cc.Node = null; private mat_progress: cc.MaterialVariant = null; private progress: number = 0.5; onLoad(){ this.mat_progress = this.sp_progress.getMaterials()[0]; this.progress = this.mat_progress.getProperty('offset', 0); cc.systemEvent.on('keydown', this.onKeyDown, this); } start(){ let data = [{}, {}, {},{}, {}, {}, {}]; let timeArray = [0.4, 0.6, 0.7, 0.9, 1, 1.2, 1.4]; let length = this.node_inviteItem.length; for(let i = 0; i != length; ++i) { if(i < data.length) { let rand = Util.rnd(0, timeArray.length-1); let time = timeArray[rand]; timeArray.splice(rand, 1); let item = this.node_inviteItem[i].getComponent(InviteItem); item.setItemData(data[i], this.node_end, time); }else{ this.node_inviteItem[i].active = false; } } } //一键领取按钮 private onClickGetAllRewardBtn() { mk.audio.playEffect("button"); } //好友详情按钮 private onClickFriendsBtn() { mk.audio.playEffect("button"); } //规则说明按钮 private onClickRuleBtn() { mk.audio.playEffect("button"); } //邀请好友按钮 private onClickInviteFriendsBtn() { mk.audio.playEffect("button"); } //提现按钮 private onClickCashOutBtn() { mk.audio.playEffect("button"); } private onClickClose(){ mk.audio.playEffect("button"); } private onKeyDown(key: cc.Event.EventKeyboard) { if(key.keyCode == cc.macro.KEY.up) { this.progress -= 0.1; if(this.progress < 0) this.progress = 0; this.mat_progress.setProperty('offset', this.progress); }else if(key.keyCode == cc.macro.KEY.down) { this.progress += 0.1; if(this.progress> 1) this.progress = 1; this.mat_progress.setProperty('offset', this.progress); } } onDestroy(){ cc.systemEvent.off('keydown', this.onKeyDown, this); } }