Skip to content

Commit

Permalink
Now optionally the alpha/transparency indicator can be applied to a s…
Browse files Browse the repository at this point in the history
…pecific bar or multibar indicator instead of the whole unit frame.
  • Loading branch information
michaelnpsp committed Oct 2, 2024
1 parent 66ef030 commit 1830aef
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 23 deletions.
63 changes: 46 additions & 17 deletions Options/modules/indicators/IndicatorAlpha.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
local Grid2Options = Grid2Options

local L = Grid2Options.L

local function GetAvailableIndicatorValues()
local t = { [0] = L['Unit Frame'] }
for name, indicator in Grid2:IterateIndicators() do
if indicator.dbx.type=='multibar' or indicator.dbx.type=='bar' then
local option = Grid2Options.indicatorsOptions[name]
if option then t[name] = string.format("|T%s:0|t%s", option.icon, option.name) end
end
end
return t
end

Grid2Options:RegisterIndicatorOptions("alpha", false, function(self, indicator)
local options, statuses, filter = {}, {}, {}
self:MakeIndicatorAlphaOptions(indicator, options)
Expand All @@ -9,50 +22,66 @@ Grid2Options:RegisterIndicatorOptions("alpha", false, function(self, indicator)
end)

function Grid2Options:MakeIndicatorAlphaOptions(indicator,options)
options.header1 = { type = "header", order = 5, name = L["Default Alpha"] }
options.defaultAlpha = {
options.header0 = { type = "header", order = 1, name = L["General"] }
options.indicator = {
type = "select",
name = L["Apply transparency to"],
desc = L["Optionally you can choose to change the transparency of a specific indicator instead of the whole unit frame. Only bar style indicators are supported."],
order = 5,
get = function() return indicator.dbx.anchorTo or 0 end,
set = function(_,v)
for _,f in next, Grid2Frame.registeredFrames do
indicator:GetFrame(f):SetAlpha(1)
end
indicator.dbx.anchorTo = (v~=0) and v or nil
self:RefreshIndicator(indicator, "Update")
end,
values = GetAvailableIndicatorValues,
}
options.header1 = { type = "header", order = 10, name = L["Active Alpha"] }
options.alpha = {
type = "range",
order = 10,
order = 20,
width = "normal",
name = L["Default Alpha Value"],
desc = L["Alpha/opacity when the indicator is not activated.\n0 = full transparent\n1 = full opaque"],
name = L["Active Alpha Value"],
desc = L["Alpha/Opacity value to apply to the frame when the indicator is activated.\n0 = full transparent\n1 = full opaque"],
min = 0,
max = 1,
step = 0.01,
get = function () return indicator.dbx.defaultAlpha or 1 end,
get = function () return indicator.dbx.alpha or 0 end,
set = function (_, v)
indicator.dbx.defaultAlpha = v<.999 and v or nil
indicator.dbx.alpha = v
self:RefreshIndicator(indicator, "Update")
end,
disabled = function() return indicator.dbx.alpha==nil end,
}
options.header2 = { type = "header", order = 15, name = L["Active Alpha"] }
options.alphaMode = {
type = "toggle",
name = L["Use Status Alpha"],
desc = L["Check this option to use the alpha value provided by the active status."],
order = 40,
width = "normal",
order = 30,
width = 1.25,
tristate = false,
get = function () return indicator.dbx.alpha==nil end,
set = function (_, v)
indicator.dbx.alpha = (not v) and 0.4 or nil
self:RefreshIndicator(indicator, "Update")
end,
}
options.alpha = {
options.header2 = { type = "header", order = 40, name = L["Default Alpha"] }
options.defaultAlpha = {
type = "range",
order = 30,
order = 50,
width = "normal",
name = L["Active Alpha Value"],
desc = L["Alpha/Opacity value to apply to the frame when the indicator is activated.\n0 = full transparent\n1 = full opaque"],
name = L["Default Alpha Value"],
desc = L["Alpha/opacity when the indicator is not activated.\n0 = full transparent\n1 = full opaque"],
min = 0,
max = 1,
step = 0.01,
get = function () return indicator.dbx.alpha or 0 end,
get = function () return indicator.dbx.defaultAlpha or 1 end,
set = function (_, v)
indicator.dbx.alpha = v
indicator.dbx.defaultAlpha = v<.999 and v or nil
self:RefreshIndicator(indicator, "Update")
end,
disabled = function() return indicator.dbx.alpha==nil end,
}
end
29 changes: 24 additions & 5 deletions modules/IndicatorAlpha.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local Alpha = Grid2.indicatorPrototype:new("alpha")

local indicatorName
local defaultAlpha = 1
local enabledAlpha = 0.5

Expand All @@ -16,18 +17,36 @@ local function Alpha_OnUpdate2(self, parent, unit, status)
parent:SetAlpha(status and enabledAlpha or defaultAlpha)
end

-- standard indicator update, opacity value is provided by the active status
local function Alpha_OnUpdate3(self, parent, unit, status)
local target = parent[indicatorName] or parent
target:SetAlpha(status and status:GetPercent(unit) or defaultAlpha)
end

-- optional indicator update, alpha provided by the statuses is ignored and instead the opacity defined in the indicator setup is used
local function Alpha_OnUpdate4(self, parent, unit, status)
local target = parent[indicatorName] or parent
target:SetAlpha(status and enabledAlpha or defaultAlpha)
end

function Alpha:GetFrame(parent)
return parent
return parent[indicatorName] or parent
end

function Alpha:Disable(parent)
parent:SetAlpha(1)
self:GetFrame(parent):SetAlpha(1)
end

function Alpha:UpdateDB()
defaultAlpha = self.dbx.defaultAlpha or 1
enabledAlpha = self.dbx.alpha
self.OnUpdate = enabledAlpha and Alpha_OnUpdate2 or Alpha_OnUpdate1
local dbx = self.dbx
defaultAlpha = dbx.defaultAlpha or 1
enabledAlpha = dbx.alpha
indicatorName = dbx.anchorTo -- hackish, we need to use anchorTo fieldname to force the controlled indicator to be loaded before alpha indicator in GridSetup.lua
if indicatorName and Grid2.indicators[indicatorName] then
self.OnUpdate = enabledAlpha and Alpha_OnUpdate4 or Alpha_OnUpdate3
else
self.OnUpdate = enabledAlpha and Alpha_OnUpdate2 or Alpha_OnUpdate1
end
end

local function Create(indicatorKey, dbx)
Expand Down
2 changes: 1 addition & 1 deletion modules/IndicatorPrivateAuras.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ local function Icon_UpdateDB(self)
self.colCount = self.maxIcons
self.rowCount = 1
end
if self.dbx.disableTooltip then
if dbx.disableTooltip then
tooltipFrame = tooltipFrame or CreateFrame("Frame")
self.tooltipFrame = tooltipFrame
tooltipFrame:Show()
Expand Down

0 comments on commit 1830aef

Please sign in to comment.