WorkStationUI: update

This commit is contained in:
Van
2026-02-18 22:18:30 +03:00
parent c70bf96734
commit 2eb7d04039

View File

@@ -4,23 +4,28 @@ local require = modInfo.require
---@type Formspec
local Formspec = require('Formspec')
---@class WorkStationUI
local WorkStationUI = {}
---@type BaseUI
local BaseUI = Mod.getInfo('smc__core__base_ui').require('BaseUI')
---@param self BaseUI
---@param playerName string
---@param isSelect boolean
---@return string
local function getFormSpecString(self, playerName, isSelect)
local outputs = self:getContex(playerName, 'outputs')
---@type CraftSystem.ImmersiveCraft
local craft = self:getContex(playerName, 'craft')
---@param items string[]
---@return string
function WorkStationUI:selectionCraftForm(items)
local listForm = Formspec:new({
size = {x=10, y=8},
size = {x=16, y=8},
})
local listFormItems = Formspec:new()
table.sort(items)
table.sort(outputs)
local w, h = 0, 0
---@param name string
for _, name in ipairs(items) do
listFormItems:itemImageButton(w, h, 2, 2, name, name..'::item_button')
for result, craftName in pairs(outputs) do
listFormItems:itemImageButton(w, h, 2, 2, result, craftName..'::item_button')
w = w + 2
@@ -34,7 +39,26 @@ function WorkStationUI:selectionCraftForm(items)
scrollContainer(listFormItems, 0.5, 0.5, 8, 6, 'work_station:list_items', 'vertical'):
scrollbar(8, 0.5, 0.25, 7, 'vertical', 'work_station:list_items')
if isSelect then
local stage = craft.stagesByName[craft.startStageName]
local outputDef = core.registered_nodes[craft.output]
listForm:
itemImage(9, 0.5, 2, 2, craft.output):
areaLabel(9, 6, 2, 1, 'Start crafting:'):
button(9, 6.5, 3, 1, 'work_station:start_craft', 'x1'):
button(12, 6.5,3, 1, 'work_station:start_craft', 'x10'):
areaLabel(11.5, 0.5, 4, 4,
outputDef._title..'\n'..
outputDef._description):
areaLabel(9, 2.5, 6, 4, 'Craft description:'..'\n'..craft:toString())
end
return listForm:toString()
end
return WorkStationUI
---@class WorkStationUI : BaseUI
---@field getFormSpecString fun(self:BaseUI,playerName:string,isSelect:boolean):string
---@field showForm fun(self:BaseUI,playerName:string,isSelect:boolean):string
local WorkStationUI = BaseUI:new('work_station:selection_craft', getFormSpecString)
return WorkStationUI