Zerotorescue@101: local addon = select(2, ...); Zerotorescue@101: Zerotorescue@101: local function ShowTooltip(self) Zerotorescue@101: -- If this function is called from a widget, self is the widget and self.frame the actual frame Zerotorescue@101: local this = self.frame or self; Zerotorescue@101: Zerotorescue@106: if not this.tooltipTitle then return; end Zerotorescue@106: Zerotorescue@101: GameTooltip:SetOwner(this, "ANCHOR_NONE"); Zerotorescue@104: if this.tooltipLocation and this.tooltipLocation == "BOTTOM" then Zerotorescue@104: GameTooltip:SetPoint("TOP", this, "BOTTOM"); Zerotorescue@101: else Zerotorescue@101: GameTooltip:SetPoint("BOTTOM", this, "TOP"); Zerotorescue@101: end Zerotorescue@101: GameTooltip:SetText(this.tooltipTitle, 1, .82, 0, 1); Zerotorescue@101: Zerotorescue@101: if type(this.tooltip) == "string" then Zerotorescue@101: GameTooltip:AddLine(this.tooltip, 1, 1, 1, 1); Zerotorescue@101: end Zerotorescue@101: Zerotorescue@101: GameTooltip:Show(); Zerotorescue@101: end Zerotorescue@101: Zerotorescue@101: local function HideTooltip() Zerotorescue@101: GameTooltip:Hide(); Zerotorescue@101: end Zerotorescue@101: Zerotorescue@101: function addon:CreateMoverFrame(onAccept, onCancel) Zerotorescue@101: local frameWidth = 400; Zerotorescue@101: Zerotorescue@101: -- Main window Zerotorescue@101: local frame = CreateFrame("Frame", "InventoriumItemMover", UIParent); Zerotorescue@101: -- Hide by default Zerotorescue@101: frame:Hide(); Zerotorescue@101: -- Center the frame (will be adjusted later) Zerotorescue@101: frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0); Zerotorescue@101: -- Put in front of other windows Zerotorescue@101: frame:SetFrameStrata("FULLSCREEN_DIALOG"); Zerotorescue@101: frame:SetToplevel(true); Zerotorescue@101: -- Give it a size Zerotorescue@101: frame:SetWidth(frameWidth); Zerotorescue@101: frame:SetHeight(175); Zerotorescue@101: -- Background Zerotorescue@101: frame:SetBackdrop({ Zerotorescue@101: bgFile = "Interface\\ChatFrame\\ChatFrameBackground", Zerotorescue@101: edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", Zerotorescue@104: edgeSize = 20, Zerotorescue@101: insets = { Zerotorescue@101: left = 5, Zerotorescue@101: right = 5, Zerotorescue@101: top = 5, Zerotorescue@101: bottom = 5, Zerotorescue@101: }, Zerotorescue@101: }); Zerotorescue@101: frame:SetBackdropColor(0, 0, 0, .8); Zerotorescue@101: -- Mouse functions Zerotorescue@101: frame:EnableMouse(); Zerotorescue@101: frame:SetMovable(true); Zerotorescue@101: frame:SetResizable(true); Zerotorescue@101: frame:SetMinResize(300, 175); Zerotorescue@101: -- Set event handlers Zerotorescue@101: frame:SetScript("OnMouseUp", function(this) this:StopMovingOrSizing(); end); Zerotorescue@101: frame:SetScript("OnShow", function(this) Zerotorescue@104: if not tContains(StaticPopup_DisplayedFrames, this) then Zerotorescue@104: -- 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: local lastFrame = StaticPopup_DisplayedFrames[#StaticPopup_DisplayedFrames]; Zerotorescue@104: if lastFrame then Zerotorescue@104: this:SetPoint("TOP", lastFrame, "BOTTOM", 0, 0); Zerotorescue@104: else Zerotorescue@104: this:SetPoint("TOP", UIParent, "TOP", 0, -135); Zerotorescue@104: end Zerotorescue@104: Zerotorescue@104: -- Position other static popups below this Zerotorescue@104: tinsert(StaticPopup_DisplayedFrames, this); Zerotorescue@101: end Zerotorescue@101: Zerotorescue@101: this:AdjustScrollTableRows(); Zerotorescue@101: Zerotorescue@101: PlaySound("OrcExploration"); Zerotorescue@101: end); Zerotorescue@101: Zerotorescue@101: -- Title (AceGUI frame-widget-title used as example) Zerotorescue@101: local titleBackground = frame:CreateTexture(nil, "OVERLAY"); Zerotorescue@101: titleBackground:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header"); Zerotorescue@101: titleBackground:SetTexCoord(0.31, 0.67, 0, 0.63); Zerotorescue@101: titleBackground:SetPoint("TOP", 0, 12); Zerotorescue@101: titleBackground:SetWidth(150); Zerotorescue@101: titleBackground:SetHeight(40); Zerotorescue@101: Zerotorescue@101: local titleBackgroundLeft = frame:CreateTexture(nil, "OVERLAY"); Zerotorescue@101: titleBackgroundLeft:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header"); Zerotorescue@101: titleBackgroundLeft:SetTexCoord(0.21, 0.31, 0, 0.63); Zerotorescue@101: titleBackgroundLeft:SetPoint("RIGHT", titleBackground, "LEFT"); Zerotorescue@101: titleBackgroundLeft:SetWidth(30); Zerotorescue@101: titleBackgroundLeft:SetHeight(40); Zerotorescue@101: Zerotorescue@101: local titleBackgroundRight = frame:CreateTexture(nil, "OVERLAY"); Zerotorescue@101: titleBackgroundRight:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header"); Zerotorescue@101: titleBackgroundRight:SetTexCoord(0.67, 0.77, 0, 0.63); Zerotorescue@101: titleBackgroundRight:SetPoint("LEFT", titleBackground, "RIGHT"); Zerotorescue@101: titleBackgroundRight:SetWidth(30); Zerotorescue@101: titleBackgroundRight:SetHeight(40); Zerotorescue@101: Zerotorescue@101: local frmTitle = CreateFrame("Frame", nil, frame); Zerotorescue@101: frmTitle:EnableMouse(true); Zerotorescue@101: frmTitle:SetScript("OnMouseDown", function(this) this:GetParent():StartMoving(); end); Zerotorescue@101: frmTitle:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end); Zerotorescue@101: frmTitle:SetAllPoints(titleBackground); Zerotorescue@101: Zerotorescue@101: local lblTitle = frmTitle:CreateFontString(nil, "OVERLAY", "GameFontNormal"); Zerotorescue@101: lblTitle:SetPoint("TOP", titleBackground, "TOP", 0, -14); Zerotorescue@101: lblTitle:SetText("Inventorium Bank Refill"); Zerotorescue@101: Zerotorescue@101: -- Resizer (vertical only) Zerotorescue@101: local frmResizer = CreateFrame("Frame", nil, frame); Zerotorescue@101: frmResizer:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 0, -10); Zerotorescue@101: frmResizer:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, -10); Zerotorescue@101: frmResizer:SetHeight(20); Zerotorescue@101: frmResizer:EnableMouse(); Zerotorescue@101: frmResizer:SetScript("OnMouseDown", function(this) this:GetParent():StartSizing("BOTTOM"); end); Zerotorescue@101: frmResizer:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end); Zerotorescue@101: Zerotorescue@101: -- Description Zerotorescue@101: local lblDescription = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal"); Zerotorescue@106: lblDescription:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -27); Zerotorescue@104: lblDescription:SetWidth(frameWidth - 15 - 15); -- 10 margin left & 10 margin right Zerotorescue@101: lblDescription:SetJustifyH("LEFT"); Zerotorescue@101: lblDescription:SetJustifyV("TOP"); Zerotorescue@101: lblDescription:SetText("The items listed below can be refilled from this location, do you wish to move them to your bags?"); Zerotorescue@101: Zerotorescue@101: frame.lblDescription = lblDescription; Zerotorescue@101: Zerotorescue@101: -- Buttons Zerotorescue@101: -- Move (proceed) Zerotorescue@101: local btnMove = CreateFrame("Button", "$parentProceed", frame, "UIPanelButtonTemplate"); Zerotorescue@101: btnMove:SetHeight(21); Zerotorescue@101: btnMove:SetWidth(125); Zerotorescue@104: btnMove:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 15, 11); Zerotorescue@101: btnMove:SetText("Move Items"); Zerotorescue@101: btnMove:SetScript("OnClick", onAccept); Zerotorescue@101: btnMove:SetScript("OnEnter", ShowTooltip); Zerotorescue@101: btnMove:SetScript("OnLeave", HideTooltip); Zerotorescue@106: btnMove.tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Move Items"); Zerotorescue@106: btnMove.tooltip = (not addon.db.profile.defaults.hideHelp and "Start moving these items from the bank."); Zerotorescue@101: Zerotorescue@101: frame.btnMove = btnMove; Zerotorescue@101: Zerotorescue@101: -- Cancel Zerotorescue@101: local btnCancel = CreateFrame("Button", "$parentCancel", frame, "UIPanelButtonTemplate"); Zerotorescue@101: btnCancel:SetHeight(21); Zerotorescue@101: btnCancel:SetWidth(125); Zerotorescue@104: btnCancel:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 11); Zerotorescue@101: btnCancel:SetText("Cancel"); Zerotorescue@101: btnCancel:SetScript("OnClick", onCancel); Zerotorescue@101: btnCancel:SetScript("OnEnter", ShowTooltip); Zerotorescue@101: btnCancel:SetScript("OnLeave", HideTooltip); Zerotorescue@106: btnCancel.tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Cancel"); Zerotorescue@106: btnCancel.tooltip = (not addon.db.profile.defaults.hideHelp and "Do not move anything and close the window."); Zerotorescue@101: Zerotorescue@101: frame.btnCancel = btnCancel; Zerotorescue@101: Zerotorescue@101: -- 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: local frmMeasureDummy = CreateFrame("Frame", nil, frame); Zerotorescue@106: frmMeasureDummy:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -18); Zerotorescue@106: frmMeasureDummy:SetPoint("LEFT", frame, "LEFT", 15, 0); Zerotorescue@104: frmMeasureDummy:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35); Zerotorescue@101: Zerotorescue@101: frame.frmMeasureDummy = frmMeasureDummy; Zerotorescue@101: Zerotorescue@101: -- Scrolling table with a list of items to be moved Zerotorescue@106: local scrollTableWidth = ( frame.frmMeasureDummy:GetWidth() - 30 ); -- adjust width by the scrollbar size Zerotorescue@101: local headers = { Zerotorescue@101: { Zerotorescue@101: ["name"] = "Item", Zerotorescue@106: ["width"] = (scrollTableWidth * .60), Zerotorescue@101: ["defaultsort"] = "asc", Zerotorescue@101: ["comparesort"] = function(this, aRow, bRow, column) Zerotorescue@106: local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.id); Zerotorescue@106: local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.id); Zerotorescue@101: local template = "%d%s"; Zerotorescue@101: aName = template:format((10 - (aRarity or 10)), (aName or ""):lower()); Zerotorescue@101: bName = template:format((10 - (bRarity or 10)), (bName or ""):lower()); Zerotorescue@101: Zerotorescue@101: if this.cols[column].sort == "dsc" then Zerotorescue@101: return aName > bName; Zerotorescue@101: else Zerotorescue@101: return aName < bName; Zerotorescue@101: end Zerotorescue@101: end, Zerotorescue@101: ["sort"] = "asc", -- when the data is set, use this column so sort the default data Zerotorescue@106: ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"), Zerotorescue@106: ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by item quality then item name."), Zerotorescue@101: }, Zerotorescue@101: { Zerotorescue@101: ["name"] = "Moving", Zerotorescue@101: ["width"] = (scrollTableWidth * .15), Zerotorescue@106: ["align"] = "RIGHT", Zerotorescue@101: ["defaultsort"] = "dsc", Zerotorescue@106: ["sortnext"] = 1, Zerotorescue@106: ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Moving"), Zerotorescue@106: ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the amount of movable items."), Zerotorescue@101: }, Zerotorescue@101: { Zerotorescue@101: ["name"] = "Available", Zerotorescue@106: ["width"] = (scrollTableWidth * .25), Zerotorescue@106: ["align"] = "RIGHT", Zerotorescue@101: ["defaultsort"] = "dsc", Zerotorescue@106: ["sortnext"] = 1, Zerotorescue@106: ["comparesort"] = function(this, aRow, bRow, column) Zerotorescue@106: local aAvailablePercent = (this:GetRow(aRow).rowData.available / this:GetRow(aRow).rowData.missing); Zerotorescue@106: local bAvailablePercent = (this:GetRow(bRow).rowData.available / this:GetRow(bRow).rowData.missing); Zerotorescue@106: Zerotorescue@106: if this.cols[column].sort == "dsc" then Zerotorescue@106: return aAvailablePercent > bAvailablePercent; Zerotorescue@106: else Zerotorescue@106: return aAvailablePercent < bAvailablePercent; Zerotorescue@106: end Zerotorescue@106: end, Zerotorescue@106: ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"), Zerotorescue@106: ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the availibility percentage."), Zerotorescue@101: }, Zerotorescue@101: }; Zerotorescue@101: Zerotorescue@101: local ScrollingTable = LibStub("ScrollingTable"); Zerotorescue@101: local table = ScrollingTable:CreateST(headers, 3, 15, nil, frame); Zerotorescue@106: -- When moving over a row, provide a tooltip for the item Zerotorescue@101: table:RegisterEvents({ Zerotorescue@101: ["OnEnter"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) Zerotorescue@106: if row and realrow then Zerotorescue@106: -- Data row Zerotorescue@106: Zerotorescue@106: if data[realrow] and data[realrow].rowData and data[realrow].rowData.id then Zerotorescue@106: GameTooltip:SetOwner(rowFrame, "ANCHOR_NONE"); Zerotorescue@106: GameTooltip:SetPoint("TOPLEFT", rowFrame, "BOTTOMLEFT"); Zerotorescue@106: GameTooltip:SetHyperlink(("item:%d"):format(data[realrow].rowData.id)); Zerotorescue@106: GameTooltip:Show(); Zerotorescue@106: end Zerotorescue@106: else Zerotorescue@106: -- Header row Zerotorescue@106: Zerotorescue@106: if cols[column].tooltipTitle and type(cols[column].tooltipTitle) == "string" then Zerotorescue@106: cellFrame.tooltipTitle = cols[column].tooltipTitle; Zerotorescue@106: if cols[column].tooltip then Zerotorescue@106: cellFrame.tooltip = cols[column].tooltip; -- Optional Zerotorescue@106: else Zerotorescue@106: cellFrame.tooltip = nil; Zerotorescue@106: end Zerotorescue@106: Zerotorescue@106: ShowTooltip(cellFrame); Zerotorescue@106: end Zerotorescue@101: end Zerotorescue@101: end, Zerotorescue@101: ["OnLeave"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) Zerotorescue@106: HideTooltip(); Zerotorescue@101: end, Zerotorescue@101: }); Zerotorescue@101: Zerotorescue@101: frame.scrollTable = table; Zerotorescue@106: table.frame:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -18); Zerotorescue@104: table.frame:SetPoint("LEFT", frame, "LEFT", 15, 0); Zerotorescue@104: table.frame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35); Zerotorescue@101: Zerotorescue@106: -- Change the amount of displayed rows based on the size of the frame Zerotorescue@106: frame.AdjustScrollTableRows = function(this) Zerotorescue@106: local newRows = math.floor(( this.frmMeasureDummy:GetHeight() - 5 ) / 15); Zerotorescue@106: newRows = (newRows < 3 and 3) or newRows; Zerotorescue@106: Zerotorescue@106: this.scrollTable:SetDisplayRows(newRows, 15); Zerotorescue@106: end; Zerotorescue@106: frame:SetScript("OnSizeChanged", frame.AdjustScrollTableRows); Zerotorescue@101: end Zerotorescue@101: Zerotorescue@101: function addon:SetMoverFrameData(data) Zerotorescue@101: InventoriumItemMover.scrollTable:SetData(data); Zerotorescue@101: Zerotorescue@101: InventoriumItemMover:Show(); Zerotorescue@101: end