Module:UI
Documentation for this module may be created at Module:UI/doc
local slot = require( [[Module:Inventory slot]] ).slot
local function addSlot(args, item, prefix, class, default)
local none, nostacksize
prefix = prefix or ''
if #prefix == 0 then
none = 'none'
nostacksize = ((item == '' or nil) and '') or (args and args[item] and args[item]:gsub('[,%d]', '') or '')
end
return slot{
nostacksize or args[item], mod = args.Mod, link = none or args[prefix .. 'link'],
title = none or args[prefix .. 'title'], class = class, default = default,
parsed = args.parsed, forcenum = args.forcenum
}
end
local p = {}
-- Crafting table
function p.craftingTable(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
local body = mw.html.create('span'):addClass('mcui mcui-Crafting_Table pixel-image')
-- CUSTOM: changing grid to use <table> since wikia mobile doesn't support CSS
local input = body:tag('table'):addClass('mcui-input')
for num = 1, 3 do
local row = input:tag('tr'):addClass('mcui-row')
for _, letter in ipairs{ 'A', 'B', 'C' } do
local td = row:tag('td')
td:wikitext(addSlot(args, letter .. num, 'I'))
end
end
local arrow = body:tag('span'):addClass('mcui-arrow'):tag('br'):done()
if args.arrow or '' ~= '' then
arrow:css(
'background-image',
'{{FileUrl|' .. args.arrow .. ' (' .. args.Mod .. ').png}}'
)
end
body
:tag('span')
:addClass('mcui-output')
:wikitext(addSlot(args, 'Output', 'O', 'invslot-large'))
local shapeless = args.shapeless or ''
local fixed = args.fixed or ''
if shapeless ~= '' or fixed ~= '' then
local icon = body:tag('span')
:addClass('mcui-icons')
:tag('span')
:tag('br')
:done()
if shapeless ~= '' then
icon:addClass('mcui-shapeless')
:attr('title',
'This recipe is shapeless, the inputs may be placed in any arrangement in the crafting grid.'
)
elseif fixed ~= '' then
local notFixed = args.notfixed or ''
local exceptFixed = ''
if notFixed ~= '' then
exceptFixed = '; except for ' .. notFixed .. ', which can go anywhere'
end
icon:addClass('mcui-fixed')
:attr('title',
'This recipe is fixed, the input arrangement may not be moved or mirrored in the crafting grid' .. exceptFixed .. '.'
)
end
end
return tostring(mw.html.create('div'):node(body))
end
-- Furnace
function p.furnace(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
local body = mw.html.create('span'):addClass('mcui mcui-Furnace pixel-image')
local input = body:tag('span'):addClass('mcui-input')
input:wikitext(addSlot(args, 'Input', 'I'))
local fuel = input:tag('span'):addClass('mcui-fuel'):tag('br'):done()
local fuelImg = args.FuelUsage or ''
local burning = args.Input or '' ~= '' and args.Fuel or '' ~= ''
if not burning then
fuel:addClass('mcui-inactive')
if fuelImg ~= '' then
fuelImg = fuelImg .. ' (in-active)'
end
end
if fuelImg ~= '' then
fuel:css(
'background-image',
'{{FileUrl|' .. fuelImg .. ' (' .. args.Mod .. ').png}}'
)
end
input:wikitext(addSlot(args, 'Fuel', 'F'))
local arrow = body:tag('span'):addClass('mcui-arrow'):tag('br'):done()
local arrowImg = args.Progress or ''
if not burning or (args.Output or '') == '' then
arrow:addClass('mcui-inactive')
if arrowImg ~= '' then
arrowImg = arrowImg .. ' (in-active)'
end
end
if arrowImg ~= '' then
arrow:css(
'background-image',
'{{FileUrl|' .. arrowImg .. ' Progress (' .. args.Mod .. ').png}}'
)
end
body
:tag('span')
:addClass('mcui-output')
:wikitext(addSlot(args, 'Output', 'O', 'invslot-large'))
return tostring(mw.html.create('div'):node(body))
end
-- Brewing Stand
function p.brewingStand(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
local body = mw.html.create('span'):addClass('mcui mcui-Brewing_Stand pixel-image')
local input = body:tag('span'):addClass('mcui-input')
input:tag('span'):addClass('mcui-bubbling'):tag('br')
input:wikitext(addSlot(args, 'Input', 'I'))
input:tag('span'):addClass('mcui-arrow'):tag('br')
if (args.Input or '') == '' or
((args.Output1 or '') == '' and (args.Output2 or '') == '' and (args.Output3 or '') == '')
then
input:addClass('mcui-inactive')
end
body:tag('span'):addClass('mcui-paths'):tag('br')
local output = body:tag('span'):addClass('mcui-output')
for i = 1, 3 do
output:wikitext(addSlot(args, 'Output' .. i, 'O' .. i, 'mcui-output' .. i))
end
return tostring(mw.html.create('div'):node(body))
end
-- Stonecutter
function p.stonecutter(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
local body = mw.html.create('span'):addClass('mcui mcui-Stonecutter pixel-image')
local input = body:tag('span'):addClass('mcui-input')
input:wikitext(addSlot(args, 'Input', 'I'))
local arrow = body:tag('span'):addClass('mcui-stonecutterArrow')
if (args.arrow or '') ~= '' then
arrow:css(
'background-image',
'{{FileUrl|' .. args.arrow .. ' (' .. args.Mod .. ').png}}'
)
end
arrow:wikitext(addSlot(args, 'Output', '', 'invslot-plain mcui-stonecutterSprite'))
body
:tag('span')
:addClass('mcui-output')
:wikitext(addSlot(args, 'Output', 'O', 'invslot-large'))
return tostring(mw.html.create('div'):node(body))
end
-- Loom
function p.loom(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
local body = mw.html.create('span'):addClass('mcui mcui-Loom pixel-image')
local tapestry = body:tag('span'):addClass('mcui-tapestry')
if args.Banner and #args.Banner>0 then
tapestry:wikitext(addSlot(args, 'Banner', 'B', 'mcui-inputBanner'))
end
if args.Dye and #args.Dye>0 then
tapestry:wikitext(addSlot(args, 'Dye', 'D', 'mcui-inputDye'))
end
if args.Pattern and #args.Pattern>0 then
tapestry:wikitext(addSlot(args, 'Pattern', 'P', 'mcui-inputPattern'))
end
tapestry:tag('span'):tag('br'):done()
local arrow = body:tag('span'):addClass('mcui-loomArrow')
if args.arrow or '' ~= '' then
arrow:css(
'background-image',
'{{FileUrl|' .. args.arrow .. ' (' .. args.Mod .. ').png}}'
)
end
local sprite = args.Sprite
local bannerSprite
if sprite and #sprite>0 then
local animate = require([[Module:AnimateSprite]]).animate
bannerSprite = animate{
args.Sprite,
sheet = 'SlotSprite'
}
else
bannerSprite = '<br>'
end
arrow
:tag('span')
:addClass('mcui-bannerSprite')
:wikitext(bannerSprite)
body
:tag('span')
:addClass('mcui-output')
:wikitext(addSlot(args, 'Output', 'O', 'invslot-large'))
return tostring(mw.html.create('div'):node(body))
end
-- Grindstone
function p.grindstone(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
local body = mw.html.create('span'):addClass('mcui mcui-Grindstone pixel-image')
local grindstone = body:tag('span'):addClass('mcui-grindstone')
grindstone:wikitext(addSlot(args, 'Input1', 'I1', 'mcui-input1'))
grindstone:wikitext(addSlot(args, 'Input2', 'I2', 'mcui-input2'))
local arrow = body:tag('span'):addClass('mcui-arrow')
if args.arrow or '' ~= '' then
arrow:css(
'background-image',
'{{FileUrl|' .. args.arrow .. ' (' .. args.Mod .. ').png}}'
)
end
body
:tag('span')
:addClass('mcui-output')
:wikitext(addSlot(args, 'Output', 'O', 'invslot-large'))
return tostring(mw.html.create('div'):node(body))
end
-- Crushing Wheel
function p.crushingWheel(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
local body = mw.html.create('span'):addClass('mcui mcui-Crushing_Wheel pixel-image')
local input = body
:tag('span')
:addClass('mcui-input')
:tag('div')
:addClass('mcui-input')
:wikitext(addSlot(args, 'Input', 'I'))
:tag('div'):addClass('mcui-arrow-bent'):done()
:done()
:tag('div'):addClass('mcui-crushingwheel'):done()
local output = body
:tag('div')
:addClass('mcui-output')
local i = 1
while args['Output'..i] do
output
:tag('span')
:tag('span')
:wikitext(addSlot(args, 'Output'..i, 'O'..i))
:done()
:tag('span')
:addClass(args['Chance'..i or 'C'..i] and 'mcui-text' or 'mcui-text mcui-text-nondisplay')
:wikitext(args['Chance'..i or 'C'..i] or 'nil')
:done()
:done()
:done()
i = i + 1
end
return tostring(mw.html.create('div'):node(body))
end
--Bulk Washing
function p.bulkWashing(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
return p.commonMachine{
args,
manyInputs=false,
manyOutputs=true,
allowChance=true,
slot='Bulk Washing',
paddingtop = '14px',
paddingtop2 = '20px'
}
end
--Bulk Smoking
function p.bulkSmoking(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
return p.commonMachine{
args,
manyInputs=false,
manyOutputs=true,
allowChance=false,
slot='Bulk Smoking',
paddingtop = '14px',
paddingtop2 = '20px'
}
end
--Bulk Blasting
function p.bulkBlasting(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
return p.commonMachine{
args,
manyInputs=false,
manyOutputs=true,
allowChance=false,
slot='Bulk Blasting',
paddingtop = '14px',
paddingtop2 = '20px'
}
end
--Mechanical Mixer
function p.mechanicalMixer(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
if args.type:lower() == 'crafting' or args.type:lower() == 'shapeless' then
return p.commonMachine{
args,
manyInputs=true,
manyOutputs=false,
allowChance=false,
slot='Mechanical Mixer Crafting',
paddingtop = '14px'
}
elseif args.type:lower() == 'mixing' then
return p.commonMachine{
args,
manyInputs=true,
manyOutputs=false,
allowChance=false,
slot='Mechanical Mixer Mixing',
paddingtop = '14px'
}
elseif args.type:lower() == 'brewing' then
return p.commonMachine{
args,
manyInputs=true,
manyOutputs=false,
allowChance=false,
slot='Mechanical Mixer Brewing',
paddingtop = '14px'
}
else
return '<strong><font color="red">Template error: invalid type specified</font></strong>'
end
end
--Mechanical Press
function p.mechanicalPress(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
if args.type:lower() == 'crafting' or args.type:lower() == 'packing' then
return p.commonMachine{
args,
inputIs2d=true,
manyOutputs=false,
allowChance=false,
slot='Mechanical Press Crafting',
paddingtop = '5px',
paddingbottom = '5px',
}
elseif args.type:lower() == 'compacting' then
return p.commonMachine{
args,
manyInputs=false,
manyOutputs=true,
allowChance=true,
slot='Mechanical Press Compacting',
paddingtop = '14px',
paddingtop2 = '20px'
}
elseif args.type:lower() == 'pressing' then
return p.commonMachine{
args,
manyInputs=false,
manyOutputs=false,
allowChance=false,
slot='Mechanical Press Pressing',
paddingtop = '14px'
}
else
return '<strong><font color="red">Template error: invalid type specified</font></strong>'
end
end
-- Millstone
function p.millstone(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
return p.commonMachine{
args,
manyInputs=false,
manyOutputs=true,
allowChance=true,
slot='Milling',
paddingtop = '14px',
paddingtop2 = '20px'
}
end
-- Common Machines
function p.commonMachine(options)
local args = options[1]
local body = mw.html.create('span'):addClass('mcui mcui-Common_Machines pixel-image')
local input
local i = 1
local classAddedByGrid
if options.inputIs2d then
classAddedByGrid = args.smallgrid and 'two' or 'three'
input = body:tag('table'):addClass('mcui-input')
if args.smallgrid then
for num = 1, 2 do
local row = input:tag('tr'):addClass('mcui-row')
for _, letter in ipairs{ 'A', 'B' } do
local td = row:tag('td')
td:wikitext(addSlot(args, letter .. num, 'I'))
end
end
else
for num = 1, 3 do
local row = input:tag('tr'):addClass('mcui-row')
for _, letter in ipairs{ 'A', 'B', 'C' } do
local td = row:tag('td')
td:wikitext(addSlot(args, letter .. num, 'I'))
end
end
end
else
input = body
:tag('span')
:addClass('mcui-input')
while args['Input'..i] or args['I'..i] or (i == 1 and (args['Input'] or args['I'])) do
local iItem = options.manyInputs and (args['Input'..i] or args['I'..i]) or nil
local item = i == 1 and (args['Input'] or args['I'] or iItem) or iItem
input = addSlotElement(input, item)
i = i + 1
end
end
local middle = body
:tag('div')
:addClass(classAddedByGrid and 'mcui-middle '..classAddedByGrid or 'mcui-middle')
:tag('div'):addClass(options.arrowclass or 'mcui-arrow-long'):done()
:tag('div')
:wikitext(slot{
options.slot,
class = 'invslot-noformat'
})
:done()
:done()
local output = body
:tag('div')
:addClass('mcui-output')
local isChance = false
if options.allowChance == nil then options.allowChance = true end
if options.allowChance then
for j=1,50,1 do
if args['Chance'..j] or args['C'..j] then
isChance = true
break
end
end
end
i = 1
while args['Output'..i] or args['O'..i] or (i == 1 and (args['Output'] or args['O'])) do
local iItem = options.manyOutputs and (args['Output'..i] or args['O'..i]) or nil
local item = i == 1 and (args['Output'] or args['O'] or iItem) or iItem
local chance = i == 1 and (args['Chance'] or args['C'] or args['Chance'..i] or args['C'..i]) or (args['Chance'..i] or args['C'..i])
output = addSlotElement(output, item, chance, isChance and options.allowChance)
i = i + 1
end
if isChance then
if options.paddingbottom then
body:css{
['padding-top'] = options.paddingtop or '20px',
['padding-bottom'] = options.paddingbottom or '0'
}
else
body:css{['padding-top'] = options.paddingtop or '20px'}
end
else
if options.paddingbottom then
body:css{
['padding-top'] = options.paddingtop or '14px',
['padding-bottom'] = options.paddingbottom or '0'
}
else
body:css{['padding-top'] = options.paddingtop or '14px'}
end
end
return tostring(mw.html.create('div'):node(body))
end
function addSlotElement(element, item, chance, allowChance)
if allowChance then
element
:css{['top']='9px'}
:tag('span')
:tag('span')
:wikitext(slot{item})
:done()
:tag('span')
:addClass(chance and 'mcui-text' or 'mcui-text mcui-text-nondisplay')
:wikitext(chance or 'nil')
:done()
:done()
:done()
else
element
:tag('span')
:wikitext(slot{item})
:done()
:done()
end
return element
end
return p