uiManager.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 static showModal(title:string, content:string, suc_cb=null, fail_cb=null, confirmText:string='确定', showCancel:boolean=true, cancelText:string='取消') {
  61. SdkUtil.showModal(title,content,suc_cb,fail_cb,confirmText,showCancel,cancelText)
  62. }
  63. public showSendMsgWait(){
  64. if(this.send_msg_view!=null){
  65. this.send_msg_view.active = true
  66. }else{
  67. console.error("send_msg_view view not init..")
  68. }
  69. }
  70. public hideSendMsgWait(){
  71. if(this.send_msg_view!=null){
  72. this.send_msg_view.active = false
  73. }else{
  74. console.error("send_msg_view view not init..")
  75. }
  76. }
  77. public onButtonListen(btn:Node,call_back){
  78. btn.on(Node.EventType.TOUCH_END,()=>{
  79. audioManager.Instance().playSound(config.AUDIO.btn)
  80. call_back()
  81. })
  82. }
  83. }