Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dialimg = {}
- for i = 1, 4 do
- dialimg[i] = {}
- end
- dialimg[1][1] = 0
- dialimg[4][1] = 0
- for i = 1, 4, 3 do
- for n = 2, 4 do
- dialimg[i][n] = 128
- end
- end
- dialimg[1][1] = 0
- dialimg[1][2] = 128
- dialimg[1][3] = 128
- dialimg[1][4] = 128
- dialimg[1][5] = 0
- for i = 2, 3 do
- for n = 1, 5 do
- dialimg[i][n] = 128
- end
- end
- Dial = {
- name = "",
- xImg = 0,
- yImg = 0,
- x = 0,
- y = 0,
- state = 1,
- mark = ""
- }
- function Dial:new(name, xImg, yImg)
- local class = {name = name, xImg = xImg, yImg = yImg, x = xImg, y = yImg + 3, state = 1, mark = "/"}
- setmetatable(class, self)
- self.__index = self
- return class
- end
- function Dial:clear()
- term.setBackgroundColor(colors.black)
- term.setCursorPos(self.xImg - 1, self.yImg + 4)
- term.write("1")
- term.setCursorPos(self.xImg - 2, self.yImg + 1)
- term.write("2")
- term.setCursorPos(self.xImg - 1, self.yImg - 1)
- term.write("3")
- term.setCursorPos(self.xImg + 2, self.yImg - 2)
- term.write("4")
- term.setCursorPos(self.xImg + 5, self.yImg - 1)
- term.write("5")
- term.setCursorPos(self.xImg + 6, self.yImg + 1)
- term.write("6")
- term.setCursorPos(self.xImg + 5, self.yImg + 4)
- term.write("7")
- term.setCursorPos(self.xImg, self.yImg + 3)
- term.write(" ")
- term.setCursorPos(self.xImg - 1, self.yImg + 2)
- term.write(" ")
- term.setCursorPos(self.xImg - 1, self.yImg + 1)
- term.write(" ")
- term.setCursorPos(self.xImg, self.yImg)
- term.write(" ")
- term.setCursorPos(self.xImg + 1, self.yImg - 1)
- term.write(" ")
- term.setCursorPos(self.xImg + 2, self.yImg - 1)
- term.write(" ")
- term.setCursorPos(self.xImg + 3, self.yImg - 1)
- term.write(" ")
- term.setCursorPos(self.xImg + 4, self.yImg)
- term.write(" ")
- term.setCursorPos(self.xImg + 5, self.yImg + 1)
- term.write(" ")
- term.setCursorPos(self.xImg + 5, self.yImg + 2)
- term.write(" ")
- term.setCursorPos(self.xImg + 4, self.yImg + 3)
- term.write(" ")
- end
- function Dial:display()
- paintutils.drawImage(dialimg, self.xImg, self.yImg)
- self:clear()
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(self.x, self.y)
- term.write(self.mark)
- term.setCursorPos(self.xImg + 2.5 - (#self.name / 2), self.yImg + 5)
- term.setBackgroundColor(colors.black)
- term.write(self.name)
- end
- function getEvents()
- events = {os.pullEventRaw()}
- end
- local clickX = nil
- local clickY = nil
- local begin = false
- function Dial:check()
- if events[1] == "mouse_click" and events[2] == 1 then
- clickX = events[3]
- clickY = events[4]
- end
- if clickX >= self.x - 1 and clickX <= self.x + 1 and clickY >= self.y - 1 and clickY <= self.y + 1 then
- begin = true
- if events[1] == "mouse_drag" and events[2] == 1 then
- clickX = events[3]
- clickY = events[4]
- end
- else
- begin = false
- end
- if begin then
- if events[3] <= self.xImg and events[4] >= self.yImg + 3 then --1
- self.x, self.y = self.xImg, self.yImg + 3
- self.state = 1
- self.mark = "/"
- self:display()
- return 1
- elseif events[3] <= self.xImg - 1 and events[4] == self.yImg + 2 then --2
- self.x, self.y = self.xImg - 1, self.yImg + 2
- self.state = 2
- self.mark = "-"
- elseif events[3] <= self.xImg - 1 and events[4] >= self.yImg + 1 then --3
- self.x, self.y = self.xImg - 1, self.yImg + 1
- self.state = 3
- self.mark = "-"
- self:display()
- return 2
- elseif events[3] <= self.xImg and events[4] <= self.yImg then --4
- self.x, self.y = self.xImg, self.yImg
- self.state = 4
- self.mark = "\\"
- self:display()
- return 3
- elseif events[3] == self.xImg + 1 and events[4] <= self.yImg - 1 then --5
- self.x, self.y = self.xImg + 1, self.yImg - 1
- self.state = 5
- self.mark = "|"
- elseif events[3] == self.xImg + 2 and events[4] <= self.yImg - 1 then --6
- self.x, self.y = self.xImg + 2, self.yImg - 1
- self.state = 6
- self.mark = "|"
- self:display()
- return 4
- elseif events[3] == self.xImg + 3 and events[4] <= self.yImg - 1 then --7
- self.x, self.y = self.xImg + 3, self.yImg - 1
- self.state = 7
- self.mark = "|"
- elseif events[3] >= self.xImg + 4 and events[4] <= self.yImg then --8
- self.x, self.y = self.xImg + 4, self.yImg
- self.state = 8
- self.mark = "/"
- self:display()
- return 5
- elseif events[3] >= self.xImg + 5 and events[4] == self.yImg + 1 then --9
- self.x, self.y = self.xImg + 5, self.yImg + 1
- self.state = 9
- self.mark = "-"
- self:display()
- return 6
- elseif events[3] >= self.xImg + 5 and events[4] == self.yImg + 2 then --10
- self.x, self.y = self.xImg + 5, self.yImg + 2
- self.state = 10
- self.mark = "-"
- elseif events[3] >= self.xImg + 4 and events[4] >= self.yImg + 3 then --11
- self.x, self.y = self.xImg + 4, self.yImg + 3
- self.state = 11
- self.mark = "\\"
- self:display()
- return 7
- end
- end
- self:display()
- end
- --optional display program--
- --[[term.setBackgroundColor(colors.black)
- term.clear()
- Start = Dial:new("Start", 10, 5)
- Octy = Dial:new("Octy", 23, 12)
- while true do
- Start:display()
- Octy:display()
- getEvents()
- if Start:check() == 7 then
- break
- end
- if Octy:check() then
- term.setCursorPos(1, 1)
- term.clearLine()
- term.write(Octy.state)
- end
- end]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement