--[[ Author: Jarth Filename: CBs_Labels.lua ]] -- ------------------------------------------------------------------------------------------------- -- VARIABLES -- ------------------------------------------------------------------------------------------------- local base = CollectionBars local texts = base.Texts ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- function base.SetupLabel(_type) local hideAllId = base.Addon.Abbreviation .. texts.Helpers.Lowdash .. texts.Components.HideAll if _type.FrameLabel == nil then _type.FrameLabel = GetControl(hideAllId .. _type.Name) if _type.FrameLabel == nil then _type.FrameLabel = base.WM:CreateControlFromVirtual(hideAllId, _type.Frame, hideAllId, _type.Name) end end _type.FrameLabel:SetHidden(not _type.Saved.LabelShow and not _type.Saved.IsCombined) _type.FrameToggleSettings = GetControl(hideAllId .. _type.Name .. texts.Components.Toggle .. texts.Components.Settings) _type.FrameLabelButton = GetControl(hideAllId .. _type.Name .. texts.Components.Button) if _type.FrameLabelButton ~= nil then _type.FrameLabelButton:SetHandler(texts.Action.OnClicked, function(_, button) if button == MOUSE_BUTTON_INDEX_RIGHT then base.ToggleEnableSettings() elseif button == MOUSE_BUTTON_INDEX_LEFT and _type.Saved.HideAllEnabled or _type.Saved.IsCombined then _type.Saved.HideAll = not _type.Saved.HideAll if _type.Saved.IsCombined then base.HideOthers(_type) end base.RestoreFrame(_type) base.RestoreCombine() end end) end base.SetupToggleSettings(_type) end function base.RestoreLabel(_type) local label = _type.Saved.Label local frameLabel = _type.FrameLabel if frameLabel ~= nil then frameLabel:ClearAnchors() frameLabel:SetHeight(label.Height) frameLabel:SetWidth(label.Width) if not _type.Saved.IsCombined then frameLabel:SetAnchor(label.Position, _type.Frame, label.PositionTarget, label.OffsetX, label.OffsetY) end frameLabel:SetHidden(not _type.Saved.LabelShow and not _type.Saved.IsCombined and not base.Global.EnableSettings) end local frameLabelButton = _type.FrameLabelButton if frameLabelButton ~= nil then frameLabelButton:SetHidden(false) frameLabelButton:SetFont(label.Font) frameLabelButton:SetHorizontalAlignment(TEXT_ALIGN_LEFT) frameLabelButton:SetVerticalAlignment(TOP) frameLabelButton:SetText(tostring(_type.Saved.Display) .. base.GetLabelPostFix(_type)) end local frameLabelToggleSettings = _type.FrameToggleSettings if frameLabelToggleSettings ~= nil then frameLabelToggleSettings:SetHidden(false) end end function base.RemoveLabel(_type) if _type.FrameLabel ~= nil then _type.FrameLabel:ClearAnchors() _type.FrameLabel:SetHidden(true) end if _type.FrameLabelButton ~= nil then _type.FrameLabelButton:SetHidden(true) end if _type.FrameToggleSettings ~= nil then _type.FrameToggleSettings:SetHidden(true) end end function base.RestoreCombineLabels() local combineLabel = base.Saved.Combine.Label local width = 0 local height = 0 for _, _type in pairs(base.TypesOrdered) do if _type.Saved.Enabled and _type.Saved.IsCombined and _type.FrameLabel then if (not _type.IsEmpty or base.Global.EnableSettings) then local hasSelected = not base.HasAny(_type.Saved.Selected) _type.FrameLabel:ClearAnchors() _type.FrameLabel:SetHidden(not hasSelected and not _type.Saved.LabelShow and not base.Global.EnableSettings) if not _type.FrameLabel:IsHidden() or (_type.Saved.LabelShow and hasSelected) or base.Global.EnableSettings then width = width + _type.Saved.Label.OffsetX local offsetY = _type.Saved.Label.OffsetY + combineLabel.OffsetY _type.FrameLabel:SetAnchor(TOPLEFT, base.Global.Combine.HideAll, TOPLEFT, width, offsetY) width = width + _type.FrameLabel:GetWidth() local labelHeight = _type.FrameLabel:GetHeight() if labelHeight > height then height = labelHeight end end end end end local frame = base.Global.Combine.HideAll if frame ~= nil and base.Global.Combine.Frame ~= nil then frame:ClearAnchors() frame:SetWidth(width) frame:SetHeight(height) frame:SetAnchor(combineLabel.Position, base.Global.Combine.Frame, combineLabel.PositionTarget, combineLabel.OffsetX, combineLabel.OffsetY) end end