Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function init(this)
- new={};
- new.info={x=0,y=0,sizeX=0,sizeY=0,bCol=0,tCol=0,text="",visible=false,onClick=function() end};
- for k,v in pairs(this) do
- if k~="init" then
- new[k]=v;
- end
- end
- return setmetatable(new,this);
- end
- function setSize(this,nX,nY)
- this.info.sizeX=nX;
- this.info.sizeY=nY;
- return this;
- end
- function setLoc(this,nX,nY)
- this.info.x=nX;
- this.info.y=nY;
- return this;
- end
- function setX(this,nX)
- this.info.x=nX;
- return this;
- end
- function setY(this,nY)
- this.info.y=nY;
- return this;
- end
- function setPos(this,nX,nY)
- this.info.x=nX;
- this.info.y=nY;
- return this;
- end
- function setBackColor(this,col)
- this.info.bCol=col;
- return this;
- end
- function setBackgroundColor(this,col)
- this.info.bCol=col;
- return this;
- end
- function setTextColor(this,col)
- this.info.tCol=col;
- return this;
- end
- function setText(this,tx)
- this.info.text=tx;
- return this;
- end
- function setVisible(this,bool)
- this.info.visible=bool;
- return this;
- end
- function getInfo(this)
- return this.info;
- end
- function clickAt(this,x,y)
- if x>=this.info.x and x<= this.info.x+this.info.sizeX-1 and y>=this.info.y and y<= this.info.y+this.info.sizeY-1 and this.info.visible then
- this.info.onClick();
- end
- end
- function setOnClick(this,oncl)
- this.info.onClick=oncl;
- return this;
- end
- function onClick(this)
- this.info.onClick();
- end
- local function writeTextSpecificCentered(text,sX,eX,y,tCol)
- if text==nil or y<=0 then return false; end
- sValue=(((eX+1)-sX)-string.len(text))/2;
- if tCol then term.setTextColor(tCol) end
- term.setCursorPos(sValue+sX,y);
- term.write(text);
- term.setBackgroundColor(colors.green)
- end
- function draw(this)
- if this.info.visible then
- tX=this.info.x;
- tY=this.info.y;
- tX2=this.info.x+this.info.sizeX-1;
- tY2=this.info.y+this.info.sizeY-1;
- ok,err=pcall(paintutils.drawFilledBox,tX,tY,tX2,tY2,this.info.bCol or colors.black);
- ok,err=pcall(writeTextSpecificCentered,this.info.text or "",tX,tX2,tY+(this.info.sizeY/2),this.info.tCol or colors.white);
- end
- return true;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement