feat: enhance smelter tab event handling and optimize stock lookup logic
This commit is contained in:
@@ -858,6 +858,25 @@ local function buildSmelterPage()
|
|||||||
selectedBackgroundColor = colors.purple,
|
selectedBackgroundColor = colors.purple,
|
||||||
unselectedBackgroundColor = colors.gray,
|
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
|
-- Status tab
|
||||||
statusTab = UI.Tab {
|
statusTab = UI.Tab {
|
||||||
index = 1,
|
index = 1,
|
||||||
@@ -1094,17 +1113,7 @@ local function buildSmelterPage()
|
|||||||
},
|
},
|
||||||
|
|
||||||
eventHandler = function(self, event)
|
eventHandler = function(self, event)
|
||||||
if event.type == 'tab_change' then
|
if event.type == 'enable_all' 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
|
|
||||||
state.disabledRecipes = {}
|
state.disabledRecipes = {}
|
||||||
log.debug("UI", "All recipes enabled")
|
log.debug("UI", "All recipes enabled")
|
||||||
ops.saveDisabledRecipes()
|
ops.saveDisabledRecipes()
|
||||||
@@ -1246,22 +1255,24 @@ function D.refreshSmelterData()
|
|||||||
end
|
end
|
||||||
smelterPage.tabs.statusTab.grid:setValues(statusValues)
|
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 = {}
|
local recipeList = {}
|
||||||
for inputName, recipe in pairs(cfg.SMELTABLE) do
|
for inputName, recipe in pairs(cfg.SMELTABLE) do
|
||||||
local short = shortName(inputName)
|
local short = shortName(inputName)
|
||||||
local resultShort = shortName(recipe.result)
|
local resultShort = shortName(recipe.result)
|
||||||
local types = ""
|
local types = ""
|
||||||
if recipe.furnaceSet["minecraft:furnace"] then types = types .. "F" end
|
local fSet = recipe.furnaceSet or {}
|
||||||
if recipe.furnaceSet["minecraft:smoker"] then types = types .. "S" end
|
if fSet["minecraft:furnace"] then types = types .. "F" end
|
||||||
if recipe.furnaceSet["minecraft:blast_furnace"] then types = types .. "B" 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 enabled = not state.disabledRecipes[inputName]
|
||||||
local inStorage = 0
|
local inStorage = stockLookup[inputName] or 0
|
||||||
if cache.catalogue[inputName] then
|
|
||||||
for _, s in ipairs(cache.catalogue[inputName]) do
|
|
||||||
inStorage = inStorage + s.total
|
|
||||||
end
|
|
||||||
end
|
|
||||||
table.insert(recipeList, {
|
table.insert(recipeList, {
|
||||||
inputName = inputName,
|
inputName = inputName,
|
||||||
inputShort = short,
|
inputShort = short,
|
||||||
|
|||||||
Reference in New Issue
Block a user