Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.wrap("top")
- local selected = 0
- local names = {"Gau","Xun","FS"}
- local cableSide = "bottom"
- local GauSwitchIn = colors.pink
- local GauToggleOut = colors.red
- local XunMainSwitchOut = colors.black
- local XunMainSwitchState = false
- function SetColor(row)
- if ( selected == row ) then
- mon.setTextColor(colors.black)
- mon.setBackgroundColor(colors.white)
- else
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- end
- end
- function CheckSwitch(color)
- local state = rs.getBundledInput(cableSide)
- return colors.test(state,color)
- end
- function getSelected()
- if ( XunMainSwitchState == true ) then return 2 end
- if ( CheckSwitch(GauSwitchIn) ) then return 1 end
- return 3
- end
- function FindSelected()
- selected = getSelected()
- end
- function DrawScreen()
- if ( selected == 0 ) then FindSelected() end
- mon.clear()
- for row = 1,#names do
- mon.setCursorPos(1,row)
- SetColor(row)
- mon.write(names[row])
- end
- SetColor(-1)
- end
- function pulse(color)
- local oldColor = rs.getBundledOutput(cableSide)
- local newColor = colors.combine(color,oldColor)
- rs.setBundledOutput(cableSide,newColor)
- os.sleep(0.2)
- rs.setBundledOutput(cableSide,oldColor)
- end
- function SetTrack(FSnew,XunNew)
- XunMainSwitchState = FSnew
- if ( XunNew ~= CheckSwitch(GauSwitchIn) ) then pulse(GauToggleOut) end
- if ( XunMainSwitchState ) then rs.setBundledOutput(cableSide,XunMainSwitchOut)
- else rs.setBundledOutput(cableSide,0) end
- end
- function NewTrack(row)
- if ( row > #names ) then return end
- if ( row == selected ) then return end
- if ( row == 1 ) then
- SetTrack(false,true)
- end
- if ( row == 2 ) then
- SetTrack(true,false)
- end
- if ( row == 3 ) then
- SetTrack(false,false)
- end
- selected = row
- DrawScreen()
- end
- print("Railcontroler. Right click on monitor name to select track")
- DrawScreen()
- while true do
- event,p1,p2,p3 = os.pullEvent()
- if ( event == "monitor_touch" ) then NewTrack(p3) end
- if ( event == "redstone" ) then
- FindSelected()
- DrawScreen()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement