Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `mon = peripheral.wrap("monitor_0")
- local rea = peripheral.wrap("right")
- monX, monY = mon.getSize()
- --Clear Function
- function clear()
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- end
- --Draw Line Function
- function drawLine(x,y, length, size, color_bar)
- for yPos = y, y+size-1 do
- mon.setBackgroundColor(color_bar)
- mon.setCursorPos(x, yPos)
- mon.write(string.rep(" ", length))
- end
- end
- --Progress Bar Function
- function drawProg(x, y, length, size, minVal, maxVal, color_bar, color_bg)
- drawLine(x, y, length, size, color_bg)
- local barSize = math.floor((minVal/maxVal)*length)
- drawLine(x, y, barSize, size, color_bar)
- end
- --Function for Centering Titles
- function centerText(title, y, per, value, maxValue)
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- local txtX, txtY = mon.getSize()
- if per == true then
- mon.setCursorPos((txtX+string.len(title))/2-(string.len(title)), y)
- mon.write(title..':'..math.floor((value/maxValue)*100).."%")
- else
- mon.setCursorPos((txtX+string.len(title))/2-(string.len(title)-1), y)
- mon.write(title)
- end
- end
- local button={}
- function clearTable()
- button = {}
- mon.clear()
- end
- function setTable(name, func, xmin, xmax, ymin, ymax)
- button[name] = {}
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- buttob[name]["ymax"] = ymax
- end
- function fill(text, color, bData)
- mon.setBackgroundColor(color)
- local yspot = math.floor((bData["ymin"] + bData['ymax']) /2)
- local xspot = math.floor(((bData["xmin"] + bData['xmax']) - string.len(text))/2)+1
- for j = bData["ymin"], bData['ymax'] do
- mon.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData['xmin'] - string.len(text) +1 do
- if k == xspot then
- mon.write(text)
- else
- mon.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData['xmax'] do
- mon.write(" ")
- end
- end
- end
- mon.setBackgroundColor(colors.black)
- end
- function screen()
- local currColor
- for name, data in pairs(button) do
- local on = data["active"]
- if on == true then
- currColor = colors.lime
- else
- currColor = colors.red
- end
- fill(name, currColor, data)
- end
- end
- function toggleButton(name)
- button[name]["active"] = not button[name]['active']
- screen()
- end
- function flash(name)
- toggleButton(name)
- screen()
- sleep(0.15)
- toggleButton(name)
- screen()
- end
- function checkxy(x, y)
- for name, data in pairs(button) do
- if y>=data["ymin"] and y <= data['ymax'] then
- if x>=data["xmin"] and x <= data['xmax'] then
- data["func"]()
- return true
- end
- end
- end
- return false
- end
- function fillTable()
- --Control Rod 1
- button.setTable("-10", R11, 2, 4, 9, 9)
- button.setTable("-5", R12, 6, 7, 9, 9)
- button.setTable("-1", R13, 8, 9, 9, 9)
- button.setTable("+1", R14, 76, 77, 9, 9)
- button.setTable("+5", R15, 79, 80, 9, 9)
- button.setTable("+10", R16, 82, 83, 9, 9)
- --Control Rod 2
- button.setTable("-10", R21, 2, 4, 11, 11)
- button.setTable("-5", R22, 6, 7, 11, 11)
- button.setTable("-1", R23, 8, 9, 11, 11)
- button.setTable("+1", R24, 76, 77, 11, 11)
- button.setTable("+5", R25, 79, 80, 11, 11)
- button.setTable("+10", R26, 82, 83, 11, 11)
- --Control Rod 3
- button.setTable("-10", R31, 2, 4, 13, 13)
- button.setTable("-5", R32, 6, 7, 13, 13)
- button.setTable("-1", R33, 8, 9, 13, 13)
- button.setTable("+1", R34, 76, 77, 13, 13)
- button.setTable("+5", R35, 79, 80, 13, 13)
- button.setTable("+10", R36, 82, 83, 13, 13)
- --Control Rod 4
- button.setTable("-10", R41, 2, 4, 15, 15)
- button.setTable("-5", R42, 6, 7, 15, 15)
- button.setTable("-1", R43, 8, 9, 15, 15)
- button.setTable("+1", R44, 76, 77, 15, 15)
- button.setTable("+5", R45, 79, 80, 15, 15)
- button.setTable("+10", R46, 82, 83, 15, 15)
- --Control Rod 5
- button.setTable("-10", R51, 2, 4, 17, 17)
- button.setTable("-5", R52, 6, 7, 17, 17)
- button.setTable("-1", R53, 8, 9, 17, 17)
- button.setTable("+1", R54, 76, 77, 17, 17)
- button.setTable("+5", R55, 79, 80, 17, 17)
- button.setTable("+10", R56, 82, 83, 17, 17)
- --Additional buttons
- button.setTable("On/Off", OnOff, 1, 6, 1, 1)
- button.setTable("X", stopProgram, 84,84, 1, 1)
- end
- function getClick()
- event, side, x, y = os.pullEvent("monitor_touch")
- checkxy(x, y)
- end
- --Button Functions
- --Control Rod 1
- function R11()
- rea.setControlRodLevel(1, rea.getControlRodLevel(1)-10)
- end
- function R12()
- rea.setControlRodLevel(1, rea.getControlRodLevel(1)-5)
- end
- function R13()
- rea.setControlRodLevel(1, rea.getControlRodLevel(1)-1)
- end
- function R14()
- rea.setControlRodLevel(1, rea.getControlRodLevel(1)+10)
- end
- function R15()
- rea.setControlRodLevel(1, rea.getControlRodLevel(1)+5)
- end
- function R16()
- rea.setControlRodLevel(1, rea.getControlRodLevel(1)+1)
- end
- --Control Rod 2
- function R21()
- rea.setControlRodLevel(2, rea.getControlRodLevel(2)-10)
- end
- function R22()
- rea.setControlRodLevel(2, rea.getControlRodLevel(2)-5)
- end
- function R23()
- rea.setControlRodLevel(2, rea.getControlRodLevel(2)-1)
- end
- function R24()
- rea.setControlRodLevel(2, rea.getControlRodLevel(2)+1)
- end
- function R25()
- rea.setControlRodLevel(2, rea.getControlRodLevel(2)+5)
- end
- function R26()
- rea.setControlRodLevel(2, rea.getControlRodLevel(2)+10)
- end
- --Control Rod 3
- function R31()
- rea.setControlRodLevel(3, rea.getControlRodLevel(3)-10)
- end
- function R32()
- rea.setControlRodLevel(3, rea.getControlRodLevel(3)-5)
- end
- function R33()
- rea.setControlRodLevel(3, rea.getControlRodLevel(3)-1)
- end
- function R34()
- rea.setControlRodLevel(3, rea.getControlRodLevel(3)+1)
- end
- function R35()
- rea.setControlRodLevel(3, rea.getControlRodLevel(3)+5)
- end
- function R36()
- rea.setControlRodLevel(3, rea.getControlRodLevel(3)+10)
- end
- --Control Rod 4
- function R41()
- rea.setControlRodLevel(4, rea.getControlRodLevel(4)-10)
- end
- function R42()
- rea.setControlRodLevel(4, rea.getControlRodLevel(4)-5)
- end
- function R43()
- rea.setControlRodLevel(4, rea.getControlRodLevel(4)-1)
- end
- function R44()
- rea.setControlRodLevel(4, rea.getControlRodLevel(4)+1)
- end
- function R45()
- rea.setControlRodLevel(4, rea.getControlRodLevel(4)+5)
- end
- function R46()
- rea.setControlRodLevel(4, rea.getControlRodLevel(4)+10)
- end
- --Control Rod 5
- function R51()
- rea.setControlRodLevel(5, rea.getControlRodLevel(5)-10)
- end
- function R52()
- rea.setControlRodLevel(5, rea.getControlRodLevel(5)-5)
- end
- function R53()
- rea.setControlRodLevel(5, rea.getControlRodLevel(5)-1)
- end
- function R54()
- rea.setControlRodLevel(5, rea.getControlRodLevel(5)+1)
- end
- function R55()
- rea.setControlRodLevel(5, rea.getControlRodLevel(5)+5)
- end
- function R56()
- rea.setControlRodLevel(5, rea.getControlRodLevel(5)+10)
- end
- --Other buttons
- function OnOff()
- if rea.getActive == true then
- rea.setActive(false)
- else
- rea.setActive(true)
- end
- end
- function stopProgram()
- SD = true
- end
- --Progress bar updates and control rod control
- local SD = false
- while SD == false do
- clear()
- --Main Title
- centerText("A.R.C.S.", 1, false, 0, 0)
- --Power Bar
- centerText('energy Stored', 4, true, rea.getEnergyStored(), 10000000)
- drawProg(12, 5, 60, 1, rea.getEnergyStored(), 10000000, colors.green, colors.red)
- --Stored Fuel
- centerText('Fuel Stored', 6, true, rea.getFuelAmount(), rea.getFuelAmountMax())
- drawProg(12, 7, 60, 1, rea.getFuelAmount(), rea.getFuelAmountMax(), colors.green, colors.red)
- --Control Rod 1
- centerText('Control Rod 1 Insertion', 8, true, rea.getControlRodLevel(0), 100)
- drawProg(12, 9, 60, 1, rea.getControlRodLevel(0), 100, colors.green, colors.red)
- --Control Rod 2
- centerText('Control Rod 2 Insertion', 10, true, rea.getControlRodLevel(1), 100)
- drawProg(12, 11, 60, 1, rea.getControlRodLevel(1), 100, colors.green, colors.red)
- --Control Rod 3
- centerText('Control Rod 3 Insertion', 12, true, rea.getControlRodLevel(2), 100)
- drawProg(12, 13, 60, 1, rea.getControlRodLevel(2), 100, colors.green, colors.red)
- --Control Rod 4
- centerText('Control Rod 4 Insertion', 14, true, rea.getControlRodLevel(3), 100)
- drawProg(12, 15, 60, 1, rea.getControlRodLevel(3), 100, colors.green, colors.red)
- --Control Rod 5
- centerText('Control Rod 5 Insertion', 16, true, rea.getControlRodLevel(4), 100)
- drawProg(12, 17, 60, 1, rea.getControlRodLevel(4), 100, colors.green, colors.red)
- --Other Things
- getClick()
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement