EquipCollectSubView = EquipCollectSubView or BaseClass(BaseItem)
|
|
local EquipCollectSubView = EquipCollectSubView
|
|
|
|
function EquipCollectSubView:__init()
|
|
self.base_file = "equipCollect"
|
|
self.layout_file = "EquipCollectSubView"
|
|
self.model = EquipCollectModel:GetInstance()
|
|
self.is_first = true
|
|
self.id, self.sub_id = self.model:GetEquipCollectJumpId()
|
|
self:Load()
|
|
end
|
|
|
|
function EquipCollectSubView:Load_callback()
|
|
self.nodes = {
|
|
"right_scroll", "left_scroll:obj", "left_scroll/Viewport/left_con", "right_scroll/Viewport/right_con", "tips_text:tmp:obj",
|
|
"bg:raw", "arrow:obj"
|
|
}
|
|
self:GetChildren(self.nodes)
|
|
self.left_scroll_rect = self.left_scroll:GetComponent("ScrollRect")
|
|
self:AddEvents()
|
|
lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("euqip_collect_sub_bg"),false)
|
|
|
|
if self.need_refreshData then
|
|
self:UpdateView()
|
|
end
|
|
end
|
|
|
|
function EquipCollectSubView:AddEvents( )
|
|
local function on_update( ... )
|
|
self:UpdateView()
|
|
end
|
|
self:BindEvent(self.model,EquipCollectConst.ANS_EQUIP_COLLECT_INFO,on_update)
|
|
end
|
|
|
|
function EquipCollectSubView:UpdateView( )
|
|
self:UpdateLeftItem()
|
|
self:UpdateRightItem()
|
|
end
|
|
|
|
function EquipCollectSubView:UpdateLeftItem( )
|
|
self.tab_cfg = self.model:GetEquipCollectCFG()
|
|
self.tab_creator = self.tab_creator or self:AddUIComponent(UI.ItemListCreator)
|
|
self.tab_data = self.tab_cfg
|
|
self.cur_select_data = self.tab_cfg[self.id]
|
|
local call_back = function(data, id, sub_id)
|
|
self.show_first_effect = nil--切页签关掉特效
|
|
self.id = id
|
|
self:UpdateLeftItem()
|
|
self:UpdateSelectVer()
|
|
end
|
|
|
|
local function final_callback( )
|
|
if self.is_first then
|
|
self.cur_select_data = self.model:GetEquipCollectCFG(self.id)
|
|
if self.id > 3 then
|
|
self:UpdateSelectVer(true)
|
|
else
|
|
self:UpdateSelectVer()
|
|
end
|
|
self.is_first = false
|
|
end
|
|
end
|
|
|
|
local function on_scroll( ... )
|
|
if self.left_scroll_rect.verticalNormalizedPosition <= 0 then
|
|
self.arrow_obj:SetActive(false)
|
|
else
|
|
self.arrow_obj:SetActive(true)
|
|
end
|
|
end
|
|
|
|
local tag_all_info = {
|
|
data_list = self.tab_data,
|
|
item_con = self.left_con,
|
|
item_class = EquipCollectLeftItem,
|
|
item_height = 127,
|
|
start_x = 2,
|
|
start_y = 0,
|
|
space_y = 0,
|
|
scroll_view = self.left_scroll,
|
|
on_scroll = on_scroll,
|
|
create_frequency = 0.01,
|
|
final_callback = final_callback,
|
|
on_update_item = function(item, i, v)
|
|
item:SetData(v, self.id, self.model:GetFirstSubId(i))
|
|
item:SetCallBackFunc(call_back)
|
|
end,
|
|
}
|
|
self.tab_creator:UpdateItems(tag_all_info)
|
|
end
|
|
|
|
--设置垂直tab选择
|
|
function EquipCollectSubView:UpdateSelectVer( need_refresh )
|
|
self.tab_creator:IterateItems(function(item, i, v)
|
|
item:SetSelect(self.id, self.sub_id)
|
|
end)
|
|
if need_refresh then
|
|
self:ScrollToSelectItem()
|
|
end
|
|
self:UpdateRightItem()
|
|
end
|
|
|
|
function EquipCollectSubView:UpdateRightItem( )
|
|
self.right_creator = self.right_creator or self:AddUIComponent(UI.ItemListCreator)
|
|
local data = {}
|
|
local sort_index = 0
|
|
for k,v in pairsByKeys(self.cur_select_data) do
|
|
table.insert(data,v)
|
|
sort_index = sort_index + 1
|
|
v.sort_index = sort_index
|
|
end
|
|
local sort_func = function ( a, b )
|
|
local is_all_collect_a = self.model:CheckIsAllEquipCollected(a[1].id, a[1].sub_id)
|
|
local is_all_collect_b = self.model:CheckIsAllEquipCollected(b[1].id, b[1].sub_id)
|
|
if is_all_collect_a and not is_all_collect_b then
|
|
return false
|
|
elseif is_all_collect_b and not is_all_collect_a then
|
|
return true
|
|
else
|
|
return a.sort_index < b.sort_index
|
|
end
|
|
end
|
|
table.sort(data, sort_func)
|
|
|
|
local tag_all_info = {
|
|
data_list = data,
|
|
item_con = self.right_con,
|
|
item_class = EquipCollectRightItem,
|
|
item_height = 138,
|
|
start_x = 2,
|
|
start_y = -2,
|
|
space_y = 10,
|
|
scroll_view = self.left_scroll,
|
|
-- create_frequency = 0.01,
|
|
on_update_item = function(item, i, v)
|
|
item:SetData(v, self.id, self.model:GetFirstSubId(i), i, self.show_first_effect)
|
|
end,
|
|
}
|
|
self.right_creator:UpdateItems(tag_all_info)
|
|
if self.sub_id == 4 then
|
|
self.right_creator:ScrollToItem(2)
|
|
end
|
|
end
|
|
|
|
function EquipCollectSubView:ScrollToSelectItem( )
|
|
for i,v in ipairs(self.tab_data) do
|
|
if i == self.id then
|
|
self.tab_creator:ScrollToItem(i)
|
|
end
|
|
end
|
|
end
|
|
|
|
function EquipCollectSubView:SetData( id, sub_id, show_first_effect)
|
|
self.id = id or self.id
|
|
self.sub_id = sub_id or self.sub_id
|
|
self.show_first_effect = show_first_effect
|
|
if id == 1 and sub_id == 1 then
|
|
self.need_do_task = true
|
|
end
|
|
if self.is_loaded then
|
|
self.need_refreshData = false
|
|
self:UpdateView()
|
|
else
|
|
self.need_refreshData = true
|
|
end
|
|
end
|
|
|
|
function EquipCollectSubView:__delete( )
|
|
if self.need_do_task then
|
|
GlobalEventSystem:Fire(EventName.FORCE_TO_DO_TASK, true, true)
|
|
end
|
|
end
|