EquipExamTaskView = EquipExamTaskView or BaseClass(BaseItem)
|
|
local EquipExamTaskView = EquipExamTaskView
|
|
local table_insert = table.insert
|
|
function EquipExamTaskView:__init()
|
|
self.base_file = "equipCollect"
|
|
self.layout_file = "EquipExamTaskView"
|
|
self.model = EquipCollectModel:GetInstance()
|
|
self.tab_item = {}
|
|
self.cur_select_index = 1
|
|
self:Load()
|
|
end
|
|
|
|
function EquipExamTaskView:Load_callback()
|
|
self.nodes = {
|
|
"tab_con", "item_scroll", "item_scroll/Viewport/item_con", "role_bg:raw", "bg:raw",
|
|
}
|
|
self:GetChildren(self.nodes)
|
|
lua_resM:setOutsideRawImage(self,self.role_bg_raw,GameResPath.GetRoleBg("equipexm_task_456_573"))
|
|
lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("equipExam_task_bg"),false)
|
|
|
|
self:AddEvents()
|
|
if self.need_refreshData then
|
|
self:UpdateView()
|
|
end
|
|
end
|
|
|
|
function EquipExamTaskView:AddEvents( )
|
|
local function on_update_item( )
|
|
self:UpdateItem()
|
|
end
|
|
self.on_update_item_id = self.model:BindOne("equip_exam_task_info", on_update_item)
|
|
end
|
|
|
|
function EquipExamTaskView:UpdateView( )
|
|
self:SetTabData()
|
|
self:SwitchTab(self.cur_select_index)
|
|
end
|
|
|
|
function EquipExamTaskView:SetTabData( )
|
|
local data = self.model:GetEquipExmTaskCFG()
|
|
local x_offset = 124
|
|
local function on_click( index )
|
|
self:SwitchTab(index)
|
|
end
|
|
for i,v in ipairs(data) do
|
|
local item = self.tab_item[i]
|
|
if not item then
|
|
item = EquipExamTaskTabItem.New(self.tab_con)
|
|
item:SetCallBackFunc(on_click)
|
|
item:SetPosition((i-1) * x_offset, 0)
|
|
self.tab_item[i] = item
|
|
end
|
|
item:SetData(v,i)
|
|
end
|
|
end
|
|
|
|
function EquipExamTaskView:UpdateItem( )
|
|
local data = {}
|
|
local cfg = self.model:GetEquipExmTaskCFG(self.cur_select_index)
|
|
local server_data = self.model:GetEquipCollectTaskInfo()
|
|
for i,v in ipairs(cfg) do
|
|
local is_not_open = false
|
|
local condition_data = stringtotable(v.condition)
|
|
if TableSize(condition_data) > 0 then
|
|
for i,v in ipairs(condition_data) do
|
|
if v[1] == "lv" then
|
|
is_not_open = RoleManager.Instance.mainRoleInfo.level < v[2] - 100
|
|
elseif v[1] == "turn" then
|
|
is_not_open = RoleManager.Instance.mainRoleInfo.turn < v[2] - 1
|
|
end
|
|
end
|
|
else
|
|
is_not_open = false
|
|
end
|
|
if not is_not_open then
|
|
table_insert(data, v)
|
|
end
|
|
end
|
|
for i,v in ipairs(data) do
|
|
if server_data[v.task_id] then
|
|
if server_data[v.task_id].status == 1 then--可领
|
|
v.sort = 3
|
|
elseif server_data[v.task_id].status == 0 then--不可领
|
|
v.sort = 1
|
|
elseif server_data[v.task_id].status == 2 then--已领
|
|
v.sort = 0
|
|
end
|
|
else--没数据就是没完成
|
|
v.sort = 1
|
|
end
|
|
end
|
|
local sort_func = function ( a, b )
|
|
if a.sort == b.sort then
|
|
return a.task_id < b.task_id
|
|
else
|
|
return a.sort > b.sort
|
|
end
|
|
end
|
|
table.sort(data, sort_func)
|
|
|
|
self.task_creator = self.task_creator or self:AddUIComponent(UI.ItemListCreator)
|
|
self.task_creator:Reset()
|
|
local tag_all_info = {
|
|
data_list = data,
|
|
item_con = self.item_con,
|
|
item_class = EquipExamTaskItem,
|
|
item_height = 126,
|
|
start_x = 0,
|
|
start_y = 0,
|
|
space_y = 2,
|
|
scroll_view = self.item_scroll,
|
|
-- create_frequency = 0.01,
|
|
reuse_item_num = 6,
|
|
on_update_item = function(item, i, v)
|
|
item:SetData(v, i, server_data[v.task_id])
|
|
end,
|
|
}
|
|
self.task_creator:UpdateItems(tag_all_info)
|
|
end
|
|
|
|
|
|
function EquipExamTaskView:SwitchTab( index )
|
|
self.cur_select_index = index
|
|
for i,v in ipairs(self.tab_item) do
|
|
v:SetSelect(i==index)
|
|
end
|
|
self:UpdateItem()
|
|
end
|
|
|
|
function EquipExamTaskView:SetData( data )
|
|
self.data = data
|
|
if self.is_loaded then
|
|
self.need_refreshData = false
|
|
self:UpdateView()
|
|
else
|
|
self.need_refreshData = true
|
|
end
|
|
end
|
|
|
|
function EquipExamTaskView:__delete( )
|
|
for i,v in ipairs(self.tab_item) do
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
self.tab_item = {}
|
|
if self.on_update_item_id then
|
|
self.model:UnBind(self.on_update_item_id)
|
|
self.on_update_item_id = nil
|
|
end
|
|
end
|