diff --git a/modules/client_entergame/entergame.otui b/modules/client_entergame/entergame.otui index 20b78dca..a0065268 100644 --- a/modules/client_entergame/entergame.otui +++ b/modules/client_entergame/entergame.otui @@ -116,3 +116,4 @@ EnterGameWindow anchors.bottom: parent.bottom anchors.left: parent.left color: green + text-auto-resize: true diff --git a/modules/client_options/graphics.otui b/modules/client_options/graphics.otui index 8f98d673..c0df08de 100644 --- a/modules/client_options/graphics.otui +++ b/modules/client_options/graphics.otui @@ -44,10 +44,6 @@ Panel id: enableLights !text: tr('Enable lights') - OptionCheckBox - id: enableShaders - !text: tr('Enable shader effects') - OptionCheckBox id: fullscreen !text: tr('Fullscreen') diff --git a/modules/client_options/options.lua b/modules/client_options/options.lua index 4b0b4d3d..6e34ead5 100644 --- a/modules/client_options/options.lua +++ b/modules/client_options/options.lua @@ -19,10 +19,8 @@ local defaultOptions = { painterEngine = 0, enableAudio = true, enableMusicSound = true, - enableShaders = true, musicSoundVolume = 100, enableLights = true, - enableShaders = true, ambientLight = 25, } @@ -77,9 +75,6 @@ local function setupGraphicsEngines() graphicsPanel:getChildById('foregroundFrameRate'):disable() graphicsPanel:getChildById('foregroundFrameRateLabel'):disable() end - - local shadersBox = graphicsPanel:getChildById('enableShaders') - shadersBox:setEnabled(g_graphics.getPainterEngine() == 2) end function init() @@ -225,8 +220,6 @@ function setOption(key, value) graphicsPanel:getChildById('ambientLightLabel'):setEnabled(value) end end) - elseif key == 'enableShaders' then - g_graphics.setShouldUseShaders(value) elseif key == 'ambientLight' then addEvent(function() local map = modules.game_interface.getMapPanel() @@ -238,12 +231,6 @@ function setOption(key, value) end) elseif key == 'painterEngine' then g_graphics.selectPainterEngine(value) - addEvent(function() - if graphicsPanel then - local shadersBox = graphicsPanel:getChildById('enableShaders') - shadersBox:setEnabled(value == 2) - end - end) end g_settings.set(key, value) options[key] = value diff --git a/modules/client_stats/stats.lua b/modules/client_stats/stats.lua index cfa55180..c4572b70 100644 --- a/modules/client_stats/stats.lua +++ b/modules/client_stats/stats.lua @@ -106,5 +106,5 @@ function onRecv(protocol, message) end function onError(protocol, message, code) - perror('Could not send statistics: ' .. message) + pdebug('Could not send statistics: ' .. message) end diff --git a/modules/corelib/settings.lua b/modules/corelib/settings.lua index adabc111..9abc7c3a 100644 --- a/modules/corelib/settings.lua +++ b/modules/corelib/settings.lua @@ -8,6 +8,7 @@ g_settings.getNode = g_configs.getNode g_settings.remove = g_configs.remove g_settings.setList = g_configs.setList g_settings.getList = g_configs.getList +g_settings.save = g_configs.save local function convertSettingValue(value) if type(value) == 'table' then diff --git a/modules/corelib/ui/uipopupmenu.lua b/modules/corelib/ui/uipopupmenu.lua index f13bc7f1..c9dd886f 100644 --- a/modules/corelib/ui/uipopupmenu.lua +++ b/modules/corelib/ui/uipopupmenu.lua @@ -18,6 +18,11 @@ function UIPopupMenu:display(pos) return end + if g_ui.isMouseGrabbed() then + self:destroy() + return + end + if currentMenu then currentMenu:destroy() end diff --git a/modules/corelib/ui/uiscrollarea.lua b/modules/corelib/ui/uiscrollarea.lua index 4df15145..e63f4a36 100644 --- a/modules/corelib/ui/uiscrollarea.lua +++ b/modules/corelib/ui/uiscrollarea.lua @@ -14,11 +14,17 @@ function UIScrollArea:onStyleApply(styleName, styleNode) for name,value in pairs(styleNode) do if name == 'vertical-scrollbar' then addEvent(function() - self:setVerticalScrollBar(self:getParent():getChildById(value)) + local parent = self:getParent() + if parent then + self:setVerticalScrollBar(parent:getChildById(value)) + end end) elseif name == 'horizontal-scrollbar' then addEvent(function() - self:setHorizontalScrollBar(self:getParent():getChildById(value)) + local parent = self:getParent() + if parent then + self:setHorizontalScrollBar(self:getParent():getChildById(value)) + end end) elseif name == 'inverted-scroll' then self:setInverted(value) diff --git a/modules/game_combatcontrols/combatcontrols.lua b/modules/game_combatcontrols/combatcontrols.lua index e1b04aa7..ed57bfb3 100644 --- a/modules/game_combatcontrols/combatcontrols.lua +++ b/modules/game_combatcontrols/combatcontrols.lua @@ -92,7 +92,7 @@ end function online() local player = g_game.getLocalPlayer() if player then - local char = player:getName() + local char = g_game.getCharacterName() local lastCombatControls = g_settings.getNode('LastCombatControls') @@ -116,7 +116,7 @@ function offline() local player = g_game.getLocalPlayer() if player then - local char = player:getName() + local char = g_game.getCharacterName() lastCombatControls[char] = { fightMode = g_game.getFightMode(), chaseMode = g_game.getChaseMode(), diff --git a/modules/game_console/console.lua b/modules/game_console/console.lua index 679f6e26..0c6a9468 100644 --- a/modules/game_console/console.lua +++ b/modules/game_console/console.lua @@ -199,7 +199,7 @@ end function clear() -- save last open channels local lastChannelsOpen = g_settings.getNode('lastChannelsOpen') or {} - local char = g_game.getLocalPlayer():getName() + local char = g_game.getCharacterName() local savedChannels = {} local set = false for channelId, channelName in pairs(channels) do @@ -447,8 +447,7 @@ function addTabText(text, speaktype, tab, creatureName) labelHighlight:setId('consoleLabel' .. consoleBufferHighlight:getChildCount()) labelHighlight:setColor("#1f9ffe") - local player = g_game.getLocalPlayer() - if speaktype.npcChat and (player:getName() ~= creatureName or player:getName() == 'Account Manager') then -- Check if it is the npc who is talking + if speaktype.npcChat and (g_game.getCharacterName() ~= creatureName or g_game.getCharacterName() == 'Account Manager') then -- Check if it is the npc who is talking local highlightData = getHighlightedText(text) if #highlightData == 0 then labelHighlight:setText("") @@ -675,7 +674,7 @@ function sendMessage(message, tab) local player = g_game.getLocalPlayer() 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()) end end @@ -740,7 +739,7 @@ function onTalk(name, level, mode, message, channelId, creaturePos) return end - if name ~= g_game.getLocalPlayer():getName() then + if name ~= g_game.getCharacterName() then if mode == MessageModes.Yell and isIgnoringYelling() then return elseif speaktype.private and isIgnoringPrivate() and mode ~= MessageModes.NpcFrom then @@ -875,7 +874,7 @@ function doChannelListSubmit() local channelListPanel = channelsWindow:getChildById('channelList') local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText() if openPrivateChannelWith ~= '' then - if openPrivateChannelWith:lower() ~= g_game.getLocalPlayer():getName():lower() then + if openPrivateChannelWith:lower() ~= g_game.getCharacterName():lower() then g_game.openPrivateChannel(openPrivateChannelWith) else modules.game_textmessage.displayFailureMessage('You cannot create a private chat channel with yourself.') @@ -1028,7 +1027,7 @@ function online() -- open last channels local lastChannelsOpen = g_settings.getNode('lastChannelsOpen') if lastChannelsOpen then - local savedChannels = lastChannelsOpen[g_game.getLocalPlayer():getName()] + local savedChannels = lastChannelsOpen[g_game.getCharacterName()] if savedChannels then for channelName, channelId in pairs(savedChannels) do channelId = tonumber(channelId) diff --git a/modules/game_hotkeys/hotkeys_manager.lua b/modules/game_hotkeys/hotkeys_manager.lua index 0b71e5a7..67a3c124 100644 --- a/modules/game_hotkeys/hotkeys_manager.lua +++ b/modules/game_hotkeys/hotkeys_manager.lua @@ -1,3 +1,4 @@ +HOTKEY_MANAGER_USE = nil HOTKEY_MANAGER_USEONSELF = 1 HOTKEY_MANAGER_USEONTARGET = 2 HOTKEY_MANAGER_USEWITH = 3 @@ -14,8 +15,7 @@ HotkeyColors = { hotkeysManagerLoaded = false hotkeysWindow = nil hotkeysButton = nil -currentHotkeysList = nil -hotkeyLabelSelectedOnList = nil +currentHotkeyLabel = nil currentItemPreview = nil itemWidget = nil addHotkeyButton = nil @@ -29,20 +29,21 @@ useOnSelf = nil useOnTarget = nil useWith = nil defaultComboKeys = nil -hotkeyList = {} +perServer = true +perCharacter = true +mouseGrabberWidget = nil +useRadioGroup = nil +currentHotkeys = nil +hotkeysList = {} -- public functions 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) g_keyboard.bindKeyDown('Ctrl+K', toggle) - g_keyboard.bindKeyPress('Down', function() hotkeyListPanel:focusNextChild(KeyboardFocusReason) end, hotkeysWindow) - g_keyboard.bindKeyPress('Up', function() hotkeyListPanel:focusPreviousChild(KeyboardFocusReason) end, hotkeysWindow) + hotkeysWindow = g_ui.displayUI('hotkeys_manager') + hotkeysWindow:setVisible(false) - currentHotkeysList = hotkeysWindow:getChildById('currentHotkeys') + currentHotkeys = hotkeysWindow:getChildById('currentHotkeys') currentItemPreview = hotkeysWindow:getChildById('itemPreview') addHotkeyButton = hotkeysWindow:getChildById('addHotkeyButton') removeHotkeyButton = hotkeysWindow:getChildById('removeHotkeyButton') @@ -55,132 +56,171 @@ function init() useOnTarget = hotkeysWindow:getChildById('useOnTarget') useWith = hotkeysWindow:getChildById('useWith') - itemWidget = g_ui.createWidget('UIItem') - itemWidget:setVirtual(true) - itemWidget:setVisible(false) - itemWidget:setFocusable(false) + useRadioGroup = UIRadioGroup.create() + useRadioGroup:addWidget(useOnSelf) + useRadioGroup:addWidget(useOnTarget) + useRadioGroup:addWidget(useWith) + useRadioGroup.onSelectionChange = function(self, selected) onChangeUseType(selected) end + + mouseGrabberWidget = g_ui.createWidget('UIWidget') + mouseGrabberWidget:setVisible(false) + mouseGrabberWidget:setFocusable(false) + mouseGrabberWidget.onMouseRelease = onChooseItemMouseRelease + + currentHotkeys.onChildFocusChange = function(self, hotkeyLabel) onSelectHotkeyLabel(hotkeyLabel) end + g_keyboard.bindKeyPress('Down', function() currentHotkeys:focusNextChild(KeyboardFocusReason) end, hotkeysWindow) + g_keyboard.bindKeyPress('Up', function() currentHotkeys:focusPreviousChild(KeyboardFocusReason) end, hotkeysWindow) connect(g_game, { - onGameStart = onGameStart, - onGameEnd = hide + onGameStart = online, + onGameEnd = offline }) - connect(currentHotkeysList, { onChildFocusChange = function (self, focusedChild) checkSelectedHotkey(focusedChild) end } ) - - hotkeysManagerLoaded = true end function terminate() - hotkeysManagerLoaded = false - disconnect(g_game, { - onGameStart = onGameStart, - onGameEnd = hide + onGameStart = online, + onGameEnd = offline }) + g_keyboard.unbindKeyDown('Ctrl+K') - for keyCombo,v in pairs(hotkeyList) do - g_keyboard.unbindKeyPress(keyCombo) - end - hotkeyList = {} + unload() - itemWidget:destroy() hotkeysWindow:destroy() hotkeysButton:destroy() + mouseGrabberWidget:destroy() end -function load() - local hotkeySettings = g_settings.getNode('HotkeysManager') - local hasCombos = false - 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 +function configure(savePerServer, savePerCharacter) + perServer = savePerServer + perCharacter = savePerCharacter +end - -- add default F keys combos - if not hasCombos then - loadDefautComboKeys() - end +function online() + reload() + hide() end -function save() - local char = g_game.getLocalPlayer():getName() - local server = G.host +function offline() + unload() + hide() +end - local hotkeySettings = g_settings.getNode('HotkeysManager') or {} - hotkeySettings[server] = {} - hotkeySettings[server][char] = {} +function show() + hotkeysWindow:show() + hotkeysWindow:raise() + hotkeysWindow:focus() +end - 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 - - g_settings.setNode('HotkeysManager', hotkeySettings) +function hide() + hotkeysWindow:hide() end function toggle() if not hotkeysWindow:isVisible() then show() + else + hide() end end -function show() - if g_game.isOnline() then - hotkeysWindow:grabKeyboard() - hotkeysWindow:show() - hotkeysWindow:raise() +function ok() + save() + hide() +end + +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 + + if currentHotkeys:getChildCount() == 0 then + loadDefautComboKeys() + end + + hotkeysManagerLoaded = true end -function hide() - hotkeysWindow:ungrabKeyboard() - hotkeysWindow:hide() +function unload() + for _,child in pairs(currentHotkeys:getChildren()) do + g_keyboard.unbindKeyPress(child.keyCombo) + end + currentHotkeys:destroyChildren() + currentHotkeyLabel = nil + updateHotkeyForm() + hotkeyList = {} end -function ok() - save() - hide() +function reset() + unload() + load(true) end function reload() - local children = currentHotkeysList:getChildren() - for i=1,#children do - hotkeyList[children[i].keyCombo] = nil - g_keyboard.unbindKeyPress(children[i].keyCombo) - end - currentHotkeysList:destroyChildren() - hotkeyLabelSelectedOnList = nil + unload() 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 function loadDefautComboKeys() if not defaultComboKeys then for i=1,12 do - addKeyCombo(nil, 'F' .. i) + addKeyCombo('F' .. i) end for i=1,4 do - addKeyCombo(nil, 'Shift+F' .. i) + addKeyCombo('Shift+F' .. i) end else for keyCombo, keySettings in pairs(defaultComboKeys) do - addKeyCombo(nil, keyCombo, keySettings) + addKeyCombo(keyCombo, keySettings) end end end @@ -189,11 +229,6 @@ function setDefaultComboKeys(combo) defaultComboKeys = combo end --- private functions -function onGameStart() - reload() -end - function onChooseItemMouseRelease(self, mousePosition, mouseButton) local item = nil if mouseButton == MouseLeftButton then @@ -213,41 +248,40 @@ function onChooseItemMouseRelease(self, mousePosition, mouseButton) end end - if item and hotkeyLabelSelectedOnList then - currentItemPreview:setItemId(item:getId()) - hotkeyLabelSelectedOnList.itemId = item:getId() - changeUseType(HOTKEY_MANAGER_USEONSELF) - checkSelectedHotkey(hotkeyLabelSelectedOnList) + if item and currentHotkeyLabel then + currentHotkeyLabel.itemId = item:getId() + if item:isMultiUse() then + currentHotkeyLabel.useType = HOTKEY_MANAGER_USEWITH + else + currentHotkeyLabel.useType = HOTKEY_MANAGER_USE + end + currentHotkeyLabel.value = nil + currentHotkeyLabel.autoSend = false + updateHotkeyLabel(currentHotkeyLabel) + updateHotkeyForm() end show() g_mouse.popCursor('target') self:ungrabMouse() - self:destroy() + return true end function startChooseItem() - local mouseGrabberWidget = g_ui.createWidget('UIWidget') - mouseGrabberWidget:setVisible(false) - mouseGrabberWidget:setFocusable(false) - - connect(mouseGrabberWidget, { onMouseRelease = onChooseItemMouseRelease }) - + if g_ui.isMouseGrabbed() then return end mouseGrabberWidget:grabMouse() g_mouse.pushCursor('target') - hide() end function clearObject() - hotkeyLabelSelectedOnList.itemId = nil - currentItemPreview:clearItem() - changeUseType(HOTKEY_MANAGER_USEONSELF) - setSendAutomatically(false) - hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': ') - - checkSelectedHotkey(hotkeyLabelSelectedOnList) + currentHotkeyLabel.itemId = nil + currentHotkeyLabel.useType = nil + currentHotkeyLabel.autoSend = nil + currentHotkeyLabel.value = nil + updateHotkeyLabel(currentHotkeyLabel) + updateHotkeyForm() end function addHotkey() @@ -256,21 +290,18 @@ function addHotkey() local comboLabel = assignWindow:getChildById('comboPreview') comboLabel.keyCombo = '' - - connect(assignWindow, { onKeyDown = hotkeyCapture }, true) + assignWindow.onKeyDown = hotkeyCapture end -function addKeyCombo(messageBox, keyCombo, keySettings, focus) +function addKeyCombo(keyCombo, keySettings, focus) if not keyCombo then return end - local label = currentHotkeysList:getChildById(keyCombo) - if not label then - label = g_ui.createWidget('HotkeyListLabel') - label:setId(keyCombo) - label:setColor(HotkeyColors.text) - label:setText(keyCombo .. ': ') - - local children = currentHotkeysList:getChildren() - children[#children+1] = label + local hotkeyLabel = currentHotkeys:getChildById(keyCombo) + if not hotkeyLabel then + hotkeyLabel = g_ui.createWidget('HotkeyListLabel') + hotkeyLabel:setId(keyCombo) + + local children = currentHotkeys:getChildren() + children[#children+1] = hotkeyLabel table.sort(children, function(a,b) if a:getId():len() < b:getId():len() then return true @@ -281,218 +312,212 @@ function addKeyCombo(messageBox, keyCombo, keySettings, focus) end end) for i=1,#children do - if children[i] == label then - currentHotkeysList:insertChild(i, label) + if children[i] == hotkeyLabel then + currentHotkeys:insertChild(i, hotkeyLabel) break end end if keySettings then - hotkeyLabelSelectedOnList = label - label.keyCombo = keyCombo - label.autoSend = keySettings.autoSend - label.itemId = keySettings.itemId - label.useType = tonumber(keySettings.useType) - label.value = keySettings.value + currentHotkeyLabel = hotkeyLabel + hotkeyLabel.keyCombo = keyCombo + hotkeyLabel.autoSend = keySettings.autoSend + hotkeyLabel.itemId = keySettings.itemId + hotkeyLabel.useType = tonumber(keySettings.useType) + hotkeyLabel.value = keySettings.value else - label.keyCombo = keyCombo - label.autoSend = false - label.itemId = nil - label.useType = HOTKEY_MANAGER_USEONSELF - label.value = '' + hotkeyLabel.keyCombo = keyCombo + hotkeyLabel.autoSend = nil + hotkeyLabel.itemId = nil + hotkeyLabel.useType = nil + hotkeyLabel.value = nil end - checkSelectedHotkey(label) + updateHotkeyLabel(hotkeyLabel) - hotkeyList[keyCombo] = label - g_keyboard.bindKeyPress(keyCombo, function () call(keyCombo) end, nil, 350) + g_keyboard.bindKeyPress(keyCombo, function() doKeyCombo(keyCombo) end, nil, 350) end if focus then - currentHotkeysList:focusChild(label) - currentHotkeysList:ensureChildVisible(label) + currentHotkeys:focusChild(hotkeyLabel) + currentHotkeys:ensureChildVisible(hotkeyLabel) + updateHotkeyForm() end +end - if messageBox then - messageBox:destroy() - messageBox = nil +function doKeyCombo(keyCombo) + if not g_game.isOnline() then return end + local hotKey = hotkeyList[keyCombo] + if not hotKey then return end + if hotKey.itemId == nil then + if not hotKey.value or #hotKey.value == 0 then return end + if hotKey.autoSend then + modules.game_console.sendMessage(hotKey.value) + else + modules.game_console.setTextEditText(hotKey.value) + end + elseif hotKey.useType == HOTKEY_MANAGER_USE then + 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 -function call(keyCombo) - if g_game.isOnline() then - local hotKey = hotkeyList[keyCombo] - if hotKey ~= nil and hotKey.itemId == nil and hotKey.value ~= '' then - if hotKey.autoSend then - modules.game_console.sendMessage(hotKey.value) - else - modules.game_console.setTextEditText(hotKey.value) - end - elseif hotKey.itemId ~= nil then - if 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 attackingCreature then - g_game.useInventoryItemWith(hotKey.itemId, attackingCreature) - end - elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then - itemWidget:setItemId(hotKey.itemId) - modules.game_interface.startUseWith(itemWidget:getItem()) - 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 -function checkSelectedHotkey(focused) - if hotkeysManagerLoaded then - hotkeyLabelSelectedOnList = focused - - 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 +function updateHotkeyForm() + if currentHotkeyLabel then + removeHotkeyButton:enable() + if currentHotkeyLabel.itemId ~= nil then hotkeyText:clearText() - removeHotkeyButton:disable() hotkeyText:disable() - sendAutomatically:disable() + hotKeyTextLabel:disable() sendAutomatically:setChecked(false) - - currentItemPreview:setItemId(0) + sendAutomatically:disable() selectObjectButton:disable() - clearObjectButton:disable() - useOnSelf:disable() - useOnTarget:disable() - useWith:disable() - useOnSelf:setChecked(false) - useOnTarget:setChecked(false) - useWith:setChecked(false) - end - 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) + clearObjectButton:enable() + currentItemPreview:setItemId(currentHotkeyLabel.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 - 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) + 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 + 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 function removeHotkey() - if hotkeyLabelSelectedOnList ~= nil then - hotkeyList[hotkeyLabelSelectedOnList.keyCombo] = nil - g_keyboard.unbindKeyPress(hotkeyLabelSelectedOnList.keyCombo) - hotkeyLabelSelectedOnList:destroy() - hotkeyLabelSelectedOnList = nil + if currentHotkeyLabel == nil then return end + g_keyboard.unbindKeyPress(currentHotkeyLabel.keyCombo) + currentHotkeyLabel:destroy() + currentHotkeyLabel = nil +end + +function onHotkeyTextChange(value) + if not hotkeysManagerLoaded then return end + if currentHotkeyLabel == nil then return end + currentHotkeyLabel.value = value + if value == '' then + currentHotkeyLabel.autoSend = false end + updateHotkeyLabel(currentHotkeyLabel) + updateHotkeyForm() end -function onHotkeyTextChange(id, value) - if hotkeyLabelSelectedOnList ~= nil and hotkeyLabelSelectedOnList.keyCombo ~= nil then - hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': ' .. value) - hotkeyLabelSelectedOnList.value = value +function onSendAutomaticallyChange(autoSend) + if not hotkeysManagerLoaded then return end + if currentHotkeyLabel == nil then return end + if not currentHotkeyLabel.value or #currentHotkeyLabel.value == 0 then return end + currentHotkeyLabel.autoSend = autoSend + updateHotkeyLabel(currentHotkeyLabel) + updateHotkeyForm() +end - if value ~= '' then - sendAutomatically:enable() - else - sendAutomatically:disable() - sendAutomatically:setChecked(false) - 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 + currentHotkeyLabel.useType = HOTKEY_MANAGER_USE end + updateHotkeyLabel(currentHotkeyLabel) + updateHotkeyForm() end -function setSendAutomatically(value) - if hotkeyLabelSelectedOnList ~= nil then - hotkeyLabelSelectedOnList.autoSend = value - if value then - hotkeyLabelSelectedOnList:setColor(HotkeyColors.autoSend) - else - hotkeyLabelSelectedOnList:setColor(HotkeyColors.text) - end - end +function onSelectHotkeyLabel(hotkeyLabel) + currentHotkeyLabel = hotkeyLabel + updateHotkeyForm() end -function hotkeyCapture(widget, keyCode, keyboardModifiers) +function hotkeyCapture(assignWindow, 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.keyCombo = keyCombo comboPreview:resizeToText() - rootWidget:getChildById('assignWindow'):getChildById('addButton'):enable() - + assignWindow:getChildById('addButton'):enable() return true end + +function hotkeyCaptureOk(assignWindow, keyCombo) + addKeyCombo(keyCombo, nil, true) + assignWindow:destroy() +end diff --git a/modules/game_hotkeys/hotkeys_manager.otui b/modules/game_hotkeys/hotkeys_manager.otui index 6e345b9f..017a4c9c 100644 --- a/modules/game_hotkeys/hotkeys_manager.otui +++ b/modules/game_hotkeys/hotkeys_manager.otui @@ -14,7 +14,7 @@ MainWindow size: 340 410 @onEnter: modules.game_hotkeys.ok() - @onEscape: modules.game_hotkeys.reload() + @onEscape: modules.game_hotkeys.cancel() Label id: currentHotkeysLabel @@ -40,12 +40,14 @@ MainWindow anchors.bottom: prev.bottom focusable: false - Label - !text: tr('Manage hotkeys:') + Button + id: resetButton + width: 96 + !text: tr('Reset All') anchors.left: parent.left - anchors.right: parent.right - anchors.top: prev.bottom - margin-top: 10 + anchors.top: next.top + @onClick: modules.game_hotkeys.reset() + margin-right: 10 Button id: addHotkeyButton @@ -82,7 +84,7 @@ MainWindow anchors.right: parent.right anchors.top: prev.bottom margin-top: 2 - @onTextChange: modules.game_hotkeys.onHotkeyTextChange(self:getId(), self:getText()) + @onTextChange: modules.game_hotkeys.onHotkeyTextChange(self:getText()) CheckBox id: sendAutomatically @@ -92,7 +94,7 @@ MainWindow anchors.top: prev.bottom enabled:false margin-top: 5 - @onCheckChange: modules.game_hotkeys.setSendAutomatically(self:isChecked()) + @onCheckChange: modules.game_hotkeys.onSendAutomaticallyChange(self:isChecked()) Item id: itemPreview @@ -132,7 +134,6 @@ MainWindow anchors.top: selectObjectButton.top checked: false margin-left: 10 - @onCheckChange: modules.game_hotkeys.changeUseType(HOTKEY_MANAGER_USEONSELF, self:isChecked()) ButtonBox id: useOnTarget @@ -144,7 +145,6 @@ MainWindow anchors.top: prev.bottom checked: false margin-top: 2 - @onCheckChange: modules.game_hotkeys.changeUseType(HOTKEY_MANAGER_USEONTARGET, self:isChecked()) ButtonBox id: useWith @@ -156,7 +156,6 @@ MainWindow anchors.top: prev.bottom checked: false margin-top: 2 - @onCheckChange: modules.game_hotkeys.changeUseType(HOTKEY_MANAGER_USEWITH, self:isChecked()) HorizontalSeparator id: separator @@ -166,6 +165,7 @@ MainWindow margin-bottom: 10 Button + id: okButton !text: tr('Ok') width: 64 anchors.right: next.left @@ -174,11 +174,12 @@ MainWindow margin-right: 10 Button + id: cancelButton !text: tr('Cancel') width: 64 anchors.right: parent.right anchors.bottom: parent.bottom - @onClick: modules.game_hotkeys.reload() + @onClick: modules.game_hotkeys.cancel() HotkeyAssignWindow < MainWindow id: assignWindow @@ -215,10 +216,11 @@ HotkeyAssignWindow < MainWindow width: 64 anchors.right: next.left anchors.bottom: parent.bottom - @onClick: modules.game_hotkeys.addKeyCombo(self:getParent(), self:getParent():getChildById('comboPreview').keyCombo, nil, true) margin-right: 10 + @onClick: modules.game_hotkeys.hotkeyCaptureOk(self:getParent(), self:getParent():getChildById('comboPreview').keyCombo) Button + id: cancelButton !text: tr('Cancel') width: 64 anchors.right: parent.right diff --git a/modules/game_interface/gameinterface.lua b/modules/game_interface/gameinterface.lua index 70563451..77065add 100644 --- a/modules/game_interface/gameinterface.lua +++ b/modules/game_interface/gameinterface.lua @@ -326,7 +326,7 @@ function onTradeWith(clickedWidget, mousePosition) end function startUseWith(thing) - if not thing then return end + if g_ui.isMouseGrabbed() or not thing then return end selectedType = 'use' selectedThing = thing mouseGrabberWidget:grabMouse() @@ -334,6 +334,7 @@ function startUseWith(thing) end function startTradeWith(thing) + if g_ui.isMouseGrabbed() or not thing then return end selectedType = 'trade' selectedThing = thing 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('Exclude from private chat'), function() g_game.excludeFromOwnChannel(creatureName) end) -- [TODO] must be removed after message's popup labels been implemented 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) end diff --git a/modules/game_minimap/minimap.lua b/modules/game_minimap/minimap.lua index c843a407..3f2a4d46 100644 --- a/modules/game_minimap/minimap.lua +++ b/modules/game_minimap/minimap.lua @@ -42,10 +42,11 @@ function init() minimapWidget.onMouseWheel = onMinimapMouseWheel flagsPanel = minimapWindow:recursiveGetChildById('flagsPanel') - g_keyboard.bindKeyPress('Alt+Left', function() move(-1,0) end) - g_keyboard.bindKeyPress('Alt+Right', function() move(1,0) end) - g_keyboard.bindKeyPress('Alt+Up', function() move(0,-1) end) - g_keyboard.bindKeyPress('Alt+Down', function() move(0,1) end) + local gameRootPanel = modules.game_interface.getRootPanel() + g_keyboard.bindKeyPress('Alt+Left', function() move(-1,0) end, gameRootPanel) + g_keyboard.bindKeyPress('Alt+Right', function() move(1,0) end, gameRootPanel) + g_keyboard.bindKeyPress('Alt+Up', function() move(0,-1) end, gameRootPanel) + g_keyboard.bindKeyPress('Alt+Down', function() move(0,1) end, gameRootPanel) reset() minimapWindow:setup() @@ -58,10 +59,11 @@ function init() end function terminate() - g_keyboard.unbindKeyPress('Alt+Left') - g_keyboard.unbindKeyPress('Alt+Right') - g_keyboard.unbindKeyPress('Alt+Up') - g_keyboard.unbindKeyPress('Alt+Down') + local gameRootPanel = modules.game_interface.getRootPanel() + g_keyboard.unbindKeyPress('Alt+Left', gameRootPanel) + g_keyboard.unbindKeyPress('Alt+Right', gameRootPanel) + g_keyboard.unbindKeyPress('Alt+Up', gameRootPanel) + g_keyboard.unbindKeyPress('Alt+Down', gameRootPanel) disconnect(g_game, { onGameStart = online, diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 02f77eb4..29b67bd9 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -317,6 +317,8 @@ void Application::registerLuaFunctions() 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", "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 g_lua.registerSingletonClass("g_fonts"); diff --git a/src/framework/ui/uimanager.h b/src/framework/ui/uimanager.h index 76977689..7cc68ad6 100644 --- a/src/framework/ui/uimanager.h +++ b/src/framework/ui/uimanager.h @@ -65,6 +65,8 @@ public: UIWidgetPtr getHoveredWidget() { return m_hoveredWidget; } UIWidgetPtr getPressedWidget() { return m_pressedWidget; } UIWidgetPtr getRootWidget() { return m_rootWidget; } + bool isMouseGrabbed() { return m_mouseReceiver != m_rootWidget; } + bool isKeyboardGrabbed() { return m_keyboardReceiver != m_rootWidget; } bool isDrawingDebugBoxes() { return m_drawDebugBoxes; }