Mercurial > wow > skeletonkey
diff SkeletonKey/BindingsUI.lua @ 17:500f9b2bd9ac
- for RegisterAction, use a function table instead of that if/then rats nest
- consequently pet bar actions work now
- unlocalize bindings data
- activate keyslot input manually instead of on mouse over
- activate checkbox to keep input mode active
- dynamic buttons update in real time for petaction/talent/profession spells
author | Nenue |
---|---|
date | Sat, 30 Jul 2016 00:08:00 -0400 |
parents | cdd387d39137 |
children | 91398d284a99 |
line wrap: on
line diff
--- a/SkeletonKey/BindingsUI.lua Fri Jul 29 21:18:15 2016 -0400 +++ b/SkeletonKey/BindingsUI.lua Sat Jul 30 00:08:00 2016 -0400 @@ -6,17 +6,15 @@ local kb, print = LibStub("LibKraken").register(KeyBinder, 'KeySlot') local BINDS_PER_ROW = 2 +local BINDING_TYPE_SPECIALIZATION = 3 +local BINDING_TYPE_CHARACTER = 2 +local BINDING_TYPE_GLOBAL = 1 local BUTTON_HSPACING = 128 local BUTTON_SPACING = 4 local BUTTON_PADDING = 12 -local BINDING_TYPE_SPECIALIZATION = 3 -local BINDING_TYPE_CHARACTER = 2 -local BINDING_TYPE_GLOBAL = 1 local KEY_BUTTON_SIZE = 48 -local MIN_BIND_SLOTS = 32 -local TAB_OFFSET = 12 +local NUM_KEY_SLOTS = BINDS_PER_ROW * 8 local TAB_HEIGHT = 40 -local TAB_SPACING = 2 local BINDING_SCHEME_COLOR = { [BINDING_TYPE_GLOBAL] = {0,.125,.5,.5}, @@ -36,12 +34,27 @@ local restingAlpha = 0.7 local fadeTime, fadeDelay = .30, 0.15 -local numButtons = BINDS_PER_ROW * 8 local saveButton -local KeyButton_OnKey = function(self, key) - kb.StoreBinding(self.saveTarget, key) - kb:SetScript('OnKeyUp', nil) - kb:SetScript('OnKeyDown', nil) + +local KeyButton_OnKeyDown = function(self, key) +end +local KeyButton_OnKeyUp = function(self, key) + if key == 'ESCAPE' then + kb.DeactivateSlot(kb.saveTarget) + else + + if key:match('[RL]SHIFT') or key:match('[RL]ALT') or key:match('[RL]CTRL') then + return + end + kb.SaveSlot(kb.saveTarget, key) + + if not kb.stickyMode then + kb:SetScript('OnKeyUp', nil) + kb:SetScript('OnKeyDown', nil) + kb.saveTarget = nil + end + end + kb.ui() end local KeyButton_OnClick = function(self, click) @@ -51,7 +64,17 @@ if cursorType then kb.DropToSlot(self) else + if IsShiftKeyDown() then + kb.stickyMode = true + KeyBinderStickyMode:SetChecked(true) + + kb.saveTarget = button + kb:SetScript('OnKeyUp', KeyButton_OnKeyUp) + kb:SetScript('OnKeyDown', KeyButton_OnKeyDown) + end + kb.ActivateSlot(self) + kb.ui() end elseif click == 'RightButton' then kb.ReleaseSlot(self) @@ -119,7 +142,6 @@ else if self.active then self.active = nil - self:SetScript('OnKeyDown', nil) end end end @@ -141,6 +163,10 @@ kb.scrollOffset = ceil(kb.scrollOffset - (delta * BINDS_PER_ROW)) end + for i = 1, #kb.buttons do + kb.buttons[i]:SetSize(KEY_BUTTON_SIZE,KEY_BUTTON_SIZE) + end + kb.ui(true) end @@ -159,7 +185,38 @@ kb.ConfirmBindings() end + local KeyBinder_Initialize = function() + do + local leftSlot, upSlot + for index = 1, NUM_KEY_SLOTS do + + local button = CreateFrame('CheckButton', 'KeyBinderSlot'..index, kb, 'KeyButton') + button:SetScript('OnClick', KeyButton_OnClick) + button:SetScript('OnUpdate', KeyButton_OnUpdate) + button:SetScript('OnDragStart', KeyButton_OnDragStart) + button:SetScript('OnReceiveDrag', KeyButton_OnReceiveDrag) + button:RegisterForClicks('AnyUp') + + + local newRow = (mod(index, BINDS_PER_ROW) == 1) + + if index == 1 then + button:SetPoint('TOPLEFT', kb.bg, 'TOPLEFT', BUTTON_PADDING, - BUTTON_PADDING) + upSlot = button + elseif newRow then + button:SetPoint('TOPLEFT', upSlot, 'BOTTOMLEFT', 0, -BUTTON_SPACING) + upSlot = button + else + button:SetPoint('TOPLEFT', leftSlot, 'TOPRIGHT', BUTTON_HSPACING, 0) + end + + button:SetSize(KEY_BUTTON_SIZE, KEY_BUTTON_SIZE) + button:Show() + kb.buttons[index] = button + leftSlot = button + end + end kb.scrollOffset = 0 @@ -170,8 +227,8 @@ kb.UIPanelGrowth = {'TOPLEFT', nil, 'BOTTOMLEFT', 0, -2 } kb.UIPanelSize = {84, 32 } kb.UIPanelIcon = {24, 32, 'LEFT', -12, 0} - kb.controlsAnchor = {'BOTTOMLEFT', kb.footer, BUTTON_PADDING, BUTTON_PADDING } - kb.controlsGrowth = {'BOTTOMLEFT', nil, 'BOTTOMRIGHT', BUTTON_SPACING, 0} + kb.controlsAnchor = {'BOTTOMRIGHT', kb.footer, -BUTTON_PADDING, BUTTON_PADDING } + kb.controlsGrowth = {'BOTTOMRIGHT', nil, 'BOTTOMLEFT', -BUTTON_SPACING, 0} -- order of these is important kb:tab('KeyBinderGlobalTab', @@ -185,8 +242,9 @@ --portraitLayers[1] = KeyBinderCharacterTab.icon + -- todo: find some generic icons for refresh/key input,etc - saveButton = kb:button('KeyBinderSaveButton', 'Refresh', 'Reload current bindings and refresh panel.', SaveButton_OnClick) + saveButton = kb:button('KeyBinderSaveButton', 'Update', 'Reload current bindings and refresh panel.', SaveButton_OnClick) --restoreButton = kb:button('KeyBinderRestoreButton', 'Discard', 'Revert all changes.', CancelButton_OnClick) --clearButton = kb:button('KeyBinderClearButton', 'Clear Page', 'Release all buttons.', ResetButton_OnClick) @@ -213,7 +271,17 @@ function() OpenAllBags() end, "Interface\\BUTTONS\\UI-MicroButtonCharacter-Up", {0, 1, .4, 1}) + KeyBinderStickyMode:SetScript('OnClick', function(self) + kb.stickyMode = self:GetChecked() + if not kb.stickyMode then + if kb.saveTarget then + kb.DeactivateSlot(kb.saveTarget) + end + end + + kb.ui() + end) kb.info:SetPoint('TOPLEFT', kb.UIPanels[1], 'BOTTOMLEFT', 0, -BUTTON_SPACING) HEADER_OFFSET = kb.UIPanels[1]:GetHeight() + BUTTON_PADDING @@ -228,48 +296,23 @@ --- Retrieves button at index; creates said button and instates any stored parameters -do - local leftSlot, upSlot - kb.GetSlot = function(index) - local slot = index + kb.scrollOffset - if not kb.buttons[index] then - local button = CreateFrame('CheckButton', 'KeyBinderSlot'..index, kb, 'KeyButton') - button:SetScript('OnClick', KeyButton_OnClick) - button:SetScript('OnUpdate', KeyButton_OnUpdate) - button:SetScript('OnDragStart', KeyButton_OnDragStart) - button:SetScript('OnReceiveDrag', KeyButton_OnReceiveDrag) - button:RegisterForClicks('AnyUp') - - - local newRow = (mod(index, BINDS_PER_ROW) == 1) - - if index == 1 then - button:SetPoint('TOPLEFT', kb.bg, 'TOPLEFT', BUTTON_PADDING, - BUTTON_PADDING) - upSlot = button - elseif newRow then - button:SetPoint('TOPLEFT', upSlot, 'BOTTOMLEFT', 0, -BUTTON_SPACING) - upSlot = button - else - button:SetPoint('TOPLEFT', leftSlot, 'TOPRIGHT', BUTTON_HSPACING, 0) - end - - button:SetSize(KEY_BUTTON_SIZE, KEY_BUTTON_SIZE) - button:Show() - kb.buttons[index] = button - leftSlot = button - end - return kb.buttons[index] - end +kb.ActivateSlot = function(button) + kb.saveTarget = button + kb:SetScript('OnKeyUp', KeyButton_OnKeyUp) + kb:SetScript('OnKeyDown', KeyButton_OnKeyDown) + kb.savingText:ClearAllPoints() + kb.savingText:SetParent(button) + kb.savingText:SetPoint('BOTTOMLEFT', button, 'TOPLEFT', 0, 0) end +kb.DeactivateSlot = function(button) + kb.saveTarget = nil + kb:SetScript('OnKeyUp', nil) + kb:SetScript('OnKeyDown', nil) +end -kb.ActivateSlot = function(self) - kb.saveTarget = self - kb:SetScript('OnKeyUp', KeyButton_OnKey) - kb.bg:SetColorTexture(0,.5,0,1) -end --- push current information into living UI kb.ui = function(force) @@ -287,8 +330,7 @@ KeyBinder_Initialize() kb.loaded = true end - for i = 1, numButtons do - local button = kb.GetSlot(i) + for i, button in ipairs(kb.buttons) do button:SetID(i+kb.scrollOffset) kb.UpdateSlot(button, force) end @@ -298,14 +340,22 @@ kb.profilebg:SetHeight(kb.tabSize[2] + BUTTON_PADDING * 2 + kb.profiletext:GetStringHeight()) kb.bg:SetWidth((KEY_BUTTON_SIZE + BUTTON_HSPACING + BUTTON_SPACING) * BINDS_PER_ROW + BUTTON_PADDING*2 - BUTTON_SPACING) - local numRows = numButtons/BINDS_PER_ROW + local numRows = NUM_KEY_SLOTS/BINDS_PER_ROW kb.bg:SetHeight((KEY_BUTTON_SIZE + BUTTON_SPACING) * numRows + BUTTON_PADDING*2 - BUTTON_SPACING) kb:SetHeight(kb.headerbg:GetHeight() + kb.profilebg:GetHeight() + kb.bg:GetHeight() + kb.footer:GetHeight()) kb:SetWidth((kb.sourcesbg:GetWidth() +(BINDS_PER_ROW * (KEY_BUTTON_SIZE + BUTTON_HSPACING) + (BINDS_PER_ROW - 1) * BUTTON_SPACING + BUTTON_PADDING * 2) )) - kb.bg:SetColorTexture(unpack(BINDING_SCHEME_COLOR[kb.db.bindMode])) + if kb.saveTarget then + kb.bg:SetColorTexture(.2,.5, .2, .5) + kb.savingText:Show() + + else + kb.bg:SetColorTexture(unpack(BINDING_SCHEME_COLOR[kb.db.bindMode])) + kb.savingText:Hide() + end + for i, tab in ipairs(kb.tabButtons) do local border = tab:GetNormalTexture() local tabTexture = "Interface\\Buttons\\UI-Quickslot2" @@ -337,6 +387,15 @@ kb:Show() + if kb.saveTarget then + KeyBinderUnbindButton:SetParent(kb.saveTarget) + KeyBinderUnbindButton:SetPoint('TOPRIGHT', kb.saveTarget, 'TOPLEFT', -2,0) + KeyBinderUnbindButton:Show() + else + KeyBinderUnbindButton:Hide() + end + + -- Reset this so talent cache can be rebuilt kb.talentsPushed = nil end