Some fixes for class names and queue (added base class).

This commit is contained in:
BenDol 2014-06-07 04:10:14 +12:00
parent 00253e46b3
commit c083d02bef
29 changed files with 94 additions and 59 deletions

View File

@ -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

View File

@ -3,21 +3,15 @@
@Details: Queue class for event queuing. @Details: Queue class for event queuing.
]] ]]
Queue = {} Queue = newclass("Queue")
Queue.__index = Queue
Queue.__class = "Queue" Queue.create = function(callback)
local obj = Queue.internalCreate()
Queue.new = function(callback) obj.queue = {}
que = { obj.callback = callback
queue = {},
callback = nil
}
que.callback = callback return obj
setmetatable(que, Queue)
return que
end end
-- gets/sets -- gets/sets

View File

@ -6,8 +6,6 @@ Module
reloadable: false reloadable: false
@onLoad: | @onLoad: |
dofiles 'classes'
dofile 'math' dofile 'math'
dofile 'string' dofile 'string'
dofile 'table' dofile 'table'
@ -22,6 +20,7 @@ Module
dofile 'mouse' dofile 'mouse'
dofile 'net' dofile 'net'
dofiles 'classes'
dofiles 'ui' dofiles 'ui'
dofile 'inputmessage' dofile 'inputmessage'

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UIButton = extends(UIWidget) UIButton = extends(UIWidget, "UIButton")
function UIButton.create() function UIButton.create()
local button = UIButton.internalCreate() local button = UIButton.internalCreate()

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UICheckBox = extends(UIWidget) UICheckBox = extends(UIWidget, "UICheckBox")
function UICheckBox.create() function UICheckBox.create()
local checkbox = UICheckBox.internalCreate() local checkbox = UICheckBox.internalCreate()

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UIComboBox = extends(UIWidget) UIComboBox = extends(UIWidget, "UIComboBox")
function UIComboBox.create() function UIComboBox.create()
local combobox = UIComboBox.internalCreate() local combobox = UIComboBox.internalCreate()

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UIImageView = extends(UIWidget) UIImageView = extends(UIWidget, "UIImageView")
function UIImageView.create() function UIImageView.create()
local imageView = UIImageView.internalCreate() local imageView = UIImageView.internalCreate()

View File

@ -1,7 +1,7 @@
if not UIWindow then dofile 'uiwindow' end if not UIWindow then dofile 'uiwindow' end
-- @docclass -- @docclass
UIInputBox = extends(UIWindow) UIInputBox = extends(UIWindow, "UIInputBox")
function UIInputBox.create(title, okCallback, cancelCallback) function UIInputBox.create(title, okCallback, cancelCallback)
local inputBox = UIInputBox.internalCreate() local inputBox = UIInputBox.internalCreate()

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UILabel = extends(UIWidget) UILabel = extends(UIWidget, "UILabel")
function UILabel.create() function UILabel.create()
local label = UILabel.internalCreate() local label = UILabel.internalCreate()

View File

@ -1,7 +1,7 @@
if not UIWindow then dofile 'uiwindow' end if not UIWindow then dofile 'uiwindow' end
-- @docclass -- @docclass
UIMessageBox = extends(UIWindow) UIMessageBox = extends(UIWindow, "UIMessageBox")
-- messagebox cannot be created from otui files -- messagebox cannot be created from otui files
UIMessageBox.create = nil UIMessageBox.create = nil

View File

@ -1,15 +1,11 @@
-- @docclass -- @docclass
UIMiniWindow = extends(UIWindow) UIMiniWindow = extends(UIWindow, "UIMiniWindow")
function UIMiniWindow.create() function UIMiniWindow.create()
local miniwindow = UIMiniWindow.internalCreate() local miniwindow = UIMiniWindow.internalCreate()
return miniwindow return miniwindow
end end
function UIMiniWindow:getClassName()
return 'UIMiniWindow'
end
function UIMiniWindow:open(dontSave) function UIMiniWindow:open(dontSave)
self:setVisible(true) self:setVisible(true)

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UIMiniWindowContainer = extends(UIWidget) UIMiniWindowContainer = extends(UIWidget, "UIMiniWindowContainer")
function UIMiniWindowContainer.create() function UIMiniWindowContainer.create()
local container = UIMiniWindowContainer.internalCreate() local container = UIMiniWindowContainer.internalCreate()
@ -9,10 +9,6 @@ function UIMiniWindowContainer.create()
return container return container
end end
function UIMiniWindowContainer:getClassName()
return 'UIMiniWindowContainer'
end
-- TODO: connect to window onResize event -- TODO: connect to window onResize event
-- TODO: try to resize another widget? -- TODO: try to resize another widget?
-- TODO: try to find another panel? -- TODO: try to find another panel?

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UIMoveableTabBar = extends(UIWidget) UIMoveableTabBar = extends(UIWidget, "UIMoveableTabBar")
-- private functions -- private functions
local function onTabClick(tab) local function onTabClick(tab)

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UIPopupMenu = extends(UIWidget) UIPopupMenu = extends(UIWidget, "UIPopupMenu")
local currentMenu local currentMenu

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UIProgressBar = extends(UIWidget) UIProgressBar = extends(UIWidget, "UIProgressBar")
function UIProgressBar.create() function UIProgressBar.create()
local progressbar = UIProgressBar.internalCreate() local progressbar = UIProgressBar.internalCreate()

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UIRadioGroup = newclass() UIRadioGroup = newclass("UIRadioGroup")
function UIRadioGroup.create() function UIRadioGroup.create()
local radiogroup = UIRadioGroup.internalCreate() local radiogroup = UIRadioGroup.internalCreate()

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UIResizeBorder = extends(UIWidget) UIResizeBorder = extends(UIWidget, "UIResizeBorder")
function UIResizeBorder.create() function UIResizeBorder.create()
local resizeborder = UIResizeBorder.internalCreate() local resizeborder = UIResizeBorder.internalCreate()

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UIScrollArea = extends(UIWidget) UIScrollArea = extends(UIWidget, "UIScrollArea")
-- public functions -- public functions
function UIScrollArea.create() function UIScrollArea.create()

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UIScrollBar = extends(UIWidget) UIScrollBar = extends(UIWidget, "UIScrollBar")
-- private functions -- private functions
local function calcValues(self) local function calcValues(self)

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UISpinBox = extends(UITextEdit) UISpinBox = extends(UITextEdit, "UISpinBox")
function UISpinBox.create() function UISpinBox.create()
local spinbox = UISpinBox.internalCreate() local spinbox = UISpinBox.internalCreate()

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UISplitter = extends(UIWidget) UISplitter = extends(UIWidget, "UISplitter")
function UISplitter.create() function UISplitter.create()
local splitter = UISplitter.internalCreate() local splitter = UISplitter.internalCreate()

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UITabBar = extends(UIWidget) UITabBar = extends(UIWidget, "UITabBar")
-- private functions -- private functions
local function onTabClick(tab) local function onTabClick(tab)

View File

@ -5,7 +5,7 @@
* Get dynamic row heights working with text wrapping. * Get dynamic row heights working with text wrapping.
* Every second row different background color applied. * Every second row different background color applied.
]] ]]
UITable = extends(UIWidget) UITable = extends(UIWidget, "UITable")
local HEADER_ID = 'row0' local HEADER_ID = 'row0'

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UIWindow = extends(UIWidget) UIWindow = extends(UIWidget, "UIWindow")
function UIWindow.create() function UIWindow.create()
local window = UIWindow.internalCreate() local window = UIWindow.internalCreate()
@ -9,10 +9,6 @@ function UIWindow.create()
return window return window
end end
function UIWindow:getClassName()
return 'UIWindow'
end
function UIWindow:onKeyDown(keyCode, keyboardModifiers) function UIWindow:onKeyDown(keyCode, keyboardModifiers)
if keyboardModifiers == KeyboardNoModifier then if keyboardModifiers == KeyboardNoModifier then
if keyCode == KeyEnter then if keyCode == KeyEnter then

View File

@ -117,7 +117,11 @@ function disconnect(object, arg1, arg2)
end end
end end
function newclass() function newclass(name)
if not name then
perror(debug.traceback('new class has no name.'))
end
local class = {} local class = {}
function class.internalCreate() function class.internalCreate()
local instance = {} local instance = {}
@ -127,10 +131,16 @@ function newclass()
return instance return instance
end end
class.create = class.internalCreate class.create = class.internalCreate
class.__class = name
class.getClassName = function() return name end
return class return class
end end
function extends(base) function extends(base, name)
if not name then
perror(debug.traceback('extended class has no name.'))
end
local derived = {} local derived = {}
function derived.internalCreate() function derived.internalCreate()
local instance = base.create() local instance = base.create()
@ -140,6 +150,9 @@ function extends(base)
return instance return instance
end end
derived.create = derived.internalCreate derived.create = derived.internalCreate
derived.__class = name
derived.getClassName = function() return name end
derived.super = base
return derived return derived
end end

View File

@ -1,4 +1,4 @@
UIGameMap = extends(UIMap) UIGameMap = extends(UIMap, "UIGameMap")
function UIGameMap.create() function UIGameMap.create()
local gameMap = UIGameMap.internalCreate() local gameMap = UIGameMap.internalCreate()

View File

@ -52,9 +52,10 @@ function g_game.getSupportedClients()
792, 800, 810, 811, 840, 842, 850, 792, 800, 810, 811, 840, 842, 850,
853, 854, 860, 861, 862, 870, 910, 853, 854, 860, 861, 862, 870, 910,
940, 944, 953, 954, 960, 961, 963, 940, 944, 953, 954, 960, 961, 963,
970, 980, 981, 982, 983, 984, 985, 970, 972, 973, 980, 981, 982, 983,
986, 1001, 1002, 1010, 1020, 1021, 984, 985, 986, 1001, 1002, 1010,
1022, 1031, 1034, 1035, 1036, 1037 1020, 1021, 1022, 1031, 1034, 1035,
1036, 1037
} }
end end

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
ProtocolLogin = extends(Protocol) ProtocolLogin = extends(Protocol, "ProtocolLogin")
LoginServerError = 10 LoginServerError = 10
LoginServerUpdate = 17 LoginServerUpdate = 17

View File

@ -1,5 +1,5 @@
-- @docclass -- @docclass
UICreatureButton = extends(UIWidget) UICreatureButton = extends(UIWidget, "UICreatureButton")
local CreatureButtonColors = { local CreatureButtonColors = {
onIdle = {notHovered = '#888888', hovered = '#FFFFFF' }, onIdle = {notHovered = '#888888', hovered = '#FFFFFF' },
@ -25,10 +25,6 @@ function UICreatureButton.create()
return button return button
end end
function UICreatureButton:getClassName()
return 'UICreatureButton'
end
function UICreatureButton:setCreature(creature) function UICreatureButton:setCreature(creature)
self.creature = creature self.creature = creature
end end