--[[ Author: Jarth Filename: CBs_Labels.lua ]] -- ------------------------------------------------------------------------------------------------- -- VARIABLES -- ------------------------------------------------------------------------------------------------- local base = CollectionBars ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- function base.SetupLabel(_type) if _type.FrameLabel == nil then _type.FrameLabel = GetControl(base.Global.HideAllId .. _type.Name) if _type.FrameLabel == nil then _type.FrameLabel = base.WM:CreateControlFromVirtual(base.Global.HideAllId, _type.Frame, base.Global.HideAllId, _type.Name) _type.FrameLabel:SetDrawLevel(2) end end _type.FrameLabel:SetHidden(not _type.Saved.LabelShow and not _type.Saved.Combine) _type.FrameToggleSettings = GetControl(base.Global.HideAllId .. _type.Name .. "ToggleSettings") _type.FrameLabelButton = GetControl(base.Global.HideAllId .. _type.Name .. "Button") if _type.FrameLabelButton ~= nil then _type.FrameLabelButton:SetHandler( "OnClicked", function(_, button) if button == MOUSE_BUTTON_INDEX_LEFT then if _type.Saved.HideAllEnabled or _type.Saved.Combine then _type.Saved.HideAll = not _type.Saved.HideAll if _type.Saved.Combine then base.HideOther(_type) end base.RestoreFrame(_type) base.RestoreCombine() end elseif button == MOUSE_BUTTON_INDEX_RIGHT then base.ToggleEnableSettings() 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.Combine then frameLabel:SetAnchor(label.Position, _type.Frame, label.PositionTarget, label.OffsetX, label.OffsetY) end frameLabel:SetHidden(not _type.Saved.Combine and not _type.Saved.LabelShow) 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(_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 local positionTarget = combineLabel.PositionTarget local position = combineLabel.Position for _, _type in pairs(base.TypeOrdered) do if _type.Saved.Enabled and _type.Saved.Combine and _type.FrameLabel then if (not _type.IsEmpty or base.Global.EnableSettings) then _type.FrameLabel:ClearAnchors() _type.FrameLabel:SetHidden(not _type.Saved.Combine and not base.HasAny(_type.Saved.Selected) and not _type.Saved.LabelShow and not base.Global.EnableSettings) if not _type.FrameLabel:IsHidden() or (_type.Saved.LabelShow and base.HasAny(_type.Saved.Selected)) 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(position, base.Global.Combine.Frame, positionTarget, combineLabel.OffsetX, combineLabel.OffsetY) end end