KLShapeShiftCardUnLockPanel.lua 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. ---@class KLShapeShiftCardUnLockPanel:UIKmlLuaPanelBase
  2. ---@field view KLShapeShiftCardUnLockPanelView
  3. local KLShapeShiftCardUnLockPanel = class(UIKmlLuaPanelBase)
  4. local this = KLShapeShiftCardUnLockPanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self.upgradeType = 1
  10. end
  11. ---注册UI事件和服务器消息
  12. function this:RegistEvents()
  13. GUI:AddOnClickEvent(self.view.btn_close, self, self.CloseSelf)
  14. --GUI:SetToggleOnValueChange(self.view.toggle_first, self, self.FirstToggleOnChange)
  15. --GUI:SetToggleOnValueChange(self.view.toggle_second, self, self.SecondToggleOnChange)
  16. GUI:AddOnClickEvent(self.view.btn_first_add, self, self.BuyTokens, 1)
  17. GUI:AddOnClickEvent(self.view.btn_second_add, self, self.BuyTokens, 2)
  18. GUI:AddOnClickEvent(self.view.btn_open, self, self.UnlockCardGrid)
  19. GUI:AddOnClickEvent(self.view.btn_help, self, self.FuncHelp)
  20. GUI:AddOnClickEvent(self.view.item_first, self, self.BtnTipsOnClick)
  21. end
  22. ---界面显示时调用一次
  23. function this:Show()
  24. --GUI:UIPanel_Open("dev/outui/ShapeShiftCard/Panel/KLShapeShiftCardUnLock/KLShapeShiftCardUnLockPanel")
  25. end
  26. ---创建或者刷新界面数据时调用
  27. function this:Refresh()
  28. ---@type cfg_card_inlay_column
  29. local cfg_card_inlay = SL:GetConfig("cfg_card_inlay", self.args.part)
  30. if cfg_card_inlay.holeAmount == #cfg_card_inlay.unlockFree then
  31. self.canUnlock = false
  32. ---@type cfg_card_inlay_column
  33. local cfg = SL:GetConfig("cfg_card_inlay", self.args.part)
  34. local rank = InfoManager.shapeShiftCardInfo:GetEquipRankByPart(self.args.part)
  35. local needRank
  36. for _, v in ipairs(cfg.unlockParameter) do
  37. if self.args.index == v[1] then
  38. needRank = v[2]
  39. if rank >= v[2] then
  40. self.canUnlock = true
  41. end
  42. end
  43. end
  44. if cfg.unlockType == 1 then
  45. local text
  46. if self.canUnlock then
  47. text = "<color=#1ADD1F>当前品阶" .. rank .. "</color>"
  48. else
  49. text = "<color=#FF2323>当前品阶" .. rank .. "</color>"
  50. end
  51. GUI:Text_setString(self.view.text_rank, text .. "/所需品阶" .. needRank)
  52. GUI:Text_setString(self.view.text_tips, "穿戴装备品阶")
  53. self.stringId = 20003
  54. else
  55. local text
  56. if self.canUnlock then
  57. text = "<color=#1ADD1F>当前等级" .. rank .. "</color>"
  58. else
  59. text = "<color=#FF2323>当前等级" .. rank .. "</color>"
  60. end
  61. GUI:Text_setString(self.view.text_rank, text .. "/所需等级" .. needRank)
  62. GUI:Text_setString(self.view.text_tips, "穿戴首饰等级")
  63. self.stringId = 500
  64. end
  65. else
  66. self.costNormalId = cfg_card_inlay.unlockNormal[self.args.index - 1][2]
  67. self.costNormalCost = cfg_card_inlay.unlockNormal[self.args.index - 1][3]
  68. local costNormalLuck = cfg_card_inlay.unlockNormal[self.args.index - 1][4]
  69. if #cfg_card_inlay.unlockSpecial > 0 then
  70. self.costSpecialId = cfg_card_inlay.unlockSpecial[self.args.index - 1][2]
  71. self.costSpecialCost = cfg_card_inlay.unlockSpecial[self.args.index - 1][3]
  72. GUI:setVisible(self.view.img_second, true)
  73. else
  74. GUI:setVisible(self.view.img_second, false)
  75. end
  76. GUI:Text_setString(self.view.text_first_success, math.floor(costNormalLuck / 100) .. "%")
  77. GUI:Item_setItemId(self.view.item_first, self.costNormalId)
  78. local normalHave = SL:GetBagItemCount(self.costNormalId)
  79. if normalHave < self.costNormalCost then
  80. normalHave = "<color=#FF2323>" .. normalHave .. "</color>"
  81. else
  82. normalHave = "<color=#1ADD1F>" .. normalHave .. "</color>"
  83. end
  84. GUI:Text_setString(self.view.text_first_cost, normalHave .. "/" .. self.costNormalCost)
  85. if self.costSpecialId then
  86. GUI:Item_setItemId(self.view.item_second, self.costSpecialId)
  87. local specialHave = SL:GetBagItemCount(self.costSpecialId)
  88. if specialHave < self.costSpecialCost then
  89. specialHave = "<color=#FF2323>" .. specialHave .. "</color>"
  90. else
  91. specialHave = "<color=#1ADD1F>" .. specialHave .. "</color>"
  92. end
  93. GUI:Text_setString(self.view.text_second_cost, specialHave .. "/" .. self.costSpecialCost)
  94. end
  95. end
  96. --GUI:Text_setString(self.view.text_bar_value, self.args.info.luck .. "/100")
  97. --GUI:SetLoadingbar_startper(self.view.loadingbar_value, self.args.info.luck)
  98. end
  99. function this:FirstToggleOnChange(_, _, eventData)
  100. if eventData[1] then
  101. self.upgradeType = 1
  102. end
  103. end
  104. function this:SecondToggleOnChange(_, _, eventData)
  105. if eventData[1] then
  106. self.upgradeType = 2
  107. end
  108. end
  109. function this:BuyTokens(_, eventData)
  110. if eventData == 1 then
  111. SL:CommonItemGetPath(nil, self.costNormalId, nil, nil, self)
  112. elseif eventData == 2 then
  113. SL:CommonItemGetPath(nil, self.costSpecialId, nil, nil, self)
  114. end
  115. end
  116. function this:UnlockCardGrid()
  117. if self.canUnlock then
  118. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_TRANSFER_CARD_UNLOCK, { self.args.part, self.args.index, self.upgradeType })
  119. self:CloseSelf()
  120. else
  121. --if self.upgradeType == 1 then
  122. -- if self.costNormalCost > SL:GetBagItemCount(self.costNormalId) then
  123. -- SL:TipMessage({ SL:GetConfig('cfg_string',437).text,1, NoticeType.NoticeMid }) --材料不足,无法开启
  124. -- return
  125. -- end
  126. --else
  127. -- if self.costSpecialCost > SL:GetBagItemCount(self.costSpecialId) then
  128. -- SL:TipMessage({ SL:GetConfig('cfg_string',437).text,1, NoticeType.NoticeMid }) --材料不足,无法开启
  129. -- return
  130. -- end
  131. --end
  132. SL:TipMessage(SL:GetConfig('cfg_string', self.stringId).text, 1, NoticeType.NoticeMid) --材料不足,无法开启
  133. end
  134. end
  135. function this:FuncHelp()
  136. local helpCfg = SL:GetConfig("cfg_rule_text", 104)
  137. if helpCfg then
  138. SL:CommonStrTipsMessage({ title = helpCfg.menutxt, str = helpCfg.location })
  139. end
  140. end
  141. function this:BtnTipsOnClick()
  142. SL:OpenTips(nil, self.costNormalId)
  143. end
  144. function this:CloseSelf()
  145. GUI:UIPanel_Close("dev/outui/ShapeShiftCard/Panel/KLShapeShiftCardUnLock/KLShapeShiftCardUnLockPanel")
  146. end
  147. function this:Close()
  148. end
  149. return this