Skip to content

Commit

Permalink
wip: update nameplate module
Browse files Browse the repository at this point in the history
  • Loading branch information
ffainy committed Jun 19, 2022
1 parent 0e6a34a commit 2316601
Show file tree
Hide file tree
Showing 9 changed files with 338 additions and 372 deletions.
4 changes: 2 additions & 2 deletions config/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ C.CharacterSettings = {
AbbrName = true,
HealthPerc = true,
FriendlyPlate = true,
TargetIndicator = true,
TargetIndicatorColor = { r = 0.73, g = 0.92, b = 0.99 },
SelectedIndicator = true,
SelectedIndicatorColor = { r = 0.73, g = 0.92, b = 0.99 },
ThreatIndicator = true,
ClassifyIndicator = true,
QuestIndicator = true,
Expand Down
28 changes: 21 additions & 7 deletions gui/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ local function RefreshAllPlates()
NAMEPLATE:RefreshAllPlates()
end

local function UpdateNameplateRaidTargetIndicator()
NAMEPLATE:UpdateRaidTargetIndicator()
end

-- Unitframe

local function UpdateHealthColor()
Expand Down Expand Up @@ -2168,6 +2172,16 @@ GUI.OptionsList = {
UpdatePlateClickThrough,
L["Hostile units' nameplate ignore mouse clicks."],
},
{
1,
'Nameplate',
'HealthPerc',
L['Health Percentage'],
true,
nil,
nil,
L['Display the health percentage on the nameplate and hides it when it is full.'],
},
{},
{
1,
Expand Down Expand Up @@ -2253,12 +2267,12 @@ GUI.OptionsList = {
{
1,
'Nameplate',
'HealthPerc',
L['Health Percentage'],
'SelectedIndicator',
L['Selected Indicator'],
true,
nil,
nil,
L['Display the health percentage on the nameplate and hides it when it is full.'],
L['The currently selected unit has a white glow at the bottom of its nameplate.'],
},
{
1,
Expand All @@ -2283,12 +2297,12 @@ GUI.OptionsList = {
{
1,
'Nameplate',
'TargetIndicator',
L['Target Indicator'],
nil,
'RaidTargetIndicator',
L['Raid Target Indicator'],
nil,
nil,
L['A white glow is displayed below the nameplate of the current target.'],
UpdateNameplateRaidTargetIndicator,
L["Display raid target indicator on nameplate."],
},
{
1,
Expand Down
5 changes: 4 additions & 1 deletion modules/nameplate/elements/elements.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/">
<Script file="indicator.lua"/>
<Script file="mouseover.lua"/>
<Script file="quest.lua"/>
<Script file="raidtarget.lua"/>
<Script file="selected.lua"/>
<Script file="totem.lua"/>
</Ui>
59 changes: 59 additions & 0 deletions modules/nameplate/elements/mouseover.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
local F, C = unpack(select(2, ...))
local NAMEPLATE = F:GetModule('Nameplate')

function NAMEPLATE:IsMouseoverUnit()
if not self or not self.unit then
return
end

if self:IsVisible() and UnitExists('mouseover') then
return UnitIsUnit('mouseover', self.unit)
end
return false
end

function NAMEPLATE:HighlightOnUpdate(elapsed)
self.elapsed = (self.elapsed or 0) + elapsed
if self.elapsed > 0.1 then
if not NAMEPLATE.IsMouseoverUnit(self.__owner) then
self:Hide()
end
self.elapsed = 0
end
end

function NAMEPLATE:HighlightOnHide()
self.__owner.HighlightIndicator:Hide()
end

function NAMEPLATE:UpdateMouseoverShown()
if not self or not self.unit then
return
end

if self:IsShown() and UnitIsUnit('mouseover', self.unit) then
self.HighlightIndicator:Show()
self.HighlightUpdater:Show()
else
self.HighlightUpdater:Hide()
end
end

function NAMEPLATE:CreateMouseoverIndicator(self)
local highlight = CreateFrame('Frame', nil, self.Health)
highlight:SetAllPoints(self)
highlight:Hide()
local texture = highlight:CreateTexture(nil, 'ARTWORK')
texture:SetAllPoints()
texture:SetColorTexture(1, 1, 1, 0.25)

self:RegisterEvent('UPDATE_MOUSEOVER_UNIT', NAMEPLATE.UpdateMouseoverShown, true)

local updater = CreateFrame('Frame', nil, self)
updater.__owner = self
updater:SetScript('OnUpdate', NAMEPLATE.HighlightOnUpdate)
updater:HookScript('OnHide', NAMEPLATE.HighlightOnHide)

self.HighlightIndicator = highlight
self.HighlightUpdater = updater
end
105 changes: 105 additions & 0 deletions modules/nameplate/elements/quest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
local F, C = unpack(select(2, ...))
local NAMEPLATE = F:GetModule('Nameplate')

local isInInstance
local function CheckInstanceStatus()
isInInstance = IsInInstance()
end

function NAMEPLATE:QuestIconCheck()
if not C.DB.Nameplate.QuestIndicator then
return
end

CheckInstanceStatus()
F:RegisterEvent('PLAYER_ENTERING_WORLD', CheckInstanceStatus)
end

local function isQuestTitle(textLine)
local r, g, b = textLine:GetTextColor()
if r > 0.99 and g > 0.82 and b == 0 then
return true
end
end

function NAMEPLATE:UpdateQuestUnit(_, unit)
if not C.DB.Nameplate.QuestIndicator then
return
end

local isNameOnly = self.plateType == 'NameOnly'
local isInGroup = IsInRaid() or IsInGroup()

if isInInstance then
self.questIcon:Hide()
self.questCount:SetText('')
return
end

unit = unit or self.unit

local startLooking, questProgress
F.ScanTip:SetOwner(_G.UIParent, 'ANCHOR_NONE')
F.ScanTip:SetUnit(unit)

for i = 2, F.ScanTip:NumLines() do
local textLine = _G[C.ADDON_NAME .. 'ScanTooltipTextLeft' .. i]
local text = textLine and textLine:GetText()

if not text then
break
end

if text ~= ' ' then
if isInGroup and text == C.MY_NAME or (not isInGroup and isQuestTitle(textLine)) then
startLooking = true
elseif startLooking then
local current, goal = string.match(text, '(%d+)/(%d+)')
local progress = string.match(text, '(%d+)%%')
if current and goal then
local diff = math.floor(goal - current)
if diff > 0 then
questProgress = diff
break
end
elseif progress and not string.match(text, _G.THREAT_TOOLTIP) then
if math.floor(100 - progress) > 0 then
questProgress = progress .. '%' -- lower priority on progress, keep looking
end
else
break
end
end
end
end

if questProgress and not isNameOnly then
self.questCount:SetText(questProgress)
self.questIcon:SetAtlas('Warfronts-BaseMapIcons-Horde-Barracks-Minimap')
self.questIcon:Show()
else
self.questCount:SetText('')
self.questIcon:Hide()
end
end

function NAMEPLATE:CreateQuestIndicator(self)
if not C.DB.Nameplate.QuestIndicator then
return
end

local height = C.DB.Nameplate.Height
local qicon = self:CreateTexture(nil, 'OVERLAY', nil, 2)
qicon:SetPoint('LEFT', self, 'RIGHT', 3, 0)
qicon:SetSize(height + 10, height + 10)
qicon:SetAtlas('adventureguide-microbutton-alert')
qicon:Hide()

local count = F.CreateFS(self, C.Assets.Font.Condensed, 12, nil, '', nil, true)
count:SetPoint('LEFT', qicon, 'RIGHT', -3, 0)
count:SetTextColor(0.6, 0.8, 1)

self.questIcon = qicon
self.questCount = count
self:RegisterEvent('QUEST_LOG_UPDATE', NAMEPLATE.UpdateQuestUnit, true)
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local F, C = unpack(select(2, ...))
local NAMEPLATE = F:GetModule('Nameplate')
local oUF = F.Libs.oUF

function NAMEPLATE.ConfigureTargetIndicator(frame)
function NAMEPLATE.ConfigureRaidTargetIndicator(frame)
local icon = frame.RaidTargetIndicator
local enable = C.DB.Nameplate.RaidTargetIndicator
local nameOnly = frame.plateType == 'NameOnly'
Expand All @@ -29,7 +29,7 @@ function NAMEPLATE:CreateRaidTargetIndicator(self)

self.RaidTargetIndicator = icon

NAMEPLATE.ConfigureTargetIndicator(self)
NAMEPLATE.ConfigureRaidTargetIndicator(self)
end

function NAMEPLATE:UpdateRaidTargetIndicator()
Expand Down
Loading

0 comments on commit 2316601

Please sign in to comment.