--[[ 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.BottomLeft then result = BOTTOMLEFT elseif value == texts.Location.BottomRight 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.TopLeft then result = TOPLEFT elseif value == texts.Location.TopRight 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.BottomLeft elseif value == BOTTOMRIGHT then result = texts.Location.BottomRight 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.TopLeft elseif value == TOPRIGHT then result = texts.Location.TopRight end return result end function base.RestorePosition(category) category.Frame:ClearAnchors() local combineFrame = base.Global.Combine.Frame if not category.Saved.IsCombined or not combineFrame then category.Frame:SetAnchor(category.Saved.Label.PositionTarget, GuiRoot, TOPLEFT, category.Saved.X, category.Saved.Y) elseif category.Saved.IsCombined then if not category.Saved.HideAll then category.Frame:SetAnchorFill(combineFrame) else category.Frame:SetAnchor(TOPLEFT, combineFrame, TOPLEFT, 0, 0) end end end function base.GetLabelPostFix(category) local postFix = "" if category.Saved.HideAllEnabled then if not category.Saved.HideAll then postFix = " -" else postFix = " +" end end return postFix end function base.IsAllSelected(category) local isAllSelected = true for _, collectible in pairs(category.Collection) do if category.Saved.Selected[collectible.Id] == nil then isAllSelected = false break end end return isAllSelected end function base.SelectAll(category, newValue) for _, collectible in pairs(category.Collection) do if newValue == true then category.Saved.Selected[collectible.Id] = newValue else category.Saved.Selected[collectible.Id] = nil end end end function base.SetAndUpdateAccountSettings(newUseAccountSettings) base.Saved = ZO_SavedVars:NewAccountWide(texts.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 base.Saved = ZO_SavedVars:NewCharacterNameSettings(texts.CharacterKey, base.Addon.Version, nil, base.Default) base.Saved.UseAccountSettings = useAccountSettings end end function base.GetCharacterSettingsDisabledState() local result = BSTATE_DISABLED if base.Saved.UseAccountSettings and _G[texts.CharacterKey] ~= nil then result = BSTATE_NORMAL end return result == BSTATE_DISABLED end function base.ResetAccountSettings() if base.Saved.UseAccountSettings then _G[texts.AccountKey] = nil base.Saved = ZO_SavedVars:NewAccountWide(texts.AccountKey, base.Addon.Version, nil, base.Default) else _G[texts.CharacterKey] = nil base.Saved = ZO_SavedVars:NewCharacterNameSettings(texts.CharacterKey, base.Addon.Version, nil, base.Default) end end function base.RemoveCharacterSettings() if base.Saved.UseAccountSettings then _G[texts.CharacterKey] = nil end end function base.GetBarWidthHeight(category) local width, height, count = 0, 0, 0 if not category.Saved.HideAll then for key, value in pairs(category.Saved.Selected) do if IsCollectibleUnlocked(key) and IsCollectibleValidForPlayer(key) and value then count = count + 1 end end end local function GetBarMaxCount(constraint) local barConstraintXY = category.Saved[constraint] if category.Saved.IsCombined then barConstraintXY = base.Saved.Combine[constraint] end if barConstraintXY == 0 then barConstraintXY = base.Saved[constraint] end if count < barConstraintXY then barConstraintXY = count end return barConstraintXY end category.BarDepth, category.BarWidth = GetBarMaxCount("BarDepth"), GetBarMaxCount("BarWidth") if count > 0 then local barWidth = math.ceil(count / category.BarDepth) local maxBarWidth = category.BarWidth if maxBarWidth > 0 and maxBarWidth < barWidth then barWidth = maxBarWidth end local isHorizontal = category.Saved.Horizontal width = base.Saved.ButtonXY * (not isHorizontal and barWidth or category.BarDepth) height = base.Saved.ButtonXY * (isHorizontal and barWidth or category.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