diff --git a/modules/addon_terminal/commands.lua b/modules/addon_terminal/commands.lua index b08f80e2..36dd70ff 100644 --- a/modules/addon_terminal/commands.lua +++ b/modules/addon_terminal/commands.lua @@ -44,3 +44,20 @@ end function quit() exit() end + +function reloadModule(name) + local module = g_modules.getModule(name) + if module then + module:unload() + module:load() + end +end + +function autoReloadModule(name) + local function reloadEvent() + reloadModule(name) + scheduleEvent(reloadEvent, 1000) + end + reloadEvent() +end + diff --git a/modules/addon_terminal/terminal.lua b/modules/addon_terminal/terminal.lua index 7bae2ddb..14601b26 100644 --- a/modules/addon_terminal/terminal.lua +++ b/modules/addon_terminal/terminal.lua @@ -108,15 +108,15 @@ function Terminal.init() terminalWidget:setVisible(false) terminalButton = TopMenu.addButton('terminalButton', 'Terminal (Ctrl + T)', 'terminal.png', Terminal.toggle) - Hotkeys.bindKeyDown('Ctrl+T', Terminal.toggle) + Keyboard.bindKeyDown('Ctrl+T', Terminal.toggle) commandHistory = Settings.getList('terminal-history') commandLineEdit = terminalWidget:getChildById('commandLineEdit') - Hotkeys.bindKeyDown('Up', function() navigateCommand(1) end, commandLineEdit) - Hotkeys.bindKeyDown('Down', function() navigateCommand(-1) end, commandLineEdit) - Hotkeys.bindKeyDown('Tab', completeCommand, commandLineEdit) - Hotkeys.bindKeyDown('Enter', doCommand, commandLineEdit) + Keyboard.bindKeyDown('Up', function() navigateCommand(1) end, commandLineEdit) + Keyboard.bindKeyDown('Down', function() navigateCommand(-1) end, commandLineEdit) + Keyboard.bindKeyDown('Tab', completeCommand, commandLineEdit) + Keyboard.bindKeyDown('Enter', doCommand, commandLineEdit) terminalBuffer = terminalWidget:getChildById('terminalBuffer') Logger.setOnLog(onLog) @@ -125,7 +125,7 @@ end function Terminal.terminate() Settings.setList('terminal-history', commandHistory) - Hotkeys.unbindKeyDown('Ctrl+T') + Keyboard.unbindKeyDown('Ctrl+T') Logger.setOnLog(nil) terminalButton:destroy() terminalButton = nil diff --git a/modules/addon_terminal/terminal.otmod b/modules/addon_terminal/terminal.otmod index 7c3e2525..d03ccfe3 100644 --- a/modules/addon_terminal/terminal.otmod +++ b/modules/addon_terminal/terminal.otmod @@ -8,8 +8,8 @@ Module autoLoadAntecedence: 200 onLoad: | - require 'terminal' - require 'commands' + dofile 'terminal' + dofile 'commands' Terminal.init() onUnload: | diff --git a/modules/client/client.lua b/modules/client/client.lua index 60f1450f..05d1db73 100644 --- a/modules/client/client.lua +++ b/modules/client/client.lua @@ -34,4 +34,5 @@ function Client.terminate() Settings.set('window-size', g_window.getUnmaximizedSize()) Settings.set('window-pos', g_window.getUnmaximizedPos()) Settings.set('window-maximized', g_window.isMaximized()) + g_window.hide() end diff --git a/modules/client/client.otmod b/modules/client/client.otmod index 84f89a58..7b1c65c6 100644 --- a/modules/client/client.otmod +++ b/modules/client/client.otmod @@ -3,6 +3,7 @@ Module description: Load all other otclient dependecies author: OTClient team website: https://github.com/edubart/otclient + canUnload: false // NOTE: order does matter dependencies: @@ -16,7 +17,7 @@ Module - game onLoad: | - require 'client' + dofile 'client' Client.init() onUnload: | diff --git a/modules/client_about/about.otmod b/modules/client_about/about.otmod index 7c934992..4bc7a306 100644 --- a/modules/client_about/about.otmod +++ b/modules/client_about/about.otmod @@ -5,7 +5,7 @@ Module website: https://github.com/edubart/otclient onLoad: | - require 'about' + dofile 'about' About.init() onUnload: | diff --git a/modules/client_background/background.otmod b/modules/client_background/background.otmod index 733586d2..16af71db 100644 --- a/modules/client_background/background.otmod +++ b/modules/client_background/background.otmod @@ -5,7 +5,7 @@ Module website: https://github.com/edubart/otclient onLoad: | - require 'background' + dofile 'background' Background.init() onUnload: | diff --git a/modules/client_entergame/entergame.lua b/modules/client_entergame/entergame.lua index 7ac44f64..19cda80b 100644 --- a/modules/client_entergame/entergame.lua +++ b/modules/client_entergame/entergame.lua @@ -57,7 +57,7 @@ end -- public functions function EnterGame.init() enterGameButton = TopMenu.addButton('enterGameButton', 'Login (Ctrl + G)', '/core_styles/icons/login.png', EnterGame.openWindow) - Hotkeys.bindKeyDown('Ctrl+G', EnterGame.openWindow) + Keyboard.bindKeyDown('Ctrl+G', EnterGame.openWindow) motdButton = TopMenu.addButton('motdButton', 'Message of the day', '/core_styles/icons/motd.png', EnterGame.displayMotd) motdButton:hide() enterGame = displayUI('entergame.otui') @@ -82,7 +82,7 @@ function EnterGame.init() end function EnterGame.terminate() - Hotkeys.unbindKeyDown('Ctrl+G') + Keyboard.unbindKeyDown('Ctrl+G') enterGame:destroy() enterGame = nil enterGameButton:destroy() diff --git a/modules/client_entergame/entergame.otmod b/modules/client_entergame/entergame.otmod index 8a9e14e0..6f96379d 100644 --- a/modules/client_entergame/entergame.otmod +++ b/modules/client_entergame/entergame.otmod @@ -5,8 +5,8 @@ Module website: https://github.com/edubart/otclient onLoad: | - require 'entergame' - require 'characterlist' + dofile 'entergame' + dofile 'characterlist' EnterGame.init() onUnload: | diff --git a/modules/client_modulemanager/modulemanager.otmod b/modules/client_modulemanager/modulemanager.otmod index 589a99c2..9fee752e 100644 --- a/modules/client_modulemanager/modulemanager.otmod +++ b/modules/client_modulemanager/modulemanager.otmod @@ -4,7 +4,7 @@ Module author: OTClient team website: https://github.com/edubart/otclient onLoad: | - require 'modulemanager' + dofile 'modulemanager' ModuleManager.init() onUnload: | diff --git a/modules/client_options/options.lua b/modules/client_options/options.lua index fb78b545..e5c9ef7c 100644 --- a/modules/client_options/options.lua +++ b/modules/client_options/options.lua @@ -25,11 +25,11 @@ function Options.init() optionsWindow = displayUI('options.otui') optionsWindow:setVisible(false) optionsButton = TopMenu.addButton('optionsButton', 'Options (Ctrl+O)', 'options.png', Options.toggle) - Hotkeys.bindKeyDown('Ctrl+O', Options.toggle) + Keyboard.bindKeyDown('Ctrl+O', Options.toggle) end function Options.terminate() - Hotkeys.unbindKeyDown('Ctrl+O') + Keyboard.unbindKeyDown('Ctrl+O') optionsWindow:destroy() optionsWindow = nil optionsButton:destroy() diff --git a/modules/client_options/options.otmod b/modules/client_options/options.otmod index fdb94178..714f93e5 100644 --- a/modules/client_options/options.otmod +++ b/modules/client_options/options.otmod @@ -5,7 +5,7 @@ Module website: https://github.com/edubart/otclient onLoad: | - require 'options' + dofile 'options' Options.init() onUnload: | diff --git a/modules/client_topmenu/topmenu.lua b/modules/client_topmenu/topmenu.lua index 77862a42..ce81d020 100644 --- a/modules/client_topmenu/topmenu.lua +++ b/modules/client_topmenu/topmenu.lua @@ -23,11 +23,11 @@ function TopMenu.init() gameButtonsPanel = topMenu:getChildById('gameButtonsPanel') TopMenu.addRightButton('logoutButton', 'Logout (Ctrl+Q)', '/core_styles/icons/logout.png', onLogout) - Hotkeys.bindKeyDown('Ctrl+Q', onLogout) + Keyboard.bindKeyDown('Ctrl+Q', onLogout) end function TopMenu.terminate() - Hotkeys.unbindKeyDown('Ctrl+Q') + Keyboard.unbindKeyDown('Ctrl+Q') leftButtonsPanel = nil rightButtonsPanel = nil gameButtonsPanel = nil @@ -71,16 +71,6 @@ function TopMenu.addRightButton(id, description, icon, callback) return TopMenu.addButton(id, description, resolvepath(icon, 2), callback, true) end -function TopMenu.removeButton(param) - local button - if type(param) == 'string' then - button = TopMenu.getButton(param) - else - button = param - end - button:destroy() -end - function TopMenu.hideGameButtons() gameButtonsPanel:hide() end @@ -93,10 +83,5 @@ function TopMenu.getButton(id) return topMenu:recursiveGetChildById(id) end -function TopMenu:getLogoutButton(id) - return TopMenu.getButton('logoutButton') -end - - connect(Game, { onLogin = TopMenu.showGameButtons, - onLogout = TopMenu.hideGameButtons}) \ No newline at end of file + onLogout = TopMenu.hideGameButtons }) diff --git a/modules/client_topmenu/topmenu.otmod b/modules/client_topmenu/topmenu.otmod index c2ad99e6..f2cfe727 100644 --- a/modules/client_topmenu/topmenu.otmod +++ b/modules/client_topmenu/topmenu.otmod @@ -5,7 +5,7 @@ Module website: https://github.com/edubart/otclient onLoad: | - require 'topmenu' + dofile 'topmenu' TopMenu.init() onUnload: | diff --git a/modules/core_fonts/core_fonts.otmod b/modules/core_fonts/core_fonts.otmod index 8d870754..51e68b2c 100644 --- a/modules/core_fonts/core_fonts.otmod +++ b/modules/core_fonts/core_fonts.otmod @@ -3,6 +3,8 @@ Module description: Contains fonts used by core author: OTClient team website: https://github.com/edubart/otclient + canUnload: false + onLoad: | importFont 'verdana-11px-antialised' importFont 'verdana-11px-monochrome' diff --git a/modules/core_lib/core_lib.otmod b/modules/core_lib/core_lib.otmod index 8a956237..763fba02 100644 --- a/modules/core_lib/core_lib.otmod +++ b/modules/core_lib/core_lib.otmod @@ -5,21 +5,21 @@ Module website: https://github.com/edubart/otclient onLoad: | - require 'ext/table' - require 'ext/string' - require 'ext/os' - require 'math/point' - require 'math/size' - require 'math/color' - require 'math/rect' - require 'const' - require 'util' - require 'globals' - require 'dispatcher' - require 'effects' - require 'settings' - require 'hotkeys' - require 'cursor' + dofile 'ext/table' + dofile 'ext/string' + dofile 'ext/os' + dofile 'math/point' + dofile 'math/size' + dofile 'math/color' + dofile 'math/rect' + dofile 'const' + dofile 'util' + dofile 'globals' + dofile 'dispatcher' + dofile 'effects' + dofile 'settings' + dofile 'keyboard' + dofile 'mouse' onUnload: | rootWidget = nil diff --git a/modules/core_lib/cursor.lua b/modules/core_lib/cursor.lua deleted file mode 100644 index ed6e83c8..00000000 --- a/modules/core_lib/cursor.lua +++ /dev/null @@ -1,7 +0,0 @@ -function setTargetCursor() - g_window.setMouseCursor('/core_styles/icons/targetcursor.png', {x=9,y=9}) -end - -function restoreCursor() - g_window.restoreMouseCursor() -end diff --git a/modules/core_lib/keyboard.lua b/modules/core_lib/keyboard.lua new file mode 100644 index 00000000..52e99553 --- /dev/null +++ b/modules/core_lib/keyboard.lua @@ -0,0 +1,134 @@ +Keyboard = {} + +-- private functions +local function translateKeyCombo(keyCombo) + if not keyCombo or #keyCombo == 0 then return nil end + table.sort(keyCombo) + local keyComboDesc = '' + for k,v in pairs(keyCombo) do + local keyDesc = KeyCodeDescs[v] + if keyDesc == nil then return nil end + keyComboDesc = keyComboDesc .. '+' .. keyDesc + end + keyComboDesc = keyComboDesc:sub(2) + return keyComboDesc +end + +local function retranslateKeyComboDesc(keyComboDesc) + if keyComboDesc == nil then return nil end + local keyCombo = {} + for i,currentKeyDesc in ipairs(keyComboDesc:split('+')) do + for keyCode, keyDesc in pairs(KeyCodeDescs) do + if keyDesc:lower() == currentKeyDesc:trim():lower() then + table.insert(keyCombo, keyCode) + end + end + end + return translateKeyCombo(keyCombo) +end + +local function determineKeyComboDesc(keyCode, keyboardModifiers) + local keyCombo = {} + if keyCode == KeyCtrl or keyCode == KeyShift or keyCode == KeyAlt then + table.insert(keyCombo, keyCode) + elseif KeyCodeDescs[keyCode] ~= nil then + if keyboardModifiers == KeyboardCtrlModifier then + table.insert(keyCombo, KeyCtrl) + elseif keyboardModifiers == KeyboardAltModifier then + table.insert(keyCombo, KeyAlt) + elseif keyboardModifiers == KeyboardCtrlAltModifier then + table.insert(keyCombo, KeyCtrl) + table.insert(keyCombo, KeyAlt) + elseif keyboardModifiers == KeyboardShiftModifier then + table.insert(keyCombo, KeyShift) + elseif keyboardModifiers == KeyboardCtrlShiftModifier then + table.insert(keyCombo, KeyCtrl) + table.insert(keyCombo, KeyShift) + elseif keyboardModifiers == KeyboardAltShiftModifier then + table.insert(keyCombo, KeyAlt) + table.insert(keyCombo, KeyShift) + elseif keyboardModifiers == KeyboardCtrlAltShiftModifier then + table.insert(keyCombo, KeyCtrl) + table.insert(keyCombo, KeyAlt) + table.insert(keyCombo, KeyShift) + end + table.insert(keyCombo, keyCode) + end + table.sort(keyCombo) + return translateKeyCombo(keyCombo) +end + +local function onWidgetKeyDown(widget, keyCode, keyboardModifiers) + if keyCode == KeyUnknown then return end + local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers) + local callback = widget.boundKeyDownCombos[keyComboDesc] + if callback then + callback() + return true + end + return false +end + +local function onWidgetKeyPress(widget, keyCode, keyboardModifiers, wouldFilter) + local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers) + if keyCode == KeyUnknown then return end + local callback = widget.boundKeyPressCombos[keyComboDesc] + if callback then + callback() + return true + end + return false +end + +local function connectKeyDownEvent(widget) + if widget.boundKeyDownCombos then return end + connect(widget, { onKeyDown = onWidgetKeyDown }) + widget.boundKeyDownCombos = {} +end + +local function connectKeyPressEvent(widget) + if widget.boundKeyPressCombos then return end + connect(widget, { onKeyPress = onWidgetKeyPress }) + widget.boundKeyPressCombos = {} +end + +-- public functions +function Keyboard.bindKeyDown(keyComboDesc, callback, widget) + widget = widget or rootWidget + connectKeyDownEvent(widget) + local keyComboDesc = retranslateKeyComboDesc(keyComboDesc) + if keyComboDesc then + widget.boundKeyDownCombos[keyComboDesc] = callback + else + error('key combo \'' .. keyComboDesc .. '\' is failed') + end +end + +function Keyboard.bindKeyPress(keyComboDesc, callback, widget) + widget = widget or rootWidget + connectKeyPressEvent(widget) + local keyComboDesc = retranslateKeyComboDesc(keyComboDesc) + if keyComboDesc then + widget.boundKeyPressCombos[keyComboDesc] = callback + else + error('key combo \'' .. keyComboDesc .. '\' is failed') + end +end + +function Keyboard.unbindKeyDown(keyComboDesc, widget) + widget = widget or rootWidget + if widget.boundKeyDownCombos == nil then return end + local keyComboDesc = retranslateKeyComboDesc(keyComboDesc) + if keyComboDesc then + widget.boundKeyDownCombos[keyComboDesc] = nil + end +end + +function Keyboard.unbindKeyPress(keyComboDesc, widget) + widget = widget or rootWidget + if widget.boundKeyPressCombos == nil then return end + local keyComboDesc = retranslateKeyComboDesc(keyComboDesc) + if keyComboDesc then + widget.boundKeyPressCombos[keyComboDesc] = nil + end +end diff --git a/modules/core_lib/mouse.lua b/modules/core_lib/mouse.lua index 602f9472..952ec6de 100644 --- a/modules/core_lib/mouse.lua +++ b/modules/core_lib/mouse.lua @@ -1,2 +1,9 @@ Mouse = {} +function Mouse.setTargetCursor() + g_window.setMouseCursor('/core_styles/icons/targetcursor.png', {x=9,y=9}) +end + +function Mouse.restoreCursor() + g_window.restoreMouseCursor() +end diff --git a/modules/core_lib/util.lua b/modules/core_lib/util.lua index a81cec8a..0fad2e46 100644 --- a/modules/core_lib/util.lua +++ b/modules/core_lib/util.lua @@ -114,7 +114,3 @@ function signalcall(param, ...) end return false end - -function runscript(file) - g_lua.runScript(resolvepath(file, 2)) -end \ No newline at end of file diff --git a/modules/core_widgets/core_widgets.otmod b/modules/core_widgets/core_widgets.otmod index 635ea906..cf721910 100644 --- a/modules/core_widgets/core_widgets.otmod +++ b/modules/core_widgets/core_widgets.otmod @@ -5,17 +5,17 @@ Module website: https://github.com/edubart/otclient onLoad: | - require 'uiwidget' - require 'uibutton' - require 'uilabel' - require 'uicheckbox' - require 'uicombobox' - require 'uispinbox' - require 'uiprogressbar' - require 'uitabbar' - require 'uipopupmenu' - require 'uiwindow' - require 'uiitem' - require 'tooltip/tooltip' - require 'messagebox/messagebox' + dofile 'uiwidget' + dofile 'uibutton' + dofile 'uilabel' + dofile 'uicheckbox' + dofile 'uicombobox' + dofile 'uispinbox' + dofile 'uiprogressbar' + dofile 'uitabbar' + dofile 'uipopupmenu' + dofile 'uiwindow' + dofile 'uiitem' + dofile 'tooltip/tooltip' + dofile 'messagebox/messagebox' diff --git a/modules/core_widgets/uiitem.lua b/modules/core_widgets/uiitem.lua index f6fd2665..403b607c 100644 --- a/modules/core_widgets/uiitem.lua +++ b/modules/core_widgets/uiitem.lua @@ -8,7 +8,7 @@ function UIItem:onDragEnter(mousePos) self.parsed = false self.currentDragThing = item - setTargetCursor() + Mouse.setTargetCursor() return true end @@ -19,7 +19,7 @@ function UIItem:onDragLeave(widget, mousePos) self.currentDragThing = nil end - restoreCursor() + Mouse.restoreCursor() self:setBorderWidth(0) return true end diff --git a/modules/core_widgets/uimessagebox.lua b/modules/core_widgets/uimessagebox.lua index 2c81a7cb..83e93ce9 100644 --- a/modules/core_widgets/uimessagebox.lua +++ b/modules/core_widgets/uimessagebox.lua @@ -1,3 +1,4 @@ +--[[ UIMessageBox = extends(UIWindow) function UIMessageBox.create(title, message) @@ -19,5 +20,4 @@ end function UIMessageBox:setMessage(message) end - -function \ No newline at end of file +]]-- \ No newline at end of file diff --git a/modules/game/game.lua b/modules/game/game.lua index ca71dee7..55e722ad 100644 --- a/modules/game/game.lua +++ b/modules/game/game.lua @@ -32,7 +32,7 @@ local function onUseWithMouseRelease(self, mousePosition, mouseButton) end end Game.selectedThing = nil - restoreCursor() + Mouse.restoreCursor() self:ungrabMouse() return true end @@ -41,7 +41,7 @@ end function Game.startUseWith(thing) Game.selectedThing = thing m_mouseGrabberWidget:grabMouse() - setTargetCursor() + Mouse.setTargetCursor() end function Game.createInterface() @@ -49,15 +49,15 @@ function Game.createInterface() CharacterList.destroyLoadBox() Game.gameUi = displayUI('game.otui') - --Hotkeys.bindKeyPress('Up', function() Game.walk(North) end) - --Hotkeys.bindKeyPress('Down', function() Game.walk(South) end) - --Hotkeys.bindKeyPress('Left', function() Game.walk(West) end) - --Hotkeys.bindKeyPress('Right', function() Game.walk(East) end) + --Keyboard.bindKeyPress('Up', function() Game.walk(North) end) + --Keyboard.bindKeyPress('Down', function() Game.walk(South) end) + --Keyboard.bindKeyPress('Left', function() Game.walk(West) end) + --Keyboard.bindKeyPress('Right', function() Game.walk(East) end) - Hotkeys.bindKeyPress('Ctrl+Shift+Up', function() Game.forceWalk(North) end) - Hotkeys.bindKeyPress('Ctrl+Shift+Down', function() Game.forceWalk(South) end) - Hotkeys.bindKeyPress('Ctrl+Shift+Left', function() Game.forceWalk(West) end) - Hotkeys.bindKeyPress('Ctrl+Shift+Right', function() Game.forceWalk(East) end) + Keyboard.bindKeyPress('Ctrl+Shift+Up', function() Game.forceWalk(North) end) + Keyboard.bindKeyPress('Ctrl+Shift+Down', function() Game.forceWalk(South) end) + Keyboard.bindKeyPress('Ctrl+Shift+Left', function() Game.forceWalk(West) end) + Keyboard.bindKeyPress('Ctrl+Shift+Right', function() Game.forceWalk(East) end) rootWidget:moveChildToIndex(Game.gameUi, 1) Game.gameMapPanel = Game.gameUi:getChildById('gameMapPanel') diff --git a/modules/game/game.otmod b/modules/game/game.otmod index 7187fcb1..ca0ed02b 100644 --- a/modules/game/game.otmod +++ b/modules/game/game.otmod @@ -15,8 +15,8 @@ Module - game_containers onLoad: | - require 'game' - require 'thing' - require 'creature' - require 'player' - require 'map' + dofile 'game' + dofile 'thing' + dofile 'creature' + dofile 'player' + dofile 'map' diff --git a/modules/game/map.lua b/modules/game/map.lua index d676e350..1d35f782 100644 --- a/modules/game/map.lua +++ b/modules/game/map.lua @@ -7,7 +7,7 @@ function UIMap:onDragEnter(mousePos) self.parsed = false self.currentDragThing = thing - setTargetCursor() + Mouse.setTargetCursor() return true end @@ -16,7 +16,7 @@ function UIMap:onDragLeave(widget, mousePos) self.currentDragThing = nil end - restoreCursor() + Mouse.restoreCursor() return true end diff --git a/modules/game_combatcontrols/combatcontrols.otmod b/modules/game_combatcontrols/combatcontrols.otmod index e7297d82..c0438b8d 100644 --- a/modules/game_combatcontrols/combatcontrols.otmod +++ b/modules/game_combatcontrols/combatcontrols.otmod @@ -4,4 +4,4 @@ Module author: OTClient team website: https://github.com/edubart/otclient onLoad: | - require 'combatcontrols' + dofile 'combatcontrols' diff --git a/modules/game_console/console.lua b/modules/game_console/console.lua index 2635b3c3..1397cd4e 100644 --- a/modules/game_console/console.lua +++ b/modules/game_console/console.lua @@ -88,11 +88,11 @@ function Console.create() Console.addChannel('Default', 0) Console.addTab('Server Log', false) - Hotkeys.bindKeyDown('Shift+Up', function() navigateMessageHistory(1) end, consolePanel) - Hotkeys.bindKeyDown('Shift+Down', function() navigateMessageHistory(-1) end, consolePanel) - Hotkeys.bindKeyDown('Tab', function() consoleTabBar:selectNextTab() end, consolePanel) - Hotkeys.bindKeyDown('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel) - Hotkeys.bindKeyDown('Enter', Console.sendCurrentMessage, consolePanel) + Keyboard.bindKeyDown('Shift+Up', function() navigateMessageHistory(1) end, consolePanel) + Keyboard.bindKeyDown('Shift+Down', function() navigateMessageHistory(-1) end, consolePanel) + Keyboard.bindKeyDown('Tab', function() consoleTabBar:selectNextTab() end, consolePanel) + Keyboard.bindKeyDown('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel) + Keyboard.bindKeyDown('Enter', Console.sendCurrentMessage, consolePanel) -- apply buttom functions after loaded connect(consolePanel:getChildById('nextChannelButton'), { onClick = function() consoleTabBar:selectNextTab() end } ) @@ -100,8 +100,8 @@ function Console.create() connect(consoleTabBar, { onTabChange = Console.onTabChange }) -- tibia like hotkeys - Hotkeys.bindKeyDown('Ctrl+O', Game.requestChannels) - Hotkeys.bindKeyDown('Ctrl+E', Console.removeCurrentTab) + Keyboard.bindKeyDown('Ctrl+O', Game.requestChannels) + Keyboard.bindKeyDown('Ctrl+E', Console.removeCurrentTab) end function Console.destroy() diff --git a/modules/game_console/console.otmod b/modules/game_console/console.otmod index 3a903985..0d802b99 100644 --- a/modules/game_console/console.otmod +++ b/modules/game_console/console.otmod @@ -4,4 +4,4 @@ Module author: OTClient team website: https://github.com/edubart/otclient onLoad: | - require 'console' + dofile 'console' diff --git a/modules/game_containers/containers.otmod b/modules/game_containers/containers.otmod index 3f24761f..670c35d3 100644 --- a/modules/game_containers/containers.otmod +++ b/modules/game_containers/containers.otmod @@ -4,4 +4,4 @@ Module author: OTClient team website: https://github.com/edubart/otclient onLoad: | - require 'containers' + dofile 'containers' diff --git a/modules/game_healthbar/healthbar.otmod b/modules/game_healthbar/healthbar.otmod index 5f8e9974..0c411cb2 100644 --- a/modules/game_healthbar/healthbar.otmod +++ b/modules/game_healthbar/healthbar.otmod @@ -4,4 +4,4 @@ Module author: OTClient team website: https://github.com/edubart/otclient onLoad: | - require 'healthbar' + dofile 'healthbar' diff --git a/modules/game_inventory/inventory.lua b/modules/game_inventory/inventory.lua index b6a0a1eb..0977ae73 100644 --- a/modules/game_inventory/inventory.lua +++ b/modules/game_inventory/inventory.lua @@ -9,11 +9,11 @@ function Inventory.create() inventoryWindow = displayUI('inventory.otui', { parent = Game.gameRightPanel }) inventoryButton = TopMenu.addGameButton('inventoryButton', 'Inventory (Ctrl+I)', 'inventory.png', Inventory.toggle) inventoryButton:setOn(true) - Hotkeys.bindKeyDown('Ctrl+I', Inventory.toggle) + Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle) end function Inventory.destroy() - Hotkeys.unbindKeyDown('Ctrl+I') + Keyboard.unbindKeyDown('Ctrl+I') inventoryWindow:destroy() inventoryWindow = nil inventoryButton:destroy() diff --git a/modules/game_inventory/inventory.otmod b/modules/game_inventory/inventory.otmod index e724a5e5..e84eb31c 100644 --- a/modules/game_inventory/inventory.otmod +++ b/modules/game_inventory/inventory.otmod @@ -4,4 +4,4 @@ Module author: OTClient team website: https://github.com/edubart/otclient onLoad: | - require 'inventory' + dofile 'inventory' diff --git a/modules/game_outfit/outfit.otmod b/modules/game_outfit/outfit.otmod index cbf3bfe8..6aa64a13 100644 --- a/modules/game_outfit/outfit.otmod +++ b/modules/game_outfit/outfit.otmod @@ -4,4 +4,4 @@ Module author: OTClient team website: https://github.com/edubart/otclient onLoad: | - require 'outfit' + dofile 'outfit' diff --git a/modules/game_skills/skills.lua b/modules/game_skills/skills.lua index 0ddab36e..5eeed668 100644 --- a/modules/game_skills/skills.lua +++ b/modules/game_skills/skills.lua @@ -45,11 +45,11 @@ function Skills.create() skillsWindow = displayUI('skills.otui', { parent = Game.gameRightPanel }) skillsWindow:hide() skillsButton = TopMenu.addGameButton('skillsButton', 'Skills (Ctrl+S)', '/core_styles/icons/skills.png', Skills.toggle) - Hotkeys.bindKeyDown('Ctrl+S', Skills.toggle) + Keyboard.bindKeyDown('Ctrl+S', Skills.toggle) end function Skills.destroy() - Hotkeys.unbindKeyDown('Ctrl+S') + Keyboard.unbindKeyDown('Ctrl+S') skillsButton:destroy() skillsButton = nil skillsWindow:destroy() diff --git a/modules/game_skills/skills.otmod b/modules/game_skills/skills.otmod index 440357d0..c9cfdd7b 100644 --- a/modules/game_skills/skills.otmod +++ b/modules/game_skills/skills.otmod @@ -4,4 +4,4 @@ Module author: OTClient team website: https://github.com/edubart/otclient onLoad: | - require 'skills' + dofile 'skills' diff --git a/modules/game_textmessage/textmessage.otmod b/modules/game_textmessage/textmessage.otmod index 6cc75030..7d285664 100644 --- a/modules/game_textmessage/textmessage.otmod +++ b/modules/game_textmessage/textmessage.otmod @@ -4,4 +4,4 @@ Module author: OTClient team website: https://github.com/edubart/otclient onLoad: | - require 'textmessage' + dofile 'textmessage' diff --git a/modules/game_viplist/viplist.otmod b/modules/game_viplist/viplist.otmod index d1ffb40f..95d02acb 100644 --- a/modules/game_viplist/viplist.otmod +++ b/modules/game_viplist/viplist.otmod @@ -4,4 +4,4 @@ Module author: OTClient team website: https://github.com/edubart/otclient onLoad: | - require 'viplist' + dofile 'viplist' diff --git a/modules/otclientrc.lua b/modules/otclientrc.lua index 7f3ce821..b5db244b 100644 --- a/modules/otclientrc.lua +++ b/modules/otclientrc.lua @@ -1,18 +1,18 @@ -- this file use loaded after everything is loaded and initialized -- you can place any custom user code here -Hotkeys.bindKeyDown('F1', function() Game.talk('exura gran') end) -Hotkeys.bindKeyDown('F2', function() Game.talk('exori mort') end) -Hotkeys.bindKeyDown('F3', function() Game.talk('exori frigo') end) -Hotkeys.bindKeyDown('F4', function() Game.talk('exevo vis hur') end) -Hotkeys.bindKeyDown('F5', function() Game.talk('utani gran hur') end) -Hotkeys.bindKeyDown('F6', function() Game.talk('exani tera') end) +Keyboard.bindKeyDown('F1', function() Game.talk('exura gran') end) +Keyboard.bindKeyDown('F2', function() Game.talk('exori mort') end) +Keyboard.bindKeyDown('F3', function() Game.talk('exori frigo') end) +Keyboard.bindKeyDown('F4', function() Game.talk('exevo vis hur') end) +Keyboard.bindKeyDown('F5', function() Game.talk('utani gran hur') end) +Keyboard.bindKeyDown('F6', function() Game.talk('exani tera') end) local function reload() - runscript('otclientrc.lua') + dofile('otclientrc.lua') TextMessage.displayEventAdvance('Script otclientrc.lua reloaded.') print('Script otclient.rc lua reloaded') end -Hotkeys.bindKeyDown('Ctrl+R', reload) +Keyboard.bindKeyDown('Ctrl+R', reload) rcloaded = true diff --git a/src/framework/luascript/luainterface.cpp b/src/framework/luascript/luainterface.cpp index 77d57fda..86c22f25 100644 --- a/src/framework/luascript/luainterface.cpp +++ b/src/framework/luascript/luainterface.cpp @@ -512,6 +512,22 @@ int LuaInterface::luaScriptLoader(lua_State* L) } } +int LuaInterface::luaScriptRunner(lua_State* L) +{ + std::string fileName = g_lua.popString(); + if(!boost::ends_with(fileName, ".lua")) + fileName += ".lua"; + + try { + g_lua.loadScript(fileName); + g_lua.call(0, LUA_MULTRET); + return g_lua.stackSize(); + } catch(LuaException& e) { + logError("failed to load script file '", fileName, "' :'", e.what()); + return 0; + } +} + int LuaInterface::luaErrorHandler(lua_State* L) { // pops the error message @@ -583,6 +599,10 @@ void LuaInterface::createLuaState() pushCFunction(&LuaInterface::luaScriptLoader); rawSeti(5); pop(2); + + // replace dofile + pushCFunction(&LuaInterface::luaScriptRunner); + setGlobal("dofile"); } void LuaInterface::closeLuaState() diff --git a/src/framework/luascript/luainterface.h b/src/framework/luascript/luainterface.h index 1338b507..9e900b72 100644 --- a/src/framework/luascript/luainterface.h +++ b/src/framework/luascript/luainterface.h @@ -186,6 +186,8 @@ public: private: /// Load scripts requested by lua 'require' static int luaScriptLoader(lua_State* L); + /// Run scripts requested by lua 'dofile' + static int luaScriptRunner(lua_State* L); /// Handle lua errors from safeCall static int luaErrorHandler(lua_State* L); /// Handle bound cpp functions callbacks