changeset 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 9cb0bc93ed11
children 4ec321eb0dfe
files Core.lua ItemAuditor.toc Modules/DisplayInvested.lua Modules/Frames.lua Modules/Options.lua Modules/Utils.lua
diffstat 6 files changed, 134 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/Core.lua	Sun Jul 25 12:52:14 2010 -0700
+++ b/Core.lua	Sun Jul 25 15:51:00 2010 -0700
@@ -45,7 +45,7 @@
 	-- /run ItemAuditor.db.profile.show_debug_frame_on_startup = true
 	if self.db.profile.show_debug_frame_on_startup then
 		ItemAuditor_DebugFrame:Show()
-		self:CreateFrames()
+		self:CreateFrame()
 	end
 end
 
--- a/ItemAuditor.toc	Sun Jul 25 12:52:14 2010 -0700
+++ b/ItemAuditor.toc	Sun Jul 25 15:51:00 2010 -0700
@@ -13,6 +13,7 @@
 
 
 Core.lua
+Modules\Frames.lua
 Modules\Utils.lua
 Modules\QuickAuctions.lua
 Modules\Events.lua
--- a/Modules/DisplayInvested.lua	Sun Jul 25 12:52:14 2010 -0700
+++ b/Modules/DisplayInvested.lua	Sun Jul 25 15:51:00 2010 -0700
@@ -9,30 +9,9 @@
 
 local promptFrame = false
 
--- Copied from QuickAuctions
-local function validateMoney(value)
-	local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g"))
-	local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s"))
-	local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c"))
-	
-	if( not gold and not silver and not copper ) then
-		return false;
-		-- return L["Invalid monney format entered, should be \"#g#s#c\", \"25g4s50c\" is 25 gold, 4 silver, 50 copper."]
-	end
-	
-	return true
-end
+local validateMoney = ItemAuditor.validateMoney
+local parseMoney = parseMoney
 
