KLUINearPlayerPanel.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. ---@class KLUINearPlayerPanel:UIKmlLuaPanelBase
  2. ---@field view KLUINearPlayerPanelView
  3. local KLUINearPlayerPanel = class(UIKmlLuaPanelBase)
  4. local this =KLUINearPlayerPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. GUI:DataListInitData( self.view.near_player_datalist,function()
  8. return self:ListItemCountFunc()
  9. end,function(realIndex)
  10. return self:ListItemGetFunc(realIndex)
  11. end,function(realIndex, kmlcontrol)
  12. return self:ListItemInitFunc(realIndex, kmlcontrol)
  13. end, function(realIndex, kmlcontrol)
  14. return self:ListItemUpdateFunc(realIndex, kmlcontrol)
  15. end)
  16. end
  17. function this:ListItemCountFunc()
  18. return #self.playerList
  19. end
  20. function this:ListItemGetFunc(realIndex)
  21. end
  22. function this:ListItemInitFunc(realIndex, kmlcontrol)
  23. end
  24. function this:ListItemUpdateFunc(realIndex, kmlcontrol)
  25. local player_info = self.playerList[realIndex + 1]
  26. local player_name = GUI:GetChildControl(self.view.near_player_datalist,realIndex,'player_name')
  27. local player_level = GUI:GetChildControl(self.view.near_player_datalist,realIndex,'player_level')
  28. local player_career = GUI:GetChildControl(self.view.near_player_datalist,realIndex,'player_career')
  29. local player_unionName = GUI:GetChildControl(self.view.near_player_datalist,realIndex,'player_unionName')
  30. local invite_btn = GUI:GetChildControl(self.view.near_player_datalist,realIndex,'invite_btn')
  31. local had_invite_btn = GUI:GetChildControl(self.view.near_player_datalist,realIndex,'had_invite_btn')
  32. GUI:Text_setString(player_name, player_info.roleInfo.name)
  33. GUI:Text_setString(player_level, "Lv." .. player_info.roleInfo.level)
  34. GUI:Text_setString(player_unionName, "无")
  35. if player_info.roleInfo.roleInfoExt and player_info.roleInfo.roleInfoExt.unionName and player_info.roleInfo.roleInfoExt.unionName ~= "" then
  36. GUI:Text_setString(player_unionName, player_info.roleInfo.roleInfoExt and player_info.roleInfo.roleInfoExt.unionName)
  37. end
  38. local career = player_info.roleInfo.career
  39. ---@type cfg_career_column[]
  40. local career_tbl = SL:GetConfigTable("cfg_career")
  41. for _, v in pairs(career_tbl) do
  42. if v.baseCareer == career.baseCareer and v.careerRank == career.careerRank then
  43. GUI:Text_setString(player_career, v.name)
  44. break
  45. end
  46. end
  47. if SL:TeamInfo_GetLeaderId() == SL:GetMetaValue(EMetaVarGetKey.UID) then
  48. if player_info.invitationState == 0 then
  49. GUI:SetActive(invite_btn, true)
  50. GUI:SetActive(had_invite_btn, false)
  51. GUI:AddOnClickEvent(invite_btn, self, self.InvitePlayer, { id = player_info.roleInfo.rid })
  52. else
  53. GUI:SetActive(invite_btn, false)
  54. GUI:SetActive(had_invite_btn, true)
  55. end
  56. else
  57. GUI:SetActive(invite_btn, true)
  58. GUI:SetActive(had_invite_btn, false)
  59. GUI:AddOnClickEvent(invite_btn, self, self.InvitePlayer, { id = player_info.roleInfo.rid })
  60. end
  61. end
  62. function this:InvitePlayer(_, eventData)
  63. local teamId = SL:TeamInfo_GetTeamId()
  64. local leaderId = SL:TeamInfo_GetLeaderId()
  65. if teamId > 0 then
  66. if leaderId == SL:GetMetaValue(EMetaVarGetKey.UID) then
  67. SL:ReqSendTeamInvitation(eventData.id,self.type)
  68. else
  69. SL:TipMessage(SL:GetConfig('cfg_string',297).text,1,NoticeType.NoticeMid )--您不是队长,不能邀请队员
  70. end
  71. else
  72. SL:TipMessage(SL:GetConfig('cfg_string',22).text,1,NoticeType.NoticeMid )--"请先创建队伍",
  73. end
  74. --SL:CommonTipsMessage({ showTips = "发送邀请成功" })
  75. end
  76. ---创建或者刷新界面数据时调用
  77. function this:Refresh()
  78. self.type = 1
  79. if self.args and self.args.myPlayerType then
  80. self.type = self.args.myPlayerType
  81. end
  82. SL:ReqPlayerList(self.type)
  83. end
  84. ---注册UI事件和服务器消息
  85. function this:RegistEvents()
  86. SL:RegisterLuaNetMsg(MessageDef.ResPlayerListMessage, self.ResPlayerListMessage, self)
  87. end
  88. ---@param message TeamProto.PlayerList
  89. function this:ResPlayerListMessage(_, message)
  90. if message then
  91. self.playerList = {}
  92. for i, v in ipairs(message.nearbyPlayer) do
  93. if v.roleInfo.rid ~= SL:GetMetaValue(EMetaVarGetKey.UID) then
  94. table.insert(self.playerList,v)
  95. end
  96. end
  97. end
  98. GUI:DataListUpdateData(self.view.near_player_datalist)
  99. end
  100. function this:Close()
  101. end
  102. return this