diff --git a/modules/corelib/classes/callbackevent.lua b/modules/corelib/classes/callbackevent.lua new file mode 100644 index 00000000..8bcadf1f --- /dev/null +++ b/modules/corelib/classes/callbackevent.lua @@ -0,0 +1,44 @@ +--[[ + @Authors: Ben Dol (BeniS) + @Details: CallbackEvent class shell for callback events +]] + +CallbackEvent = newclass("CallbackEvent") + +CallbackEvent.create = function(id, callback) + local event = CallbackEvent.internalCreate() + + event.id = id + event.callback = callback + + return event +end + +-- gets/sets + +--@RequiredBy:Queue +function CallbackEvent:getId() + return self.id +end + +--@RequiredBy:Queue +function CallbackEvent:setId(id) + self.id = id +end + +--@RequiredBy:Queue +function CallbackEvent:getCallback() + return self.callback +end + +--@RequiredBy:Queue +function CallbackEvent:setCallback(callback) + self.callback = callback +end + +-- logic + +--@RequiredBy:Queue +function CallbackEvent:start() + -- Do nothing by default +end diff --git a/modules/corelib/classes/queue.lua b/modules/corelib/classes/queue.lua index 379181f2..7bb11edb 100644 --- a/modules/corelib/classes/queue.lua +++ b/modules/corelib/classes/queue.lua @@ -3,21 +3,15 @@ @Details: Queue class for event queuing. ]] -Queue = {} -Queue.__index = Queue +Queue = newclass("Queue") -Queue.__class = "Queue" +Queue.create = function(callback) + local obj = Queue.internalCreate() -Queue.new = function(callback) - que = { - queue = {}, - callback = nil - } + obj.queue = {} + obj.callback = callback - que.callback = callback - - setmetatable(que, Queue) - return que + return obj end -- gets/sets diff --git a/modules/corelib/corelib.otmod b/modules/corelib/corelib.otmod index 58ba6f85..74ece316 100644 --- a/modules/corelib/corelib.otmod +++ b/modules/corelib/corelib.otmod @@ -6,8 +6,6 @@ Module reloadable: false @onLoad: | - dofiles 'classes' - dofile 'math' dofile 'string' dofile 'table' @@ -22,6 +20,7 @@ Module dofile 'mouse' dofile 'net' + dofiles 'classes' dofiles 'ui' dofile 'inputmessage' diff --git a/modules/corelib/ui/uibutton.lua b/modules/corelib/ui/uibutton.lua index 90da18ae..8a7d125f 100644 --- a/modules/corelib/ui/uibutton.lua +++ b/modules/corelib/ui/uibutton.lua @@ -1,5 +1,5 @@ -- @docclass -UIButton = extends(UIWidget) +UIButton = extends(UIWidget, "UIButton") function UIButton.create() local button = UIButton.internalCreate() diff --git a/modules/corelib/ui/uicheckbox.lua b/modules/corelib/ui/uicheckbox.lua index 777de4bd..195c5938 100644 --- a/modules/corelib/ui/uicheckbox.lua +++ b/modules/corelib/ui/uicheckbox.lua @@ -1,5 +1,5 @@ -- @docclass -UICheckBox = extends(UIWidget) +UICheckBox = extends(UIWidget, "UICheckBox") function UICheckBox.create() local checkbox = UICheckBox.internalCreate() diff --git a/modules/corelib/ui/uicombobox.lua b/modules/corelib/ui/uicombobox.lua index e08eaaea..9f5f830f 100644 --- a/modules/corelib/ui/uicombobox.lua +++ b/modules/corelib/ui/uicombobox.lua @@ -1,5 +1,5 @@ -- @docclass -UIComboBox = extends(UIWidget) +UIComboBox = extends(UIWidget, "UIComboBox") function UIComboBox.create() local combobox = UIComboBox.internalCreate() diff --git a/modules/corelib/ui/uiimageview.lua b/modules/corelib/ui/uiimageview.lua index a2ef2359..7a2e5fe3 100644 --- a/modules/corelib/ui/uiimageview.lua +++ b/modules/corelib/ui/uiimageview.lua @@ -1,5 +1,5 @@ -- @docclass -UIImageView = extends(UIWidget) +UIImageView = extends(UIWidget, "UIImageView") function UIImageView.create() local imageView = UIImageView.internalCreate() diff --git a/modules/corelib/ui/uiinputbox.lua b/modules/corelib/ui/uiinputbox.lua index 04c0a3ae..1db361e2 100644 --- a/modules/corelib/ui/uiinputbox.lua +++ b/modules/corelib/ui/uiinputbox.lua @@ -1,7 +1,7 @@ if not UIWindow then dofile 'uiwindow' end -- @docclass -UIInputBox = extends(UIWindow) +UIInputBox = extends(UIWindow, "UIInputBox") function UIInputBox.create(title, okCallback, cancelCallback) local inputBox = UIInputBox.internalCreate() diff --git a/modules/corelib/ui/uilabel.lua b/modules/corelib/ui/uilabel.lua index ea65856b..ecd72bc0 100644 --- a/modules/corelib/ui/uilabel.lua +++ b/modules/corelib/ui/uilabel.lua @@ -1,5 +1,5 @@ -- @docclass -UILabel = extends(UIWidget) +UILabel = extends(UIWidget, "UILabel") function UILabel.create() local label = UILabel.internalCreate() diff --git a/modules/corelib/ui/uimessagebox.lua b/modules/corelib/ui/uimessagebox.lua index cf4bba6c..62f84a22 100644 --- a/modules/corelib/ui/uimessagebox.lua +++ b/modules/corelib/ui/uimessagebox.lua @@ -1,7 +1,7 @@ if not UIWindow then dofile 'uiwindow' end -- @docclass -UIMessageBox = extends(UIWindow) +UIMessageBox = extends(UIWindow, "UIMessageBox") -- messagebox cannot be created from otui files UIMessageBox.create = nil diff --git a/modules/corelib/ui/uiminiwindow.lua b/modules/corelib/ui/uiminiwindow.lua index c46511d9..1790e810 100644 --- a/modules/corelib/ui/uiminiwindow.lua +++ b/modules/corelib/ui/uiminiwindow.lua @@ -1,15 +1,11 @@ -- @docclass -UIMiniWindow = extends(UIWindow) +UIMiniWindow = extends(UIWindow, "UIMiniWindow") function UIMiniWindow.create() local miniwindow = UIMiniWindow.internalCreate() return miniwindow end -function UIMiniWindow:getClassName() - return 'UIMiniWindow' -end - function UIMiniWindow:open(dontSave) self:setVisible(true) diff --git a/modules/corelib/ui/uiminiwindowcontainer.lua b/modules/corelib/ui/uiminiwindowcontainer.lua index 37cdfb7d..4723ba4e 100644 --- a/modules/corelib/ui/uiminiwindowcontainer.lua +++ b/modules/corelib/ui/uiminiwindowcontainer.lua @@ -1,5 +1,5 @@ -- @docclass -UIMiniWindowContainer = extends(UIWidget) +UIMiniWindowContainer = extends(UIWidget, "UIMiniWindowContainer") function UIMiniWindowContainer.create() local container = UIMiniWindowContainer.internalCreate() @@ -9,10 +9,6 @@ function UIMiniWindowContainer.create() return container end -function UIMiniWindowContainer:getClassName() - return 'UIMiniWindowContainer' -end - -- TODO: connect to window onResize event -- TODO: try to resize another widget? -- TODO: try to find another panel? diff --git a/modules/corelib/ui/uimovabletabbar.lua b/modules/corelib/ui/uimovabletabbar.lua index 081fc43b..187a8c49 100644 --- a/modules/corelib/ui/uimovabletabbar.lua +++ b/modules/corelib/ui/uimovabletabbar.lua @@ -1,5 +1,5 @@ -- @docclass -UIMoveableTabBar = extends(UIWidget) +UIMoveableTabBar = extends(UIWidget, "UIMoveableTabBar") -- private functions local function onTabClick(tab) diff --git a/modules/corelib/ui/uipopupmenu.lua b/modules/corelib/ui/uipopupmenu.lua index c155dd82..57f04bc1 100644 --- a/modules/corelib/ui/uipopupmenu.lua +++ b/modules/corelib/ui/uipopupmenu.lua @@ -1,5 +1,5 @@ -- @docclass -UIPopupMenu = extends(UIWidget) +UIPopupMenu = extends(UIWidget, "UIPopupMenu") local currentMenu diff --git a/modules/corelib/ui/uiprogressbar.lua b/modules/corelib/ui/uiprogressbar.lua index 6e54642e..35658a24 100644 --- a/modules/corelib/ui/uiprogressbar.lua +++ b/modules/corelib/ui/uiprogressbar.lua @@ -1,5 +1,5 @@ -- @docclass -UIProgressBar = extends(UIWidget) +UIProgressBar = extends(UIWidget, "UIProgressBar") function UIProgressBar.create() local progressbar = UIProgressBar.internalCreate() diff --git a/modules/corelib/ui/uiradiogroup.lua b/modules/corelib/ui/uiradiogroup.lua index b3f5bc70..701d6559 100644 --- a/modules/corelib/ui/uiradiogroup.lua +++ b/modules/corelib/ui/uiradiogroup.lua @@ -1,5 +1,5 @@ -- @docclass -UIRadioGroup = newclass() +UIRadioGroup = newclass("UIRadioGroup") function UIRadioGroup.create() local radiogroup = UIRadioGroup.internalCreate() diff --git a/modules/corelib/ui/uiresizeborder.lua b/modules/corelib/ui/uiresizeborder.lua index 9909685e..4a86ce3f 100644 --- a/modules/corelib/ui/uiresizeborder.lua +++ b/modules/corelib/ui/uiresizeborder.lua @@ -1,5 +1,5 @@ -- @docclass -UIResizeBorder = extends(UIWidget) +UIResizeBorder = extends(UIWidget, "UIResizeBorder") function UIResizeBorder.create() local resizeborder = UIResizeBorder.internalCreate() diff --git a/modules/corelib/ui/uiscrollarea.lua b/modules/corelib/ui/uiscrollarea.lua index ff8b375a..b9732acf 100644 --- a/modules/corelib/ui/uiscrollarea.lua +++ b/modules/corelib/ui/uiscrollarea.lua @@ -1,5 +1,5 @@ -- @docclass -UIScrollArea = extends(UIWidget) +UIScrollArea = extends(UIWidget, "UIScrollArea") -- public functions function UIScrollArea.create() diff --git a/modules/corelib/ui/uiscrollbar.lua b/modules/corelib/ui/uiscrollbar.lua index f94d5591..236ec95c 100644 --- a/modules/corelib/ui/uiscrollbar.lua +++ b/modules/corelib/ui/uiscrollbar.lua @@ -1,5 +1,5 @@ -- @docclass -UIScrollBar = extends(UIWidget) +UIScrollBar = extends(UIWidget, "UIScrollBar") -- private functions local function calcValues(self) diff --git a/modules/corelib/ui/uispinbox.lua b/modules/corelib/ui/uispinbox.lua index 30eb23fd..d3c1fca7 100644 --- a/modules/corelib/ui/uispinbox.lua +++ b/modules/corelib/ui/uispinbox.lua @@ -1,5 +1,5 @@ -- @docclass -UISpinBox = extends(UITextEdit) +UISpinBox = extends(UITextEdit, "UISpinBox") function UISpinBox.create() local spinbox = UISpinBox.internalCreate() diff --git a/modules/corelib/ui/uisplitter.lua b/modules/corelib/ui/uisplitter.lua index cf71a045..d8fb2e2e 100644 --- a/modules/corelib/ui/uisplitter.lua +++ b/modules/corelib/ui/uisplitter.lua @@ -1,5 +1,5 @@ -- @docclass -UISplitter = extends(UIWidget) +UISplitter = extends(UIWidget, "UISplitter") function UISplitter.create() local splitter = UISplitter.internalCreate() diff --git a/modules/corelib/ui/uitabbar.lua b/modules/corelib/ui/uitabbar.lua index 43ed3411..be43479d 100644 --- a/modules/corelib/ui/uitabbar.lua +++ b/modules/corelib/ui/uitabbar.lua @@ -1,5 +1,5 @@ -- @docclass -UITabBar = extends(UIWidget) +UITabBar = extends(UIWidget, "UITabBar") -- private functions local function onTabClick(tab) diff --git a/modules/corelib/ui/uitable.lua b/modules/corelib/ui/uitable.lua index d43d6016..af70a01b 100644 --- a/modules/corelib/ui/uitable.lua +++ b/modules/corelib/ui/uitable.lua @@ -5,7 +5,7 @@ * Get dynamic row heights working with text wrapping. * Every second row different background color applied. ]] -UITable = extends(UIWidget) +UITable = extends(UIWidget, "UITable") local HEADER_ID = 'row0' diff --git a/modules/corelib/ui/uiwindow.lua b/modules/corelib/ui/uiwindow.lua index e77473a4..28790051 100644 --- a/modules/corelib/ui/uiwindow.lua +++ b/modules/corelib/ui/uiwindow.lua @@ -1,5 +1,5 @@ -- @docclass -UIWindow = extends(UIWidget) +UIWindow = extends(UIWidget, "UIWindow") function UIWindow.create() local window = UIWindow.internalCreate() @@ -9,10 +9,6 @@ function UIWindow.create() return window end -function UIWindow:getClassName() - return 'UIWindow' -end - function UIWindow:onKeyDown(keyCode, keyboardModifiers) if keyboardModifiers == KeyboardNoModifier then if keyCode == KeyEnter then diff --git a/modules/corelib/util.lua b/modules/corelib/util.lua index e72d226a..bb6e0c5b 100644 --- a/modules/corelib/util.lua +++ b/modules/corelib/util.lua @@ -117,7 +117,11 @@ function disconnect(object, arg1, arg2) end end -function newclass() +function newclass(name) + if not name then + perror(debug.traceback('new class has no name.')) + end + local class = {} function class.internalCreate() local instance = {} @@ -127,10 +131,16 @@ function newclass() return instance end class.create = class.internalCreate + class.__class = name + class.getClassName = function() return name end return class end -function extends(base) +function extends(base, name) + if not name then + perror(debug.traceback('extended class has no name.')) + end + local derived = {} function derived.internalCreate() local instance = base.create() @@ -140,6 +150,9 @@ function extends(base) return instance end derived.create = derived.internalCreate + derived.__class = name + derived.getClassName = function() return name end + derived.super = base return derived end diff --git a/modules/game_interface/widgets/uigamemap.lua b/modules/game_interface/widgets/uigamemap.lua index 3ab9c39d..04ce91ff 100644 --- a/modules/game_interface/widgets/uigamemap.lua +++ b/modules/game_interface/widgets/uigamemap.lua @@ -1,4 +1,4 @@ -UIGameMap = extends(UIMap) +UIGameMap = extends(UIMap, "UIGameMap") function UIGameMap.create() local gameMap = UIGameMap.internalCreate() diff --git a/modules/gamelib/game.lua b/modules/gamelib/game.lua index f05c36c7..54ac7a8d 100644 --- a/modules/gamelib/game.lua +++ b/modules/gamelib/game.lua @@ -52,9 +52,10 @@ function g_game.getSupportedClients() 792, 800, 810, 811, 840, 842, 850, 853, 854, 860, 861, 862, 870, 910, 940, 944, 953, 954, 960, 961, 963, - 970, 980, 981, 982, 983, 984, 985, - 986, 1001, 1002, 1010, 1020, 1021, - 1022, 1031, 1034, 1035, 1036, 1037 + 970, 972, 973, 980, 981, 982, 983, + 984, 985, 986, 1001, 1002, 1010, + 1020, 1021, 1022, 1031, 1034, 1035, + 1036, 1037 } end diff --git a/modules/gamelib/protocollogin.lua b/modules/gamelib/protocollogin.lua index dbea0533..69bc12b4 100644 --- a/modules/gamelib/protocollogin.lua +++ b/modules/gamelib/protocollogin.lua @@ -1,5 +1,5 @@ -- @docclass -ProtocolLogin = extends(Protocol) +ProtocolLogin = extends(Protocol, "ProtocolLogin") LoginServerError = 10 LoginServerUpdate = 17 diff --git a/modules/gamelib/ui/uicreaturebutton.lua b/modules/gamelib/ui/uicreaturebutton.lua index 37cc7b48..c926466f 100644 --- a/modules/gamelib/ui/uicreaturebutton.lua +++ b/modules/gamelib/ui/uicreaturebutton.lua @@ -1,5 +1,5 @@ -- @docclass -UICreatureButton = extends(UIWidget) +UICreatureButton = extends(UIWidget, "UICreatureButton") local CreatureButtonColors = { onIdle = {notHovered = '#888888', hovered = '#FFFFFF' }, @@ -25,10 +25,6 @@ function UICreatureButton.create() return button end -function UICreatureButton:getClassName() - return 'UICreatureButton' -end - function UICreatureButton:setCreature(creature) self.creature = creature end