Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local colorList = {
- [0] = "white",
- [1] = "orange",
- [2] = "magenta",
- [3] = "lightBlue",
- [4] = "yellow",
- [5] = "lime",
- [6] = "pink",
- [7] = "gray",
- [8] = "lightGray",
- [9] = "cyan",
- [10] = "purple",
- [11] = "blue",
- [12] = "brown",
- [13] = "green",
- [14] = "red",
- [15] = "black"
- }
- local colorIndexTable = {
- [0] = colors.white,
- [1] = colors.orange,
- [2] = colors.magenta,
- [3] = colors.lightBlue,
- [4] = colors.yellow,
- [5] = colors.lime,
- [6] = colors.pink,
- [7] = colors.gray,
- [8] = colors.lightGray,
- [9] = colors.cyan,
- [10] = colors.purple,
- [11] = colors.blue,
- [12] = colors.brown,
- [13] = colors.green,
- [14] = colors.red,
- [15] = colors.black
- }
- local indexColorTable = {
- [colors.white] = 0,
- [colors.orange] = 1,
- [colors.magenta] = 2,
- [colors.lightBlue] = 3,
- [colors.yellow] = 4,
- [colors.lime] = 5,
- [colors.pink] = 6,
- [colors.gray] = 7,
- [colors.lightGray] = 8,
- [colors.cyan] = 9,
- [colors.purple] = 10,
- [colors.blue] = 11,
- [colors.brown] = 12,
- [colors.green] = 13,
- [colors.red] = 14,
- [colors.black] = 15
- }
- local colorToNameTable = {
- [colors.white] = "white",
- [colors.orange] = "orange",
- [colors.magenta] = "magenta",
- [colors.lightBlue] = "lightBlue",
- [colors.yellow] = "yellow",
- [colors.lime] = "lime",
- [colors.pink] = "pink",
- [colors.gray] = "gray",
- [colors.lightGray] = "lightGray",
- [colors.cyan] = "cyan",
- [colors.purple] = "purple",
- [colors.blue] = "blue",
- [colors.brown] = "brown",
- [colors.green] = "green",
- [colors.red] = "red",
- [colors.black] = "black"
- }
- local nameToColorTable = {
- ["white"] = colors.white,
- ["orange"] = colors.orange,
- ["magenta"] = colors.magenta,
- ["lightBlue"] = colors.lightBlue,
- ["yellow"] = colors.yellow,
- ["lime"] = colors.lime,
- ["pink"] = colors.pink,
- ["gray"] = colors.gray,
- ["lightGray"] = colors.lightGray,
- ["cyan"] = colors.cyan,
- ["purple"] = colors.purple,
- ["blue"] = colors.blue,
- ["brown"] = colors.brown,
- ["green"] = colors.green,
- ["red"] = colors.red,
- ["black"] = colors.black
- }
- local hostConfig = {
- ["id"] = nil,
- ["elevatorID"] = nil,
- ["elevatorName"] = "",
- ["rsBcInputSide"] = nil,
- ["rsBcOutputSide"] = nil,
- ["theme"] = {
- ["displayBackground"] = colors.black,
- ["displayForeground"] = colors.white,
- ["frameBackground"] = colors.lightGray,
- ["frameForeground"] = colors.black,
- ["frameBorder"] = colors.gray,
- ["buttonBackground"] = colors.gray,
- ["buttonForeground"] = colors.white,
- ["buttonBorder"] = colors.lightGray
- },
- }
- local floors = {
- [0] = {},
- [1] = {},
- [2] = {},
- [3] = {},
- [4] = {},
- [5] = {},
- [6] = {},
- [7] = {},
- [8] = {},
- [9] = {},
- [10] = {},
- [11] = {},
- [12] = {},
- [13] = {},
- [14] = {},
- [15] = {}
- }
- local basalt = require("basalt")
- rednet.open("top")
- local protocol = ""
- local main = basalt.createFrame()
- local mainFrame = main:addFrame()
- mainFrame:setSize("parent.w","parent.h")
- mainFrame:setBackground(hostConfig.theme.displayBackground)
- local mainThread = main:addThread()
- local secondThread = main:addThread()
- local thirdThread = main:addThread()
- local scrollAbleFrame = nil
- local settingsFrame = nil
- local sidebar = nil
- local function getNewFloorTemplate()
- local newFloor = {
- ["name"] = nil,
- ["id"] = nil,
- ["elevatorID"] = nil,
- ["elevatorName"] = "",
- ["isElevatorOnFloor"] = false,
- ["isFloorCalled"] = false,
- ["state"] = false,
- ["theme"] = {
- ["displayBackground"] = colors.lightGray,
- ["displayForeground"] = colors.black,
- ["frameBackground"] = colors.gray,
- ["frameForeground"] = colors.black,
- ["buttonBackground"] = colors.lightGray,
- ["buttonForeground"] = colors.black,
- ["buttonBorder"] = colors.black
- },
- ["basaltConfigFrame"] = nil,
- ["basaltConfigSideBarButton"] = nil
- }
- return newFloor
- end
- -- Load config if present
- local function SaveConfig()
- local hConfig = {
- ["id"] = hostConfig.id,
- ["elevatorID"] = hostConfig.elevatorID,
- ["elevatorName"] = hostConfig.elevatorName,
- ["rsBcInputSide"] = hostConfig.rsBcInputSide,
- ["rsBcOutputSide"] = hostConfig.rsBcOutputSide,
- ["theme"] = {
- ["displayBackground"] = hostConfig.theme.displayBackground,
- ["displayForeground"] = hostConfig.theme.displayForeground,
- ["frameBackground"] = hostConfig.theme.frameBackground,
- ["frameForeground"] = hostConfig.theme.frameForeground,
- ["frameBorder"] = hostConfig.theme.frameBorder,
- ["buttonBackground"] = hostConfig.theme.buttonBackground,
- ["buttonForeground"] = hostConfig.theme.buttonForeground,
- ["buttonBorder"] = hostConfig.theme.buttonBorder
- },
- }
- local fConfigs = {
- [0] = getNewFloorTemplate(),
- [1] = getNewFloorTemplate(),
- [2] = getNewFloorTemplate(),
- [3] = getNewFloorTemplate(),
- [4] = getNewFloorTemplate(),
- [5] = getNewFloorTemplate(),
- [6] = getNewFloorTemplate(),
- [7] = getNewFloorTemplate(),
- [8] = getNewFloorTemplate(),
- [9] = getNewFloorTemplate(),
- [10] = getNewFloorTemplate(),
- [11] = getNewFloorTemplate(),
- [12] = getNewFloorTemplate(),
- [13] = getNewFloorTemplate(),
- [14] = getNewFloorTemplate(),
- [15] = getNewFloorTemplate()
- }
- for index, floor in pairs(floors) do
- fConfigs[index].name = floors[index].name
- fConfigs[index].id = floors[index].id
- fConfigs[index].elevatorID = floors[index].elevatorID
- fConfigs[index].elevatorName = floors[index].elevatorName
- fConfigs[index].state = floors[index].state
- fConfigs[index].isElevatorOnFloor = floors[index].isElevatorOnFloor
- fConfigs[index].isFloorCalled = floors[index].isFloorCalled
- fConfigs[index].theme.displayBackground = floors[index].theme.displayBackground
- fConfigs[index].theme.displayForeground = floors[index].theme.displayForeground
- fConfigs[index].theme.frameBackground = floors[index].theme.frameBackground
- fConfigs[index].theme.frameForeground = floors[index].theme.frameForeground
- fConfigs[index].theme.buttonBackground = floors[index].theme.buttonBackground
- fConfigs[index].theme.buttonForeground = floors[index].theme.buttonForeground
- fConfigs[index].theme.buttonBorder = floors[index].theme.buttonBorder
- end
- local file = fs.open("elevatorHostConfig.txt", "w")
- local serConfig = textutils.serialise({ hConfig, fConfigs})
- file.write(serConfig)
- file.close()
- hConfig = nil
- fConfigs = nil
- end
- local function LoadConfig()
- local file = fs.open("elevatorHostConfig.txt", "r")
- if type(file) == "table" then
- local serFile = file.readAll()
- hostConfig = textutils.unserialise(serFile)[1]
- floors[0] = textutils.unserialise(serFile)[2][0]
- floors[1] = textutils.unserialise(serFile)[2][1]
- floors[2] = textutils.unserialise(serFile)[2][2]
- floors[3] = textutils.unserialise(serFile)[2][3]
- floors[4] = textutils.unserialise(serFile)[2][4]
- floors[5] = textutils.unserialise(serFile)[2][5]
- floors[6] = textutils.unserialise(serFile)[2][6]
- floors[7] = textutils.unserialise(serFile)[2][7]
- floors[8] = textutils.unserialise(serFile)[2][8]
- floors[9] = textutils.unserialise(serFile)[2][9]
- floors[10] = textutils.unserialise(serFile)[2][10]
- floors[11] = textutils.unserialise(serFile)[2][11]
- floors[12] = textutils.unserialise(serFile)[2][12]
- floors[13] = textutils.unserialise(serFile)[2][13]
- floors[14] = textutils.unserialise(serFile)[2][14]
- floors[15] = textutils.unserialise(serFile)[2][15]
- end
- if file ~= nil then
- file.close()
- end
- end
- if fs.exists("elevatorHostConfig.txt") == true then
- LoadConfig()
- else
- for index, floor in pairs(floors) do
- floors[index] = getNewFloorTemplate()
- floors[index].id = index
- end
- end
- local function CreateFloorFrameAndButton(index)
- local floor = getNewFloorTemplate()
- local frame = mainFrame:addFrame()
- floors[index].basaltConfigFrame = frame
- frame:setPosition(1,1)
- frame:setBackground(hostConfig.theme.displayBackground)
- frame:setSize("parent.w - 1", "parent.h - 1")
- frame:hide()
- local header = frame:addLabel()
- header:setPosition(2,2)
- header:setSize("parent.w - 2", 5)
- header:setForeground(hostConfig.theme.displayForeground)
- header:setTextAlign("center")
- header:setText("Floor No" .. tostring(floors[index].id))
- --add button to scrollAbleFrame and add function for show and hide frame
- local leftFrame = frame:addFrame()
- leftFrame:setSize("parent.w / 2", "parent.h -11")
- leftFrame:setPosition(1,7)
- leftFrame:setBackground(hostConfig.theme.frameBackground)
- leftFrame:setBorder(hostConfig.theme.frameBorder)
- local rightFrame = frame:addFrame()
- rightFrame:setSize("parent.w / 2", "parent.h -11")
- rightFrame:setPosition("parent.w / 2", 7)
- leftFrame:setBackground(floors[index].theme.displayBackground)
- rightFrame:setBorder(hostConfig.theme.frameBorder)
- local previewFrame = rightFrame:addFrame()
- previewFrame:setSize("(parent.w / 2) - 2", "parent.h")
- previewFrame:setPosition("(parent.w / 2) - (self.w /2), 1")
- local previewButton = previewFrame:addButton()
- previewButton:setSize("parent.w - 2", 5)
- previewButton:setPosition(2,"(parent.h /2) - (self.h /2)")
- previewButton:setText(tostring(floors[index].name))
- previewButton:setForeground(floors[index].theme.buttonForeground)
- previewButton:setBackground(floors[index].theme.buttonBackground)
- previewButton:setBorder(floors[index].theme.buttonBorder)
- local floorNameLabel = leftFrame:addLabel()
- floorNameLabel:setSize("(parent.w / 2) - 2",1)
- floorNameLabel:setPosition(2, 6)
- floorNameLabel:setForeground(hostConfig.theme.frameForeground)
- floorNameLabel:setText("Floor Name : ")
- local floorNameInput = leftFrame:addInput()
- floorNameInput:setSize("(parent.w / 2) - 10",1)
- floorNameInput:setPosition("(parent.w /2) + 5", 6)
- floorNameInput:setForeground(hostConfig.theme.frameForeground)
- floorNameInput:setBackground(colors.lightGray)
- floorNameInput:setValue(tostring(floors[index].name))
- floorNameInput:onChange(function(self, event, char)
- previewButton:setText(tostring(floorNameInput:getValue()))
- end)
- local themeDisplayForegroundLabel = leftFrame:addLabel()
- themeDisplayForegroundLabel:setSize("(parent.w / 2) - 2",1)
- themeDisplayForegroundLabel:setPosition(2, 8)
- themeDisplayForegroundLabel:setForeground(hostConfig.theme.frameForeground)
- themeDisplayForegroundLabel:setText("Display Text Color : ")
- local themeDisplayFgDropDown = leftFrame:addDropdown()
- themeDisplayFgDropDown:setPosition("(parent.w / 2) + 5",8)
- themeDisplayFgDropDown:setDropdownSize(12, 5)
- for i = 0, 15 do
- themeDisplayFgDropDown:addItem(tostring(colorList[i]))
- if floors[index].theme.displayForeground == colorIndexTable[i] then
- themeDisplayFgDropDown:selectItem(i+1)
- rightFrame:setForeground(floors[index].theme.displayForeground)
- end
- end
- themeDisplayFgDropDown:onChange(function(self, event, item)
- rightFrame:setForeground(nameToColorTable[item.text])
- floor.theme.displayForeground = nameToColorTable[item.text]
- end)
- local themeDisplayBackgroundLabel = leftFrame:addLabel()
- themeDisplayBackgroundLabel:setSize("(parent.w / 2) - 2",1)
- themeDisplayBackgroundLabel:setPosition(2, 10)
- themeDisplayBackgroundLabel:setForeground(hostConfig.theme.frameForeground)
- themeDisplayBackgroundLabel:setText("Display Background Color : ")
- local themeDisplayBgDropDown = leftFrame:addDropdown()
- themeDisplayBgDropDown:setPosition("(parent.w / 2) + 5",10)
- themeDisplayBgDropDown:setDropdownSize(12, 5)
- for i = 0, 15 do
- themeDisplayBgDropDown:addItem(tostring(colorList[i]))
- if floors[index].theme.displayBackground == colorIndexTable[i] then
- themeDisplayBgDropDown:selectItem(i+1)
- rightFrame:setBackground(floors[index].theme.displayBackground)
- end
- end
- themeDisplayBgDropDown:onChange(function(self, event, item)
- rightFrame:setBackground(nameToColorTable[item.text])
- floor.theme.displayBackground = nameToColorTable[item.text]
- end)
- local themeFrameForegroundLabel = leftFrame:addLabel()
- themeFrameForegroundLabel:setSize("(parent.w / 2) - 2",1)
- themeFrameForegroundLabel:setPosition(2, 12)
- themeFrameForegroundLabel:setForeground(hostConfig.theme.frameForeground)
- themeFrameForegroundLabel:setText("Frame Text Color : ")
- local themeFrameFgDropDown = leftFrame:addDropdown()
- themeFrameFgDropDown:setPosition("(parent.w / 2) + 5",12)
- themeFrameFgDropDown:setDropdownSize(12, 5)
- for i = 0, 15 do
- themeFrameFgDropDown:addItem(tostring(colorList[i]))
- if floors[index].theme.frameForeground == colorIndexTable[i] then
- themeFrameFgDropDown:selectItem(i+1)
- previewFrame:setForeground(floors[index].theme.frameForeground)
- end
- end
- themeFrameFgDropDown:onChange(function(self, event, item)
- previewFrame:setForeground(nameToColorTable[item.text])
- floor.theme.frameForeground = nameToColorTable[item.text]
- end)
- local themeFrameBackgroundLabel = leftFrame:addLabel()
- themeFrameBackgroundLabel:setSize("(parent.w / 2) - 2",1)
- themeFrameBackgroundLabel:setPosition(2, 14)
- themeFrameBackgroundLabel:setForeground(hostConfig.theme.frameForeground)
- themeFrameBackgroundLabel:setText("Frame Background Color : ")
- local themeFrameBgDropDown = leftFrame:addDropdown()
- themeFrameBgDropDown:setPosition("(parent.w / 2) + 5", 14)
- themeFrameBgDropDown:setDropdownSize(12, 5)
- for i = 0, 15 do
- themeFrameBgDropDown:addItem(tostring(colorList[i]))
- if floors[index].theme.frameBackground == colorIndexTable[i] then
- themeFrameBgDropDown:selectItem(i+1)
- previewFrame:setBackground(floors[index].theme.frameBackground)
- end
- end
- themeFrameBgDropDown:onChange(function(self, event, item)
- previewFrame:setBackground(nameToColorTable[item.text])
- floor.theme.frameBackground = nameToColorTable[item.text]
- end)
- local themeButtonForegroundLabel = leftFrame:addLabel()
- themeButtonForegroundLabel:setSize("(parent.w / 2) - 2",1)
- themeButtonForegroundLabel:setPosition(2, 16)
- themeButtonForegroundLabel:setForeground(hostConfig.theme.frameForeground)
- themeButtonForegroundLabel:setText("Button Text Color : ")
- local themeButtonFgDropDown = leftFrame:addDropdown()
- themeButtonFgDropDown:setPosition("(parent.w / 2) + 5",16)
- themeButtonFgDropDown:setDropdownSize(12, 5)
- for i = 0, 15 do
- themeButtonFgDropDown:addItem(tostring(colorList[i]))
- if floors[index].theme.buttonForeground == colorIndexTable[i] then
- themeButtonFgDropDown:selectItem(i+1)
- previewButton:setForeground(floors[index].theme.buttonForeground)
- end
- end
- themeButtonFgDropDown:onChange(function(self, event, item)
- previewButton:setForeground(nameToColorTable[item.text])
- floor.theme.buttonForeground = nameToColorTable[item.text]
- end)
- local themeButtonBackgroundLabel = leftFrame:addLabel()
- themeButtonBackgroundLabel:setSize("(parent.w / 2) - 2",1)
- themeButtonBackgroundLabel:setPosition(2, 18)
- themeButtonBackgroundLabel:setForeground(hostConfig.theme.frameForeground)
- themeButtonBackgroundLabel:setText("Button Background Color : ")
- local themeButtonBgDropDown = leftFrame:addDropdown()
- themeButtonBgDropDown:setPosition("(parent.w / 2) + 5", 18)
- themeButtonBgDropDown:setDropdownSize(12, 5)
- for i = 0, 15 do
- themeButtonBgDropDown:addItem(tostring(colorList[i]))
- if floors[index].theme.buttonBackground == colorIndexTable[i] then
- themeButtonBgDropDown:selectItem(i+1)
- previewButton:setBackground(floors[index].theme.buttonBackground)
- end
- end
- themeButtonBgDropDown:onChange(function(self, event, item)
- previewButton:setBackground(nameToColorTable[item.text])
- floor.theme.buttonBackground = nameToColorTable[item.text]
- end)
- local themeButtonBorderLabel = leftFrame:addLabel()
- themeButtonBorderLabel:setSize("(parent.w / 2) - 2",1)
- themeButtonBorderLabel:setPosition(2, 20)
- themeButtonBorderLabel:setForeground(hostConfig.theme.frameForeground)
- themeButtonBorderLabel:setText("Button Border Color : ")
- local themeButtonBorderDropDown = leftFrame:addDropdown()
- themeButtonBorderDropDown:setPosition("(parent.w / 2) + 5", 20)
- themeButtonBorderDropDown:setDropdownSize(12, 5)
- for i = 0, 15 do
- themeButtonBorderDropDown:addItem(tostring(colorList[i]))
- if floors[index].theme.buttonBorder == colorIndexTable[i] then
- themeButtonBorderDropDown:selectItem(i+1)
- previewButton:setBorder(floors[index].theme.buttonBorder)
- end
- end
- themeButtonBorderDropDown:onChange(function(self, event, item)
- previewButton:setBorder(nameToColorTable[item.text])
- floor.theme.buttonBorder = nameToColorTable[item.text]
- end)
- local saveButton = frame:addButton()
- saveButton:setSize(10,3)
- saveButton:setPosition("parent.w - 11", "parent.h - 2")
- saveButton:setText("Save")
- saveButton:onClick(function(self,event,button,x,y)
- if(event=="mouse_click")and(button==1)then
- if floorNameInput.getValue() ~= "" then
- floors[index].name = tostring(floorNameInput.getValue())
- floors[index].elevatorID = hostConfig.elevatorID
- floors[index].theme.displayBackground = floor.theme.displayBackground
- floors[index].theme.displayForeground = floor.theme.displayForeground
- floors[index].theme.frameBackground = floor.theme.frameBackground
- floors[index].theme.frameBackground = floor.theme.frameBackground
- floors[index].theme.buttonBackground = floor.theme.buttonBackground
- floors[index].theme.buttonForeground = floor.theme.buttonForeground
- floors[index].theme.buttonBorder = floor.theme.buttonBorder
- SaveConfig()
- else
- basalt.debug("[Error] : Please fill out all fields !!!")
- end
- end
- end)
- --SidebarButton
- if scrollAbleFrame ~= nil then
- local sideBarButton = scrollAbleFrame:addButton()
- floors[index].basaltConfigSideBarButton = sideBarButton
- sideBarButton:setSize("parent.w - 2", 3)
- sideBarButton:setText("Floor No" .. tostring(floors[index].id))
- if floors[index].id == 0 then
- sideBarButton:setPosition(2, 2)
- else
- sideBarButton:setPosition(2, (floors[index].id * 4) + 2)
- end
- if floors[index].state == true then
- sideBarButton:show()
- else
- sideBarButton:hide()
- end
- sideBarButton:onClick(function(self,event,button,x,y)
- if(event=="mouse_click")and(button==1)then
- local isVisible = floors[index].basaltConfigFrame:isVisible()
- for indexLoop, floorLoop in pairs(floors) do
- if floors[indexLoop].basaltConfigFrame ~= nil then
- floors[indexLoop].basaltConfigFrame:hide()
- end
- end
- if isVisible == false then
- floors[index].basaltConfigFrame:show()
- end
- if settingsFrame ~= nil then
- if settingsFrame:isVisible() == true then settingsFrame:hide() end
- end
- end
- end)
- end
- end
- local function ReadRednet()
- local counter = 0
- while true do
- local id, message = rednet.receive(protocol, 5)
- if message ~= nil then
- local channel = message[1]
- local data = message[2]
- if channel == "CallFloor" then
- data = tonumber(data)
- rs.setBundledOutput(hostConfig.rsBcOutputSide, colorIndexTable[data])
- os.sleep(0.2)
- rs.setBundledOutput(hostConfig.rsBcOutputSide, 0)
- floors[data].isFloorCalled = true
- rednet.broadcast({"FloorUpdate", floors}, protocol)
- --basalt.debug("[Rednet]: FloorUpdate at " .. tostring(os.time()))
- counter = 0
- end
- else
- if counter == 6 then
- rednet.broadcast({"FloorUpdate", floors}, protocol)
- --basalt.debug("[Rednet]: FloorUpdate at " .. tostring(os.time()))
- counter = 0
- else
- counter = counter + 1
- end
- end
- end
- end
- local function ReadRedstone()
- while true do
- os.pullEvent("redstone") -- Wait for a change to inputs.
- local bundledInput = rs.getBundledInput(hostConfig.rsBcInputSide)
- if bundledInput ~= 0 then
- local elevatorPos = indexColorTable[bundledInput]
- floors[elevatorPos].isElevatorOnFloor = true
- floors[elevatorPos].isFloorCalled = false
- rednet.broadcast({"FloorUpdate", floors}, protocol)
- --basalt.debug("[Rednet]: FloorUpdate at " .. tostring(os.time()))
- end
- end
- end
- local function startHost()
- --MainFrame
- local headerHostMain = mainFrame:addLabel()
- headerHostMain:setPosition("parent.w /2 - 32",2)
- headerHostMain:setText(("Elevator %d Controlboard"):format(hostConfig.elevatorID))
- headerHostMain:setForeground(hostConfig.theme.displayForeground)
- headerHostMain:setFontSize(2)
- headerHostMain:setTextAlign("center")
- sidebar = mainFrame:addFrame()
- --sidebar:setDirection("vertical")
- sidebar:setBackground(hostConfig.theme.frameBackground)
- sidebar:setPosition("parent.w", 1)
- sidebar:setSize(15, "parent.h")
- sidebar:setZIndex(25)
- sidebar:onGetFocus(function(self)
- self:setPosition("parent.w - (self.w-1)")
- end)
- sidebar:onLoseFocus(function(self)
- self:setPosition("parent.w")
- end)
- local settingsButton = sidebar:addButton()
- settingsButton:setPosition(2,2)
- settingsButton:setSize("parent.w - 2",3)
- settingsButton:setBackground(hostConfig.theme.buttonBackground)
- settingsButton:setForeground(hostConfig.theme.buttonForeground)
- settingsButton:setBorder(hostConfig.theme.buttonBorder)
- settingsButton:setText("Settings")
- settingsButton:onClick(function()
- if settingsFrame ~= nil then
- if settingsFrame:isVisible() == true then
- settingsFrame:hide()
- else
- settingsFrame:show()
- end
- end
- end)
- local line = sidebar:addPane()
- line:setSize("parent.w - 4", 1)
- line:setPosition(3, 6)
- line:setBackground(false, "\140", hostConfig.theme.buttonBorder)
- scrollAbleFrame = sidebar:addScrollableFrame()
- scrollAbleFrame:setDirection("vertical")
- scrollAbleFrame:setBackground(hostConfig.theme.frameBackground)
- scrollAbleFrame:setPosition(1, 7)
- scrollAbleFrame:setSize("parent.w", "parent.h - 7")
- for index, floor in pairs(floors) do
- --basalt.debug(floor.id)
- CreateFloorFrameAndButton(index)
- end
- --SettingsFrame
- settingsFrame = mainFrame:addFrame()
- settingsFrame:setPosition(1,1)
- settingsFrame:setBackground(hostConfig.theme.frameBackground)
- settingsFrame:setSize("parent.w - 1", "parent.h -1")
- settingsFrame:hide()
- local headerSettings = settingsFrame:addLabel()
- headerSettings:setPosition("parent.w / 2 - 32",2)
- headerSettings:setText(("Elevator %d Settings"):format(hostConfig.elevatorID))
- headerSettings:setForeground(hostConfig.theme.frameForeground)
- headerSettings:setFontSize(2)
- headerSettings:setTextAlign("center")
- local rowCounter = 0
- local rowY = 10
- for index, floor in pairs(floors) do
- if rowCounter == 8 then
- rowCounter = 0
- rowY = 12
- end
- local floorLabel = settingsFrame:addLabel()
- floorLabel:setPosition(4 + (rowCounter * 12), rowY)
- floorLabel:setText("Floor "..tostring(index))
- floorLabel:setForeground(hostConfig.theme.frameForeground)
- local floorCheckbox = settingsFrame:addCheckbox()
- floorCheckbox:setPosition(13 + (rowCounter * 12), rowY)
- floorCheckbox:setBackground(hostConfig.theme.buttonBackground)
- floorCheckbox:setForeground(hostConfig.theme.buttonForeground)
- floorCheckbox:setValue(floors[index].state)
- floorCheckbox:onChange(function(self)
- floors[index].state = self:getValue()
- end)
- rowCounter = rowCounter + 1
- end
- local leftFrame = settingsFrame:addFrame()
- leftFrame:setSize("parent.w / 2", "parent.h -20")
- leftFrame:setPosition(1,15)
- local rightFrame = settingsFrame:addFrame()
- rightFrame:setSize("parent.w / 2", "parent.h -20")
- rightFrame:setPosition("parent.w / 2", 15)
- local elevatorIDLabel = leftFrame:addLabel()
- elevatorIDLabel:setSize("(parent.w / 2) - 2",1)
- elevatorIDLabel:setPosition(2, 2)
- elevatorIDLabel:setForeground(hostConfig.theme.frameForeground)
- elevatorIDLabel:setText("Elevator ID : ")
- local elevatorIDInput = leftFrame:addInput()
- elevatorIDInput:setSize("(parent.w / 2) - 2",1)
- elevatorIDInput:setPosition("(parent.w / 2) - 2", 2)
- elevatorIDInput:setForeground(hostConfig.theme.frameForeground)
- elevatorIDInput:setBackground(colors.lightGray)
- elevatorIDInput:setValue(tonumber(hostConfig.elevatorID))
- local elevatorNameLabel = leftFrame:addLabel()
- elevatorNameLabel:setSize("(parent.w / 2) - 2",1)
- elevatorNameLabel:setPosition(2, 4)
- elevatorNameLabel:setForeground(hostConfig.theme.frameForeground)
- elevatorNameLabel:setText("Elevator ID : ")
- local elevatorNameInput = leftFrame:addInput()
- elevatorNameInput:setSize("(parent.w / 2) - 2",1)
- elevatorNameInput:setPosition("(parent.w / 2) - 2", 4)
- elevatorNameInput:setForeground(hostConfig.theme.frameForeground)
- elevatorNameInput:setBackground(colors.lightGray)
- elevatorNameInput:setValue(tostring(hostConfig.elevatorName))
- local saveButton = settingsFrame:addButton()
- saveButton:setSize(10,3)
- saveButton:setPosition("parent.w - 11", "parent.h - 4")
- saveButton:setText("Save")
- saveButton:onClick(function(self,event,button,x,y)
- if(event=="mouse_click")and(button==1)then
- if elevatorIDInput:getValue() ~= "" or elevatorNameInput:getValue() ~= "" then
- hostConfig.elevatorID = elevatorIDInput:getValue()
- hostConfig.elevatorName = elevatorNameInput:getValue()
- for index, floor in pairs(floors) do
- floors[index].elevatorName = elevatorNameInput:getValue()
- if floors[index].state == true then
- floors[index].basaltConfigSideBarButton:show()
- else
- floors[index].basaltConfigSideBarButton:hide()
- end
- end
- basalt.debug(hostConfig.elevatorName)
- SaveConfig()
- else
- basalt.debug("[Error] : ElevatorID cant be empty !!!")
- end
- end
- end)
- mainThread:start(ReadRednet)
- secondThread:start(ReadRedstone)
- end
- local function eleInit()
- if fs.exists("elevatorHostConfig.txt") == false then
- local headerLabel = mainFrame:addLabel()
- headerLabel:setPosition("parent.w /2 - 32",3)
- headerLabel:setText("Elevator Initialization")
- headerLabel:setFontSize(2)
- headerLabel:setTextAlign("center")
- local eleNumberLabel = mainFrame:addLabel()
- eleNumberLabel:setPosition(2,7)
- eleNumberLabel:setText("Elevator ID: ")
- eleNumberLabel:setForeground(hostConfig.theme.displayForeground)
- eleNumberLabel:setBackground(hostConfig.theme.displayBackground)
- local eleNumberInput = mainFrame:addInput()
- eleNumberInput:setPosition(15,7)
- eleNumberInput:setInputType("number")
- eleNumberInput:setForeground(hostConfig.theme.frameForeground)
- eleNumberInput:setBackground(hostConfig.theme.frameBackground)
- local eleRsInputLabel = mainFrame:addLabel()
- eleRsInputLabel:setPosition(2,9)
- eleRsInputLabel:setText("Redstone Bundled Cable Input Side ")
- eleRsInputLabel:setForeground(hostConfig.theme.displayForeground)
- eleRsInputLabel:setBackground(hostConfig.theme.displayBackground)
- local eleRsInputDropDown = mainFrame:addDropdown()
- eleRsInputDropDown:setPosition(2,10)
- eleRsInputDropDown:setForeground(hostConfig.theme.frameForeground)
- eleRsInputDropDown:setBackground(hostConfig.theme.frameBackground)
- eleRsInputDropDown:addItem("Top")
- eleRsInputDropDown:addItem("Bottom")
- eleRsInputDropDown:addItem("Left")
- eleRsInputDropDown:addItem("Right")
- eleRsInputDropDown:addItem("Front")
- eleRsInputDropDown:addItem("Back")
- eleRsInputDropDown:onChange(function(self, event, item)
- hostConfig.rsBcInputSide = item.text
- end)
- local eleRsOutputLabel = mainFrame:addLabel()
- eleRsOutputLabel:setPosition(2,19)
- eleRsOutputLabel:setForeground(hostConfig.theme.displayForeground)
- eleRsOutputLabel:setBackground(hostConfig.theme.displayBackground)
- eleRsOutputLabel:setText("Redstone Bundled Cable Output Side ")
- local eleRsOutputDropDown = mainFrame:addDropdown()
- eleRsOutputDropDown:setPosition(2,20)
- eleRsOutputDropDown:setForeground(hostConfig.theme.frameForeground)
- eleRsOutputDropDown:setBackground(hostConfig.theme.frameBackground)
- eleRsOutputDropDown:addItem("Top")
- eleRsOutputDropDown:addItem("Bottom")
- eleRsOutputDropDown:addItem("Left")
- eleRsOutputDropDown:addItem("Right")
- eleRsOutputDropDown:addItem("Front")
- eleRsOutputDropDown:addItem("Back")
- eleRsOutputDropDown:onChange(function(self, event, item)
- hostConfig.rsBcOutputSide = item.text
- end)
- local saveButton = mainFrame:addButton()
- saveButton:setSize(10,3)
- saveButton:setPosition("parent.w - 11", "parent.h - 4")
- saveButton:setText("Save")
- saveButton:onClick(function(self,event,button,x,y)
- if(event=="mouse_click")and(button==1)then
- if eleNumberInput:getValue() ~= "" then
- hostConfig.elevatorID = eleNumberInput:getValue()
- else
- basalt.debug("Error: You need to enter a Elevator ID")
- return
- end
- protocol = ("Elevator %d"):format(hostConfig.elevatorID)
- mainFrame:removeChildren()
- startHost()
- end
- end)
- else
- protocol = ("Elevator %d"):format(hostConfig.elevatorID)
- startHost()
- end
- end
- eleInit()
- basalt.autoUpdate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement