Permalink
Browse files

Money frame is ready for localization and now properly inherits from …

…core class
  • Loading branch information...
Jaliborc committed Mar 11, 2012
1 parent 8e6d5e8 commit cae7af56b4aeda6ee44797cc7889f679dabb7a44
Showing with 14 additions and 151 deletions.
  1. +10 −151 components/moneyFrame.lua
  2. +4 −0 localization/en.lua
View
@@ -4,83 +4,12 @@
--]]
local Bagnon = LibStub('AceAddon-3.0'):GetAddon('Bagnon')
-local MoneyFrame = Bagnon:NewClass('GuildMoneyFrame', 'Frame')
-
-
---[[ Things! ]]--
-
+local MoneyFrame = Bagnon:NewClass('GuildMoneyFrame', 'Frame', Bagnon.MoneyFrame)
local L = LibStub('AceLocale-3.0'):GetLocale('Bagnon')
-local GOLD_TEXT = string.format('|cffffd700%s|r', 'g')
-local SILVER_TEXT = string.format('|cffc7c7cf%s|r', 's')
-local COPPER_TEXT = string.format('|cffeda55f%s|r', 'c')
-
-
---[[ Constructor ]]--
-function MoneyFrame:New(frameID, parent)
- local f = self:Bind(CreateFrame('Frame', 'BagnonGuildMoneyFrame' .. self:GetNextID(), parent, 'SmallMoneyFrameTemplate'))
- f:SetFrameID(frameID)
- f:AddClickFrame()
-
- f:SetScript('OnShow', f.OnShow)
- f:SetScript('OnHide', f.OnHide)
- f:SetScript('OnEvent', f.OnEvent)
-
- return f
-end
-
---creates a clickable frame for tooltips/etc
-local function ClickFrame_OnClick(self, button)
- self:GetParent():OnClick(button)
-end
-
-local function ClickFrame_OnEnter(self)
- self:GetParent():OnEnter()
-end
-
-local function ClickFrame_OnLeave(self)
- self:GetParent():OnLeave()
-end
-
-function MoneyFrame:AddClickFrame()
- local f = CreateFrame('Button', self:GetName() .. 'Click', self)
- f:SetFrameLevel(self:GetFrameLevel() + 3)
- f:SetAllPoints(self)
- f:RegisterForClicks('anyUp')
-
- f:SetScript('OnClick', ClickFrame_OnClick)
- f:SetScript('OnEnter', ClickFrame_OnEnter)
- f:SetScript('OnLeave', ClickFrame_OnLeave)
-
- return f
-end
-
-do
- local id = 0
- function MoneyFrame:GetNextID()
- local nextID = id + 1
- id = nextID
- return nextID
- end
-end
-
-
---[[ Events ]]--
-
-function MoneyFrame:GUILDBANK_UPDATE_MONEY()
- self:UpdateValue()
-end
--[[ Frame Events ]]--
-function MoneyFrame:OnShow()
- self:UpdateEverything()
-end
-
-function MoneyFrame:OnHide()
- self:UpdateEvents()
-end
-
function MoneyFrame:OnClick(button)
local cMoney = GetCursorMoney() or 0
if cMoney > 0 then
@@ -110,27 +39,9 @@ function MoneyFrame:OnLeave()
end
end
-function MoneyFrame:OnEvent(event, ...)
- local action = self[event]
- if action then
- action(self, event, ...)
- end
-end
-
--[[ Actions ]]--
-function MoneyFrame:UpdateEverything()
- self:UpdateEvents()
- self:UpdateValue()
-end
-
-function MoneyFrame:UpdateValue()
- if self:IsVisible() then
- MoneyFrame_Update(self:GetName(), self:GetMoney())
- end
-end
-
function MoneyFrame:UpdateEvents()
self:UnregisterAllEvents()
if self:IsVisible() then
@@ -139,15 +50,15 @@ function MoneyFrame:UpdateEvents()
end
function MoneyFrame:UpdateTooltip()
- GameTooltip:SetText('Guild Funds')
- GameTooltip:AddLine('<Left Click> to deposit.', 1, 1, 1)
+ GameTooltip:SetText(L.TipFunds)
+ GameTooltip:AddLine(L.TipDeposit, 1, 1, 1)
if CanWithdrawGuildBankMoney() then
local withdrawMoney = GetGuildBankWithdrawMoney()
if withdrawMoney > 0 then
- GameTooltip:AddLine(string.format('<Right Click> to withdraw (%s remaining).', self:GetCurrencyText(withdrawMoney)), 1, 1, 1)
+ GameTooltip:AddLine(format(L.TipWithdrawRemaining, self:GetCoinsText(withdrawMoney)), 1, 1, 1)
else
- GameTooltip:AddLine('<Right Click> to withdraw.')
+ GameTooltip:AddLine(L.TipWithdraw)
end
end
@@ -171,11 +82,13 @@ function MoneyFrame:ShowDepositDialog()
end
function MoneyFrame:ShowWithdrawDialog()
- if not CanWithdrawGuildBankMoney() then return end
+ if not CanWithdrawGuildBankMoney() then
+ return
+ end
PlaySound('igMainMenuOption')
-
StaticPopup_Hide('GUILDBANK_DEPOSIT')
+
if StaticPopup_Visible('GUILDBANK_WITHDRAW') then
StaticPopup_Hide('GUILDBANK_WITHDRAW')
else
@@ -184,62 +97,8 @@ function MoneyFrame:ShowWithdrawDialog()
end
---[[ Frame Properties ]]--
-
-function MoneyFrame:GetSettings()
- return Bagnon.FrameSettings:Get(self:GetFrameID())
-end
-
-function MoneyFrame:GetPlayer()
- return self:GetSettings():GetPlayerFilter()
-end
-
-function MoneyFrame:SetFrameID(frameID)
- if self:GetFrameID() ~= frameID then
- self.frameID = frameID
- self:UpdateEverything()
- end
-end
-
-function MoneyFrame:GetFrameID()
- return self.frameID
-end
+--[[ Properties ]]--
function MoneyFrame:GetMoney()
return GetGuildBankMoney()
-end
-
-function MoneyFrame:GetGoldSilverCopper(money)
- local gold = math.floor(money / (COPPER_PER_SILVER * SILVER_PER_GOLD))
- local silver = math.floor((money - (gold * COPPER_PER_SILVER * SILVER_PER_GOLD)) / COPPER_PER_SILVER)
- local copper = money % COPPER_PER_SILVER
-
- return gold, silver, copper
-end
-
-function MoneyFrame:GetCurrencyText(money)
- local gold, silver, copper = self:GetGoldSilverCopper(money)
- local text
-
- if gold > 0 then
- text = string.format('|cffffffff%d|r%s', gold, GOLD_TEXT)
- end
-
- if silver > 0 then
- if text then
- text = text .. string.format(' |cffffffff%d|r%s', silver, SILVER_TEXT)
- else
- text = string.format('|cffffffff%d|r%s', silver, SILVER_TEXT)
- end
- end
-
- if copper > 0 or (gold == 0 and silver == 0) then
- if text then
- text = text .. string.format(' |cffffffff%d|r%s', copper, COPPER_TEXT)
- else
- text = string.format('|cffffffff%d|r%s', copper, COPPER_TEXT)
- end
- end
-
- return text
end
View
@@ -8,6 +8,10 @@ local L = LibStub('AceLocale-3.0'):NewLocale('Bagnon-GuildBank', 'enUS', true)
L.Title = [[%s's Guild Bank]]
L.Log1 = 'Transaction Log'
L.Log3 = 'Tab Information'
+L.TipFunds = 'Guild Funds'
+L.TipDeposit = '<Left Click> to deposit.'
+L.TipWithdrawRemaining = '<Right Click> to withdraw (%s remaining).'
+L.TipWithdraw = '<Right Click> to withdraw.'
-- Automatically localized - do not translate!

0 comments on commit cae7af5

Please sign in to comment.