From 338af14b6b344fa2d744d8e4d4415753c1eab0ec Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sun, 22 Mar 2026 01:56:15 -0400 Subject: [PATCH] Refactor drawing helpers to utilize shared UI module functions --- inventoryManager.lua | 46 ++++++++++---------------------------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/inventoryManager.lua b/inventoryManager.lua index c5cf9f2..fcc5753 100644 --- a/inventoryManager.lua +++ b/inventoryManager.lua @@ -679,47 +679,21 @@ local function smelterHitTest(x, y) end ------------------------------------------------- --- Drawing helpers (write to draw target) +-- Drawing helpers (delegated to shared ui module) ------------------------------------------------- -local draw = nil +local draw = nil -- set to window target before each draw cycle -local function monWrite(x, y, text, fg, bg) - draw.setCursorPos(x, y) - if fg then draw.setTextColor(fg) end - if bg then draw.setBackgroundColor(bg) end - draw.write(text) +local function setDrawTarget(target) + draw = target + ui.draw = target end -local function monFill(y, color) - local w, _ = draw.getSize() - draw.setCursorPos(1, y) - draw.setBackgroundColor(color) - draw.write(string.rep(" ", w)) -end - -local function monCenter(y, text, fg, bg) - local w, _ = draw.getSize() - local x = math.floor((w - #text) / 2) + 1 - monWrite(x, y, text, fg, bg) -end - -local function monBar(x, y, width, ratio, barColor, bgColor) - local filled = math.floor(ratio * width) - draw.setCursorPos(x, y) - draw.setBackgroundColor(barColor) - draw.write(string.rep(" ", filled)) - draw.setBackgroundColor(bgColor) - draw.write(string.rep(" ", width - filled)) -end - -local function drawButton(x, y, text, fg, bg, padLeft, padRight) - padLeft = padLeft or 1 - padRight = padRight or 1 - local full = string.rep(" ", padLeft) .. text .. string.rep(" ", padRight) - monWrite(x, y, full, fg, bg) - return x, y, x + #full - 1, y -end +local function monWrite(x, y, text, fg, bg) ui.monWrite(x, y, text, fg, bg) end +local function monFill(y, color) ui.monFill(y, color) end +local function monCenter(y, text, fg, bg) ui.monCenter(y, text, fg, bg) end +local function monBar(x, y, w, r, bc, bgc) ui.monBar(x, y, w, r, bc, bgc) end +local function drawButton(x, y, t, fg, bg, pl, pr) return ui.drawButton(x, y, t, fg, bg, pl, pr) end ------------------------------------------------- -- Dashboard (reads ONLY from cache — no peripheral calls — instant)