DailyRechargeGuagualeView = DailyRechargeGuagualeView or BaseClass(BaseView)
|
|
|
|
function DailyRechargeGuagualeView:__init()
|
|
self.base_file = "dailyRecharge"
|
|
self.layout_file = "DailyRechargeGuagualeView"
|
|
self.layer_name = "Top"
|
|
self.use_background = true
|
|
self.is_set_zdepth = true
|
|
|
|
self.model = RechargeActivityModel:getInstance()
|
|
|
|
self.is_init = false
|
|
self.is_win = false
|
|
self.is_finished = true
|
|
|
|
self.load_callback = function ()
|
|
self:LoadSuccess()
|
|
self:InitEvent()
|
|
end
|
|
self.destroy_callback = function ()
|
|
self:Clear()
|
|
end
|
|
end
|
|
|
|
function DailyRechargeGuagualeView:Clear()
|
|
|
|
end
|
|
|
|
function DailyRechargeGuagualeView:LoadSuccess()
|
|
local nodes = {
|
|
"result_text:txt", "bg:raw", "restart_btn:obj", "gaugua_back:raw", "close_btn:obj", "title_text:txt", "gaugua_top:obj",
|
|
}
|
|
self:GetChildren(nodes)
|
|
lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("dailyRecharge_bg"),true)
|
|
|
|
if self.need_refreshData then
|
|
self:SetData()
|
|
end
|
|
end
|
|
|
|
function DailyRechargeGuagualeView:InitEvent()
|
|
local function onClickHandler(target)
|
|
if self.close_btn_obj == target then
|
|
self:Close()
|
|
elseif self.restart_btn_obj == target then
|
|
Message.show("重新刮奖")
|
|
self.is_finished = true
|
|
self:ReStartGame()
|
|
end
|
|
end
|
|
|
|
AddClickEvent(self.close_btn_obj,onClickHandler)
|
|
AddClickEvent(self.restart_btn_obj,onClickHandler)
|
|
end
|
|
|
|
|
|
function DailyRechargeGuagualeView:SetData()
|
|
if self.is_loaded then
|
|
self:ReStartGame()
|
|
else
|
|
self.need_refreshData = true
|
|
end
|
|
end
|
|
|
|
|
|
function DailyRechargeGuagualeView:UpdateView()
|
|
if not self.is_finished then
|
|
return
|
|
end
|
|
if not self.is_init then
|
|
self.gaugua_top_raw = self.gaugua_top_obj:AddComponent(typeof(UnityEngine.UI.RawImage))
|
|
self.gaugua_top_raw.raycastTarget = true
|
|
local load_done_call_back = function ( )
|
|
self.is_init = true
|
|
self.is_finished = false
|
|
self.erase_handler = self.gaugua_top_obj:AddComponent(typeof(EraseHandler))
|
|
self.erase_handler:SetCamera(MainCamera.Instance.uiCamera)
|
|
local function erase_finish_call_back()
|
|
self:CheckResult()
|
|
end
|
|
self.erase_handler:SetFinishCallBack(erase_finish_call_back)
|
|
self.erase_handler:SetEraseArgs(30, 8)
|
|
self.erase_handler:SetFinishPercent(0.5)
|
|
self.erase_handler:Reset()
|
|
self:InitResult()
|
|
end
|
|
lua_resM:setOutsideRawImage(self, self.gaugua_top_raw, GameResPath.GetReadWriteImage("erase_bg"), true, load_done_call_back)
|
|
else
|
|
self.is_finished = false
|
|
self.erase_handler:Reset()
|
|
self:InitResult()
|
|
end
|
|
|
|
end
|
|
|
|
function DailyRechargeGuagualeView:InitResult()
|
|
self.is_win = self:RandomData()
|
|
if self.is_win then
|
|
self.result_text_txt.text= "恭喜中奖"
|
|
else
|
|
self.result_text_txt.text= "谢谢惠顾"
|
|
end
|
|
end
|
|
|
|
|
|
function DailyRechargeGuagualeView:CheckResult()
|
|
if self.is_win then
|
|
Message.show("恭喜中奖")
|
|
else
|
|
Message.show("谢谢惠顾")
|
|
end
|
|
self.is_finished = true
|
|
|
|
end
|
|
|
|
function DailyRechargeGuagualeView:RandomData()
|
|
--先从2到倒数第二项,随机抽,保证一定能够错开
|
|
local idx = math.random(1, 10)
|
|
return idx > 5 and true or false
|
|
end
|
|
|
|
function DailyRechargeGuagualeView:ReStartGame()
|
|
self:UpdateView()
|
|
end
|