KLTaskPanel.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. ---@class KLTaskPanel:UIKmlLuaPanelBase
  2. ---@field view KLTaskPanelView
  3. local KLTaskPanel = class(UIKmlLuaPanelBase)
  4. local this =KLTaskPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. SL:KeepOpenPanel("KLTaskPanel",true)
  8. GUI:DataListInitData( self.view.left_top_task_list,function()
  9. return self:DataListItemCountFunc()
  10. end,function(realIndex)
  11. return self:DataListItemGetFunc(realIndex)
  12. end,function(realIndex, kmlcontrol)
  13. return self:DataListItemInitFunc(realIndex, kmlcontrol)
  14. end, function(realIndex, kmlcontrol)
  15. return self:DataListItemUpdateFunc(realIndex, kmlcontrol)
  16. end)
  17. GUI:SetScrollViewRectMaskData(self.view.info_view, 111, 0,623,216)
  18. self.taskItemPanel = {}
  19. end
  20. ---创建或者刷新界面数据时调用
  21. function this:Refresh()
  22. self:RefreshTaskList()
  23. end
  24. function this:DataListItemCountFunc(realIndex)
  25. return table.count(SL:TaskInfo_GetAllTasks())
  26. --return 2
  27. end
  28. function this:DataListItemGetFunc(realIndex)
  29. end
  30. function this:DataListItemInitFunc(parent_realIndex, control)
  31. end
  32. local clickTimer = {}
  33. function this:TaskOnClick(control, eventData)
  34. local realIndex = eventData.realIndex
  35. -- 特效展示一下然后隐藏
  36. local click_eff = GUI:GetChildControl(self.view.left_top_task_list,realIndex,'Plane_')
  37. GUI:SetActive(click_eff, true)
  38. if clickTimer[realIndex] == nil then
  39. clickTimer[realIndex] = SL:ScheduleOnce(1, function()
  40. GUI:SetActive(click_eff, false)
  41. clickTimer[realIndex] = nil
  42. end)
  43. end
  44. local taskId = SL:TaskInfo_GetAllIds()[realIndex+1]
  45. local taskInfo = SL:TaskInfo_GetAllTasks()[taskId]
  46. -- 完成任务
  47. if taskInfo.state == TaskState.Completed then
  48. ---@type cfg_task_column
  49. local tbl = SL:GetConfig("cfg_task", taskId)
  50. if tbl.npcDone and tbl.npcDone ~= 0 then
  51. ---@type cfg_npclist_column
  52. local npcTbl = SL:GetConfig("cfg_npclist", tbl.npcDone)
  53. local line = SL:GetMetaValue("MAP_LINE")
  54. local sceneId
  55. for _, mapMoveInfo in pairs(SL:GetConfigTable('cfg_mapMove')) do
  56. if mapMoveInfo.mapID == npcTbl.mapId then
  57. sceneId = mapMoveInfo.id
  58. break
  59. end
  60. end
  61. if sceneId then
  62. local pos = SL:GetMetaValue(EMetaVarGetKey.MAP_PLAYER_POS)
  63. local newPos = SL.Scene:GetFindNearNpcAvilPoint(Dot2(npcTbl.x, npcTbl.y), 5, false)
  64. if pos and newPos then
  65. local arriveFunc = function()
  66. GUI:CloseAllUIWithoutMainUI()
  67. GUI:UIPanel_Open("dev/ui/Task/Panel/KLTaskFinish/KLTaskFinishPanel",nil, nil, {taskId = taskId})
  68. SL.HideMainPanel()
  69. end
  70. --已在目标点就不需要再寻路了
  71. local maxDistance = Dot2.MaxDistance(pos,newPos)
  72. if maxDistance == 0 then
  73. arriveFunc()
  74. else
  75. --RoleManager.me:MapMove(npcTbl.x, npcTbl.y, _, sceneId, arriveFunc, false, true, true, line, tbl.npcDone)
  76. SL:MapMove(npcTbl.x, npcTbl.y, sceneId, arriveFunc, false, true, true, line, tbl.npcDone)
  77. end
  78. end
  79. end
  80. else
  81. GUI:UIPanel_Open("dev/ui/Task/Panel/KLTaskFinish/KLTaskFinishPanel",nil, nil, {taskId = taskId})
  82. SL.HideMainPanel()
  83. end
  84. else
  85. if self.taskItemPanel[taskId] then
  86. self.taskItemPanel[taskId]:OnClick()
  87. end
  88. end
  89. --local extraControlNum = SL:GetConfig('cfg_task', taskId).extraControlNum
  90. --if extraControlNum == 0 then
  91. -- return
  92. --end
  93. --
  94. --
  95. ---- 直接执行
  96. --if extraControlNum == 1 then
  97. -- local instruction = SL:GetConfig('cfg_task_target', taskId).instruction[1]
  98. -- --local autoFight =
  99. -- local moveToArriveCallBack
  100. -- if self.args.cfgInfo.autoFight == EAutoFight.AutoFight and string.contains(instruction[1],"transfer") then
  101. -- AutoFightManager.isStartTaskAutoFight = true
  102. -- elseif self.args.cfgInfo.autoFight == EAutoFight.AutoFight and string.contains(instruction[1],"moveTo") then
  103. -- AutoFightManager.Stop()
  104. -- moveToArriveCallBack = function()
  105. -- AutoFightManager.StartAutoFightNoNeedHookTime()
  106. -- end
  107. -- end
  108. -- if self.args.cfgInfo.autoTask == EAutoTalk.AutoTalk and string.contains(instruction[1],"moveToNPC") then
  109. -- AutoFightManager.Stop()
  110. -- moveToArriveCallBack = function()
  111. -- SceneTouch.ClickNpc(tonumber(instruction[2]))
  112. -- end
  113. -- end
  114. -- ShortcutMgr.Do(instruction,nil,nil,moveToArriveCallBack)
  115. --end
  116. end
  117. local taskIdToRealIndex = {}
  118. function this:DataListItemUpdateFunc(realIndex, control)
  119. local taskId = SL:TaskInfo_GetAllIds()[realIndex+1]
  120. local taskInfo = SL:TaskInfo_GetAllTasks()[taskId]
  121. local task_layout = GUI:GetChildControl(self.view.left_top_task_list,realIndex,'task_layout')
  122. GUI:UIPanel_Open("dev/ui/Task/Item/KLTask/KLTaskItem", task_layout, self, {taskId = taskId}, true,
  123. function(Item)
  124. self.taskItemPanel[taskId] = Item
  125. end)
  126. taskIdToRealIndex[taskId] = realIndex
  127. self:SetTaskIcon(realIndex)
  128. local task_btn = GUI:GetChildControl(self.view.left_top_task_list,realIndex,'task_bg_')
  129. GUI:SetID(task_btn, 'task_bg_' .. taskId)
  130. GUI:AddOnClickEvent(task_btn,self,self.TaskOnClick, {realIndex=realIndex})
  131. self:SetFinishState(realIndex)
  132. if self.newTaskIdList and table.contains(self.newTaskIdList, taskId) then
  133. local start = GUI:GetChildControl(self.view.left_top_task_list,realIndex,'Start_')
  134. GUI:setVisible(start, true)
  135. end
  136. end
  137. function this:SetFinishState(realIndex)
  138. local taskId = SL:TaskInfo_GetAllIds()[realIndex+1]
  139. local taskInfo = SL:TaskInfo_GetAllTasks()[taskId]
  140. local comp_text = GUI:GetChildControl(self.view.left_top_task_list,realIndex,'Complete_Text')
  141. local comp_prefab = GUI:GetChildControl(self.view.left_top_task_list,realIndex,'Complete_')
  142. if taskInfo.state == TaskState.Completed then
  143. GUI:SetActive(comp_text, true)
  144. GUI:SetActive(comp_prefab, true)
  145. else
  146. GUI:SetActive(comp_text, false)
  147. GUI:SetActive(comp_prefab, false)
  148. end
  149. end
  150. function this:SetTaskIcon(realIndex)
  151. local taskId = SL:TaskInfo_GetAllIds()[realIndex+1]
  152. local task_icon = GUI:GetChildControl(self.view.left_top_task_list,realIndex,'task_icon')
  153. local uititletype = SL:GetConfig('cfg_task', taskId).uiTitleType
  154. if uititletype == 1 then
  155. GUI:Image_loadTexture(task_icon, "img_taskmain", "Atlas/UITask.spriteatlas")
  156. elseif uititletype == 2 then
  157. GUI:Image_loadTexture(task_icon, "img_taskBranch", "Atlas/UITask.spriteatlas")
  158. elseif uititletype == 3 then
  159. GUI:Image_loadTexture(task_icon, "img_taskOther", "Atlas/UITask.spriteatlas")
  160. elseif uititletype == 4 then
  161. GUI:Image_loadTexture(task_icon, "zhuanzhi", "Atlas/UITask.spriteatlas")
  162. else
  163. GUI:Image_loadTexture(task_icon, "img_taskmain", "Atlas/UITask.spriteatlas")
  164. end
  165. end
  166. ---注册UI事件和服务器消息
  167. function this:RegistEvents()
  168. SL:RegisterLUAEvent(LUA_EVENT_NPC_CREATE,this.LUA_EVENT_NPC_CREATE, self)
  169. SL:RegisterLUAEvent(LUA_EVENT_TASK_NEW,this.LUA_EVENT_TASK_NEW, self)
  170. SL:RegisterLUAEvent(LUA_EVENT_TASK_FINISH,this.LUA_EVENT_TASK_FINISH,self)
  171. SL:RegisterLUAEvent(LUA_EVENT_TASK_SUBMIT,this.LUA_EVENT_TASK_SUBMIT,self)
  172. SL:RegisterLUAEvent(LUA_EVENT_TASK_CHANGE,this.LUA_EVENT_TASK_CHANGE,self)
  173. SL:RegisterLUAEvent(LUA_EVENT_MAIN_UI_VISIBLE,self.ShowMonsterList,self)
  174. end
  175. function this:LUA_EVENT_TASK_CHANGE(_, changeIdList)
  176. for _, taskId in pairs(changeIdList) do
  177. local panel = self.taskItemPanel[taskId]
  178. if panel then
  179. panel:Change()
  180. end
  181. end
  182. end
  183. function this:LUA_EVENT_TASK_FINISH(_, finishId)
  184. ---@type cfg_task_column
  185. local taskTbl = SL:GetConfig('cfg_task', finishId)
  186. for _, v in pairs(taskTbl.taskTargetId) do
  187. ---@type cfg_task_target_column
  188. local cfg = SL:GetConfig("cfg_task_target", v)
  189. if cfg.taskGoalType == 4 then
  190. --对话任务
  191. local npcDone = taskTbl.npcDone
  192. if npcDone then
  193. local npc = SL:GetRoleBaseNpcId(npcDone)
  194. if npc then
  195. self:RefreshNpcIcon(npcDone)
  196. end
  197. GUI:CloseAllUIWithoutMainUI()
  198. GUI:UIPanel_Open("dev/ui/Task/Panel/KLTaskFinish/KLTaskFinishPanel",nil, nil, {taskId = finishId})
  199. SL.HideMainPanel()
  200. end
  201. break
  202. end
  203. end
  204. --local taskItem = taskItemPanel[finishId]
  205. --if taskItem then
  206. -- taskItem:Finish()
  207. --end
  208. --local realIndex = taskIdToRealIndex[finishId]
  209. --if realIndex then
  210. -- self:SetFinishState(realIndex)
  211. --end
  212. SL:ScheduleOnce(0.1,function()
  213. self:RefreshTaskList()
  214. end)
  215. end
  216. function this:LUA_EVENT_TASK_NEW(_, newTaskIdList)
  217. for _, newTaskId in pairs(newTaskIdList) do
  218. local npcDone = SL:GetConfig('cfg_task', newTaskId).npcDone
  219. if npcDone then
  220. --local npc = RoleManager.GetRoleBaseNpcId(npcDone)
  221. local npc = SL:GetRoleBaseNpcId(npcDone)
  222. if npc then
  223. self:RefreshNpcIcon(npcDone)
  224. end
  225. end
  226. end
  227. SL:ScheduleOnce(0.1,function()
  228. self.newTaskIdList = newTaskIdList
  229. self:RefreshTaskList()
  230. end)
  231. end
  232. function this:LUA_EVENT_TASK_SUBMIT(_, taskId)
  233. self:RefreshTaskList()
  234. ---@type cfg_task_column
  235. local task = SL:GetConfig("cfg_task", taskId)
  236. if task.npcDone and task.npcDone ~= 0 then
  237. SL:SetNpcIcon(task.npcDone, "")
  238. end
  239. end
  240. function this:RefreshTaskList()
  241. if self.taskItemPanel then
  242. for _, taskItem in pairs(self.taskItemPanel) do
  243. GUI:UIPanel_Close(nil, taskItem)
  244. end
  245. end
  246. self.taskItemPanel = {}
  247. taskIdToRealIndex = {}
  248. if self.view == nil then
  249. return
  250. end
  251. GUI:DataListUpdateData(self.view.left_top_task_list)
  252. end
  253. function this:ShowMonsterList(_,message)
  254. if message and message.vis == true then
  255. if self.monsterMapPointTimer then
  256. SL:UnSchedule(self.monsterMapPointTimer)
  257. end
  258. self.monsterMapPointTimer = SL:ScheduleOnce(1, function()
  259. if InfoManager.goldChallengeTaskInfo.IsMapMonsterData() and (self:IsShowMonsterList() or InfoManager.goldChallengeTaskInfo:IsShowMonsterList(InfoManager.goldChallengeTaskInfo.taskInfo)) then
  260. GUI:UIPanel_Open("dev/ui/Monster/Panel/KLMonsterMapPoint/KLMonsterMapPointPanel")
  261. else
  262. GUI:UIPanel_Close("dev/ui/Monster/Panel/KLMonsterMapPoint/KLMonsterMapPointPanel")
  263. end
  264. self.monsterMapPointTimer = nil
  265. end)
  266. else
  267. if self.monsterMapPointTimer then
  268. SL:UnSchedule(self.monsterMapPointTimer)
  269. end
  270. end
  271. end
  272. function this:IsShowMonsterList()
  273. local taskList=SL:TaskInfo_GetAllIds()
  274. for _,v in pairs(taskList) do
  275. local monsterList=SL:GetConfig("cfg_task",v).monsterlist
  276. if monsterList and monsterList == 1 then
  277. return true
  278. end
  279. end
  280. return false
  281. end
  282. function this:LUA_EVENT_NPC_CREATE(_, data)
  283. self:RefreshNpcIcon(data.npcId)
  284. --print(data.npcId)
  285. end
  286. function this:RefreshNpcIcon(npcId)
  287. local taskState = SL:GetInNpcTaskState(npcId)
  288. if taskState == 0 then
  289. SL:SetNpcIcon(npcId, "task_progress")
  290. elseif taskState == 1 then
  291. SL:SetNpcIcon(npcId, "task_finish")
  292. end
  293. end
  294. function this:Close()
  295. if self.taskItemPanel then
  296. for _, taskItem in pairs(self.taskItemPanel) do
  297. GUI:UIPanel_Close(nil, taskItem)
  298. end
  299. end
  300. self.taskItemPanel = {}
  301. end
  302. return this