diff --git a/ElvUI_SLE/config/profile.lua b/ElvUI_SLE/config/profile.lua index 46c28e5..f640449 100755 --- a/ElvUI_SLE/config/profile.lua +++ b/ElvUI_SLE/config/profile.lua @@ -228,8 +228,13 @@ P['sle'] = { }, }, + --Nameplate Options + ['nameplate'] = { + ['showthreat'] = false, + ['targetcount'] = false, + }, --Power text on classbars - ['powtext'] = false; + ['powtext'] = false, --Raid marks ['marks'] = { diff --git a/ElvUI_SLE/modules/load_modules.xml b/ElvUI_SLE/modules/load_modules.xml index 73f5972..6ead5a4 100755 --- a/ElvUI_SLE/modules/load_modules.xml +++ b/ElvUI_SLE/modules/load_modules.xml @@ -15,6 +15,7 @@ <Include file='loot\load_loot.xml'/> <Include file='marks\load_marks.xml'/> <Include file='minimap\load_minimap.xml'/> + <Include file='nameplates\load_nameplates.xml'/> <Include file='raidutility\load_raidutility.xml'/> <Include file='tooltip\load_tooltip.xml'/> <Include file='uibuttons\load_uibuttons.xml'/> diff --git a/ElvUI_SLE/modules/nameplates/load_nameplates.xml b/ElvUI_SLE/modules/nameplates/load_nameplates.xml new file mode 100644 index 0000000..04aa61d --- /dev/null +++ b/ElvUI_SLE/modules/nameplates/load_nameplates.xml @@ -0,0 +1,4 @@ +<Ui xmlns="http://www.blizzard.com/wow/ui/"> + <Script file='nameplates.lua'/> + <Script file='options.lua'/> +</Ui> \ No newline at end of file diff --git a/ElvUI_SLE/modules/nameplates/nameplates.lua b/ElvUI_SLE/modules/nameplates/nameplates.lua new file mode 100644 index 0000000..3900a7c --- /dev/null +++ b/ElvUI_SLE/modules/nameplates/nameplates.lua @@ -0,0 +1,110 @@ +local E, L, V, P, G = unpack(ElvUI); +local NP = E:GetModule('NamePlates') +local LSM = LibStub("LibSharedMedia-3.0") + +local UnitCanAttack, UnitDetailedThreatSituation, GetThreatStatusColor = UnitCanAttack, UnitDetailedThreatSituation, GetThreatStatusColor +local GetNumGroupMembers, GetNumSubgroupMembers = GetNumGroupMembers, GetNumSubgroupMembers +local IsInRaid, IsInGroup, UnitGUID, UnitName = IsInRaid, IsInGroup, UnitGUID, UnitName +local format, twipe = string.format, table.wipe +local rosterTimer + +function Hex(r, g, b) + return format('|cFF%02x%02x%02x', r * 255, g * 255, b * 255) +end + +NP.GroupMembers = {} + +hooksecurefunc(NP, 'CreatePlate', function(self, frame) + local myPlate = self.CreatedPlates[frame] + if not myPlate then return end + + if not myPlate.threatInfo then + myPlate.threatInfo = myPlate:CreateFontString(nil, "OVERLAY") + myPlate.threatInfo:SetPoint("BOTTOMLEFT", myPlate.healthBar, "BOTTOMLEFT", 1, 2) + myPlate.threatInfo:SetJustifyH("LEFT") + end + if not frame.targetcount then + myPlate.targetcount = myPlate:CreateFontString(nil, "OVERLAY") + myPlate.targetcount:SetPoint('BOTTOMRIGHT', myPlate.healthBar, 'BOTTOMRIGHT', 1, 2) + myPlate.targetcount:SetJustifyH("RIGHT") + end + myPlate.threatInfo:FontTemplate(LSM:Fetch("font", NP.db.font), NP.db.fontSize, NP.db.fontOutline) + myPlate.targetcount:FontTemplate(LSM:Fetch("font", NP.db.font), NP.db.fontSize, NP.db.fontOutline) +end) + +hooksecurefunc(NP, 'GetThreatReaction', function(self, frame) + local myPlate = self.CreatedPlates[frame] + if not myPlate then return end + + if myPlate.threatInfo then + myPlate.threatInfo:SetText() + + if E.db.sle.nameplate.showthreat then + local unit = frame.unit + if not unit then + for i=1, 4 do + if frame.guid == UnitGUID(('boss%d'):format(i)) then + unit = ('boss%d'):format(i) + break + end + end + end + + if unit and not UnitIsPlayer(unit) and UnitCanAttack('player', unit) then + local status, percent = select(2, UnitDetailedThreatSituation('player', unit)) + if (status) then + myPlate.threatInfo:SetFormattedText('%s%.0f%%|r', Hex(GetThreatStatusColor(status)), percent) + else + myPlate.threatInfo:SetFormattedText('|cFF808080%s|r', L["None"]) + end + end + end + end + if E.db.sle.nameplate.targetcount and myPlate.targetcount then + myPlate.targetcount:SetText() + if frame.guid then + local targetCount = 0 + local target + for name, unitid in pairs(NP.GroupMembers) do + target = ("%starget"):format(unitid) + if UnitExists(target) and UnitGUID(target) == frame.guid then + targetCount = targetCount + 1 + end + end + --Set the target count text + if not (targetCount == 0) then + myPlate.targetcount:SetText(('[%d]'):format(targetCount)) + end + end + end +end) + +function NP:AddToRoster(unitId) + local unitName = UnitName(unitId) + if unitName then + self.GroupMembers[unitName] = unitId + end +end + +function NP:UpdateRoster() + twipe(self.GroupMembers) + + local groupSize = IsInRaid() and GetNumGroupMembers() or IsInGroup() and GetNumSubgroupMembers() or 0 + local groupType = IsInRaid() and "raid" or IsInGroup() and "party" or "solo" + + for index = 1, groupSize do + self:AddToRoster(groupType..index) + end + + if groupType == 'party' then + self:AddToRoster('player') + end +end + +function NP:StartRosterUpdate() + if not rosterTimer or NP:TimeLeft(rosterTimer) == 0 then + rosterTimer = NP:ScheduleTimer('UpdateRoster', 1) + end +end + +NP:RegisterEvent("GROUP_ROSTER_UPDATE", "StartRosterUpdate") \ No newline at end of file diff --git a/ElvUI_SLE/modules/nameplates/options.lua b/ElvUI_SLE/modules/nameplates/options.lua new file mode 100644 index 0000000..8b7f1e6 --- /dev/null +++ b/ElvUI_SLE/modules/nameplates/options.lua @@ -0,0 +1,33 @@ +local E, L, V, P, G = unpack(ElvUI); +local NP = E:GetModule('NamePlates') + +local function configTable() + E.Options.args.sle.args.nameplate = { + type = "group", + name = L["NamePlates"], + order = 82, + get = function(info) return E.db.sle.nameplate[ info[#info] ] end, + set = function(info, value) E.db.sle.nameplate[ info[#info] ] = value; NP:UpdateAllPlates() end, + args = { + header = { + order = 1, + type = "header", + name = L["Nameplate Options"], + }, + targetcount = { + type = "toggle", + order = 2, + name = L["Target Count"], + desc = L["Display the number of party / raid members targetting the nameplate unit."], + }, + showthreat = { + type = "toggle", + order = 3, + name = L["Threat Text"], + desc = L["Display threat level as text on targeted, boss or mouseover nameplate."], + }, + }, + } +end + +table.insert(E.SLEConfigs, configTable) \ No newline at end of file