/trunk
local kui = LibStub('Kui-1.0') |
local profile, font, sizes, fontSizes, GetNameplate |
local kn = KuiNameplates |
local cw = CreateFrame('Frame') |
-- combat log events to listen to for cast warnings/healing |
guid, name = targetGUID, targetName |
end |
-- [[debug]] |
--guid, name = UnitGUID('target'), GetUnitName('target') |
local f = GetNameplate(guid, name) |
local f = kn.f:GetNameplate(guid, name) |
if f then |
if not f.SetIncomingWarning or f.trivial then return end |
local spName, spSch = select(13, ...) |
if event == 'SPELL_HEAL' or |
event == 'SPELL_PERIODIC_HEAL' |
then |
cw.CreateCastWarnings = function(frame) |
-- casting spell name |
frame.castWarning = kui.CreateFontString(frame.overlay, { |
font = font, size = fontSizes.spellname, outline = 'OUTLINE' }) |
font = kn.font, size = kn.fontSizes.spellname, outline = 'OUTLINE' }) |
frame.castWarning:SetPoint('BOTTOMLEFT', frame.level, 'TOPLEFT', 0, 1) |
frame.castWarning:Hide() |
-- incoming healing |
frame.incWarning = kui.CreateFontString(frame.overlay, { |
font = font, size = fontSizes.small, outline = 'OUTLINE' }) |
font = kn.font, size = kn.fontSizes.small, outline = 'OUTLINE' }) |
frame.incWarning:SetPoint('BOTTOMRIGHT', frame.health.p, 'TOPRIGHT', 1) |
frame.incWarning:Hide() |
end |
end |
-------------------------------------------------------------------- Register -- |
cw.Enable = function(self) |
profile = KuiNameplates.profile |
GetNameplate = KuiNameplates.f.GetNameplate |
font, sizes, fontSizes |
= KuiNameplates.font, KuiNameplates.sizes, KuiNameplates.fontSizes |
KuiNameplates.RegisterPostFunction('create', self.CreateCastWarnings) |
KuiNameplates.RegisterPostFunction('hide', self.HideCastWarnings) |
cw.Enable = function(self) |
kn.RegisterPostFunction('create', self.CreateCastWarnings) |
kn.RegisterPostFunction('hide', self.HideCastWarnings) |
self:SetScript('OnEvent', OnEvent) |
self:RegisterEvent('COMBAT_LOG_EVENT_UNFILTERED') |
end |
KuiNameplates.RegisterModule('warnings', cw) |
kn.RegisterModule('warnings', cw) |
name = 'Combo points', |
desc = 'Show combo points', |
type = 'toggle', |
order = 2 |
order = 3 |
}, |
fixaa = { |
name = 'Fix aliasing', |
desc = 'Attempt to make plates appear sharper, with some drawbacks', |
desc = 'Attempt to make plates appear sharper. Has a positive effect on FPS, but will make plates appear a bit "loose", especially at low frame rates. Works best when uiscale is disabled and at good resolutions.', |
type = 'toggle', |
order = 3 |
order = 4 |
}, |
font = { |
name = 'Font', |
type = 'select', |
dialogControl = 'LSM30_Font', |
values = AceGUIWidgetLSMlists.font, |
order = 4 |
order = 5 |
}, |
fontscale = { |
name = 'Font scale', |
type = 'range', |
min = 0.01, |
softMax = 2, |
order = 5 |
order = 6 |
} |
} |
}, |
}, |
smooth = { |
name = 'Smoothly fade', |
desc = 'Smoothly fade plates in/out (fading is instant disabled)', |
desc = 'Smoothly fade plates in/out (fading is instant when disabled)', |
type = 'toggle', |
order = 0 |
}, |
} |
} |
}, |
text = { |
name = 'Text', |
type = 'group', |
inline = true, |
order = 3, |
args = { |
level = { |
name = 'Show levels', |
desc = 'Show levels on nameplates', |
type = 'toggle', |
order = 2 |
}, |
friendlyname = { |
name = 'Friendly name text colour', |
desc = 'The colour of names of friendly units', |
type = 'color', |
order = 4, |
}, |
enemyname = { |
name = 'Enemy name text colour', |
desc = 'The colour of names of enemy units', |
type = 'color', |
order = 5, |
}, |
} |
}, |
hp = { |
name = 'Health display', |
type = 'group', |
inline = true, |
order = 3, |
order = 4, |
args = { |
showalt = { |
name = 'Show contextual health', |
name = 'Tank mode', |
type = 'group', |
inline = true, |
order = 4, |
order = 5, |
disabled = function(info) |
return not ns.db.profile.tank.enabled |
end, |
name = 'Cast bars', |
type = 'group', |
inline = true, |
order = 5, |
order = 6, |
disabled = function(info) |
return not ns.db.profile.castbar.enabled |
end, |
}, |
usenames = { |
name = 'Use names for warnings', |
desc = 'Use unit names to display cast warnings on their correct frames. May increase memory usage and may cause warnings to be displayed on incorrect frames when there are many units with the same name. Reccommended on for PvP, off for PvE.', |
desc = 'Use unit names to decide which frame to display warnings on. May increase memory usage and may cause warnings to be displayed on incorrect frames when there are many units with the same name. Reccommended on for PvP, off for PvE.', |
type = 'toggle', |
order = 6, |
disabled = function(info) |
reload = { |
name = 'Reload UI', |
type = 'execute', |
width = 'triple', |
order = 99, |
func = ReloadUI |
}, |
} |
barcolour = { .2, .9, .1, 1 }, -- the bar colour to use when you have threat |
glowcolour = { 1, 0, 0, 1, 1 } -- the glow colour to use when you have threat |
}, |
text = { |
level = true, -- display levels |
friendlyname = { 1, 1, 1 }, -- friendly name text colour |
enemyname = { 1, 1, 1 } -- enemy name text colour |
}, |
hp = { |
friendly = '=:m;<:d;', -- health display pattern for friendly units |
hostile = '<:p;', -- health display pattern for hostile/neutral units |
showalt = true, -- show alternate (contextual) health values as well as main values |
showalt = false, -- show alternate (contextual) health values as well as main values |
mouseover = false, -- hide health values until you mouse over or target the plate |
tapped = true, -- use grey health bar colour for tapped units |
smooth = true -- smoothly animate health bar changes |
local LSM = LibStub('LibSharedMedia-3.0') |
KuiNameplates = { |
f = CreateFrame('Frame'), |
font = '', fontSizes = {}, sizes = {} |
} |
-- our frame, whee |
KuiNameplates.f = CreateFrame('Frame') |
ns.f = KuiNameplates.f |
-- Custom reaction colours |
{ .5, .5, .5 }, -- tapped |
} |
local bgOffset = 4 -- inset offset for the frame glow (frame.bg) |
local uiscale, prevuiscale |
local bgOffset = 4 -- inset offset for the frame glow (frame.bg) |
local loadedGUIDs, loadedNames, targetExists, profile = {}, {} |
local origSizes, origFontSizes = {},{} |
local font, sizes, fontSizes = '', {}, {} |
--------------------------------------------------------------------- globals -- |
local strsplit, pairs, ipairs, unpack |
= strsplit, pairs, ipairs, unpack |
local select, strfind, strsplit, pairs, ipairs, unpack |
= select, strfind, strsplit, pairs, ipairs, unpack |
-- helper for setting a given fontstring's font size |
local function SetFontSize(fontstring, size) |
local font, _, flags = fontstring:GetFont() |
fontstring:SetFont(font, size, flags) |
end |
-------------------------------------------------- External calling functions -- |
local modules = {} |
local postFunctions = { |
then |
-- store the default colour |
self.health.r, self.health.g, self.health.b = r, g, b |
self.health.reset, self.friend = nil, nil |
self.health.reset, self.friend, self.player = nil, nil, nil |
if g > .9 and r == 0 and b == 0 then |
-- friendly NPC |
elseif b > .9 and r == 0 and g == 0 then |
-- friendly player |
self.friend = true |
self.player = true |
r, g, b = 0, .3, .6 |
elseif r > .9 and g == 0 and b == 0 then |
-- enemy NPC |
-- or don't change |
return |
end |
else |
-- enemy player, use default UI colour |
self.player = true |
end |
-- enemy player, use default UI colour |
self.health:SetStatusBarColor(r, g, b) |
end |
end |
local function SetNameColour(self) |
if self.friend then |
self.name:SetTextColor(unpack(profile.text.friendlyname)) |
else |
self.name:SetTextColor(unpack(profile.text.enemyname)) |
end |
end |
local function SetGlowColour(self, r, g, b, a) |
if not r then |
-- set default colour |
end |
-- classifications |
if self.boss:IsVisible() then |
self.level:SetText('??b') |
self.level:SetTextColor(1, 0, 0) |
self.level:Show() |
elseif self.state:IsVisible() then |
if self.state:GetTexture() == "Interface\\Tooltips\\EliteNameplateIcon" |
then |
self.level:SetText(self.level:GetText()..'+') |
else |
self.level:SetText(self.level:GetText()..'r') |
if self.level.enabled then |
if self.boss:IsVisible() then |
self.level:SetText('??b') |
self.level:SetTextColor(1, 0, 0) |
self.level:Show() |
elseif self.state:IsVisible() then |
if self.state:GetTexture() == "Interface\\Tooltips\\EliteNameplateIcon" |
then |
self.level:SetText(self.level:GetText()..'+') |
else |
self.level:SetText(self.level:GetText()..'r') |
end |
end |
else |
self.level:Hide() |
end |
if self.state:IsVisible() then |
-- hide the elite/rare dragon |
self.state:Hide() |
SetFontSize(self.name, fontSizes.small) |
self.name:SetJustifyH('CENTER') |
self.name:SetPoint('BOTTOMLEFT', self.health, 'TOPLEFT', -10, 0) |
self.name:SetPoint('BOTTOMRIGHT', self.health, 'TOPRIGHT', 10, 0) |
self.name:SetPoint('BOTTOMLEFT', self.health, 'TOPLEFT', -10, -3) |
self.name:SetPoint('BOTTOMRIGHT', self.health, 'TOPRIGHT', 10, -3) |
self.bg.fill:SetSize(sizes.twidth, sizes.theight) |
self.health:SetSize(sizes.twidth-2, sizes.theight-2) |
self.bg.fill:ClearAllPoints() |
self.name:ClearAllPoints() |
self.level:Show() |
self.health.p:Show() |
self.health.p:Show() |
if self.health.mo then |
self.health.mo:Show() |
SetFontSize(self.name, fontSizes.name) |
self.name:SetJustifyH('LEFT') |
self.name:SetPoint('LEFT', self.level, 'RIGHT', -2, 0) |
self.name:SetPoint('RIGHT', self.health.p, 'LEFT') |
if self.level.enabled then |
self.name:SetPoint('LEFT', self.level, 'RIGHT', -2, 0) |
self.level:Show() |
else |
self.name:SetPoint('BOTTOMLEFT', self.health, 'TOPLEFT', 2, uiscale and -(2/uiscale) or -2) |
end |
self.bg.fill:SetSize(sizes.width, sizes.height) |
self.health:SetSize(sizes.width - 2, sizes.height - 2) |
end |
local function OnFrameEnter(self) |
self:StoreGUID(UnitGUID('mouseover')) |
if self.highlight then |
self.highlight:Show() |
end |
self:StoreGUID(UnitGUID('mouseover')) |
if profile.hp.mouseover then |
self.health.p:Show() |
if self.health.mo then self.health.mo:Show() end |
-- Health bar colour |
self:SetHealthColour() |
-- Name text colour |
self:SetNameColour() |
if self.cp then |
-- combo points |
end |
end |
-- Update sizes of child frames, fonts and the position of .bg in this nameplate |
-- To be used when UIScale is changed (i.e. hardly ever) |
-- TODO I don't think I actually use this at the moment |
--[[ |
local function UpdateScales(self) |
self.carrier:SetScale(uiscale) |
self.carrier:SetSize(self:GetWidth()/uiscale, self:GetHeight()/uiscale) |
self.bg.fill:SetSize(sizes.width, sizes.height) |
self.health:SetSize(sizes.width-2, sizes.height-2) |
SetFontSize(self.health.p, fontSizes.large) |
if self.health.mo then |
SetFontSize(self.health.mo, fontSizes.small) |
end |
SetFontSize(self.level, fontSizes.name) |
SetFontSize(self.name, fontSizes.name) |
if self.cp then |
SetFontSize(self.cp, fontSizes.combopoints) |
end |
self.bg:ClearAllPoints() |
self.bg:SetPoint('BOTTOMLEFT', 22-5, 16-5) |
self.bg:SetPoint('TOPRIGHT', self.carrier, 'BOTTOMLEFT', 22+sizes.width+5, 16+sizes.height+5) |
end |
]] |
--------------------------------------------------------------- KNP functions -- |
function ns.f:GetNameplate(guid, name) |
local gf, nf = loadedGUIDs[guid], loadedNames[name] |
end |
function ns.f:IsNameplate(frame) |
if frame:GetName() and string.find(frame:GetName(), '^NamePlate%d') then |
--local healthbar = select(2, frame:GetChildren()); |
--local overlay = select(2, healthbar:GetRegions()); |
--return (overlayRegion and overlayRegion:GetObjectType() == 'Texture') |
return true |
if frame:GetName() and strfind(frame:GetName(), '^NamePlate%d') then |
local nameTextChild = select(2, frame:GetChildren()) |
if nameTextChild then |
local nameTextRegion = nameTextChild:GetRegions() |
return (nameTextRegion and nameTextRegion:GetObjectType() == 'FontString') |
end |
end |
end |
frame.UpdateFrame = UpdateFrame |
frame.UpdateFrameCritical = UpdateFrameCritical |
frame.SetHealthColour = SetHealthColour |
frame.SetNameColour = SetNameColour |
frame.SetGlowColour = SetGlowColour |
frame.IsCasting = IsFrameCasting |
frame.StoreGUID = StoreFrameGUID |
frame.health.mo:SetAlpha(.6) |
end |
-- level text -------------------------------------------------------------- |
frame.level = kui.CreateFontString(frame.level, { reset = true, |
font = font, size = fontSizes.name, outline = 'OUTLINE' }) |
frame.level:SetParent(frame.overlay) |
if profile.text.level then |
-- level text ---------------------------------------------------------- |
frame.level = kui.CreateFontString(frame.level, { reset = true, |
font = font, size = fontSizes.name, outline = 'OUTLINE' }) |
frame.level:SetParent(frame.overlay) |
frame.level:ClearAllPoints() |
frame.level:SetPoint('BOTTOMLEFT', frame.health, 'TOPLEFT', 2, uiscale and -(2/uiscale) or -2) |
frame.level:ClearAllPoints() |
frame.level:SetPoint('BOTTOMLEFT', frame.health, 'TOPLEFT', 2, uiscale and -(2/uiscale) or -2) |
frame.level.enabled = true |
else |
frame.level:Hide() |
end |
-- name text --------------------------------------------------------------- |
frame.name = kui.CreateFontString(frame.overlay, { |
font = font, size = fontSizes.name, outline = 'OUTLINE' }) |
frame.name:SetJustifyH('LEFT') |
frame.name:SetHeight(8) |
frame.name:SetHeight(13) |
frame.name:SetPoint('LEFT', frame.level, 'RIGHT', -2, 0) |
if frame.level.enabled then |
frame.name:SetPoint('LEFT', frame.level, 'RIGHT', -2, 0) |
else |
frame.name:SetPoint('BOTTOMLEFT', frame.health, 'TOPLEFT', 2, uiscale and -(2/uiscale) or -2) |
end |
frame.name:SetPoint('RIGHT', frame.health.p, 'LEFT') |
-- combo point text -------------------------------------------------------- |
------------------------------------------------------------- Script handlers -- |
ns.frames = 0 |
ns.frameList = {} |
do |
local WorldFrame, lastUpdate |
f = select(i, WorldFrame:GetChildren()) |
if self:IsNameplate(f) and not f.init then |
self:InitFrame(f) |
if profile.general.fixaa then |
tinsert(ns.frameList, f) |
end |
end |
end |
local kui = LibStub('Kui-1.0') |
local profile, font, sizes, fontSizes |
local kn = KuiNameplates |
local cb = CreateFrame('Frame') |
local castEvents = { |
['UNIT_SPELLCAST_START'] = true, |
frame.castbarbg:SetBackdropColor(0, 0, 0, .85) |
frame.castbarbg:SetBackdropBorderColor(1, .2, .1, 0) |
frame.castbarbg:SetHeight(sizes.cbheight) |
frame.castbarbg:SetHeight(kn.sizes.cbheight) |
frame.castbarbg:SetPoint('TOPLEFT', frame.bg.fill, 'BOTTOMLEFT', -5, 4) |
frame.castbarbg:SetPoint('TOPRIGHT', frame.bg.fill, 'BOTTOMRIGHT', 5, 0) |
frame.castbar.shield:Hide() |
-- cast bar text ------------------------------------------------------- |
if profile.castbar.spellname then |
if kn.profile.castbar.spellname then |
frame.castbar.name = kui.CreateFontString(frame.castbar, { |
font = font, size = fontSizes.name, outline = "OUTLINE" }) |
font = kn.font, size = kn.fontSizes.name, outline = "OUTLINE" }) |
frame.castbar.name:SetPoint('TOPLEFT', frame.castbar, 'BOTTOMLEFT', 2, -2) |
end |
if profile.castbar.casttime then |
if kn.profile.castbar.casttime then |
frame.castbar.max = kui.CreateFontString(frame.castbar, { |
font = font, size = fontSizes.name, outline = "OUTLINE" }) |
font = kn.font, size = kn.fontSizes.name, outline = "OUTLINE" }) |
frame.castbar.max:SetPoint('TOPRIGHT', frame.castbar, 'BOTTOMRIGHT', -2, -1) |
frame.castbar.curr = kui.CreateFontString(frame.castbar, { |
font = font, size = fontSizes.small, outline = "OUTLINE" }) |
font = kn.font, size = kn.fontSizes.small, outline = "OUTLINE" }) |
frame.castbar.curr:SetAlpha(.5) |
frame.castbar.curr:SetPoint('TOPRIGHT', frame.castbar.max, 'TOPLEFT', -1, -1) |
end |
-- cast bar icon background ---------------------------------------- |
frame.spellbg = frame.castbarbg:CreateTexture(nil, 'BACKGROUND') |
frame.spellbg:SetTexture(kui.m.t.solid) |
frame.spellbg:SetSize(sizes.icon, sizes.icon) |
frame.spellbg:SetSize(kn.sizes.icon, kn.sizes.icon) |
frame.spellbg:SetVertexColor(0, 0, 0, .85) |
-- cast bar icon --------------------------------------------------- |
frame.spell:ClearAllPoints() |
frame.spell:SetParent(frame.castbarbg) |
frame.spell:SetSize(sizes.icon - 2, sizes.icon - 2) |
frame.spell:SetSize(kn.sizes.icon - 2, kn.sizes.icon - 2) |
frame.spell:SetPoint('TOPRIGHT', frame.spellbg, -1, -1) |
-- scripts ------------------------------------------------------------- |
frame.castbar:HookScript('OnShow', function(bar) |
if bar.interruptible then |
bar:SetStatusBarColor(unpack(profile.castbar.barcolour)) |
bar:SetStatusBarColor(unpack(kn.profile.castbar.barcolour)) |
bar:GetParent():SetBackdropBorderColor(0, 0, 0, .3) |
bar.shield:Hide() |
else |
--print('CastEvent: ['..e..'] from ['..unit..'] (GUID: ['..(guid or 'nil')..']) (Name: ['..(name or 'nil')..'])') |
-- fetch the unit's nameplate |
f = GetNameplate(guid, name) |
f = kn.f:GetNameplate(guid, name) |
if f then |
if not f.castbar or f.trivial then return end |
if e == 'UNIT_SPELLCAST_STOP' or |
cb:UnitCastEvent(event, ...) |
end |
cb.Enable = function(self) |
profile = KuiNameplates.profile |
font, sizes, fontSizes |
= KuiNameplates.font, KuiNameplates.sizes, KuiNameplates.fontSizes |
KuiNameplates.RegisterPostFunction('create', self.CreateCastbar) |
KuiNameplates.RegisterPostFunction('hide', self.HideCastbar) |
cb.Enable = function(self) |
kn.RegisterPostFunction('create', self.CreateCastbar) |
kn.RegisterPostFunction('hide', self.HideCastbar) |
self:SetScript('OnEvent', OnEvent) |
for event,_ in pairs(castEvents) do |
end |
end |
KuiNameplates.RegisterModule('castbar', cb) |
kn.RegisterModule('castbar', cb) |