Browse Source

replace require with dofile, rename Hotkeys to Keyboard

Eduardo Bart 9 years ago
parent
commit
f97104f12e
41 changed files with 284 additions and 126 deletions
  1. 17
    0
      modules/addon_terminal/commands.lua
  2. 6
    6
      modules/addon_terminal/terminal.lua
  3. 2
    2
      modules/addon_terminal/terminal.otmod
  4. 1
    0
      modules/client/client.lua
  5. 2
    1
      modules/client/client.otmod
  6. 1
    1
      modules/client_about/about.otmod
  7. 1
    1
      modules/client_background/background.otmod
  8. 2
    2
      modules/client_entergame/entergame.lua
  9. 2
    2
      modules/client_entergame/entergame.otmod
  10. 1
    1
      modules/client_modulemanager/modulemanager.otmod
  11. 2
    2
      modules/client_options/options.lua
  12. 1
    1
      modules/client_options/options.otmod
  13. 3
    18
      modules/client_topmenu/topmenu.lua
  14. 1
    1
      modules/client_topmenu/topmenu.otmod
  15. 2
    0
      modules/core_fonts/core_fonts.otmod
  16. 15
    15
      modules/core_lib/core_lib.otmod
  17. 0
    7
      modules/core_lib/cursor.lua
  18. 134
    0
      modules/core_lib/keyboard.lua
  19. 7
    0
      modules/core_lib/mouse.lua
  20. 0
    4
      modules/core_lib/util.lua
  21. 13
    13
      modules/core_widgets/core_widgets.otmod
  22. 2
    2
      modules/core_widgets/uiitem.lua
  23. 2
    2
      modules/core_widgets/uimessagebox.lua
  24. 10
    10
      modules/game/game.lua
  25. 5
    5
      modules/game/game.otmod
  26. 2
    2
      modules/game/map.lua
  27. 1
    1
      modules/game_combatcontrols/combatcontrols.otmod
  28. 7
    7
      modules/game_console/console.lua
  29. 1
    1
      modules/game_console/console.otmod
  30. 1
    1
      modules/game_containers/containers.otmod
  31. 1
    1
      modules/game_healthbar/healthbar.otmod
  32. 2
    2
      modules/game_inventory/inventory.lua
  33. 1
    1
      modules/game_inventory/inventory.otmod
  34. 1
    1
      modules/game_outfit/outfit.otmod
  35. 2
    2
      modules/game_skills/skills.lua
  36. 1
    1
      modules/game_skills/skills.otmod
  37. 1
    1
      modules/game_textmessage/textmessage.otmod
  38. 1
    1
      modules/game_viplist/viplist.otmod
  39. 8
    8
      modules/otclientrc.lua
  40. 20
    0
      src/framework/luascript/luainterface.cpp
  41. 2
    0
      src/framework/luascript/luainterface.h

+ 17
- 0
modules/addon_terminal/commands.lua View File

@@ -44,3 +44,20 @@ end
44 44
 function quit()
45 45
   exit()
46 46
 end
47
+
48
+function reloadModule(name)
49
+  local module = g_modules.getModule(name)
50
+  if module then
51
+    module:unload()
52
+    module:load()
53
+  end
54
+end
55
+
56
+function autoReloadModule(name)
57
+  local function reloadEvent()
58
+    reloadModule(name)
59
+    scheduleEvent(reloadEvent, 1000)
60
+  end
61
+  reloadEvent()
62
+end
63
+

+ 6
- 6
modules/addon_terminal/terminal.lua View File

@@ -108,15 +108,15 @@ function Terminal.init()
108 108
   terminalWidget:setVisible(false)
109 109
 
110 110
   terminalButton = TopMenu.addButton('terminalButton', 'Terminal (Ctrl + T)', 'terminal.png', Terminal.toggle)
111
-  Hotkeys.bindKeyDown('Ctrl+T', Terminal.toggle)
111
+  Keyboard.bindKeyDown('Ctrl+T', Terminal.toggle)
112 112
 
113 113
   commandHistory = Settings.getList('terminal-history')
114 114
 
115 115
   commandLineEdit = terminalWidget:getChildById('commandLineEdit')
116
-  Hotkeys.bindKeyDown('Up', function() navigateCommand(1) end, commandLineEdit)
117
-  Hotkeys.bindKeyDown('Down', function() navigateCommand(-1) end, commandLineEdit)
118
-  Hotkeys.bindKeyDown('Tab', completeCommand, commandLineEdit)
119
-  Hotkeys.bindKeyDown('Enter', doCommand, commandLineEdit)
116
+  Keyboard.bindKeyDown('Up', function() navigateCommand(1) end, commandLineEdit)
117
+  Keyboard.bindKeyDown('Down', function() navigateCommand(-1) end, commandLineEdit)
118
+  Keyboard.bindKeyDown('Tab', completeCommand, commandLineEdit)
119
+  Keyboard.bindKeyDown('Enter', doCommand, commandLineEdit)
120 120
 
121 121
   terminalBuffer = terminalWidget:getChildById('terminalBuffer')
122 122
   Logger.setOnLog(onLog)
@@ -125,7 +125,7 @@ end
125 125
 
126 126
 function Terminal.terminate()
127 127
   Settings.setList('terminal-history', commandHistory)
128
-  Hotkeys.unbindKeyDown('Ctrl+T')
128
+  Keyboard.unbindKeyDown('Ctrl+T')
129 129
   Logger.setOnLog(nil)
130 130
   terminalButton:destroy()
131 131
   terminalButton = nil

+ 2
- 2
modules/addon_terminal/terminal.otmod View File

@@ -8,8 +8,8 @@ Module
8 8
   autoLoadAntecedence: 200
9 9
 
10 10
   onLoad: |
11
-    require 'terminal'
12
-    require 'commands'
11
+    dofile 'terminal'
12
+    dofile 'commands'
13 13
     Terminal.init()
14 14
 
15 15
   onUnload: |

+ 1
- 0
modules/client/client.lua View File

@@ -34,4 +34,5 @@ function Client.terminate()
34 34
   Settings.set('window-size', g_window.getUnmaximizedSize())
35 35
   Settings.set('window-pos', g_window.getUnmaximizedPos())
36 36
   Settings.set('window-maximized', g_window.isMaximized())
37
+  g_window.hide()
37 38
 end

+ 2
- 1
modules/client/client.otmod View File

@@ -3,6 +3,7 @@ Module
3 3
   description: Load all other otclient dependecies
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6
+  canUnload: false
6 7
 
7 8
   // NOTE: order does matter
8 9
   dependencies:
@@ -16,7 +17,7 @@ Module
16 17
     - game
17 18
 
18 19
   onLoad: |
19
-    require 'client'
20
+    dofile 'client'
20 21
     Client.init()
21 22
 
22 23
   onUnload: |

+ 1
- 1
modules/client_about/about.otmod View File

@@ -5,7 +5,7 @@ Module
5 5
   website: https://github.com/edubart/otclient
6 6
 
7 7
   onLoad: |
8
-    require 'about'
8
+    dofile 'about'
9 9
     About.init()
10 10
 
11 11
   onUnload: |

+ 1
- 1
modules/client_background/background.otmod View File

@@ -5,7 +5,7 @@ Module
5 5
   website: https://github.com/edubart/otclient
6 6
 
7 7
   onLoad: |
8
-    require 'background'
8
+    dofile 'background'
9 9
     Background.init()
10 10
 
11 11
   onUnload: |

+ 2
- 2
modules/client_entergame/entergame.lua View File

@@ -57,7 +57,7 @@ end
57 57
 -- public functions
58 58
 function EnterGame.init()
59 59
   enterGameButton = TopMenu.addButton('enterGameButton', 'Login (Ctrl + G)', '/core_styles/icons/login.png', EnterGame.openWindow)
60
-  Hotkeys.bindKeyDown('Ctrl+G', EnterGame.openWindow)
60
+  Keyboard.bindKeyDown('Ctrl+G', EnterGame.openWindow)
61 61
   motdButton = TopMenu.addButton('motdButton', 'Message of the day', '/core_styles/icons/motd.png', EnterGame.displayMotd)
62 62
   motdButton:hide()
63 63
   enterGame = displayUI('entergame.otui')
@@ -82,7 +82,7 @@ function EnterGame.init()
82 82
 end
83 83
 
84 84
 function EnterGame.terminate()
85
-  Hotkeys.unbindKeyDown('Ctrl+G')
85
+  Keyboard.unbindKeyDown('Ctrl+G')
86 86
   enterGame:destroy()
87 87
   enterGame = nil
88 88
   enterGameButton:destroy()

+ 2
- 2
modules/client_entergame/entergame.otmod View File

@@ -5,8 +5,8 @@ Module
5 5
   website: https://github.com/edubart/otclient
6 6
 
7 7
   onLoad: |
8
-    require 'entergame'
9
-    require 'characterlist'
8
+    dofile 'entergame'
9
+    dofile 'characterlist'
10 10
     EnterGame.init()
11 11
 
12 12
   onUnload: |

+ 1
- 1
modules/client_modulemanager/modulemanager.otmod View File

@@ -4,7 +4,7 @@ Module
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6 6
   onLoad: |
7
-    require 'modulemanager'
7
+    dofile 'modulemanager'
8 8
     ModuleManager.init()
9 9
 
10 10
   onUnload: |

+ 2
- 2
modules/client_options/options.lua View File

@@ -25,11 +25,11 @@ function Options.init()
25 25
   optionsWindow = displayUI('options.otui')
26 26
   optionsWindow:setVisible(false)
27 27
   optionsButton = TopMenu.addButton('optionsButton', 'Options (Ctrl+O)', 'options.png', Options.toggle)
28
-  Hotkeys.bindKeyDown('Ctrl+O', Options.toggle)
28
+  Keyboard.bindKeyDown('Ctrl+O', Options.toggle)
29 29
 end
30 30
 
31 31
 function Options.terminate()
32
-  Hotkeys.unbindKeyDown('Ctrl+O')
32
+  Keyboard.unbindKeyDown('Ctrl+O')
33 33
   optionsWindow:destroy()
34 34
   optionsWindow = nil
35 35
   optionsButton:destroy()

+ 1
- 1
modules/client_options/options.otmod View File

@@ -5,7 +5,7 @@ Module
5 5
   website: https://github.com/edubart/otclient
6 6
 
7 7
   onLoad: |
8
-    require 'options'
8
+    dofile 'options'
9 9
     Options.init()
10 10
 
11 11
   onUnload: |

+ 3
- 18
modules/client_topmenu/topmenu.lua View File

@@ -23,11 +23,11 @@ function TopMenu.init()
23 23
   gameButtonsPanel = topMenu:getChildById('gameButtonsPanel')
24 24
 
25 25
   TopMenu.addRightButton('logoutButton', 'Logout (Ctrl+Q)', '/core_styles/icons/logout.png', onLogout)
26
-  Hotkeys.bindKeyDown('Ctrl+Q', onLogout)
26
+  Keyboard.bindKeyDown('Ctrl+Q', onLogout)
27 27
 end
28 28
 
29 29
 function TopMenu.terminate()
30
-  Hotkeys.unbindKeyDown('Ctrl+Q')
30
+  Keyboard.unbindKeyDown('Ctrl+Q')
31 31
   leftButtonsPanel = nil
32 32
   rightButtonsPanel = nil
33 33
   gameButtonsPanel = nil
@@ -71,16 +71,6 @@ function TopMenu.addRightButton(id, description, icon, callback)
71 71
   return TopMenu.addButton(id, description, resolvepath(icon, 2), callback, true)
72 72
 end
73 73
 
74
-function TopMenu.removeButton(param)
75
-  local button
76
-  if type(param) == 'string' then
77
-    button = TopMenu.getButton(param)
78
-  else
79
-    button = param
80
-  end
81
-  button:destroy()
82
-end
83
-
84 74
 function TopMenu.hideGameButtons()
85 75
   gameButtonsPanel:hide()
86 76
 end
@@ -93,10 +83,5 @@ function TopMenu.getButton(id)
93 83
   return topMenu:recursiveGetChildById(id)
94 84
 end
95 85
 
96
-function TopMenu:getLogoutButton(id)
97
-  return TopMenu.getButton('logoutButton')
98
-end
99
-
100
-
101 86
 connect(Game, { onLogin = TopMenu.showGameButtons,
102
-                onLogout = TopMenu.hideGameButtons})
87
+                onLogout = TopMenu.hideGameButtons })

+ 1
- 1
modules/client_topmenu/topmenu.otmod View File

@@ -5,7 +5,7 @@ Module
5 5
   website: https://github.com/edubart/otclient
6 6
 
7 7
   onLoad: |
8
-    require 'topmenu'
8
+    dofile 'topmenu'
9 9
     TopMenu.init()
10 10
 
11 11
   onUnload: |

+ 2
- 0
modules/core_fonts/core_fonts.otmod View File

@@ -3,6 +3,8 @@ Module
3 3
   description: Contains fonts used by core
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6
+  canUnload: false
7
+
6 8
   onLoad: |
7 9
     importFont 'verdana-11px-antialised'
8 10
     importFont 'verdana-11px-monochrome'

+ 15
- 15
modules/core_lib/core_lib.otmod View File

@@ -5,21 +5,21 @@ Module
5 5
   website: https://github.com/edubart/otclient
6 6
 
7 7
   onLoad: |
8
-    require 'ext/table'
9
-    require 'ext/string'
10
-    require 'ext/os'
11
-    require 'math/point'
12
-    require 'math/size'
13
-    require 'math/color'
14
-    require 'math/rect'
15
-    require 'const'
16
-    require 'util'
17
-    require 'globals'
18
-    require 'dispatcher'
19
-    require 'effects'
20
-    require 'settings'
21
-    require 'hotkeys'
22
-    require 'cursor'
8
+    dofile 'ext/table'
9
+    dofile 'ext/string'
10
+    dofile 'ext/os'
11
+    dofile 'math/point'
12
+    dofile 'math/size'
13
+    dofile 'math/color'
14
+    dofile 'math/rect'
15
+    dofile 'const'
16
+    dofile 'util'
17
+    dofile 'globals'
18
+    dofile 'dispatcher'
19
+    dofile 'effects'
20
+    dofile 'settings'
21
+    dofile 'keyboard'
22
+    dofile 'mouse'
23 23
 
24 24
   onUnload: |
25 25
     rootWidget = nil

+ 0
- 7
modules/core_lib/cursor.lua View File

@@ -1,7 +0,0 @@
1
-function setTargetCursor()
2
-  g_window.setMouseCursor('/core_styles/icons/targetcursor.png', {x=9,y=9})
3
-end
4
-
5
-function restoreCursor()
6
-  g_window.restoreMouseCursor()
7
-end

+ 134
- 0
modules/core_lib/keyboard.lua View File

@@ -0,0 +1,134 @@
1
+Keyboard = {}
2
+
3
+-- private functions
4
+local function translateKeyCombo(keyCombo)
5
+  if not keyCombo or #keyCombo == 0 then return nil end
6
+  table.sort(keyCombo)
7
+  local keyComboDesc = ''
8
+  for k,v in pairs(keyCombo) do
9
+    local keyDesc = KeyCodeDescs[v]
10
+    if keyDesc == nil then return nil end
11
+    keyComboDesc = keyComboDesc .. '+' .. keyDesc
12
+  end
13
+  keyComboDesc = keyComboDesc:sub(2)
14
+  return keyComboDesc
15
+end
16
+
17
+local function retranslateKeyComboDesc(keyComboDesc)
18
+  if keyComboDesc == nil then return nil end
19
+  local keyCombo = {}
20
+  for i,currentKeyDesc in ipairs(keyComboDesc:split('+')) do
21
+    for keyCode, keyDesc in pairs(KeyCodeDescs) do
22
+      if keyDesc:lower() == currentKeyDesc:trim():lower() then
23
+        table.insert(keyCombo, keyCode)
24
+      end
25
+    end
26
+  end
27
+  return translateKeyCombo(keyCombo)
28
+end
29
+
30
+local function determineKeyComboDesc(keyCode, keyboardModifiers)
31
+  local keyCombo = {}
32
+  if keyCode == KeyCtrl or keyCode == KeyShift or keyCode == KeyAlt then
33
+    table.insert(keyCombo, keyCode)
34
+  elseif KeyCodeDescs[keyCode] ~= nil then
35
+    if keyboardModifiers == KeyboardCtrlModifier then
36
+      table.insert(keyCombo, KeyCtrl)
37
+    elseif keyboardModifiers == KeyboardAltModifier then
38
+      table.insert(keyCombo, KeyAlt)
39
+    elseif keyboardModifiers == KeyboardCtrlAltModifier then
40
+      table.insert(keyCombo, KeyCtrl)
41
+      table.insert(keyCombo, KeyAlt)
42
+    elseif keyboardModifiers == KeyboardShiftModifier then
43
+      table.insert(keyCombo, KeyShift)
44
+    elseif keyboardModifiers == KeyboardCtrlShiftModifier then
45
+      table.insert(keyCombo, KeyCtrl)
46
+      table.insert(keyCombo, KeyShift)
47
+    elseif keyboardModifiers == KeyboardAltShiftModifier then
48
+      table.insert(keyCombo, KeyAlt)
49
+      table.insert(keyCombo, KeyShift)
50
+    elseif keyboardModifiers == KeyboardCtrlAltShiftModifier then
51
+      table.insert(keyCombo, KeyCtrl)
52
+      table.insert(keyCombo, KeyAlt)
53
+      table.insert(keyCombo, KeyShift)
54
+    end
55
+    table.insert(keyCombo, keyCode)
56
+  end
57
+  table.sort(keyCombo)
58
+  return translateKeyCombo(keyCombo)
59
+end
60
+
61
+local function onWidgetKeyDown(widget, keyCode, keyboardModifiers)
62
+  if keyCode == KeyUnknown then return end
63
+  local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
64
+  local callback = widget.boundKeyDownCombos[keyComboDesc]
65
+  if callback then
66
+    callback()
67
+    return true
68
+  end
69
+  return false
70
+end
71
+
72
+local function onWidgetKeyPress(widget, keyCode, keyboardModifiers, wouldFilter)
73
+  local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
74
+  if keyCode == KeyUnknown then return end
75
+  local callback = widget.boundKeyPressCombos[keyComboDesc]
76
+  if callback then
77
+    callback()
78
+    return true
79
+  end
80
+  return false
81
+end
82
+
83
+local function connectKeyDownEvent(widget)
84
+  if widget.boundKeyDownCombos then return end
85
+  connect(widget, { onKeyDown = onWidgetKeyDown })
86
+  widget.boundKeyDownCombos = {}
87
+end
88
+
89
+local function connectKeyPressEvent(widget)
90
+  if widget.boundKeyPressCombos then return end
91
+  connect(widget, { onKeyPress = onWidgetKeyPress })
92
+  widget.boundKeyPressCombos = {}
93
+end
94
+
95
+-- public functions
96
+function Keyboard.bindKeyDown(keyComboDesc, callback, widget)
97
+  widget = widget or rootWidget
98
+  connectKeyDownEvent(widget)
99
+  local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
100
+  if keyComboDesc then
101
+    widget.boundKeyDownCombos[keyComboDesc] = callback
102
+  else
103
+    error('key combo \'' .. keyComboDesc .. '\' is failed')
104
+  end
105
+end
106
+
107
+function Keyboard.bindKeyPress(keyComboDesc, callback, widget)
108
+  widget = widget or rootWidget
109
+  connectKeyPressEvent(widget)
110
+  local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
111
+  if keyComboDesc then
112
+    widget.boundKeyPressCombos[keyComboDesc] = callback
113
+  else
114
+    error('key combo \'' .. keyComboDesc .. '\' is failed')
115
+  end
116
+end
117
+
118
+function Keyboard.unbindKeyDown(keyComboDesc, widget)
119
+  widget = widget or rootWidget
120
+  if widget.boundKeyDownCombos == nil then return end
121
+  local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
122
+  if keyComboDesc then
123
+    widget.boundKeyDownCombos[keyComboDesc] = nil
124
+  end
125
+end
126
+
127
+function Keyboard.unbindKeyPress(keyComboDesc, widget)
128
+  widget = widget or rootWidget
129
+  if widget.boundKeyPressCombos == nil then return end
130
+  local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
131
+  if keyComboDesc then
132
+    widget.boundKeyPressCombos[keyComboDesc] = nil
133
+  end
134
+end

+ 7
- 0
modules/core_lib/mouse.lua View File

@@ -1,2 +1,9 @@
1 1
 Mouse = {}
2 2
 
3
+function Mouse.setTargetCursor()
4
+  g_window.setMouseCursor('/core_styles/icons/targetcursor.png', {x=9,y=9})
5
+end
6
+
7
+function Mouse.restoreCursor()
8
+  g_window.restoreMouseCursor()
9
+end

+ 0
- 4
modules/core_lib/util.lua View File

@@ -114,7 +114,3 @@ function signalcall(param, ...)
114 114
   end
115 115
   return false
116 116
 end
117
-
118
-function runscript(file)
119
-  g_lua.runScript(resolvepath(file, 2))
120
-end

+ 13
- 13
modules/core_widgets/core_widgets.otmod View File

@@ -5,17 +5,17 @@ Module
5 5
   website: https://github.com/edubart/otclient
6 6
 
7 7
   onLoad: |
8
-    require 'uiwidget'
9
-    require 'uibutton'
10
-    require 'uilabel'
11
-    require 'uicheckbox'
12
-    require 'uicombobox'
13
-    require 'uispinbox'
14
-    require 'uiprogressbar'
15
-    require 'uitabbar'
16
-    require 'uipopupmenu'
17
-    require 'uiwindow'
18
-    require 'uiitem'
19
-    require 'tooltip/tooltip'
20
-    require 'messagebox/messagebox'
8
+    dofile 'uiwidget'
9
+    dofile 'uibutton'
10
+    dofile 'uilabel'
11
+    dofile 'uicheckbox'
12
+    dofile 'uicombobox'
13
+    dofile 'uispinbox'
14
+    dofile 'uiprogressbar'
15
+    dofile 'uitabbar'
16
+    dofile 'uipopupmenu'
17
+    dofile 'uiwindow'
18
+    dofile 'uiitem'
19
+    dofile 'tooltip/tooltip'
20
+    dofile 'messagebox/messagebox'
21 21
     

+ 2
- 2
modules/core_widgets/uiitem.lua View File

@@ -8,7 +8,7 @@ function UIItem:onDragEnter(mousePos)
8 8
 
9 9
   self.parsed = false
10 10
   self.currentDragThing = item
11
-  setTargetCursor()
11
+  Mouse.setTargetCursor()
12 12
   return true
13 13
 end
14 14
 
@@ -19,7 +19,7 @@ function UIItem:onDragLeave(widget, mousePos)
19 19
     self.currentDragThing = nil
20 20
   end
21 21
 
22
-  restoreCursor()
22
+  Mouse.restoreCursor()
23 23
   self:setBorderWidth(0)
24 24
   return true
25 25
 end

+ 2
- 2
modules/core_widgets/uimessagebox.lua View File

@@ -1,3 +1,4 @@
1
+--[[
1 2
 UIMessageBox = extends(UIWindow)
2 3
 
3 4
 function UIMessageBox.create(title, message)
@@ -19,5 +20,4 @@ end
19 20
 
20 21
 function UIMessageBox:setMessage(message)
21 22
 end
22
-
23
-function
23
+]]--

+ 10
- 10
modules/game/game.lua View File

@@ -32,7 +32,7 @@ local function onUseWithMouseRelease(self, mousePosition, mouseButton)
32 32
     end
33 33
   end
34 34
   Game.selectedThing = nil
35
-  restoreCursor()
35
+  Mouse.restoreCursor()
36 36
   self:ungrabMouse()
37 37
   return true
38 38
 end
@@ -41,7 +41,7 @@ end
41 41
 function Game.startUseWith(thing)
42 42
   Game.selectedThing = thing
43 43
   m_mouseGrabberWidget:grabMouse()
44
-  setTargetCursor()
44
+  Mouse.setTargetCursor()
45 45
 end
46 46
 
47 47
 function Game.createInterface()
@@ -49,15 +49,15 @@ function Game.createInterface()
49 49
   CharacterList.destroyLoadBox()
50 50
   Game.gameUi = displayUI('game.otui')
51 51
 
52
-  --Hotkeys.bindKeyPress('Up', function() Game.walk(North) end)
53
-  --Hotkeys.bindKeyPress('Down', function() Game.walk(South) end)
54
-  --Hotkeys.bindKeyPress('Left', function() Game.walk(West) end)
55
-  --Hotkeys.bindKeyPress('Right', function() Game.walk(East) end)
52
+  --Keyboard.bindKeyPress('Up', function() Game.walk(North) end)
53
+  --Keyboard.bindKeyPress('Down', function() Game.walk(South) end)
54
+  --Keyboard.bindKeyPress('Left', function() Game.walk(West) end)
55
+  --Keyboard.bindKeyPress('Right', function() Game.walk(East) end)
56 56
 
57
-  Hotkeys.bindKeyPress('Ctrl+Shift+Up', function() Game.forceWalk(North) end)
58
-  Hotkeys.bindKeyPress('Ctrl+Shift+Down', function() Game.forceWalk(South) end)
59
-  Hotkeys.bindKeyPress('Ctrl+Shift+Left', function() Game.forceWalk(West) end)
60
-  Hotkeys.bindKeyPress('Ctrl+Shift+Right', function() Game.forceWalk(East) end)
57
+  Keyboard.bindKeyPress('Ctrl+Shift+Up', function() Game.forceWalk(North) end)
58
+  Keyboard.bindKeyPress('Ctrl+Shift+Down', function() Game.forceWalk(South) end)
59
+  Keyboard.bindKeyPress('Ctrl+Shift+Left', function() Game.forceWalk(West) end)
60
+  Keyboard.bindKeyPress('Ctrl+Shift+Right', function() Game.forceWalk(East) end)
61 61
 
62 62
   rootWidget:moveChildToIndex(Game.gameUi, 1)
63 63
   Game.gameMapPanel = Game.gameUi:getChildById('gameMapPanel')

+ 5
- 5
modules/game/game.otmod View File

@@ -15,8 +15,8 @@ Module
15 15
     - game_containers
16 16
 
17 17
   onLoad: |
18
-    require 'game'
19
-    require 'thing'
20
-    require 'creature'
21
-    require 'player'
22
-    require 'map'
18
+    dofile 'game'
19
+    dofile 'thing'
20
+    dofile 'creature'
21
+    dofile 'player'
22
+    dofile 'map'

+ 2
- 2
modules/game/map.lua View File

@@ -7,7 +7,7 @@ function UIMap:onDragEnter(mousePos)
7 7
 
8 8
   self.parsed = false
9 9
   self.currentDragThing = thing
10
-  setTargetCursor()
10
+  Mouse.setTargetCursor()
11 11
   return true
12 12
 end
13 13
 
@@ -16,7 +16,7 @@ function UIMap:onDragLeave(widget, mousePos)
16 16
     self.currentDragThing = nil
17 17
   end
18 18
 
19
-  restoreCursor()
19
+  Mouse.restoreCursor()
20 20
   return true
21 21
 end
22 22
 

+ 1
- 1
modules/game_combatcontrols/combatcontrols.otmod View File

@@ -4,4 +4,4 @@ Module
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6 6
   onLoad: |
7
-    require 'combatcontrols'
7
+    dofile 'combatcontrols'

+ 7
- 7
modules/game_console/console.lua View File

@@ -88,11 +88,11 @@ function Console.create()
88 88
   Console.addChannel('Default', 0)
89 89
   Console.addTab('Server Log', false)
90 90
 
91
-  Hotkeys.bindKeyDown('Shift+Up', function() navigateMessageHistory(1) end, consolePanel)
92
-  Hotkeys.bindKeyDown('Shift+Down', function() navigateMessageHistory(-1) end, consolePanel)
93
-  Hotkeys.bindKeyDown('Tab', function() consoleTabBar:selectNextTab() end, consolePanel)
94
-  Hotkeys.bindKeyDown('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel)
95
-  Hotkeys.bindKeyDown('Enter', Console.sendCurrentMessage, consolePanel)
91
+  Keyboard.bindKeyDown('Shift+Up', function() navigateMessageHistory(1) end, consolePanel)
92
+  Keyboard.bindKeyDown('Shift+Down', function() navigateMessageHistory(-1) end, consolePanel)
93
+  Keyboard.bindKeyDown('Tab', function() consoleTabBar:selectNextTab() end, consolePanel)
94
+  Keyboard.bindKeyDown('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel)
95
+  Keyboard.bindKeyDown('Enter', Console.sendCurrentMessage, consolePanel)
96 96
 
97 97
   -- apply buttom functions after loaded
98 98
   connect(consolePanel:getChildById('nextChannelButton'), { onClick = function() consoleTabBar:selectNextTab() end } )
@@ -100,8 +100,8 @@ function Console.create()
100 100
   connect(consoleTabBar, { onTabChange = Console.onTabChange })
101 101
 
102 102
   -- tibia like hotkeys
103
-  Hotkeys.bindKeyDown('Ctrl+O', Game.requestChannels)
104
-  Hotkeys.bindKeyDown('Ctrl+E', Console.removeCurrentTab)
103
+  Keyboard.bindKeyDown('Ctrl+O', Game.requestChannels)
104
+  Keyboard.bindKeyDown('Ctrl+E', Console.removeCurrentTab)
105 105
 end
106 106
 
107 107
 function Console.destroy()

+ 1
- 1
modules/game_console/console.otmod View File

@@ -4,4 +4,4 @@ Module
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6 6
   onLoad: |
7
-    require 'console'
7
+    dofile 'console'

+ 1
- 1
modules/game_containers/containers.otmod View File

@@ -4,4 +4,4 @@ Module
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6 6
   onLoad: |
7
-    require 'containers'
7
+    dofile 'containers'

+ 1
- 1
modules/game_healthbar/healthbar.otmod View File

@@ -4,4 +4,4 @@ Module
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6 6
   onLoad: |
7
-    require 'healthbar'
7
+    dofile 'healthbar'

+ 2
- 2
modules/game_inventory/inventory.lua View File

@@ -9,11 +9,11 @@ function Inventory.create()
9 9
   inventoryWindow = displayUI('inventory.otui', { parent = Game.gameRightPanel })
10 10
   inventoryButton = TopMenu.addGameButton('inventoryButton', 'Inventory (Ctrl+I)', 'inventory.png', Inventory.toggle)
11 11
   inventoryButton:setOn(true)
12
-  Hotkeys.bindKeyDown('Ctrl+I', Inventory.toggle)
12
+  Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
13 13
 end
14 14
 
15 15
 function Inventory.destroy()
16
-  Hotkeys.unbindKeyDown('Ctrl+I')
16
+  Keyboard.unbindKeyDown('Ctrl+I')
17 17
   inventoryWindow:destroy()
18 18
   inventoryWindow = nil
19 19
   inventoryButton:destroy()

+ 1
- 1
modules/game_inventory/inventory.otmod View File

@@ -4,4 +4,4 @@ Module
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6 6
   onLoad: |
7
-    require 'inventory'
7
+    dofile 'inventory'

+ 1
- 1
modules/game_outfit/outfit.otmod View File

@@ -4,4 +4,4 @@ Module
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6 6
   onLoad: |
7
-    require 'outfit'
7
+    dofile 'outfit'

+ 2
- 2
modules/game_skills/skills.lua View File

@@ -45,11 +45,11 @@ function Skills.create()
45 45
   skillsWindow = displayUI('skills.otui', { parent = Game.gameRightPanel })
46 46
   skillsWindow:hide()
47 47
   skillsButton = TopMenu.addGameButton('skillsButton', 'Skills (Ctrl+S)', '/core_styles/icons/skills.png', Skills.toggle)
48
-  Hotkeys.bindKeyDown('Ctrl+S', Skills.toggle)
48
+  Keyboard.bindKeyDown('Ctrl+S', Skills.toggle)
49 49
 end
50 50
 
51 51
 function Skills.destroy()
52
-  Hotkeys.unbindKeyDown('Ctrl+S')
52
+  Keyboard.unbindKeyDown('Ctrl+S')
53 53
   skillsButton:destroy()
54 54
   skillsButton = nil
55 55
   skillsWindow:destroy()

+ 1
- 1
modules/game_skills/skills.otmod View File

@@ -4,4 +4,4 @@ Module
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6 6
   onLoad: |
7
-    require 'skills'
7
+    dofile 'skills'

+ 1
- 1
modules/game_textmessage/textmessage.otmod View File

@@ -4,4 +4,4 @@ Module
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6 6
   onLoad: |
7
-    require 'textmessage'
7
+    dofile 'textmessage'

+ 1
- 1
modules/game_viplist/viplist.otmod View File

@@ -4,4 +4,4 @@ Module
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6 6
   onLoad: |
7
-    require 'viplist'
7
+    dofile 'viplist'

+ 8
- 8
modules/otclientrc.lua View File

@@ -1,18 +1,18 @@
1 1
 -- this file use loaded after everything is loaded and initialized
2 2
 -- you can place any custom user code here
3 3
 
4
-Hotkeys.bindKeyDown('F1', function() Game.talk('exura gran') end)
5
-Hotkeys.bindKeyDown('F2', function() Game.talk('exori mort') end)
6
-Hotkeys.bindKeyDown('F3', function() Game.talk('exori frigo') end)
7
-Hotkeys.bindKeyDown('F4', function() Game.talk('exevo vis hur') end)
8
-Hotkeys.bindKeyDown('F5', function() Game.talk('utani gran hur') end)
9
-Hotkeys.bindKeyDown('F6', function() Game.talk('exani tera') end)
4
+Keyboard.bindKeyDown('F1', function() Game.talk('exura gran') end)
5
+Keyboard.bindKeyDown('F2', function() Game.talk('exori mort') end)
6
+Keyboard.bindKeyDown('F3', function() Game.talk('exori frigo') end)
7
+Keyboard.bindKeyDown('F4', function() Game.talk('exevo vis hur') end)
8
+Keyboard.bindKeyDown('F5', function() Game.talk('utani gran hur') end)
9
+Keyboard.bindKeyDown('F6', function() Game.talk('exani tera') end)
10 10
 
11 11
 local function reload()
12
-  runscript('otclientrc.lua')
12
+  dofile('otclientrc.lua')
13 13
   TextMessage.displayEventAdvance('Script otclientrc.lua reloaded.')
14 14
   print('Script otclient.rc lua reloaded')
15 15
 end
16
-Hotkeys.bindKeyDown('Ctrl+R', reload)
16
+Keyboard.bindKeyDown('Ctrl+R', reload)
17 17
 
18 18
 rcloaded = true

+ 20
- 0
src/framework/luascript/luainterface.cpp View File

@@ -512,6 +512,22 @@ int LuaInterface::luaScriptLoader(lua_State* L)
512 512
     }
513 513
 }
514 514
 
515
+int LuaInterface::luaScriptRunner(lua_State* L)
516
+{
517
+    std::string fileName = g_lua.popString();
518
+    if(!boost::ends_with(fileName, ".lua"))
519
+        fileName += ".lua";
520
+
521
+    try {
522
+        g_lua.loadScript(fileName);
523
+        g_lua.call(0, LUA_MULTRET);
524
+        return g_lua.stackSize();
525
+    } catch(LuaException& e) {
526
+        logError("failed to load script file '", fileName, "' :'", e.what());
527
+        return 0;
528
+    }
529
+}
530
+
515 531
 int LuaInterface::luaErrorHandler(lua_State* L)
516 532
 {
517 533
     // pops the error message
@@ -583,6 +599,10 @@ void LuaInterface::createLuaState()
583 599
     pushCFunction(&LuaInterface::luaScriptLoader);
584 600
     rawSeti(5);
585 601
     pop(2);
602
+
603
+    // replace dofile
604
+    pushCFunction(&LuaInterface::luaScriptRunner);
605
+    setGlobal("dofile");
586 606
 }
587 607
 
588 608
 void LuaInterface::closeLuaState()

+ 2
- 0
src/framework/luascript/luainterface.h View File

@@ -186,6 +186,8 @@ public:
186 186
 private:
187 187
     /// Load scripts requested by lua 'require'
188 188
     static int luaScriptLoader(lua_State* L);
189
+    /// Run scripts requested by lua 'dofile'
190
+    static int luaScriptRunner(lua_State* L);
189 191
     /// Handle lua errors from safeCall
190 192
     static int luaErrorHandler(lua_State* L);
191 193
     /// Handle bound cpp functions callbacks

Loading…
Cancel
Save