KLTaskItem.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. ---@class KLTaskItem:UIKmlLuaPanelBase
  2. ---@field view KLTaskItemView
  3. local KLTaskItem = class(UIKmlLuaPanelBase)
  4. local this = KLTaskItem
  5. ---创建时调用一次
  6. function this:Init()
  7. self.taskId = self.args.taskId
  8. local taskInfo = SL:TaskInfo_GetAllTasks()[self.taskId]
  9. GUI:DataListInitData(self.view.task_goad_, function(realIndex)
  10. return table.count(taskInfo.taskGoalRecord)
  11. end, function(realIndex)
  12. end, function(realIndex, kmlcontrol)
  13. local task_title = SL:GetConfig('cfg_task_target', taskInfo.taskGoalRecord[realIndex+1].goalId).mainuiName
  14. local title_text = GUI:GetChildControl(self.view.task_goad_, realIndex, 'title_text')
  15. GUI:Text_setString(title_text, task_title)
  16. end, function(realIndex, kmlcontrol)
  17. self:SetTaskState(realIndex)
  18. end)
  19. end
  20. ---创建或者刷新界面数据时调用
  21. function this:Refresh()
  22. GUI:DataListUpdateData(self.view.task_goad_)
  23. if SL:TaskInfo_GetAllTasks()[self.taskId].state == TaskState.Completed then
  24. GUI:SetActive(self.view.GuideBG, true)
  25. local ax,ay = GUI:getPosition(self.view.GuidePanel)
  26. self.moveX = GUI:DOAnchorPosX(self.view.GuidePanel, ax+5, 0.6)
  27. GUI:TweenSetLoops(self.moveX,-1)
  28. GUI:TweenSetEase(self.moveX,ELeanTweenType.pingPong)
  29. end
  30. end
  31. function this:SetTaskState(realIndex)
  32. local taskInfo = SL:TaskInfo_GetAllTasks()[self.taskId]
  33. local taskGoalInfo = taskInfo.taskGoalRecord[realIndex+1]
  34. local progress_control = GUI:GetChildControl(self.view.task_goad_, realIndex, 'title_progress__')
  35. local nowCount = taskGoalInfo.count
  36. local maxCount = taskGoalInfo.maxCount
  37. if taskInfo.state == TaskState.Completed then
  38. GUI:SetActive(progress_control, false)
  39. else
  40. GUI:SetActive(progress_control, true)
  41. if nowCount >= maxCount then
  42. GUI:Text_setString(progress_control, string.format("<color=green>%d/%d</color>", nowCount, maxCount))
  43. else
  44. GUI:Text_setString(progress_control, string.format("%d/%d", nowCount, maxCount))
  45. end
  46. if taskGoalInfo.isChange and nowCount < maxCount then
  47. self.co = Coroutine.Start(function()
  48. GUI:Text_setString(progress_control, string.format("<color=red>%d</color>/%d", nowCount, maxCount))
  49. Coroutine.Wait(0.1)
  50. GUI:Text_setString(progress_control, string.format("%d/%d", nowCount, maxCount))
  51. Coroutine.Wait(0.1)
  52. GUI:Text_setString(progress_control, string.format("<color=red>%d</color>/%d", nowCount, maxCount))
  53. Coroutine.Wait(0.1)
  54. GUI:Text_setString(progress_control, string.format("%d/%d", nowCount, maxCount))
  55. Coroutine.Wait(0.1)
  56. GUI:Text_setString(progress_control, string.format("<color=red>%d</color>/%d", nowCount, maxCount))
  57. Coroutine.Wait(0.1)
  58. GUI:Text_setString(progress_control, string.format("%d/%d", nowCount, maxCount))
  59. end
  60. )
  61. end
  62. end
  63. end
  64. ---注册UI事件和服务器消息
  65. function this:RegistEvents()
  66. end
  67. function this:Close()
  68. if self.moveX then
  69. GUI:DOKill(self.moveX)
  70. self.moveX = nil
  71. end
  72. if self.co ~= nil then
  73. Coroutine.Stop(self.co)
  74. self.co = nil
  75. end
  76. end
  77. function this:Finish()
  78. end
  79. function this:OnClick()
  80. local taskInfo = SL:TaskInfo_GetAllTasks()[self.taskId]
  81. for _, goal in pairs(taskInfo.taskGoalRecord) do
  82. -- 这个子任务没完成
  83. if goal.count < goal.maxCount then
  84. local targetId = goal.goalId
  85. local extraControlNum = SL:GetConfig('cfg_task_target', targetId).extraControlNum
  86. local instruction = SL:GetConfig('cfg_task_target', targetId).instruction
  87. if extraControlNum == 0 then
  88. break
  89. elseif extraControlNum == 1 then
  90. instruction = instruction[1]
  91. local autoFight = SL:GetConfig('cfg_task_target', targetId).autoFight
  92. local autoTask = SL:GetConfig('cfg_task_target', targetId).autoTask
  93. local autoDialogue = SL:GetConfig('cfg_task_target', targetId).autoDialogue
  94. local moveToArriveCallBack
  95. if autoFight == EAutoFight.AutoFight and string.contains(instruction[1],"transfer") then
  96. if not SL:GetMetaValue(EMetaVarGetKey.GET_IS_SAFEAREA) then
  97. SL:SetBattleState(true)
  98. end
  99. elseif autoFight == EAutoFight.AutoFight and string.contains(instruction[1],"moveTo") then
  100. SL:SetBattleState(false)
  101. moveToArriveCallBack = function()
  102. if not SL:GetMetaValue(EMetaVarGetKey.GET_IS_SAFEAREA) then
  103. SL:SetBattleState(true)
  104. end
  105. end
  106. end
  107. if autoTask == EAutoTalk.AutoTalk and string.contains(instruction[1],"moveToNPC") then
  108. SL:SetBattleState(false)
  109. ---判断是否已经在目标点
  110. if SL:GetTalkBtnVisByNpcId(tonumber(instruction[2])) then
  111. SL:TalkToNpc(tonumber(instruction[2]), true)
  112. else
  113. moveToArriveCallBack = function()
  114. SL:TalkToNpc(tonumber(instruction[2]), true)
  115. end
  116. end
  117. end
  118. ---寻路npc终点,触发点击npc操作
  119. if autoDialogue == EAutoTalk.AutoTalk and string.contains(instruction[1],"moveToNPC") then
  120. SL:SetBattleState(false)
  121. ---判断是否已经在目标点
  122. if SL:GetTalkBtnVisByNpcId(tonumber(instruction[2])) then
  123. SL:TalkToNpc(tonumber(instruction[2]))
  124. else
  125. moveToArriveCallBack = function()
  126. SL:TalkToNpc(tonumber(instruction[2]))
  127. end
  128. end
  129. end
  130. SL:ShortcutDO(instruction,nil,nil,moveToArriveCallBack)
  131. else
  132. local worldPositionX, worldPositionY, worldPositionZ = GUI:GetWorldPosition(self.view.TaskGuidePoint)
  133. GUI:UIPanel_Open("dev/ui/Task/Panel/KLTaskGuide/KLTaskGuidePanel", nil, nil, {goalId = goal.goalId, position={x=worldPositionX,y=worldPositionY,z=worldPositionZ}})
  134. end
  135. break
  136. end
  137. end
  138. end
  139. function this:Change()
  140. GUI:DataListUpdateData(self.view.task_goad_)
  141. end
  142. return this