local addonName, addon = ...
local CELL_WIDTH = 400
local CELL_HEIGHT = 80
local NUM_CELLS = 2
-- name and icon (and link) set by LoadItem() when the item is cached.
addon.db = {
{
-- name = "Emerald Mark of Mastery",
questID = 75612,
-- icon = "interface/icons/inv_mushroom_11",
item = 6218,
announce = {
enUS = "Awarded for outstanding service to Dragonkind. %s %s Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts"
}
},
{
-- name = "Emerald Mark of Mastery",
questID = 75624,
-- icon = "interface/icons/inv_mushroom_11",
item = 20897,
announce = {
enUS = "Awarded for outstanding service to Dragonkind. %s %s Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts\n\nAwarded for outstanding service to (clickable link to the item) Dragonkind. Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts"
}
},
{
-- name = "Emerald Mark of Mastery",
questID = 74352,
item = 193440,
-- icon = "interface/icons/inv_mushroom_11",
announce = {
enUS = "Awarded for outstanding service to Dragonkind. %s %s Bring it to Theozhaklos the Curious at the Wellspring Overlook in the Emerald Dream to receive powerful equipment for your efforts"
}
}
}
local function OnHyperlinkClick(self, link, text, region, left, bottom, width, heigh) -- function to print the link when clicked
print("You just clickled:", text)
end
local function OnHyperlinkEnter(self, link, text, region, left, bottom, width, height) -- function to display the hyperlink on mouse over
GameTooltip:SetOwner(self, "ANCHOR_CURSOR_RIGHT")
GameTooltip:SetHyperlink(link)
GameTooltip:Show()
end
local function OnHyperlinkLeave(self) -- function to hide the hyperlink on mouse exit
GameTooltip:Hide()
end
local function LoadItem(item) -- adds the item to the bd overwriting the icon, name ans sedtting the itemlink keys
addon.db[item.dbID].name = item:GetItemName()
addon.db[item.dbID].icon = "|T"..item:GetItemIcon()..":20:20|t" -- make icon size 20x20
addon.db[item.dbID].itemlink = item:GetItemLink()
print(addon.db[item.dbID].name, addon.db[item.dbID].icon, addon.db[item.dbID].itemlink)
end
for i, v in ipairs(addon.db) do -- Get the item information and call LoadItem when it's returned from the server and cached
local item = Item:CreateFromItemID(v.item)
item.dbID = i
item:ContinueOnItemLoad(function() LoadItem(item) end)
end
local data = {}
local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")
f.Title = f:CreateFontString()
f.Title:SetFontObject(GameFontNormal)
f.Title:SetPoint("TOP", 0, -5)
f.Title:SetText(addonName)
-- Create the button here
local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
local function updateData() --commented out because addon.db hasn't been created... in the code at least
wipe(data)
for _, item in ipairs(addon.db) do
tinsert(data, {text=item.announce[GetLocale()], icon=item.icon, name=item.name, link=item.itemlink})
end
end
f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600)
f:SetPoint("CENTER")
f:Hide()
f:SetMovable(true)
f:SetScript("OnMouseDown", f.StartMoving)
f:SetScript("OnMouseUp", f.StopMovingOrSizing)
-- I added this OnHide script
f:SetScript("OnHide", function()
btn:Show()
end)
f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
f.scrollFrame:SetPoint("TOPLEFT", 12, -32)
f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame)
f.scrollFrame.scrollChild:SetSize(100, 100)
f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5)
f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild)
local content = f.scrollFrame.scrollChild
content.rows = {}
local function updateList()
for i = 1, #data do
if not content.rows[i] then
local button = CreateFrame("Button", nil, content)
button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT)
button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT)
button:SetHyperlinksEnabled(true) -- Setup hyperlinking for each row
button:SetScript("OnHyperlinkClick", OnHyperlinkClick)
button:SetScript("OnHyperlinkEnter", OnHyperlinkEnter)
button:SetScript("OnHyperlinkLeave", OnHyperlinkLeave)
button.columns = {}
button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
button.columns[1]:SetJustifyH("LEFT")
button.columns[1]:SetJustifyV("TOP")
-- button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0)
button.columns[1]:SetPoint("TOPLEFT")
button.columns[1]:SetPoint("BOTTOMRIGHT", button, "BOTTOMLEFT", 140, 0)
-- Replaced the icon texture with the icon embedded in the description string.
-- button.columns[2] = button:CreateTexture()
-- button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
-- button.columns[2]:SetPoint("LEFT", button.columns[1], "RIGHT")
button.columns[2] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
button.columns[2]:SetJustifyH("LEFT")
button.columns[2]:SetJustifyV("TOP")
-- button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
button.columns[2]:SetPoint("TOPLEFT", button.columns[1], "TOPRIGHT", 5, 0)
button.columns[2]:SetPoint("BOTTOMRIGHT", button)
content.rows[i] = button
end
content.rows[i].columns[1]:SetText(data[i].name)
-- content.rows[i].columns[2]:SetTexture(data[i][2])
content.rows[i].columns[2]:SetText(format(data[i].text, data[i].icon, data[i].link)) -- insert the icon and hyperlink into the text
content.rows[i]:Show()
end
for i = #data + 1, #content.rows do
content.rows[i]:Hide()
end
end
-- Set your button options here
local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
btn:SetPoint("CENTER")
btn:SetSize(100, 40)
btn:SetText("Click me")
btn:SetMovable(true)
btn:RegisterForDrag('LeftButton')
btn:RegisterForClicks("AnyDown", "AnyUp")
btn:SetUserPlaced(true)
btn:SetScript('OnDragStart', function(self, button, down)
if button == "LeftButton" and IsShiftKeyDown() then
self:StartMoving()
end
end)
btn:SetScript('OnDragStop', function(self)
self:StopMovingOrSizing()
end)
btn:SetScript("OnMouseUp", function(self, button, ...)
if (button == "RightButton" and self:IsVisible()) then
self:Hide()
elseif button == "LeftButton" and not IsShiftKeyDown() then
updateData()
updateList()
f:Show()
end
end)
SLASH_HUBB1 = "/hubb"
SlashCmdList["HUBB"] = function(msg)
if strupper(strtrim(msg)) == "BTN" then -- toggle the shown state of the button if the type /hubb btn
btn:SetShown(not btn:IsShown()) -- show the button
return
end
updateData()
updateList()
f:Show()
end