vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 BagFu = AceLibrary("AceAddon-2.0"):new("FuBarPlugin-2.0", "AceDB-2.0", "AceEvent-2.0", "AceConsole-2.0")
2 BagFu:RegisterDB("BagFuDB")
3 BagFu:RegisterDefaults('profile', {
4 showDepletion = false,
5 includeProfession = true,
6 includeAmmo = false,
7 })
8  
9 BagFu.hasIcon = true
10 BagFu.cannotDetachTooltip = true
11 BagFu.defaultPosition = "RIGHT"
12  
13 local L = AceLibrary("AceLocale-2.0"):new("BagFu")
14 function BagFu:OnInitialize()
15 --self.dewdrop = AceLibrary("Dewdrop-2.0")
16 self.crayon = AceLibrary("Crayon-2.0")
17 self.tablet = AceLibrary("Tablet-2.0")
18  
19 self.options = {
20 type = "group",
21 args = {
22 ammobags = {
23 type = "toggle",
24 name = L["AMMO_BAGS"],
25 desc = L["MENU_INCLUDE_AMMO_BAGS"],
26 get = function() return self.db.profile.includeAmmo end,
27 set = function()
28 self.db.profile.includeAmmo = not self.db.profile.includeAmmo
29 self:Update()
30 end,
31 order = 110
32 },
33 professionbags = {
34 type = "toggle",
35 name = L["PROFESSION_BAGS"],
36 desc = L["MENU_INCLUDE_PROFESSION_BAGS"],
37 get = function() return self.db.profile.includeProfession end,
38 set = function()
39 self.db.profile.includeProfession = not self.db.profile.includeProfession
40 self:Update()
41 end,
42 order = 120
43 },
44 depletion = {
45 type = "toggle",
46 name = L["BAG_DEPLETION"],
47 desc = L["MENU_SHOW_DEPLETION_OF_BAGS"],
48 get = function() return self.db.profile.showDepletion end,
49 set = function()
50 self.db.profile.showDepletion = not self.db.profile.showDepletion
51 self:Update()
52 end,
53 order = 130
54 }
55 }
56 }
57 self.OnMenuRequest = self.options
58 self:RegisterChatCommand({ "/bagfu" }, self.options)
59 end
60  
61 function BagFu:OnEnable()
62 self:RegisterEvent("PLAYER_ENTERING_WORLD", "OnPlayerEnteringWorld")
63 self:RegisterEvent("PLAYER_LEAVING_WORLD", "OnPlayerLeavingWorld")
64 self:RegisterEvent("BAG_UPDATE", "Update")
65 end
66  
67  
68 function BagFu:OnPlayerEnteringWorld()
69 self:RegisterEvent("BAG_UPDATE", "Update")
70 end
71  
72 function BagFu:OnPlayerLeavingWorld()
73 self:UnregisterEvent("BAG_UPDATE")
74 end
75  
76 function BagFu:UpdateText()
77 local totalSlots = 0
78 local takenSlots = 0
79 for i = 0, 4 do
80 local usable = TRUE
81 if i >= 1 then
82 local link = GetInventoryItemLink("player", ContainerIDToInventoryID(i))
83 if link ~= nil then
84 local itemId = tonumber(string.gsub(link, "|cff%x%x%x%x%x%x|Hitem:(%d+):%d+:%d+:%d+|h.*", "%1") or 0)
85 local _,_,_,_,_,subtype = GetItemInfo(itemId)
86 if not self.db.profile.includeAmmo and (subtype == L["TEXT_SOUL_BAG"] or subtype == L["TEXT_AMMO_POUCH"] or subtype == L["TEXT_QUIVER"]) then
87 usable = FALSE
88 elseif not self.db.profile.includeProfession and (subtype == L["TEXT_ENCHANTING_BAG"] or subtype == L["TEXT_HERB_BAG"] or subtype == L["TEXT_ENGINEERING_BAG"]) then
89 usable = FALSE
90 end
91 end
92 end
93 if usable then
94 local size = GetContainerNumSlots(i)
95  
96 if size ~= nil and size > 0 then
97 totalSlots = totalSlots + size
98 for slot = 1, size do
99 if GetContainerItemInfo(i, slot) then
100 takenSlots = takenSlots + 1
101 end
102 end
103 end
104 end
105 end
106  
107 local color = self.crayon:GetThresholdHexColor((totalSlots - takenSlots) / totalSlots)
108  
109 if self.db.profile.showDepletion then
110 takenSlots = totalSlots - takenSlots
111 end
112  
113 self:SetText(format("|cff%s%d/%d|r", color, takenSlots, totalSlots))
114 end
115  
116 function BagFu:OnTooltipUpdate()
117 self.tablet:SetHint(L["TEXT_HINT"])
118 end
119  
120 function BagFu:OnClick()
121 if not ContainerFrame1:IsShown() then
122 for i = 1, 4 do
123 if getglobal("ContainerFrame" .. (i + 1)):IsShown() then
124 getglobal("ContainerFrame" .. (i + 1)):Hide()
125 end
126 end
127 ToggleBackpack()
128 if ContainerFrame1:IsShown() then
129 for i = 1, 4 do
130 local link = GetInventoryItemLink("player", ContainerIDToInventoryID(i))
131 if link ~= nil then
132 local itemId = tonumber(string.gsub(link, "|cff%x%x%x%x%x%x|Hitem:(%d+):%d+:%d+:%d+|h.*", "%1") or 0)
133 local _,_,_,_,_,subtype = GetItemInfo(itemId)
134 local usable = TRUE
135 if not self.db.profile.includeAmmo and (subtype == L["TEXT_SOUL_BAG"] or subtype == L["TEXT_AMMO_POUCH"] or subtype == L["TEXT_QUIVER"]) then
136 usable = FALSE
137 elseif not self.db.profile.includeProfession and (subtype == L["TEXT_ENCHANTING_BAG"] or subtype == L["TEXT_HERB_BAG"] or subtype == L["TEXT_ENGINEERING_BAG"]) then
138 usable = FALSE
139 end
140 if usable then
141 ToggleBag(i)
142 end
143 end
144 end
145 end
146 else
147 for i = 0, 4 do
148 if getglobal("ContainerFrame" .. (i + 1)):IsShown() then
149 getglobal("ContainerFrame" .. (i + 1)):Hide()
150 end
151 end
152 end
153 end