initial commit

This commit is contained in:
Gitea
2020-11-13 14:27:50 -05:00
commit e2015fd9bb
581 changed files with 101308 additions and 0 deletions

View File

@@ -0,0 +1,138 @@
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
local DB = E:GetModule('DataBars')
local _G = _G
local floor = floor
local format = format
local InCombatLockdown = InCombatLockdown
local HasArtifactEquipped = HasArtifactEquipped
local SocketInventoryItem = SocketInventoryItem
local UIParentLoadAddOn = UIParentLoadAddOn
local ToggleFrame = ToggleFrame
local Item = Item
local C_ArtifactUI_IsEquippedArtifactDisabled = C_ArtifactUI.IsEquippedArtifactDisabled
local C_AzeriteItem_FindActiveAzeriteItem = C_AzeriteItem.FindActiveAzeriteItem
local C_AzeriteItem_GetAzeriteItemXPInfo = C_AzeriteItem.GetAzeriteItemXPInfo
local C_AzeriteItem_GetPowerLevel = C_AzeriteItem.GetPowerLevel
local C_AzeriteItem_IsAzeriteItemAtMaxLevel = C_AzeriteItem.IsAzeriteItemAtMaxLevel
local ARTIFACT_POWER = ARTIFACT_POWER
function DB:AzeriteBar_Update(event, unit)
if event == 'UNIT_INVENTORY_CHANGED' and unit ~= 'player' then return end
local bar = DB.StatusBars.Azerite
DB:SetVisibility(bar)
if not bar.db.enable or bar:ShouldHide() then return end
local item = C_AzeriteItem_FindActiveAzeriteItem()
local cur, max = C_AzeriteItem_GetAzeriteItemXPInfo(item)
local currentLevel = C_AzeriteItem_GetPowerLevel(item)
local color = DB.db.colors.azerite
bar:SetStatusBarColor(color.r, color.g, color.b, color.a)
bar:SetMinMaxValues(0, max)
bar:SetValue(cur)
local textFormat = DB.db.azerite.textFormat
if textFormat == 'NONE' then
bar.text:SetText('')
elseif textFormat == 'PERCENT' then
bar.text:SetFormattedText('%s%% [%s]', floor(cur / max * 100), currentLevel)
elseif textFormat == 'CURMAX' then
bar.text:SetFormattedText('%s - %s [%s]', E:ShortValue(cur), E:ShortValue(max), currentLevel)
elseif textFormat == 'CURPERC' then
bar.text:SetFormattedText('%s - %s%% [%s]', E:ShortValue(cur), floor(cur / max * 100), currentLevel)
elseif textFormat == 'CUR' then
bar.text:SetFormattedText('%s [%s]', E:ShortValue(cur), currentLevel)
elseif textFormat == 'REM' then
bar.text:SetFormattedText('%s [%s]', E:ShortValue(max - cur), currentLevel)
elseif textFormat == 'CURREM' then
bar.text:SetFormattedText('%s - %s [%s]', E:ShortValue(cur), E:ShortValue(max - cur), currentLevel)
elseif textFormat == 'CURPERCREM' then
bar.text:SetFormattedText('%s - %s%% (%s) [%s]', E:ShortValue(cur), floor(cur / max * 100), E:ShortValue(max - cur), currentLevel)
else
bar.text:SetFormattedText('[%s]', currentLevel)
end
end
do
local azeriteItem, currentLevel, curXP, maxXP
local function dataLoadedCancelFunc()
if _G.GameTooltip:IsForbidden() then return end
_G.GameTooltip:AddDoubleLine(ARTIFACT_POWER, azeriteItem:GetItemName()..' ('..currentLevel..')', nil, nil, nil, 0.90, 0.80, 0.50) -- Temp Locale
_G.GameTooltip:AddLine(' ')
_G.GameTooltip:AddDoubleLine(L["AP:"], format(' %d / %d (%d%%)', curXP, maxXP, curXP / maxXP * 100), 1, 1, 1)
_G.GameTooltip:AddDoubleLine(L["Remaining:"], format(' %d (%d%% - %d '..L["Bars"]..')', maxXP - curXP, (maxXP - curXP) / maxXP * 100, 10 * (maxXP - curXP) / maxXP), 1, 1, 1)
_G.GameTooltip:Show()
end
function DB:AzeriteBar_OnEnter()
local item = C_AzeriteItem_FindActiveAzeriteItem()
if item then
if DB.db.azerite.mouseover then
E:UIFrameFadeIn(self, 0.4, self:GetAlpha(), 1)
end
if not _G.GameTooltip:IsForbidden() then
_G.GameTooltip:ClearLines()
_G.GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
end
curXP, maxXP = C_AzeriteItem_GetAzeriteItemXPInfo(item)
currentLevel = C_AzeriteItem_GetPowerLevel(item)
azeriteItem = Item:CreateFromItemLocation(item)
azeriteItem:ContinueWithCancelOnItemLoad(dataLoadedCancelFunc)
end
end
end
function DB:AzeriteBar_OnClick()
if InCombatLockdown() then return end
if HasArtifactEquipped() and not C_ArtifactUI_IsEquippedArtifactDisabled() then
SocketInventoryItem(_G.INVSLOT_MAINHAND)
elseif C_AzeriteItem_FindActiveAzeriteItem() then
UIParentLoadAddOn('Blizzard_AzeriteEssenceUI')
ToggleFrame(_G.AzeriteEssenceUI)
end
end
function DB:AzeriteBar_Toggle()
local bar = DB.StatusBars.Azerite
bar.db = DB.db.azerite
if bar.db.enable then
E:EnableMover(bar.holder.mover:GetName())
DB:RegisterEvent('AZERITE_ITEM_EXPERIENCE_CHANGED', 'AzeriteBar_Update')
DB:RegisterEvent('PLAYER_EQUIPMENT_CHANGED', 'AzeriteBar_Update')
DB:AzeriteBar_Update()
else
E:DisableMover(bar.holder.mover:GetName())
DB:UnregisterEvent('AZERITE_ITEM_EXPERIENCE_CHANGED')
DB:UnregisterEvent('PLAYER_EQUIPMENT_CHANGED')
end
end
function DB:AzeriteBar()
local Azerite = DB:CreateBar('ElvUI_AzeriteBar', 'Azerite', DB.AzeriteBar_Update, DB.AzeriteBar_OnEnter, DB.AzeriteBar_OnClick, {'TOPRIGHT', E.UIParent, 'TOPRIGHT', -3, -245})
DB:CreateBarBubbles(Azerite)
Azerite.ShouldHide = function()
local item = C_AzeriteItem_FindActiveAzeriteItem()
local equipped = item and item:IsEquipmentSlot()
return not equipped or (DB.db.azerite.hideAtMaxLevel and C_AzeriteItem_IsAzeriteItemAtMaxLevel())
end
E:CreateMover(Azerite.holder, 'AzeriteBarMover', L["Azerite Bar"], nil, nil, nil, nil, nil, 'databars,azerite')
DB:AzeriteBar_Toggle()
end

View File

@@ -0,0 +1,181 @@
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
local DB = E:GetModule('DataBars')
local LSM = E.Libs.LSM
local _G = _G
local unpack, select = unpack, select
local pairs, ipairs = pairs, ipairs
local CreateFrame = CreateFrame
local GetInstanceInfo = GetInstanceInfo
local UnitAffectingCombat = UnitAffectingCombat
local C_PvP_IsWarModeActive = C_PvP.IsWarModeActive
function DB:OnLeave()
if self.db.mouseover then
E:UIFrameFadeOut(self, 1, self:GetAlpha(), 0)
end
if not _G.GameTooltip:IsForbidden() then
_G.GameTooltip:Hide()
end
end
function DB:CreateBar(name, key, updateFunc, onEnter, onClick, points)
local holder = CreateFrame('Frame', name..'Holder', E.UIParent, 'BackdropTemplate')
holder:SetTemplate(DB.db.transparent and 'Transparent')
holder:SetScript('OnEnter', onEnter)
holder:SetScript('OnLeave', DB.OnLeave)
holder:SetScript('OnMouseDown', onClick)
if points then
holder:ClearAllPoints()
holder:Point(unpack(points))
end
local bar = CreateFrame('StatusBar', name, holder)
bar:SetStatusBarTexture(E.media.normTex)
bar:EnableMouse(false)
bar:SetInside()
bar:Hide()
bar.barTexture = bar:GetStatusBarTexture()
bar.text = bar:CreateFontString(nil, 'OVERLAY', nil, 7)
bar.text:FontTemplate()
bar.text:Point('CENTER')
bar.holder = holder
bar.Update = updateFunc
E.FrameLocks[holder] = true
DB.StatusBars[key] = bar
return bar
end
function DB:CreateBarBubbles(bar)
if bar.bubbles then return end
bar.bubbles = {}
for i = 1, 19 do
bar.bubbles[i] = bar:CreateTexture(nil, 'OVERLAY', nil, 0)
bar.bubbles[i]:SetColorTexture(0, 0, 0)
end
end
function DB:UpdateBarBubbles(bar)
if not bar.bubbles then return end
local width, height = bar.db.width, bar.db.height
local vertical = bar:GetOrientation() ~= 'HORIZONTAL'
local bubbleWidth, bubbleHeight = vertical and (width - 2) or 1, vertical and 1 or (height - 2)
local offset = (vertical and height or width) / 20
for i, bubble in ipairs(bar.bubbles) do
bubble:ClearAllPoints()
bubble:SetSize(bubbleWidth, bubbleHeight)
bubble:SetShown(bar.db.showBubbles)
if vertical then
bubble:Point('TOP', bar, 'BOTTOM', 0, offset * i)
else
bubble:Point('RIGHT', bar, 'LEFT', offset * i, 0)
end
end
end
function DB:UpdateAll()
local texture = DB.db.customTexture and LSM:Fetch('statusbar', DB.db.statusbar) or E.media.normTex
for _, bar in pairs(DB.StatusBars) do
bar.holder.db = bar.db
bar.holder:Size(bar.db.width, bar.db.height)
bar.holder:SetTemplate(DB.db.transparent and 'Transparent')
bar.holder:EnableMouse(not bar.db.clickThrough)
bar.text:FontTemplate(LSM:Fetch('font', bar.db.font), bar.db.fontSize, bar.db.fontOutline)
bar:SetStatusBarTexture(texture)
bar:SetReverseFill(bar.db.reverseFill)
if bar.db.enable then
bar.holder:SetAlpha(bar.db.mouseover and 0 or 1)
end
if bar.db.hideInVehicle then
E:RegisterObjectForVehicleLock(bar.holder, E.UIParent)
else
E:UnregisterObjectForVehicleLock(bar.holder)
end
if bar.db.orientation == 'AUTOMATIC' then
bar:SetOrientation(bar.db.height > bar.db.width and 'VERTICAL' or 'HORIZONTAL')
bar:SetRotatesTexture(bar.db.height > bar.db.width)
else
bar:SetOrientation(bar.db.orientation)
bar:SetRotatesTexture(bar.db.orientation ~= 'HORIZONTAL')
end
local orientation = bar:GetOrientation()
local rotatesTexture = bar:GetRotatesTexture()
local reverseFill = bar:GetReverseFill()
for i = 1, bar.holder:GetNumChildren() do
local child = select(i, bar.holder:GetChildren())
if child:IsObjectType('StatusBar') then
child:SetStatusBarTexture(texture)
child:SetOrientation(orientation)
child:SetRotatesTexture(rotatesTexture)
child:SetReverseFill(reverseFill)
end
end
DB:UpdateBarBubbles(bar)
end
DB:HandleVisibility()
end
function DB:SetVisibility(bar)
if bar.showBar ~= nil then
bar:SetShown(bar.showBar)
bar.holder:SetShown(bar.showBar)
elseif bar.db.enable then
local hideBar = (bar == DB.StatusBars.Threat or bar.db.hideInCombat) and UnitAffectingCombat('player')
or (bar.db.hideOutsidePvP and not (C_PvP_IsWarModeActive() or select(2, GetInstanceInfo()) == 'pvp'))
or (bar.ShouldHide and bar:ShouldHide())
bar:SetShown(not hideBar)
bar.holder:SetShown(not hideBar)
else
bar:SetShown(false)
bar.holder:SetShown(false)
end
end
function DB:HandleVisibility()
for _, bar in pairs(DB.StatusBars) do
DB:SetVisibility(bar)
end
end
function DB:Initialize()
DB.Initialized = true
DB.StatusBars = {}
DB.db = E.db.databars
DB:ExperienceBar()
DB:ReputationBar()
DB:HonorBar()
DB:AzeriteBar()
DB:ThreatBar()
DB:UpdateAll()
DB:RegisterEvent('PLAYER_LEVEL_UP', 'HandleVisibility')
DB:RegisterEvent('PLAYER_ENTERING_WORLD', 'HandleVisibility')
DB:RegisterEvent('PLAYER_REGEN_DISABLED', 'HandleVisibility')
DB:RegisterEvent('PLAYER_REGEN_ENABLED', 'HandleVisibility')
DB:RegisterEvent('PVP_TIMER_UPDATE', 'HandleVisibility')
end
E:RegisterModule(DB:GetName())

View File

@@ -0,0 +1,220 @@
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
local DB = E:GetModule('DataBars')
local LSM = E.Libs.LSM
local _G = _G
local min, format = min, format
local CreateFrame = CreateFrame
local GetXPExhaustion = GetXPExhaustion
local IsXPUserDisabled = IsXPUserDisabled
local GetQuestLogRewardXP = GetQuestLogRewardXP
local IsPlayerAtEffectiveMaxLevel = IsPlayerAtEffectiveMaxLevel
local C_QuestLog_GetNumQuestLogEntries = C_QuestLog.GetNumQuestLogEntries
local C_QuestLog_GetQuestIDForLogIndex = C_QuestLog.GetQuestIDForLogIndex
local C_QuestLog_ReadyForTurnIn = C_QuestLog.ReadyForTurnIn
local C_QuestLog_GetInfo = C_QuestLog.GetInfo
local UnitXP, UnitXPMax = UnitXP, UnitXPMax
local CurrentXP, XPToLevel, RestedXP, PercentRested
local PercentXP, RemainXP, RemainTotal, RemainBars
local QuestLogXP = 0
function DB:ExperienceBar_CheckQuests(questID, completedOnly)
if not questID then return end
local isCompleted = C_QuestLog_ReadyForTurnIn(questID)
if not completedOnly or isCompleted then
QuestLogXP = QuestLogXP + GetQuestLogRewardXP(questID)
end
end
function DB:ExperienceBar_ShouldBeVisible()
return not IsPlayerAtEffectiveMaxLevel() and not IsXPUserDisabled()
end
function DB:ExperienceBar_Update()
local bar = DB.StatusBars.Experience
DB:SetVisibility(bar)
if not bar.db.enable or bar:ShouldHide() then return end
CurrentXP, XPToLevel, RestedXP = UnitXP('player'), UnitXPMax('player'), GetXPExhaustion()
if XPToLevel <= 0 then XPToLevel = 1 end
local remainXP = XPToLevel - CurrentXP
local remainPercent = remainXP / XPToLevel
RemainTotal, RemainBars = remainPercent * 100, remainPercent * 20
PercentXP, RemainXP = (CurrentXP / XPToLevel) * 100, E:ShortValue(remainXP)
local expColor, restedColor = DB.db.colors.experience, DB.db.colors.rested
bar:SetStatusBarColor(expColor.r, expColor.g, expColor.b, expColor.a)
bar.Rested:SetStatusBarColor(restedColor.r, restedColor.g, restedColor.b, restedColor.a)
local displayString, textFormat = '', DB.db.experience.textFormat
if not DB:ExperienceBar_ShouldBeVisible() then
bar:SetMinMaxValues(0, 1)
bar:SetValue(1)
if textFormat ~= 'NONE' then
displayString = IsXPUserDisabled() and L["Disabled"] or L["Max Level"]
end
else
bar:SetMinMaxValues(0, XPToLevel)
bar:SetValue(CurrentXP)
if textFormat == 'PERCENT' then
displayString = format('%.2f%%', PercentXP)
elseif textFormat == 'CURMAX' then
displayString = format('%s - %s', E:ShortValue(CurrentXP), E:ShortValue(XPToLevel))
elseif textFormat == 'CURPERC' then
displayString = format('%s - %.2f%%', E:ShortValue(CurrentXP), PercentXP)
elseif textFormat == 'CUR' then
displayString = format('%s', E:ShortValue(CurrentXP))
elseif textFormat == 'REM' then
displayString = format('%s', RemainXP)
elseif textFormat == 'CURREM' then
displayString = format('%s - %s', E:ShortValue(CurrentXP), RemainXP)
elseif textFormat == 'CURPERCREM' then
displayString = format('%s - %.2f%% (%s)', E:ShortValue(CurrentXP), PercentXP, RemainXP)
end
local isRested = RestedXP and RestedXP > 0
if isRested then
bar.Rested:SetMinMaxValues(0, XPToLevel)
bar.Rested:SetValue(min(CurrentXP + RestedXP, XPToLevel))
PercentRested = (RestedXP / XPToLevel) * 100
if textFormat == 'PERCENT' then
displayString = format('%s R:%.2f%%', displayString, PercentRested)
elseif textFormat == 'CURPERC' then
displayString = format('%s R:%s [%.2f%%]', displayString, E:ShortValue(RestedXP), PercentRested)
elseif textFormat ~= 'NONE' then
displayString = format('%s R:%s', displayString, E:ShortValue(RestedXP))
end
end
if bar.db.showLevel then
displayString = format('%s %s : %s', L['Level'], E.mylevel, displayString)
end
bar.Rested:SetShown(isRested)
end
bar.text:SetText(displayString)
end
function DB:ExperienceBar_QuestXP()
if not DB:ExperienceBar_ShouldBeVisible() then return end
local bar = DB.StatusBars.Experience
QuestLogXP = 0
for i = 1, C_QuestLog_GetNumQuestLogEntries() do
local info = C_QuestLog_GetInfo(i)
if info and (not info.isHidden) and (bar.db.questCurrentZoneOnly and info.isOnMap or not bar.db.questCurrentZoneOnly) then
DB:ExperienceBar_CheckQuests(C_QuestLog_GetQuestIDForLogIndex(i), bar.db.questCompletedOnly)
end
end
if QuestLogXP > 0 then
bar.Quest:SetMinMaxValues(0, XPToLevel)
bar.Quest:SetValue(min(CurrentXP + QuestLogXP, XPToLevel))
bar.Quest:SetStatusBarColor(DB.db.colors.quest.r, DB.db.colors.quest.g, DB.db.colors.quest.b, DB.db.colors.quest.a)
bar.Quest:Show()
else
bar.Quest:Hide()
end
end
function DB:ExperienceBar_OnEnter()
if self.db.mouseover then
E:UIFrameFadeIn(self, 0.4, self:GetAlpha(), 1)
end
if _G.GameTooltip:IsForbidden() or not DB:ExperienceBar_ShouldBeVisible() then return end
_G.GameTooltip:ClearLines()
_G.GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
_G.GameTooltip:AddLine(L["Experience"])
_G.GameTooltip:AddLine(' ')
_G.GameTooltip:AddDoubleLine(L["XP:"], format(' %d / %d (%.2f%%)', CurrentXP, XPToLevel, PercentXP), 1, 1, 1)
_G.GameTooltip:AddDoubleLine(L["Remaining:"], format(' %s (%.2f%% - %d '..L["Bars"]..')', RemainXP, RemainTotal, RemainBars), 1, 1, 1)
_G.GameTooltip:AddDoubleLine(L["Quest Log XP:"], QuestLogXP, 1, 1, 1)
if RestedXP and RestedXP > 0 then
_G.GameTooltip:AddDoubleLine(L["Rested:"], format('+%d (%.2f%%)', RestedXP, PercentRested), 1, 1, 1)
end
_G.GameTooltip:Show()
end
function DB:ExperienceBar_OnClick() end
function DB:ExperienceBar_Toggle()
local bar = DB.StatusBars.Experience
bar.db = DB.db.experience
if bar.db.enable then
E:EnableMover(bar.holder.mover:GetName())
else
E:DisableMover(bar.holder.mover:GetName())
end
if bar.db.enable and not bar:ShouldHide() then
DB:RegisterEvent('PLAYER_XP_UPDATE', 'ExperienceBar_Update')
DB:RegisterEvent('DISABLE_XP_GAIN', 'ExperienceBar_Update')
DB:RegisterEvent('ENABLE_XP_GAIN', 'ExperienceBar_Update')
DB:RegisterEvent('UPDATE_EXHAUSTION', 'ExperienceBar_Update')
DB:RegisterEvent('QUEST_LOG_UPDATE', 'ExperienceBar_QuestXP')
DB:RegisterEvent('ZONE_CHANGED', 'ExperienceBar_QuestXP')
DB:RegisterEvent('ZONE_CHANGED_NEW_AREA', 'ExperienceBar_QuestXP')
DB:UnregisterEvent('UPDATE_EXPANSION_LEVEL')
DB:ExperienceBar_Update()
else
DB:UnregisterEvent('PLAYER_XP_UPDATE')
DB:UnregisterEvent('DISABLE_XP_GAIN')
DB:UnregisterEvent('ENABLE_XP_GAIN')
DB:UnregisterEvent('UPDATE_EXHAUSTION')
DB:UnregisterEvent('QUEST_LOG_UPDATE')
DB:UnregisterEvent('ZONE_CHANGED')
DB:UnregisterEvent('ZONE_CHANGED_NEW_AREA')
DB:RegisterEvent('UPDATE_EXPANSION_LEVEL', 'ExperienceBar_Toggle')
end
end
function DB:ExperienceBar()
local Experience = DB:CreateBar('ElvUI_ExperienceBar', 'Experience', DB.ExperienceBar_Update, DB.ExperienceBar_OnEnter, DB.ExperienceBar_OnClick, {'BOTTOM', E.UIParent, 'BOTTOM', 0, 43})
Experience.barTexture:SetDrawLayer('ARTWORK', 4)
DB:CreateBarBubbles(Experience)
Experience.ShouldHide = function()
return DB.db.experience.hideAtMaxLevel and not DB:ExperienceBar_ShouldBeVisible()
end
local Rested = CreateFrame('StatusBar', 'ElvUI_ExperienceBar_Rested', Experience.holder)
Rested:SetStatusBarTexture(DB.db.customTexture and LSM:Fetch('statusbar', DB.db.statusbar) or E.media.normTex)
Rested:EnableMouse(false)
Rested:SetInside()
Rested:Hide()
Rested.barTexture = Rested:GetStatusBarTexture()
Rested.barTexture:SetDrawLayer('ARTWORK', 2)
Experience.Rested = Rested
local Quest = CreateFrame('StatusBar', 'ElvUI_ExperienceBar_Quest', Experience.holder)
Quest:SetStatusBarTexture(DB.db.customTexture and LSM:Fetch('statusbar', DB.db.statusbar) or E.media.normTex)
Quest:EnableMouse(false)
Quest:SetInside()
Quest:Hide()
Quest.barTexture = Quest:GetStatusBarTexture()
Quest.barTexture:SetDrawLayer('ARTWORK', 3)
Experience.Quest = Quest
E:CreateMover(Experience.holder, 'ExperienceBarMover', L["Experience Bar"], nil, nil, nil, nil, nil, 'databars,experience')
DB:ExperienceBar_Toggle()
end

111
Modules/DataBars/Honor.lua Normal file
View File

@@ -0,0 +1,111 @@
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
local DB = E:GetModule('DataBars')
local _G = _G
local format = format
local UnitHonor = UnitHonor
local UnitHonorLevel = UnitHonorLevel
local IsPlayerAtEffectiveMaxLevel = IsPlayerAtEffectiveMaxLevel
local UnitHonorMax = UnitHonorMax
local TogglePVPUI = TogglePVPUI
local HONOR = HONOR
local CurrentHonor, MaxHonor, CurrentLevel, PercentHonor, RemainingHonor
function DB:HonorBar_Update(event, unit)
if event == 'PLAYER_FLAGS_CHANGED' and unit ~= 'player' then return end
local bar = DB.StatusBars.Honor
DB:SetVisibility(bar)
if not DB.db.honor.enable then return end
CurrentHonor, MaxHonor, CurrentLevel = UnitHonor('player'), UnitHonorMax('player'), UnitHonorLevel('player')
--Guard against division by zero, which appears to be an issue when zoning in/out of dungeons
if MaxHonor == 0 then MaxHonor = 1 end
PercentHonor, RemainingHonor = (CurrentHonor / MaxHonor) * 100, MaxHonor - CurrentHonor
local displayString, textFormat = '', DB.db.honor.textFormat
local color = DB.db.colors.honor
bar:SetMinMaxValues(0, MaxHonor)
bar:SetValue(CurrentHonor)
bar:SetStatusBarColor(color.r, color.g, color.b, color.a)
if textFormat == 'PERCENT' then
displayString = format('%d%% - [%s]', PercentHonor, CurrentLevel)
elseif textFormat == 'CURMAX' then
displayString = format('%s - %s - [%s]', E:ShortValue(CurrentHonor), E:ShortValue(MaxHonor), CurrentLevel)
elseif textFormat == 'CURPERC' then
displayString = format('%s - %d%% - [%s]', E:ShortValue(CurrentHonor), PercentHonor, CurrentLevel)
elseif textFormat == 'CUR' then
displayString = format('%s - [%s]', E:ShortValue(CurrentHonor), CurrentLevel)
elseif textFormat == 'REM' then
displayString = format('%s - [%s]', E:ShortValue(RemainingHonor), CurrentLevel)
elseif textFormat == 'CURREM' then
displayString = format('%s - %s - [%s]', E:ShortValue(CurrentHonor), E:ShortValue(RemainingHonor), CurrentLevel)
elseif textFormat == 'CURPERCREM' then
displayString = format('%s - %d%% (%s) - [%s]', E:ShortValue(CurrentHonor), CurrentHonor, E:ShortValue(RemainingHonor), CurrentLevel)
end
bar.text:SetText(displayString)
end
function DB:HonorBar_OnEnter()
if self.db.mouseover then
E:UIFrameFadeIn(self, .4, self:GetAlpha(), 1)
end
if _G.GameTooltip:IsForbidden() then return end
_G.GameTooltip:ClearLines()
_G.GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
_G.GameTooltip:AddLine(HONOR)
_G.GameTooltip:AddDoubleLine(L["Current Level:"], CurrentLevel, 1, 1, 1)
_G.GameTooltip:AddLine(' ')
_G.GameTooltip:AddDoubleLine(L["Honor XP:"], format(' %d / %d (%d%%)', CurrentHonor, MaxHonor, PercentHonor), 1, 1, 1)
_G.GameTooltip:AddDoubleLine(L["Honor Remaining:"], format(' %d (%d%% - %d '..L["Bars"]..')', RemainingHonor, (RemainingHonor) / MaxHonor * 100, 20 * (RemainingHonor) / MaxHonor), 1, 1, 1)
_G.GameTooltip:Show()
end
function DB:HonorBar_OnClick()
TogglePVPUI()
end
function DB:HonorBar_Toggle()
local bar = DB.StatusBars.Honor
bar.db = DB.db.honor
if bar.db.enable then
E:EnableMover(bar.holder.mover:GetName())
DB:RegisterEvent('HONOR_XP_UPDATE', 'HonorBar_Update')
DB:RegisterEvent('PLAYER_FLAGS_CHANGED', 'HonorBar_Update')
DB:HonorBar_Update()
else
E:DisableMover(bar.holder.mover:GetName())
DB:UnregisterEvent('HONOR_XP_UPDATE')
DB:UnregisterEvent('PLAYER_FLAGS_CHANGED')
end
end
function DB:HonorBar()
local Honor = DB:CreateBar('ElvUI_HonorBar', 'Honor', DB.HonorBar_Update, DB.HonorBar_OnEnter, DB.HonorBar_OnClick, {'TOPRIGHT', E.UIParent, 'TOPRIGHT', -3, -255})
DB:CreateBarBubbles(Honor)
Honor.ShouldHide = function()
return DB.db.honor.hideBelowMaxLevel and not IsPlayerAtEffectiveMaxLevel()
end
E:CreateMover(Honor.holder, 'HonorBarMover', L["Honor Bar"], nil, nil, nil, nil, nil, 'databars,honor')
DB:HonorBar_Toggle()
end

View File

@@ -0,0 +1,8 @@
<Ui xmlns='http://www.blizzard.com/wow/ui/'>
<Script file='DataBars.lua'/>
<Script file='Experience.lua'/>
<Script file='Reputation.lua'/>
<Script file='Honor.lua'/>
<Script file='Threat.lua'/>
<Script file='Azerite.lua'/>
</Ui>

View File

@@ -0,0 +1,154 @@
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
local DB = E:GetModule('DataBars')
local _G = _G
local format = format
local IsPlayerAtEffectiveMaxLevel = IsPlayerAtEffectiveMaxLevel
local C_Reputation_GetFactionParagonInfo = C_Reputation.GetFactionParagonInfo
local C_Reputation_IsFactionParagon = C_Reputation.IsFactionParagon
local GetFriendshipReputation = GetFriendshipReputation
local GetWatchedFactionInfo = GetWatchedFactionInfo
local ToggleCharacter = ToggleCharacter
local REPUTATION = REPUTATION
local STANDING = STANDING
function DB:ReputationBar_Update()
local bar = DB.StatusBars.Reputation
DB:SetVisibility(bar)
if not bar.db.enable or bar:ShouldHide() then return end
local name, reaction, Min, Max, value, factionID = GetWatchedFactionInfo()
local displayString, textFormat = '', DB.db.reputation.textFormat
local isCapped, isFriend, friendText, standingLabel
local friendshipID = GetFriendshipReputation(factionID)
local color = DB.db.colors.useCustomFactionColors and DB.db.colors.factionColors[reaction] or _G.FACTION_BAR_COLORS[reaction]
if friendshipID then
local _, friendRep, _, _, _, _, friendTextLevel, friendThreshold, nextFriendThreshold = GetFriendshipReputation(factionID)
isFriend, reaction, friendText = true, 5, friendTextLevel
if nextFriendThreshold then
Min, Max, value = friendThreshold, nextFriendThreshold, friendRep;
else
Min, Max, value = 0, 1, 1
isCapped = true
end
elseif C_Reputation_IsFactionParagon(factionID) then
local currentValue, threshold, _, hasRewardPending = C_Reputation_GetFactionParagonInfo(factionID)
if currentValue and threshold then
Min, Max = 0, threshold
value = currentValue % threshold
if hasRewardPending then
value = value + threshold
end
end
elseif reaction == _G.MAX_REPUTATION_REACTION then
Min, Max, value = 0, 1, 1
isCapped = true
end
bar:SetMinMaxValues(Min, Max)
bar:SetValue(value)
bar:SetStatusBarColor(color.r, color.g, color.b)
standingLabel = _G['FACTION_STANDING_LABEL'..reaction]
--Prevent a division by zero
local maxMinDiff = Max - Min
if maxMinDiff == 0 then
maxMinDiff = 1
end
if isCapped and textFormat ~= 'NONE' then
-- show only name and standing on exalted
displayString = format('%s: [%s]', name, isFriend and friendText or standingLabel)
else
if textFormat == 'PERCENT' then
displayString = format('%s: %d%% [%s]', name, ((value - Min) / (maxMinDiff) * 100), isFriend and friendText or standingLabel)
elseif textFormat == 'CURMAX' then
displayString = format('%s: %s - %s [%s]', name, E:ShortValue(value - Min), E:ShortValue(Max - Min), isFriend and friendText or standingLabel)
elseif textFormat == 'CURPERC' then
displayString = format('%s: %s - %d%% [%s]', name, E:ShortValue(value - Min), ((value - Min) / (maxMinDiff) * 100), isFriend and friendText or standingLabel)
elseif textFormat == 'CUR' then
displayString = format('%s: %s [%s]', name, E:ShortValue(value - Min), isFriend and friendText or standingLabel)
elseif textFormat == 'REM' then
displayString = format('%s: %s [%s]', name, E:ShortValue((Max - Min) - (value-Min)), isFriend and friendText or standingLabel)
elseif textFormat == 'CURREM' then
displayString = format('%s: %s - %s [%s]', name, E:ShortValue(value - Min), E:ShortValue((Max - Min) - (value-Min)), isFriend and friendText or standingLabel)
elseif textFormat == 'CURPERCREM' then
displayString = format('%s: %s - %d%% (%s) [%s]', name, E:ShortValue(value - Min), ((value - Min) / (maxMinDiff) * 100), E:ShortValue((Max - Min) - (value-Min)), isFriend and friendText or standingLabel)
end
end
bar.text:SetText(displayString)
end
function DB:ReputationBar_OnEnter()
if self.db.mouseover then
E:UIFrameFadeIn(self, 0.4, self:GetAlpha(), 1)
end
local name, reaction, min, max, value, factionID = GetWatchedFactionInfo()
if factionID and C_Reputation_IsFactionParagon(factionID) then
local currentValue, threshold, _, hasRewardPending = C_Reputation_GetFactionParagonInfo(factionID)
if currentValue and threshold then
min, max = 0, threshold
value = currentValue % threshold
if hasRewardPending then
value = value + threshold
end
end
end
if name and not _G.GameTooltip:IsForbidden() then
_G.GameTooltip:ClearLines()
_G.GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
_G.GameTooltip:AddLine(name)
_G.GameTooltip:AddLine(' ')
local friendID, friendTextLevel, _
if factionID then friendID, _, _, _, _, _, friendTextLevel = GetFriendshipReputation(factionID) end
_G.GameTooltip:AddDoubleLine(STANDING..':', (friendID and friendTextLevel) or _G['FACTION_STANDING_LABEL'..reaction], 1, 1, 1)
if reaction ~= _G.MAX_REPUTATION_REACTION or C_Reputation_IsFactionParagon(factionID) then
_G.GameTooltip:AddDoubleLine(REPUTATION..':', format('%d / %d (%d%%)', value - min, max - min, (value - min) / ((max - min == 0) and max or (max - min)) * 100), 1, 1, 1)
end
_G.GameTooltip:Show()
end
end
function DB:ReputationBar_OnClick()
ToggleCharacter('ReputationFrame')
end
function DB:ReputationBar_Toggle()
local bar = DB.StatusBars.Reputation
bar.db = DB.db.reputation
if bar.db.enable then
E:EnableMover(bar.holder.mover:GetName())
DB:RegisterEvent('UPDATE_FACTION', 'ReputationBar_Update')
DB:RegisterEvent('COMBAT_TEXT_UPDATE', 'ReputationBar_Update')
DB:ReputationBar_Update()
else
E:DisableMover(bar.holder.mover:GetName())
DB:UnregisterEvent('UPDATE_FACTION')
DB:UnregisterEvent('COMBAT_TEXT_UPDATE')
end
end
function DB:ReputationBar()
local Reputation = DB:CreateBar('ElvUI_ReputationBar', 'Reputation', DB.ReputationBar_Update, DB.ReputationBar_OnEnter, DB.ReputationBar_OnClick, {'TOPRIGHT', E.UIParent, 'TOPRIGHT', -3, -264})
DB:CreateBarBubbles(Reputation)
Reputation.ShouldHide = function()
return (DB.db.reputation.hideBelowMaxLevel and not IsPlayerAtEffectiveMaxLevel()) or not GetWatchedFactionInfo()
end
E:CreateMover(Reputation.holder, 'ReputationBarMover', L["Reputation Bar"], nil, nil, nil, nil, nil, 'databars,reputation')
DB:ReputationBar_Toggle()
end

140
Modules/DataBars/Threat.lua Normal file
View File

@@ -0,0 +1,140 @@
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
local DB = E:GetModule('DataBars')
local pairs, select, wipe = pairs, select, wipe
local GetThreatStatusColor = GetThreatStatusColor
local IsInGroup, IsInRaid = IsInGroup, IsInRaid
local UnitClass = UnitClass
local UnitAffectingCombat = UnitAffectingCombat
local UnitDetailedThreatSituation = UnitDetailedThreatSituation
local UnitExists = UnitExists
local UnitIsPlayer = UnitIsPlayer
local UnitIsUnit = UnitIsUnit
local UnitName = UnitName
local UnitReaction = UnitReaction
local UNKNOWN = UNKNOWN
-- GLOBALS: ElvUF
function DB:ThreatBar_GetLargestThreatOnList(percent)
local largestValue, largestUnit = 0, nil
for unit, threatPercent in pairs(DB.StatusBars.Threat.list) do
if threatPercent > largestValue then
largestValue = threatPercent
largestUnit = unit
end
end
return (percent - largestValue), largestUnit
end
function DB:ThreatBar_GetColor(unit)
local unitReaction = UnitReaction(unit, 'player')
local _, unitClass = UnitClass(unit)
if (UnitIsPlayer(unit)) then
local class = E:ClassColor(unitClass)
if not class then return 194, 194, 194 end
return class.r*255, class.g*255, class.b*255
elseif (unitReaction) then
local reaction = ElvUF.colors.reaction[unitReaction]
return reaction[1]*255, reaction[2]*255, reaction[3]*255
else
return 194, 194, 194
end
end
function DB:ThreatBar_Update()
local bar = DB.StatusBars.Threat
local isInGroup, isInRaid, petExists = IsInGroup(), IsInRaid(), UnitExists('pet')
if UnitAffectingCombat('player') and (isInGroup or petExists) then
local _, status, percent = UnitDetailedThreatSituation('player', 'target')
local name = UnitName('target') or UNKNOWN
bar.showBar = true
if percent == 100 then
if petExists then
bar.list.pet = select(3, UnitDetailedThreatSituation('pet', 'target'))
end
if isInRaid then
for i = 1, 40 do
if UnitExists('raid'..i) and not UnitIsUnit('raid'..i, 'player') then
bar.list['raid'..i] = select(3, UnitDetailedThreatSituation('raid'..i, 'target'))
end
end
elseif isInGroup then
for i = 1, 4 do
if UnitExists('party'..i) then
bar.list['party'..i] = select(3, UnitDetailedThreatSituation('party'..i, 'target'))
end
end
end
local leadPercent, largestUnit = DB:ThreatBar_GetLargestThreatOnList(percent)
if leadPercent > 0 and largestUnit ~= nil then
local r, g, b = DB:ThreatBar_GetColor(largestUnit)
bar.text:SetFormattedText(L["ABOVE_THREAT_FORMAT"], name, percent, leadPercent, r, g, b, UnitName(largestUnit) or UNKNOWN)
if E.myrole == 'TANK' then
bar:SetStatusBarColor(0, 0.839, 0)
bar:SetValue(leadPercent)
else
bar:SetStatusBarColor(GetThreatStatusColor(status))
bar:SetValue(percent)
end
else
bar:SetStatusBarColor(GetThreatStatusColor(status))
bar.text:SetFormattedText('%s: %.0f%%', name, percent)
bar:SetValue(percent)
end
elseif percent then
bar:SetStatusBarColor(GetThreatStatusColor(status))
bar.text:SetFormattedText('%s: %.0f%%', name, percent)
bar:SetValue(percent)
else
bar.showBar = false
end
else
bar.showBar = false
end
DB:SetVisibility(bar) -- lower visibility because of using showBar variable
wipe(bar.list)
end
function DB:ThreatBar_Toggle()
local bar = DB.StatusBars.Threat
bar.db = DB.db.threat
if bar.db.enable then
E:EnableMover(bar.holder.mover:GetName())
DB:RegisterEvent('PLAYER_TARGET_CHANGED', 'ThreatBar_Update')
DB:RegisterEvent('UNIT_THREAT_LIST_UPDATE', 'ThreatBar_Update')
DB:RegisterEvent('GROUP_ROSTER_UPDATE', 'ThreatBar_Update')
DB:RegisterEvent('UNIT_FLAGS', 'ThreatBar_Update')
DB:RegisterEvent('UNIT_PET', 'ThreatBar_Update')
DB:ThreatBar_Update()
else
E:DisableMover(bar.holder.mover:GetName())
DB:UnregisterEvent('PLAYER_TARGET_CHANGED')
DB:UnregisterEvent('UNIT_THREAT_LIST_UPDATE')
DB:UnregisterEvent('GROUP_ROSTER_UPDATE')
DB:UnregisterEvent('UNIT_FLAGS')
DB:UnregisterEvent('UNIT_PET')
end
end
function DB:ThreatBar()
local Threat = DB:CreateBar('ElvUI_ThreatBar', 'Threat', DB.ThreatBar_Update, nil, nil, {'TOPRIGHT', E.UIParent, 'TOPRIGHT', -3, -245})
Threat:SetMinMaxValues(0, 100)
Threat.list = {}
E:CreateMover(Threat.holder, 'ThreatBarMover', L["Threat Bar"], nil, nil, nil, nil, nil, 'databars,threat')
DB:ThreatBar_Toggle()
end