Bulletin.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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;
  18. protected onLoad() {
  19. super.onLoad();
  20. this.closeTips.string = StringUtil.getLanguageData('点击空白关闭');
  21. this.titleTx.string = StringUtil.getLanguageData('公告');
  22. let twinkle = (node)=>{
  23. tween(this.closeTips.getComponent(UIOpacity)).to(1.2, { opacity: 10 })
  24. .call(() => {
  25. tween(this.closeTips.getComponent(UIOpacity)).to(1, { opacity: 255 })
  26. .call(() => {
  27. twinkle(this.closeTips);
  28. }).start()
  29. }).start()
  30. }
  31. twinkle(this.closeTips);
  32. }
  33. protected onDestroy() {
  34. }
  35. //UI开打时会调用,如果有初始化代码应该放到此函数
  36. onOpen(data:BulletinEnum) {
  37. this.data = data;
  38. this.msgTx.string = this.data.content;
  39. if (this.data.img){
  40. this.load('package', 'texture/login/bulletin_img/spriteFrame', SpriteFrame, (res: SpriteFrame) => {
  41. this.msgImg.spriteFrame = res;
  42. })
  43. }
  44. }
  45. //UI关闭时会调用,该函数在onDestroy前调用
  46. onClose() {
  47. }
  48. //框架管理UI层级时会调用,可根据UI情况修改
  49. onShow() {
  50. super.onShow();
  51. }
  52. //框架管理UI层级时会调用,可根据UI情况修改
  53. onHide() {
  54. super.onHide();
  55. }
  56. //UI事件处理
  57. private onTouchButton(event: Event) {
  58. let target: any = event.target;
  59. if (target.name == 'mask') {
  60. Framework.layer.close(this);
  61. }
  62. }
  63. }