Skip to content

Commit

Permalink
Merge pull request #2 from Baertram/AF_Scalebreaker_1_5_1_8
Browse files Browse the repository at this point in the history
AF v1.5.2.1
  • Loading branch information
Baertram authored Aug 16, 2019
2 parents cc467a8 + cdf68f7 commit ad93355
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 112 deletions.
112 changes: 77 additions & 35 deletions AF_FilterBar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ local AF = AdvancedFilters
AF.AF_FilterBar = ZO_Object:Subclass()
local AF_FilterBar = AF.AF_FilterBar
local BuildDropdownCallbacks = AF.util.BuildDropdownCallbacks
local showChatDebug = AF.showChatDebug
local util = AF.util

function AF_FilterBar:New(inventoryName, tradeSkillname, groupName, subfilterNames, excludeTheseButtons)
local obj = ZO_Object.New(self)
Expand Down Expand Up @@ -35,7 +37,12 @@ function AF_FilterBar:Initialize(inventoryName, tradeSkillname, groupName, subfi

self.label = self.control:GetNamedChild("Label")
self.label:SetModifyTextType(MODIFY_TEXT_TYPE_UPPERCASE)
local allText = AF.strings[AF_CONST_ALL] or AF_CONST_ALL
local allText = AF_CONST_ALL
if AF.strings and AF.strings[AF_CONST_ALL] then
allText = AF.strings[AF_CONST_ALL]
else
showChatDebug("AF_FilterBar:Initialize", "AF.strings missing for: " ..tostring(AF_CONST_ALL) .. ", language: " .. tostring(AF.clientLang) .. ", inventoryName: " .. tostring(inventoryName) .. ", tradeSkillname: " ..tostring(tradeSkillname) .. ",groupName: " ..tostring(groupName))
end
self.label:SetText(allText)

self.divider = self.control:GetNamedChild("Divider")
Expand All @@ -57,39 +64,47 @@ function AF_FilterBar:Initialize(inventoryName, tradeSkillname, groupName, subfi
comboBox:ShowDropdownInternal()
end
elseif mouseButton == MOUSE_BUTTON_INDEX_RIGHT and upInside then
--Get the current LibFilters filterPanelId
local filterPanelIdActive = util.GetCurrentFilterTypeForInventory(AF.currentInventoryType)
--Add the currently active filtername to the dropdown "Invert" entry
local button = self:GetCurrentButton()
if not button then return end
local currentActiveFilterName = button.previousDropdownSelection.name or ""
--d("[AF]AF_FilterBar:Initialize - DropdownOnMouseUpHandler, 2: " .. tostring(button.name) .. ", filterPanelId: " ..tostring(filterPanelIdActive))
local previousDropdownSelection = (button.previousDropdownSelection ~= nil and button.previousDropdownSelection[filterPanelIdActive]) or nil
local currentActiveFilterName = previousDropdownSelection.name or ""
local invertFilterText = string.format(AF.strings.InvertDropdownFilter, currentActiveFilterName)
local entries = {
[1] = {
name = AF.strings.ResetToAll,
callback = function()
comboBox:SelectFirstItem()
button.previousDropdownSelection = comboBox.m_sortedItems[1]
filterPanelIdActive = util.GetCurrentFilterTypeForInventory(AF.currentInventoryType)
button.previousDropdownSelection[filterPanelIdActive] = comboBox.m_sortedItems[1]

PlaySound(SOUNDS.MENU_BAR_CLICK)

local filterType = AF.util.GetCurrentFilterTypeForInventory(self.inventoryType)
AF.util.LibFilters:RequestUpdate(filterType)
local filterType = util.GetCurrentFilterTypeForInventory(self.inventoryType)
util.LibFilters:RequestUpdate(filterType)
end,
},

[2] = {
name = invertFilterText,
callback = function()
local filterType = AF.util.GetCurrentFilterTypeForInventory(self.inventoryType)
local lastSelectedItem = button.previousDropdownSelection
filterPanelIdActive = util.GetCurrentFilterTypeForInventory(AF.currentInventoryType)
local filterType = util.GetCurrentFilterTypeForInventory(self.inventoryType)
local lastSelectedItem = (button.previousDropdownSelection ~= nil and button.previousDropdownSelection[filterPanelIdActive]) or nil
local currentlySelectedDropdownItem = comboBox.m_selectedItemData
if not currentlySelectedDropdownItem then return end
local originalCallback = AF.util.LibFilters:GetFilterCallback("AF_DropdownFilter", filterType)
local originalCallback = util.LibFilters:GetFilterCallback("AF_DropdownFilter", filterType)
local filterCallback = function(slot, slotIndex)
return not originalCallback(slot, slotIndex)
end
--Build the now new selected item of the dropdown with the inverted data
local newSelectedItem = {}
newSelectedItem.callback = filterCallback
newSelectedItem.filterCallback = filterCallback -- For AF.util.ApplyFilter
newSelectedItem.filterEndCallback = currentlySelectedDropdownItem.filterEndCallback -- For AF.util.ApplyFilter
--Remove all old <> (unequal) signs
currentlySelectedDropdownItem.name = string.gsub(currentlySelectedDropdownItem.name, "", "")
if lastSelectedItem and lastSelectedItem.isInverted then
Expand All @@ -99,14 +114,17 @@ function AF_FilterBar:Initialize(inventoryName, tradeSkillname, groupName, subfi
newSelectedItem.isInverted = true
newSelectedItem.name = "" .. currentlySelectedDropdownItem.name
end
button.previousDropdownSelection = newSelectedItem
button.previousDropdownSelection[filterPanelIdActive] = newSelectedItem
comboBox.m_selectedItemText:SetText(newSelectedItem.name)

PlaySound(SOUNDS.MENU_BAR_CLICK)

AF.util.LibFilters:UnregisterFilter("AF_DropdownFilter", filterType)
AF.util.LibFilters:RegisterFilter("AF_DropdownFilter", filterType, filterCallback)
AF.util.LibFilters:RequestUpdate(filterType)
--[[
util.LibFilters:UnregisterFilter("AF_DropdownFilter", filterType)
util.LibFilters:RegisterFilter("AF_DropdownFilter", filterType, filterCallback)
util.LibFilters:RequestUpdate(filterType)
]]
util.ApplyFilter(newSelectedItem, "AF_DropdownFilter", true, filterType)
end,
},
}
Expand Down Expand Up @@ -144,8 +162,10 @@ function AF_FilterBar:Initialize(inventoryName, tradeSkillname, groupName, subfi

local function OnSelect()
ZO_ComboBox_Base_ItemSelectedClickHelper(self, item)

button.previousDropdownSelection = item
--Get the current LibFilters filterPanelId
local filterPanelIdActive = util.GetCurrentFilterTypeForInventory(AF.currentInventoryType)
button.previousDropdownSelection = button.previousDropdownSelection or {}
button.previousDropdownSelection[filterPanelIdActive] = item

PlaySound(SOUNDS.MENU_BAR_CLICK)
end
Expand All @@ -162,16 +182,22 @@ function AF_FilterBar:Initialize(inventoryName, tradeSkillname, groupName, subfi
local entry = {
label = AF.strings[callbackEntry.name],
callback = function()
AF.util.ApplyFilter(callbackEntry, "AF_DropdownFilter", true)
util.ApplyFilter(callbackEntry, "AF_DropdownFilter", true)
button.forceNextDropdownRefresh = true
self.m_selectedItemText:SetText(AF.strings[callbackEntry.name])
self.m_selectedItemData = self:CreateItemEntry(AF.strings[callbackEntry.name],
function(comboBox, itemName, item, selectionChanged)
AF.util.ApplyFilter(callbackEntry,
util.ApplyFilter(callbackEntry,
"AF_DropdownFilter",
selectionChanged or button.forceNextDropdownRefresh)
end)
button.previousDropdownSelection = self.m_selectedItemData
if callbackEntry.filterEndCallback then
self.m_selectedItemData.filterEndCallback = callbackEntry.filterEndCallback
end
--Get the current LibFilters filterPanelId
local filterPanelIdActive = util.GetCurrentFilterTypeForInventory(AF.currentInventoryType)
button.previousDropdownSelection = button.previousDropdownSelection or {}
button.previousDropdownSelection[filterPanelIdActive] = self.m_selectedItemData

PlaySound(SOUNDS.MENU_BAR_CLICK)

Expand Down Expand Up @@ -276,12 +302,13 @@ function AF_FilterBar:AddSubfilter(groupName, subfilterName)
end

function AF_FilterBar:ActivateButton(newButton)
local function PopulateDropdown()
--------------------------------------------------------------------------------------------------------------------
local function PopulateDropdown(p_newButton)
local comboBox = self.dropdown.m_comboBox
newButton.dropdownCallbacks = BuildDropdownCallbacks(newButton.groupName, newButton.name)
p_newButton.dropdownCallbacks = BuildDropdownCallbacks(p_newButton.groupName, p_newButton.name)

comboBox.submenuCandidates = {}
for _, v in ipairs(newButton.dropdownCallbacks) do
for _, v in ipairs(p_newButton.dropdownCallbacks) do
if v.submenuName then
table.insert(comboBox.submenuCandidates, v)
else
Expand All @@ -307,18 +334,28 @@ function AF_FilterBar:ActivateButton(newButton)
end
local itemEntry = ZO_ComboBox:CreateItemEntry(itemEntryName,
function(comboBox, itemName, item, selectionChanged)
AF.util.ApplyFilter(v, "AF_DropdownFilter", selectionChanged or newButton.forceNextDropdownRefresh)
util.ApplyFilter(v, "AF_DropdownFilter", selectionChanged or p_newButton.forceNextDropdownRefresh)
end)
if v.filterEndCallback then
itemEntry.filterEndCallback = v.filterEndCallback
end
comboBox:AddItem(itemEntry)
end
end
end
comboBox:SetSelectedItemFont("ZoFontGameSmall")
comboBox:SetDropdownFont("ZoFontGameSmall")
end

--------------------------------------------------------------------------------------------------------------------
local name = newButton.name
self.label:SetText(AF.strings[name])
local nameText
if AF.strings and AF.strings[name] then
nameText = AF.strings[name]
else
showChatDebug("AF_FilterBar:ActivateButton", "AF.strings missing for name: " ..tostring(name) .. ", language: " .. tostring(AF.clientLang))
nameText = "ERROR: n/a"
end
self.label:SetText(nameText)
local settings = AF.settings
self.label:SetHidden(settings.hideSubFilterLabel)

Expand All @@ -333,34 +370,39 @@ function AF_FilterBar:ActivateButton(newButton)
newButton:SetEnabled(false)

--refresh filter
AF.util.ApplyFilter(newButton, "AF_ButtonFilter", true)
util.ApplyFilter(newButton, "AF_ButtonFilter", true)

--set new active button reference
self.activeButton = newButton

--clear old dropdown data
self.dropdown.m_comboBox.m_sortedItems = {}
--Get the current LibFilters filterPanelId
local filterPanelIdActive = util.GetCurrentFilterTypeForInventory(AF.currentInventoryType)
--d("[AF]AF_FilterBar:ActivateButton: " .. tostring(newButton.name) .. ", filterPanelId: " ..tostring(filterPanelIdActive))
--add new dropdown data
PopulateDropdown()
--select the first item if there is no previos selection
if not newButton.previousDropdownSelection then
PopulateDropdown(newButton)
--select the first item if there is no previous selection or the setting to remember the last selection is disabled
if not AF.settings.rememberFilterDropdownsLastSelection or not newButton.previousDropdownSelection or not newButton.previousDropdownSelection[filterPanelIdActive] then
--Select the first entry
self.dropdown.m_comboBox:SelectFirstItem()
newButton.previousDropdownSelection = self.dropdown.m_comboBox.m_sortedItems[1]
newButton.previousDropdownSelection = newButton.previousDropdownSelection or {}
newButton.previousDropdownSelection[filterPanelIdActive] = self.dropdown.m_comboBox.m_sortedItems[1]
else
local previousDropdownSelection = newButton.previousDropdownSelection
--restore previous dropdown selection
--restore previous dropdown selection if the settings is enabled for this
local previousDropdownSelection = newButton.previousDropdownSelection[filterPanelIdActive]
--Check if the previous selection was a right mouse context menu "invert" option
if previousDropdownSelection.isInverted then
--Reapply the filter of the inversion
local filterType = AF.util.GetCurrentFilterTypeForInventory(self.inventoryType)
--local originalCallback = AF.util.LibFilters:GetFilterCallback("AF_DropdownFilter", filterType)
local filterType = util.GetCurrentFilterTypeForInventory(self.inventoryType)
--local originalCallback = util.LibFilters:GetFilterCallback("AF_DropdownFilter", filterType)
local originalCallback = previousDropdownSelection.callback
local filterCallback = function(slot, slotIndex)
return originalCallback(slot, slotIndex)
end
AF.util.LibFilters:UnregisterFilter("AF_DropdownFilter", filterType)
AF.util.LibFilters:RegisterFilter("AF_DropdownFilter", filterType, filterCallback)
AF.util.LibFilters:RequestUpdate(filterType)
util.LibFilters:UnregisterFilter("AF_DropdownFilter", filterType)
util.LibFilters:RegisterFilter("AF_DropdownFilter", filterType, filterCallback)
util.LibFilters:RequestUpdate(filterType)
--Select the dropdown entry but do not call the callback function as the filter was updated above already
self.dropdown.m_comboBox:SelectItem(previousDropdownSelection, true)
else
Expand Down
6 changes: 3 additions & 3 deletions AdvancedFilters.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## Title: Advanced Filters
## Author: Randactyl
## Version: 1.5.1.8
## AddOnVersion: 1518
## Version: 1.5.2.1
## AddOnVersion: 1521
## APIVersion: 100028 100029
## DependsOn: LibFilters-3.0 LibCustomMenu libCommonInventoryFilters LibMotifCategories
## OptionalDependsOn: LibAddonMenu-2.0 CraftBagExtended
## OptionalDependsOn: LibAddonMenu-2.0 CraftBagExtended Multicraft
## SavedVariables: AdvancedFilters_Settings

constants.lua
Expand Down
29 changes: 28 additions & 1 deletion constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,31 @@ local AF = AdvancedFilters
--Addon base variables
AF.name = "AdvancedFilters"
AF.author = "ingeniousclown, Randactyl, Baertram"
AF.version = "1.5.1.8"
AF.version = "1.5.2.1"
AF.savedVarsVersion = 1.511
AF.website = "http://www.esoui.com/downloads/info245-AdvancedFilters.html"
AF.feedback = "https://www.esoui.com/portal.php?id=136&a=faq"
AF.donation = "https://www.esoui.com/portal.php?id=136&a=faq&faqid=131"
AF.currentInventoryType = INVENTORY_BACKPACK

AF.clientLang = GetCVar("language.2")

--SavedVariables default settings
AF.defaultSettings = {
doDebugOutput = false,
hideItemCount = false,
itemCountLabelColor = {
["r"] = 1,
["g"] = 1,
["b"] = 1,
["a"] = 1,
},
hideSubFilterLabel = false,
grayOutSubFiltersWithNoItems = true,
showIconsInFilterDropdowns = true,
rememberFilterDropdownsLastSelection = true,
}

--Libraries
AF.util = AF.util or {}
local util = AF.util
Expand All @@ -33,6 +53,13 @@ if not util.LibMotifCategories then d("[AdvancedFilters]ERROR: Needed library Li
-- Libraries - END
---------------------------------------------------------------------------------------------------------------------------

--Other addons
AF.otherAddons = {}

--Error strings for thrown addon errors and chat output
AF.errorStrings = {}
AF.errorStrings["MultiCraft"] = "PLEASE DISABLE THE ADDON \'MultiCraft\'! AdvancedFilters cannot work if this addon is enabled. \'Multicraft\' has been replaced by ZOs own multi crafting UI so you do not need it anymore!"

--Scene names for the SCENE_MANAGER.currentScene.name check
local scenesForChecks = {
storeVendor = "store",
Expand Down
4 changes: 3 additions & 1 deletion data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,9 @@ AF.subfilterCallbacks = {
dropdownCallbacks = {},
},
Container = {
filterCallback = GetFilterCallbackForItemTypeAndSpecializedItemtype({ITEMTYPE_CONTAINER, ITEMTYPE_CONTAINER_CURRENCY, ITEMFILTERTYPE_PROVISIONING}, {SPECIALIZED_ITEMTYPE_CONTAINER}),
filterCallback = GetFilterCallbackForItemTypeAndSpecializedItemtype(
{ITEMTYPE_CONTAINER, ITEMTYPE_CONTAINER_CURRENCY, ITEMFILTERTYPE_PROVISIONING},
{SPECIALIZED_ITEMTYPE_CONTAINER, SPECIALIZED_ITEMTYPE_CONTAINER_EVENT, SPECIALIZED_ITEMTYPE_CONTAINER_STYLE_PAGE}),
dropdownCallbacks = {},
},
Repair = {
Expand Down
Loading

0 comments on commit ad93355

Please sign in to comment.