import { RewardType } from "../../data/GameData"; const { ccclass, property } = cc._decorator; /** * 世界公告 滚动播放 * @author 邹勇 */ enum ScrollType { ST_horizontal, ST_vertical, }; @ccclass export default class TweenCast extends cc.Component { @property({ type: cc.RichText, displayName: "公告内容" }) private rich_text: cc.RichText = null; @property({ displayName: "显示时间" }) private display_time: number = 5; @property({ displayName: "进出速度" }) private move_speed: number = 3; @property({ displayName: "等待时间" }) private wait_time: number = 10; @property({displayName: '滚动方向', type: cc.Enum(ScrollType)}) private scrollType: ScrollType = ScrollType.ST_horizontal; @property({displayName: '是否一开始就是显示公告'}) private isShowFirstNotice: boolean = true; @property({ displayName: '一开始显示的公告', type: cc.RichText, visible() { return this.isShowFirstNotice } }) private rich_text_2: cc.RichText = null; @property({displayName: '是否需要设置展示内容'}) private isSetShowContent: boolean = false; private names: string[] = ["拒绝寂寞", "孽緣", "祗為与妳相爱", "羙男", "浅蓝", "腊笔小东", "卡布奇诺", "苊狠幸福", "埋葬回忆", "早已该放手", "白兎", "豿疍疍", "宿命", "渗透的葬礼", "全都是虚假", "俄侑伱-直", "隱裑", "你不配我", "非主流网名", "剧终", "如果沵走了", "續雪", "默默然", "大白痴", "衮开", "越长大越不安", "寶疍疍", "爱笑的眼睛", "暧昧", "午夜", "我继续坚强", "冷温柔", "蹲在脚落", "喲妞你赞", "满足沵", "泪流", "听风在唱歌", "假装", "海岸线丶", "流年换ノ", "细数惭愧", "寂寞别说爱╮", "疯男人", "Darling", "伤狠痛", "留的住我不要", "静静的思念", "涐愿化作飞蛾", "欲", "提苏米拉", "夜凄凉", "一种矜持", "哼,涐呸", "贪婪", "一败涂地", "美如此多娇", "暧昧已落幕", "地平线"]; private moneys: number[] = [0.5, 0.8, 1.0, 2, 5, 10, 20, 100]; private weights: number[] = [40, 20, 10, 10, 10, 5, 3, 2]; private times: number[] = [5, 7, 8, 9, 10, 20, 30, 15, 16, 24, 26]; /** * 随机生成一个世界公告 */ private getContent(): string { let len = this.names.length; let i = Math.floor(mk.math.random(0, len, false)); let name = this.names[i]; len = this.moneys.length; i = mk.math.randomByWeight(this.weights, 100, false); let money = this.moneys[i]; len = this.times.length; i = Math.floor(mk.math.random(0, len, false)); let t = this.times[i]; //return `${name}成功提现了${money}元`; return `${name} ${t}秒前成功提现${money}元` } onLoad() { if(this.isShowFirstNotice) { if(!this.rich_text_2) { console.log('sss'); } this.rich_text_2.string = this.getContent(); }else { if(this.rich_text_2) this.rich_text_2.node.active = false; } if(!this.isSetShowContent) { this.play(); } } private play() { this.reset(); cc.tween(this.node) .delay(this.wait_time) .call(this.rickPlay.bind(this)).start(); } private rickPlay() { this.rich_text.node.active = true; if(this.scrollType == ScrollType.ST_horizontal) { cc.tween(this.rich_text.node) .to(this.move_speed, { x: 0 }) .delay(this.display_time) .to(this.move_speed, { x: -450 }) .call(this.play.bind(this)).start(); if(this.isShowFirstNotice) { cc.tween(this.rich_text_2.node) .to(this.move_speed, {x: -450}) .hide() .delay(this.display_time) .call(()=>{ this.reset2(); cc.tween(this.rich_text_2.node).show().to(this.move_speed, {x: 0}).start(); }) .start(); } }else{ cc.tween(this.rich_text.node) .to(this.move_speed, { y: 0 }, cc.easeSineOut()) .delay(this.display_time) .to(this.move_speed, { y: 50 }) .call(this.play.bind(this)).start(); if(this.isShowFirstNotice) { cc.tween(this.rich_text_2.node) .to(this.move_speed, {y: 50}) .hide() .delay(this.display_time) .call(()=>{ this.reset2(); cc.tween(this.rich_text_2.node).show().to(this.move_speed, {y: 0}).start(); }) .start(); } } } private reset() { this.rich_text.node.active = false; if(this.scrollType == ScrollType.ST_horizontal) { this.rich_text.node.x = 450; this.rich_text.string = this.getContent(); }else{ this.rich_text.node.y = -50; this.rich_text.string = this.getContent(); } } private reset2(){ if(this.scrollType == ScrollType.ST_horizontal) { this.rich_text_2.node.x = 450; this.rich_text_2.string = this.getContent(); }else{ this.rich_text_2.node.y = -50; this.rich_text_2.string = this.getContent(); } } public setMoneyArr(v:number[]) { this.moneys = v; let add = this.weights.length - v.length; if(add > 0) { for(let i = 0; i != add; ++i) { this.moneys.unshift(v[0]); } } if(this.isShowFirstNotice) { if(!this.rich_text_2) { console.log('sss'); } this.rich_text_2.string = this.getContent(); } if(this.isSetShowContent) { this.play(); } } }