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',
|
|
|
|
itemUseWith = '#CC0000',
|
|
|
|
}
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
hotkeysManagerLoaded = false
|
|
|
|
hotkeysWindow = nil
|
|
|
|
hotkeysButton = nil
|
|
|
|
currentHotkeysList = nil
|
|
|
|
hotkeyLabelSelectedOnList = nil
|
|
|
|
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
|
|
|
|
hotkeyList = {}
|
|
|
|
|
2012-02-07 04:32:15 +01:00
|
|
|
-- public functions
|
2012-07-24 07:30:08 +02:00
|
|
|
function init()
|
2012-06-26 00:13:30 +02:00
|
|
|
hotkeysWindow = g_ui.displayUI('hotkeys_manager.otui')
|
2012-07-10 14:15:31 +02:00
|
|
|
local hotkeyListPanel = hotkeysWindow:getChildById('currentHotkeys')
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-07 06:52:48 +01:00
|
|
|
hotkeysWindow:setVisible(false)
|
2012-07-24 07:30:08 +02:00
|
|
|
hotkeysButton = TopMenu.addLeftGameButton('hotkeysButton', tr('Hotkeys') .. ' (Ctrl+K)', '/game_hotkeys/icon.png', toggle)
|
|
|
|
g_keyboard.bindKeyDown('Ctrl+K', toggle)
|
2012-07-10 14:15:31 +02:00
|
|
|
g_keyboard.bindKeyPress('Down', function() hotkeyListPanel:focusNextChild(KeyboardFocusReason) end, hotkeysWindow)
|
|
|
|
g_keyboard.bindKeyPress('Up', function() hotkeyListPanel:focusPreviousChild(KeyboardFocusReason) end, hotkeysWindow)
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-07 04:32:15 +01:00
|
|
|
currentHotkeysList = hotkeysWindow:getChildById('currentHotkeys')
|
|
|
|
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
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
itemWidget = g_ui.createWidget('UIItem')
|
2012-02-07 04:32:15 +01:00
|
|
|
itemWidget:setVirtual(true)
|
|
|
|
itemWidget:setVisible(false)
|
2012-02-08 22:23:15 +01:00
|
|
|
itemWidget:setFocusable(false)
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
connect(g_game, { onGameEnd = hide })
|
|
|
|
connect(currentHotkeysList, { onChildFocusChange = function (self, focusedChild) checkSelectedHotkey(focusedChild) end } )
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-07 07:57:04 +01:00
|
|
|
hotkeysManagerLoaded = true
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
load()
|
|
|
|
end
|
|
|
|
|
|
|
|
function terminate()
|
|
|
|
hotkeysManagerLoaded = false
|
|
|
|
|
|
|
|
disconnect(g_game, { onGameEnd = hide })
|
|
|
|
g_keyboard.unbindKeyDown('Ctrl+K')
|
|
|
|
|
|
|
|
save()
|
|
|
|
|
|
|
|
for keyCombo,v in pairs(hotkeyList) do
|
|
|
|
g_keyboard.unbindKeyPress(keyCombo)
|
|
|
|
end
|
|
|
|
hotkeyList = {}
|
|
|
|
|
|
|
|
itemWidget:destroy()
|
|
|
|
hotkeysWindow:destroy()
|
|
|
|
hotkeysButton:destroy()
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function load()
|
2012-06-26 00:13:30 +02:00
|
|
|
local hotkeySettings = g_settings.getNode('HotkeysManager')
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-06-07 14:25:41 +02:00
|
|
|
local hasCombos = false
|
2012-02-07 06:52:48 +01:00
|
|
|
if hotkeySettings ~= nil then
|
2012-02-08 22:23:15 +01:00
|
|
|
for i, v in pairs(hotkeySettings) do
|
2012-07-24 07:30:08 +02:00
|
|
|
addKeyCombo(nil, v.keyCombo, v)
|
2012-06-07 14:25:41 +02:00
|
|
|
hasCombos = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- add default F keys combos
|
|
|
|
if not hasCombos then
|
|
|
|
for i=1,12 do
|
2012-07-24 07:30:08 +02:00
|
|
|
addKeyCombo(nil, 'F' .. i)
|
2012-02-08 22:23:15 +01:00
|
|
|
end
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function save()
|
2012-02-08 22:23:15 +01:00
|
|
|
local hotkeySettings = {}
|
2012-06-04 02:28:19 +02:00
|
|
|
for i=1, currentHotkeysList:getChildCount() do
|
2012-02-07 04:32:15 +01:00
|
|
|
local child = currentHotkeysList:getChildByIndex(i)
|
2012-02-08 22:23:15 +01:00
|
|
|
table.insert(hotkeySettings, {keyCombo = child.keyCombo,
|
|
|
|
autoSend = child.autoSend,
|
|
|
|
itemId = child.itemId,
|
2012-02-07 04:32:15 +01:00
|
|
|
useType = child.useType,
|
2012-02-08 22:23:15 +01:00
|
|
|
value = child.value})
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
2012-06-04 02:28:19 +02:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
g_settings.setNode('HotkeysManager', hotkeySettings)
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function toggle()
|
2012-02-07 06:52:48 +01:00
|
|
|
if hotkeysWindow:isVisible() then
|
2012-07-24 07:30:08 +02:00
|
|
|
hide()
|
2012-02-07 06:52:48 +01:00
|
|
|
else
|
2012-07-24 07:30:08 +02:00
|
|
|
show()
|
2012-02-07 06:52:48 +01:00
|
|
|
end
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function show()
|
2012-02-08 22:23:15 +01:00
|
|
|
if g_game.isOnline() then
|
2012-02-07 04:32:15 +01:00
|
|
|
hotkeysWindow:grabKeyboard()
|
2012-02-07 06:52:48 +01:00
|
|
|
hotkeysWindow:show()
|
2012-02-20 03:27:08 +01:00
|
|
|
hotkeysWindow:raise()
|
2012-02-07 06:52:48 +01:00
|
|
|
end
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function hide()
|
2012-02-07 04:32:15 +01:00
|
|
|
hotkeysWindow:ungrabKeyboard()
|
2012-02-07 06:52:48 +01:00
|
|
|
hotkeysWindow:hide()
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- private functions
|
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
|
|
|
|
|
|
|
|
if item then
|
|
|
|
currentItemPreview:setItemId(item:getId())
|
|
|
|
hotkeyLabelSelectedOnList.itemId = item:getId()
|
2012-07-24 07:30:08 +02:00
|
|
|
changeUseType(HOTKEY_MANAGER_USEONSELF)
|
|
|
|
checkSelectedHotkey(hotkeyLabelSelectedOnList)
|
2012-07-27 00:13:47 +02:00
|
|
|
show()
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
g_mouse.restoreCursor()
|
2012-02-07 04:32:15 +01:00
|
|
|
self:ungrabMouse()
|
|
|
|
self:destroy()
|
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function startChooseItem()
|
2012-06-26 00:13:30 +02:00
|
|
|
local mouseGrabberWidget = g_ui.createWidget('UIWidget')
|
2012-02-07 04:32:15 +01:00
|
|
|
mouseGrabberWidget:setVisible(false)
|
|
|
|
mouseGrabberWidget:setFocusable(false)
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
connect(mouseGrabberWidget, { onMouseRelease = onChooseItemMouseRelease })
|
2012-02-07 04:32:15 +01:00
|
|
|
|
|
|
|
mouseGrabberWidget:grabMouse()
|
2012-06-26 00:13:30 +02:00
|
|
|
g_mouse.setTargetCursor()
|
2012-02-08 22:23:15 +01:00
|
|
|
|
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()
|
2012-02-08 22:23:15 +01:00
|
|
|
hotkeyLabelSelectedOnList.itemId = nil
|
2012-02-07 07:57:04 +01:00
|
|
|
currentItemPreview:clearItem()
|
2012-07-24 07:30:08 +02:00
|
|
|
changeUseType(HOTKEY_MANAGER_USEONSELF)
|
|
|
|
setSendAutomatically(false)
|
2012-02-07 04:32:15 +01:00
|
|
|
hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': ')
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
checkSelectedHotkey(hotkeyLabelSelectedOnList)
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function addHotkey()
|
2012-02-07 06:52:48 +01:00
|
|
|
local widget
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
messageBox = g_ui.createWidget('MainWindow', rootWidget)
|
2012-02-08 09:12:46 +01:00
|
|
|
messageBox:grabKeyboard()
|
2012-02-07 04:32:15 +01:00
|
|
|
messageBox:setId('assignWindow')
|
2012-04-26 21:54:16 +02:00
|
|
|
messageBox:setText(tr('Button Assign'))
|
2012-02-07 04:32:15 +01:00
|
|
|
messageBox:setWidth(420)
|
|
|
|
messageBox:setHeight(140)
|
2012-08-07 01:43:14 +02:00
|
|
|
messageBox:setDraggable(false)
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
widget = g_ui.createWidget('Label', messageBox)
|
2012-04-26 21:54:16 +02:00
|
|
|
widget:setText(tr('Please, press the key you wish to add onto your hotkeys manager'))
|
2012-02-07 06:52:48 +01:00
|
|
|
widget:resizeToText()
|
|
|
|
widget:addAnchor(AnchorHorizontalCenter, 'parent', AnchorHorizontalCenter)
|
|
|
|
widget:addAnchor(AnchorTop, 'parent', AnchorTop)
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
widget = g_ui.createWidget('Label', messageBox)
|
2012-02-07 06:52:48 +01:00
|
|
|
widget:setId('comboPreview')
|
2012-04-26 21:54:16 +02:00
|
|
|
widget:setText(tr('Current hotkey to add: %s', 'none'))
|
2012-02-07 06:52:48 +01:00
|
|
|
widget.keyCombo = ''
|
|
|
|
widget:resizeToText()
|
|
|
|
widget:addAnchor(AnchorHorizontalCenter, 'parent', AnchorHorizontalCenter)
|
|
|
|
widget:addAnchor(AnchorTop, 'prev', AnchorBottom)
|
|
|
|
widget:setMarginTop(20)
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
widget = g_ui.createWidget('Button', messageBox)
|
2012-02-07 06:52:48 +01:00
|
|
|
widget:setId('cancelButton')
|
2012-04-26 21:54:16 +02:00
|
|
|
widget:setText(tr('Cancel'))
|
2012-02-07 06:52:48 +01:00
|
|
|
widget:setWidth(64)
|
|
|
|
widget:addAnchor(AnchorBottom, 'parent', AnchorBottom)
|
|
|
|
widget:addAnchor(AnchorRight, 'parent', AnchorRight)
|
2012-02-08 22:23:15 +01:00
|
|
|
widget.onClick = function (self)
|
|
|
|
messageBox = nil
|
|
|
|
self:getParent():destroy()
|
2012-02-07 07:57:04 +01:00
|
|
|
end
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
widget = g_ui.createWidget('Button', messageBox)
|
2012-02-07 06:52:48 +01:00
|
|
|
widget:setId('addButton')
|
2012-04-26 21:54:16 +02:00
|
|
|
widget:setText(tr('Add'))
|
2012-02-07 06:52:48 +01:00
|
|
|
widget:setWidth(64)
|
|
|
|
widget:disable()
|
|
|
|
widget:addAnchor(AnchorBottom, 'cancelButton', AnchorBottom)
|
|
|
|
widget:addAnchor(AnchorRight, 'cancelButton', AnchorLeft)
|
|
|
|
widget:setMarginRight(10)
|
2012-02-08 22:23:15 +01:00
|
|
|
widget.onClick = function (self)
|
2012-02-07 07:57:04 +01:00
|
|
|
messageBox = nil
|
2012-07-24 07:30:08 +02:00
|
|
|
addKeyCombo(self:getParent(), self:getParent():getChildById('comboPreview').keyCombo)
|
2012-02-07 07:57:04 +01:00
|
|
|
end
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
connect(messageBox, { onKeyDown = hotkeyCapture }, true)
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function addKeyCombo(messageBox, keyCombo, keySettings)
|
2012-02-07 06:52:48 +01:00
|
|
|
local label = nil
|
2012-02-07 04:32:15 +01:00
|
|
|
if currentHotkeysList:getChildById(keyCombo) == nil then
|
2012-06-26 00:13:30 +02:00
|
|
|
local label = g_ui.createWidget('HotkeyListLabel', currentHotkeysList)
|
2012-02-07 04:32:15 +01:00
|
|
|
label:setId(keyCombo)
|
2012-07-24 07:30:08 +02:00
|
|
|
label:setColor(HotkeyColors.text)
|
2012-02-07 04:32:15 +01:00
|
|
|
label:setText(keyCombo..': ')
|
|
|
|
if keySettings then
|
2012-02-08 22:23:15 +01:00
|
|
|
hotkeyLabelSelectedOnList = label
|
2012-02-07 04:32:15 +01:00
|
|
|
label.keyCombo = keyCombo
|
2012-07-24 07:30:08 +02:00
|
|
|
setSendAutomatically(keySettings.autoSend)
|
2012-02-07 04:32:15 +01:00
|
|
|
label.itemId = keySettings.itemId
|
|
|
|
currentItemPreview:setItemId(keySettings.itemId)
|
2012-07-24 07:30:08 +02:00
|
|
|
changeUseType(tonumber(keySettings.useType))
|
2012-02-07 04:32:15 +01:00
|
|
|
label.value = keySettings.value
|
|
|
|
else
|
|
|
|
label.keyCombo = keyCombo
|
|
|
|
label.autoSend = false
|
|
|
|
label.itemId = nil
|
|
|
|
label.useType = HOTKEY_MANAGER_USEONSELF
|
|
|
|
label.value = ''
|
|
|
|
end
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
checkSelectedHotkey(label)
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-07 04:32:15 +01:00
|
|
|
hotkeyList[keyCombo] = label
|
2012-07-24 07:30:08 +02:00
|
|
|
g_keyboard.bindKeyPress(keyCombo, function () call(keyCombo) end, nil, 350)
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-07 04:32:15 +01:00
|
|
|
if messageBox then
|
|
|
|
messageBox:destroy()
|
2012-02-07 06:52:48 +01:00
|
|
|
messageBox = nil
|
2012-02-08 22:23:15 +01:00
|
|
|
end
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function call(keyCombo)
|
2012-02-08 22:23:15 +01:00
|
|
|
if g_game.isOnline() then
|
2012-02-07 04:32:15 +01:00
|
|
|
local hotKey = hotkeyList[keyCombo]
|
2012-04-24 05:19:01 +02:00
|
|
|
if hotKey ~= nil and hotKey.itemId == nil and hotKey.value ~= '' then
|
2012-02-07 04:32:15 +01:00
|
|
|
if hotKey.autoSend then
|
2012-02-08 22:23:15 +01:00
|
|
|
g_game.talk(hotKey.value)
|
2012-02-07 04:32:15 +01:00
|
|
|
else
|
2012-07-24 07:30:08 +02:00
|
|
|
modules.game_console.setTextEditText(hotKey.value)
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
elseif hotKey.itemId ~= nil then
|
|
|
|
if hotKey.useType == HOTKEY_MANAGER_USEONSELF then
|
2012-02-08 22:23:15 +01:00
|
|
|
g_game.useInventoryItemWith(hotKey.itemId, g_game.getLocalPlayer())
|
2012-02-07 04:32:15 +01:00
|
|
|
elseif hotKey.useType == HOTKEY_MANAGER_USEONTARGET then
|
2012-02-08 22:23:15 +01:00
|
|
|
local attackingCreature = g_game.getAttackingCreature()
|
2012-02-07 04:32:15 +01:00
|
|
|
if attackingCreature then
|
2012-02-08 22:23:15 +01:00
|
|
|
g_game.useInventoryItemWith(hotKey.itemId, attackingCreature)
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
2012-02-08 22:23:15 +01:00
|
|
|
elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then
|
2012-02-07 04:32:15 +01:00
|
|
|
itemWidget:setItemId(hotKey.itemId)
|
2012-07-24 07:30:08 +02:00
|
|
|
modules.game_interface.startUseWith(itemWidget:getItem())
|
2012-02-08 22:23:15 +01:00
|
|
|
end
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function checkSelectedHotkey(focused)
|
2012-06-04 02:28:19 +02:00
|
|
|
if not focused then return end
|
2012-02-07 07:57:04 +01:00
|
|
|
if hotkeysManagerLoaded then
|
|
|
|
hotkeyLabelSelectedOnList = focused
|
2012-02-08 22:23:15 +01:00
|
|
|
|
|
|
|
if hotkeyLabelSelectedOnList ~= nil then
|
2012-07-27 00:13:47 +02:00
|
|
|
removeHotkeyButton:enable()
|
2012-02-07 06:52:48 +01:00
|
|
|
|
2012-02-07 07:57:04 +01:00
|
|
|
if hotkeyLabelSelectedOnList.itemId == nil then
|
|
|
|
hotkeyText:enable()
|
2012-07-13 10:24:52 +02:00
|
|
|
hotkeyText:focus()
|
2012-02-07 07:57:04 +01:00
|
|
|
hotKeyTextLabel:enable()
|
|
|
|
hotkeyText:setText(hotkeyLabelSelectedOnList.value)
|
2012-02-08 22:23:15 +01:00
|
|
|
|
|
|
|
if hotkeyLabelSelectedOnList.value ~= '' then
|
2012-03-29 23:46:21 +02:00
|
|
|
sendAutomatically:setChecked(hotkeyLabelSelectedOnList.autoSend)
|
2012-02-07 07:57:04 +01:00
|
|
|
sendAutomatically:enable()
|
|
|
|
else
|
|
|
|
sendAutomatically:disable()
|
|
|
|
end
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-07 07:57:04 +01:00
|
|
|
selectObjectButton:enable()
|
2012-02-08 22:23:15 +01:00
|
|
|
clearObjectButton:disable()
|
2012-02-07 07:57:04 +01:00
|
|
|
|
|
|
|
currentItemPreview:setItemId(0)
|
2012-02-07 04:32:15 +01:00
|
|
|
else
|
2012-02-07 07:57:04 +01:00
|
|
|
hotkeyText:clearText()
|
|
|
|
hotkeyText:disable()
|
|
|
|
hotKeyTextLabel:disable()
|
2012-02-07 06:52:48 +01:00
|
|
|
sendAutomatically:disable()
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-07 07:57:04 +01:00
|
|
|
selectObjectButton:disable()
|
|
|
|
clearObjectButton:enable()
|
2012-02-08 22:23:15 +01:00
|
|
|
|
|
|
|
currentItemPreview:setItemId(hotkeyLabelSelectedOnList.itemId)
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
2012-07-24 07:30:08 +02:00
|
|
|
changeUseType(hotkeyLabelSelectedOnList.useType)
|
2012-02-07 07:57:04 +01:00
|
|
|
else
|
2012-02-07 06:52:48 +01:00
|
|
|
hotkeyText:clearText()
|
2012-07-27 00:13:47 +02:00
|
|
|
removeHotkeyButton:disable()
|
2012-02-07 06:52:48 +01:00
|
|
|
hotkeyText:disable()
|
|
|
|
sendAutomatically:disable()
|
2012-02-07 07:57:04 +01:00
|
|
|
sendAutomatically:setChecked(false)
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-07 07:57:04 +01:00
|
|
|
currentItemPreview:setItemId(0)
|
2012-02-07 06:52:48 +01:00
|
|
|
selectObjectButton:disable()
|
2012-02-07 07:57:04 +01:00
|
|
|
clearObjectButton:disable()
|
|
|
|
useOnSelf:disable()
|
|
|
|
useOnTarget:disable()
|
|
|
|
useWith:disable()
|
|
|
|
useOnSelf:setChecked(false)
|
|
|
|
useOnTarget:setChecked(false)
|
|
|
|
useWith:setChecked(false)
|
2012-02-08 22:23:15 +01:00
|
|
|
end
|
|
|
|
end
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function changeUseType(useType, checked)
|
2012-02-07 04:32:15 +01:00
|
|
|
if checked == nil or checked then
|
2012-02-08 22:23:15 +01:00
|
|
|
hotkeyLabelSelectedOnList.useType = useType
|
2012-02-07 04:32:15 +01:00
|
|
|
if hotkeyLabelSelectedOnList.itemId ~= nil and currentItemPreview:getItem():isMultiUse() then
|
2012-02-07 06:52:48 +01:00
|
|
|
useOnSelf:enable()
|
|
|
|
useOnTarget:enable()
|
|
|
|
useWith:enable()
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-07 04:32:15 +01:00
|
|
|
if useType == HOTKEY_MANAGER_USEONSELF then
|
2012-04-26 21:54:16 +02:00
|
|
|
hotkeyLabelSelectedOnList:setText(tr('%s: (use object on yourself)', hotkeyLabelSelectedOnList.keyCombo))
|
2012-07-24 07:30:08 +02:00
|
|
|
hotkeyLabelSelectedOnList:setColor(HotkeyColors.itemUseSelf)
|
2012-02-07 06:52:48 +01:00
|
|
|
useOnSelf:setChecked(true)
|
|
|
|
useOnTarget:setChecked(false)
|
|
|
|
useWith:setChecked(false)
|
2012-02-08 22:23:15 +01:00
|
|
|
elseif useType == HOTKEY_MANAGER_USEONTARGET then
|
2012-04-26 21:54:16 +02:00
|
|
|
hotkeyLabelSelectedOnList:setText(tr('%s: (use object on target)', hotkeyLabelSelectedOnList.keyCombo))
|
2012-07-24 07:30:08 +02:00
|
|
|
hotkeyLabelSelectedOnList:setColor(HotkeyColors.itemUseTarget)
|
2012-02-07 06:52:48 +01:00
|
|
|
useOnSelf:setChecked(false)
|
|
|
|
useOnTarget:setChecked(true)
|
|
|
|
useWith:setChecked(false)
|
2012-02-07 04:32:15 +01:00
|
|
|
elseif useType == HOTKEY_MANAGER_USEWITH then
|
2012-04-26 21:54:16 +02:00
|
|
|
hotkeyLabelSelectedOnList:setText(tr('%s: (use object with crosshair)', hotkeyLabelSelectedOnList.keyCombo))
|
2012-07-24 07:30:08 +02:00
|
|
|
hotkeyLabelSelectedOnList:setColor(HotkeyColors.itemUseWith)
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-07 06:52:48 +01:00
|
|
|
useOnSelf:setChecked(false)
|
|
|
|
useOnTarget:setChecked(false)
|
|
|
|
useWith:setChecked(true)
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
elseif hotkeyLabelSelectedOnList.itemId ~= nil and not currentItemPreview:getItem():isMultiUse() then
|
2012-02-07 06:52:48 +01:00
|
|
|
useOnSelf:disable()
|
|
|
|
useOnTarget:disable()
|
|
|
|
useWith:disable()
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-04-26 21:54:16 +02:00
|
|
|
hotkeyLabelSelectedOnList:setText(tr('%s: (use object)', hotkeyLabelSelectedOnList.keyCombo))
|
2012-07-24 07:30:08 +02:00
|
|
|
hotkeyLabelSelectedOnList:setColor(HotkeyColors.itemUse)
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-07 06:52:48 +01:00
|
|
|
useOnSelf:setChecked(false)
|
|
|
|
useOnTarget:setChecked(false)
|
|
|
|
useWith:setChecked(false)
|
2012-02-08 22:23:15 +01:00
|
|
|
else
|
2012-02-07 06:52:48 +01:00
|
|
|
useOnSelf:disable()
|
|
|
|
useOnTarget:disable()
|
|
|
|
useWith:disable()
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-07 06:52:48 +01:00
|
|
|
useOnSelf:setChecked(false)
|
|
|
|
useOnTarget:setChecked(false)
|
|
|
|
useWith:setChecked(false)
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function removeHotkey()
|
2012-02-07 04:32:15 +01:00
|
|
|
if hotkeyLabelSelectedOnList ~= nil then
|
|
|
|
hotkeyList[hotkeyLabelSelectedOnList.keyCombo] = nil
|
2012-06-26 00:13:30 +02:00
|
|
|
g_keyboard.unbindKeyPress(hotkeyLabelSelectedOnList.keyCombo)
|
2012-02-07 04:32:15 +01:00
|
|
|
hotkeyLabelSelectedOnList:destroy()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function onHotkeyTextChange(id, value)
|
2012-02-07 06:52:48 +01:00
|
|
|
if hotkeyLabelSelectedOnList ~= nil and hotkeyLabelSelectedOnList.keyCombo ~= nil then
|
2012-02-07 07:57:04 +01:00
|
|
|
hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': ' .. value)
|
2012-02-07 06:52:48 +01:00
|
|
|
hotkeyLabelSelectedOnList.value = value
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-07 06:52:48 +01:00
|
|
|
if value ~= '' then
|
|
|
|
sendAutomatically:enable()
|
|
|
|
else
|
|
|
|
sendAutomatically:disable()
|
|
|
|
sendAutomatically:setChecked(false)
|
2012-06-26 00:13:30 +02:00
|
|
|
end
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function setSendAutomatically(value)
|
2012-02-07 04:32:15 +01:00
|
|
|
hotkeyLabelSelectedOnList.autoSend = value
|
|
|
|
if value then
|
2012-07-24 07:30:08 +02:00
|
|
|
hotkeyLabelSelectedOnList:setColor(HotkeyColors.autoSend)
|
2012-02-07 04:32:15 +01:00
|
|
|
else
|
2012-07-24 07:30:08 +02:00
|
|
|
hotkeyLabelSelectedOnList:setColor(HotkeyColors.text)
|
2012-02-07 04:32:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function hotkeyCapture(widget, keyCode, keyboardModifiers)
|
2012-02-07 04:32:15 +01:00
|
|
|
local keyCombo = determineKeyComboDesc(keyCode, keyboardModifiers)
|
2012-03-29 04:03:01 +02:00
|
|
|
local comboPreview = rootWidget:getChildById('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()
|
2012-03-29 04:03:01 +02:00
|
|
|
rootWidget:getChildById('assignWindow'):getChildById('addButton'):enable()
|
2012-02-08 22:23:15 +01:00
|
|
|
|
2012-02-07 04:32:15 +01:00
|
|
|
return true
|
2012-03-18 14:34:39 +01:00
|
|
|
end
|