From 062c21a0198c22c7caf436db4598938f119c677f Mon Sep 17 00:00:00 2001 From: Road-block Date: Thu, 29 Dec 2016 06:49:42 +0200 Subject: [PATCH] hoverbind: add module to change keybinds --- modules/hoverbind.lua | 104 ++++++++++++++++++++++++++++++++++++++++++ pfUI.toc | 1 + 2 files changed, 105 insertions(+) create mode 100644 modules/hoverbind.lua diff --git a/modules/hoverbind.lua b/modules/hoverbind.lua new file mode 100644 index 00000000..1fe4bf70 --- /dev/null +++ b/modules/hoverbind.lua @@ -0,0 +1,104 @@ +pfUI:RegisterModule("hoverbind", function () + local default_border = pfUI_config.appearance.border.default + local keymap = { + ["BonusActionButton"] = "ACTIONBUTTON", + ["MultiBarBottomLeftButton"] = "MULTIACTIONBAR1BUTTON", + ["MultiBarBottomRightButton"] = "MULTIACTIONBAR2BUTTON", + ["MultiBarRightButton"] = "MULTIACTIONBAR3BUTTON", + ["MultiBarLeftButton"] = "MULTIACTIONBAR4BUTTON", + ["ShapeshiftButton"] = "SHAPESHIFTBUTTON", + ["PetActionButton"] = "BONUSACTIONBUTTON", + } + local modifiers = { + ["ALT"] = "ALT-", + ["CTRL"] = "CTRL-", + ["SHIFT"] = "SHIFT-" + } + + pfUI.hoverbind = CreateFrame("Frame","pfKeyBindingFrame",UIParent) + pfUI.hoverbind:RegisterEvent("PLAYER_REGEN_DISABLED") + pfUI.hoverbind:EnableMouse(true) + pfUI.hoverbind.edit = CreateFrame("Button", "pfKeyBindingFrameEdit", pfUI.hoverbind) + pfUI.hoverbind.edit:SetFrameStrata("BACKGROUND") + pfUI.hoverbind.edit:SetAllPoints(UIParent) + pfUI.hoverbind.edit.tex = pfUI.hoverbind.edit:CreateTexture("pfKeyBindShade", "BACKGROUND") + pfUI.hoverbind.edit.tex:SetAllPoints(pfUI.hoverbind.edit) + pfUI.hoverbind.edit.tex:SetTexture(0,0,0,.5) + pfUI.hoverbind.edit:SetScript("OnClick", function() + pfUI.hoverbind:Hide() + end) + + pfUI.hoverbind:SetScript("OnMouseUp",function(...) + pfUI.hoverbind:Hide() + end) + + pfUI.hoverbind:SetScript("OnShow", function() + pfUI.hoverbind.edit:Show() + + pfUI.info:ShowInfoBox("|cff33ffccKeybind Mode|r\n" .. + "This mode allows you to bind keyboard shortcuts to your actionbars.\n" .. + "By hovering a button with your cursor and pressing a key, the key will be assigned to that button.\n" .. + "Hit Escape on a button to remove bindings.\n\n" .. + "Press Escape or click on an empty area to leave the keybind mode.\n", 30, pfUI.hoverbind.edit) + end) + + pfUI.hoverbind:SetScript("OnHide",function() + pfUI.hoverbind.edit:Hide() + end) + + pfUI.hoverbind:EnableKeyboard(true) + pfUI.hoverbind:SetScript("OnKeyUp",function(...) + if modifiers[arg1] then return end -- ignore single modifier keyup + local need_save = false + local frame = GetMouseFocus() + local hovername = (frame and frame.GetName) and (frame:GetName()) or "" + local binding = pfUI.hoverbind:GetBinding(hovername) + if arg1 == "ESCAPE" and not binding then pfUI.hoverbind:Hide() return end + if (binding) then + if arg1 == "ESCAPE" then + local key = (GetBindingKey(binding)) + if (key) then + SetBinding(key) + need_save = true + end + else + if (SetBinding(pfUI.hoverbind:GetPrefix()..arg1,binding)) then + need_save = true + end + end + end + -- if we set or cleared a binding save to the selected set + if need_save then + need_save = false + SaveBindings(GetCurrentBindingSet()) + end + end) + pfUI.hoverbind:Hide() + + function pfUI.hoverbind:GetBinding(button_name) + local found,_,buttontype,buttonindex = string.find(button_name,"^(%a+)(%d+)$") + if found then + if keymap[buttontype] then + return string.format("%s%d",keymap[buttontype],buttonindex) + elseif buttontype == "ActionButton" then + return string.format("ACTIONBUTTON%d",buttonindex) + else + return nil + end + else + return nil + end + end + + function pfUI.hoverbind:GetPrefix() + return string.format("%s%s%s", + (IsAltKeyDown() and modifiers.ALT or ""), + (IsControlKeyDown() and modifiers.CTRL or ""), + (IsShiftKeyDown() and modifiers.SHIFT or "")) + end + + pfUI.hoverbind:SetScript("OnEvent",function() + -- disable hoverbind so player gets back control of their keyboard to fight + pfUI.hoverbind:Hide() + end) +end) diff --git a/pfUI.toc b/pfUI.toc index 0ca9ab97..aeb63762 100644 --- a/pfUI.toc +++ b/pfUI.toc @@ -26,6 +26,7 @@ env\fonts.lua modules\config.lua modules\gui.lua modules\pixelperfect.lua +modules\hoverbind.lua modules\actionbar.lua modules\chat.lua modules\font.lua