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@110: function addon:CreateMoverFrame() 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@110: frame:SetScript("OnHide", function(this) Zerotorescue@110: StaticPopup_CollapseTable(this); Zerotorescue@110: 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@110: Zerotorescue@110: frame.lblTitle = lblTitle; 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: 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@110: btnMove:SetScript("OnClick", function(this) this.OnClick(this); end); Zerotorescue@101: btnMove:SetScript("OnEnter", ShowTooltip); Zerotorescue@101: btnMove:SetScript("OnLeave", HideTooltip); 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@110: btnCancel:SetScript("OnClick", function(this) this.OnClick(this); end); Zerotorescue@101: btnCancel:SetScript("OnEnter", ShowTooltip); Zerotorescue@101: btnCancel:SetScript("OnLeave", HideTooltip); 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@101: local ScrollingTable = LibStub("ScrollingTable"); Zerotorescue@110: local table = ScrollingTable:CreateST({}, 4, 15, nil, frame); -- inserting a dummy cols, real cols to be set in SetFrameSettings Zerotorescue@110: table.frame:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -18); Zerotorescue@110: table.frame:SetPoint("LEFT", frame, "LEFT", 15, 0); Zerotorescue@110: table.frame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35); 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@112: if data[realrow] and data[realrow].rowData and data[realrow].rowData.itemId then Zerotorescue@106: GameTooltip:SetOwner(rowFrame, "ANCHOR_NONE"); Zerotorescue@106: GameTooltip:SetPoint("TOPLEFT", rowFrame, "BOTTOMLEFT"); Zerotorescue@112: GameTooltip:SetHyperlink(("item:%d"):format(data[realrow].rowData.itemId)); 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@110: 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@110: newRows = (newRows < 4 and 4) 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 Zerotorescue@110: Zerotorescue@110: function addon:SetFrameSettings(title, description, proceed, cancel, headers) Zerotorescue@110: local frame = InventoriumItemMover; Zerotorescue@110: Zerotorescue@110: frame.lblTitle:SetText(title); Zerotorescue@110: Zerotorescue@110: frame.lblDescription:SetText(description); Zerotorescue@110: Zerotorescue@110: frame.btnMove:SetText(proceed.text); Zerotorescue@110: frame.btnMove.tooltipTitle = proceed.tooltipTitle; Zerotorescue@110: frame.btnMove.tooltip = proceed.tooltip; Zerotorescue@110: frame.btnMove.OnClick = proceed.onClick; Zerotorescue@110: Zerotorescue@110: frame.btnCancel:SetText(cancel.text); Zerotorescue@110: frame.btnCancel.tooltipTitle = cancel.tooltipTitle; Zerotorescue@110: frame.btnCancel.tooltip = cancel.tooltip; Zerotorescue@110: frame.btnCancel.OnClick = cancel.onClick; Zerotorescue@110: Zerotorescue@110: frame.scrollTable:SetDisplayCols(headers); Zerotorescue@110: end