annotate Frames.lua @ 119:dc6f405c1a5d

Now resizing the mover frame based on text size. addon.Locations table now uses location names as value, rather than random numbers. Added proper Merchant restocking support. Please note this currently doesn?t take the bonus queue nor the min crafting queue options into account.
author Zerotorescue
date Sat, 15 Jan 2011 17:03:05 +0100
parents 9765bc3b3d6b
children 8460855e3d90
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@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@119 92
Zerotorescue@119 93 frame.titleBackground = titleBackground;
Zerotorescue@119 94
Zerotorescue@101 95 local titleBackgroundLeft = frame:CreateTexture(nil, "OVERLAY");
Zerotorescue@101 96 titleBackgroundLeft:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header");
Zerotorescue@101 97 titleBackgroundLeft:SetTexCoord(0.21, 0.31, 0, 0.63);
Zerotorescue@101 98 titleBackgroundLeft:SetPoint("RIGHT", titleBackground, "LEFT");
Zerotorescue@101 99 titleBackgroundLeft:SetWidth(30);
Zerotorescue@101 100 titleBackgroundLeft:SetHeight(40);
Zerotorescue@101 101
Zerotorescue@101 102 local titleBackgroundRight = frame:CreateTexture(nil, "OVERLAY");
Zerotorescue@101 103 titleBackgroundRight:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header");
Zerotorescue@101 104 titleBackgroundRight:SetTexCoord(0.67, 0.77, 0, 0.63);
Zerotorescue@101 105 titleBackgroundRight:SetPoint("LEFT", titleBackground, "RIGHT");
Zerotorescue@101 106 titleBackgroundRight:SetWidth(30);
Zerotorescue@101 107 titleBackgroundRight:SetHeight(40);
Zerotorescue@101 108
Zerotorescue@101 109 local frmTitle = CreateFrame("Frame", nil, frame);
Zerotorescue@101 110 frmTitle:EnableMouse(true);
Zerotorescue@101 111 frmTitle:SetScript("OnMouseDown", function(this) this:GetParent():StartMoving(); end);
Zerotorescue@101 112 frmTitle:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end);
Zerotorescue@101 113 frmTitle:SetAllPoints(titleBackground);
Zerotorescue@101 114
Zerotorescue@101 115 local lblTitle = frmTitle:CreateFontString(nil, "OVERLAY", "GameFontNormal");
Zerotorescue@101 116 lblTitle:SetPoint("TOP", titleBackground, "TOP", 0, -14);
Zerotorescue@110 117
Zerotorescue@110 118 frame.lblTitle = lblTitle;
Zerotorescue@101 119
Zerotorescue@101 120 -- Resizer (vertical only)
Zerotorescue@101 121 local frmResizer = CreateFrame("Frame", nil, frame);
Zerotorescue@101 122 frmResizer:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 0, -10);
Zerotorescue@101 123 frmResizer:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, -10);
Zerotorescue@101 124 frmResizer:SetHeight(20);
Zerotorescue@101 125 frmResizer:EnableMouse();
Zerotorescue@101 126 frmResizer:SetScript("OnMouseDown", function(this) this:GetParent():StartSizing("BOTTOM"); end);
Zerotorescue@101 127 frmResizer:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end);
Zerotorescue@101 128
Zerotorescue@101 129 -- Description
Zerotorescue@101 130 local lblDescription = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal");
Zerotorescue@106 131 lblDescription:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -27);
Zerotorescue@104 132 lblDescription:SetWidth(frameWidth - 15 - 15); -- 10 margin left & 10 margin right
Zerotorescue@101 133 lblDescription:SetJustifyH("LEFT");
Zerotorescue@101 134 lblDescription:SetJustifyV("TOP");
Zerotorescue@101 135
Zerotorescue@101 136 frame.lblDescription = lblDescription;
Zerotorescue@101 137
Zerotorescue@101 138 -- Buttons
Zerotorescue@101 139 -- Move (proceed)
Zerotorescue@101 140 local btnMove = CreateFrame("Button", "$parentProceed", frame, "UIPanelButtonTemplate");
Zerotorescue@101 141 btnMove:SetHeight(21);
Zerotorescue@101 142 btnMove:SetWidth(125);
Zerotorescue@104 143 btnMove:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 15, 11);
Zerotorescue@101 144 btnMove:SetText("Move Items");
Zerotorescue@110 145 btnMove:SetScript("OnClick", function(this) this.OnClick(this); end);
Zerotorescue@101 146 btnMove:SetScript("OnEnter", ShowTooltip);
Zerotorescue@101 147 btnMove:SetScript("OnLeave", HideTooltip);
Zerotorescue@101 148
Zerotorescue@101 149 frame.btnMove = btnMove;
Zerotorescue@101 150
Zerotorescue@101 151 -- Cancel
Zerotorescue@101 152 local btnCancel = CreateFrame("Button", "$parentCancel", frame, "UIPanelButtonTemplate");
Zerotorescue@101 153 btnCancel:SetHeight(21);
Zerotorescue@101 154 btnCancel:SetWidth(125);
Zerotorescue@104 155 btnCancel:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 11);
Zerotorescue@110 156 btnCancel:SetScript("OnClick", function(this) this.OnClick(this); end);
Zerotorescue@101 157 btnCancel:SetScript("OnEnter", ShowTooltip);
Zerotorescue@101 158 btnCancel:SetScript("OnLeave", HideTooltip);
Zerotorescue@101 159
Zerotorescue@101 160 frame.btnCancel = btnCancel;
Zerotorescue@101 161
Zerotorescue@101 162 -- 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 163 local frmMeasureDummy = CreateFrame("Frame", nil, frame);
Zerotorescue@106 164 frmMeasureDummy:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -18);
Zerotorescue@106 165 frmMeasureDummy:SetPoint("LEFT", frame, "LEFT", 15, 0);
Zerotorescue@104 166 frmMeasureDummy:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35);
Zerotorescue@101 167
Zerotorescue@101 168 frame.frmMeasureDummy = frmMeasureDummy;
Zerotorescue@101 169
Zerotorescue@101 170 -- Scrolling table with a list of items to be moved
Zerotorescue@101 171 local ScrollingTable = LibStub("ScrollingTable");
Zerotorescue@110 172 local table = ScrollingTable:CreateST({}, 4, 15, nil, frame); -- inserting a dummy cols, real cols to be set in SetFrameSettings
Zerotorescue@110 173 table.frame:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -18);
Zerotorescue@110 174 table.frame:SetPoint("LEFT", frame, "LEFT", 15, 0);
Zerotorescue@110 175 table.frame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35);
Zerotorescue@106 176 -- When moving over a row, provide a tooltip for the item
Zerotorescue@101 177 table:RegisterEvents({
Zerotorescue@101 178 ["OnEnter"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
Zerotorescue@106 179 if row and realrow then
Zerotorescue@106 180 -- Data row
Zerotorescue@106 181
Zerotorescue@112 182 if data[realrow] and data[realrow].rowData and data[realrow].rowData.itemId then
Zerotorescue@106 183 GameTooltip:SetOwner(rowFrame, "ANCHOR_NONE");
Zerotorescue@106 184 GameTooltip:SetPoint("TOPLEFT", rowFrame, "BOTTOMLEFT");
Zerotorescue@112 185 GameTooltip:SetHyperlink(("item:%d"):format(data[realrow].rowData.itemId));
Zerotorescue@106 186 GameTooltip:Show();
Zerotorescue@106 187 end
Zerotorescue@106 188 else
Zerotorescue@106 189 -- Header row
Zerotorescue@106 190
Zerotorescue@106 191 if cols[column].tooltipTitle and type(cols[column].tooltipTitle) == "string" then
Zerotorescue@106 192 cellFrame.tooltipTitle = cols[column].tooltipTitle;
Zerotorescue@106 193 if cols[column].tooltip then
Zerotorescue@106 194 cellFrame.tooltip = cols[column].tooltip; -- Optional
Zerotorescue@106 195 else
Zerotorescue@106 196 cellFrame.tooltip = nil;
Zerotorescue@106 197 end
Zerotorescue@106 198
Zerotorescue@106 199 ShowTooltip(cellFrame);
Zerotorescue@106 200 end
Zerotorescue@101 201 end
Zerotorescue@101 202 end,
Zerotorescue@101 203 ["OnLeave"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
Zerotorescue@106 204 HideTooltip();
Zerotorescue@101 205 end,
Zerotorescue@101 206 });
Zerotorescue@101 207
Zerotorescue@101 208 frame.scrollTable = table;
Zerotorescue@110 209
Zerotorescue@106 210 -- Change the amount of displayed rows based on the size of the frame
Zerotorescue@106 211 frame.AdjustScrollTableRows = function(this)
Zerotorescue@106 212 local newRows = math.floor(( this.frmMeasureDummy:GetHeight() - 5 ) / 15);
Zerotorescue@110 213 newRows = (newRows < 4 and 4) or newRows;
Zerotorescue@106 214
Zerotorescue@106 215 this.scrollTable:SetDisplayRows(newRows, 15);
Zerotorescue@106 216 end;
Zerotorescue@106 217 frame:SetScript("OnSizeChanged", frame.AdjustScrollTableRows);
Zerotorescue@101 218 end
Zerotorescue@101 219
Zerotorescue@101 220 function addon:SetMoverFrameData(data)
Zerotorescue@101 221 InventoriumItemMover.scrollTable:SetData(data);
Zerotorescue@101 222
Zerotorescue@101 223 InventoriumItemMover:Show();
Zerotorescue@101 224 end
Zerotorescue@110 225
Zerotorescue@110 226 function addon:SetFrameSettings(title, description, proceed, cancel, headers)
Zerotorescue@110 227 local frame = InventoriumItemMover;
Zerotorescue@110 228
Zerotorescue@110 229 frame.lblTitle:SetText(title);
Zerotorescue@119 230 -- Adjust size for the title background
Zerotorescue@119 231 frame.titleBackground:SetWidth((frame.lblTitle:GetWidth() or 0) + 10); -- 10 pixels margin
Zerotorescue@110 232
Zerotorescue@110 233 frame.lblDescription:SetText(description);
Zerotorescue@110 234
Zerotorescue@110 235 frame.btnMove:SetText(proceed.text);
Zerotorescue@110 236 frame.btnMove.tooltipTitle = proceed.tooltipTitle;
Zerotorescue@110 237 frame.btnMove.tooltip = proceed.tooltip;
Zerotorescue@110 238 frame.btnMove.OnClick = proceed.onClick;
Zerotorescue@110 239
Zerotorescue@110 240 frame.btnCancel:SetText(cancel.text);
Zerotorescue@110 241 frame.btnCancel.tooltipTitle = cancel.tooltipTitle;
Zerotorescue@110 242 frame.btnCancel.tooltip = cancel.tooltip;
Zerotorescue@110 243 frame.btnCancel.OnClick = cancel.onClick;
Zerotorescue@110 244
Zerotorescue@110 245 frame.scrollTable:SetDisplayCols(headers);
Zerotorescue@110 246 end