Rework hotkeys manager, fix many issues on it

This commit is contained in:
Eduardo Bart 2013-01-30 18:23:26 -02:00
parent 377c013dfe
commit 5bf03c50d6
15 changed files with 379 additions and 350 deletions

View File

@ -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

View File

@ -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')

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()
local parent = self:getParent()
if parent then
self:setHorizontalScrollBar(self:getParent():getChildById(value)) 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)

View File

@ -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(),

View File

@ -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)

View File

@ -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
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 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()
local hotkeySettings = g_settings.getNode('HotkeysManager') or {}
hotkeySettings[server] = {}
hotkeySettings[server][char] = {}
for i=1, currentHotkeysList:getChildCount() do
local child = currentHotkeysList:getChildByIndex(i)
table.insert(hotkeySettings[server][char], {
keyCombo = child.keyCombo,
autoSend = child.autoSend,
itemId = child.itemId,
useType = child.useType,
value = child.value
})
end end
g_settings.setNode('HotkeysManager', hotkeySettings) function show()
hotkeysWindow:show()
hotkeysWindow:raise()
hotkeysWindow:focus()
end
function hide()
hotkeysWindow:hide()
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()
if g_game.isOnline() then
hotkeysWindow:grabKeyboard()
hotkeysWindow:show()
hotkeysWindow:raise()
end
end
function hide()
hotkeysWindow:ungrabKeyboard()
hotkeysWindow:hide()
end
function ok() function ok()
save() save()
hide() hide()
end end
function reload() function cancel()
local children = currentHotkeysList:getChildren() reload()
for i=1,#children do
hotkeyList[children[i].keyCombo] = nil
g_keyboard.unbindKeyPress(children[i].keyCombo)
end
currentHotkeysList:destroyChildren()
hotkeyLabelSelectedOnList = nil
load()
hide() hide()
end 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
if currentHotkeys:getChildCount() == 0 then
loadDefautComboKeys()
end
hotkeysManagerLoaded = true
end
function unload()
for _,child in pairs(currentHotkeys:getChildren()) do
g_keyboard.unbindKeyPress(child.keyCombo)
end
currentHotkeys:destroyChildren()
currentHotkeyLabel = nil
updateHotkeyForm()
hotkeyList = {}
end
function reset()
unload()
load(true)
end
function reload()
unload()
load()
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
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 = currentHotkeysList:getChildren() local children = currentHotkeys:getChildren()
children[#children+1] = label children[#children+1] = hotkeyLabel
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)
end updateHotkeyForm()
if messageBox then
messageBox:destroy()
messageBox = nil
end end
end end
function call(keyCombo) function doKeyCombo(keyCombo)
if g_game.isOnline() then if not g_game.isOnline() then return end
local hotKey = hotkeyList[keyCombo] local hotKey = hotkeyList[keyCombo]
if hotKey ~= nil and hotKey.itemId == nil and hotKey.value ~= '' then 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 if hotKey.autoSend then
modules.game_console.sendMessage(hotKey.value) modules.game_console.sendMessage(hotKey.value)
else else
modules.game_console.setTextEditText(hotKey.value) modules.game_console.setTextEditText(hotKey.value)
end end
elseif hotKey.itemId ~= nil then elseif hotKey.useType == HOTKEY_MANAGER_USE then
if hotKey.useType == HOTKEY_MANAGER_USEONSELF then g_game.useInventoryItemWith(hotKey.itemId)
elseif hotKey.useType == HOTKEY_MANAGER_USEONSELF then
g_game.useInventoryItemWith(hotKey.itemId, g_game.getLocalPlayer()) g_game.useInventoryItemWith(hotKey.itemId, g_game.getLocalPlayer())
elseif hotKey.useType == HOTKEY_MANAGER_USEONTARGET then elseif hotKey.useType == HOTKEY_MANAGER_USEONTARGET then
local attackingCreature = g_game.getAttackingCreature() local attackingCreature = g_game.getAttackingCreature()
if attackingCreature then if not attackingCreature then return end
g_game.useInventoryItemWith(hotKey.itemId, attackingCreature) g_game.useInventoryItemWith(hotKey.itemId, attackingCreature)
end
elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then
itemWidget:setItemId(hotKey.itemId) local item = Item.create(hotKey.itemId)
modules.game_interface.startUseWith(itemWidget:getItem()) modules.game_interface.startUseWith(item)
end end
end end
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)
end
end end
end end
function checkSelectedHotkey(focused) function updateHotkeyForm()
if hotkeysManagerLoaded then if currentHotkeyLabel then
hotkeyLabelSelectedOnList = focused
if hotkeyLabelSelectedOnList ~= nil then
removeHotkeyButton:enable() removeHotkeyButton:enable()
if currentHotkeyLabel.itemId ~= nil then
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:clearText()
hotkeyText:disable() hotkeyText:disable()
hotKeyTextLabel:disable() hotKeyTextLabel:disable()
sendAutomatically:setChecked(false)
sendAutomatically:disable() sendAutomatically:disable()
selectObjectButton:disable() selectObjectButton:disable()
clearObjectButton:enable() clearObjectButton:enable()
currentItemPreview:setItemId(currentHotkeyLabel.itemId)
currentItemPreview:setItemId(hotkeyLabelSelectedOnList.itemId) 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()
end
else
useOnSelf:disable()
useOnTarget:disable()
useWith:disable()
useRadioGroup:clearSelected()
hotkeyText:enable()
hotkeyText:focus()
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
changeUseType(hotkeyLabelSelectedOnList.useType)
else else
hotkeyText:clearText()
removeHotkeyButton:disable() removeHotkeyButton:disable()
hotkeyText:disable() hotkeyText:disable()
sendAutomatically:disable() sendAutomatically:disable()
sendAutomatically:setChecked(false)
currentItemPreview:setItemId(0)
selectObjectButton:disable() selectObjectButton:disable()
clearObjectButton:disable() clearObjectButton:disable()
useOnSelf:disable() useOnSelf:disable()
useOnTarget:disable() useOnTarget:disable()
useWith:disable() useWith:disable()
useOnSelf:setChecked(false) hotkeyText:clearText()
useOnTarget:setChecked(false) useRadioGroup:clearSelected()
useWith:setChecked(false) sendAutomatically:setChecked(false)
end currentItemPreview:clearItem()
end
end
function changeUseType(useType, checked)
if checked == nil or checked then
hotkeyLabelSelectedOnList.useType = useType
if hotkeyLabelSelectedOnList.itemId ~= nil and currentItemPreview:getItem():isMultiUse() then
useOnSelf:enable()
useOnTarget:enable()
useWith:enable()
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
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
useOnSelf:disable()
useOnTarget:disable()
useWith:disable()
useOnSelf:setChecked(false)
useOnTarget:setChecked(false)
useWith:setChecked(false)
end
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
end end
function onHotkeyTextChange(id, value) function onHotkeyTextChange(value)
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 currentHotkeyLabel.value = value
if value == '' then
currentHotkeyLabel.autoSend = false
end
updateHotkeyLabel(currentHotkeyLabel)
updateHotkeyForm()
end
if value ~= '' then function onSendAutomaticallyChange(autoSend)
sendAutomatically:enable() 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
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 else
sendAutomatically:disable() currentHotkeyLabel.useType = HOTKEY_MANAGER_USE
sendAutomatically:setChecked(false)
end
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

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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");

View File

@ -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; }