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. }else{
  43. console.error("loading view not init..")
  44. }
  45. }
  46. public hideLoading(){
  47. if(this.loading_view!=null){
  48. }else{
  49. console.error("loading view not init..")
  50. }
  51. }
  52. public showSendMsgWait(){
  53. if(this.send_msg_view!=null){
  54. this.send_msg_view.active = true
  55. }else{
  56. console.error("send_msg_view view not init..")
  57. }
  58. }
  59. public hideSendMsgWait(){
  60. if(this.send_msg_view!=null){
  61. this.send_msg_view.active = false
  62. }else{
  63. console.error("send_msg_view view not init..")
  64. }
  65. }
  66. public onButtonListen(btn:Node,call_back){
  67. btn.on(Node.EventType.TOUCH_END,()=>{
  68. audioManager.Instance().playSound(config.AUDIO.btn)
  69. call_back()
  70. })
  71. }
  72. }