源战役客户端
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.

150 rivejä
3.8 KiB

1 kuukausi sitten
  1. EquipExamTaskView = EquipExamTaskView or BaseClass(BaseItem)
  2. local EquipExamTaskView = EquipExamTaskView
  3. local table_insert = table.insert
  4. function EquipExamTaskView:__init()
  5. self.base_file = "equipCollect"
  6. self.layout_file = "EquipExamTaskView"
  7. self.model = EquipCollectModel:GetInstance()
  8. self.tab_item = {}
  9. self.cur_select_index = 1
  10. self:Load()
  11. end
  12. function EquipExamTaskView:Load_callback()
  13. self.nodes = {
  14. "tab_con", "item_scroll", "item_scroll/Viewport/item_con", "role_bg:raw", "bg:raw",
  15. }
  16. self:GetChildren(self.nodes)
  17. lua_resM:setOutsideRawImage(self,self.role_bg_raw,GameResPath.GetRoleBg("equipexm_task_456_573"))
  18. lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("equipExam_task_bg"),false)
  19. self:AddEvents()
  20. if self.need_refreshData then
  21. self:UpdateView()
  22. end
  23. end
  24. function EquipExamTaskView:AddEvents( )
  25. local function on_update_item( )
  26. self:UpdateItem()
  27. end
  28. self.on_update_item_id = self.model:BindOne("equip_exam_task_info", on_update_item)
  29. end
  30. function EquipExamTaskView:UpdateView( )
  31. self:SetTabData()
  32. self:SwitchTab(self.cur_select_index)
  33. end
  34. function EquipExamTaskView:SetTabData( )
  35. local data = self.model:GetEquipExmTaskCFG()
  36. local x_offset = 124
  37. local function on_click( index )
  38. self:SwitchTab(index)
  39. end
  40. for i,v in ipairs(data) do
  41. local item = self.tab_item[i]
  42. if not item then
  43. item = EquipExamTaskTabItem.New(self.tab_con)
  44. item:SetCallBackFunc(on_click)
  45. item:SetPosition((i-1) * x_offset, 0)
  46. self.tab_item[i] = item
  47. end
  48. item:SetData(v,i)
  49. end
  50. end
  51. function EquipExamTaskView:UpdateItem( )
  52. local data = {}
  53. local cfg = self.model:GetEquipExmTaskCFG(self.cur_select_index)
  54. local server_data = self.model:GetEquipCollectTaskInfo()
  55. for i,v in ipairs(cfg) do
  56. local is_not_open = false
  57. local condition_data = stringtotable(v.condition)
  58. if TableSize(condition_data) > 0 then
  59. for i,v in ipairs(condition_data) do
  60. if v[1] == "lv" then
  61. is_not_open = RoleManager.Instance.mainRoleInfo.level < v[2] - 100
  62. elseif v[1] == "turn" then
  63. is_not_open = RoleManager.Instance.mainRoleInfo.turn < v[2] - 1
  64. end
  65. end
  66. else
  67. is_not_open = false
  68. end
  69. if not is_not_open then
  70. table_insert(data, v)
  71. end
  72. end
  73. for i,v in ipairs(data) do
  74. if server_data[v.task_id] then
  75. if server_data[v.task_id].status == 1 then--可领
  76. v.sort = 3
  77. elseif server_data[v.task_id].status == 0 then--不可领
  78. v.sort = 1
  79. elseif server_data[v.task_id].status == 2 then--已领
  80. v.sort = 0
  81. end
  82. else--没数据就是没完成
  83. v.sort = 1
  84. end
  85. end
  86. local sort_func = function ( a, b )
  87. if a.sort == b.sort then
  88. return a.task_id < b.task_id
  89. else
  90. return a.sort > b.sort
  91. end
  92. end
  93. table.sort(data, sort_func)
  94. self.task_creator = self.task_creator or self:AddUIComponent(UI.ItemListCreator)
  95. self.task_creator:Reset()
  96. local tag_all_info = {
  97. data_list = data,
  98. item_con = self.item_con,
  99. item_class = EquipExamTaskItem,
  100. item_height = 126,
  101. start_x = 0,
  102. start_y = 0,
  103. space_y = 2,
  104. scroll_view = self.item_scroll,
  105. -- create_frequency = 0.01,
  106. reuse_item_num = 6,
  107. on_update_item = function(item, i, v)
  108. item:SetData(v, i, server_data[v.task_id])
  109. end,
  110. }
  111. self.task_creator:UpdateItems(tag_all_info)
  112. end
  113. function EquipExamTaskView:SwitchTab( index )
  114. self.cur_select_index = index
  115. for i,v in ipairs(self.tab_item) do
  116. v:SetSelect(i==index)
  117. end
  118. self:UpdateItem()
  119. end
  120. function EquipExamTaskView:SetData( data )
  121. self.data = data
  122. if self.is_loaded then
  123. self.need_refreshData = false
  124. self:UpdateView()
  125. else
  126. self.need_refreshData = true
  127. end
  128. end
  129. function EquipExamTaskView:__delete( )
  130. for i,v in ipairs(self.tab_item) do
  131. v:DeleteMe()
  132. v = nil
  133. end
  134. self.tab_item = {}
  135. if self.on_update_item_id then
  136. self.model:UnBind(self.on_update_item_id)
  137. self.on_update_item_id = nil
  138. end
  139. end