uiManager.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 static showToast(title:string,duration=2000,success_cb=null,fail_cb=null) {
  58. SdkUtil.showToast(title, duration,success_cb,fail_cb)
  59. }
  60. public showSendMsgWait(){
  61. if(this.send_msg_view!=null){
  62. this.send_msg_view.active = true
  63. }else{
  64. console.error("send_msg_view view not init..")
  65. }
  66. }
  67. public hideSendMsgWait(){
  68. if(this.send_msg_view!=null){
  69. this.send_msg_view.active = false
  70. }else{
  71. console.error("send_msg_view view not init..")
  72. }
  73. }
  74. public onButtonListen(btn:Node,call_back){
  75. btn.on(Node.EventType.TOUCH_END,()=>{
  76. audioManager.Instance().playSound(config.AUDIO.btn)
  77. call_back()
  78. })
  79. }
  80. }