2013-01-30 21:23:26 +01:00
|
|
|
HOTKEY_MANAGER_USE = nil
|
2012-02-07 04:32:15 +01:00
|
|
|
HOTKEY_MANAGER_USEONSELF = 1
|
|
|
|
HOTKEY_MANAGER_USEONTARGET = 2
|
|
|
|
HOTKEY_MANAGER_USEWITH = 3
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
HotkeyColors = {
|
2012-02-07 04:32:15 +01:00
|
|
|
text = '#888888',
|
|
|
|
textAutoSend = '#FFFFFF',
|
|
|
|
itemUse = '#8888FF',
|
|
|
|
itemUseSelf = '#00FF00',
|
|
|
|
itemUseTarget = '#FF0000',
|
2013-01-17 12:12:17 +01:00
|
|
|
itemUseWith = '#F5B325',
|
2012-02-07 04:32:15 +01:00
|
|
|
}
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
hotkeysManagerLoaded = false
|
|
|
|
hotkeysWindow = nil
|
|
|
|
hotkeysButton = nil
|
2013-01-30 21:23:26 +01:00
|
|
|
currentHotkeyLabel = nil
|
2012-07-24 07:30:08 +02:00
|
|
|
currentItemPreview = nil
|
|
|
|
itemWidget = nil
|
2012-07-27 00:13:47 +02:00
|
|
|
addHotkeyButton = nil
|
|
|
|
removeHotkeyButton = nil
|
2012-07-24 07:30:08 +02:00
|
|
|
hotkeyText = nil
|
|
|
|
hotKeyTextLabel = nil
|
|
|
|
sendAutomatically = nil
|
|
|
|
selectObjectButton = nil
|
|
|
|
clearObjectButton = nil
|
|
|
|
useOnSelf = nil
|
|
|
|
useOnTarget = nil
|
|
|
|
useWith = nil
|
2013-01-25 13:22:51 +01:00
|
|
|
defaultComboKeys = nil
|
2013-01-30 21:23:26 +01:00
|
|
|
perServer = true
|
|
|
|
perCharacter = true
|
|
|
|
mouseGrabberWidget = nil
|
|
|
|
useRadioGroup = nil
|
|
|
|
currentHotkeys = nil
|
2013-02-18 17:16:22 +01:00
|
|
|
boundCombosCallback = {}
|
2013-01-30 21:23:26 +01:00
|
|
|
hotkeysList = {}
|
2012-07-24 07:30:08 +02:00
|
|
|
|
2012-02-07 04:32:15 +01:00
|
|
|
-- public functions
|
2012-07-24 07:30:08 +02:00
|
|
|
function init()
|
2013-01-18 23:39:11 +01:00
|
|
|
hotkeysButton = modules.client_topmenu.addLeftGameButton('hotkeysButton', tr('Hotkeys') .. ' (Ctrl+K)', '/images/topbuttons/hotkeys', toggle)
|
2012-07-24 07:30:08 +02:00
|
|
|
g_keyboard.bindKeyDown('Ctrl+K', toggle)
|
2013-01-30 21:23:26 +01:00
|
|
|
hotkeysWindow = g_ui.displayUI('hotkeys_manager')
|
|
|
|
hotkeysWindow:setVisible(false)
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
currentHotkeys = hotkeysWindow:getChildById('currentHotkeys')
|
2012-02-07 04:32:15 +01:00
|
|
|
currentItemPreview = hotkeysWindow:getChildById('itemPreview')
|
2012-07-27 00:13:47 +02:00
|
|
|
addHotkeyButton = hotkeysWindow:getChildById('addHotkeyButton')
|
|
|
|
removeHotkeyButton = hotkeysWindow:getChildById('removeHotkeyButton')
|
2012-02-07 06:52:48 +01:00
|
|
|
hotkeyText = hotkeysWindow:getChildById('hotkeyText')
|
|
|
|
hotKeyTextLabel = hotkeysWindow:getChildById('hotKeyTextLabel')
|
|
|
|
sendAutomatically = hotkeysWindow:getChildById('sendAutomatically')
|
|
|
|
selectObjectButton = hotkeysWindow:getChildById('selectObjectButton')
|
|
|
|
clearObjectButton = hotkeysWindow:getChildById('clearObjectButton')
|
|
|
|
useOnSelf = hotkeysWindow:getChildById('useOnSelf')
|
|
|
|
useOnTarget = hotkeysWindow:getChildById('useOnTarget')
|
|
|
|
useWith = hotkeysWindow:getChildById('useWith')
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
useRadioGroup = UIRadioGroup.create()
|
|
|
|
useRadioGroup:addWidget(useOnSelf)
|
|
|
|
useRadioGroup:addWidget(useOnTarget)
|
|
|
|
useRadioGroup:addWidget(useWith)
|
|
|
|
useRadioGroup.onSelectionChange = function(self, selected) onChangeUseType(selected) end
|
|
|
|
|
|
|
|
mouseGrabberWidget = g_ui.createWidget('UIWidget')
|
|
|
|
mouseGrabberWidget:setVisible(false)
|
|
|
|
mouseGrabberWidget:setFocusable(false)
|
|
|
|
mouseGrabberWidget.onMouseRelease = onChooseItemMouseRelease
|
|
|
|
|
|
|
|
currentHotkeys.onChildFocusChange = function(self, hotkeyLabel) onSelectHotkeyLabel(hotkeyLabel) end
|
|
|
|
g_keyboard.bindKeyPress('Down', function() currentHotkeys:focusNextChild(KeyboardFocusReason) end, hotkeysWindow)
|
|
|
|
g_keyboard.bindKeyPress('Up', function() currentHotkeys:focusPreviousChild(KeyboardFocusReason) end, hotkeysWindow)
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2013-01-17 12:12:17 +01:00
|
|
|
connect(g_game, {
|
2013-01-30 21:23:26 +01:00
|
|
|
onGameStart = online,
|
|
|
|
onGameEnd = offline
|
2013-01-17 12:12:17 +01:00
|
|
|
})
|
2013-03-05 08:02:54 +01:00
|
|
|
|
|
|
|
load()
|
2012-07-24 07:30:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function terminate()
|
2013-01-17 12:12:17 +01:00
|
|
|
disconnect(g_game, {
|
2013-01-30 21:23:26 +01:00
|
|
|
onGameStart = online,
|
|
|
|
onGameEnd = offline
|
2013-01-17 12:12:17 +01:00
|
|
|
})
|
2013-01-30 21:23:26 +01:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
g_keyboard.unbindKeyDown('Ctrl+K')
|
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
unload()
|
2012-07-24 07:30:08 +02:00
|
|
|
|
|
|
|
hotkeysWindow:destroy()
|
2013-02-01 05:32:15 +01:00
|
|
|
hotkeysButton:destroy()
|
2013-01-30 21:23:26 +01:00
|
|
|
mouseGrabberWidget:destroy()
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
function configure(savePerServer, savePerCharacter)
|
|
|
|
perServer = savePerServer
|
|
|
|
perCharacter = savePerCharacter
|
2013-03-05 08:02:54 +01:00
|
|
|
reload()
|
2013-01-30 21:23:26 +01:00
|
|
|
end
|
2012-06-07 14:25:41 +02:00
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
function online()
|
|
|
|
reload()
|
|
|
|
hide()
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
function offline()
|
|
|
|
unload()
|
|
|
|
hide()
|
|
|
|
end
|
2013-01-23 01:15:46 +01:00
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
function show()
|
2013-02-27 13:01:51 +01:00
|
|
|
if not g_game.isOnline() then
|
|
|
|
return
|
|
|
|
end
|
2013-01-30 21:23:26 +01:00
|
|
|
hotkeysWindow:show()
|
|
|
|
hotkeysWindow:raise()
|
|
|
|
hotkeysWindow:focus()
|
|
|
|
end
|
2013-01-23 01:15:46 +01:00
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
function hide()
|
|
|
|
hotkeysWindow:hide()
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function toggle()
|
2013-01-10 19:45:35 +01:00
|
|
|
if not hotkeysWindow:isVisible() then
|
2012-07-24 07:30:08 +02:00
|
|
|
show()
|
2013-01-30 21:23:26 +01:00
|
|
|
else
|
|
|
|
hide()
|
2012-02-07 06:52:48 +01:00
|
|
|
end
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
function ok()
|
|
|
|
save()
|
|
|
|
hide()
|
|
|
|
end
|
|
|
|
|
|
|
|
function cancel()
|
|
|
|
reload()
|
|
|
|
hide()
|
|
|
|
end
|
|
|
|
|
|
|
|
function load(forceDefaults)
|
|
|
|
hotkeysManagerLoaded = false
|
|
|
|
|
2013-02-14 18:30:45 +01:00
|
|
|
local hotkeySettings = g_settings.getNode('game_hotkeys')
|
2013-01-30 21:23:26 +01:00
|
|
|
local hotkeys = {}
|
|
|
|
|
|
|
|
if not table.empty(hotkeySettings) then hotkeys = hotkeySettings end
|
|
|
|
if perServer and not table.empty(hotkeys) then hotkeys = hotkeys[G.host] end
|
|
|
|
if perCharacter and not table.empty(hotkeys) then hotkeys = hotkeys[g_game.getCharacterName()] end
|
|
|
|
|
|
|
|
hotkeyList = {}
|
|
|
|
if not forceDefaults then
|
|
|
|
if not table.empty(hotkeys) then
|
|
|
|
for keyCombo, setting in pairs(hotkeys) do
|
2013-02-18 17:16:22 +01:00
|
|
|
keyCombo = tostring(keyCombo)
|
2013-01-30 21:23:26 +01:00
|
|
|
addKeyCombo(keyCombo, setting)
|
|
|
|
hotkeyList[keyCombo] = setting
|
|
|
|
end
|
|
|
|
end
|
2012-02-07 06:52:48 +01:00
|
|
|
end
|
2013-01-30 21:23:26 +01:00
|
|
|
|
|
|
|
if currentHotkeys:getChildCount() == 0 then
|
|
|
|
loadDefautComboKeys()
|
|
|
|
end
|
|
|
|
|
|
|
|
hotkeysManagerLoaded = true
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
function unload()
|
2013-02-18 17:16:22 +01:00
|
|
|
for keyCombo,callback in pairs(boundCombosCallback) do
|
|
|
|
g_keyboard.unbindKeyPress(keyCombo, callback)
|
2013-01-30 21:23:26 +01:00
|
|
|
end
|
2013-02-18 17:16:22 +01:00
|
|
|
boundCombosCallback = {}
|
2013-01-30 21:23:26 +01:00
|
|
|
currentHotkeys:destroyChildren()
|
|
|
|
currentHotkeyLabel = nil
|
2013-02-18 17:16:22 +01:00
|
|
|
updateHotkeyForm(true)
|
2013-01-30 21:23:26 +01:00
|
|
|
hotkeyList = {}
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
function reset()
|
|
|
|
unload()
|
|
|
|
load(true)
|
2013-01-10 19:45:35 +01:00
|
|
|
end
|
|
|
|
|
2013-01-17 12:12:17 +01:00
|
|
|
function reload()
|
2013-01-30 21:23:26 +01:00
|
|
|
unload()
|
2013-01-10 19:45:35 +01:00
|
|
|
load()
|
2013-01-30 21:23:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function save()
|
2013-02-14 18:30:45 +01:00
|
|
|
local hotkeySettings = g_settings.getNode('game_hotkeys') or {}
|
2013-01-30 21:23:26 +01:00
|
|
|
local hotkeys = hotkeySettings
|
|
|
|
|
|
|
|
if perServer then
|
2013-02-27 22:22:46 +01:00
|
|
|
if not hotkeys[G.host] then
|
|
|
|
hotkeys[G.host] = {}
|
|
|
|
end
|
2013-01-30 21:23:26 +01:00
|
|
|
hotkeys = hotkeys[G.host]
|
|
|
|
end
|
|
|
|
|
|
|
|
if perCharacter then
|
2013-02-27 22:22:46 +01:00
|
|
|
local char = g_game.getCharacterName()
|
|
|
|
if not hotkeys[char] then
|
2013-02-27 22:31:15 +01:00
|
|
|
hotkeys[char] = {}
|
2013-02-27 22:22:46 +01:00
|
|
|
end
|
|
|
|
hotkeys = hotkeys[char]
|
2013-01-30 21:23:26 +01:00
|
|
|
end
|
|
|
|
|
2013-02-18 17:16:22 +01:00
|
|
|
table.clear(hotkeys)
|
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
for _,child in pairs(currentHotkeys:getChildren()) do
|
|
|
|
hotkeys[child.keyCombo] = {
|
|
|
|
autoSend = child.autoSend,
|
|
|
|
itemId = child.itemId,
|
2013-10-05 18:08:49 +02:00
|
|
|
subType = child.subType,
|
2013-01-30 21:23:26 +01:00
|
|
|
useType = child.useType,
|
|
|
|
value = child.value
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
hotkeyList = hotkeys
|
2013-02-14 21:29:35 +01:00
|
|
|
g_settings.setNode('game_hotkeys', hotkeySettings)
|
2013-02-18 17:16:22 +01:00
|
|
|
g_settings.save()
|
2013-01-10 19:45:35 +01:00
|
|
|
end
|
|
|
|
|
2013-01-17 12:12:17 +01:00
|
|
|
function loadDefautComboKeys()
|
2013-01-25 13:22:51 +01:00
|
|
|
if not defaultComboKeys then
|
|
|
|
for i=1,12 do
|
2013-01-30 21:23:26 +01:00
|
|
|
addKeyCombo('F' .. i)
|
2013-01-25 13:22:51 +01:00
|
|
|
end
|
|
|
|
for i=1,4 do
|
2013-01-30 21:23:26 +01:00
|
|
|
addKeyCombo('Shift+F' .. i)
|
2013-01-25 13:22:51 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
for keyCombo, keySettings in pairs(defaultComboKeys) do
|
2013-01-30 21:23:26 +01:00
|
|
|
addKeyCombo(keyCombo, keySettings)
|
2013-01-25 13:22:51 +01:00
|
|
|
end
|
2013-01-17 12:12:17 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-25 13:22:51 +01:00
|
|
|
function setDefaultComboKeys(combo)
|
|
|
|
defaultComboKeys = combo
|
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function onChooseItemMouseRelease(self, mousePosition, mouseButton)
|
2012-02-07 04:32:15 +01:00
|
|
|
local item = nil
|
|
|
|
if mouseButton == MouseLeftButton then
|
2012-07-24 07:30:08 +02:00
|
|
|
local clickedWidget = modules.game_interface.getRootPanel():recursiveGetChildByPos(mousePosition, false)
|
2012-02-07 04:32:15 +01:00
|
|
|
if clickedWidget then
|
|
|
|
if clickedWidget:getClassName() == 'UIMap' then
|
|
|
|
local tile = clickedWidget:getTile(mousePosition)
|
|
|
|
if tile then
|
2012-02-07 06:52:48 +01:00
|
|
|
local thing = tile:getTopMoveThing()
|
2012-10-04 21:08:12 +02:00
|
|
|
if thing and thing:isItem() then
|
|
|
|
item = thing
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
|
|
|
|
item = clickedWidget:getItem()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
if item and currentHotkeyLabel then
|
|
|
|
currentHotkeyLabel.itemId = item:getId()
|
2013-10-05 18:08:49 +02:00
|
|
|
if item:isFluidContainer() then
|
|
|
|
currentHotkeyLabel.subType = item:getSubType()
|
|
|
|
end
|
2013-01-30 21:23:26 +01:00
|
|
|
if item:isMultiUse() then
|
|
|
|
currentHotkeyLabel.useType = HOTKEY_MANAGER_USEWITH
|
|
|
|
else
|
|
|
|
currentHotkeyLabel.useType = HOTKEY_MANAGER_USE
|
|
|
|
end
|
|
|
|
currentHotkeyLabel.value = nil
|
|
|
|
currentHotkeyLabel.autoSend = false
|
|
|
|
updateHotkeyLabel(currentHotkeyLabel)
|
2013-02-18 17:16:22 +01:00
|
|
|
updateHotkeyForm(true)
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2013-01-10 19:45:35 +01:00
|
|
|
show()
|
|
|
|
|
2013-01-25 14:47:51 +01:00
|
|
|
g_mouse.popCursor('target')
|
2012-02-07 04:32:15 +01:00
|
|
|
self:ungrabMouse()
|
2013-01-30 21:23:26 +01:00
|
|
|
return true
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function startChooseItem()
|
2013-01-30 21:23:26 +01:00
|
|
|
if g_ui.isMouseGrabbed() then return end
|
2012-02-07 04:32:15 +01:00
|
|
|
mouseGrabberWidget:grabMouse()
|
2013-01-28 19:33:10 +01:00
|
|
|
g_mouse.pushCursor('target')
|
2012-07-27 00:13:47 +02:00
|
|
|
hide()
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function clearObject()
|
2013-01-30 21:23:26 +01:00
|
|
|
currentHotkeyLabel.itemId = nil
|
2013-10-05 18:08:49 +02:00
|
|
|
currentHotkeyLabel.subType = nil
|
2013-01-30 21:23:26 +01:00
|
|
|
currentHotkeyLabel.useType = nil
|
|
|
|
currentHotkeyLabel.autoSend = nil
|
|
|
|
currentHotkeyLabel.value = nil
|
|
|
|
updateHotkeyLabel(currentHotkeyLabel)
|
2013-02-18 17:16:22 +01:00
|
|
|
updateHotkeyForm(true)
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function addHotkey()
|
2013-01-10 19:45:35 +01:00
|
|
|
local assignWindow = g_ui.createWidget('HotkeyAssignWindow', rootWidget)
|
|
|
|
assignWindow:grabKeyboard()
|
|
|
|
|
|
|
|
local comboLabel = assignWindow:getChildById('comboPreview')
|
|
|
|
comboLabel.keyCombo = ''
|
2013-01-30 21:23:26 +01:00
|
|
|
assignWindow.onKeyDown = hotkeyCapture
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
function addKeyCombo(keyCombo, keySettings, focus)
|
2013-02-18 17:16:22 +01:00
|
|
|
if keyCombo == nil or #keyCombo == 0 then return end
|
2013-01-28 19:33:10 +01:00
|
|
|
if not keyCombo then return end
|
2013-01-30 21:23:26 +01:00
|
|
|
local hotkeyLabel = currentHotkeys:getChildById(keyCombo)
|
|
|
|
if not hotkeyLabel then
|
|
|
|
hotkeyLabel = g_ui.createWidget('HotkeyListLabel')
|
|
|
|
hotkeyLabel:setId(keyCombo)
|
|
|
|
|
|
|
|
local children = currentHotkeys:getChildren()
|
|
|
|
children[#children+1] = hotkeyLabel
|
2013-01-25 12:36:57 +01:00
|
|
|
table.sort(children, function(a,b)
|
|
|
|
if a:getId():len() < b:getId():len() then
|
|
|
|
return true
|
|
|
|
elseif a:getId():len() == b:getId():len() then
|
|
|
|
return a:getId() < b:getId()
|
|
|
|
else
|
|
|
|
return false
|
2013-01-24 23:57:51 +01:00
|
|
|
end
|
2013-01-25 12:36:57 +01:00
|
|
|
end)
|
|
|
|
for i=1,#children do
|
2013-01-30 21:23:26 +01:00
|
|
|
if children[i] == hotkeyLabel then
|
|
|
|
currentHotkeys:insertChild(i, hotkeyLabel)
|
2013-01-25 12:36:57 +01:00
|
|
|
break
|
2013-01-24 23:57:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-07 04:32:15 +01:00
|
|
|
if keySettings then
|
2013-01-30 21:23:26 +01:00
|
|
|
currentHotkeyLabel = hotkeyLabel
|
|
|
|
hotkeyLabel.keyCombo = keyCombo
|
2013-02-18 17:16:22 +01:00
|
|
|
hotkeyLabel.autoSend = toboolean(keySettings.autoSend)
|
|
|
|
hotkeyLabel.itemId = tonumber(keySettings.itemId)
|
2013-10-05 18:08:49 +02:00
|
|
|
hotkeyLabel.subType = tonumber(keySettings.subType)
|
2013-01-30 21:23:26 +01:00
|
|
|
hotkeyLabel.useType = tonumber(keySettings.useType)
|
2013-02-18 17:16:22 +01:00
|
|
|
if keySettings.value then hotkeyLabel.value = tostring(keySettings.value) end
|
2012-02-07 04:32:15 +01:00
|
|
|
else
|
2013-01-30 21:23:26 +01:00
|
|
|
hotkeyLabel.keyCombo = keyCombo
|
2013-02-18 17:16:22 +01:00
|
|
|
hotkeyLabel.autoSend = false
|
2013-01-30 21:23:26 +01:00
|
|
|
hotkeyLabel.itemId = nil
|
2013-10-05 18:08:49 +02:00
|
|
|
hotkeyLabel.subType = nil
|
2013-01-30 21:23:26 +01:00
|
|
|
hotkeyLabel.useType = nil
|
2013-02-18 17:16:22 +01:00
|
|
|
hotkeyLabel.value = ''
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
updateHotkeyLabel(hotkeyLabel)
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2013-02-18 17:16:22 +01:00
|
|
|
boundCombosCallback[keyCombo] = function() doKeyCombo(keyCombo) end
|
|
|
|
g_keyboard.bindKeyPress(keyCombo, boundCombosCallback[keyCombo])
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2013-01-28 19:33:10 +01:00
|
|
|
if focus then
|
2013-01-30 21:23:26 +01:00
|
|
|
currentHotkeys:focusChild(hotkeyLabel)
|
|
|
|
currentHotkeys:ensureChildVisible(hotkeyLabel)
|
2013-02-18 17:16:22 +01:00
|
|
|
updateHotkeyForm(true)
|
2013-01-28 19:33:10 +01:00
|
|
|
end
|
2013-01-30 21:23:26 +01:00
|
|
|
end
|
2013-01-28 19:33:10 +01:00
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
function doKeyCombo(keyCombo)
|
|
|
|
if not g_game.isOnline() then return end
|
|
|
|
local hotKey = hotkeyList[keyCombo]
|
|
|
|
if not hotKey then return end
|
|
|
|
if hotKey.itemId == nil then
|
|
|
|
if not hotKey.value or #hotKey.value == 0 then return end
|
|
|
|
if hotKey.autoSend then
|
|
|
|
modules.game_console.sendMessage(hotKey.value)
|
|
|
|
else
|
|
|
|
modules.game_console.setTextEditText(hotKey.value)
|
|
|
|
end
|
|
|
|
elseif hotKey.useType == HOTKEY_MANAGER_USE then
|
2013-10-05 18:08:49 +02:00
|
|
|
if g_game.getProtocolVersion() < 780 or hotKey.subType then
|
|
|
|
local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
|
2013-10-04 04:09:54 +02:00
|
|
|
if item then
|
|
|
|
g_game.use(item)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
g_game.useInventoryItem(hotKey.itemId)
|
|
|
|
end
|
2013-01-30 21:23:26 +01:00
|
|
|
elseif hotKey.useType == HOTKEY_MANAGER_USEONSELF then
|
2013-10-05 18:08:49 +02:00
|
|
|
if g_game.getProtocolVersion() < 780 or hotKey.subType then
|
|
|
|
local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
|
2013-10-04 04:09:54 +02:00
|
|
|
if item then
|
|
|
|
g_game.useWith(item, g_game.getLocalPlayer())
|
|
|
|
end
|
|
|
|
else
|
|
|
|
g_game.useInventoryItemWith(hotKey.itemId, g_game.getLocalPlayer())
|
|
|
|
end
|
2013-01-30 21:23:26 +01:00
|
|
|
elseif hotKey.useType == HOTKEY_MANAGER_USEONTARGET then
|
|
|
|
local attackingCreature = g_game.getAttackingCreature()
|
2014-01-15 02:54:50 +01:00
|
|
|
if not attackingCreature then
|
|
|
|
local item = Item.create(hotKey.itemId)
|
|
|
|
if g_game.getProtocolVersion() < 780 or hotKey.subType then
|
|
|
|
local tmpItem = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
|
|
|
|
if not tmpItem then return end
|
|
|
|
item = tmpItem
|
|
|
|
end
|
|
|
|
|
|
|
|
modules.game_interface.startUseWith(item)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-10-05 02:31:44 +02:00
|
|
|
if not attackingCreature:getTile() then return end
|
2013-10-05 18:08:49 +02:00
|
|
|
if g_game.getProtocolVersion() < 780 or hotKey.subType then
|
|
|
|
local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
|
2013-10-04 04:09:54 +02:00
|
|
|
if item then
|
|
|
|
g_game.useWith(item, attackingCreature)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
g_game.useInventoryItemWith(hotKey.itemId, attackingCreature)
|
|
|
|
end
|
2013-01-30 21:23:26 +01:00
|
|
|
elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then
|
|
|
|
local item = Item.create(hotKey.itemId)
|
2013-10-05 18:08:49 +02:00
|
|
|
if g_game.getProtocolVersion() < 780 or hotKey.subType then
|
|
|
|
local tmpItem = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
|
2013-10-04 04:09:54 +02:00
|
|
|
if not tmpItem then return true end
|
|
|
|
item = tmpItem
|
|
|
|
end
|
2013-01-30 21:23:26 +01:00
|
|
|
modules.game_interface.startUseWith(item)
|
2012-02-08 22:23:15 +01:00
|
|
|
end
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
function updateHotkeyLabel(hotkeyLabel)
|
|
|
|
if not hotkeyLabel then return end
|
|
|
|
if hotkeyLabel.useType == HOTKEY_MANAGER_USEONSELF then
|
|
|
|
hotkeyLabel:setText(tr('%s: (use object on yourself)', hotkeyLabel.keyCombo))
|
|
|
|
hotkeyLabel:setColor(HotkeyColors.itemUseSelf)
|
|
|
|
elseif hotkeyLabel.useType == HOTKEY_MANAGER_USEONTARGET then
|
|
|
|
hotkeyLabel:setText(tr('%s: (use object on target)', hotkeyLabel.keyCombo))
|
|
|
|
hotkeyLabel:setColor(HotkeyColors.itemUseTarget)
|
|
|
|
elseif hotkeyLabel.useType == HOTKEY_MANAGER_USEWITH then
|
|
|
|
hotkeyLabel:setText(tr('%s: (use object with crosshair)', hotkeyLabel.keyCombo))
|
|
|
|
hotkeyLabel:setColor(HotkeyColors.itemUseWith)
|
|
|
|
elseif hotkeyLabel.itemId ~= nil then
|
|
|
|
hotkeyLabel:setText(tr('%s: (use object)', hotkeyLabel.keyCombo))
|
|
|
|
hotkeyLabel:setColor(HotkeyColors.itemUse)
|
|
|
|
else
|
|
|
|
local text = hotkeyLabel.keyCombo .. ': '
|
|
|
|
if hotkeyLabel.value then
|
|
|
|
text = text .. hotkeyLabel.value
|
|
|
|
end
|
|
|
|
hotkeyLabel:setText(text)
|
|
|
|
if hotkeyLabel.autoSend then
|
|
|
|
hotkeyLabel:setColor(HotkeyColors.autoSend)
|
|
|
|
else
|
|
|
|
hotkeyLabel:setColor(HotkeyColors.text)
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-18 17:16:22 +01:00
|
|
|
function updateHotkeyForm(reset)
|
2013-01-30 21:23:26 +01:00
|
|
|
if currentHotkeyLabel then
|
|
|
|
removeHotkeyButton:enable()
|
|
|
|
if currentHotkeyLabel.itemId ~= nil then
|
2012-02-07 06:52:48 +01:00
|
|
|
hotkeyText:clearText()
|
|
|
|
hotkeyText:disable()
|
2013-01-30 21:23:26 +01:00
|
|
|
hotKeyTextLabel:disable()
|
2012-02-07 07:57:04 +01:00
|
|
|
sendAutomatically:setChecked(false)
|
2013-01-30 21:23:26 +01:00
|
|
|
sendAutomatically:disable()
|
2012-02-07 06:52:48 +01:00
|
|
|
selectObjectButton:disable()
|
2013-01-30 21:23:26 +01:00
|
|
|
clearObjectButton:enable()
|
|
|
|
currentItemPreview:setItemId(currentHotkeyLabel.itemId)
|
2013-10-05 18:08:49 +02:00
|
|
|
if currentHotkeyLabel.subType then
|
|
|
|
currentItemPreview:setItemSubType(currentHotkeyLabel.subType)
|
|
|
|
end
|
2013-01-30 21:23:26 +01:00
|
|
|
if currentItemPreview:getItem():isMultiUse() then
|
|
|
|
useOnSelf:enable()
|
|
|
|
useOnTarget:enable()
|
|
|
|
useWith:enable()
|
|
|
|
if currentHotkeyLabel.useType == HOTKEY_MANAGER_USEONSELF then
|
|
|
|
useRadioGroup:selectWidget(useOnSelf)
|
|
|
|
elseif currentHotkeyLabel.useType == HOTKEY_MANAGER_USEONTARGET then
|
|
|
|
useRadioGroup:selectWidget(useOnTarget)
|
|
|
|
elseif currentHotkeyLabel.useType == HOTKEY_MANAGER_USEWITH then
|
|
|
|
useRadioGroup:selectWidget(useWith)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
useOnSelf:disable()
|
|
|
|
useOnTarget:disable()
|
|
|
|
useWith:disable()
|
|
|
|
useRadioGroup:clearSelected()
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
2012-02-08 22:23:15 +01:00
|
|
|
else
|
2012-02-07 06:52:48 +01:00
|
|
|
useOnSelf:disable()
|
|
|
|
useOnTarget:disable()
|
|
|
|
useWith:disable()
|
2013-01-30 21:23:26 +01:00
|
|
|
useRadioGroup:clearSelected()
|
|
|
|
hotkeyText:enable()
|
|
|
|
hotkeyText:focus()
|
|
|
|
hotKeyTextLabel:enable()
|
2013-02-18 17:16:22 +01:00
|
|
|
if reset then
|
|
|
|
hotkeyText:setCursorPos(-1)
|
|
|
|
end
|
2013-01-30 21:23:26 +01:00
|
|
|
hotkeyText:setText(currentHotkeyLabel.value)
|
|
|
|
sendAutomatically:setChecked(currentHotkeyLabel.autoSend)
|
|
|
|
sendAutomatically:setEnabled(currentHotkeyLabel.value and #currentHotkeyLabel.value > 0)
|
|
|
|
selectObjectButton:enable()
|
|
|
|
clearObjectButton:disable()
|
|
|
|
currentItemPreview:clearItem()
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
2013-01-30 21:23:26 +01:00
|
|
|
else
|
|
|
|
removeHotkeyButton:disable()
|
|
|
|
hotkeyText:disable()
|
|
|
|
sendAutomatically:disable()
|
|
|
|
selectObjectButton:disable()
|
|
|
|
clearObjectButton:disable()
|
|
|
|
useOnSelf:disable()
|
|
|
|
useOnTarget:disable()
|
|
|
|
useWith:disable()
|
|
|
|
hotkeyText:clearText()
|
|
|
|
useRadioGroup:clearSelected()
|
|
|
|
sendAutomatically:setChecked(false)
|
|
|
|
currentItemPreview:clearItem()
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function removeHotkey()
|
2013-01-30 21:23:26 +01:00
|
|
|
if currentHotkeyLabel == nil then return end
|
2013-02-18 17:16:22 +01:00
|
|
|
g_keyboard.unbindKeyPress(currentHotkeyLabel.keyCombo, boundCombosCallback[currentHotkeyLabel.keyCombo])
|
|
|
|
boundCombosCallback[currentHotkeyLabel.keyCombo] = nil
|
2013-01-30 21:23:26 +01:00
|
|
|
currentHotkeyLabel:destroy()
|
|
|
|
currentHotkeyLabel = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function onHotkeyTextChange(value)
|
|
|
|
if not hotkeysManagerLoaded then return end
|
|
|
|
if currentHotkeyLabel == nil then return end
|
|
|
|
currentHotkeyLabel.value = value
|
|
|
|
if value == '' then
|
|
|
|
currentHotkeyLabel.autoSend = false
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
2013-01-30 21:23:26 +01:00
|
|
|
updateHotkeyLabel(currentHotkeyLabel)
|
|
|
|
updateHotkeyForm()
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
function onSendAutomaticallyChange(autoSend)
|
|
|
|
if not hotkeysManagerLoaded then return end
|
|
|
|
if currentHotkeyLabel == nil then return end
|
|
|
|
if not currentHotkeyLabel.value or #currentHotkeyLabel.value == 0 then return end
|
|
|
|
currentHotkeyLabel.autoSend = autoSend
|
|
|
|
updateHotkeyLabel(currentHotkeyLabel)
|
|
|
|
updateHotkeyForm()
|
|
|
|
end
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
function onChangeUseType(useTypeWidget)
|
|
|
|
if not hotkeysManagerLoaded then return end
|
|
|
|
if currentHotkeyLabel == nil then return end
|
|
|
|
if useTypeWidget == useOnSelf then
|
|
|
|
currentHotkeyLabel.useType = HOTKEY_MANAGER_USEONSELF
|
|
|
|
elseif useTypeWidget == useOnTarget then
|
|
|
|
currentHotkeyLabel.useType = HOTKEY_MANAGER_USEONTARGET
|
|
|
|
elseif useTypeWidget == useWith then
|
|
|
|
currentHotkeyLabel.useType = HOTKEY_MANAGER_USEWITH
|
|
|
|
else
|
|
|
|
currentHotkeyLabel.useType = HOTKEY_MANAGER_USE
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
2013-01-30 21:23:26 +01:00
|
|
|
updateHotkeyLabel(currentHotkeyLabel)
|
|
|
|
updateHotkeyForm()
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
function onSelectHotkeyLabel(hotkeyLabel)
|
|
|
|
currentHotkeyLabel = hotkeyLabel
|
2013-02-18 17:16:22 +01:00
|
|
|
updateHotkeyForm(true)
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2013-01-30 21:23:26 +01:00
|
|
|
function hotkeyCapture(assignWindow, keyCode, keyboardModifiers)
|
2012-02-07 04:32:15 +01:00
|
|
|
local keyCombo = determineKeyComboDesc(keyCode, keyboardModifiers)
|
2013-01-30 21:23:26 +01:00
|
|
|
local comboPreview = assignWindow:getChildById('comboPreview')
|
2012-04-26 21:54:16 +02:00
|
|
|
comboPreview:setText(tr('Current hotkey to add: %s', keyCombo))
|
2012-02-07 04:32:15 +01:00
|
|
|
comboPreview.keyCombo = keyCombo
|
|
|
|
comboPreview:resizeToText()
|
2013-01-30 21:23:26 +01:00
|
|
|
assignWindow:getChildById('addButton'):enable()
|
2012-02-07 04:32:15 +01:00
|
|
|
return true
|
2012-03-18 14:34:39 +01:00
|
|
|
end
|
2013-01-30 21:23:26 +01:00
|
|
|
|
|
|
|
function hotkeyCaptureOk(assignWindow, keyCombo)
|
|
|
|
addKeyCombo(keyCombo, nil, true)
|
|
|
|
assignWindow:destroy()
|
|
|
|
end
|