diff --git a/ElvUI/Modules/DataBars/DataBars.lua b/ElvUI/Modules/DataBars/DataBars.lua index f6d5c0d..f9149ef 100644 --- a/ElvUI/Modules/DataBars/DataBars.lua +++ b/ElvUI/Modules/DataBars/DataBars.lua @@ -1,10 +1,13 @@ local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB local mod = E:GetModule("DataBars") -function mod.OnLeave(self) - if (self == ElvUI_ExperienceBar and mod.db.experience.mouseover) - or (self == ElvUI_ReputationBar and mod.db.reputation.mouseover) - then +--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() @@ -30,51 +33,27 @@ function mod:CreateBar(name, onEnter, onClick, ...) return bar end -function mod:CreateBarBubbles(bar) - local bubbles = CreateFrame("Frame", "$parent_Bubbles", bar) - bubbles:SetAllPoints() - bubbles.textures = {} - - for i = 1, 19 do - bubbles.textures[i] = bubbles:CreateTexture(nil, "OVERLAY") - bubbles.textures[i]:SetTexture(0, 0, 0, 1) - end - - bar.bubbles = bubbles - - return bubbles -end - -function mod:UpdateBarBubbles(bar, db) - if db.showBubbles then - local vertical = db.orientation ~= "HORIZONTAL" - local width = vertical and db.width or 1 - local height = not vertical and db.height or 1 - local offset = (vertical and db.height or db.width) / 20 - - for i, texture in ipairs(bar.bubbles.textures) do - texture:Size(width, height) - texture:Point("TOPLEFT", bar, "TOPLEFT", vertical and 0 or offset * i, vertical and -offset * i or 0) - texture:Show() - end - else - for _, texture in ipairs(bar.bubbles.textures) do - texture:Hide() - end - end -end function mod:UpdateDataBarDimensions() - self:ExperienceBar_UpdateDimensions() - self:ReputationBar_UpdateDimensions() + 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.maxExpansionLevel = MAX_PLAYER_LEVEL_TABLE[GetAccountExpansionLevel()] - self:ExperienceBar_Load() - self:ReputationBar_Load() + + self:LoadExperienceBar() + self:LoadReputationBar() + self:RegisterEvent("PLAYER_LEVEL_UP") end local function InitializeCallback() diff --git a/ElvUI/Modules/DataBars/Experience.lua b/ElvUI/Modules/DataBars/Experience.lua index 211989e..abc93dd 100644 --- a/ElvUI/Modules/DataBars/Experience.lua +++ b/ElvUI/Modules/DataBars/Experience.lua @@ -3,70 +3,38 @@ local mod = E:GetModule("DataBars") local LSM = LibStub("LibSharedMedia-3.0") --Lua functions -local max, min = math.max, math.min +local min = math.min local format = string.format ---WoW API -local GetNumQuestLogEntries = GetNumQuestLogEntries -local GetQuestLogRewardXP = GetQuestLogRewardXP -local GetQuestLogSelection = GetQuestLogSelection -local GetQuestLogTitle = GetQuestLogTitle +--WoW API / Variables +local GetExpansionLevel = GetExpansionLevel +local GetPetExperience = GetPetExperience local GetXPExhaustion = GetXPExhaustion -local GetZoneText = GetZoneText +local InCombatLockdown = InCombatLockdown local IsXPUserDisabled = IsXPUserDisabled -local SelectQuestLogEntry = SelectQuestLogEntry local UnitLevel = UnitLevel local UnitXP = UnitXP local UnitXPMax = UnitXPMax +local MAX_PLAYER_LEVEL_TABLE = MAX_PLAYER_LEVEL_TABLE --- GLOBALS: CreateFrame, GameTooltip, LeftChatPanel, ToggleDropDownMenu, XPRM - -local function getQuestXP(completedOnly, zoneOnly) - local lastQuestLogID = GetQuestLogSelection() - local zoneText = GetZoneText() - local totalExp = 0 - local locationName - - for questIndex = 1, GetNumQuestLogEntries() do - SelectQuestLogEntry(questIndex) - local title, _, _, _, isHeader, _, isComplete, _, questID = GetQuestLogTitle(questIndex) - - if isHeader then - locationName = title - elseif (not completedOnly or isComplete) and (not zoneOnly or locationName == zoneText) then - totalExp = totalExp + GetQuestLogRewardXP(questID) - end - end - - SelectQuestLogEntry(lastQuestLogID) - - return totalExp -end - -function mod:ExperienceBar_QuestXPUpdate(event) - if event == "ZONE_CHANGED_NEW_AREA" and not self.db.experience.questXP.questCurrentZoneOnly then return end - - self.questTotalXP = getQuestXP(self.db.experience.questXP.questCompletedOnly, self.db.experience.questXP.questCurrentZoneOnly) - - if self.questTotalXP > 0 then - self.expBar.questBar:SetMinMaxValues(0, self.expBar.maxExp) - self.expBar.questBar:SetValue(min(self.expBar.curExp + self.questTotalXP, self.expBar.maxExp)) - self.expBar.questBar:Show() +function mod:GetXP(unit) + if unit == "pet" then + return GetPetExperience() else - self.expBar.questBar:Hide() + return UnitXP(unit), UnitXPMax(unit) end end -function mod:ExperienceBar_Update(event) +function mod:UpdateExperience(event) if not mod.db.experience.enable then return end local bar = self.expBar - local hideBar = (self.playerLevel == self.maxExpansionLevel and self.db.experience.hideAtMaxLevel) or self.expDisabled + local hideXP = ((UnitLevel("player") == MAX_PLAYER_LEVEL_TABLE[GetExpansionLevel()] and self.db.experience.hideAtMaxLevel) or IsXPUserDisabled()) - if hideBar or (event == "PLAYER_REGEN_DISABLED" and self.db.experience.hideInCombat) then - E:DisableMover(bar.mover:GetName()) + if hideXP or (event == "PLAYER_REGEN_DISABLED" and self.db.experience.hideInCombat) then + E:DisableMover(self.expBar.mover:GetName()) bar:Hide() - elseif not hideBar and (not self.db.experience.hideInCombat or not self.inCombatLockdown) then - E:EnableMover(bar.mover:GetName()) + 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 @@ -75,258 +43,140 @@ function mod:ExperienceBar_Update(event) E:UnregisterObjectForVehicleLock(bar) end - local textFormat = self.db.experience.textFormat - local curExp = UnitXP("player") - local maxExp = max(1, UnitXPMax("player")) - local rested = GetXPExhaustion() - bar.curExp = curExp - bar.maxExp = maxExp + 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) - bar.statusBar:SetMinMaxValues(min(0, curExp), maxExp) - -- bar.statusBar:SetValue(curExp - 1 >= 0 and curExp - 1 or 0) - bar.statusBar:SetValue(curExp) + local rested = GetXPExhaustion() + local text = "" + local textFormat = self.db.experience.textFormat if rested and rested > 0 then - bar.rested:SetMinMaxValues(0, maxExp) - bar.rested:SetValue(min(curExp + rested, maxExp)) + bar.rested:SetMinMaxValues(0, max) + bar.rested:SetValue(min(cur + rested, max)) if textFormat == "PERCENT" then - bar.text:SetFormattedText("%d%% R:%d%%", curExp / maxExp * 100, rested / maxExp * 100) + text = format("%d%% R:%d%%", cur / max * 100, rested / max * 100) elseif textFormat == "CURMAX" then - bar.text:SetFormattedText("%s - %s R:%s", E:ShortValue(curExp), E:ShortValue(maxExp), E:ShortValue(rested)) + text = format("%s - %s R:%s", E:ShortValue(cur), E:ShortValue(max), E:ShortValue(rested)) elseif textFormat == "CURPERC" then - bar.text:SetFormattedText("%s - %d%% R:%s [%d%%]", E:ShortValue(curExp), curExp / maxExp * 100, E:ShortValue(rested), rested / maxExp * 100) + text = format("%s - %d%% R:%s [%d%%]", E:ShortValue(cur), cur / max * 100, E:ShortValue(rested), rested / max * 100) elseif textFormat == "CUR" then - bar.text:SetFormattedText("%s R:%s", E:ShortValue(curExp), E:ShortValue(rested)) + text = format("%s R:%s", E:ShortValue(cur), E:ShortValue(rested)) elseif textFormat == "REM" then - bar.text:SetFormattedText("%s R:%s", E:ShortValue(maxExp - curExp), E:ShortValue(rested)) + text = format("%s R:%s", E:ShortValue(max - cur), E:ShortValue(rested)) elseif textFormat == "CURREM" then - bar.text:SetFormattedText("%s - %s R:%s", E:ShortValue(curExp), E:ShortValue(maxExp - curExp), E:ShortValue(rested)) + text = format("%s - %s R:%s", E:ShortValue(cur), E:ShortValue(max - cur), E:ShortValue(rested)) elseif textFormat == "CURPERCREM" then - bar.text:SetFormattedText("%s - %d%% (%s) R:%s", E:ShortValue(curExp), curExp / maxExp * 100, E:ShortValue(maxExp - curExp), E:ShortValue(rested)) + 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 - bar.text:SetFormattedText("%d%%", curExp / maxExp * 100) + text = format("%d%%", cur / max * 100) elseif textFormat == "CURMAX" then - bar.text:SetFormattedText("%s - %s", E:ShortValue(curExp), E:ShortValue(maxExp)) + text = format("%s - %s", E:ShortValue(cur), E:ShortValue(max)) elseif textFormat == "CURPERC" then - bar.text:SetFormattedText("%s - %d%%", E:ShortValue(curExp), curExp / maxExp * 100) + text = format("%s - %d%%", E:ShortValue(cur), cur / max * 100) elseif textFormat == "CUR" then - bar.text:SetFormattedText("%s", E:ShortValue(curExp)) + text = format("%s", E:ShortValue(cur)) elseif textFormat == "REM" then - bar.text:SetFormattedText("%s", E:ShortValue(maxExp - curExp)) + text = format("%s", E:ShortValue(max - cur)) elseif textFormat == "CURREM" then - bar.text:SetFormattedText("%s - %s", E:ShortValue(curExp), E:ShortValue(maxExp - curExp)) + text = format("%s - %s", E:ShortValue(cur), E:ShortValue(max - cur)) elseif textFormat == "CURPERCREM" then - bar.text:SetFormattedText("%s - %d%% (%s)", E:ShortValue(curExp), curExp / maxExp * 100, E:ShortValue(maxExp - curExp)) + 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(self) +function mod:ExperienceBar_OnEnter() if mod.db.experience.mouseover then E:UIFrameFadeIn(self, 0.4, self:GetAlpha(), 1) end - - local curExp = UnitXP("player") - local maxExp = max(1, UnitXPMax("player")) - local rested = GetXPExhaustion() - 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%%)", 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: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 / maxExp * 100), 1, 1, 1) - end - - if mod.questXPEnabled and mod.db.experience.questXP.tooltip then - GameTooltip:AddDoubleLine(L["Quest Log XP:"], mod.questTotalXP, 1, 1, 1) + GameTooltip:AddDoubleLine(L["Rested:"], format("+%d (%d%%)", rested, rested / max * 100), 1, 1, 1) end GameTooltip:Show() end -function mod.ExperienceBar_OnClick(self, button) - if XPRM then -- Warmane exp rates - if button == "RightButton" then - ToggleDropDownMenu(1, nil, XPRM, "cursor") - end - end +function mod:ExperienceBar_OnClick() + end -function mod:ExperienceBar_UpdateDimensions() - self.expBar:Size(self.db.experience.width, self.db.experience.height) - self.expBar:SetAlpha(self.db.experience.mouseover and 0 or 1) +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) - self.expBar.statusBar:SetRotatesTexture(self.db.experience.orientation ~= "HORIZONTAL") - self.expBar.rested:SetOrientation(self.db.experience.orientation) - self.expBar.rested:SetRotatesTexture(self.db.experience.orientation ~= "HORIZONTAL") - - self.expBar.questBar:SetOrientation(self.db.experience.orientation) - self.expBar.questBar:SetRotatesTexture(self.db.experience.orientation ~= "HORIZONTAL") - - local color = self.db.experience.questXP.color or {r=0,g=1,b=0,a=0.4} - self.expBar.questBar:SetStatusBarColor(color.r, color.g, color.b, color.a) - - if self.expBar.bubbles then - self:UpdateBarBubbles(self.expBar, self.db.experience) - elseif self.db.experience.showBubbles then - local bubbles = self:CreateBarBubbles(self.expBar) - bubbles:SetFrameLevel(5) - self:UpdateBarBubbles(self.expBar, self.db.experience) + if self.db.experience.mouseover then + self.expBar:SetAlpha(0) + else + self.expBar:SetAlpha(1) end end -function mod:ExperienceBar_Toggle() - if self.db.experience.enable and (self.playerLevel ~= self.maxExpansionLevel or not self.db.experience.hideAtMaxLevel) then - self.playerLevel = UnitLevel("player") - self.expDisabled = IsXPUserDisabled() - - self.expBar.eventFrame:RegisterEvent("DISABLE_XP_GAIN") - self.expBar.eventFrame:RegisterEvent("ENABLE_XP_GAIN") - - if not self.expDisabled then - self.expBar.eventFrame:RegisterEvent("PLAYER_LEVEL_UP") - self.expBar.eventFrame:RegisterEvent("PLAYER_XP_UPDATE") - self.expBar.eventFrame:RegisterEvent("UPDATE_EXHAUSTION") - self.expBar.eventFrame:RegisterEvent("PLAYER_REGEN_DISABLED") - self.expBar.eventFrame:RegisterEvent("PLAYER_REGEN_ENABLED") - end - - self:ExperienceBar_Update() - self:ExperienceBar_QuestXPToggle() +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.expBar.eventFrame:UnregisterEvent("DISABLE_XP_GAIN") - self.expBar.eventFrame:UnregisterEvent("ENABLE_XP_GAIN") - - if not self.expDisabled then - self.expBar.eventFrame:UnregisterEvent("PLAYER_LEVEL_UP") - self.expBar.eventFrame:UnregisterEvent("PLAYER_XP_UPDATE") - self.expBar.eventFrame:UnregisterEvent("UPDATE_EXHAUSTION") - self.expBar.eventFrame:UnregisterEvent("PLAYER_REGEN_DISABLED") - self.expBar.eventFrame:UnregisterEvent("PLAYER_REGEN_ENABLED") - end - - self:ExperienceBar_QuestXPToggle() + 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:ExperienceBar_QuestXPToggle(event) - if not self.questXPEnabled and not self.expDisabled and self.db.experience.questXP.enable then - self.questXPEnabled = true - - self.expBar.eventFrame:RegisterEvent("QUEST_LOG_UPDATE") - self.expBar.eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD") - self.expBar.eventFrame:RegisterEvent("ZONE_CHANGED_NEW_AREA") - - self:ExperienceBar_QuestXPUpdate(event) - elseif self.questXPEnabled and (self.expDisabled or not self.db.experience.questXP.enable) then - self.questXPEnabled = false - self.expBar.eventFrame:UnregisterEvent("QUEST_LOG_UPDATE") - self.expBar.eventFrame:UnregisterEvent("PLAYER_ENTERING_WORLD") - self.expBar.eventFrame:UnregisterEvent("ZONE_CHANGED_NEW_AREA") - - self.expBar.questBar:Hide() - end -end - -function mod:ExperienceBar_Load() +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:RegisterForClicks("RightButtonUp") - self.expBar.statusBar:SetFrameLevel(3) - self.expBar.statusBar:SetStatusBarColor(0, 0.4, 1, 1) - - self.expBar.rested = CreateFrame("StatusBar", "$parent_Rested", self.expBar) - self.expBar.rested:SetFrameLevel(1) + 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) - self.expBar.rested:SetStatusBarColor(0.5, 0, 0.5, 0.8) E:RegisterStatusBar(self.expBar.rested) - - self.expBar.questBar = CreateFrame("StatusBar", "$parent_Quest", self.expBar) - self.expBar.questBar:SetFrameLevel(2) - self.expBar.questBar:SetInside() - self.expBar.questBar:SetStatusBarTexture(E.media.normTex) - self.expBar.questBar:Hide() - E:RegisterStatusBar(self.expBar.questBar) + self.expBar.rested:SetStatusBarColor(1, 0, 1, 0.2) self.expBar.eventFrame = CreateFrame("Frame") self.expBar.eventFrame:Hide() - self.expBar.eventFrame:SetScript("OnEvent", function(this, event, arg1) - if event == "PLAYER_LEVEL_UP" then - self.playerLevel = arg1 - self.forceUpdateQuestXP = true - elseif event == "PLAYER_XP_UPDATE" then - self:ExperienceBar_Update(event) + 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) - if self.forceUpdateQuestXP and self.questXPEnabled and self.db.experience.questXP.enable then - self.forceUpdateQuestXP = nil - self:ExperienceBar_QuestXPUpdate(event) - end - elseif event == "PLAYER_REGEN_DISABLED" then - self.inCombatLockdown = true - - if self.db.experience.hideInCombat then - self:ExperienceBar_Update(event) - end - elseif event == "PLAYER_REGEN_ENABLED" then - self.inCombatLockdown = false - - if self.db.experience.hideInCombat then - self:ExperienceBar_Update(event) - end - elseif event == "ENABLE_XP_GAIN" then - self.expDisabled = false - - this:RegisterEvent("PLAYER_LEVEL_UP") - this:RegisterEvent("PLAYER_XP_UPDATE") - this:RegisterEvent("UPDATE_EXHAUSTION") - this:RegisterEvent("PLAYER_REGEN_DISABLED") - this:RegisterEvent("PLAYER_REGEN_ENABLED") - - self:ExperienceBar_Update(event) - self:ExperienceBar_QuestXPToggle(event) - elseif event == "DISABLE_XP_GAIN" then - self.expDisabled = true - - this:UnregisterEvent("PLAYER_LEVEL_UP") - this:UnregisterEvent("PLAYER_XP_UPDATE") - this:UnregisterEvent("UPDATE_EXHAUSTION") - this:UnregisterEvent("PLAYER_REGEN_DISABLED") - this:UnregisterEvent("PLAYER_REGEN_ENABLED") - - self:ExperienceBar_Update(event) - self:ExperienceBar_QuestXPToggle(event) - elseif event == "QUEST_LOG_UPDATE" - or event == "ZONE_CHANGED_NEW_AREA" - then - self:ExperienceBar_QuestXPUpdate(event) - elseif event == "PLAYER_ENTERING_WORLD" then - this:UnregisterEvent(event) - self:ExperienceBar_QuestXPUpdate(event) - end - end) - - self:ExperienceBar_UpdateDimensions() + self:UpdateExperienceDimensions() E:CreateMover(self.expBar, "ExperienceBarMover", L["Experience Bar"], nil, nil, nil, nil, nil, "databars,experience") - self:ExperienceBar_Toggle() + self:EnableDisable_ExperienceBar() end \ No newline at end of file diff --git a/ElvUI/Modules/DataBars/Reputation.lua b/ElvUI/Modules/DataBars/Reputation.lua index cd705ea..3cc2dfa 100644 --- a/ElvUI/Modules/DataBars/Reputation.lua +++ b/ElvUI/Modules/DataBars/Reputation.lua @@ -4,29 +4,29 @@ local LSM = LibStub("LibSharedMedia-3.0") --Lua functions local _G = _G -local max = math.max local format = string.format ---WoW API +--WoW API / Variables +local GetFactionInfo = GetFactionInfo +local GetNumFactions = GetNumFactions local GetWatchedFactionInfo = GetWatchedFactionInfo -local ToggleCharacter = ToggleCharacter --- WoW Variables +local InCombatLockdown = InCombatLockdown local FACTION_BAR_COLORS = FACTION_BAR_COLORS local REPUTATION = REPUTATION local STANDING = STANDING local UNKNOWN = UNKNOWN -function mod:ReputationBar_Update(event) +function mod:UpdateReputation(event) if not mod.db.reputation.enable then return end local bar = self.repBar - local name, standingID, minRep, maxRep, value = GetWatchedFactionInfo() + 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 - E:DisableMover(self.repBar.mover:GetName()) bar:Hide() - elseif name and (not self.db.reputation.hideInCombat or not self.inCombatLockdown) then - E:EnableMover(self.repBar.mover:GetName()) + elseif name and (not self.db.reputation.hideInCombat or not InCombatLockdown()) then bar:Show() if self.db.reputation.hideInVehicle then @@ -35,30 +35,50 @@ function mod:ReputationBar_Update(event) E:UnregisterObjectForVehicleLock(bar) end + local text = "" local textFormat = self.db.reputation.textFormat - local standing = _G["FACTION_STANDING_LABEL"..standingID] or UNKNOWN - local color = FACTION_BAR_COLORS[standingID] or FACTION_BAR_COLORS[1] - local maxMinDiff = max(1, maxRep - minRep) - + local color = FACTION_BAR_COLORS[reaction] or FACTION_BAR_COLORS[1] bar.statusBar:SetStatusBarColor(color.r, color.g, color.b) - bar.statusBar:SetMinMaxValues(minRep, maxRep) + + bar.statusBar:SetMinMaxValues(min, max) bar.statusBar:SetValue(value) - if textFormat == "PERCENT" then - bar.text:SetFormattedText("%s: %d%% [%s]", name, ((value - minRep) / maxMinDiff * 100), standing) - elseif textFormat == "CURMAX" then - bar.text:SetFormattedText("%s: %s - %s [%s]", name, E:ShortValue(value - minRep), E:ShortValue(maxRep - minRep), standing) - elseif textFormat == "CURPERC" then - bar.text:SetFormattedText("%s: %s - %d%% [%s]", name, E:ShortValue(value - minRep), ((value - minRep) / maxMinDiff * 100), standing) - elseif textFormat == "CUR" then - bar.text:SetFormattedText("%s: %s [%s]", name, E:ShortValue(value - minRep), standing) - elseif textFormat == "REM" then - bar.text:SetFormattedText("%s: %s [%s]", name, E:ShortValue((maxRep - minRep) - (value - minRep)), standing) - elseif textFormat == "CURREM" then - bar.text:SetFormattedText("%s: %s - %s [%s]", name, E:ShortValue(value - minRep), E:ShortValue((maxRep - minRep) - (value - minRep)), standing) - elseif textFormat == "CURPERCREM" then - bar.text:SetFormattedText("%s: %s - %d%% (%s) [%s]", name, E:ShortValue(value - minRep), ((value - minRep) / maxMinDiff * 100), E:ShortValue((maxRep - minRep) - (value - minRep)), standing) + 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 @@ -66,79 +86,60 @@ function mod:ReputationBar_OnEnter() if mod.db.reputation.mouseover then E:UIFrameFadeIn(self, 0.4, self:GetAlpha(), 1) end - - local name, reaction, minRep, maxRep, value = GetWatchedFactionInfo() - if name then 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 - minRep, maxRep - minRep, (value - minRep) / ((maxRep - minRep == 0) and maxRep or (maxRep - minRep)) * 100), 1, 1, 1) - - GameTooltip:Show() + 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:ReputationBar_UpdateDimensions() - self.repBar:Size(self.db.reputation.width, self.db.reputation.height) - self.repBar:SetAlpha(self.db.reputation.mouseover and 0 or 1) - - self.repBar.text:FontTemplate(LSM:Fetch("font", self.db.reputation.font), self.db.reputation.textSize, self.db.reputation.fontOutline) - +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.statusBar:SetRotatesTexture(self.db.reputation.orientation ~= "HORIZONTAL") - - if self.repBar.bubbles then - self:UpdateBarBubbles(self.repBar, self.db.reputation) - elseif self.db.reputation.showBubbles then - local bubbles = self:CreateBarBubbles(self.repBar) - bubbles:SetFrameLevel(5) - self:UpdateBarBubbles(self.repBar, self.db.reputation) + 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:ReputationBar_Toggle() +function mod:EnableDisable_ReputationBar() if self.db.reputation.enable then - self.repBar.eventFrame:RegisterEvent("UPDATE_FACTION") - self.repBar.eventFrame:RegisterEvent("PLAYER_REGEN_DISABLED") - self.repBar.eventFrame:RegisterEvent("PLAYER_REGEN_ENABLED") - - self:ReputationBar_Update() + self:RegisterEvent("UPDATE_FACTION", "UpdateReputation") + self:UpdateReputation() E:EnableMover(self.repBar.mover:GetName()) else - self.repBar.eventFrame:UnregisterEvent("UPDATE_FACTION") - self.repBar.eventFrame:UnregisterEvent("PLAYER_REGEN_DISABLED") - self.repBar.eventFrame:UnregisterEvent("PLAYER_REGEN_ENABLED") - + self:UnregisterEvent("UPDATE_FACTION") self.repBar:Hide() E:DisableMover(self.repBar.mover:GetName()) end end -function mod:ReputationBar_Load() +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:SetScript("OnEvent", function(_, event) - if event == "PLAYER_REGEN_DISABLED" then - self.inCombatLockdown = true - elseif event == "PLAYER_REGEN_ENABLED" then - self.inCombatLockdown = false - end + 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:ReputationBar_Update(event) - end) - - self:ReputationBar_UpdateDimensions() + self:UpdateReputationDimensions() E:CreateMover(self.repBar, "ReputationBarMover", L["Reputation Bar"], nil, nil, nil, nil, nil, "databars,reputation") - self:ReputationBar_Toggle() + self:EnableDisable_ReputationBar() end \ No newline at end of file diff --git a/ElvUI_OptionsUI/DataBars.lua b/ElvUI_OptionsUI/DataBars.lua index a794f35..bbff74b 100644 --- a/ElvUI_OptionsUI/DataBars.lua +++ b/ElvUI_OptionsUI/DataBars.lua @@ -24,7 +24,7 @@ E.Options.args.databars = { type = "group", name = L["XPBAR_LABEL"], get = function(info) return mod.db.experience[info[#info]] end, - set = function(info, value) mod.db.experience[info[#info]] = value mod:ExperienceBar_UpdateDimensions() end, + set = function(info, value) mod.db.experience[info[#info]] = value mod:UpdateExperienceDimensions() end, args = { header = { order = 1, @@ -35,7 +35,7 @@ E.Options.args.databars = { order = 2, type = "toggle", name = L["Enable"], - set = function(info, value) mod.db.experience[info[#info]] = value mod:ExperienceBar_Toggle() end + set = function(info, value) mod.db.experience[info[#info]] = value mod:EnableDisable_ExperienceBar() end }, mouseover = { order = 3, @@ -46,24 +46,19 @@ E.Options.args.databars = { order = 4, type = "toggle", name = L["Hide At Max Level"], - set = function(info, value) mod.db.experience[info[#info]] = value mod:ExperienceBar_Update() end + set = function(info, value) mod.db.experience[info[#info]] = value mod:UpdateExperience() end }, hideInVehicle = { order = 5, type = "toggle", name = L["Hide In Vehicle"], - set = function(info, value) mod.db.experience[info[#info]] = value mod:ExperienceBar_Update() end + set = function(info, value) mod.db.experience[info[#info]] = value mod:UpdateExperience() end }, hideInCombat = { order = 6, type = "toggle", name = L["Hide In Combat"], - set = function(info, value) mod.db.experience[info[#info]] = value mod:ExperienceBar_Update() end - }, - showBubbles = { - order = 6, - type = "toggle", - name = L["Show Bubbles"] + set = function(info, value) mod.db.experience[info[#info]] = value mod:UpdateExperience() end }, spacer = { order = 7, @@ -125,66 +120,7 @@ E.Options.args.databars = { CURREM = L["Current - Remaining"], CURPERCREM = L["Current - Percent (Remaining)"], }, - set = function(info, value) mod.db.experience[info[#info]] = value mod:ExperienceBar_Update() end - }, - questXP = { - order = 15, - type = "group", - name = L["Quest XP"], - guiInline = true, - get = function(info) return mod.db.experience.questXP[info[#info]] end, - disabled = function() return not mod.db.experience.enable or not mod.db.experience.questXP.enable end, - args = { - enable = { - order = 1, - type = "toggle", - name = L["Enable"], - set = function(info, value) - mod.db.experience.questXP.enable = value - mod:ExperienceBar_QuestXPToggle() - end, - disabled = function() return not mod.db.experience.enable end - }, - color = { - order = 2, - type = "color", - name = L["Quest XP Color"], - hasAlpha = true, - get = function(info) - local t = mod.db.experience.questXP.color or {r=0,g=1,b=0,a=0.4} - return t.r, t.g, t.b, t.a, 0, 1, 0, 0.4 - end, - set = function(info, r, g, b, a) - local t = mod.db.experience.questXP.color - t.r, t.g, t.b, t.a = r, g, b, a - mod:ExperienceBar_UpdateDimensions() - end - }, - questCurrentZoneOnly = { - order = 3, - type = "toggle", - name = L["Quests in Current Zone Only"], - set = function(info, value) - mod.db.experience.questXP.questCurrentZoneOnly = value - mod:ExperienceBar_QuestXPUpdate() - end - }, - questCompletedOnly = { - order = 4, - type = "toggle", - name = L["Completed Quests Only"], - set = function(info, value) - mod.db.experience.questXP.questCompletedOnly = value - mod:ExperienceBar_QuestXPUpdate() - end - }, - tooltip = { - order = 5, - type = "toggle", - name = L["Add Quest XP to Tooltip"], - set = function(info, value) mod.db.experience.questXP.tooltip = value end - } - } + set = function(info, value) mod.db.experience[info[#info]] = value mod:UpdateExperience() end } } }, @@ -193,7 +129,7 @@ E.Options.args.databars = { type = "group", name = L["REPUTATION"], get = function(info) return mod.db.reputation[info[#info]] end, - set = function(info, value) mod.db.reputation[info[#info]] = value mod:ReputationBar_UpdateDimensions() end, + set = function(info, value) mod.db.reputation[info[#info]] = value mod:UpdateReputationDimensions() end, args = { header = { order = 1, @@ -204,7 +140,7 @@ E.Options.args.databars = { order = 2, type = "toggle", name = L["Enable"], - set = function(info, value) mod.db.reputation[info[#info]] = value mod:ReputationBar_Toggle() end + set = function(info, value) mod.db.reputation[info[#info]] = value mod:EnableDisable_ReputationBar() end }, mouseover = { order = 3, @@ -215,26 +151,21 @@ E.Options.args.databars = { order = 4, type = "toggle", name = L["Hide In Vehicle"], - set = function(info, value) mod.db.reputation[info[#info]] = value mod:ReputationBar_Update() end + set = function(info, value) mod.db.reputation[info[#info]] = value mod:UpdateReputation() end }, hideInCombat = { order = 5, type = "toggle", name = L["Hide In Combat"], - set = function(info, value) mod.db.reputation[info[#info]] = value mod:ReputationBar_Update() end - }, - showBubbles = { - order = 6, - type = "toggle", - name = L["Show Bubbles"] + set = function(info, value) mod.db.reputation[info[#info]] = value mod:UpdateReputation() end }, spacer = { - order = 7, + order = 6, type = "description", name = " " }, orientation = { - order = 8, + order = 7, type = "select", name = L["Statusbar Fill Orientation"], desc = L["Direction the bar moves on gains/losses"], @@ -244,37 +175,37 @@ E.Options.args.databars = { } }, width = { - order = 9, + order = 8, type = "range", name = L["Width"], min = 5, max = ceil(GetScreenWidth() or 800), step = 1 }, height = { - order = 10, + order = 9, type = "range", name = L["Height"], min = 5, max = ceil(GetScreenHeight() or 800), step = 1 }, font = { - order = 11, + order = 10, type = "select", dialogControl = "LSM30_Font", name = L["Font"], values = AceGUIWidgetLSMlists.font }, textSize = { - order = 12, + order = 11, type = "range", name = L["FONT_SIZE"], min = 6, max = 22, step = 1 }, fontOutline = { - order = 13, + order = 12, type = "select", name = L["Font Outline"], values = C.Values.FontFlags }, textFormat = { - order = 14, + order = 13, type = "select", name = L["Text Format"], width = "double", @@ -288,7 +219,7 @@ E.Options.args.databars = { CURREM = L["Current - Remaining"], CURPERCREM = L["Current - Percent (Remaining)"], }, - set = function(info, value) mod.db.reputation[info[#info]] = value mod:ReputationBar_Update() end + set = function(info, value) mod.db.reputation[info[#info]] = value mod:UpdateReputation() end } } }