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