Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("graphics.lua")
- notifications = {}
- drawingNotifications = false
- function createNotification(text, bkgColor, txtColor)
- notification = graphics.label:new()
- notification.text = text
- length = string.len(text)
- local w, h = term.getSize()
- notification.x = (w / 2) - (length / 2) + 1
- notification.y = 1
- notification.bkgColor = bkgColor
- notification.tColor = txtColor
- return notification
- end
- function addNotification(name, timer, text, bkgColor, txtColor)
- found = false
- for k,v in pairs(notifications) do
- if v["name"] == name then
- found = true
- notifications[k]["notification"].text = text
- notifications[k]["notification"].bkgColor = bkgColor
- notifications[k]["notification"].tColor = txtColor
- notifications[k]["time"] = timer
- notifiTable["text"] = text
- end
- end
- if found == false then
- notification = createNotification(text, bkgColor, txtColor)
- notifiTable = {}
- notifiTable["name"] = name
- notifiTable["notification"] = notification
- notifiTable["time"] = timer
- notifiTable["text"] = text
- table.insert(notifications, notifiTable)
- end
- end
- function drawNotifications()
- for k,v in pairs(notifications) do
- if v["time"] >= 0 then
- drawingNotifications = true
- v["notification"].draw(v["notification"])
- end
- end
- end
- function timeNotifications()
- for k,v in pairs(notifications) do
- if notifications[k]["time"] >= 0 then
- t = v["time"] - 1
- notifications[k]["time"] = t
- term.setCursorPos(notifications[k]["notification"].x,notifications[k]["notification"].y)
- term.setBackgroundColor(v["notification"].bkgColor)
- term.clearLine()
- drawingNotifications = true
- v["notification"].draw(v["notification"])
- else
- term.setCursorPos(notifications[k]["notification"].x,notifications[k]["notification"].y)
- term.setBackgroundColor(settings.headerColor)
- term.clearLine()
- notifications[k] = nil
- table.remove(notifications, k)
- drawingNotifications = false
- end
- end
- end
- function update()
- timeNotifications()
- drawNotifications()
- if drawingNotifications == false then
- notification = graphics.label:new()
- notification.text = settings.headerText
- length = string.len(notification.text)
- local w, h = term.getSize()
- notification.x = (w / 2) - (length / 2) + 1
- notification.y = 1
- notification.bkgColor = colors.blue
- notification.tColor = colors.white
- notification.draw(notification)
- end
- end
Add Comment
Please, Sign In to add comment