源战役客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

308 linhas
10 KiB

--普通礼包
GiftNormalView = GiftNormalView or BaseClass(BaseView)
local GiftNormalView = GiftNormalView
function GiftNormalView:__init()
self.base_file = "gift"
self.layout_file = "GiftNormalView"
self.layer_name = "Top"
--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.model:setIsOpenView(true)
self.base_height = 190
self.delay_time = 15
self.col_num = 5 -- 奖励展示的行展示数
self.max_num = 25
self.item_list = {}
self.load_callback = function ()
self.model.is_show_reward_view = true
self:LoadSuccess()
self:addEvents()
end
self.open_callback = function ()
self:setData()
self:setRewardShow()
end
self.close_callback = function ()
end
self.destroy_callback = function ()
self:DestroySuccess()
--判断是否需要弹物品使用框
local vo = ItemUseModel:getInstance():GetItemShowVo()
if vo then
GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo)
end
end
end
function GiftNormalView:Open(goods_vo)
self.goods_vo = goods_vo
BaseView.Open(self)
end
function GiftNormalView: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
SetSizeDeltaY(self.award_scroll, self.base_height)
end
function GiftNormalView:DestroySuccess()
self.model.is_show_reward_view = false
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 = {}
if self.success_event then
self.model:UnBind(self.success_event)
self.success_event = nil
end
if self.goods_item then
UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.goods_item)
self.goods_item = nil
end
self.model:handleCheckGoodsUseItem()
end
function GiftNormalView: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",
--重复开启的
"bg/btn_con/continue_btn:obj", "bg/btn_con/item_con:obj", "bg/btn_con/continue_btn/continue_btn_text:tmp", "bg/btn_con:obj",
"bg/btn_con/goods_num_text:tmp",
}
self:GetChildren(nodes)
SetAnchoredPositionY(self.bg, 0)
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)
end
function GiftNormalView: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, "#31e056"))
else
self:Close()
end
end
countDown()
if not self.timer_id then
self.timer_id = GlobalTimerQuest:AddPeriodQuest(countDown,1)
end
end
function GiftNormalView:addEvents()
local function click_func(target)
if target == self.continue_btn_obj then
GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT, 15050, self.goods_vo.goods_id, self.goods_vo.type_id, 1)
elseif target == self.mask_bg_obj or self.close_btn_obj then
self:Close()
end
end
AddClickEvent(self.mask_bg_obj, click_func)
AddClickEvent(self.continue_btn_obj, click_func)
AddClickEvent(self.close_btn_obj, click_func)
local function success_func(vo)
if vo.goods_id == self.goods_vo.goods_id then
self.goods_vo.goods_num = vo.goods_num
self:setData()
self:setRewardShow()
end
end
self.success_event = self.model:Bind(GiftModel.USE_GIFT_SUCCESS, success_func)
end
function GiftNormalView:setData()
if self.goods_vo == nil then return end
if not self.goods_item then
self.goods_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.item_con, nil, self.layer_name)
self.goods_item:SetItemSize(47, 47)
end
self.goods_item:SetData(self.goods_vo.type_id)
self.goods_item:SetNumText(self.goods_vo.goods_num)
-- self.goods_num_text_tmp.text = string.format("剩余数量: %s", HtmlColorTxt(self.goods_vo.goods_num, ColorUtil.GREEN_DARK))
self.goods_num_text_tmp.text = ""
if self.goods_vo.goods_num > 0 then
self.btn_con_obj:SetActive(true)
self.base_height = 155 + 50 + 6--50是按钮con的大小 5为间距
else
self.btn_con_obj:SetActive(false)
self.base_height = 155
end
end
--展示奖励
function GiftNormalView:setRewardShow()
if self.model.show_goods == nil then return end
self.show_goods_list = DeepCopy(self.model.show_goods)
local delete_list = {}
local basic
for index,data in ipairs(self.show_goods_list) do
basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(data.goodid)
if basic and basic.type == 52 and (basic.subtype == 1 or basic.subtype == 2 or basic.subtype == 3 or basic.subtype == 6) then
delete_list[data.goodid] = data.gnum
end
end
local goodid
for i = #self.show_goods_list,1,-1 do
goodid = self.show_goods_list[i].goodid
if delete_list[goodid] then
table.remove(self.show_goods_list,i)
end
end
local vo
for id,num in pairs(delete_list) do
for i = 1,num do
vo = {
type=0,
goodid=id,
gnum=1,
}
table.insert(self.show_goods_list,vo)
end
end
self:UpdateItemList()
self.model.show_goods = nil
end
function GiftNormalView:UpdateItemList( )
for k,v in pairs(self.item_list) do
v:SetVisible(false,nil,true)
end
local item_list = self.show_goods_list
local new_list = {}
for k,v in pairs(item_list) do
local goods_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(v.goodid)
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
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.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)
self.item_list[i] = item
end
local goods_Id, lock = GoodsModel:getInstance():GetMappingTypeId(v.type, v.goodid)
local goodVo = GoodsModel:getInstance():GetGoodsBasicByTypeId(goods_Id)
local stren_data = nil
if goodVo then
item:SetData(goods_Id, v.gnum, goodVo.color, stren_data, lock,true,nil)
else
-- error("没有找到物品信息 "..v.typeId)
end
item:SetVisible(false,nil,true)
end
self.scroll_mask_obj:SetActive(true)
local index = 0
if self.award_timer_id then
GlobalTimerQuest:CancelQuest(self.award_timer_id)
self.award_timer_id = nil
end
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
end