您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

345 行
10 KiB

  1. -- 房间设置界面
  2. local PKDef = PKFramework.PKImport("pk_base.luaScript.PKDef")
  3. local PKWanFa = PKFramework.ImportWanFa("luaScript.SubGameDefine.PuKe.PKWanFa")
  4. local PKRuleView = PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomRuleView")
  5. local PKRoomToolView = class("PKRoomToolView", cc.UIView)
  6. function PKRoomToolView:ctor(parent)
  7. PKRoomToolView.super.ctor(self);
  8. self.parent = parent
  9. end
  10. function PKRoomToolView:onEnter()
  11. PKRoomToolView.super.onEnter(self)
  12. local ui = loadUI("pk_base/res/ui/ui_fangjian/pk_ui_toolView.ui");
  13. self.ui = ui;
  14. self:addChild(ui);
  15. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  16. if app.room.roomInfo then
  17. local clubGameInfo = json.decode(app.room.roomInfo.Datas.strGameInfo)
  18. if clubGameInfo.ruleid then
  19. setAgainGameBaoJianId(clubGameInfo.ruleid)
  20. end
  21. end
  22. end
  23. self:initToolLayer()
  24. self:checkCanDismiss()
  25. end
  26. function PKRoomToolView:initToolLayer()
  27. --快速开始
  28. local fastImgMapping = {
  29. [4] = "pk_base/res/ui/zy_fangjian/pk_btn/pk_fangjian_fast_23.png",
  30. [3] = "pk_base/res/ui/zy_fangjian/pk_btn/pk_fangjian_23_start_btn.png",
  31. }
  32. self.ui.Items.Button_SpeedStart:loadTextureNormal(fastImgMapping[app.room.roomInfo.nMaxPlayCount] or fastImgMapping[3])
  33. self.ui.Items.Button_SpeedStart:registerClick(handler(self , self.onClickStart))
  34. -- 设置按钮
  35. self.ui.Items.Button_Menu:registerClick(handler(self , self.onClickMenu))
  36. -- 离开按钮
  37. self.ui.Items.Button_Leave:registerClick(function()
  38. if app.room.roomInfo.tableOverFlag and app.room.roomInfo.tableOverFlag > TABLE_OVER_FLAG.TABLE_OVER_NORMAL then
  39. showTooltip(TABLE_OVER_FLAG_TEXT[app.room.roomInfo.tableOverFlag]);
  40. gotoMainView()
  41. else
  42. playBtnEffect()
  43. self:leaveRoomRequet();
  44. end
  45. end)
  46. -- 解散按钮
  47. self.ui.Items.Button_Dismiss:registerClick(function ()
  48. playBtnEffect()
  49. app.room:requestDismissRoom(1)
  50. end)
  51. -- 设置按钮
  52. self.ui.Items.Button_Set:registerClick(function ()
  53. playBtnEffect()
  54. local view = import("pk_base.luaScript.Views.Room.PKRoomSettingView"):new();
  55. view:setAnchorPoint(cc.p(0.5, 0.5));
  56. app:showWaitDialog(view);
  57. end)
  58. -- 截屏按钮
  59. --[[self.ui.Items.Button_jieping:registerClick(function ()
  60. playBtnEffect()
  61. showScreenShot()
  62. end)--]]
  63. -- 邀请微信好友
  64. self.ui.Items.Button_Invite:registerClick(handler(self , self.onClickFriends))
  65. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  66. self.ui.Items.Button_club:setVisible(true)
  67. --切换回亲友圈
  68. self.ui.Items.Button_club:registerClick(function ()
  69. if IS_USER_NEW_CLUB then
  70. openClub()
  71. else
  72. local clubList = app.club_php.clubList
  73. if clubList and table.nums(clubList) > 0 then
  74. --房间号
  75. local roomInfo = app.room.roomInfo;
  76. if roomInfo then
  77. --创建房间时传入的桌子下标
  78. local strGameInfo = roomInfo.strGameInfo
  79. local ttGameInfo = json.decode(strGameInfo)
  80. local tableIdx = tonumber(ttGameInfo.tableIdx)
  81. log("PKRoomToolView:initToolLayer() clubList = ", clubList);
  82. if not clubList[tonumber(app.club_php.clubID)] or table.nums(clubList[tonumber(app.club_php.clubID)]) <= 0 then
  83. app.club_php:getClubList();
  84. return
  85. end
  86. local view = import("luaScript.Views.Club.ClubTable"):new(clubList[tonumber(app.club_php.clubID)], tableIdx)
  87. view:setAnchorPoint(cc.p(0.5, 0.5))
  88. app:showWaitDialog(view)
  89. end
  90. else
  91. --未找到亲友圈列表数据时,请求亲友圈列表(可能是断线重连)
  92. app.club_php:getClubList();
  93. end
  94. end
  95. end)
  96. else
  97. self.ui.Items.Button_club:setVisible(false)
  98. end
  99. -- 准备按钮
  100. self.ui.Items.Button_Ready:registerClick(handler(self , self.onClickReady))
  101. -- 亲友圈邀请
  102. self.ui.Items.Button_ClubInvite:registerClick(handler(self , self.onClickClubInvite))
  103. -- 详情按钮
  104. self.ui.Items.Button_Rule:registerClick(handler(self , self.onClickRule))
  105. --Button_WetChat
  106. --[[self.ui.Items.Button_gotoWeiXin:registerClick(function ()
  107. playBtnEffect()
  108. app.plugin:gotoWeiXin()
  109. end)--]]
  110. self:setMenuVisible(false)
  111. if not self.parent.isRecordview then
  112. self:initChatView()
  113. end
  114. end
  115. function PKRoomToolView:onClickReady()
  116. playBtnEffect()
  117. self.ui:sendMsg(app.room, PKDef.PKEvent.CallReadyRequest);
  118. end
  119. function PKRoomToolView:onClickStart()
  120. playBtnEffect()
  121. app.room:sendSpeedStartCmd(PKDef.SPEED_START_GAME.START_OPT_TYPE_REQ)
  122. end
  123. function PKRoomToolView:onClickMenu()
  124. playBtnEffect()
  125. self.ui.Items.Button_Menu:setBright(not self.ui.Items.Button_Menu:isBright())
  126. self:setMenuVisible(not self.ui.Items.Button_Menu:isBright())
  127. end
  128. --设置按钮菜单
  129. function PKRoomToolView:setMenuVisible(bVisible)
  130. self.ui.Items.ImageView_menu_bg:setVisible(bVisible)
  131. end
  132. -- 邀请好友
  133. function PKRoomToolView:onClickFriends()
  134. --2-4人的字牌,通用
  135. local ttFour = {
  136. [0]= "零缺四",
  137. [1]= "一缺三",
  138. [2]= "二缺二",
  139. [3]= "三缺一",
  140. [4]= "满座",
  141. }
  142. local ttThree =
  143. {
  144. [0]= "零缺三",
  145. [1]= "一缺二",
  146. [2]= "二缺一",
  147. [3]= "满座",
  148. }
  149. local ttTwo =
  150. {
  151. [0]= "零缺二",
  152. [1]= "一缺一",
  153. [2]= "满座",
  154. }
  155. local nowPlayer = app.room:getCurMaxPlayer()
  156. local maxPlayer = app.room.roomInfo.nMaxPlayCount
  157. local strNum = nil
  158. if maxPlayer == 2 then
  159. strNum = ttTwo[nowPlayer]
  160. elseif maxPlayer == 3 then
  161. strNum = ttThree[nowPlayer]
  162. elseif maxPlayer == 4 then
  163. strNum = ttFour[nowPlayer]
  164. end
  165. --根据游戏类型分享
  166. local title = string.format("板子炮 房号[%s] %s", app.room.roomInfo.nShowTableId, strNum)
  167. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  168. title = string.format("%s 亲友圈ID[%d]", title, tonumber(app.club_php.clubID))
  169. end
  170. local strGameNum = string.format("%s局", app.room.roomInfo.nTotalGameNum)
  171. local strGameMode = PKWanFa.getRuleInfo()
  172. local strNames = ""
  173. local index = 0
  174. for k,v in pairs(app.room.roomInfo.memberList) do
  175. index = index + 1
  176. local userInfo = json.decode(v.userInfo)
  177. local name = getSubStringNickname(userInfo.nickname)
  178. strNames = strNames..name
  179. if index < maxPlayer then
  180. strNames = strNames..","
  181. end
  182. end
  183. local desc = string.format("%s,%s \n玩家:%s", strGameNum, strGameMode, strNames)
  184. local info = {}
  185. if not app.room.roomInfo.nShowTableId then
  186. showTooltip("房间号不存在")
  187. return
  188. end
  189. info.title = title
  190. info.description = desc
  191. info.gameMode = strGameMode
  192. info.copyData={type=2}
  193. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  194. info.menuIdxs = {1,2,4,5,6}
  195. else
  196. info.menuIdxs = {1,2,4,5,6}
  197. end
  198. print("用户开始分享")
  199. local view = import("luaScript.Views.Main.ShareView"):new(info)
  200. view:setAnchorPoint(cc.p(0.5, 0.5))
  201. app:showWaitDialog(view)
  202. end
  203. function PKRoomToolView:onClickClubInvite()
  204. playBtnEffect()
  205. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  206. local ruleStr = PKWanFa.getInviteInfo()
  207. local view = import("luaScript.Views.Club.ClubInvite"):new(app.room.roomInfo.nShowTableId, ruleStr)
  208. view:setAnchorPoint(cc.p(0.5, 0.5))
  209. app:showWaitDialog(view)
  210. end
  211. end
  212. --显示详情
  213. function PKRoomToolView:onClickRule()
  214. playBtnEffect()
  215. local view = PKRuleView:new()
  216. view:setAnchorPoint(cc.p(0.5, 0.5))
  217. app:showWaitDialog(view)
  218. end
  219. function PKRoomToolView:initChatView()
  220. local children = self.ui.Items.Layout_FaceView:getChildByTag(99)
  221. if children then
  222. children:removeFromParent()
  223. end
  224. local messageList = PKDef.GameChatTxt
  225. local headInfos = {}
  226. headInfos[1] = {headPos = cc.pAdd(self.parent.PlayerView.allNodes[1].head:getWorldPosition() , cc.p(0,0)), voiceDir = 1}
  227. headInfos[2] = {headPos = cc.pAdd(self.parent.PlayerView.allNodes[2].head:getWorldPosition() , cc.p(0,0)), voiceDir = 2}
  228. headInfos[3] = {headPos = cc.pAdd(self.parent.PlayerView.allNodes[3].head:getWorldPosition() , cc.p(0,0)), voiceDir = 2}
  229. headInfos[4] = {headPos = cc.pAdd(self.parent.PlayerView.allNodes[4].head:getWorldPosition() , cc.p(0,0)), voiceDir = 2}
  230. self.chatView = require("luaScript.Views.Room.ChatView"):new({chatList=messageList},headInfos,true)
  231. if self.chatView then
  232. self.chatView:setLanguage(false)
  233. -- 如果没有语音插件,则不显示语音按钮
  234. if not app.plugin.pluginVoice then
  235. logE("ZPRoomView:没有语音插件")
  236. --self.messageView.ui.Items.Button_Voice:setVisible(false)
  237. end
  238. end
  239. self.chatView:setTag(99)
  240. self.chatView:setBtnFace(cc.p(0.9601563,0.1930273))
  241. self.chatView:setBtnVoice(cc.p(0.9601563,0.0630273))
  242. self.ui.Items.Layout_FaceView:addChild(self.chatView)
  243. end
  244. function PKRoomToolView:leaveRoomRequet()
  245. app.room.roomInfo.bQuitRoom = true;
  246. self.ui:sendMsg(app.room, PKDef.PKEvent.CallLeaveRequest);
  247. end
  248. function PKRoomToolView:showFastStart(is)
  249. local roomInfo = app.room.roomInfo
  250. local curCount = roomInfo.nGameStartCount or 0
  251. if curCount > 0 then
  252. self.ui.Items.Button_SpeedStart:setVisible(false)
  253. else
  254. local gameInfo=json.decode(roomInfo.strGameInfo)
  255. local playnum = gameInfo.playerNum or 0
  256. local isHaveEarlyStart = false
  257. if playnum == 5 then
  258. isHaveEarlyStart = true
  259. playnum = app.room.roomInfo.nMaxPlayCount
  260. end
  261. local isPeopleEnough = app.room:getCurMaxPlayer() < playnum and app.room:getCurMaxPlayer() > 1
  262. if isHaveEarlyStart and isPeopleEnough then
  263. self.ui.Items.Button_SpeedStart:setVisible(true)
  264. else
  265. self.ui.Items.Button_SpeedStart:setVisible(false)
  266. end
  267. end
  268. end
  269. ---
  270. -- 检测是否可以解散房间
  271. -- @param
  272. -- @return
  273. --
  274. function PKRoomToolView:checkCanDismiss( )
  275. local onCanDismissCallback = function (info)
  276. local nUserId = app.room:getMyUserId()
  277. local roomInfo = app.room.roomInfo or {}
  278. local canDismiss = (tonumber(info.canDismiss or 1) == 1) or roomInfo.nRoomOwnedUid == nUserId or dd.IClub.isAdmin()
  279. if roomInfo.nGameStartCount == 0 and roomInfo.nRoomOwnedUid ~= nUserId then
  280. canDismiss = false
  281. end
  282. self:onCanDismissCallback(canDismiss)
  283. end
  284. if dd.IClub.getCanDismiss then
  285. local canDismiss = dd.IClub.getCanDismiss(onCanDismissCallback)
  286. if canDismiss then
  287. onCanDismissCallback({canDismiss = canDismiss})
  288. end
  289. end
  290. end
  291. function PKRoomToolView:onCanDismissCallback(canDismiss)
  292. if self.ui.Items.Button_Dismiss then
  293. self.ui.Items.Button_Dismiss:setEnabled(canDismiss)
  294. end
  295. end
  296. return PKRoomToolView;