diff --git a/manager/display.lua b/manager/display.lua index 97b8aed..1df1e90 100644 --- a/manager/display.lua +++ b/manager/display.lua @@ -858,6 +858,25 @@ local function buildSmelterPage() selectedBackgroundColor = colors.purple, unselectedBackgroundColor = colors.gray, + eventHandler = function(self, event) + if event.type == 'tab_change' then + local titleMap = { + Status = 'status', Smelt = 'smelt', + Craft = 'craft', Missing = 'missing', + } + if event.tab and event.tab.text then + smelterView = titleMap[event.tab.text] or smelterView + end + D.refreshSmelterData() + local page = self.parent + if page then + page.smelterFooter:draw() + page.bottomBar:draw() + end + end + return UI.Tabs.eventHandler(self, event) + end, + -- Status tab statusTab = UI.Tab { index = 1, @@ -1094,17 +1113,7 @@ local function buildSmelterPage() }, eventHandler = function(self, event) - if event.type == 'tab_change' then - local tabMap = { 'status', 'smelt', 'craft', 'missing' } - if event.current then - smelterView = tabMap[event.current] or smelterView - end - D.refreshSmelterData() - self.smelterFooter:draw() - self.bottomBar:draw() - -- fall through to default handler for tab switching - - elseif event.type == 'enable_all' then + if event.type == 'enable_all' then state.disabledRecipes = {} log.debug("UI", "All recipes enabled") ops.saveDisabledRecipes() @@ -1246,22 +1255,24 @@ function D.refreshSmelterData() end smelterPage.tabs.statusTab.grid:setValues(statusValues) - -- Smelt tab + -- Smelt tab: build stock lookup from itemList (works for both manager and client) + state.ensureItemList() + local stockLookup = {} + for _, item in ipairs(cache.itemList or {}) do + stockLookup[item.name] = item.total + end + local recipeList = {} for inputName, recipe in pairs(cfg.SMELTABLE) do local short = shortName(inputName) local resultShort = shortName(recipe.result) local types = "" - if recipe.furnaceSet["minecraft:furnace"] then types = types .. "F" end - if recipe.furnaceSet["minecraft:smoker"] then types = types .. "S" end - if recipe.furnaceSet["minecraft:blast_furnace"] then types = types .. "B" end + local fSet = recipe.furnaceSet or {} + if fSet["minecraft:furnace"] then types = types .. "F" end + if fSet["minecraft:smoker"] then types = types .. "S" end + if fSet["minecraft:blast_furnace"] then types = types .. "B" end local enabled = not state.disabledRecipes[inputName] - local inStorage = 0 - if cache.catalogue[inputName] then - for _, s in ipairs(cache.catalogue[inputName]) do - inStorage = inStorage + s.total - end - end + local inStorage = stockLookup[inputName] or 0 table.insert(recipeList, { inputName = inputName, inputShort = short,