selopt test
This commit is contained in:
51
src/main.lua
51
src/main.lua
@@ -6,5 +6,56 @@ end
|
|||||||
|
|
||||||
local turtle = _G["turtle"]
|
local turtle = _G["turtle"]
|
||||||
|
|
||||||
|
print("House building system")
|
||||||
|
print("JUFS Technologies (c) 2026 (Justus Wolff)")
|
||||||
|
|
||||||
print("fuel: "..tostring(turtle.getFuelLevel()).."/"..tostring(turtle.getFuelLimit()))
|
print("fuel: "..tostring(turtle.getFuelLevel()).."/"..tostring(turtle.getFuelLimit()))
|
||||||
|
|
||||||
|
local function reset()
|
||||||
|
term.clear()
|
||||||
|
term.setCursorPos(1,1)
|
||||||
|
end
|
||||||
|
local function incline()
|
||||||
|
local x,y = term.getCursorPos()
|
||||||
|
term.setCursorPos(x,y+1)
|
||||||
|
end
|
||||||
|
function term.setcol(fc, bc)
|
||||||
|
term.setTextColor(fc)
|
||||||
|
term.setBackgroundColor(bc)
|
||||||
|
end
|
||||||
|
local function selopt(options, title)
|
||||||
|
reset()
|
||||||
|
term.setcol(colors.black, colors.white)
|
||||||
|
term.write(title)
|
||||||
|
|
||||||
|
local selected = 1
|
||||||
|
|
||||||
|
while true do
|
||||||
|
for i,v in pairs(options) do
|
||||||
|
incline()
|
||||||
|
if i == selected then
|
||||||
|
term.setcol(colors.black, colors.blue)
|
||||||
|
else
|
||||||
|
term.setcol(colors.white, colors.black)
|
||||||
|
end
|
||||||
|
term.write(v)
|
||||||
|
end
|
||||||
|
|
||||||
|
local event,key = os.pullEvent("key")
|
||||||
|
if keys.getName(key) == "w" and selected ~= 1 then
|
||||||
|
selected = selected - 1
|
||||||
|
end
|
||||||
|
if keys.getName(key) == "s" and selected ~= #options then
|
||||||
|
selected = selected + 1
|
||||||
|
end
|
||||||
|
if keys.getName(key) == "enter" then
|
||||||
|
return selected
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local action = selopt({
|
||||||
|
"New Design",
|
||||||
|
"Print Design"
|
||||||
|
}, "Select Action")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user