mirror of
https://github.com/S4mpsa/InfOS.git
synced 2025-08-03 18:06:04 -04:00
Parsing hex to RGB in only one file
Better encapsulating some functions in the graphics libraries
This commit is contained in:
parent
d1d7a7a448
commit
03d355dfe6
@ -1,29 +1,18 @@
|
||||
comp = require("component")
|
||||
screen = require("term")
|
||||
component = require("component")
|
||||
term = require("term")
|
||||
computer = require("computer")
|
||||
event = require("event")
|
||||
|
||||
local AR = {}
|
||||
|
||||
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)
|
||||
scale = scale or 1
|
||||
alpha = alpha or 1
|
||||
local cube = glasses.addCube3D()
|
||||
cube.set3DPos(x - terminal.x, y - terminal.y, z - terminal.z)
|
||||
cube.setColor(hexToRGB(color))
|
||||
cube.setColor(table.unpack(color))
|
||||
cube.setAlpha(alpha)
|
||||
cube.setScale(scale)
|
||||
return cube
|
||||
@ -35,7 +24,7 @@ function AR.line(glasses, source, dest, color, alpha, scale)
|
||||
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(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.setScale(scale)
|
||||
return line
|
||||
@ -46,7 +35,7 @@ function AR.worldText(glasses, name, x, y, z, color, alpha, scale)
|
||||
alpha = alpha or 1
|
||||
local text = glasses.addFloatingText()
|
||||
text.set3DPos(x - terminal.x, y - terminal.y, z - terminal.z)
|
||||
text.setColor(hexToRGB(color))
|
||||
text.setColor(table.unpack(color))
|
||||
text.setAlpha(alpha)
|
||||
text.setScale(scale)
|
||||
text.setText(name)
|
||||
@ -56,7 +45,7 @@ end
|
||||
function AR.hudTriangle(glasses, a, b, c, color, alpha)
|
||||
alpha = alpha or 1.0
|
||||
local triangle = glasses.addTriangle()
|
||||
triangle.setColor(hexToRGB(color))
|
||||
triangle.setColor(table.unpack(color))
|
||||
triangle.setAlpha(alpha)
|
||||
triangle.setVertex(1, a[1], a[2])
|
||||
triangle.setVertex(2, b[1], b[2])
|
||||
@ -67,7 +56,7 @@ end
|
||||
function AR.hudQuad(glasses, a, b, c, d, color, alpha)
|
||||
alpha = alpha or 1.0
|
||||
local quad = glasses.addQuad()
|
||||
quad.setColor(hexToRGB(color))
|
||||
quad.setColor(table.unpack(color))
|
||||
quad.setAlpha(alpha)
|
||||
quad.setVertex(1, a[1], a[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()
|
||||
rect.setPosition(x, y)
|
||||
rect.setSize(h, w)
|
||||
rect.setColor(hexToRGB(color))
|
||||
rect.setColor(table.unpack(color))
|
||||
rect.setAlpha(alpha)
|
||||
return rect
|
||||
end
|
||||
@ -99,7 +88,7 @@ function AR.hudText(glasses, displayText, x, y, color, scale)
|
||||
local text = glasses.addTextLabel()
|
||||
text.setText(displayText)
|
||||
text.setPosition(x, y)
|
||||
text.setColor(hexToRGB(color))
|
||||
text.setColor(table.unpack(color))
|
||||
AR.textSize(text, scale)
|
||||
return text
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
comp = require("component")
|
||||
screen = require("term")
|
||||
component = require("component")
|
||||
term = require("term")
|
||||
computer = require("computer")
|
||||
event = require("event")
|
||||
thread = require("thread")
|
||||
@ -226,7 +226,7 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap)
|
||||
local w = 60
|
||||
local h = 9
|
||||
local entries = 0
|
||||
local fluids = comp.me_interface.getFluidsInNetwork()
|
||||
local fluids = component.me_interface.getFluidsInNetwork()
|
||||
if initFluidMap then
|
||||
for i = 0, #fluidMap, 1 do
|
||||
local background =
|
||||
@ -422,7 +422,7 @@ local function clearTicker(glasses)
|
||||
end
|
||||
rollingTextObjects = {}
|
||||
end
|
||||
local cachedAmounts = refreshDatabase(comp.me_interface.getItemsInNetwork())
|
||||
local cachedAmounts = refreshDatabase(component.me_interface.getItemsInNetwork())
|
||||
function difference(new)
|
||||
local differenceArray = {}
|
||||
for label, amount in pairs(cachedAmounts) do
|
||||
@ -504,9 +504,9 @@ function ARWidgets.itemTicker(glasses, x, y, w)
|
||||
end
|
||||
if computer.uptime() - lastUpdate > 60 then
|
||||
lastUpdate = computer.uptime()
|
||||
allItems = comp.me_interface.getItemsInNetwork()
|
||||
allItems = component.me_interface.getItemsInNetwork()
|
||||
itemsInNetwork = #allItems
|
||||
craftables = #comp.me_interface.getCraftables()
|
||||
craftables = #component.me_interface.getCraftables()
|
||||
totalItems.setText("Total: " .. formatMillions(getTotalItemCount(allItems)))
|
||||
patterns.setText("Patterns: " .. craftables)
|
||||
uniqueItems.setText("Unique: " .. itemsInNetwork)
|
||||
@ -582,13 +582,13 @@ function ARWidgets.cpuMonitor(glasses, x, y)
|
||||
)
|
||||
initializeCpuMonitor = false
|
||||
end
|
||||
local cpus = comp.me_interface.getCpus()
|
||||
local cpus = component.me_interface.getCpus()
|
||||
for i = 1, #cpus, 1 do
|
||||
if cpus[i].busy then
|
||||
cpuLights[i].setColor(ARG.hexToRGB(colors.positiveEUColor))
|
||||
cpuLights[i].setColor(colors.positiveEUColor)
|
||||
else
|
||||
cpuLights[i].setAlpha(0.7)
|
||||
cpuLights[i].setColor(ARG.hexToRGB(colors.workingColor))
|
||||
cpuLights[i].setColor(colors.workingColor)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -615,13 +615,13 @@ function ARWidgets.displayTPS(glasses, x, y)
|
||||
local tps = math.min(20.00, get.tps())
|
||||
if tps > 15 then
|
||||
TPSText.setText("TPS: " .. string.sub(tps, 1, 5))
|
||||
TPSText.setColor(ARG.hexToRGB(colors.positiveEUColor))
|
||||
TPSText.setColor(colors.positiveEUColor)
|
||||
elseif tps >= 10 then
|
||||
TPSText.setText("TPS: " .. string.sub(tps, 1, 5))
|
||||
TPSText.setColor(ARG.hexToRGB(colors.workingColor))
|
||||
TPSText.setColor(colors.workingColor)
|
||||
else
|
||||
TPSText.setText("TPS: " .. string.sub(tps, 1, 4))
|
||||
TPSText.setColor(ARG.hexToRGB(colors.negativeEUColor))
|
||||
TPSText.setColor(colors.negativeEUColor)
|
||||
end
|
||||
end
|
||||
function ARWidgets.clear()
|
||||
|
@ -7,15 +7,15 @@ local colors = {
|
||||
cyan = 0x00FFFF,
|
||||
green = 0x008000,
|
||||
purple = 0x800080,
|
||||
brown = 0xA52A2A,
|
||||
steelBlue = 0x4682B4,
|
||||
brown = 0xA52A2A,
|
||||
chocolate = 0xD2691E,
|
||||
lightGray = 0xD3D3D3,
|
||||
darkGray = 0xA9A9A9,
|
||||
rosyBrown = 0xBC8F8F,
|
||||
white = 0xFFFFFF,
|
||||
black = 0x000000,
|
||||
lightGray = 0xD3D3D3,
|
||||
darkGray = 0xA9A9A9,
|
||||
darkSlateGrey = 0x2F4F4F,
|
||||
black = 0x000000,
|
||||
machineBackground = colors.darkGray,
|
||||
progressBackground = colors.lightGray,
|
||||
labelColor = colors.chocolate,
|
||||
@ -34,4 +34,27 @@ local colors = {
|
||||
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
|
@ -1,8 +1,8 @@
|
||||
comp = require("component")
|
||||
component = require("component")
|
||||
colors = require("colors")
|
||||
local graphics = {}
|
||||
|
||||
function pixel(GPU, x, y, color)
|
||||
function graphics.pixel(GPU, x, y, color)
|
||||
local screenY = math.ceil(y / 2)
|
||||
local baseChar, baseForeground, baseBackground = GPU.get(x, screenY)
|
||||
GPU.setForeground(color)
|
||||
@ -14,21 +14,21 @@ function pixel(GPU, x, y, color)
|
||||
end
|
||||
end
|
||||
|
||||
function graphics.rect(GPU, x, y, w, h, color)
|
||||
function graphics.rectangle(GPU, x, y, w, h, color)
|
||||
local hLeft = h
|
||||
if x > 0 and y > 0 then
|
||||
if y % 2 == 0 then
|
||||
for i = x, x + w - 1 do
|
||||
pixel(GPU, i, y, color)
|
||||
graphics.pixel(GPU, i, y, color)
|
||||
end
|
||||
hLeft = hLeft - 1
|
||||
end
|
||||
GPU.setBackground(color)
|
||||
GPU.setForeground(color)
|
||||
GPU.setBackground(table.unpack(color))
|
||||
GPU.setForeground(table.unpack(color))
|
||||
if hLeft % 2 == 1 then
|
||||
GPU.fill(x, math.ceil(y / 2) + (h - hLeft), w, (hLeft - 1) / 2, "█")
|
||||
for j = x, x + w - 1 do
|
||||
pixel(GPU, j, y + h - 1, color)
|
||||
graphics.pixel(GPU, j, y + h - 1, color)
|
||||
end
|
||||
else
|
||||
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")
|
||||
end
|
||||
local screenY = math.ceil(y / 2)
|
||||
GPU.setForeground(color)
|
||||
GPU.setForeground(table.unpack(color))
|
||||
for i = 0, #string - 1 do
|
||||
local baseChar, baseForeground, baseBackground = GPU.get(x + i, screenY)
|
||||
GPU.setBackground(baseBackground)
|
||||
@ -54,7 +54,7 @@ function graphics.centeredText(GPU, x, y, color, string)
|
||||
error("Text position must be odd on y axis")
|
||||
end
|
||||
local screenY = math.ceil(y / 2)
|
||||
local oldForeground = GPU.setForeground(color)
|
||||
local oldForeground = GPU.setForeground(table.unpack(color))
|
||||
local oldBackground = GPU.getBackground()
|
||||
for i = 0, #string - 1 do
|
||||
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
|
||||
|
||||
function graphics.border(GPU, w, h, color)
|
||||
draw.rect(GPU, 1, 1, w, 1, color)
|
||||
draw.rect(GPU, 1, h * 2, w, 1, color)
|
||||
draw.rect(GPU, 1, 1, 1, h * 2, color)
|
||||
draw.rect(GPU, w, 1, 1, h * 2, color)
|
||||
draw.rectangle(GPU, 1, 1, w, 1, color)
|
||||
draw.rectangle(GPU, 1, h * 2, w, 1, color)
|
||||
draw.rectangle(GPU, 1, 1, 1, h * 2, color)
|
||||
draw.rectangle(GPU, w, 1, 1, h * 2, color)
|
||||
end
|
||||
currentWindows = {}
|
||||
graphics.currentWindows = {}
|
||||
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 y >= params.y and y <= params.y + math.ceil(params.h / 2) - 1 then
|
||||
return window
|
||||
@ -84,7 +84,7 @@ function graphics.checkCollision(GPU, x, y)
|
||||
end
|
||||
function graphics.createWindow(GPU, width, height, name)
|
||||
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
|
||||
end
|
||||
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)
|
||||
end
|
||||
function graphics.refresh(GPU)
|
||||
for window, params in pairs(currentWindows) do
|
||||
for window, params in pairs(graphics.currentWindows) do
|
||||
if params.w > 0 then
|
||||
copyWindow(GPU, params.x, params.y, params.page)
|
||||
end
|
||||
end
|
||||
GPU.setActiveBuffer(0)
|
||||
end
|
||||
windows = {}
|
||||
|
||||
graphics.windows = {}
|
||||
function graphics.update()
|
||||
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)
|
||||
end
|
||||
end
|
||||
for name, params in pairs(windows) do
|
||||
for name, params in pairs(graphics.windows) do
|
||||
params.GPU.setActiveBuffer(params.page)
|
||||
params.update(params.GPU, name, params.address)
|
||||
params.GPU.setActiveBuffer(0)
|
||||
@ -115,7 +116,7 @@ function graphics.update()
|
||||
os.sleep()
|
||||
end
|
||||
function graphics.clear()
|
||||
currentWindows = {}
|
||||
graphics.currentWindows = {}
|
||||
end
|
||||
|
||||
return graphics
|
||||
|
@ -1,16 +1,17 @@
|
||||
local draw = require("graphics")
|
||||
local event = require("event")
|
||||
event = require("event")
|
||||
local thread = require("thread")
|
||||
local uc = require("unicode")
|
||||
local comp = require("component")
|
||||
GPU = comp.proxy(comp.get("f26678f4"))
|
||||
component = require("component")
|
||||
GPU = component.proxy(component.get("f26678f4"))
|
||||
local colors = require("colors")
|
||||
|
||||
local gui, quit, editing = {}, false, false
|
||||
local currentWindows = {}
|
||||
local activeWindow
|
||||
local keyInput, mouseInput, drag, inContextMenu
|
||||
function checkCollision(x, y)
|
||||
|
||||
gui.checkCollision = function(x, y)
|
||||
for window, params in pairs(currentWindows) do
|
||||
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
|
||||
@ -23,8 +24,8 @@ end
|
||||
|
||||
local contextMenus = 0
|
||||
|
||||
function contextMenu(GPU, x, y, data)
|
||||
function filterClicks(event)
|
||||
gui.contextMenu = function(GPU, x, y, data)
|
||||
local function filterClicks(event)
|
||||
return event == "touch"
|
||||
end
|
||||
inContextMenu = true
|
||||
@ -35,9 +36,9 @@ function contextMenu(GPU, x, y, data)
|
||||
longestData = #data
|
||||
end
|
||||
end
|
||||
local contextWindow = createWindow(GPU, longestData, #data * 2, "ContextMenu" .. contextMenus)
|
||||
local contextWindow = gui.createWindow(GPU, longestData, #data * 2, "ContextMenu" .. contextMenus)
|
||||
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
|
||||
draw.text(GPU, 1, 1 + i * 2 - 2, colors.cyan, data[i])
|
||||
end
|
||||
@ -46,8 +47,8 @@ function contextMenu(GPU, x, y, data)
|
||||
GPU.setActiveBuffer(0)
|
||||
end
|
||||
|
||||
function keyboardListener()
|
||||
function processKey(event, address, key, code, player)
|
||||
gui.keyboardListener = function()
|
||||
local function processKey(event, address, key, code, player)
|
||||
local value = uc.char(key)
|
||||
if value == "." then
|
||||
quit = true
|
||||
@ -63,41 +64,41 @@ function keyboardListener()
|
||||
return event.listen("key_up", processKey)
|
||||
end
|
||||
|
||||
function processCommand(GPU, window, option)
|
||||
gui.processCommand = function(GPU, window, option)
|
||||
local pageNumber = currentWindows[window].page
|
||||
if currentWindows["ColorBox"] == nil then
|
||||
createWindow(GPU, 10, 10, "ColorBox")
|
||||
gui.createWindow(GPU, 10, 10, "ColorBox")
|
||||
currentWindows["ColorBox"].x = 10
|
||||
currentWindows["ColorBox"].y = 10
|
||||
end
|
||||
GPU.setActiveBuffer(currentWindows["ColorBox"].page)
|
||||
if option == 1 then
|
||||
draw.rect(GPU, 1, 1, 10, 10, colors.red)
|
||||
draw.rectangle(GPU, 1, 1, 10, 10, colors.red)
|
||||
end
|
||||
if option == 2 then
|
||||
draw.rect(GPU, 1, 1, 10, 10, colors.blue)
|
||||
draw.rectangle(GPU, 1, 1, 10, 10, colors.blue)
|
||||
end
|
||||
if option == 3 then
|
||||
draw.rect(GPU, 1, 1, 10, 10, colors.green)
|
||||
draw.rectangle(GPU, 1, 1, 10, 10, colors.green)
|
||||
end
|
||||
GPU.setActiveBuffer(0)
|
||||
end
|
||||
|
||||
local i, xOffset, yOffset = 1, 0, 0
|
||||
function mouseListener()
|
||||
function processClick(event, address, x, y, key, player)
|
||||
activeWindow = checkCollision(x, y)
|
||||
gui.mouseListener = function()
|
||||
local function processClick(event, address, x, y, key, player)
|
||||
activeWindow = gui.checkCollision(x, y)
|
||||
draw.text(GPU, 1, 1, colors.cyan, "Active window: " .. activeWindow)
|
||||
if key == 1.0 and editing then
|
||||
if inContextMenu then
|
||||
contextMenus = 0
|
||||
end
|
||||
contextMenu(GPU, x, y, {[1] = "Red", [2] = "Blue", [3] = "Green"})
|
||||
gui.contextMenu(GPU, x, y, {[1] = "Red", [2] = "Blue", [3] = "Green"})
|
||||
else
|
||||
if inContextMenu then
|
||||
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
|
||||
processCommand(GPU, activeWindow, y - cont.y + 1)
|
||||
gui.processCommand(GPU, activeWindow, y - cont.y + 1)
|
||||
else
|
||||
inContextMenu = false
|
||||
for j = 1, contextMenus do
|
||||
@ -116,8 +117,8 @@ function mouseListener()
|
||||
return event.listen("touch", processClick)
|
||||
end
|
||||
|
||||
function dragListener()
|
||||
function processDrag(event, address, x, y, key, player)
|
||||
gui.dragListener = function()
|
||||
local function processDrag(event, address, x, y, key, player)
|
||||
if editing and inContextMenu == false then
|
||||
local window = currentWindows[activeWindow]
|
||||
currentWindows[activeWindow].x = x - xOffset
|
||||
@ -127,19 +128,19 @@ function dragListener()
|
||||
return event.listen("drag", processDrag)
|
||||
end
|
||||
|
||||
function dropListener()
|
||||
function processDrop(event, address, x, y, key, player)
|
||||
gui.dropListener = function()
|
||||
local function processDrop(event, address, x, y, key, player)
|
||||
end
|
||||
return event.listen("drop", processDrop)
|
||||
end
|
||||
|
||||
function createWindow(GPU, width, height, name)
|
||||
gui.createWindow = function(GPU, width, height, name)
|
||||
local pageNumber = GPU.allocateBuffer(width, math.ceil(height / 2))
|
||||
currentWindows[name] = {page = pageNumber, x = 1, y = 1, w = width, h = height}
|
||||
return pageNumber
|
||||
end
|
||||
|
||||
function compose(GPU)
|
||||
gui.compose = function(GPU)
|
||||
local stateBuffer = currentWindows["State"].page
|
||||
GPU.setActiveBuffer(stateBuffer)
|
||||
if editing then
|
||||
@ -157,27 +158,27 @@ function compose(GPU)
|
||||
GPU.setActiveBuffer(0)
|
||||
end
|
||||
|
||||
function copyWindow(GPU, x, y, page, destination)
|
||||
gui.copyWindow = function(GPU, x, y, page, destination)
|
||||
destination = 0 or destination
|
||||
GPU.bitblt(destination, x, y, 160, 50, page, 1, 1)
|
||||
end
|
||||
|
||||
--return gui
|
||||
|
||||
GPU = comp.proxy(comp.get("de837fec"))
|
||||
screen = comp.get("48ce2988")
|
||||
GPU.bind(screen)
|
||||
GPU = component.proxy(component.get("de837fec"))
|
||||
term = component.get("48ce2988")
|
||||
GPU.bind(term)
|
||||
GPU.freeAllBuffers()
|
||||
keyInput, mouseInput, drag = keyboardListener(), mouseListener(), dragListener()
|
||||
createWindow(GPU, 160, 100, "Black")
|
||||
keyInput, mouseInput, drag = gui.keyboardListener(), gui.mouseListener(), gui.dragListener()
|
||||
gui.createWindow(GPU, 160, 100, "Black")
|
||||
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"].h = 0
|
||||
GPU.setActiveBuffer(0)
|
||||
createWindow(GPU, 160, 100, "State")
|
||||
gui.createWindow(GPU, 160, 100, "State")
|
||||
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"].h = 0
|
||||
GPU.setActiveBuffer(0)
|
||||
@ -188,6 +189,8 @@ while true do
|
||||
event.cancel(keyInput)
|
||||
break
|
||||
end
|
||||
compose(GPU)
|
||||
gui.compose(GPU)
|
||||
os.sleep(0.1)
|
||||
end
|
||||
|
||||
return gui
|
||||
|
@ -1,8 +1,8 @@
|
||||
comp = require("component")
|
||||
screen = require("term")
|
||||
component = require("component")
|
||||
term = require("term")
|
||||
computer = require("computer")
|
||||
event = require("event")
|
||||
draw = require("graphics")
|
||||
graphics = require("graphics")
|
||||
util = require("utility")
|
||||
colors = require("colors")
|
||||
|
||||
@ -11,8 +11,8 @@ local widgets = {}
|
||||
function widgets.gtMachineInit(GPU, name, address)
|
||||
local maintenanceIndex = 0
|
||||
local machine = util.machine(address)
|
||||
draw.rect(GPU, 1, 1, 28, 9, colors.background)
|
||||
draw.text(GPU, 4, 3, colors.mainColor, name)
|
||||
graphics.rectangle(GPU, 1, 1, 28, 9, colors.background)
|
||||
graphics.text(GPU, 4, 3, colors.mainColor, name)
|
||||
if machine ~= nil then
|
||||
for i = 1, #machine.getSensorInformation() do --Get maintenance index
|
||||
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
|
||||
local tier = util.tier((string.gsub(machine.getSensorInformation()[6], "([^0-9]+)", "") - 1) / 10)
|
||||
if tier ~= nil then
|
||||
draw.text(GPU, 4, 5, colors.accentB, "" .. tier)
|
||||
graphics.text(GPU, 4, 5, colors.accentB, "" .. tier)
|
||||
end
|
||||
end
|
||||
--Check for parallel on Processing Arrays
|
||||
if string.match(machine.getSensorInformation()[7], "Parallel") ~= nil then
|
||||
local parallel = string.gsub(machine.getSensorInformation()[7], "([^0-9]+)", "")
|
||||
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
|
||||
else
|
||||
draw.text(GPU, 4, 5, colors.errorColor, "Unknown")
|
||||
graphics.text(GPU, 4, 5, colors.errorColor, "Unknown")
|
||||
end
|
||||
draw.rect(GPU, 3, 2, 3, 1, colors.barColor)
|
||||
draw.rect(GPU, 2, 2, 1, 7, colors.barColor)
|
||||
draw.rect(GPU, 3, 8, 20, 1, colors.barColor)
|
||||
draw.rect(GPU, 24, 8, 3, 1, colors.barColor)
|
||||
draw.rect(GPU, 27, 2, 1, 7, colors.barColor)
|
||||
draw.rect(GPU, 7, 2, 21, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 3, 2, 3, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 2, 2, 1, 7, colors.barColor)
|
||||
graphics.rectangle(GPU, 3, 8, 20, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 24, 8, 3, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 27, 2, 1, 7, colors.barColor)
|
||||
graphics.rectangle(GPU, 7, 2, 21, 1, colors.barColor)
|
||||
return maintenanceIndex
|
||||
end
|
||||
|
||||
@ -58,48 +58,48 @@ function widgets.gtMachine(GPU, name, address)
|
||||
_, f, _ = GPU.get(3, 1)
|
||||
if f ~= colors.mainColor then
|
||||
local bars1 = math.max(0, math.min(3, barAmount))
|
||||
draw.rect(GPU, 3, 2, 3, 1, colors.barColor)
|
||||
draw.rect(GPU, 24, 8, 3, 1, colors.barColor)
|
||||
draw.rect(GPU, 2, 2, 1, 7, colors.barColor)
|
||||
draw.rect(GPU, 27, 2, 1, 7, colors.barColor)
|
||||
draw.rect(GPU, 3, 8, 20, 1, colors.barColor)
|
||||
draw.rect(GPU, 7, 2, 20, 1, colors.barColor)
|
||||
draw.rect(GPU, 6 - bars1, 2, bars1, 1, colors.mainColor)
|
||||
draw.rect(GPU, 24, 8, bars1, 1, colors.mainColor)
|
||||
graphics.rectangle(GPU, 3, 2, 3, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 24, 8, 3, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 2, 2, 1, 7, colors.barColor)
|
||||
graphics.rectangle(GPU, 27, 2, 1, 7, colors.barColor)
|
||||
graphics.rectangle(GPU, 3, 8, 20, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 7, 2, 20, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 6 - bars1, 2, bars1, 1, colors.mainColor)
|
||||
graphics.rectangle(GPU, 24, 8, bars1, 1, colors.mainColor)
|
||||
end
|
||||
_, f, _ = GPU.get(2, 4)
|
||||
if barAmount > 3 and f ~= colors.mainColor then --Vertical
|
||||
bars2 = math.max(0, math.min(7, barAmount - 3))
|
||||
draw.rect(GPU, 2, 2, 1, 7, colors.barColor)
|
||||
draw.rect(GPU, 27, 2, 1, 7, colors.barColor)
|
||||
draw.rect(GPU, 3, 8, 20, 1, colors.barColor)
|
||||
draw.rect(GPU, 7, 2, 20, 1, colors.barColor)
|
||||
draw.rect(GPU, 2, 2, 1, bars2, colors.mainColor)
|
||||
draw.rect(GPU, 27, 9 - bars2, 1, bars2, colors.mainColor)
|
||||
graphics.rectangle(GPU, 2, 2, 1, 7, colors.barColor)
|
||||
graphics.rectangle(GPU, 27, 2, 1, 7, colors.barColor)
|
||||
graphics.rectangle(GPU, 3, 8, 20, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 7, 2, 20, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 2, 2, 1, bars2, colors.mainColor)
|
||||
graphics.rectangle(GPU, 27, 9 - bars2, 1, bars2, colors.mainColor)
|
||||
end
|
||||
if barAmount > 10 then --Long Straight
|
||||
local bars3 = math.max(0, barAmount - 10)
|
||||
draw.rect(GPU, 3, 8, 20, 1, colors.barColor)
|
||||
draw.rect(GPU, 7, 2, 20, 1, colors.barColor)
|
||||
draw.rect(GPU, 3, 8, bars3, 1, colors.mainColor)
|
||||
draw.rect(GPU, 27 - bars3, 2, bars3, 1, colors.mainColor)
|
||||
graphics.rectangle(GPU, 3, 8, 20, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 7, 2, 20, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 3, 8, bars3, 1, colors.mainColor)
|
||||
graphics.rectangle(GPU, 27 - bars3, 2, bars3, 1, colors.mainColor)
|
||||
end
|
||||
progressString =
|
||||
tostring(math.floor(machine.getWorkProgress() / 20)) ..
|
||||
"/" .. tostring(math.floor(machine.getWorkMaxProgress() / 20)) .. "s"
|
||||
middlePoint = math.min(9, 12 - #progressString / 2)
|
||||
draw.rect(GPU, 18, 5, 8, 2, colors.background)
|
||||
draw.text(GPU, 26 - #progressString, 5, colors.accentA, progressString)
|
||||
graphics.rectangle(GPU, 18, 5, 8, 2, colors.background)
|
||||
graphics.text(GPU, 26 - #progressString, 5, colors.accentA, progressString)
|
||||
else --No work
|
||||
_, f, _ = GPU.get(5, 1)
|
||||
if f ~= colors.barColor then
|
||||
draw.rect(GPU, 18, 5, 8, 2, colors.background)
|
||||
draw.rect(GPU, 3, 2, 3, 1, colors.barColor)
|
||||
draw.rect(GPU, 2, 2, 1, 7, colors.barColor)
|
||||
draw.rect(GPU, 3, 8, 20, 1, colors.barColor)
|
||||
draw.rect(GPU, 24, 8, 3, 1, colors.barColor)
|
||||
draw.rect(GPU, 27, 2, 1, 7, colors.barColor)
|
||||
draw.rect(GPU, 7, 2, 20, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 18, 5, 8, 2, colors.background)
|
||||
graphics.rectangle(GPU, 3, 2, 3, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 2, 2, 1, 7, colors.barColor)
|
||||
graphics.rectangle(GPU, 3, 8, 20, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 24, 8, 3, 1, colors.barColor)
|
||||
graphics.rectangle(GPU, 27, 2, 1, 7, colors.barColor)
|
||||
graphics.rectangle(GPU, 7, 2, 20, 1, colors.barColor)
|
||||
end
|
||||
end
|
||||
_, f, _ = GPU.get(6, 1)
|
||||
@ -108,19 +108,19 @@ function widgets.gtMachine(GPU, name, address)
|
||||
machine.isWorkAllowed()) == true
|
||||
then
|
||||
if f ~= colors.background then
|
||||
draw.rect(GPU, 6, 2, 1, 1, colors.background)
|
||||
draw.rect(GPU, 23, 8, 1, 1, colors.background)
|
||||
graphics.rectangle(GPU, 6, 2, 1, 1, colors.background)
|
||||
graphics.rectangle(GPU, 23, 8, 1, 1, colors.background)
|
||||
end
|
||||
else
|
||||
if (machine.isWorkAllowed()) then
|
||||
if f ~= colors.accentA then
|
||||
draw.rect(GPU, 6, 2, 1, 1, colors.accentA)
|
||||
draw.rect(GPU, 23, 8, 1, 1, colors.accentA)
|
||||
graphics.rectangle(GPU, 6, 2, 1, 1, colors.accentA)
|
||||
graphics.rectangle(GPU, 23, 8, 1, 1, colors.accentA)
|
||||
end
|
||||
else
|
||||
if f ~= colors.errorColor then
|
||||
draw.rect(GPU, 6, 2, 1, 1, colors.errorColor)
|
||||
draw.rect(GPU, 23, 8, 1, 1, colors.errorColor)
|
||||
graphics.rectangle(GPU, 6, 2, 1, 1, colors.errorColor)
|
||||
graphics.rectangle(GPU, 23, 8, 1, 1, colors.errorColor)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,44 +1,41 @@
|
||||
comp = require("component")
|
||||
screen = require("term")
|
||||
component = require("component")
|
||||
term = require("term")
|
||||
computer = require("computer")
|
||||
event = require("event")
|
||||
thread = require("thread")
|
||||
sides = require("sides")
|
||||
get = require("utility")
|
||||
local sides = require("sides")
|
||||
ARG = require("ARGraphics")
|
||||
G = require("graphics")
|
||||
graphics = require("graphics")
|
||||
S = require("stockerUtil")
|
||||
local uc = require("unicode")
|
||||
tx = require("transforms")
|
||||
config = require("config")
|
||||
local GPU = comp.gpu
|
||||
interface = comp.me_interface
|
||||
transposer = comp.transposer
|
||||
itemsToStock = {}
|
||||
craftables = {}
|
||||
local GPU = component.gpu
|
||||
local transposer = component.transposer
|
||||
local itemsToStock = {}
|
||||
local craftables = {}
|
||||
local currentlyCrafting = {}
|
||||
local drawerItem
|
||||
local number = ""
|
||||
function mouseListener()
|
||||
function processClick(event, address, x, y, key, player)
|
||||
local activeWindow = G.checkCollision(nil, x, y)
|
||||
local inNumberBox = false
|
||||
local function mouseListener()
|
||||
local function processClick(event, address, x, y, key, player)
|
||||
local activeWindow = graphics.checkCollision(nil, x, y)
|
||||
if activeWindow ~= nil then
|
||||
if activeWindow == "Button" then
|
||||
GPU.setActiveBuffer(0)
|
||||
if drawerItem == nil or number == "" then
|
||||
G.rect(
|
||||
graphics.rectangle(
|
||||
GPU,
|
||||
currentWindows["Button"].x + 2,
|
||||
currentWindows["Button"].y * 2 + 1,
|
||||
graphics.currentWindows["Button"].x + 2,
|
||||
graphics.currentWindows["Button"].y * 2 + 1,
|
||||
6,
|
||||
6,
|
||||
colors.negativeEUColor
|
||||
)
|
||||
else
|
||||
G.rect(
|
||||
graphics.rectangle(
|
||||
GPU,
|
||||
currentWindows["Button"].x + 2,
|
||||
currentWindows["Button"].y * 2 + 1,
|
||||
graphics.currentWindows["Button"].x + 2,
|
||||
graphics.currentWindows["Button"].y * 2 + 1,
|
||||
6,
|
||||
6,
|
||||
colors.positiveEUColor
|
||||
@ -55,61 +52,74 @@ function mouseListener()
|
||||
end
|
||||
number = ""
|
||||
os.sleep(0.3)
|
||||
G.refresh(GPU)
|
||||
graphics.refresh(GPU)
|
||||
elseif activeWindow == "Number" then
|
||||
GPU.setActiveBuffer(0)
|
||||
if drawerItem == nil then
|
||||
G.centeredText(
|
||||
graphics.centeredText(
|
||||
GPU,
|
||||
currentWindows["Number"].x + 25,
|
||||
currentWindows["Number"].y * 2 + 3,
|
||||
graphics.currentWindows["Number"].x + 25,
|
||||
graphics.currentWindows["Number"].y * 2 + 3,
|
||||
0xFFFFFF,
|
||||
"Pattern refresh requested..."
|
||||
)
|
||||
S.refreshCraftables()
|
||||
end
|
||||
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
|
||||
inNumberBox = false
|
||||
number = ""
|
||||
G.refresh(GPU)
|
||||
graphics.refresh(GPU)
|
||||
end
|
||||
else
|
||||
inNumberBox = false
|
||||
number = ""
|
||||
G.refresh(GPU)
|
||||
graphics.refresh(GPU)
|
||||
end
|
||||
end
|
||||
return event.listen("touch", processClick)
|
||||
end
|
||||
function keyboardListener()
|
||||
function processKey(event, address, key, code, player)
|
||||
local function keyboardListener()
|
||||
local function processKey(event, address, key, code, player)
|
||||
if inNumberBox then
|
||||
local value = uc.char(key)
|
||||
if key == 10 then
|
||||
inNumberBox = false
|
||||
G.refresh(GPU)
|
||||
graphics.refresh(GPU)
|
||||
end
|
||||
if key == 8 then
|
||||
number = string.sub(number, 1, #number - 1)
|
||||
elseif (key >= 48 and key <= 57) then
|
||||
number = number .. value
|
||||
end
|
||||
G.rect(GPU, currentWindows["Number"].x + 2, currentWindows["Number"].y * 2 + 1, 46, 6, 0x333333)
|
||||
G.text(GPU, currentWindows["Number"].x + 4, currentWindows["Number"].y * 2 + 3, colors.workingColor, number)
|
||||
graphics.rectangle(GPU, graphics.currentWindows["Number"].x + 2, graphics.currentWindows["Number"].y * 2 + 1, 46, 6, 0x333333)
|
||||
graphics.text(
|
||||
GPU,
|
||||
graphics.currentWindows["Number"].x + 4,
|
||||
graphics.currentWindows["Number"].y * 2 + 3,
|
||||
colors.workingColor,
|
||||
number
|
||||
)
|
||||
end
|
||||
end
|
||||
return event.listen("key_down", processKey)
|
||||
end
|
||||
function getNewItem(GPU, x, y)
|
||||
if currentWindows["Item"] == nil then
|
||||
local itemWindow = G.createWindow(GPU, 60, 6, "Item")
|
||||
currentWindows["Item"].x = x
|
||||
currentWindows["Item"].y = y
|
||||
local function getNewItem(GPU, x, y)
|
||||
if graphics.currentWindows["Item"] == nil then
|
||||
local itemWindow = graphics.createWindow(GPU, 60, 6, "Item")
|
||||
graphics.currentWindows["Item"].x = x
|
||||
graphics.currentWindows["Item"].y = y
|
||||
GPU.setActiveBuffer(itemWindow)
|
||||
G.rect(GPU, 2, 2, 58, 4, colors.hudColor)
|
||||
G.rect(GPU, 3, 3, 56, 2, 0x000000)
|
||||
graphics.rectangle(GPU, 2, 2, 58, 4, colors.hudColor)
|
||||
graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
|
||||
GPU.setActiveBuffer(0)
|
||||
end
|
||||
local newDrawerItem = transposer.getStackInSlot(sides.top, 2)
|
||||
@ -121,95 +131,95 @@ function getNewItem(GPU, x, y)
|
||||
end
|
||||
if drawerItem == nil then
|
||||
drawerItem = newDrawerItem.label
|
||||
GPU.setActiveBuffer(currentWindows["Item"].page)
|
||||
G.rect(GPU, 3, 3, 56, 2, 0x000000)
|
||||
GPU.setActiveBuffer(graphics.currentWindows["Item"].page)
|
||||
graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
|
||||
if craftables[drawerItem] ~= nil then
|
||||
G.centeredText(GPU, 30, 3, colors.positiveEUColor, drawerItem)
|
||||
graphics.centeredText(GPU, 30, 3, colors.positiveEUColor, drawerItem)
|
||||
else
|
||||
G.centeredText(GPU, 30, 3, colors.negativeEUColor, drawerItem)
|
||||
graphics.centeredText(GPU, 30, 3, colors.negativeEUColor, drawerItem)
|
||||
end
|
||||
GPU.setActiveBuffer(0)
|
||||
if itemsToStock[drawerItem] ~= nil then
|
||||
G.rect(GPU, currentWindows["Item"].x, currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000)
|
||||
G.centeredText(
|
||||
graphics.rectangle(GPU, graphics.currentWindows["Item"].x, graphics.currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000)
|
||||
graphics.centeredText(
|
||||
GPU,
|
||||
currentWindows["Item"].x + 30,
|
||||
currentWindows["Item"].y * 2 - 3,
|
||||
graphics.currentWindows["Item"].x + 30,
|
||||
graphics.currentWindows["Item"].y * 2 - 3,
|
||||
0xFFFFFF,
|
||||
"Configured: " .. itemsToStock[drawerItem]
|
||||
)
|
||||
end
|
||||
G.refresh(GPU)
|
||||
graphics.refresh(GPU)
|
||||
else
|
||||
if drawerItem ~= newDrawerItem.label then
|
||||
drawerItem = newDrawerItem.label
|
||||
GPU.setActiveBuffer(currentWindows["Item"].page)
|
||||
G.rect(GPU, 3, 3, 56, 2, 0x000000)
|
||||
GPU.setActiveBuffer(graphics.currentWindows["Item"].page)
|
||||
graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
|
||||
if craftables[drawerItem] ~= nil then
|
||||
G.centeredText(GPU, 30, 3, colors.positiveEUColor, drawerItem)
|
||||
graphics.centeredText(GPU, 30, 3, colors.positiveEUColor, drawerItem)
|
||||
else
|
||||
G.centeredText(GPU, 30, 3, colors.negativeEUColor, drawerItem)
|
||||
graphics.centeredText(GPU, 30, 3, colors.negativeEUColor, drawerItem)
|
||||
end
|
||||
GPU.setActiveBuffer(0)
|
||||
if itemsToStock[drawerItem] ~= nil then
|
||||
G.rect(GPU, currentWindows["Item"].x, currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000)
|
||||
G.centeredText(
|
||||
graphics.rectangle(GPU, graphics.currentWindows["Item"].x, graphics.currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000)
|
||||
graphics.centeredText(
|
||||
GPU,
|
||||
currentWindows["Item"].x + 30,
|
||||
currentWindows["Item"].y * 2 - 3,
|
||||
graphics.currentWindows["Item"].x + 30,
|
||||
graphics.currentWindows["Item"].y * 2 - 3,
|
||||
0xFFFFFF,
|
||||
"Configured: " .. itemsToStock[drawerItem]
|
||||
)
|
||||
end
|
||||
G.refresh(GPU)
|
||||
graphics.refresh(GPU)
|
||||
end
|
||||
end
|
||||
else
|
||||
if drawerItem ~= nil then
|
||||
drawerItem = nil
|
||||
GPU.setActiveBuffer(currentWindows["Item"].page)
|
||||
G.rect(GPU, 3, 3, 56, 2, 0x000000)
|
||||
G.centeredText(GPU, 30, 3, 0xFFFFFF, "")
|
||||
GPU.setActiveBuffer(graphics.currentWindows["Item"].page)
|
||||
graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
|
||||
graphics.centeredText(GPU, 30, 3, 0xFFFFFF, "")
|
||||
GPU.setActiveBuffer(0)
|
||||
G.rect(GPU, currentWindows["Item"].x, currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000)
|
||||
G.refresh(GPU)
|
||||
graphics.rectangle(GPU, graphics.currentWindows["Item"].x, graphics.currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000)
|
||||
graphics.refresh(GPU)
|
||||
end
|
||||
end
|
||||
end
|
||||
function numberBox(GPU, x, y)
|
||||
if currentWindows["Number"] == nil then
|
||||
local itemWindow = G.createWindow(GPU, 50, 10, "Number")
|
||||
currentWindows["Number"].x = x
|
||||
currentWindows["Number"].y = y
|
||||
local function numberBox(GPU, x, y)
|
||||
if graphics.currentWindows["Number"] == nil then
|
||||
local itemWindow = graphics.createWindow(GPU, 50, 10, "Number")
|
||||
graphics.currentWindows["Number"].x = x
|
||||
graphics.currentWindows["Number"].y = y
|
||||
GPU.setActiveBuffer(itemWindow)
|
||||
G.rect(GPU, 2, 2, 48, 8, colors.hudColor)
|
||||
G.rect(GPU, 3, 3, 46, 6, 0x000000)
|
||||
graphics.rectangle(GPU, 2, 2, 48, 8, colors.hudColor)
|
||||
graphics.rectangle(GPU, 3, 3, 46, 6, 0x000000)
|
||||
GPU.setActiveBuffer(0)
|
||||
end
|
||||
end
|
||||
function button(GPU, x, y)
|
||||
if currentWindows["Button"] == nil then
|
||||
local button = G.createWindow(GPU, 10, 10, "Button")
|
||||
currentWindows["Button"].x = x
|
||||
currentWindows["Button"].y = y
|
||||
local function button(GPU, x, y)
|
||||
if graphics.currentWindows["Button"] == nil then
|
||||
local button = graphics.createWindow(GPU, 10, 10, "Button")
|
||||
graphics.currentWindows["Button"].x = x
|
||||
graphics.currentWindows["Button"].y = y
|
||||
GPU.setActiveBuffer(button)
|
||||
G.rect(GPU, 2, 2, 8, 8, colors.hudColor)
|
||||
G.rect(GPU, 3, 3, 6, 6, colors.workingColor)
|
||||
graphics.rectangle(GPU, 2, 2, 8, 8, colors.hudColor)
|
||||
graphics.rectangle(GPU, 3, 3, 6, 6, colors.workingColor)
|
||||
GPU.setActiveBuffer(0)
|
||||
end
|
||||
end
|
||||
function craftableBox(GPU, x, y)
|
||||
if currentWindows["Craft"] == nil then
|
||||
local crafts = G.createWindow(GPU, 72, 100, "Craft")
|
||||
currentWindows["Craft"].x = x
|
||||
currentWindows["Craft"].y = y
|
||||
local function craftableBox(GPU, x, y)
|
||||
if graphics.currentWindows["Craft"] == nil then
|
||||
local crafts = graphics.createWindow(GPU, 72, 100, "Craft")
|
||||
graphics.currentWindows["Craft"].x = x
|
||||
graphics.currentWindows["Craft"].y = y
|
||||
GPU.setActiveBuffer(crafts)
|
||||
G.rect(GPU, 2, 2, 70, 94, colors.hudColor)
|
||||
graphics.rectangle(GPU, 2, 2, 70, 94, colors.hudColor)
|
||||
GPU.setActiveBuffer(0)
|
||||
end
|
||||
GPU.setActiveBuffer(currentWindows["Craft"].page)
|
||||
G.rect(GPU, 3, 4, 68, 90, 0x000000)
|
||||
G.rect(GPU, 48, 2, 1, 94, colors.hudColor)
|
||||
GPU.setActiveBuffer(graphics.currentWindows["Craft"].page)
|
||||
graphics.rectangle(GPU, 3, 4, 68, 90, 0x000000)
|
||||
graphics.rectangle(GPU, 48, 2, 1, 94, colors.hudColor)
|
||||
local i = 1
|
||||
S.updateCache()
|
||||
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 toStock > 0 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
|
||||
G.text(GPU, 4, 3 + 2 * i, colors.negativeEUColor, label)
|
||||
graphics.text(GPU, 4, 3 + 2 * i, colors.negativeEUColor, label)
|
||||
else
|
||||
G.text(GPU, 4, 3 + 2 * i, 0xFFFFFF, label)
|
||||
graphics.text(GPU, 4, 3 + 2 * i, 0xFFFFFF, label)
|
||||
end
|
||||
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
|
||||
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
|
||||
--Add crafting request loop here
|
||||
if craftables[label] ~= nil then
|
||||
@ -238,26 +248,26 @@ function craftableBox(GPU, x, y)
|
||||
currentlyCrafting[label] = nil
|
||||
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
|
||||
G.text(GPU, 59, 3 + 2 * i, 0xFFFFFF, "| " .. amount)
|
||||
graphics.text(GPU, 59, 3 + 2 * i, 0xFFFFFF, "| " .. amount)
|
||||
i = math.min(i + 1, 43)
|
||||
end
|
||||
end
|
||||
end
|
||||
GPU.setActiveBuffer(0)
|
||||
G.refresh(GPU)
|
||||
graphics.refresh(GPU)
|
||||
end
|
||||
|
||||
mouseListener()
|
||||
keyboardListener()
|
||||
GPU.setResolution(160, 46)
|
||||
screen.clear()
|
||||
G.clear()
|
||||
term.clear()
|
||||
graphics.clear()
|
||||
numberBox(GPU, 100, 41)
|
||||
button(GPU, 150, 41)
|
||||
craftableBox(GPU, 0, 0)
|
||||
G.refresh(GPU)
|
||||
graphics.refresh(GPU)
|
||||
S.refreshCraftables()
|
||||
S.loadPatterns()
|
||||
local timeSinceRefresh = computer.uptime()
|
||||
|
@ -1,40 +1,36 @@
|
||||
comp = require("component")
|
||||
screen = require("term")
|
||||
component = require("component")
|
||||
term = require("term")
|
||||
computer = require("computer")
|
||||
event = require("event")
|
||||
thread = require("thread")
|
||||
sides = require("sides")
|
||||
get = require("utility")
|
||||
ARG = require("ARGraphics")
|
||||
G = require("graphics")
|
||||
local uc = require("unicode")
|
||||
tx = require("transforms")
|
||||
config = require("config")
|
||||
local GPU = comp.gpu
|
||||
graphics = require("graphics")
|
||||
local tx = require("transforms")
|
||||
GPU = component.gpu
|
||||
local interface = component.me_interface
|
||||
local sUtil = {}
|
||||
local itemsToStock = {}
|
||||
function sUtil.refreshCraftables()
|
||||
local c = comp.me_interface.getCraftables()
|
||||
local craftables = interface.getCraftables()
|
||||
local max = 0
|
||||
if max > 0 then
|
||||
c = tx.sub(c, 1, max)
|
||||
craftables = tx.sub(craftables, 1, max)
|
||||
end
|
||||
for i, craftable in pairs(c) do
|
||||
for i, craftable in pairs(craftables) do
|
||||
if i ~= "n" then
|
||||
if i % 10 == 0 then
|
||||
G.centeredText(
|
||||
graphics.centeredText(
|
||||
GPU,
|
||||
currentWindows["Number"].x + 25,
|
||||
currentWindows["Number"].y * 2 + 3,
|
||||
graphics.currentWindows["Number"].x + 25,
|
||||
graphics.currentWindows["Number"].y * 2 + 3,
|
||||
0xFFFFFF,
|
||||
"Discovering Patterns: " .. i .. " / " .. #c
|
||||
"Discovering Patterns: " .. i .. " / " .. #craftables
|
||||
)
|
||||
end
|
||||
end
|
||||
if craftable ~= #c then
|
||||
if craftable ~= #craftables then
|
||||
craftables[craftable.getItemStack().label] = craftable.request
|
||||
end
|
||||
end
|
||||
G.centeredText(GPU, 86, 85, 0xFFFFFF, "Patterns in memory: " .. #c)
|
||||
graphics.centeredText(GPU, 86, 85, 0xFFFFFF, "Patterns in memory: " .. #craftables)
|
||||
end
|
||||
local cachedAmounts = {}
|
||||
function sUtil.updateCache()
|
||||
|
Loading…
x
Reference in New Issue
Block a user