Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --]] Language assigning [[--
- pos = term.setCursorPos
- bcolor = term.setBackgroundColor
- tcolor = term.setTextColor
- blink = term.setCursorBlink
- buffer = term.current().setVisible
- getpos = term.getCursorPos
- getbcolor = term.getBackgroundColor
- gettcolor = term.getTextColor
- printslow = textutils.slowPrint
- clr = term.clear
- clrln = term.clearLine
- clrlny = function(y)
- local x,_ = getpos()
- pos(x,y)
- clrln()
- end
- clrlnycolor = function(col,y) bcolor(col) clrlny(y) end
- box = paintutils.drawFilledBox
- hbox = paintutils.drawBox
- drawimage = function(img,x,y) paintutils.drawImage(paintutils.loadImage(img),x,y) end
- -- ]] Write functions [[--
- function writexy(text,x,y)
- term.setCursorPos(x,y)
- term.write(text)
- end
- function writec(text)
- local w, h = term.getSize()
- term.setCursorPos(w/2 - #text/2, (h/2)- 1)
- term.write(text)
- end
- function writecy(text,y)
- local w,_ = term.getSize()
- term.setCursorPos(w/2 - #text/2, y)
- term.write(text)
- end
- -- ]] Print functions [[--
- function printc(text)
- local w,h = term.getSize()
- term.setCursorPos( (w/2) - #text/2,(h/2) - 1)
- print(text)
- end
- function printcy(text,y)
- local w,_ = term.getSize()
- term.setCursorPos(w/2 - #text/2, y)
- print(text)
- end
- function println(text)
- local xx, yy = term.getCursorPos()
- term.setCursorPos(xx,yy+1)
- print(text)
- end
- function printxy(text,x,y)
- term.setCursorPos(x,y)
- print(text)
- end
- --]] Transitions [[--
- function fadeIn(time)
- local ctbl = {
- 'black',
- 'gray',
- 'lightGray',
- 'white',
- }
- for i = 1, #ctbl do
- term.setBackgroundColor(colors[ ctbl[i] ])
- term.clear()
- sleep(time)
- end
- end
- function fadeOut(time)
- local ctbl = {
- 'white',
- 'lightGray',
- 'gray',
- 'black',
- }
- for i = 1, #ctbl do
- term.setBackgroundColor(colors[ ctbl[i] ])
- term.clear()
- sleep(time)
- end
- end
- function fadecolors(time,ctbl)
- for i = 1, #ctbl do
- term.setBackgroundColor(colors[ctbl[i]])
- term.clear()
- sleep(time)
- end
- end
- function transitionIn(pixeltime, linetime,smoothness)
- local w, h = term.getSize()
- local left = true
- for hh = 1, h/2+1 do
- for ww = 1, w do
- bcolor(colors.white)
- if(left)then writexy(string.rep(" ",smoothness),w-(ww-1),hh) else writexy(" ",ww,hh) end
- bcolor(colors.white)
- if(left)then writexy(string.rep(" ",smoothness),ww,h-(hh-1) ) else writexy(" ",w-(ww-1),h-(hh-1)) end
- if(pixeltime > 0) then sleep(pixeltime) end
- end
- if(left)then left = false else left = true end
- if(linetime > 0)then sleep(linetime) end
- end
- end
- function transitionOut(pixeltime, linetime,smoothness)
- local w, h = term.getSize()
- local left = true
- for hh = 1, h/2+1 do
- for ww = 1, w do
- bcolor(colors.black)
- if(left)then writexy(string.rep(" ",smoothness),w-(ww-1),hh) else writexy(" ",ww,hh) end
- bcolor(colors.black)
- if(left)then writexy(string.rep(" ",smoothness),ww,h-(hh-1) ) else writexy(" ",w-(ww-1),h-(hh-1)) end
- if(pixeltime > 0) then sleep(pixeltime) end
- end
- if(left)then left = false else left = true end
- if(linetime > 0)then sleep(linetime) end
- end
- end
- --]] Button API [[ --
- function newButton(name,x,y,width,height,namecolor,color,activecolor)
- local button = {
- name = name,
- x = x,
- y = y,
- w = width-1,
- h = height-1,
- tcol = namecolor,
- col = color,
- acol = activecolor,
- active = false,
- rfun = function() end,
- fun = function() end,
- draw = function(self)
- local dbcol
- if(self.active)then dbcol = self.acol
- else dbcol = self.col end
- box(self.x,self.y,self.x+self.w,self.y+self.h,dbcol)
- -- Center text on button --
- tcolor(self.tcol)
- writexy(self.name,
- ( (self.x+self.w/2) - (#self.name/2) ),
- ( (self.y+self.h) - (self.h/2) )
- )
- end,
- update = function(self,ev)
- if(ev[1] == "mouse_click")then
- -- Display active for a bit then switch off
- if(ev[3] >= self.x and ev[3] <= self.x + self.w and ev[4] >= self.y and ev[4] <= self.y + self.h)then
- self:setActive(true)
- sleep(0.2)
- self:setActive(false)
- if(ev[2] == 1)then self.fun() end
- if(ev[2] == 2)then self.rfun() end
- end
- end
- end,
- onPress = function(self,func)
- self.fun = func
- end,
- setName = function(self,nname)
- self.name = nname
- end,
- getName = function(self,nname)
- return self.name
- end,
- setPos = function(self,x,y)
- self.x = x
- self.y = y
- self:draw()
- end,
- getPos = function(self)
- return self.x, self.y
- end,
- onRightPress = function(self,func)
- self.rfun = func
- end,
- setActive = function(self,act)
- self.active = act
- self:draw()
- end,
- getActive = function(self)
- return self.active
- end,
- }
- return button
- end
- -- Menu API --
- function newMenu(x,y,width,height,bcolor)
- local menu = {
- x = x,
- y = y,
- w = width,
- h = height,
- bcol = bcolor,
- options={},
- presets={},
- draw = function(self)
- box(self.x,self.y,self.x+self.w-1,self.y+self.h-1,self.bcol)
- for i = 1, #self.options do
- if(self.options[i].name ~= nil)then
- local bcol = self.presets[self.options[i].pset].bc
- local tcol = self.presets[self.options[i].pset].tc
- if(self.options[i].active)then
- bcol = self.presets[self.options[i].pset].ab
- tcol = self.presets[self.options[i].pset].at
- end
- term.setBackgroundColor(bcol)
- term.setTextColor(tcol)
- pos( self.x, self.y+(i-1) )
- write(self.options[i].name)
- end
- end
- end,
- update = function(self, ev)
- if(ev[1] == "mouse_click")then
- for i = 1, #self.options do
- if(self.options[i].name ~= nil)then
- if(ev[3] >= self.x and ev[3] <= #self.options[i].name + self.x
- and ev[4] == self.y + (i-1))then
- self:setActiveOption(self.options[i].name,true)
- sleep(0.2)
- self:setActiveOption(self.options[i].name,false)
- self.options[i].act()
- end
- end
- end
- end
- end,
- addOption = function(self,name,preset,action)
- if(self.presets[preset].tc ~= nil)then
- self.options[#self.options+1] = {name=name,pset=preset,act=action,active=false}
- else
- error("UGAPI: ->menu->addOption: No such preset.")
- end
- end,
- setPreset = function(self,name,tcolor,bcolor,atcolor,abcolor,action)
- self.presets[name] = {tc=tcolor,bc=bcolor,at=atcolor,ab=abcolor}
- end,
- addWhiteSpace = function(self)
- self.options[#self.options+1] = {name=nil}
- end,
- setActiveOption = function(self,nname,isact)
- for i = 1, #self.options do
- if(self.options[i].name == nname and nname ~= nil)then
- self.options[i].active = isact
- end
- end
- self:draw()
- end,
- }
- return menu
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement