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
1 change: 1 addition & 0 deletions Localization/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ L["ASSIGN_ENTRY_TO_VIEWER_DESC"] = "Assign entry to viewer"

L["VISIBILITY"] = "Visibility"
L["VISIBILITY_DESC"] = "When to show all CDM viewers. Tick the states where the bar should be visible; untick to hide in that state. Default: shown everywhere."
L["RESOURCE_BARS_VISIBILITY_DESC"] = "Hide resource bars based on mount status. Also works for druid Travel Form."
L["VISIBILITY_COMBAT"] = "Combat"
L["VISIBILITY_COMBAT_DESC"] = "Show only in combat, only out of combat, or both (leave both unchecked)."
L["SHOW_IN_COMBAT"] = "Show in combat"
Expand Down
60 changes: 60 additions & 0 deletions Modules/ResourceBars/ResourceBars.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ local DEFAULTS_SEGMENTED = {
local defaults = {
enabled = true,
throttleInterval = 0.1,
visibility = {
hideWhenMounted = false,
hideWhenMountedWhen = "both",
},
resourceColours = {},
classColours = {},
resourceBarAnchorConfig = nil,
Expand Down Expand Up @@ -186,6 +190,13 @@ function module:OnEnable()
self:RegisterPowerEvents()
-- Listen for UI scale changes to refresh pixel-perfect elements
self:RegisterMessage("TavernUI_UIScaleChanged", "OnUIScaleChanged")
-- Register visibility callback for mount/vehicle hiding
if TavernUI.Visibility and TavernUI.Visibility.RegisterCallback and not self._visibilityCallbackId then
self._visibilityCallbackId = TavernUI.Visibility.RegisterCallback(function()
if self:IsEnabled() then self:OnVisibilityChanged() end
end)
end
self:OnVisibilityChanged()
end

function module:OnUIScaleChanged()
Expand All @@ -195,10 +206,16 @@ end
function module:OnDisable()
self:UnregisterAllEvents()
self:ClearAllBars()
if self._visibilityCallbackId and TavernUI.Visibility then
TavernUI.Visibility.UnregisterCallback(self._visibilityCallbackId)
self._visibilityCallbackId = nil
end
end

function module:OnProfileChanged()
self._hiddenByVisibility = nil
self:RebuildActiveBars()
self:OnVisibilityChanged()
end

function module:OnPlayerEnteringWorld()
Expand All @@ -215,6 +232,44 @@ function module:OnShapeshiftFormChanged()
end
end

function module:ShouldHideByVisibility()
local Visibility = TavernUI and TavernUI.Visibility
if not Visibility then return false end

-- Check ResourceBars' own visibility config
local config = self:GetSetting("visibility")
if config and not Visibility.ShouldShow(config) then return true end

-- Also respect uCDM's mount visibility so one toggle hides everything
local ucdm = TavernUI:GetModule("uCDM", true)
if ucdm and ucdm.GetSetting then
local ucdmConfig = ucdm:GetSetting("general.visibility")
if ucdmConfig and ucdmConfig.hideWhenMounted then
local mountConfig = {
hideWhenMounted = ucdmConfig.hideWhenMounted,
hideWhenMountedWhen = ucdmConfig.hideWhenMountedWhen,
}
if not Visibility.ShouldShow(mountConfig) then return true end
end
end

return false
end

function module:OnVisibilityChanged()
if self:ShouldHideByVisibility() then
for _, bar in pairs(bars) do
if bar.Hide then bar:Hide() end
end
self._hiddenByVisibility = true
elseif self._hiddenByVisibility then
self._hiddenByVisibility = nil
for barId in pairs(bars) do
self:UpdateBar(barId)
end
end
end

function module:RebuildActiveBars()
if not self:IsEnabled() then
return
Expand Down Expand Up @@ -543,6 +598,11 @@ function module:UpdateBar(barId)
return
end

if self._hiddenByVisibility then
bars[barId]:Hide()
return
end

bars[barId].config = self:GetBarConfig(barId)
local config = bars[barId].config
if config[CONSTANTS.KEY_ENABLED] == false then
Expand Down
48 changes: 48 additions & 0 deletions Modules/ResourceBars/ResourceBars_Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,10 @@ local function BuildClassColoursOptions()
end

function Options:Initialize()
local function onVisibilitySettingChanged()
if module.OnVisibilityChanged then module:OnVisibilityChanged() end
end

local args = {
general = {
type = "group",
Expand Down Expand Up @@ -1476,6 +1480,50 @@ function Options:Initialize()
module:SetSetting("throttleInterval", value)
end,
},
visibilityHeader = {
type = "header",
name = L["VISIBILITY"],
order = 10,
},
visibilityDesc = {
type = "description",
name = L["RESOURCE_BARS_VISIBILITY_DESC"],
order = 11,
fontSize = "small",
},
hideWhenMounted = {
type = "toggle",
name = L["HIDE_WHEN_MOUNTED"],
order = 12,
get = function()
return module:GetSetting("visibility.hideWhenMounted", false)
end,
set = function(_, value)
module:SetSetting("visibility.hideWhenMounted", value)
onVisibilitySettingChanged()
end,
},
hideWhenMountedWhen = {
type = "select",
name = L["HIDE_WHEN_MOUNTED_WHEN"],
desc = L["HIDE_WHEN_MOUNTED_WHEN_DESC"],
order = 13,
values = {
both = L["VISIBILITY_WHEN_BOTH"],
grounded = L["VISIBILITY_WHEN_GROUNDED"],
flying = L["VISIBILITY_WHEN_FLYING"],
},
get = function()
return module:GetSetting("visibility.hideWhenMountedWhen", "both")
end,
set = function(_, value)
module:SetSetting("visibility.hideWhenMountedWhen", value)
onVisibilitySettingChanged()
end,
disabled = function()
return not module:GetSetting("visibility.hideWhenMounted", false)
end,
},
},
},
health = {
Expand Down
30 changes: 29 additions & 1 deletion visibility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ local lastMounted, lastFlying
local pollTimer = nil
local POLL_INTERVAL = 0.5

local playerClass
local TRAVEL_FORM_SPELL_ID = 783
local MOUNT_FORM_SPELL_ID = 210053

local function IsInDruidTravelForm()
if not playerClass then
playerClass = select(2, UnitClass("player"))
end
if playerClass ~= "DRUID" then return false end
return C_UnitAuras.GetPlayerAuraBySpellID(TRAVEL_FORM_SPELL_ID) ~= nil
or C_UnitAuras.GetPlayerAuraBySpellID(MOUNT_FORM_SPELL_ID) ~= nil
end

local function UpdateCache()
cache.inCombat = UnitAffectingCombat("player")
cache.hasTarget = UnitExists("target")
Expand All @@ -24,7 +37,7 @@ local function UpdateCache()
cache.groupRaid = IsInRaid()
cache.instanceType = select(2, GetInstanceInfo()) or "none"
cache.role = UnitGroupRolesAssigned("player") or "NONE"
cache.mounted = IsMounted()
cache.mounted = IsMounted() or IsInDruidTravelForm()
cache.flying = IsFlying()
cache.inVehicle = UnitInVehicle("player")
end
Expand Down Expand Up @@ -146,11 +159,26 @@ function Visibility.Initialize()
eventFrame:RegisterEvent("ZONE_CHANGED_NEW_AREA")
eventFrame:RegisterEvent("GROUP_ROSTER_UPDATE")
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
eventFrame:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
eventFrame:RegisterUnitEvent("UNIT_FLAGS", "player")
eventFrame:RegisterUnitEvent("UNIT_AURA", "player")
eventFrame:SetScript("OnEvent", function(f, event, arg1)
if event == "UNIT_ENTERED_VEHICLE" or event == "UNIT_EXITED_VEHICLE" then
if arg1 ~= "player" then return end
end
-- UNIT_AURA fires frequently; only check mount/flying state, skip full cache update
if event == "UNIT_AURA" then
local mounted = IsMounted() or IsInDruidTravelForm()
local flying = IsFlying()
if mounted ~= cache.mounted or flying ~= cache.flying then
cache.mounted = mounted
cache.flying = flying
lastMounted, lastFlying = mounted, flying
SyncMountPoll()
NotifyCallbacks()
end
return
end
OnEvent(f, event)
end)
UpdateCache()
Expand Down