123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- import { _decorator, Component, Label, Node } from 'cc';
- import { HttpHelp } from '../../game/HttpHelp';
- import { gameManager } from '../../game/gameManager';
- import { ResponseBase } from '../../game/pack/ResponseBase';
- const { ccclass, property } = _decorator;
-
-
- @ccclass('GongGaoPanel')
- export class GongGaoPanel extends Component {
- /**公告对象 */
- @property(Node)
- Parent:Node =null!;
- @property(Label)
- lab:Label = null!;
-
- private _time:number = 0;
- private index :number = 0;
- private arrMsg:string[] =[];
- private showMsg:string = "";
- private _timepm:number = 0;
- protected onEnable(): void {
- this._time=0;
- this.index= -1;
- this._timepm=0;
- this.showMsg ="";
- this.arrMsg=[];
- this.httpGetGongGao();
- }
- start () {
- // [3]
- }
- update(dt: number) {
- this._time +=dt;
- if(this._time>=60){
- this._time=0;
- this.httpGetGongGao();
- }
- this._timepm+=dt;
- if(this._timepm>0.3){ //跑马灯的效率
- this._timepm = 0;
- this.DoPaoMaDent();
- }
- }
- private DoPaoMaDent(){
- if(this.showMsg&&this.showMsg.length>0){
- // console.log("msg:"+this.showMsg+",len:"+(this.showMsg.length-1),this.arrMsg);
- this.showMsg = this.showMsg.substring(1,this.showMsg.length);
- this.lab.string=this.showMsg;
- }else{
- if(this.index>=0){
- this.showMsg = this.arrMsg[this.index];
- this.Parent.active=true;
- this.lab.string=this.showMsg;
- this._timepm-=3;
- this.index--;
- }else{
- this.Parent.active = false;
- }
- }
- }
- private httpGetGongGao(){
- let url = "coins/manage/awardList";
- HttpHelp.httpGet(url, this.GongGaoBack, gameManager.Instance.golabMemory.Token, this);
- }
- GongGaoBack(data: any){
- console.log("获取跑马灯信息返回:", data)
- var obj: ResponseBase = JSON.parse(data);
- if(obj.code!=1){
- console.error("请求成功,返回数据错误",data);
- return;
- }
-
- const strs :string[] = obj.data;
- if(strs&&strs.length>0){
- for (let i = 0; i < strs.length; i++) {
- this.index++;
- this.arrMsg[this.index]=strs[i];
- }
- }
- }
- }
|