Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Ender Chest chooser
- local screenDim = {}
- screenDim.x, screenDim.y = term.getSize()
- local players = {eniallator = 3584, YaEyezOnMe = 2816, eriyo2000 = 267}
- local numPlayers = 3
- local selectedPlayer = "no one"
- local turtleID = 48
- local boxWidth = math.floor(screenDim.x /numPlayers +0.5)
- local displayTab = {}
- local nameDisplayLimit = boxWidth -2
- local community = {name = "Community", id = 1536}
- community.button = {screenDim.x -#community.name -1, 1, screenDim.x, 1, colours.lime, community.name, community.name}
- rednet.open("right")
- term.setBackgroundColor(colours.black)
- shell.run("clear")
- local function makeDisplayTab()
- for k,v in pairs(players) do
- table.insert(displayTab,{#displayTab *boxWidth +2, 3, (#displayTab +1) *boxWidth -1, screenDim.y -1, colours.blue, k:sub(1, nameDisplayLimit), k})
- end
- end
- makeDisplayTab()
- -- tab format {x1,y1,x2,y2,background colour, substringed app name (for display purposes), original app name}
- local function fillArea(tab)
- term.setBackgroundColor(tab[5])
- for i=0,tab[4]-tab[2] do
- local j = 0
- while j <= tab[3]-tab[1] do
- term.setCursorPos(tab[1]+j,tab[2]+i)
- if tab[6] and math.floor(j-((tab[3]-tab[1])/2)+#tab[6]/2) == 0 and math.floor(i-(tab[4]-tab[2])/2) == 0 then
- -- If statement seeing whether the iterators have hit the place where it should be writing the word out
- term.write(tab[6])
- j = j + #tab[6]
- else
- j = j + 1
- term.write(" ")
- end
- end
- end
- end
- local function displayScreen()
- fillArea({1,1,screenDim.x,1,colours.black})
- term.setCursorPos(1,1)
- term.write("Selected: " .. selectedPlayer)
- fillArea(community.button)
- for i=1,#displayTab do
- fillArea(displayTab[i])
- end
- end
- local function detectClick(tab, x, y)
- if tab[1] <= x and tab[3] >= x and tab[2] <= y and tab[4] >= y then
- return tab[7]
- end
- end
- local function clickDetectDisplay(x, y)
- for i=1, #displayTab do
- if detectClick(displayTab[i], x, y) then
- return displayTab[i][7]
- end
- end
- return false
- end
- local function checkDone()
- local done = false
- repeat
- local received = {}
- received.id, received.msg = rednet.receive()
- if received.id == turtleID and received.msg == "done" then
- done = true
- end
- until done
- end
- while true do
- makeDisplayTab()
- displayScreen()
- if justSent then
- checkDone()
- justSent = false
- end
- local event = {}
- event.type, event.button, event.x, event.y = os.pullEvent()
- if event.type == "mouse_click" or event.type == "monitor_touch" then
- local clickedPlayer = clickDetectDisplay(event.x, event.y)
- if clickedPlayer then
- selectedPlayer = clickedPlayer
- rednet.send(turtleID, players[clickedPlayer])
- justSent = true
- elseif detectClick(community.button, event.x, event.y) then
- selectedPlayer = community.name
- rednet.send(turtleID, community.id)
- justSent = true
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement