restoring use with functionality and hotkeys manager module

master
AndreFaramir 12 years ago
parent fdba1379a7
commit 09e831ddc0

@ -19,7 +19,7 @@ Module
- game_combatcontrols
- game_battle
- game_viplist
//- game_hotkeys
- game_hotkeys
@onLoad: |
importStyle 'styles/items.otui'

@ -7,6 +7,7 @@ local gameRightPanel
local gameLeftPanel
local gameBottomPanel
local logoutButton
local m_mouseGrabberWidget
function GameInterface.init()
connect(g_game, { onGameStart = GameInterface.show }, true)
@ -16,6 +17,9 @@ function GameInterface.init()
gameRootPanel:hide()
gameRootPanel:lower()
m_mouseGrabberWidget = gameRootPanel:getChildById('mouseGrabber')
connect(m_mouseGrabberWidget, { onMouseRelease = GameInterface.onUseWithMouseRelease })
gameMapPanel = gameRootPanel:getChildById('gameMapPanel')
gameRightPanel = gameRootPanel:getChildById('gameRightPanel')
gameLeftPanel = gameRootPanel:getChildById('gameLeftPanel')
@ -56,6 +60,7 @@ end
function GameInterface.terminate()
disconnect(g_game, { onGameStart = GameInterface.show })
disconnect(g_game, { onGameEnd = GameInterface.hide })
disconnect(m_mouseGrabberWidget, { onMouseRelease = onUseWithMouseRelease })
logoutButton:destroy()
logoutButton = nil
@ -66,6 +71,8 @@ function GameInterface.terminate()
gameLeftPanel = nil
gameBottomPanel = nil
GameInterface = nil
m_mouseGrabberWidget:destroy()
m_mouseGrabberWidget = nil
end
function GameInterface.show()
@ -98,6 +105,33 @@ function GameInterface.tryLogout()
end
end
function GameInterface.onUseWithMouseRelease(self, mousePosition, mouseButton)
if GameInterface.selectedThing == nil then return false end
if mouseButton == MouseLeftButton then
local clickedWidget = gameRootPanel:recursiveGetChildByPos(mousePosition, false)
if clickedWidget then
if clickedWidget:getClassName() == 'UIMap' then
local tile = clickedWidget:getTile(mousePosition)
if tile then
g_game.useWith(GameInterface.selectedThing, tile:getTopMultiUseThing())
end
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
g_game.useWith(GameInterface.selectedThing, clickedWidget:getItem())
end
end
end
GameInterface.selectedThing = nil
Mouse.restoreCursor()
self:ungrabMouse()
return true
end
function GameInterface.startUseWith(thing)
GameInterface.selectedThing = thing
m_mouseGrabberWidget:grabMouse()
Mouse.setTargetCursor()
end
function GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
local menu = createWidget('PopupMenu')
@ -115,7 +149,7 @@ function GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatu
end
else
if useThing:isMultiUse() then
menu:addOption('Use with ...', function() g_game.startUseWith(useThing) end)
menu:addOption('Use with ...', function() GameInterface.startUseWith(useThing) end)
else
menu:addOption('Use', function() g_game.use(useThing) end)
end
@ -230,7 +264,7 @@ function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalk, l
return true
end
elseif useThing:isMultiUse() then
g_game.startUseWith(useThing)
GameInterface.startUseWith(useThing)
return true
else
g_game.use(useThing)
@ -255,7 +289,7 @@ function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalk, l
return true
end
elseif multiUseThing:isMultiUse() then
g_game.startUseWith(multiUseThing)
GameInterface.startUseWith(useThing)
return true
else
g_game.use(multiUseThing)

@ -34,6 +34,7 @@ local hotkeyColors = {
-- public functions
function HotkeysManager.init()
print("PASSO HK INIT")
hotkeysWindow = displayUI('hotkeys_manager.otui')
hotkeysWindow:setVisible(false)
@ -145,7 +146,7 @@ end
function HotkeysManager.onChooseItemMouseRelease(self, mousePosition, mouseButton)
local item = nil
if mouseButton == MouseLeftButton then
local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition, false)
local clickedWidget = GameInterface.getRootPanel():recursiveGetChildByPos(mousePosition, false)
if clickedWidget then
if clickedWidget:getClassName() == 'UIMap' then
local tile = clickedWidget:getTile(mousePosition)
@ -304,7 +305,7 @@ function HotkeysManager.call(keyCombo)
end
elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then
itemWidget:setItemId(hotKey.itemId)
g_game.startUseWith(itemWidget:getItem())
GameInterface.startUseWith(itemWidget:getItem())
end
end
end

@ -2,10 +2,4 @@
-- you can place any custom user code here
-- you
Keyboard.bindKeyDown('F1', function() g_game.talk('exura gran') end)
Keyboard.bindKeyDown('F2', function() g_game.talk('exori mort') end)
Keyboard.bindKeyDown('F3', function() g_game.talk('exori frigo') end)
Keyboard.bindKeyDown('F4', function() g_game.talk('exevo vis hur') end)
Keyboard.bindKeyDown('F5', function() g_game.talk('utani gran hur') end)
Keyboard.bindKeyDown('F6', function() g_game.talk('exani tera') end)
Keyboard.bindKeyDown('Ctrl+R', Client.reloadScripts)

Loading…
Cancel
Save