GongGaoPanel.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { _decorator, Component, Label, Node } from 'cc';
  2. import { HttpHelp } from '../../game/HttpHelp';
  3. import { gameManager } from '../../game/gameManager';
  4. import { ResponseBase } from '../../game/pack/ResponseBase';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('GongGaoPanel')
  7. export class GongGaoPanel extends Component {
  8. /**公告对象 */
  9. @property(Node)
  10. Parent:Node =null!;
  11. @property(Label)
  12. lab:Label = null!;
  13. private _time:number = 0;
  14. private index :number = 0;
  15. private arrMsg:string[] =[];
  16. private showMsg:string = "";
  17. private _timepm:number = 0;
  18. protected onEnable(): void {
  19. this._time=0;
  20. this.index= -1;
  21. this._timepm=0;
  22. this.showMsg ="";
  23. this.arrMsg=[];
  24. this.httpGetGongGao();
  25. }
  26. start () {
  27. // [3]
  28. }
  29. update(dt: number) {
  30. this._time +=dt;
  31. if(this._time>=60){
  32. this._time=0;
  33. this.httpGetGongGao();
  34. }
  35. this._timepm+=dt;
  36. if(this._timepm>0.3){ //跑马灯的效率
  37. this._timepm = 0;
  38. this.DoPaoMaDent();
  39. }
  40. }
  41. private DoPaoMaDent(){
  42. if(this.showMsg&&this.showMsg.length>0){
  43. // console.log("msg:"+this.showMsg+",len:"+(this.showMsg.length-1),this.arrMsg);
  44. this.showMsg = this.showMsg.substring(1,this.showMsg.length);
  45. this.lab.string=this.showMsg;
  46. }else{
  47. if(this.index>=0){
  48. this.showMsg = this.arrMsg[this.index];
  49. this.Parent.active=true;
  50. this.lab.string=this.showMsg;
  51. this._timepm-=3;
  52. this.index--;
  53. }else{
  54. this.Parent.active = false;
  55. }
  56. }
  57. }
  58. private httpGetGongGao(){
  59. let url = "coins/manage/awardList";
  60. HttpHelp.httpGet(url, this.GongGaoBack, gameManager.Instance.golabMemory.Token, this);
  61. }
  62. GongGaoBack(data: any){
  63. console.log("获取跑马灯信息返回:", data)
  64. var obj: ResponseBase = JSON.parse(data);
  65. if(obj.code!=1){
  66. console.error("请求成功,返回数据错误",data);
  67. return;
  68. }
  69. const strs :string[] = obj.data;
  70. if(strs&&strs.length>0){
  71. for (let i = 0; i < strs.length; i++) {
  72. this.index++;
  73. this.arrMsg[this.index]=strs[i];
  74. }
  75. }
  76. }
  77. }