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.

369 lines
11 KiB

  1. -- 战绩单元Layout
  2. -- local ZhanjiAllGame = require("luaScript.Protocol.ProtocolZhanJiGame"):new(-1, "zhanji_AllGame");
  3. local ZhanJiItem = class("ZhanJiItem")
  4. function ZhanJiItem:ctor(zhanjiType, infoData,index)
  5. self.zhanjiType = zhanjiType
  6. self.roomInfo = infoData
  7. --序号
  8. self.index = index
  9. self.detailTxtColor = cc.c4b(213,255,249,255)
  10. self:initView()
  11. end
  12. --初始化界面
  13. function ZhanJiItem:initView()
  14. self.ui = loadUI("res/ui/ui_zhanji/ui_zhanji_item.ui")
  15. autoAdaptWidth(self.ui)
  16. self.ui.Items.Layout_player:setVisible(false)
  17. self.ui.Items.Layout_game_title_club:setVisible(false)
  18. self.ui.Items.Layout_game_title_me:setVisible(false)
  19. self.ui.Items.Button_xiangqing:registerClick(handler(self , self.onClickDetails))
  20. self.ui.Items.Button_url:registerClick(handler(self , self.onClickShareUrl))
  21. if not app.config.ModuleConfig.IsSupportZhanJiUrl then
  22. self.ui.Items.Layout_1:setVisible(false)
  23. self.ui.Items.Layout_Button:requestDoLayout()
  24. self.ui.Items.Layout_Button:doLayout()
  25. end
  26. self.ui.Items.Button_Sure:registerClick(handler(self , self.onClickSure))
  27. self:init()
  28. end
  29. function ZhanJiItem:getRoot()
  30. return self.ui
  31. end
  32. function ZhanJiItem:init()
  33. self.ui.Items.Layout_player_count:setSize(cc.size(885,105))
  34. self.ui.Items.Button_Sure:getParent():setVisible(false)
  35. self.ui.Items.Layout_Button:requestDoLayout()
  36. self.ui.Items.Layout_Button:doLayout()
  37. local scoreList = self.roomInfo.tscore
  38. --游戏icon
  39. local gameID = tonumber(self.roomInfo.gameid)
  40. local ruleID = tonumber(self.roomInfo.gext.gamerule)
  41. local gameConfig = getSubGameConfig(gameID) or {}
  42. local gameName = getSubGameRuleName(gameID,ruleID)
  43. self.ui.Items.Layout_game_title_club:setVisible(false)
  44. self.ui.Items.Layout_game_title_me:setVisible(true)
  45. --结果
  46. self.ui.Items.ImageView_flag:setVisible(true)
  47. local myscore = scoreList[tostring(app.user.loginInfo.uid)]
  48. if myscore and myscore > 0 then
  49. self.ui.Items.ImageView_flag:loadTexture("res/ui/zy_dating/zhanji/zhanji_win_icon.png")
  50. else
  51. self.ui.Items.ImageView_flag:loadTexture("res/ui/zy_dating/zhanji/zhanji_lose_icon.png")
  52. end
  53. self.ui.Items.Text_game_me:setString(gameName)
  54. self.ui.Items.Text_game_me_1:setString(gameName)
  55. --序号
  56. self.ui.Items.Text_No:setText(self.index)
  57. --时间
  58. local time = os.date("%Y-%m-%d %H:%M",self.roomInfo.endtime)
  59. self.ui.Items.Text_time:setText(time)
  60. --大赢家
  61. --[[local maxScore = nil;
  62. for uid, score in pairs(scoreList) do
  63. if not maxScore or maxScore < score then
  64. maxScore = score;
  65. end
  66. end--]]
  67. --房号
  68. local roomInfo = self.roomInfo.roomid;
  69. self.ui.Items.Text_roomid:setText("房号:"..roomInfo);
  70. --最终分数
  71. local scorUI = self.ui.Items.Layout_player_count;
  72. --scorUI:getInnerContainer():setAutoSize(true);
  73. scorUI:removeAllChildren();
  74. local scoreSize = table.nums(scoreList)
  75. --是否显示加减分
  76. if self.ui.Items.ImageView_Rule then
  77. self.ui.Items.ImageView_Rule:setVisible(false)
  78. local diFenLimit = self.roomInfo.gext.game_ext and self.roomInfo.gext.game_ext.diFenLimit;
  79. if diFenLimit and diFenLimit > 0 and scoreSize == 2 then
  80. self.ui.Items.ImageView_Rule:setVisible(true)
  81. end
  82. end
  83. local uiTemplate = self.ui.Items.Layout_player;
  84. local contentSize = scorUI:getContentSize();
  85. for k,v in pairsByKeys(scoreList) do
  86. local uiItem = uiTemplate:getCopied()
  87. uiItem:setSize(cc.size(contentSize.width / scoreSize, contentSize.height))
  88. uiItem.Items = getUIItems(uiItem)
  89. --名字
  90. local playerInfo = app.playerInfoManager:getPlayerInfo(k);
  91. if playerInfo then
  92. local len = string.len(playerInfo.name)
  93. if len == 0 then
  94. playerInfo.name = "未知昵称"
  95. end
  96. playerInfo.name = getSubStringNickname(playerInfo.name)
  97. uiItem.Items.Text_player_name:setText(playerInfo.name)
  98. --[[--大赢家
  99. local isWin = (v == maxScore);
  100. if isWin then
  101. self.ui.Items.Text_winer_name:setText(playerInfo.name)
  102. end--]]
  103. end
  104. if gameConfig.isUseDivision10 then
  105. v = v / 10
  106. end
  107. --分数
  108. if v > 0 then
  109. v = "+"..tostring(v)
  110. uiItem.Items.Text_score:setFntFile("res/fonts/zhanji_win.fnt")
  111. else
  112. --绿色
  113. uiItem.Items.Text_score:setFntFile("res/fonts/zhanji_lose.fnt")
  114. end
  115. uiItem.Items.Text_score:setText(v)
  116. scorUI:addChild(uiItem);
  117. end
  118. scorUI:requestDoLayout()
  119. scorUI:doLayout()
  120. end
  121. function ZhanJiItem:setCallBackFun(callbackFun, object)
  122. self.m_callbackFun = callbackFun
  123. self.m_object = object
  124. end
  125. function ZhanJiItem:onClickDetails()
  126. playBtnEffect()
  127. local ui = loadUI("res/ui/ui_zhanji/ui_zhanji_item_menu.ui")
  128. ui.Items.Layout_Btn_4:setVisible(false)
  129. --查看详情
  130. ui.Items.Layout_Btn_1:registerClick(function()
  131. self:onClickLookDetails()
  132. ui:getParent():removeFromParent()
  133. end)
  134. --复制战绩
  135. ui.Items.Layout_Btn_2:registerClick(function()
  136. self:onClickCopy()
  137. ui:getParent():removeFromParent()
  138. end)
  139. --分享回放码
  140. ui.Items.Layout_Btn_3:registerClick(function()
  141. ui:getParent():removeFromParent()
  142. local gameID = tonumber(self.roomInfo.gameid)
  143. local ext = self.roomInfo.gext or {}
  144. local gameRule = ext.gamerule
  145. local gameName = getSubGameRuleName(gameID, gameRule)
  146. local title = string.format("[%s]战绩回放码分享", gameName)
  147. local content = self.roomInfo.pid
  148. local info = {}
  149. info.title = title
  150. info.description = content
  151. --TODO 战绩URL需要获取
  152. info.url = app.allZhanji.shareUrl.."?app="..getAppId().."&code="..self.roomInfo.pid
  153. --info.url = "http://m.ddpenghu.com/replay.php?app="..getAppId().."&code="..self.roomInfo.pid --ZhanjiAllGame.shareUrl..
  154. -- print("用户开始分享")
  155. --需要显示的按钮(1:微信 2:复制 3:茶馆)
  156. info.menuIdxs = {1,4,5,6}
  157. logD("回放分享:",table.tostring(info))
  158. local view = import("luaScript.Views.Main.ShareView"):new(info)
  159. view:setAnchorPoint(cc.p(0.5, 0.5))
  160. app:showWaitDialog(view)
  161. end)
  162. -- 分享网页战绩
  163. -- ui.Items.Button_4:registerClick(function()
  164. -- self:onClickSure()
  165. -- end)
  166. local totalMenuCount = ui.Items.Layout_btn_menu:getChildrenCount()
  167. for idx = 1, totalMenuCount do
  168. ui.Items["Text_" .. idx]:setTextColor(self.detailTxtColor)
  169. end
  170. ui.Items.Layout_btn_menu:requestDoLayout()
  171. ui.Items.Layout_btn_menu:doLayout()
  172. ui.Items.Layout:requestDoLayout()
  173. ui.Items.Layout:doLayout()
  174. local view = cc.UIView:new()
  175. view:setAnchorPoint(cc.p(0.5,0.5))
  176. view:addChild(ui)
  177. --计算坐标偏移
  178. local node = self.ui.Items.Button_xiangqing;
  179. local worldPos = node:getWorldPosition();
  180. local viewContentSize = ui:getSize()
  181. --X坐标
  182. local x = worldPos.x - node:getContentSize().width / 2 - 10; --10个像素间距
  183. local y = worldPos.y
  184. --yhj:临界处理
  185. --按钮离屏幕底部的距离
  186. local fromBtnToBottomY = worldPos.y
  187. --viewContentSize的一半如果大于fromBtnToBottomY则有一部分的菜单按钮显示到了屏幕外
  188. local distanBottom = viewContentSize.height/2 - fromBtnToBottomY
  189. if distanBottom > 0 then
  190. y = worldPos.y + distanBottom
  191. end
  192. --同样的考虑菜单过长时候,离顶部是否超越屏幕
  193. local fromBtnToTopY = getWinSize().height - worldPos.y
  194. local distanTop = viewContentSize.height/2 - fromBtnToTopY
  195. if distanTop > 0 then
  196. y = worldPos.y - distanTop
  197. end
  198. local newPos = cc.p(x, y);
  199. view:setPosition(newPos);
  200. app:showWaitDialog(view, 0, true)
  201. end
  202. -- 详情按钮
  203. function ZhanJiItem:onClickLookDetails()
  204. playBtnEffect()
  205. local gameID = tonumber(self.roomInfo.gameid)
  206. --检查游戏是否有下载
  207. if not app.subGameManager:isInstaller(tonumber(gameID)) or app.subGameManager:isNeedUpdate(tonumber(gameID)) then
  208. requestDownloadSubGame(tonumber(gameID), function ()
  209. showTooltip("下载完成")
  210. end, true)
  211. return
  212. end
  213. -- -- 先注册战绩协议
  214. -- app:addProtocolZhanJi(gameID)
  215. -- -- 拉取战绩数据
  216. -- local protocolZhanJi = app:getProtocolZhanJi(gameID)
  217. -- if protocolZhanJi then
  218. -- protocolZhanJi:init()
  219. -- end
  220. local function showDanJuView()
  221. local zhanjiDanJuView = getSubGameZhanjiDanJuView(gameID)
  222. if zhanjiDanJuView then
  223. local view = import(zhanjiDanJuView):new(self.roomInfo)
  224. view:setAnchorPoint(cc.p(0.5, 0.5))
  225. app:showWaitDialog(view)
  226. else
  227. showTooltip("未找到单局战绩详情的配置文件!!!")
  228. end
  229. end
  230. --有回放的统一使用大厅战绩界面
  231. local view = import("luaScript.Views.ZhanJi.ZhanJiDanjuView"):new(self.roomInfo)
  232. view:setAnchorPoint(cc.p(0.5, 0.5))
  233. app:showWaitDialog(view)
  234. end
  235. function ZhanJiItem:onClickCopy()
  236. playBtnEffect()
  237. local gameID = tonumber(self.roomInfo.gameid)
  238. local scoreList = self.roomInfo.tscore
  239. local roomInfo = self.roomInfo.roomid
  240. local ext = self.roomInfo.gext or {}
  241. local gameRule = ext.gamerule
  242. local time = os.date("%Y-%m-%d %H:%M",self.roomInfo.endtime)
  243. local scoreStr = ""
  244. local gameConfig = getSubGameConfig(gameID) or {}
  245. for k,score in pairsByKeys(scoreList) do
  246. if gameConfig.isUseDivision10 then
  247. score = score / 10
  248. end
  249. --名字
  250. local playerInfo = app.playerInfoManager:getPlayerInfo(k)
  251. if playerInfo then
  252. local len = string.len(playerInfo.name)
  253. if len == 0 then
  254. playerInfo.name = "未知昵称"
  255. end
  256. scoreStr = string.format("%s[%s] %s分\n", scoreStr, playerInfo.name,score>=0 and "+".. score or score)
  257. end
  258. end
  259. local gameName = getSubGameRuleName(gameID, gameRule)
  260. local endStr = "竞技成绩仅供娱乐,禁止赌博!"
  261. local copyData = string.format("[%s]\n房间号:%s\n结束时间:%s\n成绩:\n%s\n%s",
  262. gameName,
  263. roomInfo,
  264. time,
  265. scoreStr,
  266. endStr)
  267. logD("copyData:"..copyData)
  268. copyStringToClipboard(copyData)
  269. showTooltip("战绩复制成功!")
  270. end
  271. function ZhanJiItem:onClickSure()
  272. playBtnEffect()
  273. local club = app.club_php.clubList[self.gid]
  274. if club then
  275. if app.club_zhanji.zhanJiIdxStatus[self.roomInfo.pid]==2 then --确认过
  276. self.ui.Items.Button_Sure:setVisible(false)
  277. return
  278. end
  279. end
  280. app.club_zhanji:requestZhanjiSure(self.gid,self.roomInfo.pid,function()
  281. if not tolua.isnull(self.ui) then
  282. self.ui.Items.Button_Sure:setVisible(false)
  283. end
  284. end)
  285. end
  286. function ZhanJiItem:onClickShareUrl()
  287. -- app.waitDialogManager:showWaitNetworkDialog("获取分享链接")
  288. -- local onGetUrlCallback = function(url)
  289. -- app.waitDialogManager:closeWaitNetworkDialog()
  290. -- if url then
  291. -- local view = import("luaScript.Views.Main.ShareZhanJiUrlView"):new(url,self.roomInfo)
  292. -- view:setAnchorPoint(cc.p(0.5, 0.5))
  293. -- app:showWaitDialog(view)
  294. -- else
  295. -- showTooltip("获取分享用的链接失败")
  296. -- end
  297. -- end
  298. -- app.php:initShareZhanJiToUrl(onGetUrlCallback);
  299. app.serverConfigs:requestClientConfig(function()
  300. local url = app.serverConfigs.clientConfig.webgamb or RomSetting.ZhanJiUrl
  301. local view = import("luaScript.Views.Main.ShareZhanJiUrlView"):new(url,self.roomInfo)
  302. view:setAnchorPoint(cc.p(0.5, 0.5))
  303. app:showWaitDialog(view)
  304. end)
  305. end
  306. return ZhanJiItem