From c21d80d5ba38014f58be9623162666178ad42d9f Mon Sep 17 00:00:00 2001 From: James Whitehead II Date: Mon, 4 Oct 2010 22:27:46 +0100 Subject: [PATCH] Implemented target unit/show menu actions and binding captures --- BindConfig.lua | 81 +++++++++++++++++++++++++++----------------------------- Clique.xml | 62 +++++++++++++++++++++++++++++++++++++++---- Utils.lua | 52 +++++++++++++++++++++++++++++++----- 3 files changed, 142 insertions(+), 53 deletions(-) diff --git a/BindConfig.lua b/BindConfig.lua index 5b7aad2..a35cbc1 100755 --- a/BindConfig.lua +++ b/BindConfig.lua @@ -37,9 +37,8 @@ function CliqueConfig:SetupGUI() self.dialog = _G["CliqueDialog"] self.dialog.title = _G["CliqueDialogTitleText"] - self.dialog.title:SetText(L["Clique: Set binding"]) + self.dialog.title:SetText(L["Set binding"]) self.dialog.button_accept:SetText(L["Accept"]) - self.dialog.bindText:SetText(L["Alt-Control-Shift-F"]) self.dialog.button_binding:SetText(L["Set binding"]) local desc = L["In order to specify a binding, move your mouse over the button labelled 'Set binding' and either click with your mouse or press a key on your keyboard. You can modify the binding by holding down a combination of the alt, control and shift keys on your keyboard."] @@ -124,48 +123,21 @@ function CliqueConfig:Spellbook_DisableKeyboard(button, motion) button:EnableKeyboard(false) end -invalidKeys = { - ["UNKNOWN"] = true, - ["LSHIFT"] = true, - ["RSHIFT"] = true, - ["LCTRL"] = true, - ["RCTRL"] = true, - ["LALT"] = true, - ["RALT"] = true, -} - function CliqueConfig:Spellbook_OnBinding(button, key) - -- We can't bind modifiers or invalid keys - if invalidKeys[key] then - return - elseif key == "ESCAPE" then + if key == "ESCAPE" then HideUIPanel(CliqueConfig) return end - -- Remap any mouse buttons - if key == "LeftButton" then - key = "BUTTON1" - elseif key == "RightButton" then - key = "BUTTON2" - elseif key == "MiddleButton" then - key = "BUTTON3" - else - buttonNum = key:match("Button(%d+)") - if buttonNum and tonumber(buttonNum) <= 31 then - key = "BUTTON" .. buttonNum - end - end - - -- TODO: Support NOT splitting the modifier keys - local prefix = addon:GetPrefixString(true) - local slot = SpellBook_GetSpellBookSlot(button:GetParent()); local name, subtype = GetSpellBookItemName(slot, SpellBookFrame.bookType) local texture = GetSpellBookItemTexture(slot, SpellBookFrame.bookType) + + local key = addon:GetCapturedKey(key) + assert(key, "Unable to get binding information: " .. tostring(key)) local succ, err = addon:AddBinding{ - key = prefix .. key, + key = key, type = "spell", spell = name, icon = texture @@ -196,17 +168,13 @@ function CliqueConfig:Button_OnClick(button) { text = L["Target clicked unit"], func = function() - config.page1:Hide() - config.page2.bindType = "target" - config.page2:Show() + self:SetupCaptureDialog("target") end, }, { text = L["Open unit menu"], func = function() - config.page1:Hide() - config.page2.bindType = "menu" - config.page2:Show() + self:SetupCaptureDialog("menu") end, }, { @@ -340,12 +308,41 @@ function CliqueConfig:ShowEditPage() self.page3:Show() end -function CliqueConfig:Save_OnClick(button, button, down) +function CliqueConfig:Save_OnClick(button, down) end -function CliqueConfig:Cancel_OnClick(button, button, down) +function CliqueConfig:Cancel_OnClick(button, down) self:ClearEditPage() self.page3:Hide() self.page1:Show() end +function CliqueConfig:SetupCaptureDialog(type) + self.dialog.bindType = type + self.dialog.bindText:SetText("") + + local actionText = addon:GetBindingActionText(type) + self.dialog.title:SetText(L["Set binding: %s"]:format(actionText)) + self.dialog:Show() +end + +function CliqueConfig:BindingButton_OnClick(button, key) + local dialog = CliqueDialog + dialog.key = addon:GetCapturedKey(key) + if dialog.key then + CliqueDialog.bindText:SetText(addon:GetBindingKeyComboText(dialog.key)) + end +end + +function CliqueConfig:AcceptSetBinding() + local dialog = CliqueDialog + local key = dialog.key + local succ, err = addon:AddBinding{ + key = key, + type = dialog.bindType, + } + if succ then + CliqueConfig:UpdateList() + end + dialog:Hide() +end diff --git a/Clique.xml b/Clique.xml index 9493d27..8de5bbe 100755 --- a/Clique.xml +++ b/Clique.xml @@ -115,21 +115,21 @@ - + - + - + - - + + @@ -137,19 +137,71 @@ + + + + table.insert(UISpecialFrames, "CliqueDialog") + + diff --git a/Utils.lua b/Utils.lua index e7b29ac..d455da9 100644 --- a/Utils.lua +++ b/Utils.lua @@ -48,6 +48,8 @@ local convertMap = setmetatable({ BUTTON1 = L["LeftButton"], BUTTON2 = L["RightButton"], BUTTON3 = L["MiddleButton"], + MOUSEWHEELUP = L["MousewheelUp"], + MOUSEWHEELDOWN = L["MousewheelDown"], }, { __index = function(t, k, v) if k:match("^BUTTON(%d+)$") then @@ -87,11 +89,16 @@ function addon:GetBindingIcon(binding) end function addon:GetBindingKeyComboText(binding) - return strconcat(convert(strsplit("-", binding.key))) + if type(binding) == "table" then + return strconcat(convert(strsplit("-", binding.key))) + elseif type(binding) == "string" then + return strconcat(convert(strsplit("-", binding))) + end end function addon:GetBindingActionText(binding) - local btype = binding.type + local btype = type(binding) == "table" and binding.type or binding + if btype == "menu" then return L["Show unit menu"] elseif btype == "target" then @@ -102,10 +109,6 @@ function addon:GetBindingActionText(binding) end return L["Cast %s"]:format(binding.spell) else - for k,v in pairs(binding) do - print("binding", k, v) - end - return L["Unknown binding type '%s'"]:format(tostring(btype)) end end @@ -140,3 +143,40 @@ function addon:GetBinaryBindingKey(binding) end return table.concat(ret) end + +invalidKeys = { + ["UNKNOWN"] = true, + ["LSHIFT"] = true, + ["RSHIFT"] = true, + ["LCTRL"] = true, + ["RCTRL"] = true, + ["LALT"] = true, + ["RALT"] = true, + ["ESCAPE"] = true, +} + +function addon:GetCapturedKey(key) + -- We can't bind modifiers or invalid keys + if invalidKeys[key] then + return + end + + -- Remap any mouse buttons + if key == "LeftButton" then + key = "BUTTON1" + elseif key == "RightButton" then + key = "BUTTON2" + elseif key == "MiddleButton" then + key = "BUTTON3" + else + buttonNum = key:match("Button(%d+)") + if buttonNum and tonumber(buttonNum) <= 31 then + key = "BUTTON" .. buttonNum + end + end + + -- TODO: Support NOT splitting the modifier keys + local prefix = addon:GetPrefixString(true) + return tostring(prefix) .. tostring(key) +end + -- 1.7.9.5