Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

344 wiersze
10 KiB

  1. -- 房间设置界面
  2. local RoomDaJuView = class("RoomDaJuView_28", cc.UIView)
  3. local Functions = require("pk_doudizhu.luaScript.Functions_28")
  4. function RoomDaJuView:ctor(response)
  5. RoomDaJuView.super.ctor(self)
  6. self.response = response
  7. self.zhanjiUrl = app.serverConfigs.clientConfig.webgamb or app.config.Setting.httpZhanJiUrl
  8. end
  9. function RoomDaJuView:onEnter()
  10. RoomDaJuView.super.onEnter(self)
  11. local ui = loadUI("pk_doudizhu/res/ui/ui_fangjian/doudizhu_ui_daJu.ui")
  12. self:addChild(ui)
  13. self.ui = ui
  14. -- 分享战绩
  15. self.ui.Items.Button_Share:registerClick(handler(self , self.onClickShare))
  16. -- 结束游戏
  17. self.ui.Items.Button_Over:registerClick(handler(self , self.onClickOver))
  18. -- 防封群分享
  19. self.ui.Items.Button_PreventShare:registerClick(handler(self , self.onClickShareZhanJiUrl))
  20. self:initPlayGameAgain()
  21. end
  22. function RoomDaJuView:updateView(data)
  23. --显示
  24. self:setVisible(true)
  25. --更新房间号
  26. self.ui.Items.Text_RoomId:setText("房号: " .. app.room.roomInfo.nShowTableId)
  27. --更新局数
  28. self.ui.Items.Text_JuShu:setText(string.format("%02d / %02d 局", app.room.roomInfo.nGameStartCount, app.room.roomInfo.nTotalGameNum))
  29. --更新时间
  30. self.ui.Items.Text_SystemTime:setText(getTimeString())
  31. --规则
  32. self.ui.Items.Text_GameRules:setText(Functions.getRuleStr())
  33. -- 防封群分享
  34. if not app.config.ModuleConfig.IsSupportZhanJiUrl then
  35. self.ui.Items.Layout_preventShare:setVisible(false)
  36. self.ui.Items.Layout_Buttons:requestDoLayout()
  37. self.ui.Items.Layout_Buttons:doLayout()
  38. else
  39. -- 获取分享网页战绩用的连接
  40. self:initShareUrl();
  41. end
  42. if isReviewVersion() then
  43. self.ui.Items.Layout_Share:setVisible(false)
  44. self.ui.Items.Layout_preventShare:setVisible(false)
  45. self.ui.Items.Layout_Buttons:requestDoLayout()
  46. self.ui.Items.Layout_Buttons:doLayout()
  47. end
  48. --更新玩家信息
  49. self:updatePlayer(data)
  50. end
  51. function RoomDaJuView:updatePlayer(data)
  52. --隐藏所有玩家
  53. for i = 1, 4 do
  54. local player = self.ui.Items["Layout_Player_" .. i]
  55. if player then
  56. player:setVisible(false)
  57. end
  58. end
  59. local maxScore = 0
  60. for _,v in pairs(data.memberList) do
  61. v.nTotalScore = tonumber(v.nTotalScore)
  62. if v.nTotalScore > maxScore then
  63. maxScore = v.nTotalScore
  64. end
  65. end
  66. --更新玩家数据
  67. for k,v in pairs(data.memberList) do
  68. local viewId = app.room:getViewIdByUserId(v.nUserId)
  69. local player = self.ui.Items["Layout_Player_" .. viewId]
  70. local userInfo = json.decode(v.userInfo)
  71. if player then
  72. v.nTotalScore = tonumber(v.nTotalScore)
  73. --显示玩家信息
  74. player:setVisible(true)
  75. --更新头像
  76. local head = self.ui.Items["Image_Head_" .. viewId]
  77. if head then
  78. setPlayerHeadImage(v.nUserId, userInfo.headimgurl, head)
  79. end
  80. --名字
  81. local name = self.ui.Items["Text_Name_" .. viewId]
  82. if name then
  83. name:setText("" .. userInfo.nickname)
  84. end
  85. --玩家id
  86. local userId = self.ui.Items["Text_UserId_" .. viewId]
  87. if userId then
  88. userId:setText("" .. v.nUserId)
  89. --显示隐藏游戏内选手id(主办人和管理员不限制,只针对海选赛) -- todo lwq
  90. -- begin
  91. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  92. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  93. if app.club_php:getCestIsOpen(app.club_php.clubID) then
  94. --隐私数据
  95. local clubInfo = app.club_php.clubList[app.club_php.clubID]
  96. self.cliext = clubInfo.groupext and clubInfo.groupext.cliext
  97. if not self.cliext or not self.cliext.is_hideUid or (self.cliext and self.cliext.is_hideUid == 1) then
  98. if clubInfo.role == ClubDefine.Job.Creator or clubInfo.role == ClubDefine.Job.Manager then
  99. userId:setVisible(true)
  100. else
  101. userId:setVisible(false)
  102. end
  103. end
  104. end
  105. end
  106. if v.nUserId == tonumber(app.user.loginInfo.uid) then
  107. userId:setVisible(true)
  108. end
  109. -- end
  110. end
  111. --分数
  112. local score = self.ui.Items["Text_Score_" .. viewId]
  113. if score then
  114. if v.nTotalScore > 0 then
  115. score:setText("+" .. v.nTotalScore)
  116. else
  117. score:setText("" .. v.nTotalScore)
  118. end
  119. end
  120. --更新背景
  121. local bg = self.ui.Items["Image_Bg_" .. viewId]
  122. if bg then
  123. if v.nTotalScore >= 0 then
  124. bg:loadTexture("pk_doudizhu/res/ui/zy_fangjian/doudizhu_daju/doudizhu_daju_winbg.png")
  125. else
  126. bg:loadTexture("pk_doudizhu/res/ui/zy_fangjian/doudizhu_daju/doudizhu_daju_losebg.png")
  127. end
  128. end
  129. --大赢家
  130. local banker = self.ui.Items["Image_MaxWin_" .. viewId]
  131. if banker then
  132. banker:setVisible(maxScore > 0 and maxScore <= v.nTotalScore)
  133. end
  134. end
  135. end
  136. self.ui.Items.Layout_Players:requestDoLayout()
  137. self.ui.Items.Layout_Players:doLayout()
  138. end
  139. -- 分享
  140. function RoomDaJuView:onClickShare()
  141. playBtnEffect()
  142. function callbackEx(ret, fileName)
  143. if tonumber(ret) == 1 then
  144. local info = {}
  145. info.contentType = "image"
  146. info.image = fileName
  147. info.imageWidth = 800
  148. local gamerule = nil
  149. local roomInfo = app.room.roomInfo
  150. if roomInfo.strGameInfo then
  151. local jsonInfo = json.decode(roomInfo.strGameInfo)
  152. if jsonInfo then
  153. gamerule = jsonInfo.gamerule
  154. end
  155. end
  156. local rulename = ""
  157. if gamerule then
  158. rulename = " - " .. getSubGameRuleName(app.gameId, gamerule)
  159. end
  160. local gameName = getSubGameName(app.gameId) .. rulename
  161. info.copyData = {
  162. type = 1,
  163. gameName = gameName or "",
  164. tableId = app.room.roomInfo.nShowTableId,
  165. userInfos = {},
  166. }
  167. info.isShareZhanjiUrl = true
  168. for nUserId,totalData in pairsByKeys(self.response.memberList) do
  169. local userInfo = app.room:getUserInfo(nUserId)
  170. --昵称
  171. local nickname = userInfo.nickname or ""
  172. local totalScore = totalData.nTotalScore
  173. table.insert(info.copyData.userInfos, { nickname = nickname, totalScore = totalScore })
  174. end
  175. local view = import("luaScript.Views.Main.ShareView"):new(info)
  176. view:setAnchorPoint(cc.p(0.5, 0.5))
  177. app:showWaitDialog(view)
  178. else
  179. showTooltip("截图保存失败")
  180. end
  181. end
  182. if isWin32Platform() then
  183. callbackEx(1, "testName")
  184. else
  185. local fileNameEx = cc.FileUtils:getInstance():getWritablePath() .. tostring(app.room.roomInfo.nShowTableId) .. "_screen.jpg"
  186. cc.FileUtils:getInstance():screenToFile(fileNameEx, function(retEx)
  187. callbackEx(retEx, fileNameEx)
  188. end)
  189. end
  190. end
  191. -- 确认
  192. function RoomDaJuView:onClickOver()
  193. playBtnEffect()
  194. app.room:dispatchEvent({name = "onGameOverResponse"})
  195. self:removeFromParent()
  196. app:gotoView(import("luaScript.Views.Main.MainView"):new(app.gameId, app.room.roomInfo.nShowTableId))
  197. end
  198. function RoomDaJuView:initShareUrl()
  199. app.php:initShareZhanJiToUrl(function(url)
  200. self.zhanjiUrl = url
  201. end)
  202. end
  203. function RoomDaJuView:onClickShareZhanJiUrl( sender )
  204. playBtnEffect()
  205. local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  206. local gameName = getSubGameName(28) or "悠闲麻将"
  207. local info = {}
  208. -- info.contentType = "image"
  209. info.image = fileName
  210. info.title = gameName.."战绩"
  211. -- info.imageWidth = 800
  212. info.menuIdxs = {1, 4, 5, 6}
  213. info.FFQFlag = true
  214. -- info.isShareZhanjiUrl = false
  215. info.copyData={
  216. type = 1,
  217. tableId = app.room.roomInfo.nShowTableId,
  218. userInfos = {},
  219. }
  220. local content = nil;
  221. local memberList = self.response.memberList
  222. for k,v in pairs(memberList) do
  223. local userInfo = json.decode(v.userInfo) or {}
  224. local nickname = userInfo.nickname or ""
  225. local totalScore = v.nTotalScore
  226. local userId = v.nUserId
  227. table.insert(info.copyData.userInfos,{nickname=nickname,totalScore=totalScore,nUserId = userId})
  228. local strUserInfo = ""
  229. if totalScore > 0 then
  230. strUserInfo = string.format("%s(+%s)", getShortName(nickname), totalScore)
  231. else
  232. strUserInfo = string.format("%s(%s)", getShortName(nickname), totalScore)
  233. end
  234. if content then
  235. content = content .. "," .. strUserInfo
  236. else
  237. content = strUserInfo
  238. end
  239. end
  240. local sharUrl = string.format("%s?uid=%s&gameid=%s&app=%s&roomid=%s&endtime=%s",
  241. self.zhanjiUrl,
  242. app.user.loginInfo.uid,
  243. 28,
  244. getAppId(),
  245. app.room.roomInfo.nShowTableId,
  246. self.response.ntime or os.time())
  247. info.url = sharUrl
  248. info.description = content
  249. dump(info)
  250. local view = import("luaScript.Views.Main.ShareView"):new(info)
  251. view:setAnchorPoint(cc.p(0.5, 0.5))
  252. app:showWaitDialog(view)
  253. end
  254. ---
  255. -- 初始化大结算再来一局
  256. -- @return
  257. --
  258. function RoomDaJuView:initPlayGameAgain ()
  259. local roomInfo = app.room.roomInfo or {};
  260. local gameId = roomInfo.gameId or app.gameId
  261. if dd.IClub.isInClub() and roomInfo.nShowTableId then
  262. local inviteList = {}
  263. for k,v in pairsByKeys(roomInfo.memberList) do
  264. if tonumber(v.nUserId) ~= app.user.loginInfo.uid then
  265. table.insert(inviteList, v.nUserId)
  266. end
  267. end
  268. local strInvite = Functions.getRuleStrByClubInvite()
  269. local btnPlayAgain = self.ui.Items.Button_PlayAgain
  270. dd.IPlayGameAgain.bindPlayAgainButton(btnPlayAgain, gameId, strInvite, inviteList, function ()
  271. -- 初始化成功后干嘛干嘛
  272. local visible = btnPlayAgain:isVisible()
  273. self.ui.Items.Layout_Button_PlayAgain:setVisible(visible)
  274. if self.ui.Items.Layout_Buttons then
  275. self.ui.Items.Layout_Buttons:requestDoLayout()
  276. self.ui.Items.Layout_Buttons:doLayout()
  277. self.ui.Items.Layout_Buttons:setPositionX(cc.Director:getInstance():getVisibleSize().width / 2)
  278. end
  279. end)
  280. --绑定消息通知回调
  281. self:bindEvent(app.club_php , GAME_EVENT.CLUB_INVITE , handler(self , self.onClubInviteEvent))
  282. else
  283. logD("RoomDaJuView:initPlayGameAgain", "不在亲友圈或桌子id为空,不能进行再来一局操作")
  284. if self.ui.Items.Layout_Button_PlayAgain then
  285. self.ui.Items.Layout_Button_PlayAgain:setVisible(false)
  286. end
  287. if self.ui.Items.Layout_Buttons then
  288. self.ui.Items.Layout_Buttons:requestDoLayout()
  289. self.ui.Items.Layout_Buttons:doLayout()
  290. self.ui.Items.Layout_Buttons:setPositionX(cc.Director:getInstance():getVisibleSize().width / 2)
  291. end
  292. end
  293. end
  294. ---
  295. -- 监听亲友圈邀请信息
  296. -- @param event
  297. -- @return
  298. --
  299. function RoomDaJuView:onClubInviteEvent(event)
  300. dd.IPlayGameAgain.showClubInviteDialog(event, nil, nil)
  301. end
  302. return RoomDaJuView