KLUnionLeaderOperatePanel.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. ---@class KLUnionLeaderOperatePanel:UIKmlLuaPanelBase
  2. ---@field view KLUnionLeaderOperatePanelView
  3. local KLUnionLeaderOperatePanel = class(UIKmlLuaPanelBase)
  4. local this =KLUnionLeaderOperatePanel
  5. ---创建时调用一次
  6. function this:Init()
  7. self.typeStr = {
  8. [1] = "竞选",
  9. [2] = "弹劾",
  10. [3] = "取代",
  11. }
  12. self.type = self.args.type or 1
  13. self.isAgree = self.args.isAgree --战盟弹劾 赞成票还是反对票
  14. local level = self.args.unionLevel --战盟等级
  15. --条件
  16. local tbl = SL:GetConfigTable("cfg_unionLevel")
  17. ---@type cfg_unionLevel_column
  18. local cfg = SL:GetConfig("cfg_unionLevel", level, "unionLevel")
  19. local condTbl
  20. local costTbl
  21. local checkCondTbl
  22. if self.type == EUnionLeaderOperateType.Election then
  23. condTbl = cfg.text
  24. costTbl = cfg.cast
  25. checkCondTbl = cfg.electionConditions
  26. elseif self.type == EUnionLeaderOperateType.Campaign then
  27. condTbl = cfg.campaignText
  28. costTbl = cfg.campaignCast
  29. checkCondTbl = cfg.campaignCondition
  30. if self.isAgree ~= nil then
  31. costTbl = cfg.campaignVoteCast
  32. end
  33. elseif self.type == EUnionLeaderOperateType.Replace then
  34. condTbl = cfg.replaceText
  35. costTbl = cfg.replaceCast
  36. checkCondTbl = cfg.replaceConditions
  37. end
  38. local green = "#00ff00"
  39. local red = "#9b1818"
  40. if condTbl and condTbl[1] then
  41. GUI:setVisible(self.view.txtCond1, true)
  42. local can = false
  43. if checkCondTbl then
  44. can = ConditionManager.Check(checkCondTbl)
  45. end
  46. GUI:Text_setString(self.view.txtCond1, string.format(condTbl[1], can and green or red))
  47. else
  48. GUI:setVisible(self.view.txtCond1, false)
  49. end
  50. if condTbl and condTbl[2] then
  51. GUI:setVisible(self.view.txtCond2, true)
  52. local can = false
  53. if checkCondTbl then
  54. can = ConditionManager.Check(checkCondTbl)
  55. end
  56. GUI:Text_setString(self.view.txtCond2, string.format(condTbl[2], can and green or red))
  57. else
  58. GUI:setVisible(self.view.txtCond2, false)
  59. end
  60. self.costTbl = costTbl
  61. self.checkCondTbl = checkCondTbl
  62. if costTbl and costTbl[1] then
  63. GUI:setVisible(self.view.BgCost, true)
  64. local own = SL:GetBagItemCount(costTbl[1])
  65. GUI:Text_setString(self.view.textCost, string.format("<color=%s>%s</color>",
  66. own >= costTbl[2] and "#1BE419" or "#9b1818", costTbl[2]))
  67. GUI:Item_UpdataData(self.view.item17, {
  68. ["itemid"] = costTbl[1],
  69. })
  70. else
  71. GUI:setVisible(self.view.BgCost, false)
  72. end
  73. local str = self.typeStr[self.type]
  74. GUI:Text_setString(self.view.txtTitle, "盟主"..str)
  75. GUI:Text_setString(self.view.txtDesc, string.format("是否确定 <color=#00ff00ff>%s</color> 战盟盟主", str))
  76. GUI:Text_setString(self.view.txtCondTitle, str.."条件:")
  77. end
  78. ---创建或者刷新界面数据时调用
  79. function this:Refresh()
  80. end
  81. ---注册UI事件和服务器消息
  82. function this:RegistEvents()
  83. GUI:AddOnClickEvent(self.view.btnCancel, self, self.CloseSelf)
  84. GUI:AddOnClickEvent(self.view.BtnMask, self, self.CloseSelf)
  85. GUI:AddOnClickEvent(self.view.btnConfirm, self, self.ConfirmOnClick)
  86. end
  87. function this:ConfirmOnClick()
  88. --先判断消耗是否够
  89. local costTbl = self.costTbl
  90. local costEnough = true
  91. if costTbl and costTbl[1] then
  92. local own = SL:GetBagItemCount(costTbl[1])
  93. costEnough = own >= costTbl[2]
  94. end
  95. if not costEnough then
  96. SL:TipMessage(SL:GetConfig('cfg_string',269).text,1, NoticeType.NoticeMid)--"货币不足",
  97. return
  98. end
  99. if self.checkCondTbl then
  100. if not ConditionManager.Check(self.checkCondTbl) then
  101. SL:TipMessage(SL:GetConfig('cfg_string',284).text,1, NoticeType.NoticeMid)--"条件不满足",
  102. return
  103. end
  104. end
  105. if self.type == EUnionLeaderOperateType.Campaign then
  106. if self.isAgree == nil then
  107. --弹劾协议
  108. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_UNION_IMPEACH_LEADER)
  109. else
  110. --弹劾投票协议
  111. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_UNION_IMPEACH_VOTE, self.isAgree and 1 or 0)
  112. end
  113. else
  114. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_PLAYER_RUN_FOR_LEADER)
  115. end
  116. self:CloseSelf()
  117. end
  118. function this:CloseSelf()
  119. GUI:UIPanel_Close(self.filePath)
  120. end
  121. function this:Close()
  122. end
  123. return this