vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Utility.lua
3 bgn_atBank is a global completely controled by Banknon
4 --]]
5  
6 local currentPlayer = UnitName("player");
7  
8 --[[
9 Boolean functions
10 --]]
11  
12 function IsAddOnEnabled(addon)
13 local _, _, _, enabled = GetAddOnInfo(addon);
14 return enabled;
15 end
16  
17 function Bagnon_IsInventoryBag(bagID)
18 return (bagID >= 0 and bagID < 5);
19 end
20  
21 function Bagnon_IsBankBag(bagID)
22 return ( bagID == -1 or (bagID > 4 and bagID < 11) );
23 end
24  
25 function Bagnon_FrameHasBag(frameName, bagID)
26 if(not ( BagnonSets[frameName] and BagnonSets[frameName].bags ) ) then
27 return false;
28 end
29  
30 for i in BagnonSets[frameName].bags do
31 if(BagnonSets[frameName].bags[i] == bagID) then
32 return true;
33 end
34 end
35 return false;
36 end
37  
38 --returns if the given bag is an ammo bag/soul bag
39 function Bagnon_IsAmmoBag(bagID)
40 --bank and the main bag are never ammo bags
41 if(bagID == 0 or bagID == -1) then
42 return nil;
43 end
44  
45 local link = GetInventoryItemLink("player", ContainerIDToInventoryID(bagID) );
46  
47 if(link) then
48 local _, _, id = string.find(link, "item:(%d+)");
49 local _, _, _, _, itemType, subType = GetItemInfo(id);
50  
51 return ( itemType == BAGNON_ITEMTYPE_QUIVER or subType == BAGNON_SUBTYPE_SOULBAG );
52 end
53  
54 return nil;
55 end
56  
57 --returns if the given bag is a profession bag (herb bag, engineering bag, etc)
58 function Bagnon_IsProfessionBag(bagID)
59 if(bagID == 0 or bagID == -1) then
60 return nil;
61 end
62  
63 local link = GetInventoryItemLink("player", ContainerIDToInventoryID(bagID) );
64  
65 if(link) then
66 local _, _, id = string.find(link, "item:(%d+)");
67 local _, _, _, _, itemType, subType = GetItemInfo(id);
68  
69 return ( itemType == BAGNON_ITEMTYPE_CONTAINER and not (subType == BAGNON_SUBTYPE_BAG or subType == BAGNON_SUBTYPE_SOULBAG) );
70 end
71  
72 return nil;
73 end
74  
75 --[[
76 Detection for Cached Frames
77 Only enabled if BagnonForever is enabled
78 --]]
79  
80 function Bagnon_IsCachedFrame(frame)
81 if(not BagnonForever) then
82 return false;
83 end
84  
85 return ( currentPlayer ~= frame.player or (not bgn_atBank and frame:GetName() == "Banknon") );
86 end
87  
88 function Bagnon_IsCachedBag(player, bagID)
89 if(not BagnonForever) then
90 return false;
91 end
92  
93 return ( currentPlayer ~= player or (not bgn_atBank and Bagnon_IsBankBag(bagID)) );
94 end
95  
96 --returns true if the item is being viewed from a cache
97 function Bagnon_IsCachedItem(item)
98 if(not BagnonForever) then
99 return false;
100 end
101 --we're not looking at the current player's items
102 if( currentPlayer ~= item:GetParent():GetParent().player ) then
103 return true;
104 end
105  
106 --the bank frame is visible in the normal way
107 if( bgn_atBank ) then
108 return false;
109 end
110  
111 --we're looking at the player's bank away from the actual bank
112 return ( Bagnon_IsBankBag( item:GetParent():GetID() ) );
113 end
114  
115 function Bagnon_AnchorTooltip(frame)
116 GameTooltip:ClearAllPoints();
117  
118 if( frame:GetLeft() < ( UIParent:GetRight() / 2) ) then
119 if(frame:GetTop() < (UIParent:GetTop() / 2) ) then
120 GameTooltip:SetPoint("BOTTOMLEFT", frame, "TOPLEFT");
121 else
122 GameTooltip:SetPoint("TOPLEFT", frame, "BOTTOMRIGHT");
123 end
124 else
125 if(frame:GetTop() < (UIParent:GetTop() / 2) ) then
126 GameTooltip:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT");
127 else
128 GameTooltip:SetPoint("TOPRIGHT", frame, "BOTTOMLEFT");
129 end
130 end
131 end
132  
133 --[[
134 Messaging
135 --]]
136  
137 --send a message to the player
138 function BagnonMsg(msg)
139 DEFAULT_CHAT_FRAME:AddMessage(msg, 0, 0.7, 1);
140 end