You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
5.7 KiB

  1. -- 玩家列表提示框Layout
  2. local ClubPlayerSetPercent = class("ClubPlayerSetPercent" , cc.UIView);
  3. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  4. function ClubPlayerSetPercent:ctor(playerInfo,clubId,okCallback)
  5. ClubPlayerSetPercent.super.ctor(self)
  6. self.ui = loadUI("res/ui/ui_club/ui_club_player_setPercent.ui");
  7. self:addChild(self.ui)
  8. --玩家数据
  9. self.playerInfo = playerInfo
  10. self.clubId = clubId
  11. --确认回调
  12. self.okCallback = okCallback
  13. self.nPercent = toNumber(playerInfo.arenaRatio)
  14. self.curDisant = 1
  15. end
  16. function ClubPlayerSetPercent:onEnter()
  17. ClubPlayerSetPercent.super.onEnter(self)
  18. -- 确认回调
  19. self.ui.Items.Button_confirm:registerClick(handler(self , self.onConfirm))
  20. -- 取消回调
  21. self.ui.Items.Button_close:registerClick(handler(self , self.onClose))
  22. self.ui.Items.Button_Sub:registerClick(handler(self , self.onSub))
  23. self.ui.Items.Button_Add:registerClick(handler(self , self.onAdd))
  24. self.ui.Items.TextField_ratdio:setText(tostring(self.nPercent).."%")
  25. self:bindTextFildTouch()
  26. self:updateView()
  27. self:initBindEvent()
  28. app.club_php:requestSinglePlayer(self.clubId,self.playerInfo.uid,ClubDefine.PlayListType.MATCH_MEMBER)
  29. end
  30. function ClubPlayerSetPercent:initBindEvent()
  31. --分成比例回调
  32. self:bindEvent(app.club_php , GAME_EVENT.UPDATE_COPARTNER_RATDIO , handler(self , self.updateView));
  33. --绑定比赛开关回调
  34. self:bindEvent(app.club_php , GAME_EVENT.CLUB_SET , handler(self , self.onSetSuccess));
  35. end
  36. -- 当比赛一关,其他和比赛有关的界面需要关闭
  37. function ClubPlayerSetPercent:onSetSuccess(data)
  38. if not data or not data.setType then
  39. return
  40. end
  41. if data.setType == GAME_CLUB_SET_STATE.Math_Switch then
  42. self:removeFromParent()
  43. end
  44. end
  45. function ClubPlayerSetPercent:updateView()
  46. local player = app.club_php:getMatchPlayer(self.clubId,app.user.loginInfo.uid)
  47. if player and player.role == ClubDefine.Job.LevelOneCopartner then
  48. self.maxLimit = toNumber(player.arenaRatio)
  49. self.ui.Items.Text_limlit:setVisible(false)
  50. elseif player and player.role == ClubDefine.Job.Creator then
  51. self.maxLimit = 100
  52. if self.playerInfo.haveRole6 == 0 then
  53. self.ui.Items.Text_limlit:setVisible(false)
  54. end
  55. else
  56. self.maxLimit = 100
  57. end
  58. self.ui.Items.Text_limlit:setText("注:当前可设置的比例区间为"..tostring(self.nPercent).."%—"..tostring(self.maxLimit).."%")
  59. self.srcMinPercent = self.nPercent
  60. end
  61. function ClubPlayerSetPercent:onClose()
  62. playBtnCloseEffect()
  63. self:removeFromParent()
  64. end
  65. function ClubPlayerSetPercent:onConfirm()
  66. playBtnEffect()
  67. if self:isRight() then
  68. return
  69. end
  70. if self.nPercent == 0 then
  71. showTooltip("请设置分成比例!")
  72. return
  73. end
  74. if self.nPercent == toNumber(self.playerInfo.arenaRatio) then
  75. self:removeFromParent()
  76. return
  77. end
  78. if self.okCallback then
  79. self.okCallback(self.nPercent);
  80. end
  81. self:removeFromParent()
  82. end
  83. function ClubPlayerSetPercent:onSub()
  84. playBtnEffect()
  85. if self:isRight() then
  86. return
  87. end
  88. local nPercent = self.nPercent - self.curDisant
  89. if nPercent < 0 then
  90. return
  91. end
  92. --[[ if nPercent == 0 then
  93. self.ui.Items.Button_Sub:setEnabled(false)
  94. end
  95. self.ui.Items.Button_Add:setEnabled(true)--]]
  96. self.nPercent = self.nPercent - self.curDisant
  97. self.ui.Items.TextField_ratdio:setText(tostring(self.nPercent).."%")
  98. end
  99. function ClubPlayerSetPercent:onAdd()
  100. playBtnEffect()
  101. if self:isRight() then
  102. return
  103. end
  104. local nPercent = self.nPercent + self.curDisant
  105. if nPercent > self.maxLimit then
  106. return
  107. end
  108. --[[if nPercent == self.maxLimit then
  109. self.ui.Items.Button_Add:setEnabled(false)
  110. end
  111. self.ui.Items.Button_Sub:setEnabled(true)--]]
  112. self.nPercent = self.nPercent + self.curDisant
  113. self.ui.Items.TextField_ratdio:setText(tostring(self.nPercent).."%")
  114. end
  115. function ClubPlayerSetPercent:bindTextFildTouch()
  116. local searchBoxLeft = self.ui.Items.TextField_ratdio;
  117. self.curPercent = 0
  118. local function onTouchEndedL(touch , event)
  119. logD("event:",event)
  120. if event == cc.TextFiledEventType.enter or event == cc.TextFiledEventType.detach_with_ime then
  121. local searchCont = searchBoxLeft:getText();
  122. if searchCont == "" then
  123. searchCont = tostring(self.curPercent).."%"
  124. else
  125. searchCont = searchCont.."%"
  126. end
  127. searchBoxLeft:setText(searchCont)
  128. elseif event == cc.TextFiledEventType.attach_with_ime then
  129. local searchCont = searchBoxLeft:getText();
  130. local list = string.split(searchCont,"%")
  131. logD("list[1]:",list[1])
  132. logD("list[2]:",list[2])
  133. if list[1] and not (list[2] and list[2] ~= "") then
  134. logD("searchBoxLeft:setText(tostring(list[1]))")
  135. searchBoxLeft:setText(tostring(list[1]))
  136. self.curPercent = list[1]
  137. else
  138. logD("searchBoxLeft:setText()")
  139. searchBoxLeft:setText("")
  140. end
  141. end
  142. end
  143. searchBoxLeft:addEventListener(onTouchEndedL)
  144. end
  145. function ClubPlayerSetPercent:isRight()
  146. local searchCont = self.ui.Items.TextField_ratdio:getText();
  147. local list = string.split(searchCont,"%")
  148. searchCont = list[1]
  149. if (list[2] and list[2] ~= "") or not tonumber(searchCont) or toNumber(searchCont) < 0 or toNumber(searchCont) > 100 or self:calutPointNum(searchCont) then
  150. local player = app.club_php:getMatchPlayer(self.clubId,app.user.loginInfo.uid)
  151. if player and player.role == ClubDefine.Job.LevelOneCopartner then
  152. showTooltip("注:输入内容不合法,请输入"..tostring(0).."—"..tostring(self.maxLimit).."内的整数!")
  153. else
  154. showTooltip("注:输入内容不合法,请输入"..tostring(self.srcMinPercent).."—"..tostring(self.maxLimit).."内的整数!")
  155. end
  156. return true
  157. end
  158. self.nPercent = toNumber(searchCont)
  159. return false
  160. end
  161. function ClubPlayerSetPercent:calutPointNum(str)
  162. local list = string.split(str,".")
  163. if list and list[2] then
  164. if string.len(list[2]) ~= 0 then
  165. return true
  166. end
  167. end
  168. return false
  169. end
  170. return ClubPlayerSetPercent