Advertisement
HyperQ

Icon Menu - Computercraft

Jan 2nd, 2013
822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.30 KB | None | 0 0
  1. -- Declerations --
  2. local InstallDirectory = "installed/"
  3.  
  4. -- images have to be 14 wide and 7 high
  5.  
  6. function drawIcons(x,y)
  7.     term.setBackgroundColor(colors.black)
  8.     term.clear()
  9.     term.setCursorPos(1,1)
  10.     for i=x,y do
  11.         if filelist[i] ~= nil then
  12.             if fs.exists(InstallDirectory..filelist[i]..".ico") then
  13.                 if i == x then
  14.                     paintutils.drawImage(paintutils.loadImage(InstallDirectory..filelist[i]..".ico"),3,2)
  15.                     if #filelist[i] > 12 then term.setCursorPos(3,8);term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);print(" "..string.sub(filelist[i],1,9).."... ") else term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);term.setCursorPos(9-(#filelist[i]/2),8);print(" "..filelist[i].." ") end
  16.                 end
  17.                 if i == x+1 then
  18.                     paintutils.drawImage(paintutils.loadImage(InstallDirectory..filelist[i]..".ico"),19,2)
  19.                     if #filelist[i] > 12 then term.setCursorPos(19,8);term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);print(" "..string.sub(filelist[i],1,9).."... ") else term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);term.setCursorPos(25-(#filelist[i]/2),8);print(" "..filelist[i].." ") end
  20.                 end
  21.                 if i == x+2 then
  22.                     paintutils.drawImage(paintutils.loadImage(InstallDirectory..filelist[i]..".ico"),35,2)
  23.                     if #filelist[i] > 12 then term.setCursorPos(35,8);term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);print(" "..string.sub(filelist[i],1,9).."... ") else term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);term.setCursorPos(41-(#filelist[i]/2),8);print(" "..filelist[i].." ") end             
  24.                 end
  25.                
  26.                 if i == x+3 then
  27.                     paintutils.drawImage(paintutils.loadImage(InstallDirectory..filelist[i]..".ico"),3,10)
  28.                     if #filelist[i] > 12 then term.setCursorPos(3,6);term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);print(" "..string.sub(filelist[i],1,9).."... ") else term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);term.setCursorPos(9-(#filelist[i]/2),16);print(" "..filelist[i].." ") end
  29.                 end
  30.                
  31.                 if i == x+4 then
  32.                     paintutils.drawImage(paintutils.loadImage(InstallDirectory..filelist[i]..".ico"),19,10)
  33.                     if #filelist[i] > 12 then term.setCursorPos(19,16);term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);print(" "..string.sub(filelist[i],1,9).."... ") else term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);term.setCursorPos(25-(#filelist[i]/2),16);print(" "..filelist[i].." ") end
  34.                 end
  35.                 if i == x+5 then
  36.                     paintutils.drawImage(paintutils.loadImage(InstallDirectory..filelist[i]..".ico"),35,10)
  37.                     if #filelist[i] > 12 then term.setCursorPos(35,16);term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);print(" "..string.sub(filelist[i],1,9).."... ") else term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);term.setCursorPos(41-(#filelist[i]/2),16);print(" "..filelist[i].." ") end
  38.                 end
  39.             else
  40.                 if i == x then
  41.                     paintutils.drawImage(paintutils.loadImage(InstallDirectory.."missingicon.ico"),3,2)
  42.                     if #filelist[i] > 12 then term.setCursorPos(3,8);term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);print(" "..string.sub(filelist[i],1,9).."... ") else term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);term.setCursorPos(9-(#filelist[i]/2),8);print(" "..filelist[i].." ") end
  43.                 end
  44.                 if i == x+1 then
  45.                     paintutils.drawImage(paintutils.loadImage(InstallDirectory.."missingicon.ico"),19,2)
  46.                     if #filelist[i] > 12 then term.setCursorPos(19,8);term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);print(" "..string.sub(filelist[i],1,9).."... ") else term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);term.setCursorPos(25-(#filelist[i]/2),8);print(" "..filelist[i].." ") end
  47.                 end
  48.                 if i == x+2 then
  49.                     paintutils.drawImage(paintutils.loadImage(InstallDirectory.."missingicon.ico"),35,2)
  50.                     if #filelist[i] > 12 then term.setCursorPos(35,8);term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);print(" "..string.sub(filelist[i],1,9).."... ") else term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);term.setCursorPos(41-(#filelist[i]/2),8);print(" "..filelist[i].." ") end
  51.                 end
  52.                 if i == x+3 then
  53.                     paintutils.drawImage(paintutils.loadImage(InstallDirectory.."missingicon.ico"),3,10)
  54.                     if #filelist[i] > 12 then term.setCursorPos(3,16);term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);print(" "..string.sub(filelist[i],1,9).."... ") else term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);term.setCursorPos(9-(#filelist[i]/2),16);print(" "..filelist[i].." ") end
  55.                 end
  56.                 if i == x+4 then
  57.                     paintutils.drawImage(paintutils.loadImage(InstallDirectory.."missingicon.ico"),19,10)
  58.                     if #filelist[i] > 12 then term.setCursorPos(19,16);term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);print(" "..string.sub(filelist[i],1,9).."... ") else term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);term.setCursorPos(25-(#filelist[i]/2),16);print(" "..filelist[i].." ") end
  59.                 end
  60.                 if i == x+5 then
  61.                     paintutils.drawImage(paintutils.loadImage(InstallDirectory.."missingicon.ico"),35,10)
  62.                     if #filelist[i] > 12 then term.setCursorPos(35,16);term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);print(" "..string.sub(filelist[i],1,9).."... ") else term.setBackgroundColor(colors.gray);term.setTextColor(colors.white);term.setCursorPos(41-(#filelist[i]/2),16);print(" "..filelist[i].." ") end
  63.                 end
  64.             end
  65.         end
  66.     end
  67. end
  68. term.clear()
  69. term.setCursorPos(1,1)
  70.  
  71. filelist = fs.list(InstallDirectory)
  72. local i=1
  73. while i<= #filelist do
  74.     if string.lower(string.sub(filelist[i],#filelist[i]-3,#filelist[i])) == ".ico" then
  75.         table.remove(filelist,i)
  76.     else i=i+1 end
  77. end
  78.  
  79.  
  80. currenticonnumber = 1
  81. drawIcons(currenticonnumber,#filelist)
  82. while true do
  83.     local event,p1,p2,p3 = os.pullEvent()
  84.     if event == "mouse_scroll" then
  85.         if p1 == 1 and currenticonnumber +3 <= #filelist then currenticonnumber = currenticonnumber + 3
  86.         elseif p1 == -1 and currenticonnumber -3 >= 1 then currenticonnumber = currenticonnumber - 3 end
  87.         drawIcons(currenticonnumber,#filelist)
  88.     elseif event == "mouse_click" and p1 == 1  then
  89.         local x = p2;y = p3
  90.         term.setBackgroundColor(colors.black);term.setTextColor(colors.white);
  91.         if (x >= 3 and x <=16) and (y >=2 and y <= 8) and filelist[currenticonnumber] ~= nil then shell.run(InstallDirectory..filelist[currenticonnumber]) end
  92.         if (x >= 19 and x <=32) and (y >=2 and y <= 8)  and filelist[currenticonnumber+1] ~= nil then shell.run(InstallDirectory..filelist[currenticonnumber+1]) end
  93.         if (x >= 35 and x <=48) and (y >=2 and y <= 8)  and filelist[currenticonnumber+2] ~= nil then shell.run(InstallDirectory..filelist[currenticonnumber+2]) end
  94.         if (x >= 3 and x <=16) and (y >=10 and y <= 16)  and filelist[currenticonnumber+3] ~= nil then shell.run(InstallDirectory..filelist[currenticonnumber+3]) end
  95.         if (x >= 19 and x <=32) and (y >=10 and y <= 16) and filelist[currenticonnumber+4] ~= nil then shell.run(InstallDirectory..filelist[currenticonnumber+4]) end
  96.         if (x >= 35 and x <=48) and (y >=10 and y <= 16) and filelist[currenticonnumber+5] ~= nil then shell.run(InstallDirectory..filelist[currenticonnumber+5]) end
  97.     end
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement