Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sg = peripheral.wrap("right")
- local favAddresses = {
- {
- title = "",
- address = ""
- }
- }
- local event, p1, p2, p3 = nil
- local screenSelection = 1
- local screen = nil
- local prevX, prevY = nil
- function resetScreen()
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- end
- function PrintInline(text, x, y)
- term.setCursorPos(prevX + x, prevY + y)
- term.write(text)
- prevX = prevX + x
- prevY = prevY + y
- end
- function Print(text, x, y)
- term.setCursorPos(x, y)
- term.write(text)
- prevX = x
- prevY = y
- end
- function drawScreen(screenSettings)
- resetScreen()
- term.setBackgroundColor(colors.white)
- for i = 1, 3, 1 do
- term.setCursorPos(1, i)
- term.clearLine()
- end
- Print(screenSettings["title"], getCenterX(screenSettings["title"]), 2)
- term.setBackgroundColor(colors.gray)
- --For each option of a screen
- local line = getCenterY() - math.floor(tablelength(screenSettings["options"]) / 2)
- local curSel = 1
- for k, v in ipairs(screenSettings["options"]) do
- local label = v["option"]
- if curSel == screenSelection then
- term.setTextColor(colors.white)
- Print("[ ", getCenterX("[ " .. label .. " ]"), line)
- term.setTextColor(colors.black)
- PrintInline(label, string.len("[ "), 0, true)
- term.setTextColor(colors.white)
- PrintInline(" ]", string.len(label), 0, true)
- term.setTextColor(colors.black)
- else
- Print(label, getCenterX(label), line)
- end
- line = line + 1
- curSel = curSel + 1
- end
- end
- function getCenterX(text)
- local x,_ = term.getSize()
- return math.floor((x / 2) - (string.len(text) / 2))
- end
- function getCenterY()
- local _,y = term.getSize()
- return math.floor(y / 2)
- end
- function tablelength(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- function tableAt(T, index)
- local i = 0
- for _, v in pairs(T) do
- if i == index then
- return v
- end
- i = i + 1
- end
- end
- function startup()
- screenSelection = 1
- screen = {
- title = "Stargate Control Program",
- options = {
- {
- option = "Dial Favorite",
- func = dialFavoriteScreen
- },
- {
- option = "Dial Manually",
- func = dialFavoriteScreen
- },
- {
- option = "Exit",
- func = exitProgram
- }
- }
- }
- end
- function dialFavoriteScreen()
- end
- function exitProgram()
- os.reboot()
- end
- function awaitEvent()
- event, p1, p2, p3 = os.pullEvent()
- end
- function isSelectionChanged()
- if event == "key" then
- if p1 == keys.up then
- if screenSelection == 1 then
- screenSelection = tablelength(screen["options"])
- else
- screenSelection = screenSelection - 1
- end
- elseif p1 == keys.down then
- if screenSelection == tablelength(screen["options"]) then
- screenSelection = 1
- else
- screenSelection = screenSelection + 1
- end
- end
- end
- end
- function isSelctionSelected()
- if event == "key" then
- if p1 == keys.enter then
- tableAt(screen["options"], screenSelection - 1)["func"]()
- end
- end
- end
- startup()
- while true do
- awaitEvent()
- isSelectionChanged()
- isSelctionSelected()
- drawScreen(screen)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement