Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local termX, termY = term.getSize()
- local wind = window.create(term.current(), 1, 1, termX, termY, false)
- local bgColor = colors.white
- local altBgColor = colors.blue
- local fgColor = colors.blue
- local altFgColor = colors.white
- local frameColor = colors.green
- local altFrameColor = colors.red
- local overlay = {}
- local reverse = {}
- local direction = {"right","front","bottom","left","back","top"}
- local cols = {colors.black, colors.gray, colors.lightGray, colors.white, colors.pink, colors.magenta, colors.purple, colors.red, colors.lightBlue, colors.blue, colors.cyan, colors.green, colors.lime, colors.yellow, colors.orange, colors.brown}
- local ender = nil
- local coord = {}
- local highlight = {nil,nil,nil}
- local function drawColor(color,row)
- local x,y = wind.getCursorPos()
- local frame = window.create(wind,x-1,y-1,4,4,false)
- if color == frameColor then frame.setBackgroundColor(altFrameColor)
- else frame.setBackgroundColor(frameColor)
- end
- frame.clear()
- local clearFrame = window.create(wind,x-1,y-1,4,4,false)
- if x < 15 then clearFrame.setBackgroundColor(altBgColor)
- else clearFrame.setBackgroundColor(bgColor)
- end
- clearFrame.clear()
- if x == 15 then
- clearFrame.setBackgroundColor(altBgColor)
- for i=1,4 do
- clearFrame.setCursorPos(1,i)
- clearFrame.write(" ")
- end
- end
- reverse[textutils.serialize({color,row})] = {x,y}
- local function draw()
- wind.setBackgroundColor(color)
- frame.setBackgroundColor(color)
- clearFrame.setBackgroundColor(color)
- for i=1,2 do
- coord[textutils.serialize({wind.getCursorPos()})] = {color,row}
- overlay[textutils.serialize({wind.getCursorPos()})] = {frame,row,clearFrame}
- wind.write(" ")
- frame.write(" ")
- clearFrame.write(" ")
- end
- end
- wind.setCursorPos(x,y)
- frame.setCursorPos(2,2)
- clearFrame.setCursorPos(2,2)
- draw()
- wind.setCursorPos(x,y+1)
- frame.setCursorPos(2,3)
- clearFrame.setCursorPos(2,3)
- draw()
- wind.setCursorPos(x+3,y)
- end
- local function prepareWindow()
- wind.setVisible(false)
- wind.setBackgroundColor(bgColor)
- wind.setTextColor(fgColor)
- wind.clear()
- wind.setBackgroundColor(altBgColor)
- for i=1,19 do
- wind.setCursorPos(1,i)
- wind.write(" ")
- end
- wind.setCursorPos(1,1)
- wind.setBackgroundColor(altBgColor)
- wind.setTextColor(altFgColor)
- wind.write("Ender Chest/Ta")
- wind.setBackgroundColor(bgColor)
- wind.setTextColor(fgColor)
- wind.write("nk Colour Coder")
- wind.setCursorPos(1,termY)
- wind.setBackgroundColor(altBgColor)
- wind.setTextColor(altFgColor)
- wind.write("Press Escape t")
- wind.setBackgroundColor(bgColor)
- wind.setTextColor(fgColor)
- wind.write("o exit")
- coord = {}
- local startX, startY = 3, 5
- local function draw(row)
- local _,Y = wind.getCursorPos()
- for n,c in pairs(cols) do
- --if n == 9 then wind.setCursorPos(startX,Y+offset) end
- --coord[textutils.serialize({wind.getCursorPos()})] = c
- drawColor(c,row)
- end
- end
- wind.setCursorPos(startX,startY)
- draw(1)
- wind.setCursorPos(startX,startY + 4)
- draw(2)
- wind.setCursorPos(startX,startY + 8)
- draw(3)
- wind.setVisible(true)
- end
- local function drawUserInterface()
- wind.redraw()
- end
- local function switchVisible(frame, row, clearFrame, col)
- local oldClear = nil
- if highlight[row] then
- if highlight[row][1] then
- highlight[row][1].setVisible(false)
- end
- if highlight[row][2] then
- highlight[row][2].setVisible(true)
- end
- if highlight[row][3] then
- highlight[row][3].setVisible(false)
- end
- oldClear = highlight[row][2]
- end
- highlight[row] = {frame,clearFrame,oldClear}
- frame.setVisible(true)
- --if not ender then refreshChest() end
- if ender and col and col[1] and col[2] then
- local currentColors = {}
- currentColors[1], currentColors[2], currentColors[3] = ender.getColors()
- if currentColors[1] and currentColors[2] and currentColors[3] then
- currentColors[col[2]] = col[1]
- ender.setColors(currentColors[1],currentColors[2],currentColors[3])
- end
- end
- end
- local function removeOverlay()
- for i=1,3 do
- if highlight[i] then
- if highlight[i][3] then
- highlight[i][3].setVisible(false)
- end
- if highlight[i][2] then
- highlight[i][2].setVisible(true)
- highlight[i][3] = highlight[i][2]
- highlight[i][2] = nil
- end
- if highlight[i][1] then
- highlight[i][1].setVisible(false)
- highlight[i][1] = nil
- end
- end
- end
- end
- local function refreshChest()
- for i,dir in pairs(direction) do
- --rs.getSides()
- if peripheral.getType(dir) == "ender_chest" or peripheral.getType(dir) == "ender_tank" then
- ender = peripheral.wrap(dir)
- end
- if ender then break end
- end
- if ender then
- removeOverlay()
- local currentColors = {}
- currentColors[1], currentColors[2], currentColors[3] = ender.getColors()
- for i=1,3 do
- local frame = overlay[textutils.serialize(reverse[textutils.serialize({currentColors[i],i})])]
- --local col = coord[textutils.serialize(reverse[textutils.serialize({currentColors[i],i})])]
- if frame and frame[1] and frame[2] and frame[3] then switchVisible(frame[1],frame[2],frame[3],nil) end
- end
- end
- end
- prepareWindow()
- while true do
- drawUserInterface()
- local event, button, xPos, yPos = os.pullEvent()
- if event == "peripheral" then refreshChest() end
- if event == "mouse_click" and button == 1 then
- refreshChest()
- local frame = overlay[textutils.serialize({xPos,yPos})]
- local col = coord[textutils.serialize({xPos,yPos})]
- if frame and frame[1] and frame[2] and frame[3] then switchVisible(frame[1],frame[2],frame[3],col)
- --else refreshChest()
- end
- --drawUserInterface()
- end
- sleep(0.2)
- end
Advertisement
Add Comment
Please, Sign In to add comment