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@11
|
204 saveButton = kb:button('KeyBinderSaveButton', 'Refresh', 'Reload current bindings and refresh panel.', 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 elseif actionType == 'macro' then
|
Nenue@6
|
327 if not actionID then
|
Nenue@6
|
328 actionID = GetMacroIndexByName(name)
|
Nenue@6
|
329 end
|
Nenue@6
|
330 isAvailable = true
|
Nenue@6
|
331 else
|
Nenue@6
|
332 --- Journal selections
|
Nenue@6
|
333 -- todo: consider using the deep end of blizzard action bar instead
|
Nenue@6
|
334 if not actionID then
|
Nenue@6
|
335 actionID = command:match("^KeyBinderMacro:(.+)")
|
Nenue@6
|
336 end
|
Nenue@6
|
337 isAvailable = true
|
Nenue@6
|
338 end
|
Nenue@6
|
339
|
Nenue@6
|
340 if isAvailable then
|
Nenue@6
|
341 local oldCommand = command
|
Nenue@13
|
342 macroName, macroText, command = kb.RegisterAction(actionType, actionID, name)
|
Nenue@6
|
343 if oldCommand ~= command then
|
Nenue@6
|
344 print('|cFFFF4400fixing command string', actionType, actionID, name)
|
Nenue@6
|
345 kb.currentProfile.bound[oldCommand] = nil
|
Nenue@6
|
346 kb.currentProfile.bound[command] = slot
|
Nenue@6
|
347 for k,v in pairs(kb.currentProfile.bindings) do
|
Nenue@6
|
348 if v == oldCommand then
|
Nenue@6
|
349 kb.currentProfile.bindings[k] = command
|
Nenue@6
|
350 end
|
Nenue@6
|
351 end
|
Nenue@6
|
352 end
|
Nenue@6
|
353 kb.LoadBinding(command, name, icon, actionType, actionID, macroName, macroText)
|
Nenue@6
|
354 end
|
Nenue@6
|
355
|
Nenue@6
|
356 if actionType == 'petaction' then
|
Nenue@6
|
357 self.pickupSlot = pickupSlot
|
Nenue@6
|
358 self.pickupBook = pickupBook
|
Nenue@6
|
359 else
|
Nenue@6
|
360 self.pickupSlot = nil
|
Nenue@6
|
361 self.pickupBook = nil
|
Nenue@6
|
362 end
|
Nenue@6
|
363
|
Nenue@6
|
364 actionID = actionID or 0
|
Nenue@6
|
365 self:EnableKeyboard(true)
|
Nenue@6
|
366 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
|
367 kb.currentProfile.buttons[slot] = {command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook}
|
Nenue@6
|
368
|
Nenue@6
|
369 -- Clean up conflicting entries for loaded button
|
Nenue@6
|
370 local previous = kb.currentProfile.commands[command]
|
Nenue@6
|
371 if previous ~= slot and kb.buttons[previous] then
|
Nenue@6
|
372 kb.ReleaseSlot(kb.buttons[previous])
|
Nenue@6
|
373 end
|
Nenue@6
|
374 kb.currentProfile.commands[command] = slot
|
Nenue@6
|
375 end
|
Nenue@6
|
376
|
Nenue@6
|
377 self.isAvailable = isAvailable
|
Nenue@6
|
378 self.isDynamic = isDynamic
|
Nenue@6
|
379
|
Nenue@6
|
380 self.macroText = macroText
|
Nenue@6
|
381 self.macroName = macroName
|
Nenue@6
|
382 self.actionType = actionType
|
Nenue@6
|
383 self.actionID = actionID
|
Nenue@6
|
384 self.actionName = name
|
Nenue@6
|
385 self.command = command
|
Nenue@6
|
386 self.icon:SetTexture(icon)
|
Nenue@6
|
387 self.profile = kb.db.bindMode
|
Nenue@6
|
388 self:RegisterForDrag('LeftButton')
|
Nenue@6
|
389 end
|
Nenue@6
|
390
|
Nenue@6
|
391 --- Retrieves button at index; creates said button and instates any stored parameters
|
Nenue@7
|
392 do
|
Nenue@7
|
393 local leftSlot, upSlot
|
Nenue@7
|
394 local buttonsDepth = 0
|
Nenue@7
|
395 kb.GetSlot = function(index)
|
Nenue@6
|
396
|
Nenue@7
|
397 local slot = index + kb.scrollOffset
|
Nenue@6
|
398
|
Nenue@7
|
399 if not kb.buttons[index] then
|
Nenue@7
|
400 local button = CreateFrame('CheckButton', 'KeyBinderSlot'..index, kb, 'KeyButton')
|
Nenue@7
|
401 button:SetScript('OnClick', KeyButton_OnClick)
|
Nenue@7
|
402 button:SetScript('OnUpdate', KeyButton_OnUpdate)
|
Nenue@7
|
403 button:SetScript('OnDragStart', KeyButton_OnDragStart)
|
Nenue@7
|
404 button:SetScript('OnReceiveDrag', KeyButton_OnReceiveDrag)
|
Nenue@7
|
405 button:RegisterForClicks('AnyUp')
|
Nenue@6
|
406
|
Nenue@6
|
407
|
Nenue@7
|
408 local newRow = (mod(index, BINDS_PER_ROW) == 1)
|
Nenue@6
|
409
|
Nenue@7
|
410 if index == 1 then
|
Nenue@7
|
411 button:SetPoint('TOPLEFT', kb.bg, 'TOPLEFT', BUTTON_PADDING, - BUTTON_PADDING)
|
Nenue@7
|
412 upSlot = button
|
Nenue@7
|
413 buttonsDepth = KEY_BUTTON_SIZE + BUTTON_PADDING * 2
|
Nenue@7
|
414 elseif newRow then
|
Nenue@7
|
415 button:SetPoint('TOPLEFT', upSlot, 'BOTTOMLEFT', 0, -BUTTON_SPACING)
|
Nenue@7
|
416 upSlot = button
|
Nenue@7
|
417 buttonsDepth = buttonsDepth + KEY_BUTTON_SIZE + BUTTON_SPACING
|
Nenue@7
|
418 else
|
Nenue@7
|
419 button:SetPoint('TOPLEFT', leftSlot, 'TOPRIGHT', BUTTON_HSPACING, 0)
|
Nenue@7
|
420 end
|
Nenue@7
|
421
|
Nenue@7
|
422 button:SetSize(KEY_BUTTON_SIZE, KEY_BUTTON_SIZE)
|
Nenue@7
|
423 button:Show()
|
Nenue@7
|
424 kb.buttons[index] = button
|
Nenue@7
|
425 leftSlot = button
|
Nenue@6
|
426 end
|
Nenue@7
|
427 return kb.buttons[index]
|
Nenue@6
|
428 end
|
Nenue@6
|
429 end
|
Nenue@6
|
430
|
Nenue@6
|
431 --- Updates profile assignment and button contents
|
Nenue@6
|
432 kb.UpdateSlot = function(self, force)
|
Nenue@6
|
433 local slot = self:GetID()
|
Nenue@6
|
434
|
Nenue@6
|
435 if force then
|
Nenue@6
|
436 if kb.currentProfile.buttons[slot] then
|
Nenue@6
|
437 kb.SetSlot(self, unpack(kb.currentProfile.buttons[slot]))
|
Nenue@6
|
438 else
|
Nenue@6
|
439 kb.ReleaseSlot(self)
|
Nenue@6
|
440 end
|
Nenue@6
|
441 end
|
Nenue@6
|
442
|
Nenue@6
|
443 if self.command then
|
Nenue@6
|
444 print('['..slot..'] =', self.command, GetBindingKey(self.command))
|
Nenue@6
|
445
|
Nenue@6
|
446 if self.pending then
|
Nenue@6
|
447 self.border:SetColorTexture(unpack(BORDER_PENDING))
|
Nenue@6
|
448 elseif self.isDynamic then
|
Nenue@6
|
449 self.border:SetColorTexture(unpack(BORDER_DYNAMIC))
|
Nenue@6
|
450 else
|
Nenue@6
|
451 self.border:SetColorTexture(unpack(BORDER_ASSIGNED))
|
Nenue@6
|
452 end
|
Nenue@6
|
453
|
Nenue@6
|
454 if self.actionType == 'macro' then
|
Nenue@6
|
455 self.macro:Show()
|
Nenue@6
|
456 else
|
Nenue@6
|
457 self.macro:Hide()
|
Nenue@6
|
458 if self.actionType == 'spell' then
|
Nenue@6
|
459 local dummy = GetSpellInfo(self.actionName)
|
Nenue@6
|
460 if not dummy then
|
Nenue@6
|
461 self.icon:SetDesaturated(true)
|
Nenue@6
|
462 else
|
Nenue@6
|
463 self.icon:SetDesaturated(false)
|
Nenue@6
|
464 end
|
Nenue@6
|
465
|
Nenue@6
|
466 end
|
Nenue@6
|
467 end
|
Nenue@6
|
468
|
Nenue@6
|
469 if self.isDynamic then
|
Nenue@6
|
470 print('|cFFFFBB00UpdateSlot|r: ', self.isDynamic, self.isAvailable, self.actionID)
|
Nenue@6
|
471 end
|
Nenue@6
|
472
|
Nenue@6
|
473 if self.isDynamic == 'profession' then
|
Nenue@6
|
474 local profText = (self.spellNum == 1) and TRADE_SKILLS or (BUTTON_HEADERS[self.profIndex] or GetProfessionInfo(self.profIndex))
|
Nenue@6
|
475 if self.isAvailable then
|
Nenue@6
|
476 print(self.profIndex, 'spnum', type(self.spellNum), (self.spellNum == 1))
|
Nenue@6
|
477
|
Nenue@6
|
478 self.statusText = '|cFFFFFF00'..profText..'|r'
|
Nenue@6
|
479 self.bindingText = kb.BindingString(GetBindingKey(self.command))
|
Nenue@6
|
480 else
|
Nenue@6
|
481 self.statusText = '|cFFFF4400'..profText..'|r'
|
Nenue@6
|
482 self.actionName = '(need to train profession #'..self.profNum..')'
|
Nenue@6
|
483 self.bindingText ='?'
|
Nenue@6
|
484 end
|
Nenue@6
|
485 elseif self.isDynamic == 'talent' then
|
Nenue@6
|
486
|
Nenue@6
|
487 self.statusText = '|cFF00FFFF'.. TALENT .. '|r'
|
Nenue@6
|
488 if self.isAvailable then
|
Nenue@6
|
489 self.bindingText = kb.BindingString(GetBindingKey(self.command))
|
Nenue@6
|
490 else
|
Nenue@6
|
491 if kb.inactiveTalentBindings[self.actionID] then
|
Nenue@6
|
492 print(self.actionID, #kb.inactiveTalentBindings[self.actionID])
|
Nenue@6
|
493 self.bindingText= kb.BindingString(unpack(kb.inactiveTalentBindings[self.actionID]))
|
Nenue@6
|
494 end
|
Nenue@6
|
495
|
Nenue@6
|
496 end
|
Nenue@6
|
497 else
|
Nenue@6
|
498 self.statusText = '|cFF00FF00'.. (BUTTON_HEADERS[self.actionType] and BUTTON_HEADERS[self.actionType] or self.actionType) .. '|r'
|
Nenue@6
|
499 self.bindingText = kb.BindingString(GetBindingKey(self.command))
|
Nenue@6
|
500 end
|
Nenue@6
|
501
|
Nenue@6
|
502 local locked, layer = kb.IsCommandBound(self)
|
Nenue@6
|
503 if locked then
|
Nenue@6
|
504 self.icon:SetAlpha(0.5)
|
Nenue@6
|
505 else
|
Nenue@6
|
506 self.icon:SetAlpha(1)
|
Nenue@6
|
507 end
|
Nenue@6
|
508
|
Nenue@6
|
509 if self.actionType == 'spell' then
|
Nenue@6
|
510 self.icon:SetTexture(GetSpellTexture(self.actionID))
|
Nenue@6
|
511 end
|
Nenue@6
|
512 end
|
Nenue@6
|
513
|
Nenue@6
|
514 if not self.isAvailable then
|
Nenue@6
|
515 self.bind:SetTextColor(0.7,0.7,0.7,1)
|
Nenue@6
|
516 else
|
Nenue@6
|
517 self.bind:SetTextColor(1,1,1,1)
|
Nenue@6
|
518 end
|
Nenue@6
|
519
|
Nenue@6
|
520 self.header:SetText(self.statusText)
|
Nenue@6
|
521 self.bind:SetText(self.bindingText)
|
Nenue@6
|
522 self.details:SetText(self.actionName)
|
Nenue@6
|
523 end
|
Nenue@6
|
524
|
Nenue@6
|
525 --- push current information into living UI
|
Nenue@6
|
526 kb.ui = function(force)
|
Nenue@6
|
527 for i, module in ipairs(kb.modules) do
|
Nenue@6
|
528 if module.ui then
|
Nenue@6
|
529 module.ui(force)
|
Nenue@6
|
530 end
|
Nenue@6
|
531 end
|
Nenue@6
|
532
|
Nenue@6
|
533 if not kb.db.showUI then
|
Nenue@6
|
534 print('---end of refresh')
|
Nenue@6
|
535 return
|
Nenue@6
|
536 end
|
Nenue@6
|
537 if not kb.loaded then
|
Nenue@6
|
538 KeyBinder_Initialize()
|
Nenue@6
|
539 kb.loaded = true
|
Nenue@6
|
540 end
|
Nenue@6
|
541 for i = 1, numButtons do
|
Nenue@6
|
542 local button = kb.GetSlot(i)
|
Nenue@6
|
543 button:SetID(i+kb.scrollOffset)
|
Nenue@6
|
544 kb.UpdateSlot(button, force)
|
Nenue@6
|
545 end
|
Nenue@6
|
546
|
Nenue@6
|
547
|
Nenue@6
|
548 --- Frame Sizing
|
Nenue@6
|
549 kb.profilebg:SetHeight(kb.tabSize[2] + BUTTON_PADDING * 2 + kb.profiletext:GetStringHeight())
|
Nenue@6
|
550
|
Nenue@6
|
551 kb.bg:SetWidth((KEY_BUTTON_SIZE + BUTTON_HSPACING + BUTTON_SPACING) * BINDS_PER_ROW + BUTTON_PADDING*2 - BUTTON_SPACING)
|
Nenue@6
|
552 local numRows = numButtons/BINDS_PER_ROW
|
Nenue@6
|
553
|
Nenue@6
|
554 kb.bg:SetHeight((KEY_BUTTON_SIZE + BUTTON_SPACING) * numRows + BUTTON_PADDING*2 - BUTTON_SPACING)
|
Nenue@6
|
555
|
Nenue@6
|
556 kb:SetHeight(kb.headerbg:GetHeight() + kb.profilebg:GetHeight() + kb.bg:GetHeight() + kb.footer:GetHeight())
|
Nenue@6
|
557 kb:SetWidth((kb.sourcesbg:GetWidth() +(BINDS_PER_ROW * (KEY_BUTTON_SIZE + BUTTON_HSPACING) + (BINDS_PER_ROW - 1) * BUTTON_SPACING + BUTTON_PADDING * 2) ))
|
Nenue@6
|
558
|
Nenue@6
|
559 kb.bg:SetColorTexture(unpack(BINDING_SCHEME_COLOR[kb.db.bindMode]))
|
Nenue@6
|
560 for i, tab in ipairs(kb.tabButtons) do
|
Nenue@6
|
561 local border = tab:GetNormalTexture()
|
Nenue@6
|
562 local tabTexture = "Interface\\Buttons\\UI-Quickslot2"
|
Nenue@6
|
563 local left, top, right, bottom = -12, 12, 13, -13
|
Nenue@6
|
564 if i == kb.db.bindMode then
|
Nenue@6
|
565 tabTexture = "Interface\\Buttons\\CheckButtonGlow"
|
Nenue@6
|
566 left, top, right, bottom = -14, 14, 15, -15
|
Nenue@6
|
567 tab.icon:SetDesaturated(false)
|
Nenue@6
|
568 if tab.icon2 then tab.icon2:SetDesaturated(false) end
|
Nenue@6
|
569 border:SetDesaturated(true)
|
Nenue@6
|
570 border:SetVertexColor(1,1,1, 1)
|
Nenue@6
|
571 else
|
Nenue@6
|
572 tab.icon:SetDesaturated(true)
|
Nenue@6
|
573 if tab.icon2 then tab.icon2:SetDesaturated(true) end
|
Nenue@6
|
574 border:SetDesaturated(false)
|
Nenue@6
|
575 border:SetVertexColor(1,1,1)
|
Nenue@6
|
576 end
|
Nenue@6
|
577 border:SetTexture(tabTexture)
|
Nenue@6
|
578 border:SetPoint('TOPLEFT', tab, 'TOPLEFT', left, top)
|
Nenue@6
|
579 border:SetPoint('BOTTOMRIGHT', tab, 'BOTTOMRIGHT', right, bottom)
|
Nenue@6
|
580 end
|
Nenue@6
|
581
|
Nenue@6
|
582 KeyBinderSpecTab.icon:SetTexture(kb.specInfo.texture)
|
Nenue@12
|
583 SetPortraitTexture(KeyBinderCharacterTab.icon, 'player')
|
Nenue@6
|
584
|
Nenue@6
|
585 kb.profiletext:SetText(kb.configHeaders[kb.db.bindMode])
|
Nenue@6
|
586 print(kb.db.bindMode, kb.configHeaders[kb.db.bindMode], kb:GetSize())
|
Nenue@6
|
587 print(kb:GetPoint(1))
|
Nenue@6
|
588
|
Nenue@6
|
589 kb:Show()
|
Nenue@6
|
590
|
Nenue@6
|
591 -- Reset this so talent cache can be rebuilt
|
Nenue@6
|
592 kb.talentsPushed = nil
|
Nenue@6
|
593 end
|
Nenue@6
|
594
|
Nenue@6
|
595 kb.AcceptAssignment = function(self, ...)
|
Nenue@6
|
596 local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"]
|
Nenue@6
|
597 local source = loadedProfiles[popup.oldProfile]
|
Nenue@6
|
598 kb.SetSlot(popup.slot, unpack(popup.args))
|
Nenue@6
|
599 kb.UpdateSlot(popup.slot)
|
Nenue@6
|
600 kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) -- re-enable scrolling
|
Nenue@6
|
601 ClearCursor()
|
Nenue@6
|
602 ResetCursor()
|
Nenue@6
|
603 end
|
Nenue@6
|
604
|
Nenue@6
|
605
|
Nenue@6
|
606 --- Add to blizzard interfaces
|
Nenue@6
|
607 StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] = {
|
Nenue@6
|
608 text = "Confirm moving an assigned command.",
|
Nenue@6
|
609 button1 = OKAY,
|
Nenue@6
|
610 button2 = CANCEL,
|
Nenue@6
|
611 timeout = 0,
|
Nenue@6
|
612 whileDead = 1,
|
Nenue@6
|
613 showAlert = 1,
|
Nenue@6
|
614 OnAccept = kb.AcceptAssignment,
|
Nenue@6
|
615 OnCancel = function() kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) end
|
Nenue@6
|
616 } |