Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Modules/Options/WunderBar/SubModules/DataBar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
188 changes: 169 additions & 19 deletions Modules/WunderBar/SubModules/DataBar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ DB.const = {
mode = {
["rep"] = 0,
["exp"] = 1,
["housing"] = 2,
},
}

Expand All @@ -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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you looked at /etrace to see if there's an event that fires when housing data is ready?

C_Timer.After(3, function()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use E:Delay(), same syntax and same functionality, just a preference

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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Event is registered only for Retail, so additional and TXUI.IsRetail is unnecessary imo

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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -139,7 +163,7 @@ function DB:OnEvent(event)
self:UpdateBar()
end)

-- Experience
-- Experience
elseif
(self.mode == DB.const.mode.exp)
and not self.updateExpNextOutOfCombat
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -241,11 +319,54 @@ function DB:UpdateExperienceTooltip()
DT.tooltip:Show()
end

function DB:UpdateHousingTooltip()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the OnClick event reflected in the housing tooltip

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
Expand Down Expand Up @@ -275,6 +396,10 @@ function DB:OnLeave()
end

function DB:OnClick()
if self.mode == DB.const.mode.housing and TXUI.IsRetail then

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary and TXUI.IsRetail

if not _G.HousingDashboardFrame or not _G.HousingDashboardFrame:IsShown() then _G.HousingFramesUtil.ToggleHousingDashboard() end

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to check for IsShown(). The function toggles the dashboard eitherway, should allow the user to both open and close the dashboard via click.

return
end
if self.mode ~= DB.const.mode.rep then return end

local dtModule = WB:GetElvUIDataText("Reputation")
Expand All @@ -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
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self.db.mode == "housing" and TXUI.IsRetail then
if self.db.mode == "housing" 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
Expand Down Expand Up @@ -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)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is getting difficult to read, can we move the logic outside the E:Round() function for better readability?

.. "%"
)
else
self.infoText:SetText("")
end
Expand Down Expand Up @@ -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
Expand All @@ -514,6 +651,9 @@ function DB:OnInit()
currentXP = 0,
xpToLevel = 0,
restedXP = 0,
housingLevel = 1,
housingFavor = 0,
housingPercentage = 0,
}

self:CreateBar()
Expand All @@ -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",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since CVAR_UPDATE is currently used exclusively for housing, let's move it to retail's table

},
F.Table.If(TXUI.IsRetail, {
"SUPER_TRACKING_CHANGED",
"HOUSE_LEVEL_FAVOR_UPDATED",
"CURRENT_HOUSE_INFO_RECIEVED",
"CURRENT_HOUSE_INFO_UPDATED",
})
)
)
Loading