Thread Tools Display Modes
01-21-17, 05:45 PM   #1
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
A couple of questions

Hi,

I am doing a little addon that show in an ldb the last N loots so it is easier to whisper if you can trade the items.

But I am facing a couple of questions :

1) I have this code:

Lua Code:
  1. local function Button_OnClick(self, button, down)
  2.  
  3.     if button == "LeftButton" then
  4.  
  5.         SendChatMessage("Hey, do you mind to trade me " .. GMLM_REPORT[self.index]["loot"] .. " ?", "WHISPER", nil, GMLM_REPORT[self.index]["splayer"])
  6.  
  7.     elseif button == "RightButton" then
  8.    
  9.         -- Show loot: GMLM_REPORT[self.index]["loot"]
  10.         return
  11.        
  12.     end
  13.  
  14.     Menu:Hide()
  15.    
  16. end

I'd like to ask if there is something that can show the item frame like when we click on itemlink in the game.

2) The other question is:

With this code:

Lua Code:
  1. elseif event == "CHAT_MSG_LOOT" then
  2.    
  3.         local lootstring, _, _, _, player = ...
  4.        
  5.         local itemLink      = string.match(lootstring,"|%x+|Hitem:.-|h.-|h|r")
  6.         local itemString    = string.match(itemLink, "item[%-?%d:]+")
  7.         local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemString)

Is it possible that "class" is only localized ? Is there another way to know if the loot is an armour (for example) without have to deal with the language ?

Thanks to everyone for attention.


P.s.
This is the full code if someone wants to know:

