Rework hotkeys manager, fix many issues on it

master
Eduardo Bart 11 years ago
parent 377c013dfe
commit 5bf03c50d6

@ -116,3 +116,4 @@ EnterGameWindow
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.left: parent.left anchors.left: parent.left
color: green color: green
text-auto-resize: true

@ -44,10 +44,6 @@ Panel
id: enableLights id: enableLights
!text: tr('Enable lights') !text: tr('Enable lights')
OptionCheckBox
id: enableShaders
!text: tr('Enable shader effects')
OptionCheckBox OptionCheckBox
id: fullscreen id: fullscreen
!text: tr('Fullscreen') !text: tr('Fullscreen')

@ -19,10 +19,8 @@ local defaultOptions = {
painterEngine = 0, painterEngine = 0,
enableAudio = true, enableAudio = true,
enableMusicSound = true, enableMusicSound = true,
enableShaders = true,
musicSoundVolume = 100, musicSoundVolume = 100,
enableLights = true, enableLights = true,
enableShaders = true,
ambientLight = 25, ambientLight = 25,
} }
@ -77,9 +75,6 @@ local function setupGraphicsEngines()
graphicsPanel:getChildById('foregroundFrameRate'):disable() graphicsPanel:getChildById('foregroundFrameRate'):disable()
graphicsPanel:getChildById('foregroundFrameRateLabel'):disable() graphicsPanel:getChildById('foregroundFrameRateLabel'):disable()
end end
local shadersBox = graphicsPanel:getChildById('enableShaders')
shadersBox:setEnabled(g_graphics.getPainterEngine() == 2)
end end
function init() function init()
@ -225,8 +220,6 @@ function setOption(key, value)
graphicsPanel:getChildById('ambientLightLabel'):setEnabled(value) graphicsPanel:getChildById('ambientLightLabel'):setEnabled(value)
end end
end) end)
elseif key == 'enableShaders' then
g_graphics.setShouldUseShaders(value)
elseif key == 'ambientLight' then elseif key == 'ambientLight' then
addEvent(function() addEvent(function()
local map = modules.game_interface.getMapPanel() local map = modules.game_interface.getMapPanel()
@ -238,12 +231,6 @@ function setOption(key, value)
end) end)
elseif key == 'painterEngine' then elseif key == 'painterEngine' then
g_graphics.selectPainterEngine(value) g_graphics.selectPainterEngine(value)
addEvent(function()
if graphicsPanel then
local shadersBox = graphicsPanel:getChildById('enableShaders')
shadersBox:setEnabled(value == 2)
end
end)
end end
g_settings.set(key, value) g_settings.set(key, value)
options[key] = value options[key] = value

@ -106,5 +106,5 @@ function onRecv(protocol, message)
end end
function onError(protocol, message, code) function onError(protocol, message, code)
perror('Could not send statistics: ' .. message) pdebug('Could not send statistics: ' .. message)
end end

@ -8,6 +8,7 @@ g_settings.getNode = g_configs.getNode
g_settings.remove = g_configs.remove g_settings.remove = g_configs.remove
g_settings.setList = g_configs.setList g_settings.setList = g_configs.setList
g_settings.getList = g_configs.getList g_settings.getList = g_configs.getList
g_settings.save = g_configs.save
local function convertSettingValue(value) local function convertSettingValue(value)
if type(value) == 'table' then if type(value) == 'table' then

@ -18,6 +18,11 @@ function UIPopupMenu:display(pos)
return return
end end
if g_ui.isMouseGrabbed() then
self:destroy()
return
end
if currentMenu then if currentMenu then
currentMenu:destroy() currentMenu:destroy()
end end

@ -14,11 +14,17 @@ function UIScrollArea:onStyleApply(styleName, styleNode)
for name,value in pairs(styleNode) do for name,value in pairs(styleNode) do
if name == 'vertical-scrollbar' then if name == 'vertical-scrollbar' then
addEvent(function() addEvent(function()
self:setVerticalScrollBar(self:getParent():getChildById(value)) local parent = self:getParent()
if parent then
self:setVerticalScrollBar(parent:getChildById(value))
end
end) end)
elseif name == 'horizontal-scrollbar' then elseif name == 'horizontal-scrollbar' then
addEvent(function() addEvent(function()
self:setHorizontalScrollBar(self:getParent():getChildById(value)) local parent = self:getParent()
if parent then
self:setHorizontalScrollBar(self:getParent():getChildById(value))
end
end) end)
elseif name == 'inverted-scroll' then elseif name == 'inverted-scroll' then
self:setInverted(value) self:setInverted(value)

@ -92,7 +92,7 @@ end
function online() function online()
local player = g_game.getLocalPlayer() local player = g_game.getLocalPlayer()
if player then if player then
local char = player:getName() local char = g_game.getCharacterName()
local lastCombatControls = g_settings.getNode('LastCombatControls') local lastCombatControls = g_settings.getNode('LastCombatControls')
@ -116,7 +116,7 @@ function offline()
local player = g_game.getLocalPlayer() local player = g_game.getLocalPlayer()
if player then if player then
local char = player:getName() local char = g_game.getCharacterName()
lastCombatControls[char] = { lastCombatControls[char] = {
fightMode = g_game.getFightMode(), fightMode = g_game.getFightMode(),
chaseMode = g_game.getChaseMode(), chaseMode = g_game.getChaseMode(),

@ -199,7 +199,7 @@ end
function clear() function clear()
-- save last open channels -- save last open channels
local lastChannelsOpen = g_settings.getNode('lastChannelsOpen') or {} local lastChannelsOpen = g_settings.getNode('lastChannelsOpen') or {}
local char = g_game.getLocalPlayer():getName() local char = g_game.getCharacterName()
local savedChannels = {} local savedChannels = {}
local set = false local set = false
for channelId, channelName in pairs(channels) do for channelId, channelName in pairs(channels) do
@ -447,8 +447,7 @@ function addTabText(text, speaktype, tab, creatureName)
labelHighlight:setId('consoleLabel' .. consoleBufferHighlight:getChildCount()) labelHighlight:setId('consoleLabel' .. consoleBufferHighlight:getChildCount())
labelHighlight:setColor("#1f9ffe") labelHighlight:setColor("#1f9ffe")
local player = g_game.getLocalPlayer() if speaktype.npcChat and (g_game.getCharacterName() ~= creatureName or g_game.getCharacterName() == 'Account Manager') then -- Check if it is the npc who is talking
if speaktype.npcChat and (player:getName() ~= creatureName or player:getName() == 'Account Manager') then -- Check if it is the npc who is talking
local highlightData = getHighlightedText(text) local highlightData = getHighlightedText(text)
if #highlightData == 0 then if #highlightData == 0 then
labelHighlight:setText("") labelHighlight:setText("")
@ -675,7 +674,7 @@ function sendMessage(message, tab)
local player = g_game.getLocalPlayer() local player = g_game.getLocalPlayer()
g_game.talkPrivate(speaktype.speakType, name, message) g_game.talkPrivate(speaktype.speakType, name, message)
message = applyMessagePrefixies(player:getName(), player:getLevel(), message) message = applyMessagePrefixies(g_game.getCharacterName(), player:getLevel(), message)
addPrivateText(message, speaktype, tabname, isPrivateCommand, g_game.getCharacterName()) addPrivateText(message, speaktype, tabname, isPrivateCommand, g_game.getCharacterName())
end end
end end
@ -740,7 +739,7 @@ function onTalk(name, level, mode, message, channelId, creaturePos)
return return
end end
if name ~= g_game.getLocalPlayer():getName() then if name ~= g_game.getCharacterName() then
if mode == MessageModes.Yell and isIgnoringYelling() then if mode == MessageModes.Yell and isIgnoringYelling() then
return return
elseif speaktype.private and isIgnoringPrivate() and mode ~= MessageModes.NpcFrom then elseif speaktype.private and isIgnoringPrivate() and mode ~= MessageModes.NpcFrom then
@ -875,7 +874,7 @@ function doChannelListSubmit()
local channelListPanel = channelsWindow:getChildById('channelList') local channelListPanel = channelsWindow:getChildById('channelList')
local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText() local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
if openPrivateChannelWith ~= '' then if openPrivateChannelWith ~= '' then
if openPrivateChannelWith:lower() ~= g_game.getLocalPlayer():getName():lower() then if openPrivateChannelWith:lower() ~= g_game.getCharacterName():lower() then
g_game.openPrivateChannel(openPrivateChannelWith) g_game.openPrivateChannel(openPrivateChannelWith)
else else
modules.game_textmessage.displayFailureMessage('You cannot create a private chat channel with yourself.') modules.game_textmessage.displayFailureMessage('You cannot create a private chat channel with yourself.')
@ -1028,7 +1027,7 @@ function online()
-- open last channels -- open last channels
local lastChannelsOpen = g_settings.getNode('lastChannelsOpen') local lastChannelsOpen = g_settings.getNode('lastChannelsOpen')
if lastChannelsOpen then if lastChannelsOpen then
local savedChannels = lastChannelsOpen[g_game.getLocalPlayer():getName()] local savedChannels = lastChannelsOpen[g_game.getCharacterName()]
if savedChannels then if savedChannels then
for channelName, channelId in pairs(savedChannels) do for channelName, channelId in pairs(savedChannels) do
channelId = tonumber(channelId) channelId = tonumber(channelId)

@ -1,3 +1,4 @@
HOTKEY_MANAGER_USE = nil
HOTKEY_MANAGER_USEONSELF = 1 HOTKEY_MANAGER_USEONSELF = 1
HOTKEY_MANAGER_USEONTARGET = 2 HOTKEY_MANAGER_USEONTARGET = 2
HOTKEY_MANAGER_USEWITH = 3 HOTKEY_MANAGER_USEWITH = 3
@ -14,8 +15,7 @@ HotkeyColors = {
hotkeysManagerLoaded = false hotkeysManagerLoaded = false
hotkeysWindow = nil hotkeysWindow = nil
hotkeysButton = nil hotkeysButton = nil
currentHotkeysList = nil currentHotkeyLabel = nil
hotkeyLabelSelectedOnList = nil
currentItemPreview = nil currentItemPreview = nil
itemWidget = nil itemWidget = nil
addHotkeyButton = nil addHotkeyButton = nil
@ -29,20 +29,21 @@ useOnSelf = nil
useOnTarget = nil useOnTarget = nil
useWith = nil useWith = nil
defaultComboKeys = nil defaultComboKeys = nil
hotkeyList = {} perServer = true
perCharacter = true
mouseGrabberWidget = nil
useRadioGroup = nil
currentHotkeys = nil
hotkeysList = {}
-- public functions -- public functions
function init() function init()
hotkeysWindow = g_ui.displayUI('hotkeys_manager')
local hotkeyListPanel = hotkeysWindow:getChildById('currentHotkeys')
hotkeysWindow:setVisible(false)
hotkeysButton = modules.client_topmenu.addLeftGameButton('hotkeysButton', tr('Hotkeys') .. ' (Ctrl+K)', '/images/topbuttons/hotkeys', toggle) hotkeysButton = modules.client_topmenu.addLeftGameButton('hotkeysButton', tr('Hotkeys') .. ' (Ctrl+K)', '/images/topbuttons/hotkeys', toggle)
g_keyboard.bindKeyDown('Ctrl+K', toggle) g_keyboard.bindKeyDown('Ctrl+K', toggle)
g_keyboard.bindKeyPress('Down', function() hotkeyListPanel:focusNextChild(KeyboardFocusReason) end, hotkeysWindow) hotkeysWindow = g_ui.displayUI('hotkeys_manager')
g_keyboard.bindKeyPress('Up', function() hotkeyListPanel:focusPreviousChild(KeyboardFocusReason) end, hotkeysWindow) hotkeysWindow:setVisible(false)
currentHotkeysList = hotkeysWindow:getChildById('currentHotkeys') currentHotkeys = hotkeysWindow:getChildById('currentHotkeys')
currentItemPreview = hotkeysWindow:getChildById('itemPreview') currentItemPreview = hotkeysWindow:getChildById('itemPreview')
addHotkeyButton = hotkeysWindow:getChildById('addHotkeyButton') addHotkeyButton = hotkeysWindow:getChildById('addHotkeyButton')
removeHotkeyButton = hotkeysWindow:getChildById('removeHotkeyButton') removeHotkeyButton = hotkeysWindow:getChildById('removeHotkeyButton')
@ -55,132 +56,171 @@ function init()
useOnTarget = hotkeysWindow:getChildById('useOnTarget') useOnTarget = hotkeysWindow:getChildById('useOnTarget')
useWith = hotkeysWindow:getChildById('useWith') useWith = hotkeysWindow:getChildById('useWith')
itemWidget = g_ui.createWidget('UIItem') useRadioGroup = UIRadioGroup.create()
itemWidget:setVirtual(true) useRadioGroup:addWidget(useOnSelf)
itemWidget:setVisible(false) useRadioGroup:addWidget(useOnTarget)
itemWidget:setFocusable(false) 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)
connect(g_game, { connect(g_game, {
onGameStart = onGameStart, onGameStart = online,
onGameEnd = hide onGameEnd = offline
}) })
connect(currentHotkeysList, { onChildFocusChange = function (self, focusedChild) checkSelectedHotkey(focusedChild) end } )
hotkeysManagerLoaded = true
end end
function terminate() function terminate()
hotkeysManagerLoaded = false
disconnect(g_game, { disconnect(g_game, {
onGameStart = onGameStart, onGameStart = online,
onGameEnd = hide onGameEnd = offline
}) })
g_keyboard.unbindKeyDown('Ctrl+K') g_keyboard.unbindKeyDown('Ctrl+K')
for keyCombo,v in pairs(hotkeyList) do unload()
g_keyboard.unbindKeyPress(keyCombo)
end
hotkeyList = {}
itemWidget:destroy()
hotkeysWindow:destroy() hotkeysWindow:destroy()
hotkeysButton:destroy() hotkeysButton:destroy()
mouseGrabberWidget:destroy()
end end
function load() function configure(savePerServer, savePerCharacter)
local hotkeySettings = g_settings.getNode('HotkeysManager') perServer = savePerServer
local hasCombos = false perCharacter = savePerCharacter
if not table.empty(hotkeySettings) then end
local serverHotkeys = hotkeySettings[G.host]
local hotkeys
if not table.empty(serverHotkeys) then
hotkeys = serverHotkeys[g_game.getLocalPlayer():getName()]
end
if not table.empty(hotkeys) then
for k, setting in pairs(hotkeys) do
addKeyCombo(nil, setting.keyCombo, setting)
hasCombos = true
end
end
end
-- add default F keys combos function online()
if not hasCombos then reload()
loadDefautComboKeys() hide()
end
end end
function save() function offline()
local char = g_game.getLocalPlayer():getName() unload()
local server = G.host hide()
end
local hotkeySettings = g_settings.getNode('HotkeysManager') or {} function show()
hotkeySettings[server] = {} hotkeysWindow:show()
hotkeySettings[server][char] = {} hotkeysWindow:raise()
hotkeysWindow:focus()
end
for i=1, currentHotkeysList:getChildCount() do function hide()
local child = currentHotkeysList:getChildByIndex(i) hotkeysWindow:hide()
table.insert(hotkeySettings[server][char], {
keyCombo = child.keyCombo,
autoSend = child.autoSend,
itemId = child.itemId,
useType = child.useType,
value = child.value
})
end
g_settings.setNode('HotkeysManager', hotkeySettings)
end end
function toggle() function toggle()
if not hotkeysWindow:isVisible() then if not hotkeysWindow:isVisible() then
show() show()
else
hide()
end end
end end
function show() function ok()
if g_game.isOnline() then save()
hotkeysWindow:grabKeyboard() hide()
hotkeysWindow:show() end
hotkeysWindow:raise()
function cancel()
reload()
hide()
end
function load(forceDefaults)
hotkeysManagerLoaded = false
local hotkeySettings = g_settings.getNode('hotkeys')
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
addKeyCombo(keyCombo, setting)
hotkeyList[keyCombo] = setting
end
end
end end
if currentHotkeys:getChildCount() == 0 then
loadDefautComboKeys()
end
hotkeysManagerLoaded = true
end end
function hide() function unload()
hotkeysWindow:ungrabKeyboard() for _,child in pairs(currentHotkeys:getChildren()) do
hotkeysWindow:hide() g_keyboard.unbindKeyPress(child.keyCombo)
end
currentHotkeys:destroyChildren()
currentHotkeyLabel = nil
updateHotkeyForm()
hotkeyList = {}
end end
function ok() function reset()
save() unload()
hide() load(true)
end end
function reload() function reload()
local children = currentHotkeysList:getChildren() unload()
for i=1,#children do
hotkeyList[children[i].keyCombo] = nil
g_keyboard.unbindKeyPress(children[i].keyCombo)
end
currentHotkeysList:destroyChildren()
hotkeyLabelSelectedOnList = nil
load() load()
hide() end
function save()
local hotkeySettings = g_settings.getNode('hotkeys') or {}
local hotkeys = hotkeySettings
if perServer then
hotkeys[G.host] = {}
hotkeys = hotkeys[G.host]
end
if perCharacter then
hotkeys[g_game.getCharacterName()] = {}
hotkeys = hotkeys[g_game.getCharacterName()]
end
for _,child in pairs(currentHotkeys:getChildren()) do
hotkeys[child.keyCombo] = {
autoSend = child.autoSend,
itemId = child.itemId,
useType = child.useType,
value = child.value
}
end
hotkeyList = hotkeys
g_settings.setNode('hotkeys', hotkeySettings)
--g_settings.save()
end end
function loadDefautComboKeys() function loadDefautComboKeys()
if not defaultComboKeys then if not defaultComboKeys then
for i=1,12 do for i=1,12 do
addKeyCombo(nil, 'F' .. i) addKeyCombo('F' .. i)
end end
for i=1,4 do for i=1,4 do
addKeyCombo(nil, 'Shift+F' .. i) addKeyCombo('Shift+F' .. i)
end end
else else
for keyCombo, keySettings in pairs(defaultComboKeys) do for keyCombo, keySettings in pairs(defaultComboKeys) do
addKeyCombo(nil, keyCombo, keySettings) addKeyCombo(keyCombo, keySettings)
end end
end end
end end
@ -189,11 +229,6 @@ function setDefaultComboKeys(combo)
defaultComboKeys = combo defaultComboKeys = combo
end end
-- private functions
function onGameStart()
reload()
end
function onChooseItemMouseRelease(self, mousePosition, mouseButton) function onChooseItemMouseRelease(self, mousePosition, mouseButton)
local item = nil local item = nil
if mouseButton == MouseLeftButton then if mouseButton == MouseLeftButton then
@ -213,41 +248,40 @@ function onChooseItemMouseRelease(self, mousePosition, mouseButton)
end end
end end
if item and hotkeyLabelSelectedOnList then if item and currentHotkeyLabel then
currentItemPreview:setItemId(item:getId()) currentHotkeyLabel.itemId = item:getId()
hotkeyLabelSelectedOnList.itemId = item:getId() if item:isMultiUse() then
changeUseType(HOTKEY_MANAGER_USEONSELF) currentHotkeyLabel.useType = HOTKEY_MANAGER_USEWITH
checkSelectedHotkey(hotkeyLabelSelectedOnList) else
currentHotkeyLabel.useType = HOTKEY_MANAGER_USE
end
currentHotkeyLabel.value = nil
currentHotkeyLabel.autoSend = false
updateHotkeyLabel(currentHotkeyLabel)
updateHotkeyForm()
end end
show() show()
g_mouse.popCursor('target') g_mouse.popCursor('target')
self:ungrabMouse() self:ungrabMouse()
self:destroy() return true
end end
function startChooseItem() function startChooseItem()
local mouseGrabberWidget = g_ui.createWidget('UIWidget') if g_ui.isMouseGrabbed() then return end
mouseGrabberWidget:setVisible(false)
mouseGrabberWidget:setFocusable(false)
connect(mouseGrabberWidget, { onMouseRelease = onChooseItemMouseRelease })
mouseGrabberWidget:grabMouse() mouseGrabberWidget:grabMouse()
g_mouse.pushCursor('target') g_mouse.pushCursor('target')
hide() hide()
end end
function clearObject() function clearObject()
hotkeyLabelSelectedOnList.itemId = nil currentHotkeyLabel.itemId = nil
currentItemPreview:clearItem() currentHotkeyLabel.useType = nil
changeUseType(HOTKEY_MANAGER_USEONSELF) currentHotkeyLabel.autoSend = nil
setSendAutomatically(false) currentHotkeyLabel.value = nil
hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': ') updateHotkeyLabel(currentHotkeyLabel)
updateHotkeyForm()
checkSelectedHotkey(hotkeyLabelSelectedOnList)
end end
function addHotkey() function addHotkey()
@ -256,21 +290,18 @@ function addHotkey()
local comboLabel = assignWindow:getChildById('comboPreview') local comboLabel = assignWindow:getChildById('comboPreview')
comboLabel.keyCombo = '' comboLabel.keyCombo = ''
assignWindow.onKeyDown = hotkeyCapture
connect(assignWindow, { onKeyDown = hotkeyCapture }, true)
end end
function addKeyCombo(messageBox, keyCombo, keySettings, focus) function addKeyCombo(keyCombo, keySettings, focus)
if not keyCombo then return end if not keyCombo then return end
local label = currentHotkeysList:getChildById(keyCombo) local hotkeyLabel = currentHotkeys:getChildById(keyCombo)
if not label then if not hotkeyLabel then
label = g_ui.createWidget('HotkeyListLabel') hotkeyLabel = g_ui.createWidget('HotkeyListLabel')
label:setId(keyCombo) hotkeyLabel:setId(keyCombo)
label:setColor(HotkeyColors.text)
label:setText(keyCombo .. ': ') local children = currentHotkeys:getChildren()
children[#children+1] = hotkeyLabel
local children = currentHotkeysList:getChildren()
children[#children+1] = label
table.sort(children, function(a,b) table.sort(children, function(a,b)
if a:getId():len() < b:getId():len() then if a:getId():len() < b:getId():len() then
return true return true
@ -281,218 +312,212 @@ function addKeyCombo(messageBox, keyCombo, keySettings, focus)
end end
end) end)
for i=1,#children do for i=1,#children do
if children[i] == label then if children[i] == hotkeyLabel then
currentHotkeysList:insertChild(i, label) currentHotkeys:insertChild(i, hotkeyLabel)
break break
end end
end end
if keySettings then if keySettings then
hotkeyLabelSelectedOnList = label currentHotkeyLabel = hotkeyLabel
label.keyCombo = keyCombo hotkeyLabel.keyCombo = keyCombo
label.autoSend = keySettings.autoSend hotkeyLabel.autoSend = keySettings.autoSend
label.itemId = keySettings.itemId hotkeyLabel.itemId = keySettings.itemId
label.useType = tonumber(keySettings.useType) hotkeyLabel.useType = tonumber(keySettings.useType)
label.value = keySettings.value hotkeyLabel.value = keySettings.value
else else
label.keyCombo = keyCombo hotkeyLabel.keyCombo = keyCombo
label.autoSend = false hotkeyLabel.autoSend = nil
label.itemId = nil hotkeyLabel.itemId = nil
label.useType = HOTKEY_MANAGER_USEONSELF hotkeyLabel.useType = nil
label.value = '' hotkeyLabel.value = nil
end end
checkSelectedHotkey(label) updateHotkeyLabel(hotkeyLabel)
hotkeyList[keyCombo] = label g_keyboard.bindKeyPress(keyCombo, function() doKeyCombo(keyCombo) end, nil, 350)
g_keyboard.bindKeyPress(keyCombo, function () call(keyCombo) end, nil, 350)
end end
if focus then if focus then
currentHotkeysList:focusChild(label) currentHotkeys:focusChild(hotkeyLabel)
currentHotkeysList:ensureChildVisible(label) currentHotkeys:ensureChildVisible(hotkeyLabel)
updateHotkeyForm()
end end
end
if messageBox then function doKeyCombo(keyCombo)
messageBox:destroy() if not g_game.isOnline() then return end
messageBox = nil 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
g_game.useInventoryItemWith(hotKey.itemId)
elseif hotKey.useType == HOTKEY_MANAGER_USEONSELF then
g_game.useInventoryItemWith(hotKey.itemId, g_game.getLocalPlayer())
elseif hotKey.useType == HOTKEY_MANAGER_USEONTARGET then
local attackingCreature = g_game.getAttackingCreature()
if not attackingCreature then return end
g_game.useInventoryItemWith(hotKey.itemId, attackingCreature)
elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then
local item = Item.create(hotKey.itemId)
modules.game_interface.startUseWith(item)
end end
end end
function call(keyCombo) function updateHotkeyLabel(hotkeyLabel)
if g_game.isOnline() then if not hotkeyLabel then return end
local hotKey = hotkeyList[keyCombo] if hotkeyLabel.useType == HOTKEY_MANAGER_USEONSELF then
if hotKey ~= nil and hotKey.itemId == nil and hotKey.value ~= '' then hotkeyLabel:setText(tr('%s: (use object on yourself)', hotkeyLabel.keyCombo))
if hotKey.autoSend then hotkeyLabel:setColor(HotkeyColors.itemUseSelf)
modules.game_console.sendMessage(hotKey.value) elseif hotkeyLabel.useType == HOTKEY_MANAGER_USEONTARGET then
else hotkeyLabel:setText(tr('%s: (use object on target)', hotkeyLabel.keyCombo))
modules.game_console.setTextEditText(hotKey.value) hotkeyLabel:setColor(HotkeyColors.itemUseTarget)
end elseif hotkeyLabel.useType == HOTKEY_MANAGER_USEWITH then
elseif hotKey.itemId ~= nil then hotkeyLabel:setText(tr('%s: (use object with crosshair)', hotkeyLabel.keyCombo))
if hotKey.useType == HOTKEY_MANAGER_USEONSELF then hotkeyLabel:setColor(HotkeyColors.itemUseWith)
g_game.useInventoryItemWith(hotKey.itemId, g_game.getLocalPlayer()) elseif hotkeyLabel.itemId ~= nil then
elseif hotKey.useType == HOTKEY_MANAGER_USEONTARGET then hotkeyLabel:setText(tr('%s: (use object)', hotkeyLabel.keyCombo))
local attackingCreature = g_game.getAttackingCreature() hotkeyLabel:setColor(HotkeyColors.itemUse)
if attackingCreature then else
g_game.useInventoryItemWith(hotKey.itemId, attackingCreature) local text = hotkeyLabel.keyCombo .. ': '
end if hotkeyLabel.value then
elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then text = text .. hotkeyLabel.value
itemWidget:setItemId(hotKey.itemId) end
modules.game_interface.startUseWith(itemWidget:getItem()) hotkeyLabel:setText(text)
end if hotkeyLabel.autoSend then
hotkeyLabel:setColor(HotkeyColors.autoSend)
else
hotkeyLabel:setColor(HotkeyColors.text)
end end
end end
end end
function checkSelectedHotkey(focused) function updateHotkeyForm()
if hotkeysManagerLoaded then if currentHotkeyLabel then
hotkeyLabelSelectedOnList = focused removeHotkeyButton:enable()
if currentHotkeyLabel.itemId ~= nil then
if hotkeyLabelSelectedOnList ~= nil then
removeHotkeyButton:enable()
if hotkeyLabelSelectedOnList.itemId == nil then
hotkeyText:enable()
hotkeyText:focus()
hotKeyTextLabel:enable()
hotkeyText:setText(hotkeyLabelSelectedOnList.value)
hotkeyText:setCursorPos(-1)
if hotkeyLabelSelectedOnList.value ~= '' then
sendAutomatically:setChecked(hotkeyLabelSelectedOnList.autoSend)
sendAutomatically:enable()
else
sendAutomatically:disable()
end
selectObjectButton:enable()
clearObjectButton:disable()
currentItemPreview:setItemId(0)
else
hotkeyText:clearText()
hotkeyText:disable()
hotKeyTextLabel:disable()
sendAutomatically:disable()
selectObjectButton:disable()
clearObjectButton:enable()
currentItemPreview:setItemId(hotkeyLabelSelectedOnList.itemId)
end
changeUseType(hotkeyLabelSelectedOnList.useType)
else
hotkeyText:clearText() hotkeyText:clearText()
removeHotkeyButton:disable()
hotkeyText:disable() hotkeyText:disable()
sendAutomatically:disable() hotKeyTextLabel:disable()
sendAutomatically:setChecked(false) sendAutomatically:setChecked(false)
sendAutomatically:disable()
currentItemPreview:setItemId(0)
selectObjectButton:disable() selectObjectButton:disable()
clearObjectButton:disable() clearObjectButton:enable()
useOnSelf:disable() currentItemPreview:setItemId(currentHotkeyLabel.itemId)
useOnTarget:disable() if currentItemPreview:getItem():isMultiUse() then
useWith:disable() useOnSelf:enable()
useOnSelf:setChecked(false) useOnTarget:enable()
useOnTarget:setChecked(false) useWith:enable()
useWith:setChecked(false) if currentHotkeyLabel.useType == HOTKEY_MANAGER_USEONSELF then
end useRadioGroup:selectWidget(useOnSelf)
end elseif currentHotkeyLabel.useType == HOTKEY_MANAGER_USEONTARGET then
end useRadioGroup:selectWidget(useOnTarget)
elseif currentHotkeyLabel.useType == HOTKEY_MANAGER_USEWITH then
function changeUseType(useType, checked) useRadioGroup:selectWidget(useWith)
if checked == nil or checked then end
hotkeyLabelSelectedOnList.useType = useType else
if hotkeyLabelSelectedOnList.itemId ~= nil and currentItemPreview:getItem():isMultiUse() then useOnSelf:disable()
useOnSelf:enable() useOnTarget:disable()
useOnTarget:enable() useWith:disable()
useWith:enable() useRadioGroup:clearSelected()
if useType == HOTKEY_MANAGER_USEONSELF then
hotkeyLabelSelectedOnList:setText(tr('%s: (use object on yourself)', hotkeyLabelSelectedOnList.keyCombo))
hotkeyLabelSelectedOnList:setColor(HotkeyColors.itemUseSelf)
useOnSelf:setChecked(true)
useOnTarget:setChecked(false)
useWith:setChecked(false)
elseif useType == HOTKEY_MANAGER_USEONTARGET then
hotkeyLabelSelectedOnList:setText(tr('%s: (use object on target)', hotkeyLabelSelectedOnList.keyCombo))
hotkeyLabelSelectedOnList:setColor(HotkeyColors.itemUseTarget)
useOnSelf:setChecked(false)
useOnTarget:setChecked(true)
useWith:setChecked(false)
elseif useType == HOTKEY_MANAGER_USEWITH then
hotkeyLabelSelectedOnList:setText(tr('%s: (use object with crosshair)', hotkeyLabelSelectedOnList.keyCombo))
hotkeyLabelSelectedOnList:setColor(HotkeyColors.itemUseWith)
useOnSelf:setChecked(false)
useOnTarget:setChecked(false)
useWith:setChecked(true)
end end
elseif hotkeyLabelSelectedOnList.itemId ~= nil and not currentItemPreview:getItem():isMultiUse() then
useOnSelf:disable()
useOnTarget:disable()
useWith:disable()
hotkeyLabelSelectedOnList:setText(tr('%s: (use object)', hotkeyLabelSelectedOnList.keyCombo))
hotkeyLabelSelectedOnList:setColor(HotkeyColors.itemUse)
useOnSelf:setChecked(false)
useOnTarget:setChecked(false)
useWith:setChecked(false)
else else
useOnSelf:disable() useOnSelf:disable()
useOnTarget:disable() useOnTarget:disable()
useWith:disable() useWith:disable()
useRadioGroup:clearSelected()
useOnSelf:setChecked(false) hotkeyText:enable()
useOnTarget:setChecked(false) hotkeyText:focus()
useWith:setChecked(false) hotKeyTextLabel:enable()
hotkeyText:setText(currentHotkeyLabel.value)
hotkeyText:setCursorPos(-1)
sendAutomatically:setChecked(currentHotkeyLabel.autoSend)
sendAutomatically:setEnabled(currentHotkeyLabel.value and #currentHotkeyLabel.value > 0)
selectObjectButton:enable()
clearObjectButton:disable()
currentItemPreview:clearItem()
end end
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()
end end
end end
function removeHotkey() function removeHotkey()
if hotkeyLabelSelectedOnList ~= nil then if currentHotkeyLabel == nil then return end
hotkeyList[hotkeyLabelSelectedOnList.keyCombo] = nil g_keyboard.unbindKeyPress(currentHotkeyLabel.keyCombo)
g_keyboard.unbindKeyPress(hotkeyLabelSelectedOnList.keyCombo) currentHotkeyLabel:destroy()
hotkeyLabelSelectedOnList:destroy() currentHotkeyLabel = nil
hotkeyLabelSelectedOnList = 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
end end
updateHotkeyLabel(currentHotkeyLabel)
updateHotkeyForm()
end end
function onHotkeyTextChange(id, value) function onSendAutomaticallyChange(autoSend)
if hotkeyLabelSelectedOnList ~= nil and hotkeyLabelSelectedOnList.keyCombo ~= nil then if not hotkeysManagerLoaded then return end
hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': ' .. value) if currentHotkeyLabel == nil then return end
hotkeyLabelSelectedOnList.value = value if not currentHotkeyLabel.value or #currentHotkeyLabel.value == 0 then return end
currentHotkeyLabel.autoSend = autoSend
updateHotkeyLabel(currentHotkeyLabel)
updateHotkeyForm()
end
if value ~= '' then function onChangeUseType(useTypeWidget)
sendAutomatically:enable() if not hotkeysManagerLoaded then return end
else if currentHotkeyLabel == nil then return end
sendAutomatically:disable() if useTypeWidget == useOnSelf then
sendAutomatically:setChecked(false) currentHotkeyLabel.useType = HOTKEY_MANAGER_USEONSELF
end elseif useTypeWidget == useOnTarget then
currentHotkeyLabel.useType = HOTKEY_MANAGER_USEONTARGET
elseif useTypeWidget == useWith then
currentHotkeyLabel.useType = HOTKEY_MANAGER_USEWITH
else
currentHotkeyLabel.useType = HOTKEY_MANAGER_USE
end end
updateHotkeyLabel(currentHotkeyLabel)
updateHotkeyForm()
end end
function setSendAutomatically(value) function onSelectHotkeyLabel(hotkeyLabel)
if hotkeyLabelSelectedOnList ~= nil then currentHotkeyLabel = hotkeyLabel
hotkeyLabelSelectedOnList.autoSend = value updateHotkeyForm()
if value then
hotkeyLabelSelectedOnList:setColor(HotkeyColors.autoSend)
else
hotkeyLabelSelectedOnList:setColor(HotkeyColors.text)
end
end
end end
function hotkeyCapture(widget, keyCode, keyboardModifiers) function hotkeyCapture(assignWindow, keyCode, keyboardModifiers)
local keyCombo = determineKeyComboDesc(keyCode, keyboardModifiers) local keyCombo = determineKeyComboDesc(keyCode, keyboardModifiers)
local comboPreview = rootWidget:getChildById('assignWindow'):getChildById('comboPreview') local comboPreview = assignWindow:getChildById('comboPreview')
comboPreview:setText(tr('Current hotkey to add: %s', keyCombo)) comboPreview:setText(tr('Current hotkey to add: %s', keyCombo))
comboPreview.keyCombo = keyCombo comboPreview.keyCombo = keyCombo
comboPreview:resizeToText() comboPreview:resizeToText()
rootWidget:getChildById('assignWindow'):getChildById('addButton'):enable() assignWindow:getChildById('addButton'):enable()
return true return true
end end
function hotkeyCaptureOk(assignWindow, keyCombo)
addKeyCombo(keyCombo, nil, true)
assignWindow:destroy()
end

@ -14,7 +14,7 @@ MainWindow
size: 340 410 size: 340 410
@onEnter: modules.game_hotkeys.ok() @onEnter: modules.game_hotkeys.ok()
@onEscape: modules.game_hotkeys.reload() @onEscape: modules.game_hotkeys.cancel()
Label Label
id: currentHotkeysLabel id: currentHotkeysLabel
@ -40,12 +40,14 @@ MainWindow
anchors.bottom: prev.bottom anchors.bottom: prev.bottom
focusable: false focusable: false
Label Button
!text: tr('Manage hotkeys:') id: resetButton
width: 96
!text: tr('Reset All')
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.top: next.top
anchors.top: prev.bottom @onClick: modules.game_hotkeys.reset()
margin-top: 10 margin-right: 10
Button Button
id: addHotkeyButton id: addHotkeyButton
@ -82,7 +84,7 @@ MainWindow
anchors.right: parent.right anchors.right: parent.right
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 2 margin-top: 2
@onTextChange: modules.game_hotkeys.onHotkeyTextChange(self:getId(), self:getText()) @onTextChange: modules.game_hotkeys.onHotkeyTextChange(self:getText())
CheckBox CheckBox
id: sendAutomatically id: sendAutomatically
@ -92,7 +94,7 @@ MainWindow
anchors.top: prev.bottom anchors.top: prev.bottom
enabled:false enabled:false
margin-top: 5 margin-top: 5
@onCheckChange: modules.game_hotkeys.setSendAutomatically(self:isChecked()) @onCheckChange: modules.game_hotkeys.onSendAutomaticallyChange(self:isChecked())
Item Item
id: itemPreview id: itemPreview
@ -132,7 +134,6 @@ MainWindow
anchors.top: selectObjectButton.top anchors.top: selectObjectButton.top
checked: false checked: false
margin-left: 10 margin-left: 10
@onCheckChange: modules.game_hotkeys.changeUseType(HOTKEY_MANAGER_USEONSELF, self:isChecked())
ButtonBox ButtonBox
id: useOnTarget id: useOnTarget
@ -144,7 +145,6 @@ MainWindow
anchors.top: prev.bottom anchors.top: prev.bottom
checked: false checked: false
margin-top: 2 margin-top: 2
@onCheckChange: modules.game_hotkeys.changeUseType(HOTKEY_MANAGER_USEONTARGET, self:isChecked())
ButtonBox ButtonBox
id: useWith id: useWith
@ -156,7 +156,6 @@ MainWindow
anchors.top: prev.bottom anchors.top: prev.bottom
checked: false checked: false
margin-top: 2 margin-top: 2
@onCheckChange: modules.game_hotkeys.changeUseType(HOTKEY_MANAGER_USEWITH, self:isChecked())
HorizontalSeparator HorizontalSeparator
id: separator id: separator
@ -166,6 +165,7 @@ MainWindow
margin-bottom: 10 margin-bottom: 10
Button Button
id: okButton
!text: tr('Ok') !text: tr('Ok')
width: 64 width: 64
anchors.right: next.left anchors.right: next.left
@ -174,11 +174,12 @@ MainWindow
margin-right: 10 margin-right: 10
Button Button
id: cancelButton
!text: tr('Cancel') !text: tr('Cancel')
width: 64 width: 64
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
@onClick: modules.game_hotkeys.reload() @onClick: modules.game_hotkeys.cancel()
HotkeyAssignWindow < MainWindow HotkeyAssignWindow < MainWindow
id: assignWindow id: assignWindow
@ -215,10 +216,11 @@ HotkeyAssignWindow < MainWindow
width: 64 width: 64
anchors.right: next.left anchors.right: next.left
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
@onClick: modules.game_hotkeys.addKeyCombo(self:getParent(), self:getParent():getChildById('comboPreview').keyCombo, nil, true)
margin-right: 10 margin-right: 10
@onClick: modules.game_hotkeys.hotkeyCaptureOk(self:getParent(), self:getParent():getChildById('comboPreview').keyCombo)
Button Button
id: cancelButton
!text: tr('Cancel') !text: tr('Cancel')
width: 64 width: 64
anchors.right: parent.right anchors.right: parent.right

@ -326,7 +326,7 @@ function onTradeWith(clickedWidget, mousePosition)
end end
function startUseWith(thing) function startUseWith(thing)
if not thing then return end if g_ui.isMouseGrabbed() or not thing then return end
selectedType = 'use' selectedType = 'use'
selectedThing = thing selectedThing = thing
mouseGrabberWidget:grabMouse() mouseGrabberWidget:grabMouse()
@ -334,6 +334,7 @@ function startUseWith(thing)
end end
function startTradeWith(thing) function startTradeWith(thing)
if g_ui.isMouseGrabbed() or not thing then return end
selectedType = 'trade' selectedType = 'trade'
selectedThing = thing selectedThing = thing
mouseGrabberWidget:grabMouse() mouseGrabberWidget:grabMouse()
@ -434,7 +435,7 @@ function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
menu:addOption(tr('Invite to private chat'), function() g_game.inviteToOwnChannel(creatureName) end) menu:addOption(tr('Invite to private chat'), function() g_game.inviteToOwnChannel(creatureName) end)
menu:addOption(tr('Exclude from private chat'), function() g_game.excludeFromOwnChannel(creatureName) end) -- [TODO] must be removed after message's popup labels been implemented menu:addOption(tr('Exclude from private chat'), function() g_game.excludeFromOwnChannel(creatureName) end) -- [TODO] must be removed after message's popup labels been implemented
end end
if (not Player:hasVip(creatureName)) then if not localPlayer:hasVip(creatureName) then
menu:addOption(tr('Add to VIP list'), function() g_game.addVip(creatureName) end) menu:addOption(tr('Add to VIP list'), function() g_game.addVip(creatureName) end)
end end

@ -42,10 +42,11 @@ function init()
minimapWidget.onMouseWheel = onMinimapMouseWheel minimapWidget.onMouseWheel = onMinimapMouseWheel
flagsPanel = minimapWindow:recursiveGetChildById('flagsPanel') flagsPanel = minimapWindow:recursiveGetChildById('flagsPanel')
g_keyboard.bindKeyPress('Alt+Left', function() move(-1,0) end) local gameRootPanel = modules.game_interface.getRootPanel()
g_keyboard.bindKeyPress('Alt+Right', function() move(1,0) end) g_keyboard.bindKeyPress('Alt+Left', function() move(-1,0) end, gameRootPanel)
g_keyboard.bindKeyPress('Alt+Up', function() move(0,-1) end) g_keyboard.bindKeyPress('Alt+Right', function() move(1,0) end, gameRootPanel)
g_keyboard.bindKeyPress('Alt+Down', function() move(0,1) end) g_keyboard.bindKeyPress('Alt+Up', function() move(0,-1) end, gameRootPanel)
g_keyboard.bindKeyPress('Alt+Down', function() move(0,1) end, gameRootPanel)
reset() reset()
minimapWindow:setup() minimapWindow:setup()
@ -58,10 +59,11 @@ function init()
end end
function terminate() function terminate()
g_keyboard.unbindKeyPress('Alt+Left') local gameRootPanel = modules.game_interface.getRootPanel()
g_keyboard.unbindKeyPress('Alt+Right') g_keyboard.unbindKeyPress('Alt+Left', gameRootPanel)
g_keyboard.unbindKeyPress('Alt+Up') g_keyboard.unbindKeyPress('Alt+Right', gameRootPanel)
g_keyboard.unbindKeyPress('Alt+Down') g_keyboard.unbindKeyPress('Alt+Up', gameRootPanel)
g_keyboard.unbindKeyPress('Alt+Down', gameRootPanel)
disconnect(g_game, { disconnect(g_game, {
onGameStart = online, onGameStart = online,

@ -317,6 +317,8 @@ void Application::registerLuaFunctions()
g_lua.bindSingletonFunction("g_ui", "getPressedWidget", &UIManager::getPressedWidget, &g_ui); g_lua.bindSingletonFunction("g_ui", "getPressedWidget", &UIManager::getPressedWidget, &g_ui);
g_lua.bindSingletonFunction("g_ui", "setDebugBoxesDrawing", &UIManager::setDebugBoxesDrawing, &g_ui); g_lua.bindSingletonFunction("g_ui", "setDebugBoxesDrawing", &UIManager::setDebugBoxesDrawing, &g_ui);
g_lua.bindSingletonFunction("g_ui", "isDrawingDebugBoxes", &UIManager::setDebugBoxesDrawing, &g_ui); g_lua.bindSingletonFunction("g_ui", "isDrawingDebugBoxes", &UIManager::setDebugBoxesDrawing, &g_ui);
g_lua.bindSingletonFunction("g_ui", "isMouseGrabbed", &UIManager::isMouseGrabbed, &g_ui);
g_lua.bindSingletonFunction("g_ui", "isKeyboardGrabbed", &UIManager::isKeyboardGrabbed, &g_ui);
// FontManager // FontManager
g_lua.registerSingletonClass("g_fonts"); g_lua.registerSingletonClass("g_fonts");

@ -65,6 +65,8 @@ public:
UIWidgetPtr getHoveredWidget() { return m_hoveredWidget; } UIWidgetPtr getHoveredWidget() { return m_hoveredWidget; }
UIWidgetPtr getPressedWidget() { return m_pressedWidget; } UIWidgetPtr getPressedWidget() { return m_pressedWidget; }
UIWidgetPtr getRootWidget() { return m_rootWidget; } UIWidgetPtr getRootWidget() { return m_rootWidget; }
bool isMouseGrabbed() { return m_mouseReceiver != m_rootWidget; }
bool isKeyboardGrabbed() { return m_keyboardReceiver != m_rootWidget; }
bool isDrawingDebugBoxes() { return m_drawDebugBoxes; } bool isDrawingDebugBoxes() { return m_drawDebugBoxes; }

Loading…
Cancel
Save