KLFastItem.lua 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. ---@class KLFastItem:UIKmlLuaPanelBase
  2. ---@field view KLFastItemView
  3. local KLFastItem = class(UIKmlLuaPanelBase)
  4. local this = KLFastItem
  5. ---创建时调用一次
  6. function this:Init()
  7. end
  8. ---创建或者刷新界面数据时调用
  9. function this:RefreshItem(args)
  10. self.args = args
  11. self.cdTime = 0
  12. ---@type number[]
  13. local fastItems = SL:GetMetaValue(EMetaVarGetKey.FAST_ITEM_ID_LIST)
  14. if self.args.itemIndex == 1 then
  15. if SL:HasConfig("cfg_item",fastItems[1]) then
  16. local ownerCount = SL:GetBagItemCount(fastItems[1])
  17. if ownerCount <=0 then
  18. self.args.cfgId = 30010022
  19. end
  20. else
  21. self.args.cfgId = 30010022
  22. end
  23. end
  24. if self.args.itemIndex == 2 then
  25. if SL:HasConfig("cfg_item",fastItems[2]) then
  26. local ownerCount = SL:GetBagItemCount(fastItems[2])
  27. if ownerCount <=0 then
  28. self.args.cfgId = 30010011
  29. end
  30. else
  31. self.args.cfgId = 30010011
  32. end
  33. end
  34. if self.args.cfgId ~= 0 and fastItems[self.args.itemIndex] == self.args.cfgId then
  35. local tbl = SL:GetConfig("cfg_item", self.args.cfgId)
  36. if tbl and #tbl.coolingTime > 0 then
  37. self.cdTime = tbl.coolingTime[1]/1000
  38. end
  39. end
  40. if self.args.cfgId ~= 0 and fastItems[self.args.itemIndex] == self.args.cfgId then
  41. self.args.count = SL:GetBagItemCount(self.args.cfgId)
  42. else
  43. self.args.count = 0
  44. end
  45. if self.args.cfgId ~= 0 and self.args.count == 0 and fastItems[self.args.itemIndex] == self.args.cfgId then
  46. self.args.cfdId = 0
  47. SL:SetMetaValue(EMetaVarGetKey.FAST_ITEM_ID_LIST,self.args.itemIndex,0,0)
  48. end
  49. if self.args.cfdId == 0 or self.args.count == 0 then
  50. GUI:setVisible(self.view.add_img_0,true)
  51. GUI:setVisible(self.view.add_img_0,true)
  52. GUI:SetCirclebar_startper(self.view.control_circlebar,0)
  53. if self.args.cfgId ~= 0 and fastItems[self.args.itemIndex] ~= self.args.cfgId then
  54. GUI:Item_setItemId(self.view.shortcut_item,self.args.cfgId)
  55. GUI:Item_UpdataData(self.view.shortcut_item,{itemcount=0})
  56. end
  57. GUI:setVisible(self.view.shortcut_item,self.args.cfgId ~= 0 and fastItems[self.args.itemIndex] ~= self.args.cfgId)
  58. local isShowNoItem = false
  59. if self.args.itemIndex <= 2 then
  60. if SL:HasConfig("cfg_item",fastItems[2]) then
  61. local ownerCount = SL:GetBagItemCount(fastItems[2])
  62. if ownerCount <=0 then
  63. isShowNoItem = true
  64. end
  65. else
  66. isShowNoItem = true
  67. end
  68. end
  69. if self.args.itemIndex == 1 then
  70. if not isShowNoItem then
  71. if SL:HasConfig("cfg_item",fastItems[1]) then
  72. local ownerCount = SL:GetBagItemCount(fastItems[1])
  73. if ownerCount <=0 then
  74. isShowNoItem = true
  75. end
  76. else
  77. isShowNoItem = true
  78. end
  79. else
  80. isShowNoItem = false
  81. end
  82. end
  83. GUI:setVisible(self.view.noItem,self.args.cfgId ~= 0 and fastItems[self.args.itemIndex] ~= self.args.cfgId)
  84. GUI:setVisible(self.view.fastItemTip,self.args.cfgId ~= 0 and fastItems[self.args.itemIndex] ~= self.args.cfgId and isShowNoItem)
  85. GUI:SetCirclebar_endper(self.view.control_circlebar,0)
  86. if self.args.cfgId ~= 0 and fastItems[self.args.itemIndex] ~= self.args.cfgId and isShowNoItem then
  87. SL:onLUAEvent(LUA_EVENT_BUBBLETIPS_POSY,{posY = 40})
  88. end
  89. else
  90. GUI:setVisible(self.view.shortcut_item,true)
  91. GUI:setVisible(self.view.add_img_0,false)
  92. GUI:Item_setItemId(self.view.shortcut_item,self.args.cfgId)
  93. GUI:Item_UpdataData(self.view.shortcut_item,{itemcount=self.args.count})
  94. GUI:setVisible(self.view.noItem,false)
  95. end
  96. if fastItems[1] > 0 and fastItems[2] > 0 then
  97. SL:onLUAEvent(LUA_EVENT_BUBBLETIPS_POSY,{posY = 0})
  98. end
  99. end
  100. ---注册UI事件和服务器消息
  101. function this:RegistEvents()
  102. --SL:RegisterLuaNetMsg(MessageDef.ResBagChangeMessage, self.ResBagChangeMessage,self)
  103. SL:RegisterLUAEvent(LUA_EVENT_FASTITEM_CHANGE, self.BagChange, self)--背包改变事件
  104. SL:RegisterLUAEvent(LUA_EVENT_USE_ITEM_AFTER, self.UseItemAfter, self)--道具使用事件
  105. GUI:AddOnClickEvent(self.view.useBtn,self,self.BtnUseClick)
  106. end
  107. function this:BagChange(id, itemList)
  108. ---@type number[]
  109. local fastItems = SL:GetMetaValue(EMetaVarGetKey.FAST_ITEM_ID_LIST)
  110. if self.args.itemIndex == 1 then
  111. self.args.cfgId = fastItems[1]
  112. end
  113. if self.args.itemIndex == 2 then
  114. self.args.cfgId = fastItems[2]
  115. end
  116. if fastItems[1] > 0 and fastItems[2] > 0 then
  117. SL:onLUAEvent(LUA_EVENT_BUBBLETIPS_POSY,{posY = 0})
  118. end
  119. local count = SL:GetBagItemCount(self.args.cfgId)
  120. if count == self.args.count then
  121. return
  122. end
  123. self.args.count = count
  124. self:RefreshItem(self.args)
  125. end
  126. function this:Close()
  127. if self.timer1 then
  128. SL:UnSchedule(self.timer1)
  129. self.timer1 = nil
  130. end
  131. if self.timer2 then
  132. SL:UnSchedule(self.timer2)
  133. self.timer2 = nil
  134. end
  135. end
  136. function this:UseItemAfter(id, message)
  137. if self.args.cfgId and self.args.cfgId ~= 0 then
  138. local tbl1 = SL:GetConfig("cfg_item", message.cfgId)
  139. if tbl1.type ~= 3 then
  140. return
  141. end
  142. local tbl2 = SL:GetConfig("cfg_item", self.args.cfgId)
  143. local is_one_froup = false
  144. if tbl1.useCdGroup and tbl1.useCdGroup[1] and tbl1.useCdGroup[1][1] and tbl2.useCdGroup and tbl2.useCdGroup[1] and tbl2.useCdGroup[1][1] and tbl1.useCdGroup[1][1] == tbl2.useCdGroup[1][1] then
  145. is_one_froup = true
  146. end
  147. if self.args.cfgId == message.cfgId or is_one_froup then
  148. self.use_time = os.time()
  149. GUI:SetCirclebar_startper(self.view.control_circlebar,100)
  150. GUI:SetCirclebar_endper(self.view.control_circlebar,0)
  151. GUI:SetCirclebar_time(self.view.control_circlebar,self.cdTime)
  152. end
  153. end
  154. end
  155. function this:BtnUseClick()
  156. if not self.use_time then
  157. else
  158. if self.cdTime > 0 and self.use_time + self.cdTime > os.time() then
  159. return
  160. end
  161. end
  162. ---@type number[]
  163. local fastItems = SL:GetMetaValue(EMetaVarGetKey.FAST_ITEM_ID_LIST)
  164. local count = SL:GetBagItemCount(self.args.cfgId)
  165. if self.args.cfgId == 0 or count==0 then
  166. if (self.args.itemIndex == 1 or self.args.itemIndex == 2) and fastItems[self.args.itemIndex] ~= self.args.cfgId then
  167. self:PillNoEnough()
  168. else
  169. SL.HideMainPanel()
  170. GUI:UIPanel_Open("dev/ui/Skill/Panel/KLUISkillSetting/KLUISkillSettingPanel", nil, nil, { settingType = ESkillSettingType.FastItem })
  171. end
  172. elseif fastItems[self.args.itemIndex] == self.args.cfgId then
  173. local index = SL:GetSlotBaseOnCfgId(self.args.cfgId)
  174. self:UseItem(index,1)
  175. end
  176. end
  177. function this:PillNoEnough()
  178. if PrivilegeCardManager.iswithStore() then
  179. self:OpenShop()
  180. else
  181. SL:CommonTipsMessage({ stringTblID = 226, ui = self, sureBtnText = "随身买药", cancelBtnText = "传送", cancelCallBack = self.TransferToNpcShop,
  182. callback = self.OpenFirsh, littleTipsTextTable = { text = "<color='#FFFF00'>激活白银特权卡</color>", x = 100, y = -60 } ,
  183. sureBtnImageData = { src = "button_interface_window6", atlas = "Atlas/Common.spriteatlas" }, cancelBtnImageData = { src = "button_interface_window7", atlas = "Atlas/Common.spriteatlas" },
  184. cancelBtnColor = "#DCE1E5"})
  185. end
  186. end
  187. function this:OpenShop()
  188. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  189. if GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") then
  190. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel")
  191. end
  192. local shop_id = SL:GetMetaValue("GET_NPC_SHOPID", 100101)
  193. SL:OpenNPCShop(shop_id)
  194. end
  195. --- 传送到NPC商店(NPC商店功能)
  196. function this:TransferToNpcShop()
  197. local mapInfo = SL:GetConfig("cfg_map_info", SL:GetMetaValue("MAP_ID"), "id")
  198. if mapInfo.nopositionmove == 1 then
  199. SL:MessageTip({id=116})
  200. return
  201. end
  202. --
  203. if self.timer1 then
  204. SL:UnSchedule(self.timer1)
  205. self.timer1 = nil
  206. end
  207. if self.timer2 then
  208. SL:UnSchedule(self.timer2)
  209. self.timer2 = nil
  210. end
  211. self.timer1 = SL:ScheduleOnce(0.5, function()
  212. SL:SendTransferToNpcMessage(100101, true)
  213. end)
  214. self.timer2 = SL:ScheduleOnce(2, function()
  215. if not GUI:GetUI("dev/ui/NPC/Panel/KLNPCShop/KLNPCShopPanel") then
  216. SL:OpenNPCShop(1)
  217. end
  218. end)
  219. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  220. end
  221. function this:OpenFirsh()
  222. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  223. if GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") then
  224. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel")
  225. end
  226. GUI:UIPanel_Open("dev/outui/ShopMain/Panel/KLShopMain/KLShopMainPanel",nil,nil,{2})
  227. end
  228. function this:UseItem(index, count, notice)
  229. SL:ReqUseItemMessage(index, count, notice)
  230. end
  231. return this