|
- -- 游戏房间邀请茶馆玩家Layout
- local ClubInvite = class("ClubInvite" , cc.UIView);
- local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
-
- local PAGE_NUM = 5
-
- function ClubInvite:ctor(roomId, gameRule)
- ClubInvite.super.ctor(self)
-
- local ui = loadUI("res/ui/ui_club/ui_club_invite.ui")
- self.ui = ui;
- self:addChild(ui);
-
- --房间号
- self.roomId = roomId;
-
- --房间游戏规则
- self.gameRule = gameRule;
-
- --当前显示的页数
- self.curPlayerPage = 1
-
- --总页数
- self.allPage = 1
-
- --总玩家数
- self.allPlayerNum = 1
-
- --自己的玩家数据
- self.myUserInfo = nil
-
- --过滤后的玩家列表
- self.newPlayerList = nil
- end
-
- function ClubInvite:onEnter()
- ClubInvite.super.onEnter(self)
-
- --按钮注册事件
- self:registerButton();
-
- --监听事件
- self:inviteBindEvent();
-
- --设置默认界面
- self:setDefault();
-
- --茶馆昵称
- self.clubName = ""
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- local clubList = app.club_php.clubList
- if clubList[app.club_php.clubID] then
- self.clubName = clubList[app.club_php.clubID].clubName
- else
- app.club_php:requestClubList(function()
- if clubList[app.club_php.clubID] then
- self.clubName = clubList[app.club_php.clubID].clubName
- end
- end)
- end
- --参数1:茶馆id 参数2:排序字段 参数3:排序类型 参数4:时间标签 参数5:0默认成员数据,1在线成员数据
- app.club_php:requestInvitePlayerList(app.club_php.clubID, "role", "desc", 0, 1);
-
-
- if app.club_php:getCestIsOpen(app.club_php.clubID) then
- self.ui.Items.Text:setText("屏蔽开局选手")
- end
- end
- end
-
- --按钮注册点击事件
- function ClubInvite:registerButton()
- --关闭
- self.ui.Items.Button_Close:registerClick(handler(self , self.onClose))
-
- --左翻页
- self.ui.Items.Button_page_left:registerClick(handler(self , self.onClickLeft))
-
- --右翻页
- self.ui.Items.Button_page_right:registerClick(handler(self , self.onClickRight))
-
- --刷新
- self.ui.Items.Button_refresh:registerClick(handler(self , self.onClickRefresh))
- -- self.ui.Items.Layout_refresh:registerClick(handler(self , self.onClickRefresh))
-
- --屏蔽开局玩家
- self.ui.Items.CheckBox_pingbi:addEventListener(handler(self , self.onClickPingbi))
-
- self.ui.Items.Button_Invite_All:registerClick(handler(self , self.onClickInviteAll))
- end
-
- --监听事件
- function ClubInvite:inviteBindEvent()
- --绑定请求成员列表成功回调事件
- self:bindEvent(app.club_php , GAME_EVENT.CLUB_INVITE_PLAYER_LIST , handler(self , self.onGetPlayerListEnd));
-
- --单个茶馆请求成功回调
- -- self:bindEvent(app.club_php , "oneClubInfoEnd" , handler(self , self.oneClubInfoEnd));
-
- --屏蔽开局玩家成功回调事件
- self:bindEvent(app.club_php , "MemberSetSuccess" , handler(self , self.MemberSetSuccess));
- end
-
- --设置默认界面
- function ClubInvite:setDefault()
- self.ui.Items.Layout_player_item:setVisible(false);
-
- --页数显示
- -- self.ui.Items.Layout_page:setVisible(false);
- -- self.ui.Items.Button_page_left:setVisible(false)
- -- self.ui.Items.Button_page_right:setVisible(false)
-
- --复制房间号按钮显示
- -- self.ui.Items.Layout_page:setVisible(false);
-
-
- if app.club_php.clubID and app.club_php.clubList[app.club_php.clubID] then
- local club = app.club_php.clubList[app.club_php.clubID]
- local isHide = club.isHidePlay
- if isHide then --and isHide == 1
- --已屏蔽游戏中玩家
- self.ui.Items.CheckBox_pingbi:setSelectedState(true)
- else
- self.ui.Items.CheckBox_pingbi:setSelectedState(false)
- end
- end
- end
-
- function ClubInvite:onClose()
- playBtnCloseEffect();
- self:removeFromParent()
- end
-
- --左翻页
- function ClubInvite:onClickLeft()
- playBtnEffect()
- if self.curPlayerPage > 1 then
- self.curPlayerPage = self.curPlayerPage - 1
- end
-
- --更新页数显示
- self:updatePage()
-
- --更新玩家
- self:showPlayerInfo();
- end
-
- --右翻页
- function ClubInvite:onClickRight()
- playBtnEffect()
- if self.curPlayerPage < self.allPage then
- self.curPlayerPage = self.curPlayerPage + 1
- end
-
- --更新页数显示
- self:updatePage()
-
- --更新玩家
- self:showPlayerInfo();
- end
-
- --成员列表请求完成
- function ClubInvite:onGetPlayerListEnd(event)
- if app.club_php.clubID and app.club_php.clubList[app.club_php.clubID] then
- local club = app.club_php.clubList[app.club_php.clubID]
- local isHide = club.isHidePlay
- if isHide then --and isHide == 1
- --已屏蔽游戏中玩家
- self.ui.Items.CheckBox_pingbi:setSelectedState(true)
- else
- self.ui.Items.CheckBox_pingbi:setSelectedState(false)
- end
- local players = event and event.players or self.newPlayerList or {}
- if event and event.players then
- self.allPlayerList = event.players
- else
- if self.allPlayerList then
- players = self.allPlayerList
- end
- end
- local playerList = {}
- for k,playerInfo in pairs(players) do
-
-
- --不记录自己那条数据
- if tonumber(playerInfo.uid) == tonumber(app.user.loginInfo.uid) then
- --记录自己的用户数据
- local userInfo = {}
- userInfo.uid = playerInfo.uid
- userInfo.nick = playerInfo.name
- userInfo.icon = playerInfo.strHeadUrl
- self.myUserInfo = userInfo;
- --table.remove(playerList, k)
- else
- if playerInfo.role == ClubDefine.Job.Member then
- --玩家已选择屏蔽游戏中用户
- if isHide then
- --去掉已在游戏中玩家
- if not playerInfo.isPlay then
- table.insert(playerList, playerInfo)
- end
- else
- table.insert(playerList, playerInfo)
- end
- end
- end
- end
-
- --重新计算玩家数量及页数
- local playerNum = table.nums(playerList)
- local allPageNum = math.ceil(playerNum / PAGE_NUM)
- self.allPage = allPageNum==0 and 1 or allPageNum
- self.allPlayerNum = playerNum
-
- --游戏中玩家排到最后
- local function sortFunc(a,b)
- if a.isPlay==nil or b.isPlay==nil then
- return false
- end
- return a.isPlay==false and b.isPlay==true
- end
-
- table.sort(playerList, sortFunc);
-
- --记录过滤后的玩家列表
- self.newPlayerList = playerList
- end
-
- self.curPlayerPage = 1
-
- --更新页数显示
- self:updatePage();
-
- --更新玩家
- self:showPlayerInfo();
- end
-
- --单个茶馆请求完成
- -- function ClubInvite:oneClubInfoEnd()
- -- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- -- local clubList = app.club_php.clubList
- -- if clubList and table.nums(clubList) > 0 then
- -- self.clubName = clubList[tonumber(app.club_php.clubID)].gname;
- -- else
- -- app.club_php:requestOneClubInfo(app.club_php.clubID);
- -- end
- -- end
- -- end
-
- --显示页数
- function ClubInvite:updatePage()
- -- if self.allPlayerNum > 5 then
- self.ui.Items.Text_cure_page:setText(self.curPlayerPage);
- self.ui.Items.Text_all_page:setText("/"..self.allPage);
- self.ui.Items.Layout_page:setVisible(true);
-
- if self.allPage > 1 then
- if self.curPlayerPage == self.allPage then
- -- self.ui.Items.Button_page_right:setVisible(false)
- self.ui.Items.Button_page_left:setVisible(true)
- elseif self.curPlayerPage < self.allPage then
- self.ui.Items.Button_page_right:setVisible(true)
- if self.curPlayerPage > 1 then
- self.ui.Items.Button_page_left:setVisible(true)
- else
- -- self.ui.Items.Button_page_left:setVisible(false)
- end
- end
- else
- -- self.ui.Items.Button_page_left:setVisible(false)
- -- self.ui.Items.Button_page_right:setVisible(false)
- end
- -- else
- -- self.ui.Items.Layout_page:setVisible(false);
- -- end
- end
-
- --刷新成员列表界面
- function ClubInvite:showPlayerInfo()
- local itemLayout = self.ui.Items.Layout_player
- itemLayout:removeAllChildren();
-
- if app.club_php.clubID and app.club_php.clubList[app.club_php.clubID] then
- local club = app.club_php.clubList[app.club_php.clubID]
- local playerList = {};
- if self.newPlayerList then
- playerList = self.newPlayerList
- else
- playerList = club.players;
- end
-
- if playerList then
- --根据页数取数据
- for i = ((self.curPlayerPage - 1) * PAGE_NUM + 1), self.curPlayerPage * PAGE_NUM do
- local nativePlayerList = playerList[i]
- if nativePlayerList then
- --如果是自己,则不显示此条数据
- if tonumber(nativePlayerList.uid) ~= tonumber(app.user.loginInfo.uid) then
- self:addPlayerItem(nativePlayerList);
- end
- end
- end
- end
- end
- end
-
- function ClubInvite:addPlayerItem(playerInfo)
- local itemLayout = self.ui.Items.Layout_player
-
- local uiTemplate = self.ui.Items.Layout_player_item;
-
- local uiItem = uiTemplate:getCopied()
- uiItem.Items = getUIItems(uiItem)
-
- --头像
- local nodeHead = uiItem.Items.headImg;
- setPlayerHeadImage(playerInfo.uid, playerInfo.strHeadUrl, nodeHead)
-
- --昵称
- local nickname = getSubStringNickname(playerInfo.name, uiItem.Items.Text_name)
- uiItem.Items.Text_name:setText(nickname);
-
- --状态
- if playerInfo.isPlay then
- --游戏中
- uiItem.Items.Text_statue:setText("游戏中")
- --红色
- uiItem.Items.Text_statue:setColor(cc.c3b(254,82,0))
-
- uiItem.Items.Button_invite:setVisible(false);
- else
- --在线
- uiItem.Items.Text_statue:setText("在线")
- --绿色
- uiItem.Items.Text_statue:setColor(cc.c3b(59,145,46))
- end
-
-
- --邀请
- uiItem.Items.Button_invite:registerClick(function()
- playBtnEffect()
- if app.club_php.clubID and app.club_php.clubID ~= 0 and self.roomId and self.clubName and self.gameRule then
- local BroadcastCode = 10050;
- local Content = {};
- Content.roomid = self.roomId
-
- Content.gname = self.clubName
- local myUserInfo = json.decode(app.user.userInfo)
- local userInfo = {
- uid = app.user.loginInfo.uid,
- nick = myUserInfo.nickname,
- icon = myUserInfo.headimgurl,
- }
- -- if self.myUserInfo then
- -- --邀请提示框显示邀请人头像及昵称信息
- -- userInfo = self.myUserInfo
- -- else
- -- userInfo.uid = playerInfo.uid
- -- userInfo.nick = playerInfo.nick
- -- userInfo.icon = playerInfo.icon
- -- end
-
- Content.userInfo = userInfo
-
- Content.gamerule = self.gameRule
-
- local BroadcastContent = json.encode(Content)
- log("ClubInvite:showPlayerInfo() BroadcastContent = ", BroadcastContent)
- app.club_php:requestBroadcast(app.club_php.clubID, playerInfo.uid, BroadcastCode, BroadcastContent)
- else
- log("ClubInvite:showPlayerInfo() self.roomId is nil or self.clubName is nil or self.gameRule is nil")
- showTooltip("邀请失败,数据错误")
- end
- end)
-
- itemLayout:addChild(uiItem);
- end
-
- --刷新
- function ClubInvite:onClickRefresh()
- playBtnEffect()
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- --参数1:茶馆id 参数2:排序字段 参数3:排序类型 参数4:时间标签 参数5:0默认成员数据,1在线成员数据
- app.club_php:requestInvitePlayerList(app.club_php.clubID, "role", "desc", 0, 1);
- end
- end
-
- --屏蔽开局玩家
- function ClubInvite:onClickPingbi()
- playBtnEffect()
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- --设置类型{1:邀请勿扰, $value 拒接邀请对象uid; 2:屏蔽开局用户, $value 1屏蔽0可见; 3:俱乐部置顶, $value 1置顶0取消置顶}
- local setType = 2;
- local memberSetValue = 0
- if self.ui.Items.CheckBox_pingbi:getSelectedState() then
- --在这个监听事件里,复选框是选中后才会触发此事件,所以当前为选中状态时说明是屏蔽
- memberSetValue = 1;
- else
- memberSetValue = 0;
- end
- app.club_php:requestMemberSet(app.club_php.clubID, setType, memberSetValue)
- end
- end
-
- --屏蔽开局玩家成功
- function ClubInvite:MemberSetSuccess(event)
- if not event then
- return
- end
-
- -- if event.setType == 2 then
- -- --屏蔽开局玩家
- -- if app.club_php.clubPlayerList then
- -- --修改缓存中是否屏蔽开局玩家字段
- -- app.club_php.clubPlayerList.is_hideplay = tonumber(event.setValues)
- -- end
- -- end
-
- self:onGetPlayerListEnd()
- local club = app.club_php.clubList[app.club_php.clubID]
- local isHide = club.isHidePlay
- if not isHide then
- --参数1:茶馆id 参数2:排序字段 参数3:排序类型 参数4:时间标签 参数5:0默认成员数据,1在线成员数据
- app.club_php:requestInvitePlayerList(app.club_php.clubID, "role", "desc", 0, 1);
- end
- end
-
- function ClubInvite:onClickInviteAll()
- playBtnEffect()
- if not self.newPlayerList or table.nums(self.newPlayerList)==0 then
- return
- end
- local BroadcastCode = 10050;
- local Content = {};
- Content.roomid = self.roomId
-
- Content.gname = self.clubName
- local myUserInfo = json.decode(app.user.userInfo)
- local userInfo = {
- uid = app.user.loginInfo.uid,
- nick = myUserInfo.nickname,
- icon = myUserInfo.headimgurl,
- }
-
- local uids = ""
- for k,v in pairs(self.newPlayerList) do
- uids = uids..v.uid
- if k~= #self.newPlayerList then
- uids = uids..","
- end
- end
-
- Content.userInfo = userInfo
-
- Content.gamerule = self.gameRule
-
- local BroadcastContent = json.encode(Content)
- log("ClubInvite:onClickInviteAll() BroadcastContent = ", BroadcastContent)
- app.club_php:requestBroadcast(app.club_php.clubID, uids, BroadcastCode, BroadcastContent)
- end
-
- return ClubInvite
|