vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[---------------------------------------------------------------------------------
2 MyACEPercentage - mailto:instant.gmail.com
3 ------------------------------------------------------------------------------------]]
4 local DEFAULT_OPTIONS = {
5 current = FALSE,
6 total = TRUE,
7 colour = TRUE
8 }
9 --[[---------------------------------------------------------------------------------
10 Class Setup
11 ------------------------------------------------------------------------------------]]
12 MyAcePerc = AceAddon:new({
13 name = "MyAcePercentage",
14 description = MYACEPERC.DESCRIPTION,
15 version = "b.1.7.0",
16 releaseDate = "2005-09-27",
17 aceCompatible = "102",
18 author = "instant",
19 email = "instant0@gmail.com",
20 website = "http://www.wowace.com",
21 category = ACE_CATEGORY_INTERFACE,
22 db = AceDbClass:new("MyAcePercDB"),
23 defaults = DEFAULT_OPTIONS,
24 cmd = AceChatCmd:new(MYACEPERC.COMMANDS, MYACEPERC.CMD_OPTIONS)
25 })
26  
27 function MyAcePerc:Initialize()
28 MYACEPERC_C1 = "|cFFFFFF00"
29 MYACEPERC_C2 = "|cFF00FF00"
30  
31 self.GetOpt = function(var) return self.db:get(self.profilePath,var) end
32 self.SetOpt = function(var,val) self.db:set(self.profilePath,var,val) end
33 self.TogOpt = function(var) return self.db:toggle(self.profilePath,var) end
34 end
35  
36 --[[--------------------------------------------------------------------------------
37 Addon Enabling/Disabling
38 -----------------------------------------------------------------------------------]]
39 function MyAcePerc:Enable()
40 self:HookScript(GameTooltip, "OnShow", "ProcessOnShow")
41 end
42  
43 -- Disable() is not needed if all you are doing in Enable() is registering events
44 -- and hooking functions. Ace will automatically unregister and unhook these.
45 function MyAcePerc:Disable()
46 end
47  
48 --[[--------------------------------------------------------------------------------
49 Main Processing
50 -----------------------------------------------------------------------------------]]
51 function MyAcePerc:ProcessOnShow()
52 -- You should always call the hooked script to give other addons a chance to
53 -- process it, unless you must prevent further processing.
54 if( GameTooltip:IsVisible() ) then
55 local line2cost, line2costd, tipline2, line2number, line2mana
56 local ttext, dttext, ctext, dctext
57 if( GameTooltipTextLeft2:GetText() ) then
58 tipline2 = GameTooltipTextLeft2:GetText()
59 line2number = string.find(tipline2, '%d+')
60 if ( line2number == 1 ) then
61 line2mana = string.find(tipline2, MANA)
62 if ( line2mana ) then
63 line2cost = string.gsub(GameTooltipTextLeft2:GetText(), string.gsub(MANA_COST, "%%d", ""), "")
64 line2costd = tonumber(line2cost)
65 if ( self.GetOpt("total") ) then
66 ttext = string.format( "%.1f" , ( line2costd/( UnitManaMax('player')/100 ) ) )
67 if ( self.GetOpt("colour") ) then
68 dttext = MYACEPERC_C1.."("..ttext.."%)"
69 else
70 dttext = "(t:"..ttext.."%)"
71 end
72 end
73 if ( self.GetOpt("current") ) then
74 ctext = string.format ( "%.1f" , ( line2costd/( UnitMana('player')/100 ) ) )
75 if ( self.GetOpt("colour") ) then
76 dctext = MYACEPERC_C2.."("..ctext.."%)"
77 else
78 dctext = "(c:"..ctext.."%)"
79 end
80  
81 end
82 if not ( dctext ) then
83 dctext = ""
84 end
85 if not ( dttext ) then
86 dttext = ""
87 end
88 GameTooltipTextLeft2:SetText( format( MANA_COST,line2cost )..dctext..dttext )
89 end
90 end
91 end
92 end
93 self:CallScript(GameTooltip, "OnShow")
94 end
95  
96 --[[---------------------------------------------------------------------------------
97 Command Handlers
98 ------------------------------------------------------------------------------------]]
99 function MyAcePerc:TotalMana()
100 -- TogOpt will toggle the value of opt2 in the database to TRUE or FALSE, the
101 -- opposite of what it was, and return the new value. status() will display a
102 -- message showing the On/Off state based on the value returned by TogOpt().
103 -- If the status is TRUE then "On" will be displayed, otherwise "Off".
104 self.cmd:status(MYACEPERC.TOTAL_MSG, self.TogOpt("total"), ACEG_MAP_ONOFF)
105 end
106  
107 function MyAcePerc:CurrentMana()
108 self.cmd:status(MYACEPERC.CURNT_MSG, self.TogOpt("current"), ACEG_MAP_ONOFF)
109 end
110  
111 function MyAcePerc:Colour()
112 self.cmd:status(MYACEPERC.COLOR_MSG, self.TogOpt("colour"), ACEG_MAP_ONOFF)
113 end
114  
115 function MyAcePerc:Report()
116 self.cmd:report({
117 {text=MYACEPERC.TOTAL_MSG, val=self.GetOpt("total"), map=ACEG_MAP_ONOFF},
118 {text=MYACEPERC.CURNT_MSG, val=self.GetOpt("current"), map=ACEG_MAP_ONOFF},
119 {text=MYACEPERC.COLOR_MSG, val=self.GetOpt("colour"), map=ACEG_MAP_ONOFF}
120 })
121 end
122  
123 --[[---------------------------------------------------------------------------------
124 Register Addon Object
125 ------------------------------------------------------------------------------------]]
126 MyAcePerc:RegisterForLoad()