Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local buttons = {}
- local lastEvent = {}
- local buttonInfo = {}
- local col = { ["white"]=1, ["orange"]=2, ["magenta"]=4, ["lightblue"]=8, ["yellow"]=16, ["lime"]=32, ["pink"]=64, ["gray"]=128, ["lightgray"]=256, ["cyan"]=512, ["purple"]=1024, ["blue"]=2048, ["brown"]=4096, ["green"]=8192, ["red"]=16384, ["black"]=32768 }
- local defaultBackgroundColor = "black"
- function clear()
- term.clear()
- return true
- end
- function getSize()
- return term.getSize()
- end
- function setDefaultBackgroundColor( color )
- if col[color] == nil then
- error("Error: Background color "..color.." does not exist.")
- end
- local defaultBackgroundColor = color
- return true
- end
- function submitEvents()
- local event,pr1,pr2,pr3 = os.pullEvent()
- lastEvent = { [1]=event, [2]=pr1, [3]=pr2, [4]=pr3 }
- return true
- end
- function getEvents()
- return lastEvent
- end
- function resetButtons()
- buttons = {}
- end
- function drawButton( text, name, x, width, y, height , txtcolor, bgcolor )
- if #text > width then
- error("Error: "..name.." button text too big.")
- end
- if col[txtcolor] == nil then error("Error: "..name.." button txtcolor wrong.") end
- if col[bgcolor] == nil then error("Error: "..name.." button bgcolor wrong.") end
- term.setCursorPos( x, y )
- term.setBackgroundColor( col[bgcolor] )
- term.setTextColor( col[txtcolor] )
- for i=1,height do
- for j=1,width do
- term.setCursorPos( j + x - 1, i + y - 1 )
- term.write( " " )
- end
- end
- term.setCursorPos( x + width/2 - #text/2, y + height/2 )
- term.write( text )
- term.setBackgroundColor( col[defaultBackgroundColor] )
- buttons[name] = textutils.serialize( { [1]=x, [2]=x+width, [3]=y, [4]=y+height } )
- buttonInfo[name] = { ["text"]=text, ["x"]=x, ["width"]=width, ["y"]=y, ["height"]=height, ["txtcolor"]=txtcolor, ["bgcolor"]=bgcolor }
- return true
- end
- function drawAlignButton( text, align, name, x, width, y, height, txtcolor, bgcolor )
- if align == "left" or align == "right" or align == "mid" or align == "middle" then
- if align == "left" then
- xAlign = x
- elseif align == "right" then
- xAlign = x - width
- elseif align == "mid" or align == "middle" then
- xAlign = x - width/2
- end
- drawButton( text, name, xAlign, width, y, height, txtcolor, bgcolor )
- else
- error("Error: Align has to be left, mid or right.")
- end
- return true
- end
- function getButtonInfo( name )
- return buttonInfo[name]
- end
- function getButtonText( name )
- return buttonInfo[name]["text"]
- end
- function getButtonX( name )
- return buttonInfo[name]["x"]
- end
- function getButtonY( name )
- return buttonInfo[name]["y"]
- end
- function getButtonWidth( name )
- return buttonInfo[name]["width"]
- end
- function getButtonHeight( name )
- return buttonInfo[name]["height"]
- end
- function getButtonTextColor( name )
- return buttonInfo[name]["txtcolor"]
- end
- function getButtonColor( name )
- return buttonInfo[name]["bgcolor"]
- end
- function drawText( text, x, y, txtcolor, bgcolor )
- if col[txtcolor] == nil then error("Error: "..text.." drawText txtcolor wrong.") end
- if bgcolor == nil then
- term.setBackgroundColor( col[defaultBackgroundColor] )
- else
- if col[bgcolor] == nil then error("Error: "..text.." drawText bgcolor wrong.") end
- term.setBackgroundColor( col[bgcolor] )
- end
- term.setCursorPos( x, y )
- term.setTextColor( col[txtcolor] )
- term.write( text )
- term.setBackgroundColor( col[defaultBackgroundColor] )
- return true
- end
- function drawAlignText( text, align, x, y, txtcolor, bgcolor )
- if align == "left" or align == "right" or align == "mid" or align == "middle" then
- if align == "left" then
- xAlign = x
- elseif align == "right" then
- xAlign = x - #text
- elseif align == "mid" or align == "middle" then
- xAlign = x - #text/2
- end
- drawText( text, xAlign, y, txtcolor, bgcolor )
- else
- error("Error: Align has to be left, mid or right.")
- end
- return true
- end
- function drawOutline( header, footer, txtcolor, linecolor )
- local w,h = term.getSize()
- local w = w + 1
- local h = h + 1
- drawButton("", "", 1, w-1, 1, h-1, txtcolor, linecolor)
- drawButton("", "", 2, w-3, 2, h-3, txtcolor, defaultBackgroundColor)
- drawAlignText( header, "mid", w/2, 1, txtcolor, linecolor)
- drawAlignText( footer, "mid", w/2, h-1, txtcolor, linecolor)
- return true
- end
- function buttonPressed( name )
- if buttons[name] == nil then
- return false
- end
- if lastEvent[1] == "monitor_touch" then
- local tButton = textutils.unserialize( buttons[name] )
- if lastEvent[3] >= tButton[1] and lastEvent[3] < tButton[2] and lastEvent[4] >= tButton[3] and lastEvent[4] < tButton[4] then
- return true
- end
- end
- return false
- end
- local Args = {...}
- if Args[1] == "update" then
- print("Updating PadAPI.")
- fs.delete("papi")
- shell.run("pastebin","get","BsrHWQbW","papi")
- print("Finished updating.")
- end
Advertisement
Add Comment
Please, Sign In to add comment