TweenCast.ts 6.4 KB

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