/trunk
-- fetch the spell's target's nameplate |
guid, name = targetGUID, targetName |
end |
-- [[debug]] |
--guid, name = UnitGUID('target'), GetUnitName('target') |
local f = kn.f:GetNameplate(guid, name:gsub('%-.+$', '')) |
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, ...) |
castbar.lua |
castwarnings.lua |
combopoints.lua |
custom.lua |
local addon, ns = ... |
local kui = LibStub('Kui-1.0') |
local kn = KuiNameplates |
------------------------------------------------------------------ Ace config -- |
local AceConfig = LibStub('AceConfig-3.0') |
}, |
fixaa = { |
name = 'Fix aliasing', |
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.\n|cffff0000UI reload required to take effect.|r', |
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 = 4 |
}, |
else |
ns.db.profile[info[1]][info[#info]] = val |
end |
--print(info[#info]) |
kn.updateFunctions.Call(info[#info], val) |
end |
AceConfig:RegisterOptionsTable('kuinameplates', options) |
local kui = LibStub('Kui-1.0') |
local LSM = LibStub('LibSharedMedia-3.0') |
KuiNameplates = {} |
LibStub('AceAddon-3.0'):NewAddon(ns, 'KuiNameplates') |
-- add yanone kaffesatz and accidental presidency to LSM (only supports latin) |
--[[ |
Kui Nameplates |
Kesava-Auchindoun |
TODO make option for friendly/enemy name text colour (defaults to white) |
]] |
local addon, ns = ... |
local kui = LibStub('Kui-1.0') |
local LSM = LibStub('LibSharedMedia-3.0') |
local kn = KuiNameplates |
KuiNameplates = { |
f = CreateFrame('Frame'), |
font = '', fontSizes = {}, sizes = {} |
} |
-- our frame, whee |
kn.f = CreateFrame('Frame') |
ns.f = kn.f |
ns.f = KuiNameplates.f |
kn.font = '' |
kn.fontSizes = {} |
kn.sizes = {} |
kn.frameList = {} |
-- Custom reaction colours |
ns.r = { |
{ .7, .2, .1 }, -- hated |
{ .5, .5, .5 }, -- tapped |
} |
-- sizes of frame elements |
local defaultSizes = { |
frame = { |
width = 110, |
height = 11, |
twidth = 55, |
theight = 7, |
cbheight = 4, |
bgOffset = 4, -- inset offset for the frame glow (frame.bg) |
icon = 16 |
}, |
font = { |
combopoints = 13, |
large = 10, |
spellname = 9, |
name = 9, |
small = 8 |
}, |
} |
local bgOffset = 4 -- inset offset for the frame glow (frame.bg) |
local uiscale, prevuiscale |
local loadedGUIDs, loadedNames, targetExists, profile = {}, {} |
local origSizes, origFontSizes = {},{} |
local font, sizes, fontSizes = '', {}, {} |
local loadedGUIDs, loadedNames = {}, {} |
local targetExists, targetPlate |
local profile, uiscale, prevuiscale |
local sizes, fontSizes, origSizes, origFontSizes = {}, {}, {}, {} |
local font = '' |
--------------------------------------------------------------------- globals -- |
local select, strfind, strsplit, pairs, ipairs, unpack, tinsert |
= select, strfind, strsplit, pairs, ipairs, unpack, tinsert |
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) |
end |
end |
--------------------------------------------------------- Update combo points -- |
local function ComboPointsUpdate(self) |
if self.points and self.points > 0 then |
local size = (13 + ((18 - 13) / 5) * self.points) |
local blue = (1 - (1 / 5) * self.points) |
self:SetText(self.points) |
self:SetFont(font, size, 'OUTLINE') |
self:SetTextColor(1, 1, blue) |
elseif self:GetText() then |
self:SetText('') |
end |
end |
---------------------------------------------------- Update health bar & text -- |
local function OnHealthValueChanged(oldBar, curr) |
local frame = oldBar:GetParent():GetParent() |
condition = curr < max |
elseif condition == '=' then |
condition = curr == max |
elseif condition == '<=' or condition == '=<' then |
elseif condition == '<=' then |
condition = curr <= max |
else |
condition = nil |
end |
if condition then |
self.bg.fill:SetPoint('BOTTOMLEFT', x, y) |
self.bg:SetPoint('BOTTOMLEFT', x-(sizes.bgOffset-2), y-(sizes.bgOffset-2)) |
self.bg:SetPoint('TOPRIGHT', self.parent, 'BOTTOMLEFT', x+sizes.twidth+(sizes.bgOffset-2), y+sizes.theight+(sizes.bgOffset-2)) |
self.bg:SetPoint('BOTTOMLEFT', x-(bgOffset-2), y-(bgOffset-2)) |
self.bg:SetPoint('TOPRIGHT', self.parent, 'BOTTOMLEFT', x+sizes.twidth+(bgOffset-2), y+sizes.theight+(bgOffset-2)) |
self.trivial = true |
else |
self.bg.fill:SetPoint('BOTTOMLEFT', x, y) |
self.bg:SetPoint('BOTTOMLEFT', x-sizes.bgOffset, y-sizes.bgOffset) |
self.bg:SetPoint('TOPRIGHT', self.parent, 'BOTTOMLEFT', x+(sizes.width)+sizes.bgOffset, y+(sizes.height)+sizes.bgOffset) |
self.bg:SetPoint('BOTTOMLEFT', x-bgOffset, y-bgOffset) |
self.bg:SetPoint('TOPRIGHT', self.parent, 'BOTTOMLEFT', x+(sizes.width)+bgOffset, y+(sizes.height)+bgOffset) |
self.trivial = nil |
end |
-- remove guid from the store and unset it |
loadedGUIDs[self.guid] = nil |
self.guid = nil |
if self.cp then |
self.cp.points = nil |
self.cp:Update() |
end |
end |
if loadedNames[self.name.text] == self then |
else |
(self.carrier and self.carrier or self):SetAlpha(self.currentAlpha) |
end |
-- call delayed updates |
if self.elapsed > 1 then |
self.elapsed = 0 |
-- Name text colour |
self:SetNameColour() |
if self.cp then |
-- combo points |
self.cp:Update() |
end |
end |
-- stuff that needs to be updated often |
function ns.f:InitFrame(frame) |
frame.init = true |
frame.fontObjects = {} |
local overlayChild, nameTextChild = frame:GetChildren() |
local healthBar, castBar = overlayChild:GetChildren() |
frame.oldName = nameTextRegion |
frame.oldName:Hide() |
frame.oldHighlight = highlightRegion |
--------------------------------------------------------- Frame functions -- |
frame.bg.fill:SetPoint('BOTTOMLEFT', x, y) |
frame.bg:ClearAllPoints() |
frame.bg:SetPoint('BOTTOMLEFT', x-sizes.bgOffset, y-sizes.bgOffset) |
frame.bg:SetPoint('TOPRIGHT', parent, 'BOTTOMLEFT', x+sizes.width+sizes.bgOffset, y+sizes.height+sizes.bgOffset) |
frame.bg:SetPoint('BOTTOMLEFT', x-bgOffset, y-bgOffset) |
frame.bg:SetPoint('TOPRIGHT', parent, 'BOTTOMLEFT', x+sizes.width+bgOffset, y+sizes.height+bgOffset) |
-- health bar -------------------------------------------------------------- |
frame.health = CreateFrame('StatusBar', nil, parent) |
frame.health.p:SetPoint('BOTTOMRIGHT', frame.health, 'TOPRIGHT', -2, uiscale and -(3/uiscale) or -3) |
frame.health.p.size = 'large' |
tinsert(frame.fontObjects, frame.health.p) |
if profile.hp.showalt then |
frame.health.mo = kui.CreateFontString(frame.overlay, { |
font = font, size = fontSizes.small, outline = "OUTLINE" }) |
frame.health.mo:SetPoint('BOTTOMRIGHT', frame.health, -2, uiscale and -(3/uiscale) or -3) |
frame.health.mo:SetAlpha(.6) |
frame.health.mo.size = 'small' |
tinsert(frame.fontObjects, frame.health.mo) |
end |
if profile.text.level then |
frame.level:ClearAllPoints() |
frame.level:SetPoint('BOTTOMLEFT', frame.health, 'TOPLEFT', 2, uiscale and -(2/uiscale) or -2) |
frame.level.enabled = true |
frame.level.size = 'name' |
tinsert(frame.fontObjects, frame.level) |
else |
frame.level:Hide() |
end |
frame.name:SetJustifyH('LEFT') |
frame.name:SetHeight(13) |
if frame.level.enabled then |
frame.name:SetPoint('LEFT', frame.level, 'RIGHT', -2, 0) |
else |
frame.name:SetPoint('RIGHT', frame.health.p, 'LEFT') |
frame.name.size = 'name' |
tinsert(frame.fontObjects, frame.name) |
-- combo point text -------------------------------------------------------- |
if profile.general.combopoints then |
frame.cp = kui.CreateFontString(frame.health, |
{ font = font, size = fontSizes.combopoints, outline = 'OUTLINE', shadow = true }) |
frame.cp:SetPoint('LEFT', frame.health, 'RIGHT', 5, 1) |
frame.cp.Update = ComboPointsUpdate |
end |
----------------------------------------------------------------- Scripts -- |
frame:SetScript('OnShow', OnFrameShow) |
frame:SetScript('OnHide', OnFrameHide) |
end |
---------------------------------------------------------------------- Events -- |
function ns.f:UNIT_COMBO_POINTS() |
local target = UnitGUID('target') |
if not target or not loadedGUIDs[target] then return end |
target = loadedGUIDs[target] |
if target.cp then |
target.cp.points = GetComboPoints('player', 'target') |
target.cp:Update() |
end |
-- clear points on other frames |
for guid, frame in pairs(loadedGUIDs) do |
if frame.cp and guid ~= target.guid then |
frame.cp.points = nil |
frame.cp:Update() |
end |
end |
end |
function ns.f:PLAYER_TARGET_CHANGED() |
targetExists = UnitExists('target') |
end |
f = select(i, WorldFrame:GetChildren()) |
if self:IsNameplate(f) and not f.init then |
self:InitFrame(f) |
tinsert(kn.frameList, f) |
end |
end |
end |
end |
-------------------------------------------------- Listen for profile changes -- |
function ns:ProfileChanged() |
kn.profile = self.db.profile |
profile = kn.profile |
-- call all updateFunctions |
local groupname, group |
for groupname, group in pairs(profile) do |
local settingname, value |
for settingname, value in pairs(group) do |
kn.updateFunctions.Call(settingname, value) |
end |
function ns.ToggleComboPoints(io) |
if io then |
ns.f:RegisterEvent('UNIT_COMBO_POINTS') |
else |
ns.f:UnregisterEvent('UNIT_COMBO_POINTS') |
end |
end |
-- TODO move all this crap into config.lua |
---------------------------------------------------- Post db change functions -- |
-- for changes which require traversal of all frames |
kn.updateFunctions = {} |
kn.updateFunctions.Call = function(func, val) |
if not kn.updateFunctions[func] then return end |
local runonce, _, frame = 0 |
for _, frame in pairs(kn.frameList) do |
kn.updateFunctions[func](frame, val, runonce) |
runonce = runonce + 1 |
end |
-------------------------------------------------- Listen for profile changes -- |
function ns:ProfileChanged() |
profile = self.db.profile |
end |
kn.updateFunctions.Health = function(frame) |
if frame:IsShown() then |
-- update health display |
OnHealthValueChanged(frame.oldHealth, frame.oldHealth:GetValue()) |
end |
end |
kn.updateFunctions.friendly = kn.updateFunctions.Health |
kn.updateFunctions.hostile = kn.updateFunctions.Health |
-------------------------------------------------------------------- Finalise -- |
function ns:OnEnable() |
profile = self.db.profile |
KuiNameplates.profile = profile |
kn.updateFunctions.fontscale = function(frame, val, runonce) |
if runonce == 0 then |
ns:ScaleFonts() |
KuiNameplates.sizes, KuiNameplates.fontSizes = { |
-- frame |
width = 110, |
height = 11, |
twidth = 55, |
theight= 7, |
-- cast bar stuff |
cbheight = 14, |
icon = 16, |
}, { |
combopoints = 13, |
large = 10, |
spellname = 9, |
name = 9, |
small = 8, |
} |
sizes, fontSizes = KuiNameplates.sizes, KuiNameplates.fontSizes |
for k,size in pairs(fontSizes) do |
fontSizes[k] = size * profile.general.fontscale |
end |
local _, fontObject |
for _, fontObject in pairs(frame.fontObjects) do |
SetFontSize(fontObject, fontSizes[fontObject.size]) |
end |
end |
kn.updateFunctions.font = function(frame, val, runonce) |
val = LSM:Fetch(LSM.MediaType.FONT, val) |
if profile.general.fixaa then |
uiscale, origSizes, origFontSizes = |
UIParent:GetEffectiveScale(), sizes, fontSizes |
local _, fontObject |
for _, fontObject in pairs(frame.fontObjects) do |
local _, size, flags = fontObject:GetFont() |
fontObject:SetFont(val, size, flags) |
end |
end |
bgOffset = 5 |
origSizes.cbheight = 12 |
-------------------------------------------------------------------- Finalise -- |
-- [initialise and] scale frame sizes |
function ns:ScaleFrames() |
for k, size in pairs(defaultSizes.frame) do |
kn.sizes[k] = (uiscale and floor(size/uiscale) or size) |
end |
end |
-- scale sizes up to "unscaled" values |
for k,size in pairs(origSizes) do |
sizes[k] = floor(size/uiscale) |
end |
-- [initialise and] scale font sizes |
function ns:ScaleFonts() |
for k, size in pairs(defaultSizes.font) do |
kn.fontSizes[k] = size * profile.general.fontscale |
if uiscale then |
kn.fontSizes[k] = kn.fontSizes[k] / uiscale |
for k,size in pairs(origFontSizes) do |
fontSizes[k] = size/uiscale |
end |
end |
end |
function ns:OnEnable() |
kn.profile = self.db.profile |
profile = kn.profile |
if profile.general.fixaa then |
uiscale = UIParent:GetEffectiveScale() |
end |
self:ScaleFonts() |
self:ScaleFrames() |
fontSizes, sizes = kn.fontSizes, kn.sizes |
-- fetch font path from lsm |
kn.font = LSM:Fetch(LSM.MediaType.FONT, profile.general.font) |
font = kn.font |
KuiNameplates.font = LSM:Fetch(LSM.MediaType.FONT, profile.general.font) |
font = KuiNameplates.font |
-------------------------------------- Health bar smooth update functions -- |
-- (spoon-fed by oUF_Smooth) |
if profile.castbar.warnings and modules.warnings then |
modules.warnings:Enable() |
end |
if profile.general.combopoints and modules.combopoints then |
modules.combopoints:Enable() |
end |
ns.f:SetScript('OnUpdate', self.OnUpdate) |
ns.f:SetScript('OnEvent', self.OnEvent) |
ns.f:RegisterEvent('PLAYER_TARGET_CHANGED') |
self.ToggleCombatEvents(profile.general.combat) |
self.ToggleComboPoints(profile.general.combopoints) |
end |
-- Place code to be performed after a frame is hidden here. |
end |
---------------------------------------------------------------------- Target -- |
local function PostTarget(frame) |
-- Place code to be performed when a frame becomes the player's target here. |
end |
-------------------------------------------------------------------- Register -- |
kn.RegisterPostFunction('create', PostCreate) |
kn.RegisterPostFunction('show', PostShow) |
kn.RegisterPostFunction('hide', PostHide) |
kn.RegisterPostFunction('target', PostTarget) |
bar.progress = bar.progress + elapsed |
end |
if not bar.duration or |
((not bar.channel and bar.progress >= bar.duration) or |
(bar.channel and bar.progress <= 0)) |
if not bar.duration or |
((not bar.channel and bar.progress >= bar.duration) or |
(bar.channel and bar.progress <= 0)) |
then |
-- hide the castbar |
bar:Hide() |
-- hide the castbar bg |
bar:GetParent():Hide() |
bar.progress = 0 |
return |
end |
end |
end |
bar.bar:SetValue(bar.progress/bar.duration) |
bar:SetValue(bar.progress/bar.duration) |
end |
---------------------------------------------------------------------- create -- |
cb.CreateCastbar = function(frame) |
-- container --------------------------------------------------------------- |
frame.castbar = CreateFrame('Frame', nil, frame.parent) |
frame.castbar:Hide() |
-- background -------------------------------------------------------------- |
frame.castbar.bg = frame.castbar:CreateTexture(nil, 'BACKGROUND') |
frame.castbar.bg:SetTexture(kui.m.t.solid) |
frame.castbar.bg:SetVertexColor(0, 0, 0, .85) |
-- cast bar background ------------------------------------------------- |
frame.castbarbg = CreateFrame("Frame", nil, frame.parent) |
frame.castbarbg:SetFrameStrata('BACKGROUND'); |
frame.castbarbg:SetBackdrop({ |
bgFile = kui.m.t.solid, edgeFile = kui.m.t.shadow, |
edgeSize = 5, insets = { |
top = 5, left = 5, bottom = 5, right = 5 |
} |
}) |
frame.castbar.bg:SetHeight(kn.sizes.cbheight) |
frame.castbar.bg:SetPoint('TOPLEFT', frame.bg.fill, 'BOTTOMLEFT', 0, -1) |
frame.castbar.bg:SetPoint('TOPRIGHT', frame.bg.fill, 'BOTTOMRIGHT', 0, 0) |
frame.castbarbg:SetBackdropColor(0, 0, 0, .85) |
frame.castbarbg:SetBackdropBorderColor(1, .2, .1, 0) |
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.castbarbg:Hide() |
-- cast bar ------------------------------------------------------------ |
frame.castbar.bar = CreateFrame("StatusBar", nil, frame.castbar) |
frame.castbar.bar:SetStatusBarTexture(kui.m.t.bar) |
frame.castbar = CreateFrame("StatusBar", nil, frame.castbarbg) |
frame.castbar:SetStatusBarTexture(kui.m.t.bar) |
frame.castbar.bar:SetPoint('TOPLEFT', frame.castbar.bg, 'TOPLEFT', 1, -1) |
frame.castbar.bar:SetPoint('BOTTOMLEFT', frame.castbar.bg, 'BOTTOMLEFT', 1, 1) |
frame.castbar.bar:SetPoint('RIGHT', frame.castbar.bg, 'RIGHT', -1, 0) |
frame.castbar:SetPoint('TOPLEFT', frame.castbarbg, 'TOPLEFT', 6, -6) |
frame.castbar:SetPoint('BOTTOMLEFT', frame.castbarbg, 'BOTTOMLEFT', 6, 6) |
frame.castbar:SetPoint('RIGHT', frame.castbarbg, 'RIGHT', -6, 0) |
frame.castbar.bar:SetFrameLevel(2) |
frame.castbar.bar:SetMinMaxValues(0, 1) |
frame.castbar:SetMinMaxValues(0, 1) |
-- uninterruptible cast shield ----------------------------------------- |
frame.castbar.shield = frame.castbar:CreateTexture(nil, 'ARTWORK') |
frame.castbar.shield:SetTexCoord(0, .53125, 0, .6875) |
frame.castbar.shield:SetSize(12, 17) |
frame.castbar.shield:SetPoint('CENTER', frame.castbar.bg, 0, 1) |
frame.castbar.shield:SetPoint('CENTER', frame.castbar, 0, 1) |
frame.castbar.shield:SetBlendMode('BLEND') |
frame.castbar.shield:SetDrawLayer('ARTWORK', 7) |
if kn.profile.castbar.spellname then |
frame.castbar.name = kui.CreateFontString(frame.castbar, { |
font = kn.font, size = kn.fontSizes.name, outline = "OUTLINE" }) |
frame.castbar.name:SetPoint('TOPLEFT', frame.castbar.bg, 'BOTTOMLEFT', 2, -2) |
frame.castbar.name:SetPoint('TOPLEFT', frame.castbar, 'BOTTOMLEFT', 2, -2) |
end |
if kn.profile.castbar.casttime then |
frame.castbar.max = kui.CreateFontString(frame.castbar, { |
font = kn.font, size = kn.fontSizes.name, outline = "OUTLINE" }) |
frame.castbar.max:SetPoint('TOPRIGHT', frame.castbar.bg, 'BOTTOMRIGHT', -2, -1) |
frame.castbar.max:SetPoint('TOPRIGHT', frame.castbar, 'BOTTOMRIGHT', -2, -1) |
frame.castbar.curr = kui.CreateFontString(frame.castbar, { |
font = kn.font, size = kn.fontSizes.small, outline = "OUTLINE" }) |
if frame.spell then |
-- cast bar icon background ---------------------------------------- |
frame.spellbg = frame.castbar:CreateTexture(nil, 'BACKGROUND') |
frame.spellbg = frame.castbarbg:CreateTexture(nil, 'BACKGROUND') |
frame.spellbg:SetTexture(kui.m.t.solid) |
frame.spellbg:SetSize(kn.sizes.icon, kn.sizes.icon) |
-- cast bar icon --------------------------------------------------- |
frame.spell:ClearAllPoints() |
frame.spell:SetParent(frame.castbar) |
frame.spell:SetParent(frame.castbarbg) |
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.bar:SetStatusBarColor(unpack(kn.profile.castbar.barcolour)) |
bar:SetStatusBarColor(unpack(kn.profile.castbar.barcolour)) |
bar:GetParent():SetBackdropBorderColor(0, 0, 0, .3) |
bar.shield:Hide() |
else |
bar.bar:SetStatusBarColor(.8, .1, .1) |
bar:SetStatusBarColor(.8, .1, .1) |
bar:GetParent():SetBackdropBorderColor(1, .1, .2, .5) |
bar.shield:Show() |
end |
end) |
if frame.castbar then |
frame.castbar.duration = nil |
frame.castbar.id = nil |
frame.castbar:Hide() |
frame.castbarbg:Hide() |
end |
end |
-------------------------------------------------------------- Event handlers -- |
end |
if not name then |
frame.castbar:Hide() |
frame.castbarbg:Hide() |
return |
end |
castbar.progress = GetTime() - (startTime/1000) |
end |
frame.castbar:Show() |
frame.castbarbg:Show() |
end |
function cb:UNIT_SPELLCAST_DELAYED(frame, unit, channel) |
end |
function cb:UNIT_SPELLCAST_STOP(frame, unit) |
frame.castbar:Hide() |
frame.castbarbg:Hide() |
end |
function cb:UNIT_SPELLCAST_FAILED(frame, unit) |
frame.castbar:Hide() |
frame.castbarbg:Hide() |
end |
function cb:UNIT_SPELLCAST_INTERRUPTED(frame, unit) |
frame.castbar:Hide() |
frame.castbarbg:Hide() |
end |
function cb:UNIT_SPELLCAST_CHANNEL_STOP(frame, unit) |
frame.castbar:Hide() |
frame.castbarbg:Hide() |
end |
function cb.IsCasting(frame) |