--[[ TasWindowTab V1.4
plugin for TasWindow by Tasyen.
Instead of placing stuff onto the ContentPane one adds Frames as Tabs (pages). The current shown Tab is swaped by the user clicking TabButtons.
First Create a TasWindow then add a frame as Tab to the TasWindow.
Having a tab does not stopp one from placing something onto the ContentPane itself.
addition to TasWindow "class"
.Tabs[1 to x] -- each a windowTabTable
.TabActive
.TabPos -- Where the TabButtons are placed relative to the TasWindow. copies TasWindow.TabPos.Default when not set before addTab is called.
.IconButtonInherit -- new I
.IconButtonSize
windowTabTable
.Button
.Frame
.SizeX
.SizeY
.ShowAction -- set over setTabButtonAction
function TasWindow.addTabIcon(windowTable, frame, icon, doNotStretch, xSize, ySize)
wrapper for TasWindow.addTab that creates some icon button
uses TasWindow.IconButtonInherit & TasWindow.IconButtonSize
function TasWindow.addTab(windowTable, frame, [buttonText, doNotStretch, xSize, ySize])
adds frame as Tab to windowTable
buttonText is displayed on the Button to swap to this tab
buttonText can be a button which is than used as tabButton. sets TasButtonAction for it
doNotStretch(true) does not alter the size of frame, also pos it with its center to the WindowPane center
xSize and ySize when set, will alter the size of windowTable as long this tab is shown
Does not support SimpleFrames, directly.
frames parent, position, size (without doNotStretch) are altered in the process.
returns the new created windowTabtable
function TasWindow.setTabButtonAction(windowTabTable, actionFunction)
calls actionFunction when this button is clicked and shown.
Beaware that the action is called async.
actionFunction = function(windowTable, windowTabTable) end
Will instantly call the actionFunction if the tab is the current active tab
function TasWindow.showTab(windowTable, windowTabTable[, player])
show windowTabTable of windowTable to player
windowTabTable can be a index or a table, the table is expected to be a tabTable of the windowTable
player can be nil to affect all players
doesn't work that well with LeaderBoard, Multiboard, TimerDialog
Does not support simpleframes.
--]]
TasWindow.TabPos = {
Default = 1
-- {button1Pos, button1Relative, x2Pane, y2Pane , buttonXPos, ButtonXRelat, x2Prv, y2Prev, addgapToHead}
,{FRAMEPOINT_TOPRIGHT, FRAMEPOINT_TOPLEFT, 0, 0, FRAMEPOINT_TOPRIGHT, FRAMEPOINT_BOTTOMRIGHT, 0.000, 0.005} -- Left top -> Bot
,{FRAMEPOINT_BOTTOMRIGHT, FRAMEPOINT_BOTTOMLEFT, 0, 0, FRAMEPOINT_BOTTOMRIGHT, FRAMEPOINT_TOPRIGHT, 0.000, -0.005} -- Left Bot -> top
,{FRAMEPOINT_BOTTOMLEFT, FRAMEPOINT_TOPLEFT, 0, 0, FRAMEPOINT_BOTTOMLEFT, FRAMEPOINT_BOTTOMRIGHT, 0.005, 0.000, true} -- Top Left -> right
,{FRAMEPOINT_BOTTOMRIGHT, FRAMEPOINT_TOPRIGHT, 0, 0, FRAMEPOINT_BOTTOMRIGHT, FRAMEPOINT_BOTTOMLEFT, -0.005, 0.00, true} -- Top Right -> Left
,{FRAMEPOINT_TOPLEFT, FRAMEPOINT_BOTTOMLEFT, 0, 0, FRAMEPOINT_TOPLEFT, FRAMEPOINT_TOPRIGHT, 0.005, 0.000} -- Bottom Left -> Right
,{FRAMEPOINT_TOPRIGHT, FRAMEPOINT_BOTTOMRIGHT, 0, 0, FRAMEPOINT_TOPRIGHT, FRAMEPOINT_TOPLEFT, -0.005, 0.000} -- Bottom Right to Left
,{FRAMEPOINT_TOPLEFT, FRAMEPOINT_TOPRIGHT, 0, 0, FRAMEPOINT_TOPLEFT, FRAMEPOINT_BOTTOMLEFT, 0.000, 0.005} -- Right Top -> Bot
,{FRAMEPOINT_BOTTOMLEFT, FRAMEPOINT_BOTTOMRIGHT, 0, 0, FRAMEPOINT_BOTTOMLEFT, FRAMEPOINT_TOPLEFT, 0.000, -0.005} -- Right Bot -> Top
}
TasWindow.IconButtonInherit = "ScoreScreenTabButtonTemplate" -- Button Blueprint inherited, used without fdf
TasWindow.IconButtonSize = 0.025
function TasWindow.addTabIcon(windowTable, frame, icon, doNotStretch, xSize, ySize)
local tabButton
if TasWindow.HasToc then
tabButton = BlzCreateFrame("WindowTabIconButton", windowTable.WindowPane, 0, 0)
BlzFrameSetTexture(BlzGetFrameByName("WindowTabIconButtonBackdrop", 0), icon, 0, true)
BlzFrameSetTexture(BlzGetFrameByName("WindowTabIconButtonBackdropPushed", 0), icon, 0, true)
BlzFrameSetTexture(BlzGetFrameByName("WindowTabIconButtonBackdropDisabled", 0), icon, 0, true)
else
tabButton = BlzCreateFrameByType("BUTTON", "WindowTabButton", windowTable.WindowPane, TasWindow.IconButtonInherit, 0)
local iconframe = BlzCreateFrameByType("BACKDROP", "WindowTabIconButton", tabButton, "", 0)
BlzFrameClearAllPoints(tabButton)
BlzFrameSetAllPoints(iconframe, tabButton)
BlzFrameSetTexture(iconframe, icon, 0, true)
end
BlzFrameSetSize(tabButton, TasWindow.IconButtonSize, TasWindow.IconButtonSize)
return TasWindow.addTab(windowTable, frame, tabButton, doNotStretch, xSize, ySize)
end
function TasWindow.addTab(windowTable, frame, buttonText, doNotStretch, xSize, ySize)
--each Tab is an own Table
local windowTabTable = {}
if not windowTable.TabPos then windowTable.TabPos = TasWindow.TabPos.Default end
if not windowTable.Tabs then
--this is the first time this window gets tabs
windowTable.Tabs = {}
windowTable.TabActive = windowTabTable
end
--add the new TabTable into the array of windowTable
table.insert(windowTable.Tabs, windowTabTable)
local tabButton
if not buttonText or type(buttonText) == "string" then
if TasWindow.HasToc then
tabButton = BlzCreateFrame("WindowTabButton", windowTable.WindowPane, 0, 0)
else
tabButton = BlzCreateFrameByType("GLUETEXTBUTTON", "WindowTabButton", windowTable.WindowPane, "ScriptDialogButton", 0)
end
BlzFrameSetSize(tabButton, 0.06, 0.025)
if buttonText then
BlzFrameSetText(tabButton, buttonText)
else
BlzFrameSetText(tabButton, #windowTable.Tabs)
end
else
tabButton = buttonText
end
TasWindow[tabButton] = windowTabTable
TasWindow[windowTabTable] = windowTable
--fit the given frame into the Content Pane?
if not doNotStretch then
BlzFrameSetAllPoints(frame, windowTable.WindowPane)
BlzFrameSetSize(frame, BlzFrameGetWidth(windowTable.WindowPane), BlzFrameGetHeight(windowTable.WindowPane))
else
--only center it
BlzFrameClearAllPoints(frame)
BlzFrameSetPoint(frame, FRAMEPOINT_CENTER, windowTable.WindowPane, FRAMEPOINT_CENTER, 0, 0)
end
BlzFrameSetParent(frame, windowTable.WindowPane)
windowTabTable.Button = tabButton
windowTabTable.Frame = frame
windowTabTable.SizeX = xSize
windowTabTable.SizeY = ySize
TasButtonAction(tabButton, TasWindow.TabButtonAction)
local usedPos = windowTable.TabPos
local usedPosData = TasWindow.TabPos[usedPos]
--pos the tab button
if #windowTable.Tabs == 1 then
--the first button is located at Top Left of the TasWindow
BlzFrameSetVisible(frame, true)
BlzFrameSetPoint(tabButton, usedPosData[1], windowTable.TasWindow, usedPosData[2], usedPosData[3], usedPosData[4])
--hide the new tab button, there is nothing to choose yet.
BlzFrameSetVisible(windowTable.Tabs[1].Button, false)
TasWindow.showTab(windowTable, windowTabTable)
else
--further ones are located below to the previous one
--this is not the first added one hide it.
if usedPosData[9] then
BlzFrameSetPoint(windowTable.TasWindow, FRAMEPOINT_TOPLEFT, windowTable.WindowHead, FRAMEPOINT_BOTTOMLEFT, 0, 0.001 - BlzFrameGetHeight(tabButton))
end
BlzFrameSetVisible(frame, false)
BlzFrameSetPoint(tabButton, usedPosData[5], windowTable.Tabs[#windowTable.Tabs - 1].Button, usedPosData[6], usedPosData[7], usedPosData[8])
BlzFrameSetVisible(windowTable.Tabs[1].Button, true)
end
return windowTabTable
end
function TasWindow.setTabButtonAction(windowTabTable, actionFunction)
windowTabTable.ShowAction = actionFunction
if TasWindow[windowTabTable].TabActive == windowTabTable then
actionFunction(TasWindow[windowTabTable], windowTabTable)
end
end
function TasWindow.showTab(windowTable, windowTabTable, player)
if player and player ~= GetLocalPlayer() then return end
if windowTable.TabActive then
BlzFrameSetVisible(windowTable.TabActive.Frame, false)
end
if type(windowTabTable) == "number" then
windowTabTable = windowTable.Tabs[windowTabTable]
end
BlzFrameSetVisible(windowTabTable.Frame, true)
windowTable.TabActive = windowTabTable
if windowTabTable.SizeX then
TasWindow.setSize(windowTable, windowTabTable.SizeX + 0.02, windowTabTable.SizeY + 0.02, true)
BlzFrameSetSize(windowTabTable.Frame, BlzFrameGetWidth(windowTable.WindowPane), BlzFrameGetHeight(windowTable.WindowPane))
else
TasWindow.setSize(windowTable)
end
--custom user action when showing this Tab
if windowTabTable.ShowAction then
windowTabTable.ShowAction(windowTable, windowTabTable)
end
end
--more of an attribute hence CamelCase
function TasWindow.TabButtonAction(button, player)
local windowTable = TasWindow[BlzFrameGetParent(BlzFrameGetParent(button))]
local windowTabTable = TasWindow[button]
if GetLocalPlayer() == player then
TasWindow.showTab(windowTable, windowTabTable)
end
end