|
- -- 玩家列表提示框Layout
- local ClubPlayerSetPercent = class("ClubPlayerSetPercent" , cc.UIView);
- local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
-
- function ClubPlayerSetPercent:ctor(playerInfo,clubId,okCallback)
- ClubPlayerSetPercent.super.ctor(self)
-
- self.ui = loadUI("res/ui/ui_club/ui_club_player_setPercent.ui");
- self:addChild(self.ui)
-
- --玩家数据
- self.playerInfo = playerInfo
- self.clubId = clubId
-
- --确认回调
- self.okCallback = okCallback
-
- self.nPercent = toNumber(playerInfo.arenaRatio)
-
- self.curDisant = 1
- end
-
- function ClubPlayerSetPercent:onEnter()
- ClubPlayerSetPercent.super.onEnter(self)
-
- -- 确认回调
- self.ui.Items.Button_confirm:registerClick(handler(self , self.onConfirm))
-
- -- 取消回调
- self.ui.Items.Button_close:registerClick(handler(self , self.onClose))
-
- self.ui.Items.Button_Sub:registerClick(handler(self , self.onSub))
- self.ui.Items.Button_Add:registerClick(handler(self , self.onAdd))
-
- self.ui.Items.TextField_ratdio:setText(tostring(self.nPercent).."%")
-
- self:bindTextFildTouch()
- self:updateView()
- self:initBindEvent()
- app.club_php:requestSinglePlayer(self.clubId,self.playerInfo.uid,ClubDefine.PlayListType.MATCH_MEMBER)
- end
-
- function ClubPlayerSetPercent:initBindEvent()
- --分成比例回调
- self:bindEvent(app.club_php , GAME_EVENT.UPDATE_COPARTNER_RATDIO , handler(self , self.updateView));
- --绑定比赛开关回调
- self:bindEvent(app.club_php , GAME_EVENT.CLUB_SET , handler(self , self.onSetSuccess));
- end
-
- -- 当比赛一关,其他和比赛有关的界面需要关闭
- function ClubPlayerSetPercent:onSetSuccess(data)
- if not data or not data.setType then
- return
- end
- if data.setType == GAME_CLUB_SET_STATE.Math_Switch then
- self:removeFromParent()
- end
- end
-
- function ClubPlayerSetPercent:updateView()
- local player = app.club_php:getMatchPlayer(self.clubId,app.user.loginInfo.uid)
- if player and player.role == ClubDefine.Job.LevelOneCopartner then
- self.maxLimit = toNumber(player.arenaRatio)
- self.ui.Items.Text_limlit:setVisible(false)
- elseif player and player.role == ClubDefine.Job.Creator then
- self.maxLimit = 100
- if self.playerInfo.haveRole6 == 0 then
- self.ui.Items.Text_limlit:setVisible(false)
- end
- else
- self.maxLimit = 100
- end
-
- self.ui.Items.Text_limlit:setText("注:当前可设置的比例区间为"..tostring(self.nPercent).."%—"..tostring(self.maxLimit).."%")
-
- self.srcMinPercent = self.nPercent
- end
-
- function ClubPlayerSetPercent:onClose()
- playBtnCloseEffect()
- self:removeFromParent()
- end
-
- function ClubPlayerSetPercent:onConfirm()
- playBtnEffect()
- if self:isRight() then
- return
- end
- if self.nPercent == 0 then
- showTooltip("请设置分成比例!")
- return
- end
- if self.nPercent == toNumber(self.playerInfo.arenaRatio) then
- self:removeFromParent()
- return
- end
- if self.okCallback then
- self.okCallback(self.nPercent);
- end
-
- self:removeFromParent()
- end
-
- function ClubPlayerSetPercent:onSub()
- playBtnEffect()
- if self:isRight() then
- return
- end
- local nPercent = self.nPercent - self.curDisant
- if nPercent < 0 then
- return
- end
- --[[ if nPercent == 0 then
- self.ui.Items.Button_Sub:setEnabled(false)
- end
- self.ui.Items.Button_Add:setEnabled(true)--]]
-
- self.nPercent = self.nPercent - self.curDisant
- self.ui.Items.TextField_ratdio:setText(tostring(self.nPercent).."%")
- end
-
- function ClubPlayerSetPercent:onAdd()
- playBtnEffect()
- if self:isRight() then
- return
- end
- local nPercent = self.nPercent + self.curDisant
- if nPercent > self.maxLimit then
- return
- end
- --[[if nPercent == self.maxLimit then
- self.ui.Items.Button_Add:setEnabled(false)
- end
- self.ui.Items.Button_Sub:setEnabled(true)--]]
- self.nPercent = self.nPercent + self.curDisant
- self.ui.Items.TextField_ratdio:setText(tostring(self.nPercent).."%")
- end
-
-
- function ClubPlayerSetPercent:bindTextFildTouch()
- local searchBoxLeft = self.ui.Items.TextField_ratdio;
- self.curPercent = 0
- local function onTouchEndedL(touch , event)
- logD("event:",event)
- if event == cc.TextFiledEventType.enter or event == cc.TextFiledEventType.detach_with_ime then
- local searchCont = searchBoxLeft:getText();
- if searchCont == "" then
- searchCont = tostring(self.curPercent).."%"
- else
- searchCont = searchCont.."%"
- end
- searchBoxLeft:setText(searchCont)
- elseif event == cc.TextFiledEventType.attach_with_ime then
- local searchCont = searchBoxLeft:getText();
- local list = string.split(searchCont,"%")
- logD("list[1]:",list[1])
- logD("list[2]:",list[2])
- if list[1] and not (list[2] and list[2] ~= "") then
- logD("searchBoxLeft:setText(tostring(list[1]))")
- searchBoxLeft:setText(tostring(list[1]))
- self.curPercent = list[1]
- else
- logD("searchBoxLeft:setText()")
- searchBoxLeft:setText("")
- end
- end
- end
-
- searchBoxLeft:addEventListener(onTouchEndedL)
- end
-
- function ClubPlayerSetPercent:isRight()
- local searchCont = self.ui.Items.TextField_ratdio:getText();
- local list = string.split(searchCont,"%")
- searchCont = list[1]
- if (list[2] and list[2] ~= "") or not tonumber(searchCont) or toNumber(searchCont) < 0 or toNumber(searchCont) > 100 or self:calutPointNum(searchCont) then
- local player = app.club_php:getMatchPlayer(self.clubId,app.user.loginInfo.uid)
- if player and player.role == ClubDefine.Job.LevelOneCopartner then
- showTooltip("注:输入内容不合法,请输入"..tostring(0).."—"..tostring(self.maxLimit).."内的整数!")
- else
- showTooltip("注:输入内容不合法,请输入"..tostring(self.srcMinPercent).."—"..tostring(self.maxLimit).."内的整数!")
- end
-
- return true
- end
- self.nPercent = toNumber(searchCont)
- return false
- end
-
- function ClubPlayerSetPercent:calutPointNum(str)
- local list = string.split(str,".")
- if list and list[2] then
- if string.len(list[2]) ~= 0 then
- return true
- end
- end
- return false
- end
-
- return ClubPlayerSetPercent
|