From 6313d7afbe1e721d2fdc4e3c93741ac331cb7790 Mon Sep 17 00:00:00 2001 From: Andrew6810 <16847730+andrew6180@users.noreply.github.com> Date: Wed, 14 Dec 2022 10:58:37 -0700 Subject: [PATCH] Revert "Revert "Show current quest XP on xp bar (#17)"" This reverts commit b37859db925e8b38d1f9d93c9ad0b6119fdd1ba2. --- ElvUI/Modules/DataBars/DataBars.lua | 59 +++-- ElvUI/Modules/DataBars/Experience.lua | 326 +++++++++++++++++++------- ElvUI/Modules/DataBars/Reputation.lua | 127 +++++----- ElvUI_OptionsUI/DataBars.lua | 107 +++++++-- 4 files changed, 429 insertions(+), 190 deletions(-) diff --git a/ElvUI/Modules/DataBars/DataBars.lua b/ElvUI/Modules/DataBars/DataBars.lua index f9149ef..f6d5c0d 100644 --- a/ElvUI/Modules/DataBars/DataBars.lua +++ b/ElvUI/Modules/DataBars/DataBars.lua @@ -1,13 +1,10 @@ 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 +function mod.OnLeave(self) + 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() @@ -33,27 +30,51 @@ function mod:CreateBar(name, onEnter, onClick, ...) return bar end +function mod:CreateBarBubbles(bar) + local bubbles = CreateFrame("Frame", "$parent_Bubbles", bar) + bubbles:SetAllPoints() + bubbles.textures = {} -function mod:UpdateDataBarDimensions() - self:UpdateExperienceDimensions() - self:UpdateReputationDimensions() + 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: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) +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 - self.expBar:Hide() + for _, texture in ipairs(bar.bubbles.textures) do + texture:Hide() + end end end +function mod:UpdateDataBarDimensions() + self:ExperienceBar_UpdateDimensions() + self:ReputationBar_UpdateDimensions() +end + + function mod:Initialize() self.db = E.db.databars - - self:LoadExperienceBar() - self:LoadReputationBar() - self:RegisterEvent("PLAYER_LEVEL_UP") + self.maxExpansionLevel = MAX_PLAYER_LEVEL_TABLE[GetAccountExpansionLevel()] + self:ExperienceBar_Load() + self:ReputationBar_Load() end local function InitializeCallback() diff --git a/ElvUI/Modules/DataBars/Experience.lua b/ElvUI/Modules/DataBars/Experience.lua index abc93dd..211989e 100644 --- a/ElvUI/Modules/DataBars/Experience.lua +++ b/ElvUI/Modules/DataBars/Experience.lua @@ -3,38 +3,70 @@ local mod = E:GetModule("DataBars") local LSM = LibStub("LibSharedMedia-3.0") --Lua functions -local min = math.min +local max, min = math.max, math.min local format = string.format ---WoW API / Variables -local GetExpansionLevel = GetExpansionLevel -local GetPetExperience = GetPetExperience +--WoW API +local GetNumQuestLogEntries = GetNumQuestLogEntries +local GetQuestLogRewardXP = GetQuestLogRewardXP +local GetQuestLogSelection = GetQuestLogSelection +local GetQuestLogTitle = GetQuestLogTitle local GetXPExhaustion = GetXPExhaustion -local InCombatLockdown = InCombatLockdown +local GetZoneText = GetZoneText local IsXPUserDisabled = IsXPUserDisabled +local SelectQuestLogEntry = SelectQuestLogEntry 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() +-- 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() else - return UnitXP(unit), UnitXPMax(unit) + self.expBar.questBar:Hide() end end -function mod:UpdateExperience(event) +function mod:ExperienceBar_Update(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()) + local hideBar = (self.playerLevel == self.maxExpansionLevel and self.db.experience.hideAtMaxLevel) or self.expDisabled - if hideXP or (event == "PLAYER_REGEN_DISABLED" and self.db.experience.hideInCombat) then - E:DisableMover(self.expBar.mover:GetName()) + if hideBar or (event == "PLAYER_REGEN_DISABLED" and self.db.experience.hideInCombat) then + E:DisableMover(bar.mover:GetName()) bar:Hide() - elseif not hideXP and (not self.db.experience.hideInCombat or not InCombatLockdown()) then - E:EnableMover(self.expBar.mover:GetName()) + elseif not hideBar and (not self.db.experience.hideInCombat or not self.inCombatLockdown) then + E:EnableMover(bar.mover:GetName()) bar:Show() if self.db.experience.hideInVehicle then @@ -43,140 +75,258 @@ function mod:UpdateExperience(event) 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 + local curExp = UnitXP("player") + local maxExp = max(1, UnitXPMax("player")) + local rested = GetXPExhaustion() + bar.curExp = curExp + bar.maxExp = maxExp + + bar.statusBar:SetMinMaxValues(min(0, curExp), maxExp) + -- bar.statusBar:SetValue(curExp - 1 >= 0 and curExp - 1 or 0) + bar.statusBar:SetValue(curExp) if rested and rested > 0 then - bar.rested:SetMinMaxValues(0, max) - bar.rested:SetValue(min(cur + rested, max)) + bar.rested:SetMinMaxValues(0, maxExp) + bar.rested:SetValue(min(curExp + rested, maxExp)) if textFormat == "PERCENT" then - text = format("%d%% R:%d%%", cur / max * 100, rested / max * 100) + bar.text:SetFormattedText("%d%% R:%d%%", curExp / maxExp * 100, rested / maxExp * 100) elseif textFormat == "CURMAX" then - text = format("%s - %s R:%s", E:ShortValue(cur), E:ShortValue(max), E:ShortValue(rested)) + bar.text:SetFormattedText("%s - %s R:%s", E:ShortValue(curExp), E:ShortValue(maxExp), 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) + bar.text:SetFormattedText("%s - %d%% R:%s [%d%%]", E:ShortValue(curExp), curExp / maxExp * 100, E:ShortValue(rested), rested / maxExp * 100) elseif textFormat == "CUR" then - text = format("%s R:%s", E:ShortValue(cur), E:ShortValue(rested)) + bar.text:SetFormattedText("%s R:%s", E:ShortValue(curExp), E:ShortValue(rested)) elseif textFormat == "REM" then - text = format("%s R:%s", E:ShortValue(max - cur), E:ShortValue(rested)) + bar.text:SetFormattedText("%s R:%s", E:ShortValue(maxExp - curExp), E:ShortValue(rested)) elseif textFormat == "CURREM" then - text = format("%s - %s R:%s", E:ShortValue(cur), E:ShortValue(max - cur), E:ShortValue(rested)) + bar.text:SetFormattedText("%s - %s R:%s", E:ShortValue(curExp), E:ShortValue(maxExp - curExp), 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)) + bar.text:SetFormattedText("%s - %d%% (%s) R:%s", E:ShortValue(curExp), curExp / maxExp * 100, E:ShortValue(maxExp - curExp), E:ShortValue(rested)) end else bar.rested:SetMinMaxValues(0, 1) bar.rested:SetValue(0) if textFormat == "PERCENT" then - text = format("%d%%", cur / max * 100) + bar.text:SetFormattedText("%d%%", curExp / maxExp * 100) elseif textFormat == "CURMAX" then - text = format("%s - %s", E:ShortValue(cur), E:ShortValue(max)) + bar.text:SetFormattedText("%s - %s", E:ShortValue(curExp), E:ShortValue(maxExp)) elseif textFormat == "CURPERC" then - text = format("%s - %d%%", E:ShortValue(cur), cur / max * 100) + bar.text:SetFormattedText("%s - %d%%", E:ShortValue(curExp), curExp / maxExp * 100) elseif textFormat == "CUR" then - text = format("%s", E:ShortValue(cur)) + bar.text:SetFormattedText("%s", E:ShortValue(curExp)) elseif textFormat == "REM" then - text = format("%s", E:ShortValue(max - cur)) + bar.text:SetFormattedText("%s", E:ShortValue(maxExp - curExp)) elseif textFormat == "CURREM" then - text = format("%s - %s", E:ShortValue(cur), E:ShortValue(max - cur)) + bar.text:SetFormattedText("%s - %s", E:ShortValue(curExp), E:ShortValue(maxExp - curExp)) elseif textFormat == "CURPERCREM" then - text = format("%s - %d%% (%s)", E:ShortValue(cur), cur / max * 100, E:ShortValue(max - cur)) + bar.text:SetFormattedText("%s - %d%% (%s)", E:ShortValue(curExp), curExp / maxExp * 100, E:ShortValue(maxExp - curExp)) end end - - bar.text:SetText(text) end end -function mod:ExperienceBar_OnEnter() +function mod.ExperienceBar_OnEnter(self) 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%%)", 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) + 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) if rested then - GameTooltip:AddDoubleLine(L["Rested:"], format("+%d (%d%%)", rested, rested / max * 100), 1, 1, 1) + 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) 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) +function mod.ExperienceBar_OnClick(self, button) + if XPRM then -- Warmane exp rates + if button == "RightButton" then + ToggleDropDownMenu(1, nil, XPRM, "cursor") + end 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() +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) + + self.expBar.text:FontTemplate(LSM:Fetch("font", self.db.experience.font), self.db.experience.textSize, self.db.experience.fontOutline) + + 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) + 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() 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.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.expBar:Hide() E:DisableMover(self.expBar.mover:GetName()) end end -function mod:LoadExperienceBar() +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() 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: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.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.rested:SetStatusBarColor(1, 0, 1, 0.2) + + 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.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.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:UpdateExperienceDimensions() + 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() E:CreateMover(self.expBar, "ExperienceBarMover", L["Experience Bar"], nil, nil, nil, nil, nil, "databars,experience") - self:EnableDisable_ExperienceBar() + self:ExperienceBar_Toggle() end \ No newline at end of file diff --git a/ElvUI/Modules/DataBars/Reputation.lua b/ElvUI/Modules/DataBars/Reputation.lua index 3cc2dfa..cd705ea 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 / Variables -local GetFactionInfo = GetFactionInfo -local GetNumFactions = GetNumFactions +--WoW API local GetWatchedFactionInfo = GetWatchedFactionInfo -local InCombatLockdown = InCombatLockdown +local ToggleCharacter = ToggleCharacter +-- WoW Variables local FACTION_BAR_COLORS = FACTION_BAR_COLORS local REPUTATION = REPUTATION local STANDING = STANDING local UNKNOWN = UNKNOWN -function mod:UpdateReputation(event) +function mod:ReputationBar_Update(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() + local name, standingID, minRep, maxRep, value = GetWatchedFactionInfo() 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 InCombatLockdown()) then + elseif name and (not self.db.reputation.hideInCombat or not self.inCombatLockdown) then + E:EnableMover(self.repBar.mover:GetName()) bar:Show() if self.db.reputation.hideInVehicle then @@ -35,50 +35,30 @@ function mod:UpdateReputation(event) 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) + 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) - bar.statusBar:SetMinMaxValues(min, max) + bar.statusBar:SetStatusBarColor(color.r, color.g, color.b) + bar.statusBar:SetMinMaxValues(minRep, maxRep) 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) + bar.text:SetFormattedText("%s: %d%% [%s]", name, ((value - minRep) / maxMinDiff * 100), standing) elseif textFormat == "CURMAX" then - text = format("%s: %s - %s [%s]", name, E:ShortValue(value - min), E:ShortValue(max - min), standingLabel) + bar.text:SetFormattedText("%s: %s - %s [%s]", name, E:ShortValue(value - minRep), E:ShortValue(maxRep - minRep), standing) elseif textFormat == "CURPERC" then - text = format("%s: %s - %d%% [%s]", name, E:ShortValue(value - min), ((value - min) / maxMinDiff * 100), standingLabel) + bar.text:SetFormattedText("%s: %s - %d%% [%s]", name, E:ShortValue(value - minRep), ((value - minRep) / maxMinDiff * 100), standing) elseif textFormat == "CUR" then - text = format("%s: %s [%s]", name, E:ShortValue(value - min), standingLabel) + bar.text:SetFormattedText("%s: %s [%s]", name, E:ShortValue(value - minRep), standing) elseif textFormat == "REM" then - text = format("%s: %s [%s]", name, E:ShortValue((max - min) - (value-min)), standingLabel) + bar.text:SetFormattedText("%s: %s [%s]", name, E:ShortValue((maxRep - minRep) - (value - minRep)), standing) elseif textFormat == "CURREM" then - text = format("%s: %s - %s [%s]", name, E:ShortValue(value - min), E:ShortValue((max - min) - (value-min)), standingLabel) + bar.text:SetFormattedText("%s: %s - %s [%s]", name, E:ShortValue(value - minRep), E:ShortValue((maxRep - minRep) - (value - minRep)), standing) 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) + bar.text:SetFormattedText("%s: %s - %d%% (%s) [%s]", name, E:ShortValue(value - minRep), ((value - minRep) / maxMinDiff * 100), E:ShortValue((maxRep - minRep) - (value - minRep)), standing) end - - bar.text:SetText(text) end end @@ -86,60 +66,79 @@ 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 - min, max - min, (value - min) / ((max - min == 0) and max or (max - min)) * 100), 1, 1, 1) - end + 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() + end 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) +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) - if self.db.reputation.mouseover then - self.repBar:SetAlpha(0) - else - self.repBar:SetAlpha(1) + + 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) end end -function mod:EnableDisable_ReputationBar() +function mod:ReputationBar_Toggle() if self.db.reputation.enable then - self:RegisterEvent("UPDATE_FACTION", "UpdateReputation") - self:UpdateReputation() + self.repBar.eventFrame:RegisterEvent("UPDATE_FACTION") + self.repBar.eventFrame:RegisterEvent("PLAYER_REGEN_DISABLED") + self.repBar.eventFrame:RegisterEvent("PLAYER_REGEN_ENABLED") + + self:ReputationBar_Update() E:EnableMover(self.repBar.mover:GetName()) else - self:UnregisterEvent("UPDATE_FACTION") + self.repBar.eventFrame:UnregisterEvent("UPDATE_FACTION") + self.repBar.eventFrame:UnregisterEvent("PLAYER_REGEN_DISABLED") + self.repBar.eventFrame:UnregisterEvent("PLAYER_REGEN_ENABLED") + self.repBar:Hide() E:DisableMover(self.repBar.mover:GetName()) end end -function mod:LoadReputationBar() +function mod:ReputationBar_Load() 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.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:UpdateReputationDimensions() + self:ReputationBar_Update(event) + end) + + self:ReputationBar_UpdateDimensions() E:CreateMover(self.repBar, "ReputationBarMover", L["Reputation Bar"], nil, nil, nil, nil, nil, "databars,reputation") - self:EnableDisable_ReputationBar() + self:ReputationBar_Toggle() end \ No newline at end of file diff --git a/ElvUI_OptionsUI/DataBars.lua b/ElvUI_OptionsUI/DataBars.lua index bbff74b..a794f35 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:UpdateExperienceDimensions() end, + set = function(info, value) mod.db.experience[info[#info]] = value mod:ExperienceBar_UpdateDimensions() 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:EnableDisable_ExperienceBar() end + set = function(info, value) mod.db.experience[info[#info]] = value mod:ExperienceBar_Toggle() end }, mouseover = { order = 3, @@ -46,19 +46,24 @@ 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:UpdateExperience() end + set = function(info, value) mod.db.experience[info[#info]] = value mod:ExperienceBar_Update() end }, hideInVehicle = { order = 5, type = "toggle", name = L["Hide In Vehicle"], - set = function(info, value) mod.db.experience[info[#info]] = value mod:UpdateExperience() end + set = function(info, value) mod.db.experience[info[#info]] = value mod:ExperienceBar_Update() end }, hideInCombat = { order = 6, type = "toggle", name = L["Hide In Combat"], - set = function(info, value) mod.db.experience[info[#info]] = value mod:UpdateExperience() end + set = function(info, value) mod.db.experience[info[#info]] = value mod:ExperienceBar_Update() end + }, + showBubbles = { + order = 6, + type = "toggle", + name = L["Show Bubbles"] }, spacer = { order = 7, @@ -120,7 +125,66 @@ E.Options.args.databars = { CURREM = L["Current - Remaining"], CURPERCREM = L["Current - Percent (Remaining)"], }, - set = function(info, value) mod.db.experience[info[#info]] = value mod:UpdateExperience() end + 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 + } + } } } }, @@ -129,7 +193,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:UpdateReputationDimensions() end, + set = function(info, value) mod.db.reputation[info[#info]] = value mod:ReputationBar_UpdateDimensions() end, args = { header = { order = 1, @@ -140,7 +204,7 @@ E.Options.args.databars = { order = 2, type = "toggle", name = L["Enable"], - set = function(info, value) mod.db.reputation[info[#info]] = value mod:EnableDisable_ReputationBar() end + set = function(info, value) mod.db.reputation[info[#info]] = value mod:ReputationBar_Toggle() end }, mouseover = { order = 3, @@ -151,21 +215,26 @@ E.Options.args.databars = { order = 4, type = "toggle", name = L["Hide In Vehicle"], - set = function(info, value) mod.db.reputation[info[#info]] = value mod:UpdateReputation() end + set = function(info, value) mod.db.reputation[info[#info]] = value mod:ReputationBar_Update() end }, hideInCombat = { order = 5, type = "toggle", name = L["Hide In Combat"], - set = function(info, value) mod.db.reputation[info[#info]] = value mod:UpdateReputation() end + set = function(info, value) mod.db.reputation[info[#info]] = value mod:ReputationBar_Update() end + }, + showBubbles = { + order = 6, + type = "toggle", + name = L["Show Bubbles"] }, spacer = { - order = 6, + order = 7, type = "description", name = " " }, orientation = { - order = 7, + order = 8, type = "select", name = L["Statusbar Fill Orientation"], desc = L["Direction the bar moves on gains/losses"], @@ -175,37 +244,37 @@ E.Options.args.databars = { } }, width = { - order = 8, + order = 9, type = "range", name = L["Width"], min = 5, max = ceil(GetScreenWidth() or 800), step = 1 }, height = { - order = 9, + order = 10, type = "range", name = L["Height"], min = 5, max = ceil(GetScreenHeight() or 800), step = 1 }, font = { - order = 10, + order = 11, type = "select", dialogControl = "LSM30_Font", name = L["Font"], values = AceGUIWidgetLSMlists.font }, textSize = { - order = 11, + order = 12, type = "range", name = L["FONT_SIZE"], min = 6, max = 22, step = 1 }, fontOutline = { - order = 12, + order = 13, type = "select", name = L["Font Outline"], values = C.Values.FontFlags }, textFormat = { - order = 13, + order = 14, type = "select", name = L["Text Format"], width = "double", @@ -219,7 +288,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:UpdateReputation() end + set = function(info, value) mod.db.reputation[info[#info]] = value mod:ReputationBar_Update() end } } }