annotate SkeletonKey/UI.lua @ 10:e7977b336bf7

the refactor mess never ends
author Nenue
date Thu, 28 Jul 2016 17:37:49 -0400
parents a2fc77fa4c73
children f9c18c0a6377
rev   line source
Nenue@6 1 -- KrakTool
Nenue@6 2 -- UI.lua
Nenue@6 3 -- Created: 7/28/2016 3:39 PM
Nenue@6 4 -- %file-revision%
Nenue@6 5 --
Nenue@6 6
Nenue@6 7 local kb, print = LibStub("LibKraken").register(KeyBinder, 'KeySlot')
Nenue@6 8 local BINDS_PER_ROW = 2
Nenue@6 9 local BUTTON_HSPACING = 128
Nenue@6 10 local BUTTON_SPACING = 4
Nenue@6 11 local BUTTON_PADDING = 12
Nenue@6 12 local BINDING_TYPE_SPECIALIZATION = 3
Nenue@6 13 local BINDING_TYPE_CHARACTER = 2
Nenue@6 14 local BINDING_TYPE_GLOBAL = 1
Nenue@6 15 local KEY_BUTTON_SIZE = 48
Nenue@6 16 local MIN_BIND_SLOTS = 32
Nenue@6 17 local TAB_OFFSET = 12
Nenue@6 18 local TAB_HEIGHT = 40
Nenue@6 19 local TAB_SPACING = 2
Nenue@6 20 local BORDER_UNASSIGNED = {0.2,0.2,0.2,1 }
Nenue@6 21 local BORDER_ASSIGNED = {0.5,0.5,0.5,1 }
Nenue@6 22 local BORDER_DYNAMIC = {1,1,0,1}
Nenue@6 23 local BORDER_PENDING = {1,0.5,0,1 }
Nenue@6 24
Nenue@6 25 local BUTTON_HEADERS = {
Nenue@6 26 ['spell'] = SPELLS,
Nenue@6 27 ['macro'] = MACRO,
Nenue@6 28 ['petaction'] = PET,
Nenue@6 29 ['mount'] = MOUNT,
Nenue@6 30 ['battlepet'] = BATTLEPET,
Nenue@6 31
Nenue@6 32
Nenue@6 33 [5] = PROFESSIONS_FIRST_AID,
Nenue@6 34 [7] = PROFESSIONS_COOKING,
Nenue@6 35 [9] = PROFESSIONS_FISHING,
Nenue@6 36 [10] = PROFESSIONS_ARCHAEOLOGY,
Nenue@6 37
Nenue@6 38 }
Nenue@6 39
Nenue@6 40 local BINDING_SCHEME_COLOR = {
Nenue@6 41 [BINDING_TYPE_GLOBAL] = {0,.125,.5,.5},
Nenue@6 42 [BINDING_TYPE_CHARACTER] = {0,0.25,0,0.5},
Nenue@6 43 [BINDING_TYPE_SPECIALIZATION] = {.25,0,0,0.5},
Nenue@6 44 }
Nenue@6 45 local BINDING_SCHEME_VERTEX = {
Nenue@6 46 [BINDING_TYPE_GLOBAL] = {0,.5,1,1},
Nenue@6 47 [BINDING_TYPE_CHARACTER] = {0,1,0,1},
Nenue@6 48 [BINDING_TYPE_SPECIALIZATION] = {1,1,1,1},
Nenue@6 49 }
Nenue@6 50 local BINDING_SCHEME_TEXT = {
Nenue@6 51 [BINDING_TYPE_SPECIALIZATION] = {0, 1, 1},
Nenue@6 52 [BINDING_TYPE_CHARACTER] = {0, 1, 0},
Nenue@6 53 [BINDING_TYPE_GLOBAL] = {0, 1, 1}
Nenue@6 54 }
Nenue@6 55
Nenue@6 56 local restingAlpha = 0.7
Nenue@6 57 local fadeTime, fadeDelay = .30, 0.15
Nenue@6 58 local numButtons = BINDS_PER_ROW * 8
Nenue@6 59 local saveButton
Nenue@6 60 local KeyButton_OnKeyDown = function(self, key)
Nenue@6 61 kb.StoreBinding(self, key)
Nenue@6 62 end
Nenue@6 63 local KeyButton_OnClick = function(self, click)
Nenue@6 64 print(self:GetName(), 'OnMouseDown', click)
Nenue@6 65 if click == 'LeftButton' then
Nenue@6 66 kb.DropToSlot(self)
Nenue@6 67 elseif click == 'RightButton' then
Nenue@6 68 kb.ReleaseSlot(self)
Nenue@6 69 else
Nenue@6 70 kb.StoreBinding(self, click:upper())
Nenue@6 71 end
Nenue@6 72 end
Nenue@6 73
Nenue@6 74 local KeyButton_OnDragStart = function(self)
Nenue@6 75 kb.PickupSlot(self)
Nenue@6 76 end
Nenue@6 77
Nenue@6 78 local KeyButton_OnReceiveDrag = function(self, ...)
Nenue@6 79 kb.DropToSlot(self)
Nenue@6 80 end
Nenue@6 81
Nenue@6 82
Nenue@6 83 local KeyBinder_OnUpdate = function(self, elapsed)
Nenue@6 84 self.elapsed = self.elapsed + elapsed
Nenue@6 85 self.throttle = self.throttle + elapsed
Nenue@6 86
Nenue@6 87 if (self.throttle >= 0.032) then
Nenue@6 88 self.throttle = 0
Nenue@6 89 else
Nenue@6 90 return
Nenue@6 91 end
Nenue@6 92
Nenue@6 93 local progress = 1
Nenue@6 94 if self.elapsed > fadeTime then
Nenue@6 95 self.elapsed = 0
Nenue@6 96 self.fadeStep = 0
Nenue@6 97 --self.statustext:SetText(nil)
Nenue@6 98 --self.bindingstext:SetText(nil)
Nenue@6 99 self:SetScript('OnUpdate', nil)
Nenue@6 100 else
Nenue@6 101 if self.elapsed < fadeDelay then
Nenue@6 102 progress = 0
Nenue@6 103 else
Nenue@6 104 self.fadeStep = self.fadeStep + 1
Nenue@6 105 progress = (self.elapsed - fadeDelay) /(fadeTime - fadeDelay)
Nenue@6 106 end
Nenue@6 107 --print(self.fadeStep, format('%.02f/%.02f', (self.elapsed - fadeDelay) ,(fadeTime - fadeDelay)) , progress)
Nenue@6 108 end
Nenue@6 109
Nenue@6 110 local alpha = 1 - progress * (1- restingAlpha)
Nenue@6 111 self.statustext:SetAlpha(alpha)
Nenue@6 112 self.bindingstext:SetAlpha(alpha)
Nenue@6 113 end
Nenue@6 114
Nenue@6 115 local KeyButton_OnUpdate = function(self)
Nenue@6 116 if not self.command then
Nenue@6 117 return
Nenue@6 118 end
Nenue@6 119
Nenue@6 120 if self:IsMouseOver() then
Nenue@6 121 kb.elapsed = 0
Nenue@6 122 if not self.active then
Nenue@6 123 -- only set this handler when the button is activated/mouseOver
Nenue@6 124 self.active = true
Nenue@6 125 self:SetScript('OnKeyDown', KeyButton_OnKeyDown)
Nenue@6 126
Nenue@6 127 kb.statustext:SetText(self.statusText .. ': '..self.actionName)
Nenue@6 128 kb.bindingstext:SetText(self.bindingText)
Nenue@6 129 kb.fadeStep = 0
Nenue@6 130 kb.throttle = 0
Nenue@6 131 kb:SetScript('OnUpdate', KeyBinder_OnUpdate)
Nenue@6 132
Nenue@6 133 end
Nenue@6 134 else
Nenue@6 135 if self.active then
Nenue@6 136 self.active = nil
Nenue@6 137 self:SetScript('OnKeyDown', nil)
Nenue@6 138 end
Nenue@6 139 end
Nenue@6 140 end
Nenue@6 141
Nenue@6 142 local KeyBinder_OnMouseWheel = function(self, delta)
Nenue@6 143 print(self, delta, self.scrollOffset, (self.scrollOffset <= 0))
Nenue@6 144
Nenue@6 145
Nenue@6 146 if IsControlKeyDown() then
Nenue@6 147 KEY_BUTTON_SIZE = KEY_BUTTON_SIZE - delta
Nenue@6 148 else
Nenue@6 149
Nenue@6 150
Nenue@6 151 if (delta > 0) and (self.scrollOffset <= 0) then
Nenue@6 152 return
Nenue@6 153 elseif delta < 0 and kb.scrollOffset >= 42 then
Nenue@6 154 return
Nenue@6 155 end
Nenue@6 156 kb.scrollOffset = ceil(kb.scrollOffset - (delta * BINDS_PER_ROW))
Nenue@6 157 end
Nenue@6 158
Nenue@6 159 kb.ui(true)
Nenue@6 160 end
Nenue@6 161
Nenue@6 162 local KeyBinder_OnHide = function()
Nenue@6 163 KeyBinderImportLog:Hide()
Nenue@6 164 end
Nenue@6 165
Nenue@6 166 local CloseButton_OnClick = function()
Nenue@10 167 kb.db.showUI = false
Nenue@6 168 kb:Hide()
Nenue@6 169 end
Nenue@6 170 local CancelButton_OnClick = function()
Nenue@6 171 kb.RevertBindings()
Nenue@6 172 end
Nenue@6 173 local SaveButton_OnClick = function()
Nenue@6 174 kb.ConfirmBindings()
Nenue@6 175 end
Nenue@6 176
Nenue@6 177 local KeyBinder_Initialize = function()
Nenue@6 178
Nenue@6 179
Nenue@6 180 kb.scrollOffset = 0
Nenue@6 181 kb.tabAnchor = {'TOPLEFT', kb.profilebg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING}
Nenue@6 182 kb.tabGrowth = {'TOPLEFT', nil,'TOPRIGHT', BUTTON_SPACING, 0}
Nenue@6 183 kb.tabSize = {TAB_HEIGHT, TAB_HEIGHT }
Nenue@6 184 kb.UIPanelAnchor = {'TOPLEFT', kb.sourcesbg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING}
Nenue@6 185 kb.UIPanelGrowth = {'TOPLEFT', nil, 'BOTTOMLEFT', 0, -2 }
Nenue@6 186 kb.UIPanelSize = {84, 32 }
Nenue@6 187 kb.UIPanelIcon = {24, 32, 'LEFT', -12, 0}
Nenue@6 188 kb.controlsAnchor = {'BOTTOMLEFT', kb.footer, BUTTON_PADDING, BUTTON_PADDING }
Nenue@6 189 kb.controlsGrowth = {'BOTTOMLEFT', nil, 'BOTTOMRIGHT', BUTTON_SPACING, 0}
Nenue@6 190
Nenue@6 191 -- order of these is important
Nenue@6 192 kb:tab('KeyBinderGlobalTab',
Nenue@6 193 kb.configTitle[BINDING_TYPE_GLOBAL] .. '\n' .. kb.configDescription[BINDING_TYPE_GLOBAL], "Interface\\ICONS\\item_azereansphere", {0.15,.85,.15,.85})
Nenue@6 194 kb:tab('KeyBinderCharacterTab',
Nenue@6 195 kb.configHeaders[BINDING_TYPE_CHARACTER] .. '\n' .. kb.configDescription[BINDING_TYPE_CHARACTER], nil)
Nenue@6 196 kb:tab('KeyBinderSpecTab',
Nenue@6 197 kb.configHeaders[BINDING_TYPE_SPECIALIZATION] .. '\n' .. kb.configDescription[BINDING_TYPE_SPECIALIZATION], kb.specInfo.texture)
Nenue@6 198 KeyBinderCharacterTab.icon:SetTexCoord(0.15,.85,.15,.85)
Nenue@6 199
Nenue@6 200
Nenue@6 201
Nenue@6 202 --portraitLayers[1] = KeyBinderCharacterTab.icon
Nenue@6 203
Nenue@6 204 saveButton = kb:button('KeyBinderSaveButton', 'Save', 'Commit all changes.', SaveButton_OnClick)
Nenue@6 205 --restoreButton = kb:button('KeyBinderRestoreButton', 'Discard', 'Revert all changes.', CancelButton_OnClick)
Nenue@6 206 --clearButton = kb:button('KeyBinderClearButton', 'Clear Page', 'Release all buttons.', ResetButton_OnClick)
Nenue@6 207
Nenue@6 208 kb:uibutton(
Nenue@6 209 'KeyBinderSpellBookButton', 'SpellBook', nil,
Nenue@6 210 function() ToggleSpellBook(BOOKTYPE_SPELL) end,
Nenue@6 211 "Interface\\BUTTONS\\UI-MicroButton-Spellbook-Up", {0, 1, .4, 1})
Nenue@6 212 kb:uibutton(
Nenue@6 213 'KeyBinderTalentFrameButton', TALENTS, SPECIALIZATION,
Nenue@6 214 function() ToggleTalentFrame() end,
Nenue@6 215 "Interface\\BUTTONS\\UI-MicroButton-Talents-Up", {0, 1, .4, 1})
Nenue@6 216
Nenue@6 217 kb:uibutton(
Nenue@6 218 'KeyBinderMacroFrameButton', 'Macros', nil,
Nenue@6 219 function() if MacroFrame and MacroFrame:IsVisible() then
Nenue@6 220 HideUIPanel(MacroFrame)
Nenue@6 221 else
Nenue@6 222 ShowMacroFrame() end
Nenue@6 223 end,
Nenue@6 224 "Interface\\BUTTONS\\UI-MicroButton-Help-Up", {0, 1, .4, 1})
Nenue@6 225
Nenue@6 226 kb:uibutton(
Nenue@6 227 'KeyBinderInventoryButton', 'Bags', nil,
Nenue@6 228 function() OpenAllBags() end,
Nenue@6 229 "Interface\\BUTTONS\\UI-MicroButtonCharacter-Up", {0, 1, .4, 1})
Nenue@6 230
Nenue@6 231
Nenue@6 232
Nenue@6 233 kb.info:SetPoint('TOPLEFT', kb.UIPanels[1], 'BOTTOMLEFT', 0, -BUTTON_SPACING)
Nenue@6 234 HEADER_OFFSET = kb.UIPanels[1]:GetHeight() + BUTTON_PADDING
Nenue@6 235 + kb.info:GetHeight()
Nenue@6 236 FOOTER_OFFSET = saveButton:GetHeight() + BUTTON_PADDING
Nenue@6 237
Nenue@6 238 kb:SetScript('OnHide', KeyBinder_OnHide)
Nenue@6 239 kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel)
Nenue@6 240 kb.CloseButton:SetScript('OnClick', CloseButton_OnClick)
Nenue@6 241
Nenue@6 242 end
Nenue@6 243
Nenue@6 244 --- Resets button command
Nenue@6 245 kb.ReleaseSlot = function(self)
Nenue@6 246 local slot = self:GetID()
Nenue@6 247
Nenue@6 248
Nenue@6 249 if kb.currentProfile.buttons[slot] then
Nenue@6 250 kb.currentProfile.buttons[slot] = nil
Nenue@6 251 end
Nenue@6 252 if self.command then
Nenue@6 253 kb.currentProfile.commands[self.command] = nil
Nenue@6 254 end
Nenue@6 255 if self.actionType == 'spell' and IsTalentSpell(self.actionName) then
Nenue@6 256 if kb.currentProfile.talents[self.actionID] then
Nenue@6 257 kb.currentProfile.talents[self.actionID] = nil
Nenue@6 258 end
Nenue@6 259 end
Nenue@6 260 local droppedKeys = {}
Nenue@6 261
Nenue@6 262 -- doing removal in second loop to avoid possible iterator shenanigans
Nenue@6 263 for k,v in pairs(kb.currentProfile.bindings) do
Nenue@6 264 if v == self.command then
Nenue@6 265 tinsert(droppedKeys, k)
Nenue@6 266 end
Nenue@6 267 end
Nenue@6 268 if #droppedKeys >=1 then
Nenue@6 269 for i, k in ipairs(droppedKeys) do
Nenue@6 270 kb.currentProfile.bindings[k] = nil
Nenue@6 271 end
Nenue@6 272 end
Nenue@6 273
Nenue@6 274 self.isAvailable = nil
Nenue@6 275 self.isDynamic = nil
Nenue@6 276 self.bindingText = nil
Nenue@6 277 self.statusText = nil
Nenue@6 278 self.command = nil
Nenue@6 279 self.actionType = nil
Nenue@6 280 self.actionID = nil
Nenue@6 281 self.actionName = nil
Nenue@6 282 self.pickupSlot = nil
Nenue@6 283 self.pickupBook = nil
Nenue@6 284 self.macroName = nil
Nenue@6 285 self.profile = nil
Nenue@6 286 self.icon:SetTexture(nil)
Nenue@6 287 self.border:SetColorTexture(unpack(BORDER_UNASSIGNED))
Nenue@6 288 self:EnableKeyboard(false)
Nenue@6 289 self:SetScript('OnKeyDown', nil)
Nenue@6 290 end
Nenue@6 291
Nenue@6 292 kb.SetSlot = function(self, command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook)
Nenue@6 293 local slot = self:GetID()
Nenue@6 294 local isDynamic, isAvailable
Nenue@6 295
Nenue@6 296 print('|cFFFFFF00SetSlot|r:', self:GetID())
Nenue@6 297 if command then
Nenue@6 298
Nenue@6 299 if actionType == 'spell' then
Nenue@6 300 local professionNum, spellNum = command:match("profession_(%d)_(%d)")
Nenue@6 301
Nenue@6 302 if (professionNum and spellNum) then
Nenue@6 303 isDynamic = 'profession'
Nenue@6 304 local cacheInfo = kb.ProfessionCache[professionNum..'_'..spellNum]
Nenue@6 305 if cacheInfo then
Nenue@6 306 isAvailable = true
Nenue@6 307 name = cacheInfo.spellName
Nenue@6 308 icon = cacheInfo.icon
Nenue@6 309 actionID = cacheInfo.spellID
Nenue@6 310 self.profIndex = cacheInfo.profIndex
Nenue@6 311 self.spellOffset = cacheInfo.spellOffset
Nenue@6 312 end
Nenue@6 313 print(' Special slot: |cFF00FFFFProfession|r', professionNum, spellNum, isDynamic, isAvailable)
Nenue@6 314
Nenue@6 315 self.professionNum = tonumber(professionNum)
Nenue@6 316 self.spellNum = tonumber(spellNum)
Nenue@6 317
Nenue@6 318 else
Nenue@6 319 if kb.TalentCache[actionID] then
Nenue@6 320 isDynamic = 'talent'
Nenue@6 321 print(' Special slot: |cFFBBFF00talent|r', name, isAvailable)
Nenue@6 322 end
Nenue@6 323
Nenue@6 324 isAvailable = GetSpellInfo(name)
Nenue@6 325 end
Nenue@6 326 actionID = name
Nenue@6 327 elseif actionType == 'macro' then
Nenue@6 328 if not actionID then
Nenue@6 329 actionID = GetMacroIndexByName(name)
Nenue@6 330 end
Nenue@6 331 isAvailable = true
Nenue@6 332 else
Nenue@6 333 --- Journal selections
Nenue@6 334 -- todo: consider using the deep end of blizzard action bar instead
Nenue@6 335 if not actionID then
Nenue@6 336 actionID = command:match("^KeyBinderMacro:(.+)")
Nenue@6 337 end
Nenue@6 338 isAvailable = true
Nenue@6 339 end
Nenue@6 340
Nenue@6 341 if isAvailable then
Nenue@6 342 local oldCommand = command
Nenue@6 343 macroName, macroText, command = kb.RegisterAction(actionType, actionID)
Nenue@6 344 if oldCommand ~= command then
Nenue@6 345 print('|cFFFF4400fixing command string', actionType, actionID, name)
Nenue@6 346 kb.currentProfile.bound[oldCommand] = nil
Nenue@6 347 kb.currentProfile.bound[command] = slot
Nenue@6 348 for k,v in pairs(kb.currentProfile.bindings) do
Nenue@6 349 if v == oldCommand then
Nenue@6 350 kb.currentProfile.bindings[k] = command
Nenue@6 351 end
Nenue@6 352 end
Nenue@6 353 end
Nenue@6 354 kb.LoadBinding(command, name, icon, actionType, actionID, macroName, macroText)
Nenue@6 355 end
Nenue@6 356
Nenue@6 357 if actionType == 'petaction' then
Nenue@6 358 self.pickupSlot = pickupSlot
Nenue@6 359 self.pickupBook = pickupBook
Nenue@6 360 else
Nenue@6 361 self.pickupSlot = nil
Nenue@6 362 self.pickupBook = nil
Nenue@6 363 end
Nenue@6 364
Nenue@6 365 actionID = actionID or 0
Nenue@6 366 self:EnableKeyboard(true)
Nenue@6 367 print(' |cFF00FF00kb.currentProfile.buttons['..slot..'] |cFF00FFFF=|r |cFF00FFFF"'.. command.. '"|r |cFF00FF00"'.. name, '"|r |cFFFFFF00icon:'.. icon .. '|r |cFFFF8800"'.. actionType, '"|r |cFFFF0088id:'.. actionID ..'|r |cFF00FF00"'.. macroName .. '"|r')
Nenue@6 368 kb.currentProfile.buttons[slot] = {command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook}
Nenue@6 369
Nenue@6 370 -- Clean up conflicting entries for loaded button
Nenue@6 371 local previous = kb.currentProfile.commands[command]
Nenue@6 372 if previous ~= slot and kb.buttons[previous] then
Nenue@6 373 kb.ReleaseSlot(kb.buttons[previous])
Nenue@6 374 end
Nenue@6 375 kb.currentProfile.commands[command] = slot
Nenue@6 376 end
Nenue@6 377
Nenue@6 378 self.isAvailable = isAvailable
Nenue@6 379 self.isDynamic = isDynamic
Nenue@6 380
Nenue@6 381 self.macroText = macroText
Nenue@6 382 self.macroName = macroName
Nenue@6 383 self.actionType = actionType
Nenue@6 384 self.actionID = actionID
Nenue@6 385 self.actionName = name
Nenue@6 386 self.command = command
Nenue@6 387 self.icon:SetTexture(icon)
Nenue@6 388 self.profile = kb.db.bindMode
Nenue@6 389 self:RegisterForDrag('LeftButton')
Nenue@6 390 end
Nenue@6 391
Nenue@6 392 --- Retrieves button at index; creates said button and instates any stored parameters
Nenue@7 393 do
Nenue@7 394 local leftSlot, upSlot
Nenue@7 395 local buttonsDepth = 0
Nenue@7 396 kb.GetSlot = function(index)
Nenue@6 397
Nenue@7 398 local slot = index + kb.scrollOffset
Nenue@6 399
Nenue@7 400 if not kb.buttons[index] then
Nenue@7 401 local button = CreateFrame('CheckButton', 'KeyBinderSlot'..index, kb, 'KeyButton')
Nenue@7 402 button:SetScript('OnClick', KeyButton_OnClick)
Nenue@7 403 button:SetScript('OnUpdate', KeyButton_OnUpdate)
Nenue@7 404 button:SetScript('OnDragStart', KeyButton_OnDragStart)
Nenue@7 405 button:SetScript('OnReceiveDrag', KeyButton_OnReceiveDrag)
Nenue@7 406 button:RegisterForClicks('AnyUp')
Nenue@6 407
Nenue@6 408
Nenue@7 409 local newRow = (mod(index, BINDS_PER_ROW) == 1)
Nenue@6 410
Nenue@7 411 if index == 1 then
Nenue@7 412 button:SetPoint('TOPLEFT', kb.bg, 'TOPLEFT', BUTTON_PADDING, - BUTTON_PADDING)
Nenue@7 413 upSlot = button
Nenue@7 414 buttonsDepth = KEY_BUTTON_SIZE + BUTTON_PADDING * 2
Nenue@7 415 elseif newRow then
Nenue@7 416 button:SetPoint('TOPLEFT', upSlot, 'BOTTOMLEFT', 0, -BUTTON_SPACING)
Nenue@7 417 upSlot = button
Nenue@7 418 buttonsDepth = buttonsDepth + KEY_BUTTON_SIZE + BUTTON_SPACING
Nenue@7 419 else
Nenue@7 420 button:SetPoint('TOPLEFT', leftSlot, 'TOPRIGHT', BUTTON_HSPACING, 0)
Nenue@7 421 end
Nenue@7 422
Nenue@7 423 button:SetSize(KEY_BUTTON_SIZE, KEY_BUTTON_SIZE)
Nenue@7 424 button:Show()
Nenue@7 425 kb.buttons[index] = button
Nenue@7 426 leftSlot = button
Nenue@6 427 end
Nenue@7 428 return kb.buttons[index]
Nenue@6 429 end
Nenue@6 430 end
Nenue@6 431
Nenue@6 432 --- Updates profile assignment and button contents
Nenue@6 433 kb.UpdateSlot = function(self, force)
Nenue@6 434 local slot = self:GetID()
Nenue@6 435
Nenue@6 436 if force then
Nenue@6 437 if kb.currentProfile.buttons[slot] then
Nenue@6 438 kb.SetSlot(self, unpack(kb.currentProfile.buttons[slot]))
Nenue@6 439 else
Nenue@6 440 kb.ReleaseSlot(self)
Nenue@6 441 end
Nenue@6 442 end
Nenue@6 443
Nenue@6 444 if self.command then
Nenue@6 445 print('['..slot..'] =', self.command, GetBindingKey(self.command))
Nenue@6 446
Nenue@6 447 if self.pending then
Nenue@6 448 self.border:SetColorTexture(unpack(BORDER_PENDING))
Nenue@6 449 elseif self.isDynamic then
Nenue@6 450 self.border:SetColorTexture(unpack(BORDER_DYNAMIC))
Nenue@6 451 else
Nenue@6 452 self.border:SetColorTexture(unpack(BORDER_ASSIGNED))
Nenue@6 453 end
Nenue@6 454
Nenue@6 455 if self.actionType == 'macro' then
Nenue@6 456 self.macro:Show()
Nenue@6 457 else
Nenue@6 458 self.macro:Hide()
Nenue@6 459 if self.actionType == 'spell' then
Nenue@6 460 local dummy = GetSpellInfo(self.actionName)
Nenue@6 461 if not dummy then
Nenue@6 462 self.icon:SetDesaturated(true)
Nenue@6 463 else
Nenue@6 464 self.icon:SetDesaturated(false)
Nenue@6 465 end
Nenue@6 466
Nenue@6 467 end
Nenue@6 468 end
Nenue@6 469
Nenue@6 470 if self.isDynamic then
Nenue@6 471 print('|cFFFFBB00UpdateSlot|r: ', self.isDynamic, self.isAvailable, self.actionID)
Nenue@6 472 end
Nenue@6 473
Nenue@6 474 if self.isDynamic == 'profession' then
Nenue@6 475 local profText = (self.spellNum == 1) and TRADE_SKILLS or (BUTTON_HEADERS[self.profIndex] or GetProfessionInfo(self.profIndex))
Nenue@6 476 if self.isAvailable then
Nenue@6 477 print(self.profIndex, 'spnum', type(self.spellNum), (self.spellNum == 1))
Nenue@6 478
Nenue@6 479 self.statusText = '|cFFFFFF00'..profText..'|r'
Nenue@6 480 self.bindingText = kb.BindingString(GetBindingKey(self.command))
Nenue@6 481 else
Nenue@6 482 self.statusText = '|cFFFF4400'..profText..'|r'
Nenue@6 483 self.actionName = '(need to train profession #'..self.profNum..')'
Nenue@6 484 self.bindingText ='?'
Nenue@6 485 end
Nenue@6 486 elseif self.isDynamic == 'talent' then
Nenue@6 487
Nenue@6 488 self.statusText = '|cFF00FFFF'.. TALENT .. '|r'
Nenue@6 489 if self.isAvailable then
Nenue@6 490 self.bindingText = kb.BindingString(GetBindingKey(self.command))
Nenue@6 491 else
Nenue@6 492 if kb.inactiveTalentBindings[self.actionID] then
Nenue@6 493 print(self.actionID, #kb.inactiveTalentBindings[self.actionID])
Nenue@6 494 self.bindingText= kb.BindingString(unpack(kb.inactiveTalentBindings[self.actionID]))
Nenue@6 495 end
Nenue@6 496
Nenue@6 497 end
Nenue@6 498 else
Nenue@6 499 self.statusText = '|cFF00FF00'.. (BUTTON_HEADERS[self.actionType] and BUTTON_HEADERS[self.actionType] or self.actionType) .. '|r'
Nenue@6 500 self.bindingText = kb.BindingString(GetBindingKey(self.command))
Nenue@6 501 end
Nenue@6 502
Nenue@6 503 local locked, layer = kb.IsCommandBound(self)
Nenue@6 504 if locked then
Nenue@6 505 self.icon:SetAlpha(0.5)
Nenue@6 506 else
Nenue@6 507 self.icon:SetAlpha(1)
Nenue@6 508 end
Nenue@6 509
Nenue@6 510 if self.actionType == 'spell' then
Nenue@6 511 self.icon:SetTexture(GetSpellTexture(self.actionID))
Nenue@6 512 end
Nenue@6 513 end
Nenue@6 514
Nenue@6 515 if not self.isAvailable then
Nenue@6 516 self.bind:SetTextColor(0.7,0.7,0.7,1)
Nenue@6 517 else
Nenue@6 518 self.bind:SetTextColor(1,1,1,1)
Nenue@6 519 end
Nenue@6 520
Nenue@6 521 self.header:SetText(self.statusText)
Nenue@6 522 self.bind:SetText(self.bindingText)
Nenue@6 523 self.macro:SetText(self.macroName)
Nenue@6 524 self.details:SetText(self.actionName)
Nenue@6 525 end
Nenue@6 526
Nenue@6 527 --- push current information into living UI
Nenue@6 528 kb.ui = function(force)
Nenue@6 529 for i, module in ipairs(kb.modules) do
Nenue@6 530 if module.ui then
Nenue@6 531 module.ui(force)
Nenue@6 532 end
Nenue@6 533 end
Nenue@6 534
Nenue@6 535 if not kb.db.showUI then
Nenue@6 536 print('---end of refresh')
Nenue@6 537 return
Nenue@6 538 end
Nenue@6 539 if not kb.loaded then
Nenue@6 540 KeyBinder_Initialize()
Nenue@6 541 kb.loaded = true
Nenue@6 542 end
Nenue@6 543 for i = 1, numButtons do
Nenue@6 544 local button = kb.GetSlot(i)
Nenue@6 545 button:SetID(i+kb.scrollOffset)
Nenue@6 546 kb.UpdateSlot(button, force)
Nenue@6 547 end
Nenue@6 548
Nenue@6 549 if kb.bindsCommitted then
Nenue@6 550 KeyBinderSaveButton:Disable()
Nenue@6 551 --KeyBinderRestoreButton:Disable()
Nenue@6 552 else
Nenue@6 553 KeyBinderSaveButton:Enable()
Nenue@6 554 --KeyBinderRestoreButton:Enable()
Nenue@6 555 end
Nenue@6 556
Nenue@6 557 --- Frame Sizing
Nenue@6 558 kb.profilebg:SetHeight(kb.tabSize[2] + BUTTON_PADDING * 2 + kb.profiletext:GetStringHeight())
Nenue@6 559
Nenue@6 560 kb.bg:SetWidth((KEY_BUTTON_SIZE + BUTTON_HSPACING + BUTTON_SPACING) * BINDS_PER_ROW + BUTTON_PADDING*2 - BUTTON_SPACING)
Nenue@6 561 local numRows = numButtons/BINDS_PER_ROW
Nenue@6 562
Nenue@6 563 kb.bg:SetHeight((KEY_BUTTON_SIZE + BUTTON_SPACING) * numRows + BUTTON_PADDING*2 - BUTTON_SPACING)
Nenue@6 564
Nenue@6 565 kb:SetHeight(kb.headerbg:GetHeight() + kb.profilebg:GetHeight() + kb.bg:GetHeight() + kb.footer:GetHeight())
Nenue@6 566 kb:SetWidth((kb.sourcesbg:GetWidth() +(BINDS_PER_ROW * (KEY_BUTTON_SIZE + BUTTON_HSPACING) + (BINDS_PER_ROW - 1) * BUTTON_SPACING + BUTTON_PADDING * 2) ))
Nenue@6 567
Nenue@6 568 kb.bg:SetColorTexture(unpack(BINDING_SCHEME_COLOR[kb.db.bindMode]))
Nenue@6 569 for i, tab in ipairs(kb.tabButtons) do
Nenue@6 570 local border = tab:GetNormalTexture()
Nenue@6 571 local tabTexture = "Interface\\Buttons\\UI-Quickslot2"
Nenue@6 572 local left, top, right, bottom = -12, 12, 13, -13
Nenue@6 573 if i == kb.db.bindMode then
Nenue@6 574 tabTexture = "Interface\\Buttons\\CheckButtonGlow"
Nenue@6 575 left, top, right, bottom = -14, 14, 15, -15
Nenue@6 576 tab.icon:SetDesaturated(false)
Nenue@6 577 if tab.icon2 then tab.icon2:SetDesaturated(false) end
Nenue@6 578 border:SetDesaturated(true)
Nenue@6 579 border:SetVertexColor(1,1,1, 1)
Nenue@6 580 else
Nenue@6 581 tab.icon:SetDesaturated(true)
Nenue@6 582 if tab.icon2 then tab.icon2:SetDesaturated(true) end
Nenue@6 583 border:SetDesaturated(false)
Nenue@6 584 border:SetVertexColor(1,1,1)
Nenue@6 585 end
Nenue@6 586 border:SetTexture(tabTexture)
Nenue@6 587 border:SetPoint('TOPLEFT', tab, 'TOPLEFT', left, top)
Nenue@6 588 border:SetPoint('BOTTOMRIGHT', tab, 'BOTTOMRIGHT', right, bottom)
Nenue@6 589 end
Nenue@6 590
Nenue@6 591 KeyBinderSpecTab.icon:SetTexture(kb.specInfo.texture)
Nenue@6 592
Nenue@6 593 kb.profiletext:SetText(kb.configHeaders[kb.db.bindMode])
Nenue@6 594 print(kb.db.bindMode, kb.configHeaders[kb.db.bindMode], kb:GetSize())
Nenue@6 595 print(kb:GetPoint(1))
Nenue@6 596
Nenue@6 597 kb:Show()
Nenue@6 598
Nenue@6 599 -- Reset this so talent cache can be rebuilt
Nenue@6 600 kb.talentsPushed = nil
Nenue@6 601 end
Nenue@6 602
Nenue@6 603 kb.AcceptAssignment = function(self, ...)
Nenue@6 604 local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"]
Nenue@6 605 local source = loadedProfiles[popup.oldProfile]
Nenue@6 606 kb.SetSlot(popup.slot, unpack(popup.args))
Nenue@6 607 kb.UpdateSlot(popup.slot)
Nenue@6 608 kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) -- re-enable scrolling
Nenue@6 609 ClearCursor()
Nenue@6 610 ResetCursor()
Nenue@6 611 end
Nenue@6 612
Nenue@6 613
Nenue@6 614 --- Add to blizzard interfaces
Nenue@6 615 StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] = {
Nenue@6 616 text = "Confirm moving an assigned command.",
Nenue@6 617 button1 = OKAY,
Nenue@6 618 button2 = CANCEL,
Nenue@6 619 timeout = 0,
Nenue@6 620 whileDead = 1,
Nenue@6 621 showAlert = 1,
Nenue@6 622 OnAccept = kb.AcceptAssignment,
Nenue@6 623 OnCancel = function() kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) end
Nenue@6 624 }