SHOW:
|
|
- or go back to the newest paste.
| 1 | -- Wrap the terminal and any attached CC:Tweaked monitors as “screens” | |
| 2 | local screens = {}
| |
| 3 | ||
| 4 | -- Terminal wrapper | |
| 5 | table.insert(screens, {
| |
| 6 | clear = function() term.clear() term.setCursorPos(1,1) end, | |
| 7 | getSize = function() return term.getSize() end, | |
| 8 | setTextColor = term.setTextColor, | |
| 9 | setBackgroundColor = term.setBackgroundColor, | |
| 10 | setCursorPos = term.setCursorPos, | |
| 11 | write = term.write, | |
| 12 | }) | |
| 13 | ||
| 14 | -- Monitor wrappers | |
| 15 | for _, side in ipairs(peripheral.getNames()) do | |
| 16 | if peripheral.getType(side) == "monitor" then | |
| 17 | local m = peripheral.wrap(side) | |
| 18 | table.insert(screens, {
| |
| 19 | clear = function() m.clear() m.setCursorPos(1,1) end, | |
| 20 | getSize = function() return m.getSize() end, | |
| 21 | setTextColor = function(c) m.setTextColor(c) end, | |
| 22 | setBackgroundColor = function(c) m.setBackgroundColor(c) end, | |
| 23 | setCursorPos = function(x,y) m.setCursorPos(x,y) end, | |
| 24 | write = function(txt) m.write(txt) end, | |
| 25 | monitor = m, | |
| 26 | }) | |
| 27 | end | |
| 28 | end | |
| 29 | ||
| 30 | - | -- Menu lines |
| 30 | + | -- Menu content |
| 31 | - | local titleText = "Main Menu" |
| 31 | + | local titleText = "Main Menu" |
| 32 | - | local labelOne = "Horizontal Mining System " |
| 32 | + | local optionOneText = "Horizontal Mining System " |
| 33 | - | local labelTwo = "Laser Guided Warp System " |
| 33 | + | local optionOneKey = "(Press M)" |
| 34 | - | local hintOne = "(Press M)" |
| 34 | + | local optionTwoText = "Laser Guided Warp System " |
| 35 | - | local hintTwo = "(Press J)" |
| 35 | + | local optionTwoKey = "(Press J)" |
| 36 | ||
| 37 | - | -- Auto-scale monitors so our 5‑line layout (lines 1,3,5) always fits |
| 37 | + | -- Determine total option lengths |
| 38 | local optionOneTotal = optionOneText .. optionOneKey | |
| 39 | local optionTwoTotal = optionTwoText .. optionTwoKey | |
| 40 | ||
| 41 | -- Auto-scale monitors so our 5-line layout (lines 1,3,5) fits | |
| 42 | for _, s in ipairs(screens) do | |
| 43 | if s.monitor then | |
| 44 | - | if w >= #labelOne + #hintOne and h >= 5 then |
| 44 | + | |
| 45 | for _, scale in ipairs({1, 0.5}) do
| |
| 46 | s.monitor.setTextScale(scale) | |
| 47 | local w,h = s.getSize() | |
| 48 | if w >= #optionTwoTotal and h >= 5 then | |
| 49 | chosen = scale | |
| 50 | break | |
| 51 | end | |
| 52 | end | |
| 53 | - | -- Helper to run a function on all screens |
| 53 | + | |
| 54 | end | |
| 55 | end | |
| 56 | ||
| 57 | -- Helper: apply fn to every screen | |
| 58 | local function forAll(fn) | |
| 59 | for _, s in ipairs(screens) do fn(s) end | |
| 60 | - | -- • Option1 at Y=3: label in black-on-lightGray, hint in white-on-green |
| 60 | + | |
| 61 | - | -- • Option2 at Y=5: same |
| 61 | + | |
| 62 | -- Draw the centered menu: | |
| 63 | -- • Title at Y=1 in white-on-black | |
| 64 | - | -- Base background |
| 64 | + | -- • OptionOne at Y=3: preText black-on-lightGray, key white-on-lime |
| 65 | -- • OptionTwo at Y=5: same styling | |
| 66 | local function drawMenu() | |
| 67 | for _, s in ipairs(screens) do | |
| 68 | -- clear to light gray base | |
| 69 | s.setTextColor(colors.black) | |
| 70 | - | -- Title (line 1) white-on-black |
| 70 | + | |
| 71 | s.clear() | |
| 72 | local w,h = s.getSize() | |
| 73 | ||
| 74 | -- Title (line 1) in white-on-black | |
| 75 | local xT = math.floor((w - #titleText)/2) + 1 | |
| 76 | s.setTextColor(colors.white) | |
| 77 | - | -- Option 1 (line 3) |
| 77 | + | |
| 78 | - | local full1 = labelOne .. hintOne |
| 78 | + | |
| 79 | - | local x1 = math.floor((w - #full1)/2) + 1 |
| 79 | + | |
| 80 | - | -- label |
| 80 | + | |
| 81 | -- Option 1 (line 3) | |
| 82 | local x1 = math.floor((w - #optionOneTotal)/2) + 1 | |
| 83 | s.setCursorPos(x1, 3) | |
| 84 | - | s.write(labelOne) |
| 84 | + | -- preText |
| 85 | - | -- hint |
| 85 | + | |
| 86 | s.setBackgroundColor(colors.lightGray) | |
| 87 | - | s.setBackgroundColor(colors.green) |
| 87 | + | s.write(optionOneText) |
| 88 | - | s.write(hintOne) |
| 88 | + | -- key portion |
| 89 | s.setTextColor(colors.white) | |
| 90 | - | -- Option 2 (line 5) |
| 90 | + | s.setBackgroundColor(colors.lime) |
| 91 | - | local full2 = labelTwo .. hintTwo |
| 91 | + | s.write(optionOneKey) |
| 92 | - | local x2 = math.floor((w - #full2)/2) + 1 |
| 92 | + | |
| 93 | -- Option 2 (line 5) | |
| 94 | local x2 = math.floor((w - #optionTwoTotal)/2) + 1 | |
| 95 | s.setCursorPos(x2, 5) | |
| 96 | - | s.write(labelTwo) |
| 96 | + | |
| 97 | s.setBackgroundColor(colors.lightGray) | |
| 98 | - | s.setBackgroundColor(colors.green) |
| 98 | + | s.write(optionTwoText) |
| 99 | - | s.write(hintTwo) |
| 99 | + | |
| 100 | s.setBackgroundColor(colors.lime) | |
| 101 | s.write(optionTwoKey) | |
| 102 | end | |
| 103 | end | |
| 104 | ||
| 105 | -- Initial draw | |
| 106 | drawMenu() | |
| 107 | ||
| 108 | -- Reset to default colors & clear (for loading external scripts) | |
| 109 | local function resetColors() | |
| 110 | forAll(function(s) | |
| 111 | s.setTextColor(colors.white) | |
| 112 | s.setBackgroundColor(colors.black) | |
| 113 | s.clear() | |
| 114 | end) | |
| 115 | end | |
| 116 | ||
| 117 | -- Load a pastebin script if missing, then re‑draw the menu | |
| 118 | local function loadIfMissing(name,id) | |
| 119 | if not fs.exists(name) then | |
| 120 | resetColors() | |
| 121 | shell.run("pastebin get "..id.." "..name)
| |
| 122 | drawMenu() | |
| 123 | end | |
| 124 | - | loadIfMissing("jzc","rfXW7SiN")
|
| 124 | + | |
| 125 | - | loadIfMissing("ztc","S9SW0zHJ")
|
| 125 | + | |
| 126 | loadIfMissing("jzc","Lv1SHsGc")
| |
| 127 | loadIfMissing("ztc","qs4SAcmL")
| |
| 128 | loadIfMissing("itc","fXLxQmpe")
| |
| 129 | loadIfMissing("otc","0bWu4YgN")
| |
| 130 | ||
| 131 | -- Main key loop | |
| 132 | while true do | |
| 133 | local _, key = os.pullEvent("key")
| |
| 134 | if key == keys.m then | |
| 135 | -- Feedback | |
| 136 | forAll(function(s) | |
| 137 | s.clear() | |
| 138 | s.setTextColor(colors.black) | |
| 139 | s.setBackgroundColor(colors.lightGray) | |
| 140 | s.setCursorPos(1,1) | |
| 141 | s.write("Booting Horizontal Mining System...")
| |
| 142 | end) | |
| 143 | resetColors() | |
| 144 | shell.run("jzc")
| |
| 145 | drawMenu() | |
| 146 | ||
| 147 | elseif key == keys.j then | |
| 148 | forAll(function(s) | |
| 149 | s.clear() | |
| 150 | s.setTextColor(colors.black) | |
| 151 | s.setBackgroundColor(colors.lightGray) | |
| 152 | s.setCursorPos(1,1) | |
| 153 | s.write("Booting Laser Guided Warp System...")
| |
| 154 | end) | |
| 155 | resetColors() | |
| 156 | shell.run("ztc")
| |
| 157 | drawMenu() | |
| 158 | end | |
| 159 | end | |
| 160 |