back_title.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { _decorator, Component, Label, Node, Widget } from 'cc';
  2. import { gameManager } from '../gameManager';
  3. import { SdkUtil } from '../../sdkUtil';
  4. import { tools } from '../../tools';
  5. import { config } from '../../config';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('back_title')
  8. export class back_title extends Component {
  9. @property(Node) btn_back:Node = null;
  10. @property(Node) img_title_bg:Node = null;
  11. @property(Node) img_title:Node = null;
  12. private mCallBack = null;
  13. protected start(): void {
  14. if(SdkUtil.iPhoneIsLingdongdao()&&tools.platform == config.Platform.KS) {
  15. let p = this.img_title_bg.getPosition()
  16. this.img_title_bg.setPosition(p.x,p.y-60,p.z)
  17. }
  18. if(config.is_zb) {
  19. this.node.getComponent(Widget).top = 25
  20. this.btn_back.setScale(0.7,0.7)
  21. this.btn_back.getComponent(Widget).top = 0
  22. this.btn_back.getComponent(Widget).left = 0
  23. }
  24. }
  25. public initView(title:string,call_back){
  26. this.mCallBack = call_back;
  27. this.updateTitle(title)
  28. this.btn_back.off(Node.EventType.TOUCH_END)
  29. this.btn_back.on(Node.EventType.TOUCH_END,()=>{
  30. if(this.mCallBack!=null){
  31. this.mCallBack()
  32. }
  33. gameManager.Singleton.sys_click_button_music()
  34. })
  35. }
  36. public updateTitle(title:string){
  37. if(title.length<=0){
  38. this.img_title.parent.active = false;
  39. }else{
  40. this.img_title.parent.active = true;
  41. }
  42. this.img_title.getComponent(Label).string = title;
  43. }
  44. }