Advertisement
Corbinhol

Tablet OS Beta

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