comparison SkeletonKey/BindingsUI.lua @ 14:82170735e67c

- move co-routine handler to general lib - slightly better handling of pet actions
author Nenue
date Thu, 28 Jul 2016 23:58:53 -0400
parents SkeletonKey/UI.lua@eeec4a600064
children 32d64e42ec9b
comparison
equal deleted inserted replaced
13:eeec4a600064 14:82170735e67c
1 -- KrakTool
2 -- BindingsUI.lua
3 -- Created: 7/28/2016 3:39 PM
4 -- %file-revision%
5 --
6
7 local kb, print = LibStub("LibKraken").register(KeyBinder, 'KeySlot')
8 local BINDS_PER_ROW = 2
9 local BUTTON_HSPACING = 128
10 local BUTTON_SPACING = 4
11 local BUTTON_PADDING = 12
12 local BINDING_TYPE_SPECIALIZATION = 3
13 local BINDING_TYPE_CHARACTER = 2
14 local BINDING_TYPE_GLOBAL = 1
15 local KEY_BUTTON_SIZE = 48
16 local MIN_BIND_SLOTS = 32
17 local TAB_OFFSET = 12
18 local TAB_HEIGHT = 40
19 local TAB_SPACING = 2
20
21 local BINDING_SCHEME_COLOR = {
22 [BINDING_TYPE_GLOBAL] = {0,.125,.5,.5},
23 [BINDING_TYPE_CHARACTER] = {0,0.25,0,0.5},
24 [BINDING_TYPE_SPECIALIZATION] = {.25,0,0,0.5},
25 }
26 local BINDING_SCHEME_VERTEX = {
27 [BINDING_TYPE_GLOBAL] = {0,.5,1,1},
28 [BINDING_TYPE_CHARACTER] = {0,1,0,1},
29 [BINDING_TYPE_SPECIALIZATION] = {1,1,1,1},
30 }
31 local BINDING_SCHEME_TEXT = {
32 [BINDING_TYPE_SPECIALIZATION] = {0, 1, 1},
33 [BINDING_TYPE_CHARACTER] = {0, 1, 0},
34 [BINDING_TYPE_GLOBAL] = {0, 1, 1}
35 }
36
37 local restingAlpha = 0.7
38 local fadeTime, fadeDelay = .30, 0.15
39 local numButtons = BINDS_PER_ROW * 8
40 local saveButton
41 local KeyButton_OnKeyDown = function(self, key)
42 kb.StoreBinding(self, key)
43 end
44 local KeyButton_OnClick = function(self, click)
45 print(self:GetName(), 'OnMouseDown', click)
46 if click == 'LeftButton' then
47 kb.DropToSlot(self)
48 elseif click == 'RightButton' then
49 kb.ReleaseSlot(self)
50 else
51 kb.StoreBinding(self, click:upper())
52 end
53 end
54
55 local KeyButton_OnDragStart = function(self)
56 kb.PickupSlot(self)
57 end
58
59 local KeyButton_OnReceiveDrag = function(self, ...)
60 kb.DropToSlot(self)
61 end
62
63
64 local KeyBinder_OnUpdate = function(self, elapsed)
65 self.elapsed = self.elapsed + elapsed
66 self.throttle = self.throttle + elapsed
67
68 if (self.throttle >= 0.032) then
69 self.throttle = 0
70 else
71 return
72 end
73
74 local progress = 1
75 if self.elapsed > fadeTime then
76 self.elapsed = 0
77 self.fadeStep = 0
78 --self.statustext:SetText(nil)
79 --self.bindingstext:SetText(nil)
80 self:SetScript('OnUpdate', nil)
81 else
82 if self.elapsed < fadeDelay then
83 progress = 0
84 else
85 self.fadeStep = self.fadeStep + 1
86 progress = (self.elapsed - fadeDelay) /(fadeTime - fadeDelay)
87 end
88 --print(self.fadeStep, format('%.02f/%.02f', (self.elapsed - fadeDelay) ,(fadeTime - fadeDelay)) , progress)
89 end
90
91 local alpha = 1 - progress * (1- restingAlpha)
92 self.statustext:SetAlpha(alpha)
93 self.bindingstext:SetAlpha(alpha)
94 end
95
96 local KeyButton_OnUpdate = function(self)
97 if not self.command then
98 return
99 end
100
101 if self:IsMouseOver() then
102 kb.elapsed = 0
103 if not self.active then
104 -- only set this handler when the button is activated/mouseOver
105 self.active = true
106 self:SetScript('OnKeyDown', KeyButton_OnKeyDown)
107
108 kb.statustext:SetText(self.statusText .. ': '..self.actionName)
109 kb.bindingstext:SetText(self.bindingText)
110 kb.fadeStep = 0
111 kb.throttle = 0
112 kb:SetScript('OnUpdate', KeyBinder_OnUpdate)
113
114 end
115 else
116 if self.active then
117 self.active = nil
118 self:SetScript('OnKeyDown', nil)
119 end
120 end
121 end
122
123 local KeyBinder_OnMouseWheel = function(self, delta)
124 print(self, delta, self.scrollOffset, (self.scrollOffset <= 0))
125
126
127 if IsControlKeyDown() then
128 KEY_BUTTON_SIZE = KEY_BUTTON_SIZE - delta
129 else
130
131
132 if (delta > 0) and (self.scrollOffset <= 0) then
133 return
134 elseif delta < 0 and kb.scrollOffset >= 42 then
135 return
136 end
137 kb.scrollOffset = ceil(kb.scrollOffset - (delta * BINDS_PER_ROW))
138 end
139
140 kb.ui(true)
141 end
142
143 local KeyBinder_OnHide = function()
144 KeyBinderImportLog:Hide()
145 end
146
147 local CloseButton_OnClick = function()
148 kb.db.showUI = false
149 kb:Hide()
150 end
151 local CancelButton_OnClick = function()
152 kb.RevertBindings()
153 end
154 local SaveButton_OnClick = function()
155 kb.ConfirmBindings()
156 end
157
158 local KeyBinder_Initialize = function()
159
160
161 kb.scrollOffset = 0
162 kb.tabAnchor = {'TOPLEFT', kb.profilebg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING}
163 kb.tabGrowth = {'TOPLEFT', nil,'TOPRIGHT', BUTTON_SPACING, 0}
164 kb.tabSize = {TAB_HEIGHT, TAB_HEIGHT }
165 kb.UIPanelAnchor = {'TOPLEFT', kb.sourcesbg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING}
166 kb.UIPanelGrowth = {'TOPLEFT', nil, 'BOTTOMLEFT', 0, -2 }
167 kb.UIPanelSize = {84, 32 }
168 kb.UIPanelIcon = {24, 32, 'LEFT', -12, 0}
169 kb.controlsAnchor = {'BOTTOMLEFT', kb.footer, BUTTON_PADDING, BUTTON_PADDING }
170 kb.controlsGrowth = {'BOTTOMLEFT', nil, 'BOTTOMRIGHT', BUTTON_SPACING, 0}
171
172 -- order of these is important
173 kb:tab('KeyBinderGlobalTab',
174 kb.configTitle[BINDING_TYPE_GLOBAL] .. '\n' .. kb.configDescription[BINDING_TYPE_GLOBAL], "Interface\\ICONS\\item_azereansphere", {0.15,.85,.15,.85})
175 kb:tab('KeyBinderCharacterTab',
176 kb.configHeaders[BINDING_TYPE_CHARACTER] .. '\n' .. kb.configDescription[BINDING_TYPE_CHARACTER], nil)
177 kb:tab('KeyBinderSpecTab',
178 kb.configHeaders[BINDING_TYPE_SPECIALIZATION] .. '\n' .. kb.configDescription[BINDING_TYPE_SPECIALIZATION], kb.specInfo.texture)
179 KeyBinderCharacterTab.icon:SetTexCoord(0.15,.85,.15,.85)
180
181
182
183 --portraitLayers[1] = KeyBinderCharacterTab.icon
184
185 saveButton = kb:button('KeyBinderSaveButton', 'Refresh', 'Reload current bindings and refresh panel.', SaveButton_OnClick)
186 --restoreButton = kb:button('KeyBinderRestoreButton', 'Discard', 'Revert all changes.', CancelButton_OnClick)
187 --clearButton = kb:button('KeyBinderClearButton', 'Clear Page', 'Release all buttons.', ResetButton_OnClick)
188
189 kb:uibutton(
190 'KeyBinderSpellBookButton', 'SpellBook', nil,
191 function() ToggleSpellBook(BOOKTYPE_SPELL) end,
192 "Interface\\BUTTONS\\UI-MicroButton-Spellbook-Up", {0, 1, .4, 1})
193 kb:uibutton(
194 'KeyBinderTalentFrameButton', TALENTS, SPECIALIZATION,
195 function() ToggleTalentFrame() end,
196 "Interface\\BUTTONS\\UI-MicroButton-Talents-Up", {0, 1, .4, 1})
197
198 kb:uibutton(
199 'KeyBinderMacroFrameButton', 'Macros', nil,
200 function() if MacroFrame and MacroFrame:IsVisible() then
201 HideUIPanel(MacroFrame)
202 else
203 ShowMacroFrame() end
204 end,
205 "Interface\\BUTTONS\\UI-MicroButton-Help-Up", {0, 1, .4, 1})
206
207 kb:uibutton(
208 'KeyBinderInventoryButton', 'Bags', nil,
209 function() OpenAllBags() end,
210 "Interface\\BUTTONS\\UI-MicroButtonCharacter-Up", {0, 1, .4, 1})
211
212
213
214 kb.info:SetPoint('TOPLEFT', kb.UIPanels[1], 'BOTTOMLEFT', 0, -BUTTON_SPACING)
215 HEADER_OFFSET = kb.UIPanels[1]:GetHeight() + BUTTON_PADDING
216 + kb.info:GetHeight()
217 FOOTER_OFFSET = saveButton:GetHeight() + BUTTON_PADDING
218
219 kb:SetScript('OnHide', KeyBinder_OnHide)
220 kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel)
221 kb.CloseButton:SetScript('OnClick', CloseButton_OnClick)
222
223 end
224
225
226 --- Retrieves button at index; creates said button and instates any stored parameters
227 do
228 local leftSlot, upSlot
229 local buttonsDepth = 0
230 kb.GetSlot = function(index)
231
232 local slot = index + kb.scrollOffset
233
234 if not kb.buttons[index] then
235 local button = CreateFrame('CheckButton', 'KeyBinderSlot'..index, kb, 'KeyButton')
236 button:SetScript('OnClick', KeyButton_OnClick)
237 button:SetScript('OnUpdate', KeyButton_OnUpdate)
238 button:SetScript('OnDragStart', KeyButton_OnDragStart)
239 button:SetScript('OnReceiveDrag', KeyButton_OnReceiveDrag)
240 button:RegisterForClicks('AnyUp')
241
242
243 local newRow = (mod(index, BINDS_PER_ROW) == 1)
244
245 if index == 1 then
246 button:SetPoint('TOPLEFT', kb.bg, 'TOPLEFT', BUTTON_PADDING, - BUTTON_PADDING)
247 upSlot = button
248 buttonsDepth = KEY_BUTTON_SIZE + BUTTON_PADDING * 2
249 elseif newRow then
250 button:SetPoint('TOPLEFT', upSlot, 'BOTTOMLEFT', 0, -BUTTON_SPACING)
251 upSlot = button
252 buttonsDepth = buttonsDepth + KEY_BUTTON_SIZE + BUTTON_SPACING
253 else
254 button:SetPoint('TOPLEFT', leftSlot, 'TOPRIGHT', BUTTON_HSPACING, 0)
255 end
256
257 button:SetSize(KEY_BUTTON_SIZE, KEY_BUTTON_SIZE)
258 button:Show()
259 kb.buttons[index] = button
260 leftSlot = button
261 end
262 return kb.buttons[index]
263 end
264 end
265
266
267 --- push current information into living UI
268 kb.ui = function(force)
269 for i, module in ipairs(kb.modules) do
270 if module.ui then
271 module.ui(force)
272 end
273 end
274
275 if not kb.db.showUI then
276 print('---end of refresh')
277 return
278 end
279 if not kb.loaded then
280 KeyBinder_Initialize()
281 kb.loaded = true
282 end
283 for i = 1, numButtons do
284 local button = kb.GetSlot(i)
285 button:SetID(i+kb.scrollOffset)
286 kb.UpdateSlot(button, force)
287 end
288
289
290 --- Frame Sizing
291 kb.profilebg:SetHeight(kb.tabSize[2] + BUTTON_PADDING * 2 + kb.profiletext:GetStringHeight())
292
293 kb.bg:SetWidth((KEY_BUTTON_SIZE + BUTTON_HSPACING + BUTTON_SPACING) * BINDS_PER_ROW + BUTTON_PADDING*2 - BUTTON_SPACING)
294 local numRows = numButtons/BINDS_PER_ROW
295
296 kb.bg:SetHeight((KEY_BUTTON_SIZE + BUTTON_SPACING) * numRows + BUTTON_PADDING*2 - BUTTON_SPACING)
297
298 kb:SetHeight(kb.headerbg:GetHeight() + kb.profilebg:GetHeight() + kb.bg:GetHeight() + kb.footer:GetHeight())
299 kb:SetWidth((kb.sourcesbg:GetWidth() +(BINDS_PER_ROW * (KEY_BUTTON_SIZE + BUTTON_HSPACING) + (BINDS_PER_ROW - 1) * BUTTON_SPACING + BUTTON_PADDING * 2) ))
300
301 kb.bg:SetColorTexture(unpack(BINDING_SCHEME_COLOR[kb.db.bindMode]))
302 for i, tab in ipairs(kb.tabButtons) do
303 local border = tab:GetNormalTexture()
304 local tabTexture = "Interface\\Buttons\\UI-Quickslot2"
305 local left, top, right, bottom = -12, 12, 13, -13
306 if i == kb.db.bindMode then
307 tabTexture = "Interface\\Buttons\\CheckButtonGlow"
308 left, top, right, bottom = -14, 14, 15, -15
309 tab.icon:SetDesaturated(false)
310 if tab.icon2 then tab.icon2:SetDesaturated(false) end
311 border:SetDesaturated(true)
312 border:SetVertexColor(1,1,1, 1)
313 else
314 tab.icon:SetDesaturated(true)
315 if tab.icon2 then tab.icon2:SetDesaturated(true) end
316 border:SetDesaturated(false)
317 border:SetVertexColor(1,1,1)
318 end
319 border:SetTexture(tabTexture)
320 border:SetPoint('TOPLEFT', tab, 'TOPLEFT', left, top)
321 border:SetPoint('BOTTOMRIGHT', tab, 'BOTTOMRIGHT', right, bottom)
322 end
323
324 KeyBinderSpecTab.icon:SetTexture(kb.specInfo.texture)
325 SetPortraitTexture(KeyBinderCharacterTab.icon, 'player')
326
327 kb.profiletext:SetText(kb.configHeaders[kb.db.bindMode])
328 print(kb.db.bindMode, kb.configHeaders[kb.db.bindMode], kb:GetSize())
329 print(kb:GetPoint(1))
330
331 kb:Show()
332
333 -- Reset this so talent cache can be rebuilt
334 kb.talentsPushed = nil
335 end
336
337 kb.AcceptAssignment = function(self, ...)
338 local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"]
339 local source = loadedProfiles[popup.oldProfile]
340 kb.SetSlot(popup.slot, unpack(popup.args))
341 kb.UpdateSlot(popup.slot)
342 kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) -- re-enable scrolling
343 ClearCursor()
344 ResetCursor()
345 end