Skip to content

Commit

Permalink
Better display of buffs/debuffs info tooltips in Configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnpsp committed Dec 10, 2020
1 parent 80ca90c commit d5be78f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 47 deletions.
67 changes: 30 additions & 37 deletions Options/GridStatuses.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ Grid2Options.typeCategories = {}
-- Register a special derived label widget with a delete icon to the right, used in MakeStatusTitleOptions()
Grid2Options.statusTitleIconsOptions = {
size = 24, offsetx = -4, offsety = -2, anchor = 'TOPRIGHT',
{ image = "Interface\\AddOns\\Grid2Options\\media\\delete", tooltip = L["Delete this status"], func = function(info) Grid2Options:DeleteStatus(info.option.arg.status) end },
{ image = "Interface\\AddOns\\Grid2Options\\media\\delete", tooltip = L["Delete this status"], func = function(info) Grid2Options:DeleteStatusConfirm(info.option.arg.status) end },
}

-- Delete a status
function Grid2Options:DeleteStatusReal(status)
function Grid2Options:DeleteStatus(status)
local category = self:GetStatusCategory(status)
Grid2.db.profile.statuses[status.name] = nil
Grid2:UnregisterStatus(status)
Expand All @@ -57,11 +57,11 @@ function Grid2Options:DeleteStatusReal(status)
self:SelectGroup('statuses', category)
end

-- Delete a deletable status
function Grid2Options:DeleteStatus(status)
-- Delete a status after confirmation
function Grid2Options:DeleteStatusConfirm(status)
if status then
if next(status.indicators)==nil and not status:IsSuspended() then
Grid2Options:ConfirmDialog( L["Are you sure you want to delete this status ?"], function() Grid2Options:DeleteStatusReal(status) end )
Grid2Options:ConfirmDialog( L["Are you sure you want to delete this status ?"], function() Grid2Options:DeleteStatus(status) end )
else
Grid2Options:MessageDialog( L["This status cannot be deleted because is attached to some indicators or the status is not enabled for this character."] )
end
Expand Down Expand Up @@ -100,21 +100,16 @@ function Grid2Options:AddStatusCategoryOptions(catKey, category)
end
end

function Grid2Options:GetStatusDescription(status)
local dbx = status.dbx
if dbx.type == "buff" or dbx.type == "debuff" then
local spellId = tonumber(dbx.spellName)
if spellId then
local tip = Grid2Options.Tooltip
tip:ClearLines()
tip:SetHyperlink("spell:"..spellId)
local count = tip:NumLines()
if count>1 and count<=10 then
return tip[count]:GetText()
end
function Grid2Options:GetStatusTooltipText(status, params)
if not (params and params.titleDesc) then
local dbx = status.dbx
if dbx.type == "buff" or dbx.type == "debuff" then
return tonumber(dbx.spellName) and "spell:"..dbx.spellName
elseif dbx.type == 'buffs' and dbx.subType == "blizzard" then
return L["Show relevant buffs for each unit frame (the same buffs displayed by the Blizzard raid frames)."]
end
elseif dbx.type == 'buffs' and dbx.subType == "blizzard" then
return L["Show relevant buffs for each unit frame (the same buffs displayed by the Blizzard raid frames)."]
else
return params.titleDesc
end
end

Expand All @@ -133,18 +128,19 @@ end

-- Calculate status information necessary to create the status and group options
do
local iconCoords = { 0.05, 0.95, 0.05, 0.95 }
function Grid2Options:GetStatusInfo(status)
local params = self.optionParams[status.dbx.type]
if not ( params and params.masterStatus and params.masterStatus ~= status.name ) then
local iconCoords, emptyTable = { 0.05, 0.95, 0.05, 0.95 }, {}
function Grid2Options:GetStatusInfo(status, params)
params = params or self.optionParams[status.dbx.type] or {}
if not (params.masterStatus and params.masterStatus ~= status.name ) then
local catKey = self:GetStatusCategory(status)
local catGroup = self.statusesOptions[catKey]
if catGroup then
local name, desc, icon, coords, _
local name, desc, icon, coords, deletable, _
local category = self.categories[catKey]
local dbx = status.dbx
if dbx.type == "buff" or dbx.type == "debuff" then
name,_,icon = GetSpellInfo( tonumber(dbx.spellName) or dbx.spellName )
local spellID = tonumber(dbx.spellName)
name,_,icon = GetSpellInfo( spellID or dbx.spellName )
desc = string.format( "%s: %s", L[dbx.type], name or dbx.spellName )
elseif dbx.type == "buffs" then
desc = L["Buffs Group"]
Expand All @@ -155,10 +151,11 @@ do
desc = L[dbx.type]
end
name = self.LocalizeStatus(status, true)
desc = desc or (params and params.title) or L["Options for %s."]:format(name)
icon = icon or (params and params.titleIcon) or category.icon
coords = params and params.titleIconCoords or iconCoords
return catGroup, name, desc, icon, coords, params
desc = desc or params.title or L["Options for %s."]:format(name)
icon = icon or params.titleIcon or category.icon
coords = params.titleIconCoords or iconCoords
deletable = type(params.isDeletable)=='function' and params.isDeletable(status) or params.isDeletable
return catGroup, name, desc, icon, coords, deletable, params
end
end
end
Expand All @@ -185,19 +182,15 @@ end
-- Add a title option to the status options
function Grid2Options:MakeStatusTitleOptions(status, options, optionParams)
if not options.title then
local _, name, desc, icon, iconCoords = self:GetStatusInfo(status)
local isDeletable = optionParams and optionParams.isDeletable
if type(isDeletable)=='function' then
isDeletable = isDeletable(status)
end
local cat, name, desc, icon, iconCoords, deletable = self:GetStatusInfo(status, optionParams)
self:MakeTitleOptions(
options,
fmt( "%s |cFF8681d1[%s]|r", name, self:GetStatusCompIndicatorsText(status) ),
desc,
optionParams and optionParams.titleDesc or self:GetStatusDescription(status),
self:GetStatusTooltipText(status, optionParams),
icon,
iconCoords,
isDeletable and { status = status, icons = Grid2Options.statusTitleIconsOptions }
deletable and { status = status, icons = Grid2Options.statusTitleIconsOptions }
)
end
end
Expand Down Expand Up @@ -249,7 +242,7 @@ end

