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