--[[ Author: Jarth Filename: CBs_Helpers.lua ]] -- ------------------------------------------------------------------------------------------------- -- VARIABLES -- ------------------------------------------------------------------------------------------------- local base = CollectionBars local texts = base.Texts ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- function base.GetLocationValue(value) local result if value == texts.Location.Bottom then result = BOTTOM elseif value == (texts.Location.Bottom .. texts.Location.Left) then result = BOTTOMLEFT elseif value == (texts.Location.Bottom .. texts.Location.Right) then result = BOTTOMRIGHT elseif value == texts.Location.Center then result = CENTER elseif value == texts.Location.Left then result = LEFT elseif value == texts.Location.Right then result = RIGHT elseif value == texts.Location.Top then result = TOP elseif value == (texts.Location.Top .. texts.Location.Left) then result = TOPLEFT elseif value == (texts.Location.Top .. texts.Location.Right) then result = TOPRIGHT end return result end function base.GetLocationText(value) local result if value == BOTTOM then result = texts.Location.Bottom elseif value == BOTTOMLEFT then result = (texts.Location.Bottom .. texts.Location.Left) elseif value == BOTTOMRIGHT then result = (texts.Location.Bottom .. texts.Location.Right) elseif value == CENTER then result = texts.Location.Center elseif value == LEFT then result = texts.Location.Left elseif value == RIGHT then result = texts.Location.Right elseif value == TOP then result = texts.Location.Top elseif value == TOPLEFT then result = (texts.Location.Top .. texts.Location.Left) elseif value == TOPRIGHT then result = (texts.Location.Top .. texts.Location.Right) end return result end function base.RestorePosition(_type) _type.Frame:ClearAnchors() local combineFrame = base.Global.Combine.Frame if not _type.Saved.IsCombined or not combineFrame then _type.Frame:SetAnchor(_type.Saved.Label.PositionTarget, GuiRoot, TOPLEFT, _type.Saved.X, _type.Saved.Y) elseif _type.Saved.IsCombined then if not _type.Saved.HideAll then _type.Frame:SetAnchorFill(combineFrame) else _type.Frame:SetAnchor(TOPLEFT, combineFrame, TOPLEFT, 0, 0) end end end function base.GetLabelPostFix(_type) local postFix = texts.EmptyString if _type.Saved.HideAllEnabled then if not _type.Saved.HideAll then postFix = texts.Helpers.Space .. texts.Helpers.Minus else postFix = texts.Helpers.Space .. texts.Helpers.Plus end end return postFix end function base.IsAllSelected(_type) local isAllSelected = true for _, collectible in pairs(_type.Category) do if _type.Saved.Selected[collectible.Id] == nil then isAllSelected = false break end end return isAllSelected end function base.SelectAll(_type, newValue) for _, collectible in pairs(_type.Category) do if newValue == true then _type.Saved.Selected[collectible.Id] = newValue else _type.Saved.Selected[collectible.Id] = nil end end end function base.GetVersion(showMinor) if showMinor == false or base.Addon.MinorVersion == nil then return tostring(base.Addon.Version) end return tostring(base.Addon.Version) .. texts.Helpers.Dot .. tostring(base.Addon.MinorVersion) end function base.SetAndUpdateAccountSettings(newUseAccountSettings) local accountKey = base.Addon.Name .. texts.Helpers.Lowdash .. texts.Components.Account base.Saved = ZO_SavedVars:NewAccountWide(accountKey, base.Addon.Version, nil, base.Default) if newUseAccountSettings ~= nil then base.Saved.UseAccountSettings = newUseAccountSettings end local useAccountSettings = base.Saved.UseAccountSettings if not useAccountSettings then local characterKey = base.Addon.Name .. texts.Helpers.Lowdash .. texts.Components.Character base.Saved = ZO_SavedVars:New(characterKey, base.Addon.Version, nil, base.Default) base.Saved.UseAccountSettings = useAccountSettings end end function base.ResetAccountSettings() if base.Saved.UseAccountSettings then local accountKey = base.Addon.Name .. texts.Helpers.Lowdash .. texts.Components.Account _G[accountKey] = nil base.Saved = ZO_SavedVars:NewAccountWide(accountKey, base.Addon.Version, nil, base.Default) else local characterKey = base.Addon.Name .. texts.Helpers.Lowdash .. texts.Components.Character _G[characterKey] = nil base.Saved = ZO_SavedVars:New(characterKey, base.Addon.Version, nil, base.Default) end end function base.GetBarWidthHeight(_type) local width, height, count = 0, 0, 0 if not _type.Saved.HideAll then for key, value in pairs(_type.Saved.Selected) do if IsCollectibleUnlocked(key) and IsCollectibleValidForPlayer(key) and value then count = count + 1 end end end local function GetBarMaxCount(type) local barConstraintXY = _type.Saved[type] if _type.Saved.IsCombined then barConstraintXY = base.Saved.Combine[type] end if barConstraintXY == 0 then barConstraintXY = base.Saved[type] end if count < barConstraintXY then barConstraintXY = count end return barConstraintXY end _type.BarDepth, _type.BarWidth = GetBarMaxCount(texts.Type.BarDepth), GetBarMaxCount(texts.Type.BarWidth) if count > 0 then local barWidth = math.ceil(count / _type.BarDepth) local maxBarWidth = _type.BarWidth if maxBarWidth > 0 and maxBarWidth < barWidth then barWidth = maxBarWidth end local isHorizontal = _type.Saved.Horizontal width = base.Saved.ButtonXY * (not isHorizontal and barWidth or _type.BarDepth) height = base.Saved.ButtonXY * (isHorizontal and barWidth or _type.BarDepth) end return width, height end function base.SetFrameSizeIfExists(frame, width, height) if frame ~= nil then frame:SetHeight(height) frame:SetWidth(width) end end function base.HasAny(array) for _ in pairs(array) do return true end return false end function base.SetControlText(control, text) control.SetText(control, text) end