local ADDON = ...
local fontName, fontHeight, fontFlags = GameFontNormal:GetFont()
local BUTTON_HEIGHT = fontHeight + 4
local BUTTON_SPACING = 0
local MENU_BUFFER = 10
local MENU_SPACING = 1
local MENU_WIDTH_EMPTY = 190
local MENU_WIDTH = 350
local GMLM_REPORT = {}
local string_format = string.format
local string_find = string.find
local string_sub = string.sub
local function color(String)
if not UnitExists(String) then return string.format("\124cffff0000%s\124r", String) end
local _, class = UnitClass(String)
local color = _G["RAID_CLASS_COLORS"][class]
return string.format("\124cff%02x%02x%02x%s\124r", color.r*255, color.g*255, color.b*255, String)
end
local Menu = CreateFrame('Frame', nil, UIParent)
Menu:SetFrameStrata('TOOLTIP')
Menu:SetClampedToScreen(true)
Menu:SetBackdrop({
bgFile = "Interface/DialogFrame/UI-DialogBox-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tileSize = 32, edgeSize = 16,
insets = { left = 3, right = 3, top = 3, bottom = 3 }
})
Menu:Hide()
local function Menu_OnLeave()
local focus = GetMouseFocus() or WorldFrame
if focus ~= Menu and focus:GetParent() ~= Menu then
Menu:Hide()
end
end
Menu:SetScript('OnLeave', Menu_OnLeave)
local header_desc = Menu:CreateFontString()
header_desc:SetPoint("TOPLEFT", Menu, "TOPLEFT", MENU_BUFFER, -MENU_BUFFER)
header_desc:SetFont(fontName, fontHeight)
header_desc:SetTextColor(1, 1, 1, 1)
header_desc:SetText("Latest 30 Loots:")
local rclick_desc = Menu:CreateFontString()
rclick_desc:SetPoint("BOTTOMLEFT", Menu, "BOTTOMLEFT", MENU_BUFFER, MENU_BUFFER)
rclick_desc:SetFont(fontName, fontHeight)
rclick_desc:SetTextColor(0, 1, 0, 1)
rclick_desc:SetText("Right-Click")
local rclick_value = Menu:CreateFontString()
rclick_value:SetPoint("BOTTOMRIGHT", Menu, "BOTTOMRIGHT", -MENU_BUFFER, MENU_BUFFER)
rclick_value:SetFont(fontName, fontHeight)
rclick_value:SetTextColor(1, 0.8, 0, 1)
rclick_value:SetText("Show Item")
local lclick_desc = Menu:CreateFontString()
lclick_desc:SetPoint("BOTTOMLEFT", rclick_desc, "TOPLEFT", 0, MENU_SPACING)
lclick_desc:SetFont(fontName, fontHeight)
lclick_desc:SetTextColor(0, 1, 0, 1)
lclick_desc:SetText("Left-Click")
local lclick_value = Menu:CreateFontString()
lclick_value:SetPoint("BOTTOMRIGHT", rclick_value, "TOPRIGHT", 0, MENU_SPACING)
lclick_value:SetFont(fontName, fontHeight)
lclick_value:SetTextColor(1, 0.8, 0, 1)
lclick_value:SetText("Whisper to ask")
local dataobj = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject(ADDON, {
type = "data source",
icon = "Interface\\Icons\\INV_Misc_QuestionMark.blp",
text = ADDON,
OnClick = function(self, button)
if button == "LeftButton" then
Menu:SetShown(not Menu:IsShown())
elseif button == "RightButton" then
return
end
end,
OnEnter = function(self)
if not Menu:IsShown() then
local _, selfCenter = self:GetCenter()
local _, uiCenter = UIParent:GetCenter()
Menu:ClearAllPoints()
if selfCenter >= uiCenter then
Menu:SetPoint('TOP', self, 'BOTTOM')
else
Menu:SetPoint('BOTTOM', self, 'TOP')
end
Menu:Show()
end
end,
OnLeave = Menu_OnLeave
})
local function Button_OnClick(self, button, down)
if button == "LeftButton" then
SendChatMessage("Hey, do you mind to trade me " .. GMLM_REPORT[self.index]["loot"] .. " ?", "WHISPER", nil, GMLM_REPORT[self.index]["splayer"])
elseif button == "RightButton" then
-- Show loot: GMLM_REPORT[self.index]["loot"]
return
end
Menu:Hide()
end
Menu:RegisterEvent('PLAYER_LOGIN')
Menu:RegisterEvent('CHAT_MSG_LOOT')
Menu:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_LOGIN" then
Menu:UnregisterEvent(event)
for index = 1, 30 do
local button = CreateFrame("Button", nil, Menu)
if index ~= 1 then
button:SetPoint("TOPLEFT", Menu[index - 1], "BOTTOMLEFT", 0, -BUTTON_SPACING)
else
button:SetPoint("TOPLEFT", header_desc, "BOTTOMLEFT", 0, -MENU_BUFFER)
end
button:SetPoint("RIGHT", -MENU_BUFFER, 0)
button:SetHeight(BUTTON_HEIGHT)
button:SetNormalFontObject("GameFontNormal")
button:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
button.index = index
button:SetScript("OnClick", Button_OnClick)
button:SetScript("OnLeave", Menu_OnLeave)
local text = button:CreateFontString(ADDON .. "btn_font", nil, "GameFontNormal")
text:SetAllPoints()
text:SetJustifyH("LEFT")
text:SetJustifyV("MIDDLE")
text:SetTextColor(1, 1, 1, 1)
button:SetFontString(text)
button:SetText("")
button:Hide()
Menu[index] = button
end
Menu:SetSize(MENU_WIDTH, (MENU_BUFFER * 4) + (fontHeight * 3) + MENU_SPACING + ((BUTTON_HEIGHT + BUTTON_SPACING) - BUTTON_SPACING))
elseif event == "CHAT_MSG_LOOT" then
local lootstring, _, _, _, player = ...
local itemLink = string.match(lootstring,"|%x+|Hitem:.-|h.-|h|r")
local itemString = string.match(itemLink, "item[%-?%d:]+")
local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemString)
if player and quality >= 1 then
if #GMLM_REPORT >= 30 then table.remove(GMLM_REPORT, 1) end
GMLM_REPORT[#GMLM_REPORT+1] = {
-- player = "|Hplayer:"..player..":1:WHISPER:"..player.."|h["..color(player).."]|h",
cplayer = color(player),
splayer = player,
loot = itemLink,
}
end
end
local numButtons = #GMLM_REPORT
for index = 1, numButtons do
Menu[index]:SetText("")
Menu[index]:SetText(GMLM_REPORT[index]["cplayer"] .. " " .. GMLM_REPORT[index]["loot"])
Menu[index]:Show()
end
Menu:SetSize(MENU_WIDTH, (MENU_BUFFER * 4) + (fontHeight * 3) + MENU_SPACING + ((BUTTON_HEIGHT + BUTTON_SPACING) * numButtons - BUTTON_SPACING))
end)