Receive events from each key pressed in field and textarea (by @kilbith)
parent
c2622c1b75
commit
26bff3450e
|
@ -1914,6 +1914,7 @@ examples.
|
||||||
* Fields are a set height, but will be vertically centred on `h`
|
* Fields are a set height, but will be vertically centred on `h`
|
||||||
* Position and size units are inventory slots
|
* Position and size units are inventory slots
|
||||||
* `name` is the name of the field as returned in fields to `on_receive_fields`
|
* `name` is the name of the field as returned in fields to `on_receive_fields`
|
||||||
|
* `!name` to receive an event from each key pressed
|
||||||
* `label`, if not blank, will be text printed on the top left above the field
|
* `label`, if not blank, will be text printed on the top left above the field
|
||||||
* `default` is the default value of the field
|
* `default` is the default value of the field
|
||||||
* `default` may contain variable references such as `${text}'` which
|
* `default` may contain variable references such as `${text}'` which
|
||||||
|
|
|
@ -263,9 +263,14 @@ local function get_creative_formspec(player_name, start_i, pagenum, page, pagema
|
||||||
if page == "all" then
|
if page == "all" then
|
||||||
local inv = player_inventory[player_name] or {}
|
local inv = player_inventory[player_name] or {}
|
||||||
local filter = inv.filter or ""
|
local filter = inv.filter or ""
|
||||||
formspec = formspec .. "field_close_on_enter[search;false]"..
|
if minetest.is_singleplayer() then
|
||||||
"field[5.31,1.27;4.0,0.75;search;;"..filter.."]"..
|
formspec = formspec .. "field_close_on_enter[search;false]"..
|
||||||
"image_button[9.14,0.93;0.81,0.82;creative_search.png;creative_search;;;false]"
|
"field[5.31,1.27;4.0,0.75;!search;;"..filter.."]"
|
||||||
|
else
|
||||||
|
formspec = formspec .. "field_close_on_enter[search;false]"..
|
||||||
|
"field[5.31,1.27;4.0,0.75;search;;"..filter.."]"..
|
||||||
|
"image_button[9.14,0.93;0.81,0.82;creative_search.png;creative_search;;;false]"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if pagenum ~= nil then
|
if pagenum ~= nil then
|
||||||
formspec = formspec .. "p"..tostring(pagenum)
|
formspec = formspec .. "p"..tostring(pagenum)
|
||||||
|
|
|
@ -156,7 +156,11 @@ minetest.register_node("signs:sign", {
|
||||||
end,
|
end,
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("formspec", "field[text;;${sign_text}]")
|
if minetest.is_singleplayer() then
|
||||||
|
meta:set_string("formspec", "field[!text;Enter your text:;${sign_text}]")
|
||||||
|
else
|
||||||
|
meta:set_string("formspec", "field[text;Enter your text:;${sign_text}]")
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
on_destruct = function(pos)
|
on_destruct = function(pos)
|
||||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
||||||
|
@ -219,7 +223,11 @@ minetest.register_node("signs:wall_sign", {
|
||||||
drop = "signs:sign",
|
drop = "signs:sign",
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("formspec", "field[text;;${sign_text}]")
|
if minetest.is_singleplayer() then
|
||||||
|
meta:set_string("formspec", "field[!text;Enter your text:;${sign_text}]")
|
||||||
|
else
|
||||||
|
meta:set_string("formspec", "field[text;Enter your text:;${sign_text}]")
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
on_destruct = function(pos)
|
on_destruct = function(pos)
|
||||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
||||||
|
|
|
@ -1006,6 +1006,10 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,
|
||||||
std::string label = parts[1];
|
std::string label = parts[1];
|
||||||
std::string default_val = parts[2];
|
std::string default_val = parts[2];
|
||||||
|
|
||||||
|
bool is_dynamic = (name.length() > 0 && name[0] == '!');
|
||||||
|
if (is_dynamic)
|
||||||
|
name = name.substr(1);
|
||||||
|
|
||||||
core::rect<s32> rect;
|
core::rect<s32> rect;
|
||||||
|
|
||||||
if(data->explicit_size)
|
if(data->explicit_size)
|
||||||
|
@ -1032,6 +1036,8 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,
|
||||||
258+m_fields.size()
|
258+m_fields.size()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
spec.is_dynamic = is_dynamic;
|
||||||
|
|
||||||
if (name == "")
|
if (name == "")
|
||||||
{
|
{
|
||||||
// spec field id to 0, this stops submit searching for a value that isn't there
|
// spec field id to 0, this stops submit searching for a value that isn't there
|
||||||
|
@ -1094,6 +1100,10 @@ void GUIFormSpecMenu::parseTextArea(parserData* data, std::vector<std::string>&
|
||||||
std::string label = parts[3];
|
std::string label = parts[3];
|
||||||
std::string default_val = parts[4];
|
std::string default_val = parts[4];
|
||||||
|
|
||||||
|
bool is_dynamic = (name.length() > 0 && name[0] == '!');
|
||||||
|
if (is_dynamic)
|
||||||
|
name = name.substr(1);
|
||||||
|
|
||||||
MY_CHECKPOS(type,0);
|
MY_CHECKPOS(type,0);
|
||||||
MY_CHECKGEOM(type,1);
|
MY_CHECKGEOM(type,1);
|
||||||
|
|
||||||
|
@ -1135,6 +1145,8 @@ void GUIFormSpecMenu::parseTextArea(parserData* data, std::vector<std::string>&
|
||||||
258+m_fields.size()
|
258+m_fields.size()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
spec.is_dynamic = is_dynamic;
|
||||||
|
|
||||||
if (name == "")
|
if (name == "")
|
||||||
{
|
{
|
||||||
// spec field id to 0, this stops submit searching for a value that isn't there
|
// spec field id to 0, this stops submit searching for a value that isn't there
|
||||||
|
@ -3817,6 +3829,20 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.GUIEvent.EventType == gui::EGET_EDITBOX_CHANGED) {
|
||||||
|
if (event.GUIEvent.Caller->getID() > 257) {
|
||||||
|
for (GUIFormSpecMenu::FieldSpec &s : m_fields) {
|
||||||
|
if (s.ftype == f_Unknown && s.is_dynamic &&
|
||||||
|
s.fid == event.GUIEvent.Caller->getID()) {
|
||||||
|
s.send = true;
|
||||||
|
acceptInput();
|
||||||
|
s.send = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
|
if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
|
||||||
if (event.GUIEvent.Caller->getID() > 257) {
|
if (event.GUIEvent.Caller->getID() > 257) {
|
||||||
|
|
|
@ -214,7 +214,8 @@ class GUIFormSpecMenu : public GUIModalMenu
|
||||||
fid(id),
|
fid(id),
|
||||||
send(false),
|
send(false),
|
||||||
ftype(f_Unknown),
|
ftype(f_Unknown),
|
||||||
is_exit(false)
|
is_exit(false),
|
||||||
|
is_dynamic(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,6 +226,7 @@ class GUIFormSpecMenu : public GUIModalMenu
|
||||||
bool send;
|
bool send;
|
||||||
FormspecFieldType ftype;
|
FormspecFieldType ftype;
|
||||||
bool is_exit;
|
bool is_exit;
|
||||||
|
bool is_dynamic;
|
||||||
core::rect<s32> rect;
|
core::rect<s32> rect;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue