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.

220 lines
6.1 KiB

  1. ---
  2. -- ================================================================
  3. -- 文件名: ClubBroadcastView.lua
  4. -- 描述: 亲友圈广播条
  5. -- 版权: Copyright © 2016-2019 公司名称 版权所有
  6. -- 作者: Administrator
  7. -- 创建日期: 2019-12-05
  8. -- 更新日期: 2019-12-05
  9. -- 备注:
  10. -- ================================================================
  11. --
  12. local BroadcastType = {
  13. OFFICAL = 0, -- 官方公告
  14. GROUP = 1, -- 创始人公告
  15. }
  16. local ClubBroadcastView = class("ClubBroadcastView", cc.UIView)
  17. function ClubBroadcastView:ctor(...)
  18. ClubBroadcastView.super.ctor(self, ...)
  19. self._broadcastList = {}
  20. self.bPopConent = true
  21. self:loadUI()
  22. self:bindEvent(app.club_php , GAME_EVENT.CLUB_TABLE , handler(self , self.onEventClubTable))
  23. --收到更新公告结果
  24. self:bindEvent(app.club_php , GAME_EVENT.CLUB_NOTICE , handler(self , self.onEventClubNotice));
  25. end
  26. function ClubBroadcastView:loadUI ()
  27. local ui = loadUI("res/ui/ui_club/ui_club_broadcast.ui")
  28. self.ui = ui
  29. self:addChild(ui)
  30. end
  31. function ClubBroadcastView:onEnter ()
  32. -- 初始化界面
  33. self:initViews()
  34. end
  35. function ClubBroadcastView:onExit ( )
  36. if not tolua.isnull(self.ui.Items.Text_Content) then
  37. self.ui.Items.Text_Content:stopAllActions()
  38. end
  39. end
  40. function ClubBroadcastView:initViews()
  41. self.ui.Items.Layout_Text:registerClick(handler(self, self.onBtnEditClicked))
  42. self.ui.Items.Button_Edit:registerClick(handler(self, self.onBtnEditClicked))
  43. -- 输入公告
  44. local clubInfo = dd.IClub.getCurrentClubInfo()
  45. self.ui.Items.Button_Edit:setVisible(clubInfo.role == 2 or clubInfo.role == 3)
  46. end
  47. function ClubBroadcastView:onEventClubTable(data)
  48. if self.isFirst then
  49. return
  50. end
  51. self.isFirst = true
  52. local clubId = data.clubId
  53. local clubInfo = dd.IClub.getClubInfo(clubId)
  54. local noticeList = clubInfo.noticeList or {}
  55. if not self:isSameList(noticeList) then
  56. self:setBroadcastList(noticeList)
  57. end
  58. end
  59. function ClubBroadcastView:isSameList (newList)
  60. local oldList = self._broadcastList or {}
  61. if table.nums(newList) ~= table.nums(oldList) then
  62. -- 条数不一样,是新的列表
  63. return false
  64. end
  65. local isSame = true
  66. for k, v in pairs(newList) do
  67. -- 条数一致,检测每一条内容是否相同
  68. local isExist = false
  69. for kk, vv in pairs(oldList) do
  70. if (v.type == vv.type) and (v.notice == vv.notice) then
  71. isExist = true -- 存在记录
  72. break
  73. end
  74. end
  75. if not isExist then
  76. -- 只要有一个不存在,则列表不一致
  77. isSame = false
  78. break
  79. end
  80. end
  81. return isSame
  82. end
  83. function ClubBroadcastView:setBroadcastList(broadcastList)
  84. self._broadcastList = broadcastList or {};
  85. if table.nums(self._broadcastList) == 0 then
  86. return
  87. end
  88. if self.bPopConent then
  89. self.bPopConent = false
  90. for k,v in ipairs(self._broadcastList) do
  91. if v.type == 10 then
  92. local view = import("luaScript.Views.Main.NoticeAiDaoRiView"):new(v.notice)
  93. view:setAnchorPoint(cc.p(0.5,0.5))
  94. app:showWaitDialog(view,0)
  95. end
  96. end
  97. end
  98. self._curIndex = 1;
  99. local content = self:fotmatContnet(self._broadcastList[self._curIndex])
  100. if app.club_php:getCestIsOpen(app.club_php.clubID) then
  101. content = string.gsub(content, "玩家", "选手")
  102. end
  103. self:startRollingText(self.ui.Items.Text_Content, 80, content, self.ui.Items.Layout_Text);
  104. end
  105. -- 滚动提示
  106. -- items:滚动的Ui节点
  107. -- speedTime:滚动速度
  108. -- text: 文本显示内容
  109. -- parentNode: 裁剪的父节点
  110. function ClubBroadcastView:startRollingText(rollingNode, speed, text, parentNode)
  111. rollingNode:stopAllActions();
  112. rollingNode:setText(text);
  113. rollingNode:setPositionType(0);
  114. local parentSize = parentNode:getSize();
  115. local rollingNodeSize = rollingNode:getSize();
  116. local acMoveTo = cc.MoveTo:create((rollingNodeSize.width + parentSize.width) / speed, cc.p(-rollingNodeSize.width, rollingNode:getPositionY()))
  117. local acCallback = cc.CallFunc:create(handler(self, self.onRollingFinished))
  118. rollingNode:setPosition(cc.p(parentSize.width, rollingNode:getPositionY()))
  119. local acSeq = cc.Sequence:create(acMoveTo, acCallback)
  120. rollingNode:runAction(acSeq);
  121. end
  122. ---
  123. -- 一次滚动完成回调
  124. -- @return
  125. --
  126. function ClubBroadcastView:onRollingFinished()
  127. self._curIndex = self._curIndex + 1
  128. if self._curIndex > table.nums(self._broadcastList) then
  129. self._curIndex = 1
  130. end
  131. local content = self:fotmatContnet(self._broadcastList[self._curIndex])
  132. self:startRollingText(self.ui.Items.Text_Content, 80, content, self.ui.Items.Layout_Text);
  133. end
  134. function ClubBroadcastView:fotmatContnet(info)
  135. if not info then
  136. return ""
  137. end
  138. local title = info.type == BroadcastType.OFFICAL and "官方公告" or "创始人公告"
  139. if app.club_php:getCestIsOpen(app.club_php.clubID) then
  140. title = info.type == BroadcastType.OFFICAL and "官方公告" or "主办人公告"
  141. end
  142. local content = string.format("%s:%s", title, info.notice)
  143. return content
  144. end
  145. function ClubBroadcastView:onEventClubNotice()
  146. local clubInfo = dd.IClub.getCurrentClubInfo() or {}
  147. if clubInfo.ownerId == tonumber(app.user.loginInfo.uid) then
  148. showTooltip("设置成功")
  149. else
  150. showTooltip(app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_MESSAGE_UPDATE or PLN.CLUB_MESSAGE_UPDATE)
  151. end
  152. local clubInfo = dd.IClub.getCurrentClubInfo()
  153. if not clubInfo then
  154. return
  155. end
  156. local key = nil
  157. local content = clubInfo.noticeInfo.notice
  158. for k, v in pairs(self._broadcastList or {}) do
  159. if v.type == BroadcastType.GROUP then
  160. key = k
  161. end
  162. end
  163. if (not key) and content ~= "" then
  164. -- 不存在,则新增
  165. table.insert(self._broadcastList, {type = BroadcastType.GROUP, notice = content})
  166. else
  167. -- 存在,则修改内容
  168. if content == "" then
  169. table.remove(self._broadcastList, key)
  170. else
  171. self._broadcastList[key].notice = content
  172. end
  173. end
  174. end
  175. function ClubBroadcastView:onBtnEditClicked()
  176. local clubInfo = dd.IClub.getCurrentClubInfo() or {}
  177. if clubInfo.role == 2 or clubInfo.role == 3 then
  178. playBtnEffect()
  179. local view = import("luaScript.Views.Club.ClubSetNotice"):new(clubInfo)
  180. view:setAnchorPoint(cc.p(0.5, 0.5))
  181. app:showWaitDialog(view)
  182. end
  183. end
  184. return ClubBroadcastView