Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- local monSide = "top"
- local senSide = "left"
- local senCoords = {}
- senCoords["X"] = 1685
- senCoords["Y"] = 37
- senCoords["Z"] = 540
- local reactorCoords = {}
- reactorCoords["X"] = 1684
- reactorCoords["Y"] = 39
- reactorCoords["Z"] = 535
- local standardTextCol = colors.white
- local damageValTextCol = colors.orange
- local backgroundCol = colors.lightGray
- local gridFrameCol = colors.white
- local gridFillCol = colors.black
- local directory = "reactorIcons"
- local scale = .5
- local columns = 9
- local rows = 6
- local columnWidth = 14
- local rowHeight = 10
- local refreshDelay = 10
- local m = peripheral.wrap(monSide)
- m.setTextScale(.5)
- local s = sensor.wrap(senSide)
- sleep(1)
- local xMax, yMax = m.getSize()
- function JoJa()
- m.setBackgroundColor(colors.gray)
- m.setCursorPos(1, 1)
- for xP = 1, xMax do
- m.write(" ")
- end
- m.setCursorPos(1, 1)
- m.setTextColor(colors.cyan)
- m.write("Jo")
- m.setTextColor(colors.orange)
- m.write("Ja ")
- m.setTextColor(colors.lightGray)
- m.write("Productions")
- end
- function bg(col)
- m.setBackgroundColor(col)
- for yP = 1, yMax do
- m.setCursorPos(1, yP)
- for xP = 1, xMax do
- m.write(" ")
- end
- end
- end
- function drawGrid(xStart, yStart)
- m.setBackgroundColor(gridFrameCol)
- for yP = yStart, yStart+rows*(rowHeight+1), rowHeight+1 do
- m.setCursorPos(xStart, yP)
- for xP = 1, columns*(columnWidth+1) do
- m.write(" ")
- end
- end
- for xP = xStart, xStart+columns*(columnWidth+1), columnWidth+1 do
- for yP = yStart, yStart+rows*(rowHeight+1) do
- m.setCursorPos(xP, yP)
- m.write(" ")
- end
- end
- end
- function drawImage(xStart, yStart, image)
- for yP, info in pairs(image) do
- for xP, col in pairs(info) do
- if xP <= columnWidth and yP <= rowHeight then
- if col == 0 then
- col = gridFillCol
- end
- m.setBackgroundColor(col)
- m.setCursorPos((xStart-1)+xP, (yStart-1)+yP)
- m.write(" ")
- end
- end
- end
- end
- function getInventory()
- local xP = reactorCoords["X"]-senCoords["X"]
- local yP = reactorCoords["Y"]-senCoords["Y"]
- local zP = reactorCoords["Z"]-senCoords["Z"]
- local targets = s.getTargets()
- for target, info in pairs(targets) do
- if info.Position.X == xP and
- info.Position.Y == yP and
- info.Position.Z == zP then
- details = s.getTargetDetails(target)
- return details.Slots
- end
- end
- end
- function showSymbols(xStart, yStart, setup)
- local xP, yP = xStart+1, yStart+1
- local image = nil
- for slot, info in pairs(setup) do
- if info.Name == "empty" then
- image = paintutils.loadImage(directory ..
- "/empty")
- else
- image = paintutils.loadImage(directory ..
- "/" .. info.RawName)
- end
- if image == nil then
- image = paintutils.loadImage(directory ..
- "/error")
- end
- drawImage(xP, yP, image)
- xP = xP+columnWidth+1
- if math.fmod(slot, columns) == 0 then
- xP, yP = xStart+1, yP+rowHeight+1
- end
- end
- end
- function showInfo(xStart, yStart, setup)
- local xP, yP = xStart+1, yStart+1
- for slot, info in pairs(setup) do
- local image = paintutils.loadImage(directory ..
- "/empty")
- drawImage(xP, yP, image)
- m.setTextColor(standardTextCol)
- m.setCursorPos(xP, yP)
- m.write(tostring(slot))
- m.setCursorPos(xP, yP+1)
- m.write(string.sub(info.Name, 0, columnWidth))
- m.setCursorPos(xP, yP+2)
- local i = 1
- while string.sub(info.Name, columnWidth+i, columnWidth+i) == ' ' do
- i = i+1
- end
- m.write(string.sub(info.Name, columnWidth+i))
- if info.DamageValue ~= nil then
- m.setTextColor(damageValTextCol)
- m.setCursorPos(xP, yP+3)
- m.write(tostring(
- math.floor((1-info.DamageValue/10000)*100)) .. "%")
- end
- xP = xP+columnWidth+1
- if math.fmod(slot, columns) == 0 then
- xP, yP = xStart+1, yP+rowHeight+1
- end
- end
- end
- bg(backgroundCol)
- JoJa()
- drawGrid(15, 5)
- local refresh = true
- local stat = false
- local timerId = os.startTimer(refreshDelay)
- while true do
- if refresh then
- local inventory = getInventory()
- if stat then
- showInfo(15, 5, inventory)
- else
- showSymbols(15, 5, inventory)
- end
- end
- local event, par1 = os.pullEvent()
- refresh = false
- if event == "timer" then
- if par1 == timerId then
- timerId = os.startTimer(refreshDelay)
- refresh = true
- end
- elseif event == "monitor_touch" then
- stat = not stat
- refresh = true
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment