From 31c4e5d3995827fddab53eceded5c0be3560d902 Mon Sep 17 00:00:00 2001 From: Bill Riess Date: Tue, 3 Mar 2026 05:09:18 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20wb=20housing=20databar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Options/WunderBar/SubModules/DataBar.lua | 8 +- Modules/WunderBar/SubModules/DataBar.lua | 188 ++++++++++++++++-- 2 files changed, 175 insertions(+), 21 deletions(-) diff --git a/Modules/Options/WunderBar/SubModules/DataBar.lua b/Modules/Options/WunderBar/SubModules/DataBar.lua index 1bc63874..d79d8c32 100644 --- a/Modules/Options/WunderBar/SubModules/DataBar.lua +++ b/Modules/Options/WunderBar/SubModules/DataBar.lua @@ -31,10 +31,14 @@ function O:WunderBar_SubModules_DataBar() step = 1, }, nil, nil, nil, iconDisabled) - tab.generalGroup.args.mode = ACH:Select("Mode", nil, 3, { + local modes = { ["auto"] = "Smart (Experience under Max Level)", ["rep"] = "Reputation", - }, nil, "double") + } + + if TXUI.IsRetail then modes["housing"] = "Housing" end + + tab.generalGroup.args.mode = ACH:Select("Mode", nil, 3, modes, nil, "double") -- Bar Group tab.barGroup = ACH:Group("Bar", nil, 2) diff --git a/Modules/WunderBar/SubModules/DataBar.lua b/Modules/WunderBar/SubModules/DataBar.lua index c82b1cdf..4e05c7ea 100644 --- a/Modules/WunderBar/SubModules/DataBar.lua +++ b/Modules/WunderBar/SubModules/DataBar.lua @@ -33,6 +33,7 @@ DB.const = { mode = { ["rep"] = 0, ["exp"] = 1, + ["housing"] = 2, }, } @@ -49,10 +50,32 @@ function DB:GetValues(curValue, minValue, maxValue) end end -function DB:OnEvent(event) - -- If smart mode changes, force update +function DB:OnEvent(event, ...) + if event == "PLAYER_ENTERING_WORLD" then + -- I don't like this but its a workaround for fresh logins where the housing data isn't available yet. Might be a better solution. + C_Timer.After(3, function() + if DB and DB.OnEvent then DB:OnEvent("ELVUI_FORCE_UPDATE") end + end) + event = "ELVUI_FORCE_UPDATE" + end + if self:UpdateSmartMode() then event = "ELVUI_FORCE_UPDATE" end + if event == "HOUSE_LEVEL_FAVOR_UPDATED" and TXUI.IsRetail then + local payload = ... + if payload and payload.houseGUID then + local trackedGuid = C_Housing and C_Housing.GetTrackedHouseGuid() + if not trackedGuid then + local houseInfo = C_Housing and C_Housing.GetCurrentHouseInfo and C_Housing.GetCurrentHouseInfo() + trackedGuid = houseInfo and houseInfo.houseGUID + end + if payload.houseGUID == trackedGuid then self.cachedHouseLevelFavor = payload end + end + elseif event == "CVAR_UPDATE" then + local cvar = ... + if cvar == "trackedHouseFavor" and self.mode == self.const.mode.housing then event = "ELVUI_FORCE_UPDATE" end + end + -- Reputation if (self.mode == DB.const.mode.rep) @@ -88,6 +111,7 @@ function DB:OnEvent(event) local isCapped = false if not name then + self.data.repPercentage = 0 self.noData = true self:UpdateBar() return @@ -139,7 +163,7 @@ function DB:OnEvent(event) self:UpdateBar() end) - -- Experience + -- Experience elseif (self.mode == DB.const.mode.exp) and not self.updateExpNextOutOfCombat @@ -159,6 +183,7 @@ function DB:OnEvent(event) F.Event.ContinueOutOfCombat(function() self.updateExpNextOutOfCombat = false + self.noData = false if (not TXUI.IsClassicEra and not TXUI.IsAnniversary and IsXPUserDisabledFunction()) or (IsPlayerAtEffectiveMaxLevel()) then self.data.expRestPercentage = 0 @@ -181,6 +206,59 @@ function DB:OnEvent(event) self.data.expPercentage = (self.data.currentXP / self.data.xpToLevel) * 100 end + self:UpdateTooltip() + self:UpdateBar() + end) + + -- Housing + elseif + TXUI.IsRetail + and (self.mode == DB.const.mode.housing) + and not self.updateHousingNextOutOfCombat + and ((event == "ELVUI_FORCE_UPDATE") or (event == "HOUSE_LEVEL_FAVOR_UPDATED") or (event == "CURRENT_HOUSE_INFO_RECIEVED") or (event == "CURRENT_HOUSE_INFO_UPDATED")) + then + self.updateHousingNextOutOfCombat = true + + F.Event.ContinueOutOfCombat(function() + self.updateHousingNextOutOfCombat = false + + if event == "ELVUI_FORCE_UPDATE" and C_Housing and C_Housing.RequestCurrentHouseInfo then C_Housing.RequestCurrentHouseInfo() end + + local trackedHouseGuid = C_Housing and C_Housing.GetTrackedHouseGuid and C_Housing.GetTrackedHouseGuid() + local houseInfo = C_Housing and C_Housing.GetCurrentHouseInfo and C_Housing.GetCurrentHouseInfo() + + if not trackedHouseGuid and houseInfo then trackedHouseGuid = houseInfo.houseGUID end + + if not trackedHouseGuid then + self.noData = false + self.data.housingLevel = 1 + self.data.housingFavor = 0 + self.data.housingPercentage = 0 + else + if C_Housing and C_Housing.GetCurrentHouseLevelFavor and event ~= "HOUSE_LEVEL_FAVOR_UPDATED" then + local favorRet = C_Housing.GetCurrentHouseLevelFavor(trackedHouseGuid) + if favorRet and favorRet.houseLevel then self.cachedHouseLevelFavor = favorRet end + end + + local houseLevelFavor = self.cachedHouseLevelFavor + if not houseLevelFavor or houseLevelFavor.houseGUID ~= trackedHouseGuid then houseLevelFavor = { houseLevel = 1, houseFavor = 0 } end + + self.data.housingLevel = houseLevelFavor.houseLevel + self.data.housingFavor = houseLevelFavor.houseFavor + + local minBar = 0 + local maxBar = 1 + if C_Housing and C_Housing.GetHouseLevelFavorForLevel then + minBar = C_Housing.GetHouseLevelFavorForLevel(houseLevelFavor.houseLevel) or 0 + maxBar = C_Housing.GetHouseLevelFavorForLevel(houseLevelFavor.houseLevel + 1) or 1 + end + + if maxBar == minBar then maxBar = minBar + 1 end + + self.data.housingPercentage = ((self.data.housingFavor - minBar) / (maxBar - minBar)) * 100 + self.noData = false + end + self:UpdateTooltip() self:UpdateBar() end) @@ -241,11 +319,54 @@ function DB:UpdateExperienceTooltip() DT.tooltip:Show() end +function DB:UpdateHousingTooltip() + DT.tooltip:ClearLines() + DT.tooltip:AddDoubleLine("Housing", format("Level %d", self.data.housingLevel or 1)) + DT.tooltip:AddLine(" ") + + local minBar = 0 + local maxBar = 1 + if C_Housing and C_Housing.GetHouseLevelFavorForLevel then + minBar = C_Housing.GetHouseLevelFavorForLevel(self.data.housingLevel or 1) or 0 + maxBar = C_Housing.GetHouseLevelFavorForLevel((self.data.housingLevel or 1) + 1) or 1 + end + + if maxBar == minBar then maxBar = minBar + 1 end + + local current = (self.data.housingFavor or 0) - minBar + local maximum = maxBar - minBar + local remainXP = maximum - current + local remainPercent = (remainXP / maximum) * 100 + local remainBars = 20 * (remainXP / maximum) + + DT.tooltip:AddDoubleLine( + "Experience:", + format(" %s / %s (%.2f%%)", E:ShortValue(current), E:ShortValue(maximum), self.data.housingPercentage), + 1, + 1, + 1, + F.SlowColorGradient(1 - (remainPercent * 0.01), 1, 0.1, 0.1, 1, 1, 0.1, 0.1, 1, 0.1) + ) + + DT.tooltip:AddDoubleLine( + "Remaining:", + format(" %s (%.2f%% - %d " .. "Bars" .. ")", E:ShortValue(remainXP), remainPercent, remainBars), + 1, + 1, + 1, + F.SlowColorGradient(1 - (remainPercent * 0.01), 1, 0.1, 0.1, 1, 1, 0.1, 0.1, 1, 0.1) + ) + + DT.tooltip:Show() +end + function DB:UpdateTooltip() if not self.mouseover then return end if self.mode == DB.const.mode.exp then self:UpdateExperienceTooltip() + elseif self.mode == DB.const.mode.housing then + self:UpdateHousingTooltip() elseif self.mode == DB.const.mode.rep then local dtModule = WB:GetElvUIDataText("Reputation") if dtModule then @@ -275,6 +396,10 @@ function DB:OnLeave() end function DB:OnClick() + if self.mode == DB.const.mode.housing and TXUI.IsRetail then + if not _G.HousingDashboardFrame or not _G.HousingDashboardFrame:IsShown() then _G.HousingFramesUtil.ToggleHousingDashboard() end + return + end if self.mode ~= DB.const.mode.rep then return end local dtModule = WB:GetElvUIDataText("Reputation") @@ -300,6 +425,8 @@ function DB:UpdateBar() local barProgress if self.mode == DB.const.mode.rep then barProgress = self.data.repPercentage + elseif self.mode == DB.const.mode.housing then + barProgress = self.data.housingPercentage else barProgress = self.data.expPercentage end @@ -385,9 +512,14 @@ function DB:GetCompletedPercentage() end function DB:UpdateSmartMode(init) - local mode = ((self.db.mode == "auto") and (not IsPlayerAtEffectiveMaxLevel()) and ((TXUI.IsClassicEra or TXUI.IsAnniversary) or not IsXPUserDisabledFunction())) - and self.const.mode.exp - or self.const.mode.rep + local mode + if self.db.mode == "housing" and TXUI.IsRetail then + mode = self.const.mode.housing + elseif self.db.mode == "auto" and (not IsPlayerAtEffectiveMaxLevel()) and ((TXUI.IsClassicEra or TXUI.IsAnniversary) or not IsXPUserDisabledFunction()) then + mode = self.const.mode.exp + else + mode = self.const.mode.rep + end if not init and (mode ~= self.mode) then self.mode = mode @@ -421,7 +553,10 @@ end function DB:UpdateInfoText() if self.db.infoEnabled then - self.infoText:SetText(E:Round((self.mode == DB.const.mode.exp) and self.data.expPercentage or self.data.repPercentage) .. "%") + self.infoText:SetText( + E:Round((self.mode == DB.const.mode.exp) and self.data.expPercentage or (self.mode == DB.const.mode.housing) and self.data.housingPercentage or self.data.repPercentage) + .. "%" + ) else self.infoText:SetText("") end @@ -500,6 +635,8 @@ function DB:OnInit() -- Don't init second time if self.Initialized then return end + if TXUI.IsRetail and C_Housing and C_Housing.RequestCurrentHouseInfo then C_Housing.RequestCurrentHouseInfo() end + -- Vars self.frame = self.SubModuleHolder self.updateExpNextOutOfCombat = false @@ -514,6 +651,9 @@ function DB:OnInit() currentXP = 0, xpToLevel = 0, restedXP = 0, + housingLevel = 1, + housingFavor = 0, + housingPercentage = 0, } self:CreateBar() @@ -526,16 +666,26 @@ end WB:RegisterSubModule( DB, - F.Table.Join({ - "PLAYER_XP_UPDATE", - "QUEST_LOG_UPDATE", - "ZONE_CHANGED", - "ZONE_CHANGED_NEW_AREA", - "UPDATE_EXPANSION_LEVEL", - "DISABLE_XP_GAIN", - "ENABLE_XP_GAIN", - "UPDATE_EXHAUSTION", - "UPDATE_FACTION", - "COMBAT_TEXT_UPDATE", - }, F.Table.If(TXUI.IsRetail, { "SUPER_TRACKING_CHANGED" })) + F.Table.Join( + { + "PLAYER_ENTERING_WORLD", + "PLAYER_XP_UPDATE", + "QUEST_LOG_UPDATE", + "ZONE_CHANGED", + "ZONE_CHANGED_NEW_AREA", + "UPDATE_EXPANSION_LEVEL", + "DISABLE_XP_GAIN", + "ENABLE_XP_GAIN", + "UPDATE_EXHAUSTION", + "UPDATE_FACTION", + "COMBAT_TEXT_UPDATE", + "CVAR_UPDATE", + }, + F.Table.If(TXUI.IsRetail, { + "SUPER_TRACKING_CHANGED", + "HOUSE_LEVEL_FAVOR_UPDATED", + "CURRENT_HOUSE_INFO_RECIEVED", + "CURRENT_HOUSE_INFO_UPDATED", + }) + ) )