Browse Source

Use new coding style in game modules

Lots of refactoring and changes
Remove docs folder
Eduardo Bart 8 years ago
parent
commit
c54cd1fdf1
69 changed files with 1507 additions and 2473 deletions
  1. 0
    3
      doc/.gitignore
  2. 0
    222
      doc/StylesOverview.md
  3. 0
    477
      doc/luafunctions.rb
  4. 0
    27
      doc/plugin.rb
  5. 2
    1
      modules/client/client.lua
  6. 1
    1
      modules/client_options/options.lua
  7. 1
    0
      modules/corelib/globals.lua
  8. 19
    1
      modules/corelib/util.lua
  9. 74
    90
      modules/game_battle/battle.lua
  10. 4
    12
      modules/game_battle/battle.otmod
  11. 1
    1
      modules/game_battle/battle.otui
  12. 2
    2
      modules/game_battle/battlebutton.otui
  13. 9
    12
      modules/game_bugreport/bugreport.lua
  14. 4
    10
      modules/game_bugreport/bugreport.otmod
  15. 1
    1
      modules/game_bugreport/bugreport.otui
  16. 62
    77
      modules/game_combatcontrols/combatcontrols.lua
  17. 4
    10
      modules/game_combatcontrols/combatcontrols.otmod
  18. 264
    263
      modules/game_console/console.lua
  19. 4
    10
      modules/game_console/console.otmod
  20. 2
    2
      modules/game_console/console.otui
  21. 39
    42
      modules/game_containers/containers.lua
  22. 4
    10
      modules/game_containers/containers.otmod
  23. 43
    45
      modules/game_healthinfo/healthinfo.lua
  24. 4
    10
      modules/game_healthinfo/healthinfo.otmod
  25. 1
    1
      modules/game_healthinfo/healthinfo.otui
  26. 88
    106
      modules/game_hotkeys/hotkeys_manager.lua
  27. 4
    10
      modules/game_hotkeys/hotkeys_manager.otmod
  28. 13
    13
      modules/game_hotkeys/hotkeys_manager.otui
  29. 81
    93
      modules/game_interface/gameinterface.lua
  30. 4
    12
      modules/game_interface/interface.otmod
  31. 2
    2
      modules/game_interface/widgets/uigamemap.lua
  32. 2
    2
      modules/game_interface/widgets/uiitem.lua
  33. 19
    26
      modules/game_inventory/inventory.lua
  34. 4
    11
      modules/game_inventory/inventory.otmod
  35. 1
    1
      modules/game_inventory/inventory.otui
  36. 65
    70
      modules/game_minimap/minimap.lua
  37. 4
    10
      modules/game_minimap/minimap.otmod
  38. 6
    6
      modules/game_minimap/minimap.otui
  39. 205
    230
      modules/game_npctrade/npctrade.lua
  40. 4
    10
      modules/game_npctrade/npctrade.otmod
  41. 137
    138
      modules/game_outfit/outfit.lua
  42. 4
    10
      modules/game_outfit/outfit.otmod
  43. 9
    9
      modules/game_outfit/outfitwindow.otui
  44. 19
    25
      modules/game_playerdeath/playerdeath.lua
  45. 4
    12
      modules/game_playerdeath/playerdeath.otmod
  46. 5
    9
      modules/game_playermount/playermount.lua
  47. 4
    7
      modules/game_playermount/playermount.otmod
  48. 26
    29
      modules/game_playertrade/playertrade.lua
  49. 4
    10
      modules/game_playertrade/playertrade.otmod
  50. 35
    41
      modules/game_questlog/questlog.lua
  51. 4
    10
      modules/game_questlog/questlog.otmod
  52. 38
    43
      modules/game_ruleviolation/ruleviolation.lua
  53. 4
    10
      modules/game_ruleviolation/ruleviolation.otmod
  54. 23
    23
      modules/game_ruleviolation/ruleviolation.otui
  55. 11
    14
      modules/game_shaders/shaders.lua
  56. 3
    10
      modules/game_shaders/shaders.otmod
  57. 1
    1
      modules/game_skills/skills.lua
  58. 17
    14
      modules/game_textmessage/textmessage.lua
  59. 29
    37
      modules/game_textwindow/textwindow.lua
  60. 5
    10
      modules/game_textwindow/textwindow.otmod
  61. 2
    4
      modules/game_tibiafiles/tibiafiles.lua
  62. 4
    7
      modules/game_tibiafiles/tibiafiles.otmod
  63. 4
    4
      modules/game_viplist/addvip.otui
  64. 32
    38
      modules/game_viplist/viplist.lua
  65. 4
    7
      modules/game_viplist/viplist.otmod
  66. 3
    3
      modules/game_viplist/viplist.otui
  67. 13
    1
      src/framework/core/module.cpp
  68. 14
    11
      src/framework/luaengine/luainterface.cpp
  69. 2
    4
      src/framework/otml/otmlparser.cpp

+ 0
- 3
doc/.gitignore View File

@@ -1,3 +0,0 @@
1
-*.yardoc
2
-doc
3
-!.gitignore

+ 0
- 222
doc/StylesOverview.md View File

@@ -1,222 +0,0 @@
1
-# Style Tags Overview
2
-
3
-## Style Overview
4
-This document describes how style tags can be specified, how they affect your
5
-widgets, and how to use specific built-in style tags in otclient, as well
6
-as how to define new custom style tags.
7
-
8
-## Style Value Types
9
-
10
-{valhead:Integer}
11
-Integer number, used by most of style proprieties
12
-
13
-**Examples:**
14
-
15
-* 1
16
-* 9
17
-* 5
18
-
19
-{valhead:Float}
20
-Float number
21
-
22
-**Examples:**
23
-
24
-* 1.0
25
-* 9
26
-* 1.5
27
-
28
-{valhead:String}
29
-String containing a text
30
-
31
-
32
-**Examples:**
33
-
34
-* this is a string
35
-* it doesn't need quotes or escaping
36
-
37
-{valhead:Boolean}
38
-Value with two states, **true** or **false**
39
-
40
-**Examples:**
41
-
42
-* true
43
-* false
44
-
45
-{valhead:Size}
46
-Size type, defined by 2 integers, width followed by height
47
-
48
-    size: width height
49
-
50
-
51
-**Examples:**
52
-
53
-* 10 20
54
-* 30 10
55
-
56
-{valhead:Rect}
57
-
58
-Rect type, defined by 4 integers
59
-
60
-    rect: x y width height
61
-
62
-**Examples:**
63
-
64
-* 0 0 32 32
65
-* 10 20 30 40
66
-
67
-{valhead:Color}
68
-
69
-{valhead:Image}
70
-
71
-{valhead:Font}
72
-
73
-
74
-## UIWidget
75
-
76
-{taghead:rect Rect}
77
-Defines widget's rect
78
-
79
-**Examples:**
80
-
81
-    !!!plain
82
-    rect: 32 32 32 32
83
-
84
-**See also:** {tag:pos}, {tag:size}
85
-
86
-{taghead:size Size}
87
-Defines size of a widget in pixels
88
-
89
-**Examples:**
90
-
91
-    !!!plain
92
-    size: 32 32
93
-
94
-{taghead:width Integer}
95
-Defines width of a widget
96
-
97
-{taghead:height Integer}
98
-Defines height of a widget
99
-
100
-{taghead:pos Point}
101
-Defines absolute position of the widget relative to the window top left, this is generialy not used,
102
-if you want to position relative to parent widget, use anchors and margins
103
-
104
-
105
-**Examples:**
106
-
107
-    !!!plain
108
-    pos: 32 32
109
-
110
-{taghead:x Integer}
111
-Defines x absolute position
112
-
113
-**See also:** {tag:pos}
114
-
115
-{taghead:y Integer}
116
-Defines y absolute position
117
-
118
-**See also:** {tag:pos}
119
-
120
-
121
-{taghead:color Color}
122
-Foreground color, mostly used for coloring texts
123
-
124
-**Examples:**
125
-
126
-    !!!plain
127
-    color: red
128
-    color: #ff0000
129
-    color: #ff000080
130
-
131
-{taghead:background Color}
132
-Same as {tag:background-color}
133
-
134
-{taghead:background-color Color}
135
-Defines background color
136
-
137
-
138
-{taghead:background-rect Rect}
139
-{taghead:background-offset Point}
140
-{taghead:background-offset-x Integer}
141
-{taghead:background-offset-y Integer}
142
-{taghead:background-size Size}
143
-{taghead:background-width Integer}
144
-{taghead:background-height Integer}
145
-
146
-
147
-{taghead:icon Image}
148
-{taghead:icon-source Image}
149
-{taghead:icon-color Color}
150
-{taghead:icon-offset-x Integer}
151
-{taghead:icon-offset-y Integer}
152
-{taghead:icon-offset Point}
153
-{taghead:icon-width Integer}
154
-{taghead:icon-height Integer}
155
-{taghead:icon-size Size}
156
-{taghead:icon-rect Rect}
157
-{taghead:opacity Float}
158
-{taghead:enabled Boolean}
159
-{taghead:visible Boolean}
160
-{taghead:checked Boolean}
161
-{taghead:dragable Boolean}
162
-{taghead:on Boolean}
163
-{taghead:focusable Boolean}
164
-{taghead:phantom Boolean}
165
-{taghead:fixed-size Boolean}
166
-{taghead:clipping Boolean}
167
-{taghead:border Integer}
168
-{taghead:border-width Integer}
169
-{taghead:border-width-top Integer}
170
-{taghead:border-width-right Integer}
171
-{taghead:border-width-bottom Integer}
172
-{taghead:border-width-left Integer}
173
-{taghead:border-color Color}
174
-{taghead:border-color-top Color}
175
-{taghead:border-color-right Color}
176
-{taghead:border-color-bottom Color}
177
-{taghead:border-color-left Color}
178
-{taghead:margin-top Integer}
179
-{taghead:margin-right Integer}
180
-{taghead:margin-bottom Integer}
181
-{taghead:margin-left Integer}
182
-{taghead:margin Integer}
183
-{taghead:padding-top Integer}
184
-{taghead:padding-right Integer}
185
-{taghead:padding-bottom Integer}
186
-{taghead:padding-left Integer}
187
-{taghead:padding Integer}
188
-{taghead:layout Layout}
189
-
190
-{taghead:image-source}
191
-{taghead:image-offset-x Integer}
192
-{taghead:image-offset-y Integer}
193
-{taghead:image-offset Point}
194
-{taghead:image-width Integer}
195
-{taghead:image-height Integer}
196
-{taghead:image-size Size}
197
-{taghead:image-rect Rect}
198
-{taghead:image-clip Rect}
199
-{taghead:image-fixed-ratio Boolean}
200
-{taghead:image-repeated Boolean}
201
-{taghead:image-smooth Boolean}
202
-{taghead:image-color Color}
203
-{taghead:image-border-top Integer}
204
-{taghead:image-border-right Integer}
205
-{taghead:image-border-bottom Integer}
206
-{taghead:image-border-left Integer}
207
-{taghead:image-border Integer}
208
-
209
-{taghead:text}
210
-{taghead:text-align Align}
211
-{taghead:text-offset Point}
212
-{taghead:text-wrap Boolean}
213
-{taghead:text-auto-resize Boolean}
214
-{taghead:font Font}
215
-
216
-## UITextEdit
217
-{taghead:text-margin}
218
-{taghead:always-active}
219
-{taghead:shift-navigation}
220
-{taghead:multiline}
221
-{taghead:max-length}
222
-

+ 0
- 477
doc/luafunctions.rb View File

@@ -1,477 +0,0 @@
1
-# @group Global functions
2
-
3
-# Converts rect to string
4
-# @return [Rect]
5
-def torect(str); end
6
-# Converts point to string
7
-# @return [Point]
8
-def topoint(str); end
9
-# Converts color to string
10
-# @return [Color]
11
-def tocolor(str); end
12
-# @return [Size]
13
-def tosize(str); end
14
-# @return [String]
15
-def recttostring(rect); end
16
-# @return [String]
17
-def pointtostring(point); end
18
-# @return [String]
19
-def colortostring(color); end
20
-# @return [String]
21
-def sizetostring(size); end
22
-
23
-# @endgroup
24
-
25
-
26
-# All classes used by the engine is derived from this class
27
-class LuaObject
28
-  # Return the number of references that this object have
29
-  # @return [Integer]
30
-  def getUseCount(); end
31
-  # Get the derived class name
32
-  # @return [String]
33
-  def getClassName(); end
34
-  # Return that hold all fields for this object
35
-  # @return [Table]
36
-  def getFieldsTable(); end
37
-end
38
-
39
-# Class that holds dispatcher events
40
-class Event < LuaObject
41
-  # Cancel the event execution
42
-  # @return [Void]
43
-  def cancel(); end
44
-  # Force event execution, as an event can only be executed once,
45
-  # it will not be executed again in the next poll
46
-  # @return [Void]
47
-  def execute(); end
48
-  # Checks if the event is canceled
49
-  # @return [Boolean]
50
-  def isCanceled(); end
51
-  # Check if the event is executed
52
-  # @return [Boolean]
53
-  def isExecuted(); end
54
-end
55
-
56
-# Class that holds dispatcher scheduled events
57
-class ScheduledEvent < Event
58
-  # Return ticks in milliseconds remaining to the event execution
59
-  # @return [Integer]
60
-  def reamaningTicks(); end
61
-  # Return ticks when this event will be executed
62
-  # @return [Integer]
63
-  def ticks(); end
64
-end
65
-
66
-# This is the base class for all UI elements
67
-class UIWidget < LuaObject
68
-  # Creates a new UIWidget
69
-  # @return [UIWidget]
70
-  def self.create(); end
71
-
72
-  def addChild(); end
73
-  def insertChild(); end
74
-  def removeChild(); end
75
-  def focusChild(); end
76
-  def focusNextChild(); end
77
-  def focusPreviousChild(); end
78
-  def lowerChild(); end
79
-  def raiseChild(); end
80
-  def moveChildToIndex(); end
81
-  def lockChild(); end
82
-  def unlockChild(); end
83
-  def mergeStyle(); end
84
-  def applyStyle(); end
85
-  def addAnchor(); end
86
-  def removeAnchor(); end
87
-  def fill(); end
88
-  def centerIn(); end
89
-  def breakAnchors(); end
90
-  def updateParentLayout(); end
91
-  def updateLayout(); end
92
-  def lock(); end
93
-  def unlock(); end
94
-  def focus(); end
95
-  def lower(); end
96
-  def raise(); end
97
-  def grabMouse(); end
98
-  def ungrabMouse(); end
99
-  def grabKeyboard(); end
100
-  def ungrabKeyboard(); end
101
-  def bindRectToParent(); end
102
-  def destroy(); end
103
-  def destroyChildren(); end
104
-  def setId(); end
105
-  def setParent(); end
106
-  def setLayout(); end
107
-  def setRect(); end
108
-  def setStyle(); end
109
-  def setStyleFromNode(); end
110
-  def setEnabled(); end
111
-  def setVisible(); end
112
-  def setOn(); end
113
-  def setChecked(); end
114
-  def setFocusable(); end
115
-  def setPhantom(); end
116
-  def setDragable(); end
117
-  def setFixedSize(); end
118
-  def setClipping(); end
119
-  def setLastFocusReason(); end
120
-  def setAutoRepeatDelay(); end
121
-  def setVirtualOffset(); end
122
-  def isVisible(); end
123
-  def isChildLocked(); end
124
-  def hasChild(); end
125
-  def getChildIndex(); end
126
-  def getMarginRect(); end
127
-  def getClippingRect(); end
128
-  def getChildrenRect(); end
129
-  def getAnchoredLayout(); end
130
-  def getRootParent(); end
131
-  def getChildAfter(); end
132
-  def getChildBefore(); end
133
-  def getChildById(); end
134
-  def getChildByPos(); end
135
-  def getChildByIndex(); end
136
-  def recursiveGetChildById(); end
137
-  def recursiveGetChildByPos(); end
138
-  def recursiveGetChildrenByPos(); end
139
-  def backwardsGetWidgetById(); end
140
-  def asUIWidget(); end
141
-  def resize(); end
142
-  def move(); end
143
-  def hide(); end
144
-  def show(); end
145
-  def disable(); end
146
-  def enable(); end
147
-  def isActive(); end
148
-  def isEnabled(); end
149
-  def isDisabled(); end
150
-  def isFocused(); end
151
-  def isHovered(); end
152
-  def isPressed(); end
153
-  def isFirst(); end
154
-  def isMiddle(); end
155
-  def isLast(); end
156
-  def isAlternate(); end
157
-  def isChecked(); end
158
-  def isOn(); end
159
-  def isDragging(); end
160
-  def isHidden(); end
161
-  def isExplicitlyEnabled(); end
162
-  def isExplicitlyVisible(); end
163
-  def isFocusable(); end
164
-  def isPhantom(); end
165
-  def isDragable(); end
166
-  def isFixedSize(); end
167
-  def isClipping(); end
168
-  def isDestroyed(); end
169
-  def hasChildren(); end
170
-  def containsPoint(); end
171
-  def getId(); end
172
-  def getParent(); end
173
-  def getFocusedChild(); end
174
-  def getChildren(); end
175
-  def getFirstChild(); end
176
-  def getLastChild(); end
177
-  def getLayout(); end
178
-  def getStyle(); end
179
-  def getChildCount(); end
180
-  def getLastFocusReason(); end
181
-  def getAutoRepeatDelay(); end
182
-  def getVirtualOffset(); end
183
-  def getStyleName(); end
184
-  def getLastClickPosition(); end
185
-  def setX(); end
186
-  def setY(); end
187
-  def setWidth(); end
188
-  def setHeight(); end
189
-  def setSize(); end
190
-  def setPosition(); end
191
-  def setColor(); end
192
-  def setBackgroundColor(); end
193
-  def setBackgroundOffsetX(); end
194
-  def setBackgroundOffsetY(); end
195
-  def setBackgroundOffset(); end
196
-  def setBackgroundWidth(); end
197
-  def setBackgroundHeight(); end
198
-  def setBackgroundSize(); end
199
-  def setBackgroundRect(); end
200
-  def setIcon(); end
201
-  def setIconColor(); end
202
-  def setIconOffsetX(); end
203
-  def setIconOffsetY(); end
204
-  def setIconOffset(); end
205
-  def setIconWidth(); end
206
-  def setIconHeight(); end
207
-  def setIconSize(); end
208
-  def setIconRect(); end
209
-  def setBorderWidth(); end
210
-  def setBorderWidthTop(); end
211
-  def setBorderWidthRight(); end
212
-  def setBorderWidthBottom(); end
213
-  def setBorderWidthLeft(); end
214
-  def setBorderColor(); end
215
-  def setBorderColorTop(); end
216
-  def setBorderColorRight(); end
217
-  def setBorderColorBottom(); end
218
-  def setBorderColorLeft(); end
219
-  def setMargin(); end
220
-  def setMarginHorizontal(); end
221
-  def setMarginVertical(); end
222
-  def setMarginTop(); end
223
-  def setMarginRight(); end
224
-  def setMarginBottom(); end
225
-  def setMarginLeft(); end
226
-  def setPadding(); end
227
-  def setPaddingHorizontal(); end
228
-  def setPaddingVertical(); end
229
-  def setPaddingTop(); end
230
-  def setPaddingRight(); end
231
-  def setPaddingBottom(); end
232
-  def setPaddingLeft(); end
233
-  def setOpacity(); end
234
-  def getX(); end
235
-  def getY(); end
236
-  def getPosition(); end
237
-  def getWidth(); end
238
-  def getHeight(); end
239
-  def getSize(); end
240
-  def getRect(); end
241
-  def getColor(); end
242
-  def getBackgroundColor(); end
243
-  def getBackgroundOffsetX(); end
244
-  def getBackgroundOffsetY(); end
245
-  def getBackgroundOffset(); end
246
-  def getBackgroundWidth(); end
247
-  def getBackgroundHeight(); end
248
-  def getBackgroundSize(); end
249
-  def getBackgroundRect(); end
250
-  def getIconColor(); end
251
-  def getIconOffsetX(); end
252
-  def getIconOffsetY(); end
253
-  def getIconOffset(); end
254
-  def getIconWidth(); end
255
-  def getIconHeight(); end
256
-  def getIconSize(); end
257
-  def getIconRect(); end
258
-  def getBorderTopColor(); end
259
-  def getBorderRightColor(); end
260
-  def getBorderBottomColor(); end
261
-  def getBorderLeftColor(); end
262
-  def getBorderTopWidth(); end
263
-  def getBorderRightWidth(); end
264
-  def getBorderBottomWidth(); end
265
-  def getBorderLeftWidth(); end
266
-  def getMarginTop(); end
267
-  def getMarginRight(); end
268
-  def getMarginBottom(); end
269
-  def getMarginLeft(); end
270
-  def getPaddingTop(); end
271
-  def getPaddingRight(); end
272
-  def getPaddingBottom(); end
273
-  def getPaddingLeft(); end
274
-  def getOpacity(); end
275
-  def setImageSource(); end
276
-  def setImageClip(); end
277
-  def setImageOffsetX(); end
278
-  def setImageOffsetY(); end
279
-  def setImageOffset(); end
280
-  def setImageWidth(); end
281
-  def setImageHeight(); end
282
-  def setImageSize(); end
283
-  def setImageRect(); end
284
-  def setImageColor(); end
285
-  def setImageFixedRatio(); end
286
-  def setImageRepeated(); end
287
-  def setImageSmooth(); end
288
-  def setImageBorderTop(); end
289
-  def setImageBorderRight(); end
290
-  def setImageBorderBottom(); end
291
-  def setImageBorderLeft(); end
292
-  def setImageBorder(); end
293
-  def getImageClip(); end
294
-  def getImageOffsetX(); end
295
-  def getImageOffsetY(); end
296
-  def getImageOffset(); end
297
-  def getImageWidth(); end
298
-  def getImageHeight(); end
299
-  def getImageSize(); end
300
-  def getImageRect(); end
301
-  def getImageColor(); end
302
-  def isImageFixedRatio(); end
303
-  def isImageSmooth(); end
304
-  def getImageBorderTop(); end
305
-  def getImageBorderRight(); end
306
-  def getImageBorderBottom(); end
307
-  def getImageBorderLeft(); end
308
-  def resizeToText(); end
309
-  def clearText(); end
310
-  def setText(); end
311
-  def setTextAlign(); end
312
-  def setTextOffset(); end
313
-  def setTextWrap(); end
314
-  def setTextAutoResize(); end
315
-  def setFont(); end
316
-  def getText(); end
317
-  def getDrawText(); end
318
-  def getTextAlign(); end
319
-  def getTextOffset(); end
320
-  def getTextWrap(); end
321
-  def getFont(); end
322
-  def getTextSize(); end
323
-
324
-  # @group Class Events
325
-
326
-  # Triggered when a style is applied to the widget
327
-  # @param styleName Name of the style
328
-  # @param styleNode Table containing all style tags and values
329
-  # @return [Void]
330
-  def onStyleApply(styleName, styleNode); end
331
-  # Triggered when widget size or position has changed
332
-  # @param oldRect Table containing the old geometry rect
333
-  # @param newRect Table containing the new geometry rect
334
-  # @return [Void]
335
-  def onGeometryChange(oldRect, newRect); end
336
-  # Triggered when widget's layout updates its contents
337
-  # @return [Void]
338
-  def onLayoutUpdate(); end
339
-  # Triggered when widget focus state changes
340
-  # @param focused Boolean representing the focus state
341
-  # @param reason One of the constants: *ActiveFocusReason* *MouseFocusReason* *KeyboardFocusReason*
342
-  # @return [Void]
343
-  def onFocusChange(focused, reason); end
344
-  # Triggered when child focus changes
345
-  # @return [Void]
346
-  def onChildFocusChange(focusedChild, unfocusedChild, reason); end
347
-  # Triggered when mouse enter or leaves widget area
348
-  # @return [Void]
349
-  def onHoverChange(hovered); end
350
-  # Triggered when this widget dragging begin
351
-  # @return [Boolean]
352
-  def onDragEnter(mousePos); end
353
-  # Triggered when this widget dragging end
354
-  # @return [Boolean]
355
-  def onDragLeave(droppedWidget, mousePos); end
356
-  # Triggered when moving mouse while in dragging state
357
-  # @return [Boolean]
358
-  def onDragMove(mousePos, mouseMoved); end
359
-  # Triggered when leaving other widget dragging state while the mouse is over this widget
360
-  # @return [Boolean]
361
-  def onDrop(draggedWidget, mousePos); end
362
-  # @return [Boolean]
363
-  def onKeyText(keyText); end
364
-  # @return [Boolean]
365
-  def onKeyDown(keyCode, keyboardModifiers); end
366
-  # @return [Boolean]
367
-  def onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks); end
368
-  # @return [Boolean]
369
-  def onKeyUp(keyCode, keyboardModifiers); end
370
-  # @return [Boolean]
371
-  def onMousePress(mousePos, utton); end
372
-  # @return [Boolean]
373
-  def onMouseRelease(mousePos, button); end
374
-  # @return [Boolean]
375
-  def onMouseMove(mousePos, mouseMoved); end
376
-  # @return [Boolean]
377
-  def onMouseWheel(mousePos, direction); end
378
-  # Triggered when clicking and releasing the mouse left button inside widget area
379
-  # @return [Boolean]
380
-  def onClick(mousePos); end
381
-  # Triggered when pressing mouse left button two times inside widget area
382
-  # @return [Boolean]
383
-  def onDoubleClick(mousePos); end
384
-
385
-  # @endgroup
386
-end
387
-
388
-class g_game
389
-  def self.login(); end
390
-  def self.logout(); end
391
-  def self.loginWorld(); end
392
-  def self.cancelLogin(); end
393
-  def self.forceLogout(); end
394
-  def self.safeLogout(); end
395
-  def self.walk(); end
396
-  def self.autoWalk(); end
397
-  def self.forceWalk(); end
398
-  def self.turn(); end
399
-  def self.stop(); end
400
-  def self.look(); end
401
-  def self.move(); end
402
-  def self.moveToParentContainer(); end
403
-  def self.rotate(); end
404
-  def self.use(); end
405
-  def self.useWith(); end
406
-  def self.useInventoryItem(); end
407
-  def self.useInventoryItemWith(); end
408
-  def self.open(); end
409
-  def self.openParent(); end
410
-  def self.close(); end
411
-  def self.refreshContainer(); end
412
-  def self.attack(); end
413
-  def self.cancelAttack(); end
414
-  def self.follow(); end
415
-  def self.cancelFollow(); end
416
-  def self.cancelAttackAndFollow(); end
417
-  def self.talk(); end
418
-  def self.talkChannel(); end
419
-  def self.talkPrivate(); end
420
-  def self.openPrivateChannel(); end
421
-  def self.requestChannels(); end
422
-  def self.joinChannel(); end
423
-  def self.leaveChannel(); end
424
-  def self.closeNpcChannel(); end
425
-  def self.openOwnChannel(); end
426
-  def self.inviteToOwnChannel(); end
427
-  def self.excludeFromOwnChannel(); end
428
-  def self.partyInvite(); end
429
-  def self.partyJoin(); end
430
-  def self.partyRevokeInvitation(); end
431
-  def self.partyPassLeadership(); end
432
-  def self.partyLeave(); end
433
-  def self.partyShareExperience(); end
434
-  def self.requestOutfit(); end
435
-  def self.changeOutfit(); end
436
-  def self.addVip(); end
437
-  def self.removeVip(); end
438
-  def self.setChaseMode(); end
439
-  def self.setFightMode(); end
440
-  def self.setSafeFight(); end
441
-  def self.getChaseMode(); end
442
-  def self.getFightMode(); end
443
-  def self.isSafeFight(); end
444
-  def self.inspectNpcTrade(); end
445
-  def self.buyItem(); end
446
-  def self.sellItem(); end
447
-  def self.closeNpcTrade(); end
448
-  def self.requestTrade(); end
449
-  def self.inspectTrade(); end
450
-  def self.acceptTrade(); end
451
-  def self.rejectTrade(); end
452
-  def self.reportBug(); end
453
-  def self.reportRuleVilation(); end
454
-  def self.debugReport(); end
455
-  def self.editText(); end
456
-  def self.editList(); end
457
-  def self.requestQuestLog(); end
458
-  def self.requestQuestLine(); end
459
-  def self.canPerformGameAction(); end
460
-  def self.canReportBugs(); end
461
-  def self.checkBotProtection(); end
462
-  def self.isOnline(); end
463
-  def self.isDead(); end
464
-  def self.isAttacking(); end
465
-  def self.isFollowing(); end
466
-  def self.getContainer(); end
467
-  def self.getContainers(); end
468
-  def self.getVips(); end
469
-  def self.getAttackingCreature(); end
470
-  def self.getFollowingCreature(); end
471
-  def self.getServerBeat(); end
472
-  def self.getLocalPlayer(); end
473
-  def self.getProtocolGame(); end
474
-  def self.getProtocolVersion(); end
475
-  def self.getWorldName(); end
476
-  def self.getGMActions(); end
477
-end

+ 0
- 27
doc/plugin.rb View File

@@ -1,27 +0,0 @@
1
-include YARD
2
-include Templates
3
-
4
-module MyTemplateHelper
5
-  def linkify(*args)
6
-    if args.first.is_a?(String)
7
-      case args.first
8
-      when /^taghead:(\S+)/
9
-        tag_name = $1
10
-        params = args[1]
11
-        return "<h3 class=\"note\" id=\"#{tag_name}\" toc-title=\"#{tag_name}\"><strong>#{tag_name}:</strong> #{params}</h3>"
12
-      when /^valhead:(\S+)/
13
-        tag_name = $1
14
-        return "<h3 class=\"note private\" id=\"#{tag_name}\" toc-title=\"#{tag_name}\"><strong>#{tag_name}</strong></h3>"
15
-      when /^tag:(\S+)/
16
-        tag_name = $1
17
-        return "<a href=\"##{tag_name}\">#{tag_name}</a>"
18
-      else
19
-          super
20
-      end
21
-    end
22
-    super
23
-  end
24
-end
25
-
26
-Template.extra_includes << MyTemplateHelper
27
-Engine.register_template_path(File.dirname(__FILE__))

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

@@ -4,7 +4,8 @@ function Client.reloadScripts()
4 4
   g_modules.reloadModules()
5 5
   dofile '/otclientrc'
6 6
   local message = tr('All modules and scripts were reloaded.')
7
-  TextMessage.displayEventAdvance(message)
7
+
8
+  modules.game_textmessage.displayEventAdvance(message)
8 9
   print(message)
9 10
 end
10 11
 

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

@@ -137,7 +137,7 @@ function Options.setOption(key, value)
137 137
     g_sounds.enableMusic(value)
138 138
   elseif key == 'showLeftPanel' then
139 139
     addEvent(function()
140
-      GameInterface.getLeftPanel():setOn(value)
140
+      modules.game_interface.getLeftPanel():setOn(value)
141 141
     end)
142 142
   elseif key == 'backgroundFrameRate' then
143 143
     local text = value

+ 1
- 0
modules/corelib/globals.lua View File

@@ -2,6 +2,7 @@
2 2
 
3 3
 -- root widget
4 4
 rootWidget = g_ui.getRootWidget()
5
+modules = package.loaded
5 6
 
6 7
 -- G is used as a global table to save variables in memory between reloads
7 8
 G = G or {}

+ 19
- 1
modules/corelib/util.lua View File

@@ -36,7 +36,17 @@ function quit()
36 36
   g_app.quit()
37 37
 end
38 38
 
39
-function connect(object, signalsAndSlots, pushFront)
39
+function connect(object, arg1, arg2, arg3)
40
+  local signalsAndSlots
41
+  local pushFront
42
+  if type(arg1) == 'string' then
43
+    signalsAndSlots = { [arg1] = arg2 }
44
+    pushFront = arg3
45
+  else
46
+    signalsAndSlots = arg1
47
+    pushFront = arg2
48
+  end
49
+
40 50
   for signal,slot in pairs(signalsAndSlots) do
41 51
     if not object[signal] then
42 52
       local mt = getmetatable(object)
@@ -150,6 +160,14 @@ local function module_loader(modname)
150 160
 end
151 161
 table.insert(package.loaders, 1, module_loader)
152 162
 
163
+function import(table)
164
+  assert(type(table) == 'table')
165
+  local env = getfenv(2)
166
+  for k,v in pairs(table) do
167
+    env[k] = v
168
+  end
169
+end
170
+
153 171
 function export(what, key)
154 172
   if key ~= nil then
155 173
     _G[key] = what

+ 74
- 90
modules/game_battle/battle.lua View File

@@ -1,45 +1,41 @@
1
-Battle = {}
2
-
3 1
 --TODO
4 2
 --onCreatureAppears onCreatureHealthChange onCreatureDisappears
5 3
 --reloadable/disconnects
6 4
 
7
-local battleWindow
8
-local battleButton
9
-local battlePanel
10
-local lastBattleButtonSwitched
11
-local checkCreaturesEvent
12
-local battleButtonsByCreaturesList = {}
5
+battleWindow = nil
6
+battleButton = nil
7
+battlePanel = nil
8
+lastBattleButtonSwitched = nil
9
+checkCreaturesEvent = nil
10
+battleButtonsByCreaturesList = {}
13 11
 
14
-local mouseWidget
12
+mouseWidget = nil
15 13
 
16
-local hidePlayersButton
17
-local hideNPCsButton
18
-local hideMonstersButton
19
-local hideSkullsButton
20
-local hidePartyButton
14
+hidePlayersButton = nil
15
+hideNPCsButton = nil
16
+hideMonstersButton = nil
17
+hideSkullsButton = nil
18
+hidePartyButton = nil
21 19
 
22
-local battleButtonColors = {
20
+BattleButtonColors = {
23 21
   onIdle = {notHovered = '#888888', hovered = '#FFFFFF' },
24 22
   onTargeted = {notHovered = '#FF0000', hovered = '#FF8888' },
25 23
   onFollowed = {notHovered = '#00FF00', hovered = '#88FF88' }
26 24
 }
27 25
 
28
-local lifeBarColors = {} --Must be sorted by percentAbose
29
-table.insert(lifeBarColors, {percentAbove = 92, color = '#00BC00' } )
30
-table.insert(lifeBarColors, {percentAbove = 60, color = '#50A150' } )
31
-table.insert(lifeBarColors, {percentAbove = 30, color = '#A1A100' } )
32
-table.insert(lifeBarColors, {percentAbove = 8, color = '#3C2727' } )
33
-table.insert(lifeBarColors, {percentAbove = 3, color = '#3C0000' } )
34
-table.insert(lifeBarColors, {percentAbove = -1, color = '#4F0000' } )
35
-
36
-function Battle.init()
37
-  battleWindow = g_ui.loadUI('battle.otui', GameInterface.getRightPanel())
38
-  battleButton = TopMenu.addRightGameToggleButton('battleButton', tr('Battle') .. ' (Ctrl+B)', 'battle.png', Battle.toggle)
26
+LifeBarColors = {} --Must be sorted by percentAbose
27
+table.insert(LifeBarColors, {percentAbove = 92, color = '#00BC00' } )
28
+table.insert(LifeBarColors, {percentAbove = 60, color = '#50A150' } )
29
+table.insert(LifeBarColors, {percentAbove = 30, color = '#A1A100' } )
30
+table.insert(LifeBarColors, {percentAbove = 8, color = '#3C2727' } )
31
+table.insert(LifeBarColors, {percentAbove = 3, color = '#3C0000' } )
32
+table.insert(LifeBarColors, {percentAbove = -1, color = '#4F0000' } )
33
+
34
+function init()
35
+  battleWindow = g_ui.loadUI('battle.otui', modules.game_interface.getRightPanel())
36
+  battleButton = TopMenu.addRightGameToggleButton('battleButton', tr('Battle') .. ' (Ctrl+B)', 'battle.png', toggle)
39 37
   battleButton:setOn(true)
40
-  g_keyboard.bindKeyDown('Ctrl+B', Battle.toggle)
38
+  g_keyboard.bindKeyDown('Ctrl+B', toggle)
41 39
 
42 40
   battlePanel = battleWindow:recursiveGetChildById('battlePanel')
43 41
 
@@ -53,46 +49,32 @@ function Battle.init()
53 49
   mouseWidget:setVisible(false)
54 50
   mouseWidget:setFocusable(false)
55 51
 
56
-  connect(Creature, { onSkullChange = Battle.checkCreatureSkull,
57
-                      onEmblemChange = Battle.checkCreatureEmblem } )
52
+  connect(Creature, { onSkullChange = checkCreatureSkull,
53
+                      onEmblemChange = checkCreatureEmblem } )
58 54
 
59
-  connect(g_game, { onAttackingCreatureChange = Battle.onAttack,
60
-                    onFollowingCreatureChange = Battle.onFollow,
61
-                    onGameEnd = Battle.removeAllCreatures } )
55
+  connect(g_game, { onAttackingCreatureChange = onAttack,
56
+                    onFollowingCreatureChange = onFollow,
57
+                    onGameEnd = removeAllCreatures } )
62 58
 
63
-  addEvent(Battle.addAllCreatures)
64
-  checkCreaturesEvent = scheduleEvent(Battle.checkCreatures, 200)
59
+  addEvent(addAllCreatures)
60
+  checkCreaturesEvent = scheduleEvent(checkCreatures, 200)
65 61
 end
66 62
 
67
-function Battle.terminate()
63
+function terminate()
68 64
   g_keyboard.unbindKeyDown('Ctrl+B')
69
-  battlePanel = nil
70
-  lastBattleButtonTargeted = nil
71
-  lastBattleButtonFollowed = nil
72 65
   battleButtonsByCreaturesList = {}
73 66
   removeEvent(checkCreaturesEvent)
74
-  hidePlayersButton = nil
75
-  hideNPCsButton = nil
76
-  hideMonstersButton = nil
77
-  hideSkullsButton = nil
78
-  hidePartyButton = nil
79
-  checkCreaturesEvent = nil
80 67
   battleButton:destroy()
81
-  battleButton = nil
82 68
   battleWindow:destroy()
83
-  battleWindow = nil
84 69
   mouseWidget:destroy()
85
-  mouseWidget = nil
86
-
87
-  disconnect(Creature, { onSkullChange = Battle.checkCreatureSkull,
88
-                          onEmblemChange = Battle.checkCreatureEmblem } )
89 70
 
90
-  disconnect(g_game, { onAttackingCreatureChange = Battle.onAttack } )
71
+  disconnect(Creature, { onSkullChange = checkCreatureSkull,
72
+                          onEmblemChange = checkCreatureEmblem } )
91 73
 
92
-  Battle = nil
74
+  disconnect(g_game, { onAttackingCreatureChange = onAttack } )
93 75
 end
94 76
 
95
-function Battle.toggle()
77
+function toggle()
96 78
   if battleButton:isOn() then
97 79
     battleWindow:close()
98 80
     battleButton:setOn(false)
@@ -102,28 +84,28 @@ function Battle.toggle()
102 84
   end
103 85
 end
104 86
 
105
-function Battle.onMiniWindowClose()
87
+function onMiniWindowClose()
106 88
   battleButton:setOn(false)
107 89
 end
108 90
 
109
-function Battle.addAllCreatures()
91
+function addAllCreatures()
110 92
   local spectators = {}
111 93
     local player = g_game.getLocalPlayer()
112 94
     if player then
113 95
         creatures = g_map.getSpectators(player:getPosition(), false)
114 96
         for i, creature in ipairs(creatures) do
115
-            if creature ~= player and Battle.doCreatureFitFilters(creature) then
97
+            if creature ~= player and doCreatureFitFilters(creature) then
116 98
               table.insert(spectators, creature)
117 99
             end
118 100
         end
119 101
     end
120 102
 
121 103
   for i, v in pairs(spectators) do
122
-    Battle.addCreature(v)
104
+    addCreature(v)
123 105
   end
124 106
 end
125 107
 
126
-function Battle.doCreatureFitFilters(creature)
108
+function doCreatureFitFilters(creature)
127 109
   local hidePlayers = hidePlayersButton:isChecked()
128 110
   local hideNPCs = hideNPCsButton:isChecked()
129 111
   local hideMonsters = hideMonstersButton:isChecked()
@@ -145,7 +127,7 @@ function Battle.doCreatureFitFilters(creature)
145 127
   return true
146 128
 end
147 129
 
148
-function Battle.checkCreatures(forceRecheck)
130
+function checkCreatures(forceRecheck)
149 131
   local player = g_game.getLocalPlayer()
150 132
   if player then
151 133
     local spectators = {}
@@ -154,20 +136,20 @@ function Battle.checkCreatures(forceRecheck)
154 136
     local creaturesAppeared = {}
155 137
     creatures = g_map.getSpectators(player:getPosition(), false)
156 138
     for i, creature in ipairs(creatures) do
157
-      if creature ~= player and Battle.doCreatureFitFilters(creature) then
139
+      if creature ~= player and doCreatureFitFilters(creature) then
158 140
         -- searching for creatures that appeared on battle list
159 141
         local battleButton = battleButtonsByCreaturesList[creature:getId()]
160 142
         if battleButton == nil then
161 143
           table.insert(creaturesAppeared, creature)
162 144
         else
163
-          Battle.setLifeBarPercent(battleButton, creature:getHealthPercent())
145
+          setLifeBarPercent(battleButton, creature:getHealthPercent())
164 146
         end
165 147
         spectators[creature:getId()] = creature
166 148
       end
167 149
     end
168 150
 
169 151
     for i, v in pairs(creaturesAppeared) do
170
-      Battle.addCreature(v)
152
+      addCreature(v)
171 153
     end
172 154
 
173 155
     -- searching for creatures that disappeared from battle list
@@ -179,15 +161,15 @@ function Battle.checkCreatures(forceRecheck)
179 161
     end
180 162
 
181 163
     for i, v in pairs(creaturesDisappeared) do
182
-      Battle.removeCreature(v)
164
+      removeCreature(v)
183 165
     end
184 166
   end
185 167
   if not forceRecheck then
186
-    checkCreaturesEvent = scheduleEvent(Battle.checkCreatures, 500)
168
+    checkCreaturesEvent = scheduleEvent(checkCreatures, 500)
187 169
   end
188 170
 end
189 171
 
190
-function Battle.addCreature(creature)
172
+function addCreature(creature)
191 173
   local creatureId = creature:getId()
192 174
 
193 175
   if battleButtonsByCreaturesList[creatureId] == nil then
@@ -205,16 +187,16 @@ function Battle.addCreature(creature)
205 187
 
206 188
     labelWidget:setText(creature:getName())
207 189
     creatureWidget:setCreature(creature)
208
-    Battle.setLifeBarPercent(battleButton, creature:getHealthPercent())
190
+    setLifeBarPercent(battleButton, creature:getHealthPercent())
209 191
 
210 192
     battleButtonsByCreaturesList[creatureId] = battleButton
211 193
 
212
-    Battle.checkCreatureSkull(battleButton.creature)
213
-    Battle.checkCreatureEmblem(battleButton.creature)
194
+    checkCreatureSkull(battleButton.creature)
195
+    checkCreatureEmblem(battleButton.creature)
214 196
   end
215 197
 end
216 198
 
217
-function Battle.checkCreatureSkull(creature, skullId)
199
+function checkCreatureSkull(creature, skullId)
218 200
     local battleButton = battleButtonsByCreaturesList[creature:getId()]
219 201
     if battleButton then
220 202
       local skullWidget = battleButton:getChildById('skull')
@@ -235,7 +217,7 @@ function Battle.checkCreatureSkull(creature, skullId)
235 217
     end
236 218
 end
237 219
 
238
-function Battle.checkCreatureEmblem(creature, emblemId)
220
+function checkCreatureEmblem(creature, emblemId)
239 221
     local battleButton = battleButtonsByCreaturesList[creature:getId()]
240 222
     if battleButton then
241 223
       local emblemId = emblemId or creature:getEmblem()
@@ -259,9 +241,9 @@ function Battle.checkCreatureEmblem(creature, emblemId)
259 241
     end
260 242
 end
261 243
 
262
-function Battle.onMouseRelease(self, mousePosition, mouseButton)
244
+function onMouseRelease(self, mousePosition, mouseButton)
263 245
   if mouseButton == MouseRightButton then
264
-    GameInterface.createThingMenu(mousePosition, nil, nil, self.creature)
246
+    modules.game_interface.createThingMenu(mousePosition, nil, nil, self.creature)
265 247
     return true
266 248
   elseif mouseButton == MouseLeftButton then
267 249
     if g_keyboard.isShiftPressed() then
@@ -277,13 +259,13 @@ function Battle.onMouseRelease(self, mousePosition, mouseButton)
277 259
   end
278 260
 end
279 261
 
280
-function Battle.removeAllCreatures()
262
+function removeAllCreatures()
281 263
   for i, v in pairs(battleButtonsByCreaturesList) do
282
-    Battle.removeCreature(v.creature)
264
+    removeCreature(v.creature)
283 265
   end
284 266
 end
285 267
 
286
-function Battle.removeCreature(creature)
268
+function removeCreature(creature)
287 269
   local creatureId = creature:getId()
288 270
 
289 271
   if battleButtonsByCreaturesList[creatureId] ~= nil then
@@ -297,12 +279,12 @@ function Battle.removeCreature(creature)
297 279
   end
298 280
 end
299 281
 
300
-function Battle.setLifeBarPercent(battleButton, percent)
282
+function setLifeBarPercent(battleButton, percent)
301 283
   local lifeBarWidget = battleButton:getChildById('lifeBar')
302 284
   lifeBarWidget:setPercent(percent)
303 285
 
304 286
   local color
305
-  for i, v in pairs(lifeBarColors) do
287
+  for i, v in pairs(LifeBarColors) do
306 288
     if percent > v.percentAbove then
307 289
       color = v.color
308 290
       break
@@ -312,37 +294,37 @@ function Battle.setLifeBarPercent(battleButton, percent)
312 294
   lifeBarWidget:setBackgroundColor(color)
313 295
 end
314 296
 
315
-function Battle.onbattleButtonHoverChange(widget, hovered)
297
+function onbattleButtonHoverChange(widget, hovered)
316 298
   if widget.isBattleButton then
317 299
     widget.isHovered = hovered
318
-    Battle.checkBattleButton(widget)
300
+    checkBattleButton(widget)
319 301
   end
320 302
 end
321 303
 
322
-function Battle.onAttack(creature)
323
-  Battle.checkCreatures(true) --Force recheck
304
+function onAttack(creature)
305
+  checkCreatures(true) --Force recheck
324 306
   local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched
325 307
   if battleButton then
326 308
     battleButton.isTarget = creature and true or false
327
-    Battle.checkBattleButton(battleButton)
309
+    checkBattleButton(battleButton)
328 310
   end
329 311
 end
330 312
 
331
-function Battle.onFollow(creature)
332
-  Battle.checkCreatures(true) --Force recheck
313
+function onFollow(creature)
314
+  checkCreatures(true) --Force recheck
333 315
   local battleButton = creature and battleButtonsByCreaturesList[creature:getId()] or lastBattleButtonSwitched
334 316
   if battleButton then
335 317
     battleButton.isFollowed = creature and true or false
336
-    Battle.checkBattleButton(battleButton)
318
+    checkBattleButton(battleButton)
337 319
   end
338 320
 end
339 321
 
340
-function Battle.checkBattleButton(battleButton)
341
-  local color = battleButtonColors.onIdle
322
+function checkBattleButton(battleButton)
323
+  local color = BattleButtonColors.onIdle
342 324
   if battleButton.isTarget then
343
-    color = battleButtonColors.onTargeted
325
+    color = BattleButtonColors.onTargeted
344 326
   elseif battleButton.isFollowed then
345
-    color = battleButtonColors.onFollowed
327
+    color = BattleButtonColors.onFollowed
346 328
   end
347 329
 
348 330
   color = battleButton.isHovered and color.hovered or color.notHovered
@@ -363,7 +345,7 @@ function Battle.checkBattleButton(battleButton)
363 345
     if lastBattleButtonSwitched and lastBattleButtonSwitched ~= battleButton then
364 346
       lastBattleButtonSwitched.isTarget = false
365 347
       lastBattleButtonSwitched.isFollowed = false
366
-      Battle.checkBattleButton(lastBattleButtonSwitched)
348
+      checkBattleButton(lastBattleButtonSwitched)
367 349
     end
368 350
     lastBattleButtonSwitched = battleButton
369 351
   end

+ 4
- 12
modules/game_battle/battle.otmod View File

@@ -3,15 +3,7 @@ Module
3 3
   description: Manage battle window
4 4
   author: andrefaramir, BeniS
5 5
   website: www.otclient.info
6
-  icon: battle.png
7
-
8
-  dependencies:
9
-    - game_interface
10
-
11
-  @onLoad: |
12
-    dofile 'battle'
13
-    Battle.init()
14
-
15
-  @onUnload: |
16
-    Battle.terminate()
17
-
6
+  sandboxed: true
7
+  scripts: [ battle.lua ]
8
+  @onLoad: init()
9
+  @onUnload: terminate()

+ 1
- 1
modules/game_battle/battle.otui View File

@@ -41,7 +41,7 @@ MiniWindow
41 41
   !text: tr('Battle')
42 42
   height: 166
43 43
   icon: battle.png
44
-  @onClose: Battle.onMiniWindowClose()
44
+  @onClose: onMiniWindowClose()
45 45
   &save: true
46 46
 
47 47
   MiniWindowContents

+ 2
- 2
modules/game_battle/battlebutton.otui View File

@@ -4,8 +4,8 @@ BattleButton
4 4
   height: 20
5 5
   margin-top: 5
6 6
   fixed-size: true
7
-  &onHoverChange: Battle.onbattleButtonHoverChange
8
-  &onMouseRelease: Battle.onMouseRelease
7
+  &onHoverChange: onbattleButtonHoverChange
8
+  &onMouseRelease: onMouseRelease
9 9
   &isBattleButton: true
10 10
 
11 11
   UICreature

+ 9
- 12
modules/game_bugreport/bugreport.lua View File

@@ -1,10 +1,9 @@
1
-BugReport = {}
1
+HOTKEY = 'Ctrl+Z'
2 2
 
3
-local bugReportWindow
4
-local bugTextEdit
5
-local HOTKEY = 'Ctrl+Z'
3
+bugReportWindow = nil
4
+bugTextEdit = nil
6 5
 
7
-function BugReport.init()
6
+function init()
8 7
   g_ui.importStyle('bugreport.otui')
9 8
 
10 9
   bugReportWindow = g_ui.createWidget('BugReportWindow', rootWidget)
@@ -12,23 +11,21 @@ function BugReport.init()
12 11
 
13 12
   bugTextEdit = bugReportWindow:getChildById('bugTextEdit')
14 13
 
15
-  g_keyboard.bindKeyDown(HOTKEY, BugReport.show)
14
+  g_keyboard.bindKeyDown(HOTKEY, show)
16 15
 end
17 16
 
18
-function BugReport.terminate()
17
+function terminate()
19 18
   g_keyboard.unbindKeyDown(HOTKEY)
20 19
   bugReportWindow:destroy()
21
-  bugReportWindow = nil
22
-  bugTextEdit = nil
23 20
 end
24 21
 
25
-function BugReport.doReport()
22
+function doReport()
26 23
   g_game.reportBug(bugTextEdit:getText())
27 24
   bugReportWindow:hide()
28
-  TextMessage.displayEventAdvance(tr('Bug report sent.'))
25
+  modules.game_textmessage.displayEventAdvance(tr('Bug report sent.'))
29 26
 end
30 27
 
31
-function BugReport.show()
28
+function show()
32 29
   bugTextEdit:setText('')
33 30
   bugReportWindow:show()
34 31
   bugReportWindow:raise()

+ 4
- 10
modules/game_bugreport/bugreport.otmod View File

@@ -3,13 +3,7 @@ Module
3 3
   description: Bug report interface (Ctrl+Z)
4 4
   author: edubart
5 5
   website: www.otclient.info
6
-
7
-  dependencies:
8
-    - game_interface
9
-
10
-  @onLoad: |
11
-    dofile 'bugreport'
12
-    BugReport.init()
13
-
14
-  @onUnload: |
15
-    BugReport.terminate()
6
+  scripts: [ bugreport.lua ]
7
+  sandboxed: true
8
+  @onLoad: init()
9
+  @onUnload: terminate()

+ 1
- 1
modules/game_bugreport/bugreport.otui View File

@@ -28,7 +28,7 @@ BugReportWindow < MainWindow
28 28
     anchors.right: cancelButton.left
29 29
     margin-right: 10
30 30
     width: 80
31
-    &onClick: BugReport.doReport
31
+    &onClick: doReport
32 32
 
33 33
   Button
34 34
     id: cancelButton

+ 62
- 77
modules/game_combatcontrols/combatcontrols.lua View File

@@ -1,49 +1,16 @@
1
-CombatControls = {}
2
-
3
-local combatControlsButton
4
-local combatControlsWindow
5
-local fightOffensiveBox
6
-local fightBalancedBox
7
-local fightDefensiveBox
8
-local chaseModeButton
9
-local safeFightButton
10
-local fightModeRadioGroup
11
-
12
-local function onSetFightMode(self, selectedFightButton)
13
-  if selectedFightButton == nil then return end
14
-  local buttonId = selectedFightButton:getId()
15
-  local fightMode
16
-  if buttonId == 'fightOffensiveBox' then
17
-    fightMode = FightOffensive
18
-  elseif buttonId == 'fightBalancedBox' then
19
-    fightMode = FightBalanced
20
-  else
21
-    fightMode = FightDefensive
22
-  end
23
-  g_game.setFightMode(fightMode)
24
-end
25
-
26
-local function onSetChaseMode(self, checked)
27
-  local chaseMode
28
-  if checked then
29
-    chaseMode = ChaseOpponent
30
-  else
31
-    chaseMode = DontChase
32
-  end
33
-  g_game.setChaseMode(chaseMode)
34
-end
35
-
36
-local function onSetSafeFight(self, checked)
37
-  g_game.setSafeFight(not checked)
38
-end
39
-
40
-function CombatControls.init()
41
-  combatControlsButton = TopMenu.addRightGameToggleButton('combatControlsButton', tr('Combat Controls'), 'combatcontrols.png', CombatControls.toggle)
1
+combatControlsButton = nil
2
+combatControlsWindow = nil
3
+fightOffensiveBox = nil
4
+fightBalancedBox = nil
5
+fightDefensiveBox = nil
6
+chaseModeButton = nil
7
+safeFightButton = nil
8
+fightModeRadioGroup = nil
9
+
10
+function init()
11
+  combatControlsButton = TopMenu.addRightGameToggleButton('combatControlsButton', tr('Combat Controls'), 'combatcontrols.png', toggle)
42 12
   combatControlsButton:setOn(true)
43
-  combatControlsWindow = g_ui.loadUI('combatcontrols.otui', GameInterface.getRightPanel())
13
+  combatControlsWindow = g_ui.loadUI('combatcontrols.otui', modules.game_interface.getRightPanel())
44 14
   combatControlsWindow:disableResize()
45 15
 
46 16
   fightOffensiveBox = combatControlsWindow:recursiveGetChildById('fightOffensiveBox')
@@ -61,52 +28,39 @@ function CombatControls.init()
61 28
   connect(chaseModeButton, { onCheckChange = onSetChaseMode })
62 29
   connect(safeFightButton, { onCheckChange = onSetSafeFight })
63 30
   connect(g_game, {
64
-    onGameStart = CombatControls.online,
65
-    onGameEnd = CombatControls.offline,
66
-    onFightModeChange = CombatControls.update,
67
-    onChaseModeChange = CombatControls.update,
68
-    onSafeFightChange = CombatControls.update,
69
-    onWalk = CombatControls.check
31
+    onGameStart = online,
32
+    onGameEnd = offline,
33
+    onFightModeChange = update,
34
+    onChaseModeChange = update,
35
+    onSafeFightChange = update,
36
+    onWalk = check
70 37
   })
71 38
 
72 39
   if g_game.isOnline() then
73
-    CombatControls.online()
40
+    online()
74 41
   end
75 42
 end
76 43
 
77
-function CombatControls.terminate()
44
+function terminate()
78 45
   if g_game.isOnline() then
79
-    CombatControls.offline()
46
+    offline()
80 47
   end
81 48
 
82 49
   fightModeRadioGroup:destroy()
83
-  fightModeRadioGroup = nil
84
-
85
-  fightOffensiveBox = nil
86
-  fightBalancedBox = nil
87
-  fightDefensiveBox = nil
88
-  chaseModeButton = nil
89
-  safeFightButton = nil
90
-
91 50
   combatControlsButton:destroy()
92
-  combatControlsButton = nil
93
-
94 51
   combatControlsWindow:destroy()
95
-  combatControlsWindow = nil
96 52
 
97 53
   disconnect(g_game, {
98
-    onGameStart = CombatControls.online,
99
-    onGameEnd = CombatControls.offline,
100
-    onFightModeChange = CombatControls.update,
101
-    onChaseModeChange = CombatControls.update,
102
-    onSafeFightChange = CombatControls.update,
103
-    onWalk = CombatControls.check
54
+    onGameStart = online,
55
+    onGameEnd = offline,
56
+    onFightModeChange = update,
57
+    onChaseModeChange = update,
58
+    onSafeFightChange = update,
59
+    onWalk = check
104 60
   })
105
-
106
-  CombatControls = nil
107 61
 end
108 62
 
109
-function CombatControls.update()
63
+function update()
110 64
   local fightMode = g_game.getFightMode()
111 65
   if fightMode == FightOffensive then
112 66
     fightModeRadioGroup:selectWidget(fightOffensiveBox)
@@ -123,7 +77,7 @@ function CombatControls.update()
123 77
   safeFightButton:setChecked(not safeFight)
124 78
 end
125 79
 
126
-function CombatControls.check()
80
+function check()
127 81
   if(Options.getOption('autoChaseOverride')) then
128 82
     if(g_game.isAttacking() and g_game.getChaseMode() == ChaseOpponent) then
129 83
       g_game.setChaseMode(DontChase)
@@ -131,7 +85,7 @@ function CombatControls.check()
131 85
   end
132 86
 end
133 87
 
134
-function CombatControls.online()
88
+function online()
135 89
   local player = g_game.getLocalPlayer()
136 90
   if(player) then
137 91
     local char = player:getName()
@@ -148,10 +102,10 @@ function CombatControls.online()
148 102
   end
149 103
 
150 104
   combatControlsWindow:setVisible(combatControlsButton:isOn())
151
-  CombatControls.update()
105
+  update()
152 106
 end
153 107
 
154
-function CombatControls.offline()
108
+function offline()
155 109
   local lastCombatControls = g_settings.getNode('LastCombatControls')
156 110
   if(not lastCombatControls) then
157 111
     lastCombatControls = {}
@@ -171,7 +125,7 @@ function CombatControls.offline()
171 125
   end
172 126
 end
173 127
 
174
-function CombatControls.toggle()
128
+function toggle()
175 129
   if combatControlsButton:isOn() then
176 130
     combatControlsWindow:close()
177 131
     combatControlsButton:setOn(false)
@@ -181,6 +135,34 @@ function CombatControls.toggle()
181 135
   end
182 136
 end
183 137
 
184
-function CombatControls.onMiniWindowClose()
138
+function onMiniWindowClose()
185 139
   combatControlsButton:setOn(false)
186 140
 end
141
+
142
+function onSetFightMode(self, selectedFightButton)
143
+  if selectedFightButton == nil then return end
144
+  local buttonId = selectedFightButton:getId()
145
+  local fightMode
146
+  if buttonId == 'fightOffensiveBox' then
147
+    fightMode = FightOffensive
148
+  elseif buttonId == 'fightBalancedBox' then
149
+    fightMode = FightBalanced
150
+  else
151
+    fightMode = FightDefensive
152
+  end
153
+  g_game.setFightMode(fightMode)
154
+end
155
+
156
+function onSetChaseMode(self, checked)
157
+  local chaseMode
158
+  if checked then
159
+    chaseMode = ChaseOpponent
160
+  else
161
+    chaseMode = DontChase
162
+  end
163
+  g_game.setChaseMode(chaseMode)
164
+end
165
+
166
+function onSetSafeFight(self, checked)
167
+  g_game.setSafeFight(not checked)
168
+end

+ 4
- 10
modules/game_combatcontrols/combatcontrols.otmod View File

@@ -3,13 +3,7 @@ Module
3 3
   description: Combat controls window
4 4
   author: edubart, BeniS
5 5
   website: www.otclient.info
6
-
7
-  dependencies:
8
-    - game_interface
9
-
10
-  @onLoad: |
11
-    dofile 'combatcontrols'
12
-    CombatControls.init()
13
-
14
-  @onUnload: |
15
-    CombatControls.terminate()
6
+  sandboxed: true
7
+  scripts: [ combatcontrols.lua ]
8
+  @onLoad: init()
9
+  @onUnload: terminate()

+ 264
- 263
modules/game_console/console.lua View File

@@ -1,7 +1,4 @@
1
-Console = {}
2
-
3
-local SpeakTypesSettings = {
1
+SpeakTypesSettings = {
4 2
   say = { speakType = SpeakSay, color = '#FFFF00' },
5 3
   whisper = { speakType = SpeakWhisper, color = '#FFFF00' },
6 4
   yell = { speakType = SpeakYell, color = '#FFFF00' },
@@ -19,7 +16,7 @@ local SpeakTypesSettings = {
19 16
   monsterYell = { speakType = SpeakMonsterYell, color = '#FE6500', hideInConsole = true},
20 17
 }
21 18
 
22
-local SpeakTypes = {
19
+SpeakTypes = {
23 20
   [SpeakSay] = SpeakTypesSettings.say,
24 21
   [SpeakWhisper] = SpeakTypesSettings.whisper,
25 22
   [SpeakYell] = SpeakTypesSettings.yell,
@@ -36,235 +33,29 @@ local SpeakTypes = {
36 33
   [SpeakMonsterYell] = SpeakTypesSettings.monsterYell,
37 34
 }
38 35
 
39
-local SayModes = {
36
+SayModes = {
40 37
   [1] = { speakTypeDesc = 'whisper', icon = 'icons/whisper.png' },
41 38
   [2] = { speakTypeDesc = 'say', icon = 'icons/say.png' },
42 39
   [3] = { speakTypeDesc = 'yell', icon = 'icons/yell.png' }
43 40
 }
44 41
 
45
-local MAX_HISTORY = 1000
46
-local MAX_LINES = 100
47
-local HELP_CHANNEL = 9
48
-
49
-local consolePanel
50
-local consoleContentPanel
51
-local consoleTabBar
52
-local consoleTextEdit
53
-local channels
54
-local channelsWindow
55
-local ownPrivateName
56
-local messageHistory = {}
57
-local currentMessageIndex = 0
58
-local ignoreNpcMessages = false
59
-
60
-local function navigateMessageHistory(step)
61
-  local numCommands = #messageHistory
62
-  if numCommands > 0 then
63
-    currentMessageIndex = math.min(math.max(currentMessageIndex + step, 0), numCommands)
64
-    if currentMessageIndex > 0 then
65
-      local command = messageHistory[numCommands - currentMessageIndex + 1]
66
-      consoleTextEdit:setText(command)
67
-    else
68
-      consoleTextEdit:clearText()
69
-    end
70
-  end
71
-end
72
-
73
-function applyMessagePrefixies(name, level, message)
74
-  if name then
75
-    if Options.getOption('showLevelsInConsole') and level > 0 then
76
-      message = name .. ' [' .. level .. ']: ' .. message
77
-    else
78
-      message = name .. ': ' .. message
79
-    end
80
-  end
81
-  return message
82
-end
83
-
84
-local function onCreatureSpeak(name, level, speaktype, message, channelId, creaturePos)
85
-  if ignoreNpcMessages and speaktype == SpeakPrivateNpcToPlayer then return end
86
-  local defaultMessage = speaktype < 3 and true or false
87
-  speaktype = SpeakTypes[speaktype]
88
-  if speaktype.hideInConsole then return end
89
-
90
-  local composedMessage = applyMessagePrefixies(name, level, message)
91
-
92
-  if speaktype.private then
93
-    Console.addPrivateText(composedMessage, speaktype, name, false, name)
94
-    if Options.getOption('showPrivateMessagesOnScreen') then
95
-	  if(speaktype.speakType ~= SpeakPrivateNpcToPlayer) then
96
-        TextMessage.displayPrivate(name .. ':\n' .. message)
97
-	  end
98
-    end
99
-  else
100
-    local channel = tr('Default')
101
-    if not defaultMessage then
102
-      channel = channels[channelId]
103
-    end
104
-
105
-    if channel then
106
-      Console.addText(composedMessage, speaktype, channel, name)
107
-    elseif channelId ~= 0 then
108
-      -- server sent a message on a channel that is not open
109
-      pwarning('message in channel id ' .. channelId .. ' which is unknown, this is a server bug, relogin if you want to see messages in this channel')
110
-    end
111
-  end
112
-end
113
-
114
-local function onOpenChannel(channelId, channelName)
115
-  Console.addChannel(channelName, channelId)
116
-end
117
-
118
-local function onOpenPrivateChannel(receiver)
119
-  Console.addPrivateChannel(receiver)
120
-end
121
-
122
-local function onOpenOwnPrivateChannel(channelId, channelName)
123
-  local privateTab = Console.getTab(channelName)
124
-  if privateTab == nil then
125
-    Console.addChannel(channelName, channelId)
126
-  end
127
-  ownPrivateName = channelName
128
-end
129
-
130
-local function onCloseChannel(channelId)
131
-  local channel = channels[channelId]
132
-  if channel then
133
-    local tab = Console.getTab(channel)
134
-    if tab then
135
-      consoleTabBar:removeTab(tab)
136
-    end
137
-    for k, v in pairs(channels) do
138
-      if (k == tab.channelId) then channels[k] = nil end
139
-    end
140
-  end
141
-end
42
+MAX_HISTORY = 1000
43
+MAX_LINES = 100
44
+HELP_CHANNEL = 9
142 45
 
143
-local function doChannelListSubmit()
144
-  local channelListPanel = channelsWindow:getChildById('channelList')
145
-  local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
146
-  if openPrivateChannelWith ~= '' then
147
-    g_game.openPrivateChannel(openPrivateChannelWith)
148
-  else
149
-    local selectedChannelLabel = channelListPanel:getFocusedChild()
150
-    if not selectedChannelLabel then return end
151
-    if selectedChannelLabel.channelId == 0xFFFF then
152
-      g_game.openOwnChannel()
153
-    else
154
-      g_game.joinChannel(selectedChannelLabel.channelId)
155
-    end
156
-  end
46
+consolePanel = nil
47
+consoleContentPanel = nil
48
+consoleTabBar = nil
49
+consoleTextEdit = nil
50
+channels = nil
51
+channelsWindow = nil
52
+ownPrivateName = nil
53
+messageHistory = {}
54
+currentMessageIndex = 0
55
+ignoreNpcMessages = false
157 56
 
158
-  channelsWindow:destroy()
159
-end
160 57
 
161
-local function onChannelList(channelList)
162
-  if channelsWindow then channelsWindow:destroy() end
163
-  channelsWindow = g_ui.displayUI('channelswindow.otui')
164
-  local channelListPanel = channelsWindow:getChildById('channelList')
165
-  channelsWindow.onEnter = doChannelListSubmit
166
-  channelsWindow.onDestroy = function() channelsWindow = nil end
167
-  g_keyboard.bindKeyPress('Down', function() channelListPanel:focusNextChild(KeyboardFocusReason) end, channelsWindow)
168
-  g_keyboard.bindKeyPress('Up', function() channelListPanel:focusPreviousChild(KeyboardFocusReason) end, channelsWindow)
169
-
170
-  for k,v in pairs(channelList) do
171
-    local channelId = v[1]
172
-    local channelName = v[2]
173
-
174
-    if #channelName > 0 then
175
-      local label = g_ui.createWidget('ChannelListLabel', channelListPanel)
176
-      label.channelId = channelId
177
-      label:setText(channelName)
178
-
179
-      label:setPhantom(false)
180
-      label.onDoubleClick = doChannelListSubmit
181
-    end
182
-  end
183
-end
184
-
185
-local function onGameStart()
186
-  -- open last channels
187
-  local player = g_game.getLocalPlayer()
188
-  if(player) then
189
-    local char = player:getName()
190
-
191
-    local lastChannelsOpen = g_settings.getNode('LastChannelsOpen')
192
-
193
-    if(not table.empty(lastChannelsOpen) and lastChannelsOpen[char]) then
194
-      for channelName, channelId in ipairs(lastChannelsOpen[char]) do
195
-        channelId = tonumber(channelId)
196
-        if channelId ~= 0 then
197
-          if not table.find(channels, channelId) then
198
-            g_game.joinChannel(channelId)
199
-          end
200
-        end
201
-      end
202
-    end
203
-  end
204
-
205
-  local tab = Console.getTab(tr('Default'))
206
-  if tab then
207
-    --[[
208
-      Known Issue: The server is calling to open channels after
209
-      onGameStart is executed causing it to focus the last tab opened.
210
-
211
-      Fix: Don't save channels to the settings that are opened by the server.
212
-    ]]
213
-    addEvent(function() consoleTabBar:selectTab(tab) end, true)
214
-  end
215
-end
216
-
217
-function Console.onTabChange(tabBar, tab)
218
-  if tab:getText() == tr('Default') or tab:getText() == tr('Server Log') then
219
-    consolePanel:getChildById('closeChannelButton'):disable()
220
-  else
221
-    consolePanel:getChildById('closeChannelButton'):enable()
222
-  end
223
-end
224
-
225
-function Console.clear()
226
-  local lastChannelsOpen = {}
227
-
228
-  local player = g_game.getLocalPlayer()
229
-  if(player) then
230
-    local char = player:getName()
231
-    lastChannelsOpen[char] = {}
232
-
233
-    for channelId, channelName in pairs(channels) do
234
-      table.insert(lastChannelsOpen[char], channelId)
235
-    end
236
-  end
237
-
238
-  -- save last open channels
239
-  g_settings.setNode('LastChannelsOpen', lastChannelsOpen)
240
-
241
-  for _, channelName in pairs(channels) do
242
-    local tab = consoleTabBar:getTab(channelName)
243
-    consoleTabBar:removeTab(tab)
244
-  end
245
-
246
-  channels = {}
247
-
248
-  consoleTabBar:getTab(tr('Default')).tabPanel:getChildById('consoleBuffer'):destroyChildren()
249
-  consoleTabBar:getTab(tr('Server Log')).tabPanel:getChildById('consoleBuffer'):destroyChildren()
250
-
251
-  local npcTab = consoleTabBar:getTab('NPCs')
252
-  if npcTab then
253
-    consoleTabBar:removeTab(npcTab)
254
-  end
255
-
256
-  consoleTextEdit:clearText()
257
-
258
-  if channelsWindow then
259
-    channelsWindow:destroy()
260
-    channelsWindow = nil
261
-  end
262
-end
263
-
264
-function Console.init()
58
+function init()
265 59
   connect(g_game, { onCreatureSpeak = onCreatureSpeak,
266 60
                     onChannelList = onChannelList,
267 61
                     onOpenChannel = onOpenChannel,
@@ -272,37 +63,37 @@ function Console.init()
272 63
                     onOpenOwnPrivateChannel = onOpenOwnPrivateChannel,
273 64
                     onCloseChannel = onCloseChannel,
274 65
                     onGameStart = onGameStart,
275
-                    onGameEnd = Console.clear })
66
+                    onGameEnd = clear })
276 67
 
277
-  consolePanel = g_ui.loadUI('console.otui', GameInterface.getBottomPanel())
68
+  consolePanel = g_ui.loadUI('console.otui', modules.game_interface.getBottomPanel())
278 69
   consoleTextEdit = consolePanel:getChildById('consoleTextEdit')
279 70
   consoleContentPanel = consolePanel:getChildById('consoleContentPanel')
280 71
   consoleTabBar = consolePanel:getChildById('consoleTabBar')
281 72
   consoleTabBar:setContentWidget(consoleContentPanel)
282 73
   channels = {}
283 74
 
284
-  Console.addTab(tr('Default'), true)
285
-  Console.addTab(tr('Server Log'), false)
75
+  addTab(tr('Default'), true)
76
+  addTab(tr('Server Log'), false)
286 77
 
287 78
   g_keyboard.bindKeyPress('Shift+Up', function() navigateMessageHistory(1) end, consolePanel)
288 79
   g_keyboard.bindKeyPress('Shift+Down', function() navigateMessageHistory(-1) end, consolePanel)
289 80
   g_keyboard.bindKeyPress('Tab', function() consoleTabBar:selectNextTab() end, consolePanel)
290 81
   g_keyboard.bindKeyPress('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel)
291
-  g_keyboard.bindKeyDown('Enter', Console.sendCurrentMessage, consolePanel)
82
+  g_keyboard.bindKeyDown('Enter', sendCurrentMessage, consolePanel)
292 83
   g_keyboard.bindKeyPress('Ctrl+A', function() consoleTextEdit:clearText() end, consolePanel)
293 84
 
294 85
   -- apply buttom functions after loaded
295 86
   consolePanel:getChildById('nextChannelButton').onClick = function() consoleTabBar:selectNextTab() end
296 87
   consolePanel:getChildById('prevChannelButton').onClick = function() consoleTabBar:selectPrevTab() end
297
-  consoleTabBar.onTabChange = Console.onTabChange
88
+  consoleTabBar.onTabChange = onTabChange
298 89
 
299 90
   -- tibia like hotkeys
300 91
   g_keyboard.bindKeyDown('Ctrl+O', g_game.requestChannels)
301
-  g_keyboard.bindKeyDown('Ctrl+E', Console.removeCurrentTab)
302
-  g_keyboard.bindKeyDown('Ctrl+H', Console.openHelp)
92
+  g_keyboard.bindKeyDown('Ctrl+E', removeCurrentTab)
93
+  g_keyboard.bindKeyDown('Ctrl+H', openHelp)
303 94
 end
304 95
 
305
-function Console.terminate()
96
+function terminate()
306 97
   disconnect(g_game, { onCreatureSpeak = onCreatureSpeak,
307 98
                        onChannelList = onChannelList,
308 99
                        onOpenChannel = onOpenChannel,
@@ -310,7 +101,7 @@ function Console.terminate()
310 101
                        onOpenOwnPrivateChannel = onOpenPrivateChannel,
311 102
                        onCloseChannel = onCloseChannel,
312 103
                        onGameStart = onGameStart,
313
-                       onGameEnd = Console.clear })
104
+                       onGameEnd = clear })
314 105
 
315 106
   for channelid, channelname in pairs(channels) do
316 107
     if tonumber(channelid) and tonumber(channelid) ~= 0 then
@@ -339,16 +130,63 @@ function Console.terminate()
339 130
   Console = nil
340 131
 end
341 132
 
342
-function Console.setTextEditText(text)
133
+function onTabChange(tabBar, tab)
134
+  if tab:getText() == tr('Default') or tab:getText() == tr('Server Log') then
135
+    consolePanel:getChildById('closeChannelButton'):disable()
136
+  else
137
+    consolePanel:getChildById('closeChannelButton'):enable()
138
+  end
139
+end
140
+
141
+function clear()
142
+  local lastChannelsOpen = {}
143
+
144
+  local player = g_game.getLocalPlayer()
145
+  if(player) then
146
+    local char = player:getName()
147
+    lastChannelsOpen[char] = {}
148
+
149
+    for channelId, channelName in pairs(channels) do
150
+      table.insert(lastChannelsOpen[char], channelId)
151
+    end
152
+  end
153
+
154
+  -- save last open channels
155
+  g_settings.setNode('LastChannelsOpen', lastChannelsOpen)
156
+
157
+  for _, channelName in pairs(channels) do
158
+    local tab = consoleTabBar:getTab(channelName)
159
+    consoleTabBar:removeTab(tab)
160
+  end
161
+
162
+  channels = {}
163
+
164
+  consoleTabBar:getTab(tr('Default')).tabPanel:getChildById('consoleBuffer'):destroyChildren()
165
+  consoleTabBar:getTab(tr('Server Log')).tabPanel:getChildById('consoleBuffer'):destroyChildren()
166
+
167
+  local npcTab = consoleTabBar:getTab('NPCs')
168
+  if npcTab then
169
+    consoleTabBar:removeTab(npcTab)
170
+  end
171
+
172
+  consoleTextEdit:clearText()
173
+
174
+  if channelsWindow then
175
+    channelsWindow:destroy()
176
+    channelsWindow = nil
177
+  end
178
+end
179
+
180
+function setTextEditText(text)
343 181
   consoleTextEdit:setText(text)
344 182
 end
345 183
 
346
-function Console.openHelp()
184
+function openHelp()
347 185
   g_game.joinChannel(HELP_CHANNEL)
348 186
 end
349 187
 
350
-function Console.addTab(name, focus)
351
-  local tab = Console.getTab(name)
188
+function addTab(name, focus)
189
+  local tab = getTab(name)
352 190
   if(tab) then -- is channel already open
353 191
     if(not focus) then focus = true end
354 192
   else
@@ -362,7 +200,7 @@ function Console.addTab(name, focus)
362 200
   return tab
363 201
 end
364 202
 
365
-function Console.removeCurrentTab()
203
+function removeCurrentTab()
366 204
   local tab = consoleTabBar:getCurrentTab()
367 205
   if tab:getText() == tr('Default') or tab:getText() == tr('Server Log') then return end
368 206
 
@@ -379,56 +217,56 @@ function Console.removeCurrentTab()
379 217
   consoleTabBar:removeTab(tab)
380 218
 end
381 219
 
382
-function Console.getTab(name)
220
+function getTab(name)
383 221
   return consoleTabBar:getTab(name)
384 222
 end
385 223
 
386
-function Console.getCurrentTab()
224
+function getCurrentTab()
387 225
   return consoleTabBar:getCurrentTab()
388 226
 end
389 227
 
390
-function Console.addChannel(name, id)
228
+function addChannel(name, id)
391 229
   channels[id] = name
392
-  local tab = Console.addTab(name, true)
230
+  local tab = addTab(name, true)
393 231
   tab.channelId = id
394 232
   return tab
395 233
 end
396 234
 
397
-function Console.addPrivateChannel(receiver)
235
+function addPrivateChannel(receiver)
398 236
   channels[receiver] = receiver
399
-  return Console.addTab(receiver, true)
237
+  return addTab(receiver, true)
400 238
 end
401 239
 
402
-function Console.addPrivateText(text, speaktype, name, isPrivateCommand, creatureName)
240
+function addPrivateText(text, speaktype, name, isPrivateCommand, creatureName)
403 241
   local focus = false
404 242
   if speaktype.speakType == SpeakPrivateNpcToPlayer then
405 243
     name = 'NPCs'
406 244
     focus = true
407 245
   end
408 246
 
409
-  local privateTab = Console.getTab(name)
247
+  local privateTab = getTab(name)
410 248
   if privateTab == nil then
411 249
     if (Options.getOption('showPrivateMessagesInConsole') and not focus) or (isPrivateCommand and not privateTab) then
412
-      privateTab = Console.getTab(tr('Default'))
250
+      privateTab = getTab(tr('Default'))
413 251
     else
414
-      privateTab = Console.addTab(name, focus)
252
+      privateTab = addTab(name, focus)
415 253
       channels[name] = name
416 254
     end
417 255
     privateTab.npcChat = speaktype.npcChat
418 256
   elseif focus then
419 257
     consoleTabBar:selectTab(privateTab)
420 258
   end
421
-  Console.addTabText(text, speaktype, privateTab, creatureName)
259
+  addTabText(text, speaktype, privateTab, creatureName)
422 260
 end
423 261
 
424
-function Console.addText(text, speaktype, tabName, creatureName)
425
-  local tab = Console.getTab(tabName)
262
+function addText(text, speaktype, tabName, creatureName)
263
+  local tab = getTab(tabName)
426 264
   if tab ~= nil then
427
-    Console.addTabText(text, speaktype, tab, creatureName)
265
+    addTabText(text, speaktype, tab, creatureName)
428 266
   end
429 267
 end
430 268
 
431
-function Console.addTabText(text, speaktype, tab, creatureName)
269
+function addTabText(text, speaktype, tab, creatureName)
432 270
   if Options.getOption('showTimestampsInConsole') then
433 271
     text = os.date('%H:%M') .. ' ' .. text
434 272
   end
@@ -441,14 +279,14 @@ function Console.addTabText(text, speaktype, tab, creatureName)
441 279
   label:setColor(speaktype.color)
442 280
   consoleTabBar:blinkTab(tab)
443 281
 
444
-  label.onMouseRelease = function (self, mousePos, mouseButton) Console.popupMenu(mousePos, mouseButton, creatureName, text) end
282
+  label.onMouseRelease = function (self, mousePos, mouseButton) popupMenu(mousePos, mouseButton, creatureName, text) end
445 283
 
446 284
   if consoleBuffer:getChildCount() > MAX_LINES then
447 285
     consoleBuffer:getFirstChild():destroy()
448 286
   end
449 287
 end
450 288
 
451
-function Console.popupMenu(mousePos, mouseButton, creatureName, text)
289
+function popupMenu(mousePos, mouseButton, creatureName, text)
452 290
   if mouseButton == MouseRightButton then
453 291
     local menu = g_ui.createWidget('PopupMenu')
454 292
     if creatureName then
@@ -478,13 +316,13 @@ function Console.popupMenu(mousePos, mouseButton, creatureName, text)
478 316
   end
479 317
 end
480 318
 
481
-function Console.sendCurrentMessage()
319
+function sendCurrentMessage()
482 320
   local message = consoleTextEdit:getText()
483 321
   if #message == 0 then return end
484 322
   consoleTextEdit:clearText()
485 323
 
486 324
   -- get current channel
487
-  local tab = Console.getCurrentTab()
325
+  local tab = getCurrentTab()
488 326
 
489 327
   -- handling chat commands
490 328
   local originalMessage = message
@@ -527,7 +365,7 @@ function Console.sendCurrentMessage()
527 365
   -- when talking on server log, the message goes to default channel
528 366
   local name = tab:getText()
529 367
   if name == tr('Server Log') then
530
-    tab = Console.getTab(tr('Default'))
368
+    tab = getTab(tr('Default'))
531 369
     name = tr('Default')
532 370
   end
533 371
 
@@ -535,7 +373,7 @@ function Console.sendCurrentMessage()
535 373
   if (tab.channelId or name == tr('Default')) and not chatCommandPrivateReady then
536 374
     if name == tr('Default') then
537 375
       speaktypedesc = chatCommandSayMode or SayModes[consolePanel:getChildById('sayModeButton').sayMode].speakTypeDesc
538
-      if speaktypedesc ~= 'say' then Console.sayModeChange(2) end -- head back to say mode
376
+      if speaktypedesc ~= 'say' then sayModeChange(2) end -- head back to say mode
539 377
     else
540 378
       speaktypedesc = 'channelYellow'
541 379
     end
@@ -560,11 +398,11 @@ function Console.sendCurrentMessage()
560 398
     g_game.talkPrivate(speaktype.speakType, name, message)
561 399
 
562 400
     message = applyMessagePrefixies(player:getName(), player:getLevel(), message)
563
-    Console.addPrivateText(message, speaktype, name, isPrivateCommand, g_game.getCharacterName())
401
+    addPrivateText(message, speaktype, name, isPrivateCommand, g_game.getCharacterName())
564 402
   end
565 403
 end
566 404
 
567
-function Console.sayModeChange(sayMode)
405
+function sayModeChange(sayMode)
568 406
   local buttom = consolePanel:getChildById('sayModeButton')
569 407
   if sayMode == nil then
570 408
     sayMode = buttom.sayMode + 1
@@ -576,11 +414,170 @@ function Console.sayModeChange(sayMode)
576 414
   buttom.sayMode = sayMode
577 415
 end
578 416
 
579
-function Console.getOwnPrivateTab()
417
+function getOwnPrivateTab()
580 418
   if not ownPrivateName then return end
581
-  return Console.getTab(ownPrivateName)
419
+  return getTab(ownPrivateName)
582 420
 end
583 421
 
584
-function Console.ignoreNpcMessages(ignore)
422
+function ignoreNpcMessages(ignore)
585 423
   ignoreNpcMessages = ignore
586 424
 end
425
+
426
+
427
+function navigateMessageHistory(step)
428
+  local numCommands = #messageHistory
429
+  if numCommands > 0 then
430
+    currentMessageIndex = math.min(math.max(currentMessageIndex + step, 0), numCommands)
431
+    if currentMessageIndex > 0 then
432
+      local command = messageHistory[numCommands - currentMessageIndex + 1]
433
+      consoleTextEdit:setText(command)
434
+    else
435
+      consoleTextEdit:clearText()
436
+    end
437
+  end
438
+end
439
+
440
+function applyMessagePrefixies(name, level, message)
441
+  if name then
442
+    if Options.getOption('showLevelsInConsole') and level > 0 then
443
+      message = name .. ' [' .. level .. ']: ' .. message
444
+    else
445
+      message = name .. ': ' .. message
446
+    end
447
+  end
448
+  return message
449
+end
450
+
451
+function onCreatureSpeak(name, level, speaktype, message, channelId, creaturePos)
452
+  if ignoreNpcMessages and speaktype == SpeakPrivateNpcToPlayer then return end
453
+  local defaultMessage = speaktype < 3 and true or false
454
+  speaktype = SpeakTypes[speaktype]
455
+  if speaktype.hideInConsole then return end
456
+
457
+  local composedMessage = applyMessagePrefixies(name, level, message)
458
+
459
+  if speaktype.private then
460
+    addPrivateText(composedMessage, speaktype, name, false, name)
461
+    if Options.getOption('showPrivateMessagesOnScreen') then
462
+      if(speaktype.speakType ~= SpeakPrivateNpcToPlayer) then
463
+        TextMessage.displayPrivate(name .. ':\n' .. message)
464
+      end
465
+    end
466
+  else
467
+    local channel = tr('Default')
468
+    if not defaultMessage then
469
+      channel = channels[channelId]
470
+    end
471
+
472
+    if channel then
473
+      addText(composedMessage, speaktype, channel, name)
474
+    elseif channelId ~= 0 then
475
+      -- server sent a message on a channel that is not open
476
+      pwarning('message in channel id ' .. channelId .. ' which is unknown, this is a server bug, relogin if you want to see messages in this channel')
477
+    end
478
+  end
479
+end
480
+
481
+local function onOpenChannel(channelId, channelName)
482
+  addChannel(channelName, channelId)
483
+end
484
+
485
+local function onOpenPrivateChannel(receiver)
486
+  addPrivateChannel(receiver)
487
+end
488
+
489
+local function onOpenOwnPrivateChannel(channelId, channelName)
490
+  local privateTab = getTab(channelName)
491
+  if privateTab == nil then
492
+    addChannel(channelName, channelId)
493
+  end
494
+  ownPrivateName = channelName
495
+end
496
+
497
+local function onCloseChannel(channelId)
498
+  local channel = channels[channelId]
499
+  if channel then
500
+    local tab = getTab(channel)
501
+    if tab then
502
+      consoleTabBar:removeTab(tab)
503
+    end
504
+    for k, v in pairs(channels) do
505
+      if (k == tab.channelId) then channels[k] = nil end
506
+    end
507
+  end
508
+end
509
+
510
+local function doChannelListSubmit()
511
+  local channelListPanel = channelsWindow:getChildById('channelList')
512
+  local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
513
+  if openPrivateChannelWith ~= '' then
514
+    g_game.openPrivateChannel(openPrivateChannelWith)
515
+  else
516
+    local selectedChannelLabel = channelListPanel:getFocusedChild()
517
+    if not selectedChannelLabel then return end
518
+    if selectedChannelLabel.channelId == 0xFFFF then
519
+      g_game.openOwnChannel()
520
+    else
521
+      g_game.joinChannel(selectedChannelLabel.channelId)
522
+    end
523
+  end
524
+
525
+  channelsWindow:destroy()
526
+end
527
+
528
+local function onChannelList(channelList)
529
+  if channelsWindow then channelsWindow:destroy() end
530
+  channelsWindow = g_ui.displayUI('channelswindow.otui')
531
+  local channelListPanel = channelsWindow:getChildById('channelList')
532
+  channelsWindow.onEnter = doChannelListSubmit
533
+  channelsWindow.onDestroy = function() channelsWindow = nil end
534
+  g_keyboard.bindKeyPress('Down', function() channelListPanel:focusNextChild(KeyboardFocusReason) end, channelsWindow)
535
+  g_keyboard.bindKeyPress('Up', function() channelListPanel:focusPreviousChild(KeyboardFocusReason) end, channelsWindow)
536
+
537
+  for k,v in pairs(channelList) do
538
+    local channelId = v[1]
539
+    local channelName = v[2]
540
+
541
+    if #channelName > 0 then
542
+      local label = g_ui.createWidget('ChannelListLabel', channelListPanel)
543
+      label.channelId = channelId
544
+      label:setText(channelName)
545
+
546
+      label:setPhantom(false)
547
+      label.onDoubleClick = doChannelListSubmit
548
+    end
549
+  end
550
+end
551
+
552
+local function onGameStart()
553
+  -- open last channels
554
+  local player = g_game.getLocalPlayer()
555
+  if(player) then
556
+    local char = player:getName()
557
+
558
+    local lastChannelsOpen = g_settings.getNode('LastChannelsOpen')
559
+
560
+    if(not table.empty(lastChannelsOpen) and lastChannelsOpen[char]) then
561
+      for channelName, channelId in ipairs(lastChannelsOpen[char]) do
562
+        channelId = tonumber(channelId)
563
+        if channelId ~= 0 then
564
+          if not table.find(channels, channelId) then
565
+            g_game.joinChannel(channelId)
566
+          end
567
+        end
568
+      end
569
+    end
570
+  end
571
+
572
+  local tab = getTab(tr('Default'))
573
+  if tab then
574
+    --[[
575
+      Known Issue: The server is calling to open channels after
576
+      onGameStart is executed causing it to focus the last tab opened.
577
+
578
+      Fix: Don't save channels to the settings that are opened by the server.
579
+    ]]
580
+    addEvent(function() consoleTabBar:selectTab(tab) end, true)
581
+  end
582
+end
583
+

+ 4
- 10
modules/game_console/console.otmod View File

@@ -3,13 +3,7 @@ Module
3 3
   description: Manage chat window
4 4
   author: edubart, andrefaramir, baxnie, sn4ake, BeniS
5 5
   website: www.otclient.info
6
-
7
-  dependencies:
8
-    - game_interface
9
-
10
-  @onLoad: |
11
-    dofile 'console'
12
-    Console.init()
13
-
14
-  @onUnload: |
15
-    Console.terminate()
6
+  sandboxed: true
7
+  scripts: [ console.lua ]
8
+  @onLoad: init()
9
+  @onUnload: terminate()

+ 2
- 2
modules/game_console/console.otui View File

@@ -71,7 +71,7 @@ Panel
71 71
     enabled: false
72 72
     margin-right: 5
73 73
     margin-top: 6
74
-    @onClick: Console.removeCurrentTab()
74
+    @onClick: removeCurrentTab()
75 75
 
76 76
   TabButton
77 77
     id: clearChannelButton
@@ -118,7 +118,7 @@ Panel
118 118
     anchors.bottom: parent.bottom
119 119
     margin-left: 6
120 120
     margin-bottom: 6
121
-    @onClick: Console.sayModeChange()
121
+    @onClick: sayModeChange()
122 122
 
123 123
   TextEdit
124 124
     id: consoleTextEdit

+ 39
- 42
modules/game_containers/containers.lua View File

@@ -1,4 +1,41 @@
1
-Containers = {}
1
+function init()
2
+  g_ui.importStyle('container.otui')
3
+
4
+  connect(Container, { onOpen = onContainerOpen,
5
+                       onClose = onContainerClose,
6
+                       onAddItem = onContainerAddItem,
7
+                       onUpdateItem = onContainerUpdateItem,
8
+                       onRemoveItem = onContainerRemoveItem })
9
+  connect(Game, { onGameEnd = clean() })
10
+
11
+  reloadContainers()
12
+end
13
+
14
+function terminate()
15
+  disconnect(Container, { onOpen = onContainerOpen,
16
+                          onClose = onContainerClose,
17
+                          onAddItem = onContainerAddItem,
18
+                          onUpdateItem = onContainerUpdateItem,
19
+                          onRemoveItem = onContainerRemoveItem })
20
+  disconnect(Game, { onGameEnd = clean() })
21
+end
22
+
23
+function reloadContainers()
24
+  clean()
25
+  for containerid,container in pairs(g_game.getContainers()) do
26
+    onContainerOpen(container)
27
+  end
28
+end
29
+
30
+function clean()
31
+  for containerid,container in pairs(g_game.getContainers()) do
32
+    if container.window then
33
+      container.window:destroy()
34
+      container.window = nil
35
+      container.itemsPanel = nil
36
+    end
37
+  end
38
+end
2 39
 
3 40
 local function refreshContainerItems(container)
4 41
   for slot=0,container:getCapacity()-1 do
@@ -14,7 +51,7 @@ local function onContainerOpen(container, previousContainer)
14 51
     previousContainer.window = nil
15 52
     previousContainer.itemsPanel = nil
16 53
   else
17
-    containerWindow = g_ui.createWidget('ContainerWindow', GameInterface.getRightPanel())
54
+    containerWindow = g_ui.createWidget('ContainerWindow', modules.game_interface.getRightPanel())
18 55
   end
19 56
   containerWindow:setId('container' .. container:getId())
20 57
   local containerPanel = containerWindow:getChildById('contentsPanel')
@@ -72,43 +109,3 @@ local function onContainerRemoveItem(container, slot, item)
72 109
   if not container.window then return end
73 110
   refreshContainerItems(container)
74 111
 end
75
-
76
-function Containers.init()
77
-  g_ui.importStyle('container.otui')
78
-
79
-  connect(Container, { onOpen = onContainerOpen,
80
-                       onClose = onContainerClose,
81
-                       onAddItem = onContainerAddItem,
82
-                       onUpdateItem = onContainerUpdateItem,
83
-                       onRemoveItem = onContainerRemoveItem })
84
-  connect(Game, { onGameEnd = Containers.clean() })
85
-
86
-  Containers.reloadContainers()
87
-end
88
-
89
-function Containers.terminate()
90
-  disconnect(Container, { onOpen = onContainerOpen,
91
-                          onClose = onContainerClose,
92
-                          onAddItem = onContainerAddItem,
93
-                          onUpdateItem = onContainerUpdateItem,
94
-                          onRemoveItem = onContainerRemoveItem })
95
-  disconnect(Game, { onGameEnd = Containers.clean() })
96
-  Containers = nil
97
-end
98
-
99
-function Containers.reloadContainers()
100
-  Containers.clean()
101
-  for containerid,container in pairs(g_game.getContainers()) do
102
-    onContainerOpen(container)
103
-  end
104
-end
105
-
106
-function Containers.clean()
107
-  for containerid,container in pairs(g_game.getContainers()) do
108
-    if container.window then
109
-      container.window:destroy()
110
-      container.window = nil
111
-      container.itemsPanel = nil
112
-    end
113
-  end
114
-end

+ 4
- 10
modules/game_containers/containers.otmod View File

@@ -3,13 +3,7 @@ Module
3 3
   description: Manage containers
4 4
   author: edubart, baxnie
5 5
   website: www.otclient.info
6
-
7
-  dependencies:
8
-    - game_interface
9
-
10
-  @onLoad: |
11
-    dofile 'containers'
12
-    Containers.init()
13
-
14
-  @onUnload: |
15
-    Containers.terminate()
6
+  sandboxed: true
7
+  scripts: [containers.lua]
8
+  @onLoad: init()
9
+  @onUnload: terminate()

+ 43
- 45
modules/game_healthinfo/healthinfo.lua View File

@@ -1,7 +1,4 @@
1
-HealthInfo = {}
2
-
3
-local Icons = {}
1
+Icons = {}
4 2
 Icons[1] = { tooltip = tr('You are poisoned'), path = '/game_healthinfo/icons/poisoned.png', id = 'condition_poisoned' }
5 3
 Icons[2] = { tooltip = tr('You are burning'), path = '/game_healthinfo/icons/burning.png', id = 'condition_burning' }
6 4
 Icons[4] = { tooltip = tr('You are electrified'), path = '/game_healthinfo/icons/electrified.png', id = 'condition_electrified' }
@@ -20,28 +17,26 @@ Icons[16384] = { tooltip = tr('You are within a protection zone'), path = '/game
20 17
 Icons[32768] = { tooltip = tr('You are bleeding'), path = '/game_healthinfo/icons/bleeding.png', id = 'condition_bleeding' }
21 18
 Icons[65536] = { tooltip = tr('You are hungry'), path = '/game_healthinfo/icons/hungry.png', id = 'condition_hungry' }
22 19
 
23
-local healthInfoWindow
24
-local healthBar
25
-local manaBar
26
-local soulBar
27
-local healthLabel
28
-local manaLabel
29
-local soulLabel
30
-local capLabel
31
-
32
-function HealthInfo.init()
33
-  connect(LocalPlayer, { onHealthChange = HealthInfo.onHealthChange,
34
-                         onManaChange = HealthInfo.onManaChange,
35
-                         onStatesChange = HealthInfo.onStatesChange,
36
-                         onSoulChange = HealthInfo.onSoulChange,
37
-                         onFreeCapacityChange = HealthInfo.onFreeCapacityChange })
38
-
39
-  connect(g_game, { onGameEnd = HealthInfo.offline })
40
-
41
-  healthInfoWindow = g_ui.loadUI('healthinfo.otui', GameInterface.getRightPanel())
42
-  healthInfoButton = TopMenu.addRightGameToggleButton('healthInfoButton', tr('Health Information'), 'healthinfo.png', HealthInfo.toggle)
20
+healthInfoWindow = nil
21
+healthBar = nil
22
+manaBar = nil
23
+soulBar = nil
24
+healthLabel = nil
25
+manaLabel = nil
26
+soulLabel = nil
27
+capLabel = nil
28
+
29
+function init()
30
+  connect(LocalPlayer, { onHealthChange = onHealthChange,
31
+                         onManaChange = onManaChange,
32
+                         onStatesChange = onStatesChange,
33
+                         onSoulChange = onSoulChange,
34
+                         onFreeCapacityChange = onFreeCapacityChange })
35
+
36
+  connect(g_game, { onGameEnd = offline })
37
+
38
+  healthInfoWindow = g_ui.loadUI('healthinfo.otui', modules.game_interface.getRightPanel())
39
+  healthInfoButton = TopMenu.addRightGameToggleButton('healthInfoButton', tr('Health Information'), 'healthinfo.png', toggle)
43 40
   healthInfoWindow:disableResize()
44 41
   healthInfoButton:setOn(true)
45 42
   healthBar = healthInfoWindow:recursiveGetChildById('healthBar')
@@ -54,22 +49,22 @@ function HealthInfo.init()
54 49
 
55 50
   if g_game.isOnline() then
56 51
     local localPlayer = g_game.getLocalPlayer()
57
-    HealthInfo.onHealthChange(localPlayer, localPlayer:getHealth(), localPlayer:getMaxHealth())
58
-    HealthInfo.onManaChange(localPlayer, localPlayer:getMana(), localPlayer:getMaxMana())
59
-    HealthInfo.onStatesChange(localPlayer, localPlayer:getStates(), 0)
60
-    HealthInfo.onSoulChange(localPlayer, localPlayer:getSoul())
61
-    HealthInfo.onFreeCapacityChange(localPlayer, localPlayer:getFreeCapacity())
52
+    onHealthChange(localPlayer, localPlayer:getHealth(), localPlayer:getMaxHealth())
53
+    onManaChange(localPlayer, localPlayer:getMana(), localPlayer:getMaxMana())
54
+    onStatesChange(localPlayer, localPlayer:getStates(), 0)
55
+    onSoulChange(localPlayer, localPlayer:getSoul())
56
+    onFreeCapacityChange(localPlayer, localPlayer:getFreeCapacity())
62 57
   end
63 58
 end
64 59
 
65
-function HealthInfo.terminate()
66
-  disconnect(LocalPlayer, { onHealthChange = HealthInfo.onHealthChange,
67
-                            onManaChange = HealthInfo.onManaChange,
68
-                            onStatesChange = HealthInfo.onStatesChange,
69
-                            onSoulChange = HealthInfo.onSoulChange,
70
-                            onFreeCapacityChange = HealthInfo.onFreeCapacityChange })
60
+function terminate()
61
+  disconnect(LocalPlayer, { onHealthChange = onHealthChange,
62
+                            onManaChange = onManaChange,
63
+                            onStatesChange = onStatesChange,
64
+                            onSoulChange = onSoulChange,
65
+                            onFreeCapacityChange = onFreeCapacityChange })
71 66
 
72
-  disconnect(g_game, { onGameEnd = HealthInfo.offline })
67
+  disconnect(g_game, { onGameEnd = offline })
73 68
 
74 69
   healthInfoWindow:destroy()
75 70
   healthInfoButton:destroy()
@@ -88,7 +83,7 @@ function HealthInfo.terminate()
88 83
   HealthInfo = nil
89 84
 end
90 85
 
91
-function HealthInfo.toggle()
86
+function toggle()
92 87
   if healthInfoButton:isOn() then
93 88
     healthInfoWindow:close()
94 89
     healthInfoButton:setOn(false)
@@ -98,21 +93,21 @@ function HealthInfo.toggle()
98 93
   end
99 94
 end
100