Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --load dependencies
- if fs.exists("stockPile") == false then
- shell.run("pastebin", "get", "bWaSkZ2v", "stockPile")
- end
- if fs.exists("listen") == false then
- shell.run("pastebin", "get", "eEbSAZZV", "listen")
- end
- if fs.exists("API") == false then
- shell.run("pastebin", "get", "EzkfU5ZM", "API")
- end
- if fs.exists("messenger") == false then
- shell.run("pastebin", "get", "cJa7YLVs", "messenger")
- end
- shaka = require("API")
- rednet.open("back")
- shell.run("set", "motd.enable", "false")
- ---functions
- local function receiveInfos()
- if fs.exists(".userData") then
- local msg = nil
- local file = fs.open(".userData", "r")
- local userName = file.readAll()
- file.close()
- local end_index = string.len(userName)
- local computerName = os.computerLabel()
- local extracted_substring = ""
- if computerName ~= nil then
- extracted_substring = string.sub(computerName, 1, end_index)
- end
- if extracted_substring ~= userName then
- os.setComputerLabel(userName.."'s Pocket Rocket")
- end
- rednet.broadcast(userName, "anyMessages?")
- local sender, msg = rednet.receive("notificationReminder", 1)
- if msg ~= nil then
- if tonumber(msg) ~= 0 then
- term.setCursorPos(1,1)
- shaka.changeColors(colors.green, colors.black)
- term.clearLine()
- if tonumber(msg) > 1 then
- shaka.centerText("New messages: " ..msg)
- else
- shaka.centerText("New message!")
- end
- end
- else
- shaka.changeColors(colors.red, colors.black)
- term.clear()
- shaka.centerText("Server not responding!", 7)
- term.setCursorPos(8, 9)
- textutils.slowPrint("Restarting..", 10)
- sleep(2)
- os.reboot()
- end
- else
- shell.run("messenger")
- end
- end
- function showButtons()
- -- Define the buttons and their associated programs and colors
- local buttons = {
- {label="Messenger", program="messenger", color = colors.purple},
- {label="View stockpile items", program="stockPile", color = colors.green},
- {label="Listen to requests", program="listen", color = colors.gray},
- -- {label="test", program="test.lua", color = colors.orange},
- -- {label="Program 5", program="program3.lua", color = colors.red}
- }
- -- Set the background color and padding size
- local bgColor = colors.black
- local padding = 2
- -- Calculate the size of the buttons and the total size of the interface
- local buttonWidth = 24
- local buttonHeight = 3
- local interfaceWidth, interfaceHeight = term.getSize()
- interfaceHeight = (buttonHeight + padding) * #buttons + padding
- -- Create a new canvas to draw the interface on
- local canvas = {}
- for y = 1, interfaceHeight do
- canvas[y] = {}
- for x = 1, interfaceWidth do
- canvas[y][x] = {bg = bgColor, fg = colors.white, char = " "}
- end
- end
- -- Draw the background on the canvas
- term.setBackgroundColor(colors.black)
- term.clear()
- -- Draw the buttons on the canvas
- for i, button in ipairs(buttons) do
- local x = padding
- local y = padding + (i-1) * (buttonHeight + padding)
- for y2 = y, y + buttonHeight - 1 do
- for x2 = x, x + buttonWidth - 1 do
- canvas[y2][x2].bg = button.color
- end
- end
- local label = string.sub(button.label, 1, buttonWidth)
- local labelLength = #label
- local labelX = x + math.floor((buttonWidth - labelLength) / 2)
- local labelY = y + math.floor((buttonHeight - 1) / 2)
- for j = 1, labelLength do
- canvas[labelY][labelX+j-1] = {bg = button.color, fg = colors.black, char = string.sub(label, j, j)}
- end
- end
- -- Draw the canvas on the screen
- term.setBackgroundColor(bgColor)
- term.clear()
- for y = 1, interfaceHeight do
- for x = 1, interfaceWidth do
- term.setCursorPos(x, y)
- term.setTextColor(canvas[y][x].fg)
- term.setBackgroundColor(canvas[y][x].bg)
- term.write(canvas[y][x].char)
- end
- end
- receiveInfos()
- -- Wait for a button to be clicked
- -- while true do
- local event, _, x, y = os.pullEvent("mouse_click")
- for i, button in ipairs(buttons) do
- local buttonX = padding
- local buttonY = padding + (i-1) * (buttonHeight + padding)
- if x >= buttonX and x < buttonX + buttonWidth and y >= buttonY and y < buttonY + buttonHeight then
- shell.run(button.program)
- return
- end
- end
- -- end
- end
- function receiveReminders()
- msg = nil
- local id, msg, protocol = rednet.receive("notificationReminder")
- print(id, msg, protocol)
- if msg ~= nil then
- if tonumber(msg) ~= 0 then
- term.setCursorPos(1,1)
- shaka.changeColors(colors.green, colors.black)
- term.clearLine()
- if tonumber(msg) > 1 then
- shaka.centerText("New messages: " ..msg)
- else
- shaka.centerText("New message!")
- end
- end
- end
- end
- while true do
- showButtons()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement