KLFastItem.lua 9.9 KB

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