Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --local mon = peripheral.wrap("top")
- --mon.setTextScale(1)
- --mon.setTextColor(colors.white)
- local bar={}
- --mon.setBackgroundColor(colors.black)
- function clearTable()
- bar = {}
- end
- function newBar(name, id, type, text, func, xmin, xmax, ymin, ymax)
- bar[name] = {}
- bar[name]["id"] = id
- bar[name]["type"] = type
- bar[name]["text"] = text
- bar[name]["value"] = value
- bar[name]["func"] = func
- bar[name]["color"] = colors.green
- bar[name]["xmin"] = xmin
- bar[name]["ymin"] = ymin
- bar[name]["xmax"] = xmax
- bar[name]["ymax"] = ymax
- end
- function fill(text, color, bData)
- mon.setBackgroundColor(colors.gray)
- local yColor = (bData["ymax"]-bData["ymin"])*(1-bData["value"]/100)+bData["ymin"]
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
- for j = bData["ymin"], bData["ymax"] do
- mon.setCursorPos(bData["xmin"], j)
- if j >= yColor then mon.setBackgroundColor(color) end
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- mon.write(text)
- else
- mon.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- mon.write(" ")
- end
- end
- end
- mon.setBackgroundColor(colors.black)
- end
- function screen()
- local currColor
- for name,data in pairs(bar) do
- local currColor = data["color"]
- fill(data["text"], currColor, data)
- end
- end
- function setValue(name,val)
- bar[name]["value"] = val
- local currColor = colors.red
- if val >= 95 then
- colors.blue
- elseif val >= 75 then
- colors.green
- elseif val >= 50 then
- colors.lime
- elseif val >= 25 then
- colors.yellow
- elseif val >= 5 then
- colors.orange
- else
- colors.red
- end
- screen()
- end
- function checkxy(x, y)
- for name, data in pairs(bar) do
- if y>=data["ymin"] and y <= data["ymax"] then
- if x>=data["xmin"] and x<= data["xmax"] then
- data["func"]()
- return true
- --data["active"] = not data["active"]
- --print(name)
- end
- end
- end
- return false
- end
- function heading(text)
- w, h = mon.getSize()
- mon.setCursorPos((w-string.len(text))/2+1, 1)
- mon.write(text)
- end
- function label(w, h, text)
- mon.setCursorPos(w, h)
- mon.write(text)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement