88 lines
1.8 KiB
Lua
88 lines
1.8 KiB
Lua
local modInfo = Mod.getInfo('smc__core__formspec')
|
|
local require = modInfo.require
|
|
|
|
---@type Formspec
|
|
local Formspec = require('Formspec')
|
|
|
|
local function getForm()
|
|
local listForm = Formspec:new({
|
|
size = {x=21, y=12},
|
|
})
|
|
|
|
listForm:list('current_player', 'main', 10.5, 6.5, 8, 4)
|
|
|
|
local listFormItems = Formspec:new()
|
|
|
|
local items = table.get_keys(core.registered_nodes)
|
|
table.sort(items)
|
|
local w, h = 0, 0
|
|
|
|
---@param name string
|
|
for _, name in ipairs(items) do
|
|
listFormItems:itemImageButton(w, h, 1, 1, name, name..'::item_button')
|
|
|
|
w = w + 1
|
|
|
|
if w >= 9 then
|
|
w = 0
|
|
h = h + 1
|
|
end
|
|
end
|
|
|
|
--listFormItems:list('current_player', 'main', 0, 0, 1, 32)
|
|
|
|
listForm:
|
|
scrollContainer(listFormItems, 0.5, 0.5, 9, 11, 'admin_commands:list_items', 'vertical'):
|
|
scrollbar(10, 0.5, 0.25, 10, 'vertical', 'admin_commands:list_items')
|
|
|
|
return listForm
|
|
end
|
|
|
|
core.register_chatcommand('list', {
|
|
privs = {server = true},
|
|
|
|
func = function(name, param)
|
|
local player = core.get_player_by_name(name)
|
|
|
|
core.show_formspec(name, 'admin_commands:list_form', getForm():toString())
|
|
|
|
return true, ''
|
|
end
|
|
})
|
|
|
|
core.register_on_player_receive_fields(function(player, formname, fields)
|
|
if formname ~= 'admin_commands:list_form' then
|
|
return
|
|
end
|
|
|
|
for key, value in pairs(fields) do
|
|
if string.ends_with(key, '::item_button') then
|
|
---@type ItemStackString?
|
|
local stack = string.match(key, '(%S+)::item_button')
|
|
|
|
if stack == nil then
|
|
return
|
|
end
|
|
|
|
core.log(tostring(stack))
|
|
|
|
---@type InvRef
|
|
local inv = player:get_inventory()
|
|
|
|
if inv:room_for_item("main", stack) then
|
|
inv:add_item("main", stack)
|
|
end
|
|
end
|
|
end
|
|
end)
|
|
|
|
core.register_on_joinplayer(function(player, last_login)
|
|
player:set_sky({
|
|
sky_color = {
|
|
day_sky = '#F1DAC0',
|
|
day_horizon = '#F1B795',
|
|
},
|
|
type = "regular",
|
|
})
|
|
end)
|