--- -- ================================================================ -- 文件名: ClubBroadcastView.lua -- 描述: 亲友圈广播条 -- 版权: Copyright © 2016-2019 公司名称 版权所有 -- 作者: Administrator -- 创建日期: 2019-12-05 -- 更新日期: 2019-12-05 -- 备注: -- ================================================================ -- local BroadcastType = { OFFICAL = 0, -- 官方公告 GROUP = 1, -- 创始人公告 } local ClubBroadcastView = class("ClubBroadcastView", cc.UIView) function ClubBroadcastView:ctor(...) ClubBroadcastView.super.ctor(self, ...) self._broadcastList = {} self.bPopConent = true self:loadUI() self:bindEvent(app.club_php , GAME_EVENT.CLUB_TABLE , handler(self , self.onEventClubTable)) --收到更新公告结果 self:bindEvent(app.club_php , GAME_EVENT.CLUB_NOTICE , handler(self , self.onEventClubNotice)); end function ClubBroadcastView:loadUI () local ui = loadUI("res/ui/ui_club/ui_club_broadcast.ui") self.ui = ui self:addChild(ui) end function ClubBroadcastView:onEnter () -- 初始化界面 self:initViews() end function ClubBroadcastView:onExit ( ) if not tolua.isnull(self.ui.Items.Text_Content) then self.ui.Items.Text_Content:stopAllActions() end end function ClubBroadcastView:initViews() self.ui.Items.Layout_Text:registerClick(handler(self, self.onBtnEditClicked)) self.ui.Items.Button_Edit:registerClick(handler(self, self.onBtnEditClicked)) -- 输入公告 local clubInfo = dd.IClub.getCurrentClubInfo() self.ui.Items.Button_Edit:setVisible(clubInfo.role == 2 or clubInfo.role == 3) end function ClubBroadcastView:onEventClubTable(data) if self.isFirst then return end self.isFirst = true local clubId = data.clubId local clubInfo = dd.IClub.getClubInfo(clubId) local noticeList = clubInfo.noticeList or {} if not self:isSameList(noticeList) then self:setBroadcastList(noticeList) end end function ClubBroadcastView:isSameList (newList) local oldList = self._broadcastList or {} if table.nums(newList) ~= table.nums(oldList) then -- 条数不一样,是新的列表 return false end local isSame = true for k, v in pairs(newList) do -- 条数一致,检测每一条内容是否相同 local isExist = false for kk, vv in pairs(oldList) do if (v.type == vv.type) and (v.notice == vv.notice) then isExist = true -- 存在记录 break end end if not isExist then -- 只要有一个不存在,则列表不一致 isSame = false break end end return isSame end function ClubBroadcastView:setBroadcastList(broadcastList) self._broadcastList = broadcastList or {}; if table.nums(self._broadcastList) == 0 then return end if self.bPopConent then self.bPopConent = false for k,v in ipairs(self._broadcastList) do if v.type == 10 then local view = import("luaScript.Views.Main.NoticeAiDaoRiView"):new(v.notice) view:setAnchorPoint(cc.p(0.5,0.5)) app:showWaitDialog(view,0) end end end self._curIndex = 1; local content = self:fotmatContnet(self._broadcastList[self._curIndex]) if app.club_php:getCestIsOpen(app.club_php.clubID) then content = string.gsub(content, "玩家", "选手") end self:startRollingText(self.ui.Items.Text_Content, 80, content, self.ui.Items.Layout_Text); end -- 滚动提示 -- items:滚动的Ui节点 -- speedTime:滚动速度 -- text: 文本显示内容 -- parentNode: 裁剪的父节点 function ClubBroadcastView:startRollingText(rollingNode, speed, text, parentNode) rollingNode:stopAllActions(); rollingNode:setText(text); rollingNode:setPositionType(0); local parentSize = parentNode:getSize(); local rollingNodeSize = rollingNode:getSize(); local acMoveTo = cc.MoveTo:create((rollingNodeSize.width + parentSize.width) / speed, cc.p(-rollingNodeSize.width, rollingNode:getPositionY())) local acCallback = cc.CallFunc:create(handler(self, self.onRollingFinished)) rollingNode:setPosition(cc.p(parentSize.width, rollingNode:getPositionY())) local acSeq = cc.Sequence:create(acMoveTo, acCallback) rollingNode:runAction(acSeq); end --- -- 一次滚动完成回调 -- @return -- function ClubBroadcastView:onRollingFinished() self._curIndex = self._curIndex + 1 if self._curIndex > table.nums(self._broadcastList) then self._curIndex = 1 end local content = self:fotmatContnet(self._broadcastList[self._curIndex]) self:startRollingText(self.ui.Items.Text_Content, 80, content, self.ui.Items.Layout_Text); end function ClubBroadcastView:fotmatContnet(info) if not info then return "" end local title = info.type == BroadcastType.OFFICAL and "官方公告" or "创始人公告" if app.club_php:getCestIsOpen(app.club_php.clubID) then title = info.type == BroadcastType.OFFICAL and "官方公告" or "主办人公告" end local content = string.format("%s:%s", title, info.notice) return content end function ClubBroadcastView:onEventClubNotice() local clubInfo = dd.IClub.getCurrentClubInfo() or {} if clubInfo.ownerId == tonumber(app.user.loginInfo.uid) then showTooltip("设置成功") else showTooltip(app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_MESSAGE_UPDATE or PLN.CLUB_MESSAGE_UPDATE) end local clubInfo = dd.IClub.getCurrentClubInfo() if not clubInfo then return end local key = nil local content = clubInfo.noticeInfo.notice for k, v in pairs(self._broadcastList or {}) do if v.type == BroadcastType.GROUP then key = k end end if (not key) and content ~= "" then -- 不存在,则新增 table.insert(self._broadcastList, {type = BroadcastType.GROUP, notice = content}) else -- 存在,则修改内容 if content == "" then table.remove(self._broadcastList, key) else self._broadcastList[key].notice = content end end end function ClubBroadcastView:onBtnEditClicked() local clubInfo = dd.IClub.getCurrentClubInfo() or {} if clubInfo.role == 2 or clubInfo.role == 3 then playBtnEffect() local view = import("luaScript.Views.Club.ClubSetNotice"):new(clubInfo) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end end return ClubBroadcastView