diff --git a/Core/Events.lua b/Core/Events.lua index 43458c7..84561ba 100644 --- a/Core/Events.lua +++ b/Core/Events.lua @@ -16,6 +16,7 @@ local CUF = select(2, ...) ---| "UpdatePixelPerfect" ---| "UpdateAppearance" ---| "AddonLoaded" +---| "UpdateClickCasting" local callbacks = {} ---@param eventName Callbacks diff --git a/Core/OnLoad.lua b/Core/OnLoad.lua index fffa083..fcfe89e 100644 --- a/Core/OnLoad.lua +++ b/Core/OnLoad.lua @@ -51,6 +51,11 @@ local function OnCellInitialUpdateLayout(_layout) Cell:RegisterCallback("UpdateAppearance", "CUF_UpdateAppearance", function(kind) CUF:Fire("UpdateAppearance", kind) end) + Cell:RegisterCallback("UpdateQueuedClickCastings", "CUF_UpdateQueuedClickCastings", + function() CUF:Fire("UpdateClickCasting", true, true) end) + Cell:RegisterCallback("UpdateClickCastings", "CUF_UpdateClickCastings", + function(noReload, onlyqueued) CUF:Fire("UpdateClickCasting", noReload, onlyqueued) end) + -- Init widgets CUF:Fire("UpdateWidget", CUF.DB.GetMasterLayout()) diff --git a/Data/Defaults.lua b/Data/Defaults.lua index 1752ec2..ed07856 100644 --- a/Data/Defaults.lua +++ b/Data/Defaults.lua @@ -457,6 +457,7 @@ Defaults.Widgets = { ---@field tooltipPosition TooltipPosition ---@field sameSizeAsPlayer boolean? ---@field hideBlizzardCastBar boolean? +---@field clickCast boolean ---@alias UnitLayoutTable table ---@type UnitLayoutTable @@ -470,6 +471,7 @@ Defaults.Layouts = { widgets = Defaults.Widgets, tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, }, hideBlizzardCastBar = false, + clickCast = false, }, target = { enabled = false, @@ -494,6 +496,7 @@ Defaults.Layouts = { }, tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, }, sameSizeAsPlayer = false, + clickCast = false, }, focus = { enabled = false, @@ -518,6 +521,7 @@ Defaults.Layouts = { }, tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, }, sameSizeAsPlayer = false, + clickCast = false, }, targettarget = { enabled = false, @@ -534,6 +538,7 @@ Defaults.Layouts = { }, tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, }, sameSizeAsPlayer = false, + clickCast = false, }, pet = { enabled = false, @@ -554,5 +559,6 @@ Defaults.Layouts = { }, tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, }, sameSizeAsPlayer = false, + clickCast = false, }, } diff --git a/UnitFrames/MenuOptions.lua b/UnitFrames/MenuOptions.lua index bc42082..37e8f14 100644 --- a/UnitFrames/MenuOptions.lua +++ b/UnitFrames/MenuOptions.lua @@ -43,6 +43,9 @@ local function AddLoadPageDB(unitPage) unitPage.hideBlizzardCastBarCB:SetChecked(pageDB.hideBlizzardCastBar) end + -- click casting + unitPage.clickCastCB:SetChecked(pageDB.clickCast) + if isPlayerPage then unitPage.widthSlider:SetEnabled(true) unitPage.heightSlider:SetEnabled(true) @@ -100,10 +103,11 @@ local function AddUnitsToMenu() unitPage.pageButton = CUF:CreateButton(parent.unitSection, L[unit], { 85, 17 }) unitPage.pageButton.id = unit ---@type Unit + -- First row + ---@type CheckButton unitPage.enabledCB = Cell:CreateCheckButton(unitPage.frame, - L["Enable"] .. " " .. L[unit] .. " " .. L - .Frame, + L["Enable"], function(checked) CUF.DB.SelectedLayoutTable()[unit].enabled = checked if CUF.vars.selectedLayout == CUF.DB.GetMasterLayout() then @@ -113,6 +117,13 @@ local function AddUnitsToMenu() end) unitPage.enabledCB:SetPoint("TOPLEFT", 5, -10) + unitPage.clickCastCB = Cell:CreateCheckButton(unitPage.frame, L["Click Casting"], + function(checked) + CUF.DB.SelectedLayoutTable()[unit].clickCast = checked + CUF:Fire("UpdateClickCasting", false, false, unit) + end) + unitPage.clickCastCB:SetPoint("TOPLEFT", unitPage.enabledCB, "TOPRIGHT", 70, 0) + if unit ~= CUF.constants.UNIT.PLAYER then -- same size as player ---@type CheckButton? @@ -131,7 +142,7 @@ local function AddUnitsToMenu() CUF:Fire("UpdateLayout", CUF.vars.selectedLayout, unit .. "-power") end end) - unitPage.sameSizeAsPlayerCB:SetPoint("TOPLEFT", unitPage.enabledCB, "TOPRIGHT", 200, 0) + unitPage.sameSizeAsPlayerCB:SetPoint("TOPLEFT", unitPage.clickCastCB, "TOPRIGHT", 130, 0) else -- Disable blizzard cast bar unitPage.hideBlizzardCastBarCB = Cell:CreateCheckButton(unitPage.frame, L.HideDefaultCastBar, @@ -139,9 +150,11 @@ local function AddUnitsToMenu() CUF.DB.SelectedLayoutTable()[unit].hideBlizzardCastBar = checked CUF:Fire("UpdateVisibility", unit) end, L.HideDefaultCastBarTooltip) - unitPage.hideBlizzardCastBarCB:SetPoint("TOPLEFT", unitPage.enabledCB, "TOPRIGHT", 200, 0) + unitPage.hideBlizzardCastBarCB:SetPoint("TOPLEFT", unitPage.clickCastCB, "TOPRIGHT", 130, 0) end + -- Second row + ---@type CellSlider unitPage.widthSlider = Cell:CreateSlider(L["Width"], unitPage.frame, 20, 500, 117, 1, function(value) CUF.DB.SelectedLayoutTable()[unit].size[1] = value @@ -174,6 +187,8 @@ local function AddUnitsToMenu() CUF:SetTooltips(unitPage.copyFromDropdown, "ANCHOR_TOPLEFT", 0, 3, L.CopyWidgetsFrom, L.CopyWidgetsFromTooltip) + -- Third row + ---@type CellSlider unitPage.heightSlider = Cell:CreateSlider(L["Height"], unitPage.frame, 20, 500, 117, 1, function(value) CUF.DB.SelectedLayoutTable()[unit].size[2] = value diff --git a/UnitFrames/UnitButton.lua b/UnitFrames/UnitButton.lua index be65f55..a9b086e 100644 --- a/UnitFrames/UnitButton.lua +++ b/UnitFrames/UnitButton.lua @@ -393,3 +393,69 @@ local function UpdateAppearance(kind) end end CUF:RegisterCallback("UpdateAppearance", "UpdateAppearance", UpdateAppearance) + +------------------------------------------------- +-- MARK: Update Click Casting +------------------------------------------------- + +local previousClickCastings + +local function GetMouseWheelBindKey(fullKey, noTypePrefix) + local modifier, key = strmatch(fullKey, "^(.*)type%-(.+)$") + modifier = string.gsub(modifier, "-", "") + + if noTypePrefix then + return modifier .. key + else + return "type-" .. modifier .. key -- type-ctrlSCROLLUP + end +end + +---@param button CUFUnitButton +local function ClearClickCastings(button) + if not previousClickCastings then return end + button:SetAttribute("cell", nil) + button:SetAttribute("menu", nil) + for _, t in pairs(previousClickCastings) do + local bindKey = t[1] + if strfind(bindKey, "SCROLL") then + bindKey = GetMouseWheelBindKey(t[1]) + end + + button:SetAttribute(bindKey, nil) + local attr = string.gsub(bindKey, "type", "spell") + button:SetAttribute(attr, nil) + attr = string.gsub(bindKey, "type", "macro") + button:SetAttribute(attr, nil) + attr = string.gsub(bindKey, "type", "macrotext") + button:SetAttribute(attr, nil) + attr = string.gsub(bindKey, "type", "item") + button:SetAttribute(attr, nil) + end +end + +---@param noReload boolean? +---@param onlyqueued boolean? +---@param which string? +function U.UpdateClickCasting(noReload, onlyqueued, which) + Util:IterateAllUnitButtons(function(button, unit) + if not which or which == unit then + if CUF.DB.CurrentLayoutTable()[unit].clickCast then + F:UpdateClickCastings(noReload, onlyqueued) + local snippet = F:GetBindingSnippet() + CUF:DevAdd(snippet, "snippet") + F:UpdateClickCastOnFrame(button, snippet) + else + ClearClickCastings(button) + + button:SetAttribute('*type1', 'target') -- makes left click target the unit + button:SetAttribute('*type2', 'togglemenu') -- makes right click toggle a unit menu + end + end + end) + + previousClickCastings = F:Copy(Cell.vars.clickCastings["useCommon"] and Cell.vars.clickCastings["common"] or + Cell.vars.clickCastings[Cell.vars.playerSpecID]) +end + +CUF:RegisterCallback("UpdateClickCasting", "UpdateClickCasting", U.UpdateClickCasting) diff --git a/UnitFrames/Units.lua b/UnitFrames/Units.lua index 90aaf7a..5fc6074 100644 --- a/UnitFrames/Units.lua +++ b/UnitFrames/Units.lua @@ -87,8 +87,5 @@ function U:InitUnitButtons() local button = CreateUnitButton(unit, unitFrame) RegisterUnitButtonCallbacks(unit, button, unitFrame, anchorFrame, hoverFrame, config) - - button:SetAttribute('*type1', 'target') -- makes left click target the unit - button:SetAttribute('*type2', 'togglemenu') -- makes right click toggle a unit menu end end