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.

626 lines
17 KiB

  1. -- 房间设置界面
  2. local MJRoomSettingView = MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomSettingView")
  3. local MJWanFa=MJFramework.ImportWanFa("luaScript.SubGameDefine.MaJiang.MJWanFa")
  4. local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
  5. local MJFunction=MJFramework.MJImport("mj.luaScript.MJFunction")
  6. local MJMessage = import("mj.luaScript.Protocol.MJMessage")
  7. local MJRoomToolView = class("MJRoomToolView", cc.UIView)
  8. -- require("LiuHuQiangDef")
  9. function MJRoomToolView:ctor()
  10. MJRoomToolView.super.ctor(self);
  11. self:loadUI()
  12. --是否是该场景点了准备
  13. self.isTouchCurScene = false
  14. end
  15. function MJRoomToolView:loadUI()
  16. local ui = loadUI("mj/res/ui/ui_fangjian/mj_ui_tool.ui");
  17. -- local ui = loadUI("mj/res/ui/ui_fangjian/mj_ui_new_tool.ui");
  18. self.ui = ui;
  19. self:addChild(ui);
  20. end
  21. function MJRoomToolView:onEnter()
  22. MJRoomToolView.super.onEnter(self)
  23. self:initEvents()
  24. --测试开关
  25. self.ui.Items.Layout_Test:setVisible(false)
  26. --播放队列
  27. self.ui.Items.Button_Play:registerClick(function ()
  28. app.net:onMsgResume()
  29. end)
  30. --停止队列
  31. self.ui.Items.Button_Stop:registerClick(function ()
  32. app.net:onMsgPause()
  33. end)
  34. self:initButton()
  35. self:updateButtonPosition()
  36. --上传日记
  37. --[[ local day = os.date("%Y-%m-%d")
  38. local key = string.format("dingdinglog-%s",day)
  39. local isShow = cc.UserDefault:getInstance():getBoolForKey(key,false)
  40. if isShow or isReviewVersion() then
  41. -- self.ui.Items.Button_updateLog:setVisible(false)
  42. end
  43. if isDebug() or cc.Application:getInstance():getTargetPlatform() == 0 then
  44. self.ui.Items.Button_Upload:setVisible(true)
  45. end
  46. --]]
  47. -- 详情
  48. -- self.ui.Items.Button_ruleIntro:registerClick(handler(self , self.onClickRule))
  49. -- self.ui.Items.ImageView_Rule_bg:setVisible(false)
  50. end
  51. function MJRoomToolView:onExit( )
  52. logD("MJRoomToolView:onExit")
  53. end
  54. ---
  55. -- 初始化事件
  56. -- @return
  57. --
  58. function MJRoomToolView:initEvents()
  59. self:bindEvent(app.room , MJDefine.MJEvent.GameStartResponse, handler(self , self.onGameStartResponse));
  60. end
  61. function MJRoomToolView:initButton()
  62. if self.ui.Items.Button_Invite then
  63. self.ui.Items.Button_Invite:registerClick(handler(self,self.onClickInvite))
  64. end
  65. if self.ui.Items.Button_Ready then
  66. self.ui.Items.Button_Ready:registerClick(handler(self,self.onClickReady))
  67. end
  68. if self.ui.Items.Button_Invite_Club then
  69. self.ui.Items.Button_Invite_Club:registerClick(handler(self,self.onClickInviteClub))
  70. end
  71. if self.ui.Items.Button_FastStart then
  72. self.ui.Items.Button_FastStart:registerClick(handler(self,self.onClickQuickStart))
  73. end
  74. if self.ui.Items.Button_Copy then
  75. self.ui.Items.Button_Copy:registerClick(handler(self,self.onClickCopy))
  76. end
  77. -- self.ui.Items.Button_Voice:registerClick(handler(self,self.onClickVoice))
  78. if self.ui.Items.Button_Voice then
  79. self.ui.Items.Button_Voice:setVisible(not MJFunction:isVoiceFobided())
  80. end
  81. if self.ui.Items.Button_Face then
  82. self.ui.Items.Button_Face:registerClick(handler(self,self.onClickFace))
  83. self.ui.Items.Button_Face:setVisible(not MJFunction:isPropFobided())
  84. end
  85. -- 菜单按钮
  86. if self.ui.Items.Button_Menu then
  87. self.ui.Items.Button_Menu:registerClick(handler(self , self.onClickMenu))
  88. end
  89. --菜单背景layout,注册时间防止穿透点到下面的头像
  90. if self.ui.Items.Layout_Menu then
  91. self.ui.Items.Layout_Menu:registerClick(handler(self , self.onClickLayoutMenu))
  92. end
  93. if self.ui.Items.Button_Leave then
  94. self.ui.Items.Button_Leave:registerClick(handler(self , self.onClickLeave))
  95. end
  96. if self.ui.Items.Button_Dismiss then
  97. self.ui.Items.Button_Dismiss:registerClick(handler(self , self.onClickDismiss))
  98. end
  99. if self.ui.Items.Button_Set then
  100. self.ui.Items.Button_Set:registerClick(handler(self , self.onClickSet))
  101. end
  102. if self.ui.Items.Button_Rule then
  103. self.ui.Items.Button_Rule:registerClick(handler(self , self.onClickRule))
  104. self.ui.Items.Button_Rule:setVisible(false)
  105. end
  106. if self.ui.Items.Layout_tuoguan then
  107. self.ui.Items.Button_guoguan:registerClick(handler(self , self.onClickQXTuoGuan))
  108. self.ui.Items.Layout_tuoguan:setTouchEnabled(true)
  109. self.ui.Items.Layout_tuoguan:setLocalZOrder(1000)
  110. self:showTuoGuan(false)
  111. end
  112. ---self.ui.Items.Layout_Touch:registerClick(handler(self , self.onClickBlank))
  113. self:initVoiceComponent()
  114. self:initButtonBaoJian()
  115. self:setMenuVisible(false, true)
  116. -- self.ui.Items.Layout_Rule:setVisible(false)
  117. if self.ui.Items.Layout_Rule then
  118. self.ui.Items.Layout_Rule:runAction(cc.Sequence:create(
  119. cc.DelayTime:create(2),
  120. cc.CallFunc:create(function()
  121. self:hideRule()
  122. end)))
  123. end
  124. end
  125. function MJRoomToolView:initVoiceComponent()
  126. local voiceComponentView = import("luaScript.Views.Room.RoomVoiceComponentView"):new(self.ui.Items.Button_Voice)
  127. self:addChild(voiceComponentView)
  128. end
  129. function MJRoomToolView:onClickRule()
  130. self.ui.Items.Layout_Rule:setVisible(true)
  131. self.ui.Items.Button_Rule:setVisible(false)
  132. end
  133. function MJRoomToolView:hideRule()
  134. if self.ui.Items.Layout_Rule then
  135. self.ui.Items.Layout_Rule:stopAllActions()
  136. self.ui.Items.Layout_Rule:setVisible(false)
  137. end
  138. if self.ui.Items.Button_Rule then
  139. self.ui.Items.Button_Rule:setVisible(true)
  140. end
  141. end
  142. function MJRoomToolView:updateRule()
  143. if not self.ui.Items.Text_Rule then
  144. return
  145. end
  146. --房间规则不会中途变化,不用多次更新
  147. if not self.isHadupdateRule then
  148. self.isHadupdateRule = true
  149. else
  150. return
  151. end
  152. local roomInfo = app.room.roomInfo;
  153. self.ui.Items.Text_Rule:setVisible(false)
  154. -- self.ui.Items.Layout_Rule:setVisible(false)
  155. self.ui.Items.ListView:removeAllChildren()
  156. self.ui.Items.ListView:setAutoSize(true)
  157. local rules = MJWanFa.getWanFaInfoTab(roomInfo.strGameInfo, app.room.roomInfo.nTotalGameNum)
  158. for k,v in pairs(rules) do
  159. local text = self.ui.Items.Text_Rule:getCopied()
  160. text:setVisible(true)
  161. text:setString(v)
  162. self.ui.Items.ListView:addChild(text)
  163. end
  164. end
  165. --隐藏微信按钮
  166. function MJRoomToolView:setWetChatVisible(bVisible)
  167. if self.ui.Items.Button_Invite then
  168. self.ui.Items.Button_Invite:getParent():setVisible(bVisible)
  169. --self:updateButtonPosition()
  170. --审核或者开局后都默认隐藏
  171. if isReviewVersion() then
  172. logD("MJRoomToolView:setWetChatVisible isReviewVersion()")
  173. self.ui.Items.Button_Invite:getParent():setVisible(false)
  174. end
  175. end
  176. self:setInviteClubVisible(bVisible)
  177. end
  178. --按钮位置调整
  179. function MJRoomToolView:updateButtonPosition()
  180. if not self.ui.Items.Layout_Button then return end
  181. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  182. else
  183. -- local readyPosX = self.ui.Items.Button_Ready:getPositionX()
  184. -- self.ui.Items.Button_Ready:setPositionX(readyPosX+90)
  185. -- local posX = self.ui.Items.Button_Invite:getPositionX()
  186. -- self.ui.Items.Button_Invite:setPositionX(posX+90)
  187. end
  188. if self.ui.Items.Layout_Button then
  189. self.ui.Items.Layout_Button:requestDoLayout()
  190. self.ui.Items.Layout_Button:doLayout()
  191. end
  192. end
  193. function MJRoomToolView:updateButton(isMove)
  194. local roomInfo = app.room.roomInfo
  195. local curMemberNum = table.nums(roomInfo.memberList)
  196. --没有坐满
  197. local isNotSitFull = curMemberNum < roomInfo.nMaxPlayCount
  198. --更新邀请按钮
  199. self:setWetChatVisible(isNotSitFull)
  200. --更新快速开局 没有坐满并且当前人数大于2显示
  201. local info = json.decode(roomInfo.strGameInfo or "") or {}
  202. if self.ui.Items.Button_FastStart then
  203. self.ui.Items.Button_FastStart:setVisible(isNotSitFull and curMemberNum>=2 and info.isfaststart == 1)
  204. end
  205. local nUserId = app.room:getMyUserId()
  206. local memberInfo = roomInfo.memberList[nUserId]
  207. --更新准备按钮状态
  208. if self.ui.Items.Button_Ready then
  209. self.ui.Items.Button_Ready:getParent():setVisible(memberInfo.nPlayerFlag == 0)
  210. end
  211. --更新解散按钮状态
  212. if roomInfo.nGameStartCount == 0 and roomInfo.nRoomOwnedUid ~= nUserId then
  213. self.ui.Items.Button_Dismiss:setEnabled(false)
  214. else
  215. self.ui.Items.Button_Dismiss:setEnabled(true)
  216. end
  217. --已经开局
  218. if roomInfo.nGameStartCount>0 then
  219. if self.ui.Items.Button_Leave then
  220. self.ui.Items.Button_Leave:setEnabled(false)
  221. end
  222. self:setWetChatVisible(false)
  223. -- self.ui.Items.Button_Invite:getParent():setVisible(false)
  224. if self.ui.Items.Button_FastStart then
  225. self.ui.Items.Button_FastStart:setVisible(false)
  226. end
  227. if self.ui.Items.Button_Ready then
  228. self.ui.Items.Button_Ready:getParent():setVisible(false)
  229. end
  230. end
  231. self:updateButtonPosition()
  232. self:checkCanDismiss()
  233. end
  234. function MJRoomToolView:onClickReady()
  235. self.ui:sendMsg(app.room, MJDefine.MJEvent.CallReadyRequest)
  236. playVoice("res/sound/room/sit.ogg")
  237. end
  238. --初始包间按钮
  239. function MJRoomToolView:initButtonBaoJian()
  240. if not self.ui.Items.Button_BaoJian then
  241. return
  242. end
  243. self.ui.Items.Button_BaoJian:registerClick(handler(self , self.onClickBaoJian))
  244. --包间
  245. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  246. self.ui.Items.Button_BaoJian:setVisible(true)
  247. else
  248. self.ui.Items.Button_BaoJian:setVisible(false)
  249. end
  250. end
  251. --点击日记
  252. function MJRoomToolView:onClickLog()
  253. playBtnEffect()
  254. print("=========================DingDingLog===============================")
  255. local uiTechnialView
  256. uiTechnialView = import("luaScript.Views.Room.UplogView"):new()
  257. self:addChild(uiTechnialView)
  258. end
  259. function MJRoomToolView:getInviteData()
  260. local tt =
  261. {
  262. [0] = "零缺四",
  263. [1] = "一缺三",
  264. [2] = "二缺二",
  265. [3] = "三缺一",
  266. [4] = "满座",
  267. }
  268. if app.room:getMaxPlayerCount()==3 then
  269. tt =
  270. {
  271. [0] = "零缺三",
  272. [1] = "一缺二",
  273. [2] = "二缺一",
  274. [3] = "满座",
  275. }
  276. end
  277. if app.room:getMaxPlayerCount()==2 then
  278. tt =
  279. {
  280. [0] = "零缺二",
  281. [1] = "一缺一",
  282. [2] = "满座",
  283. }
  284. end
  285. local num = table.nums(app.room.roomInfo.memberList)
  286. local strNum = tt[num]
  287. --根据游戏类型分享
  288. local roomInfo = app.room.roomInfo;
  289. local jsonInfo = json.decode(roomInfo.strGameInfo)
  290. local mjName=getSubGameConfig(app.room.roomInfo.gameId).gameName or "麻将"
  291. local title = string.format("%s 房号[%s] %s", mjName,app.room.roomInfo.nShowTableId,strNum)
  292. --添加俱乐部ID
  293. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  294. title = string.format("%s %sID[%d]", title,PLN.CLUB_NAME, tonumber(app.club_php.clubID))
  295. end
  296. local strGameNum = string.format("%s局", app.room.roomInfo.nTotalGameNum)
  297. local strGameMode = MJWanFa.getWanFaInfo(app.room.roomInfo.strGameInfo)--getLHQRuleStr()
  298. local strNames = ""
  299. local index = 0
  300. for k,v in pairs(app.room.roomInfo.memberList) do
  301. index = index + 1
  302. local userInfo = json.decode(v.userInfo)
  303. local name = getSubStringNickname(userInfo.nickname)
  304. strNames = strNames..name
  305. if index < num then
  306. strNames = strNames..","
  307. end
  308. end
  309. local desc = string.format("%s,%s 玩家:%s", strGameNum, strGameMode, strNames)
  310. print(desc)
  311. return title,desc
  312. end
  313. -- 邀请好友
  314. function MJRoomToolView:onClickInvite()
  315. playBtnEffect()
  316. local title,desc = self:getInviteData()
  317. local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  318. local info = {}
  319. info.title = title
  320. info.description = desc
  321. info.copyData={type=2}
  322. local view = import("luaScript.Views.Main.ShareView"):new(info)
  323. view:setAnchorPoint(cc.p(0.5, 0.5))
  324. app:showWaitDialog(view)
  325. --app.plugin:shareGame(info)
  326. end
  327. --点击亲友圈邀请
  328. function MJRoomToolView:onClickInviteClub()
  329. playBtnEffect()
  330. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  331. local roomInfo = app.room.roomInfo;
  332. --local gameInfo = roomInfo.nGameInfo
  333. if roomInfo and roomInfo.nShowTableId then
  334. local strInvite = MJFunction.getClubInviteWanFa(app.gameId, roomInfo)
  335. local view = import("luaScript.Views.Club.ClubInvite"):new(roomInfo.nShowTableId, strInvite)
  336. view:setAnchorPoint(cc.p(0.5, 0.5))
  337. app:showWaitDialog(view)
  338. end
  339. end
  340. end
  341. --设置邀请亲友圈成员显示
  342. function MJRoomToolView:setInviteClubVisible(bVisible)
  343. if self.ui.Items.Button_Invite_Club then
  344. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  345. self.ui.Items.Button_Invite_Club:getParent():setVisible(bVisible)
  346. else
  347. self.ui.Items.Button_Invite_Club:getParent():setVisible(false)
  348. end
  349. local roomInfo = app.room.roomInfo or {}
  350. local gameId = roomInfo.gameId or app.gameId
  351. local gameConfig = getSubGameConfig(gameId)
  352. if gameConfig.isOpenClubInvite == false then
  353. self.ui.Items.Button_Invite_Club:getParent():setVisible(false)
  354. end
  355. --审核或者开局后都默认隐藏
  356. if isReviewVersion() then
  357. logD("MJRoomToolView:setInviteClubVisible isReviewVersion()")
  358. self.ui.Items.Button_Invite_Club:setVisible(false)
  359. end
  360. end
  361. end
  362. function MJRoomToolView:onClickQuickStart()
  363. playBtnEffect()
  364. local request = MJMessage.FastStartRequest:new()
  365. request.tp = 1
  366. self.ui:sendMsg(app.room,MJDefine.MJEvent.RequestFastsStart, request)
  367. end
  368. --菜单按钮 (通过动画实现)
  369. function MJRoomToolView:onClickMenu()
  370. playBtnEffect()
  371. self:setMenuVisible(not self.ui.Items.Layout_Menu:isVisible())
  372. end
  373. function MJRoomToolView:onClickLayoutMenu()
  374. end
  375. --设置按钮菜单
  376. function MJRoomToolView:setMenuVisible(bVisible,flag)
  377. if flag then
  378. self.ui.Items.Layout_Menu:setVisible(bVisible)
  379. return
  380. end
  381. if bVisible then
  382. self.ui.Items.Layout_Menu:setVisible(bVisible)
  383. else
  384. self.ui.Items.Layout_Menu:setVisible(bVisible)
  385. end
  386. end
  387. --离开按钮
  388. function MJRoomToolView:onClickLeave()
  389. playBtnEffect()
  390. if app.room then
  391. self.ui:sendMsg(app.room, "callLeaveRequest")
  392. end
  393. end
  394. --解散按钮
  395. function MJRoomToolView:onClickDismiss()
  396. playBtnEffect()
  397. local function onClickOk()
  398. if app.room and app.room.requestDismissRoom then
  399. app.room:requestDismissRoom(1)
  400. end
  401. end
  402. local function onClickCancel()
  403. end
  404. showConfirmDialog("确认发起解散?", onClickOk,onClickCancel)
  405. self:setMenuVisible(false)
  406. --self.ui.Items.Button_Dismiss:setEnabled(false)
  407. end
  408. --设置按钮
  409. function MJRoomToolView:onClickSet()
  410. playBtnEffect()
  411. local view = MJRoomSettingView:new();
  412. view:setAnchorPoint(cc.p(0.5, 0.5));
  413. app:showWaitDialog(view,100);
  414. --[[if self.setCallBack then
  415. self.setCallBack()
  416. end--]]
  417. end
  418. --上传按钮
  419. function MJRoomToolView:onClickUpload()
  420. local uiTechnialView = import("luaScript.Views.Room.UplogView"):new()
  421. self:addChild(uiTechnialView)
  422. end
  423. --包间按钮
  424. function MJRoomToolView:onClickBaoJian()
  425. playBtnEffect()
  426. if IS_USER_NEW_CLUB then
  427. openClub()
  428. else
  429. local clubList = app.club_php.clubList
  430. if clubList and table.nums(clubList) > 0 then
  431. --房间号
  432. local roomInfo = app.room.roomInfo
  433. if roomInfo then
  434. --创建房间时传入的桌子下标
  435. local strGameInfo = roomInfo.strGameInfo
  436. local ttGameInfo = json.decode(strGameInfo)
  437. local tableIdx = tonumber(ttGameInfo.tableIdx)
  438. self.clubView = import("luaScript.Views.Club.ClubTable"):new(clubList[app.club_php.clubID], tableIdx)
  439. self.clubView:setAnchorPoint(cc.p(0.5, 0.5))
  440. app:showWaitDialog(self.clubView)
  441. end
  442. else
  443. --未找到俱乐部列表数据时,请求俱乐部列表(可能是断线重连)
  444. app.club_php:getClubList();
  445. end
  446. end
  447. end
  448. --[[--点击空白地方
  449. function MJRoomToolView:onClickBlank()
  450. --关闭菜单
  451. self:setMenuVisible(false,true)
  452. end--]]
  453. --隐藏俱乐部
  454. function MJRoomToolView:hideClub()
  455. --self.ui.Items.Button_BaoJian:setVisible(false)
  456. if self.clubView and not tolua.isnull(self.clubView) then
  457. self.clubView:removeFromParent()
  458. self.clubView=nil
  459. end
  460. end
  461. function MJRoomToolView:onClickCopy()
  462. playBtnEffect()
  463. local title,desc = self:getInviteData()
  464. local clubData = ""
  465. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  466. local clubName = ""
  467. local clubList = app.club_php.clubList
  468. if clubList and table.nums(clubList) > 0 then
  469. clubName = clubList[tonumber(app.club_php.clubID)].clubName;
  470. end
  471. clubData = string.format(PLN.CLUB_NAME.."名:%s \n", clubName)
  472. end
  473. local tishi = "复制信息打开游戏将自动入座\n<仅供娱乐,严禁赌博>"
  474. copyData = string.format("%s%s\n%s\n%s",clubData,title,desc,tishi)
  475. logD(copyData)
  476. copyStringToClipboard(copyData)
  477. app.plugin:gotoWeiXin()
  478. end
  479. -- function MJRoomToolView:onClickVoice()
  480. -- end
  481. function MJRoomToolView:onClickFace()
  482. local chatView = import("luaScript.Views.Room.RoomChatView"):new(MJDefine.MJChatTxt,MJDefine.MJFaceConfig)
  483. chatView:setAnchorPoint(cc.p(0.5, 0.5))
  484. app:showWaitDialog(chatView,0,true)
  485. end
  486. function MJRoomToolView:onClickQXTuoGuan( sender )
  487. playBtnEffect()
  488. --
  489. local request = MJMessage.HostingRequest:new()
  490. request.nUserId = 0
  491. request.status = 0 --1托管 0取消托管
  492. self.ui:sendMsg(app.room, MJDefine.MJEvent.HostingRequest, request)
  493. end
  494. function MJRoomToolView:showTuoGuan( is )
  495. self.ui.Items.Layout_tuoguan:setVisible(is==true)
  496. end
  497. function MJRoomToolView:onGameStartResponse()
  498. self:checkCanDismiss()
  499. end
  500. ---
  501. -- 检测是否可以解散房间
  502. -- @param
  503. -- @return
  504. --
  505. function MJRoomToolView:checkCanDismiss( )
  506. local onCanDismissCallback = function (info)
  507. local nUserId = app.room:getMyUserId()
  508. local roomInfo = app.room.roomInfo or {}
  509. local canDismiss = (tonumber(info.canDismiss or 1) == 1) or roomInfo.nRoomOwnedUid == nUserId or dd.IClub.isAdmin()
  510. if roomInfo.nGameStartCount == 0 and roomInfo.nRoomOwnedUid ~= nUserId then
  511. canDismiss = false
  512. end
  513. self:onCanDismissCallback(canDismiss)
  514. end
  515. if dd.IClub.getCanDismiss then
  516. local canDismiss = dd.IClub.getCanDismiss(onCanDismissCallback)
  517. if canDismiss then
  518. onCanDismissCallback({canDismiss = canDismiss})
  519. end
  520. end
  521. end
  522. function MJRoomToolView:onCanDismissCallback(canDismiss)
  523. if not tolua.isnull(self.ui.Items.Button_Dismiss) then
  524. self.ui.Items.Button_Dismiss:setEnabled(canDismiss)
  525. end
  526. end
  527. return MJRoomToolView;