Skip to content

Commit

Permalink
Autoprofile based on spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Aviana committed Sep 24, 2022
1 parent d6ec90d commit fbeafd1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
15 changes: 12 additions & 3 deletions LunaUnitFrames.lua
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ function LUF:OnProfileDeleted(event, key, name)
end
end

function LUF:AutoswitchProfile(event)
function LUF:AutoswitchProfile(event, arg1)
local profile
if event == "DISPLAY_SIZE_CHANGED" and self.db.char.switchtype == "RESOLUTION" then
local resolutions = {GetScreenResolutions()}
Expand Down Expand Up @@ -411,6 +411,8 @@ function LUF:AutoswitchProfile(event)
elseif self.db.char.grpdb["NONARENA"] then
profile = self.db.char.grpdb["NONARENA"]
end
elseif event == "ACTIVE_TALENT_GROUP_CHANGED" and self.db.char.switchtype == "SPECIALIZATION" then
profile = self.db.char.specdb["SPEC"..arg1]
end
if profile and profile ~= self.db:GetCurrentProfile() then
self.db:SetProfile(profile)
Expand Down Expand Up @@ -1812,11 +1814,12 @@ frame:RegisterEvent("ADDON_LOADED")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent", function(self, event, addon)
frame:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
frame:SetScript("OnEvent", function(self, event, arg1)
if( event == "PLAYER_LOGIN" ) then
LUF:OnLoad()
self:UnregisterEvent("PLAYER_LOGIN")
elseif( event == "ADDON_LOADED" and ( addon == "Blizzard_ArenaUI" or addon == "Blizzard_CompactRaidFrames" ) and not LUF.InCombatLockdown) then
elseif( event == "ADDON_LOADED" and ( arg1 == "Blizzard_ArenaUI" or arg1 == "Blizzard_CompactRaidFrames" ) and not LUF.InCombatLockdown) then
LUF:HideBlizzardFrames()
elseif event == "PLAYER_REGEN_DISABLED" then
LUF.InCombatLockdown = true
Expand Down Expand Up @@ -1854,6 +1857,12 @@ frame:SetScript("OnEvent", function(self, event, addon)
else
queuedEvent = event
end
elseif event == "ACTIVE_TALENT_GROUP_CHANGED" then
if not LUF.InCombatLockdown then
LUF:AutoswitchProfile(event, arg1)
else
queuedEvent = event
end
end
end)

Expand Down
25 changes: 22 additions & 3 deletions modules/Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local SML = SML or LibStub:GetLibrary("LibSharedMedia-3.0")
local ACR = LibStub("AceConfigRegistry-3.0", true)
local L = LUF.L
local resolutionselectvalue,groupselectvalue, profiledb = GetCurrentResolution(), "SOLO", {}
local resolutionselectvalue,groupselectvalue, specselectvalue, profiledb = GetCurrentResolution(), "SOLO", "SPEC1", {}

local InfoTags = {
["numtargeting"] = true,
Expand Down Expand Up @@ -10460,7 +10460,7 @@ function LUF:CreateConfig()
desc = L["Type of event to switch to"],
type = "select",
order = 2,
values = {["DISABLED"] = ADDON_DISABLED, ["RESOLUTION"] = L["Screen Resolution"],["GROUP"] = L["Size of Group"],["ARENA"] = ARENA},
values = {["DISABLED"] = ADDON_DISABLED, ["RESOLUTION"] = L["Screen Resolution"],["GROUP"] = L["Size of Group"],["ARENA"] = ARENA, ["SPECIALIZATION"] = SPECIALIZATION},
get = function(info) return LUF.db.char.switchtype end,
set = function(info, value) LUF.db.char.switchtype = value LUF:AutoswitchProfileSetup() end,
},
Expand All @@ -10484,11 +10484,21 @@ function LUF:CreateConfig()
get = function(info) return groupselectvalue end,
set = function(info, value) groupselectvalue = value end,
},
specselect = {
name = SPECIALIZATION,
--desc = L["Size of group to assign a profile to"],
type = "select",
order = 5,
hidden = function() return LUF.db.char.switchtype ~= "SPECIALIZATION" end,
values = {["SPEC1"]=SPECIALIZATION.." 1",["SPEC2"]=SPECIALIZATION.." 2"},
get = function(info) return specselectvalue end,
set = function(info, value) specselectvalue = value end,
},
profileselect = {
name = L["Profile"],
desc = L["Name of the profile which to switch to"],
type = "select",
order = 5,
order = 6,
values = function() LUF.db:GetProfiles(profiledb) profiledb["NIL"] = NONE return profiledb end,
hidden = function() return LUF.db.char.switchtype == "DISABLED" end,
get = function(info)
Expand All @@ -10506,6 +10516,13 @@ function LUF:CreateConfig()
end
end
return "NIL"
elseif LUF.db.char.switchtype == "SPECIALIZATION" then
for k,v in pairs(profiledb) do
if v == LUF.db.char.specdb[specselectvalue] then
return k
end
end
return "NIL"
else
for k,v in pairs(profiledb) do
if v == LUF.db.char.grpdb[groupselectvalue] then
Expand All @@ -10526,6 +10543,8 @@ function LUF:CreateConfig()
return
end
end
elseif LUF.db.char.switchtype == "SPECIALIZATION" then
LUF.db.char.specdb[specselectvalue] = value ~= "NIL" and profiledb[value] or nil
elseif LUF.db.char.switchtype == "GROUP" then
LUF.db.char.grpdb[groupselectvalue] = value ~= "NIL" and profiledb[value] or nil
else
Expand Down
1 change: 1 addition & 0 deletions modules/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function LUF:LoadDefaults()
switchtype = "DISABLED",
resdb = {},
grpdb = {},
specdb = {},
},
profile = {
locked = false,
Expand Down

0 comments on commit fbeafd1

Please sign in to comment.