/branches
function mod:CreateCastWarnings(msg, frame) |
-- casting spell name |
frame.castWarning = frame:CreateFontString(frame.overlay, { |
font = addon.font, size = 'spellname', outline = 'OUTLINE' }) |
size = 'spellname', outline = 'OUTLINE' }) |
frame.castWarning:SetPoint('BOTTOMLEFT', frame.level, 'TOPLEFT', 0, 1) |
frame.castWarning:Hide() |
-- incoming healing |
frame.incWarning = frame:CreateFontString(frame.overlay, { |
font = addon.font, size = 'small', outline = 'OUTLINE' }) |
size = 'small', outline = 'OUTLINE' }) |
frame.incWarning:SetPoint('BOTTOMRIGHT', frame.health.p, 'TOPRIGHT', 1) |
frame.incWarning:Hide() |
----------------------------------------------------------------- Health text -- |
function addon:CreateHealthText(frame) |
frame.health.p = addon.CreateFontString(frame, frame.overlay, { |
frame.health.p = frame:CreateFontString(frame.overlay, { |
font = addon.font, size = 'large', outline = "OUTLINE" }) |
frame.health.p:SetJustifyH('RIGHT') |
frame.health.p:SetPoint('BOTTOMRIGHT', frame.health, 'TOPRIGHT', |
------------------------------------------------------------- Alt health text -- |
function addon:CreateAltHealthText(frame) |
frame.health.mo = addon.CreateFontString(frame, frame.overlay, { |
frame.health.mo = frame:CreateFontString(frame.overlay, { |
font = addon.font, size = 'small', outline = "OUTLINE" }) |
frame.health.mo:SetJustifyH('RIGHT') |
frame.health.mo:SetPoint('BOTTOMRIGHT', frame.health, |
function addon:CreateLevel(frame) |
if not frame.level then return end |
frame.level = addon.CreateFontString(frame, frame.level, { reset = true, |
frame.level = frame:CreateFontString(frame.level, { reset = true, |
font = addon.font, size = 'name', outline = 'OUTLINE' }) |
frame.level:SetParent(frame.overlay) |
------------------------------------------------------------------- Name text -- |
function addon:CreateName(frame) |
frame.name = addon.CreateFontString(frame, frame.overlay, { |
frame.name = frame:CreateFontString(frame.overlay, { |
font = addon.font, size = 'name', outline = 'OUTLINE' }) |
frame.name:SetHeight(13) |
name = 'Smooth health bar', |
desc = 'Smoothly animate health bar value updates', |
type = 'toggle', |
width = 'double', |
order = 3 |
}, |
tapped = { |
name = 'Use tapped colour', |
desc = 'Give tapped units a grey health bar', |
type = 'toggle', |
order = 4 |
}, |
friendly = { |
name = 'Friendly health format', |
desc = 'The health display pattern for friendly units', |
softMax = 2, |
}, |
outline = { |
name = 'NYI Outline', |
desc = 'Dsiplay an outline on all fonts [NYI doesn\'t reapply]', |
name = 'Outline', |
desc = 'Display an outline on all fonts', |
type = 'toggle', |
}, |
monochrome = { |
name = 'NYI Monochrome', |
desc = 'Don\'t anti-alias fonts. [NYI doesn\'t reapply]', |
name = 'Monochrome', |
desc = 'Don\'t anti-alias fonts', |
type = 'toggle' |
}, |
onesize = { |
name = 'NYI Use one font size', |
desc = 'Use the same font size for all strings. Useful if using a pixel font', |
name = 'Use one font size', |
desc = 'Use the same font size for all strings. Useful when using a pixel font.', |
type = 'toggle' |
}, |
} |
local MAJOR, MINOR = 'Kui-1.0', 3 |
local MAJOR, MINOR = 'Kui-1.0', 4 |
local kui = LibStub:NewLibrary(MAJOR, MINOR) |
if not kui then |
return level, classification, diff |
end |
kui.ModifyFontFlags = function(fs, io, flag) |
local font, size, flags = fs:GetFont() |
local flagStart,flagEnd = strfind(flags, flag) |
if io and not flagStart then |
-- add flag |
flags = flags..' '..flag |
elseif not val and flagStart then |
-- remove flag |
flags = strsub(flags, 0, flagStart-1) .. strsub(flags, flagEnd+1) |
end |
fs:SetFont(font, size, flags) |
end |
kui.CreateFontString = function(parent, args) |
local ob, font, size, outline, alpha, shadow |
args = args or {} |
font = args.font or NAMEPLATE_FONT |
size = args.size or 12 |
outline = args.outline or nil |
mono = args.mono or args.monochrome or nil |
alpha = args.alpha or 1 |
shadow = args.shadow or false |
ob:SetFont(font, size, outline) |
ob:SetFont(font, size) |
ob:SetAlpha(alpha) |
kui.ModifyFontFlags(ob, outline, 'OUTLINE') |
kui.ModifyFontFlags(ob, mono, 'MONOCHROME') |
if shadow then |
ob:SetShadowColor(0, 0, 0, 1) |
ob:SetShadowOffset(type(shadow) == 'table' and unpack(shadow) or 1, -1) |
hostile = '<:p;', -- health display pattern for hostile/neutral units |
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 |
}, |
fonts = { |
} |
-- sizes of frame elements |
local defaultSizes = { |
kn.defaultSizes = { |
frame = { |
width = 110, |
height = 11, |
twidth = 55, |
theight = 7, |
cbheight = 4, |
bgOffset = 4, -- inset offset for the frame glow (frame.bg) |
icon = 16 |
bgOffset = 4 -- inset offset for the frame glow (frame.bg) |
}, |
font = { |
combopoints = 13, |
------------------------------------------------------------ helper functions -- |
local function SetFontSize(fs, size) |
if profile.fonts.options.onesize then |
size = kn.fontSizes['name'] |
end |
if type(size) == 'string' and fs.size and kn.fontSizes[size] then |
fs.size = size |
size = kn.fontSizes[size] |
fs:SetFont(font, size, flags) |
end |
local function ModifyFontFlags(fs, io, flag) |
local font, size, flags = fs:GetFont() |
local flagStart,flagEnd = strfind(flags, flag) |
local function CreateFontString(self, parent, obj) |
-- store size as a key of kn.fontSizes so that it can be recalled & scaled |
-- correctly. Used by SetFontSize. |
local sizeKey |
obj.mono = profile.fonts.options.monochrome |
obj.outline = profile.fonts.options.outline |
if io and not flagStart then |
-- add flag |
flags = flags..' '..flag |
elseif not val and flagStart then |
-- remove flag |
flags = strsub(flags, 0, flagStart-1) .. strsub(flags, flagEnd+1) |
if type(obj.size) == 'string' then |
sizeKey = obj.size |
obj.size = kn.fontSizes[sizeKey] |
end |
fs:SetFont(font, size, flags) |
end |
if profile.fonts.options.onesize then |
obj.size = kn.fontSizes['name'] |
end |
local function CreateFontString(self, parent, obj) |
-- size can be stored as a key of kn.fontSizes so that it can be set |
-- correctly if fonts are scaled |
local sizeKey = obj.size |
if type(sizeKey) == 'string' then |
obj.size = kn.fontSizes[sizeKey] |
if not obj.font then |
obj.font = kn.font |
end |
local fs = kui.CreateFontString(parent, obj) |
end |
kn.SetFontSize = SetFontSize |
kn.ModifyFontFlags = ModifyFontFlags |
kn.CreateFontString = CreateFontString |
------------------------------------------------------------- Frame functions -- |
r, g, b = unpack(kn.r[2]) |
elseif b > .9 and (r+g) > 1.06 and (r+g) < 1.1 then |
-- tapped NPC |
if profile.hp.tapped then |
-- use grey... |
r, g, b = unpack(kn.r[4]) |
else |
-- or don't change |
return |
end |
r, g, b = unpack(kn.r[4]) |
else |
-- enemy player, use default UI colour |
self.player = true |
kn.configChangedFuncs.outline = function(frame, val) |
local _, fontObject |
for _, fontObject in pairs(frame.fontObjects) do |
ModifyFontFlags(fontObject, val, 'OUTLINE') |
kui.ModifyFontFlags(fontObject, val, 'OUTLINE') |
end |
end |
kn.configChangedFuncs.monochrome = function(frame, val) |
local _, fontObject |
for _, fontObject in pairs(frame.fontObjects) do |
ModifyFontFlags(fontObject, val, 'MONOCHROME') |
kui.ModifyFontFlags(fontObject, val, 'MONOCHROME') |
end |
end |
end |
end |
end |
kn.configChangedFuncs.onesize = kn.configChangedFuncs.fontscale |
kn.configChangedFuncs.Health = function(frame) |
if frame:IsShown() then |
end |
-------------------------------------------------------------------- Finalise -- |
-- scale a frame/font size to keep it relatively the same with any uiscale |
function ScaleFrameSize(key) |
local size = kn.defaultSizes.frame[key] |
kn.sizes[key] = (uiscale and floor(size/uiscale) or size) |
end |
function ScaleFontSize(key) |
local size = kn.defaultSizes.font[key] |
kn.fontSizes[key] = size * profile.fonts.options.fontscale |
if uiscale then |
kn.fontSizes[key] = kn.fontSizes[key] / uiscale |
end |
end |
-- [initialise and] scale frame sizes |
function kn:ScaleFrameSizes() |
local k, size |
for k, size in pairs(defaultSizes.frame) do |
self.sizes[k] = (uiscale and floor(size/uiscale) or size) |
local k,_ |
for k,_ in pairs(kn.defaultSizes.frame) do |
ScaleFrameSize(k) |
end |
end |
-- [initialise and] scale font sizes |
function kn:ScaleFontSizes() |
local k, size |
for k, size in pairs(defaultSizes.font) do |
self.fontSizes[k] = size * profile.fonts.options.fontscale |
if uiscale then |
self.fontSizes[k] = self.fontSizes[k] / uiscale |
end |
local k,_ |
for k,_ in pairs(kn.defaultSizes.font) do |
ScaleFontSize(k) |
end |
end |
-- modules must use this to add correctly scaled sizes |
-- font sizes can then be called as a key in kn.CreateFontString |
function kn:RegisterSize(type, key, size) |
if type ~= 'frame' and type ~= 'font' then return end |
kn.defaultSizes[type][key] = size |
if type == 'frame' then |
ScaleFrameSize(key) |
else |
ScaleFontSize(key) |
end |
end |
function kn:OnEnable() |
profile = self.db.profile |
-- cast bar text ------------------------------------------------------- |
if self.db.profile.display.spellname then |
frame.castbar.name = frame:CreateFontString(frame.castbar, { |
font = addon.font, size = 'name', outline = "OUTLINE" }) |
size = 'name', outline = "OUTLINE" }) |
frame.castbar.name:SetPoint('TOPLEFT', frame.castbar.bg, 'BOTTOMLEFT', 2, -2) |
frame.castbar.name:SetPoint('TOPRIGHT', frame.castbar.bg, 'BOTTOMRIGHT', -2, 0) |
frame.castbar.name:SetJustifyH('LEFT') |
if self.db.profile.display.casttime then |
frame.castbar.max = frame:CreateFontString(frame.castbar, { |
font = addon.font, size = 'name', outline = "OUTLINE" }) |
size = 'name', outline = "OUTLINE" }) |
frame.castbar.max:SetPoint('TOPRIGHT', frame.castbar.bg, 'BOTTOMRIGHT', -2, -1) |
frame.castbar.curr = frame:CreateFontString(frame.castbar, { |
font = addon.font, size = 'small', outline = "OUTLINE" }) |
size = 'small', outline = "OUTLINE" }) |
frame.castbar.curr:SetAlpha(.5) |
frame.castbar.curr:SetPoint('TOPRIGHT', frame.castbar.max, 'TOPLEFT', -1, -1) |
} |
}) |
addon:RegisterSize('frame', 'cbheight', 4) |
addon:RegisterSize('frame', 'icon', 16) |
addon:InitModuleOptions(self) |
end |
function mod:OnEnable() |
self:RegisterMessage('create', 'CreateCastbar') |
self:RegisterMessage('hide', 'HideCastbar') |
self:RegisterMessage('show', 'IsCasting') |
self:RegisterMessage('target', 'IsCasting') |
self:RegisterMessage('KuiNameplates_PostCreate', 'CreateCastbar') |
self:RegisterMessage('KuiNameplates_PostHide', 'HideCastbar') |
self:RegisterMessage('KuiNameplates_PostShow', 'IsCasting') |
self:RegisterMessage('KuiNameplates_PostTarget', 'IsCasting') |
for event,_ in pairs(castEvents) do |
self:RegisterEvent(event, self.UnitCastEvent) |
end |
local _,frame |
for _, frame in pairs(addon.frameList) do |
if not frame.castbar then |
self:CreateCastbar(nil, frame) |
end |
end |
end |