KLSettingBasicPanel.lua 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. ---@class KLSettingBasicPanel:UIKmlLuaPanelBase
  2. ---@field view KLSettingBasicPanelView
  3. local KLSettingBasicPanel = class(UIKmlLuaPanelBase)
  4. local this = KLSettingBasicPanel
  5. this.currentFightState = nil
  6. this.pkName = {
  7. ["全体"] = 0,
  8. ["和平"] = 1,
  9. ["组队"] = 4,
  10. ["战盟"] = 5,
  11. }
  12. ---创建时调用一次
  13. function this:Init()
  14. end
  15. ---创建或者刷新界面数据时调用
  16. function this:Refresh()
  17. local bgSound = SL:GetMetaValue(EMetaVarGetKey.GET_BACKGROUND_SOUND)
  18. local soundEffect = SL:GetMetaValue(EMetaVarGetKey.GET_SOUND_EFFECT)
  19. --第一次进游戏没有设置默认勾选
  20. local clickFloorMove = SL:GetMetaValue(EMetaVarGetKey.GET_CLICK_FLOOR_IS_SELECT)
  21. GUI:Slider_setPercent(self.view.bgSlider, bgSound)
  22. GUI:Slider_setPercent(self.view.soundSlider, soundEffect)
  23. GUI:SetIsOnWithoutNotify(self.view.clickFloor, clickFloorMove ~= EScreen.True)
  24. local pkMode = SL:GetMetaValue(EMetaVarGetKey.PKMODE)
  25. if tostring(pkMode) == "0" then
  26. this.currentFightState = self.view.toggle10
  27. elseif tostring(pkMode) == "1" then
  28. this.currentFightState = self.view.toggle12
  29. elseif tostring(pkMode) == "2" then
  30. this.currentFightState = self.view.toggle14
  31. elseif tostring(pkMode) == "3" then
  32. this.currentFightState = self.view.toggle16
  33. end
  34. GUI:SetIsOnWithoutNotify(this.currentFightState, true)
  35. end
  36. ---注册UI事件和服务器消息
  37. function this:RegistEvents()
  38. GUI:SetToggleOnValueChange(self.view.clickFloor, self, self.ClickFloorValueChange)
  39. GUI:AddOnClickEvent(self.view.BtnRoleChose, self, self.BtnRoleChoseOnClick)
  40. GUI:AddOnClickEvent(self.view.BtnExitGame, self, self.BtnExitGameOnClick)
  41. GUI:AddOnClickEvent(self.view.BtnReDefault, self, self.BtnReDefaultOnClick)
  42. GUI:SetSliderOnValueChange(self.view.bgSlider, self, self.BgSliderOnValueChange)
  43. GUI:SetSliderOnValueChange(self.view.soundSlider, self, self.SoundSliderOnValueChange)
  44. GUI:SetToggleOnValueChange(self.view.toggle10, self, self.PkMode2AllOnValueChange)
  45. GUI:SetToggleOnValueChange(self.view.toggle12, self, self.PkMode2PeaceOnValueChange)
  46. GUI:SetToggleOnValueChange(self.view.toggle14, self, self.PkMode2TeamOnValueChange)
  47. GUI:SetToggleOnValueChange(self.view.toggle16, self, self.PkMode2UnionOnValueChange)
  48. end
  49. function this:PkMode2AllOnValueChange(control, _, data)
  50. local isToggle = data[1]
  51. if isToggle then
  52. if self:SwitchPkMode(this.pkName["全体"]) then
  53. this.currentFightState = self.view.toggle10
  54. return
  55. end
  56. GUI:SetIsOnWithoutNotify(this.currentFightState, true)
  57. end
  58. end
  59. function this:PkMode2PeaceOnValueChange(control, _, data)
  60. local isToggle = data[1]
  61. if isToggle then
  62. if self:SwitchPkMode(this.pkName["和平"]) then
  63. this.currentFightState = self.view.toggle12
  64. return
  65. end
  66. GUI:SetIsOnWithoutNotify(this.currentFightState, true)
  67. end
  68. end
  69. function this:PkMode2TeamOnValueChange(control, _, data)
  70. local isToggle = data[1]
  71. if isToggle then
  72. if self:SwitchPkMode(this.pkName["组队"]) then
  73. this.currentFightState = self.view.toggle14
  74. return
  75. end
  76. GUI:SetIsOnWithoutNotify(this.currentFightState, true)
  77. end
  78. end
  79. function this:PkMode2UnionOnValueChange(control, _, data)
  80. local isToggle = data[1]
  81. if isToggle then
  82. if self:SwitchPkMode(this.pkName["战盟"]) then
  83. this.currentFightState = self.view.toggle16
  84. return
  85. end
  86. GUI:SetIsOnWithoutNotify(this.currentFightState, true)
  87. end
  88. end
  89. function this:SwitchPkMode(index)
  90. if GlobalLuaEventManager.isCrossServer and GlobalLuaEventManager.isCrossServer == 1 then
  91. if not SL:MeData_GetUnionId() or SL:MeData_GetUnionId() == 0 then
  92. if index ~= 0 then
  93. SL:TipMessage("当前地图无法切换pk模式", 1, NoticeType.NoticeMid)
  94. return false
  95. end
  96. else
  97. if index ~= 5 then
  98. SL:TipMessage("当前地图无法切换pk模式", 1, NoticeType.NoticeMid)
  99. return false
  100. end
  101. end
  102. end
  103. local tip = SL:GetMetaValue(EMetaVarGetKey.PKMODE_CAN_USE, index)
  104. if not string.isNullOrEmpty(tip) then
  105. SL:TipMessage(tip, 1, NoticeType.NoticeMid)
  106. return false
  107. end
  108. SL:SetMetaValue(EMetaVarSetKey.SET_PKMODE, index)
  109. return true
  110. end
  111. function this:ClickFloorValueChange(control, _, data)
  112. local isToggle = data[1]
  113. if not isToggle then
  114. SL:SetMetaValue(EMetaVarSetKey.SET_IS_CLICK_FLOOR_MOVE, EScreen.True)
  115. SL:TipMessage("已解除禁止角色位移", 1, NoticeType.NoticeMid)
  116. else
  117. SL:SetMetaValue(EMetaVarSetKey.SET_IS_CLICK_FLOOR_MOVE, EScreen.False)
  118. SL:TipMessage("已禁止角色位移", 1, NoticeType.NoticeMid)
  119. end
  120. end
  121. function this:FixedJoyStickOnValueChange(control, _, data)
  122. local isToggle = data[1]
  123. if isToggle then
  124. SL:SetMetaValue(EMetaVarSetKey.SET_ROCKER_TYPE, ETickModel.fixed)
  125. end
  126. end
  127. function this:MoveJoyStickOnValueChange(control, _, data)
  128. local isToggle = data[1]
  129. if isToggle then
  130. SL:SetMetaValue(EMetaVarSetKey.SET_ROCKER_TYPE, ETickModel.Move)
  131. end
  132. end
  133. function this:BtnLockOnClick()
  134. GUI:UIPanel_Open("dev/ui/Setting/Panel/KLLock/KLLockPanel")
  135. end
  136. function this:BtnRoleChoseOnClick()
  137. SL:QuitSelectRoleUI()
  138. end
  139. function this:BtnExitGameOnClick()
  140. if LoginManager.isSdk and not Main.isWindows then
  141. MuInterface.Instance:LogoutAccount()
  142. else
  143. SL:QuitGame()
  144. end
  145. end
  146. function this:BtnReDefaultOnClick()
  147. SL:ReplyDefaultBaseSetting()
  148. self:Refresh()
  149. end
  150. function this:BgSliderOnValueChange(control, _, data)
  151. local value = math.ceil(data[1])
  152. SL:SetMetaValue(EMetaVarSetKey.SET_BACKGROUND_SOUND, value)
  153. end
  154. function this:SoundSliderOnValueChange(control, _, data)
  155. local value = math.ceil(data[1])
  156. SL:SetMetaValue(EMetaVarSetKey.SET_SOUND_EFFECT, value)
  157. end
  158. function this:VoiceSliderOnValueChange(control, _, data)
  159. local value = math.ceil(data[1])
  160. SL:SetMetaValue(EMetaVarSetKey.SET_VOICE, value)
  161. end
  162. function this:Close()
  163. end
  164. return this