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.

463 lines
13 KiB

  1. -- 游戏房间邀请茶馆玩家Layout
  2. local ClubInvite = class("ClubInvite" , cc.UIView);
  3. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  4. local PAGE_NUM = 5
  5. function ClubInvite:ctor(roomId, gameRule)
  6. ClubInvite.super.ctor(self)
  7. local ui = loadUI("res/ui/ui_club/ui_club_invite.ui")
  8. self.ui = ui;
  9. self:addChild(ui);
  10. --房间号
  11. self.roomId = roomId;
  12. --房间游戏规则
  13. self.gameRule = gameRule;
  14. --当前显示的页数
  15. self.curPlayerPage = 1
  16. --总页数
  17. self.allPage = 1
  18. --总玩家数
  19. self.allPlayerNum = 1
  20. --自己的玩家数据
  21. self.myUserInfo = nil
  22. --过滤后的玩家列表
  23. self.newPlayerList = nil
  24. end
  25. function ClubInvite:onEnter()
  26. ClubInvite.super.onEnter(self)
  27. --按钮注册事件
  28. self:registerButton();
  29. --监听事件
  30. self:inviteBindEvent();
  31. --设置默认界面
  32. self:setDefault();
  33. --茶馆昵称
  34. self.clubName = ""
  35. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  36. local clubList = app.club_php.clubList
  37. if clubList[app.club_php.clubID] then
  38. self.clubName = clubList[app.club_php.clubID].clubName
  39. else
  40. app.club_php:requestClubList(function()
  41. if clubList[app.club_php.clubID] then
  42. self.clubName = clubList[app.club_php.clubID].clubName
  43. end
  44. end)
  45. end
  46. --参数1:茶馆id 参数2:排序字段 参数3:排序类型 参数4:时间标签 参数5:0默认成员数据,1在线成员数据
  47. app.club_php:requestInvitePlayerList(app.club_php.clubID, "role", "desc", 0, 1);
  48. if app.club_php:getCestIsOpen(app.club_php.clubID) then
  49. self.ui.Items.Text:setText("屏蔽开局选手")
  50. end
  51. end
  52. end
  53. --按钮注册点击事件
  54. function ClubInvite:registerButton()
  55. --关闭
  56. self.ui.Items.Button_Close:registerClick(handler(self , self.onClose))
  57. --左翻页
  58. self.ui.Items.Button_page_left:registerClick(handler(self , self.onClickLeft))
  59. --右翻页
  60. self.ui.Items.Button_page_right:registerClick(handler(self , self.onClickRight))
  61. --刷新
  62. self.ui.Items.Button_refresh:registerClick(handler(self , self.onClickRefresh))
  63. -- self.ui.Items.Layout_refresh:registerClick(handler(self , self.onClickRefresh))
  64. --屏蔽开局玩家
  65. self.ui.Items.CheckBox_pingbi:addEventListener(handler(self , self.onClickPingbi))
  66. self.ui.Items.Button_Invite_All:registerClick(handler(self , self.onClickInviteAll))
  67. end
  68. --监听事件
  69. function ClubInvite:inviteBindEvent()
  70. --绑定请求成员列表成功回调事件
  71. self:bindEvent(app.club_php , GAME_EVENT.CLUB_INVITE_PLAYER_LIST , handler(self , self.onGetPlayerListEnd));
  72. --单个茶馆请求成功回调
  73. -- self:bindEvent(app.club_php , "oneClubInfoEnd" , handler(self , self.oneClubInfoEnd));
  74. --屏蔽开局玩家成功回调事件
  75. self:bindEvent(app.club_php , "MemberSetSuccess" , handler(self , self.MemberSetSuccess));
  76. end
  77. --设置默认界面
  78. function ClubInvite:setDefault()
  79. self.ui.Items.Layout_player_item:setVisible(false);
  80. --页数显示
  81. -- self.ui.Items.Layout_page:setVisible(false);
  82. -- self.ui.Items.Button_page_left:setVisible(false)
  83. -- self.ui.Items.Button_page_right:setVisible(false)
  84. --复制房间号按钮显示
  85. -- self.ui.Items.Layout_page:setVisible(false);
  86. if app.club_php.clubID and app.club_php.clubList[app.club_php.clubID] then
  87. local club = app.club_php.clubList[app.club_php.clubID]
  88. local isHide = club.isHidePlay
  89. if isHide then --and isHide == 1
  90. --已屏蔽游戏中玩家
  91. self.ui.Items.CheckBox_pingbi:setSelectedState(true)
  92. else
  93. self.ui.Items.CheckBox_pingbi:setSelectedState(false)
  94. end
  95. end
  96. end
  97. function ClubInvite:onClose()
  98. playBtnCloseEffect();
  99. self:removeFromParent()
  100. end
  101. --左翻页
  102. function ClubInvite:onClickLeft()
  103. playBtnEffect()
  104. if self.curPlayerPage > 1 then
  105. self.curPlayerPage = self.curPlayerPage - 1
  106. end
  107. --更新页数显示
  108. self:updatePage()
  109. --更新玩家
  110. self:showPlayerInfo();
  111. end
  112. --右翻页
  113. function ClubInvite:onClickRight()
  114. playBtnEffect()
  115. if self.curPlayerPage < self.allPage then
  116. self.curPlayerPage = self.curPlayerPage + 1
  117. end
  118. --更新页数显示
  119. self:updatePage()
  120. --更新玩家
  121. self:showPlayerInfo();
  122. end
  123. --成员列表请求完成
  124. function ClubInvite:onGetPlayerListEnd(event)
  125. if app.club_php.clubID and app.club_php.clubList[app.club_php.clubID] then
  126. local club = app.club_php.clubList[app.club_php.clubID]
  127. local isHide = club.isHidePlay
  128. if isHide then --and isHide == 1
  129. --已屏蔽游戏中玩家
  130. self.ui.Items.CheckBox_pingbi:setSelectedState(true)
  131. else
  132. self.ui.Items.CheckBox_pingbi:setSelectedState(false)
  133. end
  134. local players = event and event.players or self.newPlayerList or {}
  135. if event and event.players then
  136. self.allPlayerList = event.players
  137. else
  138. if self.allPlayerList then
  139. players = self.allPlayerList
  140. end
  141. end
  142. local playerList = {}
  143. for k,playerInfo in pairs(players) do
  144. --不记录自己那条数据
  145. if tonumber(playerInfo.uid) == tonumber(app.user.loginInfo.uid) then
  146. --记录自己的用户数据
  147. local userInfo = {}
  148. userInfo.uid = playerInfo.uid
  149. userInfo.nick = playerInfo.name
  150. userInfo.icon = playerInfo.strHeadUrl
  151. self.myUserInfo = userInfo;
  152. --table.remove(playerList, k)
  153. else
  154. if playerInfo.role == ClubDefine.Job.Member then
  155. --玩家已选择屏蔽游戏中用户
  156. if isHide then
  157. --去掉已在游戏中玩家
  158. if not playerInfo.isPlay then
  159. table.insert(playerList, playerInfo)
  160. end
  161. else
  162. table.insert(playerList, playerInfo)
  163. end
  164. end
  165. end
  166. end
  167. --重新计算玩家数量及页数
  168. local playerNum = table.nums(playerList)
  169. local allPageNum = math.ceil(playerNum / PAGE_NUM)
  170. self.allPage = allPageNum==0 and 1 or allPageNum
  171. self.allPlayerNum = playerNum
  172. --游戏中玩家排到最后
  173. local function sortFunc(a,b)
  174. if a.isPlay==nil or b.isPlay==nil then
  175. return false
  176. end
  177. return a.isPlay==false and b.isPlay==true
  178. end
  179. table.sort(playerList, sortFunc);
  180. --记录过滤后的玩家列表
  181. self.newPlayerList = playerList
  182. end
  183. self.curPlayerPage = 1
  184. --更新页数显示
  185. self:updatePage();
  186. --更新玩家
  187. self:showPlayerInfo();
  188. end
  189. --单个茶馆请求完成
  190. -- function ClubInvite:oneClubInfoEnd()
  191. -- if app.club_php.clubID and app.club_php.clubID ~= 0 then
  192. -- local clubList = app.club_php.clubList
  193. -- if clubList and table.nums(clubList) > 0 then
  194. -- self.clubName = clubList[tonumber(app.club_php.clubID)].gname;
  195. -- else
  196. -- app.club_php:requestOneClubInfo(app.club_php.clubID);
  197. -- end
  198. -- end
  199. -- end
  200. --显示页数
  201. function ClubInvite:updatePage()
  202. -- if self.allPlayerNum > 5 then
  203. self.ui.Items.Text_cure_page:setText(self.curPlayerPage);
  204. self.ui.Items.Text_all_page:setText("/"..self.allPage);
  205. self.ui.Items.Layout_page:setVisible(true);
  206. if self.allPage > 1 then
  207. if self.curPlayerPage == self.allPage then
  208. -- self.ui.Items.Button_page_right:setVisible(false)
  209. self.ui.Items.Button_page_left:setVisible(true)
  210. elseif self.curPlayerPage < self.allPage then
  211. self.ui.Items.Button_page_right:setVisible(true)
  212. if self.curPlayerPage > 1 then
  213. self.ui.Items.Button_page_left:setVisible(true)
  214. else
  215. -- self.ui.Items.Button_page_left:setVisible(false)
  216. end
  217. end
  218. else
  219. -- self.ui.Items.Button_page_left:setVisible(false)
  220. -- self.ui.Items.Button_page_right:setVisible(false)
  221. end
  222. -- else
  223. -- self.ui.Items.Layout_page:setVisible(false);
  224. -- end
  225. end
  226. --刷新成员列表界面
  227. function ClubInvite:showPlayerInfo()
  228. local itemLayout = self.ui.Items.Layout_player
  229. itemLayout:removeAllChildren();
  230. if app.club_php.clubID and app.club_php.clubList[app.club_php.clubID] then
  231. local club = app.club_php.clubList[app.club_php.clubID]
  232. local playerList = {};
  233. if self.newPlayerList then
  234. playerList = self.newPlayerList
  235. else
  236. playerList = club.players;
  237. end
  238. if playerList then
  239. --根据页数取数据
  240. for i = ((self.curPlayerPage - 1) * PAGE_NUM + 1), self.curPlayerPage * PAGE_NUM do
  241. local nativePlayerList = playerList[i]
  242. if nativePlayerList then
  243. --如果是自己,则不显示此条数据
  244. if tonumber(nativePlayerList.uid) ~= tonumber(app.user.loginInfo.uid) then
  245. self:addPlayerItem(nativePlayerList);
  246. end
  247. end
  248. end
  249. end
  250. end
  251. end
  252. function ClubInvite:addPlayerItem(playerInfo)
  253. local itemLayout = self.ui.Items.Layout_player
  254. local uiTemplate = self.ui.Items.Layout_player_item;
  255. local uiItem = uiTemplate:getCopied()
  256. uiItem.Items = getUIItems(uiItem)
  257. --头像
  258. local nodeHead = uiItem.Items.headImg;
  259. setPlayerHeadImage(playerInfo.uid, playerInfo.strHeadUrl, nodeHead)
  260. --昵称
  261. local nickname = getSubStringNickname(playerInfo.name, uiItem.Items.Text_name)
  262. uiItem.Items.Text_name:setText(nickname);
  263. --状态
  264. if playerInfo.isPlay then
  265. --游戏中
  266. uiItem.Items.Text_statue:setText("游戏中")
  267. --红色
  268. uiItem.Items.Text_statue:setColor(cc.c3b(254,82,0))
  269. uiItem.Items.Button_invite:setVisible(false);
  270. else
  271. --在线
  272. uiItem.Items.Text_statue:setText("在线")
  273. --绿色
  274. uiItem.Items.Text_statue:setColor(cc.c3b(59,145,46))
  275. end
  276. --邀请
  277. uiItem.Items.Button_invite:registerClick(function()
  278. playBtnEffect()
  279. if app.club_php.clubID and app.club_php.clubID ~= 0 and self.roomId and self.clubName and self.gameRule then
  280. local BroadcastCode = 10050;
  281. local Content = {};
  282. Content.roomid = self.roomId
  283. Content.gname = self.clubName
  284. local myUserInfo = json.decode(app.user.userInfo)
  285. local userInfo = {
  286. uid = app.user.loginInfo.uid,
  287. nick = myUserInfo.nickname,
  288. icon = myUserInfo.headimgurl,
  289. }
  290. -- if self.myUserInfo then
  291. -- --邀请提示框显示邀请人头像及昵称信息
  292. -- userInfo = self.myUserInfo
  293. -- else
  294. -- userInfo.uid = playerInfo.uid
  295. -- userInfo.nick = playerInfo.nick
  296. -- userInfo.icon = playerInfo.icon
  297. -- end
  298. Content.userInfo = userInfo
  299. Content.gamerule = self.gameRule
  300. local BroadcastContent = json.encode(Content)
  301. log("ClubInvite:showPlayerInfo() BroadcastContent = ", BroadcastContent)
  302. app.club_php:requestBroadcast(app.club_php.clubID, playerInfo.uid, BroadcastCode, BroadcastContent)
  303. else
  304. log("ClubInvite:showPlayerInfo() self.roomId is nil or self.clubName is nil or self.gameRule is nil")
  305. showTooltip("邀请失败,数据错误")
  306. end
  307. end)
  308. itemLayout:addChild(uiItem);
  309. end
  310. --刷新
  311. function ClubInvite:onClickRefresh()
  312. playBtnEffect()
  313. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  314. --参数1:茶馆id 参数2:排序字段 参数3:排序类型 参数4:时间标签 参数5:0默认成员数据,1在线成员数据
  315. app.club_php:requestInvitePlayerList(app.club_php.clubID, "role", "desc", 0, 1);
  316. end
  317. end
  318. --屏蔽开局玩家
  319. function ClubInvite:onClickPingbi()
  320. playBtnEffect()
  321. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  322. --设置类型{1:邀请勿扰, $value 拒接邀请对象uid; 2:屏蔽开局用户, $value 1屏蔽0可见; 3:俱乐部置顶, $value 1置顶0取消置顶}
  323. local setType = 2;
  324. local memberSetValue = 0
  325. if self.ui.Items.CheckBox_pingbi:getSelectedState() then
  326. --在这个监听事件里,复选框是选中后才会触发此事件,所以当前为选中状态时说明是屏蔽
  327. memberSetValue = 1;
  328. else
  329. memberSetValue = 0;
  330. end
  331. app.club_php:requestMemberSet(app.club_php.clubID, setType, memberSetValue)
  332. end
  333. end
  334. --屏蔽开局玩家成功
  335. function ClubInvite:MemberSetSuccess(event)
  336. if not event then
  337. return
  338. end
  339. -- if event.setType == 2 then
  340. -- --屏蔽开局玩家
  341. -- if app.club_php.clubPlayerList then
  342. -- --修改缓存中是否屏蔽开局玩家字段
  343. -- app.club_php.clubPlayerList.is_hideplay = tonumber(event.setValues)
  344. -- end
  345. -- end
  346. self:onGetPlayerListEnd()
  347. local club = app.club_php.clubList[app.club_php.clubID]
  348. local isHide = club.isHidePlay
  349. if not isHide then
  350. --参数1:茶馆id 参数2:排序字段 参数3:排序类型 参数4:时间标签 参数5:0默认成员数据,1在线成员数据
  351. app.club_php:requestInvitePlayerList(app.club_php.clubID, "role", "desc", 0, 1);
  352. end
  353. end
  354. function ClubInvite:onClickInviteAll()
  355. playBtnEffect()
  356. if not self.newPlayerList or table.nums(self.newPlayerList)==0 then
  357. return
  358. end
  359. local BroadcastCode = 10050;
  360. local Content = {};
  361. Content.roomid = self.roomId
  362. Content.gname = self.clubName
  363. local myUserInfo = json.decode(app.user.userInfo)
  364. local userInfo = {
  365. uid = app.user.loginInfo.uid,
  366. nick = myUserInfo.nickname,
  367. icon = myUserInfo.headimgurl,
  368. }
  369. local uids = ""
  370. for k,v in pairs(self.newPlayerList) do
  371. uids = uids..v.uid
  372. if k~= #self.newPlayerList then
  373. uids = uids..","
  374. end
  375. end
  376. Content.userInfo = userInfo
  377. Content.gamerule = self.gameRule
  378. local BroadcastContent = json.encode(Content)
  379. log("ClubInvite:onClickInviteAll() BroadcastContent = ", BroadcastContent)
  380. app.club_php:requestBroadcast(app.club_php.clubID, uids, BroadcastCode, BroadcastContent)
  381. end
  382. return ClubInvite