Skip to content

Commit

Permalink
[Feature] Add support for macro conditional visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Krealle committed Nov 27, 2024
1 parent 038cd12 commit 98d4342
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cell_UnitFrames.toc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Menu/UnitFramesTab.lua
Menu/WidgetsTab.lua
Menu/FaderTab.lua
Menu/ColorTab.lua
Menu/VisibilityTab.lua

Widgets/Common.lua

Expand Down
7 changes: 7 additions & 0 deletions Data/Defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ Defaults.Widgets_Boss.castBar.spell.offsetX = 0
---@field alwaysUpdate boolean?
---@field healthBarColorType UnitButtonColorType
---@field healthLossColorType UnitButtonColorType
---@field visibility string

---@alias UnitLayoutTable table<Unit, UnitLayout>
---@type UnitLayoutTable
Expand All @@ -859,6 +860,7 @@ Defaults.Layouts = {
powerFilter = false,
healthBarColorType = CUF.constants.UnitButtonColorType.CELL,
healthLossColorType = CUF.constants.UnitButtonColorType.CUSTOM,
visibility = "[petbattle] hide;show"
},
target = {
enabled = false,
Expand Down Expand Up @@ -891,6 +893,7 @@ Defaults.Layouts = {
powerFilter = false,
healthBarColorType = CUF.constants.UnitButtonColorType.CELL,
healthLossColorType = CUF.constants.UnitButtonColorType.CUSTOM,
visibility = ""
},
focus = {
enabled = false,
Expand Down Expand Up @@ -930,6 +933,7 @@ Defaults.Layouts = {
powerFilter = false,
healthBarColorType = CUF.constants.UnitButtonColorType.CELL,
healthLossColorType = CUF.constants.UnitButtonColorType.CUSTOM,
visibility = ""
},
targettarget = {
enabled = false,
Expand Down Expand Up @@ -959,6 +963,7 @@ Defaults.Layouts = {
alwaysUpdate = true,
healthBarColorType = CUF.constants.UnitButtonColorType.CELL,
healthLossColorType = CUF.constants.UnitButtonColorType.CUSTOM,
visibility = ""
},
pet = {
enabled = false,
Expand Down Expand Up @@ -994,6 +999,7 @@ Defaults.Layouts = {
powerFilter = false,
healthBarColorType = CUF.constants.UnitButtonColorType.CELL,
healthLossColorType = CUF.constants.UnitButtonColorType.CUSTOM,
visibility = ""
},
boss = {
enabled = false,
Expand All @@ -1020,6 +1026,7 @@ Defaults.Layouts = {
},
healthBarColorType = CUF.constants.UnitButtonColorType.CELL,
healthLossColorType = CUF.constants.UnitButtonColorType.CUSTOM,
visibility = ""
}
}

Expand Down
90 changes: 90 additions & 0 deletions Menu/VisibilityTab.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---@class CUF
local CUF = select(2, ...)

local Cell = CUF.Cell
local L = CUF.L

local DB = CUF.DB
local const = CUF.constants

---@class CUF.Menu
local Menu = CUF.Menu

local unitFramesTab = Menu.unitFramesTab

---@class VisibilityTab: Menu.Tab
local VisibilityTab = {}
VisibilityTab.id = "Visibility"
VisibilityTab.height = 90
VisibilityTab.paneHeight = 17

unitFramesTab:AddTab(VisibilityTab)

-------------------------------------------------
-- MARK: Show/Hide
-------------------------------------------------

---@param unit Unit
function VisibilityTab:ShowTab(unit)
if not self.window then
self:Create()

self.window:Show()
self.LoadUnit(unit)
return
end

self.window:Show()
self.LoadUnit(unit)
end

function VisibilityTab:HideTab()
if not self.window or not self.window:IsShown() then return end
self.window:Hide()
end

function VisibilityTab:IsShown()
return self.window and self.window:IsShown()
end

---@param unit Unit
function VisibilityTab.LoadUnit(unit)
if not VisibilityTab:IsShown() then return end
unit = unit or CUF.vars.selectedUnit

local visibility = DB.SelectedLayoutTable()[unit].visibility
VisibilityTab.unit = unit

VisibilityTab.visibilityEditBox:SetText(visibility)
end

CUF:RegisterCallback("LoadPageDB", "FaderTab_LoadUnit", VisibilityTab.LoadUnit)

-------------------------------------------------
-- MARK: Create
-------------------------------------------------

function VisibilityTab:Create()
local sectionWidth = unitFramesTab.tabAnchor:GetWidth()

self.window = CUF:CreateFrame("CUF_Menu_UnitFrame_Fader", unitFramesTab.window,
sectionWidth,
self.height, true)
self.window:SetPoint("TOPLEFT", unitFramesTab.tabAnchor, "TOPLEFT")
self.unit = const.UNIT.PLAYER

local checkBoxSection = CUF:CreateFrame("CUF_Menu_UnitFrame_Fader_CheckBoxSection", self.window, sectionWidth - 10,
65, false, true)
checkBoxSection:SetPoint("TOPLEFT", self.window, "TOPLEFT", 5, -5)

local visibilityEditBox = CUF:CreateEditBox(checkBoxSection, checkBoxSection:GetWidth() - 20, 30, L.Visibility)

Check warning on line 80 in Menu/VisibilityTab.lua

View workflow job for this annotation

GitHub Actions / LUA

undefined-field

Undefined field `Visibility`.
visibilityEditBox:SetPoint("TOPLEFT", 10, -25)
self.visibilityEditBox = visibilityEditBox

visibilityEditBox:SetScript("OnEnterPressed", function()
visibilityEditBox:ClearFocus()
local value = visibilityEditBox:GetText()
DB.SelectedLayoutTable()[self.unit].visibility = value
CUF:Fire("UpdateVisibility", self.unit)
end)
end
8 changes: 7 additions & 1 deletion UnitFrames/UnitButton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ function U:UpdateUnitFrameVisibility(which, unit, button, frame)
if InCombatLockdown() then return end
if not which or which == unit then
if CUF.DB.CurrentLayoutTable()[unit].enabled then
RegisterUnitWatch(button)
local visibility = DB.CurrentLayoutTable()[unit].visibility
if visibility ~= "" then
RegisterAttributeDriver(button, 'state-visibility',
"[@" .. button._unit .. ",noexists]hide;" .. visibility)
else
RegisterUnitWatch(button)
end
frame:Show()
else
UnregisterUnitWatch(button)
Expand Down

0 comments on commit 98d4342

Please sign in to comment.