KLRoleReNamePanel.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. ---@class KLRoleReNamePanel:UIKmlLuaPanelBase
  2. ---@field view KLRoleReNamePanelView
  3. local KLRoleReNamePanel = class(UIKmlLuaPanelBase)
  4. local this =KLRoleReNamePanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. end
  10. ---注册UI事件和服务器消息
  11. function this:RegistEvents()
  12. GUI:AddOnClickEvent(self.view.closeBtn,self,self.OnClickCloseBtn)
  13. GUI:AddOnClickEvent(self.view.cancelBtn,self,self.OnClickCloseBtn)
  14. GUI:AddOnClickEvent(self.view.okBtn,self,self.OnClickOkBtn)
  15. GUI:Input_SetOnEndEdit(self.view.input,self,self.OnValueChangeInputEnd)
  16. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_GET_UNION_INFO, self.ResUnionInfo, self)
  17. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ROLE_IS_FIRST_CHANGE_NAME, self.RES_ROLE_IS_FIRST_CHANGE_NAME, self)
  18. end
  19. function this:OnClickCloseBtn()
  20. GUI:UIPanel_Close("dev/outui/ReName/Panel/KLRoleReName/KLRoleReNamePanel")
  21. end
  22. function this:OnClickOkBtn()
  23. if string.isNullOrEmpty(self.name) then
  24. GUI:UIPanel_Open("dev/outui/Activity/Panel/KLSure/KLSurePanel",nil,nil,{okFunc= function()
  25. GUI:UIPanel_Close("dev/outui/Activity/Panel/KLSure/KLSurePanel")
  26. end
  27. ,content="名字不能为空"})
  28. return
  29. end
  30. if self.ischangename and not self.isMeet then
  31. SL:TipMessage("货币不足,无法更改!",1,NoticeType.NoticeMid)
  32. return
  33. end
  34. if self.args.cfgId == 60090002 then
  35. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_CHANGE_ROLE_NAME,{roleName=self.name})
  36. elseif self.args.cfgId == 60090003 then
  37. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_CHANGE_UNION_NAME,{unionName=self.name})
  38. end
  39. GUI:UIPanel_Close("dev/outui/ReName/Panel/KLRoleReName/KLRoleReNamePanel")
  40. end
  41. function this:OnValueChangeInputEnd(_, _, eventData)
  42. self.name = eventData[1]
  43. end
  44. function this:ResUnionInfo(id,message)
  45. self.ischangename = message.ischangename == "1"
  46. self:RefreshData()
  47. end
  48. function this:RES_ROLE_IS_FIRST_CHANGE_NAME(id,message)
  49. self.ischangename = message == 1
  50. self:RefreshData()
  51. end
  52. ---界面显示时调用一次
  53. function this:Show()
  54. self.isMeet = false
  55. GUI:Image_loadTexture(self.view.title,self.args.title,"Atlas/TS_Common.spriteatlas")
  56. GUI:Text_setString(self.view.des,self.args.des or "")
  57. if self.args.cfgId == 60090003 then --战盟改名卡
  58. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_GET_UNION_INFO)
  59. elseif self.args.cfgId == 60090002 then --角色改名卡
  60. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_ROLE_IS_FIRST_CHANGE_NAME)
  61. end
  62. end
  63. ---创建或者刷新界面数据时调用
  64. function this:Refresh()
  65. end
  66. function this:RefreshData()
  67. ---@type cfg_global_column
  68. local tbl = SL:GetConfig("cfg_global",1600,"id")
  69. local str = string.split(tbl.value,"|")
  70. str = string.split(str[1],"#")
  71. local costCfgId = tonumber(str[1])
  72. local costCount = tonumber(str[2])
  73. local ownerTicket = SL:GetBagItemCount(costCfgId)
  74. if self.ischangename then
  75. ---@type cfg_global_column
  76. tbl = SL:GetConfig("cfg_global",1602,"id")
  77. str = string.split(tbl.value,"|")
  78. if self.args.cfgId == 60090002 then
  79. str = string.split(str[2],"#")
  80. local costCfgId1 = tonumber(str[1])
  81. local costCount1 = tonumber(str[2])
  82. local ownerTicket1 = SL:GetBagItemCount(costCfgId1)
  83. ownerTicket = ownerTicket1 <costCount1 and ownerTicket or ownerTicket1
  84. costCount = ownerTicket1 <costCount1 and costCount or costCount1
  85. costCfgId = ownerTicket1 <costCount1 and costCfgId or costCfgId1
  86. elseif self.args.cfgId == 60090003 then
  87. str = string.split(str[1],"#")
  88. local costCfgId2 = tonumber(str[1])
  89. local costCount2 = tonumber(str[2])
  90. local ownerTicket2 = SL:GetBagItemCount(costCfgId2)
  91. ownerTicket = ownerTicket2 <costCount2 and ownerTicket or ownerTicket2
  92. costCount = ownerTicket2 <costCount2 and costCount or costCount2
  93. costCfgId = ownerTicket2 <costCount2 and costCfgId or costCfgId2
  94. end
  95. self.isMeet = costCount <= ownerTicket
  96. local color = self.isMeet and "#1add1f" or "#ff2323"
  97. GUI:Text_setString(self.view.costCount,GUIUtil.GetColorText(costCount,color))
  98. else
  99. self.isMeet = true
  100. costCfgId = self.args.cfgId
  101. GUI:Text_setString(self.view.costCount,"首次免费")
  102. end
  103. self.item_model = GUI:Item_Create(self.view.costItem, {
  104. width = "25",
  105. height = "25",
  106. itemid = costCfgId,
  107. tips = "1",
  108. noclip = "1",
  109. mfixsize = "30,30",
  110. bgtype = "0",
  111. })
  112. end
  113. function this:Close()
  114. self.item_model = nil
  115. end
  116. return this