uiManager.ts 2.4 KB

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