Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.wrap("top")
- local selected = 0
- local names = {"Anti","Gau","Xun","Ninjuni"}
- local cableSide = "back"
- local XunSwitchIn = colors.pink
- local XunToggleOut = colors.red
- local FSMainSwitchOut = colors.black
- local FSMainSwitchState = 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 ( FSMainSwitchState == false ) then return 2 end
- if ( CheckSwitch(XunSwitchIn) ) then return 3 end
- return 4
- 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)
- FSMainSwitchState = FSnew
- if ( XunNew ~= CheckSwitch(XunSwitchIn) ) then pulse(XunToggleOut) end
- if ( FSMainSwitchState ) then rs.setBundledOutput(cableSide,FSMainSwitchOut)
- 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 or row == 4 ) then
- SetTrack(true,false)
- end
- if ( row == 2 ) then
- SetTrack(false,false)
- end
- if ( row == 3 ) then
- SetTrack(true,true)
- 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