KLUISkillSettingPanel.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. ---@class KLUISkillSettingPanel:UIKmlLuaPanelBase
  2. ---@field view KLUISkillSettingPanelView
  3. ---@field args {settingType:ESkillSettingType,curSelectId:number}
  4. ---@field curSelectSkillId number @当前选中的技能id
  5. ---@field curShowType ESkillType
  6. ---@field curSelectIndex number @选技能的序号(全部模式或者转盘模式)
  7. ---@field fastItemIds number[]
  8. ---@field curSelectItemId number
  9. ---@field curSelectItemIndex number
  10. ---@field curSettingType ESkillSettingType
  11. local KLUISkillSettingPanel = class(UIKmlLuaPanelBase)
  12. local this = KLUISkillSettingPanel
  13. ---创建时调用一次
  14. function this:Init()
  15. self.curSelectIndex = 0
  16. self.curSelectSkillId = 0
  17. self.curSelectItemId = 0
  18. self.curSelectItemIndex = 0
  19. GUI:DataListInitData(self.view.FastItemDataList,
  20. function()
  21. return self:ItemCountFunc()
  22. end,
  23. nil,
  24. nil,
  25. function(realIndex, kmlCtrl)
  26. return self:ItemUpdateFunc(realIndex, kmlCtrl)
  27. end)
  28. end
  29. function this:ItemCountFunc()
  30. return #self.fastItemIds
  31. end
  32. function this:ItemUpdateFunc(realIndex)
  33. local item = GUI:GetChildControl(self.view.FastItemDataList, realIndex, 'bagItem')
  34. local luaIdx = realIndex + 1
  35. local cfgId = self.fastItemIds[luaIdx]
  36. local count = 0
  37. if cfgId and cfgId ~= 0 then
  38. count = SL:GetBagItemCount(cfgId)
  39. end
  40. GUI:Item_setItemId(item, cfgId)
  41. local togItem = GUI:GetChildControl(self.view.FastItemDataList, realIndex, 'bagItemBg_')
  42. GUI:SetToggleOnValueChange(togItem, self, self.FastItemSelectValueChange, luaIdx)
  43. end
  44. function this:SetFastItemId()
  45. ---@type number[]
  46. local fastItems = SL:GetMetaValue(EMetaVarGetKey.FAST_ITEM_ID_LIST)
  47. if self.curSelectItemId > 0 and fastItems[self.curSelectItemIndex] ~= self.curSelectItemId then
  48. ---@type cfg_item_column
  49. local itemTbl = SL:GetConfig("cfg_item", self.curSelectItemId)
  50. local real_curSelectItemIndex = self.curSelectItemIndex
  51. if itemTbl.type == 3 and itemTbl.subType == 1 then
  52. if itemTbl.id >= 30010012 and itemTbl.id <= 30010022 then
  53. self.curSelectItemIndex = 1
  54. elseif itemTbl.id >= 30010001 and itemTbl.id <= 30010011 then
  55. self.curSelectItemIndex = 2
  56. end
  57. end
  58. if self.curSelectItemIndex <= 2 and not (itemTbl.type == 3 and itemTbl.subType == 1 and ((itemTbl.id >= 30010012 and itemTbl.id <= 30010022) or (itemTbl.id >= 30010001 and itemTbl.id <= 30010011))) then
  59. return
  60. end
  61. if SL:HasConfig("cfg_item", fastItems[self.curSelectItemIndex]) then
  62. ---@type cfg_item_column
  63. local itemTbl1 = SL:GetConfig("cfg_item", fastItems[self.curSelectItemIndex])
  64. --蓝药/血药
  65. if itemTbl.type == 3 and itemTbl.subType == 1 and ((itemTbl.id >= 30010012 and itemTbl.id <= 30010022) or (itemTbl.id >= 30010001 and itemTbl.id <= 30010011)) and itemTbl.rank < itemTbl1.rank and real_curSelectItemIndex ~= self.curSelectItemIndex then
  66. return
  67. end
  68. end
  69. fastItems[self.curSelectItemIndex] = self.curSelectItemId
  70. self.fastItemIds[self.curSelectItemIndex] = self.curSelectItemId
  71. for i = 1, #fastItems do
  72. if i ~= self.curSelectItemIndex and fastItems[i] == self.curSelectItemId then
  73. fastItems[i] = 0
  74. end
  75. end
  76. self.curSelectItemId = 0
  77. self.curSelectItemIndex = 0
  78. GUI:DataListUpdateData(self.view.FastItemDataList)
  79. end
  80. end
  81. ---@param kmlLuaCtrl UIKmlLuaControl
  82. ---@param luaIdx number
  83. function this:FastItemSelectValueChange(kmlLuaCtrl, luaIdx, args)
  84. local isOn = false
  85. if args[1] then
  86. self.curSelectItemIndex = luaIdx
  87. self.curSelectItemId = 0
  88. self:SetFastItemId()
  89. self.selectToggle = kmlLuaCtrl
  90. isOn = true
  91. else
  92. self.curSelectItemIndex = 0
  93. if not self.is_set_update and luaIdx > 2 then
  94. SL:SetMetaValue(EMetaVarGetKey.FAST_ITEM_ID_LIST, luaIdx, 0, 0)
  95. self:SetFastItemId()
  96. end
  97. end
  98. for realIndex in pairs(self.fastItemIds) do
  99. local togItem = GUI:GetChildControl(self.view.FastItemDataList, realIndex - 1, 'bagItemBg_')
  100. if togItem and ((isOn and realIndex ~= luaIdx) or not isOn) then
  101. GUI:SetIsOnWithoutNotify(togItem, false)
  102. end
  103. end
  104. self.is_set_update = false
  105. end
  106. ---创建或者刷新界面数据时调用
  107. function this:Refresh()
  108. if self.args.curSelectId and SL:GetMetaValue(EMetaVarGetKey.SKILL_CHECK_IS_LEARNED, self.args.curSelectId) then
  109. self.curSelectSkillId = self.args.curSelectId
  110. else
  111. self.curSelectSkillId = 0
  112. end
  113. local skillShowType = SL:GetMetaValue(EMetaVarGetKey.SKILL_SETTING_SHOW_TYPE)
  114. if skillShowType == ESkillType.All then
  115. GUI:SetTogDefaultThis(self.view.BtnShowAll)
  116. else
  117. GUI:SetTogDefaultThis(self.view.BtnTurnTable)
  118. end
  119. local fastItemList = SL:GetMetaValue(EMetaVarGetKey.FAST_ITEM_ID_LIST)
  120. self.fastItemIds = table.copyFrom({}, fastItemList)
  121. if not SL:HasConfig("cfg_item", self.fastItemIds[1]) then
  122. self.fastItemIds[1] = 30010022
  123. end
  124. if not SL:HasConfig("cfg_item", self.fastItemIds[2]) then
  125. self.fastItemIds[2] = 30010011
  126. end
  127. local settingType = self.args.settingType or ESkillSettingType.Skill
  128. GUI:DataListUpdateData(self.view.FastItemDataList)
  129. if settingType == ESkillSettingType.FastItem then
  130. GUI:Toggle_setIsOn(self.view.BagItemBtnSetting, true)
  131. end
  132. end
  133. ---注册UI事件和服务器消息
  134. function this:RegistEvents()
  135. GUI:SetToggleOnValueChange(self.view.SkillBtnSetting, self, self.TogSkillSettingValueChange)
  136. GUI:SetToggleOnValueChange(self.view.BagItemBtnSetting, self, self.TogBagItemValueChange)
  137. GUI:SetToggleOnValueChange(self.view.BtnShowAll, self, self.TogShowAllValueChange)
  138. GUI:SetToggleOnValueChange(self.view.BtnTurnTable, self, self.TogTurnValueChange)
  139. for i = 1, 7 do
  140. GUI:SetToggleOnValueChange(self.view["TogAllSkill" .. i], self, self.TogAllSkillValueChange, i)
  141. end
  142. for i = 1, 8 do
  143. GUI:SetToggleOnValueChange(self.view["TogTurnSkill" .. i], self, self.TogTurnSkillValueChange, i)
  144. end
  145. SL:RegisterLUAEvent(LUA_EVENT_SELECT_SKILL_UI, self.SelectSkill, self)
  146. SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.OnPanelClose, self)
  147. SL:RegisterLUAEvent(LUA_EVENT_FASTITEM_SET_SELECT, self.OnFastItemSetSelect, self)
  148. GUI:AddOnClickEvent(self.view.BtnReset, self, self.BtnResetOnClick)
  149. SL:RegisterLUAEvent(LUA_EVENT_INIT_SHORT_CUT, self.InitShortcutAfter, self)
  150. end
  151. function this:OnFastItemSetSelect(_, cfgId)
  152. self.curSelectItemId = cfgId or 0
  153. if not self.curSelectItemIndex or self.curSelectItemIndex == 0 then
  154. SL:TipMessage(SL:GetConfig('cfg_string', 294).text, 1, NoticeType.NoticeMid)
  155. ---请选择快捷栏
  156. return
  157. end
  158. ---@type number[]
  159. local fastItems = SL:GetMetaValue(EMetaVarGetKey.FAST_ITEM_ID_LIST)
  160. if fastItems[self.curSelectItemIndex] ~= self.curSelectItemId and not self:IsExistFastItem(cfgId) then
  161. self:SetFastItemId()
  162. self.is_set_update = true
  163. end
  164. GUI:Toggle_setIsOn(self.selectToggle, false)
  165. end
  166. function this:OnPanelClose(_, panelName)
  167. if panelName ~= "KLSkillBagPanel" then
  168. return
  169. end
  170. GUI:SetTogDefaultThis(self.view.SkillBtnSetting)
  171. end
  172. function this:BtnResetOnClick()
  173. ---@type number[]
  174. local showSkills = SL:GetMetaValue(EMetaVarGetKey.SKILL_SHOW_LIST)
  175. for i = 1, 8 do
  176. showSkills[i] = 0
  177. end
  178. SL:SetMetaValue(EMetaVarSetKey.SKILL_SHOW_LIST, showSkills)
  179. self:ShowSkillIcon()
  180. end
  181. ---@param skillItem KLUISkillItem
  182. function this:SelectSkill(_, skillItem)
  183. self.skillItem = skillItem
  184. self.skillId = skillItem.skillId
  185. self.skillItem:SetTogIsOn(false)
  186. if SL:GetMetaValue(EMetaVarGetKey.SKILL_CHECK_IS_LEARNED, self.skillId) and SL:GetMetaValue(EMetaVarGetKey.SKILL_CHECK_IS_UNLOCK, self.skillId) then
  187. self.curSelectSkillId = self.skillId
  188. else
  189. self.curSelectSkillId = 0
  190. end
  191. ---@type cfg_skill_column
  192. local skillTbl = SL:GetConfig("cfg_skill", self.skillId)
  193. if skillTbl.type ~= ECfgSkillType.Normal then
  194. return SL:TipMessage(SL:GetConfig('cfg_string', 295).text, 1, NoticeType.NoticeMid)--被动技能无法放置
  195. end
  196. if not self.curSelectIndex or self.curSelectIndex == 0 then
  197. return SL:TipMessage(SL:GetConfig('cfg_string', 296).text, 1, NoticeType.NoticeMid)--请选择技能栏
  198. end
  199. self:SetSkillId()
  200. GUI:Toggle_setIsOn(self.selectSkillTog, false)
  201. end
  202. function this:SetSkillId()
  203. ---@type number[]
  204. local showSkills = SL:GetMetaValue(EMetaVarGetKey.SKILL_SHOW_LIST)
  205. if self.curSelectSkillId > 0 and showSkills[self.curSelectIndex] ~= self.curSelectSkillId and SL:GetMetaValue(EMetaVarGetKey.SKILL_CHECK_IS_LEARNED, self.curSelectSkillId) then
  206. showSkills[self.curSelectIndex] = self.curSelectSkillId
  207. for i = 1, 8 do
  208. if i ~= self.curSelectIndex and showSkills[i] == self.curSelectSkillId then
  209. showSkills[i] = 0
  210. end
  211. end
  212. SL:SetMetaValue(EMetaVarSetKey.SKILL_SHOW_LIST, showSkills)
  213. self:ShowSkillIcon()
  214. end
  215. end
  216. --转盘模式
  217. function this:TogTurnSkillValueChange(kmlCtrl, index, args)
  218. if args[1] then
  219. self.curSelectIndex = index
  220. self.curSelectSkillId = 0
  221. self:SetSkillId()
  222. self.selectSkillTog = kmlCtrl
  223. else
  224. self.curSelectIndex = 0
  225. end
  226. end
  227. --全部模式
  228. function this:TogAllSkillValueChange(kmlCtrl, index, args)
  229. if args[1] then
  230. self.curSelectIndex = index
  231. self.curSelectSkillId = 0
  232. self:SetSkillId()
  233. self.selectSkillTog = kmlCtrl
  234. else
  235. self.curSelectIndex = 0
  236. end
  237. end
  238. function this:TogBagItemValueChange(_, _, args)
  239. if not args[1] then
  240. return
  241. end
  242. if self.curSettingType == ESkillSettingType.FastItem then
  243. return
  244. end
  245. self.curSettingType = ESkillSettingType.FastItem
  246. GUI:UIPanel_Open("dev/ui/Bag/Panel/KLSkillBag/KLSkillBagPanel")
  247. --关闭技能界面
  248. GUI:UIPanel_Close("dev/ui/Skill/Panel/KLUISkillInfo/KLUISkillInfoPanel")
  249. SL.HideMainPanel()
  250. end
  251. function this:TogSkillSettingValueChange(_, _, args)
  252. if not args[1] then
  253. return
  254. end
  255. if self.curSettingType == ESkillSettingType.Skill then
  256. return
  257. end
  258. self.curSettingType = ESkillSettingType.Skill
  259. GUI:UIPanel_Open("dev/ui/Skill/Panel/KLUISkillInfo/KLUISkillInfoPanel", nil, nil, ESkillUIShowPage.Setting)
  260. --关闭背包
  261. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLSkillBag/KLSkillBagPanel")
  262. end
  263. function this:ShowSkillIcon()
  264. ---@type number[]
  265. local showSkills = SL:GetMetaValue(EMetaVarGetKey.SKILL_SHOW_LIST)
  266. local maxIdx = self.curShowType == ESkillType.All and 7 or 8
  267. for i = 1, maxIdx do
  268. local spriteName = ""
  269. local skillId = showSkills[i]
  270. if skillId > 0 then
  271. ---@type Skill
  272. local skill = SL:GetMetaValue(EMetaVarGetKey.SKILL_DATA, skillId)
  273. if skill then
  274. ---@type cfg_skill_info_column
  275. local tbl = SL:GetConfigMultiKeys('cfg_skill_info', skillId, skill.level, 'skillID', 'skillLevel')
  276. spriteName = string.isNullOrEmpty(tbl.icon) and "" or tbl.icon
  277. end
  278. end
  279. local key = self.curShowType == ESkillType.All and "AllSkillIcon" or "TurnSkillIcon"
  280. GUI:Image_loadTexture(self.view[key .. i], spriteName, "Atlas/UIOutSkillIcon.spriteatlas")
  281. --key = self.curShowType == ESkillType.All and "TogAllSkill" or "TogTurnSkill"
  282. --self.view["TogTurnSkill" .. i]:SetTogIsOn(false)
  283. end
  284. end
  285. function this:TogShowAllValueChange(_, _, args)
  286. if args[1] then
  287. GUI:setVisible(self.view.BodyAllSkill, true)
  288. GUI:setVisible(self.view.BodyTurnSkill, false)
  289. self.curShowType = ESkillType.All
  290. SL:SetMetaValue(EMetaVarSetKey.SKILL_SETTING_SHOW_TYPE, self.curShowType)
  291. self.curSelectIndex = nil
  292. self:ShowSkillIcon()
  293. end
  294. end
  295. function this:TogTurnValueChange(_, _, args)
  296. if args[1] then
  297. GUI:setVisible(self.view.BodyAllSkill, false)
  298. GUI:setVisible(self.view.BodyTurnSkill, true)
  299. self.curShowType = ESkillType.Turn
  300. SL:SetMetaValue(EMetaVarSetKey.SKILL_SETTING_SHOW_TYPE, self.curShowType)
  301. self.curSelectIndex = nil
  302. self:ShowSkillIcon()
  303. end
  304. end
  305. function this:InitShortcutAfter()
  306. local fastItemList = SL:GetMetaValue(EMetaVarGetKey.FAST_ITEM_ID_LIST)
  307. self.fastItemIds = table.copyFrom({}, fastItemList)
  308. if not SL:HasConfig("cfg_item", self.fastItemIds[1]) then
  309. self.fastItemIds[1] = 30010022
  310. end
  311. if not SL:HasConfig("cfg_item", self.fastItemIds[2]) then
  312. self.fastItemIds[2] = 30010011
  313. end
  314. GUI:DataListUpdateData(self.view.FastItemDataList)
  315. end
  316. function this:IsExistFastItem(cfgId)
  317. ---@type number[]
  318. local fastItems = SL:GetMetaValue(EMetaVarGetKey.FAST_ITEM_ID_LIST)
  319. return table.contains(fastItems, cfgId)
  320. end
  321. function this:Close()
  322. self.curSettingType = nil
  323. SL:SetMetaValue(EMetaVarSetKey.SKILL_SETTING_SHOW_TYPE, self.curShowType)
  324. SL.UploadSkillSettingData()
  325. SL:onLUAEvent(LUA_EVENT_REFRESH_ATTACK_SKILL)
  326. end
  327. return this