annotate Frames.lua @ 136:396c2960d54d

Queueing = queuing. :p
author Zerotorescue
date Tue, 18 Jan 2011 00:39:40 +0100
parents 8460855e3d90
children 5ed50feddeb0
rev   line source
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@132 7 if not this.tooltipTitle or addon.db.profile.defaults.hideHelp 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@132 29 if InventoriumItemMover then
Zerotorescue@132 30 return;
Zerotorescue@132 31 end
Zerotorescue@132 32
Zerotorescue@101 33 local frameWidth = 400;
Zerotorescue@101 34
Zerotorescue@101 35 -- Main window
Zerotorescue@101 36 local frame = CreateFrame("Frame", "InventoriumItemMover", UIParent);
Zerotorescue@101 37 -- Hide by default
Zerotorescue@101 38 frame:Hide();
Zerotorescue@101 39 -- Center the frame (will be adjusted later)
Zerotorescue@101 40 frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
Zerotorescue@101 41 -- Put in front of other windows
Zerotorescue@101 42 frame:SetFrameStrata("FULLSCREEN_DIALOG");
Zerotorescue@101 43 frame:SetToplevel(true);
Zerotorescue@101 44 -- Give it a size
Zerotorescue@101 45 frame:SetWidth(frameWidth);
Zerotorescue@101 46 frame:SetHeight(175);
Zerotorescue@101 47 -- Background
Zerotorescue@101 48 frame:SetBackdrop({
Zerotorescue@101 49 bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
Zerotorescue@101 50 edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
Zerotorescue@104 51 edgeSize = 20,
Zerotorescue@101 52 insets = {
Zerotorescue@101 53 left = 5,
Zerotorescue@101 54 right = 5,
Zerotorescue@101 55 top = 5,
Zerotorescue@101 56 bottom = 5,
Zerotorescue@101 57 },
Zerotorescue@101 58 });
Zerotorescue@101 59 frame:SetBackdropColor(0, 0, 0, .8);
Zerotorescue@101 60 -- Mouse functions
Zerotorescue@101 61 frame:EnableMouse();
Zerotorescue@101 62 frame:SetMovable(true);
Zerotorescue@101 63 frame:SetResizable(true);
Zerotorescue@101 64 frame:SetMinResize(300, 175);
Zerotorescue@101 65 -- Set event handlers
Zerotorescue@101 66 frame:SetScript("OnMouseUp", function(this) this:StopMovingOrSizing(); end);
Zerotorescue@101 67 frame:SetScript("OnShow", function(this)
Zerotorescue@104 68 if not tContains(StaticPopup_DisplayedFrames, this) then
Zerotorescue@104 69 -- 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 70 local lastFrame = StaticPopup_DisplayedFrames[#StaticPopup_DisplayedFrames];
Zerotorescue@104 71 if lastFrame then
Zerotorescue@104 72 this:SetPoint("TOP", lastFrame, "BOTTOM", 0, 0);
Zerotorescue@104 73 else
Zerotorescue@104 74 this:SetPoint("TOP", UIParent, "TOP", 0, -135);
Zerotorescue@104 75 end
Zerotorescue@104 76
Zerotorescue@104 77 -- Position other static popups below this
Zerotorescue@104 78 tinsert(StaticPopup_DisplayedFrames, this);
Zerotorescue@101 79 end
Zerotorescue@101 80
Zerotorescue@101 81 this:AdjustScrollTableRows();
Zerotorescue@101 82
Zerotorescue@101 83 PlaySound("OrcExploration");
Zerotorescue@101 84 end);
Zerotorescue@110 85 frame:SetScript("OnHide", function(this)
Zerotorescue@110 86 StaticPopup_CollapseTable(this);
Zerotorescue@110 87 end);
Zerotorescue@101 88
Zerotorescue@101 89 -- Title (AceGUI frame-widget-title used as example)
Zerotorescue@101 90 local titleBackground = frame:CreateTexture(nil, "OVERLAY");
Zerotorescue@101 91 titleBackground:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header");
Zerotorescue@101 92 titleBackground:SetTexCoord(0.31, 0.67, 0, 0.63);
Zerotorescue@101 93 titleBackground:SetPoint("TOP", 0, 12);
Zerotorescue@101 94 titleBackground:SetWidth(150);
Zerotorescue@101 95 titleBackground:SetHeight(40);
Zerotorescue@119 96
Zerotorescue@119 97 frame.titleBackground = titleBackground;
Zerotorescue@119 98
Zerotorescue@101 99 local titleBackgroundLeft = frame:CreateTexture(nil, "OVERLAY");
Zerotorescue@101 100 titleBackgroundLeft:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header");
Zerotorescue@101 101 titleBackgroundLeft:SetTexCoord(0.21, 0.31, 0, 0.63);
Zerotorescue@101 102 titleBackgroundLeft:SetPoint("RIGHT", titleBackground, "LEFT");
Zerotorescue@101 103 titleBackgroundLeft:SetWidth(30);
Zerotorescue@101 104 titleBackgroundLeft:SetHeight(40);
Zerotorescue@101 105
Zerotorescue@101 106 local titleBackgroundRight = frame:CreateTexture(nil, "OVERLAY");
Zerotorescue@101 107 titleBackgroundRight:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header");
Zerotorescue@101 108 titleBackgroundRight:SetTexCoord(0.67, 0.77, 0, 0.63);
Zerotorescue@101 109 titleBackgroundRight:SetPoint("LEFT", titleBackground, "RIGHT");
Zerotorescue@101 110 titleBackgroundRight:SetWidth(30);
Zerotorescue@101 111 titleBackgroundRight:SetHeight(40);
Zerotorescue@101 112
Zerotorescue@101 113 local frmTitle = CreateFrame("Frame", nil, frame);
Zerotorescue@101 114 frmTitle:EnableMouse(true);
Zerotorescue@101 115 frmTitle:SetScript("OnMouseDown", function(this) this:GetParent():StartMoving(); end);
Zerotorescue@101 116 frmTitle:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end);
Zerotorescue@101 117 frmTitle:SetAllPoints(titleBackground);
Zerotorescue@101 118
Zerotorescue@101 119 local lblTitle = frmTitle:CreateFontString(nil, "OVERLAY", "GameFontNormal");
Zerotorescue@101 120 lblTitle:SetPoint("TOP", titleBackground, "TOP", 0, -14);
Zerotorescue@110 121
Zerotorescue@110 122 frame.lblTitle = lblTitle;
Zerotorescue@101 123
Zerotorescue@101 124 -- Resizer (vertical only)
Zerotorescue@101 125 local frmResizer = CreateFrame("Frame", nil, frame);
Zerotorescue@101 126 frmResizer:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 0, -10);
Zerotorescue@101 127 frmResizer:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, -10);
Zerotorescue@101 128 frmResizer:SetHeight(20);
Zerotorescue@101 129 frmResizer:EnableMouse();
Zerotorescue@101 130 frmResizer:SetScript("OnMouseDown", function(this) this:GetParent():StartSizing("BOTTOM"); end);
Zerotorescue@101 131 frmResizer:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end);
Zerotorescue@101 132
Zerotorescue@101 133 -- Description
Zerotorescue@101 134 local lblDescription = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal");
Zerotorescue@106 135 lblDescription:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -27);
Zerotorescue@104 136 lblDescription:SetWidth(frameWidth - 15 - 15); -- 10 margin left & 10 margin right
Zerotorescue@101 137 lblDescription:SetJustifyH("LEFT");
Zerotorescue@101 138 lblDescription:SetJustifyV("TOP");
Zerotorescue@101 139
Zerotorescue@101 140 frame.lblDescription = lblDescription;
Zerotorescue@101 141
Zerotorescue@101 142 -- Buttons
Zerotorescue@132 143 -- Proceed
Zerotorescue@132 144 local btnProceed = CreateFrame("Button", "$parentProceed", frame, "UIPanelButtonTemplate");
Zerotorescue@132 145 btnProceed:SetHeight(21);
Zerotorescue@132 146 btnProceed:SetWidth(125);
Zerotorescue@132 147 btnProceed:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 15, 11);
Zerotorescue@132 148 btnProceed:SetScript("OnClick", function(this) this.OnClick(this); end);
Zerotorescue@132 149 btnProceed:SetScript("OnEnter", ShowTooltip);
Zerotorescue@132 150 btnProceed:SetScript("OnLeave", HideTooltip);
Zerotorescue@101 151
Zerotorescue@132 152 frame.btnProceed = btnProceed;
Zerotorescue@101 153
Zerotorescue@101 154 -- Cancel
Zerotorescue@101 155 local btnCancel = CreateFrame("Button", "$parentCancel", frame, "UIPanelButtonTemplate");
Zerotorescue@101 156 btnCancel:SetHeight(21);
Zerotorescue@101 157 btnCancel:SetWidth(125);
Zerotorescue@104 158 btnCancel:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 11);
Zerotorescue@110 159 btnCancel:SetScript("OnClick", function(this) this.OnClick(this); end);
Zerotorescue@101 160 btnCancel:SetScript("OnEnter", ShowTooltip);
Zerotorescue@101 161 btnCancel:SetScript("OnLeave", HideTooltip);
Zerotorescue@101 162
Zerotorescue@101 163 frame.btnCancel = btnCancel;
Zerotorescue@101 164
Zerotorescue@101 165 -- 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 166 local frmMeasureDummy = CreateFrame("Frame", nil, frame);
Zerotorescue@106 167 frmMeasureDummy:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -18);
Zerotorescue@106 168 frmMeasureDummy:SetPoint("LEFT", frame, "LEFT", 15, 0);
Zerotorescue@104 169 frmMeasureDummy:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35);
Zerotorescue@101 170
Zerotorescue@101 171 frame.frmMeasureDummy = frmMeasureDummy;
Zerotorescue@101 172
Zerotorescue@101 173 -- Scrolling table with a list of items to be moved
Zerotorescue@101 174 local ScrollingTable = LibStub("ScrollingTable");
Zerotorescue@132 175 local scrollTable = ScrollingTable:CreateST({}, 4, 15, nil, frame); -- inserting a dummy cols, real cols to be set in SetFrameSettings
Zerotorescue@132 176 scrollTable.frame:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -18);
Zerotorescue@132 177 scrollTable.frame:SetPoint("LEFT", frame, "LEFT", 15, 0);
Zerotorescue@132 178 scrollTable.frame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35);
Zerotorescue@106 179 -- When moving over a row, provide a tooltip for the item
Zerotorescue@132 180 scrollTable:RegisterEvents({
Zerotorescue@101 181 ["OnEnter"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
Zerotorescue@106 182 if row and realrow then
Zerotorescue@106 183 -- Data row
Zerotorescue@106 184
Zerotorescue@112 185 if data[realrow] and data[realrow].rowData and data[realrow].rowData.itemId then
Zerotorescue@106 186 GameTooltip:SetOwner(rowFrame, "ANCHOR_NONE");
Zerotorescue@106 187 GameTooltip:SetPoint("TOPLEFT", rowFrame, "BOTTOMLEFT");
Zerotorescue@112 188 GameTooltip:SetHyperlink(("item:%d"):format(data[realrow].rowData.itemId));
Zerotorescue@106 189 GameTooltip:Show();
Zerotorescue@106 190 end
Zerotorescue@106 191 else
Zerotorescue@106 192 -- Header row
Zerotorescue@106 193
Zerotorescue@106 194 if cols[column].tooltipTitle and type(cols[column].tooltipTitle) == "string" then
Zerotorescue@106 195 cellFrame.tooltipTitle = cols[column].tooltipTitle;
Zerotorescue@106 196 if cols[column].tooltip then
Zerotorescue@106 197 cellFrame.tooltip = cols[column].tooltip; -- Optional
Zerotorescue@106 198 else
Zerotorescue@106 199 cellFrame.tooltip = nil;
Zerotorescue@106 200 end
Zerotorescue@106 201
Zerotorescue@106 202 ShowTooltip(cellFrame);
Zerotorescue@106 203 end
Zerotorescue@101 204 end
Zerotorescue@101 205 end,
Zerotorescue@101 206 ["OnLeave"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
Zerotorescue@106 207 HideTooltip();
Zerotorescue@101 208 end,
Zerotorescue@101 209 });
Zerotorescue@101 210
Zerotorescue@132 211 frame.scrollTable = scrollTable;
Zerotorescue@110 212
Zerotorescue@106 213 -- Change the amount of displayed rows based on the size of the frame
Zerotorescue@106 214 frame.AdjustScrollTableRows = function(this)
Zerotorescue@106 215 local newRows = math.floor(( this.frmMeasureDummy:GetHeight() - 5 ) / 15);
Zerotorescue@110 216 newRows = (newRows < 4 and 4) or newRows;
Zerotorescue@106 217
Zerotorescue@106 218 this.scrollTable:SetDisplayRows(newRows, 15);
Zerotorescue@106 219 end;
Zerotorescue@106 220 frame:SetScript("OnSizeChanged", frame.AdjustScrollTableRows);
Zerotorescue@101 221 end
Zerotorescue@101 222
Zerotorescue@101 223 function addon:SetMoverFrameData(data)
Zerotorescue@101 224 InventoriumItemMover.scrollTable:SetData(data);
Zerotorescue@101 225
Zerotorescue@101 226 InventoriumItemMover:Show();
Zerotorescue@101 227 end
Zerotorescue@110 228
Zerotorescue@132 229 function addon:SetMoverFrameSettings(title, description, proceed, cancel, headers)
Zerotorescue@110 230 local frame = InventoriumItemMover;
Zerotorescue@110 231
Zerotorescue@110 232 frame.lblTitle:SetText(title);
Zerotorescue@119 233 -- Adjust size for the title background
Zerotorescue@119 234 frame.titleBackground:SetWidth((frame.lblTitle:GetWidth() or 0) + 10); -- 10 pixels margin
Zerotorescue@110 235
Zerotorescue@110 236 frame.lblDescription:SetText(description);
Zerotorescue@110 237
Zerotorescue@132 238 frame.btnProceed:SetText(proceed.text);
Zerotorescue@132 239 frame.btnProceed.tooltipTitle = proceed.tooltipTitle;
Zerotorescue@132 240 frame.btnProceed.tooltip = proceed.tooltip;
Zerotorescue@132 241 frame.btnProceed.OnClick = proceed.onClick;
Zerotorescue@110 242
Zerotorescue@110 243 frame.btnCancel:SetText(cancel.text);
Zerotorescue@110 244 frame.btnCancel.tooltipTitle = cancel.tooltipTitle;
Zerotorescue@110 245 frame.btnCancel.tooltip = cancel.tooltip;
Zerotorescue@110 246 frame.btnCancel.OnClick = cancel.onClick;
Zerotorescue@110 247
Zerotorescue@110 248 frame.scrollTable:SetDisplayCols(headers);
Zerotorescue@110 249 end
Zerotorescue@132 250
Zerotorescue@132 251 function addon:CreateQueueFrame()
Zerotorescue@132 252 if InventoriumQueuer then
Zerotorescue@132 253 return;
Zerotorescue@132 254 end
Zerotorescue@132 255
Zerotorescue@132 256 do
Zerotorescue@132 257 local frameWidth = 400;
Zerotorescue@132 258
Zerotorescue@132 259 -- Main window
Zerotorescue@132 260 local frame = CreateFrame("Frame", "InventoriumQueuer", UIParent);
Zerotorescue@132 261 -- Hide by default
Zerotorescue@132 262 frame:Hide();
Zerotorescue@132 263 -- Center the frame (will be adjusted later)
Zerotorescue@132 264 frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
Zerotorescue@132 265 -- Put in front of other windows
Zerotorescue@132 266 frame:SetFrameStrata("FULLSCREEN_DIALOG");
Zerotorescue@132 267 frame:SetToplevel(true);
Zerotorescue@132 268 -- Give it a size
Zerotorescue@132 269 frame:SetWidth(frameWidth);
Zerotorescue@132 270 frame:SetHeight(430);
Zerotorescue@132 271 -- Background
Zerotorescue@132 272 frame:SetBackdrop({
Zerotorescue@132 273 bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
Zerotorescue@132 274 edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
Zerotorescue@132 275 edgeSize = 20,
Zerotorescue@132 276 insets = {
Zerotorescue@132 277 left = 5,
Zerotorescue@132 278 right = 5,
Zerotorescue@132 279 top = 5,
Zerotorescue@132 280 bottom = 5,
Zerotorescue@132 281 },
Zerotorescue@132 282 });
Zerotorescue@132 283 frame:SetBackdropColor(0, 0, 0, .8);
Zerotorescue@132 284 -- Mouse functions
Zerotorescue@132 285 frame:EnableMouse();
Zerotorescue@132 286 frame:SetMovable(true);
Zerotorescue@132 287 -- Set event handlers
Zerotorescue@132 288 frame:SetScript("OnMouseUp", function(this) this:StopMovingOrSizing(); end);
Zerotorescue@132 289 frame:SetScript("OnShow", function(this)
Zerotorescue@132 290 this:AdjustScrollTableRows();
Zerotorescue@132 291 end);
Zerotorescue@132 292
Zerotorescue@132 293 -- Title (AceGUI frame-widget-title used as example)
Zerotorescue@132 294 local titleBackground = frame:CreateTexture(nil, "OVERLAY");
Zerotorescue@132 295 titleBackground:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header");
Zerotorescue@132 296 titleBackground:SetTexCoord(0.31, 0.67, 0, 0.63);
Zerotorescue@132 297 titleBackground:SetPoint("TOP", 0, 12);
Zerotorescue@132 298 titleBackground:SetWidth(150);
Zerotorescue@132 299 titleBackground:SetHeight(40);
Zerotorescue@132 300
Zerotorescue@132 301 frame.titleBackground = titleBackground;
Zerotorescue@132 302
Zerotorescue@132 303 local titleBackgroundLeft = frame:CreateTexture(nil, "OVERLAY");
Zerotorescue@132 304 titleBackgroundLeft:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header");
Zerotorescue@132 305 titleBackgroundLeft:SetTexCoord(0.21, 0.31, 0, 0.63);
Zerotorescue@132 306 titleBackgroundLeft:SetPoint("RIGHT", titleBackground, "LEFT");
Zerotorescue@132 307 titleBackgroundLeft:SetWidth(30);
Zerotorescue@132 308 titleBackgroundLeft:SetHeight(40);
Zerotorescue@132 309
Zerotorescue@132 310 local titleBackgroundRight = frame:CreateTexture(nil, "OVERLAY");
Zerotorescue@132 311 titleBackgroundRight:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header");
Zerotorescue@132 312 titleBackgroundRight:SetTexCoord(0.67, 0.77, 0, 0.63);
Zerotorescue@132 313 titleBackgroundRight:SetPoint("LEFT", titleBackground, "RIGHT");
Zerotorescue@132 314 titleBackgroundRight:SetWidth(30);
Zerotorescue@132 315 titleBackgroundRight:SetHeight(40);
Zerotorescue@132 316
Zerotorescue@132 317 local frmTitle = CreateFrame("Frame", nil, frame);
Zerotorescue@132 318 frmTitle:EnableMouse(true);
Zerotorescue@132 319 frmTitle:SetScript("OnMouseDown", function(this) this:GetParent():StartMoving(); end);
Zerotorescue@132 320 frmTitle:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end);
Zerotorescue@132 321 frmTitle:SetAllPoints(titleBackground);
Zerotorescue@132 322
Zerotorescue@132 323 local lblTitle = frmTitle:CreateFontString(nil, "OVERLAY", "GameFontNormal");
Zerotorescue@132 324 lblTitle:SetPoint("TOP", titleBackground, "TOP", 0, -14);
Zerotorescue@132 325
Zerotorescue@132 326 frame.lblTitle = lblTitle;
Zerotorescue@132 327
Zerotorescue@132 328 -- Expand button
Zerotorescue@132 329 local btnExpander = CreateFrame("Button", "$parentExpander", frame);
Zerotorescue@132 330 btnExpander:SetWidth(32);
Zerotorescue@132 331 btnExpander:SetHeight(32);
Zerotorescue@132 332 btnExpander:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -10, -10);
Zerotorescue@132 333 btnExpander:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Up");
Zerotorescue@132 334 btnExpander:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Down");
Zerotorescue@132 335 btnExpander:SetDisabledTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Disabled");
Zerotorescue@132 336 btnExpander:SetHighlightTexture("Interface\\Buttons\\UI-Common-MouseHilight", "ADD");
Zerotorescue@132 337 btnExpander.tooltipTitle = "Show unqueueables";
Zerotorescue@132 338 btnExpander.tooltip = "Click to show a list of all unqueueable but tracked items.";
Zerotorescue@132 339 btnExpander:SetScript("OnEnter", ShowTooltip);
Zerotorescue@132 340 btnExpander:SetScript("OnLeave", HideTooltip);
Zerotorescue@132 341 btnExpander:SetScript("OnClick", function(this)
Zerotorescue@132 342 if this.Expanded then
Zerotorescue@132 343 -- Collapsing
Zerotorescue@132 344 this.Expanded = nil;
Zerotorescue@132 345 InventoriumQueuerUnqueueables:Hide();
Zerotorescue@132 346 PlaySound("igCharacterInfoClose");
Zerotorescue@132 347
Zerotorescue@132 348 -- Next is an expand
Zerotorescue@132 349 this:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Up");
Zerotorescue@132 350 this:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Down");
Zerotorescue@132 351 this:SetDisabledTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Disabled");
Zerotorescue@132 352 else
Zerotorescue@132 353 -- Expanding
Zerotorescue@132 354 this.Expanded = true;
Zerotorescue@132 355
Zerotorescue@132 356 -- Position the frame against the queuer window
Zerotorescue@132 357 InventoriumQueuerUnqueueables:ClearAllPoints();
Zerotorescue@132 358 InventoriumQueuerUnqueueables:SetPoint("TOPLEFT", this:GetParent(), "TOPRIGHT", 0, 0);
Zerotorescue@132 359 InventoriumQueuerUnqueueables:SetPoint("BOTTOMLEFT", this:GetParent(), "BOTTOMLEFT", 0, 0);
Zerotorescue@132 360 InventoriumQueuerUnqueueables:Show();
Zerotorescue@132 361 PlaySound("igCharacterInfoOpen");
Zerotorescue@132 362
Zerotorescue@132 363 -- Next is a collapse
Zerotorescue@132 364 this:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Up");
Zerotorescue@132 365 this:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Down");
Zerotorescue@132 366 this:SetDisabledTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Disabled");
Zerotorescue@132 367 end
Zerotorescue@132 368 end);
Zerotorescue@132 369
Zerotorescue@132 370 -- Description
Zerotorescue@132 371 local lblDescription = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal");
Zerotorescue@132 372 lblDescription:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -27);
Zerotorescue@132 373 lblDescription:SetPoint("RIGHT", btnExpander, "LEFT", -15, 0);
Zerotorescue@132 374 lblDescription:SetJustifyH("LEFT");
Zerotorescue@132 375 lblDescription:SetJustifyV("TOP");
Zerotorescue@132 376 lblDescription:SetWidth(frameWidth - 70);
Zerotorescue@132 377
Zerotorescue@132 378 frame.lblDescription = lblDescription;
Zerotorescue@132 379
Zerotorescue@132 380 -- Buttons
Zerotorescue@132 381 -- Proceed
Zerotorescue@132 382 local btnProceed = CreateFrame("Button", "$parentProceed", frame, "UIPanelButtonTemplate");
Zerotorescue@132 383 btnProceed:SetHeight(21);
Zerotorescue@132 384 btnProceed:SetWidth(125);
Zerotorescue@132 385 btnProceed:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 15, 11);
Zerotorescue@132 386 btnProceed:SetScript("OnClick", function(this) this.OnClick(this); end);
Zerotorescue@132 387 btnProceed:SetScript("OnEnter", ShowTooltip);
Zerotorescue@132 388 btnProceed:SetScript("OnLeave", HideTooltip);
Zerotorescue@132 389
Zerotorescue@132 390 frame.btnProceed = btnProceed;
Zerotorescue@132 391
Zerotorescue@132 392 -- Cancel
Zerotorescue@132 393 local btnCancel = CreateFrame("Button", "$parentCancel", frame, "UIPanelButtonTemplate");
Zerotorescue@132 394 btnCancel:SetHeight(21);
Zerotorescue@132 395 btnCancel:SetWidth(125);
Zerotorescue@132 396 btnCancel:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 11);
Zerotorescue@132 397 btnCancel:SetScript("OnClick", function(this) this.OnClick(this); end);
Zerotorescue@132 398 btnCancel:SetScript("OnEnter", ShowTooltip);
Zerotorescue@132 399 btnCancel:SetScript("OnLeave", HideTooltip);
Zerotorescue@132 400
Zerotorescue@132 401 frame.btnCancel = btnCancel;
Zerotorescue@132 402
Zerotorescue@132 403 -- Because the scrolling table code-behind will change the scrolltable element's height, we can't rely on that. Make a dummy frame which we can measure
Zerotorescue@132 404 local frmMeasureDummy = CreateFrame("Frame", nil, frame);
Zerotorescue@132 405 frmMeasureDummy:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -18);
Zerotorescue@132 406 frmMeasureDummy:SetPoint("LEFT", frame, "LEFT", 15, 0);
Zerotorescue@132 407 frmMeasureDummy:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35);
Zerotorescue@132 408
Zerotorescue@132 409 frame.frmMeasureDummy = frmMeasureDummy;
Zerotorescue@132 410
Zerotorescue@132 411 -- Scrolling table with a list of items to be queued
Zerotorescue@132 412 local ScrollingTable = LibStub("ScrollingTable");
Zerotorescue@132 413 local scrollTable = ScrollingTable:CreateST({}, 4, 15, nil, frame); -- inserting a dummy cols, real cols to be set in SetFrameSettings
Zerotorescue@132 414 scrollTable.frame:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -18);
Zerotorescue@132 415 scrollTable.frame:SetPoint("LEFT", frame, "LEFT", 15, 0);
Zerotorescue@132 416 scrollTable.frame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35);
Zerotorescue@132 417 -- When moving over a row, provide a tooltip for the item
Zerotorescue@132 418 scrollTable:RegisterEvents({
Zerotorescue@132 419 ["OnEnter"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
Zerotorescue@132 420 if row and realrow then
Zerotorescue@132 421 -- Data row
Zerotorescue@132 422
Zerotorescue@132 423 if data[realrow] and data[realrow].rowData and data[realrow].rowData.itemId then
Zerotorescue@132 424 GameTooltip:SetOwner(rowFrame, "ANCHOR_NONE");
Zerotorescue@132 425 GameTooltip:SetPoint("TOPLEFT", rowFrame, "BOTTOMLEFT");
Zerotorescue@132 426 GameTooltip:SetHyperlink(("item:%d"):format(data[realrow].rowData.itemId));
Zerotorescue@132 427 GameTooltip:Show();
Zerotorescue@132 428 end
Zerotorescue@132 429 else
Zerotorescue@132 430 -- Header row
Zerotorescue@132 431
Zerotorescue@132 432 if cols[column].tooltipTitle and type(cols[column].tooltipTitle) == "string" then
Zerotorescue@132 433 cellFrame.tooltipTitle = cols[column].tooltipTitle;
Zerotorescue@132 434 if cols[column].tooltip then
Zerotorescue@132 435 cellFrame.tooltip = cols[column].tooltip; -- Optional
Zerotorescue@132 436 else
Zerotorescue@132 437 cellFrame.tooltip = nil;
Zerotorescue@132 438 end
Zerotorescue@132 439
Zerotorescue@132 440 ShowTooltip(cellFrame);
Zerotorescue@132 441 end
Zerotorescue@132 442 end
Zerotorescue@132 443 end,
Zerotorescue@132 444 ["OnLeave"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
Zerotorescue@132 445 HideTooltip();
Zerotorescue@132 446 end,
Zerotorescue@132 447 });
Zerotorescue@132 448
Zerotorescue@132 449 frame.scrollTable = scrollTable;
Zerotorescue@132 450
Zerotorescue@132 451 -- Change the amount of displayed rows based on the size of the frame
Zerotorescue@132 452 frame.AdjustScrollTableRows = function(this)
Zerotorescue@132 453 local newRows = math.floor(( this.frmMeasureDummy:GetHeight() - 5 ) / 15);
Zerotorescue@132 454 newRows = (newRows < 4 and 4) or newRows;
Zerotorescue@132 455
Zerotorescue@132 456 this.scrollTable:SetDisplayRows(newRows, 15);
Zerotorescue@132 457 end;
Zerotorescue@132 458 frame:SetScript("OnSizeChanged", frame.AdjustScrollTableRows);
Zerotorescue@132 459 end
Zerotorescue@132 460 do
Zerotorescue@132 461 local frameWidth = 300;
Zerotorescue@132 462
Zerotorescue@132 463 -- Main window
Zerotorescue@132 464 local frame = CreateFrame("Frame", "InventoriumQueuerUnqueueables", InventoriumQueuer);
Zerotorescue@132 465 -- Hide by default
Zerotorescue@132 466 frame:Hide();
Zerotorescue@132 467 -- Position the frame against the queuer window
Zerotorescue@132 468 frame:SetPoint("TOPLEFT", InventoriumQueuer, "TOPRIGHT", 0, 0);
Zerotorescue@132 469 frame:SetPoint("BOTTOMLEFT", InventoriumQueuer, "BOTTOMLEFT", 0, 0);
Zerotorescue@132 470 -- Put in front of other windows
Zerotorescue@132 471 frame:SetFrameStrata("FULLSCREEN_DIALOG");
Zerotorescue@132 472 frame:SetToplevel(true);
Zerotorescue@132 473 -- Give it a size
Zerotorescue@132 474 frame:SetWidth(frameWidth);
Zerotorescue@132 475 -- Background
Zerotorescue@132 476 frame:SetBackdrop({
Zerotorescue@132 477 bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
Zerotorescue@132 478 edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
Zerotorescue@132 479 edgeSize = 20,
Zerotorescue@132 480 insets = {
Zerotorescue@132 481 left = 5,
Zerotorescue@132 482 right = 5,
Zerotorescue@132 483 top = 5,
Zerotorescue@132 484 bottom = 5,
Zerotorescue@132 485 },
Zerotorescue@132 486 });
Zerotorescue@132 487 frame:SetBackdropColor(0, 0, 0, .8);
Zerotorescue@132 488 -- Mouse functions
Zerotorescue@132 489 frame:EnableMouse();
Zerotorescue@132 490 frame:SetMovable(true);
Zerotorescue@132 491 -- Set event handlers
Zerotorescue@132 492 frame:SetScript("OnMouseUp", function(this) this:StopMovingOrSizing(); end);
Zerotorescue@132 493 frame:SetScript("OnShow", function(this)
Zerotorescue@132 494 this:AdjustScrollTableRows();
Zerotorescue@132 495 end);
Zerotorescue@132 496
Zerotorescue@132 497 -- Title (AceGUI frame-widget-title used as example)
Zerotorescue@132 498 local titleBackground = frame:CreateTexture(nil, "OVERLAY");
Zerotorescue@132 499 titleBackground:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header");
Zerotorescue@132 500 titleBackground:SetTexCoord(0.31, 0.67, 0, 0.63);
Zerotorescue@132 501 titleBackground:SetPoint("TOP", 0, 12);
Zerotorescue@132 502 titleBackground:SetWidth(90);
Zerotorescue@132 503 titleBackground:SetHeight(40);
Zerotorescue@132 504
Zerotorescue@132 505 frame.titleBackground = titleBackground;
Zerotorescue@132 506
Zerotorescue@132 507 local titleBackgroundLeft = frame:CreateTexture(nil, "OVERLAY");
Zerotorescue@132 508 titleBackgroundLeft:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header");
Zerotorescue@132 509 titleBackgroundLeft:SetTexCoord(0.21, 0.31, 0, 0.63);
Zerotorescue@132 510 titleBackgroundLeft:SetPoint("RIGHT", titleBackground, "LEFT");
Zerotorescue@132 511 titleBackgroundLeft:SetWidth(30);
Zerotorescue@132 512 titleBackgroundLeft:SetHeight(40);
Zerotorescue@132 513
Zerotorescue@132 514 local titleBackgroundRight = frame:CreateTexture(nil, "OVERLAY");
Zerotorescue@132 515 titleBackgroundRight:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header");
Zerotorescue@132 516 titleBackgroundRight:SetTexCoord(0.67, 0.77, 0, 0.63);
Zerotorescue@132 517 titleBackgroundRight:SetPoint("LEFT", titleBackground, "RIGHT");
Zerotorescue@132 518 titleBackgroundRight:SetWidth(30);
Zerotorescue@132 519 titleBackgroundRight:SetHeight(40);
Zerotorescue@132 520
Zerotorescue@132 521 local frmTitle = CreateFrame("Frame", nil, frame);
Zerotorescue@132 522 frmTitle:EnableMouse(true);
Zerotorescue@132 523 frmTitle:SetScript("OnMouseDown", function(this) this:GetParent():StartMoving(); end);
Zerotorescue@132 524 frmTitle:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end);
Zerotorescue@132 525 frmTitle:SetAllPoints(titleBackground);
Zerotorescue@132 526
Zerotorescue@132 527 local lblTitle = frmTitle:CreateFontString(nil, "OVERLAY", "GameFontNormal");
Zerotorescue@132 528 lblTitle:SetPoint("TOP", titleBackground, "TOP", 0, -14);
Zerotorescue@132 529 lblTitle:SetText("Unqueueables");
Zerotorescue@132 530
Zerotorescue@132 531 -- 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@132 532 local frmMeasureDummy = CreateFrame("Frame", nil, frame);
Zerotorescue@132 533 frmMeasureDummy:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -42);
Zerotorescue@132 534 frmMeasureDummy:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 15);
Zerotorescue@132 535
Zerotorescue@132 536 frame.frmMeasureDummy = frmMeasureDummy;
Zerotorescue@132 537
Zerotorescue@132 538 -- Scrolling table with a list of items to be queued
Zerotorescue@132 539 local ScrollingTable = LibStub("ScrollingTable");
Zerotorescue@132 540 local scrollTable = ScrollingTable:CreateST({}, 4, 15, nil, frame); -- inserting a dummy cols, real cols to be set in SetFrameSettings
Zerotorescue@132 541 scrollTable.frame:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -42);
Zerotorescue@132 542 scrollTable.frame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 15);
Zerotorescue@132 543 -- When moving over a row, provide a tooltip for the item
Zerotorescue@132 544 scrollTable:RegisterEvents({
Zerotorescue@132 545 ["OnEnter"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
Zerotorescue@132 546 if row and realrow then
Zerotorescue@132 547 -- Data row
Zerotorescue@132 548
Zerotorescue@132 549 if data[realrow] and data[realrow].rowData and data[realrow].rowData.itemId then
Zerotorescue@132 550 if column == 1 then
Zerotorescue@132 551 GameTooltip:SetOwner(rowFrame, "ANCHOR_NONE");
Zerotorescue@132 552 GameTooltip:SetPoint("TOPLEFT", rowFrame, "BOTTOMLEFT");
Zerotorescue@132 553 GameTooltip:SetHyperlink(("item:%d"):format(data[realrow].rowData.itemId));
Zerotorescue@132 554 GameTooltip:Show();
Zerotorescue@132 555 else
Zerotorescue@132 556 GameTooltip:SetOwner(cellFrame, "ANCHOR_NONE");
Zerotorescue@132 557 GameTooltip:SetPoint("TOPLEFT", cellFrame, "BOTTOMLEFT");
Zerotorescue@132 558 GameTooltip:SetText(data[realrow].rowData.reason[1]);
Zerotorescue@132 559 GameTooltip:AddLine(data[realrow].rowData.reason[2], 1, 1, 1, 1);
Zerotorescue@132 560 GameTooltip:Show();
Zerotorescue@132 561 end
Zerotorescue@132 562 end
Zerotorescue@132 563 else
Zerotorescue@132 564 -- Header row
Zerotorescue@132 565
Zerotorescue@132 566 if cols[column].tooltipTitle and type(cols[column].tooltipTitle) == "string" then
Zerotorescue@132 567 cellFrame.tooltipTitle = cols[column].tooltipTitle;
Zerotorescue@132 568 if cols[column].tooltip then
Zerotorescue@132 569 cellFrame.tooltip = cols[column].tooltip; -- Optional
Zerotorescue@132 570 else
Zerotorescue@132 571 cellFrame.tooltip = nil;
Zerotorescue@132 572 end
Zerotorescue@132 573
Zerotorescue@132 574 ShowTooltip(cellFrame);
Zerotorescue@132 575 end
Zerotorescue@132 576 end
Zerotorescue@132 577 end,
Zerotorescue@132 578 ["OnLeave"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
Zerotorescue@132 579 HideTooltip();
Zerotorescue@132 580 end,
Zerotorescue@132 581 });
Zerotorescue@132 582
Zerotorescue@132 583 frame.scrollTable = scrollTable;
Zerotorescue@132 584
Zerotorescue@132 585 -- Change the amount of displayed rows based on the size of the frame
Zerotorescue@132 586 frame.AdjustScrollTableRows = function(this)
Zerotorescue@132 587 local newRows = math.floor(( this.frmMeasureDummy:GetHeight() - 5 ) / 15);
Zerotorescue@132 588 newRows = (newRows < 4 and 4) or newRows;
Zerotorescue@132 589
Zerotorescue@132 590 this.scrollTable:SetDisplayRows(newRows, 15);
Zerotorescue@132 591 end;
Zerotorescue@132 592 frame:SetScript("OnSizeChanged", frame.AdjustScrollTableRows);
Zerotorescue@132 593 end
Zerotorescue@132 594 end
Zerotorescue@132 595
Zerotorescue@132 596 function addon:SetQueueFrameData(queueable, unqueueables)
Zerotorescue@132 597 InventoriumQueuer.scrollTable:SetData(queueable);
Zerotorescue@132 598 InventoriumQueuerUnqueueables.scrollTable:SetData(unqueueables);
Zerotorescue@132 599
Zerotorescue@132 600 InventoriumQueuer:Show();
Zerotorescue@132 601 end
Zerotorescue@132 602
Zerotorescue@132 603 function addon:SetQueueFrameSettings(title, description, proceed, cancel, headers, unqueueablesHeaders)
Zerotorescue@132 604 local frame = InventoriumQueuer;
Zerotorescue@132 605
Zerotorescue@132 606 frame.lblTitle:SetText(title);
Zerotorescue@132 607 -- Adjust size for the title background
Zerotorescue@132 608 frame.titleBackground:SetWidth((frame.lblTitle:GetWidth() or 0) + 10); -- 10 pixels margin
Zerotorescue@132 609
Zerotorescue@132 610 frame.lblDescription:SetText(description);
Zerotorescue@132 611
Zerotorescue@132 612 frame.btnProceed:SetText(proceed.text);
Zerotorescue@132 613 frame.btnProceed.tooltipTitle = proceed.tooltipTitle;
Zerotorescue@132 614 frame.btnProceed.tooltip = proceed.tooltip;
Zerotorescue@132 615 frame.btnProceed.OnClick = proceed.onClick;
Zerotorescue@132 616
Zerotorescue@132 617 frame.btnCancel:SetText(cancel.text);
Zerotorescue@132 618 frame.btnCancel.tooltipTitle = cancel.tooltipTitle;
Zerotorescue@132 619 frame.btnCancel.tooltip = cancel.tooltip;
Zerotorescue@132 620 frame.btnCancel.OnClick = cancel.onClick;
Zerotorescue@132 621
Zerotorescue@132 622 frame.scrollTable:SetDisplayCols(headers);
Zerotorescue@132 623
Zerotorescue@132 624 InventoriumQueuerUnqueueables.scrollTable:SetDisplayCols(unqueueablesHeaders);
Zerotorescue@132 625 end