---@class KLTaskItem:UIKmlLuaPanelBase
---@field view KLTaskItemView
local KLTaskItem = class(UIKmlLuaPanelBase)
local this = KLTaskItem
---创建时调用一次
function this:Init()
self.taskId = self.args.taskId
local taskInfo = SL:TaskInfo_GetAllTasks()[self.taskId]
GUI:DataListInitData(self.view.task_goad_, function(realIndex)
return table.count(taskInfo.taskGoalRecord)
end, function(realIndex)
end, function(realIndex, kmlcontrol)
local task_title = SL:GetConfig('cfg_task_target', taskInfo.taskGoalRecord[realIndex+1].goalId).mainuiName
local title_text = GUI:GetChildControl(self.view.task_goad_, realIndex, 'title_text')
GUI:Text_setString(title_text, task_title)
end, function(realIndex, kmlcontrol)
self:SetTaskState(realIndex)
end)
end
---创建或者刷新界面数据时调用
function this:Refresh()
GUI:DataListUpdateData(self.view.task_goad_)
if SL:TaskInfo_GetAllTasks()[self.taskId].state == TaskState.Completed then
GUI:SetActive(self.view.GuideBG, true)
local ax,ay = GUI:getPosition(self.view.GuidePanel)
self.moveX = GUI:DOAnchorPosX(self.view.GuidePanel, ax+5, 0.6)
GUI:TweenSetLoops(self.moveX,-1)
GUI:TweenSetEase(self.moveX,ELeanTweenType.pingPong)
end
end
function this:SetTaskState(realIndex)
local taskInfo = SL:TaskInfo_GetAllTasks()[self.taskId]
local taskGoalInfo = taskInfo.taskGoalRecord[realIndex+1]
local progress_control = GUI:GetChildControl(self.view.task_goad_, realIndex, 'title_progress__')
local nowCount = taskGoalInfo.count
local maxCount = taskGoalInfo.maxCount
if taskInfo.state == TaskState.Completed then
GUI:SetActive(progress_control, false)
else
GUI:SetActive(progress_control, true)
if nowCount >= maxCount then
GUI:Text_setString(progress_control, string.format("%d/%d", nowCount, maxCount))
else
GUI:Text_setString(progress_control, string.format("%d/%d", nowCount, maxCount))
end
if taskGoalInfo.isChange and nowCount < maxCount then
self.co = Coroutine.Start(function()
GUI:Text_setString(progress_control, string.format("%d/%d", nowCount, maxCount))
Coroutine.Wait(0.1)
GUI:Text_setString(progress_control, string.format("%d/%d", nowCount, maxCount))
Coroutine.Wait(0.1)
GUI:Text_setString(progress_control, string.format("%d/%d", nowCount, maxCount))
Coroutine.Wait(0.1)
GUI:Text_setString(progress_control, string.format("%d/%d", nowCount, maxCount))
Coroutine.Wait(0.1)
GUI:Text_setString(progress_control, string.format("%d/%d", nowCount, maxCount))
Coroutine.Wait(0.1)
GUI:Text_setString(progress_control, string.format("%d/%d", nowCount, maxCount))
end
)
end
end
end
---注册UI事件和服务器消息
function this:RegistEvents()
end
function this:Close()
if self.moveX then
GUI:DOKill(self.moveX)
self.moveX = nil
end
if self.co ~= nil then
Coroutine.Stop(self.co)
self.co = nil
end
end
function this:Finish()
end
function this:OnClick()
local taskInfo = SL:TaskInfo_GetAllTasks()[self.taskId]
for _, goal in pairs(taskInfo.taskGoalRecord) do
-- 这个子任务没完成
if goal.count < goal.maxCount then
local targetId = goal.goalId
local extraControlNum = SL:GetConfig('cfg_task_target', targetId).extraControlNum
local instruction = SL:GetConfig('cfg_task_target', targetId).instruction
if extraControlNum == 0 then
break
elseif extraControlNum == 1 then
instruction = instruction[1]
local autoFight = SL:GetConfig('cfg_task_target', targetId).autoFight
local autoTask = SL:GetConfig('cfg_task_target', targetId).autoTask
local autoDialogue = SL:GetConfig('cfg_task_target', targetId).autoDialogue
local moveToArriveCallBack
if autoFight == EAutoFight.AutoFight and string.contains(instruction[1],"transfer") then
if not SL:GetMetaValue(EMetaVarGetKey.GET_IS_SAFEAREA) then
SL:SetBattleState(true)
end
elseif autoFight == EAutoFight.AutoFight and string.contains(instruction[1],"moveTo") then
SL:SetBattleState(false)
moveToArriveCallBack = function()
if not SL:GetMetaValue(EMetaVarGetKey.GET_IS_SAFEAREA) then
SL:SetBattleState(true)
end
end
end
if autoTask == EAutoTalk.AutoTalk and string.contains(instruction[1],"moveToNPC") then
SL:SetBattleState(false)
---判断是否已经在目标点
if SL:GetTalkBtnVisByNpcId(tonumber(instruction[2])) then
SL:TalkToNpc(tonumber(instruction[2]), true)
else
moveToArriveCallBack = function()
SL:TalkToNpc(tonumber(instruction[2]), true)
end
end
end
---寻路npc终点,触发点击npc操作
if autoDialogue == EAutoTalk.AutoTalk and string.contains(instruction[1],"moveToNPC") then
SL:SetBattleState(false)
---判断是否已经在目标点
if SL:GetTalkBtnVisByNpcId(tonumber(instruction[2])) then
SL:TalkToNpc(tonumber(instruction[2]))
else
moveToArriveCallBack = function()
SL:TalkToNpc(tonumber(instruction[2]))
end
end
end
SL:ShortcutDO(instruction,nil,nil,moveToArriveCallBack)
else
local worldPositionX, worldPositionY, worldPositionZ = GUI:GetWorldPosition(self.view.TaskGuidePoint)
GUI:UIPanel_Open("dev/ui/Task/Panel/KLTaskGuide/KLTaskGuidePanel", nil, nil, {goalId = goal.goalId, position={x=worldPositionX,y=worldPositionY,z=worldPositionZ}})
end
break
end
end
end
function this:Change()
GUI:DataListUpdateData(self.view.task_goad_)
end
return this