Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----FUNCTIONS-----
- local function len(a)
- local length = 0
- for i in pairs(a) do
- length = length + 1
- end
- return length
- end
- --MAIN SCREEN
- local function drawMainScreen(createButton, editButton, deleteButton, width)
- term.clear()
- term.setCursorPos(width/2-7, 4)
- term.write("Art Submissions")
- term.setCursorPos(createButton.x, createButton.y)
- term.write(createButton.content)
- term.setCursorPos(editButton.x, editButton.y)
- term.write(editButton.content)
- term.setCursorPos(deleteButton.x, deleteButton.y)
- term.write(deleteButton.content)
- end
- --CREATE SCREEN
- local function drawNameScreen(width)
- term.clear()
- term.setCursorPos(width/2-6, 4)
- term.write("Name your art")
- term.setCursorPos(width/2-13, 10)
- term.write("Enter an empty name to exit")
- term.setCursorPos(width/2-10, 6)
- term.blit("00000000000000000000", "00000000000000000000", "00000000000000000000")
- term.setCursorPos(width/2-10, 6)
- end
- local function createButtons(width)
- local createButton = {}
- local editButton = {}
- local deleteButton = {}
- createButton.x = 3
- createButton.y = 18
- createButton.content = "Create"
- editButton.x = 46
- editButton.y = 18
- editButton.content = "Edit"
- deleteButton.x = width/2-3
- deleteButton.y = 18
- deleteButton.content = "Delete"
- return createButton, editButton, deleteButton
- end
- --Sync
- local function syncImages()
- local images = fs.list("artSubmissions")
- local length = len(images)
- for i=1, length do
- local image = io.open("artSubmissions/" .. images[i], "r")
- local data = {}
- data.data = image.read(image, "a")
- data.name = images[i]
- data.protocol = "Input"
- rednet.broadcast(data, "Import")
- image.close(image)
- end
- end
- --LIST SCREEN
- local function drawList(amt)
- local width, height = term.getSize()
- local images = fs.list("artSubmissions")
- term.clear()
- local length = len(images)
- local curY = 1
- for i=height*(amt-1)+1, height*amt do
- term.setCursorPos(1, curY)
- if images[i] then
- term.write(i .. ": " .. images[i])
- end
- curY = curY + 1
- end
- term.setCursorPos(52-17, 1)
- term.write("Backspace to exit")
- return images, length
- end
- ------MAIN CODE------
- --Setting up path
- if not fs.exists("artSubmissions") then
- fs.makeDir("artSubmissions")
- end
- shell.setDir("artSubmissions")
- local width, height = term.getSize()
- local createButton, editButton, deleteButton = createButtons(width)
- rednet.open("bottom")
- while true do
- drawMainScreen(createButton, editButton, deleteButton, width)
- syncImages()
- local event, button, x, y = os.pullEvent("mouse_click")
- --CREATE BUTTON
- if x >= createButton.x and x <= createButton.x + 6 and y == createButton.y and button == 1 then
- drawNameScreen(width)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- local artName = read()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- local artName = string.gsub(artName, " ", "")
- shell.execute("paint", artName)
- --EDIT BUTTON
- elseif x >=editButton.x and x <= editButton.x + 4 and y == editButton.y and button == 1 then
- local amt = 1
- while true do
- local images, length = drawList(amt)
- term.setCursorPos(50, 18)
- print(amt)
- local eventData = {os.pullEvent()}
- if eventData[1] == "mouse_click" then
- if eventData[2] == 1 and eventData[4] <= length - height * (amt-1) and length > 0 then
- shell.execute("paint", images[eventData[4]+(height*(amt-1))])
- break
- end
- elseif eventData[1] == "key" then
- if keys.getName(eventData[2]) == "backspace" then
- break
- elseif keys.getName(eventData[2]) == "down" then
- if (length > height * amt) then
- amt = amt + 1
- end
- elseif keys.getName(eventData[2]) == "up" then
- if (amt > 1) then
- amt = amt - 1
- end
- end
- elseif eventData[1] == "mouse_scroll" then
- if (tonumber(eventData[2]) == 1) then
- if (length > height * amt) then
- amt = amt + 1
- end
- else
- if (amt > 1) then
- amt = amt - 1
- end
- end
- end
- end
- --DELETE BUTTON
- elseif x >= deleteButton.x and x <= deleteButton.x + 6 and y == deleteButton.y and button ==1 then
- local amt = 1
- while true do
- local images, length = drawList(amt)
- term.setCursorPos(50, 18)
- print(amt)
- local eventData = {os.pullEvent()}
- if eventData[1] == "mouse_click" then
- if eventData[2] == 1 and eventData[4] <= length - height * (amt-1) and length > 0 then
- fs.delete("artSubmissions/" .. images[eventData[4]+(height*(amt-1))])
- local data = {}
- data.data = nil
- data.name = images[eventData[4]+(height*(amt-1))]
- data.protocal = "Delete"
- rednet.broadcast(data)
- break
- end
- elseif eventData[1] == "key" then
- if keys.getName(eventData[2]) == "backspace" then
- break
- elseif keys.getName(eventData[2]) == "down" then
- if (length > height * amt) then
- amt = amt + 1
- end
- elseif keys.getName(eventData[2]) == "up" then
- if (amt > 1) then
- amt = amt - 1
- end
- end
- elseif eventData[1] == "mouse_scroll" then
- if (tonumber(eventData[2]) == 1) then
- if (length > height * amt) then
- amt = amt + 1
- end
- else
- if (amt > 1) then
- amt = amt - 1
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement