--[[ Author: Jarth Filename: CollectionBars.lua ]] -- ------------------------------------------------------------------------------------------------- -- VARIABLES -- ------------------------------------------------------------------------------------------------- local base = CollectionBars ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- function base.OnAddOnLoaded(_, addonName) if addonName == base.Addon.Name then base.GenerateCollectionTypes() base.Initialize() end end function base.Initialize() base.SetAndUpdateAccountSettings() base.InitializeCombineFrame() base.InitializeBindings() base.InitializeSettingsSlash() base.InitializeReverseBinding() for _, _type in pairs(base.Type) do _type.Saved = base.Saved[_type.Name] if _type.Saved.Enabled then base.InitializeType(_type) end end base.InitializeCombine() base.RestoreCombine() base.CreateSettingsWindow() EVENT_MANAGER:UnregisterForEvent(base.Addon.Name, EVENT_ADD_ON_LOADED) end function base.InitializeType(_type) base.CreateCollection(_type) base.SetupLabel(_type) base.RestoreFrame(_type) end function base.InitializeCombineFrame() local name = base.Addon.Abbreviation .. "_CombineFrame" base.Global.Combine.Frame = base.GetFrame(name, name) name = name .. "HideAll" base.Global.Combine.HideAll = base.GetFrame(name, name) end function base.CreateCollection(_type) local unlocked = GetTotalUnlockedCollectiblesByCategoryType(_type.TypeId) _type.Collection = {} _type.OrderedCollection = {} _type.Unlocked = unlocked _type.Total = GetTotalCollectiblesByCategoryType(_type.TypeId) _type.IsUsable = IsCollectibleCategoryUsable(_type.TypeId) if unlocked > base.Global.HighestUnlocked then base.Global.HighestUnlocked = unlocked end local elementsAdded = 1 for index = 1, _type.Total do local id = GetCollectibleIdFromType(_type.TypeId, index) local name, description, icon, _, _unlocked, _, _, _, hint, _ = GetCollectibleInfo(id) if _unlocked or _type.Saved.MenuShowDisabled then _type.Collection[id] = { Id = id, Name = name, EnabledTexture = icon, Disabled = not _unlocked, Tooltip = string.format("Description: %s \nHint: %s", description, hint) } _type.OrderedCollection[elementsAdded] = _type.Collection[id] elementsAdded = elementsAdded + 1 end end _type.Frame = base.GetFrame(_type.Name, base.Addon.Abbreviation .. "_Frame") end function base.RestoreFrames() for _, _type in pairs(base.Type) do base.RestoreFrame(_type) end base.RestoreCombine() end function base.HideOther(newType) for _, _type in pairs(base.Type) do if _type.Saved.Enabled and _type.Saved.Combine and not _type.Saved.HideAll and _type ~= newType then _type.Saved.HideAll = not _type.Saved.HideAll base.RestoreFrame(_type) end end end function base.RestoreFrame(_type) if _type.Saved.Enabled then base.RestoreLabel(_type) base.SetFrameAndCombineSize(_type) base.SetupButtons(_type) base.RestorePosition(_type) base.UpdateToggleSettings(_type) base.UpdateMoveFrame(_type) base.UpdateFragment(_type) end end function base.RemoveFrame(_type) base.RemoveFragments(_type) for _, _value in ipairs(_type.OrderedCollection) do if base.Buttons[_value.Id] ~= nil then base.Buttons[_value.Id]:SetHidden(true) end end if _type.Frame ~= nil then _type.Frame:SetHidden(true) end end function base.InitializeCombine() base.Global.Combine.Saved = base.Saved.Combine end function base.RestoreCombine() base.RestoreCombineLabels() base.RestorePosition(base.Global.Combine) base.UpdateMoveFrame(base.Global.Combine) base.UpdateFragment(base.Global.Combine) end ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- EVENT_MANAGER:RegisterForEvent(base.Addon.Name, EVENT_ADD_ON_LOADED, base.OnAddOnLoaded)