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.

512 lines
15 KiB

  1. -- 战绩单元Layout
  2. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  3. local ClubZhanJiItem = class("ClubZhanJiItem")
  4. function ClubZhanJiItem:ctor(gid, zhanjiType, infoData, tableIdx,index)
  5. self.gid = gid
  6. self.zhanjiType = zhanjiType
  7. self.roomInfo = infoData
  8. --从房间返回茶馆的桌子标识
  9. self.tableIdx = tableIdx
  10. --序号
  11. self.index = index
  12. self.detailTxtColor = cc.c4b(213,255,249,255)
  13. self:initView()
  14. end
  15. --初始化界面
  16. function ClubZhanJiItem:initView()
  17. self.ui = loadUI("res/ui/ui_zhanji/ui_zhanji_item.ui")
  18. local uiSize = self.ui:getSize();
  19. local realSize = {width = uiSize.width * g_radio_x,height = uiSize.height * g_radio_y}
  20. self.ui:setSize(realSize)
  21. self.ui.Items.Layout_player:setVisible(false)
  22. self.ui.Items.Layout_game_title_club:setVisible(false)
  23. self.ui.Items.Layout_game_title_me:setVisible(false)
  24. self.ui.Items.Button_xiangqing:registerClick(handler(self , self.onClickDetails))
  25. self.ui.Items.Button_url:registerClick(handler(self , self.onClickShareUrl))
  26. if not app.config.ModuleConfig.IsSupportZhanJiUrl or isReviewVersion() then
  27. self.ui.Items.Layout_1:setVisible(false)
  28. self.ui.Items.Layout_Button:requestDoLayout()
  29. self.ui.Items.Layout_Button:doLayout()
  30. end
  31. -- self.ui.Items.Button_copy:getParent():setVisible(false)
  32. self.ui.Items.Button_Sure:registerClick(handler(self , self.onClickSure))
  33. self:init()
  34. end
  35. function ClubZhanJiItem:getRoot()
  36. return self.ui
  37. end
  38. function ClubZhanJiItem:init()
  39. local club = app.club_php.clubList[self.gid]
  40. if club and club.role~=ClubDefine.Job.Member and club.role~=ClubDefine.Job.LevelTwoCopartner
  41. and club.role~=ClubDefine.Job.LevelOneCopartner and club.role~=ClubDefine.Job.LevelThreeCopartner and self.zhanjiType ~= ClUB_ZHANJI_TYPE.Mine then
  42. if app.club_zhanji.zhanJiIdxStatus[self.roomInfo.pid]==2 then --确认过
  43. self.ui.Items.Button_Sure:setVisible(false)
  44. end
  45. else
  46. self.ui.Items.Layout_player_count:setSize(cc.size(885,105))
  47. self.ui.Items.Button_Sure:getParent():setVisible(false)
  48. end
  49. self.ui.Items.Layout_Button:requestDoLayout()
  50. self.ui.Items.Layout_Button:doLayout()
  51. local scoreList = self.roomInfo.tscore
  52. --游戏icon
  53. local gameID = tonumber(self.roomInfo.gameid)
  54. local ruleID = tonumber(self.roomInfo.gext.gamerule)
  55. local gameName = getSubGameRuleName(gameID,ruleID)
  56. local gameConfig = getSubGameConfig(gameID) or {}
  57. -- local img = string.format("zhanji_game_%d.png",gameID)
  58. local isAAPay = 0
  59. if self.roomInfo.gext and self.roomInfo.gext.isAAPay then
  60. isAAPay = tonumber(self.roomInfo.gext.isAAPay)
  61. end
  62. --结果
  63. if self.zhanjiType == ClUB_ZHANJI_TYPE.Mine then
  64. --我的战绩(结果)
  65. self.ui.Items.ImageView_flag:setVisible(true)
  66. local myscore = scoreList[tostring(app.user.loginInfo.uid)]
  67. if myscore and myscore > 0 then
  68. self.ui.Items.ImageView_flag:loadTexture("res/ui/zy_dating/zhanji/zhanji_win_icon.png")
  69. else
  70. self.ui.Items.ImageView_flag:loadTexture("res/ui/zy_dating/zhanji/zhanji_lose_icon.png")
  71. end
  72. self.ui.Items.Layout_game_title_me:setVisible(true)
  73. self.ui.Items.Text_game_me:setString(gameName)
  74. self.ui.Items.Text_game_me_1:setString(gameName)
  75. -- self.ui.Items.ImageView_game_me:loadTextureFromPlist(img)
  76. else
  77. --茶馆战绩(房卡消耗)
  78. self.ui.Items.Layout_game_title_club:setVisible(true)
  79. self.ui.Items.ImageView_flag:setVisible(false)
  80. local cards = self.roomInfo.nCards
  81. if cards and cards ~= nil then
  82. if isAAPay == 1 then-- AA支付
  83. self.ui.Items.Text_fangka:setText(cards.. PLN.CURRENCY_UNIT .. "(AA)");
  84. else
  85. self.ui.Items.Text_fangka:setText(cards.. PLN.CURRENCY_UNIT);
  86. end
  87. end
  88. self.ui.Items.Text_game_club:setString(gameName)
  89. self.ui.Items.Text_game_club_1:setString(gameName)
  90. -- self.ui.Items.ImageView_game_club:loadTextureFromPlist(img)
  91. end
  92. --序号
  93. self.ui.Items.Text_No:setText(self.index)
  94. --时间
  95. local time = os.date("%Y-%m-%d %H:%M",self.roomInfo.endtime)
  96. self.ui.Items.Text_time:setText(time)
  97. --大赢家
  98. --[[local maxScore = nil;
  99. for uid, score in pairs(scoreList) do
  100. if not maxScore or maxScore < score then
  101. maxScore = score;
  102. end
  103. end--]]
  104. --房号
  105. local roomInfo = self.roomInfo.roomid;
  106. self.ui.Items.Text_roomid:setText("房号:"..roomInfo);
  107. --最终分数
  108. local scorUI = self.ui.Items.Layout_player_count;
  109. --scorUI:getInnerContainer():setAutoSize(true);
  110. scorUI:removeAllChildren();
  111. local scoreSize = table.nums(scoreList)
  112. --是否显示加减分
  113. if self.ui.Items.ImageView_Rule then
  114. self.ui.Items.ImageView_Rule:setVisible(false)
  115. local diFenLimit = self.roomInfo.gext.game_ext and self.roomInfo.gext.game_ext.diFenLimit;
  116. if diFenLimit and diFenLimit > 0 and scoreSize == 2 then
  117. self.ui.Items.ImageView_Rule:setVisible(true)
  118. end
  119. end
  120. local pid = self.roomInfo.pid
  121. local listStr = app.club_zhanji.zhanJiIdxLocals[pid]
  122. local list = listStr and split(listStr,",") or nil
  123. local uiTemplate = self.ui.Items.Layout_player;
  124. local contentSize = scorUI:getContentSize();
  125. for k,v in pairsByKeys(scoreList) do
  126. local uiItem = uiTemplate:getCopied()
  127. uiItem:setSize(cc.size(contentSize.width / scoreSize, contentSize.height))
  128. uiItem.Items = getUIItems(uiItem)
  129. --名字
  130. local playerInfo = app.playerInfoManager:getPlayerInfo(k);
  131. if playerInfo then
  132. local len = string.len(playerInfo.name)
  133. if len == 0 then
  134. playerInfo.name = "未知昵称"
  135. end
  136. playerInfo.name = getSubStringNickname(playerInfo.name)
  137. uiItem.Items.Text_player_name:setText(playerInfo.name)
  138. if list then
  139. for _,uid in ipairs(list) do
  140. if tonumber(uid) == tonumber(k) then
  141. uiItem.Items.Text_player_name:setTextColor(cc.c4b(219,56,35,255))
  142. end
  143. end
  144. end
  145. end
  146. if gameConfig.isUseDivision10 then
  147. v = v / 10
  148. end
  149. --分数
  150. if v > 0 then
  151. v = "+"..tostring(v)
  152. uiItem.Items.Text_score:setFntFile("res/fonts/zhanji_win.fnt")
  153. else
  154. --绿色
  155. uiItem.Items.Text_score:setFntFile("res/fonts/zhanji_lose.fnt")
  156. end
  157. uiItem.Items.Text_score:setText(v)
  158. scorUI:addChild(uiItem);
  159. end
  160. scorUI:requestDoLayout()
  161. scorUI:doLayout()
  162. end
  163. function ClubZhanJiItem:setCallBackFun(callbackFun, object)
  164. self.m_callbackFun = callbackFun
  165. self.m_object = object
  166. end
  167. function ClubZhanJiItem:onClickDetails()
  168. playBtnEffect()
  169. local ui = loadUI("res/ui/ui_zhanji/ui_zhanji_item_menu.ui")
  170. local totalMenuCount = ui.Items.Layout_btn_menu:getChildrenCount()
  171. for idx = 1, totalMenuCount do
  172. ui.Items["Text_" .. idx]:setTextColor(self.detailTxtColor)
  173. ui.Items["Layout_Btn_" .. idx]:registerClick(function ()
  174. ui:getParent():removeFromParent()
  175. playBtnEffect()
  176. self:onClickOperateMenu(idx)
  177. end)
  178. end
  179. local club = app.club_php.clubList[self.gid]
  180. if club and (club.role == 2 or club.role == 3) then
  181. ui.Items.Layout_Btn_4:setVisible(true)
  182. else
  183. ui.Items.Layout_Btn_4:setVisible(false)
  184. end
  185. if isReviewVersion() then
  186. ui.Items.Layout_Btn_3:setVisible(false)
  187. end
  188. ui.Items.Layout_btn_menu:requestDoLayout()
  189. ui.Items.Layout_btn_menu:doLayout()
  190. ui.Items.Layout:requestDoLayout()
  191. ui.Items.Layout:doLayout()
  192. local view = cc.UIView:new()
  193. view:setAnchorPoint(cc.p(0.5,0.5))
  194. view:addChild(ui)
  195. --计算坐标偏移
  196. local node = self.ui.Items.Button_xiangqing;
  197. local worldPos = node:getWorldPosition();
  198. local viewContentSize = ui:getSize()
  199. --X坐标
  200. local x = worldPos.x - node:getContentSize().width / 2 - 10; --10个像素间距
  201. local y = worldPos.y
  202. --yhj:临界处理
  203. --按钮离屏幕底部的距离
  204. local fromBtnToBottomY = worldPos.y
  205. --viewContentSize的一半如果大于fromBtnToBottomY则有一部分的菜单按钮显示到了屏幕外
  206. local distanBottom = viewContentSize.height/2 - fromBtnToBottomY
  207. if distanBottom > 0 then
  208. y = worldPos.y + distanBottom
  209. end
  210. --同样的考虑菜单过长时候,离顶部是否超越屏幕
  211. local fromBtnToTopY = getWinSize().height - worldPos.y
  212. local distanTop = viewContentSize.height/2 - fromBtnToTopY
  213. if distanTop > 0 then
  214. y = worldPos.y - distanTop
  215. end
  216. local newPos = cc.p(x, y);
  217. view:setPosition(newPos);
  218. app:showWaitDialog(view, 0, true)
  219. end
  220. function ClubZhanJiItem:onClickOperateMenu(index)
  221. if index == 1 then
  222. -- 查看详情
  223. -- local room = app.club_php:getMyInRoom()
  224. -- local view = app:getCurrentView()
  225. -- if room or view.__cname ~= "MainView" then
  226. -- showTooltip("正在游戏中,禁止查看回放")
  227. -- return
  228. -- end
  229. self:onBtnShowZhanJiDetailClicked()
  230. elseif index == 2 then
  231. -- 复制战绩
  232. self:onBtnCopyZhanJiClicked()
  233. elseif index == 3 then
  234. -- 分享回放码
  235. self:onBtnShareZhanJiCodeClicked()
  236. elseif index == 4 then
  237. -- 删除战绩
  238. self:onBtnDeleteZhanJiClicked()
  239. end
  240. end
  241. -- 详情按钮
  242. function ClubZhanJiItem:onBtnShowZhanJiDetailClicked()
  243. local gameID = tonumber(self.roomInfo.gameid)
  244. if not app.subGameManager:isInstaller(tonumber(gameID)) or app.subGameManager:isNeedUpdate(tonumber(gameID)) then
  245. --未下载时提示下载
  246. requestDownloadSubGame(tonumber(gameID), function ()
  247. showTooltip("下载完成")
  248. end, true)
  249. return;
  250. end
  251. -- 检查子游戏文件完整性
  252. checkSubGameFiles(tonumber(gameID), function()
  253. self:onBtnShowZhanJiDetailClicked_do(gameID)
  254. end)
  255. end
  256. -- 详情按钮
  257. function ClubZhanJiItem:onBtnShowZhanJiDetailClicked_do(gameID)
  258. --所有字牌和麻将,这里都不请求详情,而是在下个界面请求
  259. local hasReplay = false
  260. local isJieSanGame = false
  261. local isNeedDown = false
  262. local gameConfig = getSubGameConfig(gameID)
  263. if gameConfig and (not gameConfig.zhanjiDanjuView) then
  264. local isJieSan = false
  265. for idx, detail in pairsByKeys(self.roomInfo.detail) do
  266. for lunshu, detail2 in pairsByKeys(detail) do
  267. if detail2.flag == 8 or detail2.flag == 9 then
  268. isJieSan = true
  269. break
  270. elseif detail2.flag == 22 or detail2.flag == 10 or detail2.flag == 25 then
  271. isNeedDown = true;
  272. break
  273. end
  274. end
  275. if isJieSan or isNeedDown then
  276. break
  277. end
  278. end
  279. if isJieSan or isNeedDown then
  280. isJieSanGame = true
  281. end
  282. hasReplay = true
  283. end
  284. local function showZhanJiDanJuView()
  285. --检查游戏是否有下载
  286. if not app.subGameManager:isInstaller(tonumber(gameID)) or app.subGameManager:isNeedUpdate(tonumber(gameID)) then
  287. requestDownloadSubGame(tonumber(gameID), function ()
  288. showTooltip("下载完成")
  289. end, true)
  290. return
  291. end
  292. local zhanjiDanJuView = getSubGameZhanjiDanJuView(gameID)
  293. if zhanjiDanJuView then
  294. local fromClub = true;
  295. local view = import(zhanjiDanJuView):new(self.roomInfo,true)--第二个参数是茶馆战绩
  296. view:setAnchorPoint(cc.p(0.5, 0.5))
  297. app:showWaitDialog(view)
  298. else
  299. showTooltip("未找到单局战绩详情的配置文件!!!")
  300. end
  301. end
  302. local function showClubDanJuView()
  303. local view = import("luaScript.Views.Club.ClubZhanJiDanjuView"):new(self.gid, self.roomInfo, self.tableIdx)
  304. view:setAnchorPoint(cc.p(0.5, 0.5))
  305. app:showWaitDialog(view)
  306. end
  307. if hasReplay then
  308. if isJieSanGame then
  309. logD("self.roomInfo.detail:",table.tostring(self.roomInfo.detail))
  310. for idx, detail in pairsByKeys(self.roomInfo.detail) do
  311. if toNumber(idx) == table.nums(self.roomInfo.detail) then --取最后一条战绩详情
  312. if type(detail) == "table" then --单局有多个结束的只拉取最后一条
  313. for lunshu, detail2 in pairsByKeys(detail) do
  314. if toNumber(lunshu) == table.nums(detail) then
  315. app.club_zhanji:getZhanJiDetail(self.roomInfo.pid, detail2.subid, showClubDanJuView)
  316. end
  317. end
  318. else
  319. --单局只有一局的
  320. app.club_zhanji:getZhanJiDetail(self.roomInfo.pid, detail.subid, showClubDanJuView)
  321. end
  322. end
  323. end
  324. else
  325. showClubDanJuView();
  326. end
  327. else
  328. app.club_zhanji:getZhanJiDetail(self.roomInfo.pid, 0, showZhanJiDanJuView)
  329. end
  330. end
  331. function ClubZhanJiItem:onClickSure()
  332. playBtnEffect()
  333. local club = app.club_php.clubList[self.gid]
  334. if club then
  335. if app.club_zhanji.zhanJiIdxStatus[self.roomInfo.pid]==2 then --确认过
  336. self.ui.Items.Button_Sure:setVisible(false)
  337. return
  338. end
  339. end
  340. app.club_zhanji:requestZhanjiSure(self.gid,self.roomInfo.pid,function()
  341. if not tolua.isnull(self.ui) then
  342. self.ui.Items.Button_Sure:setVisible(false)
  343. end
  344. end)
  345. end
  346. function ClubZhanJiItem:onClickShareUrl()
  347. -- app.waitDialogManager:showWaitNetworkDialog("获取分享链接")
  348. -- local onGetUrlCallback = function(url)
  349. -- app.waitDialogManager:closeWaitNetworkDialog()
  350. -- if url then
  351. -- local view = import("luaScript.Views.Main.ShareZhanJiUrlView"):new(url,self.roomInfo)
  352. -- view:setAnchorPoint(cc.p(0.5, 0.5))
  353. -- app:showWaitDialog(view)
  354. -- else
  355. -- showTooltip("获取分享用的链接失败")
  356. -- end
  357. -- end
  358. -- app.php:initShareZhanJiToUrl(onGetUrlCallback);
  359. app.serverConfigs:requestClientConfig(function()
  360. local url = app.serverConfigs.clientConfig.webgamb or RomSetting.ZhanJiUrl
  361. local view = import("luaScript.Views.Main.ShareZhanJiUrlView"):new(url,self.roomInfo)
  362. view:setAnchorPoint(cc.p(0.5, 0.5))
  363. app:showWaitDialog(view)
  364. end)
  365. end
  366. --- ClubZhanJiItem:onBtnCopyZhanJiClicked 复制战绩
  367. function ClubZhanJiItem:onBtnCopyZhanJiClicked()
  368. local gameID = tonumber(self.roomInfo.gameid)
  369. local scoreList = self.roomInfo.tscore
  370. local roomInfo = self.roomInfo.roomid
  371. local ext = self.roomInfo.gext or {}
  372. local gameRule = ext.gamerule
  373. local time = os.date("%Y-%m-%d %H:%M",self.roomInfo.endtime)
  374. local scoreStr = ""
  375. local gameConfig = getSubGameConfig(gameID) or {}
  376. for k,score in pairsByKeys(scoreList) do
  377. --名字
  378. local playerInfo = app.playerInfoManager:getPlayerInfo(k)
  379. if playerInfo then
  380. local len = string.len(playerInfo.name)
  381. if len == 0 then
  382. playerInfo.name = "未知昵称"
  383. end
  384. if gameConfig.isUseDivision10 then
  385. score = score / 10
  386. end
  387. scoreStr = string.format("%s[%s] %s分\n", scoreStr, playerInfo.name,score>=0 and "+".. score or score)
  388. end
  389. end
  390. local gameName = getSubGameRuleName(gameID, gameRule)
  391. local endStr = "竞技成绩仅供娱乐,禁止赌博!"
  392. local copyData = string.format("[%s]\n房间号:%s\n结束时间:%s\n成绩:\n%s\n%s",
  393. gameName,
  394. roomInfo,
  395. time,
  396. scoreStr,
  397. endStr)
  398. logD("copyData:"..copyData)
  399. copyStringToClipboard(copyData)
  400. showTooltip("战绩复制成功!")
  401. end
  402. --- ClubZhanJiItem:onBtnShareZhanJiCodeClicked 分享回放码
  403. function ClubZhanJiItem:onBtnShareZhanJiCodeClicked()
  404. local gameID = tonumber(self.roomInfo.gameid)
  405. local ext = self.roomInfo.gext or {}
  406. local gameRule = ext.gamerule
  407. local gameName = getSubGameRuleName(gameID, gameRule)
  408. local title = string.format("[%s]战绩回放码分享", gameName)
  409. local content = self.roomInfo.pid
  410. local info = {}
  411. info.ClubID = self.gid
  412. info.title = title
  413. info.description = content
  414. info.url = app.club_zhanji.shareUrl.."?app="..getAppId().."&code="..self.roomInfo.pid
  415. -- print("用户开始分享")
  416. --需要显示的按钮(1:微信 2:复制 3:茶馆 )
  417. info.menuIdxs = {1,4,5,6}
  418. -- if type(copyData) == "string" then
  419. -- info.copyData = copyData
  420. -- else
  421. -- info.copyData = ""
  422. -- end
  423. logD("回放分享:",table.tostring(info))
  424. local view = import("luaScript.Views.Main.ShareView"):new(info)
  425. view:setAnchorPoint(cc.p(0.5, 0.5))
  426. app:showWaitDialog(view)
  427. end
  428. --- ClubZhanJiItem:onBtnDeleteZhanJiClicked 删除战绩
  429. function ClubZhanJiItem:onBtnDeleteZhanJiClicked()
  430. local function confirmCallback ()
  431. app.club_zhanji:requestDeleteZhanJi(self.gid, self.roomInfo.pid, 1)
  432. end
  433. local str = "确认删除这条战绩吗?删除后所有玩家将不可见!"
  434. local function cancelCallback ()
  435. end
  436. showConfirmDialog(str, confirmCallback, cancelCallback)
  437. end
  438. return ClubZhanJiItem