Advertisement
Corbinhol

Tablet BETA

Sep 26th, 2022 (edited)
992
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.16 KB | None | 0 0
  1.         --Tablet
  2.         local filePath = "basalt.lua" --here you can change the file path that it installs to. default: /basalt.lua
  3.         if not(fs.exists(filePath))then
  4.             shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
  5.         end
  6.         local basalt = require(filePath:gsub(".lua", "")) -- here you can change the variablename in any variablename you want default: basalt
  7.         local testNumber = 1;
  8.  
  9.         basalt.setTheme(
  10.             { -- The default main theme for basalt!
  11.         BasaltBG = colors.white,
  12.         BasaltText = colors.black,
  13.         FrameBG = colors.gray,
  14.         FrameText = colors.black,
  15.         ButtonBG = colors.cyan,
  16.         ButtonText = colors.white,
  17.         CheckboxBG = colors.gray,
  18.         CheckboxText = colors.black,
  19.         InputBG = colors.gray,
  20.         InputText = colors.black,
  21.         TextfieldBG = colors.gray,
  22.         TextfieldText = colors.black,
  23.         ListBG = colors.gray,
  24.         ListText = colors.black,
  25.         MenubarBG = colors.gray,
  26.         MenubarText = colors.black,
  27.         DropdownBG = colors.gray,
  28.         DropdownText = colors.black,
  29.         RadioBG = colors.gray,
  30.         RadioText = colors.black,
  31.         SelectionBG = colors.black,
  32.         SelectionText = colors.lightGray,
  33.         GraphicBG = colors.black,
  34.         ImageBG = colors.black,
  35.         PaneBG = colors.black,
  36.         ProgramBG = colors.black,
  37.         ProgressbarBG = colors.gray,
  38.         ProgressbarText = colors.black,
  39.         ProgressbarActiveBG = colors.black,
  40.         ScrollbarBG = colors.lightGray,
  41.         ScrollbarText = colors.gray,
  42.         ScrollbarSymbolColor = colors.black,
  43.         SliderBG = false,
  44.         SliderText = colors.gray,
  45.         SliderSymbolColor = colors.black,
  46.         SwitchBG = colors.lightGray,
  47.         SwitchText = colors.gray,
  48.         SwitchBGSymbol = colors.black,
  49.         SwitchInactive = colors.red,
  50.         SwitchActive = colors.green,
  51.         LabelBG = false,
  52.         LabelText = colors.black
  53.        
  54.     }
  55.         )
  56.  
  57.         term.clear();
  58.         term.setCursorPos(1,1);
  59.         local locked = {};
  60.         local parent = {};
  61.  
  62.         local mainFrame = basalt.createFrame()
  63.         locked[mainFrame] = false;
  64.        
  65.         rednet.open("back");
  66.         local api = {};
  67.  
  68.  
  69.         local function newMessageBox()
  70.             local out = mainFrame:addFrame():setBackground(colors.gray):setSize(26, 5):setPosition(1, 7):setShadow(colors.black):hide()
  71.             return out;
  72.         end
  73.  
  74.         function showMessageBox(frame, text)
  75.             if locked[frame] == false then
  76.                 locked[frame] = true;
  77.                 local messageBox = newMessageBox(frame);
  78.                 local messageBoxLabel = messageBox:addLabel():setText(text):setPosition(2, 2):setForeground(colors.white):setFontSize(1);
  79.                 local messageBoxButton = messageBox:addButton():setText("Ok"):setPosition(11,4):setSize(6, 1):setForeground(colors.white):setBackground(colors.blue);
  80.                 messageBox:show();
  81.  
  82.                 messageBoxButton:onClick(
  83.                     function()
  84.                         messageBoxButton:setBackground(colors.lightGray);
  85.                     end
  86.                 )
  87.  
  88.                 messageBoxButton:onClickUp(
  89.                     function()
  90.                         messageBoxButton:setBackground(colors.blue);
  91.                         messageBox:hide():disable()
  92.                         messageBox = nil;
  93.                         locked[frame] = false;
  94.                     end
  95.                 )
  96.             end
  97.         end
  98.        
  99.         function onElevatorButtonClick()
  100.             if locked[mainFrame] == false then
  101.                 if api["ElevatorData"] == "Idle" then
  102.                     local apiProtocol = "API"
  103.                     local elevatorAddress = rednet.lookup(apiProtocol, "elevator");
  104.                     rednet.send(elevatorAddress, "lowerElevator", apiProtocol);
  105.                     locked[mainFrame] = true;
  106.                     local elevatorResponse = newMessageBox(mainFrame);
  107.                     local elevatorResponseLabel = elevatorResponse:addLabel():setText("Lowering Elevator..."):setPosition(2, 2):setForeground(colors.white):setFontSize(1);
  108.                     local elevatorResponseButton = elevatorResponse:addButton():setText("Ok"):setPosition(11,4):setSize(6, 1):setForeground(colors.white):setBackground(colors.blue);
  109.                     elevatorResponse:show();
  110.                    
  111.                     elevatorResponseButton:onClick(
  112.                         function()
  113.                             elevatorResponseButton:setBackground(colors.lightGray);
  114.                         end
  115.                     )
  116.  
  117.                     elevatorResponseButton:onClickUp(
  118.                         function()
  119.                             elevatorResponseButton:setBackground(colors.blue);
  120.                             elevatorResponse:hide():disable()
  121.                             elevatorResponse = nil;
  122.                             locked[mainFrame] = false;
  123.                         end
  124.                     )
  125.                 end
  126.             end
  127.         end
  128.  
  129.         function onSafeButtonClick()
  130.             if locked[mainFrame] == false then
  131.                 if api["SafeData"] == "Offline" or api["SafeData"] == nil then
  132.                     locked[mainFrame] = true;
  133.                     local safeResponse = newMessageBox(mainFrame);
  134.                     local safeResponseLabel = safeResponse:addLabel():setText("Unable To Connect."):setPosition(2, 2):setForeground(colors.white):setFontSize(1);
  135.                     local safeResponseButton = safeResponse:addButton():setText("Ok"):setPosition(11,4):setSize(6, 1):setForeground(colors.white):setBackground(colors.blue);
  136.                     safeResponse:show();
  137.                    
  138.                     safeResponseButton:onClick(
  139.                         function()
  140.                             safeResponseButton:setBackground(colors.lightGray);
  141.                         end
  142.                     )
  143.  
  144.                     safeResponseButton:onClickUp(
  145.                         function()
  146.                             safeResponseButton:setBackground(colors.blue);
  147.                             safeResponse:hide():disable()
  148.                             safeResponse = nil;
  149.                             locked[mainFrame] = false;
  150.                         end
  151.                     )
  152.                 end
  153.  
  154.                 if api["SafeData"] == "opening" then
  155.                     locked[mainFrame] = true;
  156.                     local safeResponse = newMessageBox(mainFrame);
  157.                     local safeResponseLabel = safeResponse:addLabel():setText("Already Opening."):setPosition(2, 2):setForeground(colors.white):setFontSize(1);
  158.                     local safeResponseButton = safeResponse:addButton():setText("Ok"):setPosition(11,4):setSize(6, 1):setForeground(colors.white):setBackground(colors.blue);
  159.                     safeResponse:show();
  160.                    
  161.                     safeResponseButton:onClick(
  162.                         function()
  163.                             safeResponseButton:setBackground(colors.lightGray);
  164.                         end
  165.                     )
  166.  
  167.                     safeResponseButton:onClickUp(
  168.                         function()
  169.                             safeResponseButton:setBackground(colors.blue);
  170.                             safeResponse:hide():disable()
  171.                             safeResponse = nil;
  172.                             locked[mainFrame] = false;
  173.                         end
  174.                     )
  175.                 end
  176.  
  177.                 if api["SafeData"] == "closing" then
  178.                     locked[mainFrame] = true;
  179.                     local safeResponse = newMessageBox(mainFrame);
  180.                     local safeResponseLabel = safeResponse:addLabel():setText("Already Closing."):setPosition(2, 2):setForeground(colors.white):setFontSize(1);
  181.                     local safeResponseButton = safeResponse:addButton():setText("Ok"):setPosition(11,4):setSize(6, 1):setForeground(colors.white):setBackground(colors.blue);
  182.                     safeResponse:show();
  183.                    
  184.                     safeResponseButton:onClick(
  185.                         function()
  186.                             safeResponseButton:setBackground(colors.lightGray);
  187.                         end
  188.                     )
  189.  
  190.                     safeResponseButton:onClickUp(
  191.                         function()
  192.                             safeResponseButton:setBackground(colors.blue);
  193.                             safeResponse:hide():disable()
  194.                             safeResponse = nil;
  195.                             locked[mainFrame] = false;
  196.                         end
  197.                     )
  198.                 end
  199.  
  200.                 if api["SafeData"] ~= "Offline" and api["SafeData"] ~= nil and api["SafeData"] ~= "opening" and api["SafeData"] ~= "closing" then
  201.                     local tempSafeData = api["SafeData"];
  202.                     locked[mainFrame] = true;
  203.                     safeProtocol = "SAFE";
  204.                     safeAddress = rednet.lookup(safeProtocol, "safeController");
  205.                    
  206.                     local safeLoadingWindow = newMessageBox(mainFrame);
  207.                     local safeLoadingWindowLabel = safeLoadingWindow:addLabel():setPosition(4, 3):setForeground(colors.white):setFontSize(1);
  208.                     local safeLoadingWindowLabelText;
  209.                     if api["SafeData"] == true then
  210.                         rednet.send(safeAddress, "close", safeProtocol);
  211.                         safeLoadingWindowLabelText = "Closing Safe"
  212.                     elseif api["SafeData"] == false then
  213.                         rednet.send(safeAddress, "open", safeProtocol);
  214.                         safeLoadingWindowLabelText = "Opening Safe"
  215.                     end
  216.                     safeLoadingWindowLabelAnimationStatus = false;
  217.                     safeIsDone = false;
  218.                     safeLoadingWindowLabelAnimation = safeLoadingWindow:addAnimation()
  219.                         :add(function() if safeIsDone == false then safeLoadingWindowLabel:setText(safeLoadingWindowLabelText); end end)
  220.                         :wait(.5)
  221.                         :add(function() if safeIsDone == false then safeLoadingWindowLabel:setText(safeLoadingWindowLabelText .. "."); end end)
  222.                         :wait(.5)
  223.                         :add(function() if safeIsDone == false then safeLoadingWindowLabel:setText(safeLoadingWindowLabelText .. ".."); end end)
  224.                         :wait(.5)
  225.                         :add(function() if safeIsDone == false then safeLoadingWindowLabel:setText(safeLoadingWindowLabelText .. "..."); end end)
  226.                         :wait(.8)
  227.                         :add(function() if safeIsDone == false then safeLoadingWindowLabel:setText(safeLoadingWindowLabelText .. "..."); end end)
  228.                         :onDone(function() safeLoadingWindowLabelAnimationStatus = false end)
  229.                         :play();
  230.  
  231.                     safeLoadingWindow:show();
  232.                    
  233.                     safeLoadingWindowThread = safeLoadingWindow:addThread():start(
  234.                         function()
  235.                             while true do
  236.                                 if safeLoadingWindowLabelAnimationStatus == false and safeIsDone == false then
  237.                                     safeLoadingWindowLabelAnimationStatus = true;
  238.                                     safeLoadingWindowLabelAnimation:play();
  239.                                 end
  240.                                 sleep(0);
  241.                             end
  242.                            
  243.                         end
  244.                     )
  245.                    
  246.                     safeCountdownThread = safeLoadingWindow:addThread():start(
  247.                         function()
  248.                             local from, message = rednet.receive("SAFE", 20);
  249.                             safeIsDone = true;
  250.                             safeLoadingWindowThread:stop();
  251.                             if message == nil or api["SafeData"] == "closing" or api["SafeData"] == "opening" then
  252.                                 safeLoadingWindowLabel:setText("Unable To Verify."):setPosition(2, 2)
  253.                             elseif api["SafeData"] == true then
  254.                                 safeLoadingWindowLabel:setText("Safe Opened Successfully!"):setPosition(2, 2)
  255.                             elseif api["SafeData"] == false then
  256.                                 safeLoadingWindowLabel:setText("Safe Closed Successfully!"):setPosition(2, 2)
  257.                             end
  258.                             local safeResponseButton = safeLoadingWindow:addButton():setText("Ok"):setPosition(11,4):setSize(6, 1):setForeground(colors.white):setBackground(colors.blue);
  259.                            
  260.                             safeResponseButton:onClick(
  261.                                 function()
  262.                                     safeResponseButton:setBackground(colors.lightGray);
  263.                                 end
  264.                             )
  265.        
  266.                             safeResponseButton:onClickUp(
  267.                                 function()
  268.                                     safeResponseButton:setBackground(colors.blue);
  269.                                     safeLoadingWindow:hide():disable()
  270.                                     safeLoadingWindow = nil;
  271.                                     locked[mainFrame] = false;
  272.                                 end
  273.                             )
  274.                         end
  275.                     )
  276.                 end    
  277.             end
  278.         end
  279.  
  280.         --Loading Animation
  281.         local elevatorButton = mainFrame:addButton():setText("Call Elevator"):setPosition(2, 17):setSize(24, 3):onClickUp(onElevatorButtonClick);
  282.         local safeButton = mainFrame:addButton():setText("Open Safe"):setPosition(2, 13):setSize(24, 3):onClickUp(onSafeButtonClick)
  283.  
  284.         parent[elevatorButton] = mainFrame;
  285.         parent[safeButton] = mainFrame;
  286.        
  287.         mainFrame:addPane():setSize(24, 10):setPosition(2,2)
  288.         mainFrame:addLabel():setText("Furnace Status: "):setPosition(3, 3):setForeground(colors.white)
  289.         local furnaceStatusLabel = mainFrame:addLabel():setText("Offline"):setPosition(18, 3):setForeground(colors.red);
  290.         mainFrame:addLabel():setText("Trade Stations: "):setPosition(3,4):setForeground(colors.white);
  291.         mainFrame:addLabel():setText("Online"):setPosition(18, 4):setForeground(colors.green);
  292.  
  293.         mainFrame:addLabel():setText("Elevator: "):setPosition(3,9):setForeground(colors.white);
  294.         local elevatorStatusLabel = mainFrame:addLabel():setText("Offline"):setPosition(13, 9):setForeground(colors.red);
  295.         mainFrame:addLabel():setText("Safe: "):setPosition(3,10):setForeground(colors.white);
  296.         local safeStatusLabel = mainFrame:addLabel():setText("Offline"):setPosition(9, 10):setForeground(colors.red);
  297.    
  298.         local function setupButtonColoring(self, event, button, x, y)
  299.             self:onClick(function()
  300.                 if locked[parent[self]] == false then
  301.                 self:setBackground(colors.blue)
  302.                 self:setForeground(colors.white)
  303.                 end
  304.             end)
  305.             self:onClickUp(function()
  306.                 self:setBackground(colors.cyan)
  307.                 self:setForeground(colors.white)
  308.             end)
  309.             self:onLoseFocus(function()
  310.                 self:setBackground(colors.cyan)
  311.                 self:setForeground(colors.white)
  312.             end)
  313.         end
  314.         --Gets All the data from each api server.
  315.         function getDataFromAPIs()
  316.             local apiProtocol = "API";
  317.  
  318.             local furnaceAddress = rednet.lookup(apiProtocol, "FurnaceSystem")
  319.             local elevatorAddress = rednet.lookup(apiProtocol, "elevator");
  320.             local safeAddress = rednet.lookup("SAFE", "safeController");
  321.             local test = 1;
  322.             while true do
  323.                 --Get Furnace Data
  324.                 local tempFurnaceData = "Offline";
  325.                 for i=0,5,1 do
  326.                     if furnaceAddress == nil then furnaceAddress = rednet.lookup(apiProtocol, "FurnaceSystem") end
  327.                     if furnaceAddress ~= nil then
  328.                         rednet.send(furnaceAddress, "getFurnaceData", apiProtocol);
  329.                         local from, message = rednet.receive(apiProtocol, 1);
  330.                         if message ~= nil then
  331.                             tempFurnaceData = message;
  332.                             break;
  333.                         end
  334.                     else
  335.                             break;
  336.                     end
  337.                 end
  338.                 api["FurnaceSystem"] = tempFurnaceData;
  339.                 --Get Elevator Data
  340.                 local tempElevatorData = "Offline";
  341.                 for i=0,5,1 do
  342.                     if elevatorAddress == nil then elevatorAddress = rednet.lookup(apiProtocol, "elevator"); end
  343.                     if elevatorAddress ~= nil then
  344.                         rednet.send(elevatorAddress, "getData", apiProtocol);
  345.                         local from, message = rednet.receive(apiProtocol);
  346.                         if message ~= nil and from == elevatorAddress then
  347.                             tempElevatorData = message;
  348.                             break;
  349.                         end
  350.                     else
  351.                         break;
  352.                     end
  353.                 end
  354.                 api["ElevatorData"] = tempElevatorData;
  355.                 --Get Safe Data
  356.                 local tempSafeData = "Offline";
  357.                
  358.                 for i=0,5,1 do
  359.                     if safeAddress == nil then safeAddress = rednet.lookup("API", "safeController"); end
  360.                     test = test + 1;
  361.                     if safeAddress ~= nil then
  362.                         rednet.send(safeAddress, "getDoorStatus", "API");
  363.                         local from, message = rednet.receive("API", 1);
  364.                         if message ~= nil and from == safeAddress then
  365.                             tempSafeData = message;
  366.                             break;
  367.                         end
  368.                     else
  369.                         break;
  370.                     end
  371.                 end
  372.                 api["SafeData"] = tempSafeData;
  373.                 sleep(0);
  374.             end
  375.         end
  376.        
  377.         function updateScreen()
  378.             while true do
  379.                 --Print Furnace System Status
  380.                 if api["FurnaceSystem"] == nil then api["FurnaceSystem"] = "Offline"; end
  381.                 if api["FurnaceSystem"] == "Offline" then
  382.                     furnaceStatusLabel:setText("Offline"):setForeground(colors.red);
  383.                 elseif api["FurnaceSystem"] == "Partially Online" then
  384.                     furnaceStatusLabel:setText("Partial"):setForeground(colors.yellow);
  385.                 elseif api["FurnaceSystem"] == "Online" then
  386.                     furnaceStatusLabel:setText("Online"):setForeground(colors.green);
  387.                 end
  388.                 --Print Elevator System Status
  389.                 if api["ElevatorData"] == nil then api["ElevatorData"] = "Offline"; end
  390.                 if api["ElevatorData"] == "Offline" then
  391.                     elevatorStatusLabel:setText("Offline"):setForeground(colors.red);
  392.                 elseif api["ElevatorData"] == "Idle" then
  393.                     elevatorStatusLabel:setText("Idle"):setForeground(colors.orange);
  394.                 elseif api["ElevatorData"] == "Lowering..." then
  395.                     elevatorStatusLabel:setText("Lowering..."):setForeground(colors.green);
  396.                 elseif api["ElevatorData"] == "Waiting..." then
  397.                     elevatorStatusLabel:setText("Waiting..."):setForeground(colors.green);
  398.                 elseif api["ElevatorData"] == "Raising..." then
  399.                     elevatorStatusLabel:setText("Raising..."):setForeground(colors.green);
  400.                 elseif api["ElevatorData"] == "Starting Up" then
  401.                     elevatorStatusLabel:setText("Starting Up"):setForeground(colors.orange);
  402.                 end
  403.  
  404.                 --Print Safe System Status
  405.                 if api["SafeData"] == "Offline" then
  406.                     safeStatusLabel:setText("Offline"):setForeground(colors.red);
  407.                 elseif api["SafeData"] == false then
  408.                     safeStatusLabel:setText("Locked"):setForeground(colors.red);
  409.                     safeButton:setText("Open Safe");
  410.                 elseif api["SafeData"] == true then
  411.                     safeStatusLabel:setText("Unlocked"):setForeground(colors.green);
  412.                     safeButton:setText("Close Safe");
  413.                 elseif api["SafeData"] == "opening" then
  414.                     safeStatusLabel:setText("Opening..."):setForeground(colors.green);
  415.                 elseif api["SafeData"] == "closing" then
  416.                     safeStatusLabel:setText("Closing..."):setForeground(colors.green);
  417.                 end
  418.                 sleep(0);
  419.             end
  420.         end
  421.  
  422.         setupButtonColoring(elevatorButton)
  423.         setupButtonColoring(safeButton)
  424.  
  425.         parallel.waitForAll(basalt.autoUpdate, getDataFromAPIs, updateScreen)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement