Skip to content

Commit

Permalink
Added ConsolePort support to Retail and Classic.
Browse files Browse the repository at this point in the history
Added various events for better hooking of BetterBags events.
  • Loading branch information
Cidan committed Feb 18, 2024
1 parent 47e4b7b commit 8642323
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 7 deletions.
4 changes: 3 additions & 1 deletion BetterBags.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -77,4 +77,6 @@ config\bags.lua
config\itemlist.lua
config\customcat.lua

integrations\consoleport.lua

core\init.lua
5 changes: 4 additions & 1 deletion BetterBags_Vanilla.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion BetterBags_Wrath.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions annotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
51 changes: 51 additions & 0 deletions config/classic/config.lua
Original file line number Diff line number Diff line change
@@ -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
16 changes: 14 additions & 2 deletions config/config.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field,duplicate-doc-field,duplicate-doc-alias
local addonName = ... ---@type string

---@class BetterBags: AceAddon
Expand All @@ -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')

Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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')
Expand Down
7 changes: 6 additions & 1 deletion frames/classic/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
})

Expand Down
8 changes: 7 additions & 1 deletion frames/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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
})

Expand Down
2 changes: 2 additions & 0 deletions frames/grid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
71 changes: 71 additions & 0 deletions integrations/consoleport.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8642323

Please sign in to comment.