源战役客户端
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

188 satır
6.3 KiB

--自选礼包
GiftOptionalView = GiftOptionalView or BaseClass(BaseView)
function GiftOptionalView:__init()
self.base_file = "gift"
self.layout_file = "GiftOptionalView"
self.layer_name = "UI"
self.destroy_imm = true
self.is_set_zdepth = true
self.use_background = true
self.close_mode = CloseMode.CloseDestroy
self.model = GiftModel:getInstance()
-- self.append_to_ctl_queue = true --是否要添加进界面堆栈
self:AddPreLoadList("gift", {"GiftOptionalItem"})
self.background_alpha = 0.85
self.reward_item_list = {}
self.now_choice_list = {}
self.load_callback = function ()
self:LoadSuccess()
self:addEvents()
end
self.open_callback = function ()
self:setData()
end
self.close_callback = function ()
end
self.destroy_callback = function ()
self:DestroySuccess()
end
end
function GiftOptionalView:Open(goods_vo)
self.goods_vo = goods_vo
self.max_num = goods_vo.goods_num
BaseView.Open(self)
end
function GiftOptionalView:DestroySuccess()
if self.choice_event then
self.model:UnBind(self.choice_event)
self.choice_event = nil
end
for k,v in pairs(self.reward_item_list) do
v:DeleteMe()
end
self.reward_item_list = {}
-- if self.tabWindowComponent then
-- self.tabWindowComponent:DeleteMe()
-- self.tabWindowComponent = nil
-- end
end
function GiftOptionalView:LoadSuccess()
local nodes = {
-- "Window:raw","Window/windowCloseBtn:obj",
"tips_text:tmp",--"Window/windowTitleCon/windowTitleText:txt",
"sure_btn:obj", "ScrollView/Viewport/Content",
"bg:raw", "btn_close:obj",
}
self:GetChildren(nodes)
lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetViewBigBg('gift_optiona_bg'), false)
-- local closeWin_callback = function()
-- self:Close()
-- end
-- self.tabWindowComponent = UITabWindow.New(self.transform,{},nil,closeWin_callback,self.background_wnd,self.transform, UITabWindow.SizeSmallNoTab, false,nil,true)
-- self.tabWindowComponent:SetBackgroundRes("gift_optiona_bg_945_536")
-- self.tabWindowComponent:SetTitleText("自选礼包")
-- self.tabWindowComponent:ChangeShowFlag("Empower", 270013)
-- lua_resM:setOutsideRawImage(self, self.Window_raw, GameResPath.GetViewBigBg("gift_optiona_bg_945_536"))
end
function GiftOptionalView:addEvents()
local function click_func(target)
if target == self.btn_close_obj then
self:Close()
elseif target == self.sure_btn_obj then
local num = self:GetMaxNum()
if num >= self.max_num then
Message.show("您还没选择领取的物品哦~")
else
local goods_id = self.goods_vo.goods_id
local type_id = self.goods_vo.type_id
-- local num = GoodsModel:getInstance():GetTypeGoodsNum(type_id)
local chose_num = 0
local list = {}
local sum_chosen_num = 0
for k,v in pairs(self.now_choice_list) do
if v > 0 then
sum_chosen_num = sum_chosen_num + v
local temp = {seqno = self.optional_info.goods_list[k].id, seqnum = v}
table.insert(list, temp)
end
end
if sum_chosen_num % self:GetOptionalNum(type_id) ~= 0 then
Message.show("有剩余选择次数未使用")
return
end
chose_num = sum_chosen_num/self:GetOptionalNum(type_id)
self.model:Fire(GiftModel.PROTO_CCMD_EVENT, 15086, goods_id, type_id, chose_num, list)
end
end
end
AddClickEvent(self.sure_btn_obj, click_func)
AddClickEvent(self.btn_close_obj, click_func)
local function choice_func(index,count)
self:handleOneChoice(index,count)
end
self.choice_event = self.model:Bind(GiftModel.CHOICE_ONE_ITEM, choice_func)
end
function GiftOptionalView:GetOptionalNum( type_id )
for k,v in pairs(Config.Optionalgift) do
if v.goods_id == type_id then
return v.optional_num
end
end
return 0
end
function GiftOptionalView:setData()
local goods_base = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.goods_vo.type_id)
local str_color = WordManager.GetGoodsColor(goods_base.color)
local kind, list = self.model:getOptionalConfig(self.goods_vo.type_id)
local optional_num = self:GetOptionalNum(self.goods_vo.type_id)
self.max_num = self.goods_vo.goods_num * optional_num --GoodsModel:getInstance():GetTypeGoodsNum(self.goods_vo.type_id)
self.optional_info = list
local color = tonumber(self.max_num) == 0 and ColorUtil.RED_DARK or ColorUtil.GREEN_DARK
self.tips_text_tmp.text = string.format("剩余可选数量:%s个", HtmlColorTxt( self.max_num, color))
function get_func( )
return self:GetMaxNum()
end
for i,v in ipairs(self.optional_info.goods_list) do
local item = self.reward_item_list[i]
if not item then
item = GiftOptionalItem.New(self.Content, nil, self.layer_name)
-- item:SetPosition(110*(i-1), 0)
item.GetMaxNum = get_func
self.reward_item_list[i] = item
end
item:setData(i, v)
end
end
function GiftOptionalView:GetMaxNum( )
local num = 0
for k,v in pairs(self.now_choice_list) do
num = num + v
end
if self.max_num >= num then
return self.max_num - num
else
return 0
end
end
function GiftOptionalView:handleOneChoice(index,count)
self.now_choice_list[index] = count
local num = 0
for k,v in pairs(self.now_choice_list) do
num = num + v
end
local rest_num = self.max_num - num
local color = tonumber(rest_num) == 0 and ColorUtil.RED_DARK or ColorUtil.GREEN_DARK
self.tips_text_tmp.text = string.format("剩余可选数量:%s个", HtmlColorTxt( rest_num, color))
end
function GiftOptionalView:checkBoolEnough()
local now_count = 0
for k,v in pairs(self.now_choice_list) do
now_count = now_count + 1
end
if now_count == self.optional_info.can_count then
return 1
elseif now_count > self.optional_info.can_count then
return 2
else
return 3
end
end