diff --git a/CBs_Bindings.lua b/CBs_Bindings.lua index 5ce4273..6316687 100644 --- a/CBs_Bindings.lua +++ b/CBs_Bindings.lua @@ -11,9 +11,10 @@ local texts = base.Texts ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- -function CBs_ShowSettings() base.ToggleEnableSettings(base.ShowSettings()) end +function CBs_ShowSettings() base:ToggleEnableSettings(base.ShowSettings()) end function CBs_Clicked(keyId) + base:Debug("CBs_Clicked", keyId) local control = base.WM:GetMouseOverControl() local collectibleId = base.Saved.Bindings[keyId] @@ -22,33 +23,40 @@ function CBs_Clicked(keyId) local previousCId = collectibleId if previousCId ~= newCId then - for _keyId, cid in pairs(base.Saved.Bindings) do if _keyId ~= keyId and cid == newCId then base.Saved.Bindings[_keyId] = 0 end end + for _keyId, cid in ipairs(base.Saved.Bindings) do if _keyId ~= keyId and cid == newCId then base.Saved.Bindings[_keyId] = 0 end end for cid, _keyId in pairs(base.Global.ReverseBindings) do if cid ~= newCId and _keyId == keyId then base.Global.ReverseBindings[cid] = nil - base.SetbindingText(cid) + base:SetBindingText(cid) end end base.Saved.Bindings[keyId] = newCId base.Global.ReverseBindings[newCId] = keyId - base.SetbindingText(newCId) + base:SetBindingText(newCId) end elseif collectibleId > 0 then - if base.Buttons[collectibleId] then - base.Activate(base.Buttons[collectibleId]) + if base.AllButtons[collectibleId] then + base:Activate(base.AllButtons[collectibleId]) else UseCollectible(collectibleId) end end end -function base.SetbindingText(cid) if base.Buttons[cid] then base.Buttons[cid]:SetBindingText(base.Saved.ShowBinding, cid) end end +function base:SetBindingText(cid) + base:Debug("SetBindingText", cid) + if base.AllButtons[cid] then base.AllButtons[cid]:SetBindingText(base.Saved.Bindings.Show, cid) end +end -function base.InitializeBindings() +function base:InitializeBindings() + base:Debug("InitializeBindings") ZO_CreateStringId(string.format(texts.FormatBindingName, "Settings"), "Settings") for key, _ in ipairs(base.Saved.Bindings) do ZO_CreateStringId(string.format(texts.FormatBindingName, key), string.format(texts.FormatAbbreviationLowDash, key)) end end -function base.InitializeReverseBinding() for keyId, collectibleId in ipairs(base.Saved.Bindings) do if collectibleId > 0 then base.Global.ReverseBindings[collectibleId] = keyId end end end +function base:InitializeReverseBinding() + base:Debug("InitializeReverseBinding") + for keyId, collectibleId in ipairs(base.Saved.Bindings) do if collectibleId > 0 then base.Global.ReverseBindings[collectibleId] = keyId end end +end diff --git a/CBs_Button.lua b/CBs_Button.lua index 2ba94a4..a95d719 100644 --- a/CBs_Button.lua +++ b/CBs_Button.lua @@ -13,19 +13,22 @@ local texts = base.Texts ------------------------------------------------------------------------------------------------- CBs_Button = ZO_Object:Subclass() -function CBs_Button:New(category, frame, cId, saved) +function CBs_Button:New(categoryId, frame, cId) + base:Verbose("CBs_Button:New", categoryId, frame, cId) local newB = ZO_Object.New(self) + local category = base.Categories[categoryId] + local collectible = category.Collection[cId] if newB then - local ctrl = CreateControlFromVirtual(string.format("%s_Button", category.Name), frame, string.format(CollectionBars.Texts.FormatAbbreviationLowDash, "Button"), cId) + local ctrl = CreateControlFromVirtual(string.format(texts.FormatCategoryName, category.Id), frame, string.format(texts.FormatAbbreviationLowDash, "Button"), string.format("_B%s", cId)) newB.cId = cId - newB.category = category - newB.saved = saved + newB.categoryId = categoryId newB.ctrl = ctrl newB.ctrl.cId = cId newB.button = ctrl:GetNamedChild("Button") newB.button:SetId(cId) - newB.button.tooltip = category.Collection[cId].Name + newB.button.tooltip = collectible.Name + newB.enabledTexture = collectible.EnabledTexture newB.button.CBs = true newB.icon = ctrl:GetNamedChild("Icon") newB.cooldownIcon = ctrl:GetNamedChild("CooldownIcon") @@ -43,36 +46,38 @@ function CBs_Button:New(category, frame, cId, saved) end function CBs_Button:UpdateAnchor(frame, left, top) + base:Verbose("CBs_Button:UpdateAnchor", frame, left, top) self.ctrl:ClearAnchors() self.ctrl:SetAnchor(TOPLEFT, frame, TOPLEFT, left, top) end function CBs_Button:Setup() + base:Verbose("CBs_Button:Setup") self.ctrl:SetHidden(false) - - local texture = self.category.Collection[self.cId].EnabledTexture - self.icon:SetTexture(texture) + self.icon:SetTexture(self.enabledTexture) self.icon:SetHidden(false) if self.cooldownIcon ~= nil then - self.cooldownIcon:SetTexture(texture) + self.cooldownIcon:SetTexture(self.enabledTexture) self.cooldownIcon:SetDesaturation(1) end - self.button:SetHandler("OnClicked", function() base.Activate(self) end) + self.button:SetHandler("OnClicked", function() base:Activate(self) end) self.button:SetHandler("OnMouseEnter", function() if self.playSounds then PlaySound(SOUNDS.QUICKSLOT_MOUSEOVER) end - if self.category.Saved.Tooltip.Show then - local text = self.category.Collection[self.cId].Name - ZO_Tooltips_ShowTextTooltip(self.button, self.category.Saved.Tooltip.Position, text) - end + local saved = base.Saved.Categories[self.categoryId] + if saved.Tooltip.Show then ZO_Tooltips_ShowTextTooltip(self.button, saved.Tooltip.Position, self.button.tooltip) end end) self.button:SetHandler("OnMouseExit", function() ZO_Tooltips_HideTextTooltip() end) end -function CBs_Button:SetShowBindingText(visible) self.buttonText:SetHidden(not visible) end +function CBs_Button:SetShowBindingText(visible) + base:Verbose("CBs_Button:SetShowBindingText", visible) + self.buttonText:SetHidden(not visible) +end function CBs_Button:SetSize(size) + base:Verbose("CBs_Button:SetSize", size) self.ctrl:SetHeight(size) self.ctrl:SetWidth(size) self.icon:SetHeight(size - 6) @@ -80,6 +85,7 @@ function CBs_Button:SetSize(size) end function CBs_Button:SetBindingText(show, cId) + base:Verbose("CBs_Button:SetBindingText", show, cId) local keyId = base.Global.ReverseBindings[cId] if self.buttonText ~= nil then ZO_Keybindings_UnregisterLabelForBindingUpdate(self.buttonText) @@ -90,20 +96,25 @@ function CBs_Button:SetBindingText(show, cId) self.buttonText:SetHeight(self.ctrl:GetHeight()) self.buttonText:SetWidth(self.ctrl:GetWidth()) self.buttonText:SetAnchor(BOTTOM, self.ctrl, BOTTOM, 0, 0) - ZO_Keybindings_RegisterLabelForBindingUpdate(self.buttonText, string.format(CollectionBars.Texts.FormatAbbreviationLowDash, keyId), false) + ZO_Keybindings_RegisterLabelForBindingUpdate(self.buttonText, string.format(texts.FormatAbbreviationLowDash, keyId), false) end end end -function CBs_Button:OnClicked() if self.usable then UseCollectible(self.cId) end end +function CBs_Button:OnClicked() + base:Verbose("CBs_Button:OnClicked") + if self.usable then UseCollectible(self.cId) end +end -function CBs_Button:UpdateState(forceId, isAttempting) +function CBs_Button:UpdateState(forceId, isAttempting, isActiveActivationEnabled) + base:Verbose("CBs_Button:UpdateState", forceId, isAttempting) local show = false - if self.saved.IsActiveActivationEnabled then show = self.cId == forceId and isAttempting or not forceId and IsCollectibleActive(self.cId) end + if isActiveActivationEnabled then show = self.cId == forceId and isAttempting or not forceId and IsCollectibleActive(self.cId) end self.status:SetHidden(show == false) end function CBs_Button:UpdateUsable() + base:Verbose("CBs_Button:UpdateUsable") local isShowingCooldown = self.showingCooldown local usable = false if not isShowingCooldown then usable = true end @@ -112,15 +123,20 @@ function CBs_Button:UpdateUsable() end function CBs_Button:RefreshCooldown(remaining, duration, cooldown) + base:Verbose("CBs_Button:RefreshCooldown", remaining, duration, cooldown) local percentComplete = (1 - remaining / duration) self.icon.percentComplete = percentComplete self.cooldownTime:SetText(cooldown) end -function CBs_Button:UpdatePlaySounds(playSounds) self.playSounds = playSounds end +function CBs_Button:UpdatePlaySounds(playSounds) + base:Verbose("CBs_Button:UpdatePlaySounds", playSounds) + self.playSounds = playSounds +end function CBs_Button:UpdateCooldown(remaining, duration, cooldown) + base:Verbose("CBs_Button:UpdateCooldown", remaining, duration, cooldown) local showCooldown = duration > 0 self.cooldown:SetHidden(not showCooldown) @@ -165,4 +181,13 @@ function CBs_Button:UpdateCooldown(remaining, duration, cooldown) self:UpdateUsable() end -function CBs_Button:SetHidden(value) self.ctrl:SetHidden(value) end +function CBs_Button:SetHidden(value) + base:Verbose("CBs_Button:SetHidden", value) + self.ctrl:SetHidden(value) +end + +function CBs_Button:IsHidden() + base:Verbose("CBs_Button:IsHidden") + local isHidden = self.ctrl:IsHidden() + return isHidden +end diff --git a/CBs_Button.xml b/CBs_Button.xml index 1d24a0b..357d472 100644 --- a/CBs_Button.xml +++ b/CBs_Button.xml @@ -39,7 +39,7 @@ <Anchor point="BOTTOM" relativeTo="$(parent)Button" relativePoint="BOTTOM" /> </Label> - <Label name="$(parent)CooldownTime" inherits="ZO_CollectibleTileDefaultLabel" hidden="true" clampedToScreen="true"> + <Label name="$(parent)CooldownTime" font="ZoFontWindowSubtitle" wrapMode="ELLIPSIS" color="INTERFACE_COLOR_TYPE_TEXT_COLORS:INTERFACE_TEXT_COLOR_SELECTED" horizontalAlignment="CENTER" verticalAlignment="CENTER" hidden="true"> <Anchor point="TOPLEFT" relativeTo="$(parent)Icon" relativePoint="TOPLEFT" /> <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)Icon" relativePoint="BOTTOMRIGHT" /> </Label> diff --git a/CBs_Buttons.lua b/CBs_Buttons.lua index 887f723..eda605d 100644 --- a/CBs_Buttons.lua +++ b/CBs_Buttons.lua @@ -11,153 +11,164 @@ local texts = base.Texts ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- -function base.SetFrameAndCombineSize(category) - local width, height = base.GetBarWidthHeight(category) - base.SetFrameSizeIfExists(category.Frame, width, height) +function base:Activate(button) + base:Debug("Activate", button) + if base:IsCollectibleUsable(button) then + if button and base.Saved.Button.IsActiveActivationEnabled then + local category = base.Categories[button.categoryId] + local formatCategoryEvent = string.format(texts.FormatAbbreviation .. "%%s", category.Name) + local activeEventName = string.format(formatCategoryEvent, tostring(category.EventTS)) + EVENT_MANAGER:UnregisterForEvent(activeEventName, EVENT_COLLECTIBLE_USE_RESULT) + category.EventTS = GetTimeStamp() + EVENT_MANAGER:RegisterForEvent(activeEventName, EVENT_COLLECTIBLE_USE_RESULT, function(_, result, isAttemptingActivation) + local countDown = category.Cooldown + local success = false + + if result == COLLECTIBLE_USAGE_BLOCK_REASON_NOT_BLOCKED and button.button then + success = true + countDown.CollectibleId = button.cId + base:UpdateButtonsState(category, button.cId, isAttemptingActivation) + end + + local successActivate = isAttemptingActivation and success + countDown.StartTime = GetFrameTimeMilliseconds() + + EVENT_MANAGER:UnregisterForEvent(activeEventName, EVENT_COLLECTIBLE_USE_RESULT) + + if success then + local countDownEvent = string.format(formatCategoryEvent, countDown.Event) + EVENT_MANAGER:UnregisterForUpdate(countDownEvent) + EVENT_MANAGER:RegisterForUpdate(countDownEvent, countDown.Tick, function() + local remaining, duration = GetCollectibleCooldownAndDuration(countDown.CollectibleId) + local cooldown = base:GetCooldownText(countDown, duration) - if category.Saved.IsCombined and not category.Saved.HideAll then base.SetFrameSizeIfExists(base.Global.Combine.Frame, width, height) end + base:UpdateButtonsCooldown(category, remaining, duration, cooldown) + if duration == 0 then + countDown.StartTime = nil + local isActive = successActivate or IsCollectibleActive(button.cId) + base:UpdateButtonsState(category, button.cId, isActive) + EVENT_MANAGER:UnregisterForUpdate(countDownEvent) + end + end) + end + end) + end + button:UpdateUsable() + button:OnClicked() + end end -function base.GetFrame(name, virtual) +function base:SetFrameAndCombineSize(category) + base:Debug("SetFrameAndCombineSize", category) + local width, height = base:GetBarWidthHeight(category) + base:SetFrameSizeIfExists(category.Frames.Frame, width, height) + + if category.Saved.Bar.IsCombined and not category.Saved.Bar.HideAll then base:SetFrameSizeIfExists(base.Global.Combine.Frames.Frame, width, height) end +end + +function base:GetFrame(name, virtual) + base:Debug("GetFrame", name, virtual) local frame = GetControl(name) if frame == nil then frame = base.WM:CreateControlFromVirtual(name, GuiRoot, virtual) end + base:Debug("GetFrame:return", frame) return frame end -function base.GetButtonPosition(category, index) - local x = ((index - 1) % category.BarDepth) * base.Saved.ButtonXY - local y = (math.floor((index - 1) / category.BarDepth)) * base.Saved.ButtonXY +function base:GetButtonPosition(category, index) + category.Bar.Depth, category.Bar.Width = base:GetMaxBarSize(category, "Depth", index), base:GetMaxBarSize(category, "Width", index) + base:Debug("GetButtonPosition", category, index, category.Bar.Depth, base.Saved.Button.Size) + local left = ((index - 1) % category.Bar.Depth) * base.Saved.Button.Size + local top = (zo_floor((index - 1) / category.Bar.Depth)) * base.Saved.Button.Size - if not category.Saved.Horizontal then - return y, x + base:Debug("GetButtonPosition", category.Name, index, left, top) + if not category.Saved.Bar.Horizontal then + return top, left else - return x, y + return left, top end end -function base.SetupButtons(category) +function base:SetupButtons(category) + base:Debug("SetupButtons", category, category.Name, category.Bar.Depth, category.Bar.Width) local index = 1 + local autoSelectAll = category.Saved.AutoSelectAll local selected = category.Saved.Selected - local frame = category.Frame - local maxIndex = (category.BarDepth or 0) * (category.BarWidth or 0) + local frame = category.Frames.Frame + local maxIndex = (category.Bar.Depth or 0) * (category.Bar.Width or 0) category.IsEmpty = true for _, _value in ipairs(category.CollectionOrdered) do local hideButton = true - if category.Saved.Enabled and selected[_value.Id] and IsCollectibleUnlocked(_value.Id) and IsCollectibleValidForPlayer(_value.Id) then - if base.Buttons[_value.Id] == nil then base.Buttons[_value.Id] = CBs_Button:New(category, frame, _value.Id, base.Saved) end - if not category.Saved.HideAll and (maxIndex == 0 or index <= maxIndex) then + if category.Saved.Enabled and (autoSelectAll or selected[_value.Id]) and IsCollectibleUnlocked(_value.Id) and IsCollectibleValidForPlayer(_value.Id) then + if category.Buttons[_value.Id] == nil then + category.Buttons[_value.Id] = CBs_Button:New(category.Id, frame, _value.Id) + base.AllButtons[_value.Id] = category.Buttons[_value.Id] + end + + if not category.Saved.Bar.HideAll and (maxIndex == 0 or index <= maxIndex) then hideButton = false - local left, top = base.GetButtonPosition(category, index) - base.Buttons[_value.Id]:SetBindingText(base.Saved.ShowBinding, _value.Id) - base.Buttons[_value.Id]:Setup() - base.Buttons[_value.Id]:UpdateAnchor(frame, left, top) - base.Buttons[_value.Id]:UpdatePlaySounds(base.Saved.IsAudioEnabled) - base.Buttons[_value.Id]:UpdateState() + category.Buttons[_value.Id]:SetBindingText(base.Saved.Bindings.Show, _value.Id) + category.Buttons[_value.Id]:Setup() + category.Buttons[_value.Id]:UpdateAnchor(frame, base:GetButtonPosition(category, index)) + category.Buttons[_value.Id]:UpdatePlaySounds(base.Saved.Button.IsAudioEnabled) index = index + 1 end category.IsEmpty = false - elseif not category.Saved.Enabled and base.Buttons[_value.Id] ~= nil then - base.Buttons[_value.Id]:SetHidden(true) end - if base.Buttons[_value.Id] ~= nil then - base.Buttons[_value.Id].ctrl:SetHidden(hideButton) - base.Buttons[_value.Id]:SetSize(base.Saved.ButtonXY) - base.Buttons[_value.Id]:UpdateState() + if category.Buttons[_value.Id] ~= nil then + category.Buttons[_value.Id]:SetHidden(hideButton) + if not hideButton then + category.Buttons[_value.Id]:SetSize(base.Saved.Button.Size) + category.Buttons[_value.Id]:UpdateState(nil, nil, base.Saved.Button.IsActiveActivationEnabled) + end end end - local isHidden = (category.IsEmpty or not category.Saved.LabelShow) and not base.Global.EnableSettings or not category.Saved.Enabled - if category.Frame then category.Frame:SetHidden(isHidden) end + local isHidden = (category.IsEmpty or not category.Saved.Label.Show) and not base.Global.EnableSettings or not category.Saved.Enabled + if category.Frames.Frame then category.Frames.Frame:SetHidden(isHidden) end - if category.FrameLabel then category.FrameLabel:SetHidden(isHidden) end + if category.Frames.Label then category.Frames.Label:SetHidden(isHidden) end end -function base.UpdateButtonsState(category, forceId, isAttemptingActivation) - for _, _value in ipairs(category.CollectionOrdered) do - local button = base.Buttons[_value.Id] - if button ~= nil then button:UpdateState(forceId, isAttemptingActivation) end - end +function base:UpdateButtonsState(category, forceId, isAttemptingActivation) + base:Debug("UpdateButtonsState", category, forceId, isAttemptingActivation) + for _, button in ipairs(category.Buttons) do if button ~= nil then button:UpdateState(forceId, isAttemptingActivation, base.Saved.Button.IsActiveActivationEnabled) end end end -function base.UpdateButtonsCooldown(category, remaining, duration, cooldown) - for _cId in pairs(category.Saved.Selected) do - local button = base.Buttons[_cId] - if button ~= nil and category.Collection[_cId] then button:UpdateCooldown(remaining, duration, cooldown) end - end +function base:UpdateButtonsCooldown(category, remaining, duration, cooldown) + base:Debug("UpdateButtonsCooldown", category, remaining, duration, cooldown) + for _cId, button in pairs(category.Buttons) do if button ~= nil and category.Collection[_cId] then button:UpdateCooldown(remaining, duration, cooldown) end end end -function base.GetCooldownText(countDown, duration) +function base:GetCooldownText(countDown, duration) + base:Debug("GetCooldownText", countDown, duration) local cooldown = "" if type(duration) == "number" and countDown.StartTime ~= nil then local startTime = countDown.StartTime or 0 - local secondsRemaining = math.max(startTime + duration - GetFrameTimeMilliseconds(), 0) / 1000 + local secondsRemaining = zo_max(startTime + duration - GetFrameTimeMilliseconds(), 0) / 1000 cooldown = ZO_FormatTimeAsDecimalWhenBelowThreshold(secondsRemaining, 60) end return cooldown end -function base.IsCollectibleUsable(button) - local isCollectibleUsable = button ~= nil and button.category.Cooldown.StartTime == nil and IsCollectibleUsable(button.cId) +function base:IsCollectibleUsable(button) + base:Debug("IsCollectibleUsable", button) + local category = base.Categories[button.categoryId] + local isCollectibleUsable = button ~= nil and category.Cooldown.StartTime == nil and IsCollectibleUsable(button.cId) if not isCollectibleUsable and button.cId then - local startTime = button.category.Cooldown.StartTime or 0 + local startTime = category.Cooldown.StartTime or 0 local _, duration = GetCollectibleCooldownAndDuration(button.cId) isCollectibleUsable = startTime + duration < GetFrameTimeMilliseconds() end return isCollectibleUsable end - -function base.Activate(button) - if base.IsCollectibleUsable(button) then - if button and base.Saved.IsActiveActivationEnabled then - local formatCategoryEvent = string.format(texts.FormatAbbreviation .. "%%s", button.category.Name) - local activeEventName = string.format(formatCategoryEvent, tostring(button.category.EventTS)) - EVENT_MANAGER:UnregisterForEvent(activeEventName, EVENT_COLLECTIBLE_USE_RESULT) - button.category.EventTS = GetTimeStamp() - EVENT_MANAGER:RegisterForEvent(activeEventName, EVENT_COLLECTIBLE_USE_RESULT, function(_, result, isAttemptingActivation) - local countDown = button.category.Cooldown - local success = false - - if result == COLLECTIBLE_USAGE_BLOCK_REASON_NOT_BLOCKED and button.button then - success = true - countDown.CollectibleId = button.cId - base.UpdateButtonsState(button.category, button.cId, isAttemptingActivation) - end - - local successActivate = isAttemptingActivation and success - countDown.StartTime = GetFrameTimeMilliseconds() - - EVENT_MANAGER:UnregisterForEvent(activeEventName, EVENT_COLLECTIBLE_USE_RESULT) - - if success then - local countDownEvent = string.format(formatCategoryEvent, countDown.Event) - EVENT_MANAGER:UnregisterForUpdate(countDownEvent) - EVENT_MANAGER:RegisterForUpdate(countDownEvent, countDown.Tick, function() - local remaining, duration = GetCollectibleCooldownAndDuration(countDown.CollectibleId) - local cooldown = base.GetCooldownText(countDown, duration) - - base.UpdateButtonsCooldown(button.category, remaining, duration, cooldown) - if duration == 0 then - countDown.StartTime = nil - local isActive = successActivate or IsCollectibleActive(button.cId) - base.UpdateButtonsState(button.category, button.cId, isActive) - EVENT_MANAGER:UnregisterForUpdate(countDownEvent) - end - end) - end - end) - end - button:UpdateUsable() - button:OnClicked() - end -end diff --git a/CBs_Constants.lua b/CBs_Constants.lua index 6d9f643..e7ffceb 100644 --- a/CBs_Constants.lua +++ b/CBs_Constants.lua @@ -7,24 +7,15 @@ Filename: CBs_Constants.lua ------------------------------------------------------------------------------------------------- CollectionBars = { WM = GetWindowManager(), - Addon = {Name = "CollectionBars", DisplayName = "Collection Bars", Abbreviation = "CBs", Version = 1.0, MinorVersion = 11, SettingsSlash = "/cb", Author = "Jarth"}, - Buttons = {}, + Addon = {Name = "CollectionBars", DisplayName = "Collection Bars", Abbreviation = "CBs", Version = 1.1, MinorVersion = 0, SettingsSlash = "/cb", Author = "Jarth"}, + AllButtons = {}, Default = { - BarDepth = 5, - BarWidth = 0, - ButtonXY = ZO_GAMEPAD_ACTION_BUTTON_SIZE, UseAccountSettings = true, - ShowBarOnHud = true, - ShowBarOnHudUI = true, - ShowBarInMenu = true, - ShowBarInInventory = false, - ShowBarInInteract = false, - ShowBarInBank = false, - ShowBarInFence = false, - ShowBarInStore = false, - SnapSize = 5, - ShowBinding = true, + Bar = {Depth = 5, Width = 0, SnapSize = 5}, + Button = {Size = ZO_GAMEPAD_ACTION_BUTTON_SIZE, IsAudioEnabled = true, IsActiveActivationEnabled = true}, + Scene = {OnHud = true, OnHudUI = true, InMenu = true, InInventory = false, InInteract = false, InBank = false, InFence = false, InStore = false}, Bindings = { + Show = true, [1] = 0, [2] = 0, [3] = 0, @@ -46,29 +37,34 @@ CollectionBars = { [19] = 0, [20] = 0 }, - IsAudioEnabled = true, - IsActiveActivationEnabled = true, - Combine = {BarDepth = 0, BarWidth = 0, X = CENTER, Y = CENTER, Display = "CombineBar", Label = {OffsetX = 0, OffsetY = 0, Position = BOTTOMLEFT, PositionTarget = TOPLEFT}} + Combine = { + Bar = {Depth = 0, Width = 0, Offset = {X = CENTER, Y = CENTER}}, + Label = {Show = true, Display = "CombineBar", Offset = {X = 0, Y = 0}, Position = BOTTOMLEFT, PositionTarget = TOPLEFT} + }, + Categories = {}, + Logging = {Info = false, Debug = false, Verbose = false} }, Global = { EnableSettings = false, IsMoveEnabled = false, ReverseBindings = {}, - SettingsFrame = nil, - SettingsList = nil, - SettingsFilters = {["Categories"] = "Categories", ["Collectibles"] = "Collectibles", ["Category"] = "Category", ["General"] = "General", ["Combined"] = "Combined bar"}, - Combine = {Name = "Combine", EventTS = nil, MoveFrame = nil, Frame = nil, category = nil, HideAll = nil, Fragment = nil, IsEmpty = false}, + Settings = { + Frame = nil, + List = nil, + Filters = {["Categories"] = "Categories", ["Collectibles"] = "Collectibles", ["Category"] = "Category", ["General"] = "General", ["Combined"] = "Combined bar"} + }, + Combine = {Name = "Combine", EventTS = nil, Frames = {Frame = nil, Move = nil}, category = nil, HideAll = nil, Fragment = nil, IsEmpty = false}, ChoiceLocations = {"top", "topright", "right", "bottomright", "bottom", "bottomleft", "left", "topleft", "center"}, AvailableFonts = {"ZoFontGameSmall", "ZoFontGameLarge", "ZoFontGameLargeBold", "ZoFontGameLargeBoldShadow", "ZoFontHeader", "ZoFontHeader2", "ZoFontHeader3", "ZoFontHeader4"}, - ScenePairs = { - ShowBarOnHud = HUD_SCENE, - ShowBarOnHudUI = HUD_UI_SCENE, - ShowBarInMenu = SCENE_MANAGER:GetScene("gameMenuInGame"), - ShowBarInInventory = SCENE_MANAGER:GetScene("inventory"), - ShowBarInInteract = SCENE_MANAGER:GetScene("interact"), - ShowBarInBank = SCENE_MANAGER:GetScene("bank"), - ShowBarInFence = SCENE_MANAGER:GetScene("fence_keyboard"), - ShowBarInStore = SCENE_MANAGER:GetScene("store") + Scenes = { + [1] = {Name = "OnHud", Instance = HUD_SCENE, Description = "%s on main view/hud"}, + [2] = {Name = "OnHudUI", Instance = HUD_UI_SCENE, Description = "%s on the main view when an overlay is activated/hudui"}, + [3] = {Name = "InMenu", Instance = SCENE_MANAGER:GetScene("gameMenuInGame"), Description = "%s in menu"}, + [4] = {Name = "InInventory", Instance = SCENE_MANAGER:GetScene("inventory"), Description = "%s in the inventory"}, + [5] = {Name = "InInteract", Instance = SCENE_MANAGER:GetScene("interact"), Description = "%s in interactions"}, + [6] = {Name = "InBank", Instance = SCENE_MANAGER:GetScene("bank"), Description = "%s at a bank"}, + [7] = {Name = "InFence", Instance = SCENE_MANAGER:GetScene("fence_keyboard"), Description = "%s at a fence"}, + [8] = {Name = "InStore", Instance = SCENE_MANAGER:GetScene("store"), Description = "%s at a store"} }, HighestUnlocked = 0 }, @@ -89,39 +85,41 @@ CollectionBars = { TopRight = "topright" }, Settings = {ToggleMoveFrameText = "Toggle move frame", ReloadText = "Reload list of 'Collectibles'\nHint: Usefull after gaining a new collectible)"} - } + }, + Loggers = {} } +local base = CollectionBars -CollectionBars.Texts.FormatAbbreviation = string.format("%s%%s", CollectionBars.Addon.Abbreviation) -CollectionBars.Texts.FormatAbbreviationLowDash = string.format("%s_%%s", CollectionBars.Addon.Abbreviation) -CollectionBars.Texts.FormatBindingName = string.format("SI_BINDING_NAME_%s", CollectionBars.Texts.FormatAbbreviationLowDash) - -CollectionBars.Texts.CombineFrameName = string.format(CollectionBars.Texts.FormatAbbreviationLowDash, "CombineFrame") -CollectionBars.Texts.CombineFrameNameHideAll = string.format("%s%s", CollectionBars.Texts.CombineFrameName, "HideAll") - -CollectionBars.Texts.AccountKey = string.format("%s_Account", CollectionBars.Addon.Name) -CollectionBars.Texts.CharacterKey = string.format("%s_Character", CollectionBars.Addon.Name) +base.Texts.FormatAbbreviation = string.format("%s%%s", base.Addon.Abbreviation) +base.Texts.FormatAbbreviationLowDash = string.format("%s_%%s", base.Addon.Abbreviation) +base.Texts.FormatCategoryName = string.format("%s_C%%s", base.Addon.Abbreviation) +base.Texts.FormatBindingName = string.format("SI_BINDING_NAME_%s", base.Texts.FormatAbbreviationLowDash) +base.Texts.CombineFrameName = string.format(base.Texts.FormatAbbreviationLowDash, "CombineFrame") +base.Texts.CombineFrameNameHideAll = string.format("%s%s", base.Texts.CombineFrameName, "HideAll") +base.Texts.AccountKey = string.format("%s_Account", base.Addon.Name) +base.Texts.CharacterKey = string.format("%s_Character", base.Addon.Name) ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- -function CollectionBars.GenerateCategories() - CollectionBars.Categories = {} +function base:GenerateCategories() + base:Debug("GenerateCategories") + base.Categories = {} for _, categoryData in ZO_COLLECTIBLE_DATA_MANAGER:CategoryIterator({ZO_CollectibleCategoryData.HasShownCollectiblesInCollection}) do if categoryData ~= nil and categoryData:IsStandardCategory() then - local type = CollectionBars.GetType(categoryData) - if type ~= nil and CollectionBars.CategoryHasUsableCollectible(categoryData) then - CollectionBars.AddCategory(type, categoryData) + local type = base.GetType(categoryData) + if type ~= nil and base.CategoryHasUsableCollectible(categoryData) then + base.AddCategory(type, categoryData) else - if categoryData:IsTopLevelCategory() and CollectionBars.SubCategoryHasUsableCollectible(categoryData) then + if categoryData:IsTopLevelCategory() and base.SubCategoryHasUsableCollectible(categoryData) then local parentIcons = {categoryData:GetKeyboardIcons()} - CollectionBars.AddCategory(nil, categoryData, parentIcons, true) + base.AddCategory(nil, categoryData, parentIcons, true) for _, subcategoryData in categoryData:SubcategoryIterator({ZO_CollectibleCategoryData.HasShownCollectiblesInCollection}) do - type = CollectionBars.GetType(subcategoryData) + type = base.GetType(subcategoryData) if type ~= nil and subcategoryData ~= nil and subcategoryData:HasShownCollectiblesInCollection() then - CollectionBars.AddCategory(type, subcategoryData, parentIcons, false, categoryData:GetFormattedName()) + base.AddCategory(type, subcategoryData, parentIcons, false, categoryData:GetFormattedName()) end end end @@ -130,7 +128,8 @@ function CollectionBars.GenerateCategories() end end -function CollectionBars.GetType(categoryData) +function base.GetType(categoryData) + base:Debug("GetType", categoryData) local type = nil local collectibles = categoryData:GetCollectibleDataBySpecializedSort() if collectibles ~= nil and collectibles[1] ~= nil then type = collectibles[1]:GetCategoryType() end @@ -138,52 +137,44 @@ function CollectionBars.GetType(categoryData) return type end -function CollectionBars.AddCategory(type, categoryData, parentIcons, hasChildren, parentKey) +function base.AddCategory(type, categoryData, parentIcons, hasChildren, parentKey) + base:Debug("AddCategory", type, categoryData, parentIcons, hasChildren, parentKey) local categoryName = categoryData:GetFormattedName() + local categoryId = categoryData:GetId() local icon = parentIcons or {categoryData:GetKeyboardIcons()} if icon ~= nil and icon[1] == ZO_NO_TEXTURE_FILE then icon = nil end - CollectionBars.Categories[categoryName] = { + base.Categories[categoryId] = { Collection = {}, CollectionOrdered = {}, + Buttons = {}, Type = type, + Id = categoryId, CategoryData = categoryData, Icon = icon, HasChildren = hasChildren, ParentKey = parentKey, Unlocked = 0, Name = categoryName, - FrameLabel = nil, - FrameLabelButton = nil, - FrameToggleSettings = nil, - MoveFrame = nil, - Frame = nil, - BarDepth = 0, - BarWidth = nil, + Frames = {Frame = nil, Label = nil, LabelButton = nil, ToggleSettings = nil, Move = nil}, + Bar = {Depth = 0, Width = nil}, Cooldown = {Event = string.format("Cooldown%s", categoryName), CollectibleId = nil, StartTime = nil, Tick = 100}, Fragment = nil } - table.insert(CollectionBars.CategoriesOrdered, CollectionBars.Categories[categoryName]) - CollectionBars.Default[categoryName] = { + table.insert(base.CategoriesOrdered, base.Categories[categoryId]) + base.Default.Categories[categoryId] = { + AutoSelectAll = false, Selected = {}, Enabled = false, - HideAll = true, - HideAllEnabled = true, MenuShowDisabled = false, Tooltip = {Show = true, Position = TOP}, - Horizontal = true, - BarDepth = 0, - BarWidth = 0, - X = CENTER, - Y = CENTER, - Display = categoryName, - LabelShow = true, - Label = {OffsetX = 0, OffsetY = 0, Height = 19, Width = 75, Font = "ZoFontGameSmall", Position = BOTTOMLEFT, PositionTarget = TOPLEFT}, - IsCombined = true, + Bar = {IsCombined = true, HideAll = true, Depth = 0, Width = 0, Horizontal = true, Offset = {X = CENTER, Y = CENTER}}, + Label = {Show = true, EnableHideAll = true, Display = categoryName, Offset = {X = 0, Y = 0}, Height = 19, Width = 75, Font = "ZoFontGameSmall", Position = BOTTOMLEFT, PositionTarget = TOPLEFT}, ShowChildren = true } end -function CollectionBars.CategoryHasUnlockedValidAndUsableCollectible(categoryData) +function base.CategoryHasUnlockedValidAndUsableCollectible(categoryData) + base:Debug("CategoryHasUnlockedValidAndUsableCollectible", categoryData) if GetTotalCollectiblesByCategoryType(categoryData:GetId()) > 0 then for _, collectibleData in ZO_CollectibleCategoryData.CollectibleIterator(categoryData, {ZO_CollectibleData.IsShownInCollection}) do if collectibleData:IsUnlocked() and collectibleData:IsValidForPlayer() and collectibleData:IsUsable() then return true end @@ -192,15 +183,17 @@ function CollectionBars.CategoryHasUnlockedValidAndUsableCollectible(categoryDat return false end -function CollectionBars.CategoryHasUsableCollectible(categoryData) - if categoryData ~= nil and CollectionBars.CategoryHasUnlockedValidAndUsableCollectible(categoryData) then return true end +function base.CategoryHasUsableCollectible(categoryData) + base:Debug("CategoryHasUsableCollectible", categoryData) + if categoryData ~= nil and base.CategoryHasUnlockedValidAndUsableCollectible(categoryData) then return true end return false end -function CollectionBars.SubCategoryHasUsableCollectible(categoryData) +function base.SubCategoryHasUsableCollectible(categoryData) + base:Debug("SubCategoryHasUsableCollectible", categoryData) for _, subcategoryData in categoryData:SubcategoryIterator({ZO_CollectibleCategoryData.HasShownCollectiblesInCollection}) do - local type = CollectionBars.GetType(subcategoryData) - if type ~= nil and subcategoryData ~= nil and CollectionBars.CategoryHasUnlockedValidAndUsableCollectible(subcategoryData) then return true end + local type = base.GetType(subcategoryData) + if type ~= nil and subcategoryData ~= nil and base.CategoryHasUnlockedValidAndUsableCollectible(subcategoryData) then return true end end return false end diff --git a/CBs_Fragment.lua b/CBs_Fragment.lua index f3f3df6..f0cd937 100644 --- a/CBs_Fragment.lua +++ b/CBs_Fragment.lua @@ -11,28 +11,33 @@ local texts = base.Texts ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- -function base.UpdateFragments(fragmentType) - for _, category in pairs(base.Categories) do if category.Saved.Enabled then base.UpdateFragment(category, fragmentType) end end - base.UpdateFragment(base.Global.Combine, fragmentType) +function base:UpdateFragments(fragmentType) + base:Debug("UpdateFragments", fragmentType) + for _, category in pairs(base.Categories) do if category.Saved.Enabled then base:UpdateFragment(category, fragmentType) end end + base:UpdateFragment(base.Global.Combine, fragmentType) end -function base.UpdateFragment(category, fragmentType) +function base:UpdateFragment(category, fragmentType) + base:Debug("UpdateFragment", category, fragmentType) local currentScene = SCENE_MANAGER:GetCurrentScene() - local isHidden = (currentScene == nil or currentScene:GetName() == "empty") and not base.Saved.ShowBarOnHud + local isHidden = (currentScene == nil or currentScene:GetName() == "empty") and not base.Saved.Scene.OnHud - if category.Fragment == nil then category.Fragment = ZO_HUDFadeSceneFragment:New(category.Frame) end + if category.Fragment == nil then category.Fragment = ZO_HUDFadeSceneFragment:New(category.Frames.Frame) end - for key, scene in pairs(base.Global.ScenePairs) do - if (not fragmentType or key == fragmentType) and scene ~= nil then - if base.Saved[key] then - if not scene:HasFragment(category.Fragment) then scene:AddFragment(category.Fragment) end + for _, scene in ipairs(base.Global.Scenes) do + if (not fragmentType or scene.Name == fragmentType) and scene ~= nil and scene.Instance ~= nil then + if base.Saved.Scene[scene.Name] then + if not scene.Instance:HasFragment(category.Fragment) then scene.Instance:AddFragment(category.Fragment) end else - scene:RemoveFragment(category.Fragment) + scene.Instance:RemoveFragment(category.Fragment) end end - if scene == currentScene then isHidden = isHidden or not base.Saved[key] end + if scene.Instance == currentScene then isHidden = isHidden or not base.Saved.Scene[scene.Name] end end - category.Frame:SetHidden(isHidden) + category.Frames.Frame:SetHidden(isHidden) end -function base.RemoveFragments(category) if category.Fragment ~= nil then for _, scene in pairs(base.Global.ScenePairs) do if scene ~= nil then scene:RemoveFragment(category.Fragment) end end end end +function base:RemoveFragments(category) + base:Debug("RemoveFragments", category) + if category.Fragment ~= nil then for _, scene in ipairs(base.Global.Scenes) do if scene ~= nil and scene.Instance ~= nil then scene.Instance:RemoveFragment(category.Fragment) end end end +end diff --git a/CBs_Helpers.lua b/CBs_Helpers.lua index 58ca6c2..0d365d9 100644 --- a/CBs_Helpers.lua +++ b/CBs_Helpers.lua @@ -11,7 +11,16 @@ local texts = base.Texts ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- -function base.GetLocationValue(value) +function base.GetCharacterSettingsDisabledState() + base:Debug("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:GetLocationValue(value) + base:Debug("GetLocationValue", value) local result if value == texts.Location.Bottom then @@ -37,7 +46,8 @@ function base.GetLocationValue(value) return result end -function base.GetLocationText(value) +function base:GetLocationText(value) + base:Debug("GetLocationText", value) local result if value == BOTTOM then @@ -63,24 +73,26 @@ function base.GetLocationText(value) 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) +function base:RestorePosition(frame, saved) + base:Debug("RestorePosition", frame, frame.Name, saved) + frame:ClearAnchors() + local combineFrame = base.Global.Combine.Frames.Frame + if not saved.Bar.IsCombined or not combineFrame then + frame:SetAnchor(saved.Label.PositionTarget, GuiRoot, TOPLEFT, saved.Bar.Offset.X, saved.Bar.Offset.Y) + elseif saved.Bar.IsCombined then + if not saved.Bar.HideAll then + frame:SetAnchorFill(combineFrame) else - category.Frame:SetAnchor(TOPLEFT, combineFrame, TOPLEFT, 0, 0) + frame:SetAnchor(TOPLEFT, combineFrame, TOPLEFT, 0, 0) end end end -function base.GetLabelPostFix(category) +function base:GetLabelPostFix(category) + base:Debug("GetLabelPostFix", category) local postFix = "" - if category.Saved.HideAllEnabled then - if not category.Saved.HideAll then + if category.Saved.Label.EnableHideAll then + if not category.Saved.Bar.HideAll then postFix = " -" else postFix = " +" @@ -89,7 +101,8 @@ function base.GetLabelPostFix(category) return postFix end -function base.IsAllSelected(category) +function base:IsAllSelected(category) + base:Debug("IsAllSelected", category) local isAllSelected = true for _, collectible in pairs(category.Collection) do if category.Saved.Selected[collectible.Id] == nil then @@ -101,7 +114,15 @@ function base.IsAllSelected(category) return isAllSelected end -function base.SelectAll(category, newValue) +function base:AutoSelectAll(category, newValue) + base:Debug("AutoSelectAll", category, newValue) + + if newValue then category.Saved.Selected = {} end + +end + +function base:SelectAll(category, newValue) + base:Debug("SelectAll", category, newValue) for _, collectible in pairs(category.Collection) do if newValue == true then category.Saved.Selected[collectible.Id] = newValue @@ -111,26 +132,26 @@ function base.SelectAll(category, newValue) end end -function base.SetAndUpdateAccountSettings(newUseAccountSettings) +function base:SetAndUpdateAccountSettings(newUseAccountSettings) + base:Debug("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 newUseAccountSettings ~= nil then + base:Debug("Update Saved.UseAccountSettings to:", newUseAccountSettings) + 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 + base:LogsSetEnabled() end -function base.ResetAccountSettings() +function base:ResetAccountSettings() + base:Debug("ResetAccountSettings") if base.Saved.UseAccountSettings then _G[texts.AccountKey] = nil base.Saved = ZO_SavedVars:NewAccountWide(texts.AccountKey, base.Addon.Version, nil, base.Default) @@ -140,49 +161,62 @@ function base.ResetAccountSettings() 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 +function base:RemoveCharacterSettings() + base:Debug("RemoveCharacterSettings") + if base.Saved.UseAccountSettings then _G[texts.CharacterKey] = nil end +end - 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 +function base:GetMaxBarSize(category, constraint, count) + local maxBarSize + if category.Saved.Bar.IsCombined then + maxBarSize = base.Saved.Combine.Bar[constraint] + else + maxBarSize = category.Saved.Bar[constraint] end - local function GetBarMaxCount(constraint) - local barConstraintXY = category.Saved[constraint] - if category.Saved.IsCombined then barConstraintXY = base.Saved.Combine[constraint] end + if maxBarSize == 0 then maxBarSize = base.Saved.Bar[constraint] end + if count < maxBarSize then maxBarSize = count end - if barConstraintXY == 0 then barConstraintXY = base.Saved[constraint] end + return maxBarSize +end - if count < barConstraintXY then barConstraintXY = count end - return barConstraintXY - end +function base:GetBarWidthHeight(category) + base:Debug("GetBarWidthHeight", category) + local width, height, count = 0, 0, 0 - category.BarDepth, category.BarWidth = GetBarMaxCount("BarDepth"), GetBarMaxCount("BarWidth") + if not category.Saved.Bar.HideAll then for key, button in pairs(category.Buttons) do if not button:IsHidden() then count = count + 1 end end end if count > 0 then - local barWidth = math.ceil(count / category.BarDepth) - local maxBarWidth = category.BarWidth + category.Bar.Depth, category.Bar.Width = base:GetMaxBarSize(category, "Depth", count), base:GetMaxBarSize(category, "Width", count) + + local barWidth = zo_ceil(count / category.Bar.Depth) + local maxBarWidth = category.Bar.Width + 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) + + local isHorizontal = category.Saved.Bar.Horizontal + width = base.Saved.Button.Size * (not isHorizontal and barWidth or category.Bar.Depth) + height = base.Saved.Button.Size * (isHorizontal and barWidth or category.Bar.Depth) end return width, height end -function base.SetFrameSizeIfExists(frame, width, height) +function base:SetFrameSizeIfExists(frame, width, height) + base:Debug("SetFrameSizeIfExists", frame, width, height) if frame ~= nil then - frame:SetHeight(height) frame:SetWidth(width) + frame:SetHeight(height) end end -function base.HasAny(array) +function base:HasAny(array) + base:Debug("HasAny", array) for _ in pairs(array) do return true end return false end -function base.SetControlText(control, text) control.SetText(control, text) end +function base:SetControlText(control, text) + base:Debug("SetControlText", control, text) + control.SetText(control, text) +end diff --git a/CBs_Labels.lua b/CBs_Labels.lua index e01d580..63c15e8 100644 --- a/CBs_Labels.lua +++ b/CBs_Labels.lua @@ -11,97 +11,101 @@ local texts = base.Texts ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- -function base.SetupLabel(category) +function base:SetupLabel(category) + base:Debug("SetupLabel", category) local hideAllId = string.format(texts.FormatAbbreviationLowDash, "HideAll") local hideAllCategory = string.format("%s%s", hideAllId, category.Name) - if category.FrameLabel == nil then - category.FrameLabel = GetControl(hideAllCategory) - if category.FrameLabel == nil then category.FrameLabel = base.WM:CreateControlFromVirtual(hideAllId, category.Frame, hideAllId, category.Name) end + if category.Frames.Label == nil then + category.Frames.Label = GetControl(hideAllCategory) + if category.Frames.Label == nil then category.Frames.Label = base.WM:CreateControlFromVirtual(hideAllId, category.Frames.Frame, hideAllId, category.Name) end end - category.FrameLabel:SetHidden(not category.Saved.LabelShow and not category.Saved.IsCombined) + category.Frames.Label:SetHidden(not category.Saved.Label.Show and not category.Saved.Bar.IsCombined) - category.FrameToggleSettings = GetControl(string.format("%sToggleSettings", hideAllCategory)) - category.FrameLabelButton = GetControl(string.format("%sButton", hideAllCategory)) - if category.FrameLabelButton ~= nil then - category.FrameLabelButton:SetHandler("OnClicked", function(_, button) + category.Frames.ToggleSettings = GetControl(string.format("%sToggleSettings", hideAllCategory)) + category.Frames.LabelButton = GetControl(string.format("%sButton", hideAllCategory)) + if category.Frames.LabelButton ~= nil then + category.Frames.LabelButton:SetHandler("OnClicked", function(_, button) if button == MOUSE_BUTTON_INDEX_RIGHT then - base.ToggleEnableSettings() - elseif button == MOUSE_BUTTON_INDEX_LEFT and category.Saved.HideAllEnabled or category.Saved.IsCombined then - category.Saved.HideAll = not category.Saved.HideAll - if category.Saved.IsCombined then base.HideOthers(category) end - base.RestoreFrame(category) - base.RestoreCombine() + base:ToggleEnableSettings() + elseif button == MOUSE_BUTTON_INDEX_LEFT and category.Saved.Label.EnableHideAll or category.Saved.Bar.IsCombined then + category.Saved.Bar.HideAll = not category.Saved.Bar.HideAll + if category.Saved.Bar.IsCombined then base:HideOthers(category) end + base:RestoreFrame(category) + base:RestoreCombine() end end) end - base.SetupToggleSettings(category) + base:SetupToggleSettings(category) end -function base.RestoreLabel(category) +function base:RestoreLabel(category) + base:Debug("RestoreLabel", category) local label = category.Saved.Label - local frameLabel = category.FrameLabel + local frameLabel = category.Frames.Label if frameLabel ~= nil then frameLabel:ClearAnchors() frameLabel:SetHeight(label.Height) frameLabel:SetWidth(label.Width) - if not category.Saved.IsCombined then frameLabel:SetAnchor(label.Position, category.Frame, label.PositionTarget, label.OffsetX, label.OffsetY) end - frameLabel:SetHidden(not category.Saved.LabelShow and not category.Saved.IsCombined and not base.Global.EnableSettings) + if not category.Saved.Bar.IsCombined then frameLabel:SetAnchor(label.Position, category.Frames.Frame, label.PositionTarget, label.Offset.X, label.Offset.Y) end + frameLabel:SetHidden(not category.Saved.Label.Show and not category.Saved.Bar.IsCombined and not base.Global.EnableSettings) end - local frameLabelButton = category.FrameLabelButton + local frameLabelButton = category.Frames.LabelButton if frameLabelButton ~= nil then frameLabelButton:SetHidden(false) frameLabelButton:SetFont(label.Font) frameLabelButton:SetHorizontalAlignment(TEXT_ALIGN_LEFT) frameLabelButton:SetVerticalAlignment(TOP) - frameLabelButton:SetText(string.format("%s%s", tostring(category.Saved.Display), base.GetLabelPostFix(category))) + frameLabelButton:SetText(string.format("%s%s", tostring(category.Saved.Label.Display), base:GetLabelPostFix(category))) end - local frameLabelToggleSettings = category.FrameToggleSettings + local frameLabelToggleSettings = category.Frames.ToggleSettings if frameLabelToggleSettings ~= nil then frameLabelToggleSettings:SetHidden(false) end end -function base.RemoveLabel(category) - if category.FrameLabel ~= nil then - category.FrameLabel:ClearAnchors() - category.FrameLabel:SetHidden(true) +function base:RemoveLabel(category) + base:Debug("RemoveLabel", category) + if category.Frames.Label ~= nil then + category.Frames.Label:ClearAnchors() + category.Frames.Label:SetHidden(true) end - if category.FrameLabelButton ~= nil then category.FrameLabelButton:SetHidden(true) end + if category.Frames.LabelButton ~= nil then category.Frames.LabelButton:SetHidden(true) end - if category.FrameToggleSettings ~= nil then category.FrameToggleSettings:SetHidden(true) end + if category.Frames.ToggleSettings ~= nil then category.Frames.ToggleSettings:SetHidden(true) end end -function base.RestoreCombineLabels() +function base:RestoreCombineLabels() + base:Debug("RestoreCombineLabels") local combineLabel = base.Saved.Combine.Label local width = 0 local height = 0 - for _, category in pairs(base.CategoriesOrdered) do - if category.Saved.Enabled and category.Saved.IsCombined and category.FrameLabel then + for _, category in ipairs(base.CategoriesOrdered) do + if category.Saved.Enabled and category.Saved.Bar.IsCombined and category.Frames.Label then if (not category.IsEmpty or base.Global.EnableSettings) then - local hasSelected = not base.HasAny(category.Saved.Selected) - category.FrameLabel:ClearAnchors() - category.FrameLabel:SetHidden(not hasSelected and not category.Saved.LabelShow and not base.Global.EnableSettings) - if not category.FrameLabel:IsHidden() or (category.Saved.LabelShow and hasSelected) or base.Global.EnableSettings then - width = width + category.Saved.Label.OffsetX - local offsetY = category.Saved.Label.OffsetY + combineLabel.OffsetY - category.FrameLabel:SetAnchor(TOPLEFT, base.Global.Combine.HideAll, TOPLEFT, width, offsetY) - width = width + category.FrameLabel:GetWidth() - local labelHeight = category.FrameLabel:GetHeight() + local hasSelected = not base:HasAny(category.Saved.Selected) + category.Frames.Label:ClearAnchors() + category.Frames.Label:SetHidden(not hasSelected and not category.Saved.Label.Show and not base.Global.EnableSettings) + if not category.Frames.Label:IsHidden() or (category.Saved.Label.Show and hasSelected) or base.Global.EnableSettings then + width = width + category.Saved.Label.Offset.X + local offsetY = category.Saved.Label.Offset.Y + combineLabel.Offset.Y + category.Frames.Label:SetAnchor(TOPLEFT, base.Global.Combine.Frames.HideAll, TOPLEFT, width, offsetY) + width = width + category.Frames.Label:GetWidth() + local labelHeight = category.Frames.Label: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 + local frame = base.Global.Combine.Frames.HideAll + if frame ~= nil and base.Global.Combine.Frames.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) + frame:SetAnchor(combineLabel.Position, base.Global.Combine.Frames.Frame, combineLabel.PositionTarget, combineLabel.Offset.X, combineLabel.Offset.Y) end end diff --git a/CBs_Logging.lua b/CBs_Logging.lua new file mode 100644 index 0000000..e7f086f --- /dev/null +++ b/CBs_Logging.lua @@ -0,0 +1,45 @@ +--[[ +Author: Jarth +Filename: CBs_Logging.lua +]] -- +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local base = CollectionBars +local loggers = base.Loggers +local texts = base.Texts + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +------------------------------------------------------------------------------------------------- +function base:LogInitialize(...) + if LibDebugLogger ~= nil and loggers.Logger == nil then + loggers.Logger = LibDebugLogger(base.Addon.Name) + loggers.Debug = loggers.Logger:Create("debug") + loggers.Verbose = loggers.Logger:Create("verbose") + base:Info(...) + base:LogsSetEnabled() + end +end + +function base:LogsSetEnabled() + if base.Saved then + local forceChange = base:LogSetEnabled(loggers.Logger, base.Saved and base.Saved.Logging.Info, "Logging") + base:LogSetEnabled(loggers.Debug, base.Saved and base.Saved.Logging.Debug, "Logging debug", forceChange) + base:LogSetEnabled(loggers.Verbose, base.Saved and base.Saved.Logging.Verbose, "Logging verbose", forceChange) + end +end + +function base:LogSetEnabled(logger, doLogging, loggerType, forceChange) + if logger ~= nil and (logger.enabled ~= doLogging or forceChange) then + logger:SetEnabled(doLogging) + logger:Info("LogSetEnabled:", loggerType, doLogging) + return true + end +end + +function base:Info(...) if loggers.Logger ~= nil and ... ~= nil then loggers.Logger:Info(...) end end + +function base:Debug(...) if loggers.Debug ~= nil and ... ~= nil then loggers.Debug:Debug(...) end end + +function base:Verbose(...) if loggers.Verbose ~= nil and ... ~= nil then loggers.Verbose:Verbose(...) end end diff --git a/CBs_MoveFrame.lua b/CBs_MoveFrame.lua index a1c1a06..7c27299 100644 --- a/CBs_MoveFrame.lua +++ b/CBs_MoveFrame.lua @@ -11,19 +11,18 @@ local texts = base.Texts ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- -function base.GetMoveFrameSnapPosition(frame, positionTargetXY, snapSize) +function base:GetMoveFrameSnapPosition(frame, positionTargetXY, snapSize) + base:Verbose("GetMoveFrameSnapPosition", frame, positionTargetXY, snapSize) local left, top = frame:GetLeft(), frame:GetTop() local width, height = frame:GetWidth(), frame:GetHeight() local x, y = left, top - -- if positionTargetXY == TOPLEFT or positionTargetXY == TOP or positionTargetXY == TOPRIGHT then y = top if positionTargetXY == LEFT or positionTargetXY == CENTER or positionTargetXY == RIGHT then y = top + height / 2 elseif positionTargetXY == BOTTOMLEFT or positionTargetXY == BOTTOM or positionTargetXY == BOTTOMRIGHT then y = top + height end - -- if positionTargetXY == TOPLEFT or positionTargetXY == LEFT or positionTargetXY == BOTTOMLEFT then x = left if positionTargetXY == TOP or positionTargetXY == CENTER or positionTargetXY == BOTTOM then x = left + width / 2 elseif positionTargetXY == TOPRIGHT or positionTargetXY == RIGHT or positionTargetXY == BOTTOMRIGHT then @@ -33,13 +32,14 @@ function base.GetMoveFrameSnapPosition(frame, positionTargetXY, snapSize) return (zo_round(x / snapSize) * snapSize), (zo_round(y / snapSize) * snapSize) end -function base.UpdateMoveFrame(category) - local moveFrame = category.MoveFrame - local targetFrame = category.Frame +function base:UpdateMoveFrame(category) + base:Debug("UpdateMoveFrame", category) + local moveFrame = category.Frames.Move + local targetFrame = category.Frames.Frame local onMouseEnter, onMouseExit, onMouseDown, onMouseUp = nil, nil, nil, nil - if base.Global.IsMoveEnabled and (category.Name == "Combine" or not category.IsEmpty and not category.Saved.IsCombined) then - moveFrame = base.GetOrCreateMoveFrame(targetFrame, category) + if base.Global.IsMoveEnabled and (category.Name == "Combine" or not category.IsEmpty and not category.Saved.Bar.IsCombined) then + moveFrame = base:GetOrCreateMoveFrame(targetFrame, category) onMouseEnter = function(frame) frame.MoveFrameUpdateText(frame, true) end onMouseExit = function(frame) frame.MoveFrameUpdateText(frame, false) end @@ -49,7 +49,7 @@ function base.UpdateMoveFrame(category) frame.MoveFrameOnUpdate(frame) frame.MoveFrameUpdateText(frame, false) frame:SetHandler("OnUpdate", nil) - saved.X, saved.Y = base.GetMoveFrameSnapPosition(frame, category.Saved.Label.PositionTarget, frame.Saved.SnapSize) + saved.Bar.Offset.X, saved.Bar.Offset.Y = base:GetMoveFrameSnapPosition(frame, category.Saved.Label.PositionTarget, frame.Saved.Bar.SnapSize) end end @@ -70,8 +70,9 @@ function base.UpdateMoveFrame(category) end end -function base.GetOrCreateMoveFrame(targetFrame, category) - if category.MoveFrame == nil then +function base:GetOrCreateMoveFrame(targetFrame, category) + base:Debug("GetOrCreateMoveFrame", targetFrame, category) + if category.Frames.Move == nil then local moveFrameName = string.format("%s_MoveFrame", category.Name) local newMoveFrame = base.WM:CreateControlFromVirtual(moveFrameName, GuiRoot, string.format(texts.FormatAbbreviationLowDash, "MoveFrame")) @@ -83,14 +84,14 @@ function base.GetOrCreateMoveFrame(targetFrame, category) local labelTextTopLeft = "" if (position) then - labelTextTopLeft = string.format(texts.Format.Comma, base.GetMoveFrameSnapPosition(frame.TargetFrame, category.Saved.Label.PositionTarget, frame.Saved.SnapSize)) + labelTextTopLeft = string.format(texts.Format.Comma, base:GetMoveFrameSnapPosition(frame.TargetFrame, category.Saved.Label.PositionTarget, frame.Saved.Bar.SnapSize)) end frame.labelCenter:SetText(string.format(texts.Format.Comma, frame:GetWidth(), frame:GetHeight())) frame.labelTopLeft:SetText(labelTextTopLeft) end newMoveFrame["MoveFrameOnUpdate"] = function(frame) - local x, y = base.GetMoveFrameSnapPosition(frame, category.Saved.Label.PositionTarget, frame.Saved.SnapSize) + local x, y = base:GetMoveFrameSnapPosition(frame, category.Saved.Label.PositionTarget, frame.Saved.Bar.SnapSize) frame.TargetFrame:ClearAnchors() frame.TargetFrame:SetAnchor(category.Saved.Label.PositionTarget, GuiRoot, TOPLEFT, x, y) frame.MoveFrameUpdateText(frame, true) @@ -118,8 +119,8 @@ function base.GetOrCreateMoveFrame(targetFrame, category) newMoveFrame.labelCenter:SetVerticalAlignment(TEXT_ALIGN_CENTER) end - category.MoveFrame = newMoveFrame + category.Frames.Move = newMoveFrame end - return category.MoveFrame + return category.Frames.Move end diff --git a/CBs_Settings.lua b/CBs_Settings.lua index e0ba2c0..a936a08 100644 --- a/CBs_Settings.lua +++ b/CBs_Settings.lua @@ -11,114 +11,122 @@ local texts = base.Texts ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- -function base.InitializeSettingsSlash() SLASH_COMMANDS[base.Addon.SettingsSlash] = function() base.ToggleEnableSettings(base.ShowSettings()) end end +function base:InitializeSettingsSlash() SLASH_COMMANDS[base.Addon.SettingsSlash] = function() base:ToggleEnableSettings(base.ShowSettings()) end end -function base.ToggleEnableSettings(forceShow) +function base:ToggleEnableSettings(forceShow) + base:Debug("ToggleEnableSettings", forceShow) if forceShow ~= nil then base.Global.EnableSettings = forceShow else base.Global.EnableSettings = not base.Global.EnableSettings end - base.RestoreFrames() - base.RestoreCombineLabels() + base:RestoreFrames() + base:RestoreCombineLabels() end -function base.SetupToggleSettings(category) +function base:SetupToggleSettings(category) + base:Debug("SetupToggleSettings", category) local toggleSettings = GetControl(string.format(texts.FormatAbbreviationLowDash .. "%sToggleSettings", "HideAll", category.Name)) if toggleSettings then - local hideAllSettingsFunc = function() base.ShowSettings(category) end + local hideAllSettingsFunc = function() base:ShowSettings(category) end toggleSettings:SetHandler("OnClicked", hideAllSettingsFunc) end end -function base.UpdateToggleSettings(category) +function base:UpdateToggleSettings(category) + base:Debug("UpdateToggleSettings", category) local offsetX = 0 if base.Global.EnableSettings then offsetX = -19 end - if category.FrameLabel and category.FrameToggleSettings then - category.FrameToggleSettings:ClearAnchors() - category.FrameToggleSettings:SetAnchor(TOPLEFT, category.FrameLabel, TOPRIGHT, offsetX, 0) - category.FrameToggleSettings:SetAnchor(BOTTOMRIGHT, category.FrameLabel, BOTTOMRIGHT, 0, 0) + if category.Frames.Label and category.Frames.ToggleSettings then + category.Frames.ToggleSettings:ClearAnchors() + category.Frames.ToggleSettings:SetAnchor(TOPLEFT, category.Frames.Label, TOPRIGHT, offsetX, 0) + category.Frames.ToggleSettings:SetAnchor(BOTTOMRIGHT, category.Frames.Label, BOTTOMRIGHT, 0, 0) end - if category.FrameLabel and category.FrameLabelButton then - category.FrameLabelButton:ClearAnchors() - category.FrameLabelButton:SetAnchor(TOPLEFT, category.FrameLabel, TOPLEFT, 0, 0) - category.FrameLabelButton:SetAnchor(BOTTOMRIGHT, category.FrameLabel, BOTTOMRIGHT, offsetX, 0) + if category.Frames.Label and category.Frames.LabelButton then + category.Frames.LabelButton:ClearAnchors() + category.Frames.LabelButton:SetAnchor(TOPLEFT, category.Frames.Label, TOPLEFT, 0, 0) + category.Frames.LabelButton:SetAnchor(BOTTOMRIGHT, category.Frames.Label, BOTTOMRIGHT, offsetX, 0) end end -function base.SetupSettingsFrameHandlers(control, text, onClicked) +function base:SetupSettingsFrameHandlers(control, text, onClicked) + base:Debug("SetupSettingsFrameHandlers", control, text, onClicked) control.tooltipText = text control:SetHandler("OnClicked", onClicked) control:SetHandler("OnMouseEnter", function(_control) ZO_Tooltips_ShowTextTooltip(_control, BOTTOM, _control.tooltipText) end) control:SetHandler("OnMouseExit", function() ZO_Tooltips_HideTextTooltip() end) end -function base.SetupSetttingsFrame(category) +function base:SetupSetttingsFrame(category) + base:Debug("SetupSetttingsFrame", category) local selector = string.format(texts.FormatAbbreviationLowDash, "Settings") - base.Global.SettingsFrame = base.WM:CreateControlFromVirtual(selector, GuiRoot, selector) + base.Global.Settings.Frame = base.WM:CreateControlFromVirtual(selector, GuiRoot, selector) base.Global.SettingsLabel = GetControl(string.format("%sLabel", selector)) - base.Global.SettingsList = CBs_Settings_List:New(category, base.Global.SettingsFrame) + base.Global.Settings.List = CBs_Settings_List:New(category, base.Global.Settings.Frame) local titleControl = GetControl(string.format("%sTitle", selector)) titleControl:SetText(string.format("%s Settings", base.Addon.DisplayName)) - if base.Global.SettingsFrame.closeFrame == nil then base.Global.SettingsFrame.closeFrame = GetControl(base.Global.SettingsFrame, "Close") end - if base.Global.SettingsFrame.closeFrame then - base.SetupSettingsFrameHandlers(base.Global.SettingsFrame.closeFrame, "Close", function(buttonControl) buttonControl:GetParent():SetHidden(true) end) + if base.Global.Settings.Frame.closeFrame == nil then base.Global.Settings.Frame.closeFrame = GetControl(base.Global.Settings.Frame, "Close") end + if base.Global.Settings.Frame.closeFrame then + base:SetupSettingsFrameHandlers(base.Global.Settings.Frame.closeFrame, "Close", function(buttonControl) buttonControl:GetParent():SetHidden(true) end) end - if base.Global.SettingsFrame.moveFrame == nil then base.Global.SettingsFrame.moveFrame = GetControl(base.Global.SettingsFrame, "Move") end - if base.Global.SettingsFrame.moveFrame then - base.SetupSettingsFrameHandlers(base.Global.SettingsFrame.moveFrame, texts.Settings.ToggleMoveFrameText, function() + if base.Global.Settings.Frame.moveFrame == nil then base.Global.Settings.Frame.moveFrame = GetControl(base.Global.Settings.Frame, "Move") end + if base.Global.Settings.Frame.moveFrame then + base:SetupSettingsFrameHandlers(base.Global.Settings.Frame.moveFrame, texts.Settings.ToggleMoveFrameText, function() base.Global.IsMoveEnabled = not base.Global.IsMoveEnabled - base.Global.SettingsList:RefreshData() - base.RestoreFrames() + base.Global.Settings.List:RefreshData() + base:RestoreFrames() end) end - if base.Global.SettingsFrame.refreshFrame == nil then base.Global.SettingsFrame.refreshFrame = GetControl(base.Global.SettingsFrame, "Refresh") end - if base.Global.SettingsFrame.refreshFrame then - base.SetupSettingsFrameHandlers(base.Global.SettingsFrame.refreshFrame, texts.Settings.ReloadText, function() - if base.Global.SettingsList.category ~= nil then - base.CreateCategory(base.Global.SettingsList.category) - base.RestoreFrame(base.Global.SettingsList.category) + if base.Global.Settings.Frame.refreshFrame == nil then base.Global.Settings.Frame.refreshFrame = GetControl(base.Global.Settings.Frame, "Refresh") end + if base.Global.Settings.Frame.refreshFrame then + base:SetupSettingsFrameHandlers(base.Global.Settings.Frame.refreshFrame, texts.Settings.ReloadText, function() + if base.Global.Settings.List.category ~= nil then + base:CreateCategory(base.Global.Settings.List.category) + base:RestoreFrame(base.Global.Settings.List.category) end - base.RestoreCombineLabels() - base.Global.SettingsList:RefreshData() + base:RestoreCombineLabels() + base.Global.Settings.List:RefreshData() end) end - for controlName, displayName in pairs(base.Global.SettingsFilters) do base.SetupSettingsFilter(base.Global.SettingsFrame, controlName, displayName) end + for controlName, displayName in pairs(base.Global.Settings.Filters) do base:SetupSettingsFilter(base.Global.Settings.Frame, controlName, displayName) end end -function base.SetupSettingsFilter(control, controlName, displayName) +function base:SetupSettingsFilter(control, controlName, displayName) + base:Debug("SetupSettingsFilter", control, controlName, displayName) local filterControl = GetControl(control, controlName) if filterControl then - base.SetControlText(filterControl, displayName) + base:SetControlText(filterControl, displayName) filterControl:SetHandler("OnClicked", function() - base.Global.SettingsList.masterListType = controlName - base.Global.SettingsList:RefreshFilters() + base.Global.Settings.List.masterListType = controlName + base.Global.Settings.List:RefreshFilters() end) end end -function base.ShowSettings(category) - local show = base.Global.SettingsFrame == nil - if show then base.SetupSetttingsFrame(category) end +function base:ShowSettings(category) + base:Debug("ShowSettings", category) + local show = base.Global.Settings.Frame == nil + if show then base:SetupSetttingsFrame(category) end - show = show or base.Global.SettingsFrame:IsHidden() or category ~= base.Global.SettingsList.category - base.Global.SettingsFrame:SetHidden(not show) - base.UpdateSettingsType(show, category) + show = show or base.Global.Settings.Frame:IsHidden() or category ~= base.Global.Settings.List.category + base.Global.Settings.Frame:SetHidden(not show) + base:UpdateSettingsType(show, category) if show then - base.Global.SettingsList.category = show and category or nil - base.Global.SettingsList:RefreshData() + base.Global.Settings.List.category = show and category or nil + base.Global.Settings.List:RefreshData() end return show end -function base.UpdateSettingsType(show, category) - if base.Global.SettingsList ~= nil then base.Global.SettingsList.category = category end +function base:UpdateSettingsType(show, category) + base:Debug("UpdateSettingsType", show, category) + if base.Global.Settings.List ~= nil then base.Global.Settings.List.category = category end if base.Global.SettingsLabel ~= nil then base.Global.SettingsLabel:SetText(show and category and category.Name or "Global") end end diff --git a/CBs_Settings_Data.lua b/CBs_Settings_Data.lua index 78dc382..17799c4 100644 --- a/CBs_Settings_Data.lua +++ b/CBs_Settings_Data.lua @@ -12,16 +12,17 @@ local texts = base.Texts -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- function base.AppendMasterListTypeGeneral(self, listType) + base:Debug("AppendMasterListTypeGeneral", self, listType) self:AppendRow_Checkbox(listType, { name = "Use account settings", tooltip = "When ON the account settings will be used. When OFF character settings will be used", funcGet = function() return base.Saved.UseAccountSettings end, funcSet = function(_, newValue) - base.SetAndUpdateAccountSettings(newValue) - base.InitializeWithSavedData() - base.RestoreFrames() - base.RestoreCombineLabels() - base.Global.SettingsList:RefreshData() + base:SetAndUpdateAccountSettings(newValue) + base:InitializeWithSavedData() + base:RestoreFrames() + base:RestoreCombineLabels() + base.Global.Settings.List:RefreshData() end }) self:AppendRow_Button(listType, { @@ -29,20 +30,20 @@ function base.AppendMasterListTypeGeneral(self, listType) buttonName = "Remove", disabledFunc = base.GetCharacterSettingsDisabledState, funcSet = function() - base.RemoveCharacterSettings() - base.Global.SettingsList:RefreshData() + base:RemoveCharacterSettings() + base.Global.Settings.List:RefreshData() end }) self:AppendRow_Button(listType, { name = "Reset settings", buttonName = "Reset", funcSet = function() - base.ResetAccountSettings() - base.SetAndUpdateAccountSettings() - base.InitializeWithSavedData() - base.RestoreFrames() - base.RestoreCombineLabels() - base.Global.SettingsList:RefreshData() + base:ResetAccountSettings() + base:SetAndUpdateAccountSettings() + base:InitializeWithSavedData() + base:RestoreFrames() + base:RestoreCombineLabels() + base.Global.Settings.List:RefreshData() end }) self:AppendRow_Title(listType, {name = "Position and size"}) @@ -53,78 +54,78 @@ function base.AppendMasterListTypeGeneral(self, listType) funcGet = function() return base.Global.IsMoveEnabled end, funcSet = function(_, newValue) base.Global.IsMoveEnabled = newValue - base.RestoreFrames() + base:RestoreFrames() end }) self:AppendRow_Slider(listType, { name = "Choose snap size when moving", tooltipText = "Choose snap size when moving", - funcGet = function() return base.Saved.SnapSize end, + funcGet = function() return base.Saved.Bar.SnapSize end, funcSet = function(sliderControl, newValue) local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") if valueLabel then valueLabel:SetText(newValue) end - base.Saved.SnapSize = newValue - base.RestoreFrames() + base.Saved.Bar.SnapSize = newValue + base:RestoreFrames() end, minValue = 1, maxValue = 10, valueStep = 1, - default = base.Default.SnapSize, + default = base.Default.Bar.SnapSize, valueFormat = texts.Format.Number, showValue = true }) self:AppendRow_Slider(listType, { name = "Choose max bar depth", tooltipText = "Choose max bar depth\n(number of inverse rows/columns)", - funcGet = function() return base.Saved.BarDepth end, + funcGet = function() return base.Saved.Bar.Depth end, funcSet = function(sliderControl, newValue) local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") if valueLabel then valueLabel:SetText(newValue) end - base.Saved.BarDepth = newValue - base.RestoreFrames() + base.Saved.Bar.Depth = newValue + base:RestoreFrames() end, minValue = 0, maxValue = base.Global.HighestUnlocked, valueStep = 1, - default = base.Default.BarDepth, + default = base.Default.Bar.Depth, valueFormat = texts.Format.Number, showValue = true }) self:AppendRow_Slider(listType, { name = "Choose max bar height", tooltipText = "Choose max bar height\n(number of inverse rows/columns)", - funcGet = function() return base.Saved.BarWidth end, + funcGet = function() return base.Saved.Bar.Width end, funcSet = function(sliderControl, newValue) local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") if valueLabel then valueLabel:SetText(newValue) end - base.Saved.BarWidth = newValue - base.RestoreFrames() + base.Saved.Bar.Width = newValue + base:RestoreFrames() end, minValue = 0, maxValue = base.Global.HighestUnlocked, valueStep = 1, - default = base.Default.BarWidth, + default = base.Default.Bar.Width, valueFormat = texts.Format.Number, showValue = true }) self:AppendRow_Checkbox(listType, { name = "Show binding's on bar", tooltipText = "When ON the binding's will be shown on the bar", - funcGet = function() return base.Saved.ShowBinding end, + funcGet = function() return base.Saved.Bindings.Show end, funcSet = function(_, newValue) - base.Saved.ShowBinding = newValue - base.RestoreFrames() + base.Saved.Bindings.Show = newValue + base:RestoreFrames() end }) self:AppendRow_Slider(listType, { name = "Choose button size", tooltipText = "Choose button size", - funcGet = function() return base.Saved.ButtonXY end, + funcGet = function() return base.Saved.Button.Size end, funcSet = function(sliderControl, newValue) local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") if valueLabel then valueLabel:SetText(newValue) end - base.Saved.ButtonXY = newValue - base.RestoreFrames() + base.Saved.Button.Size = newValue + base:RestoreFrames() end, minValue = 1, maxValue = 100, @@ -134,108 +135,85 @@ function base.AppendMasterListTypeGeneral(self, listType) showValue = true }) - local whenOnTheBar = "When ON the bar will show the bar " + local showBars = "Show bars " + local whenOnTheBar = "When ON the bars will shown " self:AppendRow_Title(listType, {name = "Visibility"}) self:AppendRow_Divider(listType, {}) + + for _, scene in ipairs(base.Global.Scenes) do + self:AppendRow_Checkbox(listType, { + name = string.format(scene.Description, showBars), + tooltipText = string.format(scene.Description, whenOnTheBar), + funcGet = function() return base.Saved.Scene[scene.Name] end, + funcSet = function(_, newValue) + base.Saved.Scene[scene.Name] = newValue + base:UpdateFragments(scene.Name) + end + }) + end + + self:AppendRow_Title(listType, {name = "Active and activation"}) + self:AppendRow_Divider(listType, {}) self:AppendRow_Checkbox(listType, { - name = "Show bar on main view/hud", - tooltipText = string.format("%s on main view/hud", whenOnTheBar), - funcGet = function() return base.Saved.ShowBarOnHud end, - funcSet = function(_, newValue) - base.Saved.ShowBarOnHud = newValue - base.UpdateFragments("ShowBarOnHud") - end - }) - self:AppendRow_Checkbox(listType, { - name = "Show bar on the main view when an overlay is activated/hudui", - tooltipText = string.format("%s on the main view when an overlay is activated/hudui", whenOnTheBar), - funcGet = function() return base.Saved.ShowBarOnHudUI end, - funcSet = function(_, newValue) - base.Saved.ShowBarOnHudUI = newValue - base.UpdateFragments("ShowBarOnHudUI") - end - }) - self:AppendRow_Checkbox(listType, { - name = "Show bar in menu", - tooltipText = string.format("%s in menu", whenOnTheBar), - funcGet = function() return base.Saved.ShowBarInMenu end, - funcSet = function(_, newValue) - base.Saved.ShowBarInMenu = newValue - base.UpdateFragments("ShowBarInMenu") - end - }) - self:AppendRow_Checkbox(listType, { - name = "Show bar in the inventory", - tooltipText = string.format("%s in the inventory", whenOnTheBar), - funcGet = function() return base.Saved.ShowBarInInventory end, - funcSet = function(_, newValue) - base.Saved.ShowBarInInventory = newValue - base.UpdateFragments("ShowBarInInventory") - end - }) - self:AppendRow_Checkbox(listType, { - name = "Show bar in interactions", - tooltipText = string.format("%s in interactions", whenOnTheBar), - funcGet = function() return base.Saved.ShowBarInInteract end, - funcSet = function(_, newValue) - base.Saved.ShowBarInInteract = newValue - base.UpdateFragments("ShowBarInInteract") - end - }) - self:AppendRow_Checkbox(listType, { - name = "Show bar at a bank", - tooltipText = string.format("%s at a bank", whenOnTheBar), - funcGet = function() return base.Saved.ShowBarInBank end, + name = "Show active and activation", + tooltipText = "When ON the active collectibles will be highlighted, and activation animation will display", + funcGet = function() return base.Saved.Button.IsActiveActivationEnabled end, funcSet = function(_, newValue) - base.Saved.ShowBarInBank = newValue - base.UpdateFragments("ShowBarInBank") + base.Saved.Button.IsActiveActivationEnabled = newValue + base:RestoreFrames() end }) + + self:AppendRow_Title(listType, {name = "Audio"}) + self:AppendRow_Divider(listType, {}) self:AppendRow_Checkbox(listType, { - name = "Show bar at a fence", - tooltipText = string.format("%s at a fence", whenOnTheBar), - funcGet = function() return base.Saved.ShowBarInFence end, + name = "Play hover audio", + tooltipText = "When ON hover events on the bar, will play audio", + funcGet = function() return base.Saved.Button.IsAudioEnabled end, funcSet = function(_, newValue) - base.Saved.ShowBarInFence = newValue - base.UpdateFragments("ShowBarInFence") + base.Saved.Button.IsAudioEnabled = newValue + base:RestoreFrames() end }) + self:AppendRow_Title(listType, {name = "Logging"}) + self:AppendRow_Divider(listType, {}) self:AppendRow_Checkbox(listType, { - name = "Show bar at a store", - tooltipText = string.format("%s at a store", whenOnTheBar), - funcGet = function() return base.Saved.ShowBarInStore end, + name = "Enable logging", + tooltipText = "When ON the addon will do logging\nDependsOn: LibDebugLogger", + disabledFunc = function() return base.Loggers.Logger == nil end, + funcGet = function() return base.Saved.Logging.Info end, funcSet = function(_, newValue) - base.Saved.ShowBarInStore = newValue - base.UpdateFragments("ShowBarInStore") + base.Saved.Logging.Info = newValue + if not newValue then base.Saved.Logging.Debug = newValue end + if not newValue then base.Saved.Logging.Verbose = newValue end + base.Global.Settings.List:RefreshData() + base:LogsSetEnabled() end }) - - self:AppendRow_Title(listType, {name = "Active and activation"}) - self:AppendRow_Divider(listType, {}) self:AppendRow_Checkbox(listType, { - name = "Show active and activation", - tooltipText = "When ON the active collectibles will be highlighted, and activation animation will display", - funcGet = function() return base.Saved.IsActiveActivationEnabled end, + name = "Enable logging debug", + tooltipText = "When ON the addon will do logging debug\nDependsOn: LibDebugLogger\n And Enable logging ON", + disabledFunc = function() return base.Loggers.Debug == nil or not base.Saved.Logging.Info end, + funcGet = function() return base.Saved.Logging.Debug end, funcSet = function(_, newValue) - base.Saved.IsActiveActivationEnabled = newValue - base.RestoreFrames() + base.Saved.Logging.Debug = newValue + base:LogSetEnabled(base.Loggers.Debug, newValue, "Logging debug") end }) - - self:AppendRow_Title(listType, {name = "Audio"}) - self:AppendRow_Divider(listType, {}) self:AppendRow_Checkbox(listType, { - name = "Play hover audio", - tooltipText = "When ON hover events on the bar, will play audio", - funcGet = function() return base.Saved.IsAudioEnabled end, + name = "Enable logging verbose", + tooltipText = "When ON the addon will do logging debug\nDependsOn: LibDebugLogger\n And Enable logging ON", + disabledFunc = function() return base.Loggers.Verbose == nil or not base.Saved.Logging.Info end, + funcGet = function() return base.Saved.Logging.Verbose end, funcSet = function(_, newValue) - base.Saved.IsAudioEnabled = newValue - base.RestoreFrames() + base.Saved.Logging.Verbose = newValue + base:LogSetEnabled(base.Loggers.Verbose, newValue, "Logging verbose") end }) end function base.AppendMasterListTypeCategories(self, listType) + base:Debug("AppendMasterListTypeCategories", self, listType) self:AppendRow_Title(listType, {name = "Categories"}) self:AppendRow_Divider(listType, {}) @@ -246,31 +224,33 @@ function base.AppendMasterListTypeCategories(self, listType) name = string.format("Show %s", category.Name), hasChildren = category.HasChildren, parentKey = category.ParentKey, - tooltipText = string.format("When ON the collection category:\n%s will enabled\n\nPress the 'cog' to display collectible in the tabs: 'Collectibles' and 'Category'\n and Right click wil also change the tab", category.Name), + tooltipText = string.format( + "When ON the collection category:\n%s will enabled\n\nPress the 'cog' to display collectible in the tabs: 'Collectibles' and 'Category'\n and Right click wil also change the tab", + category.Name), funcGet = function() return category.Saved.Enabled end, disabledFunc = function() return category.Disabled end, funcSet = function(_, newValue) category.Saved.Enabled = newValue if newValue then - base.InitializeCategory(category) + base:InitializeCategory(category) else - base.RemoveLabel(category) - base.RemoveFrame(category) + base:RemoveLabel(category) + base:RemoveFrame(category) if self.category == category then self.category = nil - base.UpdateSettingsType(true, nil) + base:UpdateSettingsType(true, nil) end end - if category.Saved.IsCombined then base.RestoreCombineLabels() end - base.Global.SettingsList:RefreshData() + if category.Saved.Bar.IsCombined then base:RestoreCombineLabels() end + base.Global.Settings.List:RefreshData() end, funcCog = function(button) self.category = category - base.UpdateSettingsType(true, category) - base.Global.SettingsList:RefreshData() - if button == MOUSE_BUTTON_INDEX_RIGHT then - base.Global.SettingsList.masterListType = "Collectibles" - base.Global.SettingsList:RefreshFilters() + base:UpdateSettingsType(true, category) + base.Global.Settings.List:RefreshData() + if button == MOUSE_BUTTON_INDEX_RIGHT then + base.Global.Settings.List.masterListType = "Collectibles" + base.Global.Settings.List:RefreshFilters() end end } @@ -285,60 +265,61 @@ function base.AppendMasterListTypeCategories(self, listType) end function base.AppendMasterListTypeCombined(self, listType) + base:Debug("AppendMasterListTypeCombined", self, listType) self:AppendRow_Title(listType, {name = "Display names and labels"}) self:AppendRow_Divider(listType, {}) self:AppendRow_Slider(listType, { name = "Display name offset horizontal", tooltipText = "Display name offset horizontal\n(X)", - funcGet = function() return base.Saved.Combine.Label.OffsetX end, + funcGet = function() return base.Saved.Combine.Label.Offset.X end, funcSet = function(sliderControl, newValue) local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") if valueLabel then valueLabel:SetText(newValue) end - base.Saved.Combine.Label.OffsetX = newValue - base.RestoreCombineLabels() + base.Saved.Combine.Label.Offset.X = newValue + base:RestoreCombineLabels() end, minValue = -500, maxValue = 500, valueStep = 1, - default = base.Default.Combine.Label.OffsetX, + default = base.Default.Combine.Label.Offset.X, valueFormat = texts.Format.Number, showValue = true }) self:AppendRow_Slider(listType, { name = "Display name offset vertical", tooltipText = "Display name offset vertical\n(Y)", - funcGet = function() return base.Saved.Combine.Label.OffsetY end, + funcGet = function() return base.Saved.Combine.Label.Offset.Y end, funcSet = function(sliderControl, newValue) local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") if valueLabel then valueLabel:SetText(newValue) end - base.Saved.Combine.Label.OffsetY = newValue - base.RestoreCombineLabels() + base.Saved.Combine.Label.Offset.Y = newValue + base:RestoreCombineLabels() end, minValue = -500, maxValue = 500, valueStep = 1, - default = base.Default.Combine.Label.OffsetY, + default = base.Default.Combine.Label.Offset.Y, valueFormat = texts.Format.Number, showValue = true }) self:AppendRow_Dropdown(listType, { name = "Display name anchor position on button", tooltipText = "Select display name anchor position on the button", - funcGet = function() return base.GetLocationText(base.Saved.Combine.Label.PositionTarget) end, + funcGet = function() return base:GetLocationText(base.Saved.Combine.Label.PositionTarget) end, choices = base.Global.ChoiceLocations, funcSet = function(_, newValue) - base.Saved.Combine.Label.PositionTarget = base.GetLocationValue(newValue) - base.RestoreCombineLabels() + base.Saved.Combine.Label.PositionTarget = base:GetLocationValue(newValue) + base:RestoreCombineLabels() end }) self:AppendRow_Dropdown(listType, { name = "Display name anchor position on label", tooltipText = "Select display name anchor position on the label", - funcGet = function() return base.GetLocationText(base.Saved.Combine.Label.Position) end, + funcGet = function() return base:GetLocationText(base.Saved.Combine.Label.Position) end, choices = base.Global.ChoiceLocations, funcSet = function(_, newValue) - base.Saved.Combine.Label.Position = base.GetLocationValue(newValue) - base.RestoreCombineLabels() + base.Saved.Combine.Label.Position = base:GetLocationValue(newValue) + base:RestoreCombineLabels() end }) self:AppendRow_Title(listType, {name = "Position and size"}) @@ -346,40 +327,41 @@ function base.AppendMasterListTypeCombined(self, listType) self:AppendRow_Slider(listType, { name = "Choose default bar depth", tooltipText = "Choose default bar depth\n(number of rows/columns)", - funcGet = function() return base.Saved.Combine.BarDepth end, + funcGet = function() return base.Saved.Combine.Bar.Depth end, funcSet = function(sliderControl, newValue) local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") if valueLabel then valueLabel:SetText(newValue) end - base.Saved.Combine.BarDepth = newValue - base.RestoreFrames() + base.Saved.Combine.Bar.Depth = newValue + base:RestoreFrames() end, minValue = 0, maxValue = base.Global.HighestUnlocked, valueStep = 1, - default = base.Default.BarDepth, + default = base.Default.Bar.Depth, valueFormat = texts.Format.Number, showValue = true }) self:AppendRow_Slider(listType, { name = "Choose max bar height", tooltipText = "Choose max bar height\n(number of inverse rows/columns)", - funcGet = function() return base.Saved.Combine.BarWidth end, + funcGet = function() return base.Saved.Combine.Bar.Width end, funcSet = function(sliderControl, newValue) local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") if valueLabel then valueLabel:SetText(newValue) end - base.Saved.Combine.BarWidth = newValue - base.RestoreFrames() + base.Saved.Combine.Bar.Width = newValue + base:RestoreFrames() end, minValue = 0, maxValue = base.Global.HighestUnlocked, valueStep = 1, - default = base.Default.BarWidth, + default = base.Default.Bar.Width, valueFormat = texts.Format.Number, showValue = true }) end function base.AppendMasterListTypeCollectibles(self, listType) + base:Debug("AppendMasterListTypeCollectibles", self, listType) self:AppendRow_Title(listType, {name = "Collectibles"}) self:AppendRow_Divider(listType, {}) self:AppendRow_Checkbox(listType, { @@ -388,31 +370,45 @@ function base.AppendMasterListTypeCollectibles(self, listType) funcGet = function() return self.category.Saved.MenuShowDisabled end, funcSet = function(_, newValue) self.category.Saved.MenuShowDisabled = newValue - base.CreateCategory(self.category) - base.Global.SettingsList:RefreshData() + base:CreateCategory(self.category) + base.Global.Settings.List:RefreshData() + end + }) + self:AppendRow_Divider(listType, {}) + self:AppendRow_Checkbox(listType, { + name = string.format("Auto select all %s", self.category.Name), + tooltipText = string.format("When pressed all %s will be available", self.category.Name), + funcGet = function() return self.category.Saved.AutoSelectAll end, + funcSet = function(_, newValue) + self.category.Saved.AutoSelectAll = newValue + base:AutoSelectAll(self.category, newValue) + base:RestoreFrame(self.category) + base:RestoreCombineLabels() + base.Global.Settings.List:RefreshData() end }) self:AppendRow_Divider(listType, {}) self:AppendRow_Checkbox(listType, { name = string.format("Select all %s", self.category.Name), tooltipText = string.format("When pressed all %s will either be selected or deselected", self.category.Name), - funcGet = function() return base.IsAllSelected(self.category) end, + disabledFunc = function() return self.category.Saved.AutoSelectAll end, + funcGet = function() return base:IsAllSelected(self.category) end, funcSet = function(_, newValue) - base.SelectAll(self.category, newValue) - base.RestoreFrame(self.category) - base.RestoreCombineLabels() - base.Global.SettingsList:RefreshData() + base:SelectAll(self.category, newValue) + base:RestoreFrame(self.category) + base:RestoreCombineLabels() + base.Global.Settings.List:RefreshData() end }) self:AppendRow_Divider(listType, {}) - for _, collectible in ipairs(self.category.CollectionOrdered or {}) do + for _, collectible in ipairs(self.category.CollectionOrdered) do if self.category.Saved.MenuShowDisabled and collectible.Disabled or not collectible.Disabled then self:AppendRow_Checkbox(listType, { cId = collectible.Id, name = string.format("Show %s", collectible.Name), tooltipText = collectible.Tooltip, funcGet = function() return self.category.Saved.Selected[collectible.Id] end, - disabledFunc = function() return collectible.Disabled end, + disabledFunc = function() return collectible.Disabled or self.category.Saved.AutoSelectAll end, funcSet = function(checkBoxControl, newValue) local control = checkBoxControl:GetParent() if not (control.data.disabledFunc and control.data.disabledFunc()) then @@ -421,9 +417,9 @@ function base.AppendMasterListTypeCollectibles(self, listType) else self.category.Saved.Selected[control.data.cId] = nil end - base.RestoreFrame(self.category) - base.RestoreCombineLabels() - base.Global.SettingsList:RefreshData() + base:RestoreFrame(self.category) + base:RestoreCombineLabels() + base.Global.Settings.List:RefreshData() end end @@ -433,6 +429,7 @@ function base.AppendMasterListTypeCollectibles(self, listType) end function base.AppendMasterListTypeCategory(self, listType) + base:Debug("AppendMasterListTypeCategory", self, listType) local disabledWhenTooltipIsHidden = "Disabled when tooltip is not shown" local disabledWhenLabelIsHidden = "Disabled when label is not shown" local disabledWhenCombined = "Disabled when Collection is included in combine bar" @@ -445,8 +442,8 @@ function base.AppendMasterListTypeCategory(self, listType) funcGet = function() return self.category.Saved.Tooltip.Show end, funcSet = function(_, newValue) self.category.Saved.Tooltip.Show = newValue - base.SetupButtons(self.category) - base.Global.SettingsList:RefreshData() + base:SetupButtons(self.category) + base.Global.Settings.List:RefreshData() end }) self:AppendRow_Dropdown(listType, { @@ -454,10 +451,10 @@ function base.AppendMasterListTypeCategory(self, listType) tooltipText = string.format("Select tooltip anchor position\n%s", disabledWhenTooltipIsHidden), choices = base.Global.ChoiceLocations, disabledFunc = function() return not self.category.Saved.Tooltip.Show end, - funcGet = function() return base.GetLocationText(self.category.Saved.Tooltip.Position) end, + funcGet = function() return base:GetLocationText(self.category.Saved.Tooltip.Position) end, funcSet = function(_, newValue) - self.category.Saved.Tooltip.Position = base.GetLocationValue(newValue) - base.SetupButtons(self.category) + self.category.Saved.Tooltip.Position = base:GetLocationValue(newValue) + base:SetupButtons(self.category) end }) @@ -466,181 +463,177 @@ function base.AppendMasterListTypeCategory(self, listType) self:AppendRow_Checkbox(listType, { name = "Include in combine bar", tooltipText = "When ON will be attached to a combined bar", - funcGet = function() return self.category.Saved.IsCombined end, + funcGet = function() return self.category.Saved.Bar.IsCombined end, funcSet = function(_, newValue) - self.category.Saved.IsCombined = newValue - base.RestoreFrame(self.category) - base.RestoreCombineLabels() - base.Global.SettingsList:RefreshData() + self.category.Saved.Bar.IsCombined = newValue + base:RestoreFrame(self.category) + base:RestoreCombineLabels() + base.Global.Settings.List:RefreshData() end }) self:AppendRow_Divider(listType, {}) self:AppendRow_Checkbox(listType, { name = "Enable hide/toggle visibility of the label", tooltipText = string.format("When enabled a +/- at the end of the label indicates if the label is hidden or shown\n%s", disabledWhenCombined), - disabledFunc = function() return self.category.Saved.IsCombined end, - funcGet = function() return self.category.Saved.IsCombined or self.category.Saved.HideAllEnabled end, + disabledFunc = function() return self.category.Saved.Bar.IsCombined end, + funcGet = function() return self.category.Saved.Bar.IsCombined or self.category.Saved.Label.EnableHideAll end, funcSet = function(_, newValue) if (not newValue) then - self.category.Saved.HideAll = newValue - base.RestoreFrame(self.category) + self.category.Saved.Bar.HideAll = newValue + base:RestoreFrame(self.category) end - self.category.Saved.HideAllEnabled = newValue - self.category.Saved.LabelShow = true - base.SetupLabel(self.category) - base.RestoreLabel(self.category) - base.Global.SettingsList:RefreshData() + self.category.Saved.Label.EnableHideAll = newValue + self.category.Saved.Label.Show = true + base:SetupLabel(self.category) + base:RestoreLabel(self.category) + base.Global.Settings.List:RefreshData() end }) self:AppendRow_Checkbox(listType, { name = "Show label", tooltipText = string.format("%s or hide/toggle visibility is enabled", disabledWhenCombined), - disabledFunc = function() return self.category.Saved.HideAllEnabled or self.category.Saved.IsCombined end, - funcGet = function() return self.category.Saved.LabelShow or self.category.Saved.IsCombined end, + disabledFunc = function() return self.category.Saved.Label.EnableHideAll or self.category.Saved.Bar.IsCombined end, + funcGet = function() return self.category.Saved.Label.Show or self.category.Saved.Bar.IsCombined end, funcSet = function(_, newValue) - self.category.Saved.LabelShow = newValue - base.SetupLabel(self.category) - base.RestoreLabel(self.category) - base.Global.SettingsList:RefreshData() + self.category.Saved.Label.Show = newValue + base:SetupLabel(self.category) + base:RestoreLabel(self.category) + base.Global.Settings.List:RefreshData() end }) self:AppendRow_EditBox(listType, { name = "Display name", tooltipText = string.format("Change displayname used on the label\n%s", disabledWhenLabelIsHidden), - disabledFunc = function() - return not self.category.Saved.LabelShow - end, - funcGet = function() - return tostring(self.category.Saved.Display) - end, + disabledFunc = function() return not self.category.Saved.Label.Show end, + funcGet = function() return tostring(self.category.Saved.Bar.Display) end, funcSet = function(control) - self.category.Saved.Display = control:GetText() or "" - base.RestoreFrame(self.category) - base.RestoreCombineLabels() + self.category.Saved.Bar.Display = control:GetText() or "" + base:RestoreFrame(self.category) + base:RestoreCombineLabels() end }) self:AppendRow_Dropdown(listType, { name = "Display name font", tooltipText = string.format("Change display name font\n%s", disabledWhenLabelIsHidden), - disabledFunc = function() return not self.category.Saved.LabelShow end, + disabledFunc = function() return not self.category.Saved.Label.Show end, choices = base.Global.AvailableFonts, funcGet = function() return self.category.Saved.Label.Font end, funcSet = function(_, newValue) self.category.Saved.Label.Font = newValue - base.RestoreFrame(self.category) - base.RestoreCombineLabels() + base:RestoreFrame(self.category) + base:RestoreCombineLabels() end }) self:AppendRow_Slider(listType, { name = "Display name height", tooltipText = string.format("Change display name height\n%s", disabledWhenLabelIsHidden), - disabledFunc = function() return not self.category.Saved.LabelShow end, + disabledFunc = function() return not self.category.Saved.Label.Show end, funcGet = function() return self.category.Saved.Label.Height end, funcSet = function(sliderControl, newValue) local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") if valueLabel then valueLabel:SetText(newValue) end self.category.Saved.Label.Height = newValue - base.RestoreFrame(self.category) - base.RestoreCombineLabels() + base:RestoreFrame(self.category) + base:RestoreCombineLabels() end, minValue = 0, maxValue = 100, valueStep = 1, - default = base.Default[self.category.Name].Label.Height, + default = base.Default.Categories[self.category.Id].Label.Height, valueFormat = texts.Format.Number, showValue = true }) self:AppendRow_Slider(listType, { name = "Display name width", tooltipText = string.format("Change display name width\n%s", disabledWhenLabelIsHidden), - disabledFunc = function() return not self.category.Saved.LabelShow end, + disabledFunc = function() return not self.category.Saved.Label.Show end, funcGet = function() return self.category.Saved.Label.Width end, funcSet = function(sliderControl, newValue) local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") if valueLabel then valueLabel:SetText(newValue) end self.category.Saved.Label.Width = newValue - base.RestoreFrame(self.category) - base.RestoreCombineLabels() + base:RestoreFrame(self.category) + base:RestoreCombineLabels() end, minValue = 0, maxValue = 500, valueStep = 1, - default = base.Default[self.category.Name].Label.Width, + default = base.Default.Categories[self.category.Id].Label.Width, valueFormat = texts.Format.Number, showValue = true }) self:AppendRow_Slider(listType, { name = "Display name offset horizontal", tooltipText = string.format("Display name offset horizontal\n(X)\n%s", disabledWhenLabelIsHidden), - disabledFunc = function() return not self.category.Saved.LabelShow end, - funcGet = function() return self.category.Saved.Label.OffsetX end, + disabledFunc = function() return not self.category.Saved.Label.Show end, + funcGet = function() return self.category.Saved.Label.Offset.X end, funcSet = function(sliderControl, newValue) local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") if valueLabel then valueLabel:SetText(newValue) end - self.category.Saved.Label.OffsetX = newValue - base.RestoreFrame(self.category) - base.RestoreCombineLabels() + self.category.Saved.Label.Offset.X = newValue + base:RestoreFrame(self.category) + base:RestoreCombineLabels() end, minValue = -500, maxValue = 500, valueStep = 1, - default = base.Default[self.category.Name].Label.OffsetX, + default = base.Default.Categories[self.category.Id].Label.Offset.X, valueFormat = texts.Format.Number, showValue = true }) self:AppendRow_Slider(listType, { name = "Display name offset vertical", tooltipText = string.format("Display name offset vertical\n(y)\n%s", disabledWhenLabelIsHidden), - disabledFunc = function() return not self.category.Saved.LabelShow end, - funcGet = function() return self.category.Saved.Label.OffsetY end, + disabledFunc = function() return not self.category.Saved.Label.Show end, + funcGet = function() return self.category.Saved.Label.Offset.Y end, funcSet = function(sliderControl, newValue) local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") if valueLabel then valueLabel:SetText(newValue) end - self.category.Saved.Label.OffsetY = newValue - base.RestoreFrame(self.category) - base.RestoreCombineLabels() + self.category.Saved.Label.Offset.Y = newValue + base:RestoreFrame(self.category) + base:RestoreCombineLabels() end, minValue = -500, maxValue = 500, valueStep = 1, - default = base.Default[self.category.Name].Label.OffsetY, + default = base.Default.Categories[self.category.Id].Label.Offset.Y, valueFormat = texts.Format.Number, showValue = true }) self:AppendRow_Dropdown(listType, { name = "Display name anchor position on button", tooltipText = string.format("Select display name anchor position on the button\n%s\n or Collection is included in combine bar", disabledWhenLabelIsHidden), - disabledFunc = function() return not self.category.Saved.LabelShow or self.category.Saved.IsCombined end, + disabledFunc = function() return not self.category.Saved.Label.Show or self.category.Saved.Bar.IsCombined end, funcGet = function() - if self.category.Saved.IsCombined then - return base.GetLocationText(base.Saved.Combine.Label.PositionTarget) + if self.category.Saved.Bar.IsCombined then + return base:GetLocationText(base.Saved.Combine.Label.PositionTarget) else - return base.GetLocationText(self.category.Saved.Label.PositionTarget) + return base:GetLocationText(self.category.Saved.Label.PositionTarget) end end, choices = base.Global.ChoiceLocations, funcSet = function(_, newValue) - self.category.Saved.Label.PositionTarget = base.GetLocationValue(newValue) - base.RestoreFrame(self.category) - base.RestoreCombineLabels() + self.category.Saved.Label.PositionTarget = base:GetLocationValue(newValue) + base:RestoreFrame(self.category) + base:RestoreCombineLabels() end }) self:AppendRow_Dropdown(listType, { name = "Display name anchor position on label", tooltipText = string.format("Select display name anchor position on the label\n%s\n or Collection is included in combine bar", disabledWhenLabelIsHidden), - disabledFunc = function() return not self.category.Saved.LabelShow or self.category.Saved.IsCombined end, + disabledFunc = function() return not self.category.Saved.Label.Show or self.category.Saved.Bar.IsCombined end, funcGet = function() - if self.category.Saved.IsCombined then - return base.GetLocationText(base.Saved.Combine.Label.Position) + if self.category.Saved.Bar.IsCombined then + return base:GetLocationText(base.Saved.Combine.Label.Position) else - return base.GetLocationText(self.category.Saved.Label.Position) + return base:GetLocationText(self.category.Saved.Label.Position) end end, choices = base.Global.ChoiceLocations, funcSet = function(_, newValue) - self.category.Saved.Label.Position = base.GetLocationValue(newValue) - base.RestoreFrame(self.category) - base.RestoreCombineLabels() + self.category.Saved.Label.Position = base:GetLocationValue(newValue) + base:RestoreFrame(self.category) + base:RestoreCombineLabels() end }) @@ -649,54 +642,55 @@ function base.AppendMasterListTypeCategory(self, listType) self:AppendRow_Slider(listType, { name = "Choose bar depth", tooltipText = string.format("Choose bar depth\n(number of rows/columns)\n%s", disabledWhenCombined), - disabledFunc = function() return self.category.Saved.IsCombined end, - funcGet = function() return self.category.Saved.BarDepth end, + disabledFunc = function() return self.category.Saved.Bar.IsCombined end, + funcGet = function() return self.category.Saved.Bar.Depth end, funcSet = function(sliderControl, newValue) local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") if valueLabel then valueLabel:SetText(newValue) end - self.category.Saved.BarDepth = newValue - base.RestoreFrame(self.category) - base.RestoreCombineLabels() + self.category.Saved.Bar.Depth = newValue + base:RestoreFrame(self.category) + base:RestoreCombineLabels() end, minValue = 0, maxValue = self.category.Unlocked, valueStep = 1, - default = base.Default[self.category.Name].BarDepth, + default = base.Default.Categories[self.category.Id].Bar.Depth, valueFormat = texts.Format.Number, showValue = true }) self:AppendRow_Slider(listType, { name = "Choose max bar height", tooltipText = string.format("Choose bar height\n(number of inverse rows/columns)\n%s", disabledWhenCombined), - disabledFunc = function() return self.category.Saved.IsCombined end, - funcGet = function() return self.category.Saved.BarWidth end, + disabledFunc = function() return self.category.Saved.Bar.IsCombined end, + funcGet = function() return self.category.Saved.Bar.Width end, funcSet = function(sliderControl, newValue) local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") if valueLabel then valueLabel:SetText(newValue) end - self.category.Saved.BarWidth = newValue - base.RestoreFrame(self.category) - base.RestoreCombineLabels() + self.category.Saved.Bar.Width = newValue + base:RestoreFrame(self.category) + base:RestoreCombineLabels() end, minValue = 0, maxValue = self.category.Unlocked, valueStep = 1, - default = base.Default[self.category.Name].BarWidth, + default = base.Default.Categories[self.category.Id].Bar.Width, showValue = true }) self:AppendRow_Checkbox(listType, { name = "Bar orientation horizontal", tooltipText = string.format("Bar orientation horizontal\n%s", disabledWhenCombined), - disabledFunc = function() return self.category.Saved.IsCombined end, - funcGet = function() return self.category.Saved.Horizontal end, + disabledFunc = function() return self.category.Saved.Bar.IsCombined end, + funcGet = function() return self.category.Saved.Bar.Horizontal end, funcSet = function(_, newValue) - self.category.Saved.Horizontal = newValue - base.RestoreFrame(self.category) - base.RestoreCombineLabels() + self.category.Saved.Bar.Horizontal = newValue + base:RestoreFrame(self.category) + base:RestoreCombineLabels() end }) end function base.AppendMasterListTypeNoCategory(self, listType) + base:Debug("AppendMasterListTypeNoCategory", self, listType) self:AppendRow_Title(listType, {name = "Select a category"}) self:AppendRow_Divider(listType, {}) end diff --git a/CBs_Settings_List.lua b/CBs_Settings_List.lua index 276840d..95784d7 100644 --- a/CBs_Settings_List.lua +++ b/CBs_Settings_List.lua @@ -14,12 +14,14 @@ local texts = base.Texts CBs_Settings_List = ZO_SortFilterList:Subclass() function CBs_Settings_List:New(...) + base:Debug("CBs_Settings_List:New", ...) self.list = ZO_SortFilterList.New(self, ...) self.masterListType = "Collectibles" return self.list end function CBs_Settings_List:Initialize(category, ...) + base:Debug("CBs_Settings_List:Initialize", ...) ZO_SortFilterList.Initialize(self, ...) self.category = category self.masterList = {} @@ -34,6 +36,7 @@ end ------------------------------------------------------------------------------------------------- function CBs_Settings_List:AppendDataTypes() + base:Debug("CBs_Settings_List:AppendDataTypes") local listRowAnd = string.format(texts.FormatAbbreviationLowDash .. "_ListRow_%%s", "Settings") local dataTypes = { [10] = {name = string.format(listRowAnd, "Checkbox"), height = 40, func = function(...) self:SetupRow_Checkbox(...) end}, @@ -55,12 +58,14 @@ end ------------------------------------------------------------------------------------------------- function CBs_Settings_List:AppendRow_Checkbox(listType, data) + base:Debug("CBs_Settings_List:AppendRow_Checkbox", listType, data) data.listType = listType data.dataTypeId = 10 table.insert(self.masterList, data) end function CBs_Settings_List:SetupRow_Checkbox(control, data) + base:Debug("CBs_Settings_List:SetupRow_Checkbox", control, data) control.data = data ZO_SortFilterList.SetupRow(self, control, data) @@ -82,19 +87,21 @@ function CBs_Settings_List:SetupRow_Checkbox(control, data) end function CBs_Settings_List:AppendRow_Category_Title(listType, data) + base:Debug("CBs_Settings_List:AppendRow_Category_Title", listType, data) data.listType = listType data.dataTypeId = 11 table.insert(self.masterList, data) end function CBs_Settings_List:SetupRow_Category_Title(control, data) + base:Debug("CBs_Settings_List:SetupRow_Category_Title", control, data) control.data = data ZO_SortFilterList.SetupRow(self, control, control.data) control:SetHandler("OnMouseUp", function() - local savedTypeData = base.Saved[data.name] + local savedTypeData = base.Saved.Categories[data.Id] if savedTypeData ~= nil then savedTypeData.ShowChildren = not savedTypeData.ShowChildren - base.Global.SettingsList:RefreshFilters() + base.Global.Settings.List:RefreshFilters() end end) @@ -104,12 +111,14 @@ function CBs_Settings_List:SetupRow_Category_Title(control, data) end function CBs_Settings_List:AppendRow_Category_Checkbox(listType, data) + base:Debug("CBs_Settings_List:AppendRow_Category_Checkbox", listType, data) data.listType = listType data.dataTypeId = 15 table.insert(self.masterList, data) end function CBs_Settings_List:SetupRow_Category_Checkbox(control, data) + base:Debug("CBs_Settings_List:SetupRow_Category_Checkbox", control, data) control.data = data self:SetupRow_Checkbox(control, data) control.button = GetControl(control, "Button") @@ -118,7 +127,7 @@ function CBs_Settings_List:SetupRow_Category_Checkbox(control, data) local isEnabled = control.data.funcGet and control.data.funcGet() ZO_CheckButton_SetEnableState(control.button, isEnabled) control.button:SetAlpha(isEnabled and 1 or 0.5) - base.SetupSettingsFrameHandlers(control.button, data.tooltipText, function(_, button) + base:SetupSettingsFrameHandlers(control.button, data.tooltipText, function(_, button) PlaySound(SOUNDS.SINGLE_SETTING_RESET_TO_DEFAULT) control.data.funcCog(button) end) @@ -129,12 +138,14 @@ function CBs_Settings_List:SetupRow_Category_Checkbox(control, data) end function CBs_Settings_List:AppendRow_Dropdown(listType, data) + base:Debug("CBs_Settings_List:AppendRow_Dropdown", listType, data) data.listType = listType data.dataTypeId = 20 table.insert(self.masterList, data) end function CBs_Settings_List:SetupRow_Dropdown(control, data) + base:Debug("CBs_Settings_List:SetupRow_Dropdown", control, data) control.data = data ZO_SortFilterList.SetupRow(self, control, data) @@ -151,12 +162,14 @@ function CBs_Settings_List:SetupRow_Dropdown(control, data) end function CBs_Settings_List:AppendRow_Slider(listType, data) + base:Debug("CBs_Settings_List:AppendRow_Slider", listType, data) data.listType = listType data.dataTypeId = 30 table.insert(self.masterList, data) end function CBs_Settings_List:SetupRow_Slider(control, data) + base:Debug("CBs_Settings_List:SetupRow_Slider", control, data) control.data = data ZO_SortFilterList.SetupRow(self, control, control.data) @@ -199,12 +212,14 @@ function CBs_Settings_List:SetupRow_Slider(control, data) end function CBs_Settings_List:AppendRow_EditBox(listType, data) + base:Debug("CBs_Settings_List:AppendRow_EditBox", listType, data) data.listType = listType data.dataTypeId = 40 table.insert(self.masterList, data) end function CBs_Settings_List:SetupRow_EditBox(control, data) + base:Debug("CBs_Settings_List:SetupRow_EditBox", control, data) control.data = data ZO_SortFilterList.SetupRow(self, control, control.data) @@ -221,12 +236,14 @@ function CBs_Settings_List:SetupRow_EditBox(control, data) end function CBs_Settings_List:AppendRow_Title(listType, data) + base:Debug("CBs_Settings_List:AppendRow_Title", listType, data) data.listType = listType data.dataTypeId = 50 table.insert(self.masterList, data) end function CBs_Settings_List:SetupRow_Title(control, data) + base:Debug("CBs_Settings_List:SetupRow_Title", control, data) control.data = data ZO_SortFilterList.SetupRow(self, control, data) @@ -237,12 +254,14 @@ function CBs_Settings_List:SetupRow_Title(control, data) end function CBs_Settings_List:AppendRow_Button(listType, data) + base:Debug("CBs_Settings_List:AppendRow_Button", listType, data) data.listType = listType data.dataTypeId = 60 table.insert(self.masterList, data) end function CBs_Settings_List:SetupRow_Button(control, data) + base:Debug("CBs_Settings_List:SetupRow_Button", control, data) control.data = data ZO_SortFilterList.SetupRow(self, control, control.data) @@ -257,6 +276,7 @@ function CBs_Settings_List:SetupRow_Button(control, data) end function CBs_Settings_List:AppendRow_Divider(listType, data) + base:Debug("CBs_Settings_List:AppendRow_Divider", listType, data) data.listType = listType data.dataTypeId = 100 table.insert(self.masterList, data) @@ -266,6 +286,7 @@ end -- FUNCTIONS - SetupRowType - Helpers -- ------------------------------------------------------------------------------------------------- function CBs_Settings_List.RepopulateDropdownOptions(control) + base:Debug("CBs_Settings_List.RepopulateDropdownOptions", control) control.comboBox:ClearItems() local selectedValue = control.data.funcGet() @@ -280,6 +301,7 @@ function CBs_Settings_List.RepopulateDropdownOptions(control) end function CBs_Settings_List.SetNameText(control, text, fontOverrides) + base:Debug("CBs_Settings_List.SetNameText", control, text, fontOverrides) if control.label == nil then control.label = GetControl(control, "Name") end if control.label ~= nil then if fontOverrides ~= nil then @@ -291,6 +313,7 @@ function CBs_Settings_List.SetNameText(control, text, fontOverrides) end function CBs_Settings_List.SetupIcon(control, data) + base:Debug("CBs_Settings_List.SetupIcon", control, data) if control.icon == nil then control.icon = GetControl(control, "Icon") end if control.icon ~= nil then local hasIcon = data.icon ~= nil @@ -306,6 +329,7 @@ function CBs_Settings_List.SetupIcon(control, data) end function CBs_Settings_List.SetActiveOrInactive(control) + base:Debug("CBs_Settings_List.SetActiveOrInactive", control) local disabled = control.data.disabledFunc and control.data.disabledFunc() control.label = GetControl(control, "Name") @@ -339,6 +363,7 @@ end -- FUNCTIONS - MasterList -- ------------------------------------------------------------------------------------------------- function CBs_Settings_List:BuildMasterList() + base:Debug("CBs_Settings_List:BuildMasterList") self.masterList = {} base.AppendMasterListTypeGeneral(self, "General") @@ -354,13 +379,14 @@ function CBs_Settings_List:BuildMasterList() end function CBs_Settings_List:FilterScrollList() + base:Debug("CBs_Settings_List:FilterScrollList") local scrollData = ZO_ScrollList_GetDataList(self.list) ZO_ClearNumericallyIndexedTable(scrollData) for i = 1, #self.masterList do if self.masterListType == nil or self.masterListType == self.masterList[i].listType then if self.masterListType == "Categories" and self.masterList[i].parentKey ~= nil then - local savedTypeData = base.Saved[self.masterList[i].parentKey] + local savedTypeData = base.Saved.Categories[self.masterList[i].parentKey] if savedTypeData ~= nil and savedTypeData.ShowChildren or savedTypeData == nil then scrollData[#scrollData + 1] = ZO_ScrollList_CreateDataEntry(self.masterList[i].dataTypeId, self.masterList[i]) end diff --git a/Changelog b/Changelog index c0e20a6..6367e2f 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,20 @@ ------------------------------------------------------------------------------- Collection bars ------------------------------------------------------------------------------- +Version 1.1.0 (21-06-2020) +Warning: With this version the saved variables will reset! + +Highlights: +- The settings have been rearanged for consistancy and to rework some features +- In the settings, categories are now stored on the category id rather than name +-- Makes the setup language agnostic +- Added feature when selecting collectibles, to "auto select all". +-- When "auto select all" is enabled, any valid unlocked collectible will be shown +-- When this setting is set, it will not save unique collectible id´s +-- If you get new collectibles you would need to manually reload the UI (or refresh the collection, top right in the settings panel) +- LibDebugLogger have been added as an optional dependency +-- It will only log when logging is enabled in the settings + Version 1.0.11 (01-06-2020) Highlights: - It is now possible to alter the displayname of categories (again) @@ -66,7 +80,7 @@ Version 1.0.6 (03-11-2019) - Fixed an issue when activating certan mementos: user:/AddOns/CollectionBars/CBs_Buttons.lua:125: operator + is not supported for nil + number -- Added guard, so start time defaults to 0 in: ---- base.GetCooldownText(countDown, duration) +--- base:GetCooldownText(countDown, duration) -- base.IsCollectibleUsable(button) Version 1.0.5 (08-09-2019) diff --git a/CollectionBars.lua b/CollectionBars.lua index 95d9297..7c55dab 100644 --- a/CollectionBars.lua +++ b/CollectionBars.lua @@ -13,45 +13,47 @@ local texts = base.Texts ------------------------------------------------------------------------------------------------- function base.OnAddOnLoaded(_, addonName) + base:LogInitialize("OnAddOnLoaded", addonName) if addonName == base.Addon.Name then - base.GenerateCategories() - base.Initialize() + base:GenerateCategories() + base:SetAndUpdateAccountSettings() + base:InitializeCombineFrame() + base:InitializeWithSavedData() + base:InitializeBindings() + base:InitializeSettingsSlash() + base:InitializeReverseBinding() + + EVENT_MANAGER:UnregisterForEvent(base.Addon.Name, EVENT_ADD_ON_LOADED) end + base:Info("OnAddOnLoaded:end", addonName) end -function base.Initialize() - base.SetAndUpdateAccountSettings() - base.InitializeCombineFrame() - base.InitializeBindings() - base.InitializeSettingsSlash() - base.InitializeReverseBinding() - base.InitializeWithSavedData() - - EVENT_MANAGER:UnregisterForEvent(base.Addon.Name, EVENT_ADD_ON_LOADED) -end - -function base.InitializeWithSavedData() - for _, category in pairs(base.Categories) do - category.Saved = base.Saved[category.Name] - if category.Saved.Enabled then base.InitializeCategory(category) end +function base:InitializeWithSavedData() + base:Debug("InitializeWithSavedData") + for categoryId, category in pairs(base.Categories) do + category.Saved = base.Saved.Categories[categoryId] + if category.Saved.Enabled then base:InitializeCategory(category) end end - base.InitializeCombine() - base.RestoreCombine() + base:InitializeCombine() + base:RestoreCombine() end -function base.InitializeCategory(category) - base.CreateCategory(category) - base.SetupLabel(category) - base.RestoreFrame(category) +function base:InitializeCategory(category) + base:Debug("InitializeCategory", category) + base:CreateCategory(category) + base:SetupLabel(category) + base:RestoreFrame(category) end -function base.InitializeCombineFrame() - base.Global.Combine.Frame = base.GetFrame(texts.CombineFrameName, texts.CombineFrameName) - base.Global.Combine.HideAll = base.GetFrame(texts.CombineFrameNameHideAll, texts.CombineFrameNameHideAll) +function base:InitializeCombineFrame() + base:Debug("InitializeCombineFrame") + base.Global.Combine.Frames.Frame = base:GetFrame(texts.CombineFrameName, texts.CombineFrameName) + base.Global.Combine.Frames.HideAll = base:GetFrame(texts.CombineFrameNameHideAll, texts.CombineFrameNameHideAll) end -function base.CreateCategory(category) +function base:CreateCategory(category) + base:Debug("CreateCategory", category) category.Collection = {} category.CollectionOrdered = {} category.Unlocked = GetTotalUnlockedCollectiblesByCategoryType(category.Type) @@ -60,6 +62,7 @@ function base.CreateCategory(category) for index, collectibleData in ZO_CollectibleCategoryData.SortedCollectibleIterator(category.CategoryData, {ZO_CollectibleData.IsShownInCollection}) do local isUnlocked = collectibleData:IsUnlocked() + -- TODO: Insert if new, update if exists... if isUnlocked or category.Saved.MenuShowDisabled then local collectibleId = collectibleData:GetId() -- TODO: IMPLEMENT BETTER TOOLTIPS... function ZO_Tooltip:LayoutCollectible(collectibleId, deprecatedCollectionName, collectibleName, collectibleNickname, isPurchasable, description, hint, deprecatedArg, categoryType, showVisualLayerInfo, cooldownSecondsRemaining, showBlockReason) @@ -75,55 +78,60 @@ function base.CreateCategory(category) end end - category.Frame = base.GetFrame(category.Name, string.format(texts.FormatAbbreviationLowDash, "Frame")) + category.Frames.Frame = base:GetFrame(string.format(texts.FormatCategoryName, category.Id), string.format(texts.FormatAbbreviationLowDash, "Frame")) end -function base.RestoreFrames() - for _, category in pairs(base.Categories) do base.RestoreFrame(category) end - base.RestoreCombine() +function base:RestoreFrames() + base:Debug("RestoreFrames") + for _, category in pairs(base.Categories) do base:RestoreFrame(category) end + base:RestoreCombine() end -function base.HideOthers(newCategory) +function base:HideOthers(newCategory) + base:Debug("HideOthers", newCategory) for _, category in pairs(base.Categories) do - if category.Saved.Enabled and category.Saved.IsCombined and not category.Saved.HideAll and category ~= newCategory then - category.Saved.HideAll = not category.Saved.HideAll - base.RestoreFrame(category) + if category.Saved.Enabled and category.Saved.Bar.IsCombined and not category.Saved.Bar.HideAll and category ~= newCategory then + category.Saved.Bar.HideAll = not category.Saved.Bar.HideAll + base:RestoreFrame(category) end end end -function base.RestoreFrame(category) +function base:RestoreFrame(category) + base:Debug("RestoreFrame", category) if category.Saved.Enabled then - base.RestoreLabel(category) - base.SetFrameAndCombineSize(category) - base.SetupButtons(category) - base.RestorePosition(category) - base.UpdateToggleSettings(category) - base.UpdateMoveFrame(category) - base.UpdateFragment(category) + base:RestoreLabel(category) + base:SetupButtons(category) + base:SetFrameAndCombineSize(category) + base:RestorePosition(category.Frames.Frame, category.Saved) + base:UpdateToggleSettings(category) + base:UpdateMoveFrame(category) + base:UpdateFragment(category) else - base.RemoveLabel(category) - base.RemoveFrame(category) + base:RemoveLabel(category) + base:RemoveFrame(category) end end -function base.RemoveFrame(category) - base.RemoveFragments(category) - for _, _value in ipairs(category.CollectionOrdered) do - local button = base.Buttons[_value.Id] - if button ~= nil then button:SetHidden(true) end - end +function base:RemoveFrame(category) + base:Debug("RemoveFrame", category) + base:RemoveFragments(category) + for _, button in ipairs(category.Buttons) do if button ~= nil then button:SetHidden(true) end end - if category.Frame ~= nil then category.Frame:SetHidden(true) end + if category.Frames.Frame ~= nil then + base:Debug("RemoveFrame:hide", category.Frames.Frame) + category.Frames.Frame:SetHidden(true) + end end -function base.InitializeCombine() base.Global.Combine.Saved = base.Saved.Combine 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) +function base:RestoreCombine() + base:Debug("RestoreCombine") + base:RestoreCombineLabels() + base:RestorePosition(base.Global.Combine.Frames.Frame, base.Saved.Combine) + base:UpdateMoveFrame(base.Global.Combine) + base:UpdateFragment(base.Global.Combine) end ------------------------------------------------------------------------------------------------- diff --git a/CollectionBars.txt b/CollectionBars.txt index c8e7f63..063958e 100644 --- a/CollectionBars.txt +++ b/CollectionBars.txt @@ -6,9 +6,10 @@ ## APIVersion: 100031 ## Title: Collection Bars -## Version: 1.0.11 +## AddOnVersion: 1011 +## Version: 1.1.0 ## Author: Jarth -## Description: Show collection bars and activate collections with key or button press. Shortcuts: Settings window: /cb +## Description: Show collection bars and activate collections with key or button press. Shortcuts: Settings window: /cb OptionalDependsOn: LibDebugLogger (Logging can be enabled in settings) ## ## This Add-on is not created by, affiliated with or sponsored by ZeniMax Media Inc. or its affiliates. ## The Elder Scrolls® and related logos are registered trademarks or trademarks of ZeniMax Media Inc. in the United States and/or other countries. @@ -17,11 +18,13 @@ ## You can read the full terms at https://account.elderscrollsonline.com/add-on-terms ## SavedVariables: CollectionBars_Account ## SavedVariables: CollectionBars_Character +## OptionalDependsOn: LibDebugLogger CBs_Settings.xml CBs_Button.xml CollectionBars.xml CBs_Constants.lua +CBs_Logging.lua CBs_Helpers.lua CBs_Button.lua CBs_Bindings.lua