vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | local module = ArcHUD:NewModule("Health") |
2 | module.unit = "player" |
||
3 | module.defaults = { |
||
4 | Enabled = true, |
||
5 | Outline = true, |
||
6 | ShowText = true, |
||
7 | ShowPerc = true, |
||
8 | ShowDef = false, |
||
9 | ColorFade = true, |
||
10 | Side = 1, |
||
11 | Level = 0, |
||
12 | } |
||
13 | module.options = { |
||
14 | {name = "ShowText", text = "SHOWTEXT", tooltip = "SHOWTEXT"}, |
||
15 | {name = "ShowPerc", text = "SHOWPERC", tooltip = "SHOWPERC"}, |
||
16 | {name = "ColorFade", text = "COLORFADE", tooltip = "COLORFADE"}, |
||
17 | {name = "ShowDef", text = "DEFICIT", tooltip = "DEFICIT"}, |
||
18 | attach = true, |
||
19 | } |
||
20 | module.localized = true |
||
21 | |||
22 | function module:Initialize() |
||
23 | -- Setup the frame we need |
||
24 | self.f = self:CreateRing(true, ArcHUDFrame) |
||
25 | self.f:SetAlpha(0) |
||
26 | |||
27 | self.HPText = self:CreateFontString(self.f, "BACKGROUND", {150, 15}, 14, "RIGHT", {1.0, 1.0, 0.0}, {"TOPRIGHT", ArcHUDFrameCombo, "TOPLEFT", 0, 0}) |
||
28 | self.HPPerc = self:CreateFontString(self.f, "BACKGROUND", {70, 14}, 12, "RIGHT", {1.0, 1.0, 1.0}, {"TOPRIGHT", self.HPText, "BOTTOMRIGHT", 0, 0}) |
||
29 | self.DefText = self:CreateFontString(self.f, "BACKGROUND", {70, 14}, 11, "RIGHT", {1.0, 0.2, 0.2}, {"BOTTOMRIGHT", self.HPText, "TOPRIGHT", 0, 0}) |
||
30 | end |
||
31 | |||
32 | function module:Update() |
||
33 | -- Get options and setup accordingly |
||
34 | if(self.db.profile.ShowText) then |
||
35 | self.HPText:Show() |
||
36 | else |
||
37 | self.HPText:Hide() |
||
38 | end |
||
39 | |||
40 | if(self.db.profile.ShowPerc) then |
||
41 | self.HPPerc:Show() |
||
42 | else |
||
43 | self.HPPerc:Hide() |
||
44 | end |
||
45 | |||
46 | if(self.db.profile.ShowDef) then |
||
47 | self.DefText:Show() |
||
48 | else |
||
49 | self.DefText:Hide() |
||
50 | end |
||
51 | |||
52 | if(self.db.profile.Outline) then |
||
53 | self.f.BG:Show() |
||
54 | else |
||
55 | self.f.BG:Hide() |
||
56 | end |
||
57 | |||
58 | self.ColorFade = self.db.profile.ColorFade |
||
59 | |||
60 | -- Clear all points for the ring |
||
61 | self.f:ClearAllPoints() |
||
62 | self.f:SetValue(0) |
||
63 | if(self.db.profile.Side == 1) then |
||
64 | -- Attach to left side |
||
65 | self.f:SetPoint("TOPLEFT", self.parent:GetModule("Anchors").Left, "TOPLEFT", self.db.profile.Level * -15, 0) |
||
66 | self.f.BG:SetReversed(false) |
||
67 | self.f:SetReversed(false) |
||
68 | else |
||
69 | -- Attach to right side |
||
70 | self.f:SetPoint("TOPRIGHT", self.parent:GetModule("Anchors").Right, "TOPRIGHT", self.db.profile.Level * 15, 0) |
||
71 | self.f.BG:SetReversed(true) |
||
72 | self.f:SetReversed(true) |
||
73 | end |
||
74 | self.f:SetValue(UnitHealth(self.unit)) |
||
75 | self.f.BG:SetAngle(180) |
||
76 | end |
||
77 | |||
78 | function module:Enable() |
||
79 | -- Initial setup |
||
80 | self.f:UpdateColor({["r"] = 0.1, ["g"] = 0.9, ["b"] = 0.0}) |
||
81 | self.f:SetMax(UnitHealthMax(self.unit)) |
||
82 | |||
83 | self.f.pulse = false |
||
84 | |||
85 | if(UnitIsGhost(self.unit)) then |
||
86 | self.f:GhostMode(true, self.unit) |
||
87 | else |
||
88 | self.f:GhostMode(false, self.unit) |
||
89 | self.f:SetValue(UnitHealth(self.unit)) |
||
90 | self.HPText:SetText(UnitHealth(self.unit).."/"..UnitHealthMax(self.unit)) |
||
91 | self.HPText:SetTextColor(0, 1, 0) |
||
92 | self.HPPerc:SetText(floor((UnitHealth(self.unit)/UnitHealthMax(self.unit))*100).."%") |
||
93 | self.DefText:SetText("0") |
||
94 | end |
||
95 | |||
96 | -- Register the events we will use |
||
97 | self:RegisterEvent("UNIT_HEALTH", "UpdateHealth") |
||
98 | self:RegisterEvent("UNIT_MAXHEALTH", "UpdateHealth") |
||
99 | self:RegisterEvent("PLAYER_LEVEL_UP") |
||
100 | |||
101 | -- Activate the timers |
||
102 | self:StartMetro(self.name .. "Alpha") |
||
103 | self:StartMetro(self.name .. "Fade") |
||
104 | self:StartMetro(self.name .. "Update") |
||
105 | |||
106 | self.f:Show() |
||
107 | end |
||
108 | |||
109 | function module:PLAYER_LEVEL_UP() |
||
110 | self.f:SetMax(UnitHealthMax(self.unit)) |
||
111 | end |
||
112 | |||
113 | function module:UpdateHealth() |
||
114 | if(arg1 == self.unit) then |
||
115 | local p=UnitHealth(self.unit)/UnitHealthMax(self.unit) |
||
116 | local r, g = 1, 1 |
||
117 | if ( p > 0.5 ) then |
||
118 | r = (1.0 - p) * 2 |
||
119 | g = 1.0 |
||
120 | else |
||
121 | r = 1.0 |
||
122 | g = p * 2 |
||
123 | end |
||
124 | if ( r < 0 ) then r = 0 elseif ( r > 1 ) then r = 1 end |
||
125 | if ( g < 0 ) then g = 0 elseif ( g > 1 ) then g = 1 end |
||
126 | |||
127 | if(UnitIsGhost(self.unit)) then |
||
128 | self.f:GhostMode(true, self.unit) |
||
129 | else |
||
130 | self.f:GhostMode(false, self.unit) |
||
131 | |||
132 | if(self.ColorFade) then |
||
133 | self.f:UpdateColor({["r"] = r, ["g"] = g, ["b"] = 0.0}) |
||
134 | self.HPText:SetTextColor(r, g, 0) |
||
135 | else |
||
136 | self.HPText:SetTextColor(0, 1, 0) |
||
137 | self.f:UpdateColor({["r"] = 0, ["g"] = 1, ["b"] = 0.0}) |
||
138 | end |
||
139 | self.HPText:SetText(UnitHealth(self.unit).."/"..UnitHealthMax(self.unit)) |
||
140 | self.HPPerc:SetText(floor((UnitHealth(self.unit)/UnitHealthMax(self.unit))*100).."%") |
||
141 | |||
142 | local deficit = UnitHealthMax(self.unit) - UnitHealth(self.unit) |
||
143 | if deficit <= 0 then |
||
144 | deficit = "" |
||
145 | else |
||
146 | deficit = "-" .. deficit |
||
147 | end |
||
148 | self.DefText:SetText(deficit) |
||
149 | |||
150 | self.f:SetMax(UnitHealthMax(self.unit)) |
||
151 | self.f:SetValue(UnitHealth(self.unit)) |
||
152 | end |
||
153 | end |
||
154 | end |