annotate Frames.lua @ 104:8502f02bf543

Increased edge size to make them more visible. Item mover window is no longer setting point to itself. Lowered description position so it doesn?t overlap the title.
author Zerotorescue
date Tue, 11 Jan 2011 23:13:40 +0100
parents 6ae44d372360
children d3fbb5676a5e
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@101 7 GameTooltip:SetOwner(this, "ANCHOR_NONE");
Zerotorescue@104 8 if this.tooltipLocation and this.tooltipLocation == "BOTTOM" then
Zerotorescue@104 9 GameTooltip:SetPoint("TOP", this, "BOTTOM");
Zerotorescue@101 10 else
Zerotorescue@101 11 GameTooltip:SetPoint("BOTTOM", this, "TOP");
Zerotorescue@101 12 end
Zerotorescue@101 13 GameTooltip:SetText(this.tooltipTitle, 1, .82, 0, 1);
Zerotorescue@101 14
Zerotorescue@101 15 if type(this.tooltip) == "string" then
Zerotorescue@101 16 GameTooltip:AddLine(this.tooltip, 1, 1, 1, 1);
Zerotorescue@101 17 end
Zerotorescue@101 18
Zerotorescue@101 19 GameTooltip:Show();
Zerotorescue@101 20 end
Zerotorescue@101 21
Zerotorescue@101 22 local function HideTooltip()
Zerotorescue@101 23 GameTooltip:Hide();
Zerotorescue@101 24 end
Zerotorescue@101 25
Zerotorescue@101 26 function addon:CreateMoverFrame(onAccept, onCancel)
Zerotorescue@101 27 local frameWidth = 400;
Zerotorescue@101 28
Zerotorescue@101 29 -- Main window
Zerotorescue@101 30 local frame = CreateFrame("Frame", "InventoriumItemMover", UIParent);
Zerotorescue@101 31 -- Hide by default
Zerotorescue@101 32 frame:Hide();
Zerotorescue@101 33 -- Center the frame (will be adjusted later)
Zerotorescue@101 34 frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
Zerotorescue@101 35 -- Put in front of other windows
Zerotorescue@101 36 frame:SetFrameStrata("FULLSCREEN_DIALOG");
Zerotorescue@101 37 frame:SetToplevel(true);
Zerotorescue@101 38 -- Give it a size
Zerotorescue@101 39 frame:SetWidth(frameWidth);
Zerotorescue@101 40 frame:SetHeight(175);
Zerotorescue@101 41 -- Background
Zerotorescue@101 42 frame:SetBackdrop({
Zerotorescue@101 43 bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
Zerotorescue@101 44 edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
Zerotorescue@104 45 edgeSize = 20,
Zerotorescue@101 46 insets = {
Zerotorescue@101 47 left = 5,
Zerotorescue@101 48 right = 5,
Zerotorescue@101 49 top = 5,
Zerotorescue@101 50 bottom = 5,
Zerotorescue@101 51 },
Zerotorescue@101 52 });
Zerotorescue@101 53 frame:SetBackdropColor(0, 0, 0, .8);
Zerotorescue@101 54 -- Mouse functions
Zerotorescue@101 55 frame:EnableMouse();
Zerotorescue@101 56 frame:SetMovable(true);
Zerotorescue@101 57 frame:SetResizable(true);
Zerotorescue@101 58 frame:SetMinResize(300, 175);
Zerotorescue@101 59 -- Set event handlers
Zerotorescue@101 60 frame:SetScript("OnMouseUp", function(this) this:StopMovingOrSizing(); end);
Zerotorescue@101 61 frame:SetScript("OnShow", function(this)
Zerotorescue@104 62 if not tContains(StaticPopup_DisplayedFrames, this) then
Zerotorescue@104 63 -- 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 64 local lastFrame = StaticPopup_DisplayedFrames[#StaticPopup_DisplayedFrames];
Zerotorescue@104 65 if lastFrame then
Zerotorescue@104 66 this:SetPoint("TOP", lastFrame, "BOTTOM", 0, 0);
Zerotorescue@104 67 else
Zerotorescue@104 68 this:SetPoint("TOP", UIParent, "TOP", 0, -135);
Zerotorescue@104 69 end
Zerotorescue@104 70
Zerotorescue@104 71 -- Position other static popups below this
Zerotorescue@104 72 tinsert(StaticPopup_DisplayedFrames, this);
Zerotorescue@101 73 end
Zerotorescue@101 74
Zerotorescue@101 75 this:AdjustScrollTableRows();
Zerotorescue@101 76
Zerotorescue@101 77 PlaySound("OrcExploration");
Zerotorescue@101 78 end);
Zerotorescue@101 79
Zerotorescue@101 80 -- Title (AceGUI frame-widget-title used as example)
Zerotorescue@101 81 local titleBackground = frame:CreateTexture(nil, "OVERLAY");
Zerotorescue@101 82 titleBackground:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header");
Zerotorescue@101 83 titleBackground:SetTexCoord(0.31, 0.67, 0, 0.63);
Zerotorescue@101 84 titleBackground:SetPoint("TOP", 0, 12);
Zerotorescue@101 85 titleBackground:SetWidth(150);
Zerotorescue@101 86 titleBackground:SetHeight(40);
Zerotorescue@101 87
Zerotorescue@101 88 local titleBackgroundLeft = frame:CreateTexture(nil, "OVERLAY");
Zerotorescue@101 89 titleBackgroundLeft:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header");
Zerotorescue@101 90 titleBackgroundLeft:SetTexCoord(0.21, 0.31, 0, 0.63);
Zerotorescue@101 91 titleBackgroundLeft:SetPoint("RIGHT", titleBackground, "LEFT");
Zerotorescue@101 92 titleBackgroundLeft:SetWidth(30);
Zerotorescue@101 93 titleBackgroundLeft:SetHeight(40);
Zerotorescue@101 94
Zerotorescue@101 95 local titleBackgroundRight = frame:CreateTexture(nil, "OVERLAY");
Zerotorescue@101 96 titleBackgroundRight:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header");
Zerotorescue@101 97 titleBackgroundRight:SetTexCoord(0.67, 0.77, 0, 0.63);
Zerotorescue@101 98 titleBackgroundRight:SetPoint("LEFT", titleBackground, "RIGHT");
Zerotorescue@101 99 titleBackgroundRight:SetWidth(30);
Zerotorescue@101 100 titleBackgroundRight:SetHeight(40);
Zerotorescue@101 101
Zerotorescue@101 102 local frmTitle = CreateFrame("Frame", nil, frame);
Zerotorescue@101 103 frmTitle:EnableMouse(true);
Zerotorescue@101 104 frmTitle:SetScript("OnMouseDown", function(this) this:GetParent():StartMoving(); end);
Zerotorescue@101 105 frmTitle:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end);
Zerotorescue@101 106 frmTitle:SetAllPoints(titleBackground);
Zerotorescue@101 107
Zerotorescue@101 108 local lblTitle = frmTitle:CreateFontString(nil, "OVERLAY", "GameFontNormal");
Zerotorescue@101 109 lblTitle:SetPoint("TOP", titleBackground, "TOP", 0, -14);
Zerotorescue@101 110 lblTitle:SetText("Inventorium Bank Refill");
Zerotorescue@101 111
Zerotorescue@101 112 -- Resizer (vertical only)
Zerotorescue@101 113 local frmResizer = CreateFrame("Frame", nil, frame);
Zerotorescue@101 114 frmResizer:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 0, -10);
Zerotorescue@101 115 frmResizer:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, -10);
Zerotorescue@101 116 frmResizer:SetHeight(20);
Zerotorescue@101 117 frmResizer:EnableMouse();
Zerotorescue@101 118 frmResizer:SetScript("OnMouseDown", function(this) this:GetParent():StartSizing("BOTTOM"); end);
Zerotorescue@101 119 frmResizer:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end);
Zerotorescue@101 120
Zerotorescue@101 121 -- Description
Zerotorescue@101 122 local lblDescription = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal");
Zerotorescue@104 123 lblDescription:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -25);
Zerotorescue@104 124 lblDescription:SetWidth(frameWidth - 15 - 15); -- 10 margin left & 10 margin right
Zerotorescue@101 125 lblDescription:SetJustifyH("LEFT");
Zerotorescue@101 126 lblDescription:SetJustifyV("TOP");
Zerotorescue@101 127 lblDescription:SetText("The items listed below can be refilled from this location, do you wish to move them to your bags?");
Zerotorescue@101 128
Zerotorescue@101 129 frame.lblDescription = lblDescription;
Zerotorescue@101 130
Zerotorescue@101 131 -- Buttons
Zerotorescue@101 132 -- Move (proceed)
Zerotorescue@101 133 local btnMove = CreateFrame("Button", "$parentProceed", frame, "UIPanelButtonTemplate");
Zerotorescue@101 134 btnMove:SetHeight(21);
Zerotorescue@101 135 btnMove:SetWidth(125);
Zerotorescue@104 136 btnMove:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 15, 11);
Zerotorescue@101 137 btnMove:SetText("Move Items");
Zerotorescue@101 138 btnMove:SetScript("OnClick", onAccept);
Zerotorescue@101 139 btnMove:SetScript("OnEnter", ShowTooltip);
Zerotorescue@101 140 btnMove:SetScript("OnLeave", HideTooltip);
Zerotorescue@101 141 btnMove.tooltipTitle = "Move Items";
Zerotorescue@101 142 btnMove.tooltip = "Start moving these items from the bank.";
Zerotorescue@101 143
Zerotorescue@101 144 frame.btnMove = btnMove;
Zerotorescue@101 145
Zerotorescue@101 146 -- Cancel
Zerotorescue@101 147 local btnCancel = CreateFrame("Button", "$parentCancel", frame, "UIPanelButtonTemplate");
Zerotorescue@101 148 btnCancel:SetHeight(21);
Zerotorescue@101 149 btnCancel:SetWidth(125);
Zerotorescue@104 150 btnCancel:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 11);
Zerotorescue@101 151 btnCancel:SetText("Cancel");
Zerotorescue@101 152 btnCancel:SetScript("OnClick", onCancel);
Zerotorescue@101 153 btnCancel:SetScript("OnEnter", ShowTooltip);
Zerotorescue@101 154 btnCancel:SetScript("OnLeave", HideTooltip);
Zerotorescue@101 155 btnCancel.tooltipTitle = "Cancel";
Zerotorescue@101 156 btnCancel.tooltip = "Do not move anything and close the window.";
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@101 162 frmMeasureDummy:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -20);
Zerotorescue@104 163 frmMeasureDummy:SetPoint("LEFT", frame.lblDescription, "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 scrollTableWidth = ( frame.frmMeasureDummy:GetWidth() - 20 ); -- adjust width by the scrollbar size
Zerotorescue@101 170 local headers = {
Zerotorescue@101 171 {
Zerotorescue@101 172 ["name"] = "Item",
Zerotorescue@101 173 ["width"] = (scrollTableWidth * .5),
Zerotorescue@101 174 ["defaultsort"] = "asc",
Zerotorescue@101 175 ["comparesort"] = function(this, aRow, bRow, column)
Zerotorescue@101 176 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).colorargs[2]);
Zerotorescue@101 177 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).colorargs[2]);
Zerotorescue@101 178 local template = "%d%s";
Zerotorescue@101 179 aName = template:format((10 - (aRarity or 10)), (aName or ""):lower());
Zerotorescue@101 180 bName = template:format((10 - (bRarity or 10)), (bName or ""):lower());
Zerotorescue@101 181
Zerotorescue@101 182 if this.cols[column].sort == "dsc" then
Zerotorescue@101 183 return aName > bName;
Zerotorescue@101 184 else
Zerotorescue@101 185 return aName < bName;
Zerotorescue@101 186 end
Zerotorescue@101 187 end,
Zerotorescue@101 188 ["sort"] = "asc", -- when the data is set, use this column so sort the default data
Zerotorescue@101 189 },
Zerotorescue@101 190 {
Zerotorescue@101 191 ["name"] = "Moving",
Zerotorescue@101 192 ["width"] = (scrollTableWidth * .15),
Zerotorescue@101 193 ["defaultsort"] = "dsc",
Zerotorescue@101 194 },
Zerotorescue@101 195 {
Zerotorescue@101 196 ["name"] = "Missing",
Zerotorescue@101 197 ["width"] = (scrollTableWidth * .15),
Zerotorescue@101 198 ["defaultsort"] = "dsc",
Zerotorescue@101 199 },
Zerotorescue@101 200 {
Zerotorescue@101 201 ["name"] = "Available",
Zerotorescue@101 202 ["width"] = (scrollTableWidth * .2),
Zerotorescue@101 203 ["defaultsort"] = "dsc",
Zerotorescue@101 204 },
Zerotorescue@101 205 };
Zerotorescue@101 206
Zerotorescue@101 207 local ScrollingTable = LibStub("ScrollingTable");
Zerotorescue@101 208 local table = ScrollingTable:CreateST(headers, 3, 15, nil, frame);
Zerotorescue@101 209 table:RegisterEvents({
Zerotorescue@101 210 ["OnEnter"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
Zerotorescue@101 211 if row and realrow and data[realrow] and data[realrow].colorargs and data[realrow].colorargs[2] then
Zerotorescue@101 212 GameTooltip:SetOwner(rowFrame, "ANCHOR_NONE");
Zerotorescue@101 213 GameTooltip:SetPoint("TOPLEFT", rowFrame, "BOTTOMLEFT");
Zerotorescue@101 214 GameTooltip:SetHyperlink(("item:%d"):format(data[realrow].colorargs[2]));
Zerotorescue@101 215 GameTooltip:Show();
Zerotorescue@101 216 end
Zerotorescue@101 217 end,
Zerotorescue@101 218 ["OnLeave"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
Zerotorescue@101 219 if row and realrow then
Zerotorescue@101 220 HideTooltip();
Zerotorescue@101 221 end
Zerotorescue@101 222 end,
Zerotorescue@101 223 });
Zerotorescue@101 224
Zerotorescue@101 225 frame.scrollTable = table;
Zerotorescue@101 226 table.frame:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -20);
Zerotorescue@104 227 table.frame:SetPoint("LEFT", frame, "LEFT", 15, 0);
Zerotorescue@104 228 table.frame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 35);
Zerotorescue@101 229
Zerotorescue@101 230 -- Change the amount of displayed rows based on the size of the frame
Zerotorescue@101 231 frame.AdjustScrollTableRows = function(this)
Zerotorescue@101 232 local newRows = math.floor(( this.frmMeasureDummy:GetHeight() - 5 ) / 15);
Zerotorescue@101 233 newRows = (newRows < 3 and 3) or newRows;
Zerotorescue@101 234
Zerotorescue@101 235 this.scrollTable:SetDisplayRows(newRows, 15);
Zerotorescue@101 236 end;
Zerotorescue@101 237 frame:SetScript("OnSizeChanged", frame.AdjustScrollTableRows);
Zerotorescue@101 238 end
Zerotorescue@101 239
Zerotorescue@101 240 function addon:SetMoverFrameData(data)
Zerotorescue@101 241 InventoriumItemMover.scrollTable:SetData(data);
Zerotorescue@101 242
Zerotorescue@101 243 InventoriumItemMover:Show();
Zerotorescue@101 244 end