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