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.

221 lines
6.1 KiB

  1. -- 加入茶馆界面
  2. local ClubJoin = class("ClubJoin", cc.UIView)
  3. function ClubJoin:ctor()
  4. ClubJoin.super.ctor(self);
  5. local ui = loadUI("res/ui/ui_dating/ui_jiarufangjian.ui");
  6. self.ui = ui;
  7. self:addChild(ui);
  8. self.numbers = {};
  9. self.images =
  10. {
  11. [0] = "res/ui/zy_dating/jiaru/JoinRoom_shuzi_0.png",
  12. [1] = "res/ui/zy_dating/jiaru/JoinRoom_shuzi_1.png",
  13. [2] = "res/ui/zy_dating/jiaru/JoinRoom_shuzi_2.png",
  14. [3] = "res/ui/zy_dating/jiaru/JoinRoom_shuzi_3.png",
  15. [4] = "res/ui/zy_dating/jiaru/JoinRoom_shuzi_4.png",
  16. [5] = "res/ui/zy_dating/jiaru/JoinRoom_shuzi_5.png",
  17. [6] = "res/ui/zy_dating/jiaru/JoinRoom_shuzi_6.png",
  18. [7] = "res/ui/zy_dating/jiaru/JoinRoom_shuzi_7.png",
  19. [8] = "res/ui/zy_dating/jiaru/JoinRoom_shuzi_8.png",
  20. [9] = "res/ui/zy_dating/jiaru/JoinRoom_shuzi_9.png",
  21. }
  22. end
  23. function ClubJoin:onEnter()
  24. ClubJoin.super.onEnter(self)
  25. self.ui.Items.ImageView_title:loadTexture("res/ui/zy_club/club_main/club_title_font_join.png")
  26. -- 房间号图片
  27. self.numberImage = {}
  28. self.numberImage[1] = self.ui.Items.ImageView_fangjianhao_1
  29. self.numberImage[2] = self.ui.Items.ImageView_fangjianhao_2
  30. self.numberImage[3] = self.ui.Items.ImageView_fangjianhao_3
  31. self.numberImage[4] = self.ui.Items.ImageView_fangjianhao_4
  32. self.numberImage[5] = self.ui.Items.ImageView_fangjianhao_5
  33. self.numberImage[6] = self.ui.Items.ImageView_fangjianhao_6
  34. -- 键盘按钮
  35. self.numberButton = {}
  36. self.numberButton[0] = self.ui.Items.Button_10
  37. self.numberButton[1] = self.ui.Items.Button_1
  38. self.numberButton[2] = self.ui.Items.Button_2
  39. self.numberButton[3] = self.ui.Items.Button_3
  40. self.numberButton[4] = self.ui.Items.Button_4
  41. self.numberButton[5] = self.ui.Items.Button_5
  42. self.numberButton[6] = self.ui.Items.Button_6
  43. self.numberButton[7] = self.ui.Items.Button_7
  44. self.numberButton[8] = self.ui.Items.Button_8
  45. self.numberButton[9] = self.ui.Items.Button_9
  46. for k,v in pairs(self.numberButton) do
  47. v:registerClick(function()
  48. playBtnEffect()
  49. self:onClickNumber(k)
  50. end)
  51. end
  52. -- 重输
  53. self.ui.Items.Button_11:registerClick(function()
  54. playBtnEffect()
  55. self:onClickReturn()
  56. end)
  57. self.ui.Items.btnTest:setVisible(false)
  58. -- 回删
  59. self.ui.Items.Button_12:registerClick(handler(self , self.onClickBack))
  60. -- 关闭
  61. self.ui.Items.Button_guanbi:registerClick(handler(self , self.onClickClose))
  62. -- 监听事件
  63. -- self:bindEvent(app.club_php , "onJoinClubResponse", handler(self , self.onJoinClubResponse));
  64. self:bindEvent(app.club_php , GAME_EVENT.CLUB_JOIN, handler(self , self.onJoinClubResponse));
  65. self:onClickReturn()
  66. end
  67. -- 监听事件
  68. function ClubJoin:onJoinClubResponse(event)
  69. if not event then
  70. return
  71. end
  72. local errCode = event.errCode
  73. local errcontent = event.error
  74. if errCode == 200 then
  75. showTooltip("申请成功,请等待管理员审核!")
  76. self:removeFromParent()
  77. return;
  78. elseif errCode == 201 then
  79. showTooltip(PLN.CLUB_CEST_JOIN_SUCCESS)
  80. self:removeFromParent()
  81. return;
  82. elseif errCode == 1010 then
  83. showTooltip("申请加入失败")
  84. elseif errCode == 1011 then
  85. -- showTooltip("申请加入失败,已加入"..(app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_NAME or PLN.CLUB_NAME))
  86. -- showTooltip("申请加入失败,已加入"..PLN.CLUB_CEST_NAME)
  87. showTooltip("申请加入失败,已加入"..PLN.CLUB_CEST_NAME2)
  88. elseif errCode == 1013 then
  89. showTooltip("申请加入失败,内部错误")
  90. elseif errCode == 1014 then
  91. -- showTooltip(app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_NOT_FOUND or PLN.CLUB_NOT_FOUND)
  92. showTooltip(PLN.CLUB_CEST_NOT_FOUND)
  93. elseif errCode == 1015 then
  94. -- showTooltip(app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_ALREADY_DONG_JIE or PLN.CLUB_ALREADY_DONG_JIE)
  95. showTooltip(PLN.CLUB_CEST_ALREADY_DONG_JIE)
  96. elseif errCode == 1016 then
  97. showTooltip("申请加入失败,群人员已达上限")
  98. elseif errCode == 1018 then
  99. -- showTooltip(app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_JOIN_MAX or PLN.CLUB_JOIN_MAX)
  100. showTooltip(PLN.CLUB_CEST_JOIN_MAX)
  101. elseif errCode == 1041 then
  102. showTooltip("您已申请,请等待管理员审核!")
  103. else
  104. if errcontent ~= "" then
  105. showTooltip(errcontent)
  106. else
  107. local strCode = string.format("未知错误 code = %d", errCode)
  108. showTooltip(strCode)
  109. end
  110. end
  111. self:onClickReturn()
  112. end
  113. -- 关闭
  114. function ClubJoin:onClickClose()
  115. playBtnCloseEffect()
  116. self:removeFromParent()
  117. end
  118. -- 重输
  119. function ClubJoin:onClickReturn()
  120. self.numbers = {}
  121. self:updateNumbers()
  122. end
  123. -- 回删
  124. function ClubJoin:onClickBack()
  125. playBtnEffect()
  126. local num = #self.numbers
  127. if num <= 0 then
  128. return;
  129. end
  130. table.remove(self.numbers, num)
  131. self:updateNumbers()
  132. end
  133. -- 数字
  134. function ClubJoin:onClickNumber(number)
  135. if #self.numbers >= 6 then
  136. return
  137. end
  138. table.insert(self.numbers, number)
  139. self:updateNumbers()
  140. if #self.numbers >= 6 then
  141. self:onClickOk()
  142. end
  143. end
  144. function ClubJoin:onClickTest()
  145. local n = cc.UserDefault:getInstance():getIntegerForKey("LastTestClubID",0)
  146. if n == 0 then
  147. showTooltip("请先开个赛事")
  148. return
  149. end
  150. self.numbers[1] = math.floor(n / 100000 % 10)
  151. self.numbers[2] = math.floor(n / 10000 % 10)
  152. self.numbers[3] = math.floor(n / 1000 % 10)
  153. self.numbers[4] = math.floor(n / 100 % 10)
  154. self.numbers[5] = math.floor(n / 10 % 10)
  155. self.numbers[6] = math.floor(n / 1 % 10)
  156. self:updateNumbers();
  157. self:onClickOk()
  158. end
  159. function ClubJoin:onClickOk()
  160. local str = ""
  161. for i = 1,#self.numbers do
  162. str = str..self.numbers[i]
  163. end
  164. local room_id = tonumber(str)
  165. print(room_id)
  166. --发送申请加入茶馆
  167. local userInfo = json.decode(app.user.userInfo);
  168. local nick = userInfo.nickname
  169. local nickLen = string.len(nick)
  170. if nickLen <= 0 then
  171. nick = "";
  172. end
  173. local headUrl = userInfo.headimgurl
  174. local headLen = string.len(headUrl)
  175. if headLen <= 0 then
  176. headUrl = "";
  177. end
  178. app.club_php:requestJoinClub(room_id,nick,headUrl)
  179. end
  180. --
  181. function ClubJoin:updateNumbers()
  182. for k,v in pairs(self.numberImage) do
  183. if self.numbers[k] then
  184. v:setVisible(true)
  185. local num = self.numbers[k]
  186. local image = self.images[num];
  187. v:loadTexture(image)
  188. else
  189. v:setVisible(false)
  190. end
  191. end
  192. end
  193. return ClubJoin;