1HOTKEY_MANAGER_USE = nil
2HOTKEY_MANAGER_USEONSELF = 1
3HOTKEY_MANAGER_USEONTARGET = 2
4HOTKEY_MANAGER_USEWITH = 3
5
6HotkeyColors = {
7 text = '#888888',
8 textAutoSend = '#FFFFFF',
9 itemUse = '#8888FF',
10 itemUseSelf = '#00FF00',
11 itemUseTarget = '#FF0000',
12 itemUseWith = '#F5B325',
13 extraAction = '#FFAA00'
14}
15
16hotkeysManagerLoaded = false
17hotkeysWindow = nil
18configSelector = nil
19hotkeysButton = nil
20currentHotkeyLabel = nil
21currentItemPreview = nil
22itemWidget = nil
23addHotkeyButton = nil
24removeHotkeyButton = nil
25hotkeyText = nil
26hotKeyTextLabel = nil
27sendAutomatically = nil
28selectObjectButton = nil
29clearObjectButton = nil
30useOnSelf = nil
31useOnTarget = nil
32useWith = nil
33defaultComboKeys = nil
34perCharacter = true
35mouseGrabberWidget = nil
36useRadioGroup = nil
37currentHotkeys = nil
38boundCombosCallback = {}
39hotkeysList = {}
40hotkeyConfigs = {}
41currentConfig = 1
42configValueChanged = false
43
44-- public functions
45function init()
46 if not g_app.isMobile() then
47 --hotkeysButton = modules.client_topmenu.addLeftGameButton('hotkeysButton', tr('Hotkeys') .. ' (Ctrl+K)', '/images/topbuttons/hotkeys', toggle, false, 7)
48 end
49 --g_keyboard.bindKeyDown('Ctrl+K', toggle)
50 hotkeysWindow = g_ui.displayUI('hotkeys_manager')
51 hotkeysWindow:setVisible(false)
52
53 configSelector = hotkeysWindow:getChildById('configSelector')
54 currentHotkeys = hotkeysWindow:getChildById('currentHotkeys')
55 currentItemPreview = hotkeysWindow:getChildById('itemPreview')
56 addHotkeyButton = hotkeysWindow:getChildById('addHotkeyButton')
57 removeHotkeyButton = hotkeysWindow:getChildById('removeHotkeyButton')
58 hotkeyText = hotkeysWindow:getChildById('hotkeyText')
59 hotKeyTextLabel = hotkeysWindow:getChildById('hotKeyTextLabel')
60 sendAutomatically = hotkeysWindow:getChildById('sendAutomatically')
61 selectObjectButton = hotkeysWindow:getChildById('selectObjectButton')
62 clearObjectButton = hotkeysWindow:getChildById('clearObjectButton')
63 useOnSelf = hotkeysWindow:getChildById('useOnSelf')
64 useOnTarget = hotkeysWindow:getChildById('useOnTarget')
65 useWith = hotkeysWindow:getChildById('useWith')
66
67 useRadioGroup = UIRadioGroup.create()
68 useRadioGroup:addWidget(useOnSelf)
69 useRadioGroup:addWidget(useOnTarget)
70 useRadioGroup:addWidget(useWith)
71 useRadioGroup.onSelectionChange = function(self, selected) onChangeUseType(selected) end
72
73 mouseGrabberWidget = g_ui.createWidget('UIWidget')
74 mouseGrabberWidget:setVisible(false)
75 mouseGrabberWidget:setFocusable(false)
76 mouseGrabberWidget.onMouseRelease = onChooseItemMouseRelease
77
78 currentHotkeys.onChildFocusChange = function(self, hotkeyLabel) onSelectHotkeyLabel(hotkeyLabel) end
79 g_keyboard.bindKeyPress('Down', function() currentHotkeys:focusNextChild(KeyboardFocusReason) end, hotkeysWindow)
80 g_keyboard.bindKeyPress('Up', function() currentHotkeys:focusPreviousChild(KeyboardFocusReason) end, hotkeysWindow)
81
82 if hotkeysWindow.action and setupExtraHotkeys then
83 setupExtraHotkeys(hotkeysWindow.action)
84 end
85
86 connect(g_game, {
87 onGameStart = online,
88 onGameEnd = offline
89 })
90
91 for i = 1, configSelector:getOptionsCount() do
92 hotkeyConfigs[i] = g_configs.create("/hotkeys_" .. i .. ".otml")
93 end
94
95 load()
96end
97
98function onSpaceAttack()
99 --print("Space Attack")
100 setupExtraHotkeys(01)
101end
102function terminate()
103 disconnect(g_game, {
104 onGameStart = online,
105 onGameEnd = offline
106 })
107
108 g_keyboard.unbindKeyDown('Ctrl+K')
109
110 unload()
111
112 hotkeysWindow:destroy()
113 --if hotkeysButton then
114 -- hotkeysButton:destroy()
115 --end
116 mouseGrabberWidget:destroy()
117end
118
119function online()
120 reload()
121 hide()
122end
123
124function offline()
125 unload()
126 hide()
127end
128
129function show()
130 if not g_game.isOnline() then
131 return
132 end
133 hotkeysWindow:show()
134 hotkeysWindow:raise()
135 hotkeysWindow:focus()
136end
137
138function hide()
139 hotkeysWindow:hide()
140end
141
142function toggle()
143 if not hotkeysWindow:isVisible() then
144 show()
145 else
146 hide()
147 end
148end
149
150function ok()
151 save()
152 hide()
153end
154
155function cancel()
156 reload()
157 hide()
158end
159
160function load(forceDefaults)
161 hotkeysManagerLoaded = false
162 currentConfig = 1
163
164 local hotkeysNode = g_settings.getNode('hotkeys') or {}
165 local index = g_game.getCharacterName() .. "_" .. g_game.getClientVersion()
166 if hotkeysNode[index] ~= nil and hotkeysNode[index] > 0 and hotkeysNode[index] <= #hotkeyConfigs then
167 currentConfig = hotkeysNode[index]
168 end
169
170 configSelector:setCurrentIndex(currentConfig, true)
171
172 local hotkeySettings = hotkeyConfigs[currentConfig]:getNode('hotkeys')
173 local hotkeys = {}
174
175 if not table.empty(hotkeySettings) then hotkeys = hotkeySettings end
176
177 hotkeyList = {}
178 if not forceDefaults then
179 if not table.empty(hotkeys) then
180 for keyCombo, setting in pairs(hotkeys) do
181 keyCombo = tostring(keyCombo)
182 addKeyCombo(keyCombo, setting)
183 hotkeyList[keyCombo] = setting
184 end
185 end
186 end
187
188 if currentHotkeys:getChildCount() == 0 then
189 loadDefautComboKeys()
190 end
191
192 configValueChanged = false
193 hotkeysManagerLoaded = true
194end
195
196function unload()
197 local gameRootPanel = modules.game_interface.getRootPanel()
198 for keyCombo,callback in pairs(boundCombosCallback) do
199 g_keyboard.unbindKeyPress(keyCombo, callback, gameRootPanel)
200 end
201 boundCombosCallback = {}
202 currentHotkeys:destroyChildren()
203 currentHotkeyLabel = nil
204 updateHotkeyForm(true)
205 hotkeyList = {}
206end
207
208function reset()
209 unload()
210 load(true)
211end
212
213function reload()
214 unload()
215 load()
216end
217
218function save()
219 if not configValueChanged then
220 return
221 end
222
223 local hotkeySettings = hotkeyConfigs[currentConfig]:getNode('hotkeys') or {}
224
225 table.clear(hotkeySettings)
226
227 for _,child in pairs(currentHotkeys:getChildren()) do
228 hotkeySettings[child.keyCombo] = {
229 autoSend = child.autoSend,
230 itemId = child.itemId,
231 subType = child.subType,
232 useType = child.useType,
233 value = child.value,
234 action = child.action
235 }
236 end
237
238 hotkeyList = hotkeySettings
239 hotkeyConfigs[currentConfig]:setNode('hotkeys', hotkeySettings)
240 hotkeyConfigs[currentConfig]:save()
241
242 local index = g_game.getCharacterName() .. "_" .. g_game.getClientVersion()
243 local hotkeysNode = g_settings.getNode('hotkeys') or {}
244 hotkeysNode[index] = currentConfig
245 g_settings.setNode('hotkeys', hotkeysNode)
246 g_settings.save()
247end
248
249function onConfigChange()
250 if not configSelector then return end
251 local index = g_game.getCharacterName() .. "_" .. g_game.getClientVersion()
252 local hotkeysNode = g_settings.getNode('hotkeys') or {}
253 hotkeysNode[index] = configSelector.currentIndex
254 g_settings.setNode('hotkeys', hotkeysNode)
255 reload()
256end
257
258function loadDefautComboKeys()
259 if not defaultComboKeys then
260 for i=1,12 do
261 addKeyCombo('F' .. i)
262 end
263 for i=1,4 do
264 addKeyCombo('Shift+F' .. i)
265 end
266 else
267 for keyCombo, keySettings in pairs(defaultComboKeys) do
268 addKeyCombo(keyCombo, keySettings)
269 end
270 end
271end
272
273function setDefaultComboKeys(combo)
274 defaultComboKeys = combo
275end
276
277function onChooseItemMouseRelease(self, mousePosition, mouseButton)
278 local item = nil
279 if mouseButton == MouseLeftButton then
280 local clickedWidget = modules.game_interface.getRootPanel():recursiveGetChildByPos(mousePosition, false)
281 if clickedWidget then
282 if clickedWidget:getClassName() == 'UIGameMap' then
283 local tile = clickedWidget:getTile(mousePosition)
284 if tile then
285 local thing = tile:getTopMoveThing()
286 if thing and thing:isItem() then
287 item = thing
288 end
289 end
290 elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
291 item = clickedWidget:getItem()
292 end
293 end
294 end
295
296 if item and currentHotkeyLabel then
297 currentHotkeyLabel.itemId = item:getId()
298 if item:isFluidContainer() then
299 currentHotkeyLabel.subType = item:getSubType()
300 end
301 if item:isMultiUse() then
302 currentHotkeyLabel.useType = HOTKEY_MANAGER_USEWITH
303 else
304 currentHotkeyLabel.useType = HOTKEY_MANAGER_USE
305 end
306 currentHotkeyLabel.value = nil
307 currentHotkeyLabel.autoSend = false
308 updateHotkeyLabel(currentHotkeyLabel)
309 updateHotkeyForm(true)
310 end
311
312 show()
313
314 g_mouse.popCursor('target')
315 self:ungrabMouse()
316 return true
317end
318
319function startChooseItem()
320 if g_ui.isMouseGrabbed() then return end
321 mouseGrabberWidget:grabMouse()
322 g_mouse.pushCursor('target')
323 hide()
324end
325
326function clearObject()
327 currentHotkeyLabel.action = nil
328 currentHotkeyLabel.itemId = nil
329 currentHotkeyLabel.subType = nil
330 currentHotkeyLabel.useType = nil
331 currentHotkeyLabel.autoSend = nil
332 currentHotkeyLabel.value = nil
333 updateHotkeyLabel(currentHotkeyLabel)
334 updateHotkeyForm(true)
335end
336
337function addHotkey()
338 local assignWindow = g_ui.createWidget('HotkeyAssignWindow', rootWidget)
339 assignWindow:grabKeyboard()
340
341 local comboLabel = assignWindow:getChildById('comboPreview')
342 comboLabel.keyCombo = ''
343 assignWindow.onKeyDown = hotkeyCapture
344end
345
346function addKeyCombo(keyCombo, keySettings, focus)
347 if keyCombo == nil or #keyCombo == 0 then return end
348 if not keyCombo then return end
349 local hotkeyLabel = currentHotkeys:getChildById(keyCombo)
350 if not hotkeyLabel then
351 hotkeyLabel = g_ui.createWidget('HotkeyListLabel')
352 hotkeyLabel:setId(keyCombo)
353
354 local children = currentHotkeys:getChildren()
355 children[#children+1] = hotkeyLabel
356 table.sort(children, function(a,b)
357 if a:getId():len() < b:getId():len() then
358 return true
359 elseif a:getId():len() == b:getId():len() then
360 return a:getId() < b:getId()
361 else
362 return false
363 end
364 end)
365 for i=1,#children do
366 if children[i] == hotkeyLabel then
367 currentHotkeys:insertChild(i, hotkeyLabel)
368 break
369 end
370 end
371
372 if keySettings then
373 currentHotkeyLabel = hotkeyLabel
374 hotkeyLabel.keyCombo = keyCombo
375 hotkeyLabel.autoSend = toboolean(keySettings.autoSend)
376 hotkeyLabel.action = keySettings.action
377 hotkeyLabel.itemId = tonumber(keySettings.itemId)
378 hotkeyLabel.subType = tonumber(keySettings.subType)
379 hotkeyLabel.useType = tonumber(keySettings.useType)
380 if keySettings.value then hotkeyLabel.value = tostring(keySettings.value) end
381 else
382 hotkeyLabel.keyCombo = keyCombo
383 hotkeyLabel.autoSend = false
384 hotkeyLabel.itemId = nil
385 hotkeyLabel.subType = nil
386 hotkeyLabel.useType = nil
387 hotkeyLabel.action = nil
388 hotkeyLabel.value = ''
389 end
390
391 updateHotkeyLabel(hotkeyLabel)
392
393 local gameRootPanel = modules.game_interface.getRootPanel()
394 if keyCombo:lower():find("ctrl") then
395 if boundCombosCallback[keyCombo] then
396 g_keyboard.unbindKeyPress(keyCombo, boundCombosCallback[keyCombo], gameRootPanel)
397 end
398 end
399
400 boundCombosCallback[keyCombo] = function(k, c, ticks) prepareKeyCombo(keyCombo, ticks) end
401 g_keyboard.bindKeyPress(keyCombo, boundCombosCallback[keyCombo], gameRootPanel)
402
403 if not keyCombo:lower():find("ctrl") then
404 local keyComboCtrl = "Ctrl+" .. keyCombo
405 if not boundCombosCallback[keyComboCtrl] then
406 boundCombosCallback[keyComboCtrl] = function(k, c, ticks) prepareKeyCombo(keyComboCtrl, ticks) end
407 g_keyboard.bindKeyPress(keyComboCtrl, boundCombosCallback[keyComboCtrl], gameRootPanel)
408 end
409 end
410 end
411
412 if focus then
413 currentHotkeys:focusChild(hotkeyLabel)
414 currentHotkeys:ensureChildVisible(hotkeyLabel)
415 updateHotkeyForm(true)
416 end
417 configValueChanged = true
418end
419
420function prepareKeyCombo(keyCombo, ticks)
421 local hotKey = hotkeyList[keyCombo]
422 if (keyCombo:lower():find("ctrl") and not hotKey) or (hotKey and hotKey.itemId == nil and (not hotKey.value or #hotKey.value == 0) and not hotKey.action) then
423 keyCombo = keyCombo:gsub("Ctrl%+", "")
424 keyCombo = keyCombo:gsub("ctrl%+", "")
425 hotKey = hotkeyList[keyCombo]
426 end
427 if not hotKey then
428 return
429 end
430
431 if hotKey.itemId == nil and hotKey.action == nil then -- say
432 scheduleEvent(function() doKeyCombo(keyCombo, ticks >= 5) end, g_settings.getNumber('hotkeyDelay'))
433 else
434 doKeyCombo(keyCombo, ticks >= 5)
435 end
436end
437
438function doKeyCombo(keyCombo, repeated)
439 if not g_game.isOnline() then return end
440 if modules.game_console and modules.game_console.isChatEnabled() then
441 if keyCombo:len() == 1 then
442 return
443 end
444 end
445 if modules.game_walking then
446 modules.game_walking.checkTurn()
447 end
448
449 local hotKey = hotkeyList[keyCombo]
450 if not hotKey then return end
451
452 local hotkeyDelay = 100
453 if hotKey.hotkeyDelayTo == nil or g_clock.millis() > hotKey.hotkeyDelayTo + hotkeyDelay then
454 hotkeyDelay = 200 -- for first use
455 end
456 if hotKey.hotkeyDelayTo ~= nil and g_clock.millis() < hotKey.hotkeyDelayTo then
457 return
458 end
459 if hotKey.action then
460 executeExtraHotkey(hotKey.action, repeated)
461 elseif hotKey.itemId == nil then
462 if not hotKey.value or #hotKey.value == 0 then return end
463 if hotKey.autoSend then
464 modules.game_console.sendMessage(hotKey.value)
465 else
466 modules.game_console.setTextEditText(hotKey.value)
467 end
468 hotKey.hotkeyDelayTo = g_clock.millis() + hotkeyDelay
469 elseif hotKey.useType == HOTKEY_MANAGER_USE then
470 if g_game.getClientVersion() < 780 then
471 local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
472 if item then
473 g_game.use(item)
474 end
475 else
476 g_game.useInventoryItem(hotKey.itemId)
477 end
478 hotKey.hotkeyDelayTo = g_clock.millis() + hotkeyDelay
479 elseif hotKey.useType == HOTKEY_MANAGER_USEONSELF then
480 if g_game.getClientVersion() < 780 then
481 local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
482 if item then
483 g_game.useWith(item, g_game.getLocalPlayer())
484 end
485 else
486 g_game.useInventoryItemWith(hotKey.itemId, g_game.getLocalPlayer(), hotKey.subType or -1)
487 end
488 hotKey.hotkeyDelayTo = g_clock.millis() + hotkeyDelay
489 elseif hotKey.useType == HOTKEY_MANAGER_USEONTARGET then
490 local attackingCreature = g_game.getAttackingCreature()
491 if not attackingCreature then
492 local item = Item.create(hotKey.itemId)
493 if g_game.getClientVersion() < 780 then
494 local tmpItem = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
495 if not tmpItem then return end
496 item = tmpItem
497 end
498
499 modules.game_interface.startUseWith(item, hotKey.subType or - 1)
500 return
501 end
502
503 if not attackingCreature:getTile() then return end
504 if g_game.getClientVersion() < 780 then
505 local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
506 if item then
507 g_game.useWith(item, attackingCreature, hotKey.subType or -1)
508 end
509 else
510 g_game.useInventoryItemWith(hotKey.itemId, attackingCreature, hotKey.subType or -1)
511 end
512 hotKey.hotkeyDelayTo = g_clock.millis() + hotkeyDelay
513 elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then
514 local item = Item.create(hotKey.itemId)
515 if g_game.getClientVersion() < 780 then
516 local tmpItem = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
517 if not tmpItem then return true end
518 item = tmpItem
519 end
520 modules.game_interface.startUseWith(item, hotKey.subType or - 1)
521 end
522end
523
524function updateHotkeyLabel(hotkeyLabel)
525 if not hotkeyLabel then return end
526 if hotkeyLabel.action ~= nil then
527 hotkeyLabel:setText(tr('%s: (Action: %s)', hotkeyLabel.keyCombo, getActionDescription(hotkeyLabel.action)))
528 hotkeyLabel:setColor(HotkeyColors.extraAction)
529 elseif hotkeyLabel.useType == HOTKEY_MANAGER_USEONSELF then
530 hotkeyLabel:setText(tr('%s: (use object on yourself)', hotkeyLabel.keyCombo))
531 hotkeyLabel:setColor(HotkeyColors.itemUseSelf)
532 elseif hotkeyLabel.useType == HOTKEY_MANAGER_USEONTARGET then
533 hotkeyLabel:setText(tr('%s: (use object on target)', hotkeyLabel.keyCombo))
534 hotkeyLabel:setColor(HotkeyColors.itemUseTarget)
535 elseif hotkeyLabel.useType == HOTKEY_MANAGER_USEWITH then
536 hotkeyLabel:setText(tr('%s: (use object with crosshair)', hotkeyLabel.keyCombo))
537 hotkeyLabel:setColor(HotkeyColors.itemUseWith)
538 elseif hotkeyLabel.itemId ~= nil then
539 hotkeyLabel:setText(tr('%s: (use object)', hotkeyLabel.keyCombo))
540 hotkeyLabel:setColor(HotkeyColors.itemUse)
541 else
542 local text = hotkeyLabel.keyCombo .. ': '
543 if hotkeyLabel.value then
544 text = text .. hotkeyLabel.value
545 end
546 hotkeyLabel:setText(text)
547 if hotkeyLabel.autoSend then
548 hotkeyLabel:setColor(HotkeyColors.autoSend)
549 else
550 hotkeyLabel:setColor(HotkeyColors.text)
551 end
552 end
553end
554
555function updateHotkeyForm(reset)
556 configValueChanged = true
557 if hotkeysWindow.action then
558 if currentHotkeyLabel then
559 hotkeysWindow.action:enable()
560 if currentHotkeyLabel.action then
561 hotkeysWindow.action:setCurrentIndex(translateActionToActionComboboxIndex(currentHotkeyLabel.action), true)
562 else
563 hotkeysWindow.action:setCurrentIndex(1, true)
564 end
565 else
566 hotkeysWindow.action:disable()
567 hotkeysWindow.action:setCurrentIndex(1, true)
568 end
569 end
570 local hasCustomAction = hotkeysWindow.action and hotkeysWindow.action.currentIndex > 1
571 if currentHotkeyLabel and not hasCustomAction then
572 removeHotkeyButton:enable()
573 if currentHotkeyLabel.itemId ~= nil then
574 hotkeyText:clearText()
575 hotkeyText:disable()
576 hotKeyTextLabel:disable()
577 sendAutomatically:setChecked(false)
578 sendAutomatically:disable()
579 selectObjectButton:disable()
580 clearObjectButton:enable()
581 currentItemPreview:setItemId(currentHotkeyLabel.itemId)
582 if currentHotkeyLabel.subType then
583 currentItemPreview:setItemSubType(currentHotkeyLabel.subType)
584 end
585 if currentItemPreview:getItem():isMultiUse() then
586 useOnSelf:enable()
587 useOnTarget:enable()
588 useWith:enable()
589 if currentHotkeyLabel.useType == HOTKEY_MANAGER_USEONSELF then
590 useRadioGroup:selectWidget(useOnSelf)
591 elseif currentHotkeyLabel.useType == HOTKEY_MANAGER_USEONTARGET then
592 useRadioGroup:selectWidget(useOnTarget)
593 elseif currentHotkeyLabel.useType == HOTKEY_MANAGER_USEWITH then
594 useRadioGroup:selectWidget(useWith)
595 end
596 else
597 useOnSelf:disable()
598 useOnTarget:disable()
599 useWith:disable()
600 useRadioGroup:clearSelected()
601 end
602 else
603 useOnSelf:disable()
604 useOnTarget:disable()
605 useWith:disable()
606 useRadioGroup:clearSelected()
607 hotkeyText:enable()
608 hotkeyText:focus()
609 hotKeyTextLabel:enable()
610 if reset then
611 hotkeyText:setCursorPos(-1)
612 end
613 hotkeyText:setText(currentHotkeyLabel.value)
614 sendAutomatically:setChecked(currentHotkeyLabel.autoSend)
615 sendAutomatically:setEnabled(currentHotkeyLabel.value and #currentHotkeyLabel.value > 0)
616 selectObjectButton:enable()
617 clearObjectButton:disable()
618 currentItemPreview:clearItem()
619 end
620 else
621 removeHotkeyButton:disable()
622 hotkeyText:disable()
623 sendAutomatically:disable()
624 selectObjectButton:disable()
625 clearObjectButton:disable()
626 useOnSelf:disable()
627 useOnTarget:disable()
628 useWith:disable()
629 hotkeyText:clearText()
630 useRadioGroup:clearSelected()
631 sendAutomatically:setChecked(false)
632 currentItemPreview:clearItem()
633 end
634end
635
636function removeHotkey()
637 if currentHotkeyLabel == nil then return end
638 local gameRootPanel = modules.game_interface.getRootPanel()
639 configValueChanged = true
640 g_keyboard.unbindKeyPress(currentHotkeyLabel.keyCombo, boundCombosCallback[currentHotkeyLabel.keyCombo], gameRootPanel)
641 boundCombosCallback[currentHotkeyLabel.keyCombo] = nil
642 currentHotkeyLabel:destroy()
643 currentHotkeyLabel = nil
644end
645
646function updateHotkeyAction()
647 if not hotkeysManagerLoaded then return end
648 if currentHotkeyLabel == nil then return end
649 configValueChanged = true
650 currentHotkeyLabel.action = translateActionComboboxIndexToAction(hotkeysWindow.action.currentIndex)
651 updateHotkeyLabel(currentHotkeyLabel)
652 updateHotkeyForm()
653end
654
655function onHotkeyTextChange(value)
656 if not hotkeysManagerLoaded then return end
657 if currentHotkeyLabel == nil then return end
658 currentHotkeyLabel.value = value
659 if value == '' then
660 currentHotkeyLabel.autoSend = false
661 end
662 configValueChanged = true
663 updateHotkeyLabel(currentHotkeyLabel)
664 updateHotkeyForm()
665end
666
667function onSendAutomaticallyChange(autoSend)
668 if not hotkeysManagerLoaded then return end
669 if currentHotkeyLabel == nil then return end
670 if not currentHotkeyLabel.value or #currentHotkeyLabel.value == 0 then return end
671 configValueChanged = true
672 currentHotkeyLabel.autoSend = autoSend
673 updateHotkeyLabel(currentHotkeyLabel)
674 updateHotkeyForm()
675end
676
677function onChangeUseType(useTypeWidget)
678 if not hotkeysManagerLoaded then return end
679 if currentHotkeyLabel == nil then return end
680 configValueChanged = true
681 if useTypeWidget == useOnSelf then
682 currentHotkeyLabel.useType = HOTKEY_MANAGER_USEONSELF
683 elseif useTypeWidget == useOnTarget then
684 currentHotkeyLabel.useType = HOTKEY_MANAGER_USEONTARGET
685 elseif useTypeWidget == useWith then
686 currentHotkeyLabel.useType = HOTKEY_MANAGER_USEWITH
687 else
688 currentHotkeyLabel.useType = HOTKEY_MANAGER_USE
689 end
690 updateHotkeyLabel(currentHotkeyLabel)
691 updateHotkeyForm()
692end
693
694function onSelectHotkeyLabel(hotkeyLabel)
695 currentHotkeyLabel = hotkeyLabel
696 updateHotkeyForm(true)
697end
698
699function hotkeyCapture(assignWindow, keyCode, keyboardModifiers)
700 local keyCombo = determineKeyComboDesc(keyCode, keyboardModifiers)
701 local comboPreview = assignWindow:getChildById('comboPreview')
702 comboPreview:setText(tr('Current hotkey to add: %s', keyCombo))
703 comboPreview.keyCombo = keyCombo
704 comboPreview:resizeToText()
705 assignWindow:getChildById('addButton'):enable()
706 return true
707end
708
709function hotkeyCaptureOk(assignWindow, keyCombo)
710 addKeyCombo(keyCombo, nil, true)
711 assignWindow:destroy()
712end
713