源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

218 lines
6.5 KiB

BagItem = BagItem or BaseClass(BaseItem)
function BagItem:__init(parent_wnd, prefab_asset, layer_name)
self.base_file = "bag"
self.layout_file = "BagItem"
self.is_delay_callback = true
self.Bag_model = BagModel:getInstance()
self.model = GoodsModel:getInstance()
self.cur_layout = lua_viewM.cur_layout or "" --公共组件,要判断是否对应界面
self.lock_index = nil
self.goods_pos_type = nil
self.index = nil
-- self.use_local_view = true
self:Load()
end
function BagItem:Load_callback()
self.transform.sizeDelta = Vector2(78, 78)
self.equip_conta = self:GetChild("equip_conta")
self.default_conta,self.imgLock,self.touch,self.imgSelect
= GetChildGameObjects(self.transform,
{
"default_conta","imgLock","touch","imgSelect"
})
if self.need_refreshData then
self:SetData(self.data,self.mask_id,self.hide_color_effect, self.spe_color_effect, self.equip_key)
end
self:InitEvent()
end
function BagItem:InitEvent()
local function click_fun(target,x,y)
if self.model.show_warehouse and not self.lock_index then
if self.goods_pos_type == GoodsModel.GOODS_POS_TYPE.bag then
if TimeUtil:getServerTime() - self.Bag_model.cur_click_bag_time < self.Bag_model.double_click_time then
if self.Bag_model.cur_click_bag_index == self.index then
if self.timer_out then
TimerQuest.CancelQuest(GlobalTimerQuest, self.timer_out)
self.timer_out = false
end
if self.data and self.data.goods_id then
GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT, 15003, self.data.goods_id, GoodsModel.GOODS_POS_TYPE.bag, GoodsModel.GOODS_POS_TYPE.warehouse)
end
end
else
local function delay_fun()
if self.Bag_model.cur_click_bag_index and self.Bag_model.cur_click_bag_index == self.index then
self.Bag_model.cur_click_bag_index = nil
self:ClickHandler(target,x,y)
end
end
self.timer_out = setTimeout(delay_fun,self.Bag_model.double_click_time)
end
self.Bag_model.cur_click_bag_index = self.index
self.Bag_model.cur_click_bag_time = TimeUtil:getServerTime()
elseif self.goods_pos_type == GoodsModel.GOODS_POS_TYPE.warehouse then
if TimeUtil:getServerTime() - self.Bag_model.cur_click_warehouse_time < self.Bag_model.double_click_time then
if self.Bag_model.cur_click_warehouse_index == self.index then
if self.timer2_out then
TimerQuest.CancelQuest(GlobalTimerQuest, self.timer2_out)
self.timer2_out = false
end
if self.data and self.data.goods_id then
GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT, 15003, self.data.goods_id, GoodsModel.GOODS_POS_TYPE.warehouse, GoodsModel.GOODS_POS_TYPE.bag)
end
end
else
local function delay_fun()
if self.Bag_model.cur_click_warehouse_index and self.Bag_model.cur_click_warehouse_index == self.index then
self.Bag_model.cur_click_warehouse_index = nil
self:ClickHandler(target,x,y)
end
end
self.timer2_out = setTimeout(delay_fun,self.Bag_model.double_click_time)
end
self.Bag_model.cur_click_warehouse_index = self.index
self.Bag_model.cur_click_warehouse_time = TimeUtil:getServerTime()
end
else
self:ClickHandler(target,x,y)
end
end
AddClickEvent(self.touch, click_fun, nil, false)
end
function BagItem:ClickHandler(target,x,y)
if self.goods_pos_type and self.index then
self.model:Fire(GoodsModel.CLICK_BAG_ITEM, self.index, self.goods_pos_type) --在各自的调用类中去绑定此事件去处理点击效果
end
if self.lock_index then
BagModel:getInstance():Fire(BagModel.OPEN_ENLARGE_VIEW,self.goods_pos_type,self.lock_index)
elseif self.data and self.data.goods_num > 0 then
self.icon_item:ClickCallFun(target,x,y)
end
end
function BagItem:SetCallback(cb)
self.callback = cb
end
function BagItem:SetIndex(index)
self.index = index
end
function BagItem:SetItem(data)
self.data = data
if self.data == nil then return end
if data.goods_num > 0 then
if not self.icon_item then
self.icon_item = BagIconItem.New(self.equip_conta,nil,self.layer_name)
self.icon_item:SetItemSize(78,78)
self.icon_item:SetEnableClick(false)
end
self.icon_item:SetVisible(true)
self.icon_item:SetData(data,nil,self.mask_id, self.hide_color_effect, self.spe_color_effect, self.equip_key)
if data.type == 14 and (data.subtype == 9 or data.subtype == 10) then
self.icon_item:SetDataDoubleStone(data.goods_id)
end
else
self:SetVoid()
end
self.lock_index = nil
if self.imgLock then
self.imgLock:SetActive(false)
end
end
--hide_color_effect 隐藏特效,临时使用
function BagItem:SetData(data,mask_id,hide_color_effect, spe_color_effect,equip_key)
self.data = data
self.mask_id = mask_id
self.hide_color_effect = hide_color_effect
self.spe_color_effect = spe_color_effect
self.equip_key = equip_key
if self.is_loaded then
if not self.data then return end
self.need_refreshData = false
self:SetVoid() --先清空数据
if data and data.lock_index then
self:SetLock(data.lock_index)
elseif data and data.type_id and data.goods_num and data.goods_num > 0 then
self:SetItem(data)
end
if data and data.index then
self:SetIndex(data.index)
end
self.default_conta.gameObject:SetActive(true)
else
self.need_refreshData = true
end
if data.type_id ~= nil then
self:SetGameObjectName(data.type_id)
end
end
function BagItem:SetSellState(flag)
if self.icon_item then
self.icon_item:SetSellState(flag)
end
end
--锁住的格子
function BagItem:SetLock(lock_index)
self.lock_index = lock_index
if self.icon_item then
self.icon_item:SetVisible(false, false)
end
if self.imgLock then
self.imgLock:SetActive(true)
end
end
--空格子
function BagItem:SetVoid()
self.data = nil
self.lock_index = nil
if self.icon_item then
self.icon_item:SetVisible(false, false)
end
if self.imgLock then
self.imgLock:SetActive(false)
end
if self.imgSelect then
self.imgSelect:SetActive(false)
end
end
function BagItem:SetPosType(pos_type)
self.goods_pos_type = pos_type
end
function BagItem:SetSelect(bool)
if self.imgSelect then
self.imgSelect:SetActive(bool)
end
end
function BagItem:__delete()
if self.icon_item then
self.icon_item:DeleteMe()
self.icon_item = nil
end
if self.event_id then
self.model:UnBind(self.event_id)
self.event_id = nil
end
end
function BagItem:UpdateLimitState()
if self.icon_item and self.data then
local state = BagModel:getInstance():GetGoodsLimitState(self.data)
self.icon_item:SetLimitState(state)
if state == BagModel.GoodsLimitState.TimeOut then
return self.data.goods_id
end
end
end