KLDepotsPanel.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. ---@class KLDepotsPanel:UIKmlLuaPanelBase
  2. ---@field view KLDepotsPanelView
  3. ---@field CurPage number
  4. local KLDepotsPanel = class(UIKmlLuaPanelBase)
  5. local this = KLDepotsPanel
  6. ---创建时调用一次
  7. function this:Init()
  8. ---@type KLDepotsSelectItem[]
  9. self.KLDepotsSelectItemList = {}
  10. this.curSelectTemp = nil
  11. this.storeText = self.view.storeText
  12. this.UnLockGridPage = 0
  13. local cfg = string.split(SL:GetConfig("cfg_global", 8).value, '|')
  14. this.privilegeDepots_info = {}
  15. for i, v in ipairs(cfg) do
  16. this.privilegeDepots_info[#this.privilegeDepots_info + 1] = string.split(v, '#')
  17. end
  18. this.maxPrivilegePages = #this.privilegeDepots_info
  19. this.unlockPrivilegePages = PrivilegeCardManager.GetDepotUp()
  20. this.LockList = {}
  21. ---初始化数据
  22. local itemList = SL:GetMetaValue("STORAGE_DATA", 1)
  23. local forbidCount = SL:GetMetaValue("STORAGE_FORBID_COUNT", 1)
  24. self.Depots_info = string.split(SL:GetConfig("cfg_global", 7).value, '|')
  25. for _, v in pairs(self.Depots_info) do
  26. local info = string.split(v, '#')
  27. if info[4] == "0" then
  28. this.UnLockGridPage = this.UnLockGridPage + 1
  29. end
  30. this.LockList[tonumber(info[3])] = info
  31. end
  32. this.maxDepotsPages = #self.Depots_info
  33. if SL:GetMetaValue("GET_STORAGE_MAX_PAGE") ~= 1 then
  34. this.UnLockGridPage = SL:GetMetaValue("GET_STORAGE_MAX_PAGE")
  35. end
  36. ---@type KLUIBagTileScrollViewItem
  37. GUI:UIPanel_Open("dev/ui/Common/Item/KLUIBagTileScrollView/KLUIBagTileScrollViewItem",
  38. self.view.root, self, { itemList = itemList, id = EBagTileScrollViewId.Storage, forbidCount = forbidCount,
  39. hor = tonumber(this.LockList[1][1]), vet = tonumber(this.LockList[1][2]), forbidClickCallback = self.forbidClick, x = -4, y = -45, page = 1,
  40. dragEndCallback = self.dragEnd, parent = self },nil,function(panel)
  41. this.StoreBagUI = panel
  42. GUI:setContentSize(panel.view.BagTileScrollViewPrefab, 365, 495)
  43. GUI:setPosition(panel.view.BagTileScrollViewPrefab, 36, -91)
  44. GUI:setContentSize(panel.view.prefabBagTileScrollView_, 365, 495)
  45. end)
  46. GUI:SetActive(self.view.edit_panel, false)
  47. GUI:SetActive(self.view.forbid_red_panel, false)
  48. this.bagType = "depots"
  49. end
  50. function this:forbidClick(_, _, eventData)
  51. if this.bagType == "privilege" then
  52. SL:TipMessage( "未开放", 1, NoticeType.NoticeMid )
  53. return
  54. end
  55. local bag_unlock_info = SL:GetConfig('cfg_global', 159).value
  56. local bag_unlock_split = string.split(bag_unlock_info, '#')
  57. local itemId = tonumber(bag_unlock_split[1])
  58. local needCount = tonumber(bag_unlock_split[2])
  59. local addCount = tonumber(bag_unlock_split[3])
  60. local maxAddCount = tonumber(bag_unlock_split[4])
  61. local itemName = SL:GetConfig("cfg_item", itemId).name
  62. SL:CommonTipsMessage({ stringTblID = 206, stringTblFormat={itemName, addCount}, ui = self,
  63. cfgId = itemId,
  64. needCount = needCount,
  65. callback = self.UnlockGrid, callbackData = needCount })
  66. end
  67. function this:UnlockGrid()
  68. return SL:ReqStoreAddCapacityMessage(1, this.CurPage)
  69. end
  70. ---创建或者刷新界面数据时调用
  71. function this:Refresh()
  72. local x = 0
  73. local y = 0
  74. if self.args then
  75. x = self.args.x or -400
  76. y = self.args.y or 0
  77. else
  78. SL:HideMainPanel()
  79. end
  80. GUI:setPosition(self.view.root, x, y)
  81. for i, v in pairs(self.Depots_info) do
  82. ---@type KLDepotsSelectItem
  83. local item = GUI:UIPanel_Open("dev/ui/Bag/Item/KLDepotsSelect/KLDepotsSelectItem", self.view.ItemContent, self, nil, true)
  84. item:SetClickDelegate(self.ButtonSelectOnClick, i)
  85. table.insert(self.KLDepotsSelectItemList, item)
  86. end
  87. this.CurPage = 1
  88. self:SetPageBtnSelect(this.CurPage)
  89. end
  90. ----刷新仓库数据
  91. function this:RefreshPageUI(page)
  92. if this.bagType == "privilege" then
  93. local itemList = SL:GetMetaValue("STORAGE_DATA", page + this.maxDepotsPages)
  94. local hor = tonumber(this.privilegeDepots_info[page][1])
  95. local vet = tonumber(this.privilegeDepots_info[page][2])
  96. local forbidCount = 0
  97. this.StoreBagUI.itemList = itemList
  98. this.StoreBagUI.forbidCount = forbidCount
  99. this.StoreBagUI.hor = hor
  100. this.StoreBagUI.vet = vet
  101. this.StoreBagUI.id = EBagTileScrollViewId.Storage
  102. this.StoreBagUI.page = this.CurPage
  103. this.StoreBagUI:ClearBagItem()
  104. this.StoreBagUI:Refresh()
  105. else
  106. local itemList = SL:GetMetaValue("STORAGE_DATA", page)
  107. local forbidCount = SL:GetMetaValue("STORAGE_FORBID_COUNT", page)
  108. local hor = tonumber(this.LockList[page][1])
  109. local vet = tonumber(this.LockList[page][2])
  110. this.StoreBagUI.itemList = itemList
  111. this.StoreBagUI.forbidCount = forbidCount
  112. this.StoreBagUI.hor = hor
  113. this.StoreBagUI.vet = vet
  114. this.StoreBagUI.id = EBagTileScrollViewId.Storage
  115. this.StoreBagUI.page = this.CurPage
  116. this.StoreBagUI:ClearBagItem()
  117. this.StoreBagUI:Refresh()
  118. end
  119. GUI:setContentSize(this.StoreBagUI.view.BagTileScrollViewPrefab, 365, 495)
  120. GUI:setPosition(this.StoreBagUI.view.BagTileScrollViewPrefab, 36, -91)
  121. GUI:setContentSize(this.StoreBagUI.view.prefabBagTileScrollView_, 365, 495)
  122. end
  123. function this:ButtonSelectOnClick(SelectTemp, index, needRefresh)
  124. local depotsName = ""
  125. if this.bagType == "privilege" then
  126. depotsName = "privilege_storage_Name"
  127. elseif this.bagType == "depots" then
  128. depotsName = "storage_Name"
  129. end
  130. if this.bagType == "depots" and index > this.UnLockGridPage then
  131. local bag_unlock_info = SL:GetConfig('cfg_global', 195).value
  132. local bag_unlock_split = string.split(bag_unlock_info, '#')
  133. local itemId = tonumber(bag_unlock_split[1])
  134. local needCount = tonumber(bag_unlock_split[2])
  135. local addPage = tonumber(bag_unlock_split[3])
  136. local itemName = SL:GetConfig("cfg_item", itemId).name
  137. SL:CommonTipsMessage({stringTblID=206, stringTblFormat={tostring(itemName), tostring(addPage)},
  138. ui = self,
  139. cfgId = itemId,
  140. needCount = needCount,
  141. callback = self.UnlockPage, callbackData = needCount })
  142. return
  143. end
  144. if this.bagType == "privilege" then
  145. if index > this.unlockPrivilegePages then
  146. if this.lockButShowMaxPage and index <= this.lockButShowMaxPage then
  147. GUI:setVisible(self.view.forbid_red_panel, true)
  148. else
  149. SL:TipMessage( "未开放!", 1, NoticeType.NoticeMid )
  150. return
  151. end
  152. else
  153. GUI:setVisible(self.view.forbid_red_panel,false)
  154. end
  155. end
  156. if index ~= this.CurPage or needRefresh then
  157. this:RefreshPageUI(index)
  158. end
  159. this.CurPage = index
  160. SL:SetMetaValue(EMetaVarSetKey.SET_STORAGE_CURPAGE,this.CurPage)
  161. if SL:MeData_Check() then
  162. if self.bagType == "depots" then
  163. local name = PlayerPrefs.GetString(SL:GetMetaValue(EMetaVarGetKey.UID) .. depotsName .. this.CurPage, "仓库" .. index)
  164. GUI:Text_setString(this.storeText, name)
  165. elseif self.bagType == "privilege" then
  166. local name = PlayerPrefs.GetString(SL:GetMetaValue(EMetaVarGetKey.UID) .. depotsName .. this.CurPage, "特权仓库" .. index)
  167. GUI:Text_setString(this.storeText, name)
  168. end
  169. else
  170. GUI:Text_setString(this.storeText, "仓库" .. index)
  171. end
  172. if this.curSelectTemp then
  173. GUI:SetActive(this.curSelectTemp.view.DotRed, false)
  174. end
  175. GUI:SetActive(SelectTemp.view.DotRed, true)
  176. this.curSelectTemp = SelectTemp
  177. end
  178. ---仓库页数
  179. ---@param index number @第几页
  180. function this:SetPageBtnSelect(index, needRefresh)
  181. for i, v in pairs(self.KLDepotsSelectItemList) do
  182. if i == index then
  183. self:ButtonSelectOnClick(v, index, needRefresh)
  184. end
  185. end
  186. end
  187. ---注册UI事件和服务器消息
  188. function this:RegistEvents()
  189. GUI:AddOnClickEvent(self.view.closeBtn, self, self.closeBtn)
  190. GUI:AddOnClickEvent(self.view.pageLeft_btn, self, self.pageLeft_btn)
  191. GUI:AddOnClickEvent(self.view.pageRight_btn, self, self.pageRight_btn)
  192. GUI:AddOnClickEvent(self.view.add_btn, self, self.add_btn)
  193. GUI:AddOnClickEvent(self.view.tidy_btn, self, self.tidy_btn)
  194. GUI:AddOnClickEvent(self.view.priv_btn, self, self.priv_btn)
  195. GUI:AddOnClickEvent(self.view.storage_btn, self, self.storage_btn)
  196. GUI:AddOnClickEvent(self.view.edit_btn, self, self.edit_btn)
  197. GUI:AddOnClickEvent(self.view.edit_CloseBtn, self, self.edit_CloseBtn)
  198. GUI:AddOnClickEvent(self.view.edit_Cancel, self, self.edit_CloseBtn)
  199. GUI:AddOnClickEvent(self.view.edit_Enter, self, self.edit_Enter)
  200. SL:RegisterLUAEvent(LUA_EVENT_STORAGE_UNLOCK, self.RefreshPageUIChange, self)
  201. SL:RegisterLUAEvent(LUA_EVENT_STORE_HOUSE_INFO_CHANGE, self.RefreshPageUIChange, self)
  202. SL:RegisterLUAEvent(LUA_EVENT_STORE_HOUSE_PAGE, self.LUA_EVENT_STORE_HOUSE_PAGE, self)
  203. GUI:Input_SetOnValueChange(self.view.store_Name_Input, self, self.Input_SetOnValueChange)
  204. end
  205. function this:Input_SetOnValueChange()
  206. local textName = GUI:GetInputText(self.view.store_Name_Input)
  207. if string.isNullOrEmpty(textName) then
  208. return
  209. elseif string.find(textName, "%s") ~= nil then
  210. SL:TipMessage(SL:GetConfig('cfg_string',276).text, 1, NoticeType.NoticeMid )--"名称中不能包含空格",
  211. elseif self:GetStrLen(textName) >= 10 then
  212. SL:TipMessage( SL:GetConfig('cfg_string',277).text, 1, NoticeType.NoticeMid )--"名称过长",
  213. GUI:SetInputText(self.view.store_Name_Input, "")
  214. end
  215. end
  216. function this:add_btn()
  217. local bag_unlock_info = SL:GetConfig('cfg_global', 195).value
  218. local bag_unlock_split = string.split(bag_unlock_info, '#')
  219. local itemId = tonumber(bag_unlock_split[1])
  220. local needCount = tonumber(bag_unlock_split[2])
  221. local addPage = tonumber(bag_unlock_split[3])
  222. local itemName = SL:GetConfig("cfg_item", itemId).name
  223. SL:CommonTipsMessage({stringTblID=206, stringTblFormat={tostring(itemName), tostring(addPage)},
  224. ui = self,
  225. cfgId = itemId,
  226. needCount = needCount,
  227. callback = self.UnlockPage, callbackData = needCount })
  228. --[[ GUI:UIPanel_Open("dev/ui/Common/Panel/KLCommonItemTips/KLCommonItemTipsPanel", nil, nil,
  229. { showTips = string.format("是否消耗%s扩充%s页仓库?", itemName, addPage), ui = self,
  230. cfgId = itemId,
  231. needCount = needCount,
  232. callback = self.UnlockPage, callbackData = needCount })]]
  233. end
  234. function this:UnlockPage()
  235. return SL:ReqStoreAddPageMessage(1)
  236. end
  237. function this:LUA_EVENT_STORE_HOUSE_PAGE(_, maxPage)
  238. if this.UnLockGridPage ~= maxPage then
  239. this.UnLockGridPage = maxPage
  240. self:SetPageBtnSelect(maxPage)
  241. end
  242. end
  243. function this:RefreshPageUIChange()
  244. this:RefreshPageUI(this.CurPage)
  245. end
  246. function this:tidy_btn()
  247. return SL:ReqTidyStoreItemMessage(this.CurPage)
  248. end
  249. function this:priv_btn()
  250. --if this.unlockPrivilegePages == 0 then
  251. self:CheckPrivilegeDepotsHaveItem()
  252. if this.lockButShowMaxPage == 0 then
  253. if not PrivilegeCardManager.goldPrivilege and not PrivilegeCardManager.diamondPrivilege then
  254. SL:TipMessage( "请先解锁特权", 1, NoticeType.NoticeMid )
  255. return
  256. end
  257. end
  258. GUI:setVisible(self.view.priv_btn, false)
  259. GUI:setVisible(self.view.add_btn, false)
  260. GUI:setVisible(self.view.storage_btn, true)
  261. this.bagType = "privilege"
  262. this.CurPage = 1
  263. self:RefreshSelectItemList(this.maxPrivilegePages)
  264. self:SetPageBtnSelect(this.CurPage, true)
  265. end
  266. function this:CheckPrivilegeDepotsHaveItem()
  267. this.lockButShowMaxPage = 0
  268. for i = this.unlockPrivilegePages + 1, this.maxPrivilegePages do
  269. local item = SL:GetMetaValue("STORAGE_DATA", i + this.maxDepotsPages)
  270. if item and next(item) then
  271. this.lockButShowMaxPage = i
  272. end
  273. end
  274. end
  275. function this:storage_btn()
  276. GUI:setVisible(self.view.forbid_red_panel, false)
  277. GUI:setVisible(self.view.priv_btn, true)
  278. GUI:setVisible(self.view.add_btn, true)
  279. GUI:setVisible(self.view.storage_btn, false)
  280. this.bagType = "depots"
  281. this.CurPage = 1
  282. self:RefreshSelectItemList(#self.Depots_info)
  283. self:SetPageBtnSelect(this.CurPage, true)
  284. end
  285. function this:RefreshSelectItemList(num)
  286. if #self.KLDepotsSelectItemList > num then
  287. for i = num + 1, #self.KLDepotsSelectItemList do
  288. GUI:UIPanel_Close(nil, self.KLDepotsSelectItemList[i])
  289. self.KLDepotsSelectItemList[i] = nil
  290. end
  291. elseif #self.KLDepotsSelectItemList < num then
  292. for i = #self.KLDepotsSelectItemList + 1, num do
  293. ---@type KLDepotsSelectItem
  294. local item = GUI:UIPanel_Open("dev/ui/Bag/Item/KLDepotsSelect/KLDepotsSelectItem", self.view.ItemContent, self, nil, true)
  295. item:SetClickDelegate(self.ButtonSelectOnClick, i)
  296. table.insert(self.KLDepotsSelectItemList, item)
  297. end
  298. end
  299. end
  300. function this:edit_Enter()
  301. local depotsName = ""
  302. if this.bagType == "privilege" then
  303. depotsName = "privilege_storage_Name"
  304. elseif this.bagType == "depots" then
  305. depotsName = "storage_Name"
  306. end
  307. local textName = GUI:GetInputText(self.view.store_Name_Input)
  308. if string.isNullOrEmpty(textName) then
  309. SL:TipMessage( SL:GetConfig('cfg_string',275).text, 1, NoticeType.NoticeMid )--"名称不能为空",
  310. elseif string.find(textName, "%s") ~= nil then
  311. SL:TipMessage( SL:GetConfig('cfg_string',276).text, 1, NoticeType.NoticeMid )--"名称中不能包含空格",
  312. elseif self:GetStrLen(textName) >= 10 then
  313. SL:TipMessage( SL:GetConfig('cfg_string',277).text, 1, NoticeType.NoticeMid )--"名称过长",
  314. else
  315. GUI:SetActive(self.view.edit_panel, false)
  316. GUI:Text_setString(self.view.storeText, textName)
  317. if SL:MeData_Check() then
  318. PlayerPrefs.SetString(SL:GetMetaValue(EMetaVarGetKey.UID) .. depotsName .. this.CurPage, textName)
  319. end
  320. end
  321. end
  322. function this:edit_btn()
  323. GUI:SetActive(self.view.edit_panel, true)
  324. GUI:Text_setString(self.view.old_Store_Name, "仓库" .. this.CurPage)
  325. end
  326. function this:edit_CloseBtn()
  327. GUI:SetActive(self.view.edit_panel, false)
  328. end
  329. function this:pageLeft_btn()
  330. if this.CurPage - 1 >= 1 then
  331. self:SetPageBtnSelect(this.CurPage - 1)
  332. end
  333. end
  334. function this:pageRight_btn()
  335. if this.bagType == "depots" then
  336. if this.CurPage + 1 <= self.UnLockGridPage then
  337. self:SetPageBtnSelect(this.CurPage + 1)
  338. else
  339. if this.CurPage == #self.Depots_info then
  340. SL:TipMessage( "扩容已达上限", 1, NoticeType.NoticeMid )
  341. return
  342. end
  343. local bag_unlock_info = SL:GetConfig('cfg_global', 195).value
  344. local bag_unlock_split = string.split(bag_unlock_info, '#')
  345. local itemId = tonumber(bag_unlock_split[1])
  346. local needCount = tonumber(bag_unlock_split[2])
  347. local addPage = tonumber(bag_unlock_split[3])
  348. local itemName = SL:GetConfig("cfg_item", itemId).name
  349. SL:CommonTipsMessage({stringTblID=206, stringTblFormat={tostring(itemName), tostring(addPage)},
  350. ui = self,
  351. cfgId = itemId,
  352. needCount = needCount,
  353. callback = self.UnlockPage, callbackData = needCount })
  354. end
  355. elseif this.bagType == "privilege" then
  356. if this.CurPage + 1 <= this.unlockPrivilegePages then
  357. self:SetPageBtnSelect(this.CurPage + 1)
  358. else
  359. if this.CurPage + 1 <= this.lockButShowMaxPage then
  360. self:SetPageBtnSelect(this.CurPage + 1)
  361. else
  362. SL:TipMessage( "未开放", 1, NoticeType.NoticeMid )
  363. end
  364. end
  365. end
  366. end
  367. function this:closeBtn()
  368. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel")
  369. end
  370. function this:Close()
  371. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  372. SL:ShowMainPanel()
  373. end
  374. function this:dragEnd(eventData)
  375. local bagHor = eventData.bagPutHor
  376. local bagVet = eventData.bagPutVet
  377. local raycastObj = eventData.raycastObj
  378. local dragItem = eventData.dragItem
  379. local storageHor = eventData.storageHor
  380. local storageVet = eventData.storageVet
  381. -- 丢弃道具
  382. if raycastObj == nil then
  383. local canDrop = self:GetItemCanDrop(dragItem)
  384. if canDrop then
  385. local article = SL:GetConfig('cfg_item', dragItem.item.cfgId).article
  386. local name = SL:GetConfig('cfg_item', dragItem.item.cfgId).name
  387. local isDestroy = table.contains(article, 3)
  388. if isDestroy then
  389. GUI:UIPanel_Open("dev/ui/Common/Panel/KLUICommonTips/KLUICommonTipsPanel", nil, nil, { showTips = string.format("是否摧毁%s", name), callback = self.DropItem, callbackData = { item = dragItem.item }, ui = self })
  390. else
  391. GUI:UIPanel_Open("dev/ui/Common/Panel/KLUICommonTips/KLUICommonTipsPanel", nil, nil, { showTips = string.format("是否丢弃%s", name), callback = self.DropItem, callbackData = { item = dragItem.item }, ui = self })
  392. end
  393. else
  394. SL:TipMessage( "该道具不可被丢弃", 1, NoticeType.NoticeMid )
  395. end
  396. return
  397. end
  398. local bagMaxHor, bagMaxVet = SL:GetMetaValue(EMetaVarGetKey.GET_BAG_MAX_HOR_VERT)
  399. if bagHor <= bagMaxHor and bagHor > 0 and bagVet <= bagMaxVet and bagVet > 0 then
  400. ---@type CommonProtos.Item
  401. --local dragItem = eventData.dragItem
  402. local oldIndex = eventData.index
  403. local newIndex = SL.Bag:GetIndexWithPageHorAndVet(1, bagHor, bagVet)
  404. if self.bagType == "privilege" then
  405. SL:ReqStoreToBagMessage((this.CurPage + this.maxDepotsPages) * 10000 + oldIndex, newIndex)
  406. elseif self.bagType == "depots" then
  407. SL:ReqStoreToBagMessage(this.CurPage * 10000 + oldIndex, newIndex)
  408. end
  409. else
  410. --local maxHor, maxVet = RoleManager.meData.storeHouseInfo:GetMaxHorAndVet()
  411. local maxHor,maxVet = SL:GetMetaValue(EMetaVarGetKey.GET_STORE_HOUSE_MAX_HV)
  412. if storageHor and storageHor <= maxHor and storageHor > 0 and storageVet <= maxVet and storageVet > 0 then
  413. local oldIndex = eventData.index
  414. if self.bagType == "privilege" then
  415. local newIndex = SL.StoreHouse:GetIndexWithPageHorAndVet(this.CurPage + this.maxDepotsPages, storageHor, storageVet)
  416. SL:ReqSwapStoreItemMessage((this.CurPage + this.maxDepotsPages) * 10000 + oldIndex, newIndex)
  417. elseif self.bagType == "depots" then
  418. local newIndex = SL.StoreHouse:GetIndexWithPageHorAndVet(this.CurPage, storageHor, storageVet)
  419. SL:ReqSwapStoreItemMessage(this.CurPage * 10000 + oldIndex, newIndex)
  420. end
  421. end
  422. end
  423. end
  424. ---@param item KLBagItemItem
  425. function this:GetItemCanDrop(item)
  426. local article = SL:GetConfig('cfg_item', item.item.cfgId).article
  427. local cantDrop = table.contains(article, 2)
  428. if cantDrop then
  429. return false
  430. end
  431. return not item.item.bind
  432. end
  433. function this:DropItem(callbackData)
  434. local item = callbackData.item
  435. --local index = RoleManager.meData.storeHouseInfo:GetIndexBaseOnItemId(item.id)
  436. local index = SL:GetDepotsIndex(item.id)
  437. if index then
  438. SL:ReqStoreGiveUpItemMessage(index)
  439. end
  440. end
  441. function this:GetStrLen(inputstr)
  442. if not inputstr or type(inputstr) ~= "string" or #inputstr <= 0 then
  443. return nil
  444. end
  445. local length = 0 -- 字符的个数
  446. local i = 1
  447. while true do
  448. local lengthCount = 1
  449. local curByte = string.byte(inputstr, i)
  450. local byteCount = 1
  451. if curByte > 239 then
  452. byteCount = 4 -- 4字节字符
  453. lengthCount = 2
  454. elseif curByte > 223 then
  455. lengthCount = 2
  456. byteCount = 3 -- 汉字
  457. elseif curByte > 128 then
  458. byteCount = 2 -- 双字节字符
  459. else
  460. byteCount = 1 -- 单字节字符
  461. end
  462. i = i + byteCount
  463. length = length + lengthCount
  464. if i > #inputstr then
  465. break
  466. end
  467. end
  468. return length
  469. end
  470. return this