Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Tablet
- screenWidth, screenHeight = term.getSize();
- local dir = "/YagPadBeta/";
- local basalt = require(dir .. "libraries/basalt") -- here you can change the variablename in any variablename you want default: basalt
- local testNumber = 1;
- local file = fs.open(dir .. "config/username.conf", "r");
- username = file.readAll();
- file.close();
- basalt.setTheme(
- { -- The default main theme for basalt!
- BasaltBG = colors.white,
- BasaltText = colors.black,
- FrameBG = colors.gray,
- FrameText = colors.black,
- ButtonBG = colors.cyan,
- ButtonText = colors.white,
- CheckboxBG = colors.gray,
- CheckboxText = colors.black,
- InputBG = colors.gray,
- InputText = colors.black,
- TextfieldBG = colors.gray,
- TextfieldText = colors.black,
- ListBG = colors.gray,
- ListText = colors.black,
- MenubarBG = colors.gray,
- MenubarText = colors.black,
- DropdownBG = colors.gray,
- DropdownText = colors.black,
- RadioBG = colors.gray,
- RadioText = colors.black,
- SelectionBG = colors.black,
- SelectionText = colors.lightGray,
- GraphicBG = colors.black,
- ImageBG = colors.black,
- PaneBG = colors.black,
- ProgramBG = colors.black,
- ProgressbarBG = colors.gray,
- ProgressbarText = colors.black,
- ProgressbarActiveBG = colors.black,
- ScrollbarBG = colors.lightGray,
- ScrollbarText = colors.gray,
- ScrollbarSymbolColor = colors.black,
- SliderBG = false,
- SliderText = colors.gray,
- SliderSymbolColor = colors.black,
- SwitchBG = colors.lightGray,
- SwitchText = colors.gray,
- SwitchBGSymbol = colors.black,
- SwitchInactive = colors.red,
- SwitchActive = colors.green,
- LabelBG = false,
- LabelText = colors.black
- }
- )
- term.clear();
- term.setCursorPos(1,1);
- local locked = {};
- local parent = {};
- local mainFrame = basalt.createFrame()
- locked[mainFrame] = false;
- rednet.open("back");
- local api = {};
- local function newMessageBox()
- local out = mainFrame:addFrame():setBackground(colors.gray):setSize(26, 5):setPosition(1, 7):setShadow(colors.black):hide()
- return out;
- end
- function showMessageBox(frame, text)
- if locked[frame] == false then
- locked[frame] = true;
- local messageBox = newMessageBox(frame);
- local messageBoxLabel = messageBox:addLabel():setText(text):setPosition(2, 2):setForeground(colors.white):setFontSize(1);
- local messageBoxButton = messageBox:addButton():setText("Ok"):setPosition(11,4):setSize(6, 1):setForeground(colors.white):setBackground(colors.blue);
- messageBox:show();
- messageBoxButton:onClick(
- function()
- messageBoxButton:setBackground(colors.lightGray);
- end
- )
- messageBoxButton:onClickUp(
- function()
- messageBoxButton:setBackground(colors.blue);
- messageBox:hide():disable()
- messageBox = nil;
- locked[frame] = false;
- end
- )
- end
- end
- function onElevatorButtonClick()
- if locked[mainFrame] == false then
- if api["ElevatorData"] == "Idle" then
- local apiProtocol = "API"
- local elevatorAddress = rednet.lookup(apiProtocol, "elevator");
- rednet.send(elevatorAddress, "lowerElevator", apiProtocol);
- locked[mainFrame] = true;
- local elevatorResponse = newMessageBox(mainFrame);
- local elevatorResponseLabel = elevatorResponse:addLabel():setText("Lowering Elevator..."):setPosition(2, 2):setForeground(colors.white):setFontSize(1);
- local elevatorResponseButton = elevatorResponse:addButton():setText("Ok"):setPosition(11,4):setSize(6, 1):setForeground(colors.white):setBackground(colors.blue);
- elevatorResponse:show();
- elevatorResponseButton:onClick(
- function()
- elevatorResponseButton:setBackground(colors.lightGray);
- end
- )
- elevatorResponseButton:onClickUp(
- function()
- elevatorResponseButton:setBackground(colors.blue);
- elevatorResponse:hide():disable()
- elevatorResponse = nil;
- locked[mainFrame] = false;
- end
- )
- end
- end
- end
- function onSafeButtonClick()
- if locked[mainFrame] == false then
- if api["SafeData"] == "Offline" or api["SafeData"] == nil then
- locked[mainFrame] = true;
- local safeResponse = newMessageBox(mainFrame);
- local safeResponseLabel = safeResponse:addLabel():setText("Unable To Connect."):setPosition(2, 2):setForeground(colors.white):setFontSize(1);
- local safeResponseButton = safeResponse:addButton():setText("Ok"):setPosition(11,4):setSize(6, 1):setForeground(colors.white):setBackground(colors.blue);
- safeResponse:show();
- safeResponseButton:onClick(
- function()
- safeResponseButton:setBackground(colors.lightGray);
- end
- )
- safeResponseButton:onClickUp(
- function()
- safeResponseButton:setBackground(colors.blue);
- safeResponse:hide():disable()
- safeResponse = nil;
- locked[mainFrame] = false;
- end
- )
- end
- if api["SafeData"] == "opening" then
- locked[mainFrame] = true;
- local safeResponse = newMessageBox(mainFrame);
- local safeResponseLabel = safeResponse:addLabel():setText("Already Opening."):setPosition(2, 2):setForeground(colors.white):setFontSize(1);
- local safeResponseButton = safeResponse:addButton():setText("Ok"):setPosition(11,4):setSize(6, 1):setForeground(colors.white):setBackground(colors.blue);
- safeResponse:show();
- safeResponseButton:onClick(
- function()
- safeResponseButton:setBackground(colors.lightGray);
- end
- )
- safeResponseButton:onClickUp(
- function()
- safeResponseButton:setBackground(colors.blue);
- safeResponse:hide():disable()
- safeResponse = nil;
- locked[mainFrame] = false;
- end
- )
- end
- if api["SafeData"] == "closing" then
- locked[mainFrame] = true;
- local safeResponse = newMessageBox(mainFrame);
- local safeResponseLabel = safeResponse:addLabel():setText("Already Closing."):setPosition(2, 2):setForeground(colors.white):setFontSize(1);
- local safeResponseButton = safeResponse:addButton():setText("Ok"):setPosition(11,4):setSize(6, 1):setForeground(colors.white):setBackground(colors.blue);
- safeResponse:show();
- safeResponseButton:onClick(
- function()
- safeResponseButton:setBackground(colors.lightGray);
- end
- )
- safeResponseButton:onClickUp(
- function()
- safeResponseButton:setBackground(colors.blue);
- safeResponse:hide():disable()
- safeResponse = nil;
- locked[mainFrame] = false;
- end
- )
- end
- if api["SafeData"] ~= "Offline" and api["SafeData"] ~= nil and api["SafeData"] ~= "opening" and api["SafeData"] ~= "closing" then
- local tempSafeData = api["SafeData"];
- locked[mainFrame] = true;
- safeProtocol = "SAFE";
- safeAddress = rednet.lookup(safeProtocol, "safeController");
- local safeLoadingWindow = newMessageBox(mainFrame);
- local safeLoadingWindowLabel = safeLoadingWindow:addLabel():setPosition(4, 3):setForeground(colors.white):setFontSize(1);
- local safeLoadingWindowLabelText;
- if api["SafeData"] == true then
- rednet.send(safeAddress, "close", safeProtocol);
- safeLoadingWindowLabelText = "Closing Safe"
- elseif api["SafeData"] == false then
- rednet.send(safeAddress, "open", safeProtocol);
- safeLoadingWindowLabelText = "Opening Safe"
- end
- safeLoadingWindowLabelAnimationStatus = false;
- safeIsDone = false;
- safeLoadingWindowLabelAnimation = safeLoadingWindow:addAnimation()
- :add(function() if safeIsDone == false then safeLoadingWindowLabel:setText(safeLoadingWindowLabelText); end end)
- :wait(.5)
- :add(function() if safeIsDone == false then safeLoadingWindowLabel:setText(safeLoadingWindowLabelText .. "."); end end)
- :wait(.5)
- :add(function() if safeIsDone == false then safeLoadingWindowLabel:setText(safeLoadingWindowLabelText .. ".."); end end)
- :wait(.5)
- :add(function() if safeIsDone == false then safeLoadingWindowLabel:setText(safeLoadingWindowLabelText .. "..."); end end)
- :wait(.8)
- :add(function() if safeIsDone == false then safeLoadingWindowLabel:setText(safeLoadingWindowLabelText .. "..."); end end)
- :onDone(function() safeLoadingWindowLabelAnimationStatus = false end)
- :play();
- safeLoadingWindow:show();
- safeLoadingWindowThread = safeLoadingWindow:addThread():start(
- function()
- while true do
- if safeLoadingWindowLabelAnimationStatus == false and safeIsDone == false then
- safeLoadingWindowLabelAnimationStatus = true;
- safeLoadingWindowLabelAnimation:play();
- end
- sleep(0);
- end
- end
- )
- safeCountdownThread = safeLoadingWindow:addThread():start(
- function()
- local from, message = rednet.receive("SAFE", 20);
- safeIsDone = true;
- safeLoadingWindowThread:stop();
- if message == nil or api["SafeData"] == "closing" or api["SafeData"] == "opening" then
- safeLoadingWindowLabel:setText("Unable To Verify."):setPosition(2, 2)
- elseif api["SafeData"] == true then
- safeLoadingWindowLabel:setText("Safe Opened Successfully!"):setPosition(2, 2)
- elseif api["SafeData"] == false then
- safeLoadingWindowLabel:setText("Safe Closed Successfully!"):setPosition(2, 2)
- end
- local safeResponseButton = safeLoadingWindow:addButton():setText("Ok"):setPosition(11,4):setSize(6, 1):setForeground(colors.white):setBackground(colors.blue);
- safeResponseButton:onClick(
- function()
- safeResponseButton:setBackground(colors.lightGray);
- end
- )
- safeResponseButton:onClickUp(
- function()
- safeResponseButton:setBackground(colors.blue);
- safeLoadingWindow:hide():disable()
- safeLoadingWindow = nil;
- locked[mainFrame] = false;
- end
- )
- end
- )
- end
- end
- end
- --Loading Animation
- local elevatorButton = mainFrame:addButton():setText("Call Elevator"):setPosition(2, 17):setSize(24, 3):onClickUp(onElevatorButtonClick);
- local safeButton = mainFrame:addButton():setText("Open Safe"):setPosition(2, 13):setSize(24, 3):onClickUp(onSafeButtonClick)
- parent[elevatorButton] = mainFrame;
- parent[safeButton] = mainFrame;
- mainFrame:addLabel():setPosition(1,1):setText(username):setForeground(colors.gray)
- mainFrame:addPane():setSize(24, 10):setPosition(2,2)
- mainFrame:addLabel():setText("Furnace Status: "):setPosition(3, 3):setForeground(colors.white)
- local furnaceStatusLabel = mainFrame:addLabel():setText("Offline"):setPosition(18, 3):setForeground(colors.red);
- mainFrame:addLabel():setText("Trade Stations: "):setPosition(3,4):setForeground(colors.white);
- mainFrame:addLabel():setText("Online"):setPosition(18, 4):setForeground(colors.green);
- mainFrame:addLabel():setText("Elevator: "):setPosition(3,9):setForeground(colors.white);
- local elevatorStatusLabel = mainFrame:addLabel():setText("Offline"):setPosition(13, 9):setForeground(colors.red);
- mainFrame:addLabel():setText("Safe: "):setPosition(3,10):setForeground(colors.white);
- local safeStatusLabel = mainFrame:addLabel():setText("Offline"):setPosition(9, 10):setForeground(colors.red);
- local tab = mainFrame:addButton():setSize(1, 5):setPosition(screenWidth - 1):setForeground(colors.blue);
- local function setupButtonColoring(self, event, button, x, y)
- self:onClick(function()
- if locked[parent[self]] == false then
- self:setBackground(colors.blue)
- self:setForeground(colors.white)
- end
- end)
- self:onClickUp(function()
- self:setBackground(colors.cyan)
- self:setForeground(colors.white)
- end)
- self:onLoseFocus(function()
- self:setBackground(colors.cyan)
- self:setForeground(colors.white)
- end)
- end
- --Gets All the data from each api server.
- function getDataFromAPIs()
- local apiProtocol = "API";
- local furnaceAddress = rednet.lookup(apiProtocol, "FurnaceSystem")
- local elevatorAddress = rednet.lookup(apiProtocol, "elevator");
- local safeAddress = rednet.lookup("SAFE", "safeController");
- local test = 1;
- while true do
- --Get Furnace Data
- local tempFurnaceData = "Offline";
- for i=0,5,1 do
- if furnaceAddress == nil then furnaceAddress = rednet.lookup(apiProtocol, "FurnaceSystem") end
- if furnaceAddress ~= nil then
- rednet.send(furnaceAddress, "getFurnaceData", apiProtocol);
- local from, message = rednet.receive(apiProtocol, 1);
- if message ~= nil then
- tempFurnaceData = message;
- break;
- end
- else
- break;
- end
- end
- api["FurnaceSystem"] = tempFurnaceData;
- --Get Elevator Data
- local tempElevatorData = "Offline";
- for i=0,5,1 do
- if elevatorAddress == nil then elevatorAddress = rednet.lookup(apiProtocol, "elevator"); end
- if elevatorAddress ~= nil then
- rednet.send(elevatorAddress, "getData", apiProtocol);
- local from, message = rednet.receive(apiProtocol);
- if message ~= nil and from == elevatorAddress then
- tempElevatorData = message;
- break;
- end
- else
- break;
- end
- end
- api["ElevatorData"] = tempElevatorData;
- --Get Safe Data
- local tempSafeData = "Offline";
- for i=0,5,1 do
- if safeAddress == nil then safeAddress = rednet.lookup("API", "safeController"); end
- test = test + 1;
- if safeAddress ~= nil then
- rednet.send(safeAddress, "getDoorStatus", "API");
- local from, message = rednet.receive("API", 1);
- if message ~= nil and from == safeAddress then
- tempSafeData = message;
- break;
- end
- else
- break;
- end
- end
- api["SafeData"] = tempSafeData;
- sleep(0);
- end
- end
- function updateScreen()
- while true do
- --Print Furnace System Status
- if api["FurnaceSystem"] == nil then api["FurnaceSystem"] = "Offline"; end
- if api["FurnaceSystem"] == "Offline" then
- furnaceStatusLabel:setText("Offline"):setForeground(colors.red);
- elseif api["FurnaceSystem"] == "Partially Online" then
- furnaceStatusLabel:setText("Partial"):setForeground(colors.yellow);
- elseif api["FurnaceSystem"] == "Online" then
- furnaceStatusLabel:setText("Online"):setForeground(colors.green);
- end
- --Print Elevator System Status
- if api["ElevatorData"] == nil then api["ElevatorData"] = "Offline"; end
- if api["ElevatorData"] == "Offline" then
- elevatorStatusLabel:setText("Offline"):setForeground(colors.red);
- elseif api["ElevatorData"] == "Idle" then
- elevatorStatusLabel:setText("Idle"):setForeground(colors.orange);
- elseif api["ElevatorData"] == "Lowering..." then
- elevatorStatusLabel:setText("Lowering..."):setForeground(colors.green);
- elseif api["ElevatorData"] == "Waiting..." then
- elevatorStatusLabel:setText("Waiting..."):setForeground(colors.green);
- elseif api["ElevatorData"] == "Raising..." then
- elevatorStatusLabel:setText("Raising..."):setForeground(colors.green);
- elseif api["ElevatorData"] == "Starting Up" then
- elevatorStatusLabel:setText("Starting Up"):setForeground(colors.orange);
- end
- --Print Safe System Status
- if api["SafeData"] == "Offline" then
- safeStatusLabel:setText("Offline"):setForeground(colors.red);
- elseif api["SafeData"] == false then
- safeStatusLabel:setText("Locked"):setForeground(colors.red);
- safeButton:setText("Open Safe");
- elseif api["SafeData"] == true then
- safeStatusLabel:setText("Unlocked"):setForeground(colors.green);
- safeButton:setText("Close Safe");
- elseif api["SafeData"] == "opening" then
- safeStatusLabel:setText("Opening..."):setForeground(colors.green);
- elseif api["SafeData"] == "closing" then
- safeStatusLabel:setText("Closing..."):setForeground(colors.green);
- end
- sleep(0);
- end
- end
- setupButtonColoring(elevatorButton)
- setupButtonColoring(safeButton)
- parallel.waitForAll(basalt.autoUpdate, getDataFromAPIs, updateScreen)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement