ZUIPanelUpdate.lua.txt 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. local ZUIPanelUpdate = ZUIPanelUpdate or {}
  2. ZUIPanelUpdate.textUpdateStateInfo = nil
  3. ZUIPanelUpdate.imageProgress = nil
  4. ZUIPanelUpdate.imageProgressBG = nil
  5. ZUIPanelUpdate.textTipsTitle = nil
  6. ZUIPanelUpdate.textTipsInfo = nil
  7. ZUIPanelUpdate.imgHandle = nil
  8. local function OnClickButtonYes()
  9. print("--> Click Yes ~")
  10. ZUIPanelUpdate.panelTips:SetActive(false)
  11. local eventDispatchCenter = require("Base/ZEventDispatchCenter.lua")
  12. eventDispatchCenter:DispatchEvent(eventDispatchCenter.EventType.UPDATE_RETRY)
  13. end
  14. local function OnClickButtonNo()
  15. print("--> Click No ~")
  16. ZUIPanelUpdate.panelTips:SetActive(false)
  17. CS.UnityEngine.Application.Quit()
  18. end
  19. function ZUIPanelUpdate.SetProgressPercent(percent)
  20. if percent <= 0 then percent = 0 end
  21. if percent >= 1 then percent = 1 end
  22. ZUIPanelUpdate.imageProgress:SetActive(true)
  23. ZUIPanelUpdate.imageProgressBG:SetActive(true)
  24. ZUIPanelUpdate.imgHandle:SetActive(true)
  25. local nWidth = ZUIPanelUpdate.imageProgress.transform:GetComponent("RectTransform").rect.width
  26. local x = (percent - 0.5) * nWidth
  27. ZUIPanelUpdate.imgHandle:GetComponent("RectTransform").anchoredPosition = CS.UnityEngine.Vector2(x, 0)
  28. ZUIPanelUpdate.imageProgress.transform:GetComponent("Image").fillAmount = percent;
  29. end
  30. function ZUIPanelUpdate.SetUpdateInfo(information)
  31. ZUIPanelUpdate.panelUpdateInfo:SetActive(false)
  32. ZUIPanelUpdate.textUpdateStateInfo:SetActive(true)
  33. ZUIPanelUpdate.textUpdateStateInfo:GetComponent("Text").text = information
  34. end
  35. function ZUIPanelUpdate.SetTips(title, information)
  36. ZUIPanelUpdate.panelUpdateInfo:SetActive(false)
  37. ZUIPanelUpdate.panelTips:SetActive(true)
  38. ZUIPanelUpdate.textTipsTitle:GetComponent("Text").text = title
  39. ZUIPanelUpdate.textTipsInfo:GetComponent("Text").text = information
  40. end
  41. function ZUIPanelUpdate.SetUpdateDetail(szPercent, szUpdateDetail, szUpdateSpeed)
  42. ZUIPanelUpdate.panelTips:SetActive(false)
  43. ZUIPanelUpdate.textUpdateStateInfo:SetActive(false)
  44. ZUIPanelUpdate.panelUpdateInfo:SetActive(true)
  45. ZUIPanelUpdate.textUpdatePercent:GetComponent("Text").text = szPercent
  46. ZUIPanelUpdate.textUpdateDetail:GetComponent("Text").text = szUpdateDetail
  47. ZUIPanelUpdate.textUpdateSpeed:GetComponent("Text").text = szUpdateSpeed
  48. end
  49. function ZUIPanelUpdate.Awake()
  50. print("ZUIPanelUpdate Awake")
  51. --local prefabCanvasUpdate = CS.SFramework.SResourceManagerR.LoadResource("Prefabs/Canvas_Update.prefab")
  52. local prefabCanvasUpdate = LoadResource("Prefabs/Canvas_Update.prefab")
  53. local canvasUpdate = CS.UnityEngine.GameObject.Instantiate(prefabCanvasUpdate)
  54. ZUIPanelUpdate.canvasUpdate = canvasUpdate
  55. local panelUpdate = canvasUpdate.transform:Find("Panel_Update").gameObject
  56. local textInfo = panelUpdate.transform:Find("Text_Info").gameObject
  57. local imageProgress = panelUpdate.transform:Find("Image_Progress").gameObject
  58. local imageProgressBG = panelUpdate.transform:Find("Image_Progress_BG").gameObject
  59. local imgHandle = imageProgress.transform:Find("Image").gameObject
  60. local panelUpdateInfo = panelUpdate.transform:Find("Panel_UpdateInfo").gameObject
  61. local textUpdatePercent = panelUpdateInfo.transform:Find("Text_UpdatePercent").gameObject
  62. local textUpdateDetail = panelUpdateInfo.transform:Find("Text_UpdateDetail").gameObject
  63. local textUpdateSpeed = panelUpdateInfo.transform:Find("Text_UpdateSpeed").gameObject
  64. local panelTips = canvasUpdate.transform:Find("Panel_Tips").gameObject
  65. local textTitle = panelTips.transform:Find("Text_Title").gameObject
  66. local tipsTextInfo = panelTips.transform:Find("Text_Info").gameObject
  67. panelTips:SetActive(false)
  68. panelUpdateInfo:SetActive(false)
  69. imgHandle:SetActive(false)
  70. imageProgress:SetActive(false)
  71. imageProgressBG:SetActive(false)
  72. ZUIPanelUpdate.panelTips = panelTips
  73. ZUIPanelUpdate.textUpdateStateInfo = textInfo
  74. ZUIPanelUpdate.imageProgress = imageProgress
  75. ZUIPanelUpdate.imageProgressBG = imageProgressBG
  76. ZUIPanelUpdate.panelUpdateInfo = panelUpdateInfo
  77. ZUIPanelUpdate.textUpdatePercent = textUpdatePercent
  78. ZUIPanelUpdate.textUpdateDetail = textUpdateDetail
  79. ZUIPanelUpdate.textUpdateSpeed = textUpdateSpeed
  80. ZUIPanelUpdate.textTipsTitle = textTitle
  81. ZUIPanelUpdate.textTipsInfo = tipsTextInfo
  82. ZUIPanelUpdate.imgHandle = imgHandle
  83. end
  84. function ZUIPanelUpdate.Start()
  85. print("ZUIPanelUpdate Start")
  86. local canvasUpdate = ZUIPanelUpdate.canvasUpdate
  87. local buttonYes = canvasUpdate.transform:Find("Panel_Tips/Button_Yes").gameObject
  88. buttonYes:GetComponent("Button").onClick:AddListener(OnClickButtonYes)
  89. local buttonNo = canvasUpdate.transform:Find("Panel_Tips/Button_No").gameObject
  90. buttonNo:GetComponent("Button").onClick:AddListener(OnClickButtonNo)
  91. ZUIPanelUpdate.RefreshInfo()
  92. local eventDispatchCenter = require("Base/ZEventDispatchCenter.lua")
  93. eventDispatchCenter:RegisterEvent(eventDispatchCenter.EventType.UPDATE_STATE_INFO, ZUIPanelUpdate.SetUpdateInfo)
  94. eventDispatchCenter:RegisterEvent(eventDispatchCenter.EventType.UPDATE_PROGRESS_PERCENT, ZUIPanelUpdate.SetProgressPercent)
  95. eventDispatchCenter:RegisterEvent(eventDispatchCenter.EventType.UPDATE_SHOW_TIPS, ZUIPanelUpdate.SetTips)
  96. eventDispatchCenter:RegisterEvent(eventDispatchCenter.EventType.UPDATE_SHOW_UPDATE_DETAIL, ZUIPanelUpdate.SetUpdateDetail)
  97. end
  98. function ZUIPanelUpdate.OnDestroy()
  99. print("ZUIPanelUpdate.OnDestroy")
  100. local eventDispatchCenter = require("Base/ZEventDispatchCenter.lua")
  101. eventDispatchCenter:UnregisterEvent(eventDispatchCenter.EventType.UPDATE_SHOW_UPDATE_DETAIL, ZUIPanelUpdate.SetUpdateDetail)
  102. eventDispatchCenter:UnregisterEvent(eventDispatchCenter.EventType.UPDATE_SHOW_TIPS, ZUIPanelUpdate.SetTips)
  103. eventDispatchCenter:UnregisterEvent(eventDispatchCenter.EventType.UPDATE_PROGRESS_PERCENT, ZUIPanelUpdate.SetProgressPercent)
  104. eventDispatchCenter:UnregisterEvent(eventDispatchCenter.EventType.UPDATE_STATE_INFO, ZUIPanelUpdate.SetUpdateInfo)
  105. end
  106. function ZUIPanelUpdate.RefreshInfo()
  107. ZUIPanelUpdate.textTipsTitle:GetComponent("Text").text = "更新提示"
  108. ZUIPanelUpdate.textTipsInfo:GetComponent("Text").text = "准备更新..."
  109. ZUIPanelUpdate.textUpdateStateInfo:GetComponent("Text").text = "等待更新..."
  110. end
  111. return ZUIPanelUpdate