squidGame/tgx-games-client/assets/module_arean/ui_announcement/UIAnnouncement.ts

55 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { UITransform } from "cc";
import { tgxUIController, tgx_class } from "../../core_tgx/tgx";
import { GameUILayers } from "../../scripts/GameUILayers";
import { Layout_UIAnnouncement } from "./Layout_UIAnnouncement";
import { UserMgr } from "../../module_basic/scripts/UserMgr";
import { SubGameMgr } from "../../module_basic/scripts/SubGameMgr";
import { ModuleDef } from "../../scripts/ModuleDef";
@tgx_class(ModuleDef.Arean)
export class UIAnnouncement extends tgxUIController {
constructor() {
super('ui_announcement/ui_announcement', GameUILayers.HUD, Layout_UIAnnouncement);
}
private _maskWidth = 0;
private _contentWidth = 0;
protected async onCreated(): Promise<void> {
let layout = this.layout as Layout_UIAnnouncement;
layout.node.active =false;
return;
let pos = layout.maskNode.position;
this._maskWidth = layout.maskNode.getComponent(UITransform).width;
layout.lblContent.node.setPosition(this._maskWidth / 2, pos.y, pos.z);
let ret = await UserMgr.inst.rpc_GetAnnouncement(SubGameMgr.current?.id || 'lobby');
if (ret.isSucc) {
layout.lblContent.string = ret.res.content;
}
else {
layout.lblContent.string = '获取公告失败请联系管理员微信TheMrKylin';
}
layout.lblContent.scheduleOnce(() => {
this._contentWidth = layout.lblContent.getComponent(UITransform).width;
}, 0.1);
}
setPosition(x: number, y: number) {
this.node.setPosition(x,y,0);
}
protected onUpdate(dt: number): void {
let layout = this.layout as Layout_UIAnnouncement;
if (layout) {
let pos = layout.lblContent.node.position;
if (this._contentWidth && pos.x + this._contentWidth < -this._maskWidth / 2) {
layout.lblContent.node.setPosition(this._maskWidth / 2, pos.y, pos.z);
}
else {
layout.lblContent.node.setPosition(pos.x - dt * 200, pos.y, pos.z);
}
}
}
}