KLUnionMemberListPanel.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. ---@class KLUnionMemberListPanel:UIKmlLuaPanelBase
  2. ---@field view KLUnionMemberListPanelView
  3. local KLUnionMemberListPanel = class(UIKmlLuaPanelBase)
  4. local this = KLUnionMemberListPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. -- 是否升序, nil表示不参与
  8. this.levelUpArrow = nil
  9. this.jobUpArrow = nil
  10. this.stateUpArrow = nil
  11. this.methodCompareList = {
  12. this.SortByState,
  13. this.SortByJob,
  14. this.SortByLevel,
  15. this.SortByName,
  16. }
  17. end
  18. -- 按照名字升降序
  19. -- 1表示true,-1表示false, 0表示equal
  20. -- 其他类似
  21. function this.SortByName(a, b)
  22. if a.name < b.name then
  23. return 1
  24. end
  25. return -1
  26. end
  27. function this.SortByLevel(a, b)
  28. if a.level == b.level then
  29. return 0
  30. end
  31. if this.levelUpArrow == false then
  32. if a.level < b.level then
  33. return 1
  34. else
  35. return -1
  36. end
  37. else
  38. if a.level <= b.level then
  39. return -1
  40. else
  41. return 1
  42. end
  43. end
  44. end
  45. function this.SortByJob(a, b)
  46. if a.position == b.position then
  47. return 0
  48. end
  49. if this.jobUpArrow == false then
  50. if a.position < b.position then
  51. return -1
  52. else
  53. return 1
  54. end
  55. else
  56. if a.position <= b.position then
  57. return 1
  58. else
  59. return -1
  60. end
  61. end
  62. end
  63. function this.SortByState(a, b)
  64. if a.onlineState == b.onlineState then
  65. -- 都是在线, 不比较
  66. if a.onlineState == 1 then
  67. return 0
  68. -- 都是离线, 比较离线时间
  69. else
  70. if this.stateUpArrow == false then
  71. if a.time < b.time then
  72. return 1
  73. else
  74. return -1
  75. end
  76. else
  77. if a.time <= b.time then
  78. return -1
  79. else
  80. return 1
  81. end
  82. end
  83. end
  84. end
  85. if this.stateUpArrow == false then
  86. if a.onlineState < b.onlineState then
  87. return 1
  88. else
  89. return -1
  90. end
  91. else
  92. if a.onlineState <= b.onlineState then
  93. return -1
  94. else
  95. return 1
  96. end
  97. end
  98. end
  99. -- 排序行会成员
  100. function this.SortMemberList()
  101. -- 先按在线情况, 在按职位,等级,名称排序
  102. table.sort(SL:UnionInfo_GetUnionMemberList(), function(a, b)
  103. local num = this.methodCompareList[1](a, b)
  104. if num == 0 then
  105. num = this.methodCompareList[2](a, b)
  106. if num == 0 then
  107. num = this.methodCompareList[3](a, b)
  108. if num == 0 then
  109. return this.methodCompareList[4](a, b) == 1 and true or false
  110. else
  111. return num == 1 and true or false
  112. end
  113. else
  114. return num == 1 and true or false
  115. end
  116. else
  117. return num == 1 and true or false
  118. end
  119. end)
  120. end
  121. ---创建或者刷新界面数据时调用
  122. function this:Refresh()
  123. SL:ReqViewUnionMessage()
  124. SL.HideMainPanel()
  125. end
  126. ---注册UI事件和服务器消息
  127. function this:RegistEvents()
  128. GUI:AddOnClickEvent(self.view.closeBtn, self, self.closeBtn)
  129. SL:RegisterLUAEvent(LUA_EVENT_VIEW_UNION, self.ResViewUnionMessage, self)
  130. SL:RegisterLUAEvent(LUA_EVENT_VIEW_UNION_CHANGE, self.ResViewUnionChangeMessage, self)
  131. GUI:AddOnClickEvent(self.view.title_level, self, self.title_level)
  132. GUI:AddOnClickEvent(self.view.title_position, self, self.title_position)
  133. GUI:AddOnClickEvent(self.view.title_state, self, self.title_state)
  134. GUI:AddOnClickEvent(self.view.shen_he, self, self.shen_he)
  135. end
  136. ---@param message UnionProto.ViewUnionRes
  137. function this:ResViewUnionChangeMessage(_, message)
  138. self:ResViewUnionMessage(_, message)
  139. end
  140. function this:Setshen_heTipText()
  141. local unionInfo = SL:UnionInfo_GetUnionMemberList()
  142. local allnum = table.count(unionInfo)
  143. local onlinenum = 0
  144. if unionInfo and allnum > 0 then
  145. for i, v in pairs(unionInfo) do
  146. if v.onlineState == 1 then
  147. onlinenum = onlinenum + 1
  148. end
  149. end
  150. end
  151. local linestr = onlinenum.."/"..allnum
  152. local tipdes ="连续".."<color=#1add1f>".."3天".. "</color>".."活跃成员少于".."<color=#1add1f>".."5人".. "</color>".."战盟可能会被解散"
  153. local linedes = "在线人数".."<color=#1add1f>"..linestr.. "</color>"
  154. GUI:Text_setString(self.view.tips, tipdes)
  155. GUI:Text_setString(self.view.on_line_tips, linedes)
  156. end
  157. function this:shen_he()
  158. GUI:UIPanel_Open("dev/ui/Union/Panel/KLUnionApplyList/KLUnionApplyListPanel")
  159. end
  160. function this:title_position()
  161. self:ResetArrow()
  162. if this.jobUpArrow == nil then
  163. this.jobUpArrow = true
  164. GUI:setVisible(self.view.position_sort_up_black, true)
  165. else
  166. if this.jobUpArrow then
  167. this.jobUpArrow = false
  168. GUI:setVisible(self.view.position_sort_down_black, true)
  169. else
  170. this.jobUpArrow = true
  171. GUI:setVisible(self.view.position_sort_up_black, true)
  172. end
  173. end
  174. this.levelUpArrow = nil
  175. this.stateUpArrow = nil
  176. this.methodCompareList = {
  177. this.SortByJob,
  178. this.SortByState,
  179. this.SortByLevel,
  180. this.SortByName,
  181. }
  182. this.SortMemberList()
  183. GUI:DataListUpdateData(self.view.union_data_list)
  184. end
  185. function this:title_state()
  186. self:ResetArrow()
  187. if this.stateUpArrow == nil then
  188. this.stateUpArrow = true
  189. GUI:setVisible(self.view.state_sort_up_black, true)
  190. else
  191. if this.stateUpArrow then
  192. this.stateUpArrow = false
  193. GUI:setVisible(self.view.state_sort_down_black, true)
  194. else
  195. this.stateUpArrow = true
  196. GUI:setVisible(self.view.state_sort_up_black, true)
  197. end
  198. end
  199. this.levelUpArrow = nil
  200. this.jobUpArrow = nil
  201. this.methodCompareList = {
  202. this.SortByState,
  203. this.SortByJob,
  204. this.SortByLevel,
  205. this.SortByName,
  206. }
  207. this.SortMemberList()
  208. GUI:DataListUpdateData(self.view.union_data_list)
  209. end
  210. function this:title_level()
  211. self:ResetArrow()
  212. if this.levelUpArrow == nil then
  213. this.levelUpArrow = true
  214. GUI:setVisible(self.view.level_sort_up_black, true)
  215. else
  216. if this.levelUpArrow then
  217. this.levelUpArrow = false
  218. GUI:setVisible(self.view.level_sort_down_black, true)
  219. else
  220. this.levelUpArrow = true
  221. GUI:setVisible(self.view.level_sort_up_black, true)
  222. end
  223. end
  224. this.stateUpArrow = nil
  225. this.jobUpArrow = nil
  226. this.methodCompareList = {
  227. this.SortByLevel,
  228. this.SortByState,
  229. this.SortByJob,
  230. this.SortByName,
  231. }
  232. this.SortMemberList()
  233. GUI:DataListUpdateData(self.view.union_data_list)
  234. end
  235. -- 重置排序箭头
  236. function this:ResetArrow()
  237. GUI:setVisible(self.view.level_sort_up_black, false)
  238. GUI:setVisible(self.view.level_sort_down_black, false)
  239. GUI:setVisible(self.view.position_sort_down_black, false)
  240. GUI:setVisible(self.view.position_sort_up_black, false)
  241. GUI:setVisible(self.view.state_sort_down_black, false)
  242. GUI:setVisible(self.view.state_sort_up_black, false)
  243. end
  244. function this:closeBtn()
  245. GUI:UIPanel_Close("dev/ui/Union/Panel/KLUnionMemberList/KLUnionMemberListPanel")
  246. GUI:UIPanel_Close("dev/ui/Union/Panel/KLUnionToggleList/KLUnionToggleListPanel")
  247. GUI:UIPanel_Close("dev/ui/Union/Panel/KLUnionInfo/KLUnionInfoPanel")
  248. end
  249. ---@param message UnionProto.ViewUnionRes
  250. function this:ResViewUnionMessage(_, message)
  251. SL:UnionInfo_SetUnionMemberList(message.unionInfo.unionMemberInfo)
  252. this.SortMemberList()
  253. GUI:DataListInitData(self.view.union_data_list, function()
  254. return table.count(SL:UnionInfo_GetUnionMemberList())
  255. end,
  256. function()
  257. end,
  258. function()
  259. end,
  260. function(realIndex)
  261. local unionInfo = SL:UnionInfo_GetUnionMemberList()[realIndex + 1]
  262. local name = GUI:GetChildControl(self.view.union_data_list, realIndex, 'name')
  263. local level = GUI:GetChildControl(self.view.union_data_list, realIndex, 'level')
  264. local position = GUI:GetChildControl(self.view.union_data_list, realIndex, 'position')
  265. local state = GUI:GetChildControl(self.view.union_data_list, realIndex, 'state')
  266. GUI:Text_setString(name, unionInfo.name)
  267. GUI:Text_setString(level, tostring(unionInfo.level))
  268. GUI:Text_setString(position, EUnionPositionToName[unionInfo.position])
  269. GUI:Text_setTextColor(position, string.replace(EUnionPositionToColor[unionInfo.position], '0x', '#'))
  270. if unionInfo.onlineState == 1 then
  271. GUI:Text_setString(state, "在线")
  272. GUI:Text_setTextColor(state, "#00ff00")
  273. else
  274. -- 离线时间计算
  275. local leaveSecond = (Time.GetServerTime() - unionInfo.time)//1000
  276. if leaveSecond < 3600 then
  277. GUI:Text_setString(state, "离线")
  278. elseif leaveSecond < 86400 then
  279. GUI:Text_setString(state, string.format("离线%d小时", leaveSecond // 3600))
  280. else
  281. GUI:Text_setString(state, string.format("离线%d天", leaveSecond // 86400))
  282. end
  283. GUI:Text_setTextColor(state, "#8E8E8E")
  284. end
  285. local btn = GUI:GetChildControl(self.view.union_data_list, realIndex, 'datalist_panel_btn_')
  286. GUI:AddOnClickEvent(btn, self, self.memberOnClick, {unionInfo = unionInfo})
  287. end)
  288. GUI:DataListUpdateData(self.view.union_data_list)
  289. self:Setshen_heTipText()
  290. if SL:UnionInfo_IsPowerMan() then
  291. GUI:setVisible(self.view.shen_he, true)
  292. else
  293. GUI:setVisible(self.view.shen_he, false)
  294. end
  295. end
  296. function this:memberOnClick(_, eventData)
  297. local unionInfo = eventData.unionInfo
  298. if unionInfo.memberId == SL:GetMetaValue(EMetaVarGetKey.UID) then
  299. return
  300. end
  301. GUI:UIPanel_Open("dev/ui/Union/Panel/KLUnionMemberInfo/KLUnionMemberInfoPanel", nil, nil, {memberInfo=unionInfo})
  302. end
  303. function this:Close()
  304. end
  305. return this