Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local basalt = require("modules/basalt")
- basalt.setTheme("LabelText", colors.red)
- local player = require("player")
- local main = basalt.createFrame()
- :setBackground(colors.lightBlue)
- local tx, ty = term.current().getSize()
- local title = main
- :addLabel()
- :setText("Message receiver")
- local titleX, titleY = title.getSize()
- title:setPosition(
- math.floor(tx / 2 - titleX / 2) + 1,
- math.floor(2)
- ):setForeground(colors.black)
- local chatFrame = main:addScrollableFrame()
- :setPosition(2, 3)
- :setSize("parent.w - 2", "parent.h - 4")
- :setBackground(colors.black)
- local chatFrameX, chatFrameY = chatFrame:getSize()
- local noMessagesText = chatFrame
- :addLabel()
- :setText("No messages found")
- :setBackground(colors.black)
- :setForeground(colors.red)
- local noMessageX, noMessageY = noMessagesText
- :getSize()
- noMessagesText:setPosition(
- math.floor(chatFrameX / 2 - noMessageX / 2) + 1,
- math.floor(chatFrameY / 2 + 1)
- )
- local current = 1
- local CFWidth, CFHeight = chatFrame.getSize()
- function showMessage(id, message)
- noMessagesText:hide()
- local from = ""
- local textColor = colors.red
- if not id then
- from = "You: "
- textColor = colors.blue
- else
- from = "ID_" .. id .. ": "
- textColor = colors.green
- player.playNotice()
- end
- chatFrame
- :addLabel()
- :setPosition(1, current)
- :setBackground(colors.black)
- :setForeground(textColor)
- :setText(from .. message)
- if current > CFHeight then
- chatFrame:setOffset(0, current - CFHeight)
- end
- current = current + 1
- end
- basalt.onEvent(function(event, client, message)
- if event == "rednet_message" then
- showMessage(client, message)
- end
- end)
- local input = main
- :addInput()
- :setBackground(colors.gray)
- :setForeground(colors.lightBlue)
- :setDefaultText("Send message")
- :setPosition(2, ty - 1)
- :setSize("parent.w - 2", 1)
- :onLoseFocus(function(self)
- local message = self:getValue()
- if message and message ~= "" then
- showMessage(nil, message)
- rednet.broadcast(message)
- end
- self:setValue("")
- end)
- basalt.autoUpdate()
Add Comment
Please, Sign In to add comment