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.

297 lines
7.8 KiB

  1. -- 游戏房间邀请框Layout
  2. local ClubInviteRoom = class("ClubInviteRoom" , cc.UIView);
  3. function ClubInviteRoom:ctor(gID, inviteInfo, clickCallback,agreeCallback)
  4. ClubInviteRoom.super.ctor(self)
  5. local ui = loadUI("res/ui/ui_club/ui_club_invite_room.ui")
  6. self.ui = ui;
  7. self:addChild(ui);
  8. --俱乐部id
  9. self.gid = gID;
  10. --邀请信息
  11. self.inviteInfo = inviteInfo;
  12. self.returnCallback = clickCallback;
  13. self.agreeCallback = nil
  14. if agreeCallback then
  15. self.agreeCallback = agreeCallback
  16. end
  17. end
  18. function ClubInviteRoom:onEnter()
  19. ClubInviteRoom.super.onEnter(self)
  20. --按钮注册事件
  21. self:registerButton();
  22. --设置默认界面
  23. self:setDefault();
  24. -- 监听事件
  25. self:bindEvent(app.hall , "onJoinRoomResponse", handler(self , self.onJoinRoomResponse));
  26. end
  27. --按钮注册点击事件
  28. function ClubInviteRoom:registerButton()
  29. --关闭
  30. self.ui.Items.Button_Close:registerClick(handler(self , self.onClose))
  31. --同意
  32. self.ui.Items.Button_agree:registerClick(handler(self , self.onClickAgree))
  33. --拒绝
  34. self.ui.Items.Button_disagree:registerClick(handler(self , self.onClickDisagree))
  35. --屏蔽邀请
  36. self.ui.Items.CheckBox_pingbi:addEventListener(handler(self , self.onClickPingbi))
  37. end
  38. --设置默认界面
  39. function ClubInviteRoom:setDefault()
  40. local inviteInfo = self.inviteInfo
  41. if inviteInfo.userInfo then
  42. --玩家头像
  43. local nodeHead = self.ui.Items.headImg;
  44. setPlayerHeadImage(inviteInfo.userInfo.uid, inviteInfo.userInfo.icon,nodeHead)
  45. --玩家昵称
  46. local nickname = getSubStringNickname(inviteInfo.userInfo.nick, self.ui.Items.Text_name)
  47. self.ui.Items.Text_name:setText(nickname);
  48. --玩家id
  49. self.ui.Items.Text_id:setText(inviteInfo.userInfo.uid);
  50. end
  51. --房间号
  52. self.ui.Items.Text_roomid:setText(table.tostring(inviteInfo.roomid));
  53. --茶馆名字
  54. self.ui.Items.Text_club_name:setText(inviteInfo.gname);
  55. --房间玩法规则
  56. self.ui.Items.Text_game_rule:setText(inviteInfo.gamerule);
  57. end
  58. function ClubInviteRoom:onClose()
  59. playBtnCloseEffect();
  60. if self.returnCallback then
  61. self.returnCallback()
  62. end
  63. self:removeFromParent()
  64. end
  65. --同意
  66. function ClubInviteRoom:onClickAgree()
  67. playBtnEffect()
  68. if self.agreeCallback then
  69. local parm = {
  70. roomid = self.ui.Items.Text_roomid:getText(),
  71. gid = self.gid,
  72. }
  73. setAgainGameInvitedata(parm)
  74. self.agreeCallback()
  75. return
  76. end
  77. local roomId = nil
  78. roomId = self.ui.Items.Text_roomid:getText()
  79. logD("ClubInviteRoom:onClickAgree() roomId = ", roomId)
  80. if roomId then
  81. logD("ClubInviteRoom:onClickAgree() roomId = ", roomId)
  82. --同意后进入房间,赋值当前进入的俱乐部id
  83. app.club_php.clubID = self.gid
  84. local function doRequest(gameId, roomId)
  85. if not gameId or tonumber(gameId) <= 0 then
  86. showTooltip("房间号不存在")
  87. self:onClose()
  88. return
  89. end
  90. app.hall:requestJoinRoom(gameId, roomId)
  91. end
  92. app.hall:queryRoomId(roomId,doRequest)
  93. end
  94. app.club_php:requestRuleSet(self.gid, self.inviteInfo.userInfo.baojianid, 1, 1)
  95. end
  96. --拒绝
  97. function ClubInviteRoom:onClickDisagree()
  98. playBtnEffect()
  99. if self.returnCallback then
  100. self.returnCallback()
  101. end
  102. self:removeFromParent()
  103. end
  104. --成员列表请求完成
  105. function ClubInviteRoom:onGetPlayerListEnd()
  106. if app.club_php.clubPlayerList then
  107. local playerList = app.club_php.clubPlayerList.list;
  108. for k,playerInfo in pairs(playerList) do
  109. --去掉自己那条数据
  110. if tonumber(playerInfo.uid) == tonumber(app.user.loginInfo.uid) then
  111. table.remove(playerList, k)
  112. break
  113. end
  114. end
  115. --需要去掉自己
  116. local playerNum = table.nums(playerList)
  117. local allPageNum = math.ceil(playerNum / 5)
  118. self.allPage = allPageNum
  119. self.allPlayerNum = playerNum
  120. end
  121. --更新玩家
  122. self:showPlayerInfo();
  123. end
  124. --单个茶馆请求完成
  125. function ClubInviteRoom:oneClubInfoEnd()
  126. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  127. local clubList = app.club_php.clubList
  128. if clubList and table.nums(clubList) > 0 then
  129. self.gname = clubList[tonumber(app.club_php.clubID)].gname;
  130. else
  131. app.club_php:requestOneClubInfo(app.club_php.clubID);
  132. end
  133. end
  134. end
  135. --刷新成员列表界面
  136. function ClubInviteRoom:showPlayerInfo()
  137. local itemLayout = self.ui.Items.Layout_player
  138. itemLayout:removeAllChildren();
  139. if app.club_php.clubPlayerList then
  140. local playerList = app.club_php.clubPlayerList.list;
  141. if playerList then
  142. --根据页数取数据
  143. for i = ((self.curPlayerPage - 1) * 5 + 1), self.curPlayerPage * 5 do
  144. local nativePlayerList = playerList[i]
  145. if nativePlayerList then
  146. --如果是自己,则不显示此条数据
  147. if tonumber(nativePlayerList.uid) ~= tonumber(app.user.loginInfo.uid) then
  148. self:addPlayerItem(nativePlayerList);
  149. end
  150. end
  151. end
  152. end
  153. end
  154. end
  155. function ClubInviteRoom:addPlayerItem(playerInfo)
  156. local itemLayout = self.ui.Items.Layout_player
  157. local uiTemplate = self.ui.Items.Layout_player_item;
  158. local uiItem = uiTemplate:getCopied()
  159. uiItem.Items = getUIItems(uiItem)
  160. --头像
  161. local nodeHead = uiItem.Items.headImg;
  162. getUserHeadImageWithUrl(playerInfo.uid, playerInfo.icon, function(imageData)
  163. local texture = getHeadTexture(imageData, nodeHead,true)
  164. if texture ~= nil then
  165. nodeHead:setTexture(texture)
  166. end
  167. end)
  168. --昵称
  169. local nickname = getSubStringNickname(playerInfo.nick, uiItem.Items.Text_name)
  170. uiItem.Items.Text_name:setText(nickname);
  171. --状态
  172. if playerInfo.isplay == 1 then
  173. --游戏中
  174. uiItem.Items.Text_statue:setText("游戏中")
  175. --红色
  176. uiItem.Items.Text_statue:setColor(cc.c3b(254,82,0))
  177. else
  178. --在线
  179. uiItem.Items.Text_statue:setText("在线")
  180. --绿色
  181. uiItem.Items.Text_statue:setColor(cc.c3b(59,145,46))
  182. end
  183. --邀请
  184. uiItem.Items.Button_invite:registerClick(function()
  185. playBtnEffect()
  186. if app.club_php.clubID and app.club_php.clubID ~= 0 and self.roomID and self.gname and self.gameMode then
  187. local BroadcastCode = 10050;
  188. local Content = {};
  189. Content.roomid = self.roomID
  190. Content.gname = self.gname
  191. local gclubInfo = app.club_php.clubList[app.club_php.clubID]
  192. local userInfo = {}
  193. userInfo.uid = playerInfo.uid
  194. userInfo.nick = playerInfo.nick
  195. userInfo.icon = playerInfo.icon
  196. userInfo.baojianid = gclubInfo.settings.baoJianId
  197. Content.userInfo = userInfo
  198. Content.gamerule = self.gameMode
  199. local BroadcastContent = json.encode(Content)
  200. log("ClubInviteRoom:showPlayerInfo() BroadcastContent = ", BroadcastContent)
  201. app.club_php:requestBroadcast(app.club_php.clubID, playerInfo.uid, BroadcastCode, BroadcastContent)
  202. else
  203. log("ClubInviteRoom:showPlayerInfo() self.roomID is nil or self.gname is nil or self.gameMode is nil")
  204. showTooltip("邀请失败,数据错误")
  205. end
  206. end)
  207. itemLayout:addChild(uiItem);
  208. end
  209. -- 监听加入房间返回事件
  210. function ClubInviteRoom:onJoinRoomResponse(event)
  211. if not event then
  212. return
  213. end
  214. local errCode = event.errCode
  215. if errCode ~= 0 then
  216. local errString = ENTER_ROOM_RET_STR[errCode] or "房间不存在"
  217. showTooltip(errString);
  218. end
  219. end
  220. --是否屏蔽玩家邀请
  221. function ClubInviteRoom:onClickPingbi()
  222. playBtnEffect()
  223. local isChoice = self.ui.Items.CheckBox_pingbi:getSelectedState()
  224. if isChoice then
  225. local function okCallBack()
  226. --设置类型{1:邀请勿扰, $value 拒接邀请对象uid; 2:屏蔽开局用户, $value 1屏蔽0可见; 3:俱乐部置顶, $value 1置顶0取消置顶}
  227. local setType = 1;
  228. local playerId = nil
  229. local inviteInfo = self.inviteInfo
  230. if inviteInfo and inviteInfo.userInfo then
  231. playerId = inviteInfo.userInfo.uid
  232. app.club_php:requestMemberSet(self.gid, setType, playerId)
  233. end
  234. end
  235. local function cancelCallBack()
  236. self.ui.Items.CheckBox_pingbi:setSelectedState(false)
  237. end
  238. showConfirmDialog("是否屏蔽所有玩家5分钟内发出的邀请?", okCallBack, cancelCallBack);
  239. else
  240. --不允许取消屏蔽
  241. self.ui.Items.CheckBox_pingbi:setSelectedState(true)
  242. end
  243. end
  244. return ClubInviteRoom