源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.1 KiB

  1. DailyRechargeGuagualeView = DailyRechargeGuagualeView or BaseClass(BaseView)
  2. function DailyRechargeGuagualeView:__init()
  3. self.base_file = "dailyRecharge"
  4. self.layout_file = "DailyRechargeGuagualeView"
  5. self.layer_name = "Top"
  6. self.use_background = true
  7. self.is_set_zdepth = true
  8. self.model = RechargeActivityModel:getInstance()
  9. self.is_init = false
  10. self.is_win = false
  11. self.is_finished = true
  12. self.load_callback = function ()
  13. self:LoadSuccess()
  14. self:InitEvent()
  15. end
  16. self.destroy_callback = function ()
  17. self:Clear()
  18. end
  19. end
  20. function DailyRechargeGuagualeView:Clear()
  21. end
  22. function DailyRechargeGuagualeView:LoadSuccess()
  23. local nodes = {
  24. "result_text:txt", "bg:raw", "restart_btn:obj", "gaugua_back:raw", "close_btn:obj", "title_text:txt", "gaugua_top:obj",
  25. }
  26. self:GetChildren(nodes)
  27. lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("dailyRecharge_bg"),true)
  28. if self.need_refreshData then
  29. self:SetData()
  30. end
  31. end
  32. function DailyRechargeGuagualeView:InitEvent()
  33. local function onClickHandler(target)
  34. if self.close_btn_obj == target then
  35. self:Close()
  36. elseif self.restart_btn_obj == target then
  37. Message.show("重新刮奖")
  38. self.is_finished = true
  39. self:ReStartGame()
  40. end
  41. end
  42. AddClickEvent(self.close_btn_obj,onClickHandler)
  43. AddClickEvent(self.restart_btn_obj,onClickHandler)
  44. end
  45. function DailyRechargeGuagualeView:SetData()
  46. if self.is_loaded then
  47. self:ReStartGame()
  48. else
  49. self.need_refreshData = true
  50. end
  51. end
  52. function DailyRechargeGuagualeView:UpdateView()
  53. if not self.is_finished then
  54. return
  55. end
  56. if not self.is_init then
  57. self.gaugua_top_raw = self.gaugua_top_obj:AddComponent(typeof(UnityEngine.UI.RawImage))
  58. self.gaugua_top_raw.raycastTarget = true
  59. local load_done_call_back = function ( )
  60. self.is_init = true
  61. self.is_finished = false
  62. self.erase_handler = self.gaugua_top_obj:AddComponent(typeof(EraseHandler))
  63. self.erase_handler:SetCamera(MainCamera.Instance.uiCamera)
  64. local function erase_finish_call_back()
  65. self:CheckResult()
  66. end
  67. self.erase_handler:SetFinishCallBack(erase_finish_call_back)
  68. self.erase_handler:SetEraseArgs(30, 8)
  69. self.erase_handler:SetFinishPercent(0.5)
  70. self.erase_handler:Reset()
  71. self:InitResult()
  72. end
  73. lua_resM:setOutsideRawImage(self, self.gaugua_top_raw, GameResPath.GetReadWriteImage("erase_bg"), true, load_done_call_back)
  74. else
  75. self.is_finished = false
  76. self.erase_handler:Reset()
  77. self:InitResult()
  78. end
  79. end
  80. function DailyRechargeGuagualeView:InitResult()
  81. self.is_win = self:RandomData()
  82. if self.is_win then
  83. self.result_text_txt.text= "恭喜中奖"
  84. else
  85. self.result_text_txt.text= "谢谢惠顾"
  86. end
  87. end
  88. function DailyRechargeGuagualeView:CheckResult()
  89. if self.is_win then
  90. Message.show("恭喜中奖")
  91. else
  92. Message.show("谢谢惠顾")
  93. end
  94. self.is_finished = true
  95. end
  96. function DailyRechargeGuagualeView:RandomData()
  97. --先从2到倒数第二项,随机抽,保证一定能够错开
  98. local idx = math.random(1, 10)
  99. return idx > 5 and true or false
  100. end
  101. function DailyRechargeGuagualeView:ReStartGame()
  102. self:UpdateView()
  103. end