Mercurial > wow > itemauditor
comparison Modules/Frames.lua @ 58:bdf3aba93aa9
Refactored the way the window for /ia invested works so I can add more tabs.
| author | Asa Ayers <Asa.Ayers@Gmail.com> |
|---|---|
| date | Sun, 25 Jul 2010 15:51:00 -0700 |
| parents | |
| children | 4ec321eb0dfe |
comparison
equal
deleted
inserted
replaced
| 57:9cb0bc93ed11 | 58:bdf3aba93aa9 |
|---|---|
| 1 local addonName, addonTable = ...; | |
| 2 local addon = _G[addonName] | |
| 3 | |
| 4 local AceGUI = LibStub("AceGUI-3.0") | |
| 5 | |
| 6 local tabs = {} | |
| 7 | |
| 8 function addon:RegisterTab(text, value, width, callback) | |
| 9 tabs[value] = {text=text, callback=callback, width=width} | |
| 10 end | |
| 11 | |
| 12 local displayFrame = false | |
| 13 local currentContent = false | |
| 14 local function switchTab(container, event, group) | |
| 15 if tabs[group] == nil then | |
| 16 error(format("Invaid tab name: %s", tostring(group))) | |
| 17 end | |
| 18 local cb = tabs[group].callback | |
| 19 | |
| 20 container:ReleaseChildren() | |
| 21 | |
| 22 if currentContent then | |
| 23 currentContent:Hide() | |
| 24 if displayFrame then | |
| 25 displayFrame:SetStatusText('') | |
| 26 end | |
| 27 end | |
| 28 | |
| 29 currentContent = cb(container) | |
| 30 end | |
| 31 | |
| 32 | |
| 33 function addon:CreateFrame(selectedTab) | |
| 34 --@debug@ | |
| 35 -- This is here so I can verify that all of the callbacks and tab switching works. | |
| 36 -- The real crafting tab will become its own module. | |
| 37 -- addon:RegisterTab('Placeholder Crafting', 'tab_crafting', 400, function() addon:Print('crafting') end) | |
| 38 --@end-debug@ | |
| 39 | |
| 40 if not displayFrame then | |
| 41 -- Create the frame container | |
| 42 displayFrame = AceGUI:Create("Frame") | |
| 43 ItemAuditor:RegisterFrame(displayFrame) | |
| 44 local window = displayFrame.frame; | |
| 45 -- I have no idea why AceGUI insists on using FULLSCREEN_DIALOG by default. | |
| 46 window:SetFrameStrata("MEDIUM") | |
| 47 displayFrame:SetTitle("ItemAuditor") | |
| 48 displayFrame:SetStatusText("") | |
| 49 | |
| 50 displayFrame:SetLayout("Fill") | |
| 51 | |
| 52 window:SetHeight(500); | |
| 53 | |
| 54 local tabSet = {} | |
| 55 for key, data in pairs(tabs) do | |
| 56 tinsert(tabSet, {text=data['text'], value=key}) | |
| 57 -- Default to the first tab. | |
| 58 if not selectedTab then | |
| 59 selectedTab = key | |
| 60 end | |
| 61 end | |
| 62 -- Each tab can adjust the width as needed. | |
| 63 window:SetWidth(300); | |
| 64 | |
| 65 displayFrame.tab = AceGUI:Create("TabGroup") | |
| 66 displayFrame.tab:SetLayout("Flow") | |
| 67 displayFrame.tab:SetTabs(tabSet) | |
| 68 displayFrame.tab:SetCallback("OnGroupSelected", switchTab) | |
| 69 | |
| 70 | |
| 71 displayFrame:AddChild(displayFrame.tab) | |
| 72 end | |
| 73 | |
| 74 if not selectedTab then | |
| 75 for key in pairs(tabs) do | |
| 76 selectedTab = key | |
| 77 break | |
| 78 end | |
| 79 end | |
| 80 | |
| 81 displayFrame.tab:SelectTab(selectedTab) | |
| 82 displayFrame:Show() | |
| 83 end | |
| 84 | |
| 85 function addon:UpdateStatusText(message) | |
| 86 if displayFrame then | |
| 87 displayFrame:SetStatusText(message) | |
| 88 end | |
| 89 end |
