TweenCast.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import { RewardType } from "../../data/GameData";
  2. const { ccclass, property } = cc._decorator;
  3. /**
  4. * 世界公告 滚动播放
  5. * @author 邹勇
  6. */
  7. enum ScrollType {
  8. ST_horizontal,
  9. ST_vertical,
  10. };
  11. @ccclass
  12. export default class TweenCast extends cc.Component {
  13. @property({ type: cc.RichText, displayName: "公告内容" })
  14. private rich_text: cc.RichText = null;
  15. @property({ displayName: "显示时间" })
  16. private display_time: number = 5;
  17. @property({ displayName: "进出速度" })
  18. private move_speed: number = 3;
  19. @property({ displayName: "等待时间" })
  20. private wait_time: number = 10;
  21. @property({displayName: '滚动方向', type: cc.Enum(ScrollType)})
  22. private scrollType: ScrollType = ScrollType.ST_horizontal;
  23. @property({displayName: '是否一开始就是显示公告'})
  24. private isShowFirstNotice: boolean = true;
  25. @property({ displayName: '一开始显示的公告', type: cc.RichText, visible() { return this.isShowFirstNotice } })
  26. private rich_text_2: cc.RichText = null;
  27. private names: string[] = ["拒绝寂寞", "孽緣", "祗為与妳相爱", "羙男", "浅蓝", "腊笔小东", "卡布奇诺", "苊狠幸福", "埋葬回忆", "早已该放手", "白兎",
  28. "豿疍疍", "宿命", "渗透的葬礼", "全都是虚假", "俄侑伱-直", "隱裑", "你不配我", "非主流网名", "剧终", "如果沵走了", "續雪", "默默然", "大白痴", "衮开",
  29. "越长大越不安", "寶疍疍", "爱笑的眼睛", "暧昧", "午夜", "我继续坚强", "冷温柔", "蹲在脚落", "喲妞你赞", "满足沵", "泪流", "听风在唱歌", "假装", "海岸线丶",
  30. "流年换ノ", "细数惭愧", "寂寞别说爱╮", "疯男人", "Darling", "伤狠痛", "留的住我不要", "静静的思念", "涐愿化作飞蛾", "欲", "提苏米拉", "夜凄凉",
  31. "一种矜持", "哼,涐呸", "贪婪", "一败涂地", "美如此多娇", "暧昧已落幕", "地平线"];
  32. private moneys: number[] = [0.5, 0.8, 1.0, 2, 5, 10, 20, 100];
  33. private weights: number[] = [40, 20, 10, 10, 10, 5, 3, 2];
  34. private times: number[] = [5, 7, 8, 9, 10, 20, 30, 15, 16, 24, 26];
  35. /**
  36. * 随机生成一个世界公告
  37. */
  38. private getContent(): string {
  39. let len = this.names.length;
  40. let i = Math.floor(mk.math.random(0, len, false));
  41. let name = this.names[i];
  42. len = this.moneys.length;
  43. i = mk.math.randomByWeight(this.weights, 100, false);
  44. let money = this.moneys[i];
  45. len = this.times.length;
  46. i = Math.floor(mk.math.random(0, len, false));
  47. let t = this.times[i];
  48. //return `<outline color=#000000 width=1><color=#19F7FF>${name}</color>成功提现了<color=#FCE300>${money}元</color></outline>`;
  49. return `<color=#945438>${name} ${t}秒前成功提现${money}元</c>`
  50. }
  51. onLoad() {
  52. if(this.isShowFirstNotice)
  53. {
  54. if(!this.rich_text_2)
  55. {
  56. console.log('sss');
  57. }
  58. this.rich_text_2.string = this.getContent();
  59. }else
  60. {
  61. if(this.rich_text_2)
  62. this.rich_text_2.node.active = false;
  63. }
  64. this.play();
  65. }
  66. private play() {
  67. this.reset();
  68. cc.tween(this.node)
  69. .delay(this.wait_time)
  70. .call(this.rickPlay.bind(this)).start();
  71. }
  72. private rickPlay() {
  73. this.rich_text.node.active = true;
  74. if(this.scrollType == ScrollType.ST_horizontal)
  75. {
  76. cc.tween(this.rich_text.node)
  77. .to(this.move_speed, { x: 0 })
  78. .delay(this.display_time)
  79. .to(this.move_speed, { x: -450 })
  80. .call(this.play.bind(this)).start();
  81. if(this.isShowFirstNotice)
  82. {
  83. cc.tween(this.rich_text_2.node)
  84. .to(this.move_speed, {x: -450})
  85. .hide()
  86. .delay(this.display_time)
  87. .call(()=>{
  88. this.reset2();
  89. cc.tween(this.rich_text_2.node).show().to(this.move_speed, {x: 0}).start();
  90. })
  91. .start();
  92. }
  93. }else{
  94. cc.tween(this.rich_text.node)
  95. .to(this.move_speed, { y: 0 }, cc.easeSineOut())
  96. .delay(this.display_time)
  97. .to(this.move_speed, { y: 50 })
  98. .call(this.play.bind(this)).start();
  99. if(this.isShowFirstNotice)
  100. {
  101. cc.tween(this.rich_text_2.node)
  102. .to(this.move_speed, {y: 50})
  103. .hide()
  104. .delay(this.display_time)
  105. .call(()=>{
  106. this.reset2();
  107. cc.tween(this.rich_text_2.node).show().to(this.move_speed, {y: 0}).start();
  108. })
  109. .start();
  110. }
  111. }
  112. }
  113. private reset() {
  114. this.rich_text.node.active = false;
  115. if(this.scrollType == ScrollType.ST_horizontal)
  116. {
  117. this.rich_text.node.x = 450;
  118. this.rich_text.string = this.getContent();
  119. }else{
  120. this.rich_text.node.y = -50;
  121. this.rich_text.string = this.getContent();
  122. }
  123. }
  124. private reset2(){
  125. if(this.scrollType == ScrollType.ST_horizontal)
  126. {
  127. this.rich_text_2.node.x = 450;
  128. this.rich_text_2.string = this.getContent();
  129. }else{
  130. this.rich_text_2.node.y = -50;
  131. this.rich_text_2.string = this.getContent();
  132. }
  133. }
  134. public setMoneyArr(v:number[])
  135. {
  136. this.moneys = v;
  137. let add = this.weights.length - v.length;
  138. if(add > 0)
  139. {
  140. for(let i = 0; i != add; ++i)
  141. {
  142. this.moneys.unshift(v[0]);
  143. }
  144. }
  145. if(this.isShowFirstNotice)
  146. {
  147. if(!this.rich_text_2)
  148. {
  149. console.log('sss');
  150. }
  151. this.rich_text_2.string = this.getContent();
  152. }
  153. }
  154. }