--- Copied from QuickAuctions
-local function parseMoney(value)
-	local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g"))
-	local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s"))
-	local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c"))
-		
-	-- Convert it all into copper
-	return (copper or 0) + ((gold or 0) * COPPER_PER_GOLD) + ((silver or 0) * COPPER_PER_SILVER)
-	
-end
 
 StaticPopupDialogs["ItemAuditor_NewPrice"] = {
 	text = "New price %s %s",
@@ -131,6 +110,9 @@
 	if investedTable == false then
 		local window  = container.frame
 		investedTable = ScrollingTable:CreateST(investedCols, 23, nil, nil, window)
+		
+		
+		
 		investedTable.frame:SetPoint("BOTTOMLEFT",window, 10,10)
 		investedTable.frame:SetPoint("TOP", window, 0, -60)
 		investedTable.frame:SetPoint("RIGHT", window, -10,0)
@@ -174,58 +156,24 @@
 
 	
 	UpdateInvestedData()
+	
+	return investedTable
 end
 
-
-local function switchTab(container, event, group)
-	container:ReleaseChildren()
-	
-	if investedTab then investedTab:Hide() end
-
-	if group == "tab_invested" then
-		ShowInvested(container)
+local function getinvestedColsWidth()
+	local width = 0
+	for i, data in pairs(investedCols) do 
+		width = width + data.width
 	end
+	return width
 end
 
-
-
-displayFrame = false
-local function CreateFrames()
-	if not displayFrame then
-		-- Create the frame container
-		displayFrame = AceGUI:Create("Frame")
-		ItemAuditor:RegisterFrame(displayFrame)
-		local window = displayFrame.frame;
-		-- I have no idea why AceGUI insists on using FULLSCREEN_DIALOG by default.
-		window:SetFrameStrata("MEDIUM")
-		displayFrame:SetTitle("ItemAuditor")
-		displayFrame:SetStatusText("")
-
-		displayFrame:SetLayout("Fill")
-	
-		window:SetHeight(500);
-	
-		local width = 80
-		for i, data in pairs(investedCols) do 
-			width = width + data.width
-		end
-		window:SetWidth(width);
-
-		local tab =  AceGUI:Create("TabGroup")
-		tab:SetLayout("Flow")
-		tab:SetTabs({{text="Invested", value="tab_invested"}})
-		tab:SetCallback("OnGroupSelected", switchTab)
-		tab:SelectTab("tab_invested")
-
-		displayFrame:AddChild(tab)
-	end
-	displayFrame:Show()
+local tabName = 'tab_invested'
+ItemAuditor:RegisterTab("Invested", tabName, getinvestedColsWidth(), ShowInvested)
+function ItemAuditor:DisplayInvested()
+	self:CreateFrame(tabName)
 end
 
-
-
-
-
 function UpdateInvestedData()
 	if investedTable then
 		tableData = {} --reset
@@ -273,14 +221,11 @@
 		end
 		
 		if investedTable.frame:IsShown() then
-			displayFrame:SetStatusText("Total Invested: "..ItemAuditor:FormatMoney(totalInvested))
+			ItemAuditor:UpdateStatusText("Total Invested: "..ItemAuditor:FormatMoney(totalInvested))
 		end
 		
 		investedTable:SetData(tableData, true)
 	end
 end
 
-function ItemAuditor:CreateFrames()
-	CreateFrames()
-end
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Modules/Frames.lua	Sun Jul 25 15:51:00 2010 -0700
@@ -0,0 +1,89 @@
+local addonName, addonTable = ...; 
+local addon = _G[addonName]
+
+local AceGUI = LibStub("AceGUI-3.0")
+
+local tabs = {}
+
+function addon:RegisterTab(text, value, width, callback)
+	tabs[value] = {text=text, callback=callback, width=width}
+end
+
+local displayFrame = false
+local currentContent = false
+local function switchTab(container, event, group)
+	if tabs[group] == nil then
+		error(format("Invaid tab name: %s", tostring(group)))
+	end
+	local cb = tabs[group].callback
+
+	container:ReleaseChildren()
+	
+	if currentContent then
+		currentContent:Hide()
+		if displayFrame then
+			displayFrame:SetStatusText('')
+		end
+	end
+
+	currentContent = cb(container)
+end
+
+
+function addon:CreateFrame(selectedTab)
+	--@debug@
+	-- This is here so I can verify that all of the callbacks and tab switching works.
+	-- The real crafting tab will become its own module.
+	-- addon:RegisterTab('Placeholder Crafting', 'tab_crafting', 400, function() addon:Print('crafting') end)
+	--@end-debug@
+
+	if not displayFrame then
+		-- Create the frame container
+		displayFrame = AceGUI:Create("Frame")
+		ItemAuditor:RegisterFrame(displayFrame)
+		local window = displayFrame.frame;
+		-- I have no idea why AceGUI insists on using FULLSCREEN_DIALOG by default.
+		window:SetFrameStrata("MEDIUM")
+		displayFrame:SetTitle("ItemAuditor")
+		displayFrame:SetStatusText("")
+
+		displayFrame:SetLayout("Fill")
+	
+		window:SetHeight(500);
+	
+		local tabSet = {}
+		for key, data in pairs(tabs) do 
+			tinsert(tabSet, {text=data['text'], value=key})
+			-- Default to the first tab.
+			if not selectedTab then
+				selectedTab = key
+			end
+		end
+		-- Each tab can adjust the width as needed.
+		window:SetWidth(300);
+
+		displayFrame.tab =  AceGUI:Create("TabGroup")
+		displayFrame.tab:SetLayout("Flow")
+		displayFrame.tab:SetTabs(tabSet)
+		displayFrame.tab:SetCallback("OnGroupSelected", switchTab)
+		
+		
+		displayFrame:AddChild(displayFrame.tab)
+	end
+	
+	if not selectedTab then
+		for key in pairs(tabs) do 
+			selectedTab = key
+			break
+		end
+	end
+	
+	displayFrame.tab:SelectTab(selectedTab)
+	displayFrame:Show()
+end
+
+function addon:UpdateStatusText(message)
+	if displayFrame then
+		displayFrame:SetStatusText(message)
+	end
+end
\ No newline at end of file
--- a/Modules/Options.lua	Sun Jul 25 12:52:14 2010 -0700
+++ b/Modules/Options.lua	Sun Jul 25 15:51:00 2010 -0700
@@ -210,7 +210,7 @@
 			type = "execute",
 			name = "invested",
 			desc = "Shows what you have invested in",
-			func = "CreateFrames",
+			func = "DisplayInvested",
 			guiHidden = false,
 		},
 		suspend = {
--- a/Modules/Utils.lua	Sun Jul 25 12:52:14 2010 -0700
+++ b/Modules/Utils.lua	Sun Jul 25 15:51:00 2010 -0700
@@ -39,6 +39,31 @@
 	return format("%s%s%s%s", prefix, gold, silver, copper)
 end
 
+-- Copied from QuickAuctions
+function ItemAuditor.validateMoney(value)
+	local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g"))
+	local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s"))
+	local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c"))
+	
+	if( not gold and not silver and not copper ) then
+		return false;
+		-- return L["Invalid monney format entered, should be \"#g#s#c\", \"25g4s50c\" is 25 gold, 4 silver, 50 copper."]
+	end
+	
+	return true
+end
+
+-- Copied from QuickAuctions
+function ItemAuditor.parseMoney(value)
+	local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g"))
+	local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s"))
+	local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c"))
+		
+	-- Convert it all into copper
+	return (copper or 0) + ((gold or 0) * COPPER_PER_GOLD) + ((silver or 0) * COPPER_PER_SILVER)
+	
+end
+
 -- This is only here to make sure this doesn't blow up if ReplaceItemCache is never called
 local item_db = {}