Skip to content

Commit

Permalink
Updated internal events to use the EventRegistry and added events for…
Browse files Browse the repository at this point in the history
… all sets
  • Loading branch information
Breeni committed May 4, 2024
1 parent 2269397 commit 5ab7644
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ new_read_globals = {
'CreateTexturePool',
'EditBox_ClearFocus',
'EquipmentManager_UnpackLocation',
'EventRegistry.RegisterCallback',
'EventRegistry.TriggerEvent',
'ExportUtil.MakeImportDataStream',
'FindSpellOverrideByID',
'FlagsUtil.IsSet',
Expand Down
28 changes: 26 additions & 2 deletions ActionBars.lua
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,11 @@ local function RefreshActionBarSet(set)

set.actions = actions

return UpdateSetFilters(set)
UpdateSetFilters(set)

Internal.Call("ActionBarSetUpdated", set.setID);

return set
end
local function AddActionBarSet()
local classFile = select(2, UnitClass("player"))
Expand All @@ -766,11 +770,13 @@ local function AddActionBarSet()
ignored[slot] = true
end

return Internal.AddSet(BtWLoadoutsSets.actionbars, UpdateSetFilters({
local set = Internal.AddSet(BtWLoadoutsSets.actionbars, UpdateSetFilters({
name = name,
ignored = ignored,
actions = actions,
}))
Internal.Call("ActionBarSetCreated", set.setID);
return set
end
local function GetActionBarSet(id)
local set = Internal.GetSet(BtWLoadoutsSets.actionbars, id)
Expand Down Expand Up @@ -833,6 +839,8 @@ local function DeleteActionBarSet(id)
end
end
end

Internal.Call("ActionBarSetDeleted", id);

local frame = BtWLoadoutsFrame.ActionBars;
local set = frame.set;
Expand Down Expand Up @@ -1007,6 +1015,8 @@ function BtWLoadoutsActionButtonMixin:SetAction(actionType, ...)
local set = self:GetActionBarFrame().set;
if actionType == nil then -- Clearing slot
set.actions[self:GetID()] = nil;

Internal.Call("ActionBarSetUpdated", set.setID);

self:Update();
return true;
Expand All @@ -1016,12 +1026,15 @@ function BtWLoadoutsActionButtonMixin:SetAction(actionType, ...)
tbl.type, tbl.id, tbl.subType, tbl.icon, tbl.name, tbl.macroText = actionType, ...

set.actions[self:GetID()] = tbl;

Internal.Call("ActionBarSetUpdated", set.setID);
self:Update()
end
end
function BtWLoadoutsActionButtonMixin:SetIgnored(ignored)
local set = self:GetActionBarFrame().set;
set.ignored[self:GetID()] = ignored and true or nil;
Internal.Call("ActionBarSetUpdated", set.setID);
self:Update();
end
function BtWLoadoutsActionButtonMixin:Update()
Expand Down Expand Up @@ -1147,6 +1160,8 @@ function BtWLoadoutsIgnoreActionBarMixin:OnClick()
set.ignored[id] = setIgnored
self:GetParent().Slots[id]:Update()
end

Internal.Call("ActionBarSetUpdated", set.setID);
end

local function DropDown_Initialize(self, level, menuList)
Expand All @@ -1160,6 +1175,8 @@ local function DropDown_Initialize(self, level, menuList)
info.func = function (self, arg1, arg2, checked)
set.settings = set.settings or {}
set.settings.adjustCovenant = not checked

Internal.Call("ActionBarSetUpdated", set.setID);

BtWLoadoutsFrame:Update()
end
Expand All @@ -1172,6 +1189,8 @@ local function DropDown_Initialize(self, level, menuList)
set.settings = set.settings or {}
set.settings.createMissingMacros = not checked
set.settings.createMissingMacrosCharacter = false

Internal.Call("ActionBarSetUpdated", set.setID);

BtWLoadoutsFrame:Update()
end
Expand All @@ -1184,6 +1203,8 @@ local function DropDown_Initialize(self, level, menuList)
set.settings = set.settings or {}
set.settings.createMissingMacrosCharacter = not checked
set.settings.createMissingMacros = false

Internal.Call("ActionBarSetUpdated", set.setID);

BtWLoadoutsFrame:Update()
end
Expand All @@ -1205,6 +1226,8 @@ BtWLoadoutsActionBarsMixin = {}
function BtWLoadoutsActionBarsMixin:OnLoad()
self.SettingsDropDown:SetSupportedTypes("covenant", "spec", "race")
self.SettingsDropDown:SetScript("OnChange", function ()
Internal.Call("ActionBarSetUpdated", self.set.setID);

self:Update()
end)
end
Expand All @@ -1218,6 +1241,7 @@ end
function BtWLoadoutsActionBarsMixin:UpdateSetName(value)
if self.set and self.set.name ~= not value then
self.set.name = value;
Internal.Call("ActionBarSetUpdated", self.set.setID);
self:Update();
end
end
Expand Down
24 changes: 8 additions & 16 deletions BtWLoadouts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,12 @@ function BtWLoadoutsTalentButtonMixin:OnClick()
selected[talentID] = true;
end

if self.isPvP then
Internal.Call("PvPTalentSetUpdated", frame.set.setID);
else
Internal.Call("TalentSetUpdated", frame.set.setID);
end

grid:Update()
end
function BtWLoadoutsTalentButtonMixin:OnEnter()
Expand Down Expand Up @@ -2125,25 +2131,11 @@ end

-- [[ CUSTOM EVENT HANDLING ]]

local eventHandlers = {}
function Internal.OnEvent(event, callback)
if not eventHandlers[event] then
eventHandlers[event] = {}
end

eventHandlers[event][callback] = true
EventRegistry:RegisterCallback("BtWLoadouts." .. event, callback);
end
function Internal.Call(event, ...)
local callbacks = eventHandlers[event]
local result = true
if callbacks then
for callback in pairs(callbacks) do
if callback(event, ...) == false then
result = false
end
end
end
return result
EventRegistry:TriggerEvent("BtWLoadouts." .. event, ...);
end

-- [[ Slash Command ]]
Expand Down
2 changes: 1 addition & 1 deletion Characters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8413,7 +8413,7 @@ do
end
end
function Internal.DeleteCharacter(slug)
if Internal.Call("CHARACTER_DELETE", slug) then
if Internal.Call("CharacterDeleted", slug) then
BtWLoadoutsCharacterInfo[slug] = nil
end
BtWLoadoutsFrame:Update();
Expand Down
34 changes: 34 additions & 0 deletions Conditions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ local function RefreshConditionSet(set)

UpdateSetFilters(set)

Internal.Call("ConditionUpdated", set.setID);

return set
end
local function AddConditionSet()
Expand All @@ -310,6 +312,9 @@ local function AddConditionSet()
};
UpdateSetFilters(set)
BtWLoadoutsSets.conditions[set.setID] = set;

Internal.Call("ConditionCreated", set.setID);

return set;
end
local function GetConditionSet(id)
Expand All @@ -329,6 +334,8 @@ local function DeleteConditionSet(id)
id = id.setID;
end

Internal.Call("ConditionDeleted", id);

local frame = BtWLoadoutsFrame.Conditions;
set = frame.set;
if set.setID == id then
Expand Down Expand Up @@ -590,6 +597,8 @@ local function ProfilesDropDown_OnClick(self, arg1, arg2, checked)
set.character = tab.temp["NONE"] or shallowcopy(set.character)
end

Internal.Call("ConditionUpdated", set.setID);

BtWLoadoutsFrame:Update();
end
local function ProfilesDropDown_NewOnClick(self, arg1, arg2, checked)
Expand All @@ -611,6 +620,8 @@ local function ProfilesDropDown_NewOnClick(self, arg1, arg2, checked)
subset.useCount = (subset.useCount or 0) + 1;
end

Internal.Call("ConditionUpdated", set.setID);

BtWLoadoutsFrame.Profiles.set = newSet;
PanelTemplates_SetTab(BtWLoadoutsFrame, BtWLoadoutsFrame.Profiles:GetID());

Expand Down Expand Up @@ -732,6 +743,8 @@ local function ConditionTypeDropDown_OnClick(self, arg1, arg2, checked)
set.bossID = nil;
set.affixesID = nil;

Internal.Call("ConditionUpdated", set.setID);

BtWLoadoutsFrame:Update();
end
local function ConditionTypeDropDownInit(self, level, menuList)
Expand Down Expand Up @@ -782,6 +795,8 @@ local function InstanceDropDown_OnClick(self, arg1, arg2, checked)
set.affixesID = nil;
end

Internal.Call("ConditionUpdated", set.setID);

BtWLoadoutsFrame:Update();
end
local function InstanceDropDownInit(self, level, menuList)
Expand Down Expand Up @@ -854,6 +869,8 @@ local function DifficultyDropDown_OnClick(self, arg1, arg2, checked)
set.affixesID = nil;
end

Internal.Call("ConditionUpdated", set.setID);

BtWLoadoutsFrame:Update();
end
local function DifficultyDropDownInit(self, level, menuList)
Expand Down Expand Up @@ -923,6 +940,8 @@ local function BossDropDown_OnClick(self, arg1, arg2, checked)

set.bossID = arg1;

Internal.Call("ConditionUpdated", set.setID);

BtWLoadoutsFrame:Update();
end
local function BossDropDownInit(self, level, menuList)
Expand Down Expand Up @@ -959,6 +978,8 @@ local function ScenarioDropDown_OnClick(self, arg1, arg2, checked)
set.instanceID = arg1;
set.difficultyID = arg2;

Internal.Call("ConditionUpdated", set.setID);

BtWLoadoutsFrame:Update();
end
local function ScenarioDropDownInit(self, level, menuList)
Expand Down Expand Up @@ -1002,6 +1023,8 @@ local function BattlegroundDropDown_OnClick(self, arg1, arg2, checked)
set.instanceID = arg1;
set.difficultyID = arg2;

Internal.Call("ConditionUpdated", set.setID);

BtWLoadoutsFrame:Update();
end
local function BattlegroundDropDownInit(self, level, menuList)
Expand Down Expand Up @@ -1049,6 +1072,8 @@ local function AffixDropDown_OnClick(self, arg1, arg2, checked)
set.affixesID = nil
end

Internal.Call("ConditionUpdated", set.setID);

BtWLoadoutsFrame:Update();
end

Expand Down Expand Up @@ -1144,6 +1169,8 @@ function BtWLoadoutsConditionsMixin:OnShow()
end
end

Internal.Call("ConditionUpdated", frame.set.setID);

BtWLoadoutsFrame:Update()
end
end
Expand Down Expand Up @@ -1192,12 +1219,16 @@ end
function BtWLoadoutsConditionsMixin:UpdateSetEnabled(value)
if self.set and self.set.disabled ~= value then
self.set.disabled = value;
Internal.Call("ConditionUpdated", self.set.setID);
self:Update();
end
end
function BtWLoadoutsConditionsMixin:UpdateSetName(value)
if self.set and self.set.name ~= not value then
self.set.name = value;

Internal.Call("ConditionUpdated", self.set.setID);

self:Update();
end
end
Expand All @@ -1219,6 +1250,9 @@ function BtWLoadoutsConditionsMixin:UpdateSetZone(value)
if valid then
--@TODO invalid zone?
end

Internal.Call("ConditionUpdated", self.set.setID);

self:Update();
end
end
Expand Down
Loading

0 comments on commit 5ab7644

Please sign in to comment.