Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function setButton(name, x, x2, y, y2)
- button[name] = {}
- button[name]["x"] = x
- button[name]["x2"] = x2
- button[name]["y"] = y
- button[name]["y2"] = y2
- end
- function ini(side)
- button = {}
- setButton("1",1,20,6,14)
- setButton("2",20,38,6,14)
- setButton("3",38,57,6,14)
- setButton("4",1,20,14,22)
- setButton("5",20,38,14,22)
- setButton("6",38,57,14,22)
- setButton("7",1,20,22,30)
- setButton("8",20,38,22,30)
- setButton("9",38,57,22,30)
- setButton("0",1,20,30,38)
- setButton("Clear",20,38,30,38)
- setButton("Confirm",38,57,30,38)
- m = peripheral.wrap(side)
- m.setTextColor(colors.white)
- m.setBackgroundColor(colors.black)
- m.setTextScale(0.5)
- input = false
- current = ""
- info = ""
- end
- function setInfo(i)
- info = i
- draw()
- end
- function drawButton(name,a,a2,b,b2)
- for i = a, a2 do
- for j = b, b2 do
- m.setCursorPos(i,j)
- if (i == a or i == a2 or j == b or j == b2) then
- m.setBackgroundColor(colors.blue)
- elseif input then
- m.setBackgroundColor(colors.lime)
- else
- m.setBackgroundColor(colors.red)
- end
- m.write(" ")
- end
- end
- if input then
- m.setBackgroundColor(colors.lime)
- else
- m.setBackgroundColor(colors.red)
- end
- yspot = math.floor((b + b2) /2)
- xspot= math.floor((a + a2 - string.len(name))/2) + 1
- m.setCursorPos(xspot,yspot)
- m.write(name)
- end
- function draw()
- m.clear()
- for name,data in pairs(button) do
- drawButton(name,data["x"],data["x2"],data["y"],data["y2"])
- end
- m.setBackgroundColor(colors.black)
- m.setCursorPos(1,2)
- m.write(info)
- m.setCursorPos(1,4)
- m.write(current)
- end
- function checkxy(x, y)
- for name, data in pairs(button) do
- if y >= data["y"] and y <= data["y2"] then
- if x >= data["x"] and x <= data["x2"] then
- return name
- end
- end
- end
- return "none"
- end
- function getNumber()
- input = true
- current = ""
- confirm = false
- draw()
- while not confirm do
- event = { os.pullEvent("monitor_touch") }
- result = checkxy(event[3],event[4])
- if result == "Confirm" then
- confirm = true
- elseif (result == "none" or string.len(current) == 10)then
- -- no button is pressed or max lengh is reached
- elseif result == "Clear" then
- current = ""
- else
- current = current..result
- end
- draw()
- end
- input = false
- temp = current
- current = ""
- draw()
- if temp == "" then
- return 0
- else
- return tonumber(temp)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement