uiManager.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { Node, Prefab, instantiate, resources } from "cc";
  2. import { audioManager } from "./audioManager";
  3. import { config } from "../config";
  4. export class uiManager {
  5. private static instance:uiManager =null;
  6. public static Instance(){
  7. if(this.instance==null){
  8. this.instance = new uiManager
  9. }
  10. return this.instance
  11. }
  12. private ui_parent:Node = null
  13. private loading_view:Node = null
  14. private send_msg_view:Node = null
  15. public init(ui_node:Node,loading_node:Node,send_msg_loading:Node){
  16. this.ui_parent = ui_node
  17. this.send_msg_view = send_msg_loading
  18. this.loading_view = loading_node
  19. }
  20. public showUi(ui_path:string,parent:Node =null,cb=null){
  21. if(this.ui_parent==null){
  22. return console.error("ui_parent not init..")
  23. }
  24. resources.load(ui_path,Prefab,(err,fb:Prefab)=>{
  25. if(!err){
  26. let node = instantiate(fb)
  27. if(parent!=null){
  28. node.parent = parent
  29. }else{
  30. node.parent = this.ui_parent
  31. }
  32. if(cb!=null){
  33. cb(node)
  34. }
  35. }else{
  36. console.error("showUi error:",err)
  37. }
  38. })
  39. }
  40. public showLoading(){
  41. if(this.loading_view!=null){
  42. this.loading_view.active = true
  43. }else{
  44. console.error("loading view not init..")
  45. }
  46. }
  47. public hideLoading(){
  48. if(this.loading_view!=null){
  49. this.loading_view.active = false
  50. }else{
  51. console.error("loading view not init..")
  52. }
  53. }
  54. public showSendMsgWait(){
  55. if(this.send_msg_view!=null){
  56. this.send_msg_view.active = true
  57. }else{
  58. console.error("send_msg_view view not init..")
  59. }
  60. }
  61. public hideSendMsgWait(){
  62. if(this.send_msg_view!=null){
  63. this.send_msg_view.active = false
  64. }else{
  65. console.error("send_msg_view view not init..")
  66. }
  67. }
  68. public onButtonListen(btn:Node,call_back){
  69. btn.on(Node.EventType.TOUCH_END,()=>{
  70. audioManager.Instance().playSound(config.AUDIO.btn)
  71. call_back()
  72. })
  73. }
  74. }