Mercurial > wow > inventory
comparison Frames.lua @ 101:6ae44d372360
The confirmation window when refilling from the (guild) bank is enabled can now be skipped at the general config. It defaults to false.
Added a window displaying a list of movable items when at least one is available at the (guild) bank.
Resetting the queue when closing the storage.
author | Zerotorescue |
---|---|
date | Tue, 11 Jan 2011 19:48:35 +0100 |
parents | |
children | 8502f02bf543 |
comparison
equal
deleted
inserted
replaced
100:dbb239fcc91b | 101:6ae44d372360 |
---|---|
1 local addon = select(2, ...); | |
2 | |
3 local function ShowTooltip(self) | |
4 -- If this function is called from a widget, self is the widget and self.frame the actual frame | |
5 local this = self.frame or self; | |
6 | |
7 GameTooltip:SetOwner(this, "ANCHOR_NONE"); | |
8 if this.tooltipLocation and this.tooltipLocation == "TOP" then | |
9 GameTooltip:SetPoint("TOP", this, "TOP"); | |
10 else | |
11 GameTooltip:SetPoint("BOTTOM", this, "TOP"); | |
12 end | |
13 GameTooltip:SetText(this.tooltipTitle, 1, .82, 0, 1); | |
14 | |
15 if type(this.tooltip) == "string" then | |
16 GameTooltip:AddLine(this.tooltip, 1, 1, 1, 1); | |
17 end | |
18 | |
19 GameTooltip:Show(); | |
20 end | |
21 | |
22 local function HideTooltip() | |
23 GameTooltip:Hide(); | |
24 end | |
25 | |
26 function addon:CreateMoverFrame(onAccept, onCancel) | |
27 local frameWidth = 400; | |
28 | |
29 -- Main window | |
30 local frame = CreateFrame("Frame", "InventoriumItemMover", UIParent); | |
31 -- Hide by default | |
32 frame:Hide(); | |
33 -- Center the frame (will be adjusted later) | |
34 frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0); | |
35 -- Put in front of other windows | |
36 frame:SetFrameStrata("FULLSCREEN_DIALOG"); | |
37 frame:SetToplevel(true); | |
38 -- Give it a size | |
39 frame:SetWidth(frameWidth); | |
40 frame:SetHeight(175); | |
41 -- Background | |
42 frame:SetBackdrop({ | |
43 bgFile = "Interface\\ChatFrame\\ChatFrameBackground", | |
44 edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", | |
45 edgeSize = 13, | |
46 insets = { | |
47 left = 5, | |
48 right = 5, | |
49 top = 5, | |
50 bottom = 5, | |
51 }, | |
52 }); | |
53 frame:SetBackdropColor(0, 0, 0, .8); | |
54 -- Mouse functions | |
55 frame:EnableMouse(); | |
56 frame:SetMovable(true); | |
57 frame:SetResizable(true); | |
58 frame:SetMinResize(300, 175); | |
59 -- Set event handlers | |
60 frame:SetScript("OnMouseUp", function(this) this:StopMovingOrSizing(); end); | |
61 frame:SetScript("OnShow", function(this) | |
62 -- We wish to display our box at a similar position as the default interface's static popups, so we literally copied the code for these popups | |
63 local lastFrame = StaticPopup_DisplayedFrames[#StaticPopup_DisplayedFrames]; | |
64 if lastFrame then | |
65 this:SetPoint("TOP", lastFrame, "BOTTOM", 0, 0); | |
66 else | |
67 this:SetPoint("TOP", UIParent, "TOP", 0, -135); | |
68 end | |
69 | |
70 -- Position other static popups below this | |
71 tinsert(StaticPopup_DisplayedFrames, this); | |
72 | |
73 this:AdjustScrollTableRows(); | |
74 | |
75 PlaySound("OrcExploration"); | |
76 end); | |
77 | |
78 -- Title (AceGUI frame-widget-title used as example) | |
79 local titleBackground = frame:CreateTexture(nil, "OVERLAY"); | |
80 titleBackground:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header"); | |
81 titleBackground:SetTexCoord(0.31, 0.67, 0, 0.63); | |
82 titleBackground:SetPoint("TOP", 0, 12); | |
83 titleBackground:SetWidth(150); | |
84 titleBackground:SetHeight(40); | |
85 | |
86 local titleBackgroundLeft = frame:CreateTexture(nil, "OVERLAY"); | |
87 titleBackgroundLeft:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header"); | |
88 titleBackgroundLeft:SetTexCoord(0.21, 0.31, 0, 0.63); | |
89 titleBackgroundLeft:SetPoint("RIGHT", titleBackground, "LEFT"); | |
90 titleBackgroundLeft:SetWidth(30); | |
91 titleBackgroundLeft:SetHeight(40); | |
92 | |
93 local titleBackgroundRight = frame:CreateTexture(nil, "OVERLAY"); | |
94 titleBackgroundRight:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header"); | |
95 titleBackgroundRight:SetTexCoord(0.67, 0.77, 0, 0.63); | |
96 titleBackgroundRight:SetPoint("LEFT", titleBackground, "RIGHT"); | |
97 titleBackgroundRight:SetWidth(30); | |
98 titleBackgroundRight:SetHeight(40); | |
99 | |
100 local frmTitle = CreateFrame("Frame", nil, frame); | |
101 frmTitle:EnableMouse(true); | |
102 frmTitle:SetScript("OnMouseDown", function(this) this:GetParent():StartMoving(); end); | |
103 frmTitle:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end); | |
104 frmTitle:SetAllPoints(titleBackground); | |
105 | |
106 local lblTitle = frmTitle:CreateFontString(nil, "OVERLAY", "GameFontNormal"); | |
107 lblTitle:SetPoint("TOP", titleBackground, "TOP", 0, -14); | |
108 lblTitle:SetText("Inventorium Bank Refill"); | |
109 | |
110 -- Resizer (vertical only) | |
111 local frmResizer = CreateFrame("Frame", nil, frame); | |
112 frmResizer:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 0, -10); | |
113 frmResizer:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, -10); | |
114 frmResizer:SetHeight(20); | |
115 frmResizer:EnableMouse(); | |
116 frmResizer:SetScript("OnMouseDown", function(this) this:GetParent():StartSizing("BOTTOM"); end); | |
117 frmResizer:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end); | |
118 | |
119 -- Description | |
120 local lblDescription = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal"); | |
121 lblDescription:SetPoint("TOPLEFT", frame, "TOPLEFT", 10, -23); | |
122 lblDescription:SetWidth(frameWidth - 10 - 10); -- 10 margin left & 10 margin right | |
123 lblDescription:SetJustifyH("LEFT"); | |
124 lblDescription:SetJustifyV("TOP"); | |
125 lblDescription:SetText("The items listed below can be refilled from this location, do you wish to move them to your bags?"); | |
126 | |
127 frame.lblDescription = lblDescription; | |
128 | |
129 -- Buttons | |
130 -- Move (proceed) | |
131 local btnMove = CreateFrame("Button", "$parentProceed", frame, "UIPanelButtonTemplate"); | |
132 btnMove:SetHeight(21); | |
133 btnMove:SetWidth(125); | |
134 btnMove:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 15, 10); | |
135 btnMove:SetText("Move Items"); | |
136 btnMove:SetScript("OnClick", onAccept); | |
137 btnMove:SetScript("OnEnter", ShowTooltip); | |
138 btnMove:SetScript("OnLeave", HideTooltip); | |
139 btnMove.tooltipTitle = "Move Items"; | |
140 btnMove.tooltip = "Start moving these items from the bank."; | |
141 | |
142 frame.btnMove = btnMove; | |
143 | |
144 -- Cancel | |
145 local btnCancel = CreateFrame("Button", "$parentCancel", frame, "UIPanelButtonTemplate"); | |
146 btnCancel:SetHeight(21); | |
147 btnCancel:SetWidth(125); | |
148 btnCancel:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 10); | |
149 btnCancel:SetText("Cancel"); | |
150 btnCancel:SetScript("OnClick", onCancel); | |
151 btnCancel:SetScript("OnEnter", ShowTooltip); | |
152 btnCancel:SetScript("OnLeave", HideTooltip); | |
153 btnCancel.tooltipTitle = "Cancel"; | |
154 btnCancel.tooltip = "Do not move anything and close the window."; | |
155 | |
156 frame.btnCancel = btnCancel; | |
157 | |
158 -- 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 | |
159 local frmMeasureDummy = CreateFrame("Frame", nil, frame); | |
160 frmMeasureDummy:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -20); | |
161 frmMeasureDummy:SetPoint("LEFT", frame.lblDescription, "LEFT", 10, 0); | |
162 frmMeasureDummy:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -10, 35); | |
163 | |
164 frame.frmMeasureDummy = frmMeasureDummy; | |
165 | |
166 -- Scrolling table with a list of items to be moved | |
167 local scrollTableWidth = ( frame.frmMeasureDummy:GetWidth() - 20 ); -- adjust width by the scrollbar size | |
168 local headers = { | |
169 { | |
170 ["name"] = "Item", | |
171 ["width"] = (scrollTableWidth * .5), | |
172 ["defaultsort"] = "asc", | |
173 ["comparesort"] = function(this, aRow, bRow, column) | |
174 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).colorargs[2]); | |
175 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).colorargs[2]); | |
176 local template = "%d%s"; | |
177 aName = template:format((10 - (aRarity or 10)), (aName or ""):lower()); | |
178 bName = template:format((10 - (bRarity or 10)), (bName or ""):lower()); | |
179 | |
180 if this.cols[column].sort == "dsc" then | |
181 return aName > bName; | |
182 else | |
183 return aName < bName; | |
184 end | |
185 end, | |
186 ["sort"] = "asc", -- when the data is set, use this column so sort the default data | |
187 }, | |
188 { | |
189 ["name"] = "Moving", | |
190 ["width"] = (scrollTableWidth * .15), | |
191 ["defaultsort"] = "dsc", | |
192 }, | |
193 { | |
194 ["name"] = "Missing", | |
195 ["width"] = (scrollTableWidth * .15), | |
196 ["defaultsort"] = "dsc", | |
197 }, | |
198 { | |
199 ["name"] = "Available", | |
200 ["width"] = (scrollTableWidth * .2), | |
201 ["defaultsort"] = "dsc", | |
202 }, | |
203 }; | |
204 | |
205 local ScrollingTable = LibStub("ScrollingTable"); | |
206 local table = ScrollingTable:CreateST(headers, 3, 15, nil, frame); | |
207 table:RegisterEvents({ | |
208 ["OnEnter"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) | |
209 if row and realrow and data[realrow] and data[realrow].colorargs and data[realrow].colorargs[2] then | |
210 GameTooltip:SetOwner(rowFrame, "ANCHOR_NONE"); | |
211 GameTooltip:SetPoint("TOPLEFT", rowFrame, "BOTTOMLEFT"); | |
212 GameTooltip:SetHyperlink(("item:%d"):format(data[realrow].colorargs[2])); | |
213 GameTooltip:Show(); | |
214 end | |
215 end, | |
216 ["OnLeave"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) | |
217 if row and realrow then | |
218 HideTooltip(); | |
219 end | |
220 end, | |
221 }); | |
222 | |
223 frame.scrollTable = table; | |
224 table.frame:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -20); | |
225 table.frame:SetPoint("LEFT", frame.lblDescription, "LEFT", 10, 0); | |
226 table.frame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -10, 35); | |
227 | |
228 -- Change the amount of displayed rows based on the size of the frame | |
229 frame.AdjustScrollTableRows = function(this) | |
230 local newRows = math.floor(( this.frmMeasureDummy:GetHeight() - 5 ) / 15); | |
231 newRows = (newRows < 3 and 3) or newRows; | |
232 | |
233 this.scrollTable:SetDisplayRows(newRows, 15); | |
234 end; | |
235 frame:SetScript("OnSizeChanged", frame.AdjustScrollTableRows); | |
236 end | |
237 | |
238 function addon:SetMoverFrameData(data) | |
239 InventoriumItemMover.scrollTable:SetData(data); | |
240 | |
241 InventoriumItemMover:Show(); | |
242 end |