diff --git a/Bindings.xml b/Bindings.xml deleted file mode 100644 index a2c161b..0000000 --- a/Bindings.xml +++ /dev/null @@ -1,69 +0,0 @@ -<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> - </Layer> -</Bindings> \ No newline at end of file diff --git a/CBs_Bindings.lua b/CBs_Bindings.lua deleted file mode 100644 index d1e6085..0000000 --- a/CBs_Bindings.lua +++ /dev/null @@ -1,81 +0,0 @@ ---[[ -Author: Jarth -Filename: CBs_Bindings.lua -]] -- -------------------------------------------------------------------------------------------------- --- VARIABLES -- -------------------------------------------------------------------------------------------------- -local base = CollectionBars -local texts = base.Texts - -------------------------------------------------------------------------------------------------- --- FUNCTIONS -- -------------------------------------------------------------------------------------------------- -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 -end - -function base:SetBindingText(cid) - base:Debug("SetBindingText", cid) - - if base.AllButtons[cid] then - base.AllButtons[cid]:SetBindingText(base.Saved.Bindings.Show, cid) - end -end - -function base:InitializeBindings() - 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 -end diff --git a/CBs_Button.lua b/CBs_Button.lua deleted file mode 100644 index ee575a5..0000000 --- a/CBs_Button.lua +++ /dev/null @@ -1,235 +0,0 @@ ---[[ -Author: Jarth -Filename: CBs_Button.lua -]] -- -------------------------------------------------------------------------------------------------- --- VARIABLES -- -------------------------------------------------------------------------------------------------- -local base = CollectionBars -local texts = base.Texts - -------------------------------------------------------------------------------------------------- --- FUNCTIONS -- -------------------------------------------------------------------------------------------------- -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 -end - -function CBs_Button:UpdateAnchor(frame, left, top) - base:Verbose("CBs_Button:UpdateAnchor", frame, left, top) - - self.ctrl:ClearAnchors() - self.ctrl:SetAnchor(TOPLEFT, frame, TOPLEFT, left, top) -end - -function CBs_Button:Setup() - base:Verbose("CBs_Button:Setup") - - self.ctrl:SetHidden(false) - 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) -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) -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 -end - -function CBs_Button:OnClicked() - base:Verbose("CBs_Button:OnClicked") - - if self.usable then - UseCollectible(self.cId) - end -end - -function CBs_Button:UpdateState(forceId, isAttempting, 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) -end - -function CBs_Button:UpdateUsable() - base:Verbose("CBs_Button:UpdateUsable") - - 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) - - self.icon.percentComplete = percentComplete - self.cooldownTime:SetText(cooldown) -end - -function CBs_Button:UpdatePlaySounds(playSounds) - base:Verbose("CBs_Button:UpdatePlaySounds", playSounds) - - self.playSounds = playSounds -end - -function CBs_Button:UpdateCooldown(remaining, duration, cooldown) - base:Verbose("CBs_Button:UpdateCooldown", remaining, duration, cooldown) - - local showCooldown = duration > 0 - - self.cooldown:SetHidden(not showCooldown) - 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) -end - -function CBs_Button:IsHidden() - base:Verbose("CBs_Button:IsHidden") - - local isHidden = self.ctrl:IsHidden() - - return isHidden -end diff --git a/CBs_Button.xml b/CBs_Button.xml deleted file mode 100644 index 357d472..0000000 --- a/CBs_Button.xml +++ /dev/null @@ -1,49 +0,0 @@ -<GuiXml> - <Controls> - <Control name="CBs_Button" clampedToScreen="true" movable="false" virtual="true" level="4"> - <Controls> - <Button name="$(parent)Button" mouseOverBlendMode="ADD"> - <AnchorFill /> - <MouseButton button="1" enabled="true" /> - <MouseButton button="2" enabled="true" /> - <Textures normal="/EsoUI/Art/ActionBar/abilityFrame64_up.dds" pressed="/EsoUI/Art/ActionBar/abilityFrame64_down.dds" mouseOver="/EsoUI/Art/ActionBar/actionBar_mouseOver.dds" /> - </Button> - - <Texture name="$(parent)BG" level="0" textureFile="/EsoUI/Art/ActionBar/abilityInset.dds"> - <Anchor point="TOPLEFT" relativeTo="$(parent)" /> - <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" /> - </Texture> - <Texture name="$(parent)Icon" level="1"> - <Anchor point="CENTER" relativeTo="$(parent)" /> - </Texture> - <Texture name="$(parent)CooldownIcon" level="1"> - <TextureCoords left="0" right="1" top="0" bottom="0" /> - <Anchor point="TOPLEFT" relativeTo="$(parent)Icon" relativePoint="TOPLEFT" /> - <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)Icon" relativePoint="BOTTOMRIGHT" /> - </Texture> - <Texture name="$(parent)Status" textureFile="/EsoUI/Art/ActionBar/ActionSlot_toggledon.dds" tier="HIGH" hidden="true"> - <Anchor point="TOPLEFT" relativeTo="$(parent)Icon" relativePoint="TOPLEFT" /> - <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)Icon" relativePoint="BOTTOMRIGHT" /> - </Texture> - - <Cooldown name="$(parent)Cooldown" inherits="ZO_DefaultCooldown" tier="HIGH" alpha="0.7"> - <Anchor point="TOPLEFT" relativeTo="$(parent)Icon" relativePoint="TOPLEFT" /> - <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)Icon" relativePoint="BOTTOMRIGHT" /> - </Cooldown> - <Texture name="$(parent)CooldownCompleteAnimation" textureFile="/EsoUI/Art/ActionBar/coolDown_completeEFX.dds" blendMode="ADD" tier="HIGH" hidden="true"> - <Anchor point="TOPLEFT" relativeTo="$(parent)Icon" relativePoint="TOPLEFT" /> - <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)Icon" relativePoint="BOTTOMRIGHT" /> - </Texture> - - <Label name="$(parent)ButtonText" wrapMode="ELLIPSIS" horizontalAlignment="CENTER" tier="HIGH" verticalAlignment="BOTTOM" font="ZoFontGameSmall"> - <Anchor point="BOTTOM" relativeTo="$(parent)Button" relativePoint="BOTTOM" /> - </Label> - - <Label name="$(parent)CooldownTime" font="ZoFontWindowSubtitle" wrapMode="ELLIPSIS" color="INTERFACE_COLOR_TYPE_TEXT_COLORS:INTERFACE_TEXT_COLOR_SELECTED" horizontalAlignment="CENTER" verticalAlignment="CENTER" hidden="true"> - <Anchor point="TOPLEFT" relativeTo="$(parent)Icon" relativePoint="TOPLEFT" /> - <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)Icon" relativePoint="BOTTOMRIGHT" /> - </Label> - </Controls> - </Control> - </Controls> -</GuiXml> \ No newline at end of file diff --git a/CBs_Buttons.lua b/CBs_Buttons.lua deleted file mode 100644 index 05d88d9..0000000 --- a/CBs_Buttons.lua +++ /dev/null @@ -1,206 +0,0 @@ ---[[ -Author: Jarth -Filename: CBs_Buttons.lua -]] -- -------------------------------------------------------------------------------------------------- --- VARIABLES -- -------------------------------------------------------------------------------------------------- -local base = CollectionBars -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 -end - -function base:SetFrameAndCombineSize(category) - base:Debug("SetFrameAndCombineSize", category) - local width, height = base:GetBarWidthHeight(category) - base:SetFrameSizeIfExists(category.Frames.Frame, width, height) - - if category.Saved.Bar.IsCombined and not category.Saved.Bar.HideAll then - base:SetFrameSizeIfExists(base.Global.Combine.Frames.Frame, width, height) - end -end - -function base:GetFrame(name, virtual) - base:Debug("GetFrame", name, virtual) - - local frame = GetControl(name) - - if frame == nil then - frame = base.WM:CreateControlFromVirtual(name, GuiRoot, virtual) - end - - base:Debug("GetFrame:return", frame) - - return frame -end - -function base:GetButtonPosition(category, index) - 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 -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 -end - -function base:UpdateButtonsCooldown(category, remaining, duration, cooldown) - base:Debug("UpdateButtonsCooldown", category, remaining, duration, cooldown) - - for _cId, button in pairs(category.Buttons) do - if button ~= nil and category.Collection[_cId] then - button:UpdateCooldown(remaining, duration, cooldown) - end - end -end - -function base:GetCooldownText(countDown, duration) - base:Debug("GetCooldownText", countDown, duration) - - local 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) - - 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 -end diff --git a/CBs_Constants.lua b/CBs_Constants.lua deleted file mode 100644 index 69336c7..0000000 --- a/CBs_Constants.lua +++ /dev/null @@ -1,175 +0,0 @@ ---[[ -Author: Jarth -Filename: CBs_Constants.lua -]] -- -------------------------------------------------------------------------------------------------- --- VARIABLES -- -------------------------------------------------------------------------------------------------- -CollectionBars = { - WM = GetWindowManager(), - Addon = {Name = "CollectionBars", DisplayName = "Collection Bars", Abbreviation = "CBs", Version = 1.1, MinorVersion = 11, 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"}, - [9] = {Name = "InArmoryKeyboard", Instance = SCENE_MANAGER:GetScene("armoryKeyboard"), Description = "%s at the armory (Keyboard)"}, - [10] = {Name = "InArmoryGamepad", Instance = SCENE_MANAGER:GetScene("armoryRootGamepad"), Description = "%s at the armory (Gamepad)"}, - [11] = {Name = "InDeconstructionKeyboard", Instance = SCENE_MANAGER:GetScene("universalDeconstructionSceneKeyboard"), Description = "%s in deconstruction screen (Keyboard)"}, - [12] = {Name = "InDeconstructionGamepad", Instance = SCENE_MANAGER:GetScene("universalDeconstructionSceneGamepad"), Description = "%s in deconstruction screen (Gamepad)"} - }, - 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 - -base.Texts.FormatAbbreviation = string.format("%s%%s", base.Addon.Abbreviation) -base.Texts.FormatAbbreviationLowDash = string.format("%s_%%s", base.Addon.Abbreviation) -base.Texts.FormatCategoryName = string.format("%s_C%%s", base.Addon.Abbreviation) -base.Texts.FormatBindingName = string.format("SI_BINDING_NAME_%s", base.Texts.FormatAbbreviationLowDash) -base.Texts.CombineFrameName = string.format(base.Texts.FormatAbbreviationLowDash, "CombineFrame") -base.Texts.CombineFrameNameHideAll = string.format("%s%s", base.Texts.CombineFrameName, "HideAll") -base.Texts.AccountKey = string.format("%s_Account", base.Addon.Name) -base.Texts.CharacterKey = string.format("%s_Character", base.Addon.Name) - -base.IconState = {NORMAL = 1, OVER = 2, PRESSED = 3, DISABLED = 4} -base.ToggleButtonState = {OPEN = true, CLOSED = false} -base.ToggleButtonIcon = { - [base.ToggleButtonState.OPEN] = { - [base.IconState.NORMAL] = "EsoUI/Art/Buttons/tree_open_up.dds", - [base.IconState.OVER] = "EsoUI/Art/Buttons/tree_open_over.dds", - [base.IconState.PRESSED] = "EsoUI/Art/Buttons/tree_open_down.dds", - [base.IconState.DISABLED] = "EsoUI/Art/Buttons/tree_open_disabled.dds" - }, - [base.ToggleButtonState.CLOSED] = { - [base.IconState.NORMAL] = "EsoUI/Art/Buttons/tree_closed_up.dds", - [base.IconState.OVER] = "EsoUI/Art/Buttons/tree_closed_over.dds", - [base.IconState.PRESSED] = "EsoUI/Art/Buttons/tree_closed_down.dds", - [base.IconState.DISABLED] = "EsoUI/Art/Buttons/tree_closed_disabled.dds" - } -} - -------------------------------------------------------------------------------------------------- --- FUNCTIONS -- -------------------------------------------------------------------------------------------------- - -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 -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 -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 -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} - } -end diff --git a/CBs_Fragment.lua b/CBs_Fragment.lua deleted file mode 100644 index cf99294..0000000 --- a/CBs_Fragment.lua +++ /dev/null @@ -1,65 +0,0 @@ ---[[ -Author: Jarth -Filename: CBs_Fragment.lua -]] -- -------------------------------------------------------------------------------------------------- --- VARIABLES -- -------------------------------------------------------------------------------------------------- -local base = CollectionBars -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) -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) -end - -function base:RemoveFragments(category) - base:Debug("RemoveFragments", category) - - if category.Fragment ~= nil then - for _, scene in ipairs(base.Global.Scenes) do - if scene ~= nil and scene.Instance ~= nil then - scene.Instance:RemoveFragment(category.Fragment) - end - end - end -end diff --git a/CBs_Helpers.lua b/CBs_Helpers.lua deleted file mode 100644 index 98a6a65..0000000 --- a/CBs_Helpers.lua +++ /dev/null @@ -1,285 +0,0 @@ ---[[ -Author: Jarth -Filename: CBs_Helpers.lua -]] -- -------------------------------------------------------------------------------------------------- --- VARIABLES -- -------------------------------------------------------------------------------------------------- -local base = CollectionBars -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 - - 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 -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 -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 -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 -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 - - return isAllSelected -end - -function base:AutoSelectAll(category, newValue) - base:Debug("AutoSelectAll", category, newValue) - - if newValue then - category.Saved.Selected = {} - end - -end - -function base:SelectAll(category, newValue) - base:Debug("SelectAll", category, newValue) - - for _, collectible in pairs(category.Collection) do - if newValue == true then - category.Saved.Selected[collectible.Id] = newValue - 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) -end - -function base:GetCharactersettings(useAccountSettings) - base:Debug("GetCharactersettings", useAccountSettings) - - local characterSettings = nil - - 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 -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 -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 -end - -function base:RemoveCharacterSettings() - 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 -end - -function base:GetBarWidthHeight(category) - base:Debug("GetBarWidthHeight", category) - - local width, height, count = 0, 0, 0 - - if not category.Saved.Bar.HideAll then - for key, button in pairs(category.Buttons) do - if not button:IsHidden() then - count = count + 1 - end - end - end - - if count > 0 then - category.Bar.Depth, category.Bar.Width = base:GetMaxBarSize(category, "Depth", count), base:GetMaxBarSize(category, "Width", count) - - local barWidth = zo_ceil(count / category.Bar.Depth) - local maxBarWidth = category.Bar.Width - - if maxBarWidth > 0 and maxBarWidth < barWidth then - barWidth = maxBarWidth - end - - local isHorizontal = category.Saved.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 -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 -end - -function base:SetControlText(control, text) - base:Debug("SetControlText", control, text) - - control.SetText(control, text) -end diff --git a/CBs_Labels.lua b/CBs_Labels.lua deleted file mode 100644 index 659d425..0000000 --- a/CBs_Labels.lua +++ /dev/null @@ -1,142 +0,0 @@ ---[[ -Author: Jarth -Filename: CBs_Labels.lua -]] -- -------------------------------------------------------------------------------------------------- --- VARIABLES -- -------------------------------------------------------------------------------------------------- -local base = CollectionBars -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) -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 -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 - - if category.Frames.LabelButton ~= nil then - category.Frames.LabelButton: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 -end diff --git a/CBs_Logging.lua b/CBs_Logging.lua deleted file mode 100644 index fdea6e0..0000000 --- a/CBs_Logging.lua +++ /dev/null @@ -1,57 +0,0 @@ ---[[ -Author: Jarth -Filename: CBs_Logging.lua -]] -- -------------------------------------------------------------------------------------------------- --- VARIABLES -- -------------------------------------------------------------------------------------------------- -local base = CollectionBars -local loggers = base.Loggers -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 -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 -end - -function base:LogSetEnabled(logger, doLogging, loggerType) - 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:Debug(...) - if loggers.Debug ~= nil and ... ~= nil then - loggers.Debug:Debug(...) - end -end - -function base:Verbose(...) - if loggers.Verbose ~= nil and ... ~= nil then - loggers.Verbose:Verbose(...) - end -end diff --git a/CBs_MoveFrame.lua b/CBs_MoveFrame.lua deleted file mode 100644 index 0e3d391..0000000 --- a/CBs_MoveFrame.lua +++ /dev/null @@ -1,134 +0,0 @@ ---[[ -Author: Jarth -Filename: CBs_MoveFrame.lua -]] -- -------------------------------------------------------------------------------------------------- --- VARIABLES -- -------------------------------------------------------------------------------------------------- -local base = CollectionBars -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) -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 -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 -end diff --git a/CBs_Settings.lua b/CBs_Settings.lua deleted file mode 100644 index c4a91cc..0000000 --- a/CBs_Settings.lua +++ /dev/null @@ -1,176 +0,0 @@ ---[[ -Author: Jarth -Filename: CBs_Settings.lua -]] -- -------------------------------------------------------------------------------------------------- --- VARIABLES -- -------------------------------------------------------------------------------------------------- -local base = CollectionBars -local texts = base.Texts - -------------------------------------------------------------------------------------------------- --- FUNCTIONS -- -------------------------------------------------------------------------------------------------- -function base:InitializeSettingsSlash() - base:Debug("InitializeSettingsSlash") - - SLASH_COMMANDS[base.Addon.SettingsSlash] = function() - base:ToggleEnableSettings(base.ShowSettings()) - end -end - -function base:ToggleEnableSettings(forceShow) - 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 - 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 -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) -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 -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 -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 -end - -function base:UpdateSettingsType(show, category) - base:Debug("UpdateSettingsType", show, category) - - if base.Global.Settings.List ~= nil then - base.Global.Settings.List.category = category - end - - if base.Global.SettingsLabel ~= nil then - base.Global.SettingsLabel:SetText(show and category and category.Name or "Global") - end -end diff --git a/CBs_Settings.xml b/CBs_Settings.xml deleted file mode 100644 index 9d8b004..0000000 --- a/CBs_Settings.xml +++ /dev/null @@ -1,244 +0,0 @@ -<GuiXml> - <Controls> - <TopLevelControl name="CBs_Settings" clampedToScreen="true" movable="true" mouseEnabled="true" virtual="true"> - <Anchor point="CENTER" relativePoint="CENTER"/> - <Dimensions x="544" y="944" /> - <DimensionConstraints minX="544" minY="944" /> - <Controls> - <Backdrop name="$(parent)Bg" integralWrapping="true"> - <Anchor point="TOPLEFT" offsetX="-8" offsetY="-6"/> - <Anchor point="BOTTOMRIGHT" offsetX="4" offsetY="4"/> - - <Edge file="EsoUI/Art/ChatWindow/chat_BG_edge.dds" edgeFileWidth="256" edgeFileHeight="256" edgeSize="32"/> - <Center file="EsoUI/Art/ChatWindow/chat_BG_center.dds" /> - <Insets left="32" top="32" right="-32" bottom="-32" /> - </Backdrop> - <Label name="$(parent)Title" font="ZoFontWinH1" modifyTextType="UPPERCASE"> - <Anchor point="TOPLEFT" offsetX="22" offsetY="22" /> - </Label> - - <Texture name="$(parent)Divider" inherits="ZO_Options_Divider"> - <Anchor point="TOPLEFT" relativeTo="$(parent)Title" relativePoint="BOTTOMLEFT" offsetY="2"/> - </Texture> - - <Label name="$(parent)Label" inherits="ZO_Options_SectionTitleLabel"> - <Anchor point="TOPLEFT" relativeTo="$(parent)Divider" relativePoint="TOPLEFT" offsetY="5"/> - </Label> - - <Button name="$(parent)General" inherits="ZO_DefaultButton" clickSound="Click" relativeTo="$(parent)"> - <Anchor point="TOPLEFT" relativeTo="$(parent)Label" relativePoint="BOTTOMLEFT" offsetY="15"/> - <Dimensions x="122" y="22" /> - </Button> - <Button name="$(parent)Categories" inherits="ZO_DefaultButton" clickSound="Click" relativeTo="$(parent)"> - <Anchor point="TOPLEFT" relativeTo="$(parent)General" relativePoint="TOPRIGHT" /> - <Dimensions x="122" y="22" /> - </Button> - <Button name="$(parent)Collectibles" inherits="ZO_DefaultButton" clickSound="Click" relativeTo="$(parent)"> - <Anchor point="TOPLEFT" relativeTo="$(parent)Categories" relativePoint="TOPRIGHT" /> - <Dimensions x="122" y="22" /> - </Button> - <Button name="$(parent)Category" inherits="ZO_DefaultButton" clickSound="Click" relativeTo="$(parent)"> - <Anchor point="TOPLEFT" relativeTo="$(parent)Collectibles" relativePoint="TOPRIGHT" /> - <Dimensions x="122" y="22" /> - </Button> - <Button name="$(parent)Combined" inherits="ZO_DefaultButton" clickSound="Click" relativeTo="$(parent)"> - <Anchor point="BOTTOMLEFT" relativeTo="$(parent)Category" relativePoint="TOPLEFT" offsetY="-5" /> - <Dimensions x="122" y="22" /> - </Button> - - <Control name="$(parent)List" inherits="ZO_ScrollList"> - <Anchor point="TOPLEFT" relativeTo="$(parent)General" relativePoint="BOTTOMLEFT" offsetY="22"/> - <Anchor point="BOTTOMRIGHT" offsetX="-22" offsetY="-22" /> - </Control> - - <Button name="$(parent)Close" clickSound="Click" relativeTo="$(parent)"> - <Anchor point="TOPRIGHT" relativeTo="$(parent)" relativePoint="TOPRIGHT" offsetX="-10" offsetY="10" /> - <Dimensions x="22" y="22" /> - <Textures name="$(parent)Textures" normal="/EsoUI/Art/Buttons/decline_up.dds" mouseOver="/EsoUI/Art/Buttons/decline_over.dds" pressed="/EsoUI/Art/Buttons/decline_down.dds" /> - </Button> - <Button name="$(parent)Refresh" clickSound="Click" relativeTo="$(parent)"> - <Anchor point="TOPRIGHT" relativeTo="$(parent)Close" relativePoint="TOPRIGHT" offsetX="-32" /> - <Dimensions x="22" y="22" /> - <Textures name="$(parent)Textures" normal="/EsoUI/Art/Buttons/edit_save_up.dds" mouseOver="/EsoUI/Art/Buttons/edit_save_over.dds" pressed="/EsoUI/Art/Buttons/edit_save_down.dds" /> - </Button> - <Button name="$(parent)Move" clickSound="Click" relativeTo="$(parent)"> - <Anchor point="TOPRIGHT" relativeTo="$(parent)Refresh" relativePoint="TOPRIGHT" offsetX="-32" /> - <Dimensions x="22" y="22" /> - <Textures name="$(parent)Textures" normal="/EsoUI/Art/Buttons/edit_up.dds" mouseOver="/EsoUI/Art/Buttons/edit_over.dds" pressed="/EsoUI/Art/Buttons/edit_down.dds" /> - </Button> - </Controls> - </TopLevelControl> - - <!-- Inspiration: ZO_Options_Checkbox --> - <Control name="CBs_Settings_ListRow_Checkbox" mouseEnabled="true" virtual="true"> - <Dimensions x="510" y="26" /> - <Controls> - <Button name="$(parent)Checkbox" inherits="ZO_CheckButton_Text" horizontalAlignment="LEFT" font="ZoFontWinH4" modifyTextType="UPPERCASE"> - <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="425" /> - <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" relativePoint="BOTTOMRIGHT" /> - </Button> - </Controls> - </Control> - - <Control name="CBs_Settings_ListRow_Category_Title" mouseEnabled="true" virtual="true"> - <Dimensions x="510" y="26" /> - <Controls> - <Texture name="$(parent)Icon" relativeTo="$(parent)"> - <Dimensions x="26" y="26" /> - <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" /> - <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="26" offsetY="26" /> - </Texture> - <Label name="$(parent)Name" font="ZoFontWinH4" modifyTextType="NONE"> - <Anchor point="TOPLEFT" offsetX="26" /> - <OnLinkClicked> - </OnLinkClicked> - </Label> - </Controls> - </Control> - - <!-- Inspiration: ZO_Options_Checkbox --> - <Control name="CBs_Settings_ListRow_Category_Checkbox" mouseEnabled="true" virtual="true"> - <Dimensions x="510" y="26" /> - <Controls> - <Texture name="$(parent)Icon" relativeTo="$(parent)"> - <Dimensions x="26" y="26" /> - <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" /> - <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="26" offsetY="26" /> - </Texture> - <Button name="$(parent)Button" relativeTo="$(parent)"> - <Dimensions x="26" y="26" /> - <MouseButton button="1" enabled="true" /> - <MouseButton button="2" enabled="true" /> - <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPRIGHT" offsetX="-26" /> - <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" relativePoint="BOTTOMRIGHT" /> - <Textures name="$(parent)Textures" normal="/EsoUI/Art/Chatwindow/chat_options_up.dds" pressed="/EsoUI/Art/Chatwindow/chat_options_down.dds" mouseOver="/EsoUI/Art/Chatwindow/chat_options_over.dds" /> - </Button> - <Button name="$(parent)Checkbox" inherits="ZO_CheckButton_Text" horizontalAlignment="LEFT" font="ZoFontWinH4" modifyTextType="UPPERCASE"> - <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="425" /> - <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" relativePoint="BOTTOMRIGHT" offsetX="-26" /> - </Button> - </Controls> - </Control> - - <!-- Inspiration: ZO_ScrollableComboBox --> - <Control name="CBs_Settings_ListRow_Dropdown" mouseEnabled="true" virtual="true"> - <Dimensions x="510" y="26" /> - <OnMouseEnter> - ZO_Options_OnMouseEnter(self) - </OnMouseEnter> - <OnMouseExit> - ZO_Options_OnMouseExit(self) - </OnMouseExit> - - <Controls> - <Control name="$(parent)Dropdown" inherits="ZO_ComboBox"> - <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="293" /> - <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" relativePoint="BOTTOMRIGHT" /> - <OnMouseEnter> - ZO_Options_OnMouseEnter(self:GetParent()) - </OnMouseEnter> - <OnMouseExit> - ZO_Options_OnMouseExit(self:GetParent()) - </OnMouseExit> - </Control> - - <Label name="$(parent)Name" font="ZoFontWinH4" wrapMode="ELLIPSIS"> - <Anchor point="LEFT" /> - <Anchor point="RIGHT" relativeTo="$(parent)Dropdown" relativePoint="LEFT" /> - </Label> - </Controls> - </Control> - - <!-- Inspiration: ZO_Options_Slider --> - <Control name="CBs_Settings_ListRow_Slider" mouseEnabled="true" virtual="true"> - <Dimensions x="510" y="26" /> - <OnMouseEnter> - ZO_Options_OnMouseEnter(self) - </OnMouseEnter> - <OnMouseExit> - ZO_Options_OnMouseExit(self) - </OnMouseExit> - <OnShow> - ZO_Options_OnShow(self) - </OnShow> - - <Controls> - <Slider name="$(parent)Slider" inherits="ZO_Slider"> - <Dimensions x="150" y="16" /> - <Anchor point="RIGHT" offsetX="-40" /> - <OnMouseEnter> - ZO_Options_OnMouseEnter(self:GetParent()) - </OnMouseEnter> - <OnMouseExit> - ZO_Options_OnMouseExit(self:GetParent()) - </OnMouseExit> - </Slider> - - <Label name="$(parent)Name" font="ZoFontWinH4" wrapMode="ELLIPSIS" horizontalAlignment="LEFT" verticalAlignment="CENTER"> - <Dimensions y="26" /> - <Anchor point="LEFT" /> - <Anchor point="RIGHT" relativeTo="$(parent)Slider" relativePoint="LEFT" /> - </Label> - - <Label name="$(parent)ValueLabel" font="ZoFontWinH4" wrapMode="ELLIPSIS" verticalAlignment="CENTER" excludeFromResizeToFitExtents="true"> - <Dimensions x="75" y="26" /> - <Anchor point="LEFT" relativeTo="$(parent)Slider" relativePoint="RIGHT" offsetX="10" /> - </Label> - </Controls> - </Control> - - <Control name="CBs_Settings_ListRow_Label" mouseEnabled="true" virtual="true"> - <Dimensions x="510" y="26" /> - <OnMouseEnter> - ZO_Options_OnMouseEnter(self) - </OnMouseEnter> - <OnMouseExit> - ZO_Options_OnMouseExit(self) - </OnMouseExit> - - <Controls> - <Label name="$(parent)Name" font="ZoFontWinH4" wrapMode="ELLIPSIS" horizontalAlignment="LEFT" verticalAlignment="CENTER"> - <Dimensions y="26" /> - <Anchor point="LEFT" /> - <Anchor point="RIGHT" relativeTo="$(parent)LowLabel" relativePoint="LEFT" /> - </Label> - </Controls> - </Control> - - <!-- Inspiration: ZO_EditDefaultText --> - <Control name="CBs_Settings_ListRow_EditBox" inherits="CBs_Settings_ListRow_Label" mouseEnabled="true" virtual="true"> - <Dimensions x="510" y="26" /> - <Controls> - <EditBox name="$(parent)EditBox" inherits="ZO_DefaultEditForBackdrop ZO_EditDefaultText"> - <Dimensions x="150" y="26" /> - <Anchor point="RIGHT" offsetX="-40" /> - </EditBox> - </Controls> - </Control> - - <Control name="CBs_Settings_ListRow_Title" mouseEnabled="true" virtual="true"> - <Dimensions x="510" y="38" /> - <Controls> - <Label name="$(parent)Name" font="ZoFontWinH1" modifyTextType="UPPERCASE"> - <Dimensions y="38" /> - <Anchor point="LEFT" /> - </Label> - </Controls> - </Control> - - <!-- Inspiration: ZO_EditDefaultText --> - <Control name="CBs_Settings_ListRow_Button" inherits="CBs_Settings_ListRow_Label" mouseEnabled="true" virtual="true"> - <Dimensions x="510" y="26" /> - <Controls> - <Button name="$(parent)Button" inherits="ZO_DefaultButton" clickSound="Click" relativeTo="$(parent)"> - <Anchor point="RIGHT" offsetX="-40" /> - <Dimensions x="150" y="26" /> - </Button> - </Controls> - </Control> - - <Texture name="CBs_Settings_ListRow_Divider" inherits="ZO_Options_Divider" virtual="true"> - <Dimensions x="512" y="2" /> - </Texture> - </Controls> -</GuiXml> \ No newline at end of file diff --git a/CBs_Settings_Data.lua b/CBs_Settings_Data.lua deleted file mode 100644 index 20154e0..0000000 --- a/CBs_Settings_Data.lua +++ /dev/null @@ -1,896 +0,0 @@ ---[[ -Author: Jarth -Filename: CBs_Settings_Data.lua -]] -- -------------------------------------------------------------------------------------------------- --- VARIABLES -- -------------------------------------------------------------------------------------------------- -local base = CollectionBars -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 - 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 = "" - local icon - - if category.HasChildren then - toolTipText = string.format("Click to toggle subcategories for\n%s", category.Name) - icon = base.ToggleButtonIcon[base.Global.ShowChildren[category.Name] == base.ToggleButtonState.OPEN] - 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) - icon = category.Icon - end - - local data = { - cId = category.Id, - icon = 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 - }) -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 -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() - 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, {}) -end diff --git a/CBs_Settings_List.lua b/CBs_Settings_List.lua deleted file mode 100644 index be68857..0000000 --- a/CBs_Settings_List.lua +++ /dev/null @@ -1,551 +0,0 @@ ---[[ -Author: Jarth -Filename: CBs_Settings_List.lua -]] -- -------------------------------------------------------------------------------------------------- --- VARIABLES -- -------------------------------------------------------------------------------------------------- -local base = CollectionBars -local texts = base.Texts - -------------------------------------------------------------------------------------------------- --- FUNCTIONS -- -------------------------------------------------------------------------------------------------- -CBs_Settings_List = ZO_SortFilterList:Subclass() - -function CBs_Settings_List:New(...) - base:Debug("CBs_Settings_List:New", ...) - - self.list = ZO_SortFilterList.New(self, ...) - self.masterListType = "Collectibles" - return self.list -end - -function CBs_Settings_List:Initialize(category, ...) - base:Debug("CBs_Settings_List:Initialize", ...) - - ZO_SortFilterList.Initialize(self, ...) - self.category = category - self.masterList = {} - - if not (self.category and self.category.Enabled) then - self.masterListType = "Categories" - end - - self:SetAlternateRowBackgrounds(false) - self:AppendDataTypes() -end - -------------------------------------------------------------------------------------------------- --- FUNCTIONS - Append DataTypes -- -------------------------------------------------------------------------------------------------- - -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 -end - -------------------------------------------------------------------------------------------------- --- FUNCTIONS - Append and Setup RowTypes -- -------------------------------------------------------------------------------------------------- - -function CBs_Settings_List:AppendRow_Checkbox(listType, data) - base:Debug("CBs_Settings_List:AppendRow_Checkbox", listType, data) - - data.listType = listType - data.dataTypeId = 10 - table.insert(self.masterList, data) -end - -function CBs_Settings_List:SetupRow_Checkbox(control, data) - base:Debug("CBs_Settings_List:SetupRow_Checkbox", control, data) - - control.data = data - ZO_SortFilterList.SetupRow(self, control, data) - - 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) -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] - data.icon = base.ToggleButtonIcon[base.Global.ShowChildren[data.name] == base.ToggleButtonState.OPEN] - 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) -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 -end - -function CBs_Settings_List:AppendRow_Dropdown(listType, data) - base:Debug("CBs_Settings_List:AppendRow_Dropdown", listType, data) - - data.listType = listType - data.dataTypeId = 20 - table.insert(self.masterList, data) -end - -function CBs_Settings_List:SetupRow_Dropdown(control, data) - base:Debug("CBs_Settings_List:SetupRow_Dropdown", control, data) - - control.data = data - ZO_SortFilterList.SetupRow(self, control, data) - - 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) -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) -end - -function CBs_Settings_List:AppendRow_EditBox(listType, data) - base:Debug("CBs_Settings_List:AppendRow_EditBox", listType, data) - - data.listType = listType - data.dataTypeId = 40 - table.insert(self.masterList, data) -end - -function CBs_Settings_List:SetupRow_EditBox(control, data) - base:Debug("CBs_Settings_List:SetupRow_EditBox", control, data) - - control.data = data - ZO_SortFilterList.SetupRow(self, control, control.data) - - 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) -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) -end - -function CBs_Settings_List:AppendRow_Button(listType, data) - base:Debug("CBs_Settings_List:AppendRow_Button", listType, data) - - data.listType = listType - data.dataTypeId = 60 - table.insert(self.masterList, data) -end - -function CBs_Settings_List:SetupRow_Button(control, data) - base:Debug("CBs_Settings_List:SetupRow_Button", control, data) - - control.data = data - ZO_SortFilterList.SetupRow(self, control, control.data) - - 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) -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) -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 -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[base.IconState.NORMAL]) - - if data.icon[base.IconState.NORMAL] ~= nil and data.icon[base.IconState.OVER] ~= nil then - control:SetHandler("OnMouseEnter", function() - control.icon:SetTexture(data.icon[base.IconState.OVER]) - if funcMouseEnter ~= nil then - funcMouseEnter(control) - end - end) - control:SetHandler("OnMouseExit", function() - control.icon:SetTexture(data.icon[base.IconState.NORMAL]) - 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() - 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 -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] - - 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 diff --git a/Changelog b/Changelog index ecc0238..61c23c4 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,13 @@ ------------------------------------------------------------------------------- Collection bars ------------------------------------------------------------------------------- +Version 1.1.13 (2023-02-12) +- Added confirmation for: + - Remove all character settings + - Reset settings +- Moved files into folders +- Updated APIVersion + Version 1.1.12 (09-04-2022) - Added scenes for assistants: "Ghrasharog, Armory Assistant" and "Giladil the Ragpicker" - Added for both keyboard and gamepad diff --git a/CollectionBars.txt b/CollectionBars.txt index 4a2836e..b1776f9 100644 --- a/CollectionBars.txt +++ b/CollectionBars.txt @@ -5,28 +5,45 @@ ; You can read the full terms at https://account.elderscrollsonline.com/add-on-terms ## Title: Collection Bars -## APIVersion: 101033 -## Version: 1.1.12 +## APIVersion: 101036 +## Version: 1.1.13 ## Author: Jarth ## 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 -CBs_Settings.xml -CBs_Button.xml +# i18n (TODO - Implement?!) + +# constants +values/General.lua + +# logging +logging/Logging.lua + +# core +core/Handlers.lua + +# components - shared +components/shared/MoveFrame.lua +components/shared/Fragment.lua + +# components - ui +components/ui/Button.lua +components/ui/Button.xml +components/ui/Buttons.lua +components/ui/Labels.lua + +# components - menu +components/menu/Settings_Data.lua +components/menu/Settings_List.lua +components/menu/Settings.lua +components/menu/Settings.xml + +# main CollectionBars.xml -CBs_Constants.lua -CBs_Logging.lua -CBs_Helpers.lua -CBs_Button.lua -CBs_Bindings.lua -CBs_MoveFrame.lua -CBs_Fragment.lua -CBs_Buttons.lua -CBs_Settings_Data.lua -CBs_Settings_List.lua -CBs_Settings.lua -CBs_Labels.lua CollectionBars.lua -Bindings.xml \ No newline at end of file + +# bindings +bindings/Bindings.lua +bindings/Bindings.xml \ No newline at end of file diff --git a/bindings/Bindings.lua b/bindings/Bindings.lua new file mode 100644 index 0000000..c7e251d --- /dev/null +++ b/bindings/Bindings.lua @@ -0,0 +1,81 @@ +--[[ +Author: Jarth +Filename: Bindings.lua +]] -- +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local base = CollectionBars +local texts = base.Texts + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +------------------------------------------------------------------------------------------------- +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 +end + +function base:SetBindingText(cid) + base:Debug("SetBindingText", cid) + + if base.AllButtons[cid] then + base.AllButtons[cid]:SetBindingText(base.Saved.Bindings.Show, cid) + end +end + +function base:InitializeBindings() + 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 +end diff --git a/bindings/Bindings.xml b/bindings/Bindings.xml new file mode 100644 index 0000000..a2c161b --- /dev/null +++ b/bindings/Bindings.xml @@ -0,0 +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> + </Layer> +</Bindings> \ No newline at end of file diff --git a/components/menu/Settings.lua b/components/menu/Settings.lua new file mode 100644 index 0000000..4a6b70c --- /dev/null +++ b/components/menu/Settings.lua @@ -0,0 +1,176 @@ +--[[ +Author: Jarth +Filename: Settings.lua +]] -- +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local base = CollectionBars +local texts = base.Texts + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +------------------------------------------------------------------------------------------------- +function base:InitializeSettingsSlash() + base:Debug("InitializeSettingsSlash") + + SLASH_COMMANDS[base.Addon.SettingsSlash] = function() + base:ToggleEnableSettings(base.ShowSettings()) + end +end + +function base:ToggleEnableSettings(forceShow) + 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 + 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 +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) +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 +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 +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 +end + +function base:UpdateSettingsType(show, category) + base:Debug("UpdateSettingsType", show, category) + + if base.Global.Settings.List ~= nil then + base.Global.Settings.List.category = category + end + + if base.Global.SettingsLabel ~= nil then + base.Global.SettingsLabel:SetText(show and category and category.Name or "Global") + end +end diff --git a/components/menu/Settings.xml b/components/menu/Settings.xml new file mode 100644 index 0000000..9d8b004 --- /dev/null +++ b/components/menu/Settings.xml @@ -0,0 +1,244 @@ +<GuiXml> + <Controls> + <TopLevelControl name="CBs_Settings" clampedToScreen="true" movable="true" mouseEnabled="true" virtual="true"> + <Anchor point="CENTER" relativePoint="CENTER"/> + <Dimensions x="544" y="944" /> + <DimensionConstraints minX="544" minY="944" /> + <Controls> + <Backdrop name="$(parent)Bg" integralWrapping="true"> + <Anchor point="TOPLEFT" offsetX="-8" offsetY="-6"/> + <Anchor point="BOTTOMRIGHT" offsetX="4" offsetY="4"/> + + <Edge file="EsoUI/Art/ChatWindow/chat_BG_edge.dds" edgeFileWidth="256" edgeFileHeight="256" edgeSize="32"/> + <Center file="EsoUI/Art/ChatWindow/chat_BG_center.dds" /> + <Insets left="32" top="32" right="-32" bottom="-32" /> + </Backdrop> + <Label name="$(parent)Title" font="ZoFontWinH1" modifyTextType="UPPERCASE"> + <Anchor point="TOPLEFT" offsetX="22" offsetY="22" /> + </Label> + + <Texture name="$(parent)Divider" inherits="ZO_Options_Divider"> + <Anchor point="TOPLEFT" relativeTo="$(parent)Title" relativePoint="BOTTOMLEFT" offsetY="2"/> + </Texture> + + <Label name="$(parent)Label" inherits="ZO_Options_SectionTitleLabel"> + <Anchor point="TOPLEFT" relativeTo="$(parent)Divider" relativePoint="TOPLEFT" offsetY="5"/> + </Label> + + <Button name="$(parent)General" inherits="ZO_DefaultButton" clickSound="Click" relativeTo="$(parent)"> + <Anchor point="TOPLEFT" relativeTo="$(parent)Label" relativePoint="BOTTOMLEFT" offsetY="15"/> + <Dimensions x="122" y="22" /> + </Button> + <Button name="$(parent)Categories" inherits="ZO_DefaultButton" clickSound="Click" relativeTo="$(parent)"> + <Anchor point="TOPLEFT" relativeTo="$(parent)General" relativePoint="TOPRIGHT" /> + <Dimensions x="122" y="22" /> + </Button> + <Button name="$(parent)Collectibles" inherits="ZO_DefaultButton" clickSound="Click" relativeTo="$(parent)"> + <Anchor point="TOPLEFT" relativeTo="$(parent)Categories" relativePoint="TOPRIGHT" /> + <Dimensions x="122" y="22" /> + </Button> + <Button name="$(parent)Category" inherits="ZO_DefaultButton" clickSound="Click" relativeTo="$(parent)"> + <Anchor point="TOPLEFT" relativeTo="$(parent)Collectibles" relativePoint="TOPRIGHT" /> + <Dimensions x="122" y="22" /> + </Button> + <Button name="$(parent)Combined" inherits="ZO_DefaultButton" clickSound="Click" relativeTo="$(parent)"> + <Anchor point="BOTTOMLEFT" relativeTo="$(parent)Category" relativePoint="TOPLEFT" offsetY="-5" /> + <Dimensions x="122" y="22" /> + </Button> + + <Control name="$(parent)List" inherits="ZO_ScrollList"> + <Anchor point="TOPLEFT" relativeTo="$(parent)General" relativePoint="BOTTOMLEFT" offsetY="22"/> + <Anchor point="BOTTOMRIGHT" offsetX="-22" offsetY="-22" /> + </Control> + + <Button name="$(parent)Close" clickSound="Click" relativeTo="$(parent)"> + <Anchor point="TOPRIGHT" relativeTo="$(parent)" relativePoint="TOPRIGHT" offsetX="-10" offsetY="10" /> + <Dimensions x="22" y="22" /> + <Textures name="$(parent)Textures" normal="/EsoUI/Art/Buttons/decline_up.dds" mouseOver="/EsoUI/Art/Buttons/decline_over.dds" pressed="/EsoUI/Art/Buttons/decline_down.dds" /> + </Button> + <Button name="$(parent)Refresh" clickSound="Click" relativeTo="$(parent)"> + <Anchor point="TOPRIGHT" relativeTo="$(parent)Close" relativePoint="TOPRIGHT" offsetX="-32" /> + <Dimensions x="22" y="22" /> + <Textures name="$(parent)Textures" normal="/EsoUI/Art/Buttons/edit_save_up.dds" mouseOver="/EsoUI/Art/Buttons/edit_save_over.dds" pressed="/EsoUI/Art/Buttons/edit_save_down.dds" /> + </Button> + <Button name="$(parent)Move" clickSound="Click" relativeTo="$(parent)"> + <Anchor point="TOPRIGHT" relativeTo="$(parent)Refresh" relativePoint="TOPRIGHT" offsetX="-32" /> + <Dimensions x="22" y="22" /> + <Textures name="$(parent)Textures" normal="/EsoUI/Art/Buttons/edit_up.dds" mouseOver="/EsoUI/Art/Buttons/edit_over.dds" pressed="/EsoUI/Art/Buttons/edit_down.dds" /> + </Button> + </Controls> + </TopLevelControl> + + <!-- Inspiration: ZO_Options_Checkbox --> + <Control name="CBs_Settings_ListRow_Checkbox" mouseEnabled="true" virtual="true"> + <Dimensions x="510" y="26" /> + <Controls> + <Button name="$(parent)Checkbox" inherits="ZO_CheckButton_Text" horizontalAlignment="LEFT" font="ZoFontWinH4" modifyTextType="UPPERCASE"> + <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="425" /> + <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" relativePoint="BOTTOMRIGHT" /> + </Button> + </Controls> + </Control> + + <Control name="CBs_Settings_ListRow_Category_Title" mouseEnabled="true" virtual="true"> + <Dimensions x="510" y="26" /> + <Controls> + <Texture name="$(parent)Icon" relativeTo="$(parent)"> + <Dimensions x="26" y="26" /> + <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" /> + <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="26" offsetY="26" /> + </Texture> + <Label name="$(parent)Name" font="ZoFontWinH4" modifyTextType="NONE"> + <Anchor point="TOPLEFT" offsetX="26" /> + <OnLinkClicked> + </OnLinkClicked> + </Label> + </Controls> + </Control> + + <!-- Inspiration: ZO_Options_Checkbox --> + <Control name="CBs_Settings_ListRow_Category_Checkbox" mouseEnabled="true" virtual="true"> + <Dimensions x="510" y="26" /> + <Controls> + <Texture name="$(parent)Icon" relativeTo="$(parent)"> + <Dimensions x="26" y="26" /> + <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" /> + <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="26" offsetY="26" /> + </Texture> + <Button name="$(parent)Button" relativeTo="$(parent)"> + <Dimensions x="26" y="26" /> + <MouseButton button="1" enabled="true" /> + <MouseButton button="2" enabled="true" /> + <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPRIGHT" offsetX="-26" /> + <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" relativePoint="BOTTOMRIGHT" /> + <Textures name="$(parent)Textures" normal="/EsoUI/Art/Chatwindow/chat_options_up.dds" pressed="/EsoUI/Art/Chatwindow/chat_options_down.dds" mouseOver="/EsoUI/Art/Chatwindow/chat_options_over.dds" /> + </Button> + <Button name="$(parent)Checkbox" inherits="ZO_CheckButton_Text" horizontalAlignment="LEFT" font="ZoFontWinH4" modifyTextType="UPPERCASE"> + <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="425" /> + <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" relativePoint="BOTTOMRIGHT" offsetX="-26" /> + </Button> + </Controls> + </Control> + + <!-- Inspiration: ZO_ScrollableComboBox --> + <Control name="CBs_Settings_ListRow_Dropdown" mouseEnabled="true" virtual="true"> + <Dimensions x="510" y="26" /> + <OnMouseEnter> + ZO_Options_OnMouseEnter(self) + </OnMouseEnter> + <OnMouseExit> + ZO_Options_OnMouseExit(self) + </OnMouseExit> + + <Controls> + <Control name="$(parent)Dropdown" inherits="ZO_ComboBox"> + <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="293" /> + <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" relativePoint="BOTTOMRIGHT" /> + <OnMouseEnter> + ZO_Options_OnMouseEnter(self:GetParent()) + </OnMouseEnter> + <OnMouseExit> + ZO_Options_OnMouseExit(self:GetParent()) + </OnMouseExit> + </Control> + + <Label name="$(parent)Name" font="ZoFontWinH4" wrapMode="ELLIPSIS"> + <Anchor point="LEFT" /> + <Anchor point="RIGHT" relativeTo="$(parent)Dropdown" relativePoint="LEFT" /> + </Label> + </Controls> + </Control> + + <!-- Inspiration: ZO_Options_Slider --> + <Control name="CBs_Settings_ListRow_Slider" mouseEnabled="true" virtual="true"> + <Dimensions x="510" y="26" /> + <OnMouseEnter> + ZO_Options_OnMouseEnter(self) + </OnMouseEnter> + <OnMouseExit> + ZO_Options_OnMouseExit(self) + </OnMouseExit> + <OnShow> + ZO_Options_OnShow(self) + </OnShow> + + <Controls> + <Slider name="$(parent)Slider" inherits="ZO_Slider"> + <Dimensions x="150" y="16" /> + <Anchor point="RIGHT" offsetX="-40" /> + <OnMouseEnter> + ZO_Options_OnMouseEnter(self:GetParent()) + </OnMouseEnter> + <OnMouseExit> + ZO_Options_OnMouseExit(self:GetParent()) + </OnMouseExit> + </Slider> + + <Label name="$(parent)Name" font="ZoFontWinH4" wrapMode="ELLIPSIS" horizontalAlignment="LEFT" verticalAlignment="CENTER"> + <Dimensions y="26" /> + <Anchor point="LEFT" /> + <Anchor point="RIGHT" relativeTo="$(parent)Slider" relativePoint="LEFT" /> + </Label> + + <Label name="$(parent)ValueLabel" font="ZoFontWinH4" wrapMode="ELLIPSIS" verticalAlignment="CENTER" excludeFromResizeToFitExtents="true"> + <Dimensions x="75" y="26" /> + <Anchor point="LEFT" relativeTo="$(parent)Slider" relativePoint="RIGHT" offsetX="10" /> + </Label> + </Controls> + </Control> + + <Control name="CBs_Settings_ListRow_Label" mouseEnabled="true" virtual="true"> + <Dimensions x="510" y="26" /> + <OnMouseEnter> + ZO_Options_OnMouseEnter(self) + </OnMouseEnter> + <OnMouseExit> + ZO_Options_OnMouseExit(self) + </OnMouseExit> + + <Controls> + <Label name="$(parent)Name" font="ZoFontWinH4" wrapMode="ELLIPSIS" horizontalAlignment="LEFT" verticalAlignment="CENTER"> + <Dimensions y="26" /> + <Anchor point="LEFT" /> + <Anchor point="RIGHT" relativeTo="$(parent)LowLabel" relativePoint="LEFT" /> + </Label> + </Controls> + </Control> + + <!-- Inspiration: ZO_EditDefaultText --> + <Control name="CBs_Settings_ListRow_EditBox" inherits="CBs_Settings_ListRow_Label" mouseEnabled="true" virtual="true"> + <Dimensions x="510" y="26" /> + <Controls> + <EditBox name="$(parent)EditBox" inherits="ZO_DefaultEditForBackdrop ZO_EditDefaultText"> + <Dimensions x="150" y="26" /> + <Anchor point="RIGHT" offsetX="-40" /> + </EditBox> + </Controls> + </Control> + + <Control name="CBs_Settings_ListRow_Title" mouseEnabled="true" virtual="true"> + <Dimensions x="510" y="38" /> + <Controls> + <Label name="$(parent)Name" font="ZoFontWinH1" modifyTextType="UPPERCASE"> + <Dimensions y="38" /> + <Anchor point="LEFT" /> + </Label> + </Controls> + </Control> + + <!-- Inspiration: ZO_EditDefaultText --> + <Control name="CBs_Settings_ListRow_Button" inherits="CBs_Settings_ListRow_Label" mouseEnabled="true" virtual="true"> + <Dimensions x="510" y="26" /> + <Controls> + <Button name="$(parent)Button" inherits="ZO_DefaultButton" clickSound="Click" relativeTo="$(parent)"> + <Anchor point="RIGHT" offsetX="-40" /> + <Dimensions x="150" y="26" /> + </Button> + </Controls> + </Control> + + <Texture name="CBs_Settings_ListRow_Divider" inherits="ZO_Options_Divider" virtual="true"> + <Dimensions x="512" y="2" /> + </Texture> + </Controls> +</GuiXml> \ No newline at end of file diff --git a/components/menu/Settings_Data.lua b/components/menu/Settings_Data.lua new file mode 100644 index 0000000..5f0d047 --- /dev/null +++ b/components/menu/Settings_Data.lua @@ -0,0 +1,943 @@ +--[[ +Author: Jarth +Filename: Settings_Data.lua +]] -- +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local base = CollectionBars +local texts = base.Texts + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +------------------------------------------------------------------------------------------------- + +ESO_Dialogs["CB_CONFIRM_DIALOG"] = +{ + mustChoose = true, + title = { text = "Confirm <<1>>" }, + mainText = { text = "<<1>>" }, + buttons = + { + [1] = + { + text = SI_OPTIONS_RESET, + callback = function(dialog) + local callback = dialog and dialog.data and dialog.data.callback + if callback ~= nil then + callback() + end + end + }, + [2] = + { + text = SI_DIALOG_CANCEL, + }, + } +} + +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, + confirmation = true, + message = "ARE YOU SURE!?", + funcSet = function() + ZO_Dialogs_ShowDialog("CB_CONFIRM_DIALOG", + { + callback = function() + base:RemoveCharacterSettings() + base.Global.Settings.List:RefreshData() + end + }, { + titleParams={"remove all character settings"}, + mainTextParams={"It will remove all character settings, only relying on account settings."} + } + ) + end + }) + self:AppendRow_Button(listType, { + name = "Reset settings", + buttonName = "Reset", + confirmation = true, + message = "ARE YOU SURE!?", + funcSet = function() + ZO_Dialogs_ShowDialog("CB_CONFIRM_DIALOG", + { + callback = function() + base:ResetSavedSettings() + base:SetLogsEnabled() + base:InitializeWithSavedData() + base:RestoreFrames() + base:RestoreCombineLabels() + base.Global.Settings.List:RefreshData() + end + }, { + titleParams={"reset settings"}, + mainTextParams={"It will reset settings back to default."} + } + ) + 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 = "" + local icon + + if category.HasChildren then + toolTipText = string.format("Click to toggle subcategories for\n%s", category.Name) + icon = base.ToggleButtonIcon[base.Global.ShowChildren[category.Name] == base.ToggleButtonState.OPEN] + 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) + icon = category.Icon + end + + local data = { + cId = category.Id, + icon = 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 + }) +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 +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() + 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, {}) +end diff --git a/components/menu/Settings_List.lua b/components/menu/Settings_List.lua new file mode 100644 index 0000000..bb3a880 --- /dev/null +++ b/components/menu/Settings_List.lua @@ -0,0 +1,551 @@ +--[[ +Author: Jarth +Filename: Settings_List.lua +]] -- +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local base = CollectionBars +local texts = base.Texts + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +------------------------------------------------------------------------------------------------- +CBs_Settings_List = ZO_SortFilterList:Subclass() + +function CBs_Settings_List:New(...) + base:Debug("CBs_Settings_List:New", ...) + + self.list = ZO_SortFilterList.New(self, ...) + self.masterListType = "Collectibles" + return self.list +end + +function CBs_Settings_List:Initialize(category, ...) + base:Debug("CBs_Settings_List:Initialize", ...) + + ZO_SortFilterList.Initialize(self, ...) + self.category = category + self.masterList = {} + + if not (self.category and self.category.Enabled) then + self.masterListType = "Categories" + end + + self:SetAlternateRowBackgrounds(false) + self:AppendDataTypes() +end + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS - Append DataTypes -- +------------------------------------------------------------------------------------------------- + +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 +end + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS - Append and Setup RowTypes -- +------------------------------------------------------------------------------------------------- + +function CBs_Settings_List:AppendRow_Checkbox(listType, data) + base:Debug("CBs_Settings_List:AppendRow_Checkbox", listType, data) + + data.listType = listType + data.dataTypeId = 10 + table.insert(self.masterList, data) +end + +function CBs_Settings_List:SetupRow_Checkbox(control, data) + base:Debug("CBs_Settings_List:SetupRow_Checkbox", control, data) + + control.data = data + ZO_SortFilterList.SetupRow(self, control, data) + + 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) +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] + data.icon = base.ToggleButtonIcon[base.Global.ShowChildren[data.name] == base.ToggleButtonState.OPEN] + 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) +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 +end + +function CBs_Settings_List:AppendRow_Dropdown(listType, data) + base:Debug("CBs_Settings_List:AppendRow_Dropdown", listType, data) + + data.listType = listType + data.dataTypeId = 20 + table.insert(self.masterList, data) +end + +function CBs_Settings_List:SetupRow_Dropdown(control, data) + base:Debug("CBs_Settings_List:SetupRow_Dropdown", control, data) + + control.data = data + ZO_SortFilterList.SetupRow(self, control, data) + + 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) +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) +end + +function CBs_Settings_List:AppendRow_EditBox(listType, data) + base:Debug("CBs_Settings_List:AppendRow_EditBox", listType, data) + + data.listType = listType + data.dataTypeId = 40 + table.insert(self.masterList, data) +end + +function CBs_Settings_List:SetupRow_EditBox(control, data) + base:Debug("CBs_Settings_List:SetupRow_EditBox", control, data) + + control.data = data + ZO_SortFilterList.SetupRow(self, control, control.data) + + 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) +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) +end + +function CBs_Settings_List:AppendRow_Button(listType, data) + base:Debug("CBs_Settings_List:AppendRow_Button", listType, data) + + data.listType = listType + data.dataTypeId = 60 + table.insert(self.masterList, data) +end + +function CBs_Settings_List:SetupRow_Button(control, data) + base:Debug("CBs_Settings_List:SetupRow_Button", control, data) + + control.data = data + ZO_SortFilterList.SetupRow(self, control, control.data) + + 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) +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) +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 +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[base.IconState.NORMAL]) + + if data.icon[base.IconState.NORMAL] ~= nil and data.icon[base.IconState.OVER] ~= nil then + control:SetHandler("OnMouseEnter", function() + control.icon:SetTexture(data.icon[base.IconState.OVER]) + if funcMouseEnter ~= nil then + funcMouseEnter(control) + end + end) + control:SetHandler("OnMouseExit", function() + control.icon:SetTexture(data.icon[base.IconState.NORMAL]) + 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() + 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 +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] + + 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 diff --git a/components/shared/Fragment.lua b/components/shared/Fragment.lua new file mode 100644 index 0000000..e614dca --- /dev/null +++ b/components/shared/Fragment.lua @@ -0,0 +1,65 @@ +--[[ +Author: Jarth +Filename: Fragment.lua +]] -- +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local base = CollectionBars +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) +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) +end + +function base:RemoveFragments(category) + base:Debug("RemoveFragments", category) + + if category.Fragment ~= nil then + for _, scene in ipairs(base.Global.Scenes) do + if scene ~= nil and scene.Instance ~= nil then + scene.Instance:RemoveFragment(category.Fragment) + end + end + end +end diff --git a/components/shared/MoveFrame.lua b/components/shared/MoveFrame.lua new file mode 100644 index 0000000..66fd6e9 --- /dev/null +++ b/components/shared/MoveFrame.lua @@ -0,0 +1,134 @@ +--[[ +Author: Jarth +Filename: MoveFrame.lua +]] -- +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local base = CollectionBars +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) +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 +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 +end diff --git a/components/ui/Button.lua b/components/ui/Button.lua new file mode 100644 index 0000000..3f5cc68 --- /dev/null +++ b/components/ui/Button.lua @@ -0,0 +1,235 @@ +--[[ +Author: Jarth +Filename: Button.lua +]] -- +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local base = CollectionBars +local texts = base.Texts + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +------------------------------------------------------------------------------------------------- +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 +end + +function CBs_Button:UpdateAnchor(frame, left, top) + base:Verbose("CBs_Button:UpdateAnchor", frame, left, top) + + self.ctrl:ClearAnchors() + self.ctrl:SetAnchor(TOPLEFT, frame, TOPLEFT, left, top) +end + +function CBs_Button:Setup() + base:Verbose("CBs_Button:Setup") + + self.ctrl:SetHidden(false) + 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) +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) +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 +end + +function CBs_Button:OnClicked() + base:Verbose("CBs_Button:OnClicked") + + if self.usable then + UseCollectible(self.cId) + end +end + +function CBs_Button:UpdateState(forceId, isAttempting, 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) +end + +function CBs_Button:UpdateUsable() + base:Verbose("CBs_Button:UpdateUsable") + + 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) + + self.icon.percentComplete = percentComplete + self.cooldownTime:SetText(cooldown) +end + +function CBs_Button:UpdatePlaySounds(playSounds) + base:Verbose("CBs_Button:UpdatePlaySounds", playSounds) + + self.playSounds = playSounds +end + +function CBs_Button:UpdateCooldown(remaining, duration, cooldown) + base:Verbose("CBs_Button:UpdateCooldown", remaining, duration, cooldown) + + local showCooldown = duration > 0 + + self.cooldown:SetHidden(not showCooldown) + 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) +end + +function CBs_Button:IsHidden() + base:Verbose("CBs_Button:IsHidden") + + local isHidden = self.ctrl:IsHidden() + + return isHidden +end diff --git a/components/ui/Button.xml b/components/ui/Button.xml new file mode 100644 index 0000000..357d472 --- /dev/null +++ b/components/ui/Button.xml @@ -0,0 +1,49 @@ +<GuiXml> + <Controls> + <Control name="CBs_Button" clampedToScreen="true" movable="false" virtual="true" level="4"> + <Controls> + <Button name="$(parent)Button" mouseOverBlendMode="ADD"> + <AnchorFill /> + <MouseButton button="1" enabled="true" /> + <MouseButton button="2" enabled="true" /> + <Textures normal="/EsoUI/Art/ActionBar/abilityFrame64_up.dds" pressed="/EsoUI/Art/ActionBar/abilityFrame64_down.dds" mouseOver="/EsoUI/Art/ActionBar/actionBar_mouseOver.dds" /> + </Button> + + <Texture name="$(parent)BG" level="0" textureFile="/EsoUI/Art/ActionBar/abilityInset.dds"> + <Anchor point="TOPLEFT" relativeTo="$(parent)" /> + <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" /> + </Texture> + <Texture name="$(parent)Icon" level="1"> + <Anchor point="CENTER" relativeTo="$(parent)" /> + </Texture> + <Texture name="$(parent)CooldownIcon" level="1"> + <TextureCoords left="0" right="1" top="0" bottom="0" /> + <Anchor point="TOPLEFT" relativeTo="$(parent)Icon" relativePoint="TOPLEFT" /> + <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)Icon" relativePoint="BOTTOMRIGHT" /> + </Texture> + <Texture name="$(parent)Status" textureFile="/EsoUI/Art/ActionBar/ActionSlot_toggledon.dds" tier="HIGH" hidden="true"> + <Anchor point="TOPLEFT" relativeTo="$(parent)Icon" relativePoint="TOPLEFT" /> + <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)Icon" relativePoint="BOTTOMRIGHT" /> + </Texture> + + <Cooldown name="$(parent)Cooldown" inherits="ZO_DefaultCooldown" tier="HIGH" alpha="0.7"> + <Anchor point="TOPLEFT" relativeTo="$(parent)Icon" relativePoint="TOPLEFT" /> + <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)Icon" relativePoint="BOTTOMRIGHT" /> + </Cooldown> + <Texture name="$(parent)CooldownCompleteAnimation" textureFile="/EsoUI/Art/ActionBar/coolDown_completeEFX.dds" blendMode="ADD" tier="HIGH" hidden="true"> + <Anchor point="TOPLEFT" relativeTo="$(parent)Icon" relativePoint="TOPLEFT" /> + <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)Icon" relativePoint="BOTTOMRIGHT" /> + </Texture> + + <Label name="$(parent)ButtonText" wrapMode="ELLIPSIS" horizontalAlignment="CENTER" tier="HIGH" verticalAlignment="BOTTOM" font="ZoFontGameSmall"> + <Anchor point="BOTTOM" relativeTo="$(parent)Button" relativePoint="BOTTOM" /> + </Label> + + <Label name="$(parent)CooldownTime" font="ZoFontWindowSubtitle" wrapMode="ELLIPSIS" color="INTERFACE_COLOR_TYPE_TEXT_COLORS:INTERFACE_TEXT_COLOR_SELECTED" horizontalAlignment="CENTER" verticalAlignment="CENTER" hidden="true"> + <Anchor point="TOPLEFT" relativeTo="$(parent)Icon" relativePoint="TOPLEFT" /> + <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)Icon" relativePoint="BOTTOMRIGHT" /> + </Label> + </Controls> + </Control> + </Controls> +</GuiXml> \ No newline at end of file diff --git a/components/ui/Buttons.lua b/components/ui/Buttons.lua new file mode 100644 index 0000000..827809b --- /dev/null +++ b/components/ui/Buttons.lua @@ -0,0 +1,206 @@ +--[[ +Author: Jarth +Filename: Buttons.lua +]] -- +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local base = CollectionBars +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 +end + +function base:SetFrameAndCombineSize(category) + base:Debug("SetFrameAndCombineSize", category) + local width, height = base:GetBarWidthHeight(category) + base:SetFrameSizeIfExists(category.Frames.Frame, width, height) + + if category.Saved.Bar.IsCombined and not category.Saved.Bar.HideAll then + base:SetFrameSizeIfExists(base.Global.Combine.Frames.Frame, width, height) + end +end + +function base:GetFrame(name, virtual) + base:Debug("GetFrame", name, virtual) + + local frame = GetControl(name) + + if frame == nil then + frame = base.WM:CreateControlFromVirtual(name, GuiRoot, virtual) + end + + base:Debug("GetFrame:return", frame) + + return frame +end + +function base:GetButtonPosition(category, index) + 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 +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 +end + +function base:UpdateButtonsCooldown(category, remaining, duration, cooldown) + base:Debug("UpdateButtonsCooldown", category, remaining, duration, cooldown) + + for _cId, button in pairs(category.Buttons) do + if button ~= nil and category.Collection[_cId] then + button:UpdateCooldown(remaining, duration, cooldown) + end + end +end + +function base:GetCooldownText(countDown, duration) + base:Debug("GetCooldownText", countDown, duration) + + local 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) + + 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 +end diff --git a/components/ui/Labels.lua b/components/ui/Labels.lua new file mode 100644 index 0000000..916626e --- /dev/null +++ b/components/ui/Labels.lua @@ -0,0 +1,142 @@ +--[[ +Author: Jarth +Filename: Labels.lua +]] -- +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local base = CollectionBars +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) +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 +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 + + if category.Frames.LabelButton ~= nil then + category.Frames.LabelButton: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 +end diff --git a/core/Handlers.lua b/core/Handlers.lua new file mode 100644 index 0000000..80dd080 --- /dev/null +++ b/core/Handlers.lua @@ -0,0 +1,285 @@ +--[[ +Author: Jarth +Filename: Handlers.lua +]] -- +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local base = CollectionBars +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 + + 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 +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 +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 +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 +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 + + return isAllSelected +end + +function base:AutoSelectAll(category, newValue) + base:Debug("AutoSelectAll", category, newValue) + + if newValue then + category.Saved.Selected = {} + end + +end + +function base:SelectAll(category, newValue) + base:Debug("SelectAll", category, newValue) + + for _, collectible in pairs(category.Collection) do + if newValue == true then + category.Saved.Selected[collectible.Id] = newValue + 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) +end + +function base:GetCharactersettings(useAccountSettings) + base:Debug("GetCharactersettings", useAccountSettings) + + local characterSettings = nil + + 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 +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 +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 +end + +function base:RemoveCharacterSettings() + 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 +end + +function base:GetBarWidthHeight(category) + base:Debug("GetBarWidthHeight", category) + + local width, height, count = 0, 0, 0 + + if not category.Saved.Bar.HideAll then + for key, button in pairs(category.Buttons) do + if not button:IsHidden() then + count = count + 1 + end + end + end + + if count > 0 then + category.Bar.Depth, category.Bar.Width = base:GetMaxBarSize(category, "Depth", count), base:GetMaxBarSize(category, "Width", count) + + local barWidth = zo_ceil(count / category.Bar.Depth) + local maxBarWidth = category.Bar.Width + + if maxBarWidth > 0 and maxBarWidth < barWidth then + barWidth = maxBarWidth + end + + local isHorizontal = category.Saved.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 +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 +end + +function base:SetControlText(control, text) + base:Debug("SetControlText", control, text) + + control.SetText(control, text) +end diff --git a/logging/Logging.lua b/logging/Logging.lua new file mode 100644 index 0000000..8b42fa1 --- /dev/null +++ b/logging/Logging.lua @@ -0,0 +1,57 @@ +--[[ +Author: Jarth +Filename: Logging.lua +]] -- +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local base = CollectionBars +local loggers = base.Loggers +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 +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 +end + +function base:LogSetEnabled(logger, doLogging, loggerType) + 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:Debug(...) + if loggers.Debug ~= nil and ... ~= nil then + loggers.Debug:Debug(...) + end +end + +function base:Verbose(...) + if loggers.Verbose ~= nil and ... ~= nil then + loggers.Verbose:Verbose(...) + end +end diff --git a/values/General.lua b/values/General.lua new file mode 100644 index 0000000..528bc85 --- /dev/null +++ b/values/General.lua @@ -0,0 +1,175 @@ +--[[ +Author: Jarth +Filename: General.lua +]] -- +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +CollectionBars = { + WM = GetWindowManager(), + Addon = {Name = "CollectionBars", DisplayName = "Collection Bars", Abbreviation = "CBs", Version = 1.1, MinorVersion = 11, 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"}, + [9] = {Name = "InArmoryKeyboard", Instance = SCENE_MANAGER:GetScene("armoryKeyboard"), Description = "%s at the armory (Keyboard)"}, + [10] = {Name = "InArmoryGamepad", Instance = SCENE_MANAGER:GetScene("armoryRootGamepad"), Description = "%s at the armory (Gamepad)"}, + [11] = {Name = "InDeconstructionKeyboard", Instance = SCENE_MANAGER:GetScene("universalDeconstructionSceneKeyboard"), Description = "%s in deconstruction screen (Keyboard)"}, + [12] = {Name = "InDeconstructionGamepad", Instance = SCENE_MANAGER:GetScene("universalDeconstructionSceneGamepad"), Description = "%s in deconstruction screen (Gamepad)"} + }, + 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 + +base.Texts.FormatAbbreviation = string.format("%s%%s", base.Addon.Abbreviation) +base.Texts.FormatAbbreviationLowDash = string.format("%s_%%s", base.Addon.Abbreviation) +base.Texts.FormatCategoryName = string.format("%s_C%%s", base.Addon.Abbreviation) +base.Texts.FormatBindingName = string.format("SI_BINDING_NAME_%s", base.Texts.FormatAbbreviationLowDash) +base.Texts.CombineFrameName = string.format(base.Texts.FormatAbbreviationLowDash, "CombineFrame") +base.Texts.CombineFrameNameHideAll = string.format("%s%s", base.Texts.CombineFrameName, "HideAll") +base.Texts.AccountKey = string.format("%s_Account", base.Addon.Name) +base.Texts.CharacterKey = string.format("%s_Character", base.Addon.Name) + +base.IconState = {NORMAL = 1, OVER = 2, PRESSED = 3, DISABLED = 4} +base.ToggleButtonState = {OPEN = true, CLOSED = false} +base.ToggleButtonIcon = { + [base.ToggleButtonState.OPEN] = { + [base.IconState.NORMAL] = "EsoUI/Art/Buttons/tree_open_up.dds", + [base.IconState.OVER] = "EsoUI/Art/Buttons/tree_open_over.dds", + [base.IconState.PRESSED] = "EsoUI/Art/Buttons/tree_open_down.dds", + [base.IconState.DISABLED] = "EsoUI/Art/Buttons/tree_open_disabled.dds" + }, + [base.ToggleButtonState.CLOSED] = { + [base.IconState.NORMAL] = "EsoUI/Art/Buttons/tree_closed_up.dds", + [base.IconState.OVER] = "EsoUI/Art/Buttons/tree_closed_over.dds", + [base.IconState.PRESSED] = "EsoUI/Art/Buttons/tree_closed_down.dds", + [base.IconState.DISABLED] = "EsoUI/Art/Buttons/tree_closed_disabled.dds" + } +} + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +------------------------------------------------------------------------------------------------- + +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 +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 +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 +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} + } +end