PHP код:
local engine, modules, media = select(2, ...):unpack()
local n = modules:LoadModule("NamePlates")
local nameplates, visible = {}, {}
local units = {
["pet"] = true, ["target"] = true,
["party1"] = true, ["partypet1"] = true,
["party2"] = true, ["partypet2"] = true,
["party3"] = true, ["partypet3"] = true,
["party4"] = true, ["partypet4"] = true,
["arena1"] = true, ["arenapet1"] = true,
["arena2"] = true, ["arenapet2"] = true,
["arena3"] = true, ["arenapet3"] = true,
}
-- черный список для дебафов игрока , дебафы которые не нужно отображать на нижней полоске
local blackLicst = {
-- вар
[30070] = true,
[12721] = true,
[46857] = true,
}
-- фильтр для верхней полоски аур (там бафы и дебафы) , это белый лист для аур и черный список для дебафов (нижней полоски)
local AuraList = {
-- щиты общее
[53601] = true, -- священный щит
[58597] = true, -- священный щит поглощение
[48066] = true, -- слово силы щит (прист)
[6788] = true, -- ослабленная душа (прист дебаф от щита)
[60503] = true,
-- Рыцарь смерти
[47481] = true, -- Отгрызть
[51209] = true, -- Ненасытная стужа
[47476] = true, -- Удушение
-- Друид
[5211] = true, -- Оглушить
[33786] = true, -- Смерч
[2637] = true, -- Спячка
[22570] = true, -- Калечение
[9005] = true, -- Наскок
[339] = true, -- Гнев деревьев
[19675] = true, -- Звериная атака - эффект
[69369] = true,
-- Охотник
[60210] = true, -- Эффект замораживающей стрелы
[3355] = true, -- Эффект замораживающей ловушки
[24394] = true, -- Устрашение
[1513] = true, -- Отпугивание зверя
[19503] = true, -- Дизориентирующий выстрел
[19386] = true, -- Укус виверны
[34490] = true, -- Глушащий выстрел
[53359] = true, -- Выстрел химеры - сорпид
[19306] = true, -- Контратака
[19185] = true, -- Удержание
-- Питомец Охотника
[50519] = true, -- Ультразвук
[50245] = true, -- Шип
[50518] = true, -- Накинуться
[54706] = true, -- Ядовитая паутина
[4167] = true, -- Сеть
-- Маг
[44572] = true, -- Глубокая замарозка
[31661] = true, -- Дыхание дракона
[12355] = true, -- Сотрясение
[118] = true, -- Превращение
[18469] = true, -- Антимагия - немота
[64346] = true, -- Огненная расплата
[33395] = true, -- Холод
[122] = true, -- Кольцо льда
[11071] = true, -- Обморожение
[55080] = true, -- Разрушенная преграда
-- Паладин
[853] = true, -- Молот правосудия
[2812] = true, -- Гнев небес
[20066] = true, -- Покаяние
[20170] = true, -- Оглушение
[10326] = true, -- Изгнание зла
[63529] = true, -- Немота - Щит храмовника
-- Жрец
[605] = true, -- Контроль над разумом
[64044] = true, -- Глубинный ужас
[8122] = true, -- Ментальный крик
[9484] = true, -- Сковывание нежити
[15487] = true, -- Безмолвие
[64058] = true, -- Глубинный ужас
[33206] = true,
-- Разбойник
[2094] = true, -- Ослепление
[1833] = true, -- Подлый трюк
[1776] = true, -- Парализующий удар
[408] = true, -- Удар по почкам
[6770] = true, -- Ошеломление
[1330] = true, -- Гаррота - немота
[18425] = true, -- Пинок - немота
[51722] = true, -- Долой оружие
-- Шаман
[39796] = true, -- Оглушение каменного когтя
[51514] = true, -- Сглаз
[64695] = true, -- Хватка земли
[63685] = true, -- Заморозка
[3600] = true, -- Оковы земли
[8056] = true, -- Ледяной шок
[8034] = true, -- Наложение ледяного клейма
[49284] = true, -- щит земли
-- Чернокнижник
[710] = true, -- Изгнание
[6789] = true, -- Лик смерти
[5782] = true, -- Страх
[5484] = true, -- Вой ужаса
[6358] = true, -- Соблазн
[30283] = true, -- Неистовство Тьмы
[24259] = true, -- Запрет чар
[18118] = true, -- Огненный шлейф
[18223] = true, -- Проклятие изнеможения
-- Воин
[7922] = true, -- Наскок и оглушение
[12809] = true, -- Оглушающий удар
[20253] = true, -- Перехват
[5246] = true, -- Устрашающий крик
[12798] = true, -- Реванш - оглушение
[46968] = true, -- Ударная волна
[18498] = true, -- Обет молчания - немота
[676] = true, -- Разоружение
[58373] = true, -- Символ подрезанного сухожилия
[23694] = true, -- Улучшенное подрезание сухожилий
}
local IsTarget = function(frame)
return frame:IsShown() and frame:GetAlpha() == 1 and UnitExists("target") or false
end
function n:GetNameplate(unit)
if self.InArena then
local min, max, name = UnitHealth(unit), UnitHealthMax(unit), UnitName(unit)
local tmp
for plate in pairs(visible) do
if plate:IsShown() then
if name==plate.name:GetText() then
local hb = plate.health
if min==hb:GetValue() and max==select(2, hb:GetMinMaxValues()) then
tmp = plate
break
end
end
end
end
return tmp
else
return self.targeted
end
end
local SetPosition = function(icons, x)
if(icons and x > 0) then
local col = 0
local row = 0
local gap = icons.gap
local sizex = (icons.size or 16) + (icons['spacing-x'] or icons.spacing or 0)
local sizey = (icons.size or 16) + (icons['spacing-y'] or icons.spacing or 0)
local anchor = icons.initialAnchor or "BOTTOMLEFT"
local growthx = (icons["growth-x"] == "LEFT" and -1) or 1
local growthy = (icons["growth-y"] == "DOWN" and -1) or 1
local cols = icons.cols
for i = 1, #icons do
local button = icons[i]
if(button and button:IsShown()) then
if(col >= cols) then
col = 0
row = row + 1
end
button:ClearAllPoints()
button:SetPoint(anchor, icons, anchor, col * sizex * growthx, row * sizey * growthy)
col = col + 1
elseif(not button) then
break
end
end
if col > 0 then
icons:SetHeight(sizey)
else
icons:SetHeight(1)
end
icons:SetWidth((col * sizex) + 1)
end
end
local Icon_OnUpdate
do
local FormatTime, GetTime = engine.FormatTime, GetTime
Icon_OnUpdate = function(self)
local endTime = self.timeLeft - GetTime()
if endTime > 0 then
self.timer:SetText(FormatTime(endTime))
end
end
end
local createAuraIcon = function(icons, index)
local button = CreateFrame("frame", nil, icons)
button.icons = icons
button:SetWidth(icons.size or 16)
button:SetHeight(icons.size or 16)
local icon = button:CreateTexture(nil, "BACKGROUND")
icon:SetAllPoints(button)
local count = button:CreateFontString(nil, "OVERLAY")
count:SetFontObject(NumberFontNormal)
count:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -1, 0)
local timer = button:CreateFontString(nil, "OVERLAY")
timer:SetFontObject(NumberFontNormal)
timer:SetPoint("TOP", button, "BOTTOM", 0, -1)
local overlay = button:CreateTexture(nil, "OVERLAY")
overlay:SetTexture"Interface\\Buttons\\UI-Debuff-Overlays"
overlay:SetAllPoints(button)
overlay:SetTexCoord(.296875, .5703125, 0, .515625)
button.overlay = overlay
table.insert(icons, button)
button.parent = icons
button.icon = icon
button.count = count
button.timer = timer
return button
end
local customFilter = function(icons, unit, icon, name, rank, texture, count, dtype, duration, timeLeft, caster, isStealable, shouldConsolidate, spellID)
if duration == 0 then return false end
local isPlayer
if(caster == 'player' or caster == 'vehicle') then
isPlayer = true
end
local filter = AuraList[spellID]
if(icons.onlyShowPlayer) then
if isPlayer and not filter and not blackLicst[spellID] then
icon.isPlayer = isPlayer
icon.owner = caster
return true
end
else
if filter then
return true
end
end
end
local updateIcon = function(unit, icons, index, offset, filter, isDebuff, max)
local name, rank, texture, count, dtype, duration, timeLeft, caster, isStealable, shouldConsolidate, spellID = UnitAura(unit, index, filter)
if(name) then
local icon = icons[index + offset]
if(not icon) then
icon = createAuraIcon(icons, index)
end
local show = (icons.CustomFilter or customFilter) (icons, unit, icon, name, rank, texture, count, dtype, duration, timeLeft, caster, isStealable, shouldConsolidate, spellID)
if(show) then
local color = DebuffTypeColor[dtype] or DebuffTypeColor.none
icon.overlay:SetVertexColor(color.r, color.g, color.b)
icon.overlay:Show()
icon.icon:SetTexture(texture)
icon.count:SetText((count > 1 and count))
icon.filter = filter
icon.debuff = isDebuff
icon:SetID(index)
icon:Show()
if duration > 0 then
icon.timeLeft = timeLeft
icon:SetScript("OnUpdate", Icon_OnUpdate)
else
icon.timeLeft = nil
end
return 1
else
icon:Hide()
return 0
end
end
end
local filterIcons = function(unit, icons, filter, limit, isDebuff, offset, dontHide)
if(not offset) then offset = 0 end
local index = 1
local visible = 0
while(visible < limit) do
local result = updateIcon(unit, icons, index, offset, filter, isDebuff)
if(not result) then
break
elseif(result == VISIBLE) then
visible = visible + 1
end
index = index + 1
end
if(not dontHide) then
for i = offset + index, #icons do
icons[i]:Hide()
end
end
return visible, index - 1
end
local CASTING_BAR_ALPHA_STEP, CASTING_BAR_HOLD_TIME = CASTING_BAR_ALPHA_STEP, CASTING_BAR_HOLD_TIME
function n:OnEvent(event, unit, _, _, castid)
if unit=="player" or not units[unit] then return end
local plate = self:GetNameplate(unit)
if not plate then return end
if event=="UNIT_AURA" then
local auras = plate.Auras
if(auras) then
local numBuffs = auras.numBuffs or 32
local numDebuffs = auras.numDebuffs or 40
local max = numBuffs + numDebuffs
local visibleBuffs, offset = filterIcons(unit, auras, auras.buffFilter or auras.filter or 'HELPFUL', numBuffs, nil, 0, true)
auras.visibleBuffs = visibleBuffs
auras.visibleDebuffs = filterIcons(unit, auras, auras.debuffFilter or auras.filter or 'HARMFUL', numDebuffs,true, offset)
auras.visibleAuras = auras.visibleBuffs + auras.visibleDebuffs
SetPosition(auras, max)
end
local debuffs = plate.Debuffs
if(debuffs) then
local numDebuffs = debuffs.num or 40
debuffs.visibleDebuffs = filterIcons(unit, debuffs, debuffs.filter or 'HARMFUL', numDebuffs, true)
SetPosition(debuffs, numDebuffs)
end
else
local castbar = plate.castbar
if event=="UNIT_SPELLCAST_START" then
local name, _, text, texture, startTime, endTime, isTradeSkill, castid, interrupt = UnitCastingInfo(unit)
if(not name) then
return
end
castbar.duration = GetTime() - (startTime/1000)
castbar.max = (endTime - startTime) / 1000
castbar:SetValue(0)
castbar:SetStatusBarColor(1.0, 0.7, 0.0)
castbar:SetMinMaxValues(0, castbar.max)
castbar:SetAlpha(1.0)
castbar.holdTime = 0
castbar.casting = 1
castbar.castid = castid
castbar.delay = 0
castbar.channeling = nil
castbar.fadeOut = nil
castbar.interrupt = interrupt
castbar.isTradeSkill = isTradeSkill
if(castbar.icon) then
castbar.icon:SetTexture(texture)
end
castbar:Show()
elseif event=="UNIT_SPELLCAST_FAILED" then
if(castbar.castid ~= castid) then
return
end
castbar:SetValue(castbar.max)
castbar:SetStatusBarColor(1.0, 0.0, 0.0)
castbar.casting = nil
castbar.channeling = nil
castbar.interrupt = nil
castbar.fadeOut = 1
castbar.holdTime = GetTime() + CASTING_BAR_HOLD_TIME
elseif event=="UNIT_SPELLCAST_INTERRUPTED" then
if(castbar.castid ~= castid) then
return
end
castbar:SetValue(castbar.max)
castbar:SetStatusBarColor(1.0, 0.0, 0.0)
castbar.casting = nil
castbar.channeling = nil
castbar.fadeOut = 1
castbar.holdTime = GetTime() + CASTING_BAR_HOLD_TIME
elseif event=="UNIT_SPELLCAST_DELAYED" then
if(castbar:IsShown()) then
local name, _, text, texture, startTime, endTime, isTradeSkill = UnitCastingInfo(unit)
if(not name) then
return
end
local duration = GetTime() - (startTime / 1000)
if(duration < 0) then duration = 0 end
castbar.delay = castbar.delay + castbar.duration - duration
castbar.duration = duration
castbar:SetValue(duration)
castbar:SetStatusBarColor(1.0, 0.7, 0.0)
if(not castbar.casting) then
castbar.casting = 1
castbar.channeling = nil
castbar.fadeOut = 0
end
end
elseif event=="UNIT_SPELLCAST_STOP" then
if(castbar.castid == castid and castbar.casting and (not castbar.fadeOut)) then
castbar:SetValue(castbar.max)
castbar.casting = nil
castbar.interrupt = nil
castbar.fadeOut = 1
castbar.holdTime = 0
castbar:SetStatusBarColor(0, 1, 0.0)
end
if not castbar.fadeOut then
castbar:SetStatusBarColor(0, 1, 0.0)
end
elseif event=="UNIT_SPELLCAST_CHANNEL_START" then
local name, _, text, texture, startTime, endTime, isTradeSkill, notInterruptible = UnitChannelInfo(unit);
if(not name) then
return
end
castbar.duration = ((endTime / 1000) - GetTime())
castbar.max = (endTime - startTime) / 1000
castbar.delay = 0
castbar:SetMinMaxValues(0, castbar.max)
castbar:SetValue(castbar.duration)
castbar:SetStatusBarColor(0.0, 1.0, 0.0)
if(castbar.icon) then
castbar.icon:SetTexture(texture)
end
castbar:SetAlpha(1.0)
castbar.holdTime = 0
castbar.casting = nil
castbar.channeling = 1
castbar.interrupt = notInterruptible
castbar.fadeOut = nil
castbar:Show()
elseif event=="UNIT_SPELLCAST_CHANNEL_UPDATE" then
if(castbar:IsShown()) then
local name, _, text, texture, startTime, endTime, isTradeSkill = UnitChannelInfo(unit)
if(not name) then
return
end
local duration = ((endTime / 1000) - GetTime())
castbar.delay = castbar.delay + castbar.duration - duration
castbar.duration = duration
castbar.max = (endTime - startTime) / 1000
castbar:SetMinMaxValues(0, castbar.max)
castbar:SetValue(duration)
end
elseif event=="UNIT_SPELLCAST_CHANNEL_STOP" then
if(castbar:IsShown() or castbar.channeling) then
castbar:SetValue(castbar.max)
castbar.channeling = nil
castbar.interrupt = nil
castbar.fadeOut = 1
castbar.holdTime = 0
end
end
end
end
function n:PLAYER_ENTERING_WORLD()
self.InArena = select(2,IsInInstance()) == "arena"
if self.InArena then
self:UnregisterEvent("PLAYER_TARGET_CHANGED")
for k, v in pairs(units) do
if k == "target" then
units[k] = false
else
units[k] = true
end
end
else
self:RegisterEvent("PLAYER_TARGET_CHANGED")
for k, v in pairs(units) do
if k=="target" then
units[k] = true
else
units[k] = false
end
end
end
end
local HideStuff = function(self)
for i = 1, #self.Debuffs do
local icon = self.Debuffs[i]
if not icon then break end
icon:Hide()
end
for i = 1, #self.Auras do
local icon = self.Auras[i]
if not icon then break end
icon:Hide()
end
self.castbar:Hide()
end
local OnUpdate = function(self)
HideStuff(self)
if IsTarget(self) then
n.targeted = self
end
for unit in next, units do
if unit then
if UnitExists(unit) then
n:OnEvent("UNIT_AURA", unit)
n:OnEvent("UNIT_SPELLCAST_START", unit)
n:OnEvent("UNIT_SPELLCAST_CHANNEL_START", unit)
end
end
end
self:SetScript("OnUpdate", nil)
end
local OnShow = function(self)
visible[self] = true
self:SetScript("OnUpdate", OnUpdate)
end
local OnHide = function(self)
visible[self] = nil
if self == n.targeted then
n.targeted = nil
end
HideStuff(self)
end
do
n.targeted = nil
function n:PLAYER_TARGET_CHANGED()
n.targeted = nil
for frame in pairs(visible) do
frame:SetScript("OnUpdate", OnUpdate)
end
end
end
local IsNamePlate
do
local overlayTexture = [=[Interface\Tooltips\Nameplate-Border]=]
IsNamePlate = function(frame)
if frame:GetName() then return end
local overlayRegion = select(2, frame:GetRegions())
return overlayRegion and overlayRegion:GetObjectType() == "Texture" and overlayRegion:GetTexture() == overlayTexture
end
end
local onUpdate_Castbar = function(self, elapsed)
if ( self.casting ) then
local duration = self.duration + elapsed
if(duration >= self.max) then
self:SetValue(self.max)
self.holdTime = 0
self.fadeOut = 1
self.casting = nil
return
end
self.duration = duration
self:SetValue(duration)
elseif ( self.channeling ) then
local duration = self.duration - elapsed
if(duration <= 0) then
self.fadeOut = 1
self.channeling = nil
self.holdTime = 0
return
end
self.duration = duration
self:SetValue(duration)
elseif ( GetTime() < self.holdTime ) then
return
elseif ( self.fadeOut ) then
local alpha = self:GetAlpha() - CASTING_BAR_ALPHA_STEP
if (alpha > 0.05) then
self:SetAlpha(alpha)
else
self.fadeOut = nil
self:Hide()
end
end
end
local ScanWorldFrameChildren
do
function ScanWorldFrameChildren(frame, ...)
if not frame then return end
if not nameplates[frame] and IsNamePlate(frame) then
local healthBar, castBar = frame:GetChildren()
local glow, overlay, castRegion, shielded, spellIcon, highlight, nameText = frame:GetRegions()
frame.name = nameText
local castbar = engine.CreateStatusBar(frame, nil, nil, true)
castbar:SetFrameLevel(frame:GetFrameLevel()-1)
castbar:SetAllPoints(castBar)
castbar.overlay = castbar:CreateTexture(nil, "ARTWORK")
castbar.overlay:SetTexture(castRegion:GetTexture())
castbar.overlay:SetTexCoord(castRegion:GetTexCoord())
castbar.overlay:SetAllPoints(castRegion)
castbar.icon = castbar:CreateTexture(nil, "OVERLAY")
castbar.icon:SetAllPoints(spellIcon)
castbar.icon:SetTexture(1,1,1)
castbar:Hide()
castbar:SetScript("OnUpdate", onUpdate_Castbar)
frame.castbar = castbar
frame.health = healthBar
frame.Debuffs = CreateFrame("frame", nil, frame)
frame.Debuffs:SetPoint("BOTTOM", frame, "TOP", 0, 12)
frame.Debuffs.size = 26
frame.Debuffs['spacing-x'] = 2
frame.Debuffs['spacing-y'] = 6
frame.Debuffs.cols = 7
frame.Debuffs.num = 7
frame.Debuffs.onlyShowPlayer = true
frame.Auras = CreateFrame("frame", nil, frame)
frame.Auras:SetPoint("BOTTOM", frame.Debuffs, "TOP", 0, 12)
frame.Auras:SetHeight(32)
frame.Auras.size = 32
frame.Auras['spacing-x'] = 2
frame.Auras['spacing-y'] = 6
frame.Auras.cols = 6
frame:SetScript("OnShow", OnShow)
frame:SetScript("OnHide", OnHide)
frame:SetScript("OnUpdate", OnUpdate)
visible[frame] = true
nameplates[frame] = true
end
return ScanWorldFrameChildren(...)
end
end
local HandlePlates
do
local WorldFrame = WorldFrame
local curChildren
local prevChildren = 0
function HandlePlates(this, elapsed)
local curChildren = WorldFrame:GetNumChildren()
if curChildren ~= prevChildren then
prevChildren = curChildren
ScanWorldFrameChildren( WorldFrame:GetChildren() )
end
end
end
function n:Init()
self.InArena = select(2,IsInInstance()) == "arena"
CreateFrame("frame"):SetScript("OnUpdate", HandlePlates)
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("UNIT_AURA", "OnEvent")
self:RegisterEvent("UNIT_SPELLCAST_START", "OnEvent")
self:RegisterEvent("UNIT_SPELLCAST_FAILED", "OnEvent")
self:RegisterEvent("UNIT_SPELLCAST_STOP", "OnEvent")
self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED", "OnEvent")
self:RegisterEvent("UNIT_SPELLCAST_DELAYED", "OnEvent")
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START", "OnEvent")
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE", "OnEvent")
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP", "OnEvent")
SetCVar("ShowVKeyCastbar", 0)
end