Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Click Casting toggle #48

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Core/Events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ local CUF = select(2, ...)
---| "UpdatePixelPerfect"
---| "UpdateAppearance"
---| "AddonLoaded"
---| "UpdateClickCasting"
local callbacks = {}

---@param eventName Callbacks
Expand Down
5 changes: 5 additions & 0 deletions Core/OnLoad.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
6 changes: 6 additions & 0 deletions Data/Defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ Defaults.Widgets = {
---@field tooltipPosition TooltipPosition
---@field sameSizeAsPlayer boolean?
---@field hideBlizzardCastBar boolean?
---@field clickCast boolean

---@alias UnitLayoutTable table<Unit, UnitLayout>
---@type UnitLayoutTable
Expand All @@ -470,6 +471,7 @@ Defaults.Layouts = {
widgets = Defaults.Widgets,
tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, },
hideBlizzardCastBar = false,
clickCast = false,
},
target = {
enabled = false,
Expand All @@ -494,6 +496,7 @@ Defaults.Layouts = {
},
tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, },
sameSizeAsPlayer = false,
clickCast = false,
},
focus = {
enabled = false,
Expand All @@ -518,6 +521,7 @@ Defaults.Layouts = {
},
tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, },
sameSizeAsPlayer = false,
clickCast = false,
},
targettarget = {
enabled = false,
Expand All @@ -534,6 +538,7 @@ Defaults.Layouts = {
},
tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, },
sameSizeAsPlayer = false,
clickCast = false,
},
pet = {
enabled = false,
Expand All @@ -554,5 +559,6 @@ Defaults.Layouts = {
},
tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, },
sameSizeAsPlayer = false,
clickCast = false,
},
}
23 changes: 19 additions & 4 deletions UnitFrames/MenuOptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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?
Expand All @@ -131,17 +142,19 @@ 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,
function(checked)
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
Expand Down Expand Up @@ -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
Expand Down
66 changes: 66 additions & 0 deletions UnitFrames/UnitButton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 0 additions & 3 deletions UnitFrames/Units.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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