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