Mercurial > wow > inventory
comparison Modules/Summary.lua @ 205:0ea991d9093c
Config and Summary windows are now toggled rather than always shown.
author | Zerotorescue |
---|---|
date | Sat, 05 Feb 2011 19:36:35 +0100 |
parents | 15f22a466596 |
children | 72de51449286 |
comparison
equal
deleted
inserted
replaced
204:4f5e114fe15f | 205:0ea991d9093c |
---|---|
1 local addon = select(2, ...); -- Get a reference to the main addon object | 1 local addon = select(2, ...); -- Get a reference to the main addon object |
2 local mod = addon:NewModule("Summary"); -- register a new module, Summary: resposible for building the summary window | 2 local mod = addon:NewModule("Summary", "AceTimer-3.0"); -- register a new module, Summary: resposible for building the summary window |
3 | 3 |
4 local _G = _G; -- prevent looking up of the global table | 4 local _G = _G; -- prevent looking up of the global table |
5 local sformat, sgsub, supper, mceil, mfloor, tinsert, twipe, tsort = _G.string.format, _G.string.gsub, _G.string.upper, _G.math.ceil, _G.math.floor, _G.table.insert, _G.table.wipe, _G.table.sort; | 5 local sformat, sgsub, supper, mceil, mfloor, tinsert, twipe, tsort = _G.string.format, _G.string.gsub, _G.string.upper, _G.math.ceil, _G.math.floor, _G.table.insert, _G.table.wipe, _G.table.sort; |
6 local pairs, type, select = _G.pairs, _G.type, _G.select; | 6 local pairs, type, select = _G.pairs, _G.type, _G.select; |
7 | 7 |
17 AceGUI = LibStub("AceGUI-3.0"); | 17 AceGUI = LibStub("AceGUI-3.0"); |
18 | 18 |
19 -- Register our own slash commands | 19 -- Register our own slash commands |
20 -- /im summary | 20 -- /im summary |
21 addon:RegisterSlash(function() | 21 addon:RegisterSlash(function() |
22 mod:BuildMain(); | 22 if self:IsFrameOpen() then |
23 mod:Build(); | 23 self:CloseFrame(); |
24 else | |
25 self:Show(); | |
26 end | |
24 end, { "s", "sum", "summary" }, "|Hfunction:InventoriumCommandHandler:summary|h|cff00fff7/im summary|r|h (or /im s) - Show the summary window containing an overview of all items within the groups tracked at this current character."); | 27 end, { "s", "sum", "summary" }, "|Hfunction:InventoriumCommandHandler:summary|h|cff00fff7/im summary|r|h (or /im s) - Show the summary window containing an overview of all items within the groups tracked at this current character."); |
25 | 28 |
26 -- /im reset | 29 -- /im reset |
27 addon:RegisterSlash(function() | 30 addon:RegisterSlash(function() |
28 if mod.frame then | 31 if mod.frame then |
52 local function HideTooltip() | 55 local function HideTooltip() |
53 GameTooltip:Hide(); | 56 GameTooltip:Hide(); |
54 end | 57 end |
55 | 58 |
56 function mod:BuildMain() | 59 function mod:BuildMain() |
57 LibStub("AceConfigDialog-3.0"):Close("InventoriumOptions"); | 60 if not self.frame then |
58 | 61 -- Main Window |
59 self:CloseFrame(); | 62 self.frame = AceGUI:Create("Frame"); |
60 | 63 _G["InventoriumSummary"] = self.frame; -- name the global frame so it can be put in the UISpecialFrames |
61 -- Main Window | 64 self.frame:SetTitle("Inventory Summary"); |
62 mod.frame = AceGUI:Create("Frame"); | 65 self.frame:SetLayout("Fill"); |
63 _G["InventoriumSummary"] = mod.frame; -- name the global frame so it can be put in the UISpecialFrames | 66 self.frame:SetCallback("OnClose", function(widget) |
64 mod.frame:SetTitle("Inventory Summary"); | 67 mod:CancelTimer(self.tmrUpdater, true); |
65 mod.frame:SetLayout("Fill"); | 68 mod:CloseFrame(); |
66 mod.frame:SetCallback("OnClose", function(widget) | 69 end); |
67 mod:CancelTimer(self.tmrUpdater, true); | 70 self.frame:SetWidth(addon.db.profile.defaults.summary.width); |
68 mod:CloseFrame(); | 71 self.frame:SetHeight(addon.db.profile.defaults.summary.height); |
69 end); | 72 self.frame.OnWidthSet = function(_, width) |
70 mod.frame:SetWidth(addon.db.profile.defaults.summary.width); | 73 addon.db.profile.defaults.summary.width = width; |
71 mod.frame:SetHeight(addon.db.profile.defaults.summary.height); | 74 end; |
72 mod.frame.OnWidthSet = function(_, width) | 75 self.frame.OnHeightSet = function(_, height) |
73 addon.db.profile.defaults.summary.width = width; | 76 addon.db.profile.defaults.summary.height = height; |
74 end; | 77 end; |
75 mod.frame.OnHeightSet = function(_, height) | 78 |
76 addon.db.profile.defaults.summary.height = height; | 79 -- Close on escape |
77 end; | 80 tinsert(UISpecialFrames, "InventoriumSummary"); |
78 | 81 |
79 -- Close on escape | 82 -- ScrollFrame child |
80 tinsert(UISpecialFrames, "InventoriumSummary"); | 83 self.scrollFrame = AceGUI:Create("ScrollFrame"); |
81 | 84 self.scrollFrame:SetLayout("Flow"); |
82 -- ScrollFrame child | 85 |
83 mod.scrollFrame = AceGUI:Create("ScrollFrame"); | 86 self.frame:AddChild(self.scrollFrame); |
84 mod.scrollFrame:SetLayout("Flow"); | 87 |
85 | 88 -- Reset items cache |
86 mod.frame:AddChild(mod.scrollFrame); | 89 twipe(itemsCache); |
87 | 90 end |
88 -- Reset items cache | 91 end |
89 twipe(itemsCache); | 92 |
93 function mod:Show() | |
94 -- We don't want any other windows open at this time. | |
95 for name, module in addon:IterateModules() do | |
96 if module.CloseFrame then | |
97 module:CloseFrame(); | |
98 end | |
99 end | |
100 | |
101 self:BuildMain(); | |
102 self:Build(); | |
103 end | |
104 | |
105 function mod:IsFrameOpen() | |
106 return (self.frame and self.frame:IsShown()); | |
90 end | 107 end |
91 | 108 |
92 function mod:CloseFrame() | 109 function mod:CloseFrame() |
93 if mod.frame then | 110 if self:IsFrameOpen() then |
94 mod.frame:Release(); | 111 --self.scrollFrame:Release(); |
95 mod.frame = nil; | 112 --self.scrollFrame = nil; |
113 | |
114 self.frame:Hide(); | |
96 | 115 |
97 -- Stop caching | 116 -- Stop caching |
98 | 117 |
99 -- Stop timer | 118 -- Stop timer |
100 self:CancelTimer(self.tmrUpdater, true); | 119 self:CancelTimer(self.tmrUpdater, true); |
133 return iter | 152 return iter |
134 end | 153 end |
135 | 154 |
136 function mod:Build() | 155 function mod:Build() |
137 local buildStartTime, times = GetTime(), {}; | 156 local buildStartTime, times = GetTime(), {}; |
157 | |
158 self.frame:Show(); | |
138 | 159 |
139 -- We are going to add hunderds of widgets to this container, but don't want it to also cause hunderds of reflows, thus pause reflowing and just do it once when everything is prepared | 160 -- We are going to add hunderds of widgets to this container, but don't want it to also cause hunderds of reflows, thus pause reflowing and just do it once when everything is prepared |
140 -- This appears to be required for each container we wish to pause, so also do this for the contents | 161 -- This appears to be required for each container we wish to pause, so also do this for the contents |
141 mod.scrollFrame:PauseLayout(); | 162 mod.scrollFrame:PauseLayout(); |
142 | 163 |