Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mon = peripheral.find("monitor")
- areas = {}
- defaultTextColor = colors.black
- defaultBgColor = colors.white
- titleTextColor = colors.white
- titleBgColor = colors.black
- headerTextColor = colors.black
- headerBgColor = colors.gray
- buttonTextColor = colors.black
- buttonBgColor = colors.green
- function createAreas()
- local monWidth, monHeight = mon.getSize()
- areas["title"] = {width=monWidth, height=1, x=1, y=1, textColor=titleTextColor, bgColor=titleBgColor}
- areas["itemHeader"] = {width=monWidth-11, height=1, x=1, y=2, textColor=headerTextColor, bgColor=headerBgColor}
- areas["ipmHeader"] = {width=5, height=1, x=areas.itemHeader.width+1, y=2, textColor=headerTextColor, bgColor=headerBgColor}
- areas["tot15mHeader"] = {width=6, height=1, x=areas.itemHeader.width+areas.ipmHeader.width+1, y=2, textColor=headerTextColor, bgColor=headerBgColor}
- local colHeight = monHeight - 4
- areas["itemCol"] = {width=areas.itemHeader.width, height=colHeight, x=1, y=3, textColor=defaultTextColor, bgColor=defaultBgColor}
- areas["ipmCol"] = {width=areas.ipmHeader.width, height=colHeight, x=areas.itemCol.width+1, y=3, textColor=defaultTextColor, bgColor=defaultBgColor}
- areas["tot15mCol"] = {width=areas.tot15mHeader.width, height=colHeight, x=areas.itemCol.width+areas.ipmCol.width+1, y=3, textColor=defaultTextColor, bgColor=defaultBgColor}
- local controlSpace1 = (monWidth - (8+8+3)) / 2
- local controlSpace2 = (monWidth - (8+8+3)) / 2
- if (controlSpace1 % 1 ~= 0) then
- controlSpace1 = controlSpace1 - 0.5
- controlSpace2 = controlSpace2 + 0.5
- end
- areas["sortAzControl"] = {width=8, height=1, x=1, y=areas.itemCol.height+2+1, textColor=buttonTextColor, bgColor=buttonBgColor}
- areas["sortAmtControl"] = {width=8, height=1, x=8+controlSpace1+1, y=areas.itemCol.height+2+1, textColor=buttonTextColor, bgColor=buttonBgColor}
- local pageControlSpace = 1
- areas["leftPageControl"] = {width=1, height=1, x=8+controlSpace1+8+controlSpace2+1, y=areas.itemCol.height+2+1, textColor=buttonTextColor, bgColor=buttonBgColor}
- areas["rightPageControl"] = {width=1, height=1, x=areas.leftPageControl.x+areas.leftPageControl.width+pageControlSpace+1, y=areas.itemCol.height+2+1, textColor=buttonTextColor, bgColor=buttonBgColor}
- local statusSpace = monWidth - (7+8+6+6)
- areas["statusTotalLabel"] = {width=7, height=1, x=1, y=areas.itemCol.height+3+1, textColor=defaultTextColor, bgColor=defaultBgColor}
- areas["statusTotal"] = {width=8, height=1, x=7+1, y=areas.itemCol.height+3+1, textColor=defaultTextColor, bgColor=defaultBgColor}
- areas["statusDataLabel"] = {width=6, height=1, x=7+statusSpace+1, y=areas.itemCol.height+3+1, textColor=defaultTextColor, bgColor=defaultBgColor}
- areas["statusData"] = {width=6, height=1, x=7+statusSpace+6+1, y=areas.itemCol.height+3+1, textColor=defaultTextColor, bgColor=defaultBgColor}
- end
- function init()
- mon.setTextScale(1)
- mon.setTextColor(colors.black)
- mon.setBackgroundColor(colors.white)
- mon.clear()
- createAreas()
- writeLine("Item Input Statistics", areas.title)
- writeLine("item", areas.itemHeader)
- writeLine("ipm", areas.ipmHeader)
- writeLine("15mTot", areas.tot15mHeader)
- writeLine("Sort A-Z", areas.sortAzControl)
- writeLine("Sort Amt", areas.sortAmtControl)
- writeLine("<", areas.leftPageControl)
- writeLine(">", areas.rightPageControl)
- writeLine("Total: ", areas.statusTotalLabel)
- writeLine("Data: ", areas.statusDataLabel)
- end
- function clearArea(area)
- writeLine("", area)
- end
- function writeLine(line, area)
- writeLines({line}, area)
- end
- function writeLines(lines, area)
- mon.setTextColor(area.textColor)
- mon.setBackgroundColor(area.bgColor)
- local y = area.y
- local n = 1
- while y <= area.y + area.height - 1 do
- mon.setCursorPos(area.x, y)
- local buffer = ""
- if (lines[n] ~= nil) then
- buffer = lines[n]
- else
- buffer = spaces(area.width)
- end
- if (string.len(buffer) > area.width) then
- buffer = string.sub(buffer, 1, area.width)
- elseif (string.len(buffer) < area.width) then
- buffer = buffer..spaces(area.width - string.len(buffer))
- end
- print("writing @"..y..": '"..buffer.."'")
- mon.write(buffer)
- y = y + 1
- n = n + 1
- end
- end
- function spaces(length)
- local result = ""
- for i=1, length do
- result = result.." "
- end
- return result
- end
- function printEnv()
- local xPos, yPos = mon.getCursorPos()
- print("x="..xPos..",y="..yPos)
- local monWidth, monHeight = mon.getSize()
- print("width="..monWidth..",height="..monHeight)
- for areaName, obj in pairs(areas) do
- print(areaName)
- for key, val in pairs(obj) do
- print(" "..key.." = "..val)
- end
- end
- end
- function main()
- while true do
- local event, side, x, y = os.pullEvent("monitor_touch")
- mon.setCursorPos(x, y)
- mon.write("click")
- end
- end
- init()
- --printEnv()
- --print("|"..spaces(5).."|")
- --writeLine("Title", areas.title)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement