Browse Source

BEAWARE all game functionality is disabled with this commit for a while

* rework client modules
* hide main window when loading
* remake top menu functions
* rework modules autoload
* improve path resolving for otml and lua
* move core_widgets to core_lib
* fix tooltip issues
* split some styles
* add bit32 lua library
* fix assert issues
* fix compilation on linux 32 systems
* rework gcc compile options
* renable and fix some warnings
* remove unused constants
* speedup sprite cache
* move UIGame to lua (not funcional yet)
* fix a lot of issues in x11 window
* fix crash handler
* add some warnings do uiwidget
and much more...
Eduardo Bart 9 years ago
parent
commit
e03bf33f58
100 changed files with 404 additions and 463 deletions
  1. 7
    1
      modules/client/client.lua
  2. 23
    0
      modules/client/client.otmod
  3. 0
    0
      modules/client/clienticon.png
  4. 16
    5
      modules/client_about/about.lua
  5. 3
    5
      modules/client_about/about.otmod
  6. 4
    1
      modules/client_about/about.otui
  7. 7
    0
      modules/client_background/background.lua
  8. 6
    4
      modules/client_background/background.otmod
  9. 22
    0
      modules/client_entergame/characterlist.lua
  10. 5
    4
      modules/client_entergame/entergame.lua
  11. 7
    4
      modules/client_entergame/entergame.otmod
  12. 4
    4
      modules/client_entergame/entergame.otui
  13. 0
    0
      modules/client_entergame/login.png
  14. 0
    0
      modules/client_entergame/motd.png
  15. 0
    14
      modules/client_main/client.otmod
  16. 6
    5
      modules/client_modulemanager/modulemanager.lua
  17. 4
    3
      modules/client_modulemanager/modulemanager.otmod
  18. 13
    5
      modules/client_modulemanager/modulemanager.otui
  19. 31
    26
      modules/client_options/options.lua
  20. 3
    4
      modules/client_options/options.otmod
  21. 3
    3
      modules/client_options/options.otui
  22. 0
    4
      modules/client_terminal/commands.lua
  23. 12
    11
      modules/client_terminal/terminal.lua
  24. 3
    4
      modules/client_terminal/terminal.otmod
  25. 0
    14
      modules/client_tibiafiles/tibiafiles.otmod
  26. 0
    0
      modules/client_topmenu/images/top_button.png
  27. 0
    0
      modules/client_topmenu/images/top_game_button.png
  28. 0
    0
      modules/client_topmenu/images/top_panel.png
  29. 36
    37
      modules/client_topmenu/topmenu.lua
  30. 3
    4
      modules/client_topmenu/topmenu.otmod
  31. 22
    27
      modules/client_topmenu/topmenu.otui
  32. 0
    15
      modules/core_fonts/core_fonts.otmod
  33. 21
    4
      modules/core_lib/core_lib.otmod
  34. 0
    20
      modules/core_lib/dispatcher.lua
  35. 28
    50
      modules/core_lib/globals.lua
  36. 1
    0
      modules/core_lib/mouse.lua
  37. 0
    1
      modules/core_lib/settings.lua
  38. 0
    0
      modules/core_lib/ui/effects.lua
  39. 0
    0
      modules/core_lib/ui/radiogroup.lua
  40. 12
    5
      modules/core_lib/ui/tooltip.lua
  41. 4
    9
      modules/core_lib/util.lua
  42. 0
    0
      modules/core_lib/widgets/uibutton.lua
  43. 0
    0
      modules/core_lib/widgets/uicheckbox.lua
  44. 0
    0
      modules/core_lib/widgets/uicombobox.lua
  45. 0
    0
      modules/core_lib/widgets/uilabel.lua
  46. 0
    0
      modules/core_lib/widgets/uimessagebox.lua
  47. 2
    1
      modules/core_lib/widgets/uipopupmenu.lua
  48. 0
    0
      modules/core_lib/widgets/uiprogressbar.lua
  49. 0
    0
      modules/core_lib/widgets/uispinbox.lua
  50. 0
    0
      modules/core_lib/widgets/uitabbar.lua
  51. 0
    0
      modules/core_lib/widgets/uiwidget.lua
  52. 3
    4
      modules/core_lib/widgets/uiwindow.lua
  53. 8
    3
      modules/core_styles/core_styles.otmod
  54. 0
    0
      modules/core_styles/cursors/targetcursor.png
  55. 0
    0
      modules/core_styles/fonts/terminus-14px-bold.otfont
  56. 0
    0
      modules/core_styles/fonts/terminus-14px-bold.png
  57. 0
    0
      modules/core_styles/fonts/verdana-11px-antialised.otfont
  58. 0
    0
      modules/core_styles/fonts/verdana-11px-antialised.png
  59. 0
    0
      modules/core_styles/fonts/verdana-11px-monochrome.otfont
  60. 0
    0
      modules/core_styles/fonts/verdana-11px-monochrome.png
  61. 0
    0
      modules/core_styles/fonts/verdana-11px-rounded.otfont
  62. 0
    0
      modules/core_styles/fonts/verdana-11px-rounded.png
  63. 4
    4
      modules/core_styles/styles/buttons.otui
  64. 5
    5
      modules/core_styles/styles/checkboxes.otui
  65. 3
    3
      modules/core_styles/styles/comboboxes.otui
  66. 1
    4
      modules/core_styles/styles/creatures.otui
  67. 0
    0
      modules/core_styles/styles/images/button.png
  68. 0
    0
      modules/core_styles/styles/images/button_down.png
  69. 0
    0
      modules/core_styles/styles/images/button_hover.png
  70. 0
    0
      modules/core_styles/styles/images/checkbox.png
  71. 0
    0
      modules/core_styles/styles/images/colorbox.png
  72. 0
    0
      modules/core_styles/styles/images/combobox.png
  73. 0
    0
      modules/core_styles/styles/images/container_bg.png
  74. 0
    0
      modules/core_styles/styles/images/horizontal_separator.png
  75. 0
    0
      modules/core_styles/styles/images/horizotal_separator.png
  76. 0
    0
      modules/core_styles/styles/images/item.png
  77. 0
    0
      modules/core_styles/styles/images/menu.png
  78. 0
    0
      modules/core_styles/styles/images/menubox.png
  79. 0
    0
      modules/core_styles/styles/images/panel_flat.png
  80. 0
    0
      modules/core_styles/styles/images/progressbar.png
  81. 0
    0
      modules/core_styles/styles/images/tabbutton.png
  82. 0
    0
      modules/core_styles/styles/images/window.png
  83. 1
    1
      modules/core_styles/styles/items.otui
  84. 0
    2
      modules/core_styles/styles/labels.otui
  85. 1
    1
      modules/core_styles/styles/lineedits.otui
  86. 1
    1
      modules/core_styles/styles/listboxes.otui
  87. 1
    19
      modules/core_styles/styles/panels.otui
  88. 2
    2
      modules/core_styles/styles/popupmenus.otui
  89. 1
    1
      modules/core_styles/styles/progressbars.otui
  90. 1
    1
      modules/core_styles/styles/separators.otui
  91. 1
    1
      modules/core_styles/styles/spinboxes.otui
  92. 1
    1
      modules/core_styles/styles/tabbars.otui
  93. 2
    2
      modules/core_styles/styles/windows.otui
  94. 0
    33
      modules/core_widgets/core_widgets.otmod
  95. 0
    24
      modules/game/game.lua
  96. 3
    11
      modules/game/game.otmod
  97. 11
    0
      modules/game_tibiafiles/tibiafiles.otmod
  98. 46
    46
      modules/old/game_battle/battle.lua
  99. 0
    0
      modules/old/game_battle/battle.otmod
  100. 0
    0
      modules/old/game_battle/battle.otui

modules/client_main/client.lua → modules/client/client.lua View File

@@ -1,7 +1,6 @@
1 1
 Client = {}
2 2
 
3 3
 function Client.init()
4
-  g_window.show()
5 4
   g_window.setMinimumSize({ width = 600, height = 480 })
6 5
 
7 6
   -- initialize in fullscreen mode on mobile devices
@@ -27,6 +26,13 @@ function Client.init()
27 26
 
28 27
   g_window.setTitle('OTClient')
29 28
   g_window.setIcon(resolvepath('clienticon.png'))
29
+
30
+  -- show the only window after the first frame is rendered
31
+  addEvent(function()
32
+    addEvent(function()
33
+        g_window.show()
34
+    end)
35
+  end)
30 36
 end
31 37
 
32 38
 function Client.terminate()

+ 23
- 0
modules/client/client.otmod View File

@@ -0,0 +1,23 @@
1
+Module
2
+  name: client
3
+  description: Initialize the client and setups its main window
4
+  author: OTClient team
5
+  website: https://github.com/edubart/otclient
6
+  autoload: true
7
+  autoload-priority: 100
8
+
9
+  load-later:
10
+    - client_topmenu
11
+    - client_background
12
+    - client_about
13
+    - client_options
14
+    - client_terminal
15
+    - client_modulemanager
16
+    - client_entergame
17
+
18
+  @onLoad: |
19
+    dofile 'client'
20
+    Client.init()
21
+
22
+  @onUnload: |
23
+    Client.terminate()

modules/client_main/clienticon.png → modules/client/clienticon.png View File


+ 16
- 5
modules/client_about/about.lua View File

@@ -2,22 +2,33 @@ About = {}
2 2
 
3 3
 -- private variables
4 4
 local aboutButton
5
+local aboutWindow
5 6
 
6 7
 -- public functions
7 8
 function About.init()
8
-  aboutButton = TopMenu.addRightButton('aboutButton', 'About', 'about.png', About.display)
9
-end
10
-
11
-function About.display()
12
-  displayUI('about.otui', { locked = true })
9
+  aboutButton = TopMenu.addRightButton('aboutButton', 'About', 'about.png', About.show)
10
+  aboutWindow = displayUI('about.otui')
11
+  aboutWindow:hide()
13 12
 end
14 13
 
15 14
 function About.terminate()
16 15
   aboutButton:destroy()
17 16
   aboutButton = nil
17
+  aboutWindow:destroy()
18
+  aboutWindow = nil
18 19
   About = nil
19 20
 end
20 21
 
22
+function About.show()
23
+  aboutWindow:show()
24
+  aboutWindow:raise()
25
+  aboutWindow:focus()
26
+end
27
+
28
+function About.hide()
29
+  aboutWindow:hide()
30
+end
31
+
21 32
 function About.openWebpage()
22 33
   displayErrorBox("Error", "Not implemented yet")
23 34
 end

+ 3
- 5
modules/client_about/about.otmod View File

@@ -3,16 +3,14 @@ Module
3 3
   description: Create the about window
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6
-  autoload: true
7
-  autoload-antecedence: 160
8
-  unloadable: true
6
+  reloadable: true
9 7
 
10 8
   dependencies:
11 9
     - client_topmenu
12 10
 
13
-  onLoad: |
11
+  @onLoad: |
14 12
     dofile 'about'
15 13
     About.init()
16 14
 
17
-  onUnload: |
15
+  @onUnload: |
18 16
     About.terminate()

+ 4
- 1
modules/client_about/about.otui View File

@@ -3,6 +3,9 @@ MainWindow
3 3
   text: Info
4 4
   size: 244 221
5 5
 
6
+  @onEnter: About.hide()
7
+  @onEscape: About.hide()
8
+
6 9
   FlatPanel
7 10
     size: 208 129
8 11
     anchors.left: parent.left
@@ -52,4 +55,4 @@ MainWindow
52 55
     size: 46 24
53 56
     anchors.right: parent.right
54 57
     anchors.bottom: parent.bottom
55
-    @onClick: self:getParent():destroy()
58
+    @onClick: About.hide()

+ 7
- 0
modules/client_background/background.lua View File

@@ -7,11 +7,18 @@ local background
7 7
 function Background.init()
8 8
   background = displayUI('background.otui')
9 9
   background:lower()
10
+
11
+  connect(g_game, { onGameStart = Background.hide })
12
+  connect(g_game, { onGameEnd = Background.show })
10 13
 end
11 14
 
12 15
 function Background.terminate()
16
+  disconnect(g_game, { onGameStart = Background.hide })
17
+  disconnect(g_game, { onGameEnd = Background.show })
18
+
13 19
   background:destroy()
14 20
   background = nil
21
+
15 22
   Background = nil
16 23
 end
17 24
 

+ 6
- 4
modules/client_background/background.otmod View File

@@ -3,12 +3,14 @@ Module
3 3
   description: Handles the background of the login screen
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6
-  autoload: true
7
-  autoload-antecedence: 110
6
+  reloadable: true
8 7
 
9
-  onLoad: |
8
+  dependencies:
9
+    - client_topmenu
10
+
11
+  @onLoad: |
10 12
     dofile 'background'
11 13
     Background.init()
12 14
 
13
-  onUnload: |
15
+  @onUnload: |
14 16
     Background.terminate()

+ 22
- 0
modules/client_entergame/characterlist.lua View File

@@ -52,7 +52,27 @@ local function tryLogin(charInfo, tries)
52 52
   Settings.set('lastUsedCharacter', charInfo.characterName)
53 53
 end
54 54
 
55
+
56
+function onGameLoginError(message)
57
+  CharacterList.destroyLoadBox()
58
+  local errorBox = displayErrorBox("Login Error", "Login error: " .. message)
59
+  errorBox.onOk = CharacterList.show
60
+end
61
+
62
+function onGameConnectionError(message)
63
+  CharacterList.destroyLoadBox()
64
+  local errorBox = displayErrorBox("Login Error", "Connection error: " .. message)
65
+  errorBox.onOk = CharacterList.show
66
+end
67
+
55 68
 -- public functions
69
+function CharacterList.init()
70
+  connect(g_game, { onLoginError = onGameLoginError })
71
+  connect(g_game, { onConnectionError = onGameConnectionError })
72
+  connect(g_game, { onGameStart = CharacterList.destroyLoadBox })
73
+  connect(g_game, { onGameEnd = CharacterList.show })
74
+end
75
+
56 76
 function CharacterList.terminate()
57 77
   characterList = nil
58 78
   if charactersWindow then
@@ -60,6 +80,7 @@ function CharacterList.terminate()
60 80
     charactersWindow = nil
61 81
   end
62 82
   if loadBox then
83
+    g_game.cancelLogin()
63 84
     loadBox:destroy()
64 85
     loadBox = nil
65 86
   end
@@ -118,6 +139,7 @@ end
118 139
 function CharacterList.show()
119 140
   if not loadBox then
120 141
     charactersWindow:show()
142
+    charactersWindow:raise()
121 143
     charactersWindow:focus()
122 144
   end
123 145
 end

+ 5
- 4
modules/client_entergame/entergame.lua View File

@@ -59,11 +59,11 @@ end
59 59
 
60 60
 -- public functions
61 61
 function EnterGame.init()
62
-  enterGameButton = TopMenu.addButton('enterGameButton', 'Login (Ctrl + G)', '/core_styles/icons/login.png', EnterGame.openWindow)
63
-  Keyboard.bindKeyDown('Ctrl+G', EnterGame.openWindow)
64
-  motdButton = TopMenu.addButton('motdButton', 'Message of the day', '/core_styles/icons/motd.png', EnterGame.displayMotd)
65
-  motdButton:hide()
66 62
   enterGame = displayUI('entergame.otui')
63
+  enterGameButton = TopMenu.addLeftButton('enterGameButton', 'Login (Ctrl + G)', 'login.png', EnterGame.openWindow)
64
+  motdButton = TopMenu.addLeftButton('motdButton', 'Message of the day', 'motd.png', EnterGame.displayMotd)
65
+  motdButton:hide()
66
+  Keyboard.bindKeyDown('Ctrl+G', EnterGame.openWindow)
67 67
 
68 68
   local account = Settings.get('account')
69 69
   local password = Settings.get('password')
@@ -102,6 +102,7 @@ end
102 102
 
103 103
 function EnterGame.show()
104 104
   enterGame:show()
105
+  enterGame:raise()
105 106
   enterGame:focus()
106 107
 end
107 108
 

+ 7
- 4
modules/client_entergame/entergame.otmod View File

@@ -3,14 +3,17 @@ Module
3 3
   description: Manages enter game and character list windows
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6
-  autoload: true
7
-  autoload-antecedence: 150
6
+  reloadable: true
8 7
 
9
-  onLoad: |
8
+  dependencies:
9
+    - client_topmenu
10
+
11
+  @onLoad: |
10 12
     dofile 'entergame'
11 13
     dofile 'characterlist'
12 14
     EnterGame.init()
15
+    CharacterList.init()
13 16
 
14
-  onUnload: |
17
+  @onUnload: |
15 18
     EnterGame.terminate()
16 19
     CharacterList.terminate()

+ 4
- 4
modules/client_entergame/entergame.otui View File

@@ -5,7 +5,7 @@ MainWindow
5 5
   @onEnter: EnterGame.doLogin()
6 6
   @onEscape: EnterGame.hide()
7 7
 
8
-  LargerLabel
8
+  Label
9 9
     text: Account name
10 10
     anchors.left: parent.left
11 11
     anchors.top: parent.top
@@ -17,7 +17,7 @@ MainWindow
17 17
     anchors.top: prev.bottom
18 18
     margin-top: 2
19 19
 
20
-  LargerLabel
20
+  Label
21 21
     text: Password
22 22
     anchors.left: prev.left
23 23
     anchors.top: prev.bottom
@@ -30,7 +30,7 @@ MainWindow
30 30
     anchors.top: prev.bottom
31 31
     margin-top: 2
32 32
 
33
-  LargerLabel
33
+  Label
34 34
     id: serverLabel
35 35
     width: 140
36 36
     text: Server
@@ -46,7 +46,7 @@ MainWindow
46 46
     anchors.top: serverLabel.bottom
47 47
     margin-top: 2
48 48
 
49
-  LargerLabel
49
+  Label
50 50
     id: portLabel
51 51
     text: Port
52 52
     width: 50

modules/core_styles/icons/login.png → modules/client_entergame/login.png View File


modules/core_styles/icons/motd.png → modules/client_entergame/motd.png View File


+ 0
- 14
modules/client_main/client.otmod View File

@@ -1,14 +0,0 @@
1
-Module
2
-  name: client_main
3
-  description: Initialize the client and setups its main window
4
-  author: OTClient team
5
-  website: https://github.com/edubart/otclient
6
-  autoload: true
7
-  autoload-antecedence: 100
8
-
9
-  onLoad: |
10
-    dofile 'client'
11
-    Client.init()
12
-
13
-  onUnload: |
14
-    Client.terminate()

+ 6
- 5
modules/client_modulemanager/modulemanager.lua View File

@@ -16,8 +16,9 @@ function ModuleManager.init()
16 16
   Keyboard.bindKeyPress('Up', function() moduleList:focusPreviousChild(KeyboardFocusReason) end, moduleManagerWindow)
17 17
   Keyboard.bindKeyPress('Down', function() moduleList:focusNextChild(KeyboardFocusReason) end, moduleManagerWindow)
18 18
 
19
-  moduleManagerButton = TopMenu.addButton('moduleManagerButton', 'Module manager', 'modulemanager.png', ModuleManager.toggle)
19
+  moduleManagerButton = TopMenu.addLeftButton('moduleManagerButton', 'Module manager', 'modulemanager.png', ModuleManager.toggle)
20 20
 
21
+  -- refresh modules only after all modules are loaded
21 22
   addEvent(ModuleManager.listModules)
22 23
 end
23 24
 
@@ -36,8 +37,8 @@ end
36 37
 
37 38
 function ModuleManager.show()
38 39
   moduleManagerWindow:show()
39
-  moduleManagerWindow:focus()
40 40
   moduleManagerWindow:raise()
41
+  moduleManagerWindow:focus()
41 42
 end
42 43
 
43 44
 function ModuleManager.toggle()
@@ -98,8 +99,8 @@ function ModuleManager.updateModuleInfo(moduleName)
98 99
     website = module:getWebsite()
99 100
     version = module:getVersion()
100 101
     loaded = module:isLoaded()
102
+    canReload = module:canReload()
101 103
     canUnload = module:canUnload()
102
-    canReload = not loaded or canUnload
103 104
   end
104 105
 
105 106
   moduleManagerWindow:recursiveGetChildById('moduleName'):setText(name)
@@ -111,12 +112,10 @@ function ModuleManager.updateModuleInfo(moduleName)
111 112
 
112 113
   local reloadButton = moduleManagerWindow:recursiveGetChildById('moduleReloadButton')
113 114
   reloadButton:setEnabled(canReload)
114
-  reloadButton:setVisible(true)
115 115
   if loaded then reloadButton:setText('Reload')
116 116
   else reloadButton:setText('Load') end
117 117
 
118 118
   local unloadButton = moduleManagerWindow:recursiveGetChildById('moduleUnloadButton')
119
-  unloadButton:setVisible(true)
120 119
   unloadButton:setEnabled(canUnload)
121 120
 end
122 121
 
@@ -126,6 +125,7 @@ function ModuleManager.reloadCurrentModule()
126 125
     local module = g_modules.getModule(focusedChild:getText())
127 126
     if module then
128 127
       module:reload()
128
+      if ModuleManager == nil then return end
129 129
       ModuleManager.updateModuleInfo(module:getName())
130 130
       ModuleManager.refreshLoadedModules()
131 131
       ModuleManager.show()
@@ -139,6 +139,7 @@ function ModuleManager.unloadCurrentModule()
139 139
     local module = g_modules.getModule(focusedChild:getText())
140 140
     if module then
141 141
       module:unload()
142
+      if ModuleManager == nil then return end
142 143
       ModuleManager.updateModuleInfo(module:getName())
143 144
       ModuleManager.refreshLoadedModules()
144 145
     end

+ 4
- 3
modules/client_modulemanager/modulemanager.otmod View File

@@ -3,15 +3,16 @@ Module
3 3
   description: Manage other modules
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6
+  reloadable: true
6 7
   autoload: true
7
-  autoload-antecedence: 140
8
+  autoload-priority: 140
8 9
 
9 10
   dependencies:
10 11
     - client_topmenu
11 12
 
12
-  onLoad: |
13
+  @onLoad: |
13 14
     dofile 'modulemanager'
14 15
     ModuleManager.init()
15 16
 
16
-  onUnload: |
17
+  @onUnload: |
17 18
     ModuleManager.terminate()

+ 13
- 5
modules/client_modulemanager/modulemanager.otui View File

@@ -27,7 +27,7 @@ ModuleValueLabel < UILabel
27 27
   font: verdana-11px-antialised
28 28
   color: #aaaaaa
29 29
   text-offset: 3 0
30
-  image-source: /core_styles/images/panel_flat.png
30
+  image-source: /core_styles/styles/images/panel_flat.png
31 31
   image-border: 1
32 32
   height: 16
33 33
 
@@ -92,9 +92,9 @@ MainWindow
92 92
     //  id: moduleAutoload
93 93
 
94 94
     //ModuleInfoLabel
95
-    //  text: Autoload antecedence
95
+    //  text: Autoload priority
96 96
     //ModuleValueLabel
97
-    //  id: moduleLoadAntecedence
97
+    //  id: moduleLoadPriority
98 98
     //  text: 1000
99 99
 
100 100
     ModuleInfoLabel
@@ -118,7 +118,7 @@ MainWindow
118 118
     anchors.left: moduleInfo.left
119 119
     margin-top: 8
120 120
     text: Load
121
-    visible: false
121
+    enabled: false
122 122
     @onClick: ModuleManager.reloadCurrentModule()
123 123
 
124 124
   Button
@@ -128,6 +128,14 @@ MainWindow
128 128
     margin-left: 10
129 129
     margin-top: 8
130 130
     text: Unload
131
-    visible: false
131
+    enabled: false
132 132
     @onClick: ModuleManager.unloadCurrentModule()
133 133
 
134
+  Button
135
+    id: closeButton
136
+    anchors.bottom: parent.bottom
137
+    anchors.right: parent.right
138
+    text: Close
139
+    width: 60
140
+    @onClick: ModuleManager.hide()
141
+

+ 31
- 26
modules/client_options/options.lua View File

@@ -2,29 +2,29 @@ Options = {}
2 2
 
3 3
 local optionsWindow
4 4
 local optionsButton
5
+local options = { vsync = true,
6
+                  showfps = true,
7
+                  fullscreen = false,
8
+                  classicControl = false,
9
+                  showStatusMessagesInConsole = true,
10
+                  showEventMessagesInConsole = true,
11
+                  showInfoMessagesInConsole = true,
12
+                  showTimestampsInConsole = true,
13
+                  showLevelsInConsole = true,
14
+                  showPrivateMessagesInConsole = true }
5 15
 
6 16
 function Options.init()
7
-  -- load settings
8
-  local booleanOptions = { vsync = true,
9
-                           showfps = true,
10
-                           fullscreen = false,
11
-                           classicControl = false,
12
-                           showStatusMessagesInConsole = true,
13
-                           showEventMessagesInConsole = true,
14
-                           showInfoMessagesInConsole = true,
15
-                           showTimestampsInConsole = true,
16
-                           showLevelsInConsole = true,
17
-                           showPrivateMessagesInConsole = true,
18
-                           }
19
-
20
-  for k,v in pairs(booleanOptions) do
21
-    Settings.setDefault(k, v)
22
-    Options.changeOption(k, Settings.getBoolean(k))
17
+  -- load options
18
+  for k,v in pairs(options) do
19
+    if type(v) == 'boolean' then
20
+      Settings.setDefault(k, v)
21
+      Options.setOption(k, Settings.getBoolean(k))
22
+    end
23 23
   end
24 24
 
25 25
   optionsWindow = displayUI('options.otui')
26
-  optionsWindow:setVisible(false)
27
-  optionsButton = TopMenu.addButton('optionsButton', 'Options (Ctrl+O)', 'options.png', Options.toggle)
26
+  optionsWindow:hide()
27
+  optionsButton = TopMenu.addLeftButton('optionsButton', 'Options (Ctrl+O)', 'options.png', Options.toggle)
28 28
   Keyboard.bindKeyDown('Ctrl+O', Options.toggle)
29 29
 end
30 30
 
@@ -47,11 +47,11 @@ end
47 47
 
48 48
 function Options.show()
49 49
   optionsWindow:show()
50
-  optionsWindow:lock()
50
+  optionsWindow:raise()
51
+  optionsWindow:focus()
51 52
 end
52 53
 
53 54
 function Options.hide()
54
-  optionsWindow:unlock()
55 55
   optionsWindow:hide()
56 56
 end
57 57
 
@@ -59,20 +59,24 @@ function Options.openWebpage()
59 59
   displayErrorBox("Error", "Not implemented yet")
60 60
 end
61 61
 
62
-function Options.changeOption(key, status)
62
+function Options.setOption(key, value)
63 63
   if key == 'vsync' then
64
-    g_window.setVerticalSync(status)
64
+    g_window.setVerticalSync(value)
65 65
   elseif key == 'showfps' then
66 66
     addEvent(function()
67 67
       local frameCounter = rootWidget:recursiveGetChildById('frameCounter')
68
-      if frameCounter then frameCounter:setVisible(status) end
68
+      if frameCounter then frameCounter:setVisible(value) end
69 69
     end)
70 70
   elseif key == 'fullscreen' then
71 71
     addEvent(function()
72
-      g_window.setFullscreen(status)
72
+      g_window.setFullscreen(value)
73 73
     end)
74 74
   end
75
-  Settings.set(key, status)
76
-  Options[key] = status
75
+  Settings.set(key, value)
76
+  options[key] = value
77 77
 end
78
+
79
+function Options.getOption(key)
80
+  return options[key]
81
+end
82
+

+ 3
- 4
modules/client_options/options.otmod View File

@@ -3,15 +3,14 @@ Module
3 3
   description: Create the options window
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6
-  autoload: true
7
-  autoload-antecedence: 130
6
+  reloadable: true
8 7
 
9 8
   dependencies:
10 9
     - client_topmenu
11 10
 
12
-  onLoad: |
11
+  @onLoad: |
13 12
     dofile 'options'
14 13
     Options.init()
15 14
 
16
-  onUnload: |
15
+  @onUnload: |
17 16
     Options.terminate()

+ 3
- 3
modules/client_options/options.otui View File

@@ -1,6 +1,6 @@
1 1
 OptionCheckBox < CheckBox
2
-  @onCheckChange: Options.changeOption(self:getId(), self:isChecked())
3
-  @onSetup: self:setChecked(Options[self:getId()])
2
+  @onCheckChange: Options.setOption(self:getId(), self:isChecked())
3
+  @onSetup: self:setChecked(Options.getOption(self:getId()))
4 4
 
5 5
   $first:
6 6
     anchors.left: parent.left
@@ -67,4 +67,4 @@ MainWindow
67 67
     width: 64
68 68
     anchors.right: parent.right
69 69
     anchors.bottom: parent.bottom
70
-    @onClick: Options.hide()
70
+    @onClick: Options.hide()

+ 0
- 4
modules/client_terminal/commands.lua View File

@@ -41,10 +41,6 @@ function debugContainersItems()
41 41
   end
42 42
 end
43 43
 
44
-function quit()
45
-  exit()
46
-end
47
-
48 44
 function autoReloadModule(name)
49 45
   local function reloadEvent()
50 46
     reloadModule(name)

+ 12
- 11
modules/client_terminal/terminal.lua View File

@@ -110,26 +110,27 @@ function Terminal.init()
110 110
   terminalWidget = displayUI('terminal.otui')
111 111
   terminalWidget:setVisible(false)
112 112
 
113
-  terminalButton = TopMenu.addButton('terminalButton', 'Terminal (Ctrl + T)', 'terminal.png', Terminal.toggle)
113
+  terminalButton = TopMenu.addLeftButton('terminalButton', 'Terminal (Ctrl + T)', 'terminal.png', Terminal.toggle)
114 114
   Keyboard.bindKeyDown('Ctrl+T', Terminal.toggle)
115 115
 
116 116
   commandHistory = Settings.getList('terminal-history')
117 117
 
118 118
   commandLineEdit = terminalWidget:getChildById('commandLineEdit')
119
-  Keyboard.bindKeyDown('Up', function() navigateCommand(1) end, commandLineEdit)
120
-  Keyboard.bindKeyDown('Down', function() navigateCommand(-1) end, commandLineEdit)
119
+  Keyboard.bindKeyPress('Up', function() navigateCommand(1) end, commandLineEdit)
120
+  Keyboard.bindKeyPress('Down', function() navigateCommand(-1) end, commandLineEdit)
121 121
   Keyboard.bindKeyDown('Tab', completeCommand, commandLineEdit)
122 122
   Keyboard.bindKeyDown('Enter', doCommand, commandLineEdit)
123
+  Keyboard.bindKeyDown('Escape', Terminal.hide, terminalWidget)
123 124
 
124 125
   terminalBuffer = terminalWidget:getChildById('terminalBuffer')
125
-  Logger.setOnLog(onLog)
126
-  Logger.fireOldMessages()
126
+  g_logger.setOnLog(onLog)
127
+  g_logger.fireOldMessages()
127 128
 end
128 129
 
129 130
 function Terminal.terminate()
130 131
   Settings.setList('terminal-history', commandHistory)
131 132
   Keyboard.unbindKeyDown('Ctrl+T')
132
-  Logger.setOnLog(nil)
133
+  g_logger.setOnLog(nil)
133 134
   terminalButton:destroy()
134 135
   terminalButton = nil
135 136
   commandLineEdit = nil
@@ -150,11 +151,11 @@ end
150 151
 
151 152
 function Terminal.show()
152 153
   terminalWidget:show()
153
-  terminalWidget:lock()
154
+  terminalWidget:raise()
155
+  terminalWidget:focus()
154 156
 end
155 157
 
156 158
 function Terminal.hide()
157
-  terminalWidget:unlock()
158 159
   terminalWidget:hide()
159 160
 end
160 161
 
@@ -178,7 +179,7 @@ function Terminal.executeCommand(command)
178 179
   if command == nil or #command == 0 then return end
179 180
 
180 181
   logLocked = true
181
-  Logger.log(LogInfo, '>> ' .. command)
182
+  g_logger.log(LogInfo, '>> ' .. command)
182 183
   logLocked = false
183 184
 
184 185
   -- detect and convert commands with simple syntax
@@ -210,7 +211,7 @@ function Terminal.executeCommand(command)
210 211
 
211 212
   -- check for syntax errors
212 213
   if not func then
213
-    Logger.log(LogError, 'incorrect lua syntax: ' .. err:sub(5))
214
+    g_logger.log(LogError, 'incorrect lua syntax: ' .. err:sub(5))
214 215
     return
215 216
   end
216 217
 
@@ -223,6 +224,6 @@ function Terminal.executeCommand(command)
223 224
     -- if the command returned a value, print it
224 225
     if ret then print(ret) end
225 226
   else
226
-    Logger.log(LogError, 'command failed: ' .. ret)
227
+    g_logger.log(LogError, 'command failed: ' .. ret)
227 228
   end
228 229
 end

+ 3
- 4
modules/client_terminal/terminal.otmod View File

@@ -3,13 +3,12 @@ Module
3 3
   description: Terminal for executing lua functions
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6
-  autoload: true
7
-  autoload-antecedence: 160
6
+  reloadable: true
8 7
 
9
-  onLoad: |
8
+  @onLoad: |
10 9
     dofile 'terminal'
11 10
     dofile 'commands'
12 11
     Terminal.init()
13 12
 
14
-  onUnload: |
13
+  @onUnload: |
15 14
     Terminal.terminate()

+ 0
- 14
modules/client_tibiafiles/tibiafiles.otmod View File

@@ -1,14 +0,0 @@
1
-Module
2
-  name: client_tibiafiles
3
-  description: Contains tibia spr and dat
4
-  unloadable: false
5
-  autoload: true
6
-  autoload-antecedence: 170
7
-
8
-  onLoad: |
9
-    if not g_thingsType.load('/client_tibiafiles/Tibia.dat') then
10
-      fatal("Unable to load dat file, please place a valid Tibia dat in modules/client_tibiafiles/Tibia.dat")
11
-    end
12
-    if not g_sprites.load('/client_tibiafiles/Tibia.spr') then
13
-      fatal("Unable to load spr file, please place a valid Tibia spr in modules/client_tibiafiles/Tibia.spr")
14
-    end

modules/core_styles/images/top_button.png → modules/client_topmenu/images/top_button.png View File


modules/core_styles/images/top_button2.png → modules/client_topmenu/images/top_game_button.png View File


modules/core_styles/images/top_panel.png → modules/client_topmenu/images/top_panel.png View File


+ 36
- 37
modules/client_topmenu/topmenu.lua View File

@@ -7,12 +7,25 @@ local rightButtonsPanel
7 7
 local gameButtonsPanel
8 8
 
9 9
 -- private functions
10
-local function onLogout()
11
-  if g_game.isOnline() then
12
-    g_game.safeLogout()
10
+local function addButton(id, description, icon, callback, panel, toggle)
11
+  local class
12
+  if toggle then
13
+    class = 'TopToggleButton'
14
+  else
15
+    class = 'TopButton'
16
+  end
17
+
18
+  local button = createWidget(class, panel)
19
+  button:setId(id)
20
+  button:setTooltip(description)
21
+  button:setIcon(resolvepath(icon, 3))
22
+
23
+  if toggle then
24
+    button.onCheckChange = callback
13 25
   else
14
-    exit()
26
+    button.onClick = callback
15 27
   end
28
+  return button
16 29
 end
17 30
 
18 31
 -- public functions
@@ -22,15 +35,11 @@ function TopMenu.init()
22 35
   rightButtonsPanel = topMenu:getChildById('rightButtonsPanel')
23 36
   gameButtonsPanel = topMenu:getChildById('gameButtonsPanel')
24 37
 
25
-  TopMenu.addRightButton('logoutButton', 'Logout (Ctrl+Q)', '/core_styles/icons/logout.png', onLogout)
26
-  Keyboard.bindKeyDown('Ctrl+Q', onLogout)
27
-
28 38
   connect(g_game, { onGameStart = TopMenu.showGameButtons,
29
-                  onGameEnd = TopMenu.hideGameButtons })
39
+                    onGameEnd = TopMenu.hideGameButtons })
30 40
 end
31 41
 
32 42
 function TopMenu.terminate()
33
-  Keyboard.unbindKeyDown('Ctrl+Q')
34 43
   leftButtonsPanel = nil
35 44
   rightButtonsPanel = nil
36 45
   gameButtonsPanel = nil
@@ -38,45 +47,33 @@ function TopMenu.terminate()
38 47
   topMenu = nil
39 48
 
40 49
   disconnect(g_game, { onGameStart = TopMenu.showGameButtons,
41
-                     onGameEnd = TopMenu.hideGameButtons })
50
+                       onGameEnd = TopMenu.hideGameButtons })
42 51
 
43 52
   TopMenu = nil
44 53
 end
45 54
 
46
-function TopMenu.addButton(id, description, icon, callback, right)
47
-  local panel
48
-  local class
49
-  if right then
50
-    panel = rightButtonsPanel
51
-    class = 'TopRightButton'
52
-  else
53
-    panel = leftButtonsPanel
54
-    class = 'TopLeftButton'
55
-  end
55
+function TopMenu.addLeftButton(id, description, icon, callback)
56
+  return addButton(id, description, icon, callback, leftButtonsPanel, false)
57
+end
56 58
 
57
-  local button = createWidget(class, panel)
58
-  button:setId(id)
59
-  button:setTooltip(description)
60
-  button:setIcon(resolvepath(icon, 2))
61
-  button.onClick = callback
62
-  return button
59
+function TopMenu.addLeftToggleButton(id, description, icon, callback, right)
60
+  return addButton(id, description, icon, callback, leftButtonsPanel, true)
63 61
 end
64 62
 
65
-function TopMenu.addGameButton(id, description, icon, callback)
66
-  local button = createWidget('GameTopButton', gameButtonsPanel)
67
-  button:setId(id)
68
-  button:setTooltip(description)
69
-  button:setIcon(resolvepath(icon, 2))
70
-  button.onClick = callback
71
-  return button
63
+function TopMenu.addRightButton(id, description, icon, callback)
64
+  return addButton(id, description, icon, callback, rightButtonsPanel, false)
72 65
 end
73 66
 
74
-function TopMenu.addLeftButton(id, description, icon, callback)
75
-  return TopMenu.addButton(id, description, resolvepath(icon, 2), callback, false)
67
+function TopMenu.addRightToggleButton(id, description, icon, callback, right)
68
+  return addButton(id, description, icon, callback, rightButtonsPanel, true)
76 69
 end
77 70
 
78
-function TopMenu.addRightButton(id, description, icon, callback)
79
-  return TopMenu.addButton(id, description, resolvepath(icon, 2), callback, true)
71
+function TopMenu.addGameButton(id, description, icon, callback)
72
+  return addButton(id, description, icon, callback, gameButtonsPanel, false)
73
+end
74
+
75
+function TopMenu.addGameToggleButton(id, description, icon, callback, right)
76
+  return addButton(id, description, icon, callback, gameButtonsPanel, true)
80 77
 end
81 78
 
82 79
 function TopMenu.hideGameButtons()
@@ -90,3 +87,5 @@ end
90 87
 function TopMenu.getButton(id)
91 88
   return topMenu:recursiveGetChildById(id)
92 89
 end
90
+
91
+

+ 3
- 4
modules/client_topmenu/topmenu.otmod View File

@@ -3,12 +3,11 @@ Module
3 3
   description: Create the top menu
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6
-  autoload: true
7
-  autoload-antecedence: 120
6
+  reloadable: true
8 7
 
9
-  onLoad: |
8
+  @onLoad: |
10 9
     dofile 'topmenu'
11 10
     TopMenu.init()
12 11
 
13
-  onUnload: |
12
+  @onUnload: |
14 13
     TopMenu.terminate()

+ 22
- 27
modules/client_topmenu/topmenu.otui View File

@@ -1,6 +1,6 @@
1 1
 TopButton < UIButton
2 2
   size: 26 26
3
-  image-source: /core_styles/images/top_button.png
3
+  image-source: images/top_button.png
4 4
   image-clip: 0 0 26 26
5 5
   image-border: 3
6 6
   image-color: #ffffffff
@@ -17,66 +17,61 @@ TopButton < UIButton
17 17
     image-color: #ffffff44
18 18
     icon-color: #ffffff44
19 19
 
20
-GameTopButton < UIButton
20
+TopToggleButton < UICheckBox
21 21
   size: 26 26
22
-  image-source: /core_styles/images/top_button2.png
22
+  image-source: images/top_game_button.png
23 23
   image-clip: 26 0 26 26
24 24
   image-color: #ffffff22
25
-  icon-color: #ffffffff
26 25
   image-border: 3
26
+  icon-color: #ffffffff
27 27
 
28
-  $on:
28
+  $checked:
29 29
     image-clip: 0 0 26 26
30 30
     image-color: #ffffffff
31 31
     icon-color: #ffffffff
32 32
 
33
-TopLeftButton < TopButton
34
-TopRightButton < TopButton
33
+TopMenuButtonsPanel < Panel
34
+  layout:
35
+    type: horizontalBox
36
+    spacing: 4
37
+    fit-children: true
38
+  padding: 6 4
39
+
40
+TopPanel < Panel
41
+  height: 36
42
+  image-source: images/top_panel.png
43
+  image-repeated: true
44
+  focusable: false
45
+
35 46
 
36 47
 TopPanel
37 48
   id: topMenu
38 49
   anchors.top: parent.top
39 50
   anchors.left: parent.left
40 51
   anchors.right: parent.right
41
-  focusable: false
42 52
 
43
-  Panel
53
+  TopMenuButtonsPanel
44 54
     id: leftButtonsPanel
45 55
     anchors.top: parent.top
46 56
     anchors.bottom: parent.bottom
47 57
     anchors.left: parent.left
48
-    layout:
49
-      type: horizontalBox
50
-      spacing: 4
51
-      fit-children: true
52
-    padding: 6 4
53 58
 
54
-  Panel
59
+  TopMenuButtonsPanel
55 60
     id: gameButtonsPanel
56 61
     anchors.top: parent.top
57 62
     anchors.bottom: parent.bottom
58 63
     anchors.left: prev.right
59 64
     anchors.right: next.left
60
-    layout:
61
-      type: horizontalBox
62
-      spacing: 4
63
-    padding: 6 4
64
-    visible: false
65 65
 
66
-  Panel
66
+  TopMenuButtonsPanel
67 67
     id: rightButtonsPanel
68 68
     anchors.top: parent.top
69 69
     anchors.bottom: parent.bottom
70 70
     anchors.right: parent.right
71
-    layout:
72
-      type: horizontalBox
73
-      spacing: 4
74
-      fit-children: true
75
-    padding: 6 4
76 71
 
77 72
   FrameCounter
78 73
     id: frameCounter
79 74
     anchors.top: parent.top
80 75
     anchors.right: prev.left
81 76
     margin-top: 8
82
-    margin-right: 5
77
+    margin-right: 5

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

@@ -1,15 +0,0 @@
1
-Module
2
-  name: core_fonts
3
-  description: Contains fonts used by core
4
-  author: OTClient team
5
-  website: https://github.com/edubart/otclient
6
-  autoload: true
7
-  autoload-antecedence: 30
8
-
9
-  onLoad: |
10
-    importFont 'verdana-11px-antialised'
11
-    importFont 'verdana-11px-monochrome'
12
-    importFont 'verdana-11px-rounded'
13
-    importFont 'terminus-14px-bold'
14
-    setDefaultFont 'verdana-11px-antialised'
15
-

+ 21
- 4
modules/core_lib/core_lib.otmod View File

@@ -4,9 +4,9 @@ Module
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6 6
   autoload: true
7
-  autoload-antecedence: 10
7
+  autoload-priority: 10
8 8
 
9
-  onLoad: |
9
+  @onLoad: |
10 10
     dofile 'ext/table'
11 11
     dofile 'ext/string'
12 12
     dofile 'ext/os'
@@ -17,9 +17,26 @@ Module
17 17
     dofile 'const'
18 18
     dofile 'util'
19 19
     dofile 'globals'
20
-    dofile 'dispatcher'
21
-    dofile 'effects'
22 20
     dofile 'settings'
23 21
     dofile 'keyboard'
24 22
     dofile 'mouse'
25 23
 
24
+    dofile 'ui/effects'
25
+    dofile 'ui/radiogroup'
26
+    dofile 'ui/tooltip'
27
+
28
+    dofile 'widgets/uiwidget'
29
+    dofile 'widgets/uibutton'
30
+    dofile 'widgets/uilabel'
31
+    dofile 'widgets/uicheckbox'
32
+    dofile 'widgets/uicombobox'
33
+    dofile 'widgets/uispinbox'
34
+    dofile 'widgets/uiprogressbar'
35
+    dofile 'widgets/uitabbar'
36
+    dofile 'widgets/uipopupmenu'
37
+    dofile 'widgets/uiwindow'
38
+    --dofile 'widgets/uiminiwindow'
39
+    --dofile 'widgets/uiminiwindowcontainer'
40
+    dofile 'widgets/uimessagebox'
41
+
42
+

+ 0
- 20
modules/core_lib/dispatcher.lua View File

@@ -1,20 +0,0 @@
1
-function scheduleEvent(callback, delay)
2
-  local event = g_dispatcher.scheduleEvent(callback, delay)
3
-
4
-  -- must hold a reference to the callback, otherwise it would be collected
5
-  event._callback = callback
6
-  return event
7
-end
8
-
9
-function addEvent(callback, front)
10
-  local event = g_dispatcher.addEvent(callback, front)
11
-  -- must hold a reference to the callback, otherwise it would be collected
12
-  event._callback = callback
13
-  return event
14
-end
15
-
16
-function removeEvent(event)
17
-  if event then
18
-    event:cancel()
19
-  end
20
-end

+ 28
- 50
modules/core_lib/globals.lua View File

@@ -1,57 +1,13 @@
1 1
 rootWidget = g_ui.getRootWidget()
2 2
 
3
-function importStyle(otui)
4
-  g_ui.importStyle(resolvepath(otui, 2))
5
-end
6
-
7
-function importFont(otfont)
8
-  g_fonts.importFont(resolvepath(otfont, 2))
9
-end
3
+importStyle = g_ui.importStyle
4
+importFont = g_fonts.importFont
5
+setDefaultFont = g_fonts.setDefaultFont
10 6
 
11
-function setDefaultFont(font)
12
-  g_fonts.setDefaultFont(font)
13
-end
7
+loadUI = g_ui.loadUI
14 8
 
15
-function displayUI(arg1, options)
16
-  local widget
17
-  local parent
18
-  if options then parent = options.parent end
9
+function displayUI(otui, parent)
19 10
   parent = parent or rootWidget
20
-
21
-  -- display otui files
22
-  if type(arg1) == 'string' then
23
-    local otuiFilePath = resolvepath(arg1, 2)
24
-    widget = g_ui.loadUI(otuiFilePath, parent)
25
-  -- display already loaded widgets
26
-  else
27
-    widget = arg1
28
-    if parent:hasChild(widget) then
29
-      widget:focus()
30
-      widget:show()
31
-    else
32
-      parent:addChild(widget)
33
-      widget:show()
34
-    end
35
-  end
36
-
37
-  -- apply display options
38
-  if widget and options then
39
-    for option,value in pairs(options) do
40
-      if option == 'locked' and value then
41
-        widget:lock()
42
-      elseif option == 'visible' then
43
-        widget:setVisible(value)
44
-      elseif option == 'x' then
45
-        widget:setX(value)
46
-      elseif option == 'y' then
47
-        widget:setY(value)
48
-      end
49
-    end
50
-  end
51
-  return widget
52
-end
53
-
54
-function loadUI(otui, parent)
55 11
   local otuiFilePath = resolvepath(otui, 2)
56 12
   return g_ui.loadUI(otuiFilePath, parent)
57 13
 end
@@ -65,7 +21,7 @@ function createWidget(style, parent)
65 21
 
66 22
   local class = _G[className]
67 23
   if not class then
68
-    error('could not find widget class ' .. class)
24
+    error('could not find widget class ' .. className)
69 25
     return
70 26
   end
71 27
 
@@ -80,6 +36,28 @@ function createWidget(style, parent)
80 36
   return widget
81 37
 end
82 38
 
39
+function scheduleEvent(callback, delay)
40
+  local event = g_dispatcher.scheduleEvent(callback, delay)
41
+
42
+  -- must hold a reference to the callback, otherwise it would be collected
43
+  event._callback = callback
44
+  return event
45
+end
46
+
47
+function addEvent(callback, front)
48
+  local event = g_dispatcher.addEvent(callback, front)
49
+  -- must hold a reference to the callback, otherwise it would be collected
50
+  event._callback = callback
51
+  return event
52
+end
53
+
54
+function removeEvent(event)
55
+  if event then
56
+    event:cancel()
57
+    event._callback = nil
58
+  end
59
+end
60
+
83 61
 function reloadModule(name)
84 62
   local module = g_modules.getModule(name)
85 63
   if module then

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

@@ -7,3 +7,4 @@ end
7 7
 function Mouse.restoreCursor()
8 8
   g_window.restoreMouseCursor()
9 9
 end
10
+

+ 0
- 1
modules/core_lib/settings.lua View File

@@ -32,7 +32,6 @@ function Settings.set(key, value)
32 32
   g_configs.set(key, convertSettingValue(value))
33 33
 end
34 34
 
35
-
36 35
 function Settings.setDefault(key, value)
37 36
   if Settings.exists(key) then return false end
38 37
   Settings.set(key, value)

modules/core_lib/effects.lua → modules/core_lib/ui/effects.lua View File


modules/core_widgets/radiogroup.lua → modules/core_lib/ui/radiogroup.lua View File


modules/core_widgets/tooltip.lua → modules/core_lib/ui/tooltip.lua View File

@@ -41,13 +41,15 @@ end
41 41
 
42 42
 -- public functions
43 43
 function ToolTip.init()
44
-  toolTipLabel = createWidget('Label', rootWidget)
45
-  toolTipLabel:setId('toolTip')
46
-  toolTipLabel:setBackgroundColor('#111111bb')
47
-  toolTipLabel.onMouseMove = moveToolTip
48
-
49 44
   connect(UIWidget, {  onStyleApply = onWidgetStyleApply,
50 45
                        onHoverChange = onWidgetHoverChange})
46
+
47
+  addEvent(function()
48
+    toolTipLabel = createWidget('Label', rootWidget)
49
+    toolTipLabel:setId('toolTip')
50
+    toolTipLabel:setBackgroundColor('#111111bb')
51
+    toolTipLabel.onMouseMove = moveToolTip
52
+  end)
51 53
 end
52 54
 
53 55
 function ToolTip.terminate()
@@ -63,6 +65,8 @@ end
63 65
 
64 66
 function ToolTip.display(text)
65 67
   if text == nil then return end
68
+  if not toolTipLabel then return end
69
+
66 70
   toolTipLabel:setText(text)
67 71
   toolTipLabel:resizeToText()
68 72
   toolTipLabel:resize(toolTipLabel:getWidth() + 4, toolTipLabel:getHeight() + 4)
@@ -73,6 +77,7 @@ function ToolTip.display(text)
73 77
 end
74 78
 
75 79
 function ToolTip.hide()
80
+  
76 81
   toolTipLabel:hide()
77 82
 end
78 83
 
@@ -85,3 +90,5 @@ function UIWidget:getTooltip()
85 90
   return self.tooltip
86 91
 end
87 92
 
93
+ToolTip.init()
94
+connect(g_app, { onTerminate = ToolTip.terminate })

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

@@ -3,20 +3,15 @@ function print(...)
3 3
   for i,v in ipairs(arg) do
4 4
     msg = msg .. tostring(v) .. "\t"
5 5
   end
6
-  Logger.log(LogInfo, msg)
6
+  g_logger.log(LogInfo, msg)
7 7
 end
8 8
 
9 9
 function fatal(msg)
10
-  Logger.log(LogFatal, msg)
10
+  g_logger.log(LogFatal, msg)
11 11
 end
12 12
 
13
-function setonclose(func)
14
-  g_app.onClose = func
15
-end
16
-
17
-function exit()
18
-  g_app.exit()
19
-end
13
+exit = g_app.exit
14
+quit = g_app.exit
20 15
 
21 16
 function connect(object, signalsAndSlots, pushFront)
22 17
   for signal,slot in pairs(signalsAndSlots) do

modules/core_widgets/uibutton.lua → modules/core_lib/widgets/uibutton.lua View File


modules/core_widgets/uicheckbox.lua → modules/core_lib/widgets/uicheckbox.lua View File


modules/core_widgets/uicombobox.lua → modules/core_lib/widgets/uicombobox.lua View File


modules/core_widgets/uilabel.lua → modules/core_lib/widgets/uilabel.lua View File


modules/core_widgets/uimessagebox.lua → modules/core_lib/widgets/uimessagebox.lua View File


modules/core_widgets/uipopupmenu.lua → modules/core_lib/widgets/uipopupmenu.lua View File

@@ -21,7 +21,8 @@ function UIPopupMenu:display(pos)
21 21
     currentMenu:destroy()
22 22
   end
23 23
 
24
-  displayUI(self, {x = pos.x, y = pos.y})
24
+  rootWidget:addChild(self)
25
+  self:setPosition(pos)
25 26
   self:grabMouse()
26 27
   self:grabKeyboard()
27 28
   currentMenu = self

modules/core_widgets/uiprogressbar.lua → modules/core_lib/widgets/uiprogressbar.lua View File


modules/core_widgets/uispinbox.lua → modules/core_lib/widgets/uispinbox.lua View File


modules/core_widgets/uitabbar.lua → modules/core_lib/widgets/uitabbar.lua View File


modules/core_widgets/uiwidget.lua → modules/core_lib/widgets/uiwidget.lua View File


modules/core_widgets/uiwindow.lua → modules/core_lib/widgets/uiwindow.lua View File

@@ -7,7 +7,7 @@ function UIWindow.create()
7 7
   return window
8 8
 end
9 9
 
10
-function UIWindow:onKeyPress(keyCode, keyboardModifiers)
10
+function UIWindow:onKeyDown(keyCode, keyboardModifiers)
11 11
   if keyboardModifiers == KeyboardNoModifier then
12 12
     if keyCode == KeyEnter then
13 13
       signalcall(self.onEnter, self)
@@ -17,9 +17,8 @@ function UIWindow:onKeyPress(keyCode, keyboardModifiers)
17 17
   end
18 18
 end
19 19
 
20
-function UIWindow:onMousePress(mousePos, mouseButton)
21
-  self:raise()
22
-  return true
20
+function UIWindow:onFocusChange(focused)
21
+  if focused then self:raise() end
23 22
 end
24 23
 
25 24
 function UIWindow:onDragEnter(mousePos)

+ 8
- 3
modules/core_styles/core_styles.otmod View File

@@ -3,11 +3,16 @@ Module
3 3
   description: Contains ui styles used by other modules
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6
-  reloadable: true
7 6
   autoload: true
8
-  autoload-antecedence: 20
7
+  autoload-priority: 20
8
+
9
+  @onLoad: |
10
+    importFont 'fonts/verdana-11px-antialised'
11
+    importFont 'fonts/verdana-11px-monochrome'
12
+    importFont 'fonts/verdana-11px-rounded'
13
+    importFont 'fonts/terminus-14px-bold'
14
+    setDefaultFont 'verdana-11px-antialised'
9 15
 
10
-  onLoad: |
11 16
     importStyle 'styles/buttons.otui'
12 17
     importStyle 'styles/labels.otui'
13 18
     importStyle 'styles/panels.otui'

modules/core_styles/icons/targetcursor.png → modules/core_styles/cursors/targetcursor.png View File


modules/core_fonts/terminus-14px-bold.otfont → modules/core_styles/fonts/terminus-14px-bold.otfont View File


modules/core_fonts/terminus-14px-bold.png → modules/core_styles/fonts/terminus-14px-bold.png View File


modules/core_fonts/verdana-11px-antialised.otfont → modules/core_styles/fonts/verdana-11px-antialised.otfont View File


modules/core_fonts/verdana-11px-antialised.png → modules/core_styles/fonts/verdana-11px-antialised.png View File


modules/core_fonts/verdana-11px-monochrome.otfont → modules/core_styles/fonts/verdana-11px-monochrome.otfont View File


modules/core_fonts/verdana-11px-monochrome.png → modules/core_styles/fonts/verdana-11px-monochrome.png View File


modules/core_fonts/verdana-11px-rounded.otfont → modules/core_styles/fonts/verdana-11px-rounded.otfont View File


modules/core_fonts/verdana-11px-rounded.png → modules/core_styles/fonts/verdana-11px-rounded.png View File


+ 4
- 4
modules/core_styles/styles/buttons.otui View File

@@ -4,15 +4,15 @@ Button < UIButton
4 4
   size: 106 24
5 5
   text-offset: 0 0
6 6
   image-color: white
7
-  image-source: /core_styles/images/button.png
7
+  image-source: /core_styles/styles/images/button.png
8 8
   image-border: 5
9 9
 
10 10
   $hover !disabled:
11
-    image-source: /core_styles/images/button_hover.png
11
+    image-source: /core_styles/styles/images/button_hover.png
12 12
 
13 13
   $pressed:
14 14
     text-offset: 1 1
15
-    image-source: /core_styles/images/button_down.png
15
+    image-source: /core_styles/styles/images/button_down.png
16 16
 
17 17
   $disabled:
18 18
     color: #f0ad4d88
@@ -20,7 +20,7 @@ Button < UIButton
20 20
 
21 21
 ConsoleButton < UIButton
22 22
   size: 20 20
23
-  image-source: /core_styles/images/tabbutton.png
23
+  image-source: /core_styles/styles/images/tabbutton.png
24 24
   image-color: white
25 25
   image-clip: 0 0 20 20
26 26
   image-border: 2

+ 5
- 5
modules/core_styles/styles/checkboxes.otui View File

@@ -6,7 +6,7 @@ CheckBox < UICheckBox
6 6
   image-color: #ffffffff
7 7
   image-rect: 0 0 12 12
8 8
   image-offset: 0 2
9
-  image-source: /core_styles/images/checkbox.png
9
+  image-source: /core_styles/styles/images/checkbox.png
10 10
 
11 11
   $hover !disabled:
12 12
     color: #cccccc
@@ -30,7 +30,7 @@ CheckBox < UICheckBox
30 30
 ColorBox < UICheckBox
31 31
   size: 16 16
32 32
   image-color: #ffffffff
33
-  image-source: /core_styles/images/colorbox.png
33
+  image-source: /core_styles/styles/images/colorbox.png
34 34
 
35 35
   $checked:
36 36
     image-clip: 16 0 16 16
@@ -44,16 +44,16 @@ ButtonBox < UICheckBox
44 44
   size: 106 24
45 45
   text-offset: 0 0
46 46
   text-align: center
47
-  image-source: /core_styles/images/button.png
47
+  image-source: /core_styles/styles/images/button.png
48 48
   image-color: white
49 49
   image-border: 5
50 50
 
51 51
   $hover !disabled:
52
-    image-source: /core_styles/images/button_hover.png
52
+    image-source: /core_styles/styles/images/button_hover.png
53 53
 
54 54
   $checked:
55 55
     text-offset: 1 1
56
-    image-source: /core_styles/images/button_down.png
56
+    image-source: /core_styles/styles/images/button_down.png
57 57
 
58 58
   $disabled:
59 59
     color: #f0ad4d88

+ 3
- 3
modules/core_styles/styles/comboboxes.otui View File

@@ -14,14 +14,14 @@ ComboBoxPopupMenuButton < UIButton
14 14
     color: #555555
15 15
 
16 16
 ComboBoxPopupMenuSeparator < UIWidget
17
-  image-source: /core_styles/images/combobox.png
17
+  image-source: /core_styles/styles/images/combobox.png
18 18
   image-repeated: true
19 19
   image-clip: 1 59 89 1
20 20
   height: 1
21 21
   phantom: true
22 22
 
23 23
 ComboBoxPopupMenu < UIPopupMenu
24
-  image-source: /core_styles/images/combobox.png
24
+  image-source: /core_styles/styles/images/combobox.png
25 25
   image-clip: 0 60 89 20
26 26
   image-border: 1
27 27
   image-border-top: 0
@@ -33,7 +33,7 @@ ComboBox < UIComboBox
33 33
   size: 86 20
34 34
   text-offset: 3 0
35 35
   text-align: left
36
-  image-source: /core_styles/images/combobox.png
36
+  image-source: /core_styles/styles/images/combobox.png
37 37
   image-border: 1
38 38
   image-border-right: 17
39 39
   image-clip: 0 0 89 20

+ 1
- 4
modules/core_styles/styles/creatures.otui View File

@@ -1,8 +1,5 @@
1 1
 Creature < UICreature
2 2
   size: 80 80
3 3
   padding: 1
4
-  image-source: /core_styles/images/panel_flat.png
4
+  image-source: /core_styles/styles/images/panel_flat.png
5 5
   image-border: 1
6
-
7
-  UIWidget
8
-    id: lala

modules/core_styles/images/button.png → modules/core_styles/styles/images/button.png View File


modules/core_styles/images/button_down.png → modules/core_styles/styles/images/button_down.png View File


modules/core_styles/images/button_hover.png → modules/core_styles/styles/images/button_hover.png View File


modules/core_styles/images/checkbox.png → modules/core_styles/styles/images/checkbox.png View File


modules/core_styles/images/colorbox.png → modules/core_styles/styles/images/colorbox.png View File


modules/core_styles/images/combobox.png → modules/core_styles/styles/images/combobox.png View File


modules/core_styles/images/container_bg.png → modules/core_styles/styles/images/container_bg.png View File


modules/core_styles/images/horizontal_separator.png → modules/core_styles/styles/images/horizontal_separator.png View File


modules/core_styles/images/horizotal_separator.png → modules/core_styles/styles/images/horizotal_separator.png View File


modules/core_styles/images/item.png → modules/core_styles/styles/images/item.png View File


modules/core_styles/images/menu.png → modules/core_styles/styles/images/menu.png View File


modules/core_styles/images/menubox.png → modules/core_styles/styles/images/menubox.png View File


modules/core_styles/images/panel_flat.png → modules/core_styles/styles/images/panel_flat.png View File


modules/core_styles/images/progressbar.png → modules/core_styles/styles/images/progressbar.png View File


modules/core_styles/images/tabbutton.png → modules/core_styles/styles/images/tabbutton.png View File


modules/core_styles/images/window.png → modules/core_styles/styles/images/window.png View File


+ 1
- 1
modules/core_styles/styles/items.otui View File

@@ -1,5 +1,5 @@
1 1
 Item < UIItem
2 2
   size: 34 34
3
-  image-source: /core_styles/images/item.png
3
+  image-source: /core_styles/styles/images/item.png
4 4
   font: verdana-11px-rounded
5 5
   border-color: white

+ 0
- 2
modules/core_styles/styles/labels.otui View File

@@ -5,8 +5,6 @@ Label < UILabel
5 5
   $disabled:
6 6
     color: #aaaaaa88
7 7
 
8
-LargerLabel < Label
9
-
10 8
 GameLabel < UILabel
11 9
   font: verdana-11px-antialised
12 10
   color: #aaaaaa

+ 1
- 1
modules/core_styles/styles/lineedits.otui View File

@@ -3,7 +3,7 @@ LineEdit < UILineEdit
3 3
   color: #aaaaaa
4 4
   size: 86 20
5 5
   text-margin: 3
6
-  image-source: /core_styles/images/panel_flat.png
6
+  image-source: /core_styles/styles/images/panel_flat.png
7 7
   image-border: 1
8 8
 
9 9
   $disabled:

+ 1
- 1
modules/core_styles/styles/listboxes.otui View File

@@ -2,4 +2,4 @@ TextList < UIWidget
2 2
   layout: verticalBox
3 3
   border-width: 1
4 4
   border-color: #1d222b
5
-  background-color: #222833
5
+  background-color: #222833

+ 1
- 19
modules/core_styles/styles/panels.otui View File

@@ -2,23 +2,5 @@ Panel < UIWidget
2 2
   phantom: true
3 3
 
4 4
 FlatPanel < Panel
5
-  image-source: /core_styles/images/panel_flat.png
5
+  image-source: /core_styles/styles/images/panel_flat.png
6 6
   image-border: 1
7
-
8
-TopPanel < Panel
9
-  height: 36
10
-  image-source: /core_styles/images/top_panel.png
11
-  image-repeated: true
12
-
13
-InterfacePanel < UIMiniWindowContainer
14
-  image-source: /core_styles/images/interface_panel.png
15
-  image-border: 4
16
-
17
-InterfacePanel2 < Panel
18
-  image-source: /core_styles/images/interface_panel2.png
19
-  image-border: 4
20
-
21
-Map < UIMap
22
-  padding: 4
23
-  image-source: /core_styles/images/map_panel.png
24
-  image-border: 4

+ 2
- 2
modules/core_styles/styles/popupmenus.otui View File

@@ -17,7 +17,7 @@ PopupMenuButton < UIButton
17 17
 PopupMenuSeparator < UIWidget
18 18
   margin-left: 2
19 19
   margin-right: 2
20
-  image-source: /core_styles/images/menubox.png
20
+  image-source: /core_styles/styles/images/menubox.png
21 21
   image-border-left: 1
22 22
   image-border-right: 1
23 23
   image-clip: 0 0 32 2
@@ -26,7 +26,7 @@ PopupMenuSeparator < UIWidget
26 26
 
27 27
 PopupMenu < UIPopupMenu
28 28
   width: 50
29
-  image-source: /core_styles/images/menubox.png
29
+  image-source: /core_styles/styles/images/menubox.png
30 30
   image-border: 3
31 31
   padding-top: 3
32 32
   padding-bottom: 3

+ 1
- 1
modules/core_styles/styles/progressbars.otui View File

@@ -2,6 +2,6 @@ ProgressBar < UIProgressBar
2 2
   height: 16
3 3
   background-color: red
4 4
   border: 1 black
5
-  image: /core_styles/images/progressbar.png
5
+  image: /core_styles/styles/images/progressbar.png
6 6
   image-border: 1
7 7
 

+ 1
- 1
modules/core_styles/styles/separators.otui View File

@@ -1,5 +1,5 @@
1 1
 HorizontalSeparator < UIWidget
2
-  image-source: /core_styles/images/horizontal_separator.png
2
+  image-source: /core_styles/styles/images/horizontal_separator.png
3 3
   image-border-top: 2
4 4
   height: 2
5 5
   phantom: true

+ 1
- 1
modules/core_styles/styles/spinboxes.otui View File

@@ -3,7 +3,7 @@ SpinBox < UISpinBox
3 3
   color: #aaaaaa
4 4
   size: 86 20
5 5
   text-margin: 3
6
-  image-source: /core_styles/images/panel_flat.png
6
+  image-source: /core_styles/styles/images/panel_flat.png
7 7
   image-border: 1
8 8
 
9 9
   $disabled:

+ 1
- 1
modules/core_styles/styles/tabbars.otui View File

@@ -2,7 +2,7 @@ TabBar < UITabBar
2 2
 TabBarPanel < Panel
3 3
 TabBarButton < UIButton
4 4
   size: 20 20
5
-  image-source: /core_styles/images/tabbutton.png
5
+  image-source: /core_styles/styles/images/tabbutton.png
6 6
   image-color: white
7 7
   image-clip: 0 0 20 20
8 8
   image-border: 2

+ 2
- 2
modules/core_styles/styles/windows.otui View File

@@ -5,7 +5,7 @@ Window < UIWindow
5 5
   color: white
6 6
   text-offset: 0 2
7 7
   text-align: top
8
-  image-source: /core_styles/images/window.png
8
+  image-source: /core_styles/styles/images/window.png
9 9
   image-border: 4
10 10
   image-border-top: 20
11 11
   opacity: 1
@@ -35,7 +35,7 @@ MiniWindow < UIMiniWindow
35 35
   margin-left: 6
36 36
   margin-right: 6
37 37
   move-policy: free updated
38
-  image-source: /core_styles/images/mini_window.png
38
+  image-source: /core_styles/styles/images/mini_window.png
39 39
   image-border: 4
40 40
   image-border-top: 23
41 41
   padding: 25 8 2 8

+ 0
- 33
modules/core_widgets/core_widgets.otmod View File

@@ -1,33 +0,0 @@
1
-Module
2
-  name: core_widgets
3
-  description: Contains widgets used by other modules
4
-  author: OTClient team
5
-  website: https://github.com/edubart/otclient
6
-  reloadable: true
7
-  unloadble: false
8
-  autoload: true
9
-  autoload-antecedence: 40
10
-
11
-  onLoad: |
12
-    dofile 'uiwidget'
13
-    dofile 'uibutton'
14
-    dofile 'uilabel'
15
-    dofile 'uicheckbox'
16
-    dofile 'uicombobox'
17
-    dofile 'uispinbox'
18
-    dofile 'uiprogressbar'
19
-    dofile 'uitabbar'
20
-    dofile 'uipopupmenu'
21
-    dofile 'uiwindow'
22
-    dofile 'uiminiwindow'
23
-    dofile 'uiminiwindowcontainer'
24
-    dofile 'uiitem'
25
-    dofile 'uimessagebox'
26
-
27
-    dofile 'tooltip'
28
-    dofile 'radiogroup'
29
-
30
-    ToolTip.init()
31
-
32
-  onUnload: |
33
-    ToolTip.terminate()

+ 0
- 24
modules/game/game.lua View File

@@ -46,19 +46,6 @@ function g_game.startUseWith(thing)
46 46
 end
47 47
 
48 48
 function g_game.createInterface()
49
-  Background.hide()
50
-  CharacterList.destroyLoadBox()
51
-  g_game.gameUi = displayUI('game.otui')
52
-
53
-  --Keyboard.bindKeyPress('Up', function() g_game.walk(North) end)
54
-  --Keyboard.bindKeyPress('Down', function() g_game.walk(South) end)
55
-  --Keyboard.bindKeyPress('Left', function() g_game.walk(West) end)
56
-  --Keyboard.bindKeyPress('Right', function() g_game.walk(East) end)
57
-
58
-  Keyboard.bindKeyPress('Ctrl+Shift+Up', function() g_game.forceWalk(North) end)
59
-  Keyboard.bindKeyPress('Ctrl+Shift+Down', function() g_game.forceWalk(South) end)
60
-  Keyboard.bindKeyPress('Ctrl+Shift+Left', function() g_game.forceWalk(West) end)
61
-  Keyboard.bindKeyPress('Ctrl+Shift+Right', function() g_game.forceWalk(East) end)
62 49
 
63 50
   rootWidget:moveChildToIndex(g_game.gameUi, 1)
64 51
   g_game.gameMapPanel = g_game.gameUi:getChildById('gameMapPanel')
@@ -89,17 +76,6 @@ function g_game.hide()
89 76
 end
90 77
 
91 78
 -- hooked events
92
-function g_game.onLoginError(message)
93
-  CharacterList.destroyLoadBox()
94
-  local errorBox = displayErrorBox("Login Error", "Login error: " .. message)
95
-  connect(errorBox, { onOk = CharacterList.show })
96
-end
97
-
98
-function g_game.onConnectionError(message)
99
-  CharacterList.destroyLoadBox()
100
-  local errorBox = displayErrorBox("Login Error", "Connection error: " .. message)
101
-  connect(errorBox, { onOk = CharacterList.show })
102
-end
103 79
 
104 80
 local function onApplicationClose()
105 81
   if g_game.isOnline() then

+ 3
- 11
modules/game/game.otmod View File

@@ -3,19 +3,11 @@ Module
3 3
   description: Create the game interface, where the ingame stuff starts
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6
+  reloadable: true
6 7
 
7 8
   dependencies:
8
-    - game_healthbar
9
-    - game_inventory
10
-    - game_skills
11
-    - game_textmessage
12
-    - game_viplist
13
-    - game_console
14
-    - game_outfit
15
-    - game_containers
16
-    - game_combatcontrols
17
-    - game_hotkeys
18
-    - game_battle
9
+    - game_tibiafiles
10
+    //- game_shaders
19 11
 
20 12
   onLoad: |
21 13
     dofile 'game'

+ 11
- 0
modules/game_tibiafiles/tibiafiles.otmod View File

@@ -0,0 +1,11 @@
1
+Module
2
+  name: game_tibiafiles
3
+  description: Contains tibia spr and dat
4
+
5
+  @onLoad: |
6
+    if not g_thingsType.load('/game_tibiafiles/Tibia.dat') then
7
+      fatal("Unable to load dat file, please place a valid Tibia dat in modules/game_tibiafiles/Tibia.dat")
8
+    end
9
+    if not g_sprites.load('/game_tibiafiles/Tibia.spr') then
10
+      fatal("Unable to load spr file, please place a valid Tibia spr in modules/game_tibiafiles/Tibia.spr")
11
+    end

modules/game_battle/battle.lua → modules/old/game_battle/battle.lua View File

@@ -36,29 +36,29 @@ table.insert(lifeBarColors, {percentAbove = -1, color = '#4F0000' } )
36 36
 
37 37
 -- public functions
38 38
 function Battle.create()
39
-  battleWindow = displayUI('battle.otui', { parent = g_game.gameRightPanel })
39
+  battleWindow = displayUI('battle.otui', g_game.gameRightPanel)
40 40
   battleWindow:hide()
41 41
   battleButton = TopMenu.addGameButton('battleButton', 'Battle (Ctrl+B)', '/game_battle/battle.png', Battle.toggle)
42 42
   Keyboard.bindKeyDown('Ctrl+B', Battle.toggle)
43
-  
43
+
44 44
   battlePannel = battleWindow:getChildById('battlePanel')
45
-  
45
+
46 46
   hidePlayersButton = battleWindow:getChildById('hidePlayers')
47 47
   hideNPCsButton = battleWindow:getChildById('hideNPCs')
48 48
   hideMonstersButton = battleWindow:getChildById('hideMonsters')
49 49
   hideSkullsButton = battleWindow:getChildById('hideSkulls')
50 50
   hidePartyButton = battleWindow:getChildById('hideParty')
51
-  
51
+
52 52
   mouseWidget = createWidget('UIButton')
53 53
   mouseWidget:setVisible(false)
54
-  mouseWidget:setFocusable(false) 
55
-                
54
+  mouseWidget:setFocusable(false)
55
+
56 56
   connect(Creature, { onSkullChange = Battle.checkCreatureSkull,
57
-                      onEmblemChange = Battle.checkCreatureEmblem } )                      
58
-  
57
+                      onEmblemChange = Battle.checkCreatureEmblem } )
58
+
59 59
   connect(g_game, { onAttackingCreatureChange = Battle.onAttack,
60 60
                     onFollowingCreatureChange = Battle.onFollow } )
61
-                  
61
+
62 62
   addEvent(Battle.addAllCreatures)
63 63
   checkCreaturesEvent = scheduleEvent(Battle.checkCreatures, 200)
64 64
 end
@@ -80,10 +80,10 @@ function Battle.destroy()
80 80
   battleButton = nil
81 81
   battleWindow:destroy()
82 82
   battleWindow = nil
83
-                
83
+
84 84
   disconnect(Creature, {  onSkullChange = Battle.checkCreatureSkull,
85
-                          onEmblemChange = Battle.checkCreatureEmblem } )                      
86
-  
85
+                          onEmblemChange = Battle.checkCreatureEmblem } )
86
+
87 87
   disconnect(g_game, {    onAttackingCreatureChange = Battle.onAttack } )
88 88
 end
89 89
 
@@ -94,7 +94,7 @@ function Battle.toggle()
94 94
 end
95 95
 
96 96
 function Battle.addAllCreatures()
97
-  local spectators = {} 
97
+  local spectators = {}
98 98
 	local player = g_game.getLocalPlayer()
99 99
 	if player then
100 100
 		creatures = g_map.getSpectators(player:getPosition(), false)
@@ -104,7 +104,7 @@ function Battle.addAllCreatures()
104 104
 			end
105 105
 		end
106 106
 	end
107
-  
107
+
108 108
   for i, v in pairs(spectators) do
109 109
     Battle.addCreature(v)
110 110
   end
@@ -116,7 +116,7 @@ function Battle.doCreatureFitFilters(creature)
116 116
   local hideMonsters = hideMonstersButton:isChecked()
117 117
   local hideSkulls = hideSkullsButton:isChecked()
118 118
   local hideParty = hidePartyButton:isChecked()
119
-  
119
+
120 120
   if hidePlayers and not creature:asMonster() and not creature:asNpc() then
121 121
     return false
122 122
   elseif hideNPCs and creature:asNpc() then
@@ -128,35 +128,35 @@ function Battle.doCreatureFitFilters(creature)
128 128
   elseif hideParty and creature:getShield() > ShieldWhiteBlue then
129 129
     return false
130 130
   end
131
-  
131
+
132 132
   return true
133 133
 end
134 134
 
135 135
 function Battle.checkCreatures()
136 136
   local player = g_game.getLocalPlayer()
137
-  if player then 
137
+  if player then
138 138
     local spectators = {}
139 139
 
140 140
     -- reloading list of spectators
141
-    local creaturesAppeared = {}  
141
+    local creaturesAppeared = {}
142 142
     creatures = g_map.getSpectators(player:getPosition(), false)
143 143
     for i, creature in ipairs(creatures) do
144 144
       if creature ~= player and Battle.doCreatureFitFilters(creature) then
145 145
         -- searching for creatures that appeared on battle list
146 146
         local battleButton = battleButtonsByCreaturesList[creature:getId()]
147 147
         if battleButton == nil then
148
-          table.insert(creaturesAppeared, creature)     
148
+          table.insert(creaturesAppeared, creature)
149 149
         else
150 150
           Battle.setLifeBarPercent(battleButton, creature:getHealthPercent())
151 151
         end
152 152
         spectators[creature:getId()] = creature
153 153
       end
154 154
     end
155
-    
155
+
156 156
     for i, v in pairs(creaturesAppeared) do
157 157
       Battle.addCreature(v)
158 158
     end
159
-    
159
+
160 160
     -- searching for creatures that disappeared from battle list
161 161
     local creaturesDisappeared = {}
162 162
     for i, creature in pairs(battleButtonsByCreaturesList) do
@@ -164,7 +164,7 @@ function Battle.checkCreatures()
164 164
         table.insert(creaturesDisappeared, creature.creature)
165 165
       end
166 166
     end
167
-    
167
+
168 168
     for i, v in pairs(creaturesDisappeared) do
169 169
       Battle.removeCreature(v)
170 170
     end
@@ -174,28 +174,28 @@ end
174 174
 
175 175
 function Battle.addCreature(creature)
176 176
   local creatureId = creature:getId()
177
-  
177
+
178 178
   if battleButtonsByCreaturesList[creatureId] == nil then
179
-    local battleButton = displayUI('battleButton.otui', { parent = battlePannel })
179
+    local battleButton = displayUI('battleButton.otui', battlePanne)
180 180
     local creatureWidget = battleButton:getChildById('creature')
181 181
     local labelWidget = battleButton:getChildById('label')
182 182
     local lifeBarWidget = battleButton:getChildById('lifeBar')
183
-    
183
+
184 184
     battleButton:setId('BattleButton_' .. creature:getName():gsub('%s','_'))
185 185
     battleButton.creatureId = creatureId
186 186
     battleButton.creature = creature
187 187
     battleButton.isHovered = false
188 188
     battleButton.isTarget = false
189 189
     battleButton.isFollowed = false
190
-    
190
+
191 191
     labelWidget:setText(creature:getName())
192
-    creatureWidget:setCreature(creature)  
192
+    creatureWidget:setCreature(creature)
193 193
     Battle.setLifeBarPercent(battleButton, creature:getHealthPercent())
194 194
 
195 195
     battleButtonsByCreaturesList[creatureId] = battleButton
196
-    
196
+
197 197
     Battle.checkCreatureSkull(battleButton.creature)
198
-    Battle.checkCreatureEmblem(battleButton.creature)   
198
+    Battle.checkCreatureEmblem(battleButton.creature)
199 199
   end
200 200
 end
201 201
 
@@ -205,7 +205,7 @@ function Battle.checkCreatureSkull(creature, skullId)
205 205
       local skullWidget = battleButton:getChildById('skull')
206 206
       local labelWidget = battleButton:getChildById('label')
207 207
       local creature = battleButton.creature
208
-      
208
+
209 209
       if creature:getSkull() ~= SkullNone then
210 210
         skullWidget:setWidth(skullWidget:getHeight())
211 211
         local imagePath = getSkullImagePath(creature:getSkull())
@@ -265,12 +265,12 @@ end
265 265
 
266 266
 function Battle.removeCreature(creature)
267 267
   local creatureId = creature:getId()
268
-  
268
+
269 269
   if battleButtonsByCreaturesList[creatureId] ~= nil then
270 270
     if lastBattleButtonSwitched == battleButtonsByCreaturesList[creatureId] then
271 271
       lastBattleButtonSwitched = nil
272 272
     end
273
-  
273
+
274 274
     battleButtonsByCreaturesList[creatureId].creature:hideStaticSquare()
275 275
     battleButtonsByCreaturesList[creatureId]:destroy()
276 276
     battleButtonsByCreaturesList[creatureId] = nil
@@ -280,7 +280,7 @@ end
280 280
 function Battle.setLifeBarPercent(battleButton, percent)
281 281
   local lifeBarWidget = battleButton:getChildById('lifeBar')
282 282
   lifeBarWidget:setPercent(percent)
283
-  
283
+
284 284
   local color
285 285
   for i, v in pairs(lifeBarColors) do
286 286
     if percent > v.percentAbove then
@@ -288,31 +288,31 @@ function Battle.setLifeBarPercent(battleButton, percent)
288 288
       break
289 289
     end
290 290
   end
291
-  
291
+
292 292
   lifeBarWidget:setBackgroundColor(color)
293 293
 end
294 294
 
295 295
 function Battle.onbattlePannelHoverChange(widget, hovered)
296
-  if widget.isBattleButton then    
296
+  if widget.isBattleButton then
297 297
     widget.isHovered = hovered
298 298
     Battle.checkBattleButton(widget)
299 299
   end
300 300
 end
301 301
 
302
-function Battle.onAttack(creature)  
303
-  local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched 
302
+function Battle.onAttack(creature)
303
+  local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched
304 304
   if battleButton then
305 305
     battleButton.isTarget = creature and true or false
306 306
     Battle.checkBattleButton(battleButton)
307 307
   end
308 308
 end
309 309
 
310
-function Battle.onFollow(creature)  
311
-  local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched 
310
+function Battle.onFollow(creature)
311
+  local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched
312 312
   if battleButton then
313 313
     battleButton.isFollowed = creature and true or false
314 314
     Battle.checkBattleButton(battleButton)
315
-  end 
315
+  end
316 316
 end
317 317
 
318 318
 function Battle.checkBattleButton(battleButton)
@@ -322,20 +322,20 @@ function Battle.checkBattleButton(battleButton)
322 322
   elseif battleButton.isFollowed then
323 323
     color = battleButtonColors.onFollowed
324 324
   end
325
-  
325
+
326 326
   color = battleButton.isHovered and color.hovered or color.notHovered
327
-  
327
+
328 328
   if battleButton.isHovered or battleButton.isTarget or battleButton.isFollowed then
329 329
     battleButton.creature:showStaticSquare(color)
330 330
     battleButton:getChildById('creature'):setBorderWidth(1)
331 331
     battleButton:getChildById('creature'):setBorderColor(color)
332
-    battleButton:getChildById('label'):setColor(color) 
333
-  else    
332
+    battleButton:getChildById('label'):setColor(color)
333
+  else
334 334
     battleButton.creature:hideStaticSquare()
335 335
     battleButton:getChildById('creature'):setBorderWidth(0)
336
-    battleButton:getChildById('label'):setColor(color) 
336
+    battleButton:getChildById('label'):setColor(color)
337 337
   end
338
-  
338
+
339 339
   if battleButton.isTarget or battleButton.isFollowed then
340 340
     if lastBattleButtonSwitched and lastBattleButtonSwitched ~= battleButton then
341 341
       lastBattleButtonSwitched.isTarget = false

modules/game_battle/battle.otmod → modules/old/game_battle/battle.otmod View File


modules/game_battle/battle.otui → modules/old/game_battle/battle.otui View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save