This commit is contained in:
Andrew6810
2022-10-21 07:09:01 -07:00
parent cbdabfbcca
commit 60ef8a38af
614 changed files with 138573 additions and 2 deletions
+63
View File
@@ -0,0 +1,63 @@
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
local mod = E:GetModule("DataBars")
--Lua functions
--WoW API / Variables
local GetExpansionLevel = GetExpansionLevel
local MAX_PLAYER_LEVEL_TABLE = MAX_PLAYER_LEVEL_TABLE
function mod:OnLeave()
if (self == ElvUI_ExperienceBar and mod.db.experience.mouseover) or (self == ElvUI_ReputationBar and mod.db.reputation.mouseover) then
E:UIFrameFadeOut(self, 1, self:GetAlpha(), 0)
end
GameTooltip:Hide()
end
function mod:CreateBar(name, onEnter, onClick, ...)
local bar = CreateFrame("Button", name, E.UIParent)
bar:Point(...)
bar:SetScript("OnEnter", onEnter)
bar:SetScript("OnLeave", mod.OnLeave)
bar:SetScript("OnClick", onClick)
bar:SetFrameStrata("LOW")
bar:SetTemplate("Transparent")
bar:Hide()
bar.statusBar = CreateFrame("StatusBar", nil, bar)
bar.statusBar:SetInside()
bar.statusBar:SetStatusBarTexture(E.media.normTex)
E:RegisterStatusBar(bar.statusBar)
bar.text = bar.statusBar:CreateFontString(nil, "OVERLAY")
bar.text:FontTemplate()
bar.text:Point("CENTER")
return bar
end
function mod:UpdateDataBarDimensions()
self:UpdateExperienceDimensions()
self:UpdateReputationDimensions()
end
function mod:PLAYER_LEVEL_UP(level)
local maxLevel = MAX_PLAYER_LEVEL_TABLE[GetExpansionLevel()]
if (level ~= maxLevel or not self.db.experience.hideAtMaxLevel) and self.db.experience.enable then
self:UpdateExperience("PLAYER_LEVEL_UP", level)
else
self.expBar:Hide()
end
end
function mod:Initialize()
self.db = E.db.databars
self:LoadExperienceBar()
self:LoadReputationBar()
self:RegisterEvent("PLAYER_LEVEL_UP")
end
local function InitializeCallback()
mod:Initialize()
end
E:RegisterModule(mod:GetName(), InitializeCallback)
+182
View File
@@ -0,0 +1,182 @@
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
local mod = E:GetModule("DataBars")
local LSM = LibStub("LibSharedMedia-3.0")
--Lua functions
local min = math.min
local format = string.format
--WoW API / Variables
local GetExpansionLevel = GetExpansionLevel
local GetPetExperience = GetPetExperience
local GetXPExhaustion = GetXPExhaustion
local InCombatLockdown = InCombatLockdown
local IsXPUserDisabled = IsXPUserDisabled
local UnitLevel = UnitLevel
local UnitXP = UnitXP
local UnitXPMax = UnitXPMax
local MAX_PLAYER_LEVEL_TABLE = MAX_PLAYER_LEVEL_TABLE
function mod:GetXP(unit)
if unit == "pet" then
return GetPetExperience()
else
return UnitXP(unit), UnitXPMax(unit)
end
end
function mod:UpdateExperience(event)
if not mod.db.experience.enable then return end
local bar = self.expBar
local hideXP = ((UnitLevel("player") == MAX_PLAYER_LEVEL_TABLE[GetExpansionLevel()] and self.db.experience.hideAtMaxLevel) or IsXPUserDisabled())
if hideXP or (event == "PLAYER_REGEN_DISABLED" and self.db.experience.hideInCombat) then
E:DisableMover(self.expBar.mover:GetName())
bar:Hide()
elseif not hideXP and (not self.db.experience.hideInCombat or not InCombatLockdown()) then
E:EnableMover(self.expBar.mover:GetName())
bar:Show()
if self.db.experience.hideInVehicle then
E:RegisterObjectForVehicleLock(bar, E.UIParent)
else
E:UnregisterObjectForVehicleLock(bar)
end
local cur, max = self:GetXP("player")
if max <= 0 then max = 1 end
bar.statusBar:SetMinMaxValues(0, max)
bar.statusBar:SetValue(cur - 1 >= 0 and cur - 1 or 0)
bar.statusBar:SetValue(cur)
local rested = GetXPExhaustion()
local text = ""
local textFormat = self.db.experience.textFormat
if rested and rested > 0 then
bar.rested:SetMinMaxValues(0, max)
bar.rested:SetValue(min(cur + rested, max))
if textFormat == "PERCENT" then
text = format("%d%% R:%d%%", cur / max * 100, rested / max * 100)
elseif textFormat == "CURMAX" then
text = format("%s - %s R:%s", E:ShortValue(cur), E:ShortValue(max), E:ShortValue(rested))
elseif textFormat == "CURPERC" then
text = format("%s - %d%% R:%s [%d%%]", E:ShortValue(cur), cur / max * 100, E:ShortValue(rested), rested / max * 100)
elseif textFormat == "CUR" then
text = format("%s R:%s", E:ShortValue(cur), E:ShortValue(rested))
elseif textFormat == "REM" then
text = format("%s R:%s", E:ShortValue(max - cur), E:ShortValue(rested))
elseif textFormat == "CURREM" then
text = format("%s - %s R:%s", E:ShortValue(cur), E:ShortValue(max - cur), E:ShortValue(rested))
elseif textFormat == "CURPERCREM" then
text = format("%s - %d%% (%s) R:%s", E:ShortValue(cur), cur / max * 100, E:ShortValue(max - cur), E:ShortValue(rested))
end
else
bar.rested:SetMinMaxValues(0, 1)
bar.rested:SetValue(0)
if textFormat == "PERCENT" then
text = format("%d%%", cur / max * 100)
elseif textFormat == "CURMAX" then
text = format("%s - %s", E:ShortValue(cur), E:ShortValue(max))
elseif textFormat == "CURPERC" then
text = format("%s - %d%%", E:ShortValue(cur), cur / max * 100)
elseif textFormat == "CUR" then
text = format("%s", E:ShortValue(cur))
elseif textFormat == "REM" then
text = format("%s", E:ShortValue(max - cur))
elseif textFormat == "CURREM" then
text = format("%s - %s", E:ShortValue(cur), E:ShortValue(max - cur))
elseif textFormat == "CURPERCREM" then
text = format("%s - %d%% (%s)", E:ShortValue(cur), cur / max * 100, E:ShortValue(max - cur))
end
end
bar.text:SetText(text)
end
end
function mod:ExperienceBar_OnEnter()
if mod.db.experience.mouseover then
E:UIFrameFadeIn(self, 0.4, self:GetAlpha(), 1)
end
GameTooltip:ClearLines()
GameTooltip:SetOwner(self, "ANCHOR_CURSOR", 0, -4)
local cur, max = mod:GetXP("player")
local rested = GetXPExhaustion()
GameTooltip:AddLine(L["Experience"])
GameTooltip:AddLine(" ")
GameTooltip:AddDoubleLine(L["XP:"], format(" %d / %d (%d%%)", cur, max, cur/max * 100), 1, 1, 1)
GameTooltip:AddDoubleLine(L["Remaining:"], format(" %d (%d%% - %d "..L["Bars"]..")", max - cur, (max - cur) / max * 100, 20 * (max - cur) / max), 1, 1, 1)
if rested then
GameTooltip:AddDoubleLine(L["Rested:"], format("+%d (%d%%)", rested, rested / max * 100), 1, 1, 1)
end
GameTooltip:Show()
end
function mod:ExperienceBar_OnClick()
end
function mod:UpdateExperienceDimensions()
self.expBar:Width(self.db.experience.width)
self.expBar:Height(self.db.experience.height)
self.expBar.text:FontTemplate(LSM:Fetch("font", self.db.experience.font), self.db.experience.textSize, self.db.experience.fontOutline)
self.expBar.rested:SetOrientation(self.db.experience.orientation)
self.expBar.statusBar:SetOrientation(self.db.experience.orientation)
if self.db.experience.mouseover then
self.expBar:SetAlpha(0)
else
self.expBar:SetAlpha(1)
end
end
function mod:EnableDisable_ExperienceBar()
local maxLevel = MAX_PLAYER_LEVEL_TABLE[GetExpansionLevel()]
if (UnitLevel("player") ~= maxLevel or not self.db.experience.hideAtMaxLevel) and self.db.experience.enable then
self:RegisterEvent("PLAYER_XP_UPDATE", "UpdateExperience")
self:RegisterEvent("DISABLE_XP_GAIN", "UpdateExperience")
self:RegisterEvent("ENABLE_XP_GAIN", "UpdateExperience")
self:RegisterEvent("UPDATE_EXHAUSTION", "UpdateExperience")
self:UnregisterEvent("UPDATE_EXPANSION_LEVEL")
self:UpdateExperience()
E:EnableMover(self.expBar.mover:GetName())
else
self:UnregisterEvent("PLAYER_XP_UPDATE")
self:UnregisterEvent("DISABLE_XP_GAIN")
self:UnregisterEvent("ENABLE_XP_GAIN")
self:UnregisterEvent("UPDATE_EXHAUSTION")
self:RegisterEvent("UPDATE_EXPANSION_LEVEL", "EnableDisable_ExperienceBar")
self.expBar:Hide()
E:DisableMover(self.expBar.mover:GetName())
end
end
function mod:LoadExperienceBar()
self.expBar = self:CreateBar("ElvUI_ExperienceBar", self.ExperienceBar_OnEnter, self.ExperienceBar_OnClick, "LEFT", LeftChatPanel, "RIGHT", -E.Border + E.Spacing*3, 0)
self.expBar.statusBar:SetStatusBarColor(0, 0.4, 1, .8)
self.expBar.rested = CreateFrame("StatusBar", nil, self.expBar)
self.expBar.rested:SetInside()
self.expBar.rested:SetStatusBarTexture(E.media.normTex)
E:RegisterStatusBar(self.expBar.rested)
self.expBar.rested:SetStatusBarColor(1, 0, 1, 0.2)
self.expBar.eventFrame = CreateFrame("Frame")
self.expBar.eventFrame:Hide()
self.expBar.eventFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
self.expBar.eventFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
self.expBar.eventFrame:SetScript("OnEvent", function(_, event) mod:UpdateExperience(event) end)
self:UpdateExperienceDimensions()
E:CreateMover(self.expBar, "ExperienceBarMover", L["Experience Bar"], nil, nil, nil, nil, nil, "databars,experience")
self:EnableDisable_ExperienceBar()
end
+5
View File
@@ -0,0 +1,5 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/">
<Script file="DataBars.lua"/>
<Script file="Experience.lua"/>
<Script file="Reputation.lua"/>
</Ui>
+145
View File
@@ -0,0 +1,145 @@
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
local mod = E:GetModule("DataBars")
local LSM = LibStub("LibSharedMedia-3.0")
--Lua functions
local max, min = math.max, math.min
local format = string.format
--WoW API
local GetPetExperience = GetPetExperience
local HasPetUI = HasPetUI
local UnitLevel = UnitLevel
function mod:PetExperienceBar_Update(event)
if E.myclass ~= "HUNTER" or not mod.db.petExperience.enable then return end
local bar = self.petExpBar
local _, hunterPet = HasPetUI()
local hideBar = not hunterPet or (UnitLevel("pet") == self.maxExpansionLevel and self.db.petExperience.hideAtMaxLevel)
if hideBar or (event == "PLAYER_REGEN_DISABLED" and self.db.petExperience.hideInCombat) then
E:DisableMover(self.petExpBar.mover:GetName())
bar:Hide()
elseif not hideBar and (not self.db.petExperience.hideInCombat or not self.inCombatLockdown) then
E:EnableMover(self.petExpBar.mover:GetName())
bar:Show()
local textFormat = self.db.petExperience.textFormat
local curExp, maxExp = GetPetExperience()
maxExp = max(1, maxExp)
bar.statusBar:SetMinMaxValues(min(0, curExp), maxExp)
-- bar.statusBar:SetValue(curExp - 1 >= 0 and curExp - 1 or 0)
bar.statusBar:SetValue(curExp)
if textFormat == "PERCENT" then
bar.text:SetFormattedText("%d%%", curExp / maxExp * 100)
elseif textFormat == "CURMAX" then
bar.text:SetFormattedText("%s - %s", E:ShortValue(curExp), E:ShortValue(maxExp))
elseif textFormat == "CURPERC" then
bar.text:SetFormattedText("%s - %d%%", E:ShortValue(curExp), curExp / maxExp * 100)
elseif textFormat == "CUR" then
bar.text:SetFormattedText("%s", E:ShortValue(curExp))
elseif textFormat == "REM" then
bar.text:SetFormattedText("%s", E:ShortValue(maxExp - curExp))
elseif textFormat == "CURREM" then
bar.text:SetFormattedText("%s - %s", E:ShortValue(curExp), E:ShortValue(maxExp - curExp))
elseif textFormat == "CURPERCREM" then
bar.text:SetFormattedText("%s - %d%% (%s)", E:ShortValue(curExp), curExp / maxExp * 100, E:ShortValue(maxExp - curExp))
end
end
end
function mod:PetExperienceBar_OnEnter()
if mod.db.petExperience.mouseover then
E:UIFrameFadeIn(self, 0.4, self:GetAlpha(), 1)
end
local curExp, maxExp = GetPetExperience()
maxExp = max(1, maxExp)
GameTooltip:ClearLines()
GameTooltip:SetOwner(self, "ANCHOR_CURSOR", 0, -4)
GameTooltip:AddLine(L["Pet Experience"])
GameTooltip:AddLine(" ")
GameTooltip:AddDoubleLine(L["XP:"], format("%d / %d (%d%%)", curExp, maxExp, curExp / maxExp * 100), 1, 1, 1)
GameTooltip:AddDoubleLine(L["Remaining:"], format("%d (%d%% - %d %s)", maxExp - curExp, (maxExp - curExp) / maxExp * 100, 20 * (maxExp - curExp) / maxExp, L["Bars"]), 1, 1, 1)
GameTooltip:Show()
end
function mod:PetExperienceBar_OnClick()
end
function mod:PetExperienceBar_UpdateDimensions()
if E.myclass ~= "HUNTER" then return end
self.petExpBar:Size(self.db.petExperience.width, self.db.petExperience.height)
self.petExpBar:SetAlpha(self.db.petExperience.mouseover and 0 or 1)
self.petExpBar.text:FontTemplate(LSM:Fetch("font", self.db.petExperience.font), self.db.petExperience.textSize, self.db.petExperience.fontOutline)
self.petExpBar.statusBar:SetOrientation(self.db.petExperience.orientation)
self.petExpBar.statusBar:SetRotatesTexture(self.db.petExperience.orientation ~= "HORIZONTAL")
if self.petExpBar.bubbles then
self:UpdateBarBubbles(self.petExpBar, self.db.petExperience)
elseif self.db.petExperience.showBubbles then
local bubbles = self:CreateBarBubbles(self.petExpBar)
bubbles:SetFrameLevel(5)
self:UpdateBarBubbles(self.petExpBar, self.db.petExperience)
end
end
function mod:PetExperienceBar_Toggle()
if E.myclass ~= "HUNTER" then return end
if self.db.petExperience.enable then
self.petExpBar.eventFrame:RegisterEvent("UNIT_PET")
self.petExpBar.eventFrame:RegisterEvent("UNIT_PET_EXPERIENCE")
self.petExpBar.eventFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
self.petExpBar.eventFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
self:PetExperienceBar_Update()
E:EnableMover(self.petExpBar.mover:GetName())
else
self.petExpBar.eventFrame:UnregisterEvent("UNIT_PET")
self.petExpBar.eventFrame:UnregisterEvent("UNIT_PET_EXPERIENCE")
self.petExpBar.eventFrame:UnregisterEvent("PLAYER_REGEN_DISABLED")
self.petExpBar.eventFrame:UnregisterEvent("PLAYER_REGEN_ENABLED")
self.petExpBar:Hide()
E:DisableMover(self.petExpBar.mover:GetName())
end
end
function mod:PetExperienceBar_Load()
if E.myclass ~= "HUNTER" then return end
self.petExpBar = self:CreateBar("ElvUI_PetExperienceBar", self.PetExperienceBar_OnEnter, self.PetExperienceBar_OnClick, "LEFT", LeftChatPanel, "RIGHT", -E.Border + E.Spacing*3, 0)
self.petExpBar.statusBar:SetStatusBarColor(1, 1, 0.41, 0.8)
self.petExpBar.eventFrame = CreateFrame("Frame")
self.petExpBar.eventFrame:Hide()
self.petExpBar.eventFrame:SetScript("OnEvent", function(_, event, arg1)
if event == "UNIT_PET" then
if arg1 == "player" then
self:PetExperienceBar_Toggle()
end
elseif event == "PLAYER_REGEN_DISABLED" then
self.inCombatLockdown = true
elseif event == "PLAYER_REGEN_ENABLED" then
self.inCombatLockdown = false
else
self:PetExperienceBar_Update(event)
end
end)
self:PetExperienceBar_UpdateDimensions()
E:CreateMover(self.petExpBar, "PetExperienceBarMover", L["Pet Experience Bar"], nil, nil, nil, nil, nil, "databars,petExperience")
self:PetExperienceBar_Toggle()
end
+145
View File
@@ -0,0 +1,145 @@
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
local mod = E:GetModule("DataBars")
local LSM = LibStub("LibSharedMedia-3.0")
--Lua functions
local _G = _G
local format = string.format
--WoW API / Variables
local GetFactionInfo = GetFactionInfo
local GetNumFactions = GetNumFactions
local GetWatchedFactionInfo = GetWatchedFactionInfo
local InCombatLockdown = InCombatLockdown
local FACTION_BAR_COLORS = FACTION_BAR_COLORS
local REPUTATION = REPUTATION
local STANDING = STANDING
local UNKNOWN = UNKNOWN
function mod:UpdateReputation(event)
if not mod.db.reputation.enable then return end
local bar = self.repBar
local ID, standingLabel
local name, reaction, min, max, value = GetWatchedFactionInfo()
local numFactions = GetNumFactions()
if not name or (event == "PLAYER_REGEN_DISABLED" and self.db.reputation.hideInCombat) then
bar:Hide()
elseif name and (not self.db.reputation.hideInCombat or not InCombatLockdown()) then
bar:Show()
if self.db.reputation.hideInVehicle then
E:RegisterObjectForVehicleLock(bar, E.UIParent)
else
E:UnregisterObjectForVehicleLock(bar)
end
local text = ""
local textFormat = self.db.reputation.textFormat
local color = FACTION_BAR_COLORS[reaction] or FACTION_BAR_COLORS[1]
bar.statusBar:SetStatusBarColor(color.r, color.g, color.b)
bar.statusBar:SetMinMaxValues(min, max)
bar.statusBar:SetValue(value)
for i = 1, numFactions do
local factionName, _, standingID = GetFactionInfo(i)
if factionName == name then
ID = standingID
end
end
if ID then
standingLabel = _G["FACTION_STANDING_LABEL"..ID]
else
standingLabel = UNKNOWN
end
--Prevent a division by zero
local maxMinDiff = max - min
if maxMinDiff == 0 then
maxMinDiff = 1
end
if textFormat == "PERCENT" then
text = format("%s: %d%% [%s]", name, ((value - min) / maxMinDiff * 100), standingLabel)
elseif textFormat == "CURMAX" then
text = format("%s: %s - %s [%s]", name, E:ShortValue(value - min), E:ShortValue(max - min), standingLabel)
elseif textFormat == "CURPERC" then
text = format("%s: %s - %d%% [%s]", name, E:ShortValue(value - min), ((value - min) / maxMinDiff * 100), standingLabel)
elseif textFormat == "CUR" then
text = format("%s: %s [%s]", name, E:ShortValue(value - min), standingLabel)
elseif textFormat == "REM" then
text = format("%s: %s [%s]", name, E:ShortValue((max - min) - (value-min)), standingLabel)
elseif textFormat == "CURREM" then
text = format("%s: %s - %s [%s]", name, E:ShortValue(value - min), E:ShortValue((max - min) - (value-min)), standingLabel)
elseif textFormat == "CURPERCREM" then
text = format("%s: %s - %d%% (%s) [%s]", name, E:ShortValue(value - min), ((value - min) / maxMinDiff * 100), E:ShortValue((max - min) - (value-min)), standingLabel)
end
bar.text:SetText(text)
end
end
function mod:ReputationBar_OnEnter()
if mod.db.reputation.mouseover then
E:UIFrameFadeIn(self, 0.4, self:GetAlpha(), 1)
end
GameTooltip:ClearLines()
GameTooltip:SetOwner(self, "ANCHOR_CURSOR", 0, -4)
local name, reaction, min, max, value = GetWatchedFactionInfo()
if name then
GameTooltip:AddLine(name)
GameTooltip:AddLine(" ")
GameTooltip:AddDoubleLine(STANDING..":", _G["FACTION_STANDING_LABEL"..reaction], 1, 1, 1)
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
GameTooltip:Show()
end
function mod:ReputationBar_OnClick()
ToggleCharacter("ReputationFrame")
end
function mod:UpdateReputationDimensions()
self.repBar:Width(self.db.reputation.width)
self.repBar:Height(self.db.reputation.height)
self.repBar.statusBar:SetOrientation(self.db.reputation.orientation)
self.repBar.text:FontTemplate(LSM:Fetch("font", self.db.reputation.font), self.db.reputation.textSize, self.db.reputation.fontOutline)
if self.db.reputation.mouseover then
self.repBar:SetAlpha(0)
else
self.repBar:SetAlpha(1)
end
end
function mod:EnableDisable_ReputationBar()
if self.db.reputation.enable then
self:RegisterEvent("UPDATE_FACTION", "UpdateReputation")
self:UpdateReputation()
E:EnableMover(self.repBar.mover:GetName())
else
self:UnregisterEvent("UPDATE_FACTION")
self.repBar:Hide()
E:DisableMover(self.repBar.mover:GetName())
end
end
function mod:LoadReputationBar()
self.repBar = self:CreateBar("ElvUI_ReputationBar", self.ReputationBar_OnEnter, self.ReputationBar_OnClick, "RIGHT", RightChatPanel, "LEFT", E.Border - E.Spacing*3, 0)
E:RegisterStatusBar(self.repBar.statusBar)
self.repBar.eventFrame = CreateFrame("Frame")
self.repBar.eventFrame:Hide()
self.repBar.eventFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
self.repBar.eventFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
self.repBar.eventFrame:SetScript("OnEvent", function(_, event) mod:UpdateReputation(event) end)
self:UpdateReputationDimensions()
E:CreateMover(self.repBar, "ReputationBarMover", L["Reputation Bar"], nil, nil, nil, nil, nil, "databars,reputation")
self:EnableDisable_ReputationBar()
end