Mercurial > wow > inventory
comparison Frames.lua @ 110:67bd5057ecb7
Implemented vendor restocking with the mover. Comitting so I can always review this working version, but I?ll be disabling all part of it as it is not going to work properly without seriously compromising the code structure.
Debug messages are now appended with ?Inventorium? (my MailOpener addon was making stuff difficult).
Now properly removing the refill window from the displayed static popup windows list so new popups won?t be aligned at odd locations.
Changed ?CreateMoverFrame? to not contain any scenario-specific info. All settings can be set with SetFrameSettings.
Items that belong to speciality bags are now put there. Other items now ignore spaciality bags.
Implemented test code for mailbox refill support. It has been disabled due to some issues but may be introduced later.
The guild withdrawal limit is now taken into consideration.
Queue is now reset before scanning again.
author | Zerotorescue |
---|---|
date | Fri, 14 Jan 2011 23:25:05 +0100 |
parents | d3fbb5676a5e |
children | 9765bc3b3d6b |
comparison
equal
deleted
inserted
replaced
109:3bbad0429d87 | 110:67bd5057ecb7 |
---|---|
23 | 23 |
24 local function HideTooltip() | 24 local function HideTooltip() |
25 GameTooltip:Hide(); | 25 GameTooltip:Hide(); |
26 end | 26 end |
27 | 27 |
28 function addon:CreateMoverFrame(onAccept, onCancel) | 28 function addon:CreateMoverFrame() |
29 local frameWidth = 400; | 29 local frameWidth = 400; |
30 | 30 |
31 -- Main window | 31 -- Main window |
32 local frame = CreateFrame("Frame", "InventoriumItemMover", UIParent); | 32 local frame = CreateFrame("Frame", "InventoriumItemMover", UIParent); |
33 -- Hide by default | 33 -- Hide by default |
76 | 76 |
77 this:AdjustScrollTableRows(); | 77 this:AdjustScrollTableRows(); |
78 | 78 |
79 PlaySound("OrcExploration"); | 79 PlaySound("OrcExploration"); |
80 end); | 80 end); |
81 frame:SetScript("OnHide", function(this) | |
82 StaticPopup_CollapseTable(this); | |
83 end); | |
81 | 84 |
82 -- Title (AceGUI frame-widget-title used as example) | 85 -- Title (AceGUI frame-widget-title used as example) |
83 local titleBackground = frame:CreateTexture(nil, "OVERLAY"); | 86 local titleBackground = frame:CreateTexture(nil, "OVERLAY"); |
84 titleBackground:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header"); | 87 titleBackground:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header"); |
85 titleBackground:SetTexCoord(0.31, 0.67, 0, 0.63); | 88 titleBackground:SetTexCoord(0.31, 0.67, 0, 0.63); |
107 frmTitle:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end); | 110 frmTitle:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end); |
108 frmTitle:SetAllPoints(titleBackground); | 111 frmTitle:SetAllPoints(titleBackground); |
109 | 112 |
110 local lblTitle = frmTitle:CreateFontString(nil, "OVERLAY", "GameFontNormal"); | 113 local lblTitle = frmTitle:CreateFontString(nil, "OVERLAY", "GameFontNormal"); |
111 lblTitle:SetPoint("TOP", titleBackground, "TOP", 0, -14); | 114 lblTitle:SetPoint("TOP", titleBackground, "TOP", 0, -14); |
112 lblTitle:SetText("Inventorium Bank Refill"); | 115 |
116 frame.lblTitle = lblTitle; | |
113 | 117 |
114 -- Resizer (vertical only) | 118 -- Resizer (vertical only) |
115 local frmResizer = CreateFrame("Frame", nil, frame); | 119 local frmResizer = CreateFrame("Frame", nil, frame); |
116 frmResizer:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 0, -10); | 120 frmResizer:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 0, -10); |
117 frmResizer:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, -10); | 121 frmResizer:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, -10); |
124 local lblDescription = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal"); | 128 local lblDescription = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal"); |
125 lblDescription:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -27); | 129 lblDescription:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -27); |
126 lblDescription:SetWidth(frameWidth - 15 - 15); -- 10 margin left & 10 margin right | 130 lblDescription:SetWidth(frameWidth - 15 - 15); -- 10 margin left & 10 margin right |
127 lblDescription:SetJustifyH("LEFT"); | 131 lblDescription:SetJustifyH("LEFT"); |
128 lblDescription:SetJustifyV("TOP"); | 132 lblDescription:SetJustifyV("TOP"); |
129 lblDescription:SetText("The items listed below can be refilled from this location, do you wish to move them to your bags?"); | |
130 | 133 |
131 frame.lblDescription = lblDescription; | 134 frame.lblDescription = lblDescription; |
132 | 135 |
133 -- Buttons | 136 -- Buttons |
134 -- Move (proceed) | 137 -- Move (proceed) |
135 local btnMove = CreateFrame("Button", "$parentProceed", frame, "UIPanelButtonTemplate"); | 138 local btnMove = CreateFrame("Button", "$parentProceed", frame, "UIPanelButtonTemplate"); |
136 btnMove:SetHeight(21); | 139 btnMove:SetHeight(21); |
137 btnMove:SetWidth(125); | 140 btnMove:SetWidth(125); |
138 btnMove:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 15, 11); | 141 btnMove:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 15, 11); |
139 btnMove:SetText("Move Items"); | 142 btnMove:SetText("Move Items"); |
140 btnMove:SetScript("OnClick", onAccept); | 143 btnMove:SetScript("OnClick", function(this) this.OnClick(this); end); |
141 btnMove:SetScript("OnEnter", ShowTooltip); | 144 btnMove:SetScript("OnEnter", ShowTooltip); |
142 btnMove:SetScript("OnLeave", HideTooltip); | 145 btnMove:SetScript("OnLeave", HideTooltip); |
143 btnMove.tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Move Items"); | |
144 btnMove.tooltip = (not addon.db.profile.defaults.hideHelp and "Start moving these items from the bank."); | |
145 | 146 |
146 frame.btnMove = btnMove; | 147 frame.btnMove = btnMove; |
147 | 148 |
148 -- Cancel | 149 -- Cancel |
149 local btnCancel = CreateFrame("Button", "$parentCancel", frame, "UIPanelButtonTemplate"); | 150 local btnCancel = CreateFrame("Button", "$parentCancel", frame, "UIPanelButtonTemplate"); |
150 btnCancel:SetHeight(21); | 151 btnCancel:SetHeight(21); |
151 btnCancel:SetWidth(125); | 152 btnCancel:SetWidth(125); |
152 btnCancel:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 11); | 153 btnCancel:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 11); |
153 btnCancel:SetText("Cancel"); | 154 btnCancel:SetScript("OnClick", function(this) this.OnClick(this); end); |
154 btnCancel:SetScript("OnClick", onCancel); | |
155 btnCancel:SetScript("OnEnter", ShowTooltip); | 155 btnCancel:SetScript("OnEnter", ShowTooltip); |
156 btnCancel:SetScript("OnLeave", HideTooltip); | 156 btnCancel:SetScript("OnLeave", HideTooltip); |
157 btnCancel.tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Cancel"); | |
158 btnCancel.tooltip = (not addon.db.profile.defaults.hideHelp and "Do not move anything and close the window."); | |
159 | 157 |
160 frame.btnCancel = btnCancel; | 158 frame.btnCancel = btnCancel; |
161 | 159 |
162 -- Because the scrolling table code-behind will change this element's height, we can't rely on that. Make a dummy frame which we can measure | 160 -- Because the scrolling table code-behind will change this element's height, we can't rely on that. Make a dummy frame which we can measure |
163 local frmMeasureDummy = CreateFrame("Frame", nil, frame); | 161 local frmMeasureDummy = CreateFrame("Frame", nil, frame); |
166 frmMeasureDummy:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35); | 164 frmMeasureDummy:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35); |
167 | 165 |
168 frame.frmMeasureDummy = frmMeasureDummy; | 166 frame.frmMeasureDummy = frmMeasureDummy; |
169 | 167 |
170 -- Scrolling table with a list of items to be moved | 168 -- Scrolling table with a list of items to be moved |
171 local scrollTableWidth = ( frame.frmMeasureDummy:GetWidth() - 30 ); -- adjust width by the scrollbar size | |
172 local headers = { | |
173 { | |
174 ["name"] = "Item", | |
175 ["width"] = (scrollTableWidth * .60), | |
176 ["defaultsort"] = "asc", | |
177 ["comparesort"] = function(this, aRow, bRow, column) | |
178 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.id); | |
179 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.id); | |
180 local template = "%d%s"; | |
181 aName = template:format((10 - (aRarity or 10)), (aName or ""):lower()); | |
182 bName = template:format((10 - (bRarity or 10)), (bName or ""):lower()); | |
183 | |
184 if this.cols[column].sort == "dsc" then | |
185 return aName > bName; | |
186 else | |
187 return aName < bName; | |
188 end | |
189 end, | |
190 ["sort"] = "asc", -- when the data is set, use this column so sort the default data | |
191 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"), | |
192 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by item quality then item name."), | |
193 }, | |
194 { | |
195 ["name"] = "Moving", | |
196 ["width"] = (scrollTableWidth * .15), | |
197 ["align"] = "RIGHT", | |
198 ["defaultsort"] = "dsc", | |
199 ["sortnext"] = 1, | |
200 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Moving"), | |
201 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the amount of movable items."), | |
202 }, | |
203 { | |
204 ["name"] = "Available", | |
205 ["width"] = (scrollTableWidth * .25), | |
206 ["align"] = "RIGHT", | |
207 ["defaultsort"] = "dsc", | |
208 ["sortnext"] = 1, | |
209 ["comparesort"] = function(this, aRow, bRow, column) | |
210 local aAvailablePercent = (this:GetRow(aRow).rowData.available / this:GetRow(aRow).rowData.missing); | |
211 local bAvailablePercent = (this:GetRow(bRow).rowData.available / this:GetRow(bRow).rowData.missing); | |
212 | |
213 if this.cols[column].sort == "dsc" then | |
214 return aAvailablePercent > bAvailablePercent; | |
215 else | |
216 return aAvailablePercent < bAvailablePercent; | |
217 end | |
218 end, | |
219 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"), | |
220 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the availibility percentage."), | |
221 }, | |
222 }; | |
223 | |
224 local ScrollingTable = LibStub("ScrollingTable"); | 169 local ScrollingTable = LibStub("ScrollingTable"); |
225 local table = ScrollingTable:CreateST(headers, 3, 15, nil, frame); | 170 local table = ScrollingTable:CreateST({}, 4, 15, nil, frame); -- inserting a dummy cols, real cols to be set in SetFrameSettings |
171 table.frame:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -18); | |
172 table.frame:SetPoint("LEFT", frame, "LEFT", 15, 0); | |
173 table.frame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35); | |
226 -- When moving over a row, provide a tooltip for the item | 174 -- When moving over a row, provide a tooltip for the item |
227 table:RegisterEvents({ | 175 table:RegisterEvents({ |
228 ["OnEnter"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) | 176 ["OnEnter"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) |
229 if row and realrow then | 177 if row and realrow then |
230 -- Data row | 178 -- Data row |
254 HideTooltip(); | 202 HideTooltip(); |
255 end, | 203 end, |
256 }); | 204 }); |
257 | 205 |
258 frame.scrollTable = table; | 206 frame.scrollTable = table; |
259 table.frame:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -18); | 207 |
260 table.frame:SetPoint("LEFT", frame, "LEFT", 15, 0); | |
261 table.frame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35); | |
262 | |
263 -- Change the amount of displayed rows based on the size of the frame | 208 -- Change the amount of displayed rows based on the size of the frame |
264 frame.AdjustScrollTableRows = function(this) | 209 frame.AdjustScrollTableRows = function(this) |
265 local newRows = math.floor(( this.frmMeasureDummy:GetHeight() - 5 ) / 15); | 210 local newRows = math.floor(( this.frmMeasureDummy:GetHeight() - 5 ) / 15); |
266 newRows = (newRows < 3 and 3) or newRows; | 211 newRows = (newRows < 4 and 4) or newRows; |
267 | 212 |
268 this.scrollTable:SetDisplayRows(newRows, 15); | 213 this.scrollTable:SetDisplayRows(newRows, 15); |
269 end; | 214 end; |
270 frame:SetScript("OnSizeChanged", frame.AdjustScrollTableRows); | 215 frame:SetScript("OnSizeChanged", frame.AdjustScrollTableRows); |
271 end | 216 end |
273 function addon:SetMoverFrameData(data) | 218 function addon:SetMoverFrameData(data) |
274 InventoriumItemMover.scrollTable:SetData(data); | 219 InventoriumItemMover.scrollTable:SetData(data); |
275 | 220 |
276 InventoriumItemMover:Show(); | 221 InventoriumItemMover:Show(); |
277 end | 222 end |
223 | |
224 function addon:SetFrameSettings(title, description, proceed, cancel, headers) | |
225 local frame = InventoriumItemMover; | |
226 | |
227 frame.lblTitle:SetText(title); | |
228 | |
229 frame.lblDescription:SetText(description); | |
230 | |
231 frame.btnMove:SetText(proceed.text); | |
232 frame.btnMove.tooltipTitle = proceed.tooltipTitle; | |
233 frame.btnMove.tooltip = proceed.tooltip; | |
234 frame.btnMove.OnClick = proceed.onClick; | |
235 | |
236 frame.btnCancel:SetText(cancel.text); | |
237 frame.btnCancel.tooltipTitle = cancel.tooltipTitle; | |
238 frame.btnCancel.tooltip = cancel.tooltip; | |
239 frame.btnCancel.OnClick = cancel.onClick; | |
240 | |
241 frame.scrollTable:SetDisplayCols(headers); | |
242 end |