KLUIConsumerRankingPanel.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. ---@class KLUIConsumerRankingPanel:UIKmlLuaPanelBase
  2. ---@field view KLUIConsumerRankingPanelView
  3. ---@field leftCfgDataList table<number,cfg_rank_column>
  4. ---@field titleCfgDataList table<number,cfg_rank_column>
  5. ---@field allCfgDataList table<number,table<number,table<number,cfg_rank_column>>>
  6. local KLUIConsumerRankingPanel = class(UIKmlLuaPanelBase)
  7. local this =KLUIConsumerRankingPanel
  8. ---创建时调用一次
  9. function this:Init()
  10. self.allCfgDataList = {}
  11. ---排行榜玩家信息
  12. self.all_rank = {}
  13. ---选择的玩家id
  14. self.selectPlayerId = ""
  15. self.reqOtherRoleInfo = true
  16. GUI:DataListInitData(self.view.PlayerDataList,function()
  17. return self:PlayerDataListItemCountFunc()
  18. end,function(realIndex)
  19. return self:PlayerDataListItemGetFunc(realIndex)
  20. end,function(realIndex, kmlcontrol)
  21. return self:PlayerDataListItemInitFunc(realIndex, kmlcontrol)
  22. end, function(realIndex, kmlcontrol)
  23. return self:PlayerDataListItemUpdateFunc(realIndex, kmlcontrol)
  24. end)
  25. self.reward_all_item ={}
  26. local tip_str = SL:GetConfig("cfg_string",28002).text
  27. GUI:Text_setString(self.view.RewardText,tip_str)
  28. end
  29. ---创建或者刷新界面数据时调用
  30. function this:Refresh()
  31. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_MAIN_ACTIVE_INFO, { subType = 5})
  32. end
  33. function this:LUA_EVENT_MAINOPERATEACTIVITY_CHANGE()
  34. self:InitMyRankInfo()
  35. self:InitRankList()
  36. GUI:DataListUpdateData(self.view.PlayerDataList)
  37. local leftTime = InfoManager.mainOperateActivityInfo:GetOADJSTimeBySubType(EOperateActivityActivityType.ConsumerRanking)
  38. GUI:SetControl_time(self.view.refreshTime, leftTime)
  39. end
  40. ---初始化个人排名信息
  41. function this:InitMyRankInfo()
  42. local consumerRank = InfoManager.mainOperateActivityInfo.operateMainActivityData.consumerRank
  43. local rankValue = 0
  44. local money = 0
  45. if consumerRank and consumerRank.ownInfo then
  46. money = consumerRank.ownInfo.money
  47. end
  48. if consumerRank and consumerRank.ownInfo and consumerRank.rank then
  49. local my_rid = SL:GetMetaValue(EMetaVarGetKey.USER_ID)
  50. for k, v in pairs(consumerRank.rank) do
  51. if v.rid == my_rid then
  52. rankValue = tonumber(k)
  53. end
  54. end
  55. end
  56. --local name = SL:GetMetaValue(EMetaVarGetKey.USER_NAME)
  57. local money_str = "累计充值" .. tostring(money) .. "元"
  58. local rank_str = "第"..rankValue .. "名"
  59. GUI:Text_setString(self.view.MyRank_money,money_str)
  60. if rankValue > 0 then--排行榜有值的情况下
  61. GUI:Text_setString(self.view.MyRank_RankText,rank_str)
  62. GUI:setVisible(self.view.MyRank_RankText, true)
  63. GUI:setVisible(self.view.MyRank_no, false)
  64. else--排行榜没有值的情况下直接拿自身数据
  65. local myValue = "无"
  66. GUI:setVisible(self.view.MyRank_RankText, false)
  67. GUI:setVisible(self.view.MyRank_no, true)
  68. end
  69. end
  70. --------------------------------排行榜玩家信息-------------------------------------------------------
  71. -- "consumerRank":{"ownInfo":{"money":48,"name":"艾比盖高尔","rid":"19130817457520640"},
  72. -- "rank":{"1":{"money":48,"name":"艾比盖高尔","rid":"19130817457520640"},"2":{"money":6,"name":"黛西格林","rid":"19130817443788800"}}},
  73. function this:InitRankList()
  74. local consumerRank = InfoManager.mainOperateActivityInfo.operateMainActivityData.consumerRank
  75. self.all_rank = {}
  76. if consumerRank then
  77. local rank = consumerRank.rank
  78. --SL:LogTable(rank,true)
  79. for i = 1, 10, 1 do
  80. if rank[tostring(i)] then
  81. local tab = rank[tostring(i)]
  82. tab.rank = i
  83. table.insert(self.all_rank,tab)
  84. else
  85. table.insert(self.all_rank,{name="",rid="",money=0,rank = i})
  86. end
  87. end
  88. end
  89. if table.count(self.all_rank) > 0 and not string.isNullOrEmpty(self.all_rank[1].rid) then
  90. self.selectPlayerId = self.all_rank[1].rid
  91. self.selectPlayerName = tostring(self.all_rank[1].name)
  92. else
  93. self.selectPlayerId = ""
  94. self.selectPlayerName = "虚位以待"
  95. end
  96. GUI:Text_setString(self.view.user_name,self.selectPlayerName)
  97. if string.isNullOrEmpty(self.selectPlayerId) or self.selectPlayerId == SL:GetMetaValue(EMetaVarGetKey.USER_ID) then
  98. GUI:SetActive(self.view.LockButton,false)
  99. else
  100. GUI:SetActive(self.view.LockButton,true)
  101. end
  102. if string.isNullOrEmpty(self.selectPlayerId) then
  103. SL:UIModel_Recycle(self.curShowRole)
  104. GUI:setVisible(self.view.player_block, true)
  105. GUI:setVisible(self.view.xuwei, true)
  106. elseif self.selectPlayerId == SL:GetMetaValue(EMetaVarGetKey.USER_ID) then
  107. GUI:setVisible(self.view.player_block, false)
  108. self:ShowMyRole()
  109. GUI:setVisible(self.view.xuwei, false)
  110. else
  111. GUI:setVisible(self.view.xuwei, false)
  112. GUI:setVisible(self.view.player_block, false)
  113. if self.reqOtherRoleInfo then--避免多次请求
  114. self.reqOtherRoleInfo = false
  115. self.otherRoleInfo = nil
  116. SL.Friend:ReqOtherRoleInfoMessage(tonumber(self.selectPlayerId), 1)
  117. end
  118. end
  119. end
  120. function this:PlayerDataListItemCountFunc()
  121. return #self.all_rank
  122. end
  123. function this:PlayerDataListItemGetFunc(realIndex)
  124. local data = self.all_rank[realIndex + 1]
  125. local item = GUI:UIPanel_Open("dev/outui/ConsumerRanking/Item/KLRankItem/KLRankItem", self.view.PlayerDataList, self, {}, true)
  126. self.reward_all_item[realIndex + 1] = item
  127. return item.view.root
  128. end
  129. function this:PlayerDataListItemInitFunc(realIndex, kmlcontrol)
  130. end
  131. function this:PlayerDataListItemUpdateFunc(realIndex, kmlcontrol)
  132. local data = self.all_rank[realIndex + 1]
  133. self.reward_all_item[realIndex + 1]:RefreshItem(data, self.selectPlayerId, self)
  134. end
  135. function this:OnClickPlayer(data)
  136. self.selectPlayerId = data.rid
  137. self.selectPlayerName = tostring(data.name)
  138. if self.selectPlayerId == SL:GetMetaValue(EMetaVarGetKey.USER_ID) then
  139. self:ShowMyRole()
  140. GUI:SetActive(self.view.LockButton,false)
  141. else
  142. GUI:SetActive(self.view.LockButton,true)
  143. self.otherRoleInfo = nil
  144. SL.Friend:ReqOtherRoleInfoMessage(tonumber(self.selectPlayerId), 1)
  145. end
  146. GUI:Text_setString(self.view.user_name,self.selectPlayerName)
  147. end
  148. ---@param data UserProtos.RoleInfo
  149. function this:GetPlayerRoleInfo(data)
  150. local role_param = { "body", "head", "armor", "hand", "pants", "boot" }
  151. local wear_list_str = ""
  152. local model_list_str = ""
  153. local equipInfo = data.roleInfoExt.equip
  154. if equipInfo then
  155. local default_tbl = SL:GetConfig("cfg_model_default", data.career.baseCareer)
  156. local model_list = {}
  157. for _, v in pairs(role_param) do
  158. model_list[v] = default_tbl[v]
  159. end
  160. for _, v in ipairs(equipInfo) do
  161. ---@type cfg_item_column
  162. local itemInfo = SL:GetConfig("cfg_item", v.cfgId)
  163. if itemInfo and itemInfo.type == 2 then
  164. if itemInfo.subType == 1 then
  165. if wear_list_str == "" then
  166. wear_list_str = "WeaponRspineParent#" .. itemInfo.field[1]
  167. else
  168. wear_list_str = wear_list_str .. ",WeaponRspineParent#" .. itemInfo.field[1]
  169. end
  170. elseif itemInfo.subType == 2 then
  171. if wear_list_str == "" then
  172. wear_list_str = "WeaponLspineParent#" .. itemInfo.field[1]
  173. else
  174. wear_list_str = wear_list_str .. ",WeaponLspineParent#" .. itemInfo.field[1]
  175. end
  176. elseif itemInfo.subType == 3 then
  177. if wear_list_str == "" then
  178. wear_list_str = "WeaponRspineParent#" .. itemInfo.field[1]
  179. else
  180. wear_list_str = wear_list_str .. ",WeaponRspineParent#" .. itemInfo.field[1]
  181. end
  182. elseif itemInfo.subType == 13 then
  183. if wear_list_str == "" then
  184. wear_list_str = "Wing#" .. itemInfo.field[1]
  185. else
  186. wear_list_str = wear_list_str .. ",Wing#" .. itemInfo.field[1]
  187. end
  188. elseif itemInfo.subType == 30 then
  189. if wear_list_str == "" then
  190. wear_list_str = "BuffspineParent#" .. itemInfo.field[1]
  191. else
  192. wear_list_str = wear_list_str .. ",BuffspineParent#" .. itemInfo.field[1]
  193. end
  194. else
  195. local point = ""
  196. ---@type cfg_model_charactor_column
  197. local model_tbl = SL:GetConfig("cfg_model_charactor", itemInfo.field[1])
  198. if model_tbl then
  199. if model_tbl.part == 23 then
  200. point = "body"
  201. elseif model_tbl.part == 11 then
  202. point = "head"
  203. elseif model_tbl.part == 2 then
  204. point = "armor"
  205. elseif model_tbl.part == 9 then
  206. point = "hand"
  207. elseif model_tbl.part == 15 then
  208. point = "pants"
  209. elseif model_tbl.part == 5 then
  210. point = "boot"
  211. end
  212. if point ~= "" then
  213. model_list[point] = itemInfo.field[1]
  214. end
  215. end
  216. end
  217. end
  218. end
  219. for _, v in pairs(model_list) do
  220. if model_list_str == "" then
  221. model_list_str = v
  222. else
  223. model_list_str = model_list_str .. "#" .. v
  224. end
  225. end
  226. end
  227. return model_list_str, wear_list_str
  228. end
  229. ---显示自己的模型
  230. function this:ShowMyRole()
  231. --local role = {roleInfoExt = {equip=RoleManager.meData.equips,mountId = RoleManager.meData.MountId},career = SL:MeData_GetCareer()}
  232. --local model_list, equip_list = self:GetPlayerRoleInfo(role)
  233. --self:CreateRole(model_list, equip_list)
  234. local mountId = InfoManager.mountInfo.ride_mount_id
  235. if InfoManager.mountInfo.isHasOwnerMount and not InfoManager.mountInfo.isRankShowMount then
  236. mountId = 0
  237. end
  238. local behaviour = EBehaviourType_Stand.Stand
  239. if self.selectPlayerIndex == 0 and mountId == 0 then
  240. behaviour = EBehaviourType_Stand.Sit
  241. end
  242. local iconName = mountId == 0 and "S_BG" or "rank_mount_bg"
  243. local rotation = mountId == 0 and 50 or 10
  244. -- GUI:setPositionY(self.view.mountModel, mountId == 0 and -170 or -205)
  245. -- GUI:setPositionX(self.view.mountModel, mountId == 0 and 0 or 70)
  246. SL:UIModel_Recycle(self.curShowRole)
  247. self.curShowRole = SL:UIModel_Create(GUI:GetRectTransform(self.view.mountModel),SL:GetMetaValue(EMetaVarGetKey.UID),SL:MeData_GetCareer(),SL:MeData_GetLevel(),SL:GetMetaValue(EMetaVarGetKey.USER_NAME),mountId,EAction.Stand,behaviour,SL:MeData_GetRoleExtInfo().roleInfoExtData,-50,0,-76,170,0,rotation,0)
  248. end
  249. ---@param message UserProtos.OtherRoleInfoRes
  250. function this:ResOtherRoleInfoMessage(id, message)
  251. if message.type == 1 and self.selectPlayerId == tostring(message.role.rid) then
  252. self.otherRoleInfo = message
  253. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_OTHER_MOUNT_RANK,message.role.rid)
  254. end
  255. end
  256. function this:RES_OTHER_MOUNT_RANK(id,message)
  257. if self.otherRoleInfo then
  258. local mountId = message
  259. local behaviour = EBehaviourType_Stand.Stand
  260. if self.selectPlayerIndex == 0 and mountId == 0 then
  261. behaviour = EBehaviourType_Stand.Sit
  262. end
  263. local iconName = mountId == 0 and "S_BG" or "rank_mount_bg"
  264. local rotation = mountId == 0 and 50 or 10
  265. -- GUI:setPositionY(self.view.mountModel, mountId == 0 and -170 or -205)
  266. -- GUI:setPositionX(self.view.mountModel, mountId == 0 and 0 or 70)
  267. SL:UIModel_Recycle(self.curShowRole)
  268. self.curShowRole = SL:UIModel_Create(GUI:GetRectTransform(self.view.mountModel),self.otherRoleInfo.role.rid,self.otherRoleInfo.role.career,self.otherRoleInfo.role.level,self.otherRoleInfo.role.name,mountId,EAction.Stand,behaviour,self.otherRoleInfo.role.roleInfoExt,-50,0,-76,170,0,rotation,0)
  269. end
  270. end
  271. function this:CreateRole(model_list, equip_list)
  272. local ani = "idle"
  273. if self.selectPlayerIndex == 0 then
  274. ani = "Sit"
  275. end
  276. self.view.Role.kmlControl:SetSingleAttr("ani", ani)
  277. GUI:SetPlayerRoleInfo(self.view.Role, model_list, equip_list,ani)
  278. end
  279. ------------------------------------------------------------------------------------------------
  280. ---注册UI事件和服务器消息
  281. function this:RegistEvents()
  282. SL:RegisterLUAEvent(LUA_EVENT_MAINOPERATEACTIVITY_CHANGE, self.LUA_EVENT_MAINOPERATEACTIVITY_CHANGE, self)
  283. SL:RegisterLUAEvent(LUA_EVENT_ROLE_INFO, self.ResOtherRoleInfoMessage, self)
  284. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_OTHER_MOUNT_RANK,self.RES_OTHER_MOUNT_RANK,self)
  285. --GUI:AddOnClickEvent(self.view.CloseButton, self, self.OnClickCloseButton)
  286. GUI:AddOnClickEvent(self.view.LockButton, self, self.OnClickLockButton)
  287. --SL:RegisterLuaNetMsg(LuaMessageIdToClient.SEND_RANK_DATA_TO_CLIENT,self.RankDataChange,self)
  288. end
  289. function this:OnClickCloseButton()
  290. GUI:UIPanel_Close("dev/outui/UIRankList/Panel/KLUIRankList/KLUIConsumerRankingPanel")
  291. SL.ShowMainPanel()
  292. end
  293. function this:OnClickLockButton()
  294. if not self.selectPlayerId or self.selectPlayerId == 0 then
  295. SL:TipMessage(SL:GetConfig('cfg_string',280).text,1,NoticeType.NoticeMid)--"请先选择查看的玩家",
  296. return
  297. end
  298. GUI:SetActive(self.view.closeEquipUIButton,true)
  299. --角色装备信息
  300. GUI:UIPanel_Open("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel", _, _, {
  301. isOther = true,
  302. rid = tonumber(self.selectPlayerId),
  303. isHideMainUI = true,
  304. callBack = function() GUI:SetActive(self.view.closeEquipUIButton,false) end,
  305. x = 17,
  306. z=-200
  307. })
  308. end
  309. ---排行榜回包
  310. function this:RankDataChange(_,message)
  311. self.all_rank = {}
  312. local count = table.count(message["rankDatas"])
  313. if count <= 0 then
  314. GUI:setVisible(self.view.NoRankListImg, true)
  315. GUI:setVisible(self.view.RankList_Panel, false)
  316. else
  317. self:InitMyRankInfo(message["myRankData"])
  318. GUI:setVisible(self.view.NoRankListImg, false)
  319. GUI:setVisible(self.view.RankList_Panel, true)
  320. for i = 1, count do
  321. local data = message["rankDatas"][tostring(i)]
  322. if data["actor"]["id"] == SL:GetMetaValue(EMetaVarGetKey.UID) then
  323. self:InitMyRankInfo(data,i)
  324. end
  325. table.insert(self.all_rank,data)
  326. end
  327. GUI:DataListUpdateData(self.view.PlayerDataList)
  328. end
  329. end
  330. function this:Close()
  331. SL:SendLuaNetMsg(LuaMessageIdToSever.STOP_REFRESH_RANK_DATA)
  332. SL:UIModel_Recycle(self.curShowRole)
  333. self.curShowRole = nil
  334. self.otherRoleInfo = nil
  335. end
  336. return this