mirror of
https://github.com/edubart/otclient.git
synced 2025-11-30 15:26:49 +01:00
straightforward signal and slots system for lua events
This commit is contained in:
@@ -67,7 +67,7 @@ end
|
||||
function Console.init()
|
||||
consoleWidget = UI.loadAndDisplay("/console/console.otui")
|
||||
consoleWidget:hide()
|
||||
consoleWidget.onKeyPress = onKeyPress
|
||||
connect(consoleWidget, { onKeyPress = onKeyPress })
|
||||
|
||||
commandLineEdit = consoleWidget:getChildById('commandLineEdit')
|
||||
consoleBuffer = consoleWidget:getChildById('consoleBuffer')
|
||||
|
||||
@@ -10,4 +10,17 @@ function createEnvironment()
|
||||
local env = { }
|
||||
setmetatable(env, { __index = _G} )
|
||||
return env
|
||||
end
|
||||
end
|
||||
|
||||
function connect(object, signalsAndSlots)
|
||||
for signal,slot in pairs(signalsAndSlots) do
|
||||
if not object[signal] then
|
||||
object[signal] = slot
|
||||
elseif type(object[signal]) == 'function' then
|
||||
object[signal] = { object[signal], slot }
|
||||
elseif type(signal) == 'table' then
|
||||
table.insert(object[signal], slot)
|
||||
else
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,6 +7,9 @@ local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers)
|
||||
if keyCode == KeyG then
|
||||
CharacterList.show()
|
||||
return true
|
||||
elseif keyCode == KeyQ then
|
||||
Game.logout()
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user