public
Description: WoW Powerleveling addon
Homepage: http://www.tekkub.net/
Clone URL: git://github.com/tekkub/tourguide.git
Click here to lend your support to: tourguide and make a donation at www.pledgie.com !
tourguide / ItemButton.lua
100644 80 lines (62 sloc) 2.438 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
local TourGuide = TourGuide
local texture, item
 
 
local frame = CreateFrame("Button", "TourGuideItemFrame", UIParent, "SecureActionButtonTemplate")
frame:SetFrameStrata("LOW")
frame:SetHeight(36)
frame:SetWidth(36)
frame:SetPoint("BOTTOMRIGHT", MinimapCluster, "BOTTOMRIGHT", -192-62, -192+20)
frame:Hide()
 
local cooldown = CreateFrame("Cooldown", nil, frame)
cooldown:SetAllPoints(frame)
cooldown:Hide()
 
local function RefreshCooldown()
  if not item or not frame:IsVisible() then return end
  local start, duration, enabled = GetItemCooldown(item)
  if enabled then
    cooldown:Show()
    cooldown:SetCooldown(start, duration)
  else cooldown:Hide() end
end
cooldown:RegisterEvent("ACTIONBAR_UPDATE_COOLDOWN")
cooldown:SetScript("OnEvent", RefreshCooldown)
frame:SetScript("OnShow", RefreshCooldown)
 
 
local itemicon = frame:CreateTexture(nil, "ARTWORK")
itemicon:SetWidth(24) itemicon:SetHeight(24)
itemicon:SetTexture("Interface\\Icons\\INV_Misc_Bag_08")
itemicon:SetAllPoints(frame)
 
 
frame:RegisterForClicks("anyUp")
frame:HookScript("OnClick", function() if TourGuide:GetObjectiveInfo() == "USE" then TourGuide:SetTurnedIn() end end)
 
 
local function PLAYER_REGEN_ENABLED(self)
  if texture then
    itemicon:SetTexture(texture)
    frame:SetAttribute("type1", "item")
    frame:SetAttribute("item1", "item:"..item)
    frame:Show()
    texture = nil
  else
    frame:SetAttribute("item1", nil)
    frame:Hide()
  end
  self:UnregisterEvent("PLAYER_REGEN_ENABLED")
end
frame:SetScript("OnEvent", PLAYER_REGEN_ENABLED)
 
 
function TourGuide:SetUseItem(tex, use)
  texture, item = tex, use
  if InCombatLockdown() then frame:RegisterEvent("PLAYER_REGEN_ENABLED") else PLAYER_REGEN_ENABLED(frame) end
end
 
 
frame:RegisterForDrag("LeftButton")
frame:SetMovable(true)
frame:SetClampedToScreen(true)
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", function(frame)
  frame:StopMovingOrSizing()
  TourGuide.db.profile.itemframepoint, TourGuide.db.profile.itemframex, TourGuide.db.profile.itemframey = TourGuide.GetUIParentAnchor(frame)
  TourGuide:Debug(1, "Item frame moved", TourGuide.db.profile.itemframepoint, TourGuide.db.profile.itemframex, TourGuide.db.profile.itemframey)
end)
 
 
function TourGuide:PositionItemFrame()
  if self.db.profile.itemframepoint then
    frame:ClearAllPoints()
    frame:SetPoint(self.db.profile.itemframepoint, self.db.profile.itemframex, self.db.profile.itemframey)
  end
  self.PositionItemFrame = nil
end