Lua Code:
  1. local ADDON = ...
  2.  
  3. local fontName, fontHeight, fontFlags = GameFontNormal:GetFont()
  4.  
  5. local BUTTON_HEIGHT = fontHeight + 4
  6. local BUTTON_SPACING = 0
  7. local MENU_BUFFER = 10
  8. local MENU_SPACING = 1
  9. local MENU_WIDTH_EMPTY = 190
  10. local MENU_WIDTH = 350
  11.  
  12. local GMLM_REPORT = {}
  13.    
  14. local string_format = string.format
  15. local string_find = string.find
  16. local string_sub = string.sub
  17.  
  18. local function color(String)
  19.     if not UnitExists(String) then return string.format("\124cffff0000%s\124r", String) end
  20.     local _, class = UnitClass(String)
  21.     local color = _G["RAID_CLASS_COLORS"][class]
  22.     return string.format("\124cff%02x%02x%02x%s\124r", color.r*255, color.g*255, color.b*255, String)
  23. end
  24.  
  25. local Menu = CreateFrame('Frame', nil, UIParent)
  26. Menu:SetFrameStrata('TOOLTIP')
  27. Menu:SetClampedToScreen(true)
  28. Menu:SetBackdrop({
  29.     bgFile = "Interface/DialogFrame/UI-DialogBox-Background",
  30.     edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
  31.     tile = true, tileSize = 32, edgeSize = 16,
  32.     insets = { left = 3, right = 3, top = 3, bottom = 3 }
  33. })
  34. Menu:Hide()
  35.  
  36. local function Menu_OnLeave()
  37.     local focus = GetMouseFocus() or WorldFrame
  38.     if focus ~= Menu and focus:GetParent() ~= Menu then
  39.         Menu:Hide()
  40.     end
  41. end
  42. Menu:SetScript('OnLeave', Menu_OnLeave)
  43.  
  44. local header_desc = Menu:CreateFontString()
  45. header_desc:SetPoint("TOPLEFT", Menu, "TOPLEFT", MENU_BUFFER, -MENU_BUFFER)
  46. header_desc:SetFont(fontName, fontHeight)
  47. header_desc:SetTextColor(1, 1, 1, 1)
  48. header_desc:SetText("Latest 30 Loots:")
  49.  
  50. local rclick_desc = Menu:CreateFontString()
  51. rclick_desc:SetPoint("BOTTOMLEFT", Menu, "BOTTOMLEFT", MENU_BUFFER, MENU_BUFFER)
  52. rclick_desc:SetFont(fontName, fontHeight)
  53. rclick_desc:SetTextColor(0, 1, 0, 1)
  54. rclick_desc:SetText("Right-Click")
  55.  
  56. local rclick_value = Menu:CreateFontString()
  57. rclick_value:SetPoint("BOTTOMRIGHT", Menu, "BOTTOMRIGHT", -MENU_BUFFER, MENU_BUFFER)
  58. rclick_value:SetFont(fontName, fontHeight)
  59. rclick_value:SetTextColor(1, 0.8, 0, 1)
  60. rclick_value:SetText("Show Item")
  61.  
  62. local lclick_desc = Menu:CreateFontString()
  63. lclick_desc:SetPoint("BOTTOMLEFT", rclick_desc, "TOPLEFT", 0, MENU_SPACING)
  64. lclick_desc:SetFont(fontName, fontHeight)
  65. lclick_desc:SetTextColor(0, 1, 0, 1)
  66. lclick_desc:SetText("Left-Click")
  67.  
  68. local lclick_value = Menu:CreateFontString()
  69. lclick_value:SetPoint("BOTTOMRIGHT", rclick_value, "TOPRIGHT", 0, MENU_SPACING)
  70. lclick_value:SetFont(fontName, fontHeight)
  71. lclick_value:SetTextColor(1, 0.8, 0, 1)
  72. lclick_value:SetText("Whisper to ask")
  73.  
  74.  
  75. local dataobj = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject(ADDON, {
  76.     type = "data source",
  77.     icon = "Interface\\Icons\\INV_Misc_QuestionMark.blp",
  78.     text = ADDON,
  79.     OnClick = function(self, button)
  80.         if button == "LeftButton" then
  81.             Menu:SetShown(not Menu:IsShown())
  82.         elseif button == "RightButton" then
  83.             return
  84.         end
  85.     end,
  86.     OnEnter = function(self)
  87.         if not Menu:IsShown() then
  88.             local _, selfCenter = self:GetCenter()
  89.             local _, uiCenter = UIParent:GetCenter()
  90.             Menu:ClearAllPoints()
  91.             if selfCenter >= uiCenter then
  92.                 Menu:SetPoint('TOP', self, 'BOTTOM')
  93.             else
  94.                 Menu:SetPoint('BOTTOM', self, 'TOP')
  95.             end
  96.             Menu:Show()
  97.         end
  98.     end,
  99.     OnLeave = Menu_OnLeave
  100. })
  101.  
  102. local function Button_OnClick(self, button, down)
  103.  
  104.     if button == "LeftButton" then
  105.  
  106.         SendChatMessage("Hey, do you mind to trade me " .. GMLM_REPORT[self.index]["loot"] .. " ?", "WHISPER", nil, GMLM_REPORT[self.index]["splayer"])
  107.  
  108.     elseif button == "RightButton" then
  109.    
  110.         -- Show loot: GMLM_REPORT[self.index]["loot"]
  111.         return
  112.        
  113.     end
  114.  
  115.     Menu:Hide()
  116.    
  117. end
  118.  
  119. Menu:RegisterEvent('PLAYER_LOGIN')
  120. Menu:RegisterEvent('CHAT_MSG_LOOT')
  121. Menu:SetScript("OnEvent", function(self, event, ...)
  122.    
  123.    
  124.     if event == "PLAYER_LOGIN" then
  125.  
  126.         Menu:UnregisterEvent(event)
  127.        
  128.         for index = 1, 30 do
  129.        
  130.         local button = CreateFrame("Button", nil, Menu)
  131.         if index ~= 1 then
  132.             button:SetPoint("TOPLEFT", Menu[index - 1], "BOTTOMLEFT", 0, -BUTTON_SPACING)
  133.         else
  134.             button:SetPoint("TOPLEFT", header_desc, "BOTTOMLEFT", 0, -MENU_BUFFER)
  135.         end
  136.        
  137.         button:SetPoint("RIGHT", -MENU_BUFFER, 0)
  138.         button:SetHeight(BUTTON_HEIGHT)
  139.         button:SetNormalFontObject("GameFontNormal")
  140.         button:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
  141.         button.index = index
  142.         button:SetScript("OnClick", Button_OnClick)
  143.         button:SetScript("OnLeave", Menu_OnLeave)
  144.  
  145.         local text = button:CreateFontString(ADDON .. "btn_font", nil, "GameFontNormal")
  146.         text:SetAllPoints()
  147.         text:SetJustifyH("LEFT")
  148.         text:SetJustifyV("MIDDLE")
  149.         text:SetTextColor(1, 1, 1, 1)
  150.        
  151.         button:SetFontString(text)
  152.         button:SetText("")
  153.         button:Hide()
  154.        
  155.         Menu[index] = button
  156.        
  157.     end        
  158.        
  159.     Menu:SetSize(MENU_WIDTH, (MENU_BUFFER * 4) + (fontHeight * 3) + MENU_SPACING + ((BUTTON_HEIGHT + BUTTON_SPACING) - BUTTON_SPACING))
  160.                
  161.     elseif event == "CHAT_MSG_LOOT" then
  162.    
  163.         local lootstring, _, _, _, player = ...
  164.        
  165.         local itemLink      = string.match(lootstring,"|%x+|Hitem:.-|h.-|h|r")
  166.         local itemString    = string.match(itemLink, "item[%-?%d:]+")
  167.         local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemString)
  168.                
  169.         if player and quality >= 1 then
  170.        
  171.             if #GMLM_REPORT >= 30 then table.remove(GMLM_REPORT, 1) end
  172.        
  173.             GMLM_REPORT[#GMLM_REPORT+1] = {
  174.                 -- player       = "|Hplayer:"..player..":1:WHISPER:"..player.."|h["..color(player).."]|h",
  175.                 cplayer         = color(player),
  176.                 splayer         = player,
  177.                 loot            = itemLink,
  178.             }  
  179.        
  180.         end
  181.     end
  182.    
  183.     local numButtons = #GMLM_REPORT    
  184.     for index = 1, numButtons do
  185.  
  186.         Menu[index]:SetText("")
  187.         Menu[index]:SetText(GMLM_REPORT[index]["cplayer"] .. " " ..  GMLM_REPORT[index]["loot"])
  188.         Menu[index]:Show()
  189.  
  190.     end
  191.  
  192.     Menu:SetSize(MENU_WIDTH, (MENU_BUFFER * 4) + (fontHeight * 3) + MENU_SPACING + ((BUTTON_HEIGHT + BUTTON_SPACING) * numButtons - BUTTON_SPACING))
  193.    
  194. end)
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.

Last edited by gmarco : 01-21-17 at 05:49 PM.
  Reply With Quote
01-22-17, 06:04 AM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
1) To show static item tooltip:
Code:
ShowUIPanel(ItemRefTooltip)
if not ItemRefTooltip:IsShown() then
	ItemRefTooltip:SetOwner(UIParent, "ANCHOR_PRESERVE")
end
ItemRefTooltip:SetHyperlink(link)
2) Yes. There are additional returns that use IDs instead.
Code:
local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice, classID, subClassID = GetItemInfo(itemString)
Use with these:
https://www.townlong-yak.com/framexm...aEnum.lua#1226
Also, you can pass the entire item link to GetItemInfo, if you want.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
01-22-17, 11:30 PM   #3
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Thanks Lombra,
your suggestions work great !

Really thanks.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » A couple of questions


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off