Nenue@0
|
1 --------------------------------------------
|
Nenue@0
|
2 -- KrakTool
|
Nenue@0
|
3 -- Nick
|
Nenue@0
|
4 -- @project - r e v i s i o n @ @project-hash@
|
Nenue@0
|
5 -- @file - r e v i s i o n @ @file-hash@
|
Nenue@0
|
6 -- Created: 6/16/2016 3:46 AM
|
Nenue@0
|
7 --------------------------------------------
|
Nenue@0
|
8
|
Nenue@1
|
9 local KT = LibKT.register(SkeletonUnits)
|
Nenue@0
|
10 local PLAYER_NAMEPLATE
|
Nenue@0
|
11 local PLAYER_WIDTH = 220
|
Nenue@0
|
12 local BUFF_SIZE = 24
|
Nenue@1
|
13 local sk = SkeletonUnits
|
Nenue@1
|
14 local player = KTPlayerFrame
|
Nenue@1
|
15 local prototypes = {
|
Nenue@1
|
16 player = {},
|
Nenue@1
|
17 target = {},
|
Nenue@1
|
18 pet = {},
|
Nenue@1
|
19 focus = {}
|
Nenue@1
|
20 }
|
Nenue@1
|
21 local units = {}
|
Nenue@1
|
22 local buttons = {}
|
Nenue@1
|
23 local params = {
|
Nenue@1
|
24 player = {width = 220, height = 30},
|
Nenue@1
|
25 pet = {height = 25}
|
Nenue@1
|
26 }
|
Nenue@1
|
27 sk.handler = sk -- so sk.event can work
|
Nenue@0
|
28
|
Nenue@0
|
29
|
Nenue@1
|
30 local UpdateUnitAnchor = function(self)
|
Nenue@1
|
31 self.nameplate = C_NamePlate.GetNamePlateForUnit(self.unit)
|
Nenue@1
|
32 if self.nameplate and self.nameplate.namePlateUnitToken then
|
Nenue@1
|
33 self:ClearAllPoints()
|
Nenue@1
|
34 self:SetPoint('TOP', self.nameplate, 'BOTTOM', 0, 0)
|
Nenue@1
|
35 print('snapping', self.unit, 'to', self.nameplate.namePlateUnitToken)
|
Nenue@1
|
36 else
|
Nenue@1
|
37 self:ClearAllPoints()
|
Nenue@1
|
38 self:SetPoint(unpack(self.anchorPoint))
|
Nenue@1
|
39 end
|
Nenue@0
|
40 end
|
Nenue@0
|
41
|
Nenue@0
|
42 local SetupButton = function(self, unit, index)
|
Nenue@1
|
43 if not buttons[unit][index] then
|
Nenue@1
|
44 buttons[unit][index] = CreateFrame('Frame', 'KT'..unit..'Buff'..index, self, 'KTAuraButton')
|
Nenue@1
|
45 buttons[unit][index]:SetSize(BUFF_SIZE, BUFF_SIZE)
|
Nenue@1
|
46 buttons[unit][index].cooldown:SetHideCountdownNumbers(true)
|
Nenue@0
|
47
|
Nenue@0
|
48 end
|
Nenue@1
|
49 return buttons[unit][index]
|
Nenue@0
|
50 end
|
Nenue@0
|
51
|
Nenue@1
|
52 sk.init = function()
|
Nenue@1
|
53 for unit, handler in pairs(prototypes) do
|
Nenue@1
|
54 if not _G['KT'..unit..'Frame'] then
|
Nenue@1
|
55 CreateFrame('Frame', 'KT'.. unit .. 'Frame', sk)
|
Nenue@1
|
56 end
|
Nenue@1
|
57 local frame = _G['KT'..unit..'Frame']
|
Nenue@1
|
58 frame.unit = unit
|
Nenue@1
|
59 frame.anchorPoint = {frame:GetPoint(1)}
|
Nenue@1
|
60 frame.handler = handler
|
Nenue@1
|
61 if handler.init then
|
Nenue@1
|
62 handler.init(frame, unit)
|
Nenue@1
|
63 end
|
Nenue@1
|
64 buttons[unit] = {}
|
Nenue@1
|
65 units[unit] = frame
|
Nenue@1
|
66 end
|
Nenue@1
|
67
|
Nenue@1
|
68 sk:RegisterEvent('PLAYER_TARGET_CHANGED')
|
Nenue@1
|
69 sk:RegisterUnitEvent("UNIT_AURA")
|
Nenue@1
|
70 end
|
Nenue@1
|
71 sk.variables = function()
|
Nenue@1
|
72 for unit, frame in pairs(units) do
|
Nenue@1
|
73 if frame.handler.variables then
|
Nenue@1
|
74 frame.handler.variables(frame, unit)
|
Nenue@1
|
75 end
|
Nenue@1
|
76 local width = params.player.width
|
Nenue@1
|
77 local height = params.player.height
|
Nenue@1
|
78 if params[unit] then
|
Nenue@1
|
79 if params[unit].width then
|
Nenue@1
|
80 width = params[unit].width
|
Nenue@1
|
81 end
|
Nenue@1
|
82 if params[unit].height then
|
Nenue@1
|
83 height = params[unit].height
|
Nenue@1
|
84 end
|
Nenue@1
|
85 end
|
Nenue@1
|
86
|
Nenue@1
|
87 frame:SetWidth(width)
|
Nenue@1
|
88 frame:SetHeight(height)
|
Nenue@1
|
89 end
|
Nenue@1
|
90 end
|
Nenue@1
|
91
|
Nenue@1
|
92 sk.event = function(self, event, ...)
|
Nenue@1
|
93 if self.handler[event] then
|
Nenue@1
|
94 self.handler[event](self, event, ...)
|
Nenue@1
|
95 end
|
Nenue@1
|
96 end
|
Nenue@1
|
97
|
Nenue@1
|
98 sk.PLAYER_TARGET_CHANGED = function()
|
Nenue@1
|
99 prototypes.player.refresh(units.target)
|
Nenue@1
|
100 end
|
Nenue@1
|
101
|
Nenue@1
|
102 prototypes.player.init = function(self)
|
Nenue@1
|
103 self:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", self.unit)
|
Nenue@1
|
104 self:RegisterUnitEvent("UNIT_POWER_FREQUENT", self.unit)
|
Nenue@1
|
105 self:RegisterEvent("NAME_PLATE_UNIT_ADDED")
|
Nenue@1
|
106 self:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
|
Nenue@1
|
107 self:RegisterEvent("UNIT_TARGET")
|
Nenue@1
|
108 self:SetScript('OnEvent', sk.event)
|
Nenue@1
|
109 end
|
Nenue@1
|
110
|
Nenue@1
|
111 --- Runs once
|
Nenue@1
|
112 prototypes.player.variables = function(self)
|
Nenue@1
|
113 self.handler.refresh(self)
|
Nenue@1
|
114 end
|
Nenue@1
|
115
|
Nenue@1
|
116 --- Runs when event handler decides so
|
Nenue@1
|
117 prototypes.player.refresh = function(self)
|
Nenue@1
|
118 if not UnitExists(self.unit) then
|
Nenue@1
|
119 self:Hide()
|
Nenue@1
|
120 return
|
Nenue@1
|
121 end
|
Nenue@1
|
122
|
Nenue@1
|
123 local class, classFile = UnitClass(self.unit)
|
Nenue@1
|
124 if classFile then
|
Nenue@1
|
125 self.healthbar:SetColorTexture(RAID_CLASS_COLORS[classFile].r, RAID_CLASS_COLORS[classFile].g, RAID_CLASS_COLORS[classFile].b)
|
Nenue@1
|
126 end
|
Nenue@1
|
127
|
Nenue@1
|
128 self.handler.UNIT_HEALTH_FREQUENT(self)
|
Nenue@1
|
129 self.handler.UNIT_POWER_FREQUENT(self)
|
Nenue@1
|
130 end
|
Nenue@1
|
131
|
Nenue@1
|
132 sk.UNIT_AURA = function(self, event, unit)
|
Nenue@1
|
133 if not units[unit] then return end
|
Nenue@1
|
134
|
Nenue@0
|
135 local buffOffset = 0
|
Nenue@1
|
136 local buttons = buttons[unit]
|
Nenue@0
|
137 for i = 1, 16 do
|
Nenue@1
|
138
|
Nenue@1
|
139 local aura, _, texture, count, dispelType, duration, expires, caster = UnitAura(unit, i, 'HARMFUL')
|
Nenue@0
|
140 if aura then
|
Nenue@1
|
141 local button = SetupButton(units[unit], unit, i)
|
Nenue@0
|
142
|
Nenue@0
|
143 button.icon:SetTexture(texture)
|
Nenue@0
|
144 button.cooldown:SetCooldown(expires - duration, duration)
|
Nenue@0
|
145 button.cooldown:Show()
|
Nenue@0
|
146 button.count:SetText(count > 0 and count or nil)
|
Nenue@1
|
147 button:SetPoint('BOTTOMLEFT', units[unit], 'TOPLEFT', buffOffset* BUFF_SIZE, 2)
|
Nenue@0
|
148 button:Show()
|
Nenue@0
|
149 buffOffset = buffOffset + 1
|
Nenue@0
|
150 else
|
Nenue@0
|
151 if buttons[i] then
|
Nenue@0
|
152 buttons[i]:Hide()
|
Nenue@0
|
153 end
|
Nenue@0
|
154 end
|
Nenue@0
|
155 end
|
Nenue@0
|
156 end
|
Nenue@0
|
157
|
Nenue@1
|
158 prototypes.player.NAME_PLATE_UNIT_ADDED = function(self, event, nameplate)
|
Nenue@1
|
159 UpdateUnitAnchor(self)
|
Nenue@1
|
160 end
|
Nenue@1
|
161 prototypes.player.NAME_PLATE_UNIT_REMOVED = function(self, event, nameplate)
|
Nenue@1
|
162 UpdateUnitAnchor(self)
|
Nenue@1
|
163 end
|
Nenue@1
|
164
|
Nenue@1
|
165 prototypes.player.UNIT_HEALTH_FREQUENT = function(self, ...)
|
Nenue@1
|
166 if UnitHealthMax(self.unit) > 0 then
|
Nenue@1
|
167 self.healthbar:SetWidth(PLAYER_WIDTH * UnitHealth(self.unit) / UnitHealthMax(self.unit))
|
Nenue@1
|
168 self.healthtext:SetText(UnitHealth(self.unit))
|
Nenue@1
|
169 else
|
Nenue@1
|
170 self.healthbar:SetWidth(PLAYER_WIDTH)
|
Nenue@1
|
171 self.healthtext:SetText(nil)
|
Nenue@0
|
172 end
|
Nenue@1
|
173 return true
|
Nenue@0
|
174 end
|
Nenue@1
|
175
|
Nenue@1
|
176 prototypes.player.UNIT_POWER_FREQUENT = function(self)
|
Nenue@1
|
177 if UnitPowerMax(self.unit) > 0 then
|
Nenue@1
|
178 self.powerbar:SetWidth(PLAYER_WIDTH * UnitPower(self.unit) / UnitPowerMax(self.unit))
|
Nenue@1
|
179 self.powertext:SetText(UnitPower(self.unit))
|
Nenue@1
|
180 else
|
Nenue@1
|
181 self.powerbar:Hide()
|
Nenue@1
|
182 self.powertext:SetText(nil)
|
Nenue@1
|
183 end
|
Nenue@1
|
184 return true
|
Nenue@1
|
185 end
|
Nenue@1
|
186
|
Nenue@1
|
187
|
Nenue@1
|
188 prototypes.player.UNIT_TARGET = function(self, ...)
|
Nenue@1
|
189 if not UnitExists(self.unit) then
|
Nenue@1
|
190 self:Hide()
|
Nenue@1
|
191 else
|
Nenue@1
|
192 self:Show()
|
Nenue@1
|
193 self.handler.refresh(self)
|
Nenue@1
|
194 UpdateUnitAnchor(self)
|
Nenue@0
|
195 end
|
Nenue@0
|
196 end
|
Nenue@0
|
197
|
Nenue@1
|
198 prototypes.pet = prototypes.player
|
Nenue@1
|
199 prototypes.target = prototypes.player |