Mercurial > wow > skeletonkey
comparison SkeletonKey/BindingsFrame.lua @ 27:73df13211b22
- actionbar hotkey text properly updates after hotkeys get switched
- remove a unused function call
| author | Nenue |
|---|---|
| date | Tue, 02 Aug 2016 12:33:13 -0400 |
| parents | SkeletonKey/BindingsUI.lua@67db6b712bf3 |
| children | b0e4d04d428a |
comparison
equal
deleted
inserted
replaced
| 26:c081f117c19d | 27:73df13211b22 |
|---|---|
| 1 -- KrakTool | |
| 2 -- BindingsFrame.lua | |
| 3 -- Created: 7/28/2016 3:39 PM | |
| 4 -- %file-revision% | |
| 5 -- Code piecing the interface together | |
| 6 | |
| 7 local kb, print = LibStub("LibKraken").register(KeyBinder, 'KeySlot') | |
| 8 local BINDS_PER_ROW = 2 | |
| 9 local BINDING_TYPE_SPECIALIZATION = 3 | |
| 10 local BINDING_TYPE_CHARACTER = 2 | |
| 11 local BINDING_TYPE_GLOBAL = 1 | |
| 12 local BUTTON_HSPACING = 128 | |
| 13 local BUTTON_SPACING = 4 | |
| 14 local BUTTON_PADDING = 12 | |
| 15 local KEY_BUTTON_SIZE = 48 | |
| 16 local NUM_KEY_SLOTS = BINDS_PER_ROW * 8 | |
| 17 local TAB_HEIGHT = 40 | |
| 18 | |
| 19 local BINDING_SCHEME_COLOR = { | |
| 20 [BINDING_TYPE_GLOBAL] = {0,.125,.5,.5}, | |
| 21 [BINDING_TYPE_CHARACTER] = {0,0.25,0,0.5}, | |
| 22 [BINDING_TYPE_SPECIALIZATION] = {.25,0,0,0.5}, | |
| 23 } | |
| 24 local BINDING_SCHEME_VERTEX = { | |
| 25 [BINDING_TYPE_GLOBAL] = {0,.5,1,1}, | |
| 26 [BINDING_TYPE_CHARACTER] = {0,1,0,1}, | |
| 27 [BINDING_TYPE_SPECIALIZATION] = {1,1,1,1}, | |
| 28 } | |
| 29 local BINDING_SCHEME_TEXT = { | |
| 30 [BINDING_TYPE_SPECIALIZATION] = {0, 1, 1}, | |
| 31 [BINDING_TYPE_CHARACTER] = {0, 1, 0}, | |
| 32 [BINDING_TYPE_GLOBAL] = {0, 1, 1} | |
| 33 } | |
| 34 | |
| 35 local restingAlpha = 0.7 | |
| 36 local fadeTime, fadeDelay = .30, 0.15 | |
| 37 local saveButton | |
| 38 | |
| 39 local KeyButton_OnKeyDown = function(self, key) | |
| 40 if key == 'ESCAPE' or key:match('[RL]SHIFT') or key:match('[RL]ALT') or key:match('[RL]CTRL') then | |
| 41 return | |
| 42 end | |
| 43 kb.saveTarget.border:SetColorTexture(1,1,1,1) | |
| 44 end | |
| 45 local KeyButton_OnKeyUp = function(self, key) | |
| 46 if key == 'ESCAPE' then | |
| 47 kb.DeactivateSlot(kb.saveTarget) | |
| 48 kb.ui() | |
| 49 return | |
| 50 end | |
| 51 | |
| 52 if key:match('[RL]SHIFT') or key:match('[RL]ALT') or key:match('[RL]CTRL') then | |
| 53 return | |
| 54 end | |
| 55 | |
| 56 if kb.SaveSlot(kb.saveTarget, key) then | |
| 57 if not (kb.db.stickyMode or kb.db.hoverInput) then | |
| 58 | |
| 59 kb.DeactivateSlot(kb.saveTarget) | |
| 60 end | |
| 61 kb.ui() | |
| 62 end | |
| 63 end | |
| 64 | |
| 65 local KeyButton_OnClick = function(self, click) | |
| 66 print(self:GetName(), 'OnMouseDown', click) | |
| 67 local cursorType = GetCursorInfo() | |
| 68 if click == 'LeftButton' then | |
| 69 if cursorType then | |
| 70 kb.DropToSlot(self) | |
| 71 else | |
| 72 if IsShiftKeyDown() then | |
| 73 kb.db.stickyMode = true | |
| 74 KeyBinderStickyMode:SetChecked(true) | |
| 75 end | |
| 76 | |
| 77 kb.ActivateSlot(self) | |
| 78 kb.ui() | |
| 79 end | |
| 80 elseif click == 'RightButton' then | |
| 81 kb.ReleaseSlot(self) | |
| 82 end | |
| 83 end | |
| 84 | |
| 85 local KeyButton_OnDragStart = function(self) | |
| 86 kb.PickupSlot(self) | |
| 87 end | |
| 88 | |
| 89 local KeyButton_OnReceiveDrag = function(self, ...) | |
| 90 kb.DropToSlot(self) | |
| 91 end | |
| 92 | |
| 93 | |
| 94 local KeyBinder_OnUpdate = function(self, elapsed) | |
| 95 self.elapsed = self.elapsed + elapsed | |
| 96 self.throttle = self.throttle + elapsed | |
| 97 | |
| 98 if (self.throttle >= 0.032) then | |
| 99 self.throttle = 0 | |
| 100 else | |
| 101 return | |
| 102 end | |
| 103 | |
| 104 local progress = 1 | |
| 105 if self.elapsed > fadeTime then | |
| 106 self.elapsed = 0 | |
| 107 self.fadeStep = 0 | |
| 108 --self.statustext:SetText(nil) | |
| 109 --self.bindingstext:SetText(nil) | |
| 110 self:SetScript('OnUpdate', nil) | |
| 111 else | |
| 112 if self.elapsed < fadeDelay then | |
| 113 progress = 0 | |
| 114 else | |
| 115 self.fadeStep = self.fadeStep + 1 | |
| 116 progress = (self.elapsed - fadeDelay) /(fadeTime - fadeDelay) | |
| 117 end | |
| 118 --print(self.fadeStep, format('%.02f/%.02f', (self.elapsed - fadeDelay) ,(fadeTime - fadeDelay)) , progress) | |
| 119 end | |
| 120 | |
| 121 local alpha = 1 - progress * (1- restingAlpha) | |
| 122 self.statustext:SetAlpha(alpha) | |
| 123 self.bindingstext:SetAlpha(alpha) | |
| 124 end | |
| 125 | |
| 126 local KeyButton_OnUpdate = function(self) | |
| 127 if not self.command then | |
| 128 return | |
| 129 end | |
| 130 | |
| 131 if self:IsMouseOver() then | |
| 132 kb.elapsed = 0 | |
| 133 if not self.active then | |
| 134 -- only set this handler when the button is activated/mouseOver | |
| 135 self.active = true | |
| 136 kb.statustext:SetText(self.statusText .. ': '..self.actionName) | |
| 137 kb.bindingstext:SetText(self.bindingText) | |
| 138 kb.fadeStep = 0 | |
| 139 kb.throttle = 0 | |
| 140 kb:SetScript('OnUpdate', KeyBinder_OnUpdate) | |
| 141 | |
| 142 if kb.db.hoverInput and kb.saveTarget ~= self then | |
| 143 kb.ActivateSlot(self) | |
| 144 kb.ui() | |
| 145 end | |
| 146 | |
| 147 end | |
| 148 else | |
| 149 if self.active and kb.db.hoverInput then | |
| 150 self.active = nil | |
| 151 --kb.DeactivateSlot(self) | |
| 152 --kb.ui() | |
| 153 end | |
| 154 end | |
| 155 end | |
| 156 | |
| 157 local KeyBinder_OnMouseWheel = function(self, delta) | |
| 158 print(self, delta, self.scrollOffset, (self.scrollOffset <= 0)) | |
| 159 | |
| 160 | |
| 161 if IsControlKeyDown() then | |
| 162 KEY_BUTTON_SIZE = KEY_BUTTON_SIZE - delta | |
| 163 else | |
| 164 | |
| 165 | |
| 166 if (delta > 0) and (self.scrollOffset <= 0) then | |
| 167 return | |
| 168 elseif delta < 0 and kb.scrollOffset >= 42 then | |
| 169 return | |
| 170 end | |
| 171 kb.scrollOffset = ceil(kb.scrollOffset - (delta * BINDS_PER_ROW)) | |
| 172 end | |
| 173 | |
| 174 for i = 1, #kb.buttons do | |
| 175 kb.buttons[i]:SetSize(KEY_BUTTON_SIZE,KEY_BUTTON_SIZE) | |
| 176 end | |
| 177 | |
| 178 kb.ui(true) | |
| 179 end | |
| 180 | |
| 181 local KeyBinder_CheckButton = function(frame ,enableText, disableText, dbKey, tooltipText, callback) | |
| 182 if kb.db[dbKey] then | |
| 183 frame:SetChecked(true) | |
| 184 end | |
| 185 frame.label:SetText(kb.db[dbKey] and enableText or disableText) | |
| 186 frame:SetWidth(frame.label:GetStringWidth()+8) | |
| 187 | |
| 188 frame:SetScript('OnClick', function(self) | |
| 189 if callback then | |
| 190 callback(self) | |
| 191 end | |
| 192 kb.db[dbKey] = self:GetChecked() | |
| 193 if not kb.db[dbKey] then | |
| 194 if kb.saveTarget then | |
| 195 kb.DeactivateSlot(kb.saveTarget) | |
| 196 end | |
| 197 end | |
| 198 self.label:SetText(kb.db[dbKey] and enableText or disableText) | |
| 199 self:SetWidth(self.label:GetStringWidth()+8) | |
| 200 kb.ui() | |
| 201 end) | |
| 202 | |
| 203 frame:SetScript('OnEnter', function(self) | |
| 204 if tooltipText then | |
| 205 GameTooltip:SetOwner(self) | |
| 206 GameTooltip:SetText(tooltipText) | |
| 207 GameTooltip:Show() | |
| 208 end | |
| 209 end) | |
| 210 | |
| 211 frame:SetScript('OnLeave', function(self) | |
| 212 if tooltipText and GameTooltip:GetOwner() == self then | |
| 213 GameTooltip:Hide() | |
| 214 end | |
| 215 end) | |
| 216 end | |
| 217 | |
| 218 local KeyBinder_OnHide = function() | |
| 219 KeyBinderImportLog:Hide() | |
| 220 end | |
| 221 | |
| 222 local CloseButton_OnClick = function() | |
| 223 kb.db.showUI = false | |
| 224 kb:Hide() | |
| 225 end | |
| 226 local CancelButton_OnClick = function() | |
| 227 kb.RevertBindings() | |
| 228 end | |
| 229 local SaveButton_OnClick = function() | |
| 230 kb.ConfirmBindings() | |
| 231 end | |
| 232 | |
| 233 | |
| 234 local KeyBinder_Initialize = function() | |
| 235 do | |
| 236 local leftSlot, upSlot | |
| 237 for index = 1, NUM_KEY_SLOTS do | |
| 238 | |
| 239 local button = CreateFrame('CheckButton', 'KeyBinderSlot'..index, kb, 'KeyButton') | |
| 240 button:SetScript('OnClick', KeyButton_OnClick) | |
| 241 button:SetScript('OnUpdate', KeyButton_OnUpdate) | |
| 242 button:SetScript('OnDragStart', KeyButton_OnDragStart) | |
| 243 button:SetScript('OnReceiveDrag', KeyButton_OnReceiveDrag) | |
| 244 button:RegisterForClicks('AnyUp') | |
| 245 | |
| 246 | |
| 247 local newRow = (mod(index, BINDS_PER_ROW) == 1) | |
| 248 | |
| 249 if index == 1 then | |
| 250 button:SetPoint('TOPLEFT', kb.bg, 'TOPLEFT', BUTTON_PADDING, - BUTTON_PADDING) | |
| 251 upSlot = button | |
| 252 elseif newRow then | |
| 253 button:SetPoint('TOPLEFT', upSlot, 'BOTTOMLEFT', 0, -BUTTON_SPACING) | |
| 254 upSlot = button | |
| 255 else | |
| 256 button:SetPoint('TOPLEFT', leftSlot, 'TOPRIGHT', BUTTON_HSPACING, 0) | |
| 257 end | |
| 258 | |
| 259 button:SetSize(KEY_BUTTON_SIZE, KEY_BUTTON_SIZE) | |
| 260 button:Show() | |
| 261 kb.buttons[index] = button | |
| 262 leftSlot = button | |
| 263 end | |
| 264 end | |
| 265 | |
| 266 | |
| 267 kb.scrollOffset = 0 | |
| 268 kb.tabAnchor = {'TOPLEFT', kb.profilebg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING} | |
| 269 kb.tabGrowth = {'TOPLEFT', nil,'TOPRIGHT', BUTTON_SPACING, 0} | |
| 270 kb.tabSize = {TAB_HEIGHT, TAB_HEIGHT } | |
| 271 kb.UIPanelAnchor = {'TOPLEFT', kb.sourcesbg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING} | |
| 272 kb.UIPanelGrowth = {'TOPLEFT', nil, 'BOTTOMLEFT', 0, -2 } | |
| 273 kb.UIPanelSize = {84, 32 } | |
| 274 kb.UIPanelIcon = {24, 32, 'LEFT', -12, 0} | |
| 275 kb.controlsAnchor = {'BOTTOMRIGHT', kb.footer, -BUTTON_PADDING, BUTTON_PADDING } | |
| 276 kb.controlsGrowth = {'BOTTOMRIGHT', nil, 'BOTTOMLEFT', -BUTTON_SPACING, 0} | |
| 277 | |
| 278 -- order of these is important | |
| 279 kb:tab('KeyBinderGlobalTab', | |
| 280 kb.configTitle[BINDING_TYPE_GLOBAL] .. '\n' .. kb.configDescription[BINDING_TYPE_GLOBAL], "Interface\\ICONS\\item_azereansphere", {0.15,.85,.15,.85}) | |
| 281 kb:tab('KeyBinderCharacterTab', | |
| 282 kb.configHeaders[BINDING_TYPE_CHARACTER] .. '\n' .. kb.configDescription[BINDING_TYPE_CHARACTER], nil) | |
| 283 kb:tab('KeyBinderSpecTab', | |
| 284 kb.configHeaders[BINDING_TYPE_SPECIALIZATION] .. '\n' .. kb.configDescription[BINDING_TYPE_SPECIALIZATION], kb.specInfo.texture) | |
| 285 KeyBinderCharacterTab.icon:SetTexCoord(0.15,.85,.15,.85) | |
| 286 | |
| 287 | |
| 288 | |
| 289 --portraitLayers[1] = KeyBinderCharacterTab.icon | |
| 290 -- todo: find some generic icons for refresh/key input,etc | |
| 291 | |
| 292 saveButton = kb:button('KeyBinderSaveButton', 'Update', 'Reload current bindings and refresh panel.', SaveButton_OnClick) | |
| 293 --restoreButton = kb:button('KeyBinderRestoreButton', 'Discard', 'Revert all changes.', CancelButton_OnClick) | |
| 294 --clearButton = kb:button('KeyBinderClearButton', 'Clear Page', 'Release all buttons.', ResetButton_OnClick) | |
| 295 | |
| 296 kb:uibutton( | |
| 297 'KeyBinderSpellBookButton', 'SpellBook', nil, | |
| 298 function() ToggleSpellBook(BOOKTYPE_SPELL) end, | |
| 299 "Interface\\BUTTONS\\UI-MicroButton-Spellbook-Up", {0, 1, .4, 1}) | |
| 300 kb:uibutton( | |
| 301 'KeyBinderTalentFrameButton', TALENTS, SPECIALIZATION, | |
| 302 function() ToggleTalentFrame() end, | |
| 303 "Interface\\BUTTONS\\UI-MicroButton-Talents-Up", {0, 1, .4, 1}) | |
| 304 | |
| 305 kb:uibutton( | |
| 306 'KeyBinderMacroFrameButton', 'Macros', nil, | |
| 307 function() if MacroFrame and MacroFrame:IsVisible() then | |
| 308 HideUIPanel(MacroFrame) | |
| 309 else | |
| 310 ShowMacroFrame() end | |
| 311 end, | |
| 312 "Interface\\BUTTONS\\UI-MicroButton-Help-Up", {0, 1, .4, 1}) | |
| 313 | |
| 314 kb:uibutton( | |
| 315 'KeyBinderInventoryButton', 'Bags', nil, | |
| 316 function() OpenAllBags() end, | |
| 317 "Interface\\BUTTONS\\UI-MicroButtonCharacter-Up", {0, 1, .4, 1}) | |
| 318 | |
| 319 KeyBinder_CheckButton(KeyBinderStickyMode, 'Enabled', 'Disabled', 'stickyMode', 'Keep input active after receiving a key.') | |
| 320 KeyBinder_CheckButton(KeyBinderHoverInput, 'MouseOver', 'Click', 'hoverInput', 'Enable key input when the cursor is over a binding slot.') | |
| 321 | |
| 322 | |
| 323 KeyBinderUnbindButton:SetScript('OnClick', function() | |
| 324 if kb.saveTarget then | |
| 325 kb.UnbindSlot(kb.saveTarget) | |
| 326 end | |
| 327 kb.ui() | |
| 328 end) | |
| 329 | |
| 330 | |
| 331 kb.info:SetPoint('TOPLEFT', kb.UIPanels[1], 'BOTTOMLEFT', 0, -BUTTON_SPACING) | |
| 332 HEADER_OFFSET = kb.UIPanels[1]:GetHeight() + BUTTON_PADDING | |
| 333 + kb.info:GetHeight() | |
| 334 FOOTER_OFFSET = saveButton:GetHeight() + BUTTON_PADDING | |
| 335 | |
| 336 kb:SetScript('OnHide', KeyBinder_OnHide) | |
| 337 kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) | |
| 338 kb.CloseButton:SetScript('OnClick', CloseButton_OnClick) | |
| 339 | |
| 340 end | |
| 341 | |
| 342 | |
| 343 --- Retrieves button at index; creates said button and instates any stored parameters | |
| 344 | |
| 345 | |
| 346 kb.ActivateSlot = function(button) | |
| 347 kb.saveTarget = button | |
| 348 kb:SetScript('OnKeyUp', KeyButton_OnKeyUp) | |
| 349 kb:SetScript('OnKeyDown', KeyButton_OnKeyDown) | |
| 350 kb.savingText:ClearAllPoints() | |
| 351 kb.savingText:SetParent(button) | |
| 352 kb.savingText:SetPoint('BOTTOMLEFT', button, 'TOPLEFT', 0, 0) | |
| 353 end | |
| 354 | |
| 355 kb.DeactivateSlot = function(button) | |
| 356 kb.saveTarget = nil | |
| 357 kb:SetScript('OnKeyUp', nil) | |
| 358 kb:SetScript('OnKeyDown', nil) | |
| 359 end | |
| 360 | |
| 361 | |
| 362 --- push current information into living UI | |
| 363 kb.ui = function(force) | |
| 364 for i, module in ipairs(kb.modules) do | |
| 365 if module.ui then | |
| 366 module.ui(force) | |
| 367 end | |
| 368 end | |
| 369 | |
| 370 if not kb.db.showUI then | |
| 371 print('---end of refresh') | |
| 372 return | |
| 373 end | |
| 374 if not kb.loaded then | |
| 375 KeyBinder_Initialize() | |
| 376 kb.loaded = true | |
| 377 end | |
| 378 for i, button in ipairs(kb.buttons) do | |
| 379 button:SetID(i+kb.scrollOffset) | |
| 380 kb.UpdateSlot(button, force) | |
| 381 end | |
| 382 | |
| 383 | |
| 384 --- Frame Sizing | |
| 385 kb.profilebg:SetHeight(kb.tabSize[2] + BUTTON_PADDING * 2 + kb.profiletext:GetStringHeight()) | |
| 386 | |
| 387 kb.bg:SetWidth((KEY_BUTTON_SIZE + BUTTON_HSPACING + BUTTON_SPACING) * BINDS_PER_ROW + BUTTON_PADDING*2 - BUTTON_SPACING) | |
| 388 local numRows = NUM_KEY_SLOTS/BINDS_PER_ROW | |
| 389 | |
| 390 kb.bg:SetHeight((KEY_BUTTON_SIZE + BUTTON_SPACING) * numRows + BUTTON_PADDING*2 - BUTTON_SPACING) | |
| 391 | |
| 392 kb:SetHeight(kb.headerbg:GetHeight() + kb.profilebg:GetHeight() + kb.bg:GetHeight() + kb.footer:GetHeight()) | |
| 393 kb:SetWidth((kb.sourcesbg:GetWidth() +(BINDS_PER_ROW * (KEY_BUTTON_SIZE + BUTTON_HSPACING) + (BINDS_PER_ROW - 1) * BUTTON_SPACING + BUTTON_PADDING * 2) )) | |
| 394 | |
| 395 if kb.saveTarget then | |
| 396 kb.bg:SetColorTexture(.2,.5, .2, .5) | |
| 397 kb.savingText:Show() | |
| 398 | |
| 399 else | |
| 400 kb.bg:SetColorTexture(unpack(BINDING_SCHEME_COLOR[kb.db.bindMode])) | |
| 401 kb.savingText:Hide() | |
| 402 end | |
| 403 | |
| 404 for i, tab in ipairs(kb.tabButtons) do | |
| 405 local border = tab:GetNormalTexture() | |
| 406 local tabTexture = "Interface\\Buttons\\UI-Quickslot2" | |
| 407 local left, top, right, bottom = -12, 12, 13, -13 | |
| 408 if i == kb.db.bindMode then | |
| 409 tabTexture = "Interface\\Buttons\\CheckButtonGlow" | |
| 410 left, top, right, bottom = -14, 14, 15, -15 | |
| 411 tab.icon:SetDesaturated(false) | |
| 412 if tab.icon2 then tab.icon2:SetDesaturated(false) end | |
| 413 border:SetDesaturated(true) | |
| 414 border:SetVertexColor(1,1,1, 1) | |
| 415 else | |
| 416 tab.icon:SetDesaturated(true) | |
| 417 if tab.icon2 then tab.icon2:SetDesaturated(true) end | |
| 418 border:SetDesaturated(false) | |
| 419 border:SetVertexColor(1,1,1) | |
| 420 end | |
| 421 border:SetTexture(tabTexture) | |
| 422 border:SetPoint('TOPLEFT', tab, 'TOPLEFT', left, top) | |
| 423 border:SetPoint('BOTTOMRIGHT', tab, 'BOTTOMRIGHT', right, bottom) | |
| 424 end | |
| 425 | |
| 426 KeyBinderSpecTab.icon:SetTexture(kb.specInfo.texture) | |
| 427 SetPortraitTexture(KeyBinderCharacterTab.icon, 'player') | |
| 428 | |
| 429 kb.profiletext:SetText(kb.configHeaders[kb.db.bindMode]) | |
| 430 print(kb.db.bindMode, kb.configHeaders[kb.db.bindMode], kb:GetSize()) | |
| 431 print(kb:GetPoint(1)) | |
| 432 | |
| 433 kb:Show() | |
| 434 | |
| 435 if kb.saveTarget then | |
| 436 KeyBinderUnbindButton:SetParent(kb.saveTarget) | |
| 437 KeyBinderUnbindButton:SetPoint('TOPLEFT', kb.saveTarget, 'BOTTOMLEFT', 0, -1) | |
| 438 KeyBinderUnbindButton:Show() | |
| 439 else | |
| 440 KeyBinderUnbindButton:Hide() | |
| 441 end | |
| 442 | |
| 443 -- Reset this so talent cache can be rebuilt | |
| 444 kb.talentsPushed = nil | |
| 445 end | |
| 446 | |
| 447 kb.AcceptAssignment = function(self, ...) | |
| 448 local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] | |
| 449 local source = loadedProfiles[popup.oldProfile] | |
| 450 kb.SetSlot(popup.slot, unpack(popup.args)) | |
| 451 kb.UpdateSlot(popup.slot) | |
| 452 kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) -- re-enable scrolling | |
| 453 ClearCursor() | |
| 454 ResetCursor() | |
| 455 end |
