|
|
- --通用奖励结算界面
- ComAwardResultView = ComAwardResultView or BaseClass(BaseView)
- local ComAwardResultView = ComAwardResultView
-
- function ComAwardResultView:__init()
- self.base_file = "uiComponent"
- self.layout_file = "ComAwardResultView"
- self.layer_name = "Top"
- self.destroy_imm = true
- self.use_background = true
- self.hide_maincancas = true --全屏界面需要放开隐藏主UI
- self.change_scene_close = true
- self.append_to_ctl_queue = false --是否要添加进界面堆栈
- self.need_show_money = false --是否要显示顶部的金钱栏
- self.model = GuildModel:getInstance()
- self.base_height = 155
- self.delay_time = 15
- self.col_num = 5 -- 奖励展示的行展示数
- self.max_num = 25
- self.item_list = {}
- self.is_set_zdepth = true --是否设置z深度,当需要盖住下层的UI界面上的模型时,要设true
- self.jump_close = true --用于某些界面跳转了之后就需要关掉界面
- ItemUseModel:getInstance():HideItemUseView( )
-
- self.load_callback = function ()
- self:LoadSuccess()
- self:AddEvent()
- end
- self.open_callback = function ( )
- self:OpenSuccess()
- end
- self.destroy_callback = function ( )
- self:DestroySuccess()
- end
- end
-
- function ComAwardResultView:DestroySuccess()
- if self.pos_id then
- TweenLite.Stop(self.pos_id)
- self.pos_id = nil
- end
-
- if self.award_timer_id then
- GlobalTimerQuest:CancelQuest(self.award_timer_id)
- self.award_timer_id = nil
- end
-
- if self.timer_id then
- GlobalTimerQuest:CancelQuest(self.timer_id)
- self.timer_id = nil
- end
-
- for i,item in pairs(self.item_list) do
- UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, item)
- end
- self.item_list = {}
-
- ItemUseModel:getInstance():ShowItemUseView( )
- end
-
- function ComAwardResultView:LoadSuccess()
- local nodes = {
- "bg/titlebg:img", "bg/scroll_mask:obj",
- "bg:img", "bg/time_text:tmp", "bg/award_con:obj",
- "mask_bg:obj","bg/close_btn:obj",
- "bg/award_scroll:obj", "bg/award_scroll/Viewport/award_scroll_con",
- }
- self:GetChildren(nodes)
-
- lua_resM:setOutsideImageSprite(self, self.bg_img, GameResPath.GetCommonImage("com_award_result_view_new_bg"),false)
- lua_resM:setOutsideImageSprite(self, self.titlebg_img, GameResPath.GetCommonImage("com_award_result_view_new_title"),false)
- -- local function onDelay()
- -- local function end_call_func( ... )
- -- if self.effect_forever then
- -- self:AddUIEffect("getgoods_02",self.effect_forever, self.layer_name, nil, 1, true,nil,nil,nil)
- -- end
- -- end
- -- self:AddUIEffect("getgoods_01",self.effect, self.layer_name, nil, 1, false,nil,nil,end_call_func)
- -- end
- -- self.slow_effect_id = GlobalTimerQuest:AddDelayQuest(onDelay, 0.1)
-
- if self.need_refreshData then
- self:UpdateView( )
- end
- end
-
- function ComAwardResultView:AddEvent()
- local function onBtnClickHandler(target,x,y)
- if target == self.mask_bg_obj or self.close_btn_obj then--关闭
- self:BtnCloseEvt()
- end
- end
- AddClickEvent(self.mask_bg_obj,onBtnClickHandler)
- AddClickEvent(self.close_btn_obj,onBtnClickHandler)
- end
-
- --data.delay_time--关闭时间
- --data.title_res--标题资源
- --data.title_ab_name--标题资源ab包路径
- --data.award = {kind,type_id,goods_num,goods_vo}
- --data.col_num = 6 -- 每行展示的个数
- function ComAwardResultView:Open( data )
- data.col_num = 5--限定5了 不能改
- self.data = data
- self.delay_time = self.data and self.data.delay_time or self.delay_time
- BaseView.Open(self)
- end
-
- function ComAwardResultView:OpenSuccess( )
- self:UpdateView()
- end
-
- function ComAwardResultView:UpdateView( data )
- self.data = data or self.data
- if self.is_loaded then
- self.need_refreshData = false
- else
- self.need_refreshData = true
- return
- end
- if not self.data then return end
- if data then--有新数据 就重置
- self:Reset()
- end
- self:UpdateItemList()
- -- self:UpdateTime()
- if self.data.title_res then
- lua_resM:setOutsideImageSprite(self, self.titlebg_img, GameResPath.GetCommonImage(self.data.title_res),false)
- end
- end
-
- function ComAwardResultView:Reset( )
- if self.pos_id then
- TweenLite.Stop(self.pos_id)
- self.pos_id = nil
- end
- if self.award_timer_id then
- GlobalTimerQuest:CancelQuest(self.award_timer_id)
- self.award_timer_id = nil
- end
- if self.timer_id then
- GlobalTimerQuest:CancelQuest(self.timer_id)
- self.timer_id = nil
- end
- if self.data then
- self.data.col_num = 5--限定5了 不能改
- self.delay_time = self.data.delay_time or self.delay_time
- end
- SetSizeDeltaY(self.award_scroll, self.base_height)
- end
-
- function ComAwardResultView:BtnCloseEvt()--关闭按钮回调
- if self.data and self.data.close_callback then
- self.data.close_callback()
- end
- self:Close()
- end
-
- function ComAwardResultView:UpdateItemList( )
- for k,v in pairs(self.item_list) do
- v:SetVisible(false,nil,true)
- end
- self.col_num = self.data.col_num or self.col_num
- local item_list = self.data.award
- if not item_list or TableSize(item_list) == 0 then return end
- local len = #item_list
- self.parent_con = self.award_scroll_con
- self.award_scroll_obj:SetActive(true)
- --如果比最大高度要高 那就只能滚动了
- local offer_x = 4
- local offer_y = 0
- local space_x = 8
- local space_y = 8
- local item_height = 78
- if len > self.max_num then
- self.parent_con = self.award_scroll_con
- self.award_con_obj:SetActive(false)
- SetSizeDeltaY(self.award_scroll, (item_height + space_y) * math.ceil(self.max_num/self.col_num))
- end
- local max_height = (item_height + space_y) * (math.ceil(self.max_num/self.col_num)-1)--最大高度限制5行
- local x = 0
- local y = 0
- for i, v in ipairs(item_list) do
- local item = self.item_list[i]
- if item == nil then
- item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.parent_con)
- item:SetItemSize(78,78)
- item:SetGoodsVo(v[4])
- self.item_list[i] = item
- end
- local goods_Id, lock = GoodsModel:getInstance():GetMappingTypeId(v[1], v[2])
- local goodVo = GoodsModel:getInstance():GetGoodsBasicByTypeId(goods_Id)
- local stren_data = nil
- if v[4] then
- stren_data = EquipModel:getInstance():GetBagEquipAwaraItemInfo(v[4])
- stren_data.equip_key = "EquipView"
- end
- if not v.is_mul then--副本多倍
- if v.is_rare == 2 then
- item:SetNumLimitVisible(true,12)
- elseif v.is_rare == 1 then
- item:SetNumLimitVisible(true,13)
- end
- else
- item:SetNumLimitVisible(v.is_mul ~= nil ,15)
- end
- if goodVo then
- item:SetData(goods_Id, v[3], goodVo.color, stren_data, lock,true,nil)
- else
- -- error("没有找到物品信息 "..v.typeId)
- end
- item:SetVisible(false,nil,true)
- end
-
- if not self.data.not_show_anim then
- self.scroll_mask_obj:SetActive(true)
- local index = 0
- local function countDown()
- index = index + 1
- if len >= index then
- if self.item_list[index] then
- self.item_list[index]:SetVisible(true,nil,true)
- local height = (item_height + space_y) * (math.ceil(index/self.col_num) - 1)
- height = height >= max_height and max_height or height
- SetSizeDeltaY(self.bg, self.base_height + height)
- if index > self.max_num then
- SetSizeDeltaY(self.award_scroll, (item_height + space_y) * math.ceil(self.max_num/self.col_num))
- else
- SetSizeDeltaY(self.award_scroll, (item_height + space_y) * math.ceil(index/self.col_num))
- end
- SetSizeDeltaY(self.parent_con, (item_height + space_y) * math.ceil(index/self.col_num))
- --如果大于了就得滚动
- if index >= self.max_num then
- local pos_y = (math.ceil((index - self.max_num) / self.col_num) )* (item_height + space_y)
- if self.pos_id then
- TweenLite.Stop(self.pos_id)
- self.pos_id = nil
- end
- self.pos_id = TweenLite.to(self, self.parent_con, TweenLite.UiAnimationType.ANCHORED_POSY, pos_y, 0.15, callback)
- end
- end
- else
- if self.award_timer_id then
- GlobalTimerQuest:CancelQuest(self.award_timer_id)
- self.award_timer_id = nil
- end
- self:UpdateTime()
- end
- end
- if not self.award_timer_id then
- self.award_timer_id = GlobalTimerQuest:AddPeriodQuest(countDown,0.15)
- end
- else
- if self.award_timer_id then
- GlobalTimerQuest:CancelQuest(self.award_timer_id)
- self.award_timer_id = nil
- end
- for k,v in pairs(self.item_list) do
- v:SetVisible(true,nil,true)
- end
- end
- end
-
- function ComAwardResultView:UpdateTime( )
- local time = self.delay_time
- local function countDown()
- if self._use_delete_method then return end
- time = time - 1
- if time > 0 then
- self.time_text_tmp.text = (self.data.time_des or "点击任意处继续")..HtmlColorTxt("("..time.."s)", "#31e056")
- else
- self:Close()
- end
- end
- countDown()
- if not self.timer_id then
- self.timer_id = GlobalTimerQuest:AddPeriodQuest(countDown,1)
- end
- end
|