KLBagTipsPanel.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. ---@class KLBagTipsPanel:UIKmlLuaPanelBase
  2. ---@field view KLBagTipsPanelView
  3. local KLBagTipsPanel = class(UIKmlLuaPanelBase)
  4. local this = KLBagTipsPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. self.ShowTipType = EShortcutUserType.NormalBox
  8. self.ShowTipItemData = nil
  9. end
  10. ---创建或者刷新界面数据时调用
  11. function this:Refresh()
  12. self:UpdataPanel()
  13. end
  14. ---特殊属性点快捷提示
  15. function this:SetAttrPosUI()
  16. self:CloseDownTimer()
  17. GUI:setVisible(self.view.Item, false)
  18. GUI:setVisible(self.view.TimeCountdown, false)
  19. local namestr = "<color=#F5EFE4>" .. "可分配点数" .. "</color>"
  20. local usestr = EShortcutUserTypeStr[EShortcutUserType.AttrPos]
  21. local AttrPoint = tostring(SL:GetMetaValue("REMAIN_ATTR_POINT"))
  22. GUI:SetOnPrefabControlLoaded(self.view.scroll_text_template, function()
  23. GUI:Text_setString(self.view.Text, namestr)
  24. end)
  25. GUI:Text_setString(self.view.UseText, usestr)
  26. GUI:setPositionX(self.view.UseText, 0)
  27. GUI:Text_setString(self.view.AttrText, AttrPoint)
  28. GUI:setVisible(self.view.AttrImage, true)
  29. end
  30. function this:UpdataPanel()
  31. if not self.view then
  32. return
  33. end
  34. local bagItem = SL:GetShowEquip()
  35. local boxitems = SL:UiBoxTipsInfo_GetShowBoxItem()
  36. if bagItem == nil and boxitems == nil then
  37. GUI:UIPanel_Close("dev/ui/Preview/Panel/KLBagTips/KLBagTipsPanel")
  38. return
  39. end
  40. ---背包装备
  41. if self.isShowEquip and self.showBag and self.showBag == bagItem and boxitems == nil then
  42. --重复刷新当前正显示装备
  43. --self.ShowTipItemData = bagItem
  44. --self:UpdataEquipPanel(bagItem)
  45. return
  46. end
  47. self.showBag = bagItem
  48. self.isShowEquip = false ---装备提示
  49. self.isShowAttrPos = false ---属性点提示
  50. ---在此处操作排序
  51. if boxitems == nil then
  52. self.ShowTipItemData = bagItem
  53. self:UpdataEquipPanel(bagItem)
  54. return
  55. end
  56. if self.qualityItem then
  57. GUI:UIPanel_Close(nil, self.qualityItem)
  58. end
  59. self.qualityItem = nil
  60. ---属性点,技能
  61. self.showBag = nil
  62. self.ShowTipItemData = boxitems
  63. GUI:setVisible(self.view.equiptag, false)
  64. GUI:setVisible(self.view.bagtag, false)
  65. if boxitems.itemId and boxitems.itemId == 10030007 then
  66. self.isShowAttrPos = true
  67. self.ShowTipType = EShortcutUserType.AttrPos
  68. self:SetAttrPosUI()
  69. else
  70. self.ShowTipType = EShortcutUserType.NormalBox
  71. local itemcfg = SL:GetConfig("cfg_item", boxitems.itemId)
  72. if itemcfg == nil then
  73. return
  74. end
  75. GUI:SetOnPrefabControlLoaded(self.view.scroll_text_template, function()
  76. GUI:Text_setTextColor(self.view.Text, SL:GetColorCfg(itemcfg.color).color)
  77. GUI:Text_setString(self.view.Text, itemcfg.name)
  78. end)
  79. --GUI:Text_setTextColor(self.view.Text, SL:GetColorCfg(itemcfg.color).color)
  80. --GUI:Text_setString(self.view.Text, itemcfg.name)
  81. GUI:Text_setString(self.view.AttrText, "")
  82. GUI:setVisible(self.view.AttrImage, false)
  83. GUI:setVisible(self.view.Item, true)
  84. self:SetEquipItemIcon(true, itemcfg.id)
  85. self.nowCfgId = itemcfg.id
  86. if boxitems ~= nil or bagItem == nil then
  87. GUI:setVisible(self.view.TimeCountdown, false)
  88. self:CloseDownTimer() --删除倒计时
  89. self:UpdataItemPanel(boxitems.itemId)
  90. end
  91. end
  92. end
  93. function this:SetEquipItemIcon(show, id)
  94. GUI:setVisible(self.view.Item, show)
  95. if show then
  96. if self.equipIcon then
  97. --self.view.Item.kmlControl:HideAllChilds()
  98. GUI:RemoveAllChildren(self.view.Item)
  99. end
  100. self.equipIcon = GUI:Item_Create(self.view.Item, {
  101. width = "70",
  102. height = "70",
  103. itemid = id,
  104. tips = "1",
  105. noclip = "1",
  106. bgtype = "0",
  107. mfixsize = "70,70"
  108. })
  109. GUI:Item_UpdataData(self.equipIcon, {
  110. itemid = id,
  111. })
  112. --GUI:AddOnClickEvent(self.equipIcon, self, self.ClickEquipItemIcon, { id = id})
  113. end
  114. end
  115. ----按钮倒计时设置
  116. function this:CountDownText()
  117. if self.countDownTimer and self.countDownTimer <= 0 then
  118. return
  119. end
  120. self.countDownTimer = self.countDownTimer - 1
  121. GUI:Text_setString(self.view.TimeCountdown, string.format(" (%ds)", self.countDownTimer))
  122. --if DebugFlag.LogEnable then
  123. -- log('倒计时 find = ' ..self.countDownTimer)
  124. --end
  125. if self.countDownTimer <= 0 then
  126. GUI:Text_setString(self.view.TimeCountdown, "")
  127. self:CloseDownTimer()
  128. self:Use1BtnClick()
  129. if self.timer_autoUse then
  130. SL:UnSchedule(self.timer_autoUse)
  131. self.timer_autoUse = nil
  132. end
  133. end
  134. end
  135. function this:CloseDownTimer()
  136. if self.timer_autoUse then
  137. SL:UnSchedule(self.timer_autoUse)
  138. self.timer_autoUse = nil
  139. end
  140. end
  141. ---按钮文本设置
  142. function this:StartCountDownTimer(type, cfg)
  143. local usestr = EShortcutUserTypeStr[type]
  144. GUI:Text_setString(self.view.UseText, usestr)
  145. --local contentX = self.view.UseText.rectTransform.localPosition.x
  146. --self.view.UseText.rectTransform:SetLocalPosition(-18, 0)
  147. GUI:setLocalPosition(self.view.UseText, -18, 0)
  148. self.countDownTimer = 8
  149. if cfg ~= nil and cfg.bayWindow > 0 and cfg.bayWindow < 999 then
  150. self.countDownTimer = cfg.bayWindow
  151. end
  152. self.timer_autoUse = SL:Schedule(self.timer_autoUse, 0, 1, -1, function()
  153. self:CountDownText()
  154. end)
  155. end
  156. function this:SetUseText_NoCountDown(type)
  157. local usestr = EShortcutUserTypeStr[type]
  158. GUI:Text_setString(self.view.UseText, usestr)
  159. --self.view.UseText.rectTransform:SetLocalPosition(0, 0)
  160. GUI:setLocalPosition(self.view.UseText, 0, 0)
  161. end
  162. ---注册UI事件和服务器消息
  163. function this:RegistEvents()
  164. -- if self.view then
  165. GUI:AddOnClickEvent(self.view.BtnClose, self, self.CloseBtnClick)
  166. GUI:AddOnClickEvent(self.view.BtnUse1, self, self.Use1BtnClick)
  167. --SL:RegisterLUAEvent(LUA_EVENT_ADDFIREND,self.LUA_EVENT_ADDFIREND,self)
  168. SL:RegisterLUAEvent(LUA_EVENT_OPEN_UI, self.LUA_EVENT_OPEN_UI, self)
  169. SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.LUA_EVENT_CLOSEWIN, self)
  170. -- end
  171. end
  172. function this:LUA_EVENT_OPEN_UI(_, message)
  173. if message.panelName == "KLUIBagPanel" then
  174. SL:DelAllEquip()
  175. end
  176. end
  177. function this:LUA_EVENT_CLOSEWIN(_, message)
  178. if message == "KLUIBagPanel" then
  179. SL:DelAllEquip()
  180. end
  181. end
  182. ---使用/穿戴
  183. function this:Use1BtnClick(_, event)
  184. if self.isShowAttrPos then
  185. SL:OpenKLAttrPanel()
  186. elseif self.isShowEquip then
  187. self:CloseDownTimer()
  188. if self.ShowTipType == EShortcutUserType.WearEquip then
  189. --SL:SetMetaValue(EMetaVarSetKey.SET_ROLE_ATTR_VALUE_OFFSET, self.offsetAttrList)
  190. --SL:WearEquip()
  191. SL:PutOnEquip(self.ShowTipItemData.item)
  192. else
  193. SL:OpenKLBagPanel()
  194. self:CloseBtnClick()
  195. end
  196. else
  197. local itemcfg = SL:GetConfig("cfg_item", self.ShowTipItemData.itemId)
  198. if SL:CheckIsSkillBookType(self.ShowTipItemData.itemId) then
  199. local useParam = string.split(itemcfg.useParam, "#")
  200. local skillId = tonumber(useParam[1])
  201. SL:ReqUpSkillMessage(skillId)
  202. SL:DeleteBoxItem(self.ShowTipItemData.itemId)
  203. else
  204. --批量使用宝箱ReqBatchOpenBoxMessage
  205. local bag = SL:GetMetaValue("BAG_DATA")[1]
  206. for _, v in pairs(bag) do
  207. if v.cfgId == self.ShowTipItemData.itemId then
  208. SL:UseItem(self.ShowTipItemData.itemId, v.id, 1)
  209. self:CloseBtnClick()
  210. return
  211. end
  212. end
  213. --SL:UseBoxItem()
  214. --SL:UseItem(self.args.cfgId, self.args.id, self.args.count)
  215. end
  216. end
  217. self:UpdataPanel()
  218. end
  219. ---关闭活动预告
  220. function this:CloseBtnClick()
  221. if self.isShowEquip then
  222. SL:ReMoveNowItem()
  223. self:UpdataPanel()
  224. else
  225. SL:HideBoxItem()
  226. self:UpdataPanel()
  227. end
  228. end
  229. function this:UpdataItemPanel(itemId)
  230. local cfg = SL:GetConfig("cfg_item", itemId, "id")
  231. if cfg.bayWindow < 999 then
  232. --自动使用
  233. self.ShowTipType = EShortcutUserType.NormalBox
  234. GUI:setVisible(self.view.TimeCountdown, true)
  235. self:StartCountDownTimer(self.ShowTipType, cfg)
  236. else
  237. self.ShowTipType = EShortcutUserType.NormalBox
  238. self:CloseDownTimer()
  239. GUI:setVisible(self.view.TimeCountdown, false)
  240. self:SetUseText_NoCountDown(self.ShowTipType)
  241. end
  242. end
  243. ---@param bagItem BagProtos.BagItem
  244. function this:UpdataEquipPanel(bagItem)
  245. local canEquip = self:ShowEquip(bagItem)
  246. if self.isShowEquip then
  247. --装备替换的时候先卸下装备,再穿上新装备
  248. --此时如果下一个要显示快捷使用的装备跟替换的装备是同一个部位的话
  249. --会在穿上新装备之前检测了下一个同部位的装备,会出现身上对应部位没有装备,但是实际上下一帧就会有装备穿上
  250. --因此等下一帧再跑检测逻辑
  251. if self.coroutineAutoUse then
  252. Coroutine.Stop(self.coroutineAutoUse)
  253. self.coroutineAutoUse = nil
  254. end
  255. self.coroutineAutoUse = Coroutine.Start(self.CheckEquipAutoUse, self, canEquip)
  256. end
  257. end
  258. ---canEquip == true 满足要求可自动穿戴
  259. function this:CheckEquipAutoUse(canEquip)
  260. Coroutine.WaitForEndOfFrame()
  261. if self.showBag == nil then
  262. return
  263. end
  264. if self.qualityItem then
  265. self.qualityItem:SetData(self.showBag.item.cfgId, table.count(SL:GetEquipEntrys(self.showBag.item)))
  266. else
  267. GUI:UIPanel_Open("dev/ui/Common/Item/KLEquipQualityEntry/KLEquipQualityEntryItem",
  268. self.view.MainPanle, self,
  269. { cfgId = self.showBag.item.cfgId, entryCount = table.count(SL:GetEquipEntrys(self.showBag.item)) }, false,
  270. function(qualityItem)
  271. self.qualityItem = qualityItem
  272. end)
  273. end
  274. local cfg = SL:GetConfig("cfg_item", self.showBag.item.cfgId)
  275. if canEquip then
  276. ---立即装备
  277. local noEquip = true
  278. for i = 1, #cfg.strPart do
  279. --local equip = RoleManager.meData.equipInfo:GetEquipByPosAndWearBar(cfg.strPart[i], cfg.wearBarID[1])
  280. local equip = SL:MeData_GetEquipByPosAndWearBar(cfg.strPart[i], cfg.wearBarID[1])
  281. --对应部位没穿装备才开启自动使用
  282. if not equip then
  283. noEquip = true
  284. break
  285. end
  286. end
  287. if cfg.bayWindow == 999 then
  288. noEquip = false
  289. end
  290. if noEquip then
  291. --自动使用装备
  292. self.ShowTipType = EShortcutUserType.WearEquip
  293. GUI:setVisible(self.view.TimeCountdown, true)
  294. self:StartCountDownTimer(self.ShowTipType, cfg)
  295. else
  296. self.ShowTipType = EShortcutUserType.WearEquip
  297. self:CloseDownTimer()
  298. GUI:setVisible(self.view.TimeCountdown, false)
  299. self:SetUseText_NoCountDown(self.ShowTipType)
  300. end
  301. else
  302. ---打开背包
  303. self.ShowTipType = EShortcutUserType.NoWearEquip
  304. self:CloseDownTimer()
  305. GUI:setVisible(self.view.TimeCountdown, false)
  306. self:SetUseText_NoCountDown(self.ShowTipType)
  307. end
  308. GUI:setVisible(self.view.equiptag, self.ShowTipType == EShortcutUserType.WearEquip)
  309. GUI:setVisible(self.view.bagtag, self.ShowTipType == EShortcutUserType.NoWearEquip)
  310. end
  311. --是否满足穿戴要求
  312. function this:ShowEquip(bagItem)
  313. if bagItem == nil then
  314. return false
  315. end
  316. local itemCfg = SL:GetConfig("cfg_item", bagItem.item.cfgId)
  317. if itemCfg == nil then
  318. return false
  319. end
  320. GUI:SetOnPrefabControlLoaded(self.view.scroll_text_template, function()
  321. GUI:Text_setTextColor(self.view.Text, SL:GetColorCfg(itemCfg.color).color)
  322. GUI:Text_setString(self.view.Text, SL:GetItemNameByItemData(bagItem.item))
  323. end)
  324. --GUI:Text_setTextColor(self.view.Text, SL:GetColorCfg(itemCfg.color).color)
  325. --GUI:Text_setString(self.view.Text, SL:GetItemNameByItemData(bagItem.item))
  326. GUI:Text_setString(self.view.AttrText, "")
  327. GUI:setVisible(self.view.AttrImage, false)
  328. self:SetEquipItemIcon(true, bagItem.item.cfgId)
  329. self.isShowEquip = true
  330. local needLevelList = SL:Split(itemCfg.useLevelLimit, '#')
  331. if #needLevelList ~= 0 then
  332. --- 超过某一级才能使用的装备
  333. if #needLevelList == 1 then
  334. if tonumber(needLevelList[1]) > SL:GetMetaValue(EMetaVarGetKey.LEVEL) then
  335. return false
  336. end
  337. --- 等级在某一区间才能用
  338. elseif #needLevelList == 2 then
  339. if tonumber(needLevelList[1]) > SL:GetMetaValue(EMetaVarGetKey.LEVEL) or SL:GetMetaValue(EMetaVarGetKey.LEVEL) > tonumber(needLevelList[2]) then
  340. return false
  341. end
  342. end
  343. end
  344. ---穿戴栏是否解锁 rein 为空
  345. if itemCfg.wearBarID[1] and itemCfg.wearBarID[1] > SL:MeData_GetCareer().careerRank - 1 then
  346. --return false
  347. end
  348. --- 属性判断
  349. local needAttrList = SL:GetNeedAttrList(bagItem.item.cfgId)
  350. self.offsetAttrList = {}
  351. for _, attrInfo in pairs(needAttrList) do
  352. local attrId = attrInfo[1]
  353. local attrValue = attrInfo[2]
  354. local attrCfg = SL:GetConfig("cfg_att_info", attrId)
  355. if attrCfg ~= nil then
  356. local haveAttr = SL:GetMetaValue(EMetaVarGetKey.GET_ATTR_VALUE_BY_ID, attrId)
  357. local offsetValue = self:GetAttrValueOffset(attrId, attrValue,
  358. bagItem.item.itemExtInfo.equipExtInfo.entryAttr)
  359. self.offsetAttrList[attrId] = -offsetValue
  360. attrValue = attrValue - offsetValue
  361. if haveAttr < attrValue then
  362. return false
  363. end
  364. end
  365. end
  366. return true
  367. end
  368. ---获取被属性衰减过的实际生效属性
  369. ---@param attrList CommonProtos.EquipEntryAttrVo[] 幸运属性
  370. function this:GetAttrValueOffset(attrId, attrValue, attrList)
  371. if not attrList then
  372. return 0
  373. end
  374. local specialValue = 0
  375. ---@type cfg_att_special_column
  376. local specialTbl = SL:GetConfig("cfg_att_special", tostring(attrId), "param")
  377. if specialTbl and specialTbl.type[1] == 21 then
  378. for _, v in pairs(attrList) do
  379. if v.type == specialTbl.id then
  380. specialValue = v.num
  381. break
  382. end
  383. end
  384. ---@type cfg_att_info_column
  385. local tbl = SL:GetConfig("cfg_att_info", specialTbl.id)
  386. if tbl then
  387. if tbl.remarks == 2 then
  388. specialValue = attrValue * specialValue * 100
  389. end
  390. end
  391. end
  392. return specialValue
  393. end
  394. function this:Close()
  395. --SL:RegisterLUAEvent(LUA_EVENT_ADDFIREND,self.LUA_EVENT_ADDFIREND,self)
  396. SL:UnRegisterLUAEvent(LUA_EVENT_OPEN_UI, self.LUA_EVENT_OPEN_UI, self)
  397. SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.LUA_EVENT_CLOSEWIN, self)
  398. if self.coroutineAutoUse then
  399. Coroutine.Stop(self.coroutineAutoUse)
  400. self.coroutineAutoUse = nil
  401. end
  402. self:CloseDownTimer()
  403. Coroutine.Stop(self.coroutineAutoUse)
  404. -- Coroutine.StopAll()
  405. if self.qualityItem then
  406. GUI:UIPanel_Close(nil, self.qualityItem)
  407. self.qualityItem = nil
  408. end
  409. end
  410. return this