yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: AMR TabGroup Container yellowfive@57: Container that uses tabs on top to switch between groups. yellowfive@57: This is adapted from AceGUIContainer-TabGroup, but has a custom look. yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local Type, Version = "AmrUiTabGroup", 1 yellowfive@57: local AceGUI = LibStub and LibStub("AceGUI-3.0", true) yellowfive@57: if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end yellowfive@57: yellowfive@57: local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot") yellowfive@57: yellowfive@57: -- Lua APIs yellowfive@57: local pairs, ipairs, assert, type, wipe = pairs, ipairs, assert, type, wipe yellowfive@57: yellowfive@57: -- WoW APIs yellowfive@57: local PlaySound = PlaySound yellowfive@57: local CreateFrame, UIParent = CreateFrame, UIParent yellowfive@57: local _G = _G yellowfive@57: yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Support functions yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: yellowfive@57: local function tabSetSelected(frame, selected) yellowfive@57: frame.selected = selected yellowfive@57: end yellowfive@57: yellowfive@57: local function tabSetDisabled(frame, disabled) yellowfive@57: frame.disabled = disabled yellowfive@57: end yellowfive@57: yellowfive@57: local function buildTabsOnUpdate(frame) yellowfive@57: local self = frame.obj yellowfive@57: self:BuildTabs() yellowfive@57: frame:SetScript("OnUpdate", nil) yellowfive@57: end yellowfive@57: yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Scripts yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local function tabOnClick(frame) yellowfive@57: if not (frame.selected or frame.disabled) then yellowfive@57: PlaySound("igCharacterInfoTab") yellowfive@57: frame.obj:SelectTab(frame.value) yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Methods yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local methods = { yellowfive@57: ["OnAcquire"] = function(self) yellowfive@57: self.tabSelector:Hide() yellowfive@57: self.frame:ClearAllPoints() yellowfive@57: end, yellowfive@57: yellowfive@57: ["OnRelease"] = function(self) yellowfive@57: self.status = nil yellowfive@57: for k in pairs(self.localstatus) do yellowfive@57: self.localstatus[k] = nil yellowfive@57: end yellowfive@57: self.tablist = nil yellowfive@57: for _, tab in pairs(self.tabs) do yellowfive@57: tab:Hide() yellowfive@57: end yellowfive@57: self.tabSelector:Hide() yellowfive@57: end, yellowfive@57: yellowfive@57: ["CreateTab"] = function(self, id, style) yellowfive@57: local tabname = ("AmrUiTabGroup%dTab%d"):format(self.num, id) yellowfive@57: yellowfive@57: local tab = CreateFrame("Button", tabname, self.border) yellowfive@57: tab.obj = self yellowfive@57: tab.id = id yellowfive@57: yellowfive@57: if style == "bold" then yellowfive@57: tab:SetNormalFontObject(Amr.CreateFont("Regular", 24, Amr.Colors.TextHeaderDisabled)) yellowfive@57: tab:SetHighlightFontObject(Amr.CreateFont("Regular", 24, Amr.Colors.TextHover)) yellowfive@57: else yellowfive@57: tab:SetNormalFontObject(Amr.CreateFont("Regular", 28, Amr.Colors.Text)) yellowfive@57: tab:SetHighlightFontObject(Amr.CreateFont("Regular", 28, Amr.Colors.TextHover)) yellowfive@57: end yellowfive@57: yellowfive@57: tab:SetScript("OnClick", tabOnClick) yellowfive@57: yellowfive@57: tab.SetSelected = tabSetSelected yellowfive@57: tab.SetDisabled = tabSetDisabled yellowfive@57: yellowfive@57: return tab yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetStatusTable"] = function(self, status) yellowfive@57: assert(type(status) == "table") yellowfive@57: self.status = status yellowfive@57: end, yellowfive@57: yellowfive@57: ["SelectTab"] = function(self, value) yellowfive@57: local status = self.status or self.localstatus yellowfive@57: yellowfive@57: self.tabSelector:Hide() yellowfive@57: yellowfive@57: local found yellowfive@57: for i, v in ipairs(self.tabs) do yellowfive@57: if v.value == value then yellowfive@57: v:SetSelected(true) yellowfive@57: found = true yellowfive@57: yellowfive@57: -- show the tab selector under the proper tab yellowfive@57: if v.style == "underline" then yellowfive@57: self.tabSelector:SetWidth(v:GetWidth()) yellowfive@57: self.tabSelector:ClearAllPoints() yellowfive@57: self.tabSelector:SetPoint("TOPLEFT", v, "BOTTOMLEFT", 0, -2) yellowfive@57: self.tabSelector:Show() yellowfive@57: v:SetNormalFontObject(Amr.CreateFont("Regular", 28, Amr.Colors.Text)) yellowfive@57: v:SetHighlightFontObject(Amr.CreateFont("Regular", 28, Amr.Colors.Text)) yellowfive@57: elseif v.style == "bold" then yellowfive@57: v:SetNormalFontObject(Amr.CreateFont("Bold", 28, Amr.Colors.TextHeaderActive)) yellowfive@57: v:SetHighlightFontObject(Amr.CreateFont("Bold", 28, Amr.Colors.TextHeaderActive)) yellowfive@57: end yellowfive@57: else yellowfive@57: v:SetSelected(false) yellowfive@57: if v.style == "bold" then yellowfive@57: v:SetNormalFontObject(Amr.CreateFont("Regular", 24, Amr.Colors.TextHeaderDisabled)) yellowfive@57: v:SetHighlightFontObject(Amr.CreateFont("Regular", 24, Amr.Colors.TextHover)) yellowfive@57: else yellowfive@57: v:SetNormalFontObject(Amr.CreateFont("Regular", 28, Amr.Colors.Text)) yellowfive@57: v:SetHighlightFontObject(Amr.CreateFont("Regular", 28, Amr.Colors.TextHover)) yellowfive@57: end yellowfive@57: end yellowfive@57: end yellowfive@57: status.selected = value yellowfive@57: yellowfive@57: -- call this to reposition after style change yellowfive@57: self:BuildTabs() yellowfive@57: yellowfive@57: if found then yellowfive@57: self:Fire("OnGroupSelected",value) yellowfive@57: end yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetTabs"] = function(self, tabs) yellowfive@57: self.tablist = tabs yellowfive@57: self:BuildTabs() yellowfive@57: end, yellowfive@57: yellowfive@57: ["BuildTabs"] = function(self) yellowfive@57: local status = self.status or self.localstatus yellowfive@57: local tablist = self.tablist yellowfive@57: local tabs = self.tabs yellowfive@57: yellowfive@57: if not tablist then return end yellowfive@57: yellowfive@57: local first = true yellowfive@57: for i, v in ipairs(tablist) do yellowfive@57: local tab = tabs[i] yellowfive@57: if not tab then yellowfive@57: tab = self:CreateTab(i) yellowfive@57: tabs[i] = tab yellowfive@57: end yellowfive@57: yellowfive@57: local padding = 20 yellowfive@57: if v.style == "bold" then padding = 0 end yellowfive@57: yellowfive@57: tab:Show() yellowfive@57: tab:SetText(v.text) yellowfive@57: tab:SetWidth(tab:GetTextWidth() + padding) yellowfive@57: tab:SetHeight(tab:GetTextHeight()) yellowfive@57: tab:SetDisabled(v.disabled) yellowfive@57: tab.value = v.value yellowfive@57: tab.style = v.style or "underline" yellowfive@57: yellowfive@57: tab:ClearAllPoints() yellowfive@57: if first then yellowfive@57: local firstOffset = 0 yellowfive@57: if tab.style == "bold" then firstOffset = 4 end yellowfive@57: tab:SetPoint("BOTTOMLEFT", self.border, "TOPLEFT", firstOffset, 8) yellowfive@57: first = false yellowfive@57: else yellowfive@57: tab:SetPoint("LEFT", tabs[i - 1], "RIGHT", 30, 0) yellowfive@57: end yellowfive@57: end yellowfive@57: end, yellowfive@57: yellowfive@57: ["OnWidthSet"] = function(self, width) yellowfive@57: local content = self.content yellowfive@57: local contentwidth = width - 60 yellowfive@57: if contentwidth < 0 then yellowfive@57: contentwidth = 0 yellowfive@57: end yellowfive@57: content:SetWidth(contentwidth) yellowfive@57: content.width = contentwidth yellowfive@57: self:BuildTabs(self) yellowfive@57: self.frame:SetScript("OnUpdate", buildTabsOnUpdate) yellowfive@57: end, yellowfive@57: yellowfive@57: ["OnHeightSet"] = function(self, height) yellowfive@57: local content = self.content yellowfive@57: local contentheight = height - (self.borderoffset + 23) yellowfive@57: if contentheight < 0 then yellowfive@57: contentheight = 0 yellowfive@57: end yellowfive@57: content:SetHeight(contentheight) yellowfive@57: content.height = contentheight yellowfive@57: end, yellowfive@57: yellowfive@57: ["LayoutFinished"] = function(self, width, height) yellowfive@57: if self.noAutoHeight then return end yellowfive@57: self:SetHeight((height or 0) + (self.borderoffset + 23)) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetVisible"] = function(self, visible) yellowfive@57: if visible then yellowfive@57: self.frame:Show() yellowfive@57: else yellowfive@57: self.frame:Hide() yellowfive@57: end yellowfive@57: end yellowfive@57: } yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Constructor yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local function Constructor() yellowfive@57: local num = AceGUI:GetNextWidgetNum(Type) yellowfive@57: local frame = CreateFrame("Frame",nil,UIParent) yellowfive@57: frame:SetHeight(100) yellowfive@57: frame:SetWidth(100) yellowfive@57: frame:SetFrameStrata("FULLSCREEN_DIALOG") yellowfive@57: yellowfive@57: local border = CreateFrame("Frame", nil, frame) yellowfive@57: local borderoffset = 30 yellowfive@57: border:SetPoint("TOPLEFT", 0, -borderoffset) yellowfive@57: border:SetPoint("BOTTOMRIGHT", 0, 3) yellowfive@57: yellowfive@57: local line = border:CreateTexture(nil, "ARTWORK") yellowfive@57: line:Hide() yellowfive@57: line:SetTexture(1, 1, 1, 1) yellowfive@57: line:SetHeight(4) yellowfive@57: yellowfive@57: local content = CreateFrame("Frame", nil, border) yellowfive@57: content:SetPoint("TOPLEFT", 0, 0) yellowfive@57: content:SetPoint("BOTTOMRIGHT", 0, 0) yellowfive@57: yellowfive@57: local widget = { yellowfive@57: num = num, yellowfive@57: frame = frame, yellowfive@57: localstatus = {}, yellowfive@57: alignoffset = 18, yellowfive@57: border = border, yellowfive@57: borderoffset = borderoffset, yellowfive@57: tabs = {}, yellowfive@57: tabSelector = line, yellowfive@57: content = content, yellowfive@57: type = Type yellowfive@57: } yellowfive@57: for method, func in pairs(methods) do yellowfive@57: widget[method] = func yellowfive@57: end yellowfive@57: yellowfive@57: return AceGUI:RegisterAsContainer(widget) yellowfive@57: end yellowfive@57: yellowfive@57: AceGUI:RegisterWidgetType(Type, Constructor, Version)