FullTabButton = FullTabButton or BaseClass(BaseItem)
|
|
local FullTabButton = FullTabButton
|
|
function FullTabButton:__init(parent)
|
|
self.base_file = "uiComponent"
|
|
self.layout_file = "FullTabButton"
|
|
self.index = 0
|
|
self.name = ""
|
|
self.tabbar_asset = ""
|
|
self.dark_res = ""
|
|
self.light_res = ""
|
|
self:Load()
|
|
self.is_selected = -1
|
|
self.show_red_dot = -1
|
|
end
|
|
|
|
function FullTabButton:__delete()
|
|
if self.timer_id then
|
|
TimerQuest.CancelQuest(GlobalTimerQuest, self.timer_id)
|
|
self.timer_id = nil
|
|
end
|
|
if self.tween_id then
|
|
TweenLite.Stop(self.tween_id)
|
|
self.tween_id = nil
|
|
end
|
|
end
|
|
|
|
function FullTabButton:Load_callback()
|
|
self.select_img = self:GetChild("Select").gameObject
|
|
self.btn_img = self:GetChild("Icon"):GetComponent("Image")
|
|
self.redPoint = self:GetChild("Dot").gameObject
|
|
self.line = self:GetChild("Line").gameObject
|
|
|
|
self:InitEvent()
|
|
|
|
if self.need_refreshData then
|
|
self:SetData(self.index,self.tabbar_asset,self.data,self.callback,self.show_anim)
|
|
end
|
|
end
|
|
|
|
function FullTabButton:SetData(index,tabbar_asset,data,callback,show_anim)
|
|
self.index = index
|
|
self.tabbar_asset = tabbar_asset
|
|
self.data = data
|
|
self.callback = callback
|
|
self.show_anim = show_anim
|
|
self.name = data.name or ""
|
|
self.light_res = data.light_res or ""
|
|
self.dark_res = data.dark_res or ""
|
|
|
|
if self.is_loaded then
|
|
self.index = index
|
|
|
|
if self.dark_res ~= "" then
|
|
lua_resM:setImageSprite(self,self.btn_img,self.tabbar_asset,self.dark_res,true)
|
|
end
|
|
|
|
if self.is_selected ~= -1 then
|
|
self:SetSelect(self.is_selected)
|
|
end
|
|
|
|
if self.show_red_dot ~= -1 then
|
|
self:ShowRedPoint(self.show_red_dot)
|
|
end
|
|
|
|
if show_anim then
|
|
self.transform.anchoredPosition = Vector2(-150, (self.index - 1) * -100 - 65)
|
|
|
|
local function delay_func( ... )
|
|
self.tween_id = TweenLite.to(self, self.transform, TweenLite.UiAnimationType.POSX, 0, 0.2, nil)
|
|
end
|
|
self.timer_id = setTimeout(delay_func, 0.1 * self.index)
|
|
else
|
|
self.transform.anchoredPosition = Vector2(0, (self.index - 1) * -100 - 65)
|
|
end
|
|
else
|
|
self.need_refreshData = true
|
|
end
|
|
end
|
|
|
|
function FullTabButton:SetSelect(bool)
|
|
bool = bool == nil and -1 or bool
|
|
if self.is_loaded then
|
|
if bool ~= -1 then
|
|
if bool then
|
|
self.line:SetActive(false)
|
|
self.select_img:SetActive(true)
|
|
if self.light_res ~= "" then
|
|
lua_resM:setImageSprite(self,self.btn_img,self.tabbar_asset,self.light_res,true)
|
|
end
|
|
else
|
|
self.line:SetActive(true)
|
|
self.select_img:SetActive(false)
|
|
if self.dark_res ~= "" then
|
|
lua_resM:setImageSprite(self,self.btn_img,self.tabbar_asset,self.dark_res,true)
|
|
end
|
|
end
|
|
self.is_selected = -1
|
|
end
|
|
else
|
|
self.is_selected = bool
|
|
end
|
|
end
|
|
|
|
function FullTabButton:InitEvent()
|
|
local function onTabBtnHandler(target)
|
|
if self.callback ~= nil then
|
|
self:ClickCall()
|
|
end
|
|
end
|
|
|
|
AddClickEvent(self.gameObject,onTabBtnHandler,2)
|
|
end
|
|
|
|
function FullTabButton:ShowRedPoint(bool)
|
|
bool = bool == nil and -1 or bool
|
|
if self.is_loaded then
|
|
if bool ~= -1 then
|
|
self.redPoint:SetActive(bool)
|
|
self.show_red_dot = -1
|
|
end
|
|
else
|
|
self.show_red_dot = bool
|
|
end
|
|
end
|
|
|
|
function FullTabButton:ClickCall( )
|
|
self.callback(self.index)
|
|
end
|
|
|