Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local quarryMiner = require("quarryMiner")
- local stripMiner = require("stripMiner")
- --##Key grabber##
- --local evt, key = os.pullEvent("key")
- local titleColor = colors.lightBlue
- local menuColor = colors.purple
- local textColor = colors.white
- local highlightColor = colors.pink
- local menuColors = {
- title = titleColor,
- menu = menuColor,
- text = textColor,
- highlight = highlightColor
- }
- --(menu = array of strings, colorList = array of named colors)
- --returns: cursor as int, item name as string, bool as true if user chose option/ false if user wants to exit
- local function openMenu(menu,colorList)
- local col = term.getTextColor()
- local cursor = 1
- term.clear()
- while true do
- term.setCursorPos(1,1)
- term.setTextColor(colorList.menu)
- print("Use the arrow keys to navigate")
- print("Press 'enter' to select, 'backspace' to exit")
- if menu.name then
- term.setTextColor(colorList.title)
- print("<<< "..menu.name.." >>>")
- end
- term.setCursorPos(1,5)
- for i = 1, #menu do
- if cursor == i then
- term.setTextColor(colorList.highlight)
- print(">"..i.."< "..menu[i])
- else
- term.setTextColor(colorList.text)
- print(" "..i.." "..menu[i])
- end
- end
- local evt, key = os.pullEvent("key")
- key = keys.getName(key)
- if key == "up" and cursor > 1 then
- cursor = cursor - 1
- elseif key == "down" and cursor < #menu then
- cursor = cursor + 1
- --elseif key == "left" then
- --elseif key == "right" then
- elseif key == "enter" then
- term.setTextColor(col)
- return cursor, menu[cursor], true
- elseif key == "backspace" then
- term.setTextColor(col)
- return cursor, menu[cursor], false
- end
- end
- end
- local function openNumberMenu(menu,colorList,numberList)
- --numberList = numberList or {}
- if numberList == nil then
- numberList = {}
- for i = 1, #menu do
- numberList[i] = 0
- end
- end
- local col = term.getTextColor()
- local cursor = 1
- --term.clear()
- while true do
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colorList.menu)
- print("Use the arrow keys to navigate")
- print("Press 'enter' to select, 'backspace' to exit")
- if menu.name then
- term.setTextColor(colorList.title)
- print("<<< "..menu.name.." >>>")
- end
- term.setCursorPos(1,5)
- for i = 1, #menu do
- if cursor == i then
- term.setTextColor(colorList.highlight)
- print(">"..i.."< "..menu[i]..": "..numberList[i])
- else
- term.setTextColor(colorList.text)
- print(" "..i.." "..menu[i]..": "..numberList[i])
- end
- end
- local len = #menu+2
- if cursor == len-1 then
- term.setTextColor(colorList.highlight)
- print(">"..(len-1).."< Confirm")
- term.setTextColor(colorList.text)
- print(" "..(len).." Exit")
- elseif cursor == len then
- term.setTextColor(colorList.text)
- print(" "..(len-1).." Confirm")
- term.setTextColor(colorList.highlight)
- print(">"..(len).."< Exit")
- else
- term.setTextColor(colorList.text)
- print(" "..(len-1).." Confirm")
- print(" "..(len).." Exit")
- end
- local evt, key = os.pullEvent("key")
- key = keys.getName(key)
- if key == "up" and cursor > 1 then
- cursor = cursor - 1
- elseif key == "down" and cursor < len then
- cursor = cursor + 1
- --elseif key == "left" then
- --elseif key == "right" then
- elseif key == "enter" then
- if cursor == len-1 then
- term.setTextColor(col)
- return cursor, numberList, true
- elseif cursor == len then
- term.setTextColor(col)
- return cursor, numberList, false
- else
- local lineLen = #("{"..cursor.."} "..menu[cursor]..": ")
- term.setCursorPos(lineLen+1,cursor+4)
- term.setTextColor(colorList.menu)
- numberList[cursor] = tonumber(read(nil,nil,nil,tostring(numberList[cursor])))
- term.setTextColor(colorList.text)
- end
- elseif key == "backspace" then
- term.setTextColor(col)
- return cursor, numberList, false
- end
- end
- end
- --######### Main Program Start ##############
- local menu = {name = "Main Menu", "Quarry Miner", "Strip Miner", "Refuel"}
- local quarryMenu = {name = "Quarry Miner", "X (right)", "Y (forward)", "Z (depth)"}
- local quarryNums = {0,0,0}
- local stripMineMenu = {name = "Strip Miner", "X (columns)", "Y (depth)", "direction (0=right, 1=left)"}
- local stripMineNums = {0,0,0}
- while true do
- local cursor,_,_ = openMenu(menu,menuColors)
- term.clear()
- if cursor == 1 then
- --quarry miner
- _,quarryNums,val = openNumberMenu(quarryMenu,menuColors,quarryNums)
- if val == true then
- quarryMiner.run(quarryNums[1],quarryNums[2],quarryNums[3])
- end
- elseif cursor == 2 then
- --strip miner
- _,stripMineNums,val = openNumberMenu(stripMineMenu,menuColors,stripMineNums)
- if val == true then
- stripMiner.run(stripMineNums[1],stripMineNums[2],stripMineNums[3])
- end
- elseif cursor == 3 then
- --refuel
- for i = 1, 16 do
- turtle.select(i)
- turtle.refuel()
- end
- end
- term.clear()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement