/trunk/Kui_Nameplates
---------------------------------------------------------------------- Create -- |
cw.CreateCastWarnings = function(frame) |
-- casting spell name |
frame.castWarning = kui.CreateFontString(frame.overlay, { |
font = kn.font, size = kn.fontSizes.spellname, outline = 'OUTLINE' }) |
frame.castWarning = frame:CreateFontString(frame.overlay, { |
font = kn.font, size = 'spellname', outline = 'OUTLINE' }) |
frame.castWarning:SetPoint('BOTTOMLEFT', frame.level, 'TOPLEFT', 0, 1) |
frame.castWarning:Hide() |
end) |
-- incoming healing |
frame.incWarning = kui.CreateFontString(frame.overlay, { |
font = kn.font, size = kn.fontSizes.small, outline = 'OUTLINE' }) |
frame.incWarning = frame:CreateFontString(frame.overlay, { |
font = kn.font, size = 'small', outline = 'OUTLINE' }) |
frame.incWarning:SetPoint('BOTTOMRIGHT', frame.health.p, 'TOPRIGHT', 1) |
frame.incWarning:Hide() |
type = 'toggle', |
order = 4 |
}, |
font = { |
name = 'Font', |
desc = 'The font used for all text on frames', |
type = 'select', |
dialogControl = 'LSM30_Font', |
values = AceGUIWidgetLSMlists.font, |
order = 5 |
}, |
fontscale = { |
name = 'Font scale', |
desc = 'The scale of all fonts displayed on nameplates', |
type = 'range', |
min = 0.01, |
softMax = 2, |
order = 6 |
} |
} |
}, |
fade = { |
} |
} |
local fontsOptions = { |
name = 'Fonts', |
handler = handler, |
type = 'group', |
get = 'Get', |
set = 'Set', |
args = { |
fontoptions = { |
name = 'Global font settings', |
type = 'group', |
inline = true, |
args = { |
font = { |
name = 'Font', |
desc = 'The font used for all text on nameplates', |
type = 'select', |
dialogControl = 'LSM30_Font', |
values = AceGUIWidgetLSMlists.font, |
}, |
fontscale = { |
name = 'Font scale', |
desc = 'The scale of all fonts displayed on nameplates', |
type = 'range', |
min = 0.01, |
softMax = 2, |
}, |
outline = { |
name = 'Outline', |
desc = 'Dsiplay an outline on all fonts', |
type = 'toggle', |
}, |
monochrome = { |
name = 'Monochrome', |
desc = 'Don\'t anti-alias fonts', |
type = 'toggle' |
}, |
} |
}, |
fontsizes = { |
name = 'Sizes', |
type = 'group', |
inline = true, |
args = { |
combopoints = { |
name = 'Combo points', |
type = 'range', |
min = 1, |
softMax = 20 |
}, |
large = { |
name = 'Large', |
desc = 'Used for health on normal nameplates', |
type = 'range', |
min = 1, |
softMax = 20 |
}, |
spellname = { |
name = 'Spell name', |
type = 'range', |
min = 1, |
softMax = 20 |
}, |
name = { |
name = 'Name & level', |
type = 'range', |
min = 1, |
softMax = 20 |
}, |
small = { |
name = 'Small', |
desc = 'Used for contextual health on normal nameplates and name on trivial nameplates', |
type = 'range', |
min = 1, |
softMax = 20 |
}, |
} |
} |
} |
} |
function handler:Get(info) |
local k = ns.db.profile[info[1]][info[#info]] |
AceConfig:RegisterOptionsTable('kuinameplates', options) |
AceConfigDialog:AddToBlizOptions('kuinameplates', 'Kui Nameplates') |
AceConfig:RegisterOptionsTable('kuinameplatesfonts', fontsOptions) |
AceConfigDialog:AddToBlizOptions('kuinameplatesfonts', 'Fonts', 'Kui Nameplates') |
end |
--------------------------------------------------------------- Slash command -- |
highlight = true, -- highlight plates on mouse-over |
combopoints = true, -- display combo points |
fixaa = true, -- attempt to make plates appear sharper (with some drawbacks) |
font = (latin and 'Yanone Kaffesatz' or LSM:GetDefault(LSM.MediaType.FONT)), -- the font used for all text |
fontscale = 1.0, -- the scale of all displayed font sizes |
}, |
fade = { |
smooth = true, -- smoothy fade plates (fading is instant if disabled) |
spellicon = true, -- display spell icon |
barcolour = { .43, .47, .55, 1 }, -- the colour of the spell bar (interruptible casts) |
warnings = false, -- display spell cast warnings on any plates |
usenames = false -- 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. |
usenames = false -- use unit names to display cast warnings |
}, |
fontoptions = { |
font = (latin and 'Yanone Kaffesatz' or LSM:GetDefault(LSM.MediaType.FONT)), |
fontscale = 1.0, |
outline = true, |
monochrome = false, |
}, |
fontsizes = { |
combopoints = 13, |
large = 10, |
spellname = 9, |
name = 9, |
small = 8 |
}, |
} |
} |
local size = (13 + ((18 - 13) / 5) * self.points) |
local blue = (1 - (1 / 5) * self.points) |
kn.SetFontSize(self, size) |
self:SetText(self.points) |
self:SetFont(kn.font, size, 'OUTLINE') |
self:SetTextColor(1, 1, blue) |
self:Show() |
elseif self:GetText() then |
end |
---------------------------------------------------------------------- Create -- |
cp.CreateComboPoints = function(frame) |
frame.cp = kui.CreateFontString(frame.health, |
{ font = kn.font, size = kn.fontSizes.combopoints, outline = 'OUTLINE', shadow = true }) |
frame.cp = frame:CreateFontString(frame.health, { |
font = kn.font, size = 'combopoints', outline = 'OUTLINE', shadow = true }) |
frame.cp:SetPoint('LEFT', frame.health, 'RIGHT', 5, 1) |
frame.cp.Update = ComboPointsUpdate |
frame.cp:Hide() |
} |
local loadedGUIDs, loadedNames = {}, {} |
local targetExists, targetPlate |
local profile, uiscale, prevuiscale |
local sizes, fontSizes, origSizes, origFontSizes = {}, {}, {}, {} |
local font = '' |
local targetExists |
local profile, uiscale |
--------------------------------------------------------------------- globals -- |
local select, strfind, strsplit, pairs, ipairs, unpack, tinsert |
= select, strfind, strsplit, pairs, ipairs, unpack, tinsert |
local select, strfind, strsplit, pairs, ipairs, unpack, tinsert, type |
= select, strfind, strsplit, pairs, ipairs, unpack, tinsert, type |
-- helper for setting a given fontstring's font size |
local function SetFontSize(fontstring, size) |
local font, _, flags = fontstring:GetFont() |
fontstring:SetFont(font, size, flags) |
------------------------------------------------------------ helper functions -- |
local function SetFontSize(fs, size) |
if type(size) == 'string' and fs.size and kn.fontSizes[size] then |
fs.size = size |
size = kn.fontSizes[size] |
end |
local font, _, flags = fs:GetFont() |
fs:SetFont(font, size, flags) |
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] |
end |
local fs = kui.CreateFontString(parent, obj) |
fs.size = sizeKey |
--fs.SetFontSize = SetFontSize |
--fs.SetFontStyle = SetFontStyle |
tinsert(self.fontObjects, fs) |
return fs |
end |
-------------------------------------------------- External calling functions -- |
local modules = {} |
local postFunctions = { |
local w,h = self.parent:GetSize() |
local x,y = |
floor((w / 2) - (sizes.twidth / 2)), |
floor((h / 2) - (sizes.theight / 2)) |
floor((w / 2) - (kn.sizes.twidth / 2)), |
floor((h / 2) - (kn.sizes.theight / 2)) |
self.health:ClearAllPoints() |
self.bg:ClearAllPoints() |
self.health.mo:Hide() |
end |
SetFontSize(self.name, fontSizes.small) |
SetFontSize(self.name, 'small') |
self.name:SetJustifyH('CENTER') |
self.name:SetPoint('BOTTOMLEFT', self.health, 'TOPLEFT', -10, -3) |
self.name:SetPoint('BOTTOMRIGHT', self.health, 'TOPRIGHT', 10, -3) |
self.name:SetPoint('BOTTOM', self.health, 'TOP', 0, -3) |
self.bg.fill:SetSize(sizes.twidth, sizes.theight) |
self.health:SetSize(sizes.twidth-2, sizes.theight-2) |
self.bg.fill:SetSize(kn.sizes.twidth, kn.sizes.theight) |
self.health:SetSize(kn.sizes.twidth-2, kn.sizes.theight-2) |
self.health:SetPoint('BOTTOMLEFT', x+1, y+1) |
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-(kn.sizes.bgOffset-2), y-(kn.sizes.bgOffset-2)) |
self.bg:SetPoint('TOPRIGHT', self.parent, 'BOTTOMLEFT', x+kn.sizes.twidth+(kn.sizes.bgOffset-2), y+kn.sizes.theight+(kn.sizes.bgOffset-2)) |
self.trivial = true |
else |
local w,h = self.parent:GetSize() |
local x,y = |
floor((w / 2) - (sizes.width / 2)), |
floor((h / 2) - (sizes.height / 2)) |
floor((w / 2) - (kn.sizes.width / 2)), |
floor((h / 2) - (kn.sizes.height / 2)) |
self.health:ClearAllPoints() |
self.bg:ClearAllPoints() |
self.health.mo:Show() |
end |
SetFontSize(self.name, fontSizes.name) |
SetFontSize(self.name, 'name') |
self.name:SetJustifyH('LEFT') |
self.name:SetPoint('RIGHT', self.health.p, 'LEFT') |
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) |
self.bg.fill:SetSize(kn.sizes.width, kn.sizes.height) |
self.health:SetSize(kn.sizes.width - 2, kn.sizes.height - 2) |
self.health:SetPoint('BOTTOMLEFT', x+1, y+1) |
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-kn.sizes.bgOffset, y-kn.sizes.bgOffset) |
self.bg:SetPoint('TOPRIGHT', self.parent, 'BOTTOMLEFT', x+(kn.sizes.width)+kn.sizes.bgOffset, y+(kn.sizes.height)+kn.sizes.bgOffset) |
self.trivial = nil |
end |
frame.oldHighlight = highlightRegion |
--------------------------------------------------------- Frame functions -- |
frame.CreateFontString = CreateFontString |
frame.UpdateFrame = UpdateFrame |
frame.UpdateFrameCritical = UpdateFrameCritical |
frame.SetHealthColour = SetHealthColour |
local w,h = parent:GetSize() |
local x,y |
x = floor((w / 2) - (sizes.width / 2)) |
y = floor((h / 2) - (sizes.height / 2)) |
x = floor((w / 2) - (kn.sizes.width / 2)) |
y = floor((h / 2) - (kn.sizes.height / 2)) |
-- border ------------------------------------------------------------------ |
--frame.bg = (frame.carrier and frame.carrier or frame):CreateTexture(nil, 'BACKGROUND') |
frame.bg.fill:SetVertexColor(0, 0, 0, .8) |
frame.bg.fill:SetDrawLayer('ARTWORK', 1) -- (1 sub-layer above .bg) |
frame.bg.fill:SetSize(sizes.width, sizes.height) |
frame.bg.fill:SetSize(kn.sizes.width, kn.sizes.height) |
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-kn.sizes.bgOffset, y-kn.sizes.bgOffset) |
frame.bg:SetPoint('TOPRIGHT', parent, 'BOTTOMLEFT', x+kn.sizes.width+kn.sizes.bgOffset, y+kn.sizes.height+kn.sizes.bgOffset) |
-- health bar -------------------------------------------------------------- |
frame.health = CreateFrame('StatusBar', nil, parent) |
frame.health:SetStatusBarTexture(kui.m.t.bar) |
frame.health:ClearAllPoints() |
frame.health:SetSize(sizes.width-2, sizes.height-2) |
frame.health:SetSize(kn.sizes.width-2, kn.sizes.height-2) |
frame.health:SetPoint('BOTTOMLEFT', x+1, y+1) |
if ns.SetValueSmooth then |
end |
-- health text ------------------------------------------------------------- |
frame.health.p = kui.CreateFontString(frame.overlay, { |
font = font, size = fontSizes.large, outline = "OUTLINE" }) |
frame.health.p = frame:CreateFontString(frame.overlay, { |
font = kn.font, size = 'large', outline = "OUTLINE" }) |
frame.health.p:SetJustifyH('RIGHT') |
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 = frame:CreateFontString(frame.overlay, { |
font = kn.font, size = 'small', outline = "OUTLINE" }) |
frame.health.mo:SetJustifyH('RIGHT') |
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 |
-- level text ---------------------------------------------------------- |
frame.level = kui.CreateFontString(frame.level, { reset = true, |
font = font, size = fontSizes.name, outline = 'OUTLINE' }) |
frame.level = frame:CreateFontString(frame.level, { reset = true, |
font = kn.font, size = '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.enabled = true |
frame.level.size = 'name' |
tinsert(frame.fontObjects, frame.level) |
else |
frame.level:Hide() |
end |
-- name text --------------------------------------------------------------- |
frame.name = kui.CreateFontString(frame.overlay, { |
font = font, size = fontSizes.name, outline = 'OUTLINE' }) |
frame.name = frame:CreateFontString(frame.overlay, { |
font = kn.font, size = 'name', outline = 'OUTLINE' }) |
frame.name:SetJustifyH('LEFT') |
frame.name:SetHeight(13) |
end |
frame.name:SetPoint('RIGHT', frame.health.p, 'LEFT') |
frame.name.size = 'name' |
tinsert(frame.fontObjects, frame.name) |
----------------------------------------------------------------- Scripts -- |
frame:SetScript('OnShow', OnFrameShow) |
frame:SetBackdrop({bgFile=kui.m.t.solid}) |
frame:SetBackdropColor(1, 1, 1, .5) |
frame.isfriend = kui.CreateFontString(frame, { |
font = font, size = 10, outline = 'OUTLINE' }) |
frame.isfriend = frame:CreateFontString(frame, { |
font = kn.font, size = 10, outline = 'OUTLINE' }) |
frame.isfriend:SetPoint('BOTTOM', frame, 'TOP') |
frame.guidtext = kui.CreateFontString(frame, { |
font = font, size = 10, outline = "OUTLINE" }) |
frame.guidtext = frame:CreateFontString(frame, { |
font = kn.font, size = 10, outline = "OUTLINE" }) |
frame.guidtext:SetPoint('TOP', frame, 'BOTTOM') |
frame.nametext = kui.CreateFontString(frame, { |
font = font, size = 10, outline = "OUTLINE" }) |
frame.nametext = frame:CreateFontString(frame, { |
font = kn.font, size = 10, outline = "OUTLINE" }) |
frame.nametext:SetPoint('TOP', frame.guidtext, 'BOTTOM') |
end |
end |
end |
-- TODO move all this crap into config.lua |
-- TODO move all this crap into config.lua (or maybe not, create.lua?) |
---------------------------------------------------- Post db change functions -- |
-- for changes which require traversal of all frames |
kn.updateFunctions = {} |
local _, fontObject |
for _, fontObject in pairs(frame.fontObjects) do |
SetFontSize(fontObject, fontSizes[fontObject.size]) |
if type(fontObject.size) == 'string' then |
SetFontSize(fontObject, kn.fontSizes[fontObject.size]) |
end |
end |
end |
kn.updateFunctions.font = function(frame, val, runonce) |
val = LSM:Fetch(LSM.MediaType.FONT, val) |
if runonce == 0 then |
kn.font = val |
end |
local _, fontObject |
for _, fontObject in pairs(frame.fontObjects) do |
local _, size, flags = fontObject:GetFont() |
-- [initialise and] scale font sizes |
function ns:ScaleFonts() |
for k, size in pairs(defaultSizes.font) do |
kn.fontSizes[k] = size * profile.general.fontscale |
kn.fontSizes[k] = size * profile.fontoptions.fontscale |
if uiscale then |
kn.fontSizes[k] = kn.fontSizes[k] / uiscale |
if profile.general.fixaa then |
uiscale = UIParent:GetEffectiveScale() |
end |
self:ScaleFrames() |
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 |
kn.font = LSM:Fetch(LSM.MediaType.FONT, profile.fontoptions.font) |
-------------------------------------- Health bar smooth update functions -- |
-- (spoon-fed by oUF_Smooth) |
['UNIT_SPELLCAST_CHANNEL_STOP'] = true |
} |
local GetNameplate = KuiNameplates.GetNameplate |
local UnitGUID, GetUnitName, UnitChannelInfo, UnitCastingInfo, GetTime, format = |
UnitGUID, GetUnitName, UnitChannelInfo, UnitCastingInfo, GetTime, format |
------------------------------------------------------------- Script handlers -- |
local function OnCastbarUpdate(bar, elapsed) |
-- display progress |
if bar.max then |
bar.curr:SetText(string.format("%.1f", bar.progress)) |
bar.curr:SetText(format("%.1f", bar.progress)) |
if bar.delay == 0 or not bar.delay then |
bar.max:SetText(string.format("%.1f", bar.duration)) |
bar.max:SetText(format("%.1f", bar.duration)) |
else |
-- display delay |
if bar.channel then |
-- time is removed |
bar.max:SetText(string.format("%.1f", bar.duration).. |
'|cffff0000-'..string.format("%.1f", bar.delay)..'|r') |
bar.max:SetText(format("%.1f", bar.duration).. |
'|cffff0000-'..format("%.1f", bar.delay)..'|r') |
else |
-- time is added |
bar.max:SetText(string.format("%.1f", bar.duration).. |
'|cffff0000+'..string.format("%.1f", bar.delay)..'|r') |
bar.max:SetText(format("%.1f", bar.duration).. |
'|cffff0000+'..format("%.1f", bar.delay)..'|r') |
end |
end |
end |
-- cast bar text ------------------------------------------------------- |
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 = frame:CreateFontString(frame.castbar, { |
font = kn.font, 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') |
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 = frame:CreateFontString(frame.castbar, { |
font = kn.font, size = 'name', outline = "OUTLINE" }) |
frame.castbar.max:SetPoint('TOPRIGHT', frame.castbar.bg, 'BOTTOMRIGHT', -2, -1) |
frame.castbar.curr = kui.CreateFontString(frame.castbar, { |
font = kn.font, size = kn.fontSizes.small, outline = "OUTLINE" }) |
frame.castbar.curr = frame:CreateFontString(frame.castbar, { |
font = kn.font, size = 'small', outline = "OUTLINE" }) |
frame.castbar.curr:SetAlpha(.5) |
frame.castbar.curr:SetPoint('TOPRIGHT', frame.castbar.max, 'TOPLEFT', -1, -1) |
frame.castbar.name:SetPoint('TOPRIGHT', frame.castbar.curr, 'TOPLEFT', -1, 0) |
end |
if frame.spell then |