-- Creates the parent group option and the options of the status in AceConfigTable
function Grid2Options:MakeStatusOptions(status)
local catGroup, name, desc, icon, coords, params = self:GetStatusInfo(status)
local catGroup, name, desc, icon, coords, deletable, params = self:GetStatusInfo(status)
if catGroup then
local order = params and params.groupOrder
local group = catGroup.args[status.name]
Expand Down
6 changes: 3 additions & 3 deletions Options/GridUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ end
do
local titleCoords = { 0.05, 0.95, 0.05, 0.95 }
local titleMask = NORMAL_FONT_COLOR_CODE .. "%s|r\n%s"
function Grid2Options:MakeTitleOptions(options, title, subtitle, desc, icon, coords, arg)
function Grid2Options:MakeTitleOptions(options, title, subtitle, tipText, icon, coords, arg)
options.title = {
type = "description", order = 0, width = "full", fontSize = "large", dialogControl = "Grid2Title",
image = icon, imageWidth = 34, imageHeight = 34, imageCoords = coords or titleCoords,
name = string.format(titleMask, title, subtitle),
desc = desc,
arg = arg, -- optional argument to inject action icons configuration, see Grid2Title widget in GridWidget.lua
desc = tipText,
arg = arg, -- optional argument to inject action icons configuration, see Grid2Title widget in GridWidget.lua
}
end
end
Expand Down
29 changes: 23 additions & 6 deletions Options/GridWidgets.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
-------------------------------------------------------------------------------------------------
-- Grid2 AceGUI widgets to be used in AceConfigTables, using dialogControl property.
-------------------------------------------------------------------------------------------------

local AceGUI= LibStub("AceGUI-3.0", true)

-------------------------------------------------------------------------------------------------
Expand All @@ -24,13 +28,21 @@ do
end

-------------------------------------------------------------------------------------------------
-- Custom "description" AceConfigDialog control
-- Title displayed on top of the configuration panel for items like statuses, indicators, etc
-- optional action icons displayed on the top right can be defined
-- {
-- optional action icons displayed on the top right can be defined.
-- AceConfigTable option usage example:
-- iconsTable = {
-- size = 32, padding = 2, spacing = 4 , offsetx = 0, offsety = 0, anchor = 'TOPRIGHT',
-- [1] = { image = "Path to icon texture", tooltip = "Delete Item", func = deleteFunction },
-- [2] = { image = "Path to icon texture", tooltip = 'Create Item', func = createFunction },
-- } )
-- description = {
-- type = "description", dialogControl = "Grid2Title",
-- order = 0, width = "full", fontSize = "large",
-- image = icon, imageWidth = 34, imageHeight = 34, name = "Title", desc = "Tooltip",
-- arg = iconsTable || { icons = iconsTable },
-- }
-------------------------------------------------------------------------------------------------
do
local Type, Version = "Grid2Title", 1
Expand All @@ -42,7 +54,11 @@ do
tooltip:ClearAllPoints()
tooltip:SetPoint("TOP",frame,"BOTTOM", 0, -8)
tooltip:ClearLines()
tooltip:SetText( text , 1, 1, 1, 1, true)
if text:find( "^spell:%d+$" ) then
tooltip:SetHyperlink(text)
else
tooltip:SetText( text , 1, 1, 1, 1, true)
end
tooltip:Show()
end

Expand Down Expand Up @@ -72,7 +88,7 @@ do
end
end

-- create action icons when userdata configuration is available (is set by AceConfigDialog after widget creation)
-- create action icons when AceConfigTable userdata configuration is available
local function OnShow(frame)
local self = frame.obj
local options = self.userdata and self.userdata.option
Expand Down Expand Up @@ -143,8 +159,9 @@ do
local iconSize = options.size or 32
local offsetx = options.offsetx or 0
local offsety = options.offsety or 0
local anchor = options.anchor or 'TOPRIGHT'
local imgSize = iconSize - (options.padding or 0)*2
local multx = string.find(options.anchor,'LEFT') and (iconSize+spacing) or -(iconSize+spacing)
local multx = string.find(anchor,'LEFT') and (iconSize+spacing) or -(iconSize+spacing)
for i,option in ipairs(options) do
local icon = AceGUI:Create("Icon")
icon.index = i
Expand All @@ -157,7 +174,7 @@ do
icon:SetCallback( "OnEnter", OnIconEnter )
icon:SetCallback( "OnLeave", OnLeave )
icon.frame:SetParent( self.frame )
icon.frame:SetPoint( options.anchor, (i-1)*multx+offsetx, offsety )
icon.frame:SetPoint( anchor, (i-1)*multx+offsetx, offsety )
icon.image:ClearAllPoints()
icon.image:SetPoint( "CENTER" )
icon.frame:Show()
Expand Down
1 change: 0 additions & 1 deletion modules/IndicatorMultiBar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ end
--- }}}

local function Create(indicatorKey, dbx)

local Bar = Grid2.indicators[indicatorKey] or Grid2.indicatorPrototype:new(indicatorKey)
Bar.dbx = dbx
-- Hack to caculate status index fast: statuses[priorities[status]] == status
Expand Down

0 comments on commit d5be78f

Please sign in to comment.