Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --TouchPc API--
- button = {}
- Text = {}
- CurrentPage = 1
- side = "left"
- pp = peripheral.isPresent(side)
- if pp then
- m = peripheral.wrap(side)
- end
- floppy = false --Currently does nothing, but is going to be used in a later release to be able to save and retrieve the status on each button on load/exit--
- function setPage(page)
- CurrentPage = page
- ClearScreen()
- end
- function ChangePeripheral()
- end
- function CreateButton(Id,MinX,MaxX,MinY,MaxY,Page,Function,Color,State,Text,...) -- the ... is for the optional function to be triggered when a button changes to the "off" state
- -- Create a list of buttons and their variables --
- button[Id] = {}
- button[Id][1] = MinX
- button[Id][2] = MaxX
- button[Id][3] = MinY
- button[Id][4] = MaxY
- button[Id][5] = Text
- button[Id][6] = Function
- button[Id][7] = Color
- button[Id][8] = State
- button[Id][9] = Page
- button[Id][10] = ...
- end
- function AddText(Id,text,x,y,page,colorT,colorB)
- Text[Id] = {}
- Text[Id][1] = text
- Text[Id][2] = x
- Text[Id][3] = y
- Text[Id][4] = page
- Text[Id][5] = colorT
- Text[Id][6] = colorB
- end
- function CheckButtons() --eventc is used to define whether it is a monitor event or a terminal event.--
- -- Checks if the the player clicked a button--
- --Change it to be able to distinguish what page the button is on
- event, z, x, y = os.pullEvent()
- if event == "monitor_touch" or event == "mouse_click" then
- for i = 1, table.getn(button) do
- if x >= button[i][1] and x <= button[i][2] and y >= button[i][3] and y <= button[i][4] and button[i][9] == CurrentPage then
- if button[i][8] == "on" then
- button[i][8] = "off"
- button[i][10]()
- elseif button[i][8] == "off" then
- button[i][8] = "on"
- button[i][6]()
- elseif button[i][8] == "none" then
- button[i][6]()
- end
- sleep(0.1)
- end
- end
- end
- end
- function ClearScreen()
- if pp == true then
- m.setBackgroundColor(colors.black)
- m.clear()
- else
- term.setBackgroundColor(colors.black)
- term.clear()
- end
- end
- function DrawButton()
- ClearScreen()
- --draws the button on the screen--
- for i = 1, table.getn(button) do
- if button[i][9] == CurrentPage then
- if pp == true then
- m.setBackgroundColor(button[i][7])
- else
- term.setBackgroundColor(button[i][7])
- end
- for y = button[i][3], button[i][4] do
- for x = button[i][1], button[i][2] do
- if pp == true then
- m.setCursorPos(x,y)
- m.write(" ")
- else
- term.setCursorPos(x,y)
- term.write(" ")
- end
- end
- if pp == true then
- m.setCursorPos(button[i][1],button[i][3])
- m.write(button[i][5])
- else
- term.setCursorPos(button[i][1],button[i][3])
- term.write(button[i][5])
- end
- end
- if pp == true then
- m.setBackgroundColor(colors.black)
- else
- term.setBackgroundColor(colors.black)
- end
- end
- end
- for i = 1, table.getn(Text) do
- if Text[i][4] == CurrentPage then
- if pp == true then
- m.setBackgroundColor(Text[i][6])
- m.setTextColor(Text[i][5])
- m.setCursorPos(Text[i][2],Text[i][3])
- m.write(Text[i][1])
- m.setBackgroundColor(colors.black)
- else
- term.setBackgroundColor(Text[i][6])
- term.setTextColor(Text[i][5])
- term.setCursorPos(Text[i][2],Text[i][3])
- term.write(Text[i][1])
- term.setBackgroundColor(colors.black)
- end
- end
- end
- return event,z,x,y
- end
- function DialogBox(message,x,y)
- --enables the use of dialog boxes--
- if pp == true then
- m.setBackgroundColor(colors.black)
- m.clear()
- m.setCursorPos(x,y)
- m.write(message)
- m.setCursorPos(x,y+1)
- msg = read()
- m.clear()
- return msg
- end
- end
- function SaveTo(info,file)
- -- in the case you would like to save a information to a file(especially useful to save dialog box messages) --
- end
Add Comment
Please, Sign In to add comment