From 8642323e04c0841cf59b10d1ef03e5a96a8c81d0 Mon Sep 17 00:00:00 2001 From: Antonio Lobato Date: Sun, 18 Feb 2024 14:09:48 -0800 Subject: [PATCH] Added ConsolePort support to Retail and Classic. Added various events for better hooking of BetterBags events. --- BetterBags.toc | 4 +- BetterBags_Vanilla.toc | 5 ++- BetterBags_Wrath.toc | 5 ++- annotations.lua | 9 +++++ config/classic/config.lua | 51 ++++++++++++++++++++++++++ config/config.lua | 16 +++++++- core/init.lua | 5 +++ frames/classic/context.lua | 7 +++- frames/context.lua | 8 +++- frames/grid.lua | 2 + integrations/consoleport.lua | 71 ++++++++++++++++++++++++++++++++++++ 11 files changed, 176 insertions(+), 7 deletions(-) create mode 100644 config/classic/config.lua create mode 100644 integrations/consoleport.lua diff --git a/BetterBags.toc b/BetterBags.toc index ac5e9283..7c5ea55a 100644 --- a/BetterBags.toc +++ b/BetterBags.toc @@ -9,7 +9,7 @@ ## X-License: MIT ## X-Curse-Project-ID: 942432 ## X-Wago-ID: aNDmy96o -## OptionalDeps: LibStub, Masque, CallbackHandler-1.0, Ace3, LibSharedMedia-3.0, _DebugLog +## OptionalDeps: LibStub, Masque, CallbackHandler-1.0, Ace3, LibSharedMedia-3.0, _DebugLog, ConsolePort libs\LibStub\LibStub.lua libs\CallbackHandler-1.0\CallbackHandler-1.0.xml @@ -77,4 +77,6 @@ config\bags.lua config\itemlist.lua config\customcat.lua +integrations\consoleport.lua + core\init.lua \ No newline at end of file diff --git a/BetterBags_Vanilla.toc b/BetterBags_Vanilla.toc index 00ccc9ec..917f5bbe 100644 --- a/BetterBags_Vanilla.toc +++ b/BetterBags_Vanilla.toc @@ -9,7 +9,7 @@ ## X-License: MIT ## X-Curse-Project-ID: 942432 ## X-Wago-ID: aNDmy96o -## OptionalDeps: LibStub, Masque, CallbackHandler-1.0, Ace3, LibSharedMedia-3.0, _DebugLog +## OptionalDeps: LibStub, Masque, CallbackHandler-1.0, Ace3, LibSharedMedia-3.0, _DebugLog, ConsolePort libs\LibStub\LibStub.lua libs\CallbackHandler-1.0\CallbackHandler-1.0.xml @@ -79,10 +79,13 @@ frames\bag.lua frames\classic\bag.lua config\config.lua +config\classic\config.lua config\help.lua config\classic\bags.lua config\itemlist.lua config\customcat.lua +integrations\consoleport.lua + core\init.lua core\classic\init.lua \ No newline at end of file diff --git a/BetterBags_Wrath.toc b/BetterBags_Wrath.toc index cd202f71..c3b7b26b 100644 --- a/BetterBags_Wrath.toc +++ b/BetterBags_Wrath.toc @@ -9,7 +9,7 @@ ## X-License: MIT ## X-Curse-Project-ID: 942432 ## X-Wago-ID: aNDmy96o -## OptionalDeps: LibStub, Masque, CallbackHandler-1.0, Ace3, LibSharedMedia-3.0, _DebugLog +## OptionalDeps: LibStub, Masque, CallbackHandler-1.0, Ace3, LibSharedMedia-3.0, _DebugLog, ConsolePort libs\LibStub\LibStub.lua libs\CallbackHandler-1.0\CallbackHandler-1.0.xml @@ -79,10 +79,13 @@ frames\bag.lua frames\classic\bag.lua config\config.lua +config\classic\config.lua config\help.lua config\classic\bags.lua config\itemlist.lua config\customcat.lua +integrations\consoleport.lua + core\init.lua core\classic\init.lua \ No newline at end of file diff --git a/annotations.lua b/annotations.lua index 339629e7..009dac9c 100644 --- a/annotations.lua +++ b/annotations.lua @@ -258,3 +258,12 @@ function AceItemList:SetList(values) end ---@param id number ---@param button Button function ContainerFrame_UpdateCooldown(id, button) end + +---- +-- ConsolePort annotations +---- + +ConsolePort = {} + +---@param frame Frame +function ConsolePort:AddInterfaceCursorFrame(frame) end \ No newline at end of file diff --git a/config/classic/config.lua b/config/classic/config.lua new file mode 100644 index 00000000..8cd48b66 --- /dev/null +++ b/config/classic/config.lua @@ -0,0 +1,51 @@ +---@diagnostic disable: duplicate-set-field,duplicate-doc-field,duplicate-doc-alias +local addonName = ... ---@type string + +---@class BetterBags: AceAddon +local addon = LibStub('AceAddon-3.0'):GetAddon(addonName) + +---@class Localization: AceModule +local L = addon:GetModule('Localization') + +---@class Database: AceModule +local DB = addon:GetModule('Database') + +---@class Constants: AceModule +local const = addon:GetModule('Constants') + +---@class Config: AceModule +local config = addon:GetModule('Config') + +---@class Events: AceModule +local events = addon:GetModule('Events') + + +local GUI = LibStub('AceGUI-3.0') + +---@return AceConfig.OptionsTable +function config:GetGeneralOptions() + ---@type AceConfig.OptionsTable + local options = { + type = "group", + name = L:G("General"), + order = 0, + args = { + newItemTime = { + type = "range", + order = 2, + name = L:G("New Item Duration"), + desc = L:G("The time, in minutes, to consider an item a new item."), + min = 0, + max = 240, + step = 5, + get = function() + return DB:GetData().profile.newItemTime / 60 + end, + set = function(_, value) + DB:GetData().profile.newItemTime = value * 60 + end, + } + } + } + return options +end diff --git a/config/config.lua b/config/config.lua index 63433069..616d5f4b 100644 --- a/config/config.lua +++ b/config/config.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: duplicate-set-field,duplicate-doc-field,duplicate-doc-alias local addonName = ... ---@type string ---@class BetterBags: AceAddon @@ -18,6 +19,8 @@ local const = addon:GetModule('Constants') ---@field group string ---@class Config: AceModule +---@field frame Frame +---@field category string ---@field helpText HelpText[] local config = addon:NewModule('Config') @@ -115,18 +118,27 @@ function config:GetOptions() return options end +function config:Open() + LibStub("AceConfigDialog-3.0"):Open(addonName) + events:SendMessage('config/Opened') +end + function config:OnEnable() self.helpText = {} self:CreateAllHelp() GUI:RegisterWidgetType("ItemList", config.CreateItemListWidget, 1) LibStub('AceConfig-3.0'):RegisterOptionsTable(addonName, function() return self:GetOptions() end) - LibStub("AceConfigDialog-3.0"):AddToBlizOptions(addonName, "BetterBags") + self.frame, self.category = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(addonName, "BetterBags") LibStub("AceConfigDialog-3.0"):SetDefaultSize(addonName, 700, 800) LibStub('AceConsole-3.0'):RegisterChatCommand("bb", function() - LibStub("AceConfigDialog-3.0"):Open(addonName) + self:Open() end) events:RegisterMessage('categories/Changed', function() LibStub('AceConfigRegistry-3.0'):NotifyChange(addonName) end) + + events:RegisterMessage('config/Open', function() + self:Open() + end) end diff --git a/core/init.lua b/core/init.lua index 057def71..8ef2e3a1 100644 --- a/core/init.lua +++ b/core/init.lua @@ -47,6 +47,9 @@ local currency = addon:GetModule('Currency') ---@class Search: AceModule local search = addon:GetModule('Search') +---@class ConsolePort: AceModule +local consoleport = addon:GetModule('ConsolePort') + ---@class Debug: AceModule local debug = addon:GetModule('Debug') @@ -118,6 +121,8 @@ function addon:OnEnable() addon.Bags.Backpack = BagFrame:Create(const.BAG_KIND.BACKPACK) addon.Bags.Bank = BagFrame:Create(const.BAG_KIND.BANK) + consoleport:Enable() + self:SecureHook('OpenBackpack') self:SecureHook('OpenAllBags') self:SecureHook('CloseBackpack') diff --git a/frames/classic/context.lua b/frames/classic/context.lua index e30da99f..f164a012 100644 --- a/frames/classic/context.lua +++ b/frames/classic/context.lua @@ -20,6 +20,9 @@ local slider = addon:GetModule('Slider') ---@class Categories: AceModule local categories = addon:GetModule('Categories') +---@class Events: AceModule +local events = addon:GetModule('Events') + ---@class Localization: AceModule local L = addon:GetModule('Localization') @@ -55,10 +58,12 @@ end ---@param menuList MenuList[] function context:Show(menuList) LibDD:EasyMenu(menuList, self.frame, 'cursor', 0, 0, 'MENU') + events:SendMessage('context/show') end function context:Hide() LibDD:HideDropDownMenu(1) + events:SendMessage('context/hide') end --[[ local function addDivider(menuList) @@ -175,7 +180,7 @@ function context:CreateContextMenu(bag) tooltipText = L:G("Click to open the options screen."), func = function() context:Hide() - LibStub("AceConfigDialog-3.0"):Open(addonName) + events:SendMessage('config/Open') end }) diff --git a/frames/context.lua b/frames/context.lua index 844b5145..1bbe6b80 100644 --- a/frames/context.lua +++ b/frames/context.lua @@ -20,6 +20,9 @@ local slider = addon:GetModule('Slider') ---@class Categories: AceModule local categories = addon:GetModule('Categories') +---@class Events: AceModule +local events = addon:GetModule('Events') + ---@class Localization: AceModule local L = addon:GetModule('Localization') @@ -55,11 +58,14 @@ end ---@param menuList MenuList[] function context:Show(menuList) LibDD:EasyMenu(menuList, self.frame, 'cursor', 0, 0, 'MENU') + events:SendMessage('context/show') end function context:Hide() LibDD:HideDropDownMenu(1) + events:SendMessage('context/hide') end + --[[ local function addDivider(menuList) table.insert(menuList, { @@ -226,7 +232,7 @@ function context:CreateContextMenu(bag) tooltipText = L:G("Click to open the options screen."), func = function() context:Hide() - LibStub("AceConfigDialog-3.0"):Open(addonName) + events:SendMessage('config/Open') end }) diff --git a/frames/grid.lua b/frames/grid.lua index e1301207..26c35169 100644 --- a/frames/grid.lua +++ b/frames/grid.lua @@ -126,9 +126,11 @@ end function gridProto:HideScrollBar() self.bar:SetAlpha(0) + self.bar:SetAttribute("nodeignore", true) end function gridProto:ShowScrollBar() + self.bar:SetAttribute("nodeignore", false) self.bar:SetAlpha(1) end -- Sort will sort the cells in this grid using the given function. diff --git a/integrations/consoleport.lua b/integrations/consoleport.lua new file mode 100644 index 00000000..c55a537a --- /dev/null +++ b/integrations/consoleport.lua @@ -0,0 +1,71 @@ +---@diagnostic disable: duplicate-set-field,duplicate-doc-field,duplicate-doc-alias +local addonName = ... ---@type string + +---@class BetterBags: AceAddon +local addon = LibStub('AceAddon-3.0'):GetAddon(addonName) + +---@class Events: AceModule +local events = addon:GetModule('Events') + +---@class Context: AceModule +local context = addon:GetModule('Context') + +---@class Config: AceModule +local config = addon:GetModule('Config') + +---@class ConsolePort: AceModule +---@field private enabled boolean +local consoleport = addon:NewModule('ConsolePort') + +function consoleport:OnInitialize() + self.enabled = ConsolePort and true or false +end + +function consoleport:OnEnable() + if not self.enabled then return end + self:Add(addon.Bags.Backpack.frame) + self:Add(addon.Bags.Bank.frame) + + -- Context menus are created on demand, so we need to listen for the context/show event to add them. + events:RegisterMessage('context/show', function() + local listCount = 1 + local buttonCount = 1 + while _G[format('L_DropDownList%d', listCount)] ~= nil do + self:Add(_G[format('L_DropDownList%d', listCount)]) + while _G[format('L_DropDownList%dButton%d', listCount, buttonCount)] ~= nil do + self:Add(_G[format('L_DropDownList%dButton%d', listCount, buttonCount)]) + buttonCount = buttonCount + 1 + end + listCount = listCount + 1 + buttonCount = 1 + end + self:Select(_G['L_DropDownList1Button2']) + end) + + -- Overwrite the config open function so that it opens to Blizzard config when using ConsolePort + config.Open = function(me) + ---@cast me +Config + if addon.isClassic then + InterfaceOptionsFrame_OpenToCategory(me.frame) + else + Settings.OpenToCategory(me.category) + end + end +end + +---@param frame Frame +function consoleport:Add(frame) + if not self.enabled then return end + ConsolePort:AddInterfaceCursorFrame(frame) +end + +---@param frame Frame +function consoleport:Select(frame) + if not self.enabled then return end + ConsolePort:SetCursorNode(frame) +end + +---@return boolean +function consoleport:Active() + return self.enabled +end \ No newline at end of file