UIGuildInfoView.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. local UIGuildInfoView = require("UIGuild/UIGuildInfoView_Generate")
  2. local LoadStatusLoopListCtr = require('Common/LoadStatusLoopListCtr')
  3. function UIGuildInfoView:OnAwake(data)
  4. self.controller = require("UIGuild/UIGuildInfoCtr"):new()
  5. self.controller:Init(self)
  6. self.controller:SetData(data)
  7. end
  8. function UIGuildInfoView:AddEventListener()
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.GUILD_OTHER_MORE_INFO_CHANGED, self, self.OnGuildMoreInfoChanged)
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.GUILD_MEMBER_MORE_INFO_CHANGED, self, self.OnGuildMemberMoreInfoChanged)
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.GUILD_SUBMIT_APPLY_CHANGED, self, self.OnGuildSubmitChanged)
  12. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.GUILD_ENTER_SUCCESS, self, self.OnGuildEnterSuccess)
  13. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.GUILD_CREATE_SUCCESS, self, self.OnGuildCreateSuccess)
  14. end
  15. function UIGuildInfoView:FillContent(data, uiBase)
  16. self.uiBase = uiBase
  17. local gameObject = self.uiBase:GetRoot()
  18. if gameObject ~= nil then
  19. self.gameObject = gameObject
  20. self.transform = gameObject.transform
  21. end
  22. self:InitGenerate(self.transform, data)
  23. self:Init()
  24. end
  25. function UIGuildInfoView:Init()
  26. if self.loadStatusLoopListCtr then
  27. self.loadStatusLoopListCtr:Dispose()
  28. end
  29. self.loadStatusLoopListCtr = LoadStatusLoopListCtr:new(self, self.peopleList.loopListView, 0, 50,
  30. false, nil, nil,
  31. true, 'LoadingItem', Enum.ListLoadingStatus.WaitLoad,
  32. self.GetItemByIndex, nil, self.OnBeginLoad)
  33. self.peopleList.loopListView.ScrollRect.enabled = false
  34. self.noticeTxt.text.text = ''
  35. self.bottom:SetActive(not self.controller:IsInGuild())
  36. self:RefreshBriefView()
  37. self:RefreshMoreInfoView()
  38. self:RefreshApplyBtn()
  39. -- 界面准备好了,等待服务器数据到来
  40. local errorCode = self.controller:SendGetGuildMoreInfoReq()
  41. if errorCode ~= 0 then
  42. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  43. end
  44. end
  45. function UIGuildInfoView:RemoveEventListener()
  46. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  47. end
  48. function UIGuildInfoView:AddUIEventListener()
  49. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  50. self.uiBase:AddButtonUniqueEventListener(self.AnyBtn.button, self, self.OnClickCloseBtn)
  51. self.uiBase:AddButtonUniqueEventListener(self.btnClose.button, self, self.OnClickCloseBtn)
  52. self.uiBase:AddButtonUniqueEventListener(self.btnEnter.button, self, self.OnClickSubmitApply)
  53. self.uiBase:AddButtonUniqueEventListener(self.btnCancel.button, self, self.OnClickCancelBtn)
  54. end
  55. function UIGuildInfoView:OnHide()
  56. end
  57. function UIGuildInfoView:OnShow(data)
  58. self.controller:SetData(data)
  59. end
  60. function UIGuildInfoView:OnClose()
  61. end
  62. function UIGuildInfoView:OnDispose()
  63. if self.loadStatusLoopListCtr then
  64. self.loadStatusLoopListCtr:Dispose()
  65. self.loadStatusLoopListCtr = nil
  66. end
  67. self.controller:OnDispose()
  68. end
  69. function UIGuildInfoView:OnPageInEnd()
  70. UIGuildInfoView.super.OnPageInEnd(self)
  71. self.peopleList.loopListView.ScrollRect.enabled = true
  72. end
  73. function UIGuildInfoView:OnGuildMoreInfoChanged()
  74. if not self.controller:RefreshGuildData() then return end
  75. self:RefreshBriefView()
  76. self:RefreshMoreInfoView()
  77. self:RefreshApplyBtn()
  78. self:OnBeginLoad()
  79. end
  80. function UIGuildInfoView:OnGuildMemberMoreInfoChanged(guild)
  81. if guild ~= self.controller:GetId() then return end
  82. self:RefreshMemberInfoView()
  83. end
  84. function UIGuildInfoView:OnGuildSubmitChanged()
  85. self:RefreshApplyBtn()
  86. end
  87. function UIGuildInfoView:OnGuildEnterSuccess()
  88. if not self.controller:IsInGuild() then
  89. return
  90. end
  91. self:UIClose()
  92. end
  93. function UIGuildInfoView:OnGuildCreateSuccess()
  94. if not self.controller:IsInGuild() then
  95. return
  96. end
  97. self:UIClose()
  98. end
  99. function UIGuildInfoView:OnClickCloseBtn()
  100. self:UIClose()
  101. end
  102. function UIGuildInfoView:OnClickSubmitApply()
  103. local cdTime = self.controller:GetNextCDTime()
  104. if cdTime then
  105. local remainTime = ManagerContainer.LuaTimerMgr:GetRemainSecondsWithUInt64(cdTime)
  106. if remainTime > 0 then
  107. ManagerContainer.LuaUIMgr:ErrorNoticeDisplayWithParam('GuildTips_004', DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true))
  108. return
  109. end
  110. end
  111. local errorCode = self.controller:SendSubmitApplyReq()
  112. if errorCode ~= 0 then
  113. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  114. end
  115. end
  116. function UIGuildInfoView:OnClickCancelBtn()
  117. local errorCode = self.controller:SendCancelApplyReq()
  118. if errorCode ~= 0 then
  119. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  120. end
  121. end
  122. function UIGuildInfoView:OnClickGuildPeopleItem(btn, param)
  123. local uid = param[0]
  124. ManagerContainer.LuaUIMgr:OpenRoleMessagePanel(uid)
  125. end
  126. function UIGuildInfoView:GetItemByIndex(loopListView, idx, dataIdx)
  127. local itemData = self.controller:GetMemberMoreInfoByItemidx(dataIdx)
  128. if not itemData then return nil end
  129. local item = loopListView:NewListViewItem('GuildPeopleItem')
  130. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'GuildPeopleItem', item.gameObject)
  131. if itemLua then
  132. local brief = itemData.brief
  133. local playerBrief = itemData.playerBrief
  134. local uid
  135. local data = {IsHero = true}
  136. local headFrameId = nil
  137. local vipLv = nil
  138. if playerBrief then
  139. uid = playerBrief.uid
  140. vipLv = playerBrief.vipLv
  141. headFrameId = playerBrief.headFrame
  142. if int64.equals(uid, ManagerContainer.DataMgr.UserData:GetUserId()) then
  143. headFrameId = ManagerContainer.DataMgr.UserData:GetHeadFrameId()
  144. vipLv = ManagerContainer.DataMgr.UserData:GetVipLv()
  145. end
  146. local jobCfg = ManagerContainer.CfgMgr:GetJobDataById(playerBrief.configId)
  147. local jobIcon = ''
  148. if jobCfg then
  149. jobIcon = jobCfg.JobIcon
  150. end
  151. data.Level = playerBrief.level
  152. data.ProfessionIcon = jobIcon
  153. data.HeadIcon = playerBrief.headPortraitName
  154. itemLua.nameTxt.text.text = tostring(playerBrief.nickName)
  155. itemLua.atkTxt.text.text = tostring(playerBrief.fightPower)
  156. local offlineTime = brief and brief.offlineTime or 0
  157. itemLua.onlineTxt.text.text = CommonUtil.GetOnlineStatus((offlineTime == 0), offlineTime)
  158. else
  159. itemLua.nameTxt.text.text = ''
  160. itemLua.atkTxt.text.text = ''
  161. itemLua.onlineTxt.text.text = ''
  162. end
  163. itemLua.headItem.head.button.enabled = false
  164. CommonUtil.SetPlayerHeadAndFrame(self, itemLua.headItem, data, false, headFrameId)
  165. itemLua.vipIcon.image.enabled = false
  166. itemLua.vipIcon.image.sprite = nil
  167. if vipLv and vipLv >= 0 then
  168. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
  169. if vipCfg then
  170. CommonUtil.LoadIcon(self, vipCfg.SmallIcon, function(sprite)
  171. if sprite then
  172. itemLua.vipIcon.image.sprite = sprite
  173. itemLua.vipIcon.image.enabled = true
  174. end
  175. end, itemLua, 'VipIcon')
  176. end
  177. end
  178. local post = brief and brief.post or Enum.GuildPostType.None
  179. if not uid then uid = brief and brief.uid or nil end
  180. itemLua.presidentTag:SetActive(post == Enum.GuildPostType.President)
  181. itemLua.vicePresidentTag:SetActive(post == Enum.GuildPostType.VicePresident)
  182. local active = itemData.active
  183. itemLua.activeTxt.text.text = (active and tostring(active) or '0')
  184. itemLua.select:SetActive(false)
  185. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickGuildPeopleItem, uid)
  186. end
  187. return item
  188. end
  189. function UIGuildInfoView:OnBeginLoad(isLeft)
  190. -- 发送获得后续公会玩家信息
  191. local errorCode = self.controller:SendGetGuildMemberInfoReq()
  192. if errorCode ~= 0 then
  193. if errorCode == 1 then
  194. self:RefreshMemberInfoView()
  195. else
  196. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  197. end
  198. end
  199. end
  200. function UIGuildInfoView:RefreshBriefView()
  201. local brief = self.controller:GetGuildBriefData()
  202. local itemLua = self.guildBadgeItem
  203. itemLua.badge.image.enabled = false
  204. itemLua.badge.image.sprite = nil
  205. CommonUtil.LoadIcon(self, brief and brief.badgeResPath or nil, function(sprite)
  206. itemLua.badge.image.enabled = true
  207. itemLua.badge.image.sprite = sprite
  208. end, itemLua, 'BadgeIcon')
  209. if brief then
  210. self.lvTxt.text.text = tostring(brief.level)
  211. self.nameTxt.text.text = tostring(brief.name)
  212. self.idTxt.text.text = tostring(brief.id)
  213. self.activeTxt.text.text = tostring(brief.active)
  214. else
  215. self.lvTxt.text.text = '-'
  216. self.nameTxt.text.text = '-'
  217. self.idTxt.text.text = '-'
  218. self.activeTxt.text.text = '-'
  219. end
  220. end
  221. function UIGuildInfoView:RefreshMoreInfoView()
  222. local moreInfo = self.controller:GetGuildMoreInfoData()
  223. if not moreInfo then
  224. self.noticeTxt.text.text = ''
  225. self.enterLimitTxt.text.text = '-'
  226. self.peopleTxt.text.text = '-'
  227. self.verifyTypeTxt.text.text = '-'
  228. return
  229. end
  230. if not moreInfo.recruitNotice or moreInfo.recruitNotice == '' then
  231. self.noticeTxt.text.text = string.formatbykey('GuildInfo_033')
  232. else
  233. self.noticeTxt.text.text = tostring(moreInfo.recruitNotice)
  234. end
  235. self.enterLimitTxt.text.text = tostring((moreInfo.recuritLevel or 999))
  236. self.peopleTxt.text.text = tostring(self.controller:GetGuildMemberNum()) .. '/' .. tostring(self.controller:GetGuildMemberLimit())
  237. self.verifyTypeTxt.text.text = self:GetGuildVerifyTypeStr(moreInfo.recuritType)
  238. end
  239. function UIGuildInfoView:RefreshMemberInfoView()
  240. local dataLength = self.controller:GetGuildMemberNum()
  241. local validLength = self.controller:GetValidMemberNum()
  242. self.loadStatusLoopListCtr:OnAllLoaded()
  243. self.loadStatusLoopListCtr:RefreshMaxDataLength(dataLength)
  244. self.loadStatusLoopListCtr:RefreshDataLength(validLength)
  245. end
  246. function UIGuildInfoView:RefreshApplyBtn()
  247. local moreInfo = self.controller:GetGuildMoreInfoData()
  248. if not moreInfo then
  249. self.btnEnter:SetActive(false)
  250. self.btnCancel:SetActive(false)
  251. self.appliedTag:SetActive(false)
  252. return
  253. end
  254. self.btnEnter.text.uILocalizeScript:SetContent(moreInfo.recuritType == Enum.GuildEnterVerifyType.NotVerify and 'BtnJoin' or 'BtnApplyJoin')
  255. local apply = not self.controller:IsInGuild() and self.controller:GetIsSubmitApply()
  256. self.btnEnter.button.interactable = (moreInfo.recuritType ~= Enum.GuildEnterVerifyType.Ban)
  257. self.btnEnter:SetActive(not apply)
  258. self.btnCancel:SetActive(apply)
  259. self.appliedTag:SetActive(apply)
  260. end
  261. function UIGuildInfoView:GetGuildVerifyTypeStr(VerifyType)
  262. if VerifyType == Enum.GuildEnterVerifyType.NotVerify then
  263. return string.formatbykey('GuildEnterType_01')
  264. elseif VerifyType == Enum.GuildEnterVerifyType.NeedVerify then
  265. return string.formatbykey('GuildEnterType_02')
  266. else
  267. return string.formatbykey('GuildEnterType_03')
  268. end
  269. end
  270. return UIGuildInfoView