vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --$Id: OneBank.lua 8012 2006-08-14 20:35:14Z hk2717 $
2 OneBank = OneCore:NewModule("OneBank", "AceEvent-2.0", "AceHook-2.0", "AceDebug-2.0", "AceConsole-2.0", "AceDB-2.0")
3 local L = AceLibrary("AceLocale-2.0"):new("OneBank")
4  
5 function OneBank:OnInitialize()
6  
7 local baseArgs = OneCore:GetFreshOptionsTable(self)
8  
9 local customArgs = {
10 ["5"] = {
11 name = L"First Bag", type = 'toggle', order = 5,
12 desc = L"Turns display of your first bag on and off.",
13 get = function() return self.db.profile.show[5] end,
14 set = function(v)
15 self.db.profile.show[5] = v
16 self:OrganizeFrame(true)
17 end,
18 },
19 ["6"] = {
20 name = L"Second Bag", type = 'toggle', order = 6,
21 desc = L"Turns display of your second bag on and off.",
22 get = function() return self.db.profile.show[6] end,
23 set = function(v)
24 self.db.profile.show[6] = v
25 self:OrganizeFrame(true)
26 end,
27 },
28 ["7"] = {
29 name = L"Third Bag", type = 'toggle', order = 7,
30 desc = L"Turns display of your third bag on and off.",
31 get = function() return self.db.profile.show[7] end,
32 set = function(v)
33 self.db.profile.show[7] = v
34 self:OrganizeFrame(true)
35 end,
36 },
37 ["8"] = {
38 name = L"Fourth Bag", type = 'toggle', order = 8,
39 desc = L"Turns display of your fourth bag on and off.",
40 get = function() return self.db.profile.show[8] end,
41 set = function(v)
42 self.db.profile.show[8] = v
43 self:OrganizeFrame(true)
44 end,
45 },
46 ["9"] = {
47 name = L"Fifth Bag", type = 'toggle', order = 9,
48 desc = L"Turns display of your fifth bag on and off.",
49 get = function() return self.db.profile.show[9] end,
50 set = function(v)
51 self.db.profile.show[9] = v
52 self:OrganizeFrame(true)
53 end,
54 },
55 ["10"] = {
56 name = L"Sixth Bag", type = 'toggle', order = 10,
57 desc = L"Turns display of your sixth bag on and off.",
58 get = function() return self.db.profile.show[10] end,
59 set = function(v)
60 self.db.profile.show[10] = v
61 self:OrganizeFrame(true)
62 end,
63 },
64 }
65  
66 OneCore:CopyTable(customArgs, baseArgs.args.show.args)
67  
68 OneCore:LoadOptionalCommands(baseArgs, self)
69  
70 self:RegisterDB("OneBankDB")
71 self:RegisterDefaults('profile', OneCore.defaults)
72 self:RegisterChatCommand({"/obb", "/OneBank"}, baseArgs, string.upper(self.title))
73  
74 --self:SetDebugging(true)
75  
76 self.fBags = {-1, 5, 6, 7, 8, 9, 10}
77 self.rBags = {10, 9, 8, 7, 6, 5, -1}
78  
79 OneBankFrameName:SetText(UnitName("player").. L"'s Bank Bags")
80  
81 self.frame = OneBankFrame
82 self.frame.handler = self
83  
84 self.frame.bagFrame = OBBBagFra
85 self.frame.bagFrame.handler = self
86  
87 self.frame.bags = {}
88  
89 self.lastCounts = {}
90 self.isBank = true
91  
92 self:RegisterDewdrop(baseArgs)
93 end
94  
95 function OneBank:OnEnable()
96 self.frame:SetClampedToScreen(true)
97  
98 self:RegisterEvent("BAG_UPDATE", function() self:UpdateBag(arg1) end)
99 self:RegisterEvent("BAG_UPDATE_COOLDOWN", function() self:UpdateBag(arg1) end)
100  
101 self:RegisterEvent("BANKFRAME_OPENED", function() self.frame:Show() end)
102 self:RegisterEvent("BANKFRAME_CLOSED", function() self.frame:Hide() end)
103  
104 self:RegisterEvent("PLAYERBANKSLOTS_CHANGED", function()
105 if not self.frame.bags[-1].colorLocked then
106 for k, v in ipairs(self.frame.bags[-1]) do
107 self:SetBorderColor(v)
108 end
109 end
110 end)
111  
112 if CT_oldPurchaseSlot then PurchaseSlot = CT_oldPurchaseSlot end
113 self:Hook("PurchaseSlot", function() self.hooks.PurchaseSlot.orig() self.bagPurchased = true end)
114 self:BuildFrame()
115 end
116  
117 function OneBank:OnUpdate()
118 local total, bagChanged = 0, false
119  
120 for i, k in self.fBags do
121 local count = GetContainerNumSlots(k)
122 if self.lastCounts[k] ~= count then
123 self.lastCounts[k] = count
124 bagChanged = true
125 end
126 total = total + count
127 end
128  
129 if self.lastCount ~= total or bagChanged then
130 self:BuildFrame()
131 self:OrganizeFrame()
132 self:DoSlotCounts()
133  
134 self.lastCount = total
135 end
136  
137 if self.bagPurchased then
138 self:UpdateBagSlotStatus()
139 end
140 end
141  
142 function OneBank:StartOnUpdate()
143 self:ScheduleRepeatingEvent(self.title, self.OnUpdate, .25, self)
144 self:UpdateBag(-1)
145 end
146  
147 function OneBank:StopOnUpdate()
148 self:CancelScheduledEvent(self.title)
149 end
150  
151 function OneBank:UpdateBagSlotStatus()
152 local purchaseFrame = OBBBagFraPurchaseInfo
153 if( purchaseFrame == nil ) then
154 return
155 end
156  
157 local numSlots,full = GetNumBankSlots()
158 local button
159 for i=1, NUM_BANKBAGSLOTS, 1 do
160 button = getglobal("OBBBagFraBag"..i)
161 if ( button ) then
162 if ( i <= numSlots ) then
163 SetItemButtonTextureVertexColor(button, 1.0,1.0,1.0)
164 button.tooltipText = BANK_BAG
165 else
166 SetItemButtonTextureVertexColor(button, 1.0,0.1,0.1)
167 button.tooltipText = BANK_BAG_PURCHASE
168 end
169 end
170 end
171  
172 -- pass in # of current slots, returns cost of next slot
173 local cost = GetBankSlotCost(numSlots)
174 BankFrame.nextSlotCost = cost
175 if( GetMoney() >= cost ) then
176 SetMoneyFrameColor("OBBBagFraPurchaseInfoDetailMoneyFrame", 1.0, 1.0, 1.0)
177 else
178 SetMoneyFrameColor("OBBBagFraPurchaseInfoDetailMoneyFrame", 1.0, 0.1, 0.1)
179 end
180 MoneyFrame_Update("OBBBagFraPurchaseInfoDetailMoneyFrame", cost)
181  
182 if( full ) then
183 purchaseFrame:Hide()
184 else
185 purchaseFrame:Show()
186 end
187 end
188  
189  
190 function OneBank:OnCustomShow()
191 if self.db.profile.point then
192 local point = self.db.profile.point
193 this:ClearAllPoints()
194 this:SetPoint("TOPLEFT", point.parent, "BOTTOMLEFT", point.left, point.top)
195 else
196 if not OneBag:IsActive() then
197 this:ClearAllPoints()
198 this:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
199 else
200 this:ClearAllPoints()
201 this:SetPoint("BOTTOMLEFT", OneBagFrame, "TOPLEFT", 0, 25)
202 end
203  
204  
205 end
206 self:StartOnUpdate()
207 self:UpdateBagSlotStatus()
208 end
209  
210 function OneBank:OnCustomHide()
211 CloseBankFrame()
212 self:StopOnUpdate()
213 end