源战役客户端
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.
 
 
 
 
 

172 lines
3.9 KiB

--[[
横向Bar
示例:
self.tabBar = UIHorTabBar.New(self.tabCon)
self.tabBar:SetData({"按钮1","按钮2"}, call_back)
self.tabBar:SetSize(180,60)
self.tabBar:SetSelectTab(1)
]]
UIHorTabBar = UIHorTabBar or BaseClass(BaseComponent)
function UIHorTabBar:__init(handle_wnd)
self:CreateGameObject(UIType.UIHorTabBar)
self.item_list = {}
end
--[[
data = {"标签1","标签2","标签3"}
]]
function UIHorTabBar:SetData( data, call_back )
self.data = data
self.call_back = call_back
local call_back = function ( index )
self:SetSelectTab(index)
if self.call_back then
self.call_back(index)
end
end
for i,v in ipairs(data) do
local item = self.item_list[i]
if not item then
item = UIHorTabBtn.New(self.ScrollViewCon, call_back)
self.item_list[i] = item
end
item:SetVisible(true)
item:SetText(i, v)
end
self:BoolCanClick(true)
for i=#data+1, #self.item_list do
self.item_list[i]:SetVisible(false)
end
end
function UIHorTabBar:BoolCanClick(state)
self.can_click_state = state
for k,v in pairs(self.item_list) do
v:SetCanClick(self.can_click_state)
end
end
function UIHorTabBar:ShowItemRedDot( index, bool )
if self.item_list[index] then
self.item_list[index]:ShowRedDot(bool)
end
end
function UIHorTabBar:GetSize( )
local count = 0
for k,v in pairs(self.item_list) do
if v:GetVisible() then
count = count + 1
end
end
return count
end
function UIHorTabBar:GetTotalSize( )
local count = 0
for k,v in pairs(self.item_list) do
count = count + 1
end
return count
end
function UIHorTabBar:SetSelectTab( index )
self.cur_index = index
if self.item_list[self.last_index] then
self.item_list[self.last_index]:SetSelected(false)
end
if self.item_list[self.cur_index] then
self.item_list[self.cur_index]:SetSelected(true)
end
self.last_index = self.cur_index
end
function UIHorTabBar:SetItemVisible( index, bool )
if self.item_list[index] then
self.item_list[index]:SetVisible(bool)
end
end
function UIHorTabBar:GetItemVisible( index )
if self.item_list[index] then
return self.item_list[index]:GetVisible()
end
end
function UIHorTabBar:SetSize( w, h )
self.grid_layout.cellSize = Vector2(w, h)
end
function UIHorTabBar:SetScrollConPos(x, y)
local max_width = GetSizeDeltaX(self.ScrollViewCon)
if max_width > 0 then
if x > 0 then
x = 0
else
x = math.max(x,-max_width)
end
self.ScrollViewCon.transform.localPosition = Vector2(x, y)
else
self.con_x = x
self.con_y = y
local function delay_method( )
self:SetScrollConPos(self.con_x,self.con_y)
end
self.delay_time = self.delay_time or setTimeout(delay_method, 0.01)
end
end
function UIHorTabBar:LoadSuccess()
self.ScrollView = self:GetChild("ScrollView")
self.ScrollViewViewport = self:GetChild("ScrollView/Viewport")
self.ScrollViewCon = self:GetChild("ScrollView/Viewport/Content")
self.group = self.gameObject:GetComponent("ToggleGroup")
self.scroll_view_rect = self.ScrollView:GetComponent("ScrollRect")
self.scroll_view_rect.horizontal = true
self.scroll_view_rect.vertical = false
self.grid_layout = self.ScrollViewCon:GetComponent("GridLayoutGroup")
self.transform.anchoredPosition = Vector2.zero
self.transform.sizeDelta = Vector2(0, 116)
self:InitEvent()
end
function UIHorTabBar:SetHorizontal( bool )
self.scroll_view_rect.horizontal = bool
end
function UIHorTabBar:SetBtnRes( asset, res1, res2 )
for k,v in pairs(self.item_list) do
v:SetBtnRes(asset, res1, res2)
end
end
function UIHorTabBar:SetBtnLabelColor(color1,color2)
for k,v in pairs(self.item_list) do
v:SetBtnLabelColor(color1,color2)
end
end
function UIHorTabBar:SetSpacing( w, h )
self.grid_layout.spacing = Vector2(w, h)
end
function UIHorTabBar:InitEvent()
end
function UIHorTabBar:GetItemByIndex(index)
local item = self.item_list[index]
if not item then
return
end
return item
end
function UIHorTabBar:__delete( )
for k,v in pairs(self.item_list) do
v:DeleteMe()
end
self.item_list = {}
end