Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local button = {}
- local filleds = {}
- local boxes = {}
- local lines = {}
- local texts = {}
- local refresh = true
- local infosSize = {}
- local controlsSize = {}
- local numbersSize = {}
- local currentRfTotal = 1
- local currentRfTick = 1
- local currentFuelConsumedLastTick = 0.00001
- local rfPerTickMax = 1
- local minPowerRod = 0
- local maxPowerRod = 100
- local currentRodLevel = 1
- local monitors = {}
- local modems = {}
- monitors = {peripheral.find("monitor")}
- modems = {peripheral.find("modem")}
- local mon = monitors[1]
- term.redirect(mon)
- mon.clear()
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- function openChannel()
- local modem = modems[1]
- modem.open(1)
- end
- function clearTable()
- button = {}
- end
- function setButton(name, title, func, xmin, ymin, xmax, ymax, elem, elem2, color)
- button[name] = {}
- button[name]["title"] = title
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- button[name]["color"] = color
- button[name]["elem"] = elem
- button[name]["elem2"] = elem2
- end
- function fill(text, color, bData)
- mon.setBackgroundColor(color)
- mon.setTextColor(colors.white)
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(bData["title"])) /2) +1
- for j = bData["ymin"], bData["ymax"] do
- mon.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(bData["title"]) +1 do
- if k == xspot then
- mon.write(bData["title"])
- 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(button) do
- local on = data["active"]
- currColor = data["color"]
- fill(name, currColor, data)
- end
- end
- function flash(name)
- screen()
- end
- function checkxy(x, y)
- for name, data in pairs(button) do
- if y>=data["ymin"] and y <= data["ymax"] then
- if x>=data["xmin"] and x<= data["xmax"] then
- data["func"](data["elem"], data["elem2"])
- flash(data['name'])
- return true
- end
- end
- end
- return false
- end
- function draw()
- for key,value in pairs(filleds) do
- local counter = 1
- for i=value[2],value[4],1 do
- paintutils.drawLine(value[1] , value[2]+counter, value[3], value[2]+counter, value[5])
- counter = counter + 1
- end
- end
- for key,value in pairs(boxes) do
- paintutils.drawLine(value[1] , value[2], value[1], value[4], value[5])
- paintutils.drawLine(value[1] , value[2], value[3], value[2], value[5])
- paintutils.drawLine(value[1] , value[4], value[3], value[4], value[5])
- paintutils.drawLine(value[3] , value[2], value[3], value[4], value[5])
- end
- for key,value in pairs(lines) do
- paintutils.drawLine(value[1] , value[2], value[3], value[4], value[5])
- end
- for key,value in pairs(texts) do
- mon.setCursorPos(value[1], value[2])
- mon.setTextColor(value[4])
- mon.setBackgroundColor(value[5])
- mon.write(value[3])
- end
- screen()
- resetDraw()
- end
- function resetDraw()
- filleds = {}
- boxes = {}
- lines = {}
- texts = {}
- end
- function clickEvent()
- local myEvent={os.pullEvent("monitor_touch")}
- checkxy(myEvent[3], myEvent[4])
- end
- function powerUp(m,n)
- local modem = modems[1]
- modem.transmit(3, 1, {"start", 1})
- end
- function powerDown(m,n)
- local modem = modems[1]
- modem.transmit(3, 1, {"stop", 1})
- end
- function modifyRods(limit, number)
- local tempLevel = 0
- if limit == "min" then
- tempLevel = minPowerRod + number
- if tempLevel <= 0 then
- minPowerRod = 0
- end
- if tempLevel >= maxPowerRod then
- minPowerRod = maxPowerRod -10
- end
- if tempLevel < maxPowerRod and tempLevel > 0 then
- minPowerRod = tempLevel
- end
- else
- tempLevel = maxPowerRod + number
- if tempLevel <= minPowerRod then
- maxPowerRod = minPowerRod +10
- end
- if tempLevel >= 100 then
- maxPowerRod = 100
- end
- if tempLevel > minPowerRod and tempLevel < 100 then
- maxPowerRod = tempLevel
- end
- end
- table.insert(lines, {controlsSize['inX'], controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, controlsSize['inX'] + controlsSize['width'], controlsSize['inY']+(controlsSize['sectionHeight']*1)+4, colors.black})
- table.insert(texts, {controlsSize['inX']+5, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, minPowerRod .. '%', colors.lightBlue, colors.black})
- table.insert(texts, {controlsSize['inX']+13, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, '--', colors.white, colors.black})
- table.insert(texts, {controlsSize['inX']+20, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, maxPowerRod .. '%', colors.purple, colors.black})
- transmitMinMax()
- end
- function transmitMinMax()
- local modem = modems[1]
- modem.transmit(3, 1, {"min", minPowerRod, maxPowerRod})
- end
- function addDrawBoxesSingleReactor()
- local w, h = mon.getSize()
- local margin = math.floor((w/100)*2)
- infosSize['startX'] = margin + 1
- infosSize['startY'] = margin + 1
- infosSize['endX'] = (((w-(margin*2))/3)*2)-margin
- infosSize['endY'] = h - margin
- infosSize['height'] = infosSize['endY']-infosSize['startY']-(margin*2)-2
- infosSize['width'] = infosSize['endX']-infosSize['startX']-(margin*2)-2
- infosSize['inX'] = infosSize['startX'] + margin +1
- infosSize['inY'] = infosSize['startY'] + margin +1
- infosSize['sectionHeight'] = math.floor(infosSize['height']/3)
- table.insert(boxes, {infosSize['startX'] , infosSize['startY'], infosSize['endX'], infosSize['endY'], colors.gray})
- local name = "INFOS"
- table.insert(lines, {infosSize['startX'] + margin , infosSize['startY'], infosSize['startX'] + (margin*2) + #name+1, infosSize['startY'], colors.black})
- table.insert(texts, {infosSize['startX'] + (margin*2), infosSize['startY'], name, colors.white, colors.black})
- local names = {}
- names[1] = 'ENERGY LAST TICK'
- names[2] = 'ENERGY STORED'
- names[3] = 'CONTROL ROD LEVEL'
- for i=0,2,1 do
- table.insert(texts, {infosSize['inX'] + margin, infosSize['inY'] + (infosSize['sectionHeight']*i) +i, names[i+1], colors.white, colors.black})
- table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 2 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
- end
- -- Controls
- controlsSize['startX'] = infosSize['endX'] + margin + 1
- controlsSize['startY'] = margin + 1
- controlsSize['endX'] = w-margin
- controlsSize['endY'] = (((h - (margin*2))/3)*2) +1
- controlsSize['height'] = controlsSize['endY']-controlsSize['startY']-(margin)-1
- controlsSize['width'] = controlsSize['endX']-controlsSize['startX']-(margin*2)-2
- controlsSize['inX'] = controlsSize['startX'] + margin +1
- controlsSize['inY'] = controlsSize['startY'] + margin
- table.insert(boxes, {controlsSize['startX'] , controlsSize['startY'], controlsSize['endX'], controlsSize['endY'], colors.gray})
- name = "CONTROLS"
- table.insert(lines, {controlsSize['startX'] + margin , controlsSize['startY'], controlsSize['startX'] + (margin*2) + #name+1, controlsSize['startY'], colors.black})
- table.insert(texts, {controlsSize['startX'] + (margin*2), controlsSize['startY'], name, colors.white, colors.black})
- controlsSize['sectionHeight'] = math.floor(controlsSize['height']/4)
- mon.setTextColor(colors.white)
- setButton("ON","ON", powerUp, controlsSize['inX'], controlsSize['inY'], controlsSize['inX'] + math.floor(controlsSize['width']/2) -1, controlsSize['inY'] +2, 0, 0, colors.green)
- setButton("OFF","OFF", powerDown, controlsSize['inX'] + math.floor(controlsSize['width']/2) +2, controlsSize['inY'], controlsSize['inX'] + controlsSize['width'], controlsSize['inY'] +2,0, 0, colors.red)
- table.insert(texts, {controlsSize['inX']+8, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+1, 'AUTO-CONTROL', colors.white, colors.black})
- table.insert(texts, {controlsSize['inX']+5, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+3, 'MIN', colors.lightBlue, colors.black})
- table.insert(texts, {controlsSize['inX']+5, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, minPowerRod..'%', colors.lightBlue, colors.black})
- table.insert(texts, {controlsSize['inX']+13, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, '--', colors.white, colors.black})
- table.insert(texts, {controlsSize['inX']+20, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+3, 'MAX', colors.purple, colors.black})
- table.insert(texts, {controlsSize['inX']+20, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, maxPowerRod..'%', colors.purple, colors.black})
- mon.setTextColor(colors.white)
- setButton("low-10","-10", modifyRods, controlsSize['inX'], controlsSize['inY'] +(controlsSize['sectionHeight']*2)+2, controlsSize['inX'] + math.floor(controlsSize['width']/2) -1, controlsSize['inY'] +(controlsSize['sectionHeight']*2)+4, "min", -10, colors.lightBlue)
- setButton("high-10","-10", modifyRods, controlsSize['inX'] + math.floor(controlsSize['width']/2) +2, controlsSize['inY'] +(controlsSize['sectionHeight']*2)+2, controlsSize['inX'] + controlsSize['width'], controlsSize['inY'] +(controlsSize['sectionHeight']*2)+4, "max", -10, colors.purple)
- setButton("low+10","+10", modifyRods, controlsSize['inX'], controlsSize['inY'] +(controlsSize['sectionHeight']*3)+2, controlsSize['inX'] + math.floor(controlsSize['width']/2) -1, controlsSize['inY'] +(controlsSize['sectionHeight']*3)+4, "min", 10, colors.lightBlue)
- setButton("high+10","+10", modifyRods, controlsSize['inX'] + math.floor(controlsSize['width']/2) +2, controlsSize['inY'] +(controlsSize['sectionHeight']*3)+2, controlsSize['inX'] + controlsSize['width'], controlsSize['inY'] +(controlsSize['sectionHeight']*3)+4, "max", 10, colors.purple)
- numbersSize['startX'] = infosSize['endX'] + margin + 1
- numbersSize['startY'] = controlsSize['endY'] + margin + 1
- numbersSize['endX'] = w-margin
- numbersSize['endY'] = h-margin
- numbersSize['height'] = numbersSize['endY']-numbersSize['startY']-(margin)-1
- numbersSize['width'] = numbersSize['endX']-numbersSize['startX']-(margin*2)-2
- numbersSize['inX'] = numbersSize['startX'] + margin +1
- numbersSize['inY'] = numbersSize['startY'] + margin
- table.insert(boxes, {numbersSize['startX'] , numbersSize['startY'], numbersSize['endX'], numbersSize['endY'], colors.gray})
- name = "NUMBERS"
- table.insert(lines, {numbersSize['startX'] + margin , numbersSize['startY'], numbersSize['startX'] + (margin*2) + #name+1, numbersSize['startY'], colors.black})
- table.insert(texts, {numbersSize['startX'] + (margin*2), numbersSize['startY'], name, colors.white, colors.black})
- refresh = true
- while refresh do
- parallel.waitForAny(refreshSingleReactor,clickEvent)
- end
- end
- function getAllStats()
- local stats = {}
- local modem = modems[1]
- local event, side, send, reply, message, distance = os.pullEvent("modem_message")
- stats["rfTotal"] = message[1]
- stats["rfPerTick"] = message[2]
- stats["rodLevel"] = message[3]
- stats["fuelPerTick"] = message[4]
- stats["energyCapacity"] = message[5]
- return stats
- end
- function refreshSingleReactor()
- local rfPerTick = 0
- local rfTotal = 0
- local allStats = getAllStats()
- rfTotal = allStats["rfTotal"]
- rfPerTick = allStats["rfPerTick"]
- rodLevel = allStats["rodLevel"]
- fuelPerTick = allStats["fuelPerTick"]
- rfTotalMax = allStats["energyCapacity"]
- local i = 0
- local infotoAdd = 'FE PER TICK : '
- if currentRfTick ~= rfPerTick then
- currentRfTick = rfPerTick
- if rfPerTick > rfPerTickMax then
- rfPerTickMax = rfPerTick
- end
- table.insert(lines, {numbersSize['inX'] , numbersSize['inY'],numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'], colors.black})
- table.insert(texts, {numbersSize['inX'], numbersSize['inY'], infotoAdd .. rfPerTick .. " FE", colors.white, colors.black})
- table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
- width = math.floor((infosSize['width'] / rfPerTickMax)*rfPerTick)
- table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green})
- end
- i = 1
- infotoAdd = 'ENERGY STORED : '
- if currentRfTotal ~= rfTotal then
- currentRfTotal = rfTotal
- table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
- width = math.floor((infosSize['width'] / rfTotalMax)*rfTotal)
- table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green})
- table.insert(lines, {numbersSize['inX'] , numbersSize['inY'] +2 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +2, colors.black})
- table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 2 , infotoAdd .. rfTotal .. " FE", colors.white, colors.black})
- end
- i = 2
- infotoAdd = 'CONTROL ROD LEVEL : '
- if currentRodLevel ~= rodLevel then
- currentRodLevel = rodLevel
- table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
- width = math.floor((infosSize['width'] / 100)*rodLevel)
- table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green})
- table.insert(lines, {numbersSize['inX'] , numbersSize['inY']+4 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +4, colors.black})
- table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 4 , infotoAdd .. rodLevel .. "%", colors.white, colors.black})
- end
- i = 3
- infotoAdd = 'FUEL USAGE : '
- if currentFuelConsumedLastTick ~= fuelPerTick then
- currentFuelConsumedLastTick = fuelPerTick
- table.insert(lines, {numbersSize['inX'] , numbersSize['inY']+6 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +6, colors.black})
- table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 6 , infotoAdd .. format_num(tonumber(fuelPerTick),3) .. "mb/t", colors.white, colors.black})
- end
- mon.setTextColor(colors.white)
- draw()
- sleep(2)
- end
- function comma_value(amount)
- local formatted = amount
- while true do
- formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
- if (k==0) then
- break
- end
- end
- return formatted
- end
- function round(val, decimal)
- if (decimal) then
- return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
- else
- return math.floor(val+0.5)
- end
- end
- function format_num(amount, decimal, prefix, neg_prefix)
- local str_amount, formatted, famount, remain
- decimal = decimal or 2
- neg_prefix = neg_prefix or "-"
- famount = math.abs(round(amount,decimal))
- famount = math.floor(famount)
- remain = round(math.abs(amount) - famount, decimal)
- formatted = comma_value(famount)
- if (decimal > 0) then
- remain = string.sub(tostring(remain),3)
- formatted = formatted .. "." .. remain ..
- string.rep("0", decimal - string.len(remain))
- end
- formatted = (prefix or "") .. formatted
- if (amount<0) then
- if (neg_prefix=="()") then
- formatted = "("..formatted ..")"
- else
- formatted = neg_prefix .. formatted
- end
- end
- return formatted
- end
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setTextScale(0.5)
- openChannel()
- addDrawBoxesSingleReactor()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement