-
Notifications
You must be signed in to change notification settings - Fork 20
📦 NEW: wb housing databar #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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() | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||||||
| 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 | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Event is registered only for Retail, so additional |
||||||
| 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() | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the |
||||||
| 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 | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary |
||||||
| if not _G.HousingDashboardFrame or not _G.HousingDashboardFrame:IsShown() then _G.HousingFramesUtil.ToggleHousingDashboard() end | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to check for |
||||||
| 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 | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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) | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
| .. "%" | ||||||
| ) | ||||||
| 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", | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||||||
| }, | ||||||
| F.Table.If(TXUI.IsRetail, { | ||||||
| "SUPER_TRACKING_CHANGED", | ||||||
| "HOUSE_LEVEL_FAVOR_UPDATED", | ||||||
| "CURRENT_HOUSE_INFO_RECIEVED", | ||||||
| "CURRENT_HOUSE_INFO_UPDATED", | ||||||
| }) | ||||||
| ) | ||||||
| ) | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you looked at
/etraceto see if there's an event that fires when housing data is ready?