Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vos.loadApi('core.api')
- vos.loadApi('ui.api')
- vos.loadApi('relay.api')
- Relay.find()
- Relay.register('panelUpdate')
- Logger.filter('modem_receive', 'event')
- --Message.enableWirelessLogging()
- local textRows = 6
- local radioRows = 2
- local meterRows = 2
- local col = 2
- local dirty = { }
- local window = UI.term
- if Peripheral.isPresent('openperipheral_glassesbridge') then
- window = UI.Window({ parent =
- UI.Glasses({
- height = 37,
- width = 57,
- textScale = .5,
- backgroundOpacity = .75
- })
- })
- elseif Peripheral.isPresent('monitor') then
- window = UI.Device({
- deviceType = 'monitor',
- -- backgroundColor = colors.gray,
- textScale = .5,
- })
- end
- UI.CenteredText = class.class(UI.Window)
- function UI.CenteredText:draw()
- local y = 1
- self:clear()
- for w in self.value:gmatch("%S+") do
- self:centeredWrite(y, w)
- y = y + 1
- end
- end
- window:add({
- messages = UI.ScrollingText({
- backgroundColor = colors.gray,
- x = 2,
- width = window.width - 2,
- y = 12,
- height = 13,
- }),
- timeDisplay = UI.Text({
- y = 10,
- x = window.width - 8,
- width = 8
- })
- })
- window:draw()
- window.messages:clear()
- Message.addHandler('panelUpdate', function(h, id, msg)
- local s = msg.contents
- local t = window[s.uid]
- if s.type == 'text' then
- if not t then
- local x = 33
- t = UI.Text({
- x = x,
- y = textRows,
- width = 24,
- })
- textRows = textRows + 2
- end
- t.value = s.text
- table.insert(dirty, t)
- elseif s.type == 'meter' then
- if not t then
- local x = 33
- local label = UI.Text({
- x = x,
- y = meterRows,
- value = s.text,
- width = #s.text
- })
- t = UI.ProgressBar({
- x = x + 9,
- y = meterRows,
- width = 10,
- backgroundColor = colors.lightGray,
- })
- local text = UI.Text({
- x = x + 20,
- y = meterRows,
- width = 4
- })
- table.insert(dirty, label)
- window:add({
- [ s.uid .. 'label' ] = label,
- [ s.uid .. 'text' ] = text
- })
- meterRows = meterRows + 2
- end
- t.progress = s.value
- t.progressColor = s.color
- window[s.uid .. 'text'].value = s.value .. '%'
- table.insert(dirty, window[s.uid .. 'text'])
- table.insert(dirty, t)
- elseif s.type == 'radio' then
- if not t then
- local x = 2
- local y = radioRows
- if radioRows > 10 then
- y = radioRows - 10
- x = 18
- end
- local label = UI.Text({
- x = x + 3,
- y = y,
- value = s.text,
- width = #s.text
- })
- window:add({
- [ s.uid .. 'label' ] = label,
- })
- table.insert(dirty, label)
- t = UI.Window({
- x = x,
- y = y,
- width = 2,
- height = 1,
- })
- radioRows = radioRows + 2
- end
- if s.active then
- t.backgroundColor = colors.yellow
- else
- t.backgroundColor = colors.gray
- end
- table.insert(dirty, t)
- elseif s.type == 'message' then
- s.uid = 'messages'
- local time = textutils.formatTime(os.time(), false)
- if type(s.message) == 'table' then
- for _,message in ipairs(s.message) do
- window.messages:write(' ' .. time .. ' ' .. message)
- end
- else
- window.messages:write(' ' .. time .. ' ' .. s.message)
- end
- table.insert(dirty, window.messages)
- elseif s.type == 'fluids' then
- local tanks = s.tanks
- for _,tank in pairs(tanks) do
- if not window[tank.name] then
- window:add({
- [ tank.name ] =
- UI.VerticalMeter({
- x = col + 3,
- y = 28,
- width = 4,
- percent = 50,
- height = 7,
- backgroundColor = colors.gray,
- }),
- [ tank.name .. 'label' ] =
- UI.CenteredText({
- x = col,
- y = 26,
- width = 10,
- height = 2,
- value = tank.name,
- }),
- [ tank.name .. 'percent' ] =
- UI.CenteredText({
- x = col,
- y = 36,
- width = 10,
- height = 2,
- value = '',
- }),
- })
- col = col + 9
- table.insert(dirty, window[tank.name .. 'label'])
- end
- local percent = math.floor(tank.amount / tank.capacity * 100)
- local color = colors.green
- if percent < tank.low then
- color = colors.red
- elseif percent < tank.high then
- color = colors.orange
- end
- window[tank.name].meterColor = color
- window[tank.name].percent = percent
- local value = window[tank.name].percent .. '%'
- if tank.difference and tank.difference ~= 0 then
- value = string.format('%s %+d', value, tank.difference)
- end
- window[tank.name .. 'percent' ].value = value
- table.insert(dirty, window[tank.name])
- table.insert(dirty, window[tank.name .. 'percent'])
- end
- end
- if s.uid and not window[s.uid] then
- window:add({ [ s.uid ] = t })
- end
- end)
- Event.addHandler('heartbeat', function()
- window.timeDisplay.value = textutils.formatTime(os.time(), false)
- window.timeDisplay:draw()
- for _,v in pairs(dirty) do
- v:draw()
- end
- dirty = { }
- end)
- Event.heartbeat(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement