Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local callback
- do
- local callback_id = 0
- callback = setmetatable({ }, {
- __call = function(this, eventName, x, y, w, h, hidden)
- local id = callback_id
- local action
- local hasClickableRange, range = false, 0
- local fixed = false
- local textarea = function(playerName)
- ui.addTextArea(id, "<textformat leftmargin='1' rightmargin='1'><a href='event:callback." .. eventName .. "'>" .. string.rep('\n', h / 10), playerName, x - 5, y - 5, w + 5, h + 5, 1, 1, 0, fixed)
- end
- local self = {
- callback = eventName,
- x = x,
- y = y,
- w = w,
- h = h
- }
- self.displayCallback = function(self, f)
- if type(f) == "string" then
- return textarea(f)
- end
- for k, v in next, tfm.get.room.playerList do
- if not f or f(k, v) then
- textarea(k)
- end
- end
- end
- self.fixed = function(self)
- fixed = true
- return self
- end
- self.inClickableRange = function(self, playerName)
- if hasClickableRange then
- local x, y = tfm.get.room.playerList[playerName].x, tfm.get.room.playerList[playerName].y
- return ((x >= (self.x - range) and x <= (self.x + self.w + range)) and (y >= (self.y - range) and y <= (self.y + self.h + range)))
- end
- return true
- end
- self.performAction = function(self, ...)
- if action then
- action(self, ...)
- return self, true
- end
- return self, false
- end
- self.remove = function(self, playerName)
- ui.removeTextArea(id, playerName)
- if not playerName then
- this[eventName] = nil
- end
- return true
- end
- self.setAction = function(self, f)
- if type(f) == "function" then
- action = f
- this[eventName] = self
- return true
- end
- return false
- end
- self.setClickableRange = function(self, complement)
- hasClickableRange, range = true, (complement or 0)
- end
- if not hidden then
- self.displayCallback(self)
- end
- callback_id = callback_id + 1
- return self
- end
- })
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement