Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function findDev (dType)
- local d
- for _,d in pairs(peripheral.getNames()) do
- if (peripheral.getType(d) == dType) then
- return peripheral.wrap(d)
- end
- end
- return nil, dType..": not found"
- end
- m=findDev("monitor")
- local tButton = {
- isClicked = function( self, x, y )
- return true and self.x <= x and self.maxx > x and self.y <= y and self.y + 3 > y or false
- end,
- render = function( self, bColor, tColor )
- m.setBackgroundColor( bColor )
- m.setTextColor( tColor )
- for i = 0, 2 do
- m.setCursorPos( self.x, self.y + i )
- m.write( string.rep( " ", self.maxx - self.x ) )
- end
- m.setCursorPos( math.ceil( (self.maxx + self.x - #self.str)/ 2 ), self.y + 1 )
- m.write( self.str )
- end,
- }
- local function newButton( x, y, maxx, str )
- local button = { x = x, y = y, maxx = maxx, str = str }
- setmetatable( button, { __index = tButton } )
- return button
- end
- local tPages = {
- render = function( self )
- m.setBackgroundColor( self.backgroundColor )
- m.clear()
- for k, v in pairs( self[ self.current ] ) do
- v:render( self.bColor, self.bTextColor )
- end
- end,
- }
- function makeButtonPages( backgroundColor, bColor, bTextColor, ... )
- local maxx, maxy = m.getSize()
- local tStrings = { ... }
- local maxStringLen = 0
- for k, v in pairs( tStrings ) do
- if #v > maxStringLen then
- maxStringLen = #v
- end
- end
- if #tStrings < 1 then
- error( "Not enough arguments", 2 )
- end
- local tButtonPages = {{}}
- local x = math.ceil( maxx / 2 - maxStringLen / 2 ) - 1
- local nMax = x + maxStringLen + 2
- local y = 3
- for k, v in pairs( tStrings ) do
- if y + 3 >= maxy then
- tButtonPages[ #tButtonPages ][ #tButtonPages[ #tButtonPages ] + 1 ] = newButton( maxx - 1, math.ceil( maxy / 2 ) - 1, maxx + 1, ">" )
- tButtonPages[ #tButtonPages + 1 ] = {}
- tButtonPages[ #tButtonPages ][ #tButtonPages[ #tButtonPages ] + 1 ] = newButton( 1, math.ceil( maxy / 2 ) - 1, 3, "< " )
- y = 3
- end
- tButtonPages[ #tButtonPages ][ #tButtonPages[ #tButtonPages ] + 1 ] = newButton( x, y, nMax, v )
- y = y + 4
- end
- tButtonPages.backgroundColor = backgroundColor
- tButtonPages.bColor = bColor
- tButtonPages.bTextColor = bTextColor
- tButtonPages.current = 1
- return setmetatable( tButtonPages, { __index = tPages } )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement