|
|
DepotView = DepotView or BaseClass(BaseItem)
|
|
|
|
function DepotView:__init(parent_wnd, prefab_asset, layer_name)
|
|
self.base_file = "bag"
|
|
self.layout_file = "DepotView"
|
|
|
|
self.item_list = {}
|
|
self.curr_list = {}
|
|
self.event_list = {}
|
|
self.column_num = 4 --一行多少个图标
|
|
self.loop_mgr = LoopScrowViewMgr.New()
|
|
self.model = GoodsModel:getInstance()
|
|
self.titleTabbar = {[1] = "全部",[2] = "常用",[3] = "礼包",}
|
|
self.title_cur_index = 1
|
|
self.titleTabbar_list = {}
|
|
self.titleTabbar_text = {}
|
|
self.need_sort = true
|
|
self.full_screen = true
|
|
self.ani_right = 400
|
|
self:Load()
|
|
end
|
|
|
|
--清除界面
|
|
function DepotView:__delete()
|
|
self:Clear()
|
|
end
|
|
|
|
function DepotView:Load_callback()
|
|
self:LoadSuccess()
|
|
self:InitEvent()
|
|
end
|
|
|
|
function DepotView:Clear()
|
|
for i,item in pairs(self.item_list) do
|
|
item:DeleteMe()
|
|
end
|
|
self.item_list = {}
|
|
|
|
for k,v in pairs(self.event_list) do
|
|
GoodsModel:getInstance():UnBind(v)
|
|
v = nil
|
|
end
|
|
|
|
if self.loop_mgr then
|
|
self.loop_mgr:DeleteMe()
|
|
self.loop_mgr = nil
|
|
end
|
|
|
|
if self.maskID then
|
|
self:UnRegisterMask(self.maskID)
|
|
self.maskID = nil
|
|
end
|
|
|
|
if self.step_sort_bag_cd_id then
|
|
GlobalTimerQuest:CancelQuest(self.step_sort_bag_cd_id)
|
|
self.step_sort_bag_cd_id = nil
|
|
end
|
|
end
|
|
|
|
function DepotView:Close()
|
|
BaseView.Close(self)
|
|
end
|
|
|
|
function DepotView:LoadSuccess()
|
|
self.scroll_image = self:GetChild("right/ScrollView/Viewport"):GetComponent("Image")
|
|
self.scroll,self.scroll_content,
|
|
self.con = GetChildTransforms(self.transform,
|
|
{
|
|
"right/ScrollView","right/ScrollView/Viewport/Content",
|
|
"right/ScrollView/Viewport/Content/con"
|
|
})
|
|
self.sortBtn = GetChildGameObjects (self.transform,
|
|
{
|
|
"right/Button"
|
|
})
|
|
|
|
|
|
self.sortBtn_img = self:GetChild("right/Button"):GetComponent("Image")
|
|
self.sortBtn_txt = self:GetChild("right/Button/Text"):GetComponent("TextMeshProUGUI")
|
|
|
|
for i=1,#self.titleTabbar do
|
|
table.insert(self.titleTabbar_list,self:GetChild("right/titleBarCon/tabbar"..i).gameObject)
|
|
table.insert(self.titleTabbar_text,self:GetChild("right/titleBarCon/tabbar"..i.."/Background/Text"):GetComponent("TextMeshProUGUI"))
|
|
end
|
|
self:SetTextColor(self.title_cur_index)
|
|
self.maskID = self:RegisterMask(self.scroll_image)
|
|
BagModel:getInstance().cur_click_bag_time = 0
|
|
BagModel:getInstance().cur_click_warehouse_time = 0
|
|
self:UpdateItems(true)
|
|
end
|
|
|
|
|
|
function DepotView:InitEvent()
|
|
local function onBtnClickHandler(target)
|
|
if target == self.close_btn then
|
|
self:Close()
|
|
elseif target == self.sortBtn then
|
|
self.need_sort = true
|
|
if BagModel:getInstance():TrySortBag(GoodsModel.GOODS_POS_TYPE.warehouse) then
|
|
self.model:DelayFire(GoodsModel.CHANGE_WAREHOUSE_LIST)
|
|
end
|
|
self:UpdateSortCD()
|
|
--GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT,15004,GoodsModel.GOODS_POS_TYPE.warehouse)
|
|
else
|
|
for i,v in ipairs(self.titleTabbar) do
|
|
local obj = self.titleTabbar_list[i]
|
|
if target == obj then
|
|
self.title_cur_index = i
|
|
self:SetTextColor(self.title_cur_index)
|
|
self:UpdateItems()
|
|
self.loop_mgr:RestToBeginning()
|
|
break
|
|
end
|
|
end
|
|
end
|
|
end
|
|
--AddClickEvent(self.close_btn,onBtnClickHandler)
|
|
AddClickEvent(self.sortBtn,onBtnClickHandler)
|
|
for i=1,#self.titleTabbar do
|
|
AddClickEvent(self.titleTabbar_list[i],onBtnClickHandler)
|
|
end
|
|
|
|
local function onChangeBagListHandler()
|
|
self:UpdateItems()
|
|
end
|
|
self.event_list[1] = self.model:Bind(GoodsModel.CHANGE_WAREHOUSE_LIST,onChangeBagListHandler)
|
|
|
|
local function event_func2()
|
|
self:UpdateItems()
|
|
end
|
|
self.event_list[2] = self.model:BindOne("slot_info_pos_3",event_func2)
|
|
|
|
local click_fun = function (index,pos_type)
|
|
if pos_type == GoodsModel.GOODS_POS_TYPE.warehouse then
|
|
self.click_item_index = index
|
|
self:UpdateItemState()
|
|
end
|
|
end
|
|
self.event_list[3] = self.model:Bind(GoodsModel.CLICK_BAG_ITEM, click_fun)
|
|
|
|
end
|
|
|
|
function DepotView:SetTextColor( )
|
|
for i,v in ipairs(self.titleTabbar_text) do
|
|
if self.title_cur_index == i then
|
|
v.text = "<color=#ffffff>"..self.titleTabbar[i].."</color>"
|
|
SetTMPSharedMaterial(v, ShaderTools.TMPSharedMaterialType.HKYTW7OutlineBlueTab)
|
|
else
|
|
v.text = "<color=#9eb3cf>"..self.titleTabbar[i].."</color>"
|
|
SetTMPSharedMaterial(v, ShaderTools.TMPSharedMaterialType.MSYHSDFDefault)
|
|
end
|
|
end
|
|
end
|
|
|
|
function DepotView:UpdateItems(to_top)
|
|
local item = nil
|
|
local info = self.model.slot_info_pos_3
|
|
local slot_num = info.slot_num
|
|
local all_slot = info.all_slot
|
|
|
|
local warehouse_goods_list = self.model.warehouse_goods_list
|
|
|
|
if self.need_sort then
|
|
self.need_sort = false
|
|
self.model:SortBagListByBagView(warehouse_goods_list)
|
|
self.model:SortBagListByBagView(self.model.warehouse_goods_list)
|
|
end
|
|
|
|
self.curr_list = {}
|
|
|
|
local m_index = 1
|
|
for k,v in pairs(warehouse_goods_list) do
|
|
if self.title_cur_index == 2 then ---常用(消耗 3 和 碎片 4)
|
|
if self.model:GetGoodsTab(v.type, v.subtype) == 3 or self.model:GetGoodsTab(v.type, v.subtype) == 4 then
|
|
self.curr_list[m_index] = v
|
|
self.curr_list[m_index].index = m_index
|
|
m_index = m_index + 1
|
|
end
|
|
elseif self.title_cur_index == 3 then --礼包
|
|
if self.model:GetGoodsTab(v.type, v.subtype) == 5 then
|
|
self.curr_list[m_index] = v
|
|
self.curr_list[m_index].index = m_index
|
|
m_index = m_index + 1
|
|
end
|
|
else --全部
|
|
self.curr_list[k] = v
|
|
self.curr_list[k].index = k
|
|
end
|
|
end
|
|
|
|
|
|
if slot_num and all_slot then
|
|
for k = #self.curr_list + 1,slot_num do
|
|
self.curr_list[k] = {type_id = 0, goods_num = 0,index = k}
|
|
end
|
|
for k = slot_num + 1,all_slot do
|
|
self.curr_list[k] = {lock_index = k - slot_num,index = k}
|
|
end
|
|
|
|
for k = 1,35 do
|
|
local item = self.item_list[k]
|
|
if item == nil then
|
|
item = BagItem.New(self.con,nil,self.maskID)
|
|
self.item_list[k] = item
|
|
item:SetPosType(GoodsModel.GOODS_POS_TYPE.warehouse)
|
|
end
|
|
end
|
|
end
|
|
|
|
if to_top then
|
|
self.loop_mgr:Init(self.scroll,self.scroll_content,self.column_num,89.5,89.5,function(item,index,realIndex )
|
|
self:OnInitializeItem(item,index,realIndex )
|
|
end, 0, 0, {x=10,y=-6})
|
|
self.loop_mgr:InitChildren(self.item_list, #self.curr_list)
|
|
self.loop_mgr:RestToBeginning()
|
|
self.loop_mgr:SetContentSizeData()
|
|
else
|
|
self.loop_mgr:InitChildren(self.item_list, #self.curr_list)
|
|
self.loop_mgr:ForceUpdateCurrentItems()
|
|
self.loop_mgr:SetContentSizeData()
|
|
end
|
|
|
|
end
|
|
|
|
function DepotView:OnInitializeItem(item,index,realIndex)
|
|
if item and realIndex > 0 and realIndex <= #self.curr_list then
|
|
item:SetData(self.curr_list[realIndex],self.maskID, nil,nil, "BagView")
|
|
self:UpdateItemState()
|
|
end
|
|
end
|
|
|
|
function DepotView:UpdateItemState()
|
|
if not self.click_item_index then return end
|
|
for k,item in pairs(self.item_list) do
|
|
item:SetSelect(item.index == self.click_item_index)
|
|
end
|
|
end
|
|
|
|
function DepotView:UpdateSortCD( )
|
|
if not self.is_loaded then return end
|
|
local last_sort_bag_time = BagModel:getInstance():GetLastSortBagTime(GoodsModel.GOODS_POS_TYPE.warehouse)
|
|
if not last_sort_bag_time then
|
|
self.sortBtn_img.color = ColorUtilValue.WHITE
|
|
self.sortBtn_txt.text = "整理"
|
|
return
|
|
end
|
|
|
|
local function step_sort_bag_cd( ... )
|
|
local left_cd = 5 - (Time.time - last_sort_bag_time)
|
|
if left_cd > 0 then
|
|
self.sortBtn_txt.text = math.ceil(left_cd)
|
|
self.sortBtn_img.color = Color(148/255,148/255,148/255)
|
|
else
|
|
self.sortBtn_img.color = ColorUtilValue.WHITE
|
|
self.sortBtn_txt.text = "整理"
|
|
if self.step_sort_bag_cd_id then
|
|
GlobalTimerQuest:CancelQuest(self.step_sort_bag_cd_id)
|
|
self.step_sort_bag_cd_id = nil
|
|
end
|
|
end
|
|
end
|
|
step_sort_bag_cd()
|
|
if not self.step_sort_bag_cd_id then
|
|
self.step_sort_bag_cd_id = GlobalTimerQuest:AddPeriodQuest(step_sort_bag_cd, 1, -1)
|
|
end
|
|
end
|