123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- ---@class KLTaskPanel:UIKmlLuaPanelBase
- ---@field view KLTaskPanelView
- local KLTaskPanel = class(UIKmlLuaPanelBase)
- local this =KLTaskPanel
- ---创建时调用一次
- function this:Init()
- SL:KeepOpenPanel("KLTaskPanel",true)
- GUI:DataListInitData( self.view.left_top_task_list,function()
- return self:DataListItemCountFunc()
- end,function(realIndex)
- return self:DataListItemGetFunc(realIndex)
- end,function(realIndex, kmlcontrol)
- return self:DataListItemInitFunc(realIndex, kmlcontrol)
- end, function(realIndex, kmlcontrol)
- return self:DataListItemUpdateFunc(realIndex, kmlcontrol)
- end)
- GUI:SetScrollViewRectMaskData(self.view.info_view, 111, 0,623,216)
-
- self.taskItemPanel = {}
- end
- ---创建或者刷新界面数据时调用
- function this:Refresh()
- self:RefreshTaskList()
- end
- function this:DataListItemCountFunc(realIndex)
- return table.count(SL:TaskInfo_GetAllTasks())
- --return 2
- end
- function this:DataListItemGetFunc(realIndex)
-
- end
- function this:DataListItemInitFunc(parent_realIndex, control)
- end
- local clickTimer = {}
- function this:TaskOnClick(control, eventData)
- local realIndex = eventData.realIndex
-
- -- 特效展示一下然后隐藏
- local click_eff = GUI:GetChildControl(self.view.left_top_task_list,realIndex,'Plane_')
- GUI:SetActive(click_eff, true)
- if clickTimer[realIndex] == nil then
- clickTimer[realIndex] = SL:ScheduleOnce(1, function()
- GUI:SetActive(click_eff, false)
- clickTimer[realIndex] = nil
- end)
- end
- local taskId = SL:TaskInfo_GetAllIds()[realIndex+1]
- local taskInfo = SL:TaskInfo_GetAllTasks()[taskId]
-
- -- 完成任务
- if taskInfo.state == TaskState.Completed then
- ---@type cfg_task_column
- local tbl = SL:GetConfig("cfg_task", taskId)
- if tbl.npcDone and tbl.npcDone ~= 0 then
- ---@type cfg_npclist_column
- local npcTbl = SL:GetConfig("cfg_npclist", tbl.npcDone)
- local line = SL:GetMetaValue("MAP_LINE")
- local sceneId
- for _, mapMoveInfo in pairs(SL:GetConfigTable('cfg_mapMove')) do
- if mapMoveInfo.mapID == npcTbl.mapId then
- sceneId = mapMoveInfo.id
- break
- end
- end
- if sceneId then
- local pos = SL:GetMetaValue(EMetaVarGetKey.MAP_PLAYER_POS)
- local newPos = SL.Scene:GetFindNearNpcAvilPoint(Dot2(npcTbl.x, npcTbl.y), 5, false)
- if pos and newPos then
- local arriveFunc = function()
- GUI:CloseAllUIWithoutMainUI()
- GUI:UIPanel_Open("dev/ui/Task/Panel/KLTaskFinish/KLTaskFinishPanel",nil, nil, {taskId = taskId})
- SL.HideMainPanel()
- end
- --已在目标点就不需要再寻路了
- local maxDistance = Dot2.MaxDistance(pos,newPos)
- if maxDistance == 0 then
- arriveFunc()
- else
- --RoleManager.me:MapMove(npcTbl.x, npcTbl.y, _, sceneId, arriveFunc, false, true, true, line, tbl.npcDone)
- SL:MapMove(npcTbl.x, npcTbl.y, sceneId, arriveFunc, false, true, true, line, tbl.npcDone)
- end
- end
- end
- else
- GUI:UIPanel_Open("dev/ui/Task/Panel/KLTaskFinish/KLTaskFinishPanel",nil, nil, {taskId = taskId})
- SL.HideMainPanel()
- end
- else
- if self.taskItemPanel[taskId] then
- self.taskItemPanel[taskId]:OnClick()
- end
- end
- --local extraControlNum = SL:GetConfig('cfg_task', taskId).extraControlNum
- --if extraControlNum == 0 then
- -- return
- --end
- --
- --
- ---- 直接执行
- --if extraControlNum == 1 then
- -- local instruction = SL:GetConfig('cfg_task_target', taskId).instruction[1]
- -- --local autoFight =
- -- local moveToArriveCallBack
- -- if self.args.cfgInfo.autoFight == EAutoFight.AutoFight and string.contains(instruction[1],"transfer") then
- -- AutoFightManager.isStartTaskAutoFight = true
- -- elseif self.args.cfgInfo.autoFight == EAutoFight.AutoFight and string.contains(instruction[1],"moveTo") then
- -- AutoFightManager.Stop()
- -- moveToArriveCallBack = function()
- -- AutoFightManager.StartAutoFightNoNeedHookTime()
- -- end
- -- end
- -- if self.args.cfgInfo.autoTask == EAutoTalk.AutoTalk and string.contains(instruction[1],"moveToNPC") then
- -- AutoFightManager.Stop()
- -- moveToArriveCallBack = function()
- -- SceneTouch.ClickNpc(tonumber(instruction[2]))
- -- end
- -- end
- -- ShortcutMgr.Do(instruction,nil,nil,moveToArriveCallBack)
- --end
-
-
- end
- local taskIdToRealIndex = {}
- function this:DataListItemUpdateFunc(realIndex, control)
- local taskId = SL:TaskInfo_GetAllIds()[realIndex+1]
- local taskInfo = SL:TaskInfo_GetAllTasks()[taskId]
- local task_layout = GUI:GetChildControl(self.view.left_top_task_list,realIndex,'task_layout')
- GUI:UIPanel_Open("dev/ui/Task/Item/KLTask/KLTaskItem", task_layout, self, {taskId = taskId}, true,
- function(Item)
- self.taskItemPanel[taskId] = Item
- end)
- taskIdToRealIndex[taskId] = realIndex
- self:SetTaskIcon(realIndex)
- local task_btn = GUI:GetChildControl(self.view.left_top_task_list,realIndex,'task_bg_')
- GUI:SetID(task_btn, 'task_bg_' .. taskId)
- GUI:AddOnClickEvent(task_btn,self,self.TaskOnClick, {realIndex=realIndex})
-
- self:SetFinishState(realIndex)
- if self.newTaskIdList and table.contains(self.newTaskIdList, taskId) then
- local start = GUI:GetChildControl(self.view.left_top_task_list,realIndex,'Start_')
- GUI:setVisible(start, true)
- end
- end
- function this:SetFinishState(realIndex)
- local taskId = SL:TaskInfo_GetAllIds()[realIndex+1]
- local taskInfo = SL:TaskInfo_GetAllTasks()[taskId]
- local comp_text = GUI:GetChildControl(self.view.left_top_task_list,realIndex,'Complete_Text')
- local comp_prefab = GUI:GetChildControl(self.view.left_top_task_list,realIndex,'Complete_')
- if taskInfo.state == TaskState.Completed then
- GUI:SetActive(comp_text, true)
- GUI:SetActive(comp_prefab, true)
- else
- GUI:SetActive(comp_text, false)
- GUI:SetActive(comp_prefab, false)
- end
- end
- function this:SetTaskIcon(realIndex)
- local taskId = SL:TaskInfo_GetAllIds()[realIndex+1]
- local task_icon = GUI:GetChildControl(self.view.left_top_task_list,realIndex,'task_icon')
- local uititletype = SL:GetConfig('cfg_task', taskId).uiTitleType
- if uititletype == 1 then
- GUI:Image_loadTexture(task_icon, "img_taskmain", "Atlas/UITask.spriteatlas")
- elseif uititletype == 2 then
- GUI:Image_loadTexture(task_icon, "img_taskBranch", "Atlas/UITask.spriteatlas")
- elseif uititletype == 3 then
- GUI:Image_loadTexture(task_icon, "img_taskOther", "Atlas/UITask.spriteatlas")
- elseif uititletype == 4 then
- GUI:Image_loadTexture(task_icon, "zhuanzhi", "Atlas/UITask.spriteatlas")
- else
- GUI:Image_loadTexture(task_icon, "img_taskmain", "Atlas/UITask.spriteatlas")
- end
- end
- ---注册UI事件和服务器消息
- function this:RegistEvents()
- SL:RegisterLUAEvent(LUA_EVENT_NPC_CREATE,this.LUA_EVENT_NPC_CREATE, self)
- SL:RegisterLUAEvent(LUA_EVENT_TASK_NEW,this.LUA_EVENT_TASK_NEW, self)
- SL:RegisterLUAEvent(LUA_EVENT_TASK_FINISH,this.LUA_EVENT_TASK_FINISH,self)
- SL:RegisterLUAEvent(LUA_EVENT_TASK_SUBMIT,this.LUA_EVENT_TASK_SUBMIT,self)
- SL:RegisterLUAEvent(LUA_EVENT_TASK_CHANGE,this.LUA_EVENT_TASK_CHANGE,self)
- SL:RegisterLUAEvent(LUA_EVENT_MAIN_UI_VISIBLE,self.ShowMonsterList,self)
- end
- function this:LUA_EVENT_TASK_CHANGE(_, changeIdList)
- for _, taskId in pairs(changeIdList) do
- local panel = self.taskItemPanel[taskId]
- if panel then
- panel:Change()
- end
- end
- end
- function this:LUA_EVENT_TASK_FINISH(_, finishId)
- ---@type cfg_task_column
- local taskTbl = SL:GetConfig('cfg_task', finishId)
- for _, v in pairs(taskTbl.taskTargetId) do
- ---@type cfg_task_target_column
- local cfg = SL:GetConfig("cfg_task_target", v)
- if cfg.taskGoalType == 4 then
- --对话任务
- local npcDone = taskTbl.npcDone
- if npcDone then
- local npc = SL:GetRoleBaseNpcId(npcDone)
- if npc then
- self:RefreshNpcIcon(npcDone)
- end
- GUI:CloseAllUIWithoutMainUI()
- GUI:UIPanel_Open("dev/ui/Task/Panel/KLTaskFinish/KLTaskFinishPanel",nil, nil, {taskId = finishId})
- SL.HideMainPanel()
- end
- break
- end
- end
- --local taskItem = taskItemPanel[finishId]
- --if taskItem then
- -- taskItem:Finish()
- --end
- --local realIndex = taskIdToRealIndex[finishId]
- --if realIndex then
- -- self:SetFinishState(realIndex)
- --end
-
- SL:ScheduleOnce(0.1,function()
- self:RefreshTaskList()
- end)
- end
- function this:LUA_EVENT_TASK_NEW(_, newTaskIdList)
- for _, newTaskId in pairs(newTaskIdList) do
- local npcDone = SL:GetConfig('cfg_task', newTaskId).npcDone
- if npcDone then
- --local npc = RoleManager.GetRoleBaseNpcId(npcDone)
- local npc = SL:GetRoleBaseNpcId(npcDone)
- if npc then
- self:RefreshNpcIcon(npcDone)
- end
- end
- end
- SL:ScheduleOnce(0.1,function()
- self.newTaskIdList = newTaskIdList
- self:RefreshTaskList()
- end)
- end
- function this:LUA_EVENT_TASK_SUBMIT(_, taskId)
- self:RefreshTaskList()
- ---@type cfg_task_column
- local task = SL:GetConfig("cfg_task", taskId)
- if task.npcDone and task.npcDone ~= 0 then
- SL:SetNpcIcon(task.npcDone, "")
- end
- end
- function this:RefreshTaskList()
- if self.taskItemPanel then
- for _, taskItem in pairs(self.taskItemPanel) do
- GUI:UIPanel_Close(nil, taskItem)
- end
- end
- self.taskItemPanel = {}
- taskIdToRealIndex = {}
-
- if self.view == nil then
- return
- end
-
- GUI:DataListUpdateData(self.view.left_top_task_list)
- end
- function this:ShowMonsterList(_,message)
- if message and message.vis == true then
- if self.monsterMapPointTimer then
- SL:UnSchedule(self.monsterMapPointTimer)
- end
- self.monsterMapPointTimer = SL:ScheduleOnce(1, function()
- if InfoManager.goldChallengeTaskInfo.IsMapMonsterData() and (self:IsShowMonsterList() or InfoManager.goldChallengeTaskInfo:IsShowMonsterList(InfoManager.goldChallengeTaskInfo.taskInfo)) then
- GUI:UIPanel_Open("dev/ui/Monster/Panel/KLMonsterMapPoint/KLMonsterMapPointPanel")
- else
- GUI:UIPanel_Close("dev/ui/Monster/Panel/KLMonsterMapPoint/KLMonsterMapPointPanel")
- end
- self.monsterMapPointTimer = nil
- end)
- else
- if self.monsterMapPointTimer then
- SL:UnSchedule(self.monsterMapPointTimer)
- end
- end
- end
- function this:IsShowMonsterList()
- local taskList=SL:TaskInfo_GetAllIds()
- for _,v in pairs(taskList) do
- local monsterList=SL:GetConfig("cfg_task",v).monsterlist
- if monsterList and monsterList == 1 then
- return true
- end
- end
- return false
- end
- function this:LUA_EVENT_NPC_CREATE(_, data)
- self:RefreshNpcIcon(data.npcId)
- --print(data.npcId)
- end
- function this:RefreshNpcIcon(npcId)
- local taskState = SL:GetInNpcTaskState(npcId)
- if taskState == 0 then
- SL:SetNpcIcon(npcId, "task_progress")
- elseif taskState == 1 then
- SL:SetNpcIcon(npcId, "task_finish")
- end
- end
- function this:Close()
- if self.taskItemPanel then
- for _, taskItem in pairs(self.taskItemPanel) do
- GUI:UIPanel_Close(nil, taskItem)
- end
- end
- self.taskItemPanel = {}
- end
- return this
|