From 5e27e3803a009ba7ec82732cd03edcd3b0c9a797 Mon Sep 17 00:00:00 2001 From: James Whitehead II Date: Sun, 3 Oct 2010 21:42:14 +0100 Subject: [PATCH] Rename files to remove over-namespacing --- BindConfig.lua | 351 ++++++++++++++++++++++++++++++++++++++++++++++++ Clique.toc | 10 +- CliqueConfig.lua | 351 ------------------------------------------------ CliqueOptionsPanel.lua | 15 --- CliqueTest.lua | 56 -------- CliqueTest.xml | 53 -------- CliqueUtils.lua | 142 -------------------- HeaderTest.lua | 56 ++++++++ HeaderTest.xml | 53 ++++++++ OptionsPanel.lua | 15 +++ Utils.lua | 142 ++++++++++++++++++++ 11 files changed, 622 insertions(+), 622 deletions(-) create mode 100755 BindConfig.lua delete mode 100755 CliqueConfig.lua delete mode 100644 CliqueOptionsPanel.lua delete mode 100644 CliqueTest.lua delete mode 100644 CliqueTest.xml delete mode 100644 CliqueUtils.lua create mode 100644 HeaderTest.lua create mode 100644 HeaderTest.xml create mode 100644 OptionsPanel.lua create mode 100644 Utils.lua diff --git a/BindConfig.lua b/BindConfig.lua new file mode 100755 index 0000000..5b7aad2 --- /dev/null +++ b/BindConfig.lua @@ -0,0 +1,351 @@ +local addonName, addon = ... +local L = addon.L + +local MAX_ROWS = 12 + +function CliqueConfig:OnShow() + if not self.initialized then + self:SetupGUI() + self:HijackSpellbook() + self.initialized = true + end + + self:UpdateList() + self:EnableSpellbookButtons() +end + + +function CliqueConfig:SetupGUI() + self.rows = {} + for i = 1, MAX_ROWS do + self.rows[i] = CreateFrame("Button", "CliqueRow" .. i, self.page1, "CliqueRowTemplate") + end + + self.rows[1]:ClearAllPoints() + self.rows[1]:SetPoint("TOPLEFT", "CliqueConfigPage1Column1", "BOTTOMLEFT", 0, -3) + self.rows[1]:SetPoint("RIGHT", CliqueConfigPage1Column2, "RIGHT", 0, 0) + + for i = 2, MAX_ROWS do + self.rows[i]:ClearAllPoints() + self.rows[i]:SetPoint("TOPLEFT", self.rows[i - 1], "BOTTOMLEFT") + self.rows[i]:SetPoint("RIGHT", CliqueConfigPage1Column2, "RIGHT", 0, 0) + end + + -- Set text elements using localized values + _G[self:GetName() .. "TitleText"]:SetText(L["Clique Binding Configuration"]) + + self.dialog = _G["CliqueDialog"] + self.dialog.title = _G["CliqueDialogTitleText"] + + self.dialog.title:SetText(L["Clique: 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."] + self.dialog.desc:SetText(desc) + + self.page1.column1:SetText(L["Action"]) + self.page1.column2:SetText(L["Binding"]) + + -- Set columns up to handle sorting + self.page1.column1.sortType = "name" + self.page1.column2.sortType = "key" + self.page1.sortType = self.page1.column2.sortType + + self.page1.button_spell:SetText(L["Bind spell"]) + self.page1.button_other:SetText(L["Bind other"]) + self.page1.button_options:SetText(L["Options"]) + + self.page2.button_save:SetText(L["Save"]) + self.page2.button_cancel:SetText(L["Cancel"]) + + self.page1:Show() +end + +function CliqueConfig:Column_OnClick(frame, button) + self.page1.sortType = frame.sortType + self:UpdateList() +end + +function CliqueConfig:HijackSpellbook() + self.spellbookButtons = {} + + for idx = 1, 12 do + local parent = getglobal("SpellButton" .. idx) + local button = CreateFrame("Button", "CliqueSpellbookButton" .. idx, parent, "CliqueSpellbookButtonTemplate") + button.spellbutton = parent + button:EnableKeyboard(false) + button:EnableMouseWheel(true) + button:RegisterForClicks("AnyDown") + button:SetID(parent:GetID()) + self.spellbookButtons[idx] = button + end + + local function showHideHandler(frame) + self:EnableSpellbookButtons() + end + SpellBookFrame:HookScript("OnShow", showHideHandler) + SpellBookFrame:HookScript("OnHide", showHideHandler) + + -- TODO: This isn't a great way to do this, but for now + hooksecurefunc("SpellBookSkillLineTab_OnClick", showHideHandler) + self:EnableSpellbookButtons() +end + +function CliqueConfig:EnableSpellbookButtons() + local enabled; + + if self.page1:IsVisible() and SpellBookFrame:IsVisible() then + enabled = true + self:SetNotification("Your spellbook is open. You can mouse over a spell in your spellbook and click or press a key conbination to add it to your bindings configuration") + else + method = false + self:ClearNotification() + end + + if self.spellbookButtons then + for idx, button in ipairs(self.spellbookButtons) do + if enabled and button.spellbutton:IsEnabled() == 1 then + button:Show() + else + button:Hide() + end + end + end +end + +-- Spellbook button functions +function CliqueConfig:Spellbook_EnableKeyboard(button, motion) + button:EnableKeyboard(true) +end + +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 + 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 succ, err = addon:AddBinding{ + key = prefix .. key, + type = "spell", + spell = name, + icon = texture + } + + if not succ then + CliqueConfig:SetNotification(err) + else + CliqueConfig:UpdateList() + end +end + +function CliqueConfig:Button_OnClick(button) + -- Click handler for "Bind spell" button + if button == self.page1.button_spell then + if SpellBookFrame and not SpellBookFrame:IsVisible() then + ShowUIPanel(SpellBookFrame) + end + + -- Click handler for "Bind other" button + elseif button == self.page1.button_other then + local config = CliqueConfig + local menu = { + { + text = L["Select a binding type"], + isTitle = true + }, + { + text = L["Target clicked unit"], + func = function() + config.page1:Hide() + config.page2.bindType = "target" + config.page2:Show() + end, + }, + { + text = L["Open unit menu"], + func = function() + config.page1:Hide() + config.page2.bindType = "menu" + config.page2:Show() + end, + }, + { + text = L["Run custom macro"], + func = function() + config.page1:Hide() + config.page2.bindType = "macro" + config.page2:Show() + end, + }, + } + UIDropDownMenu_SetAnchor(self.dropdown, 0, 0, "BOTTOMLEFT", self.page1.button_other, "TOP") + EasyMenu(menu, self.dropdown, nil, 0, 0, nil, nil) + + -- Click handler for "Edit" button + elseif button == self.page1.button_options then + InterfaceOptionsFrame_OpenToCategory("Clique") + elseif button == self.page2.button_cancel then + self.page2:Hide() + self.page1:Show() + elseif button == self.page2.button_cancel then + self.page2:Hide() + self.page1:Show() + end +end + +function CliqueConfig:SetNotification(text) +end + +function CliqueConfig:ClearNotification() +end + +local memoizeBindings = setmetatable({}, {__index = function(t, k, v) + local binbits = addon:GetBinaryBindingKey(k) + rawset(t, k, binbits) + return binbits +end}) + +local compareFunctions; +compareFunctions = { + name = function(a, b) + local texta = addon:GetBindingActionText(a) + local textb = addon:GetBindingActionText(b) + if texta == textb then + return compareFunctions.key(a, b) + end + return texta < textb + end, + key = function(a, b) + local keya = addon:GetBindingKey(a) + local keyb = addon:GetBindingKey(b) + if keya == keyb then + return memoizeBindings[a] < memoizeBindings[b] + else + return keya < keyb + end + end, + binding = function(a, b) + local mem = memoizeBindings + return mem[a] < mem[b] + end, +} + +CliqueConfig.binds = {} +function CliqueConfig:UpdateList() + local page = self.page1 + local binds = Clique.profile.binds + + -- GUI not created yet + if not page then + return + end + + -- Sort the bindings + local sort = {} + for uid, entry in pairs(binds) do + sort[#sort + 1] = entry + end + + if page.sortType then + table.sort(sort, compareFunctions[page.sortType]) + else + table.sort(sort, compareFunctions.key) + end + + -- Enable or disable the scroll bar + if #sort > MAX_ROWS - 1 then + -- Set up the scrollbar for the item list + page.slider:SetMinMaxValues(0, #sort - MAX_ROWS) + + -- Adjust and show + if not page.slider:IsShown() then + -- Adjust column positions + for idx, row in ipairs(self.rows) do + row.bind:SetWidth(90) + end + page.slider:SetValue(0) + page.slider:Show() + end + elseif page.slider:IsShown() then + -- Move column positions back and hide the slider + for idx, row in ipairs(self.rows) do + row.bind:SetWidth(105) + end + page.slider:Hide() + end + + -- Update the rows in the list + local offset = page.slider:GetValue() or 0 + for idx, row in ipairs(self.rows) do + local offsetIndex = offset + idx + if sort[offsetIndex] then + local bind = sort[offsetIndex] + row.icon:SetTexture(addon:GetBindingIcon(bind)) + row.name:SetText(addon:GetBindingActionText(bind)) + --row.type:SetText(bind.type) + row.bind:SetText(addon:GetBindingKeyComboText(bind)) + row:Show() + else + row:Hide() + end + end +end + +function CliqueConfig:ClearEditPage() +end + +function CliqueConfig:ShowEditPage() + self:ClearEditPage() + self.page1:Hide() + self.page3:Show() +end + +function CliqueConfig:Save_OnClick(button, button, down) +end + +function CliqueConfig:Cancel_OnClick(button, button, down) + self:ClearEditPage() + self.page3:Hide() + self.page1:Show() +end + diff --git a/Clique.toc b/Clique.toc index a432574..0942c8c 100755 --- a/Clique.toc +++ b/Clique.toc @@ -13,12 +13,12 @@ ClickCastTemplate.xml Clique.xml -CliqueUtils.lua Clique.lua -CliqueConfig.lua -CliqueOptionsPanel.lua +Utils.lua +BindConfig.lua +OptionsPanel.lua -CliqueTest.xml -CliqueTest.lua +HeaderTest.xml +HeaderTest.lua BlizzardFrames.lua diff --git a/CliqueConfig.lua b/CliqueConfig.lua deleted file mode 100755 index 5b7aad2..0000000 --- a/CliqueConfig.lua +++ /dev/null @@ -1,351 +0,0 @@ -local addonName, addon = ... -local L = addon.L - -local MAX_ROWS = 12 - -function CliqueConfig:OnShow() - if not self.initialized then - self:SetupGUI() - self:HijackSpellbook() - self.initialized = true - end - - self:UpdateList() - self:EnableSpellbookButtons() -end - - -function CliqueConfig:SetupGUI() - self.rows = {} - for i = 1, MAX_ROWS do - self.rows[i] = CreateFrame("Button", "CliqueRow" .. i, self.page1, "CliqueRowTemplate") - end - - self.rows[1]:ClearAllPoints() - self.rows[1]:SetPoint("TOPLEFT", "CliqueConfigPage1Column1", "BOTTOMLEFT", 0, -3) - self.rows[1]:SetPoint("RIGHT", CliqueConfigPage1Column2, "RIGHT", 0, 0) - - for i = 2, MAX_ROWS do - self.rows[i]:ClearAllPoints() - self.rows[i]:SetPoint("TOPLEFT", self.rows[i - 1], "BOTTOMLEFT") - self.rows[i]:SetPoint("RIGHT", CliqueConfigPage1Column2, "RIGHT", 0, 0) - end - - -- Set text elements using localized values - _G[self:GetName() .. "TitleText"]:SetText(L["Clique Binding Configuration"]) - - self.dialog = _G["CliqueDialog"] - self.dialog.title = _G["CliqueDialogTitleText"] - - self.dialog.title:SetText(L["Clique: 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."] - self.dialog.desc:SetText(desc) - - self.page1.column1:SetText(L["Action"]) - self.page1.column2:SetText(L["Binding"]) - - -- Set columns up to handle sorting - self.page1.column1.sortType = "name" - self.page1.column2.sortType = "key" - self.page1.sortType = self.page1.column2.sortType - - self.page1.button_spell:SetText(L["Bind spell"]) - self.page1.button_other:SetText(L["Bind other"]) - self.page1.button_options:SetText(L["Options"]) - - self.page2.button_save:SetText(L["Save"]) - self.page2.button_cancel:SetText(L["Cancel"]) - - self.page1:Show() -end - -function CliqueConfig:Column_OnClick(frame, button) - self.page1.sortType = frame.sortType - self:UpdateList() -end - -function CliqueConfig:HijackSpellbook() - self.spellbookButtons = {} - - for idx = 1, 12 do - local parent = getglobal("SpellButton" .. idx) - local button = CreateFrame("Button", "CliqueSpellbookButton" .. idx, parent, "CliqueSpellbookButtonTemplate") - button.spellbutton = parent - button:EnableKeyboard(false) - button:EnableMouseWheel(true) - button:RegisterForClicks("AnyDown") - button:SetID(parent:GetID()) - self.spellbookButtons[idx] = button - end - - local function showHideHandler(frame) - self:EnableSpellbookButtons() - end - SpellBookFrame:HookScript("OnShow", showHideHandler) - SpellBookFrame:HookScript("OnHide", showHideHandler) - - -- TODO: This isn't a great way to do this, but for now - hooksecurefunc("SpellBookSkillLineTab_OnClick", showHideHandler) - self:EnableSpellbookButtons() -end - -function CliqueConfig:EnableSpellbookButtons() - local enabled; - - if self.page1:IsVisible() and SpellBookFrame:IsVisible() then - enabled = true - self:SetNotification("Your spellbook is open. You can mouse over a spell in your spellbook and click or press a key conbination to add it to your bindings configuration") - else - method = false - self:ClearNotification() - end - - if self.spellbookButtons then - for idx, button in ipairs(self.spellbookButtons) do - if enabled and button.spellbutton:IsEnabled() == 1 then - button:Show() - else - button:Hide() - end - end - end -end - --- Spellbook button functions -function CliqueConfig:Spellbook_EnableKeyboard(button, motion) - button:EnableKeyboard(true) -end - -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 - 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 succ, err = addon:AddBinding{ - key = prefix .. key, - type = "spell", - spell = name, - icon = texture - } - - if not succ then - CliqueConfig:SetNotification(err) - else - CliqueConfig:UpdateList() - end -end - -function CliqueConfig:Button_OnClick(button) - -- Click handler for "Bind spell" button - if button == self.page1.button_spell then - if SpellBookFrame and not SpellBookFrame:IsVisible() then - ShowUIPanel(SpellBookFrame) - end - - -- Click handler for "Bind other" button - elseif button == self.page1.button_other then - local config = CliqueConfig - local menu = { - { - text = L["Select a binding type"], - isTitle = true - }, - { - text = L["Target clicked unit"], - func = function() - config.page1:Hide() - config.page2.bindType = "target" - config.page2:Show() - end, - }, - { - text = L["Open unit menu"], - func = function() - config.page1:Hide() - config.page2.bindType = "menu" - config.page2:Show() - end, - }, - { - text = L["Run custom macro"], - func = function() - config.page1:Hide() - config.page2.bindType = "macro" - config.page2:Show() - end, - }, - } - UIDropDownMenu_SetAnchor(self.dropdown, 0, 0, "BOTTOMLEFT", self.page1.button_other, "TOP") - EasyMenu(menu, self.dropdown, nil, 0, 0, nil, nil) - - -- Click handler for "Edit" button - elseif button == self.page1.button_options then - InterfaceOptionsFrame_OpenToCategory("Clique") - elseif button == self.page2.button_cancel then - self.page2:Hide() - self.page1:Show() - elseif button == self.page2.button_cancel then - self.page2:Hide() - self.page1:Show() - end -end - -function CliqueConfig:SetNotification(text) -end - -function CliqueConfig:ClearNotification() -end - -local memoizeBindings = setmetatable({}, {__index = function(t, k, v) - local binbits = addon:GetBinaryBindingKey(k) - rawset(t, k, binbits) - return binbits -end}) - -local compareFunctions; -compareFunctions = { - name = function(a, b) - local texta = addon:GetBindingActionText(a) - local textb = addon:GetBindingActionText(b) - if texta == textb then - return compareFunctions.key(a, b) - end - return texta < textb - end, - key = function(a, b) - local keya = addon:GetBindingKey(a) - local keyb = addon:GetBindingKey(b) - if keya == keyb then - return memoizeBindings[a] < memoizeBindings[b] - else - return keya < keyb - end - end, - binding = function(a, b) - local mem = memoizeBindings - return mem[a] < mem[b] - end, -} - -CliqueConfig.binds = {} -function CliqueConfig:UpdateList() - local page = self.page1 - local binds = Clique.profile.binds - - -- GUI not created yet - if not page then - return - end - - -- Sort the bindings - local sort = {} - for uid, entry in pairs(binds) do - sort[#sort + 1] = entry - end - - if page.sortType then - table.sort(sort, compareFunctions[page.sortType]) - else - table.sort(sort, compareFunctions.key) - end - - -- Enable or disable the scroll bar - if #sort > MAX_ROWS - 1 then - -- Set up the scrollbar for the item list - page.slider:SetMinMaxValues(0, #sort - MAX_ROWS) - - -- Adjust and show - if not page.slider:IsShown() then - -- Adjust column positions - for idx, row in ipairs(self.rows) do - row.bind:SetWidth(90) - end - page.slider:SetValue(0) - page.slider:Show() - end - elseif page.slider:IsShown() then - -- Move column positions back and hide the slider - for idx, row in ipairs(self.rows) do - row.bind:SetWidth(105) - end - page.slider:Hide() - end - - -- Update the rows in the list - local offset = page.slider:GetValue() or 0 - for idx, row in ipairs(self.rows) do - local offsetIndex = offset + idx - if sort[offsetIndex] then - local bind = sort[offsetIndex] - row.icon:SetTexture(addon:GetBindingIcon(bind)) - row.name:SetText(addon:GetBindingActionText(bind)) - --row.type:SetText(bind.type) - row.bind:SetText(addon:GetBindingKeyComboText(bind)) - row:Show() - else - row:Hide() - end - end -end - -function CliqueConfig:ClearEditPage() -end - -function CliqueConfig:ShowEditPage() - self:ClearEditPage() - self.page1:Hide() - self.page3:Show() -end - -function CliqueConfig:Save_OnClick(button, button, down) -end - -function CliqueConfig:Cancel_OnClick(button, button, down) - self:ClearEditPage() - self.page3:Hide() - self.page1:Show() -end - diff --git a/CliqueOptionsPanel.lua b/CliqueOptionsPanel.lua deleted file mode 100644 index 27f067b..0000000 --- a/CliqueOptionsPanel.lua +++ /dev/null @@ -1,15 +0,0 @@ -local addonName, addon = ... - -local panel = CreateFrame("Frame") -panel.name = "Clique" - -panel:SetScript("OnShow", function(self) - if not panel.initialized then - panel:CreateOptions() - end -end) - -function panel:CreateOptions() -end - -InterfaceOptions_AddCategory(panel) diff --git a/CliqueTest.lua b/CliqueTest.lua deleted file mode 100644 index 74d286a..0000000 --- a/CliqueTest.lua +++ /dev/null @@ -1,56 +0,0 @@ -local addonName, addon = ... - -function addon:RunTest() - function CliqueTest_Unit_OnShow(self) - local unit = self:GetAttribute("unit") - if not unit or not UnitExists(unit) then - return - end - local name = UnitName(unit) - self.name:SetText(name) - self.healthBar:SetMinMaxValues(0, UnitHealthMax(unit)) - self.powerBar:SetMinMaxValues(0, UnitPowerMax(unit)) - self.healthBar:SetValue(UnitHealth(unit)) - self.powerBar:SetValue(UnitPower(unit)) - end - - -- Create a fake "group header" to test things properly - local groupheader = CreateFrame("Button", "MyGroupHeader", UIParent, "SecureGroupHeaderTemplate") - SecureHandler_OnLoad(groupheader) - - -- Ensure the group header has a reference to the click-cast header - groupheader:SetFrameRef("clickcast_header", addon.header) - - -- Set header attributes - groupheader:SetAttribute("showParty", true) - groupheader:SetAttribute("showRaid", true) - groupheader:SetAttribute("showPlayer", true) - groupheader:SetAttribute("showSolo", true) - groupheader:SetAttribute("maxColumns", 8) - groupheader:SetAttribute("unitsPerColumn", 5) - groupheader:SetAttribute("columnAnchorPoint", "TOP") - groupheader:SetAttribute("point", "LEFT") - groupheader:SetAttribute("template", "CliqueTest_UnitTemplate") - groupheader:SetAttribute("templateType", "Button") - groupheader:SetAttribute("xOffset", -1) - groupheader:SetAttribute("yOffset", -1) - - -- Set up the group header to display a solo/party/raid frame - groupheader:SetAttribute("initialConfigFunction", [==[ - self:SetAttribute("shift-type1", "spell") - self:SetAttribute("shift-spell1", "Regrowth") - - self:SetAttribute("type-cliquebutton1", "spell") - self:SetAttribute("spell-cliquebutton1", "Lifebloom") - - -- Register this frame with the global click-cast header - local header = self:GetParent():GetFrameRef("clickcast_header") - header:SetAttribute("clickcast_button", self) - header:RunAttribute("clickcast_register") - ]==]) - - groupheader:SetPoint("CENTER", UIParent, "CENTER", 0, 0) - groupheader:Show() -end - - diff --git a/CliqueTest.xml b/CliqueTest.xml deleted file mode 100644 index 615f47e..0000000 --- a/CliqueTest.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - diff --git a/CliqueUtils.lua b/CliqueUtils.lua deleted file mode 100644 index e7b29ac..0000000 --- a/CliqueUtils.lua +++ /dev/null @@ -1,142 +0,0 @@ -local addonName, addon = ... -local L = addon.L - --- Returns the prefix string for the current keyboard state. --- --- Arguments: --- split - Whether or not to split the modifier keys into left and right components - -function addon:GetPrefixString(split) - shift, lshift, rshift = IsShiftKeyDown(), IsLeftShiftKeyDown(), IsRightShiftKeyDown() - ctrl, lctrl, rctrl = IsControlKeyDown(), IsLeftControlKeyDown(), IsRightControlKeyDown() - alt, lalt, ralt = IsAltKeyDown(), IsLeftAltKeyDown() IsRightAltKeyDown() - - if not extended then - shift = shift or lshift or rshift - ctrl = ctrl or lctrl or rctrl - alt = alt or lalt or ralt - - lshift, rshift = false, false - lctrl, rctrl = false, false - lalt, ralt = false, false - end - - local prefix = "" - if shift then - prefix = ((lshift and "LSHIFT-") or (rshift and "RSHIFT-") or "SHIFT-") .. prefix - end - if ctrl then - prefix = ((lctrl and "LCTRL-") or (rctrl and "RCTRL-") or "CTRL-") .. prefix - end - if alt then - prefix = ((lalt and "LALT-") or (ralt and "RALT-") or "ALT-") .. prefix - end - - return prefix -end - -local convertMap = setmetatable({ - LSHIFT = L["LShift"], - RSHIFT = L["RShift"], - SHIFT = L["Shift"], - LCTRL = L["LCtrl"], - RCTRL = L["RCtrl"], - CTRL = L["Ctrl"], - LALT = L["LAlt"], - RALT = L["RAlt"], - ALT = L["Alt"], - BUTTON1 = L["LeftButton"], - BUTTON2 = L["RightButton"], - BUTTON3 = L["MiddleButton"], -}, { - __index = function(t, k, v) - if k:match("^BUTTON(%d+)$") then - return k:gsub("^BUTTON(%d+)$", "Button%1") - else - return k:sub(1,1) .. k:sub(2, -1):lower() - end - end, -}) - -local function convert(item, ...) - if not item then - return "" - else - local mapItem = convertMap[item] - item = mapItem and mapItem or item - - if select("#", ...) > 0 then - return item, "-", convert(...) - else - return item, convert(...) - end - end -end - -function addon:GetBindingIcon(binding) - local btype = binding.type - if btype == "menu" then - --return "Interface\\Icons\\Trade_Engineering" - return nil - elseif btype == "target" then - --return "Interface\\Icons\\Ability_Mage_IncantersAbsorbtion" - return nil - else - return binding.icon or "Interface\\Icons\\INV_Misc_QuestionMark" - end -end - -function addon:GetBindingKeyComboText(binding) - return strconcat(convert(strsplit("-", binding.key))) -end - -function addon:GetBindingActionText(binding) - local btype = binding.type - if btype == "menu" then - return L["Show unit menu"] - elseif btype == "target" then - return L["Target clicked unit"] - elseif btype == "spell" then - if binding.rank then - return L["Cast %s (Rank %d)"]:format(binding.spell, binding.rank) - 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 - -function addon:GetBindingKey(binding) - local key = binding.key:match("[^%-]+$") - return key -end - -local binMap = { - ALT = 1, - LALT = 2, - RALT = 3, - CTRL = 4, - LCTRL = 5, - LCTRL = 6, - SHIFT = 7, - LSHIFT = 8, - RSHIFT = 9, -} - -function addon:GetBinaryBindingKey(binding) - ret = {"0", "0", "0", "0", "0", "0", "0", "0", "0"} - splits = {strsplit("-", binding.key)} - for idx, modifier in ipairs(splits) do - local bit = binMap[modifier] - if bit then - ret[bit] = "1" - else - ret[10] = modifier - end - end - return table.concat(ret) -end diff --git a/HeaderTest.lua b/HeaderTest.lua new file mode 100644 index 0000000..74d286a --- /dev/null +++ b/HeaderTest.lua @@ -0,0 +1,56 @@ +local addonName, addon = ... + +function addon:RunTest() + function CliqueTest_Unit_OnShow(self) + local unit = self:GetAttribute("unit") + if not unit or not UnitExists(unit) then + return + end + local name = UnitName(unit) + self.name:SetText(name) + self.healthBar:SetMinMaxValues(0, UnitHealthMax(unit)) + self.powerBar:SetMinMaxValues(0, UnitPowerMax(unit)) + self.healthBar:SetValue(UnitHealth(unit)) + self.powerBar:SetValue(UnitPower(unit)) + end + + -- Create a fake "group header" to test things properly + local groupheader = CreateFrame("Button", "MyGroupHeader", UIParent, "SecureGroupHeaderTemplate") + SecureHandler_OnLoad(groupheader) + + -- Ensure the group header has a reference to the click-cast header + groupheader:SetFrameRef("clickcast_header", addon.header) + + -- Set header attributes + groupheader:SetAttribute("showParty", true) + groupheader:SetAttribute("showRaid", true) + groupheader:SetAttribute("showPlayer", true) + groupheader:SetAttribute("showSolo", true) + groupheader:SetAttribute("maxColumns", 8) + groupheader:SetAttribute("unitsPerColumn", 5) + groupheader:SetAttribute("columnAnchorPoint", "TOP") + groupheader:SetAttribute("point", "LEFT") + groupheader:SetAttribute("template", "CliqueTest_UnitTemplate") + groupheader:SetAttribute("templateType", "Button") + groupheader:SetAttribute("xOffset", -1) + groupheader:SetAttribute("yOffset", -1) + + -- Set up the group header to display a solo/party/raid frame + groupheader:SetAttribute("initialConfigFunction", [==[ + self:SetAttribute("shift-type1", "spell") + self:SetAttribute("shift-spell1", "Regrowth") + + self:SetAttribute("type-cliquebutton1", "spell") + self:SetAttribute("spell-cliquebutton1", "Lifebloom") + + -- Register this frame with the global click-cast header + local header = self:GetParent():GetFrameRef("clickcast_header") + header:SetAttribute("clickcast_button", self) + header:RunAttribute("clickcast_register") + ]==]) + + groupheader:SetPoint("CENTER", UIParent, "CENTER", 0, 0) + groupheader:Show() +end + + diff --git a/HeaderTest.xml b/HeaderTest.xml new file mode 100644 index 0000000..615f47e --- /dev/null +++ b/HeaderTest.xml @@ -0,0 +1,53 @@ + + + + diff --git a/OptionsPanel.lua b/OptionsPanel.lua new file mode 100644 index 0000000..27f067b --- /dev/null +++ b/OptionsPanel.lua @@ -0,0 +1,15 @@ +local addonName, addon = ... + +local panel = CreateFrame("Frame") +panel.name = "Clique" + +panel:SetScript("OnShow", function(self) + if not panel.initialized then + panel:CreateOptions() + end +end) + +function panel:CreateOptions() +end + +InterfaceOptions_AddCategory(panel) diff --git a/Utils.lua b/Utils.lua new file mode 100644 index 0000000..e7b29ac --- /dev/null +++ b/Utils.lua @@ -0,0 +1,142 @@ +local addonName, addon = ... +local L = addon.L + +-- Returns the prefix string for the current keyboard state. +-- +-- Arguments: +-- split - Whether or not to split the modifier keys into left and right components + +function addon:GetPrefixString(split) + shift, lshift, rshift = IsShiftKeyDown(), IsLeftShiftKeyDown(), IsRightShiftKeyDown() + ctrl, lctrl, rctrl = IsControlKeyDown(), IsLeftControlKeyDown(), IsRightControlKeyDown() + alt, lalt, ralt = IsAltKeyDown(), IsLeftAltKeyDown() IsRightAltKeyDown() + + if not extended then + shift = shift or lshift or rshift + ctrl = ctrl or lctrl or rctrl + alt = alt or lalt or ralt + + lshift, rshift = false, false + lctrl, rctrl = false, false + lalt, ralt = false, false + end + + local prefix = "" + if shift then + prefix = ((lshift and "LSHIFT-") or (rshift and "RSHIFT-") or "SHIFT-") .. prefix + end + if ctrl then + prefix = ((lctrl and "LCTRL-") or (rctrl and "RCTRL-") or "CTRL-") .. prefix + end + if alt then + prefix = ((lalt and "LALT-") or (ralt and "RALT-") or "ALT-") .. prefix + end + + return prefix +end + +local convertMap = setmetatable({ + LSHIFT = L["LShift"], + RSHIFT = L["RShift"], + SHIFT = L["Shift"], + LCTRL = L["LCtrl"], + RCTRL = L["RCtrl"], + CTRL = L["Ctrl"], + LALT = L["LAlt"], + RALT = L["RAlt"], + ALT = L["Alt"], + BUTTON1 = L["LeftButton"], + BUTTON2 = L["RightButton"], + BUTTON3 = L["MiddleButton"], +}, { + __index = function(t, k, v) + if k:match("^BUTTON(%d+)$") then + return k:gsub("^BUTTON(%d+)$", "Button%1") + else + return k:sub(1,1) .. k:sub(2, -1):lower() + end + end, +}) + +local function convert(item, ...) + if not item then + return "" + else + local mapItem = convertMap[item] + item = mapItem and mapItem or item + + if select("#", ...) > 0 then + return item, "-", convert(...) + else + return item, convert(...) + end + end +end + +function addon:GetBindingIcon(binding) + local btype = binding.type + if btype == "menu" then + --return "Interface\\Icons\\Trade_Engineering" + return nil + elseif btype == "target" then + --return "Interface\\Icons\\Ability_Mage_IncantersAbsorbtion" + return nil + else + return binding.icon or "Interface\\Icons\\INV_Misc_QuestionMark" + end +end + +function addon:GetBindingKeyComboText(binding) + return strconcat(convert(strsplit("-", binding.key))) +end + +function addon:GetBindingActionText(binding) + local btype = binding.type + if btype == "menu" then + return L["Show unit menu"] + elseif btype == "target" then + return L["Target clicked unit"] + elseif btype == "spell" then + if binding.rank then + return L["Cast %s (Rank %d)"]:format(binding.spell, binding.rank) + 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 + +function addon:GetBindingKey(binding) + local key = binding.key:match("[^%-]+$") + return key +end + +local binMap = { + ALT = 1, + LALT = 2, + RALT = 3, + CTRL = 4, + LCTRL = 5, + LCTRL = 6, + SHIFT = 7, + LSHIFT = 8, + RSHIFT = 9, +} + +function addon:GetBinaryBindingKey(binding) + ret = {"0", "0", "0", "0", "0", "0", "0", "0", "0"} + splits = {strsplit("-", binding.key)} + for idx, modifier in ipairs(splits) do + local bit = binMap[modifier] + if bit then + ret[bit] = "1" + else + ret[10] = modifier + end + end + return table.concat(ret) +end -- 1.7.9.5