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