Advertisement
Guest User

pc.lua

a guest
Nov 25th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.78 KB | None | 0 0
  1. OOS=require("OOS")
  2. component=require("component")
  3.  
  4. w,h=component.gpu.getResolution()
  5. running=true
  6. exit=OOS.makeButton("gpu",{w-3,h},"exit",0x000000,0xff0000,{char="q"})
  7.  
  8. tab={
  9.     "tab1";
  10.     "tab2";
  11.     "tab3";
  12.     "tab4";
  13.     "tab5";
  14.     "tab6";
  15.     "tab7";
  16.     "tab8";
  17.     "tab9";
  18.  
  19. }
  20.  
  21. oddbjorn={}
  22. for i=1,45 do
  23.  
  24.     oddbjorn[i]={string=string.rep("X",math.random(0,9)),slot=i};
  25. end
  26.  
  27.  
  28. tabs=function(tab)
  29.     tabs={}
  30.     for i=1,#tab do
  31.         tabs[i]=OOS.makeButton("gpu",{w-3,2*i},tab[i],0xffffff,0x000000,{char=tostring(i),isToggle=true})
  32.     end
  33.     return tabs
  34. end
  35.  
  36. currentTab=1
  37. sidebar=tabs(tab)
  38.  
  39. drawSidebar=function(e)
  40.     for i=1,#sidebar do
  41.         if sidebar[i]:detect(e) then
  42.             for q=1,#sidebar do
  43.                 sidebar[q].hit=false
  44.             end
  45.             sidebar[i].hit=true
  46.             currentTab=i
  47.         end
  48.     end
  49.  
  50.     for i=1,#sidebar do
  51.         if sidebar[i].hit then
  52.             if not sidebar[i].hit==sidebar[i].lastHit then
  53.                 sidebar[i]:changeColor(0xffffff,0xff0000)
  54.                 sidebar[i]:vanish()
  55.                 sidebar[i]:draw()
  56.                 sidebar[i].lastHit=sidebar[i].hit
  57.             end
  58.         else
  59.             if not sidebar[i].hit==sidebar[i].lastHit then
  60.                 sidebar[i]:changeColor(0xffffff,0x0000ff)
  61.                 sidebar[i]:vanish()
  62.                 sidebar[i]:draw()
  63.                 sidebar[i].lastHit=sidebar[i].hit
  64.             end
  65.         end
  66.     end
  67. end
  68.  
  69. makeButtons=function(data)
  70.     buttons={}
  71.     foundLeap=false
  72.     leap=0
  73.     maxlenght=0
  74.     for i=1,#data do
  75.         if #data[i].string > maxlenght then maxlenght=#data[i].string end
  76.     end
  77.     maxlenght=maxlenght+3
  78.     xnmb=math.floor(w/(maxlenght+1))-2
  79.     ynmb=math.floor(h/(4))-2
  80.     i=1
  81.     for x=1,xnmb do
  82.         for y=1,ynmb do
  83.             if i>#data then break end
  84.             xPos=x*maxlenght+2
  85.             yPos=y*4+1
  86.             buttons[i]={button=OOS.makeButton("gpu",{xPos,yPos},{"/"..string.rep("-",#data[i].string).."\\","|"..data[i].string.."|","\\"..string.rep("-",#data[i].string).."/"},0xffffff,0x0000ff);slot=data[i].slot}
  87.             i=i+1
  88.         end
  89.     end
  90.     return buttons
  91. end
  92.  
  93. drawButton=function(buttonList)
  94.     for i =1,#buttonList do
  95.         buttonList[i].button:draw()
  96.     end
  97. end
  98.  
  99. detectButton=function(buttonlist,e)
  100.     toreturn="   "
  101.     for i=1,#buttonlist() do
  102.         if buttonList[i].button:detect(e) then
  103.             toreturn=i
  104.             break
  105.         end
  106.     end
  107.     return toreturn
  108. end
  109.  
  110. vanishButton=function(buttonList)
  111.     for i=1,#buttonList do
  112.         buttonList[i].button:vanish()
  113.     end
  114. end
  115.  
  116. for i=1,#tab*2+1 do
  117.     if i==1 then
  118.         component.gpu.set(w-4,i,"/----")
  119.     elseif i==2*#tab+1 then
  120.         component.gpu.set(w-4,i,"\\----")
  121.     elseif i%2==1 then
  122.         component.gpu.set(w-4,i,"+----")
  123.     else
  124.         component.gpu.set(w-4,i,"|")
  125.     end
  126. end
  127.  
  128. oddbjornButtons=makeButtons(oddbjorn)
  129. drawButton(oddbjornButtons)
  130. --os.sleep(3)
  131. --vanishButton(oddbjornButtons)
  132.  
  133.  
  134.  
  135. for i=1,#sidebar do
  136.     sidebar[i]:draw()
  137.     sidebar[i].lastHit=true
  138. end
  139. while running do
  140.     e=OOS.eventHandle(1)
  141.     exit:draw()
  142.     if exit:detect(e) then running=false end
  143.     drawSidebar(e)
  144.  
  145.  
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement