FuliNoticeView = FuliNoticeView or BaseClass(BaseItem)
|
|
local FuliNoticeView = FuliNoticeView
|
|
|
|
function FuliNoticeView:__init()
|
|
self.base_file = "Fuli"
|
|
self.layout_file = "FuliNoticeView"
|
|
self.model = LoginModel:getInstance()
|
|
self.index = index or 1
|
|
self.tab_list = {}
|
|
self.cont_height = 564 + 15
|
|
self:Load()
|
|
end
|
|
|
|
function FuliNoticeView:Load_callback()
|
|
self.nodes = {
|
|
"scrollNotice/Viewport/Content/bg2:raw", "arrow_image", "scrollNotice/Viewport/Content/bg2/jump_btn:obj",
|
|
}
|
|
self:GetChildren(self.nodes)
|
|
|
|
self.scrollTab = self:GetChild("scrollTab/Viewport/Content")
|
|
self.scrollNotice = self:GetChild("scrollNotice/Viewport/Content")
|
|
self.scroll_rect = self:GetChild("scrollNotice"):GetComponent("ScrollRect")
|
|
self.scroll_obj = self:GetChild("scrollNotice").gameObject
|
|
self.arrow_image_canvas = self.arrow_image:GetComponent("CanvasGroup")
|
|
self.contentTxt = self:GetChild("scrollNotice/Viewport/Content/contentTxt"):GetComponent("TextMeshProUGUI")
|
|
self:AddEvents()
|
|
|
|
|
|
self.bg2.transform.pivot = Vector2(0,1)
|
|
self.bg2.transform.anchorMin = Vector2(0, 1)
|
|
self.bg2.transform.anchorMax = Vector2(0, 1)
|
|
SetAnchoredPosition(self.bg2,0,0)
|
|
|
|
if self.need_refreshData then
|
|
self:UpdateView()
|
|
end
|
|
end
|
|
|
|
function FuliNoticeView:AddEvents( )
|
|
local on_scroll_end = function ( )
|
|
self:StopAllAnim()
|
|
self:RemoveDelayHideId()
|
|
self.arrow_image_canvas.alpha = 0
|
|
end
|
|
BindScrollViewEndEvent(self.scroll_obj, self.scroll_rect, on_scroll_end)
|
|
local function on_click( ... )
|
|
if self.data then
|
|
local jump_id = stringtotable(self.data.jump_id)
|
|
if TableSize(jump_id) > 0 then
|
|
OpenFun.Open(jump_id[1][1],jump_id[1][2])
|
|
end
|
|
end
|
|
end
|
|
AddClickEvent(self.jump_btn_obj, on_click)
|
|
end
|
|
|
|
function FuliNoticeView:UpdateView( )
|
|
local data = self.model:GetNoticeData("fuli_view")
|
|
if TableSize(data) == 0 then
|
|
return
|
|
end
|
|
local sort_func = function ( a, b )
|
|
return a.sequence < b.sequence
|
|
end
|
|
table.sort(data, sort_func)
|
|
local callback = function (index)
|
|
self.index = index
|
|
for _, v in pairs(self.tab_list) do
|
|
v:SetSelectState(v.index == index)
|
|
end
|
|
self:SwitchView(data, index)
|
|
end
|
|
|
|
local tab = nil
|
|
for i, v in ipairs(data) do
|
|
tab = self.tab_list[i]
|
|
if tab == nil then
|
|
tab = FuliNoticeTab.New(self.scrollTab)
|
|
self.tab_list[i] = tab
|
|
end
|
|
tab:SetPosition(7, -61 * (i - 1)-8)
|
|
tab:SetCallBack(callback)
|
|
tab:SetData(v, i)
|
|
end
|
|
self.scrollTab.sizeDelta = Vector2(245, #data * 80)
|
|
callback(self.index)
|
|
end
|
|
|
|
function FuliNoticeView:SwitchView(content_list, index)
|
|
local banner = content_list[index].picture == "[]" and 1 or content_list[index].picture
|
|
local content = content_list[index].content or ""
|
|
lua_resM:setOutsideRawImage(self,self.bg2_raw,GameResPath.GetViewBigBg("notice_banner"..banner),true)
|
|
self.contentTxt.text = content
|
|
self.size = self.contentTxt.preferredHeight + 60 + 145--145是banner高
|
|
self.scrollNotice.sizeDelta = Vector2(688, self.size)
|
|
if self.size < self.cont_height then
|
|
self.scroll_rect.enabled = false
|
|
self:StopAllAnim()
|
|
self:RemoveDelayHideId()
|
|
self.arrow_image_canvas.alpha = 0
|
|
else
|
|
self.scroll_rect.enabled = true
|
|
end
|
|
SetAnchoredPositionY(self.scrollNotice, 0)
|
|
self:SetTimer()
|
|
--设置跳转按钮开不开
|
|
local data = content_list[index]
|
|
self.data = data
|
|
self.jump_btn_obj:SetActive(false)
|
|
if data then
|
|
local jump_id = stringtotable(data.jump_id)
|
|
local day_can_jump = false
|
|
local lv_can_jump = false
|
|
if TableSize(jump_id) > 0 then--有跳转
|
|
local openDay = stringtotable(data.open_day)
|
|
if TableSize(openDay) > 0 then--有配开服天数
|
|
local server_open_time = ServerTimeModel:getInstance():GetOpenServerTime()
|
|
local open_day = 0
|
|
if server_open_time > 0 then
|
|
local open_time = os.time() - server_open_time
|
|
open_day = open_time / 3600 / 24
|
|
-- return math.ceil(day)--当时间刚好是3600*24*n的时候 就会比服务端少算一天的时间 客户端只有经过24小时+1秒才会递进1天
|
|
open_day = math.floor(open_day+1)
|
|
if openDay[1][1] <= open_day and openDay[1][2] >= open_day then
|
|
day_can_jump = true
|
|
end
|
|
end
|
|
else
|
|
day_can_jump = true
|
|
end
|
|
local jump_lv = stringtotable(data.jump_lv)
|
|
if TableSize(jump_lv) > 0 then--有限制等级跳转
|
|
local level = RoleManager.Instance.mainRoleInfo.level
|
|
if jump_lv[1][1] <= level and jump_lv[1][2] >= level then
|
|
lv_can_jump = true
|
|
end
|
|
else
|
|
lv_can_jump = true
|
|
end
|
|
self.jump_btn_obj:SetActive(day_can_jump and lv_can_jump)
|
|
end
|
|
end
|
|
end
|
|
|
|
function FuliNoticeView:SetData( data )
|
|
self.data = data
|
|
if self.is_loaded then
|
|
self.need_refreshData = false
|
|
self:UpdateView()
|
|
else
|
|
self.need_refreshData = true
|
|
end
|
|
end
|
|
|
|
function FuliNoticeView:SetTimer( )
|
|
self:StopTimer()
|
|
local time = 3
|
|
local function onBoxTimer()
|
|
time = time - 1
|
|
if time > 0 then
|
|
|
|
else
|
|
local x, y_offset = GetAnchoredPosition(self.scrollNotice, 0)
|
|
if self.size <= self.cont_height or y_offset ~= 0 then--后面没东西了或者玩家动过
|
|
else
|
|
self:FlashHideCall()
|
|
self:StopAllAnim()
|
|
end
|
|
self:StopTimer()
|
|
end
|
|
end
|
|
self.arrow_timer_id = GlobalTimerQuest:AddPeriodQuest(onBoxTimer, 1, -1)
|
|
end
|
|
|
|
function FuliNoticeView:FlashShowCall( )
|
|
if self._use_delete_method then
|
|
return
|
|
end
|
|
local function callback( )
|
|
self:FlashHideCall()
|
|
end
|
|
self.arrow_img_anim_id = TweenLite.to(self, self.arrow_image_canvas, TweenLite.UiAnimationType.ALPHA, 1, 0.5, callback)
|
|
end
|
|
|
|
function FuliNoticeView:FlashHideCall( )
|
|
if self._use_delete_method then
|
|
return
|
|
end
|
|
local function callback( )
|
|
self:FlashShowCall()
|
|
end
|
|
if not self.delay_hide_id then
|
|
local function delay( )
|
|
self:RemoveDelayHideId()
|
|
self.arrow_img_anim_id = TweenLite.to(self, self.arrow_image_canvas, TweenLite.UiAnimationType.ALPHA, 0.3, 0.5, callback)
|
|
end
|
|
self.delay_hide_id = setTimeout(delay,0.2)
|
|
end
|
|
end
|
|
|
|
function FuliNoticeView:RemoveDelayHideId( )
|
|
if self.delay_hide_id then
|
|
GlobalTimerQuest:CancelQuest(self.delay_hide_id)
|
|
self.delay_hide_id = nil
|
|
end
|
|
end
|
|
|
|
function FuliNoticeView:StopAllAnim( )
|
|
if self.arrow_img_anim_id then
|
|
TweenLite.Stop(self.arrow_img_anim_id)
|
|
self.arrow_img_anim_id = nil
|
|
end
|
|
end
|
|
|
|
function FuliNoticeView:StopTimer( )
|
|
if self.arrow_timer_id then
|
|
GlobalTimerQuest:CancelQuest(self.arrow_timer_id)
|
|
self.arrow_timer_id = nil
|
|
end
|
|
end
|
|
|
|
function FuliNoticeView:__delete( )
|
|
for k, v in pairs(self.tab_list) do
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
self.item_list = {}
|
|
self.scroll_rect.onValueChanged:RemoveAllListeners()
|
|
self:StopAllAnim()
|
|
self:RemoveDelayHideId()
|
|
self:StopTimer()
|
|
end
|