Advertisement
ColdIV

masterApp

Jul 15th, 2021 (edited)
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.42 KB | None | 0 0
  1. args = {...}
  2. exitProgram = false
  3.  
  4.  
  5. if not fs.exists("config/masterAppConfig") then
  6.     shell.run("pastebin", "get", "F7Czj8j4", "config/masterAppConfig")
  7. end
  8.  
  9. -- load apps from config
  10. local apps = require "config/masterAppConfig"
  11.  
  12. function draw ()
  13.     term.clear()
  14.    
  15.     local x = 2
  16.     local y = 2
  17.     for i = 1, #apps, 2 do
  18.         -- 1st button in row
  19.         paintutils.drawFilledBox(
  20.             x,
  21.             y,
  22.             x + apps[i].width,
  23.             y + apps[i].height,
  24.             apps[i].color
  25.         )
  26.         -- 2nd button in row
  27.         paintutils.drawFilledBox(
  28.             x + apps[i + 1].width + 3,
  29.             y,
  30.             x + apps[i + 1].width * 2 + 3,
  31.             y + apps[i + 1].height,
  32.             apps[i + 1].color
  33.         )
  34.  
  35.         -- 1st label
  36.         term.setCursorPos(
  37.             x + math.max(
  38.                 0,
  39.                 math.floor((apps[i].width - #apps[i].name) / 2)
  40.             ),
  41.             y + math.floor(apps[i].height / 2)
  42.         )
  43.         term.setBackgroundColour(apps[i].color)
  44.         term.write(apps[i].name)
  45.  
  46.         -- 2nd label
  47.         term.setCursorPos(
  48.             x + math.max(
  49.                 apps[i + 1].width + 3,
  50.                 apps[i + 1].width + 3 + math.floor((apps[i + 1].width - #apps[i + 1].name) / 2)
  51.             ),
  52.             y + math.floor(apps[i].height / 2)
  53.         )
  54.         term.setBackgroundColour(apps[i + 1].color)
  55.         term.write(apps[i + 1].name)
  56.  
  57.         -- increase y position for next row
  58.         y = y + math.max(apps[i].height, apps[i + 1].height) + 2
  59.     end
  60.  
  61.     -- print version
  62.     term.setCursorPos(2, 19)
  63.     term.setBackgroundColour(colors.black)
  64.     term.setTextColour(colors.white)
  65.     term.write("RC7fbgX5 - masterApp 1.0")
  66.  
  67.     -- hide cursor off screen
  68.     term.setCursorPos(26, 30)
  69. end
  70.  
  71. function main ()
  72.     draw()
  73.  
  74.     -- check clicks
  75.     local tabN = 1
  76.     local inactiveTab = "inactive"
  77.     while exitProgram == false do
  78.         if multishell.getFocus() == tabN and multishell.getTitle(tabN) == inactiveTab then
  79.             draw()
  80.         end
  81.        
  82.         x = 2
  83.         y = 2
  84.         local event, button, mx, my = os.pullEvent("mouse_click")
  85.         if button == 1 and mx > 1 and mx < 26 and my > 1 and my < 20 then
  86.             tabN = multishell.getCurrent()
  87.             for i = 1, #apps, 2 do
  88.                 if  mx <= x + apps[i].width and
  89.                     my >= y and
  90.                     my <= y + apps[i].height
  91.                 then
  92.                     multishell.setTitle(tabN, inactiveTab)
  93.                     apps[i].func()
  94.                     draw()
  95.                 elseif  mx <= x + apps[i + 1].width * 2 + 3 and
  96.                         mx >= x + apps[i].width + 3 and
  97.                     my >= y and
  98.                     my <= y + apps[i + 1].height
  99.                 then
  100.                     multishell.setTitle(tabN, inactiveTab)
  101.                     apps[i + 1].func()
  102.                     draw()
  103.                 end
  104.  
  105.                 y = y + math.max(apps[i].height, apps[i + 1].height) + 2
  106.             end
  107.         end
  108.     end
  109. end
  110.  
  111. if args[1] == "update" then
  112.     masterAppConfigUpdate()
  113.    
  114.     if args[2] == "run" then
  115.         shell.run("pastebin", "run", "FuQ3WvPs RC7fbgX5 masterApp run")
  116.     else
  117.         shell.run("pastebin", "run", "FuQ3WvPs RC7fbgX5 masterApp")
  118.     end
  119. else
  120.     term.clear()
  121.     main()
  122.     term.clear()
  123.     term.setCursorPos(1, 1)
  124. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement