diff --git a/Bindings.xml b/Bindings.xml index 17dda63..a2c161b 100644 --- a/Bindings.xml +++ b/Bindings.xml @@ -1,27 +1,69 @@ <Bindings> <Layer name="SI_KEYBINDINGS_LAYER_GENERAL"> <Category name="Collection bars"> - <Action name="CBs_Settings"><Down>CBs_ShowSettings()</Down></Action> - <Action name="CBs_1"><Down>CBs_Clicked(1)</Down></Action> - <Action name="CBs_2"><Down>CBs_Clicked(2)</Down></Action> - <Action name="CBs_3"><Down>CBs_Clicked(3)</Down></Action> - <Action name="CBs_4"><Down>CBs_Clicked(4)</Down></Action> - <Action name="CBs_5"><Down>CBs_Clicked(5)</Down></Action> - <Action name="CBs_6"><Down>CBs_Clicked(6)</Down></Action> - <Action name="CBs_7"><Down>CBs_Clicked(7)</Down></Action> - <Action name="CBs_8"><Down>CBs_Clicked(8)</Down></Action> - <Action name="CBs_9"><Down>CBs_Clicked(9)</Down></Action> - <Action name="CBs_10"><Down>CBs_Clicked(10)</Down></Action> - <Action name="CBs_11"><Down>CBs_Clicked(11)</Down></Action> - <Action name="CBs_12"><Down>CBs_Clicked(12)</Down></Action> - <Action name="CBs_13"><Down>CBs_Clicked(13)</Down></Action> - <Action name="CBs_14"><Down>CBs_Clicked(14)</Down></Action> - <Action name="CBs_15"><Down>CBs_Clicked(15)</Down></Action> - <Action name="CBs_16"><Down>CBs_Clicked(16)</Down></Action> - <Action name="CBs_17"><Down>CBs_Clicked(17)</Down></Action> - <Action name="CBs_18"><Down>CBs_Clicked(18)</Down></Action> - <Action name="CBs_19"><Down>CBs_Clicked(19)</Down></Action> - <Action name="CBs_20"><Down>CBs_Clicked(20)</Down></Action> - </Category> + <Action name="CBs_Settings"> + <Down>CBs_ShowSettings()</Down> + </Action> + <Action name="CBs_1"> + <Down>CBs_Clicked(1)</Down> + </Action> + <Action name="CBs_2"> + <Down>CBs_Clicked(2)</Down> + </Action> + <Action name="CBs_3"> + <Down>CBs_Clicked(3)</Down> + </Action> + <Action name="CBs_4"> + <Down>CBs_Clicked(4)</Down> + </Action> + <Action name="CBs_5"> + <Down>CBs_Clicked(5)</Down> + </Action> + <Action name="CBs_6"> + <Down>CBs_Clicked(6)</Down> + </Action> + <Action name="CBs_7"> + <Down>CBs_Clicked(7)</Down> + </Action> + <Action name="CBs_8"> + <Down>CBs_Clicked(8)</Down> + </Action> + <Action name="CBs_9"> + <Down>CBs_Clicked(9)</Down> + </Action> + <Action name="CBs_10"> + <Down>CBs_Clicked(10)</Down> + </Action> + <Action name="CBs_11"> + <Down>CBs_Clicked(11)</Down> + </Action> + <Action name="CBs_12"> + <Down>CBs_Clicked(12)</Down> + </Action> + <Action name="CBs_13"> + <Down>CBs_Clicked(13)</Down> + </Action> + <Action name="CBs_14"> + <Down>CBs_Clicked(14)</Down> + </Action> + <Action name="CBs_15"> + <Down>CBs_Clicked(15)</Down> + </Action> + <Action name="CBs_16"> + <Down>CBs_Clicked(16)</Down> + </Action> + <Action name="CBs_17"> + <Down>CBs_Clicked(17)</Down> + </Action> + <Action name="CBs_18"> + <Down>CBs_Clicked(18)</Down> + </Action> + <Action name="CBs_19"> + <Down>CBs_Clicked(19)</Down> + </Action> + <Action name="CBs_20"> + <Down>CBs_Clicked(20)</Down> + </Action> + </Category> </Layer> </Bindings> \ No newline at end of file diff --git a/CBs_Bindings.lua b/CBs_Bindings.lua index 6316687..d1e6085 100644 --- a/CBs_Bindings.lua +++ b/CBs_Bindings.lua @@ -11,52 +11,71 @@ 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] - - if control ~= nil and control.CBs then - local newCId = control:GetId() - local previousCId = collectibleId - - if previousCId ~= newCId then - 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) - end - end - - base.Saved.Bindings[keyId] = newCId - base.Global.ReverseBindings[newCId] = keyId - base:SetBindingText(newCId) - end - elseif collectibleId > 0 then - if base.AllButtons[collectibleId] then - base:Activate(base.AllButtons[collectibleId]) - else - UseCollectible(collectibleId) - end - end + base:Debug("CBs_Clicked", keyId) + + local control = base.WM:GetMouseOverControl() + local collectibleId = base.Saved.Bindings[keyId] + + if control ~= nil and control.CBs then + local newCId = control:GetId() + local previousCId = collectibleId + + if previousCId ~= newCId then + 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) + end + end + + base.Saved.Bindings[keyId] = newCId + base.Global.ReverseBindings[newCId] = keyId + base:SetBindingText(newCId) + end + elseif collectibleId > 0 then + if base.AllButtons[collectibleId] then + base:Activate(base.AllButtons[collectibleId]) + else + UseCollectible(collectibleId) + end + 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 + base:Debug("SetBindingText", cid) + + if base.AllButtons[cid] then + base.AllButtons[cid]:SetBindingText(base.Saved.Bindings.Show, cid) + end end 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 + 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() - base:Debug("InitializeReverseBinding") - for keyId, collectibleId in ipairs(base.Saved.Bindings) do if collectibleId > 0 then base.Global.ReverseBindings[collectibleId] = keyId end end + 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 2903841..ee575a5 100644 --- a/CBs_Button.lua +++ b/CBs_Button.lua @@ -14,179 +14,222 @@ local texts = base.Texts CBs_Button = ZO_Object:Subclass() 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(texts.FormatCategoryName, category.Id), frame, string.format(texts.FormatAbbreviationLowDash, "Button"), string.format("_B%s", cId)) - newB.cId = cId - newB.categoryId = categoryId - newB.ctrl = ctrl - newB.ctrl.cId = cId - newB.button = ctrl:GetNamedChild("Button") - newB.button:SetId(cId) - newB.button.tooltip = collectible.Name - newB.enabledTexture = collectible.EnabledTexture - newB.button.CBs = true - newB.icon = ctrl:GetNamedChild("Icon") - newB.cooldownIcon = ctrl:GetNamedChild("CooldownIcon") - newB.cooldownTime = ctrl:GetNamedChild("CooldownTime") - newB.buttonText = ctrl:GetNamedChild("ButtonText") - newB.cooldown = ctrl:GetNamedChild("Cooldown") - newB.cooldownCompleteAnim = ctrl:GetNamedChild("CooldownCompleteAnimation") - newB.status = ctrl:GetNamedChild("Status") - newB.inCooldown = false - newB.showingCooldown = false - newB.playSounds = false - end - - return newB + 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(texts.FormatCategoryName, category.Id), frame, string.format(texts.FormatAbbreviationLowDash, "Button"), string.format("_B%s", cId)) + newB.cId = cId + newB.categoryId = categoryId + newB.ctrl = ctrl + newB.ctrl.cId = cId + newB.button = ctrl:GetNamedChild("Button") + newB.button:SetId(cId) + newB.button.tooltip = collectible.Name + newB.enabledTexture = collectible.EnabledTexture + newB.button.CBs = true + newB.icon = ctrl:GetNamedChild("Icon") + newB.cooldownIcon = ctrl:GetNamedChild("CooldownIcon") + newB.cooldownTime = ctrl:GetNamedChild("CooldownTime") + newB.buttonText = ctrl:GetNamedChild("ButtonText") + newB.cooldown = ctrl:GetNamedChild("Cooldown") + newB.cooldownCompleteAnim = ctrl:GetNamedChild("CooldownCompleteAnimation") + newB.status = ctrl:GetNamedChild("Status") + newB.inCooldown = false + newB.showingCooldown = false + newB.playSounds = false + end + + return newB 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) + 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) - self.icon:SetTexture(self.enabledTexture) - self.icon:SetHidden(false) - - if self.cooldownIcon ~= nil then - self.cooldownIcon:SetTexture(self.enabledTexture) - self.cooldownIcon:SetDesaturation(1) - end - - self.button:SetHandler("OnClicked", function() base:Activate(self) end) - self.button:SetHandler("OnMouseEnter", function() - if self.playSounds then PlaySound(SOUNDS.QUICKSLOT_MOUSEOVER) 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) + base:Verbose("CBs_Button:Setup") + + self.ctrl:SetHidden(false) + self.icon:SetTexture(self.enabledTexture) + self.icon:SetHidden(false) + + if self.cooldownIcon ~= nil then + self.cooldownIcon:SetTexture(self.enabledTexture) + self.cooldownIcon:SetDesaturation(1) + end + + self.button:SetHandler("OnClicked", function() + base:Activate(self) + end) + self.button:SetHandler("OnMouseEnter", function() + if self.playSounds then + PlaySound(SOUNDS.QUICKSLOT_MOUSEOVER) + 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) - base:Verbose("CBs_Button:SetShowBindingText", visible) - self.buttonText:SetHidden(not 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) - self.icon:SetWidth(size - 6) + base:Verbose("CBs_Button:SetSize", size) + + self.ctrl:SetHeight(size) + self.ctrl:SetWidth(size) + self.icon:SetHeight(size - 6) + self.icon:SetWidth(size - 6) 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) - self.buttonText:ClearAnchors() - self.buttonText:SetText("") - if keyId ~= nil and show then - 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(texts.FormatAbbreviationLowDash, keyId), false) - end - end + base:Verbose("CBs_Button:SetBindingText", show, cId) + + local keyId = base.Global.ReverseBindings[cId] + + if self.buttonText ~= nil then + ZO_Keybindings_UnregisterLabelForBindingUpdate(self.buttonText) + self.buttonText:ClearAnchors() + self.buttonText:SetText("") + + if keyId ~= nil and show then + 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(texts.FormatAbbreviationLowDash, keyId), false) + end + end end function CBs_Button:OnClicked() - base:Verbose("CBs_Button:OnClicked") - if self.usable then UseCollectible(self.cId) end + base:Verbose("CBs_Button:OnClicked") + + if self.usable then + UseCollectible(self.cId) + end end function CBs_Button:UpdateState(forceId, isAttempting, isActiveActivationEnabled) - base:Verbose("CBs_Button:UpdateState", forceId, isAttempting) - local show = false - if isActiveActivationEnabled then show = self.cId == forceId and isAttempting or not forceId and IsCollectibleActive(self.cId) end - self.status:SetHidden(show == false) + base:Verbose("CBs_Button:UpdateState", forceId, isAttempting) + + local show = false + + 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 + base:Verbose("CBs_Button:UpdateUsable") - if usable ~= self.usable then self.usable = usable end + local isShowingCooldown = self.showingCooldown + local usable = false + + if not isShowingCooldown then + usable = true + end + + if usable ~= self.usable then + self.usable = usable + end end function CBs_Button:RefreshCooldown(remaining, duration, cooldown) - base:Verbose("CBs_Button:RefreshCooldown", remaining, duration, cooldown) - local percentComplete = (1 - remaining / duration) + base:Verbose("CBs_Button:RefreshCooldown", remaining, duration, cooldown) - self.icon.percentComplete = percentComplete - self.cooldownTime:SetText(cooldown) + local percentComplete = (1 - remaining / duration) + + self.icon.percentComplete = percentComplete + self.cooldownTime:SetText(cooldown) end function CBs_Button:UpdatePlaySounds(playSounds) - base:Verbose("CBs_Button:UpdatePlaySounds", playSounds) - self.playSounds = 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) - self.cooldownTime:SetHidden(not showCooldown) - - if showCooldown then - self.cooldown:StartCooldown(remaining, duration, CD_TYPE_RADIAL, nil, NO_LEADING_EDGE) - if self.cooldownCompleteAnim.animation then self.cooldownCompleteAnim.animation:GetTimeline():PlayInstantlyToStart() end - self.cooldown:SetHidden(false) - self.ctrl:SetHandler("OnUpdate", function() self:RefreshCooldown(remaining, duration, cooldown) end) - else - if self.showingCooldown then - if self.playSounds then PlaySound(SOUNDS.ABILITY_READY) end - - self.cooldownCompleteAnim.animation = self.cooldownCompleteAnim.animation or CreateSimpleAnimation(ANIMATION_TEXTURE, self.cooldownCompleteAnim) - self.cooldownCompleteAnim:SetHidden(false) - self.cooldown:SetHidden(false) - - self.cooldownCompleteAnim.animation:SetImageData(16, 1) - self.cooldownCompleteAnim.animation:SetFramerate(30) - self.cooldownCompleteAnim.animation:GetTimeline():PlayFromStart() - end - - self.icon.percentComplete = 1 - self.ctrl:SetHandler("OnUpdate", nil) - self.cooldown:ResetCooldown() - end - - if showCooldown ~= self.showingCooldown then - self.showingCooldown = showCooldown - - if self.showingCooldown then - ZO_ContextualActionBar_AddReference() - else - ZO_ContextualActionBar_RemoveReference() - end - end - - local textColor = showCooldown and INTERFACE_TEXT_COLOR_FAILED or INTERFACE_TEXT_COLOR_SELECTED - self.buttonText:SetColor(GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, textColor)) - - self:UpdateUsable() + base:Verbose("CBs_Button:UpdateCooldown", remaining, duration, cooldown) + + local showCooldown = duration > 0 + + self.cooldown:SetHidden(not showCooldown) + self.cooldownTime:SetHidden(not showCooldown) + + if showCooldown then + self.cooldown:StartCooldown(remaining, duration, CD_TYPE_RADIAL, nil, NO_LEADING_EDGE) + + if self.cooldownCompleteAnim.animation then + self.cooldownCompleteAnim.animation:GetTimeline():PlayInstantlyToStart() + end + + self.cooldown:SetHidden(false) + self.ctrl:SetHandler("OnUpdate", function() + self:RefreshCooldown(remaining, duration, cooldown) + end) + else + if self.showingCooldown then + if self.playSounds then + PlaySound(SOUNDS.ABILITY_READY) + end + + self.cooldownCompleteAnim.animation = self.cooldownCompleteAnim.animation or CreateSimpleAnimation(ANIMATION_TEXTURE, self.cooldownCompleteAnim) + self.cooldownCompleteAnim:SetHidden(false) + self.cooldown:SetHidden(false) + + self.cooldownCompleteAnim.animation:SetImageData(16, 1) + self.cooldownCompleteAnim.animation:SetFramerate(30) + self.cooldownCompleteAnim.animation:GetTimeline():PlayFromStart() + end + + self.icon.percentComplete = 1 + self.ctrl:SetHandler("OnUpdate", nil) + self.cooldown:ResetCooldown() + end + + if showCooldown ~= self.showingCooldown then + self.showingCooldown = showCooldown + + if self.showingCooldown then + ZO_ContextualActionBar_AddReference() + else + ZO_ContextualActionBar_RemoveReference() + end + end + + local textColor = showCooldown and INTERFACE_TEXT_COLOR_FAILED or INTERFACE_TEXT_COLOR_SELECTED + self.buttonText:SetColor(GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, textColor)) + + self:UpdateUsable() end function CBs_Button:SetHidden(value) - base:Verbose("CBs_Button:SetHidden", value) - self.ctrl: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 + base:Verbose("CBs_Button:IsHidden") + + local isHidden = self.ctrl:IsHidden() + + return isHidden end diff --git a/CBs_Buttons.lua b/CBs_Buttons.lua index 0635c01..05d88d9 100644 --- a/CBs_Buttons.lua +++ b/CBs_Buttons.lua @@ -12,163 +12,195 @@ local texts = base.Texts -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- 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) - - 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 + 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) + + 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:SetFrameAndCombineSize(category) - base:Debug("SetFrameAndCombineSize", category) - local width, height = base:GetBarWidthHeight(category) - base:SetFrameSizeIfExists(category.Frames.Frame, width, height) + 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 + 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) + base:Debug("GetFrame", name, virtual) - if frame == nil then frame = base.WM:CreateControlFromVirtual(name, GuiRoot, virtual) end + local frame = GetControl(name) - base:Debug("GetFrame:return", frame) - return frame + 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) - 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 - - base:Debug("GetButtonPosition", category.Name, index, left, top) - if not category.Saved.Bar.Horizontal then - return top, left - else - return left, top - end + 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 + + base:Debug("GetButtonPosition", category.Name, index, left, top) + + if not category.Saved.Bar.Horizontal then + return top, left + else + return left, top + end end 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.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 (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 - - 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 - end - - 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.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.Frames.Label then category.Frames.Label:SetHidden(isHidden) end + 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.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 (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 + + 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 + end + + 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.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.Frames.Label then + category.Frames.Label:SetHidden(isHidden) + end end function base:UpdateButtonsState(category, forceId, isAttemptingActivation) - base:Debug("UpdateButtonsState", category, forceId, isAttemptingActivation) - for _, button in pairs(category.Buttons) do if button ~= nil then button:UpdateState(forceId, isAttemptingActivation, base.Saved.Button.IsActiveActivationEnabled) end end + base:Debug("UpdateButtonsState", category, forceId, isAttemptingActivation) + + for _, button in pairs(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) - 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 + 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) - base:Debug("GetCooldownText", countDown, duration) - local cooldown = "" + base:Debug("GetCooldownText", countDown, duration) - if type(duration) == "number" and countDown.StartTime ~= nil then - local startTime = countDown.StartTime or 0 - local secondsRemaining = zo_max(startTime + duration - GetFrameTimeMilliseconds(), 0) / 1000 - cooldown = ZO_FormatTimeAsDecimalWhenBelowThreshold(secondsRemaining, 60) - end + local cooldown = "" - return cooldown + if type(duration) == "number" and countDown.StartTime ~= nil then + local startTime = countDown.StartTime or 0 + local secondsRemaining = zo_max(startTime + duration - GetFrameTimeMilliseconds(), 0) / 1000 + cooldown = ZO_FormatTimeAsDecimalWhenBelowThreshold(secondsRemaining, 60) + end + + return cooldown end 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) + 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 = category.Cooldown.StartTime or 0 - local _, duration = GetCollectibleCooldownAndDuration(button.cId) - isCollectibleUsable = startTime + duration < GetFrameTimeMilliseconds() - end + if not isCollectibleUsable and button.cId then + local startTime = category.Cooldown.StartTime or 0 + local _, duration = GetCollectibleCooldownAndDuration(button.cId) + isCollectibleUsable = startTime + duration < GetFrameTimeMilliseconds() + end - return isCollectibleUsable + return isCollectibleUsable end diff --git a/CBs_Constants.lua b/CBs_Constants.lua index 828a8f6..da41b10 100644 --- a/CBs_Constants.lua +++ b/CBs_Constants.lua @@ -6,88 +6,49 @@ Filename: CBs_Constants.lua -- VARIABLES -- ------------------------------------------------------------------------------------------------- CollectionBars = { - WM = GetWindowManager(), - Addon = {Name = "CollectionBars", DisplayName = "Collection Bars", Abbreviation = "CBs", Version = 1.1, MinorVersion = 9, SettingsSlash = "/cb", Author = "Jarth"}, - AllButtons = {}, - Default = { - UseAccountSettings = 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, - [4] = 0, - [5] = 0, - [6] = 0, - [7] = 0, - [8] = 0, - [9] = 0, - [10] = 0, - [11] = 0, - [12] = 0, - [13] = 0, - [14] = 0, - [15] = 0, - [16] = 0, - [17] = 0, - [18] = 0, - [19] = 0, - [20] = 0 - }, - 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 = {}, - 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"}, - 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, - ShowChildren = {} - }, - Categories = {}, - CategoriesOrdered = {}, - Texts = { - Font = {ZoFontWinT1 = "ZoFontWinT1", ZoFontWinH4 = "ZoFontWinH4"}, - Format = {Number = "%.2f", Decimal = "%d", Comma = "%s,%s"}, - Location = { - Bottom = "bottom", - BottomLeft = "bottomleft", - BottomRight = "bottomright", - Center = "center", - Left = "left", - Right = "right", - Top = "top", - TopLeft = "topleft", - TopRight = "topright" - }, - Settings = {ToggleMoveFrameText = "Toggle move frame", ReloadText = "Reload list of 'Collectibles'\nHint: Usefull after gaining a new collectible)"} - }, - Loggers = {} + WM = GetWindowManager(), + Addon = {Name = "CollectionBars", DisplayName = "Collection Bars", Abbreviation = "CBs", Version = 1.1, MinorVersion = 10, SettingsSlash = "/cb", Author = "Jarth"}, + AllButtons = {}, + Default = { + UseAccountSettings = 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, [4] = 0, [5] = 0, [6] = 0, [7] = 0, [8] = 0, [9] = 0, [10] = 0, [11] = 0, [12] = 0, [13] = 0, [14] = 0, [15] = 0, [16] = 0, [17] = 0, [18] = 0, [19] = 0, [20] = 0}, + 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 = {}, + 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"}, + 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, + ShowChildren = {} + }, + Categories = {}, + CategoriesOrdered = {}, + Texts = { + Font = {ZoFontWinT1 = "ZoFontWinT1", ZoFontWinH4 = "ZoFontWinH4"}, + Format = {Number = "%.2f", Decimal = "%d", Comma = "%s,%s"}, + Location = {Bottom = "bottom", BottomLeft = "bottomleft", BottomRight = "bottomright", Center = "center", Left = "left", Right = "right", Top = "top", TopLeft = "topleft", TopRight = "topright"}, + Settings = {ToggleMoveFrameText = "Toggle move frame", ReloadText = "Reload list of 'Collectibles'\nHint: Usefull after gaining a new collectible)"} + }, + Loggers = {} } local base = CollectionBars @@ -105,76 +66,89 @@ base.Texts.CharacterKey = string.format("%s_Character", base.Addon.Name) ------------------------------------------------------------------------------------------------- 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 categoryType = base.GetCategoryTypeFromCollectible(categoryData) - local keyboardIcons = {categoryData:GetKeyboardIcons()} - local parentKey = categoryData:GetFormattedName() - local hasSubCategories = categoryData:GetNumSubcategories() > 0 - - base.AddCategory(categoryData, categoryType, keyboardIcons, hasSubCategories) - if hasSubCategories then base:AddSubCategories(categoryData, keyboardIcons, parentKey) end - end - end + 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 categoryType = base.GetCategoryTypeFromCollectible(categoryData) + local keyboardIcons = {categoryData:GetKeyboardIcons()} + local parentKey = categoryData:GetFormattedName() + local hasSubCategories = categoryData:GetNumSubcategories() > 0 + + base.AddCategory(categoryData, categoryType, keyboardIcons, hasSubCategories) + + if hasSubCategories then + base:AddSubCategories(categoryData, keyboardIcons, parentKey) + end + end + end end function base:AddSubCategories(categoryData, parentKeyboardIcons, parentKey) - base:Debug("AddSubCategories", categoryData, parentKeyboardIcons, parentKey) - for _, subcategoryData in categoryData:SubcategoryIterator({ZO_CollectibleCategoryData.HasShownCollectiblesInCollection}) do - local categoryType = base.GetCategoryTypeFromCollectible(subcategoryData) - local hasSubCategories = subcategoryData.subcategories ~= nil and subcategoryData:GetNumSubcategories() > 0 - base.AddCategory(subcategoryData, categoryType, parentKeyboardIcons, hasSubCategories, parentKey) - if hasSubCategories then - local subcategoryParentKey = subcategoryData:GetFormattedName() - base:AddSubCategories(subcategoryData, parentKeyboardIcons, subcategoryParentKey) - end - end + base:Debug("AddSubCategories", categoryData, parentKeyboardIcons, parentKey) + + for _, subcategoryData in categoryData:SubcategoryIterator({ZO_CollectibleCategoryData.HasShownCollectiblesInCollection}) do + local categoryType = base.GetCategoryTypeFromCollectible(subcategoryData) + local hasSubCategories = subcategoryData.subcategories ~= nil and subcategoryData:GetNumSubcategories() > 0 + base.AddCategory(subcategoryData, categoryType, parentKeyboardIcons, hasSubCategories, parentKey) + + if hasSubCategories then + local subcategoryParentKey = subcategoryData:GetFormattedName() + base:AddSubCategories(subcategoryData, parentKeyboardIcons, subcategoryParentKey) + end + end end function base.GetCategoryTypeFromCollectible(categoryData) - base:Debug("GetCategoryType", categoryData) - local categoryType = nil - for _, collectible in ZO_CollectibleCategoryData.SortedCollectibleIterator(categoryData, {ZO_CollectibleData.IsShownInCollection}) do - categoryType = collectible:GetCategoryType() - break - end - - return categoryType + base:Debug("GetCategoryType", categoryData) + + local categoryType = nil + + for _, collectible in ZO_CollectibleCategoryData.SortedCollectibleIterator(categoryData, {ZO_CollectibleData.IsShownInCollection}) do + categoryType = collectible:GetCategoryType() + break + end + + return categoryType end function base.AddCategory(categoryData, categoryType, keyboardIcons, hasChildren, parentKey) - base:Debug("AddCategory", categoryData, categoryType, keyboardIcons, hasChildren, parentKey) - local categoryName = categoryData:GetFormattedName() - local categoryId = categoryData:GetId() - if keyboardIcons ~= nil and keyboardIcons[1] == ZO_NO_TEXTURE_FILE then keyboardIcons = nil end - base.Categories[categoryId] = { - Collection = {}, - CollectionOrdered = {}, - Buttons = {}, - CategoryType = categoryType, - Id = categoryId, - CategoryData = categoryData, - Icon = keyboardIcons, - HasChildren = hasChildren, - ParentKey = parentKey, - Unlocked = 0, - Name = categoryName, - 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(base.CategoriesOrdered, base.Categories[categoryId]) - base.Default.Categories[categoryId] = { - AutoSelectAll = false, - Selected = {}, - Enabled = false, - Tooltip = {Show = true, Position = TOP}, - Bar = {IsCombined = true, HideAll = true, Depth = 0, Width = 0, Horizontal = true, Offset = {X = CENTER, Y = CENTER}}, - Menu = {ShowDisabled = false}, - Label = {Show = true, EnableHideAll = true, Display = categoryName, Offset = {X = 0, Y = 0}, Height = 19, Width = 75, Font = "ZoFontGameSmall", Position = BOTTOMLEFT, PositionTarget = TOPLEFT} - } + base:Debug("AddCategory", categoryData, categoryType, keyboardIcons, hasChildren, parentKey) + + local categoryName = categoryData:GetFormattedName() + local categoryId = categoryData:GetId() + + if keyboardIcons ~= nil and keyboardIcons[1] == ZO_NO_TEXTURE_FILE then + keyboardIcons = nil + end + + base.Categories[categoryId] = { + Collection = {}, + CollectionOrdered = {}, + Buttons = {}, + CategoryType = categoryType, + Id = categoryId, + CategoryData = categoryData, + Icon = keyboardIcons, + HasChildren = hasChildren, + ParentKey = parentKey, + Unlocked = 0, + Name = categoryName, + 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(base.CategoriesOrdered, base.Categories[categoryId]) + base.Default.Categories[categoryId] = { + AutoSelectAll = false, + Selected = {}, + Enabled = false, + Tooltip = {Show = true, Position = TOP}, + Bar = {IsCombined = true, HideAll = true, Depth = 0, Width = 0, Horizontal = true, Offset = {X = CENTER, Y = CENTER}}, + Menu = {ShowDisabled = false}, + Label = {Show = true, EnableHideAll = true, Display = categoryName, Offset = {X = 0, Y = 0}, Height = 19, Width = 75, Font = "ZoFontGameSmall", Position = BOTTOMLEFT, PositionTarget = TOPLEFT} + } end diff --git a/CBs_Fragment.lua b/CBs_Fragment.lua index f0cd937..cf99294 100644 --- a/CBs_Fragment.lua +++ b/CBs_Fragment.lua @@ -12,32 +12,54 @@ local texts = base.Texts -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- 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) + 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) - base:Debug("UpdateFragment", category, fragmentType) - local currentScene = SCENE_MANAGER:GetCurrentScene() - 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.Frames.Frame) 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.Instance:RemoveFragment(category.Fragment) - end - end - if scene.Instance == currentScene then isHidden = isHidden or not base.Saved.Scene[scene.Name] end - end - category.Frames.Frame:SetHidden(isHidden) + base:Debug("UpdateFragment", category, fragmentType) + + local currentScene = SCENE_MANAGER:GetCurrentScene() + 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.Frames.Frame) + 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.Instance:RemoveFragment(category.Fragment) + end + end + + if scene.Instance == currentScene then + isHidden = isHidden or not base.Saved.Scene[scene.Name] + end + end + + category.Frames.Frame:SetHidden(isHidden) 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 + 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 1e7a59e..98a6a65 100644 --- a/CBs_Helpers.lua +++ b/CBs_Helpers.lua @@ -12,232 +12,274 @@ local texts = base.Texts -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- function base.GetCharacterSettingsDisabledState() - base:Debug("GetCharacterSettingsDisabledState") - local result = BSTATE_DISABLED - if base.Saved.UseAccountSettings and _G[texts.CharacterKey] ~= nil then result = BSTATE_NORMAL end + base:Debug("GetCharacterSettingsDisabledState") - return result == BSTATE_DISABLED + 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 - result = BOTTOM - elseif value == texts.Location.BottomLeft then - result = BOTTOMLEFT - elseif value == texts.Location.BottomRight then - result = BOTTOMRIGHT - elseif value == texts.Location.Center then - result = CENTER - elseif value == texts.Location.Left then - result = LEFT - elseif value == texts.Location.Right then - result = RIGHT - elseif value == texts.Location.Top then - result = TOP - elseif value == texts.Location.TopLeft then - result = TOPLEFT - elseif value == texts.Location.TopRight then - result = TOPRIGHT - end - - return result + base:Debug("GetLocationValue", value) + + local result + + if value == texts.Location.Bottom then + result = BOTTOM + elseif value == texts.Location.BottomLeft then + result = BOTTOMLEFT + elseif value == texts.Location.BottomRight then + result = BOTTOMRIGHT + elseif value == texts.Location.Center then + result = CENTER + elseif value == texts.Location.Left then + result = LEFT + elseif value == texts.Location.Right then + result = RIGHT + elseif value == texts.Location.Top then + result = TOP + elseif value == texts.Location.TopLeft then + result = TOPLEFT + elseif value == texts.Location.TopRight then + result = TOPRIGHT + end + + return result end function base:GetLocationText(value) - base:Debug("GetLocationText", value) - local result - - if value == BOTTOM then - result = texts.Location.Bottom - elseif value == BOTTOMLEFT then - result = texts.Location.BottomLeft - elseif value == BOTTOMRIGHT then - result = texts.Location.BottomRight - elseif value == CENTER then - result = texts.Location.Center - elseif value == LEFT then - result = texts.Location.Left - elseif value == RIGHT then - result = texts.Location.Right - elseif value == TOP then - result = texts.Location.Top - elseif value == TOPLEFT then - result = texts.Location.TopLeft - elseif value == TOPRIGHT then - result = texts.Location.TopRight - end - - return result + base:Debug("GetLocationText", value) + + local result + + if value == BOTTOM then + result = texts.Location.Bottom + elseif value == BOTTOMLEFT then + result = texts.Location.BottomLeft + elseif value == BOTTOMRIGHT then + result = texts.Location.BottomRight + elseif value == CENTER then + result = texts.Location.Center + elseif value == LEFT then + result = texts.Location.Left + elseif value == RIGHT then + result = texts.Location.Right + elseif value == TOP then + result = texts.Location.Top + elseif value == TOPLEFT then + result = texts.Location.TopLeft + elseif value == TOPRIGHT then + result = texts.Location.TopRight + end + + return result end function base:RestorePosition(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 - frame:SetAnchor(TOPLEFT, combineFrame, TOPLEFT, 0, 0) - end - end + 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 + frame:SetAnchor(TOPLEFT, combineFrame, TOPLEFT, 0, 0) + end + end end function base:GetLabelPostFix(category) - base:Debug("GetLabelPostFix", category) - local postFix = "" - if category.Saved.Label.EnableHideAll then - if not category.Saved.Bar.HideAll then - postFix = " -" - else - postFix = " +" - end - end - return postFix + base:Debug("GetLabelPostFix", category) + + local postFix = "" + + if category.Saved.Label.EnableHideAll then + if not category.Saved.Bar.HideAll then + postFix = " -" + else + postFix = " +" + end + end + return postFix end 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 - isAllSelected = false - break - end - end + base:Debug("IsAllSelected", category) + + local isAllSelected = true - return isAllSelected + for _, collectible in pairs(category.Collection) do + if category.Saved.Selected[collectible.Id] == nil then + isAllSelected = false + break + end + end + + return isAllSelected end function base:AutoSelectAll(category, newValue) - base:Debug("AutoSelectAll", category, newValue) + base:Debug("AutoSelectAll", category, newValue) - if newValue then category.Saved.Selected = {} end + 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 - else - category.Saved.Selected[collectible.Id] = nil - end - end + base:Debug("SelectAll", category, newValue) + + for _, collectible in pairs(category.Collection) do + if newValue == true then + category.Saved.Selected[collectible.Id] = newValue + else + category.Saved.Selected[collectible.Id] = nil + end + end end function base:GetAccountsettings() - base:Debug("GetAccountsettings") - return ZO_SavedVars:NewAccountWide(texts.AccountKey, base.Addon.Version, nil, base.Default) + base:Debug("GetAccountsettings") + + return ZO_SavedVars:NewAccountWide(texts.AccountKey, base.Addon.Version, nil, base.Default) end function base:GetCharactersettings(useAccountSettings) - base:Debug("GetCharactersettings", useAccountSettings) - local characterSettings = nil + base:Debug("GetCharactersettings", useAccountSettings) - if not useAccountSettings then - characterSettings = ZO_SavedVars:NewCharacterNameSettings(texts.CharacterKey, base.Addon.Version, nil, base.Default) - characterSettings.UseAccountSettings = false - end + local characterSettings = nil - return characterSettings + if not useAccountSettings then + characterSettings = ZO_SavedVars:NewCharacterNameSettings(texts.CharacterKey, base.Addon.Version, nil, base.Default) + characterSettings.UseAccountSettings = false + end + + return characterSettings end function base:SetSavedSettings() - base:Debug("SetSavedSettings") - local accountSettings = base:GetAccountsettings() - local characterSettings = base:GetCharactersettings(accountSettings.UseAccountSettings) - base.Saved = characterSettings or accountSettings + base:Debug("SetSavedSettings") + + local accountSettings = base:GetAccountsettings() + local characterSettings = base:GetCharactersettings(accountSettings.UseAccountSettings) + base.Saved = characterSettings or accountSettings end function base:UpdateUseAccountSettings(useAccountSettings) - base:Debug("UpdateUseAccountSettings", useAccountSettings) - local accountSettings = base:GetAccountsettings() - accountSettings.UseAccountSettings = useAccountSettings - local characterSettings = base:GetCharactersettings(accountSettings.UseAccountSettings) - base.Saved = characterSettings or accountSettings + base:Debug("UpdateUseAccountSettings", useAccountSettings) + + local accountSettings = base:GetAccountsettings() + accountSettings.UseAccountSettings = useAccountSettings + local characterSettings = base:GetCharactersettings(accountSettings.UseAccountSettings) + base.Saved = characterSettings or accountSettings end function base:ResetSavedSettings() - base:Debug("ResetSavedSettings") - local useAccountSettings = base.Saved.UseAccountSettings - if useAccountSettings then - _G[texts.AccountKey] = nil - base.Saved = base:GetAccountsettings() - else - _G[texts.CharacterKey] = nil - base.Saved = base:GetCharactersettings(useAccountSettings) - end + base:Debug("ResetSavedSettings") + + local useAccountSettings = base.Saved.UseAccountSettings + + if useAccountSettings then + _G[texts.AccountKey] = nil + base.Saved = base:GetAccountsettings() + else + _G[texts.CharacterKey] = nil + base.Saved = base:GetCharactersettings(useAccountSettings) + end end function base:RemoveCharacterSettings() - base:Debug("RemoveCharacterSettings") - if base.Saved.UseAccountSettings then _G[texts.CharacterKey] = nil end + base:Debug("RemoveCharacterSettings") + + if base.Saved.UseAccountSettings then + _G[texts.CharacterKey] = nil + 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 - - if maxBarSize == 0 then maxBarSize = base.Saved.Bar[constraint] end - if count < maxBarSize then maxBarSize = count end - - return maxBarSize + local maxBarSize + if category.Saved.Bar.IsCombined then + maxBarSize = base.Saved.Combine.Bar[constraint] + else + maxBarSize = category.Saved.Bar[constraint] + end + + if maxBarSize == 0 then + maxBarSize = base.Saved.Bar[constraint] + end + if count < maxBarSize then + maxBarSize = count + end + + return maxBarSize end function base:GetBarWidthHeight(category) - base:Debug("GetBarWidthHeight", category) - local width, height, count = 0, 0, 0 + base:Debug("GetBarWidthHeight", category) - 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 + local width, height, count = 0, 0, 0 - if count > 0 then - category.Bar.Depth, category.Bar.Width = base:GetMaxBarSize(category, "Depth", count), base:GetMaxBarSize(category, "Width", count) + 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 - local barWidth = zo_ceil(count / category.Bar.Depth) - local maxBarWidth = category.Bar.Width + if count > 0 then + category.Bar.Depth, category.Bar.Width = base:GetMaxBarSize(category, "Depth", count), base:GetMaxBarSize(category, "Width", count) - if maxBarWidth > 0 and maxBarWidth < barWidth then barWidth = maxBarWidth end + local barWidth = zo_ceil(count / category.Bar.Depth) + local maxBarWidth = category.Bar.Width - 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 + if maxBarWidth > 0 and maxBarWidth < barWidth then + barWidth = maxBarWidth + end - return width, height + 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) - base:Debug("SetFrameSizeIfExists", frame, width, height) - if frame ~= nil then - frame:SetWidth(width) - frame:SetHeight(height) - end + base:Debug("SetFrameSizeIfExists", frame, width, height) + + if frame ~= nil then + frame:SetWidth(width) + frame:SetHeight(height) + end end function base:HasAny(array) - base:Debug("HasAny", array) - local hasAny = false - if array ~= nil then - for _ in pairs(array) do - hasAny = true - break - end - end - return hasAny + base:Debug("HasAny", array) + + local hasAny = false + + if array ~= nil then + for _ in pairs(array) do + hasAny = true + break + end + end + + return hasAny end function base:SetControlText(control, text) - base:Debug("SetControlText", control, text) - control.SetText(control, text) + base:Debug("SetControlText", control, text) + + control.SetText(control, text) end diff --git a/CBs_Labels.lua b/CBs_Labels.lua index 63c15e8..659d425 100644 --- a/CBs_Labels.lua +++ b/CBs_Labels.lua @@ -12,100 +12,131 @@ local texts = base.Texts -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- 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.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.Frames.Label:SetHidden(not category.Saved.Label.Show and not category.Saved.Bar.IsCombined) - - 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.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:Debug("SetupLabel", category) + + local hideAllId = string.format(texts.FormatAbbreviationLowDash, "HideAll") + local hideAllCategory = string.format("%s%s", hideAllId, category.Name) + + 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.Frames.Label:SetHidden(not category.Saved.Label.Show and not category.Saved.Bar.IsCombined) + + 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.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) end function base:RestoreLabel(category) - base:Debug("RestoreLabel", category) - local label = category.Saved.Label - local frameLabel = category.Frames.Label - - if frameLabel ~= nil then - frameLabel:ClearAnchors() - frameLabel:SetHeight(label.Height) - frameLabel:SetWidth(label.Width) - 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.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.Label.Display), base:GetLabelPostFix(category))) - end - - local frameLabelToggleSettings = category.Frames.ToggleSettings - if frameLabelToggleSettings ~= nil then frameLabelToggleSettings:SetHidden(false) end + base:Debug("RestoreLabel", category) + + local label = category.Saved.Label + local frameLabel = category.Frames.Label + + if frameLabel ~= nil then + frameLabel:ClearAnchors() + frameLabel:SetHeight(label.Height) + frameLabel:SetWidth(label.Width) + + 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.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.Label.Display), base:GetLabelPostFix(category))) + end + + local frameLabelToggleSettings = category.Frames.ToggleSettings + + if frameLabelToggleSettings ~= nil then + frameLabelToggleSettings:SetHidden(false) + end end function base:RemoveLabel(category) - base:Debug("RemoveLabel", category) - if category.Frames.Label ~= nil then - category.Frames.Label:ClearAnchors() - category.Frames.Label:SetHidden(true) - end + base:Debug("RemoveLabel", category) + + if category.Frames.Label ~= nil then + category.Frames.Label:ClearAnchors() + category.Frames.Label:SetHidden(true) + end - if category.Frames.LabelButton ~= nil then category.Frames.LabelButton:SetHidden(true) end + if category.Frames.LabelButton ~= nil then + category.Frames.LabelButton:SetHidden(true) + end - if category.Frames.ToggleSettings ~= nil then category.Frames.ToggleSettings:SetHidden(true) end + if category.Frames.ToggleSettings ~= nil then + category.Frames.ToggleSettings:SetHidden(true) + end end function base:RestoreCombineLabels() - base:Debug("RestoreCombineLabels") - local combineLabel = base.Saved.Combine.Label - local width = 0 - local height = 0 - 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.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.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.Frames.Frame, combineLabel.PositionTarget, combineLabel.Offset.X, combineLabel.Offset.Y) - end + base:Debug("RestoreCombineLabels") + + local combineLabel = base.Saved.Combine.Label + local width = 0 + local height = 0 + + 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.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.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.Frames.Frame, combineLabel.PositionTarget, combineLabel.Offset.X, combineLabel.Offset.Y) + end end diff --git a/CBs_Logging.lua b/CBs_Logging.lua index c1fb283..fdea6e0 100644 --- a/CBs_Logging.lua +++ b/CBs_Logging.lua @@ -13,33 +13,45 @@ local texts = base.Texts -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- function base:InitializeLog(...) - 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:SetLogsEnabled() - end + 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:SetLogsEnabled() + end end function base:SetLogsEnabled() - if base.Saved then - 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") - base:LogSetEnabled(loggers.Verbose, base.Saved and base.Saved.Logging.Verbose, "Logging verbose") - end + if base.Saved then + 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") + base:LogSetEnabled(loggers.Verbose, base.Saved and base.Saved.Logging.Verbose, "Logging verbose") + end end function base:LogSetEnabled(logger, doLogging, loggerType) - if logger ~= nil then - logger:SetEnabled(doLogging) - logger:Info("LogSetEnabled:", loggerType, doLogging) - return true - end + if logger ~= nil 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: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: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 +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 7c27299..0e3d391 100644 --- a/CBs_MoveFrame.lua +++ b/CBs_MoveFrame.lua @@ -12,115 +12,123 @@ local texts = base.Texts -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- 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 == 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 == TOP or positionTargetXY == CENTER or positionTargetXY == BOTTOM then - x = left + width / 2 - elseif positionTargetXY == TOPRIGHT or positionTargetXY == RIGHT or positionTargetXY == BOTTOMRIGHT then - x = left + width - end - - return (zo_round(x / snapSize) * snapSize), (zo_round(y / snapSize) * 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 == 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 == TOP or positionTargetXY == CENTER or positionTargetXY == BOTTOM then + x = left + width / 2 + elseif positionTargetXY == TOPRIGHT or positionTargetXY == RIGHT or positionTargetXY == BOTTOMRIGHT then + x = left + width + end + + return (zo_round(x / snapSize) * snapSize), (zo_round(y / snapSize) * snapSize) end 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.Bar.IsCombined) then - moveFrame = base:GetOrCreateMoveFrame(targetFrame, category) - - onMouseEnter = function(frame) frame.MoveFrameUpdateText(frame, true) end - onMouseExit = function(frame) frame.MoveFrameUpdateText(frame, false) end - onMouseDown = function(frame) frame:SetHandler("OnUpdate", frame.MoveFrameOnUpdate) end - onMouseUp = function(frame) - local saved = frame.category.Saved - frame.MoveFrameOnUpdate(frame) - frame.MoveFrameUpdateText(frame, false) - frame:SetHandler("OnUpdate", nil) - saved.Bar.Offset.X, saved.Bar.Offset.Y = base:GetMoveFrameSnapPosition(frame, category.Saved.Label.PositionTarget, frame.Saved.Bar.SnapSize) - end - end - - if moveFrame then - moveFrame:SetHandler("OnMouseEnter", onMouseEnter) - moveFrame:SetHandler("OnMouseExit", onMouseExit) - moveFrame:SetHandler("OnMouseDown", onMouseDown) - moveFrame:SetHandler("OnMouseUp", onMouseUp) - moveFrame:SetHidden(not base.Global.IsMoveEnabled) - moveFrame.overlay:SetHidden(not base.Global.IsMoveEnabled) - moveFrame.labelCenter:SetHidden(not base.Global.IsMoveEnabled) - moveFrame.labelTopLeft:SetHidden(not base.Global.IsMoveEnabled) - moveFrame.MoveFrameUpdateText(moveFrame) - moveFrame.MoveFrameUpdateColor(moveFrame) - moveFrame:ClearAnchors() - moveFrame:SetDimensions(targetFrame:GetWidth(), targetFrame:GetHeight()) - moveFrame:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, targetFrame:GetLeft(), targetFrame:GetTop()) - end + 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.Bar.IsCombined) then + moveFrame = base:GetOrCreateMoveFrame(targetFrame, category) + + onMouseEnter = function(frame) + frame.MoveFrameUpdateText(frame, true) + end + onMouseExit = function(frame) + frame.MoveFrameUpdateText(frame, false) + end + onMouseDown = function(frame) + frame:SetHandler("OnUpdate", frame.MoveFrameOnUpdate) + end + onMouseUp = function(frame) + local saved = frame.category.Saved + frame.MoveFrameOnUpdate(frame) + frame.MoveFrameUpdateText(frame, false) + frame:SetHandler("OnUpdate", nil) + saved.Bar.Offset.X, saved.Bar.Offset.Y = base:GetMoveFrameSnapPosition(frame, category.Saved.Label.PositionTarget, frame.Saved.Bar.SnapSize) + end + end + + if moveFrame then + moveFrame:SetHandler("OnMouseEnter", onMouseEnter) + moveFrame:SetHandler("OnMouseExit", onMouseExit) + moveFrame:SetHandler("OnMouseDown", onMouseDown) + moveFrame:SetHandler("OnMouseUp", onMouseUp) + moveFrame:SetHidden(not base.Global.IsMoveEnabled) + moveFrame.overlay:SetHidden(not base.Global.IsMoveEnabled) + moveFrame.labelCenter:SetHidden(not base.Global.IsMoveEnabled) + moveFrame.labelTopLeft:SetHidden(not base.Global.IsMoveEnabled) + moveFrame.MoveFrameUpdateText(moveFrame) + moveFrame.MoveFrameUpdateColor(moveFrame) + moveFrame:ClearAnchors() + moveFrame:SetDimensions(targetFrame:GetWidth(), targetFrame:GetHeight()) + moveFrame:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, targetFrame:GetLeft(), targetFrame:GetTop()) + end end 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")) - - -- Variable is used to define what savedVariable the Frame refers to. - newMoveFrame.TargetFrame = targetFrame - newMoveFrame.Saved = base.Saved - newMoveFrame.category = category - newMoveFrame["MoveFrameUpdateText"] = function(frame, position) - local labelTextTopLeft = "" - - if (position) then - 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.Bar.SnapSize) - frame.TargetFrame:ClearAnchors() - frame.TargetFrame:SetAnchor(category.Saved.Label.PositionTarget, GuiRoot, TOPLEFT, x, y) - frame.MoveFrameUpdateText(frame, true) - end - newMoveFrame["MoveFrameUpdateColor"] = function(frame) - frame.overlay:SetCenterColor(0.88, 0.88, 0.88, 0.4) - frame.overlay:SetEdgeColor(0.88, 0.88, 0.88, 0) - frame.labelCenter:SetColor(0.9, 0.9, 0.9, 0.9) - frame.labelTopLeft:SetColor(0.9, 0.9, 0.9, 0.9) - end - newMoveFrame:SetAnchorFill(targetFrame) - newMoveFrame:SetParent(GuiRoot) - - -- -- overlay - if newMoveFrame.overlay == nil then newMoveFrame.overlay = GetControl(string.format("%sBG", moveFrameName)) end - - -- labels - if newMoveFrame.labelTopLeft == nil or newMoveFrame.labelCenter == nil then - newMoveFrame.labelTopLeft = GetControl(string.format("%sLabelTopLeft", moveFrameName)) - newMoveFrame.labelTopLeft:SetHorizontalAlignment(TEXT_ALIGN_LEFT) - newMoveFrame.labelTopLeft:SetVerticalAlignment(TEXT_ALIGN_TOP) - - newMoveFrame.labelCenter = GetControl(string.format("%sLabelCenter", moveFrameName)) - newMoveFrame.labelCenter:SetHorizontalAlignment(TEXT_ALIGN_CENTER) - newMoveFrame.labelCenter:SetVerticalAlignment(TEXT_ALIGN_CENTER) - end - - category.Frames.Move = newMoveFrame - end - - return category.Frames.Move + 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")) + + -- Variable is used to define what savedVariable the Frame refers to. + newMoveFrame.TargetFrame = targetFrame + newMoveFrame.Saved = base.Saved + newMoveFrame.category = category + newMoveFrame["MoveFrameUpdateText"] = function(frame, position) + local labelTextTopLeft = "" + + if (position) then + 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.Bar.SnapSize) + frame.TargetFrame:ClearAnchors() + frame.TargetFrame:SetAnchor(category.Saved.Label.PositionTarget, GuiRoot, TOPLEFT, x, y) + frame.MoveFrameUpdateText(frame, true) + end + newMoveFrame["MoveFrameUpdateColor"] = function(frame) + frame.overlay:SetCenterColor(0.88, 0.88, 0.88, 0.4) + frame.overlay:SetEdgeColor(0.88, 0.88, 0.88, 0) + frame.labelCenter:SetColor(0.9, 0.9, 0.9, 0.9) + frame.labelTopLeft:SetColor(0.9, 0.9, 0.9, 0.9) + end + newMoveFrame:SetAnchorFill(targetFrame) + newMoveFrame:SetParent(GuiRoot) + + -- -- overlay + if newMoveFrame.overlay == nil then + newMoveFrame.overlay = GetControl(string.format("%sBG", moveFrameName)) + end + + -- labels + if newMoveFrame.labelTopLeft == nil or newMoveFrame.labelCenter == nil then + newMoveFrame.labelTopLeft = GetControl(string.format("%sLabelTopLeft", moveFrameName)) + newMoveFrame.labelTopLeft:SetHorizontalAlignment(TEXT_ALIGN_LEFT) + newMoveFrame.labelTopLeft:SetVerticalAlignment(TEXT_ALIGN_TOP) + + newMoveFrame.labelCenter = GetControl(string.format("%sLabelCenter", moveFrameName)) + newMoveFrame.labelCenter:SetHorizontalAlignment(TEXT_ALIGN_CENTER) + newMoveFrame.labelCenter:SetVerticalAlignment(TEXT_ALIGN_CENTER) + end + + category.Frames.Move = newMoveFrame + end + + return category.Frames.Move end diff --git a/CBs_Settings.lua b/CBs_Settings.lua index 6668b19..c4a91cc 100644 --- a/CBs_Settings.lua +++ b/CBs_Settings.lua @@ -12,124 +12,165 @@ local texts = base.Texts -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- function base:InitializeSettingsSlash() - base:Debug("InitializeSettingsSlash") - SLASH_COMMANDS[base.Addon.SettingsSlash] = function() base:ToggleEnableSettings(base.ShowSettings()) end + base:Debug("InitializeSettingsSlash") + + SLASH_COMMANDS[base.Addon.SettingsSlash] = function() + base:ToggleEnableSettings(base.ShowSettings()) + end end 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:Debug("ToggleEnableSettings", forceShow) + + base.Global.EnableSettings = forceShow or not base.Global.EnableSettings + + base:RestoreFrames() + base:RestoreCombineLabels() end 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 - toggleSettings:SetHandler("OnClicked", hideAllSettingsFunc) - end + base:Debug("SetupToggleSettings", category) + + local toggleSettings = GetControl(string.format(texts.FormatAbbreviationLowDash .. "%sToggleSettings", "HideAll", category.Name)) + + if toggleSettings then + toggleSettings:SetHandler("OnClicked", function() + base:ShowSettings(category) + end) + end end function base:UpdateToggleSettings(category) - base:Debug("UpdateToggleSettings", category) - local offsetX = 0 - if base.Global.EnableSettings then offsetX = -19 end - - 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.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 + base:Debug("UpdateToggleSettings", category) + + local offsetX = 0 + + if base.Global.EnableSettings then + offsetX = -19 + end + + 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.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) - 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) + 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) - base:Debug("SetupSetttingsFrame", category) - local selector = string.format(texts.FormatAbbreviationLowDash, "Settings") - base.Global.Settings.Frame = base.WM:CreateControlFromVirtual(selector, GuiRoot, selector) - base.Global.SettingsLabel = GetControl(string.format("%sLabel", selector)) - 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.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.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.Settings.List:RefreshData() - base:RestoreFrames() - end) - end - - 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.Settings.List:RefreshData() - end) - end - - for controlName, displayName in pairs(base.Global.Settings.Filters) do base:SetupSettingsFilter(base.Global.Settings.Frame, controlName, displayName) end + base:Debug("SetupSetttingsFrame", category) + + local selector = string.format(texts.FormatAbbreviationLowDash, "Settings") + base.Global.Settings.Frame = base.WM:CreateControlFromVirtual(selector, GuiRoot, selector) + base.Global.SettingsLabel = GetControl(string.format("%sLabel", selector)) + 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.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.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.Settings.List:RefreshData() + base:RestoreFrames() + end) + end + + 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.Settings.List:RefreshData() + end) + 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) - base:Debug("SetupSettingsFilter", control, controlName, displayName) - local filterControl = GetControl(control, controlName) - if filterControl then - base:SetControlText(filterControl, displayName) - filterControl:SetHandler("OnClicked", function() - base.Global.Settings.List.masterListType = controlName - base.Global.Settings.List:RefreshFilters() - end) - end + base:Debug("SetupSettingsFilter", control, controlName, displayName) + + local filterControl = GetControl(control, controlName) + + if filterControl then + base:SetControlText(filterControl, displayName) + filterControl:SetHandler("OnClicked", function() + base.Global.Settings.List.masterListType = controlName + base.Global.Settings.List:RefreshFilters() + end) + end 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.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.Settings.List.category = show and category or nil - base.Global.Settings.List:RefreshData() - end - return show + base:Debug("ShowSettings", category) + + local show = base.Global.Settings.Frame == nil + + if show then + base:SetupSetttingsFrame(category) + end + + 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.Settings.List.category = show and category or nil + base.Global.Settings.List:RefreshData() + end + + return show 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 + 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 + 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 2124521..b61db39 100644 --- a/CBs_Settings_Data.lua +++ b/CBs_Settings_Data.lua @@ -12,693 +12,880 @@ 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:UpdateUseAccountSettings(newValue) - base:SetLogsEnabled() - base:InitializeWithSavedData() - base:RestoreFrames() - base:RestoreCombineLabels() - base.Global.Settings.List:RefreshData() - end - }) - self:AppendRow_Button(listType, { - name = "Remove all character settings", - buttonName = "Remove", - disabledFunc = base.GetCharacterSettingsDisabledState, - funcSet = function() - base:RemoveCharacterSettings() - base.Global.Settings.List:RefreshData() - end - }) - self:AppendRow_Button(listType, { - name = "Reset settings", - buttonName = "Reset", - funcSet = function() - base:ResetSavedSettings() - base:SetLogsEnabled() - base:InitializeWithSavedData() - base:RestoreFrames() - base:RestoreCombineLabels() - base.Global.Settings.List:RefreshData() - end - }) - self:AppendRow_Title(listType, {name = "Position and size"}) - self:AppendRow_Divider(listType, {}) - self:AppendRow_Checkbox(listType, { - name = "Unlock movement of bar", - tooltipText = "When ON the bar will show the X,Y position of the top left corner, and is draggable", - funcGet = function() return base.Global.IsMoveEnabled end, - funcSet = function(_, newValue) - base.Global.IsMoveEnabled = newValue - base:RestoreFrames() - end - }) - self:AppendRow_Slider(listType, { - name = "Choose snap size when moving", - tooltipText = "Choose snap size when moving", - 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.Bar.SnapSize = newValue - base:RestoreFrames() - end, - minValue = 1, - maxValue = 10, - valueStep = 1, - 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.Bar.Depth end, - funcSet = function(sliderControl, newValue) - local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") - if valueLabel then valueLabel:SetText(newValue) end - base.Saved.Bar.Depth = newValue - base:RestoreFrames() - end, - minValue = 0, - maxValue = base.Global.HighestUnlocked, - valueStep = 1, - 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.Bar.Width end, - funcSet = function(sliderControl, newValue) - local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") - if valueLabel then valueLabel:SetText(newValue) end - base.Saved.Bar.Width = newValue - base:RestoreFrames() - end, - minValue = 0, - maxValue = base.Global.HighestUnlocked, - valueStep = 1, - 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.Bindings.Show end, - funcSet = function(_, newValue) - 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.Button.Size end, - funcSet = function(sliderControl, newValue) - local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") - if valueLabel then valueLabel:SetText(newValue) end - base.Saved.Button.Size = newValue - base:RestoreFrames() - end, - minValue = 1, - maxValue = 100, - valueStep = 1, - default = ZO_GAMEPAD_ACTION_BUTTON_SIZE, - valueFormat = texts.Format.Number, - showValue = true - }) - - 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 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.Button.IsActiveActivationEnabled = newValue - base:RestoreFrames() - 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.Button.IsAudioEnabled end, - funcSet = function(_, newValue) - base.Saved.Button.IsAudioEnabled = newValue - base:RestoreFrames() - end - }) - self:AppendRow_Title(listType, {name = "Logging"}) - self:AppendRow_Divider(listType, {}) - self:AppendRow_Checkbox(listType, { - 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.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:SetLogsEnabled() - end - }) - self:AppendRow_Checkbox(listType, { - 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.Logging.Debug = newValue - base:LogSetEnabled(base.Loggers.Debug, newValue, "Logging debug") - if not newValue then base:LogSetEnabled(base.Loggers.Verbose, newValue, "Logging verbose") end - end - }) - self:AppendRow_Checkbox(listType, { - name = "Enable logging verbose", - tooltipText = "When ON the addon will do logging debug\nDependsOn: LibDebugLogger\n And Enable logging ON\n\nRequired: add verbose logger to the StartupConfig.lua in LibDebugLogger\nas whitelist[\"CollectionBars/verbose\"] = true", - 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.Logging.Verbose = newValue - base:LogSetEnabled(base.Loggers.Verbose, newValue, "Logging verbose") - end - }) + 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:UpdateUseAccountSettings(newValue) + base:SetLogsEnabled() + base:InitializeWithSavedData() + base:RestoreFrames() + base:RestoreCombineLabels() + base.Global.Settings.List:RefreshData() + end + }) + self:AppendRow_Button(listType, { + name = "Remove all character settings", + buttonName = "Remove", + disabledFunc = base.GetCharacterSettingsDisabledState, + funcSet = function() + base:RemoveCharacterSettings() + base.Global.Settings.List:RefreshData() + end + }) + self:AppendRow_Button(listType, { + name = "Reset settings", + buttonName = "Reset", + funcSet = function() + base:ResetSavedSettings() + base:SetLogsEnabled() + base:InitializeWithSavedData() + base:RestoreFrames() + base:RestoreCombineLabels() + base.Global.Settings.List:RefreshData() + end + }) + self:AppendRow_Title(listType, {name = "Position and size"}) + self:AppendRow_Divider(listType, {}) + self:AppendRow_Checkbox(listType, { + name = "Unlock movement of bar", + tooltipText = "When ON the bar will show the X,Y position of the top left corner, and is draggable", + funcGet = function() + return base.Global.IsMoveEnabled + end, + funcSet = function(_, newValue) + base.Global.IsMoveEnabled = newValue + base:RestoreFrames() + end + }) + self:AppendRow_Slider(listType, { + name = "Choose snap size when moving", + tooltipText = "Choose snap size when moving", + 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.Bar.SnapSize = newValue + base:RestoreFrames() + end, + minValue = 1, + maxValue = 10, + valueStep = 1, + 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.Bar.Depth + end, + funcSet = function(sliderControl, newValue) + local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") + + if valueLabel then + valueLabel:SetText(newValue) + end + + base.Saved.Bar.Depth = newValue + base:RestoreFrames() + end, + minValue = 0, + maxValue = base.Global.HighestUnlocked, + valueStep = 1, + 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.Bar.Width + end, + funcSet = function(sliderControl, newValue) + local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") + + if valueLabel then + valueLabel:SetText(newValue) + end + + base.Saved.Bar.Width = newValue + base:RestoreFrames() + end, + minValue = 0, + maxValue = base.Global.HighestUnlocked, + valueStep = 1, + 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.Bindings.Show + end, + funcSet = function(_, newValue) + 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.Button.Size + end, + funcSet = function(sliderControl, newValue) + local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") + + if valueLabel then + valueLabel:SetText(newValue) + end + + base.Saved.Button.Size = newValue + base:RestoreFrames() + end, + minValue = 1, + maxValue = 100, + valueStep = 1, + default = ZO_GAMEPAD_ACTION_BUTTON_SIZE, + valueFormat = texts.Format.Number, + showValue = true + }) + + 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 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.Button.IsActiveActivationEnabled = newValue + base:RestoreFrames() + 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.Button.IsAudioEnabled + end, + funcSet = function(_, newValue) + base.Saved.Button.IsAudioEnabled = newValue + base:RestoreFrames() + end + }) + self:AppendRow_Title(listType, {name = "Logging"}) + self:AppendRow_Divider(listType, {}) + self:AppendRow_Checkbox(listType, { + 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.Logging.Info = newValue + + if not newValue then + base.Saved.Logging.Debug = newValue + base.Saved.Logging.Verbose = newValue + end + + base.Global.Settings.List:RefreshData() + base:SetLogsEnabled() + end + }) + self:AppendRow_Checkbox(listType, { + 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.Logging.Debug = newValue + base:LogSetEnabled(base.Loggers.Debug, newValue, "Logging debug") + + if not newValue then + base:LogSetEnabled(base.Loggers.Verbose, newValue, "Logging verbose") + end + end + }) + self:AppendRow_Checkbox(listType, { + name = "Enable logging verbose", + tooltipText = "When ON the addon will do logging debug\nDependsOn: LibDebugLogger\n And Enable logging ON\n\nRequired: add verbose logger to the StartupConfig.lua in LibDebugLogger\nas whitelist[\"CollectionBars/verbose\"] = true", + 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.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, {}) - - for _, category in ipairs(base.CategoriesOrdered or {}) do - local toolTipText = "" - if category.HasChildren then - toolTipText = string.format("Click to toggle subcategories for\n%s", category.Name) - else - 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) - end - local data = { - cId = category.Id, - icon = category.Icon, - name = string.format("Show %s", category.Name), - hasChildren = category.HasChildren, - parentKey = category.ParentKey, - tooltipText = toolTipText, - 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) - else - base:RemoveLabel(category) - base:RemoveFrame(category) - if self.category == category then - self.category = nil - base:UpdateSettingsType(true, nil) - end - end - 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.Settings.List:RefreshData() - if button == MOUSE_BUTTON_INDEX_RIGHT then - base.Global.Settings.List.masterListType = "Collectibles" - base.Global.Settings.List:RefreshFilters() - end - end - } - - if category.HasChildren then - data.name = category.Name - self:AppendRow_Category_Title(listType, data) - else - self:AppendRow_Category_Checkbox(listType, data) - end - end + base:Debug("AppendMasterListTypeCategories", self, listType) + self:AppendRow_Title(listType, {name = "Categories"}) + self:AppendRow_Divider(listType, {}) + + for _, category in ipairs(base.CategoriesOrdered or {}) do + local toolTipText = "" + if category.HasChildren then + toolTipText = string.format("Click to toggle subcategories for\n%s", category.Name) + else + 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) + end + local data = { + cId = category.Id, + icon = category.Icon, + name = string.format("Show %s", category.Name), + hasChildren = category.HasChildren, + parentKey = category.ParentKey, + tooltipText = toolTipText, + 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) + else + base:RemoveLabel(category) + base:RemoveFrame(category) + if self.category == category then + self.category = nil + base:UpdateSettingsType(true, nil) + end + end + + 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.Settings.List:RefreshData() + + if button == MOUSE_BUTTON_INDEX_RIGHT then + base.Global.Settings.List.masterListType = "Collectibles" + base.Global.Settings.List:RefreshFilters() + end + end + } + + if category.HasChildren then + data.name = category.Name + self:AppendRow_Category_Title(listType, data) + else + self:AppendRow_Category_Checkbox(listType, data) + end + end 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.Offset.X end, - funcSet = function(sliderControl, newValue) - local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") - if valueLabel then valueLabel:SetText(newValue) end - base.Saved.Combine.Label.Offset.X = newValue - base:RestoreCombineLabels() - end, - minValue = -500, - maxValue = 500, - valueStep = 1, - 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.Offset.Y end, - funcSet = function(sliderControl, newValue) - local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") - if valueLabel then valueLabel:SetText(newValue) end - base.Saved.Combine.Label.Offset.Y = newValue - base:RestoreCombineLabels() - end, - minValue = -500, - maxValue = 500, - valueStep = 1, - 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, - choices = base.Global.ChoiceLocations, - funcSet = function(_, newValue) - 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, - choices = base.Global.ChoiceLocations, - funcSet = function(_, newValue) - base.Saved.Combine.Label.Position = base:GetLocationValue(newValue) - base:RestoreCombineLabels() - end - }) - self:AppendRow_Title(listType, {name = "Position and size"}) - self:AppendRow_Divider(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.Bar.Depth end, - funcSet = function(sliderControl, newValue) - local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") - if valueLabel then valueLabel:SetText(newValue) end - base.Saved.Combine.Bar.Depth = newValue - base:RestoreFrames() - end, - minValue = 0, - maxValue = base.Global.HighestUnlocked, - valueStep = 1, - 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.Bar.Width end, - funcSet = function(sliderControl, newValue) - local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") - if valueLabel then valueLabel:SetText(newValue) end - base.Saved.Combine.Bar.Width = newValue - base:RestoreFrames() - end, - minValue = 0, - maxValue = base.Global.HighestUnlocked, - valueStep = 1, - default = base.Default.Bar.Width, - valueFormat = texts.Format.Number, - showValue = true - }) + 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.Offset.X + end, + funcSet = function(sliderControl, newValue) + local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") + + if valueLabel then + valueLabel:SetText(newValue) + end + + base.Saved.Combine.Label.Offset.X = newValue + base:RestoreCombineLabels() + end, + minValue = -500, + maxValue = 500, + valueStep = 1, + 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.Offset.Y + end, + funcSet = function(sliderControl, newValue) + local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") + + if valueLabel then + valueLabel:SetText(newValue) + end + + base.Saved.Combine.Label.Offset.Y = newValue + base:RestoreCombineLabels() + end, + minValue = -500, + maxValue = 500, + valueStep = 1, + 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, + choices = base.Global.ChoiceLocations, + funcSet = function(_, newValue) + 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, + choices = base.Global.ChoiceLocations, + funcSet = function(_, newValue) + base.Saved.Combine.Label.Position = base:GetLocationValue(newValue) + base:RestoreCombineLabels() + end + }) + self:AppendRow_Title(listType, {name = "Position and size"}) + self:AppendRow_Divider(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.Bar.Depth + end, + funcSet = function(sliderControl, newValue) + local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") + + if valueLabel then + valueLabel:SetText(newValue) + end + + base.Saved.Combine.Bar.Depth = newValue + base:RestoreFrames() + end, + minValue = 0, + maxValue = base.Global.HighestUnlocked, + valueStep = 1, + 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.Bar.Width + end, + funcSet = function(sliderControl, newValue) + local valueLabel = GetControl(sliderControl:GetParent(), "ValueLabel") + + if valueLabel then + valueLabel:SetText(newValue) + end + + base.Saved.Combine.Bar.Width = newValue + base:RestoreFrames() + end, + minValue = 0, + maxValue = base.Global.HighestUnlocked, + valueStep = 1, + 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, { - name = string.format("Show disabled %s", self.category.Name), - tooltipText = string.format("When ON disabled elements will be shown for %s", self.category.Name), - funcGet = function() return self.category.Saved.Menu.ShowDisabled end, - funcSet = function(_, newValue) - self.category.Saved.Menu.ShowDisabled = newValue - 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), - 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.Settings.List:RefreshData() - end - }) - self:AppendRow_Divider(listType, {}) - for _, collectible in ipairs(self.category.CollectionOrdered) do - if not collectible.Disabled or self.category.Saved.Menu.ShowDisabled and 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 or self.category.Saved.AutoSelectAll end, - funcSet = function(checkBoxControl, newValue) - local control = checkBoxControl:GetParent() - if not (control.data.disabledFunc and control.data.disabledFunc()) then - if newValue == true then - self.category.Saved.Selected[control.data.cId] = newValue - else - self.category.Saved.Selected[control.data.cId] = nil - end - base:RestoreFrame(self.category) - base:RestoreCombineLabels() - base.Global.Settings.List:RefreshData() - end - end - - }) - end - end + base:Debug("AppendMasterListTypeCollectibles", self, listType) + self:AppendRow_Title(listType, {name = "Collectibles"}) + self:AppendRow_Divider(listType, {}) + self:AppendRow_Checkbox(listType, { + name = string.format("Show disabled %s", self.category.Name), + tooltipText = string.format("When ON disabled elements will be shown for %s", self.category.Name), + funcGet = function() + return self.category.Saved.Menu.ShowDisabled + end, + funcSet = function(_, newValue) + self.category.Saved.Menu.ShowDisabled = newValue + 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), + 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.Settings.List:RefreshData() + end + }) + self:AppendRow_Divider(listType, {}) + for _, collectible in ipairs(self.category.CollectionOrdered) do + if not collectible.Disabled or self.category.Saved.Menu.ShowDisabled and 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 or self.category.Saved.AutoSelectAll + end, + funcSet = function(checkBoxControl, newValue) + local control = checkBoxControl:GetParent() + + if not (control.data.disabledFunc and control.data.disabledFunc()) then + if newValue == true then + self.category.Saved.Selected[control.data.cId] = newValue + else + self.category.Saved.Selected[control.data.cId] = nil + end + + base:RestoreFrame(self.category) + base:RestoreCombineLabels() + base.Global.Settings.List:RefreshData() + end + end + + }) + end + end 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" - - self:AppendRow_Title(listType, {name = "Tooltip"}) - self:AppendRow_Divider(listType, {}) - self:AppendRow_Checkbox(listType, { - name = "Show tooltip", - tooltipText = "When ON tooltips will be shown, when hovering buttons on the bar", - funcGet = function() return self.category.Saved.Tooltip.Show end, - funcSet = function(_, newValue) - self.category.Saved.Tooltip.Show = newValue - base:SetupButtons(self.category) - base.Global.Settings.List:RefreshData() - end - }) - self:AppendRow_Dropdown(listType, { - name = "Show tooltip anchor position", - 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, - funcSet = function(_, newValue) - self.category.Saved.Tooltip.Position = base:GetLocationValue(newValue) - base:SetupButtons(self.category) - end - }) - - self:AppendRow_Title(listType, {name = "Display name and label"}) - self:AppendRow_Divider(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.Bar.IsCombined end, - funcSet = function(_, newValue) - 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.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.Bar.HideAll = newValue - base:RestoreFrame(self.category) - end - 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.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.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.Label.Show end, - funcGet = function() return tostring(self.category.Saved.Label.Display) end, - funcSet = function(control) - self.category.Saved.Label.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.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() - 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.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() - end, - minValue = 0, - maxValue = 100, - valueStep = 1, - 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.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() - end, - minValue = 0, - maxValue = 500, - valueStep = 1, - 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.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.Offset.X = newValue - base:RestoreFrame(self.category) - base:RestoreCombineLabels() - end, - minValue = -500, - maxValue = 500, - valueStep = 1, - 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.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.Offset.Y = newValue - base:RestoreFrame(self.category) - base:RestoreCombineLabels() - end, - minValue = -500, - maxValue = 500, - valueStep = 1, - 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.Label.Show or self.category.Saved.Bar.IsCombined end, - funcGet = function() - if self.category.Saved.Bar.IsCombined then - return base:GetLocationText(base.Saved.Combine.Label.PositionTarget) - else - 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() - 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.Label.Show or self.category.Saved.Bar.IsCombined end, - funcGet = function() - if self.category.Saved.Bar.IsCombined then - return base:GetLocationText(base.Saved.Combine.Label.Position) - else - 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() - end - }) - - self:AppendRow_Title(listType, {name = "Position and size"}) - self:AppendRow_Divider(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.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.Bar.Depth = newValue - base:RestoreFrame(self.category) - base:RestoreCombineLabels() - end, - minValue = 0, - maxValue = self.category.Unlocked, - valueStep = 1, - 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.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.Bar.Width = newValue - base:RestoreFrame(self.category) - base:RestoreCombineLabels() - end, - minValue = 0, - maxValue = self.category.Unlocked, - valueStep = 1, - 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.Bar.IsCombined end, - funcGet = function() return self.category.Saved.Bar.Horizontal end, - funcSet = function(_, newValue) - self.category.Saved.Bar.Horizontal = newValue - base:RestoreFrame(self.category) - base:RestoreCombineLabels() - end - }) + 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" + + self:AppendRow_Title(listType, {name = "Tooltip"}) + self:AppendRow_Divider(listType, {}) + self:AppendRow_Checkbox(listType, { + name = "Show tooltip", + tooltipText = "When ON tooltips will be shown, when hovering buttons on the bar", + funcGet = function() + return self.category.Saved.Tooltip.Show + end, + funcSet = function(_, newValue) + self.category.Saved.Tooltip.Show = newValue + base:SetupButtons(self.category) + base.Global.Settings.List:RefreshData() + end + }) + self:AppendRow_Dropdown(listType, { + name = "Show tooltip anchor position", + 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, + funcSet = function(_, newValue) + self.category.Saved.Tooltip.Position = base:GetLocationValue(newValue) + base:SetupButtons(self.category) + end + }) + + self:AppendRow_Title(listType, {name = "Display name and label"}) + self:AppendRow_Divider(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.Bar.IsCombined + end, + funcSet = function(_, newValue) + 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.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.Bar.HideAll = newValue + base:RestoreFrame(self.category) + end + 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.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.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.Label.Show + end, + funcGet = function() + return tostring(self.category.Saved.Label.Display) + end, + funcSet = function(control) + self.category.Saved.Label.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.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() + 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.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() + end, + minValue = 0, + maxValue = 100, + valueStep = 1, + 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.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() + end, + minValue = 0, + maxValue = 500, + valueStep = 1, + 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.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.Offset.X = newValue + base:RestoreFrame(self.category) + base:RestoreCombineLabels() + end, + minValue = -500, + maxValue = 500, + valueStep = 1, + 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.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.Offset.Y = newValue + base:RestoreFrame(self.category) + base:RestoreCombineLabels() + end, + minValue = -500, + maxValue = 500, + valueStep = 1, + 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.Label.Show or self.category.Saved.Bar.IsCombined + end, + funcGet = function() + local text = self.category.Saved.Label.PositionTarget + + if self.category.Saved.Bar.IsCombined then + text = base.Saved.Combine.Label.PositionTarget + end + + return base:GetLocationText(text) + end, + choices = base.Global.ChoiceLocations, + funcSet = function(_, newValue) + 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.Label.Show or self.category.Saved.Bar.IsCombined + end, + funcGet = function() + local text = self.category.Saved.Label.Position + + if self.category.Saved.Bar.IsCombined then + text = base.Saved.Combine.Label.Position + end + + return base:GetLocationText(text) + end, + choices = base.Global.ChoiceLocations, + funcSet = function(_, newValue) + self.category.Saved.Label.Position = base:GetLocationValue(newValue) + base:RestoreFrame(self.category) + base:RestoreCombineLabels() + end + }) + + self:AppendRow_Title(listType, {name = "Position and size"}) + self:AppendRow_Divider(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.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.Bar.Depth = newValue + base:RestoreFrame(self.category) + base:RestoreCombineLabels() + end, + minValue = 0, + maxValue = self.category.Unlocked, + valueStep = 1, + 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.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.Bar.Width = newValue + base:RestoreFrame(self.category) + base:RestoreCombineLabels() + end, + minValue = 0, + maxValue = self.category.Unlocked, + valueStep = 1, + 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.Bar.IsCombined + end, + funcGet = function() + return self.category.Saved.Bar.Horizontal + end, + funcSet = function(_, newValue) + 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, {}) + 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 86dcf20..a963e20 100644 --- a/CBs_Settings_List.lua +++ b/CBs_Settings_List.lua @@ -14,21 +14,26 @@ 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 + 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 = {} - if not (self.category and self.category.Enabled) then self.masterListType = "Categories" end - - self:SetAlternateRowBackgrounds(false) - self:AppendDataTypes() + base:Debug("CBs_Settings_List:Initialize", ...) + + ZO_SortFilterList.Initialize(self, ...) + self.category = category + self.masterList = {} + + if not (self.category and self.category.Enabled) then + self.masterListType = "Categories" + end + + self:SetAlternateRowBackgrounds(false) + self:AppendDataTypes() end ------------------------------------------------------------------------------------------------- @@ -36,21 +41,78 @@ 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}, - [11] = {name = string.format(listRowAnd, "Category_Title"), height = 40, func = function(...) self:SetupRow_Category_Title(...) end}, - [15] = {name = string.format(listRowAnd, "Category_Checkbox"), height = 40, func = function(...) self:SetupRow_Category_Checkbox(...) end}, - [20] = {name = string.format(listRowAnd, "Dropdown"), height = 40, func = function(...) self:SetupRow_Dropdown(...) end}, - [30] = {name = string.format(listRowAnd, "Slider"), height = 40, func = function(...) self:SetupRow_Slider(...) end}, - [40] = {name = string.format(listRowAnd, "EditBox"), height = 40, func = function(...) self:SetupRow_EditBox(...) end}, - [50] = {name = string.format(listRowAnd, "Title"), height = 40, func = function(...) self:SetupRow_Title(...) end}, - [60] = {name = string.format(listRowAnd, "Button"), height = 40, func = function(...) self:SetupRow_Button(...) end}, - [100] = {name = string.format(listRowAnd, "Divider"), height = 6, func = function(...) ZO_SortFilterList.SetupRow(self, ...) end} - } - - for index, dataType in pairs(dataTypes) do ZO_ScrollList_AddDataType(self.list, index, dataType.name, dataType.height, dataType.func) end + 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 + }, + [11] = { + name = string.format(listRowAnd, "Category_Title"), + height = 40, + func = function(...) + self:SetupRow_Category_Title(...) + end + }, + [15] = { + name = string.format(listRowAnd, "Category_Checkbox"), + height = 40, + func = function(...) + self:SetupRow_Category_Checkbox(...) + end + }, + [20] = { + name = string.format(listRowAnd, "Dropdown"), + height = 40, + func = function(...) + self:SetupRow_Dropdown(...) + end + }, + [30] = { + name = string.format(listRowAnd, "Slider"), + height = 40, + func = function(...) + self:SetupRow_Slider(...) + end + }, + [40] = { + name = string.format(listRowAnd, "EditBox"), + height = 40, + func = function(...) + self:SetupRow_EditBox(...) + end + }, + [50] = { + name = string.format(listRowAnd, "Title"), + height = 40, + func = function(...) + self:SetupRow_Title(...) + end + }, + [60] = { + name = string.format(listRowAnd, "Button"), + height = 40, + func = function(...) + self:SetupRow_Button(...) + end + }, + [100] = { + name = string.format(listRowAnd, "Divider"), + height = 6, + func = function(...) + ZO_SortFilterList.SetupRow(self, ...) + end + } + } + + for index, dataType in pairs(dataTypes) do + ZO_ScrollList_AddDataType(self.list, index, dataType.name, dataType.height, dataType.func) + end end ------------------------------------------------------------------------------------------------- @@ -58,352 +120,433 @@ 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) + 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) - - control.checkbox = GetControl(control, "Checkbox") - if control.checkbox then - control.checkbox.tooltipText = data.tooltipText - ZO_CheckButton_SetCheckState(control.checkbox, control.data.funcGet and control.data.funcGet()) - ZO_CheckButton_SetLabelText(control.checkbox, data.name) - if control.checkbox.label then - control.checkbox.label.defaultNormalColor = ZO_DEFAULT_ENABLED_COLOR - control.checkbox.label:ClearAnchors() - control.checkbox.label:SetAnchor(TOPLEFT, control, TOPLEFT, 0) - control.checkbox.label:SetAnchor(BOTTOMRIGHT, control.checkbox, BOTTOMLEFT) - end - ZO_CheckButton_SetTooltipAnchor(control.checkbox, TOP, control.checkbox.label) - ZO_CheckButton_SetToggleFunction(control.checkbox, control.data.funcSet) - ZO_CheckButton_SetEnableState(control.checkbox, not (control.data.disabledFunc and control.data.disabledFunc())) - end + base:Debug("CBs_Settings_List:SetupRow_Checkbox", control, data) + + control.data = data + ZO_SortFilterList.SetupRow(self, control, data) + + control.checkbox = GetControl(control, "Checkbox") + + if control.checkbox then + control.checkbox.tooltipText = data.tooltipText + ZO_CheckButton_SetCheckState(control.checkbox, control.data.funcGet and control.data.funcGet()) + ZO_CheckButton_SetLabelText(control.checkbox, data.name) + + if control.checkbox.label then + control.checkbox.label.defaultNormalColor = ZO_DEFAULT_ENABLED_COLOR + control.checkbox.label:ClearAnchors() + control.checkbox.label:SetAnchor(TOPLEFT, control, TOPLEFT, 0) + control.checkbox.label:SetAnchor(BOTTOMRIGHT, control.checkbox, BOTTOMLEFT) + end + + ZO_CheckButton_SetTooltipAnchor(control.checkbox, TOP, control.checkbox.label) + ZO_CheckButton_SetToggleFunction(control.checkbox, control.data.funcSet) + ZO_CheckButton_SetEnableState(control.checkbox, not (control.data.disabledFunc and control.data.disabledFunc())) + end 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) + 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) - local funcMouseEnter = nil - local funcMouseExit = nil - control:SetHidden(false) - control:SetAlpha(1) - if data.hasChildren then - control:SetHandler("OnMouseUp", function() - base.Global.ShowChildren[data.name] = not base.Global.ShowChildren[data.name] - base.Global.Settings.List:RefreshFilters() - end) - funcMouseEnter = function(_control) ZO_Tooltips_ShowTextTooltip(_control, BOTTOM, _control.data.tooltipText) end - funcMouseExit = function() ZO_Tooltips_HideTextTooltip() end - end - - self.SetNameText(control, control.data.name) - self.SetupIcon(control, control.data, funcMouseEnter, funcMouseExit) - self.SetActiveOrInactive(control) + base:Debug("CBs_Settings_List:SetupRow_Category_Title", control, data) + + control.data = data + ZO_SortFilterList.SetupRow(self, control, control.data) + local funcMouseEnter = nil + local funcMouseExit = nil + control:SetHidden(false) + control:SetAlpha(1) + + if data.hasChildren then + control:SetHandler("OnMouseUp", function() + base.Global.ShowChildren[data.name] = not base.Global.ShowChildren[data.name] + base.Global.Settings.List:RefreshFilters() + end) + funcMouseEnter = function(_control) + ZO_Tooltips_ShowTextTooltip(_control, BOTTOM, _control.data.tooltipText) + end + funcMouseExit = function() + ZO_Tooltips_HideTextTooltip() + end + end + + self.SetNameText(control, control.data.name) + self.SetupIcon(control, control.data, funcMouseEnter, funcMouseExit) + self.SetActiveOrInactive(control) 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) + 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") - if control.button then - control.button:SetHidden(false) - 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) - PlaySound(SOUNDS.SINGLE_SETTING_RESET_TO_DEFAULT) - control.data.funcCog(button) - end) - end - - local hasIcon = self.SetupIcon(control, data) - if control.checkbox ~= nil and control.checkbox.label ~= nil and hasIcon then control.checkbox.label:SetAnchor(TOPLEFT, control, TOPLEFT, 26) end + base:Debug("CBs_Settings_List:SetupRow_Category_Checkbox", control, data) + + control.data = data + self:SetupRow_Checkbox(control, data) + control.button = GetControl(control, "Button") + + if control.button then + control.button:SetHidden(false) + 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) + PlaySound(SOUNDS.SINGLE_SETTING_RESET_TO_DEFAULT) + control.data.funcCog(button) + end) + end + + local hasIcon = self.SetupIcon(control, data) + if control.checkbox ~= nil and control.checkbox.label ~= nil and hasIcon then + control.checkbox.label:SetAnchor(TOPLEFT, control, TOPLEFT, 26) + end 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) + 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) - - control.dropdown = GetControl(control, "Dropdown") - control.comboBox = ZO_ComboBox_ObjectFromContainer(control.dropdown) - control.comboBox:SetSortsItems(false) - control.comboBox:SetFont(texts.Font.ZoFontWinT1) - control.comboBox:SetSpacing(4) - control.comboBox.tooltipText = data.tooltipText - - self.SetNameText(control, control.data.name) - self.RepopulateDropdownOptions(control) - self.SetActiveOrInactive(control) + base:Debug("CBs_Settings_List:SetupRow_Dropdown", control, data) + + control.data = data + ZO_SortFilterList.SetupRow(self, control, data) + + control.dropdown = GetControl(control, "Dropdown") + control.comboBox = ZO_ComboBox_ObjectFromContainer(control.dropdown) + control.comboBox:SetSortsItems(false) + control.comboBox:SetFont(texts.Font.ZoFontWinT1) + control.comboBox:SetSpacing(4) + control.comboBox.tooltipText = data.tooltipText + + self.SetNameText(control, control.data.name) + self.RepopulateDropdownOptions(control) + self.SetActiveOrInactive(control) 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) + 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) - - control.slider = GetControl(control, "Slider") - -- Need to override the existing value changed handler first so it doesn't run when we do the SetMinMax - control.slider:SetHandler("OnValueChanged", nil) - control.slider:SetMinMax(control.data.minValue, control.data.maxValue) - control.slider:SetValueStep(control.data.valueStep or 1) - control.slider:SetValue(data.funcGet()) - control.slider:SetHandler("OnValueChanged", control.data.funcSet) - - if data.default then - if control.defaultMarkerControl == nil then control.defaultMarkerControl = CreateControlFromVirtual("$(parent)DefaultMarker", control.slider, "ZO_Options_DefaultMarker") end - local offsetX = zo_clampedPercentBetween(data.minValue, data.maxValue, data.default) * control.slider:GetWidth() - control.defaultMarkerControl:SetAnchor(TOP, control.slider, LEFT, offsetX + .25, 6) - - control.defaultMarkerControl:SetHandler("OnClicked", function() - PlaySound(SOUNDS.SINGLE_SETTING_RESET_TO_DEFAULT) - control.slider:SetValue(data.default) - control.data.funcSet(control.slider, data.default) - end) - end - - local valueLabelControl = GetControl(control, "ValueLabel") - if valueLabelControl and data.showValue then - local shownVal = data.funcGet() - if data.valueMin and data.valueMax and data.valueMax > data.valueMin then - local range = data.maxValue - data.minValue - local percentage = (shownVal - data.minValue) / range - - local shownRange = data.valueMax - data.valueMin - shownVal = data.valueMin + percentage * shownRange - shownVal = string.format(texts.Format.Decimal, shownVal) - end - valueLabelControl:SetText(shownVal) - end - - self.SetNameText(control, control.data.name) - self.SetActiveOrInactive(control) + base:Debug("CBs_Settings_List:SetupRow_Slider", control, data) + + control.data = data + ZO_SortFilterList.SetupRow(self, control, control.data) + + control.slider = GetControl(control, "Slider") + -- Need to override the existing value changed handler first so it doesn't run when we do the SetMinMax + control.slider:SetHandler("OnValueChanged", nil) + control.slider:SetMinMax(control.data.minValue, control.data.maxValue) + control.slider:SetValueStep(control.data.valueStep or 1) + control.slider:SetValue(data.funcGet()) + control.slider:SetHandler("OnValueChanged", control.data.funcSet) + + if data.default then + if control.defaultMarkerControl == nil then + control.defaultMarkerControl = CreateControlFromVirtual("$(parent)DefaultMarker", control.slider, "ZO_Options_DefaultMarker") + end + + local offsetX = zo_clampedPercentBetween(data.minValue, data.maxValue, data.default) * control.slider:GetWidth() + control.defaultMarkerControl:SetAnchor(TOP, control.slider, LEFT, offsetX + .25, 6) + + control.defaultMarkerControl:SetHandler("OnClicked", function() + PlaySound(SOUNDS.SINGLE_SETTING_RESET_TO_DEFAULT) + control.slider:SetValue(data.default) + control.data.funcSet(control.slider, data.default) + end) + end + + local valueLabelControl = GetControl(control, "ValueLabel") + + if valueLabelControl and data.showValue then + local shownVal = data.funcGet() + + if data.valueMin and data.valueMax and data.valueMax > data.valueMin then + local range = data.maxValue - data.minValue + local percentage = (shownVal - data.minValue) / range + + local shownRange = data.valueMax - data.valueMin + shownVal = data.valueMin + percentage * shownRange + shownVal = string.format(texts.Format.Decimal, shownVal) + end + + valueLabelControl:SetText(shownVal) + end + + self.SetNameText(control, control.data.name) + self.SetActiveOrInactive(control) 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) + 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) - - control.editBox = GetControl(control, "EditBox") - if control.editBox then - ZO_EditDefaultText_Initialize(control.editBox) - control.editBox:SetHandler("OnTextChanged", nil) - control.editBox:SetText(data.funcGet()) - control.editBox:SetHandler("OnTextChanged", function() data.funcSet(control.editBox) end) - end - - self.SetNameText(control, control.data.name) - self.SetActiveOrInactive(control) + base:Debug("CBs_Settings_List:SetupRow_EditBox", control, data) + + control.data = data + ZO_SortFilterList.SetupRow(self, control, control.data) + + control.editBox = GetControl(control, "EditBox") + + if control.editBox then + ZO_EditDefaultText_Initialize(control.editBox) + control.editBox:SetHandler("OnTextChanged", nil) + control.editBox:SetText(data.funcGet()) + control.editBox:SetHandler("OnTextChanged", function() + data.funcSet(control.editBox) + end) + end + + self.SetNameText(control, control.data.name) + self.SetActiveOrInactive(control) 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) + 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) - - local fontOverrides = nil - if data.hasChildren then fontOverrides = {font = texts.Font.ZoFontWinH4, modifyTextType = MODIFY_TEXT_TYPE_NONE} end - self.SetNameText(control, data.name, fontOverrides) - self.SetActiveOrInactive(control) + base:Debug("CBs_Settings_List:SetupRow_Title", control, data) + + control.data = data + ZO_SortFilterList.SetupRow(self, control, data) + + local fontOverrides = nil + + if data.hasChildren then + fontOverrides = {font = texts.Font.ZoFontWinH4, modifyTextType = MODIFY_TEXT_TYPE_NONE} + end + + self.SetNameText(control, data.name, fontOverrides) + self.SetActiveOrInactive(control) 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) + 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) - - control.button = GetControl(control, "Button") - if control.button then - control.button:SetText(control.data.buttonName or "") - control.button:SetHandler("OnClicked", function() control.data.funcSet() end) - end - - self.SetNameText(control, control.data.name) - self.SetActiveOrInactive(control) + base:Debug("CBs_Settings_List:SetupRow_Button", control, data) + + control.data = data + ZO_SortFilterList.SetupRow(self, control, control.data) + + control.button = GetControl(control, "Button") + + if control.button then + control.button:SetText(control.data.buttonName or "") + control.button:SetHandler("OnClicked", function() + control.data.funcSet() + end) + end + + self.SetNameText(control, control.data.name) + self.SetActiveOrInactive(control) 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) + base:Debug("CBs_Settings_List:AppendRow_Divider", listType, data) + + data.listType = listType + data.dataTypeId = 100 + table.insert(self.masterList, data) 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() - local selectedEntry = nil - for _, optionValue in pairs(control.data.choices or {}) do - local entry = ZO_ComboBox:CreateItemEntry(optionValue, control.data.funcSet) - control.comboBox:AddItem(entry) - - if optionValue == selectedValue then selectedEntry = entry end - end - control.comboBox:SelectItem(selectedEntry) + base:Debug("CBs_Settings_List.RepopulateDropdownOptions", control) + + control.comboBox:ClearItems() + + local selectedValue = control.data.funcGet() + local selectedEntry = nil + + for _, optionValue in pairs(control.data.choices or {}) do + local entry = ZO_ComboBox:CreateItemEntry(optionValue, control.data.funcSet) + control.comboBox:AddItem(entry) + + if optionValue == selectedValue then + selectedEntry = entry + end + end + + control.comboBox:SelectItem(selectedEntry) 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 - control.label:SetFont(fontOverrides.font) - control.label:SetModifyTextType(fontOverrides.modifyTextType) - end - control.label:SetText(text or "") - end + 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 + control.label:SetFont(fontOverrides.font) + control.label:SetModifyTextType(fontOverrides.modifyTextType) + end + + control.label:SetText(text or "") + end end function CBs_Settings_List.SetupIcon(control, data, funcMouseEnter, funcMouseExit) - 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 - control.icon:SetHidden(not hasIcon) - control.icon:SetTexture(data.icon and data.icon[1]) - - if data.icon[1] ~= nil and data.icon[3] ~= nil then - control:SetHandler("OnMouseEnter", function() - control.icon:SetTexture(data.icon[3]) - if funcMouseEnter ~= nil then funcMouseEnter(control) end - end) - control:SetHandler("OnMouseExit", function() - control.icon:SetTexture(data.icon[1]) - if funcMouseExit ~= nil then funcMouseExit(control) end - end) - end - return hasIcon - end + 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 + control.icon:SetHidden(not hasIcon) + control.icon:SetTexture(data.icon and data.icon[1]) + + if data.icon[1] ~= nil and data.icon[3] ~= nil then + control:SetHandler("OnMouseEnter", function() + control.icon:SetTexture(data.icon[3]) + if funcMouseEnter ~= nil then + funcMouseEnter(control) + end + end) + control:SetHandler("OnMouseExit", function() + control.icon:SetTexture(data.icon[1]) + if funcMouseExit ~= nil then + funcMouseExit(control) + end + end) + end + + return hasIcon + end 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") - if control.label then - if disabled then - control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA()) - else - control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA()) - end - end - - control.valueLabelControl = GetControl(control, "ValueLabel") - if control.valueLabelControl then - if disabled then - control.valueLabelControl:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA()) - else - control.valueLabelControl:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA()) - end - end - - if control.button then control.button:SetEnabled(not disabled) end - - if control.comboBox then control.comboBox:SetEnabled(not disabled) end - - if control.slider then control.slider:SetEnabled(not disabled) end - - if control.editBox then ZO_DefaultEdit_SetEnabled(control.editBox, not disabled) end + base:Debug("CBs_Settings_List.SetActiveOrInactive", control) + + local disabled = control.data.disabledFunc and control.data.disabledFunc() + local disabledColor = ZO_DEFAULT_DISABLED_COLOR + local enabledColor = ZO_DEFAULT_ENABLED_COLOR + local function SetColor(label) + if label then + local color = enabledColor + + if disabled then + label:SetColor(disabledColor:UnpackRGBA()) + end + + label:SetColor(color:UnpackRGBA()) + end + + end + + local function SetEnabled(element) + if element then + element:SetEnabled(not disabled) + end + end + + control.label = GetControl(control, "Name") + SetColor(control.label) + + control.valueLabelControl = GetControl(control, "ValueLabel") + SetColor(control.valueLabelControl) + + SetEnabled(control.button) + SetEnabled(control.comboBox) + SetEnabled(control.slider) + + if control.editBox then + ZO_DefaultEdit_SetEnabled(control.editBox, not disabled) + end end ------------------------------------------------------------------------------------------------- -- FUNCTIONS - MasterList -- ------------------------------------------------------------------------------------------------- function CBs_Settings_List:BuildMasterList() - base:Debug("CBs_Settings_List:BuildMasterList") - self.masterList = {} - - base.AppendMasterListTypeGeneral(self, "General") - base.AppendMasterListTypeCategories(self, "Categories") - base.AppendMasterListTypeCombined(self, "Combined") - if self.category then - base.AppendMasterListTypeCollectibles(self, "Collectibles") - base.AppendMasterListTypeCategory(self, "Category") - else - base.AppendMasterListTypeNoCategory(self, "Collectibles") - base.AppendMasterListTypeNoCategory(self, "Category") - end + base:Debug("CBs_Settings_List:BuildMasterList") + + self.masterList = {} + + base.AppendMasterListTypeGeneral(self, "General") + base.AppendMasterListTypeCategories(self, "Categories") + base.AppendMasterListTypeCombined(self, "Combined") + + if self.category then + base.AppendMasterListTypeCollectibles(self, "Collectibles") + base.AppendMasterListTypeCategory(self, "Category") + else + base.AppendMasterListTypeNoCategory(self, "Collectibles") + base.AppendMasterListTypeNoCategory(self, "Category") + end end function CBs_Settings_List:FilterScrollList() - base:Debug("CBs_Settings_List:FilterScrollList") - local scrollData = ZO_ScrollList_GetDataList(self.list) - ZO_ClearNumericallyIndexedTable(scrollData) - for _, listElement in ipairs(self.masterList) do - if self.masterListType == nil or self.masterListType == listElement.listType then - if self.masterListType == "Categories" and listElement.parentKey ~= nil then - local showChildren = base.Global.ShowChildren[listElement.parentKey] - base:Debug("FilterScrollList", base.Global.ShowChildren, listElement.parentKey, base.Global.ShowChildren[listElement.parentKey]) - if showChildren then scrollData[#scrollData + 1] = ZO_ScrollList_CreateDataEntry(listElement.dataTypeId, listElement) end - else - scrollData[#scrollData + 1] = ZO_ScrollList_CreateDataEntry(listElement.dataTypeId, listElement) - end - end - end + base:Debug("CBs_Settings_List:FilterScrollList") + + local scrollData = ZO_ScrollList_GetDataList(self.list) + ZO_ClearNumericallyIndexedTable(scrollData) + + for _, listElement in ipairs(self.masterList) do + if self.masterListType == nil or self.masterListType == listElement.listType then + if self.masterListType == "Categories" and listElement.parentKey ~= nil then + local showChildren = base.Global.ShowChildren[listElement.parentKey] + + base:Debug("FilterScrollList", base.Global.ShowChildren, listElement.parentKey, base.Global.ShowChildren[listElement.parentKey]) + + if showChildren then + scrollData[#scrollData + 1] = ZO_ScrollList_CreateDataEntry(listElement.dataTypeId, listElement) + end + else + scrollData[#scrollData + 1] = ZO_ScrollList_CreateDataEntry(listElement.dataTypeId, listElement) + end + end + end end -function CBs_Settings_List:SortScrollList() end +function CBs_Settings_List:SortScrollList() +end diff --git a/Changelog b/Changelog index c8416a8..3915633 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,9 @@ ------------------------------------------------------------------------------- Collection bars ------------------------------------------------------------------------------- +Version 1.1.10 (22-08-2021) +- Formatted files and updated version + Version 1.1.9 (02-11-2020) - Fixed issue when creating categories as subcategories would cause an exception when trying to fetch the number of subcategories on them. diff --git a/CollectionBars.lua b/CollectionBars.lua index e192801..5e92d45 100644 --- a/CollectionBars.lua +++ b/CollectionBars.lua @@ -13,127 +13,154 @@ local texts = base.Texts ------------------------------------------------------------------------------------------------- function base.OnAddOnLoaded(_, addonName) - base:InitializeLog("OnAddOnLoaded", addonName) - if addonName == base.Addon.Name then - base:SetSavedSettings() -- Incomplete saved settings - For SetLogsEnabled - base:SetLogsEnabled() - base:GenerateCategories() - base:SetSavedSettings() -- Complete saved settings - base:InitializeReverseBinding() - base:InitializeCombineFrame() - base:InitializeWithSavedData() - base:InitializeBindings() - base:InitializeSettingsSlash() - - EVENT_MANAGER:UnregisterForEvent(base.Addon.Name, EVENT_ADD_ON_LOADED) - end - base:Info("OnAddOnLoaded:end", addonName) + base:InitializeLog("OnAddOnLoaded", addonName) + + if addonName == base.Addon.Name then + base:SetSavedSettings() -- Incomplete saved settings - For SetLogsEnabled + base:SetLogsEnabled() + base:GenerateCategories() + base:SetSavedSettings() -- Complete saved settings + base:InitializeReverseBinding() + base:InitializeCombineFrame() + base:InitializeWithSavedData() + base:InitializeBindings() + base:InitializeSettingsSlash() + + EVENT_MANAGER:UnregisterForEvent(base.Addon.Name, EVENT_ADD_ON_LOADED) + end + + base:Info("OnAddOnLoaded:end", addonName) 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: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() end function base:InitializeCategory(category) - base:Debug("InitializeCategory", category) - base:CreateCategory(category) - base:SetupLabel(category) - base:RestoreFrame(category) + base:Debug("InitializeCategory", category) + + base:CreateCategory(category) + base:SetupLabel(category) + base:RestoreFrame(category) end 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) + 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) - base:Debug("CreateCategory", category) - category.Collection = {} - category.CollectionOrdered = {} - category.Unlocked = GetTotalUnlockedCollectiblesByCategoryType(category.CategoryType) - - if category.Unlocked > base.Global.HighestUnlocked then base.Global.HighestUnlocked = category.Unlocked end - - 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.Menu.ShowDisabled 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) - category.Collection[collectibleId] = { - Id = collectibleId, - Name = collectibleData:GetName(), - EnabledTexture = collectibleData:GetIcon(), - Disabled = not isUnlocked, - Tooltip = string.format("%s\n%s", collectibleData:GetDescription(), collectibleData:GetHint()), - CollectibleData = collectibleData - } - table.insert(category.CollectionOrdered, category.Collection[collectibleId]) - end - end - - category.Frames.Frame = base:GetFrame(string.format(texts.FormatCategoryName, category.Id), string.format(texts.FormatAbbreviationLowDash, "Frame")) + base:Debug("CreateCategory", category) + + category.Collection = {} + category.CollectionOrdered = {} + category.Unlocked = GetTotalUnlockedCollectiblesByCategoryType(category.CategoryType) + + if category.Unlocked > base.Global.HighestUnlocked then + base.Global.HighestUnlocked = category.Unlocked + end + + for _, 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.Menu.ShowDisabled 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) + category.Collection[collectibleId] = { + Id = collectibleId, + Name = collectibleData:GetName(), + EnabledTexture = collectibleData:GetIcon(), + Disabled = not isUnlocked, + Tooltip = string.format("%s\n%s", collectibleData:GetDescription(), collectibleData:GetHint()), + CollectibleData = collectibleData + } + table.insert(category.CollectionOrdered, category.Collection[collectibleId]) + end + end + + category.Frames.Frame = base:GetFrame(string.format(texts.FormatCategoryName, category.Id), string.format(texts.FormatAbbreviationLowDash, "Frame")) end function base:RestoreFrames() - base:Debug("RestoreFrames") - for _, category in pairs(base.Categories) do base:RestoreFrame(category) end - base:RestoreCombine() + base:Debug("RestoreFrames") + + for _, category in pairs(base.Categories) do + base:RestoreFrame(category) + end + + base:RestoreCombine() end function base:HideOthers(newCategory) - base:Debug("HideOthers", newCategory) - for _, category in pairs(base.Categories) do - 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 + base:Debug("HideOthers", newCategory) + + for _, category in pairs(base.Categories) do + 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) - base:Debug("RestoreFrame", category) - if category.Saved.Enabled then - 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) - end + base:Debug("RestoreFrame", category) + + if category.Saved.Enabled then + 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) + end end function base:RemoveFrame(category) - base:Debug("RemoveFrame", category) - base:RemoveFragments(category) - for _, button in pairs(category.Buttons) do if button ~= nil then button:SetHidden(true) end end - - if category.Frames.Frame ~= nil then - base:Debug("RemoveFrame:hide", category.Frames.Frame) - category.Frames.Frame:SetHidden(true) - end + base:Debug("RemoveFrame", category) + + base:RemoveFragments(category) + + for _, button in pairs(category.Buttons) do + if button ~= nil then + button:SetHidden(true) + end + 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:Debug("RestoreCombine") - base:RestoreCombineLabels() - base:RestorePosition(base.Global.Combine.Frames.Frame, base.Saved.Combine) - base:UpdateMoveFrame(base.Global.Combine) - base:UpdateFragment(base.Global.Combine) + 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 e7458a9..a990ec6 100644 --- a/CollectionBars.txt +++ b/CollectionBars.txt @@ -4,21 +4,14 @@ ; States and/or other countries. All rights reserved. ; You can read the full terms at https://account.elderscrollsonline.com/add-on-terms -## APIVersion: 100033 ## Title: Collection Bars -## AddOnVersion: 10109 -## Version: 1.1.9 +## APIVersion: 100035 +## Version: 1.1.10 ## Author: Jarth -## 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. -## All rights reserved -## -## You can read the full terms at https://account.elderscrollsonline.com/add-on-terms +## Description: Show collection bars and activate collections with key or button press. Settings window: /cb. LibDebugLogger can be used for logging can be enabled in the settings +## OptionalDependsOn: LibDebugLogger ## SavedVariables: CollectionBars_Account ## SavedVariables: CollectionBars_Character -## OptionalDependsOn: LibDebugLogger CBs_Settings.xml CBs_Button.xml