KLEquipUIPanel.lua 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. ---@class KLEquipUIPanel:UIKmlLuaPanelBase
  2. ---@field view KLEquipUIPanelView
  3. ---@field slotToGrid table<number, KLBagItemItem>
  4. ---@field gridData table<number, EEquipGridDefaultData> @<装备位置, EEquipGridDefaultData>
  5. ---@field wearBarItems KLWearBarBtnItem[]
  6. local KLEquipUIPanel = class(UIKmlLuaPanelBase)
  7. local this = KLEquipUIPanel
  8. ---@class ESlotCondition
  9. local ESlotCondition = {
  10. [EEquipSlotType.FashionHelmet] = EEquipSlotType.Helmet,
  11. [EEquipSlotType.FashionArmor] = EEquipSlotType.Armor,
  12. [EEquipSlotType.FashionArmor] = EEquipSlotType.Armor,
  13. [EEquipSlotType.FashionWeapon] = EEquipSlotType.Weapon,
  14. [EEquipSlotType.TwoHandWeapon] = EEquipSlotType.Weapon,
  15. [EEquipSlotType.FashionTwoHandWeapon] = EEquipSlotType.Weapon,
  16. [EEquipSlotType.FashionOffHandWeapon] = EEquipSlotType.OffHandWeapon,
  17. [EEquipSlotType.FashionGlove] = EEquipSlotType.Glove,
  18. [EEquipSlotType.FashionPant] = EEquipSlotType.Pant,
  19. [EEquipSlotType.FashionBoot] = EEquipSlotType.Boot,
  20. [EEquipSlotType.FashionWing] = EEquipSlotType.Wing,
  21. [EEquipSlotType.FashionGuard] = EEquipSlotType.Guard,
  22. [EEquipSlotType.FashionNecklace] = EEquipSlotType.Necklace,
  23. [EEquipSlotType.FashionLeftEarring] = EEquipSlotType.LeftEarring,
  24. [EEquipSlotType.FashionRightEarring] = EEquipSlotType.RightRing,
  25. [EEquipSlotType.FashionLeftRing] = EEquipSlotType.LeftRing,
  26. [EEquipSlotType.FashionRightRing] = EEquipSlotType.RightRing,
  27. [EEquipSlotType.ArchangelTwoHandWeapon] = EEquipSlotType.ArchangelWeapon
  28. }
  29. ---@class EEquipGridDefaultData
  30. ---@field width number @grid的宽度
  31. ---@field height number @grid的高度
  32. ---@field x number @grid的x坐标
  33. ---@field y number @grid的y坐标
  34. ---@field qualityX number @品阶角标x坐标
  35. ---@field qualityY number @品阶角标y坐标
  36. ---@field strengthX number @强化追加x坐标
  37. local jewelryDefaultId = {
  38. [EEquipSlotType.Necklace] = 21000021,
  39. [EEquipSlotType.LeftEarring] = 21200121,
  40. [EEquipSlotType.RightEarring] = 21200121,
  41. [EEquipSlotType.LeftRing] = 21100031,
  42. [EEquipSlotType.RightRing] = 21100031,
  43. }
  44. function this:AsyncLoadUI(...)
  45. SL:LoadUIAssetAsync('UI/UIEquipPanel.prefab', self)
  46. end
  47. function this:Hide()
  48. --for _, wearBarItem in pairs(self.wearBarItems) do
  49. -- GUI:UIPanel_Close(nil, wearBarItem)
  50. --end
  51. --self.wearBarItems = nil
  52. end
  53. ---创建时调用一次
  54. function this:Init()
  55. self.equipSlotTypeList = {}
  56. for i, v in pairs(EEquipSlotType) do
  57. table.insert(self.equipSlotTypeList, { name = i, type = v })
  58. end
  59. table.sort(self.equipSlotTypeList, function(a, b)
  60. return a.type < b.type
  61. end)
  62. if not self.slotToGrid then
  63. self.slotToGrid = {}
  64. else
  65. ---初始化红点为隐藏
  66. for i, v in pairs(self.slotToGrid) do
  67. if v.redPointItem then
  68. GUI:setVisible(v.redPointItem, false)
  69. end
  70. end
  71. end
  72. self.equips = {}
  73. if not self.wearBarItems then
  74. self.wearBarItems = {}
  75. --self.selectItem = nil
  76. local config = SL:GetConfigTable("cfg_wearing_bar")
  77. ---@param v cfg_wearing_bar_column
  78. for k, v in pairs(config) do
  79. if string.contains(v.tag, "时装穿戴栏") then
  80. local width = 81
  81. local height = 82
  82. if k == EEquipWearBarType.Angel then
  83. width = 168
  84. height = 85
  85. end
  86. local item = GUI:UIPanel_Open('dev/ui/Equip/Item/KLWearBarBtn/KLWearBarBtnItem', self.view.Content, self,
  87. { sprite = v.icon, altas = "Atlas/UIzhuangbeixt.spriteatlas", selectSprite = string.replace(v.icon, "01", "02"),
  88. onClick = self.SetSelfWearBarType, clickData = self, wearBar = k,
  89. width = width, height = height, toggleGroup = self.view.Content }, true)
  90. self.wearBarItems[k] = item
  91. end
  92. end
  93. end
  94. self.gridData = {
  95. [EEquipSlotType.Weapon] = { bg = "img_player_weapon1", width = 97, height = 228, x = 28, y = -157, qualityX = 3, qualityY = -3, strengthX = -16, selectX = 5, selectY = -2, selectWidth = 78, selectHeight = 211 },
  96. [EEquipSlotType.OffHandWeapon] = { bg = "img_player_weapon2", width = 98, height = 228, x = 328, qualityX = 5.2, qualityY = -2.8, y = -157, strengthX = -10, selectX = 8.5, selectY = -5, selectWidth = 80, selectHeight = 210 },
  97. [EEquipSlotType.Helmet] = { bg = "img_player_helm", width = 124, height = 115, x = 166, y = -15, qualityX = 7, qualityY = -2, strengthX = -12, selectX = 7, selectY = -2, selectWidth = 107, selectHeight = 102 },
  98. [EEquipSlotType.Armor] = { bg = "img_player_armor", width = 124, height = 228, x = 166, y = -157, qualityX = 7, qualityY = -2, strengthX = -12, selectX = 7, selectY = -3, selectWidth = 105, selectHeight = 210 },
  99. [EEquipSlotType.Glove] = { bg = "img_player_glove", width = 96, height = 116, x = 30, y = -411, qualityX = 3, qualityY = -2, strengthX = -12, selectX = 2, selectY = -2, selectWidth = 86, selectHeight = 101 },
  100. [EEquipSlotType.Pant] = { bg = "img_player_pant", width = 124, height = 115, x = 166, y = -411, qualityX = 7, qualityY = -2, strengthX = -12, selectX = 7, selectY = -3, selectWidth = 105, selectHeight = 100 },
  101. [EEquipSlotType.Boot] = { bg = "img_player_boot", width = 96, height = 116, x = 330, y = -411, qualityX = 3, qualityY = -2, strengthX = -12, selectX = 3, selectY = -3, selectWidth = 83, selectHeight = 100 },
  102. [EEquipSlotType.Necklace] = { bg = "img_player_necklace", width = 55, height = 57, x = 118, y = -19, qualityX = 0, qualityY = 0, strengthX = -3, selectX = 0, selectY = 0, selectWidth = 54, selectHeight = 50 },
  103. [EEquipSlotType.LeftEarring] = { bg = "img_player_earrings", width = 55, height = 57, x = 118, y = -322, qualityX = 0, qualityY = 0, strengthX = -3, selectX = 0, selectY = 0, selectWidth = 54, selectHeight = 50 },
  104. [EEquipSlotType.RightEarring] = { bg = "img_player_earrings", width = 55, height = 57, x = 279, y = -322, qualityX = 0, qualityY = 0, strengthX = -3, selectX = 0, selectY = 0, selectWidth = 51, selectHeight = 50 },
  105. [EEquipSlotType.LeftRing] = { bg = "img_player_ring", width = 55, height = 57, x = 118, y = -413, qualityX = 0, qualityY = 0, strengthX = -3, selectX = 0, selectY = 0, selectWidth = 54, selectHeight = 50 },
  106. [EEquipSlotType.RightRing] = { bg = "img_player_ring", width = 55, height = 57, x = 279, y = -413, qualityX = 0, qualityY = 0, strengthX = -3, selectX = 3, selectY = -1, selectWidth = 50, selectHeight = 48 },
  107. [EEquipSlotType.Guard] = { bg = "img_player_pet", width = 96, height = 116, x = 30, y = -15, qualityX = 3, qualityY = -2, strengthX = -12, selectX = 3, selectY = -2, selectWidth = 84, selectHeight = 100 },
  108. [EEquipSlotType.Wing] = { bg = "img_player_wing", width = 96, height = 116, x = 330, y = -15, qualityX = 3, qualityY = -2, strengthX = -12, selectX = 3, selectY = -2, selectWidth = 82, selectHeight = 100 },
  109. [EEquipSlotType.PriestHawk] = { bg = "img_player_washi", width = 96, height = 116, x = 330, y = -157, qualityX = 3, qualityY = -2, strengthX = -10 },
  110. [EEquipSlotType.ArchangelWeapon] = { bg = "img_player_weapon1", width = 97, height = 228, x = 28, y = -157, qualityX = 3, qualityY = -3, strengthX = -16, selectX = 5, selectY = -2, selectWidth = 78, selectHeight = 211 },
  111. [EEquipSlotType.ArchangelOffHandWeapon] = { bg = "img_player_weapon2", width = 98, height = 228, x = 328, qualityX = 5.2, qualityY = -2.8, y = -157, strengthX = -10, selectX = 8.5, selectY = -5, selectWidth = 80, selectHeight = 210 },
  112. [EEquipSlotType.ArchangelHelmet] = { bg = "img_player_helm", width = 124, height = 115, x = 166, y = -15, qualityX = 7, qualityY = -2, strengthX = -12, selectX = 7, selectY = -2, selectWidth = 107, selectHeight = 102 },
  113. [EEquipSlotType.ArchangelArmor] = { bg = "img_player_armor", width = 124, height = 228, x = 166, y = -157, qualityX = 7, qualityY = -2, strengthX = -12, selectX = 7, selectY = -3, selectWidth = 105, selectHeight = 210 },
  114. [EEquipSlotType.ArchangelGlove] = { bg = "img_player_glove", width = 96, height = 116, x = 30, y = -411, qualityX = 3, qualityY = -2, strengthX = -12, selectX = 2, selectY = -2, selectWidth = 86, selectHeight = 101 },
  115. [EEquipSlotType.ArchangelPant] = { bg = "img_player_pant", width = 124, height = 115, x = 166, y = -411, qualityX = 7, qualityY = -2, strengthX = -12, selectX = 7, selectY = -3, selectWidth = 105, selectHeight = 100 },
  116. [EEquipSlotType.ArchangelBoot] = { bg = "img_player_boot", width = 96, height = 116, x = 330, y = -411, qualityX = 3, qualityY = -2, strengthX = -12, selectX = 3, selectY = -3, selectWidth = 83, selectHeight = 100 },
  117. }
  118. self.specialData = { bg = "img_player_gemstone", width = 96, height = 116, x = 330, y = -270, qualityX = 3, qualityY = -2, strengthX = -10 }
  119. if not self.args then
  120. self.args = {}
  121. end
  122. local x = self.args.x or -400
  123. local y = self.args.y or 0
  124. local z = self.args.z or 0
  125. --local wearArchangeX = GUI:getPositionX(self.view.WearArchange)
  126. --local wearArchangeOffest = wearArchangeX - GUI:getPosition(self.view.UIEquipPanel_Root)
  127. GUI:setPosition(self.view.UIEquipPanel_Root, x, y)
  128. GUI:setPositionZ(self.view.UIEquipPanel_Root, z)
  129. --GUI:setPositionX(self.view.WearArchange,x + wearArchangeOffest)
  130. --self.relatePanel = self.args.relatePanel
  131. ---是否隐藏主界面
  132. self.isHideMainUI = self.args.isHideMainUI
  133. self.hideTips = self.args.hideTips
  134. self.closeCallBack = self.args.callBack
  135. self.closeCallBackData = self.args.callBackData
  136. --是否是查看其他玩家装备
  137. self.isOtherPlayer = self.args.isOther
  138. self.otherRid = self.args.rid
  139. self.forgeGroupType = self.args.forgeGroupType
  140. self.otherEquips = nil
  141. if self.isOtherPlayer then
  142. EquipFunc.otherRid = tostring(self.otherRid)
  143. SL.Friend:ReqOtherRoleInfoMessage(self.otherRid, 4)
  144. end
  145. self:SetBaseWearBar()
  146. if self.selectItem then
  147. self.selectItem:SetSelect(false)
  148. self.selectItem = nil
  149. end
  150. self.updateTime = 0
  151. end
  152. function this:SetBaseWearBar(career)
  153. --基础穿戴栏
  154. local wearBars
  155. if self.isOtherPlayer and career then
  156. wearBars = SL:GeCareerBaseWearBar(career)
  157. else
  158. wearBars = SL:GeCareerBaseWearBar(SL:MeData_GetCareer())
  159. end
  160. --[[ self.baseWearBar = EEquipWearBarType.BaseEquip
  161. if wearBars and wearBars[1] then
  162. self.baseWearBar = wearBars[1]
  163. end]]
  164. self.baseWearBar = wearBars
  165. end
  166. function this:Show(...)
  167. self.relatePanel = self.args.relatePanel
  168. end
  169. ---创建或者刷新界面数据时调用
  170. function this:Refresh()
  171. if not self.isOtherPlayer then
  172. ---打开自己的装备界面的时候如果没有萤石数据的时候请求一下
  173. if not InfoManager.gemSlateInfo.AllSchemeData then
  174. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_SCHEME_INFO)
  175. end
  176. self:UpdatePanel()
  177. else
  178. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_OTHER_GEM_EQUIP_INFO, { rid = self.otherRid })--请求一下别的玩家的萤石信息
  179. end
  180. if not self.args or (self.args and not self.args.isPreLoad) then
  181. SL.HideMainPanel()
  182. end
  183. end
  184. function this:SetSelectIndex(index)
  185. local item = self.slotToGrid[index]
  186. if item then
  187. if self.selectItem then
  188. self.selectItem:SetSelect(false)
  189. end
  190. item:SetSelect(true)
  191. self.selectItem = item
  192. end
  193. end
  194. function this:CanShowFashion()
  195. local ui = GUI:GetUI("dev/ui/UIForgeGroup/Panel/KLUIForgeGroup/KLUIForgeGroupPanel")
  196. return ui == nil and SL:CheckOwnFashion()
  197. end
  198. ---@刷新界面
  199. function this:UpdatePanel()
  200. --拥有时装时才显示切换时装穿戴栏按钮
  201. local ownFashion
  202. --到达指定等级才显示大天使穿戴栏按钮
  203. local archange = false
  204. if self.isOtherPlayer then
  205. --查看他人装备只查看基础穿戴栏装备
  206. ownFashion = false
  207. archange = true
  208. else
  209. ownFashion = SL:CheckOwnFashion()
  210. self:UpdateMoney()
  211. end
  212. local global = SL:GetConfig("cfg_global", 22002, "id")
  213. if global and SL:GetMetaValue("LEVEL") >= tonumber(global.value) then
  214. archange = true
  215. end
  216. local ui = GUI:GetUI("dev/ui/UIForgeGroup/Panel/KLUIForgeGroup/KLUIForgeGroupPanel")
  217. local archangeUI = GUI:GetUI("dev/outui/Archangel/Panel/KLArchangelGroup/KLArchangelGroupPanel")
  218. if archangeUI then
  219. ownFashion = false
  220. archange = false
  221. end
  222. local isShowFashion = ownFashion and ui == nil
  223. local isShowArchange = archange and ui == nil
  224. GUI:setVisible(self.view.wearBarChange, isShowFashion)
  225. GUI:setVisible(self.view.WearArchange, isShowArchange)
  226. local wearBar = self.args and self.args.wearBar or self.baseWearBar
  227. if not isShowFashion then
  228. wearBar = self.baseWearBar
  229. end
  230. self:SetSelfWearBarType(wearBar)
  231. end
  232. ---@param wearBarType EEquipWearBarType
  233. function this:SetSelfWearBarType(wearBarType)
  234. self.wearBar = wearBarType
  235. local equips
  236. if self.isOtherPlayer then
  237. --别人装备
  238. equips = self.otherEquips and self.otherEquips[wearBarType] or {}
  239. GUI:setVisible(self.view.MoneyList, false)
  240. GUI:setVisible(self.view.WearBarList, false)
  241. if wearBarType == self.baseWearBar then
  242. local icon = SL:GetConfig("cfg_wearing_bar", EEquipWearBarType.Archange).icon
  243. GUI:Image_loadTexture(self.view.WearArchange, icon, "Atlas/UIzhuangbeixt.spriteatlas")
  244. else
  245. local icon = SL:GetConfig("cfg_wearing_bar", self.baseWearBar).icon
  246. GUI:Image_loadTexture(self.view.WearArchange, icon, "Atlas/UIzhuangbeixt.spriteatlas")
  247. end
  248. else
  249. --自己装备
  250. equips = SL:GetWearBarsData(wearBarType)
  251. local show = false
  252. if wearBarType == self.baseWearBar then
  253. show = true
  254. local icon = SL:GetConfig("cfg_wearing_bar", EEquipWearBarType.Archange).icon
  255. local icon2 = SL:GetConfig("cfg_wearing_bar", EEquipWearBarType.ShengDaoShi).icon
  256. GUI:Image_loadTexture(self.view.WearArchange, icon, "Atlas/UIzhuangbeixt.spriteatlas")
  257. GUI:Image_loadTexture(self.view.wearBarChange, icon2, "Atlas/UIzhuangbeixt.spriteatlas")
  258. elseif wearBarType == EEquipWearBarType.Archange then
  259. show = true
  260. local icon = SL:GetConfig("cfg_wearing_bar", self.baseWearBar).icon
  261. local icon2 = SL:GetConfig("cfg_wearing_bar", EEquipWearBarType.ShengDaoShi).icon
  262. GUI:Image_loadTexture(self.view.wearBarChange, icon2, "Atlas/UIzhuangbeixt.spriteatlas")
  263. GUI:Image_loadTexture(self.view.WearArchange, icon, "Atlas/UIzhuangbeixt.spriteatlas")
  264. else
  265. local icon = SL:GetConfig("cfg_wearing_bar", EEquipWearBarType.Archange).icon
  266. local icon2 = SL:GetConfig("cfg_wearing_bar", self.baseWearBar).icon
  267. GUI:Image_loadTexture(self.view.wearBarChange, icon2, "Atlas/UIzhuangbeixt.spriteatlas")
  268. GUI:Image_loadTexture(self.view.WearArchange, icon, "Atlas/UIzhuangbeixt.spriteatlas")
  269. end
  270. GUI:setVisible(self.view.MoneyList, show)
  271. GUI:setVisible(self.view.WearBarList, not show)
  272. end
  273. self.equips = equips
  274. if self.wearBarItems[wearBarType] then
  275. self.wearBarItems[wearBarType]:SetSelected()
  276. end
  277. self:UpdateEquips()
  278. end
  279. --更下当前穿戴栏装备
  280. function this:UpdateEquips()
  281. if self.isUpdateEquips then
  282. return
  283. end
  284. local wearBarType = self.wearBar
  285. --根据穿戴栏更新装备数据以及需要显示的装备grid
  286. local noShowSlot = {
  287. EEquipSlotType.None,
  288. EEquipSlotType.Banner,
  289. EEquipSlotType.FashionTotalArmor
  290. }
  291. ---@type cfg_wearing_bar_column
  292. local tbl = SL:GetConfig("cfg_wearing_bar", wearBarType)
  293. for k, data in ipairs(self.equipSlotTypeList) do
  294. --类型
  295. local v = data.type
  296. --双手武器和双手时装武器 跟对应主武器共用一个
  297. if v ~= EEquipSlotType.TwoHandWeapon and v ~= EEquipSlotType.FashionTwoHandWeapon and v ~= EEquipSlotType.ArchangelTwoHandWeapon then
  298. if not table.contains(noShowSlot, v) and not table.contains(tbl.hideArea, v) then
  299. local p = v
  300. if ESlotCondition[v] then
  301. p = ESlotCondition[v]
  302. end
  303. if not self.slotToGrid[v] then
  304. self.isUpdateEquips = true
  305. self.endEquipSlotTypeListIndex = k
  306. local default = self.gridData[v] or self.gridData[p]
  307. if self.wearBar == EEquipWearBarType.ShengDaoShi and v == EEquipSlotType.OffHandWeapon then
  308. default = self.specialData
  309. end
  310. local args = { equipPos = v, isOtherPlayer = self.isOtherPlayer, isEquipGrid = true, item = nil, default = default or {}, x = default.x, y = default.y, click = self.OnGridItemClick, callBackUI = self }
  311. GUI:UIPanel_Open("dev/ui/Common/Item/KLBagItem/KLBagItemItem", self.view.EquipGrid, self, args, true, function(win)
  312. self.slotToGrid[v] = win
  313. GUI:setName(self.slotToGrid[v].view.root, "Grid_" .. data.name)
  314. GUI:setVisible(self.slotToGrid[v].view.root, true)
  315. self.slotToGrid[v]:SetItem(self.equips[v], self.forgeGroupType)
  316. --双手武器没进来 正常双手武器跟主手武器不会同时出现,主武器空就设置一下双手武器
  317. if v== EEquipSlotType.Weapon then
  318. self.slotToGrid[EEquipSlotType.TwoHandWeapon] = self.slotToGrid[EEquipSlotType.Weapon] --双手武器和主武器用同一个
  319. if self.equips[v] == nil then
  320. self.slotToGrid[EEquipSlotType.TwoHandWeapon]:SetItem(self.equips[EEquipSlotType.TwoHandWeapon], self.forgeGroupType)
  321. end
  322. elseif v== EEquipSlotType.FashionWeapon then
  323. self.slotToGrid[EEquipSlotType.FashionTwoHandWeapon] = self.slotToGrid[EEquipSlotType.FashionWeapon] --时装双手武器和时装主武器用同一个
  324. if self.equips[v] == nil then
  325. self.slotToGrid[EEquipSlotType.FashionTwoHandWeapon]:SetItem(self.equips[EEquipSlotType.FashionTwoHandWeapon], self.forgeGroupType)
  326. end
  327. elseif v== EEquipSlotType.ArchangelWeapon then
  328. self.slotToGrid[EEquipSlotType.ArchangelTwoHandWeapon] = self.slotToGrid[EEquipSlotType.ArchangelWeapon] -- 天使装备同上
  329. if self.equips[v] == nil then
  330. self.slotToGrid[EEquipSlotType.ArchangelTwoHandWeapon]:SetItem(self.equips[EEquipSlotType.ArchangelTwoHandWeapon], self.forgeGroupType)
  331. end
  332. elseif v== EEquipSlotType.Pant or v == EEquipSlotType.Glove then
  333. -- Glove和Pant和右侧的装备栏贴的太近 需要调下层级(主要是加了红点会被遮挡)
  334. GUI:SetAsLastSibling(self.slotToGrid[v].view.root)
  335. end
  336. if k == self.endEquipSlotTypeListIndex then
  337. self.isUpdateEquips = false
  338. end
  339. end)
  340. else
  341. local default = self.gridData[v] or self.gridData[p]
  342. if self.wearBar == EEquipWearBarType.ShengDaoShi and v == EEquipSlotType.OffHandWeapon then
  343. default = self.specialData
  344. end
  345. local args = { equipPos = v, isOtherPlayer = self.isOtherPlayer, isEquipGrid = true, item = nil, default = default or {}, x = default.x, y = default.y, click = self.OnGridItemClick, callBackUI = self }
  346. self.slotToGrid[v]:set_args(args)
  347. self.slotToGrid[v]:SetItem(self.equips[v], self.forgeGroupType)
  348. if self.equips[v] == nil then
  349. --双手武器没进来 只能在设置主武器时同时设置一下
  350. if v== EEquipSlotType.Weapon then
  351. self.slotToGrid[EEquipSlotType.TwoHandWeapon]:SetItem(self.equips[EEquipSlotType.TwoHandWeapon], self.forgeGroupType)
  352. elseif v== EEquipSlotType.FashionWeapon then
  353. self.slotToGrid[EEquipSlotType.FashionTwoHandWeapon]:SetItem(self.equips[EEquipSlotType.FashionTwoHandWeapon], self.forgeGroupType)
  354. elseif v== EEquipSlotType.ArchangelWeapon then
  355. self.slotToGrid[EEquipSlotType.ArchangelTwoHandWeapon]:SetItem(self.equips[EEquipSlotType.ArchangelTwoHandWeapon], self.forgeGroupType)
  356. end
  357. end
  358. -- 预加载重新调用下这个
  359. self.slotToGrid[v]:RegistEvents()
  360. GUI:setVisible(self.slotToGrid[v].view.root, true)
  361. end
  362. else
  363. if self.slotToGrid[v] then
  364. GUI:setVisible(self.slotToGrid[v].view.root, false)
  365. end
  366. end
  367. end
  368. end
  369. end
  370. ---@param view KLBagItemItemView
  371. --装备穿戴栏点击回调
  372. function this:OnGridItemClick(view, item)
  373. if not self.hideTips and item then
  374. local bag = self.isOtherPlayer and "otherEquip" or "equip"
  375. SL:OpenTips(bag, item.cfgId, item.id, nil, nil, { otherRid = self.otherRid })
  376. end
  377. if self.hideTips then
  378. if GUI:getVisible(view.selectImg) then
  379. local ui = GUI:GetUI("dev/ui/UIForgeGroup/Panel/KLUIForgeGroup/KLUIForgeGroupPanel")
  380. local archangeUI = GUI:GetUI("dev/outui/Archangel/Panel/KLArchangelGroup/KLArchangelGroupPanel")
  381. if ui or archangeUI then
  382. local bag = self.isOtherPlayer and "otherEquip" or "equip"
  383. SL:OpenTips(bag, item.cfgId, item.id, nil, nil, { hideBtn = true, otherRid = self.otherRid })
  384. end
  385. end
  386. end
  387. if not self.isOtherPlayer then
  388. for pos, v in pairs(self.slotToGrid) do
  389. if v.view and v.view == view then
  390. if not self.hideTips and item == nil and jewelryDefaultId[pos] then
  391. --SL:CommonItemGetPath("", jewelryDefaultId[pos])
  392. SL:OpenTips("", jewelryDefaultId[pos])
  393. end
  394. SL:onLUAEvent(LUA_EVENT_EQUIP_GRID_CLICK, pos, self.wearBar)
  395. break
  396. end
  397. end
  398. end
  399. end
  400. ---刷新所有位置上的装备(主要是为了显示红点 对应面板上的事件调用即可)
  401. function this:UpdateAllItem()
  402. -- 背包改变消息包一帧可能发多个导致调用多次这个逻辑(一段时间仅生效一次)
  403. local currentTime = SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)
  404. --出现问题的情况为1秒点10下
  405. if currentTime - self.updateTime > 100 then
  406. for v, equip in pairs(self.equips) do
  407. if self.slotToGrid[v] then
  408. self.slotToGrid[v]:SetItem(equip, self.forgeGroupType)
  409. end
  410. end
  411. self.updateTime = currentTime
  412. end
  413. end
  414. --刷新货币数据
  415. function this:UpdateMoney()
  416. if self.isOtherPlayer then
  417. return
  418. end
  419. GUI:Text_setString(self.view.moneyText, tostring(SL:GetMetaValue(EMetaVarGetKey.MONEY, MUEResourceType.GoldMoney)))
  420. GUI:Text_setString(self.view.muCoinText, tostring(SL:GetMetaValue(EMetaVarGetKey.MONEY, MUEResourceType.MiracleCurrency)))
  421. GUI:Text_setString(self.view.muBindCoinText, tostring(SL:GetMetaValue(EMetaVarGetKey.MONEY, MUEResourceType.BindDiaMond)))
  422. GUI:Text_setString(self.view.diamondText, tostring(SL:GetMetaValue(EMetaVarGetKey.MONEY, MUEResourceType.DiaMond)))
  423. end
  424. ---注册UI事件和服务器消息
  425. function this:RegistEvents()
  426. GUI:AddOnClickEvent(self.view.CloseButton, self, self.CloseOnClick)
  427. GUI:AddOnClickEvent(self.view.wearBarChange, self, self.WearBarChangeOnClick)
  428. SL:RegisterLUAEvent(LUA_EVENT_MONEYCHANGE, self.UpdateMoney, self)
  429. SL:RegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, self.EquipChange, self)
  430. GUI:AddOnClickEvent(self.view.moneyBackground, self, self.ShowMoneyTips, MUEResourceType.GoldMoney)
  431. GUI:AddOnClickEvent(self.view.MUCoinBackground, self, self.ShowMoneyTips, MUEResourceType.MiracleCurrency)
  432. GUI:AddOnClickEvent(self.view.MUBindCoinBackground, self, self.ShowMoneyTips, MUEResourceType.BindDiaMond)
  433. GUI:AddOnClickEvent(self.view.diamondBackground, self, self.ShowMoneyTips, MUEResourceType.DiaMond)
  434. SL:RegisterLUAEvent(LUA_EVENT_ROLE_INFO, self.ResOtherRoleInfoMessage, self)
  435. GUI:AddOnClickEvent(self.view.WearArchange, self, self.WearArchangeOnClick)
  436. end
  437. ---@param message UserProtos.OtherRoleInfoRes
  438. function this:ResOtherRoleInfoMessage(id, message)
  439. if message.type == 4 and message.role.rid == self.otherRid then
  440. SL:FriendInfo_SetOtherPlayerEquips(message.equipIndex)
  441. local equips = {}
  442. for _, v in pairs(message.equipIndex) do
  443. local wearBar, pos = SL:GetWearBarAndPosBaseEquipIndex(v.index)
  444. if not equips[wearBar] then
  445. equips[wearBar] = {}
  446. end
  447. equips[wearBar][pos] = v.equip
  448. end
  449. self.otherEquips = equips
  450. self:SetBaseWearBar(message.role.career)
  451. self:UpdatePanel()
  452. end
  453. end
  454. ---@param moneyId number @货币id
  455. function this:ShowMoneyTips(_, moneyId)
  456. SL:OpenTips("bag", moneyId)
  457. end
  458. ---@param data table {MakeIndex = 唯一ID, Where = 装备位置, opera = 操作类型 ( 0:初始化 1:增加 2:删除 3:改变), ItemData = 装备数据, WearBar = 穿戴栏id}
  459. function this:EquipChange(_, data)
  460. if self.isOtherPlayer then
  461. return
  462. end
  463. if table.isNullOrEmpty(data) then
  464. return
  465. end
  466. if data.WearBar ~= self.wearBar then
  467. -- 基础装备逻辑
  468. if data.WearBar == EEquipWearBarType.BaseEquip then
  469. self:SetSelfWearBarType(self.baseWearBar)
  470. return
  471. end
  472. --跳转到穿戴装备的穿戴栏
  473. if self.wearBarItems[data.WearBar] then
  474. self.wearBarItems[data.WearBar]:SetSelectedIgnoreIsOn()
  475. --跳转到时装穿戴栏需要检测一下每个时装穿戴栏的显示状况
  476. --只有拥有对应时装才显示
  477. local tbl = SL:GetConfigTable("cfg_wearing_bar")
  478. ---@param v cfg_wearing_bar_column
  479. for k, v in pairs(tbl) do
  480. if self.wearBarItems[v.id] then
  481. --判断有没有该穿戴栏的装备数据包括背包里
  482. if SL:CheckOwnTargetWearbarFashion(v.id) then
  483. GUI:setVisible(self.wearBarItems[v.id].view.root, true)
  484. else
  485. GUI:setVisible(self.wearBarItems[v.id].view.root, false)
  486. end
  487. end
  488. end
  489. GUI:setVisible(self.view.wearBarChange, self:CanShowFashion())
  490. end
  491. if data.WearBar == EEquipWearBarType.Archange then
  492. -- 跳转到大天使穿戴栏
  493. local archange = false
  494. local global = SL:GetConfig("cfg_global", 22002, "id")
  495. if global and SL:GetMetaValue("LEVEL") >= tonumber(global.value) then
  496. archange = true
  497. end
  498. local bagUI = GUI:GetUI("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  499. if archange and bagUI then
  500. self:SetSelfWearBarType(EEquipWearBarType.Archange)
  501. end
  502. end
  503. else
  504. self.equips = SL:GetWearBarsData(self.wearBar)
  505. local pos = data.Where
  506. if self.slotToGrid[pos] then
  507. self.slotToGrid[pos]:SetItem(self.equips[pos], self.forgeGroupType)
  508. end
  509. local isShowFashion = self:CanShowFashion()
  510. GUI:setVisible(self.view.wearBarChange, isShowFashion)
  511. if self.wearBar == EEquipWearBarType.Angel then
  512. if not isShowFashion then
  513. self:SetSelfWearBarType(self.baseWearBar)
  514. end
  515. end
  516. end
  517. end
  518. function this:WearBarChangeOnClick()
  519. if self.wearBar == self.baseWearBar or self.wearBar == EEquipWearBarType.Archange then
  520. --切换时装优先切换到穿有时装的穿戴栏
  521. local tbl = SL:GetConfigTable("cfg_wearing_bar")
  522. local first
  523. local ownFashion = false
  524. ---@param v cfg_wearing_bar_column
  525. for k, v in pairs(tbl) do
  526. if self.wearBarItems[v.id] then
  527. --判断有没有该穿戴栏的装备数据包括背包里
  528. if SL:CheckOwnTargetWearbarFashion(v.id) then
  529. if not first then
  530. first = self.wearBarItems[v.id]
  531. end
  532. if not ownFashion then
  533. local equips = SL:GetWearBarsData(v.id)
  534. if table.count(equips) > 0 then
  535. ownFashion = true
  536. self.wearBarItems[v.id]:SetSelectedIgnoreIsOn()
  537. end
  538. end
  539. GUI:setVisible(self.wearBarItems[v.id].view.root, true)
  540. else
  541. GUI:setVisible(self.wearBarItems[v.id].view.root, false)
  542. end
  543. end
  544. end
  545. --没时装默认选中第一个
  546. if not ownFashion and first then
  547. first:SetSelectedIgnoreIsOn()
  548. end
  549. else
  550. self:SetSelfWearBarType(self.baseWearBar)
  551. end
  552. end
  553. function this:WearArchangeOnClick()
  554. if self.wearBar == self.baseWearBar or self.wearBar ~= EEquipWearBarType.Archange then
  555. self:SetSelfWearBarType(EEquipWearBarType.Archange)
  556. else
  557. self:SetSelfWearBarType(self.baseWearBar)
  558. end
  559. end
  560. function this:CloseOnClick()
  561. GUI:UIPanel_Close("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel")
  562. if self.relatePanel then
  563. GUI:UIPanel_Close(self.relatePanel)
  564. end
  565. self.relatePanel = nil
  566. if self.closeCallBack then
  567. self.closeCallBack(self.closeCallBackData)
  568. end
  569. if not self.isHideMainUI then
  570. SL.ShowMainPanel()
  571. end
  572. end
  573. function this:Close()
  574. self.wearBar = nil
  575. end
  576. return this