WorkStationUI: update
This commit is contained in:
@@ -4,23 +4,28 @@ local require = modInfo.require
|
|||||||
---@type Formspec
|
---@type Formspec
|
||||||
local Formspec = require('Formspec')
|
local Formspec = require('Formspec')
|
||||||
|
|
||||||
---@class WorkStationUI
|
---@type BaseUI
|
||||||
local WorkStationUI = {}
|
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({
|
local listForm = Formspec:new({
|
||||||
size = {x=10, y=8},
|
size = {x=16, y=8},
|
||||||
})
|
})
|
||||||
|
|
||||||
local listFormItems = Formspec:new()
|
local listFormItems = Formspec:new()
|
||||||
table.sort(items)
|
table.sort(outputs)
|
||||||
local w, h = 0, 0
|
local w, h = 0, 0
|
||||||
|
|
||||||
---@param name string
|
for result, craftName in pairs(outputs) do
|
||||||
for _, name in ipairs(items) do
|
listFormItems:itemImageButton(w, h, 2, 2, result, craftName..'::item_button')
|
||||||
listFormItems:itemImageButton(w, h, 2, 2, name, name..'::item_button')
|
|
||||||
|
|
||||||
w = w + 2
|
w = w + 2
|
||||||
|
|
||||||
@@ -34,7 +39,26 @@ function WorkStationUI:selectionCraftForm(items)
|
|||||||
scrollContainer(listFormItems, 0.5, 0.5, 8, 6, 'work_station:list_items', 'vertical'):
|
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')
|
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()
|
return listForm:toString()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@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
|
return WorkStationUI
|
||||||
Reference in New Issue
Block a user