|
- -- 游戏房间邀请框Layout
- local ClubInviteRoom = class("ClubInviteRoom" , cc.UIView);
-
- function ClubInviteRoom:ctor(gID, inviteInfo, clickCallback,agreeCallback)
- ClubInviteRoom.super.ctor(self)
-
- local ui = loadUI("res/ui/ui_club/ui_club_invite_room.ui")
- self.ui = ui;
- self:addChild(ui);
-
- --俱乐部id
- self.gid = gID;
-
- --邀请信息
- self.inviteInfo = inviteInfo;
-
- self.returnCallback = clickCallback;
- self.agreeCallback = nil
- if agreeCallback then
- self.agreeCallback = agreeCallback
- end
- end
-
- function ClubInviteRoom:onEnter()
- ClubInviteRoom.super.onEnter(self)
-
- --按钮注册事件
- self:registerButton();
-
- --设置默认界面
- self:setDefault();
-
- -- 监听事件
- self:bindEvent(app.hall , "onJoinRoomResponse", handler(self , self.onJoinRoomResponse));
- end
-
- --按钮注册点击事件
- function ClubInviteRoom:registerButton()
- --关闭
- self.ui.Items.Button_Close:registerClick(handler(self , self.onClose))
-
- --同意
- self.ui.Items.Button_agree:registerClick(handler(self , self.onClickAgree))
-
- --拒绝
- self.ui.Items.Button_disagree:registerClick(handler(self , self.onClickDisagree))
-
- --屏蔽邀请
- self.ui.Items.CheckBox_pingbi:addEventListener(handler(self , self.onClickPingbi))
- end
-
- --设置默认界面
- function ClubInviteRoom:setDefault()
- local inviteInfo = self.inviteInfo
-
- if inviteInfo.userInfo then
- --玩家头像
- local nodeHead = self.ui.Items.headImg;
- setPlayerHeadImage(inviteInfo.userInfo.uid, inviteInfo.userInfo.icon,nodeHead)
-
- --玩家昵称
- local nickname = getSubStringNickname(inviteInfo.userInfo.nick, self.ui.Items.Text_name)
- self.ui.Items.Text_name:setText(nickname);
-
- --玩家id
- self.ui.Items.Text_id:setText(inviteInfo.userInfo.uid);
- end
-
- --房间号
- self.ui.Items.Text_roomid:setText(table.tostring(inviteInfo.roomid));
-
- --茶馆名字
- self.ui.Items.Text_club_name:setText(inviteInfo.gname);
-
- --房间玩法规则
- self.ui.Items.Text_game_rule:setText(inviteInfo.gamerule);
- end
-
- function ClubInviteRoom:onClose()
- playBtnCloseEffect();
- if self.returnCallback then
- self.returnCallback()
- end
- self:removeFromParent()
- end
-
- --同意
- function ClubInviteRoom:onClickAgree()
- playBtnEffect()
-
- if self.agreeCallback then
- local parm = {
- roomid = self.ui.Items.Text_roomid:getText(),
- gid = self.gid,
- }
- setAgainGameInvitedata(parm)
- self.agreeCallback()
- return
- end
-
- local roomId = nil
-
- roomId = self.ui.Items.Text_roomid:getText()
-
- logD("ClubInviteRoom:onClickAgree() roomId = ", roomId)
-
- if roomId then
- logD("ClubInviteRoom:onClickAgree() roomId = ", roomId)
-
- --同意后进入房间,赋值当前进入的俱乐部id
- app.club_php.clubID = self.gid
- local function doRequest(gameId, roomId)
- if not gameId or tonumber(gameId) <= 0 then
- showTooltip("房间号不存在")
- self:onClose()
- return
- end
- app.hall:requestJoinRoom(gameId, roomId)
- end
- app.hall:queryRoomId(roomId,doRequest)
- end
- app.club_php:requestRuleSet(self.gid, self.inviteInfo.userInfo.baojianid, 1, 1)
- end
-
- --拒绝
- function ClubInviteRoom:onClickDisagree()
- playBtnEffect()
- if self.returnCallback then
- self.returnCallback()
- end
- self:removeFromParent()
- end
-
- --成员列表请求完成
- function ClubInviteRoom:onGetPlayerListEnd()
- if app.club_php.clubPlayerList then
- local playerList = app.club_php.clubPlayerList.list;
- for k,playerInfo in pairs(playerList) do
- --去掉自己那条数据
- if tonumber(playerInfo.uid) == tonumber(app.user.loginInfo.uid) then
- table.remove(playerList, k)
- break
- end
- end
- --需要去掉自己
- local playerNum = table.nums(playerList)
- local allPageNum = math.ceil(playerNum / 5)
- self.allPage = allPageNum
- self.allPlayerNum = playerNum
- end
-
- --更新玩家
- self:showPlayerInfo();
- end
-
- --单个茶馆请求完成
- function ClubInviteRoom: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.gname = clubList[tonumber(app.club_php.clubID)].gname;
- else
- app.club_php:requestOneClubInfo(app.club_php.clubID);
- end
- end
- end
-
- --刷新成员列表界面
- function ClubInviteRoom:showPlayerInfo()
- local itemLayout = self.ui.Items.Layout_player
- itemLayout:removeAllChildren();
-
- if app.club_php.clubPlayerList then
- local playerList = app.club_php.clubPlayerList.list;
- if playerList then
- --根据页数取数据
- for i = ((self.curPlayerPage - 1) * 5 + 1), self.curPlayerPage * 5 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 ClubInviteRoom: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;
- getUserHeadImageWithUrl(playerInfo.uid, playerInfo.icon, function(imageData)
- local texture = getHeadTexture(imageData, nodeHead,true)
- if texture ~= nil then
- nodeHead:setTexture(texture)
- end
- end)
-
- --昵称
- local nickname = getSubStringNickname(playerInfo.nick, uiItem.Items.Text_name)
- uiItem.Items.Text_name:setText(nickname);
-
- --状态
- if playerInfo.isplay == 1 then
- --游戏中
- uiItem.Items.Text_statue:setText("游戏中")
- --红色
- uiItem.Items.Text_statue:setColor(cc.c3b(254,82,0))
- 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.gname and self.gameMode then
- local BroadcastCode = 10050;
- local Content = {};
- Content.roomid = self.roomID
-
- Content.gname = self.gname
- local gclubInfo = app.club_php.clubList[app.club_php.clubID]
- local userInfo = {}
- userInfo.uid = playerInfo.uid
- userInfo.nick = playerInfo.nick
- userInfo.icon = playerInfo.icon
- userInfo.baojianid = gclubInfo.settings.baoJianId
-
- Content.userInfo = userInfo
-
- Content.gamerule = self.gameMode
-
- local BroadcastContent = json.encode(Content)
- log("ClubInviteRoom:showPlayerInfo() BroadcastContent = ", BroadcastContent)
- app.club_php:requestBroadcast(app.club_php.clubID, playerInfo.uid, BroadcastCode, BroadcastContent)
- else
- log("ClubInviteRoom:showPlayerInfo() self.roomID is nil or self.gname is nil or self.gameMode is nil")
- showTooltip("邀请失败,数据错误")
- end
- end)
-
- itemLayout:addChild(uiItem);
- end
-
- -- 监听加入房间返回事件
- function ClubInviteRoom:onJoinRoomResponse(event)
- if not event then
- return
- end
- local errCode = event.errCode
- if errCode ~= 0 then
- local errString = ENTER_ROOM_RET_STR[errCode] or "房间不存在"
- showTooltip(errString);
- end
- end
-
- --是否屏蔽玩家邀请
- function ClubInviteRoom:onClickPingbi()
- playBtnEffect()
- local isChoice = self.ui.Items.CheckBox_pingbi:getSelectedState()
- if isChoice then
- local function okCallBack()
- --设置类型{1:邀请勿扰, $value 拒接邀请对象uid; 2:屏蔽开局用户, $value 1屏蔽0可见; 3:俱乐部置顶, $value 1置顶0取消置顶}
- local setType = 1;
- local playerId = nil
- local inviteInfo = self.inviteInfo
- if inviteInfo and inviteInfo.userInfo then
- playerId = inviteInfo.userInfo.uid
- app.club_php:requestMemberSet(self.gid, setType, playerId)
- end
- end
-
- local function cancelCallBack()
- self.ui.Items.CheckBox_pingbi:setSelectedState(false)
- end
- showConfirmDialog("是否屏蔽所有玩家5分钟内发出的邀请?", okCallBack, cancelCallBack);
- else
- --不允许取消屏蔽
- self.ui.Items.CheckBox_pingbi:setSelectedState(true)
- end
-
- end
-
- return ClubInviteRoom
|