MainCollectLayout.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. local MainCollectLayout = class("MainCollectLayout", function()
  2. return cc.Node:create()
  3. end)
  4. MainCollectLayout._path = global.MMO.PATH_RES_PRIVATE .. "main/collect/"
  5. function MainCollectLayout:ctor()
  6. self._status = -1 -- -1:初始化状态,可任意切换 0:无,需要隐藏(持续监测中) 1:显示可以采集 2:开始采集 3:采集中 4:采集完成 5:采集结束
  7. self._collectionID = nil -- 采集物ID
  8. end
  9. function MainCollectLayout.create()
  10. local layout = MainCollectLayout.new()
  11. if layout:Init() then
  12. return layout
  13. end
  14. return nil
  15. end
  16. function MainCollectLayout:Init()
  17. return true
  18. end
  19. function MainCollectLayout:InitGUI(...)
  20. SL:RequireFile(SLDefine.LUAFile.LUA_FILE_MAIN_COLLECT)
  21. MainCollect.main()
  22. self._ui = ui_delegate(self)
  23. if not self._ui then
  24. return
  25. end
  26. -- -- 开始采集
  27. self._ui.Panel_1:addClickEventListener(function()
  28. self:SendAutoFindCollection()
  29. end)
  30. self:HideCollect(true)
  31. end
  32. function MainCollectLayout:SendAutoFindCollection()
  33. if self._collectionID then
  34. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  35. local targetID = inputProxy:SetTargetID(self._collectionID, global.MMO.SELETE_TARGET_TYPE_FIND)
  36. end
  37. global.Facade:sendNotification(global.NoticeTable.AutoFindCollection)
  38. end
  39. function MainCollectLayout:ShowCollect(collections)
  40. if not collections or not next(collections) then
  41. return nil
  42. end
  43. local hideSelect = tonumber(SL:GetMetaValue("GAME_DATA", "Hide_Select_Collection")) == 1
  44. local selectList = self._ui.Panel_1:getChildByName("List_Collect_Select")
  45. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  46. local targetID = inputProxy:GetTargetID()
  47. local collectionID = self._collectionID
  48. local tempID = {}
  49. if selectList then
  50. local items = selectList:getItems()
  51. for i, item in ipairs(items) do
  52. local collectID = item:getName()
  53. if collections[collectID] then
  54. tempID[collectID] = collectID
  55. else
  56. if collectID == collectionID then
  57. collectionID = nil
  58. end
  59. local index = selectList:getIndex(item)
  60. selectList:removeItem(index)
  61. end
  62. end
  63. end
  64. for k, actor in pairs(collections) do
  65. if not tempID[k] then
  66. if not collectionID then
  67. collectionID = actor and k
  68. end
  69. if k == targetID then
  70. collectionID = actor and k
  71. end
  72. if actor and not hideSelect and selectList then
  73. local item = self:CreateItemCell(actor)
  74. selectList:pushBackCustomItem(item)
  75. end
  76. end
  77. end
  78. if not collectionID then
  79. return
  80. end
  81. self._collectionID = collectionID
  82. if MainCollect and MainCollect.ShowCollectUI then
  83. MainCollect.ShowCollectUI()
  84. end
  85. end
  86. function MainCollectLayout:CreateItemCell(actor)
  87. local widget = self._ui.Panel_1:getChildByName("Layout_Item"):cloneEx()
  88. widget:setVisible(true)
  89. widget:setName(actor:GetID())
  90. local nameText = widget:getChildByName("Text_Name")
  91. if nameText then
  92. nameText:setString(actor:GetName())
  93. end
  94. widget:addClickEventListener(function()
  95. self._collectionID = actor:GetID()
  96. self:SendAutoFindCollection()
  97. end)
  98. return widget
  99. end
  100. function MainCollectLayout:HideCollect(isInit)
  101. if not self._collectionID and not isInit then
  102. return
  103. end
  104. self._collectionID = nil
  105. if MainCollect and MainCollect.HideCollectUI then
  106. MainCollect.HideCollectUI()
  107. end
  108. end
  109. function MainCollectLayout:OnRefreshCollect(data)
  110. local actor = data and data.actor
  111. if actor and actor:IsCollection() then
  112. local selectList = self._ui.Panel_1:getChildByName("List_Collect_Select")
  113. local item = selectList and selectList:getChildByName(actor:GetID())
  114. if item then
  115. selectList:removeChild(item)
  116. item = nil
  117. end
  118. local items = selectList and selectList:getItems() or {}
  119. if items[1] then
  120. self._collectionID = items[1]:getName()
  121. else
  122. global.Facade:sendNotification(global.NoticeTable.CollectCompleted)
  123. self:HideCollect()
  124. end
  125. end
  126. end
  127. return MainCollectLayout