KLUnionInfoPanel.lua 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. ---@class KLUnionInfoPanel:UIKmlLuaPanelBase
  2. ---@field view KLUnionInfoPanelView
  3. local KLUnionInfoPanel = class(UIKmlLuaPanelBase)
  4. local this =KLUnionInfoPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. end
  8. ---创建或者刷新界面数据时调用
  9. function this:Refresh()
  10. SL:ReqViewUnionMessage()
  11. SL:ReqUnionMemberDynamicMessage()
  12. GUI:setVisible(self.view.btn_Impeach, false)
  13. GUI:setVisible(self.view.btn_Replace, false)
  14. ---放到KLUnionToggleListPanel界面请求,如果没有数据(网络延时等等),重新请求一次
  15. local info = InfoManager.unionElectionInfo.MyUnionInfo
  16. if InfoManager.unionElectionInfo.MyUnionInfo then
  17. self:RES_GET_UNION_INFO(_, info)
  18. else
  19. self.timer = SL:ScheduleOnce(Time.deltaTime,function()
  20. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_GET_UNION_INFO)
  21. end)
  22. end
  23. end
  24. function this:StopTimer()
  25. if self.timer then
  26. SL:UnSchedule(self.timer)
  27. self.timer = nil
  28. end
  29. end
  30. ---注册UI事件和服务器消息
  31. function this:RegistEvents()
  32. SL:RegisterLUAEvent(LUA_EVENT_VIEW_UNION,self.ResViewUnionMessage, self)
  33. SL:RegisterLUAEvent(LUA_EVENT_UNION_MEMBER_DYNAMIC,self.ResUnionMemberDynamicMessage, self)
  34. SL:RegisterLUAEvent(LUA_EVENT_UNION_NAME_VIEW,self.ResUnionNameViewMessage, self)
  35. SL:RegisterLUAEvent(LUA_EVENT_QUIT_UNION,self.ResQuitUnionMessage, self)
  36. SL:RegisterLUAEvent(LUA_EVENT_UNION_MEMBER_CHANGE,self.ResUnionMemberChangeMessage, self)
  37. SL:RegisterLUAEvent(LUA_EVENT_VIEW_UNION_CHANGE,self.ResViewUnionChangeMessage, self)
  38. GUI:AddOnClickEvent(self.view.exitButton, self, self.exitButton)
  39. GUI:AddOnClickEvent(self.view.changeUnionNameBtn, self, self.changeUnionNameBtn)
  40. GUI:AddOnClickEvent(self.view.btn_panel_name_no, self, self.btn_panel_name_no)
  41. GUI:AddOnClickEvent(self.view.btn_panel_name_yes, self, self.btn_panel_name_yes)
  42. GUI:AddOnClickEvent(self.view.btn_3DItem, self, self.btn_3DItem)
  43. GUI:AddOnClickEvent(self.view.CloseButton, self, self.CloseButton)
  44. GUI:AddOnClickEvent(self.view.changeFlagBtn, self, self.changeFlagBtn)
  45. GUI:AddOnClickEvent(self.view.changeAnnoyBtn, self, self.changeAnnoyBtn)
  46. GUI:AddOnClickEvent(self.view.btn_panel_report_yes, self, self.btn_panel_report_yes)
  47. GUI:AddOnClickEvent(self.view.btn_panel_report_no, self, self.btn_panel_report_no)
  48. GUI:AddOnClickEvent(self.view.reportMask, self, self.reportMask)
  49. GUI:AddOnClickEvent(self.view.nameMask, self, self.nameMask)
  50. GUI:AddOnClickEvent(self.view.inexpAddButton, self, self.inexpAddButton)
  51. GUI:AddOnClickEvent(self.view.btn_Impeach, self, self.OnClickBtnImpeach)
  52. GUI:AddOnClickEvent(self.view.btn_Election, self, self.OnClickBtnElection)
  53. GUI:AddOnClickEvent(self.view.btn_Replace, self, self.OnClickBtnReplace)
  54. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_GET_UNION_INFO, self.RES_GET_UNION_INFO, self)
  55. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_UNION_LEADER_ON_LINE_STATE, self.RES_GET_UNION_INFO, self)
  56. end
  57. function this:RES_GET_UNION_INFO(id, message)
  58. self.outUnionInfo = message
  59. self:StopCountDownReqUnionInfo()
  60. if tostring(message.leaderid) ~= "0" then
  61. GUI:setVisible(self.view.btn_Election, false)
  62. local myId = SL:GetMetaValue(EMetaVarGetKey.MAIN_ACTOR_ID)
  63. if tonumber(myId) == tonumber(message.leaderid) then
  64. --盟主是自己的时候不显示取代和弹劾
  65. GUI:setVisible(self.view.btn_Replace, false)
  66. GUI:setVisible(self.view.btn_Impeach, false)
  67. return
  68. end
  69. --有盟主显示 弹劾或者取代
  70. ---@type cfg_unionLevel_column
  71. local cfg = SL:GetConfig("cfg_unionLevel", tonumber(message.unionlevel), "unionLevel")
  72. local leaderInfo = message.memberinfos[tostring(message.leaderid)]
  73. local now = tonumber(SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME))
  74. local deltaTime = now - tonumber(leaderInfo.quitlinetime)
  75. if deltaTime > cfg.continuousOfflineTime * 60000 and tostring( leaderInfo.online) ~= "true" then
  76. --盟主离线cfg.continuousOfflineTime分钟后,显示取代
  77. GUI:setVisible(self.view.btn_Replace, true)
  78. GUI:setVisible(self.view.btn_Impeach, false)
  79. local endTime = InfoManager.unionElectionInfo:GetReplaceEndTime()
  80. if endTime then
  81. if tonumber(endTime) <= now then
  82. GUI:setVisible(self.view.btn_Replace, false)
  83. end
  84. end
  85. else
  86. GUI:setVisible(self.view.btn_Replace, false)
  87. GUI:setVisible(self.view.btn_Impeach, true)
  88. local delta = cfg.continuousOfflineTime * 60000 - deltaTime
  89. if delta > 0 and tostring(leaderInfo.online) ~= "true" then
  90. --计算盟主的离线时间 当打到取代条件时刷新界面显示取代按钮
  91. self.countDownReq = SL:ScheduleOnce((delta)/1000 + 1, function()
  92. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_GET_UNION_INFO)
  93. end)
  94. end
  95. end
  96. else
  97. --无盟主状态下显示竞选
  98. GUI:setVisible(self.view.btn_Election, true)
  99. local endTime = InfoManager.unionElectionInfo:GetElectionEndTime()
  100. if endTime then
  101. local now = SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)
  102. if tonumber(endTime) <= tonumber(now) then
  103. GUI:setVisible(self.view.btn_Election, false)
  104. end
  105. end
  106. GUI:setVisible(self.view.btn_Replace, false)
  107. GUI:setVisible(self.view.btn_Impeach, false)
  108. end
  109. end
  110. function this:StopCountDownReqUnionInfo()
  111. if self.countDownReq then
  112. SL:UnSchedule(self.countDownReq)
  113. end
  114. self.countDownReq = nil
  115. end
  116. --弹劾盟主
  117. function this:OnClickBtnImpeach()
  118. local data = InfoManager.unionElectionInfo:GetCampaignData()
  119. if table.isNullOrEmpty(data) then
  120. if not self.outUnionInfo then
  121. return
  122. end
  123. local onTime = tonumber(self.outUnionInfo.leaderontime)
  124. local nowTime = tonumber(SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME))
  125. local deltaTime = nowTime - onTime
  126. ---@type cfg_unionLevel_column
  127. local cfg = SL:GetConfig("cfg_unionLevel", self.unionInfo.unionLevel, "unionLevel")
  128. if deltaTime < cfg.abdicationTime * 60 * 1000 then
  129. SL:MessageTip({id=298})---盟主在位没有超过3天,不能弹劾
  130. return
  131. end
  132. GUI:UIPanel_Open("dev/outui/Union/Panel/KLUnionLeaderOperate/KLUnionLeaderOperatePanel",
  133. _, _, {type = 2, unionLevel = self.unionInfo.unionLevel})
  134. else
  135. SL:onLUAEvent(LUA_EVENT_CHANGE_UNION_FUNCTION, "campaignToggle")
  136. end
  137. end
  138. --竞选盟主
  139. function this:OnClickBtnElection()
  140. local data = InfoManager.unionElectionInfo:GetElectionDataList()
  141. if table.count(data) > 0 then
  142. SL:onLUAEvent(LUA_EVENT_CHANGE_UNION_FUNCTION, "electionToggle")
  143. else
  144. GUI:UIPanel_Open("dev/outui/Union/Panel/KLUnionLeaderOperate/KLUnionLeaderOperatePanel",
  145. _, _, {type = 1, unionLevel = self.unionInfo.unionLevel})
  146. end
  147. end
  148. --取代盟主
  149. function this:OnClickBtnReplace()
  150. local data = InfoManager.unionElectionInfo:GetReplaceDataList()
  151. if table.count(data) > 0 then
  152. SL:onLUAEvent(LUA_EVENT_CHANGE_UNION_FUNCTION, "replaceToggle")
  153. else
  154. if not self.outUnionInfo then
  155. return
  156. end
  157. local onTime = tonumber(self.outUnionInfo.leaderontime)
  158. local nowTime = tonumber(SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME))
  159. local deltaTime = nowTime - onTime
  160. ---@type cfg_unionLevel_column
  161. local cfg = SL:GetConfig("cfg_unionLevel", self.unionInfo.unionLevel, "unionLevel")
  162. if deltaTime < cfg.abdicationTime * 60 * 1000 then
  163. SL:TipMessage(SL:GetConfig('cfg_string',298).text, 1, NoticeType.NoticeLeftBottom)--,"盟主在位没有超过3天,不能取代",
  164. return
  165. end
  166. GUI:UIPanel_Open("dev/outui/Union/Panel/KLUnionLeaderOperate/KLUnionLeaderOperatePanel",
  167. _, _, {type = 3, unionLevel = self.unionInfo.unionLevel})
  168. end
  169. end
  170. function this:inexpAddButton()
  171. SL:CommonItemGetPath(nil, 10090001)
  172. end
  173. ---@param message UnionProto.ViewUnionRes
  174. function this:ResViewUnionChangeMessage(_, message)
  175. SL:ReqUnionMemberDynamicMessage()
  176. self:ResViewUnionMessage(_, message)
  177. end
  178. function this:nameMask()
  179. --GUI:setVisible(self.view.unionNameModify, false)
  180. self:btn_panel_name_no()
  181. end
  182. function this:reportMask()
  183. --GUI:setVisible(self.view.panel_report, false)
  184. self:btn_panel_report_no()
  185. end
  186. ---@param message UnionProto.UnionMemberChangeRes
  187. function this:ResUnionMemberChangeMessage(_, message)
  188. --
  189. --local isBoss = false
  190. --for _, memberInfo in pairs(message.unionMemberInfo) do
  191. -- if memberInfo.memberId == SL:GetMetaValue(EMetaVarGetKey.UID) and memberInfo.position == 1 then
  192. -- isBoss = true
  193. -- end
  194. --end
  195. --if isBoss then
  196. -- GUI:setVisible(self.view.changeUnionNameBtn,true)
  197. -- GUI:setVisible(self.view.changeAnnoyBtn,true)
  198. -- GUI:setVisible(self.view.changeFlagBtn,true)
  199. --else
  200. -- GUI:setVisible(self.view.changeUnionNameBtn,false)
  201. -- GUI:setVisible(self.view.changeAnnoyBtn,false)
  202. -- GUI:setVisible(self.view.changeFlagBtn,false)
  203. --end
  204. end
  205. function this:ResQuitUnionMessage()
  206. self:CloseButton()
  207. end
  208. function this:btn_panel_report_yes()
  209. SL:ReqChangeAnnouncementMessage(GUI:Button_getTitleText(self.view.noticeInput))
  210. GUI:setVisible(self.view.panel_report, false)
  211. end
  212. function this:btn_panel_report_no()
  213. GUI:setVisible(self.view.panel_report, false)
  214. end
  215. function this:changeAnnoyBtn()
  216. GUI:setVisible(self.view.panel_report, true)
  217. GUI:Button_setTitleText(self.view.noticeInput, "")
  218. end
  219. function this:changeFlagBtn()
  220. GUI:UIPanel_Close("dev/ui/Union/Panel/KLUnionMemberList/KLUnionMemberListPanel")
  221. GUI:UIPanel_Open("dev/ui/Union/Panel/KLUnionModifyFlag/KLUnionModifyFlagPanel", nil, nil, {unionInfo=self.unionInfo})
  222. end
  223. function this:CloseButton()
  224. GUI:UIPanel_Close("dev/ui/Union/Panel/KLUnionMemberList/KLUnionMemberListPanel")
  225. GUI:UIPanel_Close("dev/ui/Union/Panel/KLUnionToggleList/KLUnionToggleListPanel")
  226. GUI:UIPanel_Close("dev/ui/Union/Panel/KLUnionInfo/KLUnionInfoPanel")
  227. GUI:UIPanel_Close("dev/ui/Union/Panel/KLUnionModifyFlag/KLUnionModifyFlagPanel")
  228. end
  229. function this:changeUnionNameBtn()
  230. if InfoManager.loranSiegeInfo:GetIsOpen() then
  231. SL:TipMessage(SL:GetConfig("cfg_string",16009).text ,1, NoticeType.NoticeMid)
  232. return
  233. end
  234. --GUI:setVisible(self.view.unionNameModify, true)
  235. GUI:UIPanel_Open("dev/outui/ReName/Panel/KLRoleReName/KLRoleReNamePanel", nil, nil, {title="rename",des="请输入新的战盟名称:",cfgId=60090003})
  236. end
  237. function this:btn_3DItem()
  238. local needItemInfo = string.split(SL:GetConfig('cfg_global', 1600).value,'|')[1]
  239. local needItemInfo1 = string.split(needItemInfo, '#')
  240. local itemId = tonumber(needItemInfo1[1])
  241. SL:OpenTips(nil, itemId)
  242. end
  243. ---@param message UnionProto.ChangeUnionNameViewRes
  244. function this:ResUnionNameViewMessage(_, message)
  245. local isChange = message.isChange
  246. GUI:setVisible(self.view.unionNameModify, true)
  247. local needItemInfo = string.split(SL:GetConfig('cfg_global', 1600).value,'|')[1]
  248. local needItemInfo1 = string.split(needItemInfo, '#')
  249. local itemId = tonumber(needItemInfo1[1])
  250. local needCount = tonumber(needItemInfo1[2])
  251. GUI:Item_setItemId(self.view.cost_item, itemId)
  252. GUI:setVisible(self.view.cost_item, true)
  253. if isChange then
  254. GUI:Text_setString(self.view.cost_txt_count, tostring(needCount))
  255. if needCount <= SL:GetBagItemCount(itemId) then
  256. GUI:Text_setTextColor(self.view.cost_txt_count, "#FFFFFF")
  257. else
  258. GUI:Text_setTextColor(self.view.cost_txt_count, "#FF0000")
  259. end
  260. else
  261. GUI:Text_setString(self.view.cost_txt_count, "免费改名")
  262. end
  263. end
  264. function this:btn_panel_name_no()
  265. GUI:setVisible(self.view.unionNameModify, false)
  266. GUI:setVisible(self.view.cost_item, false)
  267. GUI:Button_setTitleText(self.view.warAllianceNameInput, "")
  268. end
  269. function this:btn_panel_name_yes()
  270. SL:ReqChangeUnionNameMessage(GUI:Button_getTitleText(self.view.warAllianceNameInput))
  271. GUI:setVisible(self.view.unionNameModify, false)
  272. GUI:setVisible(self.view.cost_item, false)
  273. end
  274. function this:exitButton()
  275. if InfoManager.loranSiegeInfo:GetIsOpen() then
  276. SL:TipMessage(SL:GetConfig("cfg_string",16007).text ,1, NoticeType.NoticeMid)
  277. return
  278. end
  279. if SL:UnionInfo_IsBoos() then
  280. if SL:UnionInfo_GetAllNum() == 1 then
  281. SL:CommonTipsMessage({stringTblID=239,
  282. showTips = "退出后,该战盟将被解散,所有战盟资源,成长都将被清除!",
  283. callback = function()
  284. SL:ReqQuitUnionMessage()
  285. end,
  286. })
  287. else
  288. SL:ReqQuitUnionMessage()
  289. end
  290. else
  291. SL:CommonTipsMessage({stringTblID=240,
  292. showTips = "是否确定退出战盟",
  293. callback = function()
  294. SL:ReqQuitUnionMessage()
  295. end,
  296. --cancelCallBack = function()
  297. --
  298. --end
  299. })
  300. end
  301. end
  302. function this:Close()
  303. self:StopCountDownReqUnionInfo()
  304. self:StopTimer()
  305. end
  306. ---@param message UnionProto.ViewUnionRes
  307. function this:ResViewUnionMessage(_, message)
  308. local unionInfo = message.unionInfo
  309. self.unionInfo = unionInfo
  310. GUI:Text_setString(self.view.unionName, unionInfo.unionName)
  311. GUI:Text_setString(self.view.levelValue, tostring(unionInfo.unionLevel))
  312. if SL:HasConfig('cfg_unionLevel', unionInfo.unionLevel+1, 'unionLevel') then
  313. local nextExp = SL:GetConfig('cfg_unionLevel', unionInfo.unionLevel, 'unionLevel').unionExp
  314. GUI:Text_setString(self.view.inexpValue, unionInfo.unionExp .. "/" .. nextExp)
  315. else
  316. GUI:Text_setString(self.view.inexpValue, tostring(unionInfo.unionExp))
  317. end
  318. --local nextExp = SL:GetConfig('cfg_unionLevel', unionInfo.unionLevel, 'unionLevel').unionExp
  319. --GUI:Text_setString(self.view.inexpValue, unionInfo.unionExp .. "/" .. nextExp)
  320. local maxPeople = SL:GetConfig('cfg_unionLevel', unionInfo.unionLevel, 'unionLevel').playerNumber
  321. GUI:Text_setString(self.view.peopleCountValue, table.count(unionInfo.unionMemberInfo) .. "/" .. maxPeople)
  322. GUI:Text_setString(self.view.inMoneyValue, tostring(unionInfo.unionCapital))
  323. local bossName = this.GetBossName(unionInfo.unionMemberInfo)
  324. GUI:Text_setString(self.view.bossValue, bossName)
  325. GUI:Image_loadTexture(self.view.flag_img, string.format("Texture/log%s.png",unionInfo.unionArmband), "")
  326. GUI:Text_setString(self.view.inUnionAnnoy, unionInfo.announcement)
  327. --GUI:Text_setString(self.view.inUnionEnemy, "无")
  328. if this.GetIsPowerMan(unionInfo.unionMemberInfo) then
  329. GUI:setVisible(self.view.changeUnionNameBtn,true)
  330. GUI:setVisible(self.view.changeAnnoyBtn,true)
  331. GUI:setVisible(self.view.changeFlagBtn,true)
  332. else
  333. GUI:setVisible(self.view.changeUnionNameBtn,false)
  334. GUI:setVisible(self.view.changeAnnoyBtn,false)
  335. GUI:setVisible(self.view.changeFlagBtn,false)
  336. end
  337. end
  338. ---@param message UnionProto.UnionMemberDynamic
  339. function this:ResUnionMemberDynamicMessage(_, message)
  340. GUI:Text_setString(self.view.inMemberState, this.GetMemberDynamicText(message.memberDynamic))
  341. end
  342. function this.GetBossName(unionMemberList)
  343. for _, memberInfo in pairs(unionMemberList) do
  344. -- 是盟主或副盟主
  345. if memberInfo.position == 1 then
  346. return memberInfo.name
  347. end
  348. end
  349. return "无"
  350. end
  351. ---@param unionMemberList UnionProto.UnionMemberInfo[]
  352. function this.GetIsPowerMan(unionMemberList)
  353. for _, memberInfo in pairs(unionMemberList) do
  354. -- 是盟主或副盟主
  355. if memberInfo.memberId == SL:GetMetaValue(EMetaVarGetKey.UID) and (memberInfo.position == 1 or memberInfo.position == 2) then
  356. return true
  357. end
  358. end
  359. return false
  360. end
  361. -- 拼接成员动态相关
  362. function this.GetMemberDynamicText(dynamicList)
  363. local ret = ""
  364. for _, dynamicInfo in pairs(dynamicList) do
  365. local time = dynamicInfo.time
  366. -- 时间戳转时间
  367. ret = ret .. os.date("%Y-%m-%d<color=#00000000>.</color>%H:%M:%S", time) .. "<color=#00000000>..</color>"
  368. -- 修改职位
  369. if dynamicInfo.type == 1 then
  370. local preColor = EUnionPositionToColor[dynamicInfo.memberPosition]
  371. local nowColor = EUnionPositionToColor[dynamicInfo.changePosition]
  372. -- 之前职位文本
  373. ret = ret .. string.format("<color=%s>%s</color>", Misc.TransUnityColorToTableColor(preColor), EUnionPositionToName[dynamicInfo.memberPosition])
  374. -- 名字文本
  375. ret = ret .. string.format("<color=#00ff00ff>%s</color>", dynamicInfo.memberName) .. '成为了'
  376. -- 改变后的职位文本
  377. ret = ret .. string.format("<color=%s>%s</color>", Misc.TransUnityColorToTableColor(nowColor), EUnionPositionToName[dynamicInfo.changePosition]) .. "\n"
  378. elseif dynamicInfo.type == 2 then
  379. ret = ret .. string.format("<color=#00ff00ff>%s</color>", dynamicInfo.memberName) .. '加入了战盟' .. "\n"
  380. elseif dynamicInfo.type == 3 then
  381. local color = EUnionPositionToColor[dynamicInfo.memberPosition]
  382. -- 被踢的人的文本
  383. ret = ret .. string.format("<color=#00ff00ff>%s</color>", dynamicInfo.memberName) .. '被'
  384. -- 踢的人的职位
  385. ret = ret .. string.format("<color=%s>%s</color>", Misc.TransUnityColorToTableColor(color), EUnionPositionToName[dynamicInfo.masterPosition])
  386. ret = ret .. string.format("<color=#00ff00ff>%s</color>", dynamicInfo.masterName) .. '踢出了战盟' .. "\n"
  387. -- 退出战盟
  388. elseif dynamicInfo.type == 4 then
  389. -- 盟主或副盟主和成员的退出发的字段不一样
  390. if dynamicInfo.memberName ~= nil then
  391. ret = ret .. string.format("<color=#00ff00ff>%s</color>", dynamicInfo.memberName) .. '退出了战盟' .. "\n"
  392. else
  393. ret = ret .. string.format("<color=#00ff00ff>%s</color>", dynamicInfo.masterName) .. '退出了战盟' .. "\n"
  394. end
  395. -- 宣战
  396. elseif dynamicInfo.type == 5 then
  397. ret = ret .. string.format("<color=#00ff00ff>%s</color>", dynamicInfo.masterName) .. '对'
  398. ret = ret .. string.format("<color=#00ff00ff>%s</color>", dynamicInfo.enemyName) .. '正式发起宣战!' .. "\n"
  399. end
  400. end
  401. return ret
  402. end
  403. return this