mirror of
https://github.com/OldManAlpha/Puppeteer.git
synced 2025-11-28 23:48:35 +00:00
Add mouse wheel and key bindings
This commit is contained in:
parent
11ec78e8b0
commit
0deee656df
32
Bindings.xml
Normal file
32
Bindings.xml
Normal file
@ -0,0 +1,32 @@
|
||||
<Bindings>
|
||||
<Binding name ="PUPPETEERBINDING1" runOnUp="true" header="PUPPETEER">
|
||||
Puppeteer.HandleKeyPress(1)
|
||||
</Binding>
|
||||
<Binding name ="PUPPETEERBINDING2" runOnUp="true">
|
||||
Puppeteer.HandleKeyPress(2)
|
||||
</Binding>
|
||||
<Binding name ="PUPPETEERBINDING3" runOnUp="true">
|
||||
Puppeteer.HandleKeyPress(3)
|
||||
</Binding>
|
||||
<Binding name ="PUPPETEERBINDING4" runOnUp="true">
|
||||
Puppeteer.HandleKeyPress(4)
|
||||
</Binding>
|
||||
<Binding name ="PUPPETEERBINDING5" runOnUp="true">
|
||||
Puppeteer.HandleKeyPress(5)
|
||||
</Binding>
|
||||
<Binding name ="PUPPETEERBINDING6" runOnUp="true">
|
||||
Puppeteer.HandleKeyPress(6)
|
||||
</Binding>
|
||||
<Binding name ="PUPPETEERBINDING7" runOnUp="true">
|
||||
Puppeteer.HandleKeyPress(7)
|
||||
</Binding>
|
||||
<Binding name ="PUPPETEERBINDING8" runOnUp="true">
|
||||
Puppeteer.HandleKeyPress(8)
|
||||
</Binding>
|
||||
<Binding name ="PUPPETEERBINDING9" runOnUp="true">
|
||||
Puppeteer.HandleKeyPress(9)
|
||||
</Binding>
|
||||
<Binding name ="PUPPETEERBINDING10" runOnUp="true">
|
||||
Puppeteer.HandleKeyPress(10)
|
||||
</Binding>
|
||||
</Bindings>
|
||||
@ -1271,6 +1271,8 @@ function PTUnitFrame:Initialize()
|
||||
SetMouseoverUnit(self:GetResolvedUnit())
|
||||
end
|
||||
PT.Mouseover = self:GetResolvedUnit()
|
||||
PT.MouseoverFrame = self
|
||||
PT.ApplyOverrideBindings()
|
||||
end)
|
||||
button:SetScript("OnLeave", function()
|
||||
PT.HideSpellsTooltip()
|
||||
@ -1280,6 +1282,8 @@ function PTUnitFrame:Initialize()
|
||||
SetMouseoverUnit(nil)
|
||||
end
|
||||
PT.Mouseover = nil
|
||||
PT.MouseoverFrame = nil
|
||||
PT.RemoveOverrideBindings()
|
||||
end)
|
||||
button:EnableMouse(true)
|
||||
|
||||
|
||||
@ -78,6 +78,8 @@ CurrentlyInRaid = false
|
||||
|
||||
AssignedRoles = nil
|
||||
|
||||
Mouseover = nil
|
||||
|
||||
-- Returns the array of unit frames of the unit
|
||||
function GetUnitFrames(unit)
|
||||
return PTUnitFrames[unit]
|
||||
@ -476,6 +478,7 @@ function OnAddonLoaded()
|
||||
}
|
||||
loadouts["Default"] = default
|
||||
end
|
||||
SetupSpecialButtons()
|
||||
InitBindingDisplayCache()
|
||||
|
||||
if util.IsSuperWowPresent() then
|
||||
|
||||
@ -51,6 +51,7 @@ core\SpellsTooltip.lua
|
||||
core\EventHandler.lua
|
||||
core\DistanceScanner.lua
|
||||
core\Command.lua
|
||||
core\SpecialButtons.lua
|
||||
|
||||
PuppeteerSettings.lua
|
||||
PTUnitFrame.lua
|
||||
|
||||
@ -103,6 +103,9 @@ RegisterEventHandler("RAID_TARGET_UPDATE", function()
|
||||
ui:UpdateRaidMark()
|
||||
end
|
||||
end)
|
||||
RegisterEventHandler("PLAYER_LOGOUT", function()
|
||||
RemoveOverrideBindings()
|
||||
end)
|
||||
|
||||
local GetKeyModifier = util.GetKeyModifier
|
||||
local keyListener = CreateFrame("Frame", "PTTooltipKeyListener")
|
||||
|
||||
98
core/SpecialButtons.lua
Normal file
98
core/SpecialButtons.lua
Normal file
@ -0,0 +1,98 @@
|
||||
-- Handles mouse wheel and key bindings
|
||||
|
||||
PTUtil.SetEnvironment(Puppeteer)
|
||||
local _G = getfenv(0)
|
||||
local util = PTUtil
|
||||
|
||||
_G.BINDING_HEADER_PUPPETEER = "Puppeteer"
|
||||
local bindingsNames = {}
|
||||
for i = 1, 10 do
|
||||
bindingsNames[i] = "PUPPETEERBINDING"..i
|
||||
_G["BINDING_NAME_"..bindingsNames[i]] = "Dynamic Binding "..i
|
||||
end
|
||||
|
||||
local BindingPrefixes = {
|
||||
"",
|
||||
"SHIFT-",
|
||||
"CTRL-",
|
||||
"ALT-",
|
||||
"ALT-CTRL-SHIFT-",
|
||||
"ALT-CTRL-",
|
||||
"ALT-SHIFT-",
|
||||
"CTRL-SHIFT-"
|
||||
}
|
||||
|
||||
StoredBindings = {} -- Key: Baked keybind key(like "ALT-SHIFT-R") | Value: The stored value of the binding
|
||||
IndexButtonMap = {} -- Key: Index corresponding to the binding | Value: Button name
|
||||
KeybindIndexMap = {} -- Key: Baked keybind key | Value: Index corresponding to the binding
|
||||
|
||||
function SetupSpecialButtons()
|
||||
util.ClearTable(IndexButtonMap)
|
||||
util.ClearTable(KeybindIndexMap)
|
||||
local index = 1
|
||||
for _, button in ipairs(PTOptions.Buttons) do
|
||||
if not util.ArrayContains(util.GetAllButtons(), button) then
|
||||
for _, prefix in ipairs(BindingPrefixes) do
|
||||
KeybindIndexMap[prefix..button] = index
|
||||
end
|
||||
IndexButtonMap[index] = button
|
||||
index = index + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ApplyOverrideBindings()
|
||||
for fullButton, index in pairs(KeybindIndexMap) do
|
||||
local binding = GetBindingAction(fullButton)
|
||||
StoredBindings[fullButton] = binding
|
||||
SetBinding(fullButton, bindingsNames[index])
|
||||
end
|
||||
end
|
||||
|
||||
function RemoveOverrideBindings()
|
||||
for button, binding in pairs(StoredBindings) do
|
||||
SetBinding(button, binding)
|
||||
end
|
||||
util.ClearTable(StoredBindings)
|
||||
end
|
||||
|
||||
function HandleKeyPress(index)
|
||||
local button = IndexButtonMap[index]
|
||||
if keystate == "down" then
|
||||
CurrentlyHeldButton = button
|
||||
if button == "MOUSEWHEELUP" or button == "MOUSEWHEELDOWN" then
|
||||
FakeMouseWheelHold(button)
|
||||
end
|
||||
ReapplySpellsTooltip()
|
||||
if PTOptions.CastWhen == "Mouse Down" then
|
||||
UnitFrame_OnClick(button, Mouseover, MouseoverFrame)
|
||||
end
|
||||
else
|
||||
if button ~= "MOUSEWHEELUP" and button ~= "MOUSEWHEELDOWN" then
|
||||
CurrentlyHeldButton = nil
|
||||
ReapplySpellsTooltip()
|
||||
end
|
||||
if PTOptions.CastWhen == "Mouse Up" then
|
||||
UnitFrame_OnClick(button, Mouseover, MouseoverFrame)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
MouseWheelHeldFaker = CreateFrame("Frame", "PTMouseWheelHeldFaker")
|
||||
|
||||
local unholdAt
|
||||
local unholdButton
|
||||
local MouseWheelHeldFaker_OnUpdate = function()
|
||||
if GetTime() >= unholdAt then
|
||||
MouseWheelHeldFaker:SetScript("OnUpdate", nil)
|
||||
if CurrentlyHeldButton == unholdButton then
|
||||
CurrentlyHeldButton = nil
|
||||
ReapplySpellsTooltip()
|
||||
end
|
||||
end
|
||||
end
|
||||
function FakeMouseWheelHold(button)
|
||||
unholdAt = GetTime() + 0.08
|
||||
unholdButton = button
|
||||
MouseWheelHeldFaker:SetScript("OnUpdate", MouseWheelHeldFaker_OnUpdate)
|
||||
end
|
||||
@ -88,8 +88,8 @@ function InitBindingDisplayCache()
|
||||
ButtonDisplayCache = {}
|
||||
for _, button in ipairs(PTOptions.Buttons) do
|
||||
ButtonDisplayCache[button] = {}
|
||||
ButtonDisplayCache[button]["Normal"] = PTOptions.ButtonNames[button]
|
||||
ButtonDisplayCache[button]["Unfocused"] = colorize(PTOptions.ButtonNames[button], 0.3, 0.3, 0.3)
|
||||
ButtonDisplayCache[button]["Normal"] = PTOptions.ButtonNames[button] or button
|
||||
ButtonDisplayCache[button]["Unfocused"] = colorize(PTOptions.ButtonNames[button] or button, 0.3, 0.3, 0.3)
|
||||
end
|
||||
|
||||
BindingDisplayCache = {}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user