|
|
- --活动礼包开启
- GiftActNormalView = GiftActNormalView or BaseClass(BaseView)
- local GiftActNormalView = GiftActNormalView
- function GiftActNormalView:__init()
- self.base_file = "gift"
- self.layout_file = "GiftActNormalView"
- self.layer_name = "Activity"
- --self.use_local_view = true
- self.click_bg_toClose = true
- self.destroy_imm = true
- self.use_background = true
- self.is_set_zdepth = true
- self.close_mode = CloseMode.CloseDestroy
- self.model = GiftModel:getInstance()
- self.delay_time = 10
- self.col_num = 5 -- 奖励展示的行展示数
- self.max_num = 10
- self.item_list = {}
- self.name_item_list = {}
-
- self.load_callback = function ()
- self:LoadSuccess()
- self:addEvents()
- end
-
- self.open_callback = function ()
- self:UpdateView()
- end
-
- self.close_callback = function ()
-
- end
-
- self.destroy_callback = function ()
- self:DestroySuccess()
- end
- end
-
- function GiftActNormalView:Open(show_goods_list,only_read_goods_type_id)
- self.show_goods_list = show_goods_list
- self.only_read_goods_type_id = only_read_goods_type_id
- BaseView.Open(self)
- end
-
-
- function GiftActNormalView:DestroySuccess()
- 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 = {}
-
-
- for k,v in pairs(self.name_item_list) do
- v:DeleteMe()
- v = nil
- end
- self.name_item_list = {}
- end
-
- function GiftActNormalView:LoadSuccess()
- local nodes = {
- "bg:raw", "titlebg:img", "mask_bg:obj",
- "time_text:tmp", "awardScroll:obj", "awardScroll/Viewport/awardCon", "awardNCon:obj",
- }
- self:GetChildren(nodes)
-
- lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetViewBigBg("com_act_reward_result_bg"), false)
- lua_resM:setOutsideImageSprite(self, self.titlebg_img, GameResPath.GetCommonImage("com_act_reward_title_bg"),false)
- end
-
- function GiftActNormalView:addEvents()
- local function click_func(target)
- if target == self.mask_bg_obj then
- self:Close()
- end
- end
- AddClickEvent(self.mask_bg_obj, click_func)
- end
-
- function GiftActNormalView:UpdateView()
- local item_list = self.show_goods_list or {}
- if #item_list <= 5 then--带名字的道具
- self:UpdateNameItemList()
- else
- self:UpdateItemList()
- end
- end
-
- function GiftActNormalView: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 = string.format("点击任意区域关闭 (%s)",HtmlColorTxt(time.."s",ColorUtil.GREEN_DARK))
- else
- self:Close()
- end
- end
- countDown()
- if not self.timer_id then
- self.timer_id = GlobalTimerQuest:AddPeriodQuest(countDown,1)
- end
- end
-
- function GiftActNormalView:UpdateNameItemList( )
- for k,v in pairs(self.name_item_list) do
- v:SetVisible(false,nil,true)
- end
- local item_list = self.show_goods_list or {}
- local new_list = {}
- for k,v in pairs(item_list) do
- local goods_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(v[2])
- if goods_vo then
- v.sort_id = goods_vo.color * 10000000000000 + goods_vo.type_id
- if v.type == GoodsModel.TYPE.EQUIP then--装备+100W
- v.sort_id = v.sort_id + 10000000
- end
- new_list[#new_list + 1] = v
- end
- end
- local sort_func = function ( a, b )
- return a.sort_id > b.sort_id
- end
- table.sort(new_list, sort_func)
- item_list = new_list
- if not item_list or TableSize(item_list) == 0 then return end
- local len = #item_list
- self.parent_con = self.awardNCon
- self.awardScroll_obj:SetActive(false)
- self.awardNCon_obj:SetActive(true)
- local x = 0
- local y = 0
- for i, v in ipairs(item_list) do
- local item = self.name_item_list[i]
- if item == nil then
- item = GiftActNormalItem.New(self.parent_con,nil,self.layer_name)
- self.name_item_list[i] = item
- end
- item:SetData(i,v,self.only_read_goods_type_id)
- item:SetVisible(false,nil,true)
- end
-
- local index = 0
- local function countDown()
- index = index + 1
- if len >= index then
- if self.name_item_list[index] then
- self.name_item_list[index]:SetVisible(true,nil,true)
- 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
- end
-
- function GiftActNormalView:UpdateItemList( )
- for k,v in pairs(self.item_list) do
- v:SetVisible(false,nil,true)
- end
- local item_list = self.show_goods_list or {}
- local new_list = {}
- for k,v in pairs(item_list) do
- local goods_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(v[2])
- if goods_vo then
- v.sort_id = goods_vo.color * 10000000000000 + goods_vo.type_id
- if v.type == GoodsModel.TYPE.EQUIP then--装备+100W
- v.sort_id = v.sort_id + 10000000
- end
- new_list[#new_list + 1] = v
- end
- end
- local sort_func = function ( a, b )
- return a.sort_id > b.sort_id
- end
- table.sort(new_list, sort_func)
- item_list = new_list
- if not item_list or TableSize(item_list) == 0 then return end
- local len = #item_list
- --如果比最大高度要高 那就只能滚动了
- local space_x = 30
- local space_y = 20
- local item_height = 78
- self.parent_con = self.awardCon
- self.awardNCon_obj:SetActive(false)
- self.awardScroll_obj:SetActive(true)
- 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.resetTransform = true
- item:SetItemSize(78,78)
- self.item_list[i] = item
- end
- if not self.only_read_goods_type_id then
- local goods_Id, lock = GoodsModel:getInstance():GetMappingTypeId(v[1], v[2])
- local goodVo = GoodsModel:getInstance():GetGoodsBasicByTypeId(goods_Id)
- local stren_data = nil
- if goodVo then
- item:SetData(goods_Id, v[3], nil, stren_data, lock,true,nil)
- else
- -- error("没有找到物品信息 "..v.typeId)
- end
- else--如果物品格式第一个数字不是按照物品类型来的,那就直接展示物品
- item:SetData(v[2], v[3])
- end
-
- item:SetVisible(false,nil,true)
- x = (78+41.5)*((i-1)%self.col_num)
- y = -(78+20)*math.floor((i-1)/self.col_num)
- item:SetPosition(x,y)
- if v[4] then
- item:SetNumLimitVisible( true, v[4])
- end
- end
- local max_height = (78+20) * math.ceil(len/self.col_num) + 100--最大高度限制10行
- SetSizeDeltaY(self.awardCon,max_height)
- 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)
- end
- -- if index%self.col_num == 0 and index ~= 0 and index > self.col_num then
- -- SetAnchoredPositionY(self.awardCon,(78+20)*math.floor(index/self.col_num))
- -- print("huangcong:GiftActNormalView [start:244] :", math.floor(index/self.col_num),index)
- -- end
- 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
- 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
- end
|