Advertisement
incinirate

BLib

Nov 7th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.72 KB | None | 0 0
  1. local blib = {scene = {}}
  2.  
  3. function blib.newScene()
  4.     blib.scene = {}
  5. end
  6.  
  7. function blib.addButton(tx,x,y,px,py,cob,cot,callback)
  8.     if x=="c" then
  9.         x = txc - (#tx+px*2)/2
  10.     end
  11.     table.insert(blib.scene,{x,y,px,py,tx,cob,cot,callback})
  12. end
  13.  
  14. function blib.saveScene()
  15.     return deepcopy(blib.scene)
  16. end
  17.  
  18. function blib.loadScene(newScene)
  19.     blib.scene = newScene
  20. end
  21.  
  22. function blib.deployScene()
  23.     local bcheck = {}
  24.     for k,v in ipairs(blib.scene) do
  25.         term.setBackgroundColor(v[6])
  26.         term.setTextColor(v[7])
  27.         for i=1,v[4]*2+1 do
  28.             term.setCursorPos(v[1],v[2]+i-1)
  29.             term.write(string.rep(" ",#v[5]+(v[3]*2)))
  30.         end
  31.         term.setCursorPos(v[1]+v[3],v[2]+v[4])
  32.         term.write(v[5])
  33.         table.insert(bcheck, {v[1],v[2],v[1]+#v[5]+v[3]*2-1,v[2]+v[4]*2,k})
  34.     end
  35.     while true do
  36.         local e,p1,p2,p3 = os.pullEvent()
  37.         local success = false
  38.         if e=="mouse_click" then
  39.             local b,x,y = p1,p2,p3
  40.             --local bufferdebug = x..";"..y..": "
  41.             for k,v in ipairs(bcheck) do
  42.                 --bufferdebug = bufferdebug.."("..math.floor(v[1])..","..math.floor(v[2]).."-"..math.floor(v[3])..","..math.floor(v[4])..") "
  43.                 if x >= math.floor(v[1]) and x <= math.floor(v[3]) then
  44.                     if y >= math.floor(v[2]) and y <= math.floor(v[4]) then
  45.                         blib.scene[v[5]][8]()
  46.                         success = true
  47.                         break
  48.                     end
  49.                 end
  50.             end
  51.             --term.setCursorPos(1,ty)
  52.             --term.write(bufferdebug)
  53.         end
  54.         if success then break end
  55.     end
  56. end
  57.  
  58. _G.blib = blib
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement