---@class KLMainAttackPanel:UIKmlLuaPanelBase ---@field view KLMainAttackPanelView local KLMainAttackPanel = class(UIKmlLuaPanelBase) local this = KLMainAttackPanel ---@type table> local centerPos = { [ESkillType.All] = { 0, 0 }, [ESkillType.Turn] = { 92, -131 }, } ---@type table> local itemPos = { [ESkillType.All] = { [1] = { 107, 53 }, [2] = { 24, 20 }, [3] = { -43, -53 }, [4] = { -81, -143 }, [5] = { 25, 121 }, [6] = { -67, 41 }, [7] = { -136, -61 }, }, [ESkillType.Turn] = { [1] = { 39, 164 }, [2] = { -64, 156 }, [3] = { -142, 88 }, [4] = { -165, -15 }, [5] = { -127, -106 }, [6] = { -39, -156 }, [7] = { 60, -146 }, [8] = { 139, -88 }, }, } ---@type KLSkillBtnItem[] local skillBtns = {} ---创建时调用一次 function this:Init() end ---创建或者刷新界面数据时调用 function this:Refresh() self:UpdateUI() end function this:UpdateUI() self.curShowType = SL:GetMetaValue(EMetaVarGetKey.SKILL_SETTING_SHOW_TYPE) or ESkillType.All local cPos = centerPos[self.curShowType] GUI:setPosition(self.view.SkillStruct, cPos[1], cPos[2]) local maxCount = 8 if self.curShowType == ESkillType.All then if skillBtns[8] then GUI:UIPanel_Close(nil, skillBtns[8]) skillBtns[8] = nil end maxCount = 7 end GUI:SetLocalEulerAngles(self.view.SkillStruct, 0, 0, 0) ---变身走另一套逻辑 if InfoManager.shapeShiftCardInfo:isShiftMonster() then local shiftMonsterGroup = InfoManager.shapeShiftCardInfo.shiftMonsterGroup local shiftSkill = InfoManager.shapeShiftCardInfo.shiftSkill ---@type number[] local skills = shiftSkill[shiftMonsterGroup].unlockSkill local lockSkills = shiftSkill[shiftMonsterGroup].lockSkill local showSkills = {} local showSkillsLevel = {} for i, v in pairs(skills) do ---@type cfg_skill_column local skill = SL:GetConfig("cfg_skill", i) if skill.type == ECfgSkillType.Normal and skill.group == ESkillGroup.normal then showSkills[#showSkills + 1] = i showSkillsLevel[#showSkillsLevel + 1] = false elseif skill.type == ECfgSkillType.Normal and skill.group == ESkillGroup.ordinaryAttack then self.ordinaryAttackId = i self.ordinaryAttackLevel = v ---@type cfg_skill_info_column local skill_info = SL:GetConfigMultiKeys('cfg_skill_info', self.ordinaryAttackId, self.ordinaryAttackLevel, 'skillID', 'skillLevel') GUI:Image_loadTexture(self.view.sword, skill_info.icon, "Atlas/UIOutSkillIcon.spriteatlas") end end for i, v in pairs(lockSkills) do ---@type cfg_skill_column local skill = SL:GetConfig("cfg_skill", i) if skill.type == ECfgSkillType.Normal and skill.group == ESkillGroup.normal then local isHave = false for ii, vv in ipairs(showSkills) do if i == vv then isHave = true break end end if not isHave then showSkills[#showSkills + 1] = i showSkillsLevel[#showSkillsLevel + 1] = true end end end local pos = itemPos[self.curShowType] for i = 1, maxCount do ---@type KLSkillBtnItem local item = skillBtns[i] if not item then item = GUI:UIPanel_Open("dev/ui/MainUI/Item/KLSkillBtn/KLSkillBtnItem", self.view.SkillStruct, self, nil, true) skillBtns[i] = item end GUI:setPosition(item.view.root, pos[i][1], pos[i][2]) GUI:SetEulerAngles(item.view.root, 0, 0, 0) item:UpdateUI(showSkills[i],showSkillsLevel[i]) end return end ---@type number[] local showSkills = SL:GetMetaValue(EMetaVarGetKey.SKILL_SHOW_LIST) local pos = itemPos[self.curShowType] for i = 1, maxCount do ---@type KLSkillBtnItem local item = skillBtns[i] if not item then item = GUI:UIPanel_Open("dev/ui/MainUI/Item/KLSkillBtn/KLSkillBtnItem", self.view.SkillStruct, self, nil, true) skillBtns[i] = item end GUI:setPosition(item.view.root, pos[i][1], pos[i][2]) GUI:SetEulerAngles(item.view.root, 0, 0, 0) item:UpdateUI(showSkills[i]) end GUI:Image_loadTexture(self.view.sword, "img_interface_main039", "Atlas/UIMainAttackPanel.spriteatlas") GUI:SetCirclebar_time(self.view.Img_cdTime, 0) end ---注册UI事件和服务器消息 function this:RegistEvents() SL:RegisterLUAEvent(Event.Skill_CDing, self.OnSkillCDing, self) SL:RegisterLUAEvent(LUA_EVENT_REFRESH_ATTACK_SKILL, self.UpdateUI, self) GUI:AddOnClickEvent(self.view.AttackButton, self, self.OnAttackClick) GUI:AddOnTouchEvent(self.view.AttackButton, self, self.OnAttackTouch) GUI:AddOnClickEvent(self.view.BtnKillMonster, self, self.KillMonsterOnClick) GUI:AddOnClickEvent(self.view.BtnKillPerson, self, self.KillPersonOnClick) GUI:AddOnClickEvent(self.view.BtnMount, self, self.BtnMountOnClick) SL:RegisterLUAEvent(Event.UpdateSkillSetting, self.UpdateUI, self) end function this:KillPersonOnClick() GUI:SetActive(self.view.killPerson, true) if self.co_eff_person then SL:UnSchedule(self.co_eff_person) end self.co_eff_person = SL:ScheduleOnce(0.5, function() GUI:SetActive(self.view.killPerson, false) end) ---@type CheckIsCanSkillDataType local skillDat = { skillId = SL:GetMetaValue(EMetaVarGetKey.SKILL_GET_COMMON_ID) or 0, selectAttachType = ERoleType.Player } SL:onLUAEvent(Event.ReleaseSkill, skillDat) end function this:KillMonsterOnClick() GUI:SetActive(self.view.killMonster, true) if self.co_eff_monster then SL:UnSchedule(self.co_eff_monster) end self.co_eff_monster = SL:ScheduleOnce(0.5, function() GUI:SetActive(self.view.killMonster, false) end) ---@type CheckIsCanSkillDataType local skillDat = { skillId = SL:GetMetaValue(EMetaVarGetKey.SKILL_GET_COMMON_ID) or 0, selectAttachType = ERoleType.Monster } SL:onLUAEvent(Event.ReleaseSkill, skillDat) end function this:BtnMountOnClick() if InfoManager.shapeShiftCardInfo:isShiftMonster() then SL:TipMessage( SL:GetConfig('cfg_string',487).text,1, NoticeType.NoticeMid ) return end if InfoManager.mountInfo.ride_mount_id ~= 0 then SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_CANCEL_RIDING_MOUNT, {}) else SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RIDING_MOUNT, {}) end end function this:OnAttackClick() self:ResetAttackControl() GUI:SetActive(self.view.clickEffect, true) local skillDat if InfoManager.shapeShiftCardInfo:isShiftMonster() then ---@type Skill local skill = SL:GetMetaValue(EMetaVarGetKey.SKILL_DATA, self.ordinaryAttackId) if not skill or not skill:IsCDEnough() then return end ---@type CheckIsCanSkillDataType skillDat = { skillId = self.ordinaryAttackId or 0, } else ---@type CheckIsCanSkillDataType skillDat = { skillId = SL:GetMetaValue(EMetaVarGetKey.SKILL_GET_COMMON_ID) or 0, } end SL:onLUAEvent(Event.ReleaseSkill, skillDat) end ---@param kmlCtrl UIKmlLuaControl ---@param eventType EUIEventName function this:OnAttackTouch(kmlCtrl, eventType, args) if eventType == EUIEventName.OnBeginDrag then self.pointDownPos = args.position elseif eventType == EUIEventName.OnDrag then if args.position.y > self.pointDownPos.y then GUI:SetActive(self.view.killPerson, true) GUI:SetActive(self.view.killMonster, false) else GUI:SetActive(self.view.killPerson, false) GUI:SetActive(self.view.killMonster, true) end elseif eventType == EUIEventName.OnEndDrag then --玩家 if args.position.y > self.pointDownPos.y then if args.position.y - self.pointDownPos.y > 5 then self:KillPersonOnClick() end else --怪物 if self.pointDownPos.y - args.position.y > 5 then self:KillMonsterOnClick() end end self:ResetAttackControl() elseif eventType == EUIEventName.OnPointerUp then self:ResetAttackControl() end end function this:ResetAttackControl() GUI:SetActive(self.view.killPerson, false) GUI:SetActive(self.view.killMonster, false) end ---@param skill Skill function this:OnSkillCDing(_, skill) local commonSkillId if InfoManager.shapeShiftCardInfo:isShiftMonster() then commonSkillId = self.ordinaryAttackId else commonSkillId = SL:GetMetaValue(EMetaVarGetKey.SKILL_GET_COMMON_ID) or 0 end if commonSkillId ~= skill.skillId then return end self.remainCdTime = skill:LeftCDTime() if skill.curCDTime / 1000 ~= self.cdTime then self.cdTime = skill.curCDTime / 1000 end if not self.cdTime then return end if self.remainCdTime / self.cdTime <= 0.05 then GUI:SetCirclebar_startper(self.view.Img_cdTime, 0) else local startper = self.remainCdTime / self.cdTime * 100 startper = math.floor(startper) GUI:SetCirclebar_startper(self.view.Img_cdTime, startper) GUI:SetCirclebar_time(self.view.Img_cdTime, self.remainCdTime) end end ---@param kmlCtrl UIKmlLuaControl ---@param eventType EUIEventName function this:OnTouchEvent(kmlCtrl, eventType, args) if self.curShowType == ESkillType.All then return end if eventType == EUIEventName.OnDrag then local angleX, angleY, angleZ = GUI:GetLocalEulerAngles(self.view.SkillStruct) if (angleZ ~= 0 and angleZ < 200) or angleZ > 360 then return end local nor = args.delta.y if Mathf.Abs(args.delta.x) > Mathf.Abs(args.delta.y) then nor = args.delta.x end local mag = Vector2.Magnitude(args.delta) if nor < 0 then angleZ = angleZ + mag * 0.4 else angleZ = angleZ - mag * 0.4 end if (angleZ > 0 and angleZ < 100) or angleZ > 360 then angleZ = 0 end if angleZ > 100 and angleZ < 200 then angleZ = 200 end GUI:SetLocalEulerAngles(self.view.SkillStruct, angleX, angleY, angleZ) for _, v in pairs(skillBtns) do GUI:SetEulerAngles(v.view.root, 0, 0, 0) end elseif eventType == EUIEventName.OnEndDrag then local angleX, angleY, angleZ = GUI:GetLocalEulerAngles(self.view.SkillStruct) local delta = 0 local tmp1, tmp2 = math.modf(angleZ / 36) if tmp2 < 0.5 then angleZ = (tmp1) * 36 - delta else angleZ = (tmp1 + 1) * 36 - delta end if (angleZ > 0 and angleZ < 100) or angleZ > 360 then angleZ = 0 end if angleZ > 100 and angleZ <= 200 then angleZ = 216 end GUI:SetLocalEulerAngles(self.view.SkillStruct, angleX, angleY, angleZ) for _, v in pairs(skillBtns) do GUI:SetEulerAngles(v.view.root, 0, 0, 0) end end end function this:Close() for _, v in pairs(skillBtns) do GUI:UIPanel_Close("dev/ui/MainUI/Item/KLSkillBtn/KLSkillBtnItem", v) end table.clear(skillBtns) self.cdTime = 0 self.remainCdTime = 0 if self.co_eff_monster then SL:UnSchedule(self.co_eff_monster) self.co_eff_monster = nil end if self.co_eff_person then SL:UnSchedule(self.co_eff_person) self.co_eff_person = nil end end return this