Compare commits
2 Commits
4a8a6245a6
...
f60faa4293
| Author | SHA1 | Date | |
|---|---|---|---|
| f60faa4293 | |||
| c902aff4af |
@@ -509,7 +509,7 @@ end
|
|||||||
---@return Formspec
|
---@return Formspec
|
||||||
function Formspec:field(x, y, w, h, name, label, default)
|
function Formspec:field(x, y, w, h, name, label, default)
|
||||||
local element = ('field[%s,%s;%s,%s;%s;%s;%s]'):format(
|
local element = ('field[%s,%s;%s,%s;%s;%s;%s]'):format(
|
||||||
x, y, w, h, name, label or '', default or '')
|
x, y, w, h, name, label or '', core.formspec_escape(default) or '')
|
||||||
|
|
||||||
self:addElement(element)
|
self:addElement(element)
|
||||||
return self
|
return self
|
||||||
@@ -590,7 +590,7 @@ end
|
|||||||
---@return Formspec
|
---@return Formspec
|
||||||
function Formspec:textArea(x, y, w, h, name, label, default)
|
function Formspec:textArea(x, y, w, h, name, label, default)
|
||||||
local element = ('textarea[%s,%s;%s,%s;%s;%s;%s]'):format(
|
local element = ('textarea[%s,%s;%s,%s;%s;%s;%s]'):format(
|
||||||
x, y, w, h, name or '', label or '', default or '')
|
x, y, w, h, name or '', label or '', core.formspec_escape(default) or '')
|
||||||
|
|
||||||
self:addElement(element)
|
self:addElement(element)
|
||||||
return self
|
return self
|
||||||
@@ -610,7 +610,7 @@ end
|
|||||||
---@return Formspec
|
---@return Formspec
|
||||||
function Formspec:label(x, y, label)
|
function Formspec:label(x, y, label)
|
||||||
local element = ('label[%s,%s;%s]'):format(
|
local element = ('label[%s,%s;%s]'):format(
|
||||||
x, y, label)
|
x, y, core.formspec_escape(label))
|
||||||
|
|
||||||
self:addElement(element)
|
self:addElement(element)
|
||||||
return self
|
return self
|
||||||
@@ -630,7 +630,7 @@ end
|
|||||||
---@return Formspec
|
---@return Formspec
|
||||||
function Formspec:areaLabel(x, y, w, h, label)
|
function Formspec:areaLabel(x, y, w, h, label)
|
||||||
local element = ('label[%s,%s;%s,%s;%s]'):format(
|
local element = ('label[%s,%s;%s,%s;%s]'):format(
|
||||||
x, y, w, h, label)
|
x, y, w, h, core.formspec_escape(label))
|
||||||
|
|
||||||
self:addElement(element)
|
self:addElement(element)
|
||||||
return self
|
return self
|
||||||
@@ -664,7 +664,7 @@ end
|
|||||||
---@return Formspec
|
---@return Formspec
|
||||||
function Formspec:vertlabel(x, y, label)
|
function Formspec:vertlabel(x, y, label)
|
||||||
local element = ('vertlabel[%s,%s;%s]'):format(
|
local element = ('vertlabel[%s,%s;%s]'):format(
|
||||||
x, y, label)
|
x, y, core.formspec_escape(label))
|
||||||
|
|
||||||
self:addElement(element)
|
self:addElement(element)
|
||||||
return self
|
return self
|
||||||
|
|||||||
@@ -7,14 +7,43 @@ local PrimitiveCraftHandler = Smc.requireCraftSystemPrimitiveCraftHandler()
|
|||||||
|
|
||||||
local Formspec = Smc.requireFormspec()
|
local Formspec = Smc.requireFormspec()
|
||||||
|
|
||||||
|
---A text indicator of the presence or absence
|
||||||
|
---of a material in the player's inventory.
|
||||||
|
local CHECK = {YES = 'x', NO = ' '}
|
||||||
|
|
||||||
|
---@param inventory InvRef
|
||||||
|
---@param material ItemStack
|
||||||
|
---@return string
|
||||||
|
local function getCheckMaterialItem(inventory, material)
|
||||||
|
if inventory:contains_item('main', material) then
|
||||||
|
return CHECK.YES
|
||||||
|
else
|
||||||
|
return CHECK.NO
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param inventory InvRef
|
||||||
|
---@param material string
|
||||||
|
---@return string
|
||||||
|
local function getCheckMaterialGroup(inventory, material)
|
||||||
|
for _, item in ipairs(inventory:get_list('main')) do
|
||||||
|
if core.get_item_group(item:get_name(), material) > 0 then
|
||||||
|
return CHECK.YES
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return CHECK.NO
|
||||||
|
end
|
||||||
|
|
||||||
---Returns a human-readable list of materials required for crafting (recipe).
|
---Returns a human-readable list of materials required for crafting (recipe).
|
||||||
|
---@param inventory InvRef
|
||||||
---@param craft CraftSystem.PrimitiveCraft
|
---@param craft CraftSystem.PrimitiveCraft
|
||||||
---@param index integer Recipe number. If `0` is specified,
|
---@param index integer Recipe number. If `0` is specified,
|
||||||
--- the primary craft (`craft.recipe`) will be used;
|
--- the primary craft (`craft.recipe`) will be used;
|
||||||
--- if `1` or greater, the alternative craft
|
--- if `1` or greater, the alternative craft
|
||||||
--- corresponding to the index will be used (`craft.altRecipes`).
|
--- corresponding to the index will be used (`craft.altRecipes`).
|
||||||
---@return string
|
---@return string
|
||||||
local function getRecipeDesc(craft, index)
|
local function getRecipeDesc(inventory, craft, index)
|
||||||
local recipe
|
local recipe
|
||||||
if index == 0 or craft.altRecipes == nil then
|
if index == 0 or craft.altRecipes == nil then
|
||||||
recipe = craft.recipe
|
recipe = craft.recipe
|
||||||
@@ -33,9 +62,9 @@ local function getRecipeDesc(craft, index)
|
|||||||
|
|
||||||
if group == nil then
|
if group == nil then
|
||||||
local recipeItem = ItemStack(itemName)
|
local recipeItem = ItemStack(itemName)
|
||||||
recipeDesc = recipeDesc..'- '..core.strip_colors(recipeItem:get_definition()._title)..' x'..recipeItem:get_count()..'\n'
|
recipeDesc = recipeDesc..('[%s] %s x%s\n'):format(getCheckMaterialItem(inventory, recipeItem), core.strip_colors(recipeItem:get_definition()._title), recipeItem:get_count())
|
||||||
else
|
else
|
||||||
recipeDesc = recipeDesc..'- any item from the group "'..group..'" x'..count..'\n'
|
recipeDesc = recipeDesc..('[%s] any item from the group %s x%s\n'):format(getCheckMaterialGroup(inventory, group), group, count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -89,7 +118,7 @@ local function getCraftTab(self, playerName, tabType)
|
|||||||
|
|
||||||
local w, h = 0.0, 0.0
|
local w, h = 0.0, 0.0
|
||||||
|
|
||||||
if selectedGroup ~= nil then
|
if selectedGroup ~= nil and (searchFieldValue == nil or searchFieldValue == '') then
|
||||||
craftsListForm
|
craftsListForm
|
||||||
:imageButton(0, 0, 1.125, 1.125, 'player_inventory_craft_tab_close_group_button_background.png', tabType..'::close_group')
|
:imageButton(0, 0, 1.125, 1.125, 'player_inventory_craft_tab_close_group_button_background.png', tabType..'::close_group')
|
||||||
w = 1.125
|
w = 1.125
|
||||||
@@ -152,7 +181,9 @@ local function getCraftTab(self, playerName, tabType)
|
|||||||
self:setContex(playerName, tabType..'_tab_craft_selected_recipe_index', #craft.altRecipes)
|
self:setContex(playerName, tabType..'_tab_craft_selected_recipe_index', #craft.altRecipes)
|
||||||
end
|
end
|
||||||
|
|
||||||
local recipeDesc = getRecipeDesc(craft, recipeIndex)
|
local player = core.get_player_by_name(playerName)
|
||||||
|
assert(player ~= nil)
|
||||||
|
local recipeDesc = getRecipeDesc(player:get_inventory(), craft, recipeIndex)
|
||||||
|
|
||||||
CraftTab
|
CraftTab
|
||||||
:itemImage(5.5, 0.5, 2, 2, craft.output)
|
:itemImage(5.5, 0.5, 2, 2, craft.output)
|
||||||
|
|||||||
Reference in New Issue
Block a user