vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | TinyMoneyFrame functions |
||
3 | 3.8.0 (Kangaroo) |
||
4 | |||
5 | $Id: TinyMoneyFrame.lua 632 2005-12-18 14:36:34Z norganna $ |
||
6 | |||
7 | License: |
||
8 | This program is free software; you can redistribute it and/or |
||
9 | modify it under the terms of the GNU General Public License |
||
10 | as published by the Free Software Foundation; either version 2 |
||
11 | of the License, or (at your option) any later version. |
||
12 | |||
13 | This program is distributed in the hope that it will be useful, |
||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | GNU General Public License for more details. |
||
17 | |||
18 | You should have received a copy of the GNU General Public License |
||
19 | along with this program(see GLP.txt); if not, write to the Free Software |
||
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||
21 | ]] |
||
22 | |||
23 | function TinyMoneyFrame_Update(frameName, money) |
||
24 | local frame = getglobal(frameName); |
||
25 | local info = frame.info; |
||
26 | if ( not info ) then |
||
27 | message("Error moneyType not set"); |
||
28 | end |
||
29 | |||
30 | -- Breakdown the money into denominations |
||
31 | local gold = floor(money / (COPPER_PER_SILVER * SILVER_PER_GOLD)); |
||
32 | local silver = floor((money - (gold * COPPER_PER_SILVER * SILVER_PER_GOLD)) / COPPER_PER_SILVER); |
||
33 | local copper = mod(money, COPPER_PER_SILVER); |
||
34 | |||
35 | local goldButton = getglobal(frameName.."GoldButton"); |
||
36 | local silverButton = getglobal(frameName.."SilverButton"); |
||
37 | local copperButton = getglobal(frameName.."CopperButton"); |
||
38 | |||
39 | local iconWidth = MONEY_ICON_WIDTH; |
||
40 | local spacing = MONEY_BUTTON_SPACING; |
||
41 | if ( frame.small ) then |
||
42 | iconWidth = MONEY_ICON_WIDTH_SMALL; |
||
43 | spacing = MONEY_BUTTON_SPACING_SMALL; |
||
44 | end |
||
45 | |||
46 | -- Set values for each denomination |
||
47 | goldButton:SetText(gold); |
||
48 | goldButton:SetWidth(goldButton:GetTextWidth() + iconWidth); |
||
49 | goldButton:Show(); |
||
50 | |||
51 | if (gold > 0) then |
||
52 | silverButton:SetText(string.format("%."..math.log10(SILVER_PER_GOLD).."d", silver)); |
||
53 | else |
||
54 | silverButton:SetText(silver); |
||
55 | end |
||
56 | silverButton:SetWidth(silverButton:GetTextWidth() + iconWidth); |
||
57 | silverButton:Show(); |
||
58 | |||
59 | if (gold > 0 or silver > 0) then |
||
60 | copperButton:SetText(string.format("%."..math.log10(COPPER_PER_SILVER).."d", copper)); |
||
61 | else |
||
62 | copperButton:SetText(copper); |
||
63 | end |
||
64 | copperButton:SetWidth(copperButton:GetTextWidth() + iconWidth); |
||
65 | copperButton:Show(); |
||
66 | |||
67 | -- Store how much money the frame is displaying |
||
68 | frame.staticMoney = money; |
||
69 | |||
70 | -- If not collapsable don't need to continue |
||
71 | if ( not info.collapse ) then |
||
72 | return; |
||
73 | end |
||
74 | |||
75 | local width = iconWidth; |
||
76 | local showLowerDenominations, truncateCopper; |
||
77 | if ( gold > 0 ) then |
||
78 | width = width + goldButton:GetWidth(); |
||
79 | if ( info.showSmallerCoins ) then |
||
80 | showLowerDenominations = 1; |
||
81 | end |
||
82 | if ( info.truncateSmallCoins ) then |
||
83 | truncateCopper = 1; |
||
84 | end |
||
85 | else |
||
86 | goldButton:Hide(); |
||
87 | end |
||
88 | |||
89 | if ( silver > 0 or showLowerDenominations ) then |
||
90 | if ( gold > 0 ) then |
||
91 | silverButton:SetWidth(25); |
||
92 | end |
||
93 | |||
94 | width = width + silverButton:GetWidth(); |
||
95 | goldButton:SetPoint("RIGHT", frameName.."SilverButton", "LEFT", spacing, 0); |
||
96 | if ( goldButton:IsVisible() ) then |
||
97 | width = width - spacing; |
||
98 | end |
||
99 | if ( info.showSmallerCoins ) then |
||
100 | showLowerDenominations = 1; |
||
101 | end |
||
102 | else |
||
103 | silverButton:Hide(); |
||
104 | goldButton:SetPoint("RIGHT", frameName.."SilverButton", "RIGHT", 0, 0); |
||
105 | end |
||
106 | |||
107 | -- Used if we're not showing lower denominations |
||
108 | if ( (copper > 0 or showLowerDenominations or info.showSmallerCoins == "Backpack") and not truncateCopper) then |
||
109 | if ( gold > 0 or silver > 0 ) then |
||
110 | copperButton:SetWidth(25); |
||
111 | end |
||
112 | |||
113 | width = width + copperButton:GetWidth(); |
||
114 | silverButton:SetPoint("RIGHT", frameName.."CopperButton", "LEFT", spacing, 0); |
||
115 | if ( silverButton:IsVisible() ) then |
||
116 | width = width - spacing; |
||
117 | end |
||
118 | else |
||
119 | copperButton:Hide(); |
||
120 | silverButton:SetPoint("RIGHT", frameName.."CopperButton", "RIGHT", 0, 0); |
||
121 | end |
||
122 | |||
123 | frame:SetWidth(width); |
||
124 | end |
||
125 | |||
126 | function TinyMoneyFrame_UpdateMoney() |
||
127 | if ( this.info ) then |
||
128 | local money = this.info.UpdateFunc(); |
||
129 | TinyMoneyFrame_Update(this:GetName(), money); |
||
130 | if ( this.hasPickup == 1 ) then |
||
131 | UpdateCoinPickupFrame(money); |
||
132 | end |
||
133 | else |
||
134 | message("Error moneyType not set"); |
||
135 | end |
||
136 | end |