Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Reactor name appears center of screen.
- local reactorTitle = "Reactor Core #01"
- -- Reactor menu options
- local menu_options =
- {
- [1] = {menuOption="Reactor:", option1=" ON ", option2=" OFF ", yPos=8, option1xPos=22, option2xPos=31, selected=2},
- [2] = {menuOption="Lights:", option1=" ON ", option2=" OFF ", yPos=9, option1xPos=22, option2xPos=31, selected=2},
- [3] = {menuOption="Info Displays:", option1=" ON ", option2=" OFF ", yPos=10, option1xPos=22, option2xPos=31, selected=2},
- [4] = {menuOption="Emerg. Flood:", option1=" ON ", option2=" OFF ", yPos=11, option1xPos=22, option2xPos=31, selected=2},
- [5] = {menuOption="Access Doors:", option1=" OPEN ", option2="CLOSED", yPos=12, option1xPos=22, option2xPos=31, selected=2},
- [6] = {menuOption="", option1="Emergency Shutdown", option2="", yPos=16, option1xPos=17, option2xPos=0, selected=0},
- }
- -- Clear Screen
- term.clear()
- -- FUNCTION (Draw Menu)
- local function drawMenu()
- for index, data in pairs(menu_options) do
- term.setCursorPos(data.option1xPos-2-data.menuOption:len(), data.yPos)
- term.setBackgroundColor(colors.black)
- term.write(data.menuOption)
- term.setCursorPos(data.option1xPos, data.yPos)
- if data.selected == 1 then
- term.setBackgroundColor(colors.green)
- elseif data.selected == 0 then
- term.setBackgroundColor(colors.red)
- else
- term.setBackgroundColor(colors.gray)
- end
- term.write(data.option1)
- term.setCursorPos(data.option2xPos, data.yPos)
- if data.selected == 2 then
- term.setBackgroundColor(colors.red)
- elseif data.selected == 0 then
- term.setBackgroundColor(colors.red)
- else
- term.setBackgroundColor(colors.gray)
- end
- term.write(data.option2)
- end
- end
- drawMenu()
- -- FUNCTION (Center Text)
- local function centerText(text)
- term.setCursorPos(1,3)
- local x,y = term.getSize()
- local x2,y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- term.setBackgroundColor(colors.black)
- write(text)
- end
- centerText(reactorTitle)
- local function checkClick(x,y)
- for index, data in pairs(menu_options) do
- if x > data.option1xPos and x < data.option1:len() + data.option1xPos and y == data.yPos then
- if data.selected ~= 0 then
- return index, 1
- else
- return index, 0
- end
- end
- if x > data.option2xPos and x < data.option2:len() + data.option2xPos and y == data.yPos then
- if data.selected ~= 0 then
- return index, 2
- else
- return index, 0
- end
- end
- end
- return false, false
- end
- while true do
- local e = {os.pullEvent()}
- local indexSelected, optionSelected = "", ""
- if e[1] == "mouse_click" then
- indexSelected, optionSelected = checkClick(e[3], e[4]) --Check the mouse click
- if indexSelected ~= false and optionSelected ~= false then
- menu_options[indexSelected].selected = optionSelected
- end
- end
- term.setCursorPos(1,19)
- term.setBackgroundColor(colors.black)
- if optionSelected == 1 then
- term.write(menu_options[indexSelected].menuOption .. " " .. menu_options[indexSelected].option1 .. " ")
- elseif optionSelected == 2 then
- term.write(menu_options[indexSelected].menuOption .. " " .. menu_options[indexSelected].option2 .. " ")
- elseif optionSelected == 0 then
- term.write(menu_options[indexSelected].menuOption .. " " .. menu_options[indexSelected].option1 .. " " .. menu_options[indexSelected].option2 .. " ")
- end
- -- Put button actions below
- if indexSelected == 1 and optionSelected == 1 then -- Reactor On
- elseif indexSelected == 1 and optionSelected == 2 then -- Reactor Off
- elseif indexSelected == 2 and optionSelected == 1 then -- Lights On
- elseif indexSelected == 2 and optionSelected == 2 then -- Lights Off
- elseif indexSelected == 3 and optionSelected == 1 then -- Info Displays ON
- elseif indexSelected == 3 and optionSelected == 2 then -- Info Displays OFF
- elseif indexSelected == 4 and optionSelected == 1 then -- Access Doors On
- elseif indexSelected == 4 and optionSelected == 2 then -- Access Doors Off
- elseif indexSelected == 4 and optionSelected == 0 then -- Emergency Shutdown
- end
- drawMenu()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement