Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com = require("component")
- local gpu = com.gpu
- local shell = require("shell")
- local event = require("event")
- local term = require("term")
- local unicode = require("unicode")
- local ecs = require("ECSAPI")
- local holo = require("component").hologram
- ------------------------------------------------------------------
- local printer = com.printer3d
- local xSize, ySize = 80, 50
- gpu.setResolution(xSize*2, ySize)
- local rightPartSize = 30
- local userData = {
- label = "Printered Block",
- tooltip = "byShahar",
- emitRedstone = false,
- buttonMode = false,
- }
- local doingShapes = {}
- local onlineShape = 1
- local onlineLayer = 1
- local mode = false
- local startHolo = 16
- local button = {
- Name = {text = "Name...", x1, y1, x2, y2},
- Tooltip = {text = "Description...", x1, y1, x2, y2},
- IsEmitRedstone = {text = "isRedstone", x1, y1, x2, y2},
- IsButtonMode = {text = "howButton", x1, y1, x2, y2},
- Print = {text = "Print", x1, y1, x2, y2}
- }
- local colors = {
- [1] = 16711680,
- [2] = 16725760,
- [3] = 16739840,
- [4] = 16754176,
- [5] = 16768256,
- [6] = 15400704,
- [7] = 11730688,
- [8] = 8126208,
- [9] = 4521728,
- [10] = 917248,
- [11] = 6532.25,
- [12] = 65377.75,
- [13] = 65433,
- [14] = 65488.25,
- [15] = 63487,
- [16] = 49151,
- [17] = 35071,
- [18] = 20991,
- [19] = 6911,
- [20] = 1966335,
- [21] = 5570815,
- [22] = 9175295,
- [23] = 12779775,
- [24] = 16449791
- }
- -------------------------------------------------------------------------------------------------
- local function Square(x, y, width, height, color)
- ecs.square(x*2 - 1, y, width*2, height, color)
- end
- local function isIn(x1, y1, x2, y2, xClick, yClick)
- print(x1, y1, x2, y2, xClick, yClick)
- if xClick >= x1 and xClick <= x2 and yClick >= y1 and yClick <= y2 then
- return true
- else
- return false
- end
- end
- local function Text(x, y, text, colorBack, colorText)
- gpu.setBackground(colorBack)
- gpu.setForeground(colorText)
- gpu.set(x, y, text)
- end
- local function inDiapason(num1, num2, num)
- if num >= num1 and num <= num2 then
- return true
- elseif num >= num2 and num <= num1 then
- return true
- else
- return false
- end
- end
- local function whatsClickMain(x, y)
- if x > 1 and x < 49 and y > 1 and y < 50 then
- return math.floor((x+2)/ 3), math.floor((y + 1)/ 3)
- else
- return "fail", " "
- end
- end
- local function whatsClickShape(x, y)
- for i = 1, 24 do
- if isIn(doingShapes[i].x, doingShapes[i].y, doingShapes[i].x + 4, doingShapes[i].y, x, y) then
- return "nofail", i
- end
- end
- return "fail"
- end
- local function whatsClickButton(x, y)
- if isIn(button.Name.x1, button.Name.y1, button.Name.x2, button.Name.y2, x, y) then
- return "name"
- elseif isIn(button.Tooltip.x1, button.Tooltip.y1, button.Tooltip.x2, button.Tooltip.y2, x, y) then
- return "tooltip"
- elseif isIn(button.IsEmitRedstone.x1, button.IsEmitRedstone.y1, button.IsEmitRedstone.x2, button.IsEmitRedstone.y2, x, y) then
- return "redstone"
- elseif isIn(button.IsButtonMode.x1, button.IsButtonMode.y1, button.IsButtonMode.x2, button.IsButtonMode.y2, x, y) then
- return "buttonMode"
- elseif isIn(button.Print.x1, button.Print.y1, button.Print.x2, button.Print.y2, x, y) then
- return "print"
- else
- return "fail"
- end
- end
- local function whatsClick(x, y)
- local mainScreenX, mainScreenY = whatsClickMain(x/2, y)
- if mainScreenX ~= "fail" then
- return "main", mainScreenX, mainScreenY
- end
- local shape = {whatsClickShape(x, y)}
- if shape[1] ~= "fail" then
- return "shape", shape[2]
- end
- local button = whatsClickButton(x/2, y)
- if button ~= "fail" then
- return "button", button
- end
- return "none", 0
- end
- local function textInCount(text)
- return
- end
- ------------------------------Изичные функции-----------------------------------------
- local function getPosXForShapeButton(i)
- local x
- x = i % 6 * 5
- return x
- end
- local function getPosYForShapeButton(i)
- local y
- y = math.floor(i / 6) * 3
- return y
- end
- ------------------------------------Прорисовка кнопок и окон---------------------
- local function drawLayerBar(x, y, number)
- gpu.setBackground(0x111111)
- gpu.setForeground(0xff0000)
- gpu.set(x-7, y-1, " ")
- gpu.set(x-7, y, " Layer: ")
- gpu.set(x-7, y+1, " ")
- gpu.setBackground(0xffffff)
- gpu.setForeground(0x000000)
- if number < 10 then
- gpu.set(x, y, " "..tostring(number).." ")
- else
- gpu.set(x, y, " "..tostring(number).." ")
- end
- end
- local function drawShapeButton(x, y, number)
- if number ~= onlineShape then
- gpu.setBackground(0x111111)
- gpu.setForeground(0xffffff)
- else
- gpu.setBackground(colors[number])
- gpu.setForeground(0xffffff)
- end
- if number < 10 then
- gpu.set(x, y, " "..tostring(number).." ")
- else
- gpu.set(x, y, " "..tostring(number).." ")
- end
- end
- local function calculateButtons(x, y)
- x = x * 2
- for i = 1, 24 do
- doingShapes[i] = {
- x = x + getPosXForShapeButton(i - 1),
- y = y + getPosYForShapeButton(i - 1),
- isNil = true
- }
- end
- end
- local function drawShapeButtonsList()
- for i = 1, 24 do
- drawShapeButton(doingShapes[i].x, doingShapes[i].y, i)
- end
- end
- local function drawButtons(xN, yN, xT, yT, xP, yP)
- button.Name.x1, button.Name.y1, button.Name.x2, button.Name.y2 = ecs.drawAdaptiveButton(xN, yN, 2, 1, button.Name.text, 0x111111, 0xffffff)
- button.Tooltip.x1, button.Tooltip.y1, button.Tooltip.x2, button.Tooltip.y2 = ecs.drawAdaptiveButton(xT, yT, 2, 1, button.Tooltip.text, 0x111111, 0xffffff)
- button.Print.x1, button.Print.y1, button.Print.x2, button.Print.y2 = ecs.drawAdaptiveButton(xP, yP, 2, 1, button.Print.text, 0x111111, 0xffffff)
- ecs.error(button.Name.x1..button.Name.y1..button.Name.x2..button.Name.y2)
- end
- local function digitToText(numb)
- return unicode.char(numb)
- end
- local function WindowsWithTextBox(x, y, width, height, mainText, buttonText)
- local input = ""
- local buttonWidth = 4
- Square(x, y, width, 1, 0x0000dd)
- Square(x, y + 1, width, height - 1, 0xdddddd)
- Text(x*2 + 1, y, mainText, 0x0000dd, 0xffffff)
- Square(x + 1, y + math.floor(height/2), width - 2, 1, 0xffffff)
- Square(x + width - buttonWidth - 1, y + height - 2, buttonWidth, 1, 0x0000dd)
- Text((x + width - buttonWidth - 1)*2, y + height - 2, buttonText, 0x0000dd, 0xffffff)
- while true do
- local event = {event.pull()}
- if event[1] == "key_down" then
- input = input..digitToText(event[3])
- Text((x + 1)*2, y + math.floor(height/2), input, 0xffffff, 0x000000)
- end
- if event[1] == "touch" then
- break
- end
- end
- return input
- end
- -------------------------------------------Главный экран-----------------------------------
- local function drawShapeScreen(numberShape, numberLayer)
- for xShape = 1, 16 do
- for yShape = 1, 16 do
- local color = 0x9f8f8f
- if doingShapes[numberShape].isNil == false then
- if doingShapes[numberShape].x1 == xShape and doingShapes[numberShape].y1 == yShape and doingShapes[numberShape].z1 == numberLayer then
- color = 0xffffff
- elseif doingShapes[numberShape].x2 == xShape and doingShapes[numberShape].y2 == yShape and doingShapes[numberShape].z2 == numberLayer then
- color = 0x000000
- elseif inDiapason(doingShapes[numberShape].x1, doingShapes[numberShape].x2, xShape) and inDiapason(doingShapes[numberShape].y1, doingShapes[numberShape].y2, yShape) and inDiapason(doingShapes[numberShape].z1, doingShapes[numberShape].z2, numberLayer) then
- color = colors[numberShape]
- end
- end
- Square((xShape - 1) * 3 + 2, (yShape - 1) * 3 + 2, 3, 3, color)
- end
- end
- end
- ---------------------------------------------Холограмма------------------------------------
- local function ShapeInHolo(numb, color)
- if numb == onlineShape then
- holo.setPaletteColor(3, colors[numb])
- for zHolo = doingShapes[numb].z1, doingShapes[numb].z2 do
- for xHolo = doingShapes[numb].x1, doingShapes[numb].x2 do
- holo.fill(xHolo + startHolo, zHolo + startHolo, 32 - doingShapes[numb].y2, 32 - doingShapes[numb].y1, 3)
- end
- end
- else
- for zHolo = doingShapes[numb].z1, doingShapes[numb].z2 do
- for xHolo = doingShapes[numb].x1, doingShapes[numb].x2 do
- holo.fill(xHolo + startHolo, zHolo + startHolo, 32 - doingShapes[numb].y2, 32 - doingShapes[numb].y1, 1)
- end
- end
- end
- end
- local function ShapeUgli(number)
- holo.set(doingShapes[number].x1 + startHolo, 32 - doingShapes[number].y1, doingShapes[number].z1 + startHolo, 2)
- holo.set(doingShapes[number].x2 + startHolo, 32 - doingShapes[number].y2, doingShapes[number].z2 + startHolo, 2)
- end
- local function AllShapesInHolo(color, color2)
- holo.clear()
- holo.setPaletteColor(1, color)
- holo.setPaletteColor(2, color2)
- for numb = 1, 24 do
- if doingShapes[numb].isNil == false then
- ShapeInHolo(numb)
- end
- end
- for numb = 1, 24 do
- if doingShapes[numb].isNil == false then
- ShapeUgli(numb)
- end
- end
- end
- ---------------------------------------Принтер-------------------------------------------
- local function converForPrinter(oldShapes)
- for i = 1, 24 do
- if oldShapes[i].isNil == false then
- local x1 = math.min(oldShapes[i].x1, oldShapes[i].x2)
- local x2 = math.max(oldShapes[i].x1, oldShapes[i].x2)
- local y1 = math.min(oldShapes[i].y1, oldShapes[i].y2)
- local y2 = math.max(oldShapes[i].y1, oldShapes[i].y2)
- local z1 = math.min(oldShapes[i].z1, oldShapes[i].z2)
- local z2 = math.max(oldShapes[i].z1, oldShapes[i].z2)
- oldShapes[i].x1 = x1
- oldShapes[i].x2 = x2
- oldShapes[i].y1 = y1
- oldShapes[i].y2 = y2
- oldShapes[i].z1 = z1
- oldShapes[i].z2 = z2
- end
- end
- return oldShapes
- end
- local function inputData(newLabel, newTooltip, newEmitRedstone, newButtonMode, shapes)
- printer.reset()
- printer.setLabel(newLabel)
- printer.setTooltip(newTooltip)
- printer.setLightLevel(1)
- printer.setRedstoneEmitter(newEmitRedstone)
- printer.setButtonMode(newButtonMode)
- local normShapes = converForPrinter(shapes)
- for i = 1, 24 do
- if normShapes[i].isNil == false then
- printer.addShape(normShapes[i].x1 - 1, 16 - (normShapes[i].y1 - 1), normShapes[i].z1 - 1, normShapes[i].x2, 16 - normShapes[i].y2, normShapes[i].z2, "quartz_block_side", false, 0xffffff)
- end
- end
- end
- local function print(count)
- printer.commit(count)
- end
- -----------------------------------------------Прога-----------------------------
- ecs.prepareToExit()
- Square(1, 1, xSize - rightPartSize, ySize, 0xffffff)
- calculateButtons(xSize - 21, ySize - 18)
- drawButtons(xSize*2 - 20, 15, xSize*2 - 10, 15, xSize*2 - 15, 20)
- drawShapeButtonsList()
- drawShapeScreen(onlineShape, onlineLayer)
- drawLayerBar(xSize*2 - 30, 25, onlineLayer)
- holo.clear()
- while true do
- local event = {event.pull()}
- if event[1] == "touch" then
- local case = {whatsClick(event[3], event[4])}
- if case[1] == "main" then
- if mode == false then
- doingShapes[onlineShape].x1 = case[2]
- doingShapes[onlineShape].y1 = case[3]
- doingShapes[onlineShape].z1 = onlineLayer
- doingShapes[onlineShape].x2 = case[2]
- doingShapes[onlineShape].y2 = case[3]
- doingShapes[onlineShape].z2 = onlineLayer
- doingShapes[onlineShape].isNil = false
- mode = true
- else
- doingShapes[onlineShape].x2 = case[2]
- doingShapes[onlineShape].y2 = case[3]
- doingShapes[onlineShape].z2 = onlineLayer
- doingShapes[onlineShape].isNil = false
- mode = false
- AllShapesInHolo(0x00ff00, 0xffffff)
- end
- drawShapeScreen(onlineShape, onlineLayer)
- end
- if case[1] == "shape" then
- onlineShape = case[2]
- drawShapeButtonsList()
- AllShapesInHolo(0x00ff00, 0xffffff)
- end
- if case[1] == "button" then
- if case[2] == "name" then
- userData.label = WindowsWithTextBox(xSize/2 - 7, ySize/2 - 3, 15, 7, "Name will be ...", "Ок")
- elseif case[2] == "tooltip" then
- userData.tooltip = WindowsWithTextBox(xSize/2 - 7, ySize/2 - 3, 15, 7, "Tooltip will be ...", "Ок")
- elseif case[2] == "redstone" then
- elseif case[2] == "buttonMode" then
- elseif case[2] == "print" then
- inputData(userData.label, userData.tooltip, userData.emitRedstone, userData.buttonMode, doingShapes)
- print(1)
- end
- end
- elseif event[1] == "scroll" then
- onlineLayer = onlineLayer - event[5]
- if onlineLayer < 1 then
- onlineLayer = 1
- elseif onlineLayer > 16 then
- onlineLayer = 16
- end
- drawShapeScreen(onlineShape, onlineLayer)
- drawLayerBar(xSize*2 - 30, 25, onlineLayer)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement