Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Wrap the terminal and any attached CC:Tweaked monitors as “screens”
- local screens = {}
- -- Terminal wrapper
- table.insert(screens, {
- clear = function() term.clear() term.setCursorPos(1,1) end,
- getSize = function() return term.getSize() end,
- setTextColor = term.setTextColor,
- setBackgroundColor = term.setBackgroundColor,
- setCursorPos = term.setCursorPos,
- write = term.write,
- })
- -- Monitor wrappers
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "monitor" then
- local m = peripheral.wrap(side)
- table.insert(screens, {
- clear = function() m.clear() m.setCursorPos(1,1) end,
- getSize = function() return m.getSize() end,
- setTextColor = function(c) m.setTextColor(c) end,
- setBackgroundColor = function(c) m.setBackgroundColor(c) end,
- setCursorPos = function(x,y) m.setCursorPos(x,y) end,
- write = function(txt) m.write(txt) end,
- monitor = m,
- })
- end
- end
- -- Menu content
- local titleText = "Main Menu"
- local optionOneText = "Horizontal Mining System "
- local optionOneKey = "(Press M)"
- local optionTwoText = "Laser Guided Warp System "
- local optionTwoKey = "(Press J)"
- -- Determine total option lengths
- local optionOneTotal = optionOneText .. optionOneKey
- local optionTwoTotal = optionTwoText .. optionTwoKey
- -- Auto-scale monitors so our 5-line layout (lines 1,3,5) fits
- for _, s in ipairs(screens) do
- if s.monitor then
- local chosen = 0.5
- for _, scale in ipairs({1, 0.5}) do
- s.monitor.setTextScale(scale)
- local w,h = s.getSize()
- if w >= #optionTwoTotal and h >= 5 then
- chosen = scale
- break
- end
- end
- s.monitor.setTextScale(chosen)
- end
- end
- -- Helper: apply fn to every screen
- local function forAll(fn)
- for _, s in ipairs(screens) do fn(s) end
- end
- -- Draw the centered menu:
- -- • Title at Y=1 in white-on-black
- -- • OptionOne at Y=3: preText black-on-lightGray, key white-on-lime
- -- • OptionTwo at Y=5: same styling
- local function drawMenu()
- for _, s in ipairs(screens) do
- -- clear to light gray base
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.clear()
- local w,h = s.getSize()
- -- Title (line 1) in white-on-black
- local xT = math.floor((w - #titleText)/2) + 1
- s.setTextColor(colors.white)
- s.setBackgroundColor(colors.black)
- s.setCursorPos(xT, 1)
- s.write(titleText)
- -- Option 1 (line 3)
- local x1 = math.floor((w - #optionOneTotal)/2) + 1
- s.setCursorPos(x1, 3)
- -- preText
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.write(optionOneText)
- -- key portion
- s.setTextColor(colors.white)
- s.setBackgroundColor(colors.lime)
- s.write(optionOneKey)
- -- Option 2 (line 5)
- local x2 = math.floor((w - #optionTwoTotal)/2) + 1
- s.setCursorPos(x2, 5)
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.write(optionTwoText)
- s.setTextColor(colors.white)
- s.setBackgroundColor(colors.lime)
- s.write(optionTwoKey)
- end
- end
- -- Initial draw
- drawMenu()
- -- Reset to default colors & clear (for loading external scripts)
- local function resetColors()
- forAll(function(s)
- s.setTextColor(colors.white)
- s.setBackgroundColor(colors.black)
- s.clear()
- end)
- end
- -- Load a pastebin script if missing, then re‑draw the menu
- local function loadIfMissing(name,id)
- if not fs.exists(name) then
- resetColors()
- shell.run("pastebin get "..id.." "..name)
- drawMenu()
- end
- end
- loadIfMissing("jzc","rfXW7SiN")
- loadIfMissing("ztc","qs4SAcmL")
- loadIfMissing("itc","fXLxQmpe")
- loadIfMissing("otc","0bWu4YgN")
- -- Main key loop
- while true do
- local _, key = os.pullEvent("key")
- if key == keys.m then
- -- Feedback
- forAll(function(s)
- s.clear()
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.setCursorPos(1,1)
- s.write("Booting Horizontal Mining System...")
- end)
- resetColors()
- shell.run("jzc")
- drawMenu()
- elseif key == keys.j then
- forAll(function(s)
- s.clear()
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.setCursorPos(1,1)
- s.write("Booting Laser Guided Warp System...")
- end)
- resetColors()
- shell.run("ztc")
- drawMenu()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement