Parsing hex to RGB in only one file

Better encapsulating some functions in the graphics libraries
This commit is contained in:
Gabriel Moreira Minossi 2021-01-06 11:21:22 -03:00
parent d1d7a7a448
commit 03d355dfe6
8 changed files with 280 additions and 258 deletions

View File

@ -1,29 +1,18 @@
comp = require("component") component = require("component")
screen = require("term") term = require("term")
computer = require("computer") computer = require("computer")
event = require("event") event = require("event")
local AR = {} local AR = {}
local terminal = {x = 8257, y = 199, z = -2731} local terminal = {x = 8257, y = 199, z = -2731}
local function hexToRGB(hexcode)
local r = ((hexcode >> 16) & 0xFF) / 255.0
local g = ((hexcode >> 8) & 0xFF) / 255.0
local b = ((hexcode) & 0xFF) / 255.0
return r, g, b
end
function AR.hexToRGB(hexcode)
local r = ((hexcode >> 16) & 0xFF) / 255.0
local g = ((hexcode >> 8) & 0xFF) / 255.0
local b = ((hexcode) & 0xFF) / 255.0
return r, g, b
end
function AR.cube(glasses, x, y, z, color, alpha, scale) function AR.cube(glasses, x, y, z, color, alpha, scale)
scale = scale or 1 scale = scale or 1
alpha = alpha or 1 alpha = alpha or 1
local cube = glasses.addCube3D() local cube = glasses.addCube3D()
cube.set3DPos(x - terminal.x, y - terminal.y, z - terminal.z) cube.set3DPos(x - terminal.x, y - terminal.y, z - terminal.z)
cube.setColor(hexToRGB(color)) cube.setColor(table.unpack(color))
cube.setAlpha(alpha) cube.setAlpha(alpha)
cube.setScale(scale) cube.setScale(scale)
return cube return cube
@ -35,7 +24,7 @@ function AR.line(glasses, source, dest, color, alpha, scale)
local line = glasses.addLine3D() local line = glasses.addLine3D()
line.setVertex(1, source.x - terminal.x + 0.5, source.y - terminal.y + 0.5, source.z - terminal.z + 0.5) line.setVertex(1, source.x - terminal.x + 0.5, source.y - terminal.y + 0.5, source.z - terminal.z + 0.5)
line.setVertex(2, dest.x - terminal.x + 0.5, dest.y - terminal.y + 0.5, dest.z - terminal.z + 0.5) line.setVertex(2, dest.x - terminal.x + 0.5, dest.y - terminal.y + 0.5, dest.z - terminal.z + 0.5)
line.setColor(hexToRGB(color)) line.setColor(table.unpack(color))
line.setAlpha(alpha) line.setAlpha(alpha)
line.setScale(scale) line.setScale(scale)
return line return line
@ -46,7 +35,7 @@ function AR.worldText(glasses, name, x, y, z, color, alpha, scale)
alpha = alpha or 1 alpha = alpha or 1
local text = glasses.addFloatingText() local text = glasses.addFloatingText()
text.set3DPos(x - terminal.x, y - terminal.y, z - terminal.z) text.set3DPos(x - terminal.x, y - terminal.y, z - terminal.z)
text.setColor(hexToRGB(color)) text.setColor(table.unpack(color))
text.setAlpha(alpha) text.setAlpha(alpha)
text.setScale(scale) text.setScale(scale)
text.setText(name) text.setText(name)
@ -56,7 +45,7 @@ end
function AR.hudTriangle(glasses, a, b, c, color, alpha) function AR.hudTriangle(glasses, a, b, c, color, alpha)
alpha = alpha or 1.0 alpha = alpha or 1.0
local triangle = glasses.addTriangle() local triangle = glasses.addTriangle()
triangle.setColor(hexToRGB(color)) triangle.setColor(table.unpack(color))
triangle.setAlpha(alpha) triangle.setAlpha(alpha)
triangle.setVertex(1, a[1], a[2]) triangle.setVertex(1, a[1], a[2])
triangle.setVertex(2, b[1], b[2]) triangle.setVertex(2, b[1], b[2])
@ -67,7 +56,7 @@ end
function AR.hudQuad(glasses, a, b, c, d, color, alpha) function AR.hudQuad(glasses, a, b, c, d, color, alpha)
alpha = alpha or 1.0 alpha = alpha or 1.0
local quad = glasses.addQuad() local quad = glasses.addQuad()
quad.setColor(hexToRGB(color)) quad.setColor(table.unpack(color))
quad.setAlpha(alpha) quad.setAlpha(alpha)
quad.setVertex(1, a[1], a[2]) quad.setVertex(1, a[1], a[2])
quad.setVertex(2, b[1], b[2]) quad.setVertex(2, b[1], b[2])
@ -81,7 +70,7 @@ function AR.hudRectangle(glasses, x, y, w, h, color, alpha)
local rect = glasses.addRect() local rect = glasses.addRect()
rect.setPosition(x, y) rect.setPosition(x, y)
rect.setSize(h, w) rect.setSize(h, w)
rect.setColor(hexToRGB(color)) rect.setColor(table.unpack(color))
rect.setAlpha(alpha) rect.setAlpha(alpha)
return rect return rect
end end
@ -99,7 +88,7 @@ function AR.hudText(glasses, displayText, x, y, color, scale)
local text = glasses.addTextLabel() local text = glasses.addTextLabel()
text.setText(displayText) text.setText(displayText)
text.setPosition(x, y) text.setPosition(x, y)
text.setColor(hexToRGB(color)) text.setColor(table.unpack(color))
AR.textSize(text, scale) AR.textSize(text, scale)
return text return text
end end

View File

@ -1,5 +1,5 @@
comp = require("component") component = require("component")
screen = require("term") term = require("term")
computer = require("computer") computer = require("computer")
event = require("event") event = require("event")
thread = require("thread") thread = require("thread")
@ -226,7 +226,7 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap)
local w = 60 local w = 60
local h = 9 local h = 9
local entries = 0 local entries = 0
local fluids = comp.me_interface.getFluidsInNetwork() local fluids = component.me_interface.getFluidsInNetwork()
if initFluidMap then if initFluidMap then
for i = 0, #fluidMap, 1 do for i = 0, #fluidMap, 1 do
local background = local background =
@ -422,7 +422,7 @@ local function clearTicker(glasses)
end end
rollingTextObjects = {} rollingTextObjects = {}
end end
local cachedAmounts = refreshDatabase(comp.me_interface.getItemsInNetwork()) local cachedAmounts = refreshDatabase(component.me_interface.getItemsInNetwork())
function difference(new) function difference(new)
local differenceArray = {} local differenceArray = {}
for label, amount in pairs(cachedAmounts) do for label, amount in pairs(cachedAmounts) do
@ -504,9 +504,9 @@ function ARWidgets.itemTicker(glasses, x, y, w)
end end
if computer.uptime() - lastUpdate > 60 then if computer.uptime() - lastUpdate > 60 then
lastUpdate = computer.uptime() lastUpdate = computer.uptime()
allItems = comp.me_interface.getItemsInNetwork() allItems = component.me_interface.getItemsInNetwork()
itemsInNetwork = #allItems itemsInNetwork = #allItems
craftables = #comp.me_interface.getCraftables() craftables = #component.me_interface.getCraftables()
totalItems.setText("Total: " .. formatMillions(getTotalItemCount(allItems))) totalItems.setText("Total: " .. formatMillions(getTotalItemCount(allItems)))
patterns.setText("Patterns: " .. craftables) patterns.setText("Patterns: " .. craftables)
uniqueItems.setText("Unique: " .. itemsInNetwork) uniqueItems.setText("Unique: " .. itemsInNetwork)
@ -582,13 +582,13 @@ function ARWidgets.cpuMonitor(glasses, x, y)
) )
initializeCpuMonitor = false initializeCpuMonitor = false
end end
local cpus = comp.me_interface.getCpus() local cpus = component.me_interface.getCpus()
for i = 1, #cpus, 1 do for i = 1, #cpus, 1 do
if cpus[i].busy then if cpus[i].busy then
cpuLights[i].setColor(ARG.hexToRGB(colors.positiveEUColor)) cpuLights[i].setColor(colors.positiveEUColor)
else else
cpuLights[i].setAlpha(0.7) cpuLights[i].setAlpha(0.7)
cpuLights[i].setColor(ARG.hexToRGB(colors.workingColor)) cpuLights[i].setColor(colors.workingColor)
end end
end end
end end
@ -615,13 +615,13 @@ function ARWidgets.displayTPS(glasses, x, y)
local tps = math.min(20.00, get.tps()) local tps = math.min(20.00, get.tps())
if tps > 15 then if tps > 15 then
TPSText.setText("TPS: " .. string.sub(tps, 1, 5)) TPSText.setText("TPS: " .. string.sub(tps, 1, 5))
TPSText.setColor(ARG.hexToRGB(colors.positiveEUColor)) TPSText.setColor(colors.positiveEUColor)
elseif tps >= 10 then elseif tps >= 10 then
TPSText.setText("TPS: " .. string.sub(tps, 1, 5)) TPSText.setText("TPS: " .. string.sub(tps, 1, 5))
TPSText.setColor(ARG.hexToRGB(colors.workingColor)) TPSText.setColor(colors.workingColor)
else else
TPSText.setText("TPS: " .. string.sub(tps, 1, 4)) TPSText.setText("TPS: " .. string.sub(tps, 1, 4))
TPSText.setColor(ARG.hexToRGB(colors.negativeEUColor)) TPSText.setColor(colors.negativeEUColor)
end end
end end
function ARWidgets.clear() function ARWidgets.clear()

View File

@ -7,15 +7,15 @@ local colors = {
cyan = 0x00FFFF, cyan = 0x00FFFF,
green = 0x008000, green = 0x008000,
purple = 0x800080, purple = 0x800080,
brown = 0xA52A2A,
steelBlue = 0x4682B4, steelBlue = 0x4682B4,
brown = 0xA52A2A,
chocolate = 0xD2691E, chocolate = 0xD2691E,
lightGray = 0xD3D3D3,
darkGray = 0xA9A9A9,
rosyBrown = 0xBC8F8F, rosyBrown = 0xBC8F8F,
white = 0xFFFFFF, white = 0xFFFFFF,
black = 0x000000, lightGray = 0xD3D3D3,
darkGray = 0xA9A9A9,
darkSlateGrey = 0x2F4F4F, darkSlateGrey = 0x2F4F4F,
black = 0x000000,
machineBackground = colors.darkGray, machineBackground = colors.darkGray,
progressBackground = colors.lightGray, progressBackground = colors.lightGray,
labelColor = colors.chocolate, labelColor = colors.chocolate,
@ -34,4 +34,27 @@ local colors = {
barColor = colors.blue barColor = colors.blue
} }
local RGB = {}
for name, value in pairs(colors) do
local function hexToRGB(hexcode)
local r = ((hexcode >> 16) & 0xFF) / 255.0
local g = ((hexcode >> 8) & 0xFF) / 255.0
local b = ((hexcode) & 0xFF) / 255.0
return r, g, b
end
RGB[name] = hexToRGB(value)
end
colors.RGB = RGB
setmetatable(
colors,
{
__index = function(self, color)
return self.RGB[color] or {0, 0, 0}
end
}
)
return colors return colors

View File

@ -1,8 +1,8 @@
comp = require("component") component = require("component")
colors = require("colors") colors = require("colors")
local graphics = {} local graphics = {}
function pixel(GPU, x, y, color) function graphics.pixel(GPU, x, y, color)
local screenY = math.ceil(y / 2) local screenY = math.ceil(y / 2)
local baseChar, baseForeground, baseBackground = GPU.get(x, screenY) local baseChar, baseForeground, baseBackground = GPU.get(x, screenY)
GPU.setForeground(color) GPU.setForeground(color)
@ -14,21 +14,21 @@ function pixel(GPU, x, y, color)
end end
end end
function graphics.rect(GPU, x, y, w, h, color) function graphics.rectangle(GPU, x, y, w, h, color)
local hLeft = h local hLeft = h
if x > 0 and y > 0 then if x > 0 and y > 0 then
if y % 2 == 0 then if y % 2 == 0 then
for i = x, x + w - 1 do for i = x, x + w - 1 do
pixel(GPU, i, y, color) graphics.pixel(GPU, i, y, color)
end end
hLeft = hLeft - 1 hLeft = hLeft - 1
end end
GPU.setBackground(color) GPU.setBackground(table.unpack(color))
GPU.setForeground(color) GPU.setForeground(table.unpack(color))
if hLeft % 2 == 1 then if hLeft % 2 == 1 then
GPU.fill(x, math.ceil(y / 2) + (h - hLeft), w, (hLeft - 1) / 2, "") GPU.fill(x, math.ceil(y / 2) + (h - hLeft), w, (hLeft - 1) / 2, "")
for j = x, x + w - 1 do for j = x, x + w - 1 do
pixel(GPU, j, y + h - 1, color) graphics.pixel(GPU, j, y + h - 1, color)
end end
else else
GPU.fill(x, math.ceil(y / 2) + (h - hLeft), w, hLeft / 2, "") GPU.fill(x, math.ceil(y / 2) + (h - hLeft), w, hLeft / 2, "")
@ -41,7 +41,7 @@ function graphics.text(GPU, x, y, color, string)
error("Text position must be odd on y axis") error("Text position must be odd on y axis")
end end
local screenY = math.ceil(y / 2) local screenY = math.ceil(y / 2)
GPU.setForeground(color) GPU.setForeground(table.unpack(color))
for i = 0, #string - 1 do for i = 0, #string - 1 do
local baseChar, baseForeground, baseBackground = GPU.get(x + i, screenY) local baseChar, baseForeground, baseBackground = GPU.get(x + i, screenY)
GPU.setBackground(baseBackground) GPU.setBackground(baseBackground)
@ -54,7 +54,7 @@ function graphics.centeredText(GPU, x, y, color, string)
error("Text position must be odd on y axis") error("Text position must be odd on y axis")
end end
local screenY = math.ceil(y / 2) local screenY = math.ceil(y / 2)
local oldForeground = GPU.setForeground(color) local oldForeground = GPU.setForeground(table.unpack(color))
local oldBackground = GPU.getBackground() local oldBackground = GPU.getBackground()
for i = 0, #string - 1 do for i = 0, #string - 1 do
local baseChar, baseForeground, baseBackground = GPU.get(x + i - math.ceil(#string / 2) + 1, screenY) local baseChar, baseForeground, baseBackground = GPU.get(x + i - math.ceil(#string / 2) + 1, screenY)
@ -66,14 +66,14 @@ function graphics.centeredText(GPU, x, y, color, string)
end end
function graphics.border(GPU, w, h, color) function graphics.border(GPU, w, h, color)
draw.rect(GPU, 1, 1, w, 1, color) draw.rectangle(GPU, 1, 1, w, 1, color)
draw.rect(GPU, 1, h * 2, w, 1, color) draw.rectangle(GPU, 1, h * 2, w, 1, color)
draw.rect(GPU, 1, 1, 1, h * 2, color) draw.rectangle(GPU, 1, 1, 1, h * 2, color)
draw.rect(GPU, w, 1, 1, h * 2, color) draw.rectangle(GPU, w, 1, 1, h * 2, color)
end end
currentWindows = {} graphics.currentWindows = {}
function graphics.checkCollision(GPU, x, y) function graphics.checkCollision(GPU, x, y)
for window, params in pairs(currentWindows) do for window, params in pairs(graphics.currentWindows) do
if x >= params.x and x <= params.x + params.w - 1 then if x >= params.x and x <= params.x + params.w - 1 then
if y >= params.y and y <= params.y + math.ceil(params.h / 2) - 1 then if y >= params.y and y <= params.y + math.ceil(params.h / 2) - 1 then
return window return window
@ -84,7 +84,7 @@ function graphics.checkCollision(GPU, x, y)
end end
function graphics.createWindow(GPU, width, height, name) function graphics.createWindow(GPU, width, height, name)
local pageNumber = GPU.allocateBuffer(width, math.ceil(height / 2)) local pageNumber = GPU.allocateBuffer(width, math.ceil(height / 2))
currentWindows[name] = {page = pageNumber, x = 1, y = 1, w = width, h = height, GPU = GPU} graphics.currentWindows[name] = {page = pageNumber, x = 1, y = 1, w = width, h = height, GPU = GPU}
return pageNumber return pageNumber
end end
local function copyWindow(GPU, x, y, page, destination) local function copyWindow(GPU, x, y, page, destination)
@ -92,21 +92,22 @@ local function copyWindow(GPU, x, y, page, destination)
GPU.bitblt(destination, x, y, 160, 50, page, 1, 1) GPU.bitblt(destination, x, y, 160, 50, page, 1, 1)
end end
function graphics.refresh(GPU) function graphics.refresh(GPU)
for window, params in pairs(currentWindows) do for window, params in pairs(graphics.currentWindows) do
if params.w > 0 then if params.w > 0 then
copyWindow(GPU, params.x, params.y, params.page) copyWindow(GPU, params.x, params.y, params.page)
end end
end end
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
end end
windows = {}
graphics.windows = {}
function graphics.update() function graphics.update()
local function redraw() local function redraw()
for window, params in pairs(windows) do for window, params in pairs(graphics.windows) do
copyWindow(params.GPU, params.x, params.y, params.page) copyWindow(params.GPU, params.x, params.y, params.page)
end end
end end
for name, params in pairs(windows) do for name, params in pairs(graphics.windows) do
params.GPU.setActiveBuffer(params.page) params.GPU.setActiveBuffer(params.page)
params.update(params.GPU, name, params.address) params.update(params.GPU, name, params.address)
params.GPU.setActiveBuffer(0) params.GPU.setActiveBuffer(0)
@ -115,7 +116,7 @@ function graphics.update()
os.sleep() os.sleep()
end end
function graphics.clear() function graphics.clear()
currentWindows = {} graphics.currentWindows = {}
end end
return graphics return graphics

View File

@ -1,16 +1,17 @@
local draw = require("graphics") local draw = require("graphics")
local event = require("event") event = require("event")
local thread = require("thread") local thread = require("thread")
local uc = require("unicode") local uc = require("unicode")
local comp = require("component") component = require("component")
GPU = comp.proxy(comp.get("f26678f4")) GPU = component.proxy(component.get("f26678f4"))
local colors = require("colors") local colors = require("colors")
local gui, quit, editing = {}, false, false local gui, quit, editing = {}, false, false
local currentWindows = {} local currentWindows = {}
local activeWindow local activeWindow
local keyInput, mouseInput, drag, inContextMenu local keyInput, mouseInput, drag, inContextMenu
function checkCollision(x, y)
gui.checkCollision = function(x, y)
for window, params in pairs(currentWindows) do for window, params in pairs(currentWindows) do
if x >= params.x and x <= params.x + params.w - 1 then if x >= params.x and x <= params.x + params.w - 1 then
if y >= params.y and y <= params.y + math.ceil(params.h / 2) - 1 then if y >= params.y and y <= params.y + math.ceil(params.h / 2) - 1 then
@ -23,8 +24,8 @@ end
local contextMenus = 0 local contextMenus = 0
function contextMenu(GPU, x, y, data) gui.contextMenu = function(GPU, x, y, data)
function filterClicks(event) local function filterClicks(event)
return event == "touch" return event == "touch"
end end
inContextMenu = true inContextMenu = true
@ -35,9 +36,9 @@ function contextMenu(GPU, x, y, data)
longestData = #data longestData = #data
end end
end end
local contextWindow = createWindow(GPU, longestData, #data * 2, "ContextMenu" .. contextMenus) local contextWindow = gui.createWindow(GPU, longestData, #data * 2, "ContextMenu" .. contextMenus)
GPU.setActiveBuffer(contextWindow) GPU.setActiveBuffer(contextWindow)
draw.rect(GPU, 1, 1, longestData, #data * 2, colors.lightGray) draw.rectangle(GPU, 1, 1, longestData, #data * 2, colors.lightGray)
for i = 1, #data do for i = 1, #data do
draw.text(GPU, 1, 1 + i * 2 - 2, colors.cyan, data[i]) draw.text(GPU, 1, 1 + i * 2 - 2, colors.cyan, data[i])
end end
@ -46,8 +47,8 @@ function contextMenu(GPU, x, y, data)
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
end end
function keyboardListener() gui.keyboardListener = function()
function processKey(event, address, key, code, player) local function processKey(event, address, key, code, player)
local value = uc.char(key) local value = uc.char(key)
if value == "." then if value == "." then
quit = true quit = true
@ -63,41 +64,41 @@ function keyboardListener()
return event.listen("key_up", processKey) return event.listen("key_up", processKey)
end end
function processCommand(GPU, window, option) gui.processCommand = function(GPU, window, option)
local pageNumber = currentWindows[window].page local pageNumber = currentWindows[window].page
if currentWindows["ColorBox"] == nil then if currentWindows["ColorBox"] == nil then
createWindow(GPU, 10, 10, "ColorBox") gui.createWindow(GPU, 10, 10, "ColorBox")
currentWindows["ColorBox"].x = 10 currentWindows["ColorBox"].x = 10
currentWindows["ColorBox"].y = 10 currentWindows["ColorBox"].y = 10
end end
GPU.setActiveBuffer(currentWindows["ColorBox"].page) GPU.setActiveBuffer(currentWindows["ColorBox"].page)
if option == 1 then if option == 1 then
draw.rect(GPU, 1, 1, 10, 10, colors.red) draw.rectangle(GPU, 1, 1, 10, 10, colors.red)
end end
if option == 2 then if option == 2 then
draw.rect(GPU, 1, 1, 10, 10, colors.blue) draw.rectangle(GPU, 1, 1, 10, 10, colors.blue)
end end
if option == 3 then if option == 3 then
draw.rect(GPU, 1, 1, 10, 10, colors.green) draw.rectangle(GPU, 1, 1, 10, 10, colors.green)
end end
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
end end
local i, xOffset, yOffset = 1, 0, 0 local i, xOffset, yOffset = 1, 0, 0
function mouseListener() gui.mouseListener = function()
function processClick(event, address, x, y, key, player) local function processClick(event, address, x, y, key, player)
activeWindow = checkCollision(x, y) activeWindow = gui.checkCollision(x, y)
draw.text(GPU, 1, 1, colors.cyan, "Active window: " .. activeWindow) draw.text(GPU, 1, 1, colors.cyan, "Active window: " .. activeWindow)
if key == 1.0 and editing then if key == 1.0 and editing then
if inContextMenu then if inContextMenu then
contextMenus = 0 contextMenus = 0
end end
contextMenu(GPU, x, y, {[1] = "Red", [2] = "Blue", [3] = "Green"}) gui.contextMenu(GPU, x, y, {[1] = "Red", [2] = "Blue", [3] = "Green"})
else else
if inContextMenu then if inContextMenu then
local cont = currentWindows["ContextMenu1"] local cont = currentWindows["ContextMenu1"]
if x >= cont.x and x < cont.x + cont.w and y >= cont.y and y < cont.y + math.ceil(cont.h / 2) then if x >= cont.x and x < cont.x + cont.w and y >= cont.y and y < cont.y + math.ceil(cont.h / 2) then
processCommand(GPU, activeWindow, y - cont.y + 1) gui.processCommand(GPU, activeWindow, y - cont.y + 1)
else else
inContextMenu = false inContextMenu = false
for j = 1, contextMenus do for j = 1, contextMenus do
@ -116,8 +117,8 @@ function mouseListener()
return event.listen("touch", processClick) return event.listen("touch", processClick)
end end
function dragListener() gui.dragListener = function()
function processDrag(event, address, x, y, key, player) local function processDrag(event, address, x, y, key, player)
if editing and inContextMenu == false then if editing and inContextMenu == false then
local window = currentWindows[activeWindow] local window = currentWindows[activeWindow]
currentWindows[activeWindow].x = x - xOffset currentWindows[activeWindow].x = x - xOffset
@ -127,19 +128,19 @@ function dragListener()
return event.listen("drag", processDrag) return event.listen("drag", processDrag)
end end
function dropListener() gui.dropListener = function()
function processDrop(event, address, x, y, key, player) local function processDrop(event, address, x, y, key, player)
end end
return event.listen("drop", processDrop) return event.listen("drop", processDrop)
end end
function createWindow(GPU, width, height, name) gui.createWindow = function(GPU, width, height, name)
local pageNumber = GPU.allocateBuffer(width, math.ceil(height / 2)) local pageNumber = GPU.allocateBuffer(width, math.ceil(height / 2))
currentWindows[name] = {page = pageNumber, x = 1, y = 1, w = width, h = height} currentWindows[name] = {page = pageNumber, x = 1, y = 1, w = width, h = height}
return pageNumber return pageNumber
end end
function compose(GPU) gui.compose = function(GPU)
local stateBuffer = currentWindows["State"].page local stateBuffer = currentWindows["State"].page
GPU.setActiveBuffer(stateBuffer) GPU.setActiveBuffer(stateBuffer)
if editing then if editing then
@ -157,27 +158,27 @@ function compose(GPU)
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
end end
function copyWindow(GPU, x, y, page, destination) gui.copyWindow = function(GPU, x, y, page, destination)
destination = 0 or destination destination = 0 or destination
GPU.bitblt(destination, x, y, 160, 50, page, 1, 1) GPU.bitblt(destination, x, y, 160, 50, page, 1, 1)
end end
--return gui --return gui
GPU = comp.proxy(comp.get("de837fec")) GPU = component.proxy(component.get("de837fec"))
screen = comp.get("48ce2988") term = component.get("48ce2988")
GPU.bind(screen) GPU.bind(term)
GPU.freeAllBuffers() GPU.freeAllBuffers()
keyInput, mouseInput, drag = keyboardListener(), mouseListener(), dragListener() keyInput, mouseInput, drag = gui.keyboardListener(), gui.mouseListener(), gui.dragListener()
createWindow(GPU, 160, 100, "Black") gui.createWindow(GPU, 160, 100, "Black")
GPU.setActiveBuffer(currentWindows["Black"].page) GPU.setActiveBuffer(currentWindows["Black"].page)
draw.rect(GPU, 1, 1, 160, 100, 0x000000) draw.rectangle(GPU, 1, 1, 160, 100, 0x000000)
currentWindows["Black"].w = 0 currentWindows["Black"].w = 0
currentWindows["Black"].h = 0 currentWindows["Black"].h = 0
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
createWindow(GPU, 160, 100, "State") gui.createWindow(GPU, 160, 100, "State")
GPU.setActiveBuffer(currentWindows["State"].page) GPU.setActiveBuffer(currentWindows["State"].page)
draw.rect(GPU, 1, 1, 160, 100, 0x000000) draw.rectangle(GPU, 1, 1, 160, 100, 0x000000)
currentWindows["State"].w = 0 currentWindows["State"].w = 0
currentWindows["State"].h = 0 currentWindows["State"].h = 0
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
@ -188,6 +189,8 @@ while true do
event.cancel(keyInput) event.cancel(keyInput)
break break
end end
compose(GPU) gui.compose(GPU)
os.sleep(0.1) os.sleep(0.1)
end end
return gui

View File

@ -1,8 +1,8 @@
comp = require("component") component = require("component")
screen = require("term") term = require("term")
computer = require("computer") computer = require("computer")
event = require("event") event = require("event")
draw = require("graphics") graphics = require("graphics")
util = require("utility") util = require("utility")
colors = require("colors") colors = require("colors")
@ -11,8 +11,8 @@ local widgets = {}
function widgets.gtMachineInit(GPU, name, address) function widgets.gtMachineInit(GPU, name, address)
local maintenanceIndex = 0 local maintenanceIndex = 0
local machine = util.machine(address) local machine = util.machine(address)
draw.rect(GPU, 1, 1, 28, 9, colors.background) graphics.rectangle(GPU, 1, 1, 28, 9, colors.background)
draw.text(GPU, 4, 3, colors.mainColor, name) graphics.text(GPU, 4, 3, colors.mainColor, name)
if machine ~= nil then if machine ~= nil then
for i = 1, #machine.getSensorInformation() do --Get maintenance index for i = 1, #machine.getSensorInformation() do --Get maintenance index
if string.match(machine.getSensorInformation()[i], "Problems") ~= nil then if string.match(machine.getSensorInformation()[i], "Problems") ~= nil then
@ -24,26 +24,26 @@ function widgets.gtMachineInit(GPU, name, address)
if string.match(machine.getSensorInformation()[6], "tier") ~= nil then if string.match(machine.getSensorInformation()[6], "tier") ~= nil then
local tier = util.tier((string.gsub(machine.getSensorInformation()[6], "([^0-9]+)", "") - 1) / 10) local tier = util.tier((string.gsub(machine.getSensorInformation()[6], "([^0-9]+)", "") - 1) / 10)
if tier ~= nil then if tier ~= nil then
draw.text(GPU, 4, 5, colors.accentB, "" .. tier) graphics.text(GPU, 4, 5, colors.accentB, "" .. tier)
end end
end end
--Check for parallel on Processing Arrays --Check for parallel on Processing Arrays
if string.match(machine.getSensorInformation()[7], "Parallel") ~= nil then if string.match(machine.getSensorInformation()[7], "Parallel") ~= nil then
local parallel = string.gsub(machine.getSensorInformation()[7], "([^0-9]+)", "") local parallel = string.gsub(machine.getSensorInformation()[7], "([^0-9]+)", "")
if parallel ~= nil then if parallel ~= nil then
draw.text(GPU, 11 + -(#parallel) .. "", 5, colors.mainColor, parallel .. "x") graphics.text(GPU, 11 + -(#parallel) .. "", 5, colors.mainColor, parallel .. "x")
end end
end end
end end
else else
draw.text(GPU, 4, 5, colors.errorColor, "Unknown") graphics.text(GPU, 4, 5, colors.errorColor, "Unknown")
end end
draw.rect(GPU, 3, 2, 3, 1, colors.barColor) graphics.rectangle(GPU, 3, 2, 3, 1, colors.barColor)
draw.rect(GPU, 2, 2, 1, 7, colors.barColor) graphics.rectangle(GPU, 2, 2, 1, 7, colors.barColor)
draw.rect(GPU, 3, 8, 20, 1, colors.barColor) graphics.rectangle(GPU, 3, 8, 20, 1, colors.barColor)
draw.rect(GPU, 24, 8, 3, 1, colors.barColor) graphics.rectangle(GPU, 24, 8, 3, 1, colors.barColor)
draw.rect(GPU, 27, 2, 1, 7, colors.barColor) graphics.rectangle(GPU, 27, 2, 1, 7, colors.barColor)
draw.rect(GPU, 7, 2, 21, 1, colors.barColor) graphics.rectangle(GPU, 7, 2, 21, 1, colors.barColor)
return maintenanceIndex return maintenanceIndex
end end
@ -58,48 +58,48 @@ function widgets.gtMachine(GPU, name, address)
_, f, _ = GPU.get(3, 1) _, f, _ = GPU.get(3, 1)
if f ~= colors.mainColor then if f ~= colors.mainColor then
local bars1 = math.max(0, math.min(3, barAmount)) local bars1 = math.max(0, math.min(3, barAmount))
draw.rect(GPU, 3, 2, 3, 1, colors.barColor) graphics.rectangle(GPU, 3, 2, 3, 1, colors.barColor)
draw.rect(GPU, 24, 8, 3, 1, colors.barColor) graphics.rectangle(GPU, 24, 8, 3, 1, colors.barColor)
draw.rect(GPU, 2, 2, 1, 7, colors.barColor) graphics.rectangle(GPU, 2, 2, 1, 7, colors.barColor)
draw.rect(GPU, 27, 2, 1, 7, colors.barColor) graphics.rectangle(GPU, 27, 2, 1, 7, colors.barColor)
draw.rect(GPU, 3, 8, 20, 1, colors.barColor) graphics.rectangle(GPU, 3, 8, 20, 1, colors.barColor)
draw.rect(GPU, 7, 2, 20, 1, colors.barColor) graphics.rectangle(GPU, 7, 2, 20, 1, colors.barColor)
draw.rect(GPU, 6 - bars1, 2, bars1, 1, colors.mainColor) graphics.rectangle(GPU, 6 - bars1, 2, bars1, 1, colors.mainColor)
draw.rect(GPU, 24, 8, bars1, 1, colors.mainColor) graphics.rectangle(GPU, 24, 8, bars1, 1, colors.mainColor)
end end
_, f, _ = GPU.get(2, 4) _, f, _ = GPU.get(2, 4)
if barAmount > 3 and f ~= colors.mainColor then --Vertical if barAmount > 3 and f ~= colors.mainColor then --Vertical
bars2 = math.max(0, math.min(7, barAmount - 3)) bars2 = math.max(0, math.min(7, barAmount - 3))
draw.rect(GPU, 2, 2, 1, 7, colors.barColor) graphics.rectangle(GPU, 2, 2, 1, 7, colors.barColor)
draw.rect(GPU, 27, 2, 1, 7, colors.barColor) graphics.rectangle(GPU, 27, 2, 1, 7, colors.barColor)
draw.rect(GPU, 3, 8, 20, 1, colors.barColor) graphics.rectangle(GPU, 3, 8, 20, 1, colors.barColor)
draw.rect(GPU, 7, 2, 20, 1, colors.barColor) graphics.rectangle(GPU, 7, 2, 20, 1, colors.barColor)
draw.rect(GPU, 2, 2, 1, bars2, colors.mainColor) graphics.rectangle(GPU, 2, 2, 1, bars2, colors.mainColor)
draw.rect(GPU, 27, 9 - bars2, 1, bars2, colors.mainColor) graphics.rectangle(GPU, 27, 9 - bars2, 1, bars2, colors.mainColor)
end end
if barAmount > 10 then --Long Straight if barAmount > 10 then --Long Straight
local bars3 = math.max(0, barAmount - 10) local bars3 = math.max(0, barAmount - 10)
draw.rect(GPU, 3, 8, 20, 1, colors.barColor) graphics.rectangle(GPU, 3, 8, 20, 1, colors.barColor)
draw.rect(GPU, 7, 2, 20, 1, colors.barColor) graphics.rectangle(GPU, 7, 2, 20, 1, colors.barColor)
draw.rect(GPU, 3, 8, bars3, 1, colors.mainColor) graphics.rectangle(GPU, 3, 8, bars3, 1, colors.mainColor)
draw.rect(GPU, 27 - bars3, 2, bars3, 1, colors.mainColor) graphics.rectangle(GPU, 27 - bars3, 2, bars3, 1, colors.mainColor)
end end
progressString = progressString =
tostring(math.floor(machine.getWorkProgress() / 20)) .. tostring(math.floor(machine.getWorkProgress() / 20)) ..
"/" .. tostring(math.floor(machine.getWorkMaxProgress() / 20)) .. "s" "/" .. tostring(math.floor(machine.getWorkMaxProgress() / 20)) .. "s"
middlePoint = math.min(9, 12 - #progressString / 2) middlePoint = math.min(9, 12 - #progressString / 2)
draw.rect(GPU, 18, 5, 8, 2, colors.background) graphics.rectangle(GPU, 18, 5, 8, 2, colors.background)
draw.text(GPU, 26 - #progressString, 5, colors.accentA, progressString) graphics.text(GPU, 26 - #progressString, 5, colors.accentA, progressString)
else --No work else --No work
_, f, _ = GPU.get(5, 1) _, f, _ = GPU.get(5, 1)
if f ~= colors.barColor then if f ~= colors.barColor then
draw.rect(GPU, 18, 5, 8, 2, colors.background) graphics.rectangle(GPU, 18, 5, 8, 2, colors.background)
draw.rect(GPU, 3, 2, 3, 1, colors.barColor) graphics.rectangle(GPU, 3, 2, 3, 1, colors.barColor)
draw.rect(GPU, 2, 2, 1, 7, colors.barColor) graphics.rectangle(GPU, 2, 2, 1, 7, colors.barColor)
draw.rect(GPU, 3, 8, 20, 1, colors.barColor) graphics.rectangle(GPU, 3, 8, 20, 1, colors.barColor)
draw.rect(GPU, 24, 8, 3, 1, colors.barColor) graphics.rectangle(GPU, 24, 8, 3, 1, colors.barColor)
draw.rect(GPU, 27, 2, 1, 7, colors.barColor) graphics.rectangle(GPU, 27, 2, 1, 7, colors.barColor)
draw.rect(GPU, 7, 2, 20, 1, colors.barColor) graphics.rectangle(GPU, 7, 2, 20, 1, colors.barColor)
end end
end end
_, f, _ = GPU.get(6, 1) _, f, _ = GPU.get(6, 1)
@ -108,19 +108,19 @@ function widgets.gtMachine(GPU, name, address)
machine.isWorkAllowed()) == true machine.isWorkAllowed()) == true
then then
if f ~= colors.background then if f ~= colors.background then
draw.rect(GPU, 6, 2, 1, 1, colors.background) graphics.rectangle(GPU, 6, 2, 1, 1, colors.background)
draw.rect(GPU, 23, 8, 1, 1, colors.background) graphics.rectangle(GPU, 23, 8, 1, 1, colors.background)
end end
else else
if (machine.isWorkAllowed()) then if (machine.isWorkAllowed()) then
if f ~= colors.accentA then if f ~= colors.accentA then
draw.rect(GPU, 6, 2, 1, 1, colors.accentA) graphics.rectangle(GPU, 6, 2, 1, 1, colors.accentA)
draw.rect(GPU, 23, 8, 1, 1, colors.accentA) graphics.rectangle(GPU, 23, 8, 1, 1, colors.accentA)
end end
else else
if f ~= colors.errorColor then if f ~= colors.errorColor then
draw.rect(GPU, 6, 2, 1, 1, colors.errorColor) graphics.rectangle(GPU, 6, 2, 1, 1, colors.errorColor)
draw.rect(GPU, 23, 8, 1, 1, colors.errorColor) graphics.rectangle(GPU, 23, 8, 1, 1, colors.errorColor)
end end
end end
end end

View File

@ -1,44 +1,41 @@
comp = require("component") component = require("component")
screen = require("term") term = require("term")
computer = require("computer") computer = require("computer")
event = require("event") event = require("event")
thread = require("thread") thread = require("thread")
sides = require("sides") local sides = require("sides")
get = require("utility")
ARG = require("ARGraphics") ARG = require("ARGraphics")
G = require("graphics") graphics = require("graphics")
S = require("stockerUtil") S = require("stockerUtil")
local uc = require("unicode") local uc = require("unicode")
tx = require("transforms") local GPU = component.gpu
config = require("config") local transposer = component.transposer
local GPU = comp.gpu local itemsToStock = {}
interface = comp.me_interface local craftables = {}
transposer = comp.transposer
itemsToStock = {}
craftables = {}
local currentlyCrafting = {} local currentlyCrafting = {}
local drawerItem local drawerItem
local number = "" local number = ""
function mouseListener() local inNumberBox = false
function processClick(event, address, x, y, key, player) local function mouseListener()
local activeWindow = G.checkCollision(nil, x, y) local function processClick(event, address, x, y, key, player)
local activeWindow = graphics.checkCollision(nil, x, y)
if activeWindow ~= nil then if activeWindow ~= nil then
if activeWindow == "Button" then if activeWindow == "Button" then
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
if drawerItem == nil or number == "" then if drawerItem == nil or number == "" then
G.rect( graphics.rectangle(
GPU, GPU,
currentWindows["Button"].x + 2, graphics.currentWindows["Button"].x + 2,
currentWindows["Button"].y * 2 + 1, graphics.currentWindows["Button"].y * 2 + 1,
6, 6,
6, 6,
colors.negativeEUColor colors.negativeEUColor
) )
else else
G.rect( graphics.rectangle(
GPU, GPU,
currentWindows["Button"].x + 2, graphics.currentWindows["Button"].x + 2,
currentWindows["Button"].y * 2 + 1, graphics.currentWindows["Button"].y * 2 + 1,
6, 6,
6, 6,
colors.positiveEUColor colors.positiveEUColor
@ -55,61 +52,74 @@ function mouseListener()
end end
number = "" number = ""
os.sleep(0.3) os.sleep(0.3)
G.refresh(GPU) graphics.refresh(GPU)
elseif activeWindow == "Number" then elseif activeWindow == "Number" then
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
if drawerItem == nil then if drawerItem == nil then
G.centeredText( graphics.centeredText(
GPU, GPU,
currentWindows["Number"].x + 25, graphics.currentWindows["Number"].x + 25,
currentWindows["Number"].y * 2 + 3, graphics.currentWindows["Number"].y * 2 + 3,
0xFFFFFF, 0xFFFFFF,
"Pattern refresh requested..." "Pattern refresh requested..."
) )
S.refreshCraftables() S.refreshCraftables()
end end
inNumberBox = true inNumberBox = true
G.rect(GPU, currentWindows["Number"].x + 2, currentWindows["Number"].y * 2 + 1, 46, 6, 0x333333) graphics.rectangle(
GPU,
graphics.currentWindows["Number"].x + 2,
graphics.currentWindows["Number"].y * 2 + 1,
46,
6,
0x333333
)
else else
inNumberBox = false inNumberBox = false
number = "" number = ""
G.refresh(GPU) graphics.refresh(GPU)
end end
else else
inNumberBox = false inNumberBox = false
number = "" number = ""
G.refresh(GPU) graphics.refresh(GPU)
end end
end end
return event.listen("touch", processClick) return event.listen("touch", processClick)
end end
function keyboardListener() local function keyboardListener()
function processKey(event, address, key, code, player) local function processKey(event, address, key, code, player)
if inNumberBox then if inNumberBox then
local value = uc.char(key) local value = uc.char(key)
if key == 10 then if key == 10 then
inNumberBox = false inNumberBox = false
G.refresh(GPU) graphics.refresh(GPU)
end end
if key == 8 then if key == 8 then
number = string.sub(number, 1, #number - 1) number = string.sub(number, 1, #number - 1)
elseif (key >= 48 and key <= 57) then elseif (key >= 48 and key <= 57) then
number = number .. value number = number .. value
end end
G.rect(GPU, currentWindows["Number"].x + 2, currentWindows["Number"].y * 2 + 1, 46, 6, 0x333333) graphics.rectangle(GPU, graphics.currentWindows["Number"].x + 2, graphics.currentWindows["Number"].y * 2 + 1, 46, 6, 0x333333)
G.text(GPU, currentWindows["Number"].x + 4, currentWindows["Number"].y * 2 + 3, colors.workingColor, number) graphics.text(
GPU,
graphics.currentWindows["Number"].x + 4,
graphics.currentWindows["Number"].y * 2 + 3,
colors.workingColor,
number
)
end end
end end
return event.listen("key_down", processKey) return event.listen("key_down", processKey)
end end
function getNewItem(GPU, x, y) local function getNewItem(GPU, x, y)
if currentWindows["Item"] == nil then if graphics.currentWindows["Item"] == nil then
local itemWindow = G.createWindow(GPU, 60, 6, "Item") local itemWindow = graphics.createWindow(GPU, 60, 6, "Item")
currentWindows["Item"].x = x graphics.currentWindows["Item"].x = x
currentWindows["Item"].y = y graphics.currentWindows["Item"].y = y
GPU.setActiveBuffer(itemWindow) GPU.setActiveBuffer(itemWindow)
G.rect(GPU, 2, 2, 58, 4, colors.hudColor) graphics.rectangle(GPU, 2, 2, 58, 4, colors.hudColor)
G.rect(GPU, 3, 3, 56, 2, 0x000000) graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
end end
local newDrawerItem = transposer.getStackInSlot(sides.top, 2) local newDrawerItem = transposer.getStackInSlot(sides.top, 2)
@ -121,95 +131,95 @@ function getNewItem(GPU, x, y)
end end
if drawerItem == nil then if drawerItem == nil then
drawerItem = newDrawerItem.label drawerItem = newDrawerItem.label
GPU.setActiveBuffer(currentWindows["Item"].page) GPU.setActiveBuffer(graphics.currentWindows["Item"].page)
G.rect(GPU, 3, 3, 56, 2, 0x000000) graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
if craftables[drawerItem] ~= nil then if craftables[drawerItem] ~= nil then
G.centeredText(GPU, 30, 3, colors.positiveEUColor, drawerItem) graphics.centeredText(GPU, 30, 3, colors.positiveEUColor, drawerItem)
else else
G.centeredText(GPU, 30, 3, colors.negativeEUColor, drawerItem) graphics.centeredText(GPU, 30, 3, colors.negativeEUColor, drawerItem)
end end
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
if itemsToStock[drawerItem] ~= nil then if itemsToStock[drawerItem] ~= nil then
G.rect(GPU, currentWindows["Item"].x, currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000) graphics.rectangle(GPU, graphics.currentWindows["Item"].x, graphics.currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000)
G.centeredText( graphics.centeredText(
GPU, GPU,
currentWindows["Item"].x + 30, graphics.currentWindows["Item"].x + 30,
currentWindows["Item"].y * 2 - 3, graphics.currentWindows["Item"].y * 2 - 3,
0xFFFFFF, 0xFFFFFF,
"Configured: " .. itemsToStock[drawerItem] "Configured: " .. itemsToStock[drawerItem]
) )
end end
G.refresh(GPU) graphics.refresh(GPU)
else else
if drawerItem ~= newDrawerItem.label then if drawerItem ~= newDrawerItem.label then
drawerItem = newDrawerItem.label drawerItem = newDrawerItem.label
GPU.setActiveBuffer(currentWindows["Item"].page) GPU.setActiveBuffer(graphics.currentWindows["Item"].page)
G.rect(GPU, 3, 3, 56, 2, 0x000000) graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
if craftables[drawerItem] ~= nil then if craftables[drawerItem] ~= nil then
G.centeredText(GPU, 30, 3, colors.positiveEUColor, drawerItem) graphics.centeredText(GPU, 30, 3, colors.positiveEUColor, drawerItem)
else else
G.centeredText(GPU, 30, 3, colors.negativeEUColor, drawerItem) graphics.centeredText(GPU, 30, 3, colors.negativeEUColor, drawerItem)
end end
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
if itemsToStock[drawerItem] ~= nil then if itemsToStock[drawerItem] ~= nil then
G.rect(GPU, currentWindows["Item"].x, currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000) graphics.rectangle(GPU, graphics.currentWindows["Item"].x, graphics.currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000)
G.centeredText( graphics.centeredText(
GPU, GPU,
currentWindows["Item"].x + 30, graphics.currentWindows["Item"].x + 30,
currentWindows["Item"].y * 2 - 3, graphics.currentWindows["Item"].y * 2 - 3,
0xFFFFFF, 0xFFFFFF,
"Configured: " .. itemsToStock[drawerItem] "Configured: " .. itemsToStock[drawerItem]
) )
end end
G.refresh(GPU) graphics.refresh(GPU)
end end
end end
else else
if drawerItem ~= nil then if drawerItem ~= nil then
drawerItem = nil drawerItem = nil
GPU.setActiveBuffer(currentWindows["Item"].page) GPU.setActiveBuffer(graphics.currentWindows["Item"].page)
G.rect(GPU, 3, 3, 56, 2, 0x000000) graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
G.centeredText(GPU, 30, 3, 0xFFFFFF, "") graphics.centeredText(GPU, 30, 3, 0xFFFFFF, "")
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
G.rect(GPU, currentWindows["Item"].x, currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000) graphics.rectangle(GPU, graphics.currentWindows["Item"].x, graphics.currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000)
G.refresh(GPU) graphics.refresh(GPU)
end end
end end
end end
function numberBox(GPU, x, y) local function numberBox(GPU, x, y)
if currentWindows["Number"] == nil then if graphics.currentWindows["Number"] == nil then
local itemWindow = G.createWindow(GPU, 50, 10, "Number") local itemWindow = graphics.createWindow(GPU, 50, 10, "Number")
currentWindows["Number"].x = x graphics.currentWindows["Number"].x = x
currentWindows["Number"].y = y graphics.currentWindows["Number"].y = y
GPU.setActiveBuffer(itemWindow) GPU.setActiveBuffer(itemWindow)
G.rect(GPU, 2, 2, 48, 8, colors.hudColor) graphics.rectangle(GPU, 2, 2, 48, 8, colors.hudColor)
G.rect(GPU, 3, 3, 46, 6, 0x000000) graphics.rectangle(GPU, 3, 3, 46, 6, 0x000000)
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
end end
end end
function button(GPU, x, y) local function button(GPU, x, y)
if currentWindows["Button"] == nil then if graphics.currentWindows["Button"] == nil then
local button = G.createWindow(GPU, 10, 10, "Button") local button = graphics.createWindow(GPU, 10, 10, "Button")
currentWindows["Button"].x = x graphics.currentWindows["Button"].x = x
currentWindows["Button"].y = y graphics.currentWindows["Button"].y = y
GPU.setActiveBuffer(button) GPU.setActiveBuffer(button)
G.rect(GPU, 2, 2, 8, 8, colors.hudColor) graphics.rectangle(GPU, 2, 2, 8, 8, colors.hudColor)
G.rect(GPU, 3, 3, 6, 6, colors.workingColor) graphics.rectangle(GPU, 3, 3, 6, 6, colors.workingColor)
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
end end
end end
function craftableBox(GPU, x, y) local function craftableBox(GPU, x, y)
if currentWindows["Craft"] == nil then if graphics.currentWindows["Craft"] == nil then
local crafts = G.createWindow(GPU, 72, 100, "Craft") local crafts = graphics.createWindow(GPU, 72, 100, "Craft")
currentWindows["Craft"].x = x graphics.currentWindows["Craft"].x = x
currentWindows["Craft"].y = y graphics.currentWindows["Craft"].y = y
GPU.setActiveBuffer(crafts) GPU.setActiveBuffer(crafts)
G.rect(GPU, 2, 2, 70, 94, colors.hudColor) graphics.rectangle(GPU, 2, 2, 70, 94, colors.hudColor)
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
end end
GPU.setActiveBuffer(currentWindows["Craft"].page) GPU.setActiveBuffer(graphics.currentWindows["Craft"].page)
G.rect(GPU, 3, 4, 68, 90, 0x000000) graphics.rectangle(GPU, 3, 4, 68, 90, 0x000000)
G.rect(GPU, 48, 2, 1, 94, colors.hudColor) graphics.rectangle(GPU, 48, 2, 1, 94, colors.hudColor)
local i = 1 local i = 1
S.updateCache() S.updateCache()
for label, amount in pairs(itemsToStock) do for label, amount in pairs(itemsToStock) do
@ -219,16 +229,16 @@ function craftableBox(GPU, x, y)
if S.uniques() > 2500 then --Check against rebooted system if S.uniques() > 2500 then --Check against rebooted system
if toStock > 0 then if toStock > 0 then
if drawerItem == label then if drawerItem == label then
G.text(GPU, 4, 3 + 2 * i, colors.workingColor, label) graphics.text(GPU, 4, 3 + 2 * i, colors.workingColor, label)
elseif craftables[label] == nil then elseif craftables[label] == nil then
G.text(GPU, 4, 3 + 2 * i, colors.negativeEUColor, label) graphics.text(GPU, 4, 3 + 2 * i, colors.negativeEUColor, label)
else else
G.text(GPU, 4, 3 + 2 * i, 0xFFFFFF, label) graphics.text(GPU, 4, 3 + 2 * i, 0xFFFFFF, label)
end end
if stockedAmount >= toStock then --In stock if stockedAmount >= toStock then --In stock
G.text(GPU, 59 - (#stockedString + 1), 3 + 2 * i, 0xFFFFFF, stockedString) graphics.text(GPU, 59 - (#stockedString + 1), 3 + 2 * i, 0xFFFFFF, stockedString)
elseif stockedAmount >= toStock * 0.85 then --Edit hysteresis here, slightly below stock elseif stockedAmount >= toStock * 0.85 then --Edit hysteresis here, slightly below stock
G.text(GPU, 59 - (#stockedString + 1), 3 + 2 * i, colors.workingColor, stockedString) graphics.text(GPU, 59 - (#stockedString + 1), 3 + 2 * i, colors.workingColor, stockedString)
else --Needs to be ordered else --Needs to be ordered
--Add crafting request loop here --Add crafting request loop here
if craftables[label] ~= nil then if craftables[label] ~= nil then
@ -238,26 +248,26 @@ function craftableBox(GPU, x, y)
currentlyCrafting[label] = nil currentlyCrafting[label] = nil
end end
end end
G.text(GPU, 59 - (#stockedString + 1), 3 + 2 * i, colors.negativeEUColor, stockedString) graphics.text(GPU, 59 - (#stockedString + 1), 3 + 2 * i, colors.negativeEUColor, stockedString)
end end
G.text(GPU, 59, 3 + 2 * i, 0xFFFFFF, "| " .. amount) graphics.text(GPU, 59, 3 + 2 * i, 0xFFFFFF, "| " .. amount)
i = math.min(i + 1, 43) i = math.min(i + 1, 43)
end end
end end
end end
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
G.refresh(GPU) graphics.refresh(GPU)
end end
mouseListener() mouseListener()
keyboardListener() keyboardListener()
GPU.setResolution(160, 46) GPU.setResolution(160, 46)
screen.clear() term.clear()
G.clear() graphics.clear()
numberBox(GPU, 100, 41) numberBox(GPU, 100, 41)
button(GPU, 150, 41) button(GPU, 150, 41)
craftableBox(GPU, 0, 0) craftableBox(GPU, 0, 0)
G.refresh(GPU) graphics.refresh(GPU)
S.refreshCraftables() S.refreshCraftables()
S.loadPatterns() S.loadPatterns()
local timeSinceRefresh = computer.uptime() local timeSinceRefresh = computer.uptime()

View File

@ -1,40 +1,36 @@
comp = require("component") component = require("component")
screen = require("term") term = require("term")
computer = require("computer") computer = require("computer")
event = require("event")
thread = require("thread")
sides = require("sides")
get = require("utility")
ARG = require("ARGraphics") ARG = require("ARGraphics")
G = require("graphics") graphics = require("graphics")
local uc = require("unicode") local tx = require("transforms")
tx = require("transforms") GPU = component.gpu
config = require("config") local interface = component.me_interface
local GPU = comp.gpu
local sUtil = {} local sUtil = {}
local itemsToStock = {}
function sUtil.refreshCraftables() function sUtil.refreshCraftables()
local c = comp.me_interface.getCraftables() local craftables = interface.getCraftables()
local max = 0 local max = 0
if max > 0 then if max > 0 then
c = tx.sub(c, 1, max) craftables = tx.sub(craftables, 1, max)
end end
for i, craftable in pairs(c) do for i, craftable in pairs(craftables) do
if i ~= "n" then if i ~= "n" then
if i % 10 == 0 then if i % 10 == 0 then
G.centeredText( graphics.centeredText(
GPU, GPU,
currentWindows["Number"].x + 25, graphics.currentWindows["Number"].x + 25,
currentWindows["Number"].y * 2 + 3, graphics.currentWindows["Number"].y * 2 + 3,
0xFFFFFF, 0xFFFFFF,
"Discovering Patterns: " .. i .. " / " .. #c "Discovering Patterns: " .. i .. " / " .. #craftables
) )
end end
end end
if craftable ~= #c then if craftable ~= #craftables then
craftables[craftable.getItemStack().label] = craftable.request craftables[craftable.getItemStack().label] = craftable.request
end end
end end
G.centeredText(GPU, 86, 85, 0xFFFFFF, "Patterns in memory: " .. #c) graphics.centeredText(GPU, 86, 85, 0xFFFFFF, "Patterns in memory: " .. #craftables)
end end
local cachedAmounts = {} local cachedAmounts = {}
function sUtil.updateCache() function sUtil.updateCache()