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.

170 lines
4.5 KiB

  1. -- 大厅总战绩
  2. local BTN_TAG_IMG_SELECT = {
  3. [0] = "club_zhanji_me_btn_sel.png", --我的战绩
  4. [1] = "zhanji_other_title_sel.png", --茶馆战绩
  5. -- [2] = "club_zhanji_tongji_btn_sel.png", --战绩统计
  6. }
  7. local BTN_TAG_IMG_NORMAL = {
  8. [0] = "club_zhanji_me_btn.png", --我的战绩
  9. [1] = "zhanji_other_title_nor.png", --茶馆战绩
  10. -- [2] = "club_zhanji_tongji_btn.png", --战绩统计
  11. }
  12. local ZhanJiViewBase = class("ZhanJiViewBase", cc.UIView)
  13. -- local app.allZhanji = require("luaScript.Protocol.ProtocolZhanJiGame"):new(-1, "zhanji_AllGame");
  14. function ZhanJiViewBase:ctor(gameId, listItemClass,code)
  15. ZhanJiViewBase.super.ctor(self);
  16. self.gameId = gameId;
  17. self.listItemClass = listItemClass;
  18. self.code = code
  19. self.ui = loadUI("res/ui/ui_zhanji/zhanji_view.ui")
  20. self:addChild(self.ui)
  21. self.protocolZhanJi = app:getProtocolZhanJi(self.gameId)
  22. end
  23. function ZhanJiViewBase:onEnter()
  24. ZhanJiViewBase.super.onEnter(self)
  25. self.ui.Items.Button:registerClick(handler(self , self.onClickClose))
  26. self.ui.Items.Button_search:registerClick(handler(self , self.onClickSearch))
  27. self.ui.Items.Layout_allgame_item:setVisible(false)
  28. self.ui.Items.Layout_player_score:setVisible(false)
  29. self.ui.Items.Layout_no_data:setVisible(false)
  30. self:bindEvent(app.allZhanji, "getZhanjiBriefResponse", handler(self, self.showAllGameZhanji))
  31. if self.gameId == -1 then
  32. --当前显示为大厅总战绩
  33. app.allZhanji:init()
  34. elseif self.gameId ~= nil then
  35. self:showOneGameZhanji()
  36. end
  37. self.curShowType = 1
  38. if self.code then --有回放码 默认查看他人战绩
  39. self.curShowType = 2
  40. app.allZhanji:requestOtherZhanji(self.code)
  41. end
  42. local radioManager = import("luaScript.Tools.RadioManager"):new()
  43. radioManager:addItem(self.ui.Items.CheckBox_my,1)
  44. radioManager:addItem(self.ui.Items.CheckBox_other,2)
  45. radioManager:setCallback(handler(self , self.onClickZhanji))
  46. radioManager:setDefault(self.curShowType)
  47. if isReviewVersion() then
  48. self.ui.Items.Layout_manager:setVisible(false)
  49. end
  50. end
  51. function ZhanJiViewBase:onClickSearch()
  52. local str = self.ui.Items.TextField_search:getString()
  53. if not str or str=="" then
  54. return
  55. end
  56. app.allZhanji:requestOtherZhanji(str)
  57. end
  58. function ZhanJiViewBase:onClickZhanji(index)
  59. --playBtnTagEffect()
  60. self.curShowType = index
  61. if index==2 then
  62. app.allZhanji:requestOtherZhanji()
  63. self.ui.Items.Layout_search:setVisible(true)
  64. else
  65. self.ui.Items.Layout_search:setVisible(false)
  66. end
  67. self:showAllGameZhanji()
  68. end
  69. --显示单个游戏战绩
  70. function ZhanJiViewBase:showOneGameZhanji()
  71. local fangjianInfo = self.protocolZhanJi.zhanjiInfoList
  72. if fangjianInfo == nil then
  73. self.ui.Items.Layout_no_data:setVisible(true)
  74. return
  75. end
  76. self.ui.Items.Layout_no_data:setVisible(false)
  77. logD("ZhanJiViewBase:showOneGameZhanji() fangjianInfo"..table.tostring(fangjianInfo))
  78. local mScrollView = self.ui.Items.ScrollView
  79. mScrollView:getInnerContainer():setAutoSize(true)
  80. mScrollView:removeAllChildren();
  81. mScrollView:hideAllBar()
  82. local ttZhanJiList = {}
  83. for _,info in pairs(fangjianInfo) do
  84. ttZhanJiList[info.endtime] = info;
  85. end
  86. local totalSize = table.nums(fangjianInfo);
  87. if totalSize > 0 then
  88. for _,info in pairsByKeysEx(ttZhanJiList) do
  89. local item = import(self.listItemClass):new(info)
  90. mScrollView:addChild(item:getRoot())
  91. end
  92. end
  93. mScrollView:jumpToTopOnSizeChanged()
  94. end
  95. -- 显示所有游戏
  96. function ZhanJiViewBase:showAllGameZhanji(event)
  97. local mListView = self.ui.Items.ScrollView
  98. mListView:removeAllChildren()
  99. mListView:getInnerContainer():setAutoSize(true)
  100. if self.curShowType==2 and event and event.result and table.nums(event.result.gamb)==0 then
  101. showTooltip("回放码错误或者已经失效!")
  102. end
  103. local uiTemplate = self.ui.Items.Layout_allgame_item;
  104. local zhanjiList = self.curShowType==1 and app.allZhanji:getZhanJiList() or app.allZhanji:getZhanJiListOther()
  105. if zhanjiList and table.nums(zhanjiList) <= 0 then
  106. self.ui.Items.Layout_no_data:setVisible(true)
  107. return
  108. end
  109. self.ui.Items.Layout_no_data:setVisible(false)
  110. local index = table.nums(zhanjiList)
  111. for logid, zhanjiInfo in pairsByKeys(zhanjiList) do
  112. local endtime = tonumber(zhanjiInfo.endtime)
  113. local uiContent = import("luaScript.Views.ZhanJi.ZhanJiItem"):new(self.curShowType, zhanjiInfo ,index)
  114. if uiContent and uiContent.ui then
  115. mListView:addChild(uiContent.ui)
  116. index = index-1
  117. end
  118. end
  119. mListView:jumpToTopOnSizeChanged()
  120. end
  121. -- 关闭
  122. function ZhanJiViewBase:onClickClose()
  123. playBtnCloseEffect()
  124. self:removeFromParent()
  125. end
  126. return ZhanJiViewBase;