Bulletin.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { _decorator, Label, Node, RichText, Sprite, SpriteFrame, tween, UIOpacity } from 'cc';
  2. import { BaseView } from '../../../framework/layer/BaseView';
  3. import { Framework } from '../../../framework/Framework';
  4. import { StringUtil } from '../../../framework/util/StringUtil';
  5. import { BulletinEnum } from '../../common/InterfaceAddEnum';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('Bulletin')
  8. export class Bulletin extends BaseView {
  9. @property({ type: Label, tooltip: "关闭提示" })
  10. closeTips: Label = null;
  11. @property({ type: Label, tooltip: "标题" })
  12. titleTx: Label = null;
  13. @property({ type: Sprite, tooltip: "公告图" })
  14. msgImg: Sprite = null;
  15. @property({ type: RichText, tooltip: "公告内容" })
  16. msgTx: RichText = null;
  17. private data:BulletinEnum = null;
  18. protected onLoad() {
  19. super.onLoad();
  20. this.closeTips.string = StringUtil.getLanguageData('点击空白关闭');
  21. this.titleTx.string = StringUtil.getLanguageData('公告');
  22. this.closeTips.node.getComponent(UIOpacity).opacity = 0;
  23. }
  24. protected onDestroy() {
  25. }
  26. //UI开打时会调用,如果有初始化代码应该放到此函数
  27. onOpen(data:BulletinEnum) {
  28. this.data = data;
  29. this.msgTx.string = data.content;
  30. if (this.data.img){
  31. this.load('package', 'texture/login/bulletin_img/spriteFrame', SpriteFrame, (res: SpriteFrame) => {
  32. this.msgImg.spriteFrame = res;
  33. })
  34. }
  35. tween(this.closeTips.node.getComponent(UIOpacity))
  36. .to(1, { opacity: 255 })
  37. .to(1.2, { opacity: 10 })
  38. .union()
  39. .repeatForever()
  40. .start()
  41. }
  42. //UI关闭时会调用,该函数在onDestroy前调用
  43. onClose() {
  44. }
  45. //框架管理UI层级时会调用,可根据UI情况修改
  46. onShow() {
  47. super.onShow();
  48. }
  49. //框架管理UI层级时会调用,可根据UI情况修改
  50. onHide() {
  51. super.onHide();
  52. }
  53. //UI事件处理
  54. private onTouchButton(event: Event) {
  55. let target: any = event.target;
  56. if (target.name == 'mask') {
  57. Framework.layer.close(this);
  58. }
  59. }
  60. }