Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local termWidth, termHeight = term.getSize()
- local blueprints = fs.list("/bps")
- local selectedBlueprintIndex = -1
- local currentBlueprint
- local BP_LIST_W = 18
- local BP_DATA_X = BP_LIST_W + 2
- local BP_DATA_W = 18
- -- black out
- paintutils.drawFilledBox(1, 1, termWidth, termHeight, colors.black)
- function checkBuilditClick(x, y)
- if x >= BP_DATA_X + 9 and x <= BP_DATA_X + 19 and y == 13 then
- if selectedBlueprintIndex ~= -1 then
- shell.run("blueprint_builder " .. blueprints[selectedBlueprintIndex])
- end
- end
- end
- function drawBuildButton()
- term.setCursorPos(BP_DATA_X + 9, 13)
- term.setBackgroundColor(colors.green)
- term.setTextColor(colors.lime)
- term.write("[Build It]")
- end
- function formatMaterial(s, count)
- local colonIndex = string.find(s, ":")
- if colonIndex then
- s = string.sub(s, colonIndex+1, string.len(s))
- end
- return string.sub(count .. ": " ..s, 1, BP_DATA_W)
- end
- function drawBlueprintData()
- -- Draw the data Header
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.lightGray)
- term.setCursorPos(BP_DATA_X, 3)
- print("Required Blocks")
- paintutils.drawFilledBox(BP_DATA_X, 4, BP_DATA_X + BP_DATA_W, 10, colors.gray)
- if currentBlueprint then
- local matY = 4
- term.setTextColor(colors.white)
- for k, v in pairs(currentBlueprint.quantities) do
- if matY <= 10 then
- term.setCursorPos(BP_DATA_X, matY)
- term.write(formatMaterial(k, v))
- end
- matY = matY + 1
- end
- end
- term.setCursorPos(1, 12)
- term.setBackgroundColor(colors.black)
- print("Dimensions")
- paintutils.drawLine(1, 13, BP_DATA_W, 13, colors.gray)
- term.setCursorPos(1, 13)
- term.setBackgroundColor(colors.gray)
- -- buid a string for the dimensions
- if currentBlueprint then
- local dimString = string.format("H:%d W:%d D:%d", currentBlueprint.dimensions.height, currentBlueprint.dimensions.width, currentBlueprint.dimensions.depth)
- term.write(dimString)
- end
- end
- function drawCloseButton()
- -- Draw an X button in the top Right
- term.setCursorPos(termWidth, 1)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.lightGray)
- print("x")
- end
- function drawMainMenu()
- -- Draw the [Builder] button
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.orange)
- term.setTextColor(colors.gray)
- print("[Builder]")
- paintutils.drawLine(10,1, termWidth-1, 1, colors.lightGray)
- drawCloseButton()
- end
- function getBlueprints()
- local bp = {}
- for key, value in pairs(blueprints) do
- if string.len(value) > BP_LIST_W then
- bp[key] = string.sub(blueprints[key], 1, BP_LIST_W-2) .. ".."
- else
- bp[key] = blueprints[key]
- end
- end
- return bp
- end
- function drawBlueprintsList()
- -- The header
- term.setCursorPos(1, 3)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.lightGray)
- print("Blueprints")
- -- The list of blueprints to click on
- paintutils.drawFilledBox(1, 4, BP_LIST_W, 10, colors.gray)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- local yStart = 4
- for key, value in pairs(getBlueprints()) do
- if selectedBlueprintLine == yStart then
- term.setBackgroundColor(colors.cyan)
- paintutils.drawLine(1, yStart, BP_LIST_W, yStart, colors.cyan)
- else
- term.setBackgroundColor(colors.gray)
- paintutils.drawLine(1, yStart, BP_LIST_W, yStart, colors.gray)
- end
- term.setCursorPos(1, yStart)
- print(value)
- yStart = yStart + 1
- end
- end
- function checkBlueprintsClick(x, y)
- if x < BP_LIST_W and y >= 4 and y <= 10 then
- selectedBlueprintLine = y
- drawBlueprintsList()
- loadNewBlueprint()
- end
- end
- function loadNewBlueprint()
- local bpFile = fs.open("/bps/" .. blueprints[selectedBlueprintLine - 3], "r")
- currentBlueprint = textutils.unserialise(bpFile.readAll())
- selectedBlueprintIndex = selectedBlueprintLine - 3
- bpFile.close()
- drawBlueprintData()
- end
- drawMainMenu()
- drawBlueprintsList()
- drawBlueprintData()
- drawBuildButton()
- while true do
- local event, button, x, y = os.pullEventRaw()
- if event == "mouse_click" then
- if x == termWidth and y == 1 then
- term.setBackgroundColor(colors.black)
- shell.run("clear")
- return -- close program
- end
- checkBlueprintsClick(x, y)
- checkBuilditClick(x, y)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement