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.

207 lines
5.7 KiB

  1. local PKDef = require("pk_base.luaScript.PKDef")
  2. -- 解散界面
  3. local RoomStartWaitView = class("RoomStartWaitView", cc.UIView)
  4. local stateColor = {
  5. agreeColor = cc.c4b(16,160,0,255),
  6. noAgreeColor = cc.c4b(219,56,35,255)
  7. }
  8. local function getUserNameById(userId)
  9. local userInfo = app.room:getUserInfo(userId)
  10. userInfo = type(userInfo) == "string" and json.decode(userInfo) or userInfo
  11. if not userInfo then return end
  12. local userName = getSubStringNickname(userInfo.nickname) or userId
  13. return userName
  14. end
  15. function RoomStartWaitView:ctor(response,callback)
  16. RoomStartWaitView.super.ctor(self);
  17. self.nleftStartGameTimeout = response.nleftStartGameTimeout
  18. self.response = response
  19. self.callback = callback
  20. end
  21. function RoomStartWaitView:onEnter()
  22. RoomStartWaitView.super.onEnter(self)
  23. local ui = loadUI("pk_base/res/ui/ui_fangjian/pk_ui_speedStart.ui");
  24. self.ui = ui;
  25. self:addChild(ui);
  26. -- 同意
  27. self.ui.Items.Button_1:registerClick(handler(self , self.onClickAgree))
  28. -- 拒绝
  29. self.ui.Items.Button_2:registerClick(handler(self , self.onClickRefuse))
  30. self.ui.Items.Layout_Player_Item:setVisible(false)
  31. local layout = self.ui.Items.Layout_Player
  32. self.sateList = {}
  33. layout:removeAllChildren()
  34. for k,v in pairs(app.room.roomInfo.memberList) do
  35. local itemEx = self.ui.Items.Layout_Player_Item:getCopied()
  36. itemEx.Items = getUIItems(itemEx)
  37. local userInfo = json.decode(v.userInfo)
  38. if userInfo then
  39. -- 玩家名字
  40. itemEx.Items.Text_name:setText(getSubStringNickname(userInfo.nickname))
  41. --头像
  42. setPlayerHeadImage(k, userInfo.headimgurl, itemEx.Items.ImageView_head)
  43. end
  44. self.sateList[app.room:getViewIdByUserId(k)] = itemEx.Items.Text_state
  45. layout:addChild(itemEx)
  46. end
  47. --默认时间总为60
  48. local timer = self.nleftStartGameTimeout
  49. local totalTime = 60
  50. --进度条
  51. --[[ self.ui.Items.LoadingBar:setPercent(timer/totalTime * 100)
  52. self.loadingBarTimer = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  53. timer = timer - 1
  54. if self.ui.Items.LoadingBar then
  55. self.ui.Items.LoadingBar:setPercent(timer/totalTime * 100)
  56. end
  57. if timer == 0 then
  58. self:cleanup()
  59. end
  60. end,1.0,false)--]]
  61. self.ui.Items.Text_3:setText(tostring(timer))
  62. self.loadingBarTimer = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  63. timer = timer - 1
  64. if self.ui.Items.Text_3 then
  65. self.ui.Items.Text_3:setText(tostring(timer))
  66. end
  67. if timer == 0 then
  68. self:cleanup()
  69. end
  70. end,1.0,false)
  71. layout:requestDoLayout()
  72. layout:doLayout()
  73. self:updateState(self.response)
  74. local happenUserName = getUserNameById(self.happenUserId)
  75. self.ui.Items.Text_1:setText("【" .. happenUserName .. "】申请立刻开局,是否同意?")
  76. end
  77. function RoomStartWaitView:initData(response)
  78. self.choiceData = {}
  79. for k,v in pairs(response) do
  80. local index = app.room:getViewIdByUserId(v.uid)
  81. if v.optType == PKDef.SPEED_START_GAME.START_OPT_TYPE_INIT or v.optType == PKDef.SPEED_START_GAME.START_OPT_TYPE_INITEX then
  82. self.choiceData[index] = {
  83. isChoice = false,
  84. isAgree = false
  85. }
  86. elseif v.optType == PKDef.SPEED_START_GAME.START_OPT_TYPE_REQ then
  87. self.happenUserId = v.uid
  88. self.choiceData[index] = {
  89. isChoice = true,
  90. isAgree = true
  91. }
  92. elseif v.optType == PKDef.SPEED_START_GAME.START_OPT_TYPE_AGREE then
  93. self.choiceData[index] = {
  94. isChoice = true,
  95. isAgree = true
  96. }
  97. elseif v.optType == PKDef.SPEED_START_GAME.START_OPT_TYPE_DISAGREE then
  98. self.choiceData[index] = {
  99. isChoice = true,
  100. isAgree = false
  101. }
  102. end
  103. end
  104. end
  105. function RoomStartWaitView:updateState(response,callTip)
  106. self.callTip = callTip
  107. self:initData(response.playerList)
  108. local myUserId = app.room.roomInfo.nUserId
  109. local myViewId = app.room:getViewIdByUserId(myUserId)
  110. if self.choiceData[myViewId].isChoice or self.happenUserId == myUserId then
  111. -- 我已经选择过了或者我是发起申请的那个
  112. self.ui.Items.Button_1:setVisible(false)
  113. self.ui.Items.Button_2:setVisible(false)
  114. else
  115. -- 我还没选择
  116. self.ui.Items.Button_1:setVisible(true)
  117. self.ui.Items.Button_2:setVisible(true)
  118. end
  119. local index = 0;
  120. local isNoAgree = false
  121. for viewId,v in pairs(self.choiceData) do
  122. if v.isAgree then
  123. self.sateList[viewId]:setTextColor(stateColor.agreeColor)
  124. self.sateList[viewId]:setText("已同意")
  125. else
  126. if v.isChoice then
  127. self.sateList[viewId]:setTextColor(stateColor.agreeColor)
  128. self.sateList[viewId]:setText("已拒绝")
  129. isNoAgree = true
  130. if self.callTip then
  131. local nUserId = app.room:getUserIdByViewId(viewId)
  132. local name = getUserNameById(nUserId)
  133. local txt = "玩家".. name .."未同意立刻开局,建议等待其他小伙伴再开局哦。"
  134. self.callTip(txt)
  135. end
  136. end
  137. end
  138. if v.isChoice then
  139. index = index + 1
  140. end
  141. end
  142. if index >= app.room:getCurMaxPlayer() or isNoAgree then
  143. self:cleanup()
  144. end
  145. end
  146. -- 同意
  147. function RoomStartWaitView:onClickAgree()
  148. app.room:sendSpeedStartCmd(PKDef.SPEED_START_GAME.START_OPT_TYPE_AGREE)
  149. end
  150. -- 拒绝
  151. function RoomStartWaitView:onClickRefuse()
  152. app.room:sendSpeedStartCmd(PKDef.SPEED_START_GAME.START_OPT_TYPE_DISAGREE)
  153. end
  154. -- 获取我的选择
  155. function RoomStartWaitView:cleanup()
  156. self:runDelay(0.01, function()
  157. self:removeView();
  158. end )
  159. end
  160. function RoomStartWaitView:removeView()
  161. if self.loadingBarTimer then
  162. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.loadingBarTimer)
  163. end
  164. if self.callback then
  165. self.callback()
  166. end
  167. self:removeFromParent()
  168. end
  169. --
  170. function RoomStartWaitView:onExit()
  171. if self.loadingBarTimer then
  172. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.loadingBarTimer)
  173. end
  174. end
  175. return RoomStartWaitView;