Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local m = peripheral.wrap( "SIDE" )
- local w, h = m.getSize()
- local divx = math.floor((w-3) / 3)
- local divy = math.floor((y-1) / 2)
- local butColor = colors.red
- local usedColor = colors.pink
- local colorBUND = 0
- local tCoords = {
- -- xMin, xMax, yMin, yMax, numb
- [1] = {1, 1+divx, 1, 1+divy, text = "1", used = false, colorVal = 1},
- [2] = {2+divx, 3+divx, 2+divy, 3+divy, text = "2", used = false, colorVal = 2},
- [3] = {4+divx, 5+divx, 2+divy, 3+divy, text = "3", used = false, colorVal = 4},
- [4] = {6+divx, 7+divx, 4+divy, 5+divy, text = "4", used = false, colorVal = 8},
- [5] = {8+divx, 9+divx, 4+divy, 5+divy, text = "5", used = false, colorVal = 16},
- [6] = {10+divx, 11+divx, 4+divy, 5+divy, text = "6", used = false, colorVal = 32}
- }
- function fillButton( xMin, xMax, yMin, yMax, color)
- local color = color or colors.black
- m.setBackgroundColor( color )
- for i = 1, yMax - yMin do
- term.setCursorPos( xMin, i )
- m.write( string.rep( " ", xMax - xMin ))
- end
- m.setBackgroundColor( colors.black )
- end
- function cWrite( str, yPos, color)
- local color = color or colors.white
- local w, h = m.getSize()
- m.setCursorPos( math.floor( (w - #str)\2), yPos)
- m.setTextColor( color )
- m.write( str )
- m.setTextColor( colors.white )
- end
- function cWriteBound( xMin, xMax, str)
- local bound = xMax - xMin
- return xMin + math.floor( (bound - #str )/2 )
- end
- while true do
- cWrite( "Activate", math.floor(y/2), colors.white)
- fillButton( w-(w-1), w-1, y-(y-1), y-1, colors.red)
- local evt = { os.pullEvent( "monitor_touch") }
- if evt[3] >= w - (w - 1) and evt[3] <= w - 1 and evt[4] >= y - (y - 1) and evt[4] <= y - 1 then
- break
- end
- end
- m.clear()
- for i = 1, #tCoords do
- fillButton( tCoords[i][1], tCoords[i][2], tCoords[i][3], tCoords[i][4], butColor)
- if i <= 3 then
- term.setCursorPos( cWriteBound(tCoords[i][1], tCoords[i][2], tCoords[i].text ), math.floor(divy/2) )
- else
- term.setCursorPos( cWriteBound(tCoords[i][1], tCoords[i][2], tCoords[i].text ), math.floor(divy/2) + divy )
- end
- write(tCoords[i].text)
- end
- while true do
- local evt = {os.pullEvent("monitor_touch")}
- local button
- for i = 1, #tCoords do
- if evt[3] >= tCoords[i][1] and evt[3] <= tCoords[i][2] and evt[4] >= tCoords[i][3] and evt[4] <= tCoords[i][4] then
- button = i
- end
- end
- if type( button ) == "number" then
- if not tCoords[button].used then
- fillButton( tCoords[button][1], tCoords[button][2], tCoords[button][3], tCoords[button][4], usedColor)
- tCoords[button].used = true
- colorBUND = colorBUND + tCoords[button].colorVal
- elseif tCoords[button].used then
- fillButton( tCoords[button][1], tCoords[button][2], tCoords[button][3], tCoords[button][4], butColor)
- tCoords[button].used = false
- colorBUND = colorBUND - tCoords[button].colorVal
- end
- rs.setBundledOutput( "SIDE", colorBUND )
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment