added some specs

This commit is contained in:
tour 2024-01-03 13:50:20 +01:00
commit ec41200bb3
5 changed files with 86 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea*

8
init.lua Normal file
View File

@ -0,0 +1,8 @@
chat_formspec = {}
local modpath = minetest.get_modpath(minetest.get_current_modname())
dofile(modpath .. "/predefined_formspecs.lua")
dofile(modpath .. "/specs.lua")

2
mod.conf Normal file
View File

@ -0,0 +1,2 @@
name = chat_formspec
description = allows to send formspecs (predefined or created on the fly) to players

19
predefined_formspecs.lua Normal file
View File

@ -0,0 +1,19 @@
chat_formspec.predefined = {
replant_farm = {
fs = "",
replacements = {
}
},
default = {
fs = [[
field[1.1,6.8;10.7,0.8;answer;Your answer;]
button_exit[12.1,6.8;3,0.8;submit;submit]
button[12.1,0.7;3,0.8;chat_help;How to chat?]
label[1.2,1.1;We tried to contact you via chat already\, but you did not respond]
textarea[1.2,2;13.8,4.2;;;%s]
]],
replacement = [[You have shown behavior about which we have some questions for reasons of moderation.\
It would be nice if you could answer them. Otherwise we will unfortunately have to resort to other means.]]
}
}

56
specs.lua Normal file
View File

@ -0,0 +1,56 @@
local function create_selection_formspec()
local fs = [[
formspec_version[6]
size[16,12]
dropdown[2.6,2.8;5.9;select;%s;0;true]
button[9.5,2.8;3,0.8;template;use this template]
]]
local dropdown_items = ""
for name, _ in pairs(chat_formspec.predefined) do
dropdown_items = dropdown_items .. name .. ","
end
fs = string.format(fs, string.sub(dropdown_items, 1, -2))
return fs
end
chat_formspec.selection_fs = create_selection_formspec()
chat_formspec.create_new = [[
formspec_version[6]
size[16,12]
textarea[1,0.5;13.7,2.4;;;to create formspecs
https://luk3yx.gitlab.io/minetest-formspec-editor/
might be very useful.
Please make sure the field the player should answer with has the name "answer"]
textarea[0.8,3.4;14,5.4;c_fs;your custom formspec;]
textarea[0.8,8.9;13.7,1.1;;;There is no validation check done for this formspec.
If you are not sure wheter it looks correct\, consider sending it to yourself]
button[0.8,10.5;3,0.8;back;Back]
field[7.8,10.5;3,0.8;target;send to player;]
button[11.7,10.5;3,0.8;send;Send]
]]
chat_formspec.predefined_template = [[
formspec_version[6]
size[16,12]
box[0.8,0.4;14.6,7.7;gray]
%s
button[1,10.8;3,0.8;back;Back]
button[12.4,10.7;3,0.9;send;Send]
textarea[0.8,8.6;14.6,1.8;change_text;change default text;default text]
button[4.7,10.8;3,0.8;change_text;change text]
field[8.8,10.9;3,0.8;target;send to player;]
]]
function chat_formspec.get_predefined_template(id, replacement)
local predefined = chat_formspec.predefined[id].fs
local replacement = replacement or chat_formspec.predefined[id].replacement
predefined = string.format(predefined, replacement)
local fs = string.format(chat_formspec.predefined_template, predefined)
return fs
end