您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

163 行
4.6 KiB

  1. -- 快速成局界面
  2. local ZPRoomQuickStartView = class("ZPRoomQuickStartView", cc.UIView)
  3. local function getUserNameById(userId)
  4. local userInfo = app.room:getUserInfo(userId)
  5. if not userInfo then return end
  6. local userName = userInfo.nickname or tostring(userId)
  7. return userName
  8. end
  9. function ZPRoomQuickStartView:ctor(initiateUserId)
  10. ZPRoomQuickStartView.super.ctor(self);
  11. self.m_initiateUserId = initiateUserId
  12. self.itemList = {}
  13. end
  14. function ZPRoomQuickStartView:onEnter()
  15. ZPRoomQuickStartView.super.onEnter(self)
  16. local ui = loadUI("res/ui/ui_fangjian/ui_fangjian_quickstart.ui");
  17. self.ui = ui;
  18. self:addChild(ui);
  19. --谁申请快速开始
  20. local initiateUserName = getUserNameById(self.m_initiateUserId)
  21. initiateUserName = getSubStringNickname(initiateUserName,self.ui.Items.Text)
  22. self.ui.Items.Text:setText("["..initiateUserName.."]")
  23. -- 同意
  24. self.ui.Items.Button_1:registerClick(handler(self , self.onClickAgree))
  25. -- 拒绝
  26. self.ui.Items.Button_2:registerClick(handler(self , self.onClickRefuse))
  27. local layout = self.ui.Items.Layout_3
  28. layout:removeAllChildren()
  29. --桌子有坐下的人
  30. for nUserId, memberInfo in pairsByKeys(app.room.roomInfo.memberList) do
  31. local item = import("zp_base.luaScript.Views.Room.ZPRoomQuickStartItem"):new(nUserId, 0)
  32. layout:addChild(item.ui)
  33. self.itemList[nUserId] = item
  34. end
  35. self:bindEvent(app.room , "onQuickStartResponse" , handler(self , self.onQuickStartResponse));
  36. self:bindEvent(app.room , "onGameOverResponse" , handler(self , self.onGameOverResponse));
  37. self:updateButton()
  38. local nLeftTime = app.room.nleftStartGameTimeout
  39. local timer = nLeftTime or 60
  40. local nTotalTime = app.room.nStartGameToTalTime
  41. local totalTime = nTotalTime or 60
  42. if self.ui.Items.LoadingBar then
  43. self.ui.Items.LoadingBar:setPercent(timer/totalTime * 100)
  44. end
  45. self.ui.Items.Text_3:setString("")
  46. self.ui.Items.time:setText(tostring(totalTime))
  47. --self.ui.Items.time:setText(tostring(timer))--数字跟着倒计时
  48. self.loadingBarTimer = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  49. timer = timer - 1
  50. if timer < 0 then
  51. self:removeView()
  52. return
  53. end
  54. if tolua.isnull(self.ui.Items.Text_3) then
  55. if self.loadingBarTimer then
  56. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.loadingBarTimer)
  57. self.loadingBarTimer = nil
  58. end
  59. return
  60. end
  61. if timer <= 0 then
  62. self.ui.Items.Text_3:setText(tostring(0))--数字跟着倒计时
  63. else
  64. self.ui.Items.Text_3:setText(tostring(timer))--数字跟着倒计时
  65. end
  66. if self.ui.Items.LoadingBar then
  67. self.ui.Items.LoadingBar:setPercent(timer/totalTime * 100)
  68. end
  69. end,1.0,false)
  70. end
  71. function ZPRoomQuickStartView:updateButton()
  72. local myUserId = app.room.roomInfo.nUserId
  73. if (app.room.quickStartInfo[myUserId] and app.room.quickStartInfo[myUserId] ~= 0) or self.m_initiateUserId == myUserId then
  74. -- 我已经选择过了或者我是发起申请的那个
  75. self.ui.Items.Button_1:setVisible(false)
  76. self.ui.Items.Button_2:setVisible(false)
  77. else
  78. -- 我还没选择
  79. self.ui.Items.Button_1:setVisible(true)
  80. self.ui.Items.Button_2:setVisible(true)
  81. end
  82. if app.room.isOnLooker then
  83. self.ui.Items.Button_1:setVisible(false)
  84. self.ui.Items.Button_2:setVisible(false)
  85. end
  86. end
  87. -- 同意
  88. function ZPRoomQuickStartView:onClickAgree()
  89. app.room:requestQuickStart(2)
  90. end
  91. -- 拒绝
  92. function ZPRoomQuickStartView:onClickRefuse()
  93. app.room:requestQuickStart(3)
  94. end
  95. function ZPRoomQuickStartView:onQuickStartResponse(event)
  96. self:updateButton()
  97. for id,op in pairs(app.room.quickStartInfo) do
  98. local item = self.itemList[id]
  99. if item then
  100. item:updateStatus();
  101. end
  102. end
  103. -- 房间内的人全都回复过了
  104. local isReplyNum = 0
  105. local isNoRefuse = true
  106. for _, operateType in pairs(app.room.quickStartInfo) do
  107. if operateType == 1 or operateType == 2 or operateType == 3 then
  108. isReplyNum = isReplyNum + 1
  109. if operateType == 3 then
  110. isNoRefuse = false
  111. local refuseUserName = getUserNameById(_)--"~@&111"--
  112. --showTooltip(refuseUserName.."拒绝了立即开局!")
  113. self:runDelay(1, function()
  114. if not tolua.isnull(self) then
  115. self:removeView()
  116. end
  117. end )
  118. end
  119. end
  120. end
  121. if isReplyNum >= app.room:getActualPlayerNum() and isNoRefuse then
  122. if not tolua.isnull(self) then
  123. self:removeView()
  124. end
  125. end
  126. end
  127. function ZPRoomQuickStartView:onGameOverResponse(event)
  128. self:removeView()
  129. end
  130. function ZPRoomQuickStartView:removeView()
  131. if self.loadingBarTimer then
  132. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.loadingBarTimer)
  133. self.loadingBarTimer = nil
  134. end
  135. self:removeFromParent()
  136. end
  137. return ZPRoomQuickStartView;