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.

244 lines
7.5 KiB

  1. --
  2. local MatchDefined = require("luaScript.Views.Match.Constant.MatchDefined")
  3. local MatchInfo = class("MatchInfo", cc.UIView)
  4. local RuleText =
  5. {
  6. [1] = {
  7. "赛事名称:%s",
  8. "报名时间:%s",
  9. "比赛时间:%s",
  10. "报名条件:%s",
  11. "赛事玩法:%s",
  12. },
  13. [2] = {
  14. "使用'定局积分'赛制,同一轮比赛中对手相同,打完规定局数后,同桌最高分晋级。"
  15. },
  16. [3] = {
  17. "第一名: %s",
  18. "第二名: %s",
  19. "第三名: %s"
  20. },
  21. }
  22. function MatchInfo:ctor(matchInfo)
  23. MatchInfo.super.ctor(self)
  24. local ui = loadUI("res/ui/ui_match/ui_match_rule.ui")
  25. self.ui = ui
  26. self:addChild(ui)
  27. self.matchInfo = matchInfo
  28. end
  29. function MatchInfo:onEnter()
  30. MatchInfo.super.onEnter(self)
  31. self:init();
  32. end
  33. function MatchInfo:init()
  34. self.ui.Items.Button:registerClick(function ()
  35. self:onClickClose()
  36. end)
  37. self.ui.Items.Button_Sign:registerClick(function ()
  38. playBtnEffect()
  39. local cost = json.decode(self.matchInfo.signupInfo)
  40. local costStr=""
  41. for n,signInfos in pairs(cost.signInfo) do
  42. for _,info in pairs(signInfos) do
  43. if info.type==MatchDefined.CURRENCY_TYPE.Card then
  44. costStr=costStr.."房卡x"..info.value
  45. elseif info.type==MatchDefined.CURRENCY_TYPE.Coin then
  46. costStr=costStr.."金币x"..info.value
  47. -- elseif info.type==MatchDefined.CURRENCY_TYPE.Money then
  48. -- costStr=costStr.."红包"..info.value.."元"
  49. end
  50. end
  51. if n~=#cost.signInfo then
  52. costStr=costStr.." 或 "
  53. end
  54. end
  55. local function btnCallbackOk()
  56. app.match:signUp(self.matchInfo);
  57. end
  58. local function btnCallbackCancel()
  59. end
  60. if not app.subGameManager:isInstaller(tonumber(self.matchInfo.gameId)) or app.subGameManager:isNeedUpdate(tonumber(self.matchInfo.gameId)) then
  61. --未下载时提示下载
  62. requestDownloadSubGame(tonumber(self.matchInfo.gameId), function ()
  63. showTooltip("下载完成")
  64. end, true)
  65. return;
  66. end
  67. showConfirmDialog("确定花费["..costStr.."]报名?",btnCallbackOk,btnCallbackCancel)
  68. end)
  69. if not self.matchInfo then
  70. self.ui.Items.Button_Sign:setVisible(false)
  71. end
  72. self.ruleButtonList = {}
  73. self.ui.Items.Layout_Content:setVisible(false)
  74. self.ui.Items.Layout_Item_Award:setVisible(false)
  75. self:initLayout()
  76. for i = 1, 3 do
  77. local btnName = string.format("Button_%d",i)
  78. local layoutName = string.format("Layout_%d",i)
  79. --init
  80. if i == 1 then
  81. self.ui.Items[btnName]:setBright(true)
  82. self.ui.Items[layoutName]:setVisible(true)
  83. else
  84. self.ui.Items[btnName]:setBright(false)
  85. self.ui.Items[layoutName]:setVisible(false)
  86. end
  87. --data
  88. self.ruleButtonList[i] = self.ui.Items[btnName];
  89. self.ui.Items[btnName]:setTag(i)
  90. self.ui.Items[btnName]:registerClick(function ()
  91. self:onClickType(i)
  92. end)
  93. end
  94. end
  95. function MatchInfo:onClickType(tag)
  96. playBtnEffect()
  97. for k,v in pairs(self.ruleButtonList) do
  98. local layoutName = string.format("Layout_%d",k)
  99. if v:getTag() == tag then
  100. v:setBright(true)
  101. self.ui.Items[layoutName]:setVisible(true)
  102. else
  103. v:setBright(false)
  104. self.ui.Items[layoutName]:setVisible(false)
  105. end
  106. end
  107. end
  108. function MatchInfo:initLayout()
  109. local matchInfo = app.match.matchInfo
  110. for i = 1, 3 do
  111. local name = string.format("ScrollView_"..i)
  112. local uiScrollView = self.ui.Items[name];
  113. uiScrollView:getInnerContainer():setAutoSize(true)
  114. if i==1 then
  115. self.ui.Items.ImageView_Macth_Info:loadTexture("res/ui/zy_match/match_"..matchInfo.matchIndex..".png")
  116. -- local cost = json.decode(self.matchInfo.signupInfo)
  117. -- local costStr=""
  118. -- for n,signInfos in pairs(cost.signInfo) do
  119. -- for _,info in pairs(signInfos) do
  120. -- if info.type==13 then
  121. -- costStr=costStr.."房卡x"..info.value
  122. -- elseif info.type==1 then
  123. -- costStr=costStr.."金币x"..info.value
  124. -- end
  125. -- end
  126. -- if n~=#cost.signInfo then
  127. -- costStr=costStr.." 或 "
  128. -- end
  129. -- end
  130. -- local tab={
  131. -- self.matchInfo.matchName,
  132. -- "全天",
  133. -- "人满开赛",
  134. -- costStr,
  135. -- "",
  136. -- }
  137. -- for k,v in pairs(RuleText[i]) do
  138. -- local uiContent = self:createContent(string.format(v,tab[k]))
  139. -- uiScrollView:addChild(uiContent)
  140. -- end
  141. elseif i==2 then
  142. self.ui.Items.ImageView_Macth_Rule:loadTexture("res/ui/zy_match/match_"..matchInfo.matchIndex.."_rule.png")
  143. -- for k,v in pairs(RuleText[i]) do
  144. -- local uiContent = self:createContent(v)
  145. -- uiScrollView:addChild(uiContent)
  146. -- end
  147. else
  148. -- local str=""
  149. local rewards = matchInfo.rewards
  150. for j=1,3 do
  151. if rewards[j] then
  152. local awardStr = ""
  153. local tp = MatchDefined.CURRENCY_TYPE.Card
  154. for k,v in pairs(rewards[j]) do
  155. tp=v.type
  156. if v.type==MatchDefined.CURRENCY_TYPE.Card then --房卡
  157. awardStr=awardStr.."房卡x"..v.value.." "
  158. elseif v.type==MatchDefined.CURRENCY_TYPE.Coin then --金币
  159. awardStr=awardStr.."金币x"..v.value.." "
  160. elseif v.type==MatchDefined.CURRENCY_TYPE.Money then
  161. awardStr=awardStr.."红包"..v.value.."元"
  162. end
  163. end
  164. local uiContent = self:createContentTwo(j,awardStr,tp)
  165. uiScrollView:addChild(uiContent)
  166. else
  167. end
  168. end
  169. end
  170. uiScrollView:hideAllBar()
  171. uiScrollView:jumpToTopOnSizeChanged()
  172. end
  173. end
  174. function MatchInfo:createContent(text)
  175. local ui = self.ui.Items.Layout_Content:getCopied()
  176. ui.Items = getUIItems(ui);
  177. ui.Items.Text_Content:setText(text)
  178. ui:requestDoLayout()
  179. ui:doLayout()
  180. return ui
  181. end
  182. function MatchInfo:createContentTwo(rank,award,tp)
  183. local ui = self.ui.Items.Layout_Item_Award:getCopied()
  184. ui.Items = getUIItems(ui);
  185. if rank<=3 then
  186. ui.Items.Text_Rank_Award:setVisible(false)
  187. ui.Items.ImageView_Rank_Award:loadTexture("match_common_rank"..rank..".png",cc.TextureResType.plistType)
  188. else
  189. ui.Items.ImageView_Rank_Award:setVisible(false)
  190. ui.Items.Text_Rank_Award:setString(rank)
  191. end
  192. if tp==MatchDefined.CURRENCY_TYPE.Money then
  193. ui.Items.ImageView_Item_Icon:loadTexture("match_common_icon_hongbao.png",cc.TextureResType.plistType)
  194. ui.Items.ImageView_Item_Icon:setScale(0.5)
  195. end
  196. ui.Items.Text_Num:setString(award)
  197. ui:requestDoLayout()
  198. ui:doLayout()
  199. return ui
  200. end
  201. function MatchInfo:onClickClose()
  202. playBtnCloseEffect()
  203. self:removeFromParent()
  204. end
  205. return MatchInfo