mirror of
https://github.com/minetest/minetest.git
synced 2024-09-12 00:26:50 +02:00
Mainmenu: Use textarea in error formspecs
This commit is contained in:
parent
ec3142af99
commit
3ceef8e6a0
@ -54,52 +54,39 @@ end
|
|||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
local function wordwrap_quickhack(str)
|
|
||||||
local res = ""
|
|
||||||
local ar = str:split("\n")
|
|
||||||
for i = 1, #ar do
|
|
||||||
local text = ar[i]
|
|
||||||
-- Hack to add word wrapping.
|
|
||||||
-- TODO: Add engine support for wrapping in formspecs
|
|
||||||
while #text > 80 do
|
|
||||||
if res ~= "" then
|
|
||||||
res = res .. ","
|
|
||||||
end
|
|
||||||
res = res .. core.formspec_escape(string.sub(text, 1, 79))
|
|
||||||
text = string.sub(text, 80, #text)
|
|
||||||
end
|
|
||||||
if res ~= "" then
|
|
||||||
res = res .. ","
|
|
||||||
end
|
|
||||||
res = res .. core.formspec_escape(text)
|
|
||||||
end
|
|
||||||
return res
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
function ui.update()
|
function ui.update()
|
||||||
local formspec = ""
|
local formspec = {}
|
||||||
|
|
||||||
-- handle errors
|
-- handle errors
|
||||||
if gamedata ~= nil and gamedata.reconnect_requested then
|
if gamedata ~= nil and gamedata.reconnect_requested then
|
||||||
formspec = wordwrap_quickhack(gamedata.errormessage or "")
|
local error_message = core.formspec_escape(
|
||||||
formspec = "size[12,5]" ..
|
gamedata.errormessage or "<none available>")
|
||||||
"label[0.5,0;" .. fgettext("The server has requested a reconnect:") ..
|
formspec = {
|
||||||
"]textlist[0.2,0.8;11.5,3.5;;" .. formspec ..
|
"size[14,8]",
|
||||||
"]button[6,4.6;3,0.5;btn_reconnect_no;" .. fgettext("Main menu") .. "]" ..
|
"real_coordinates[true]",
|
||||||
"button[3,4.6;3,0.5;btn_reconnect_yes;" .. fgettext("Reconnect") .. "]"
|
("textarea[0.5,1.2;13,5;;%s;%s]"):format(
|
||||||
|
fgettext("The server has requested a reconnect:"), error_message),
|
||||||
|
"box[0.5,1.2;13,5;#000]",
|
||||||
|
"button[2,6.6;4,1;btn_reconnect_yes;" .. fgettext("Reconnect") .. "]",
|
||||||
|
"button[8,6.6;4,1;btn_reconnect_no;" .. fgettext("Main menu") .. "]"
|
||||||
|
}
|
||||||
elseif gamedata ~= nil and gamedata.errormessage ~= nil then
|
elseif gamedata ~= nil and gamedata.errormessage ~= nil then
|
||||||
formspec = wordwrap_quickhack(gamedata.errormessage)
|
local error_message = core.formspec_escape(gamedata.errormessage)
|
||||||
|
|
||||||
local error_title
|
local error_title
|
||||||
if string.find(gamedata.errormessage, "ModError") then
|
if string.find(gamedata.errormessage, "ModError") then
|
||||||
error_title = fgettext("An error occurred in a Lua script, such as a mod:")
|
error_title = fgettext("An error occurred in a Lua script:")
|
||||||
else
|
else
|
||||||
error_title = fgettext("An error occurred:")
|
error_title = fgettext("An error occurred:")
|
||||||
end
|
end
|
||||||
formspec = "size[12,5]" ..
|
formspec = {
|
||||||
"label[0.5,0;" .. error_title ..
|
"size[14,8]",
|
||||||
"]textlist[0.2,0.8;11.5,3.5;;" .. formspec ..
|
"real_coordinates[true]",
|
||||||
"]button[4.5,4.6;3,0.5;btn_error_confirm;" .. fgettext("Ok") .. "]"
|
("textarea[0.5,1.2;13,5;;%s;%s]"):format(
|
||||||
|
error_title, error_message),
|
||||||
|
"box[0.5,1.2;13,5;#000]",
|
||||||
|
"button[5,6.6;4,1;btn_error_confirm;" .. fgettext("Ok") .. "]"
|
||||||
|
}
|
||||||
else
|
else
|
||||||
local active_toplevel_ui_elements = 0
|
local active_toplevel_ui_elements = 0
|
||||||
for key,value in pairs(ui.childlist) do
|
for key,value in pairs(ui.childlist) do
|
||||||
@ -107,8 +94,8 @@ function ui.update()
|
|||||||
local retval = value:get_formspec()
|
local retval = value:get_formspec()
|
||||||
|
|
||||||
if retval ~= nil and retval ~= "" then
|
if retval ~= nil and retval ~= "" then
|
||||||
active_toplevel_ui_elements = active_toplevel_ui_elements +1
|
active_toplevel_ui_elements = active_toplevel_ui_elements + 1
|
||||||
formspec = formspec .. retval
|
table.insert(formspec, retval)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -120,7 +107,7 @@ function ui.update()
|
|||||||
local retval = value:get_formspec()
|
local retval = value:get_formspec()
|
||||||
|
|
||||||
if retval ~= nil and retval ~= "" then
|
if retval ~= nil and retval ~= "" then
|
||||||
formspec = formspec .. retval
|
table.insert(formspec, retval)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -135,10 +122,10 @@ function ui.update()
|
|||||||
core.log("warning", "no toplevel ui element "..
|
core.log("warning", "no toplevel ui element "..
|
||||||
"active; switching to default")
|
"active; switching to default")
|
||||||
ui.childlist[ui.default]:show()
|
ui.childlist[ui.default]:show()
|
||||||
formspec = ui.childlist[ui.default]:get_formspec()
|
formspec = {ui.childlist[ui.default]:get_formspec()}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
core.update_formspec(formspec)
|
core.update_formspec(table.concat(formspec))
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
@ -4256,7 +4256,8 @@ void the_game(bool *kill,
|
|||||||
error_message = e.what();
|
error_message = e.what();
|
||||||
errorstream << "ServerError: " << error_message << std::endl;
|
errorstream << "ServerError: " << error_message << std::endl;
|
||||||
} catch (ModError &e) {
|
} catch (ModError &e) {
|
||||||
error_message = e.what() + strgettext("\nCheck debug.txt for details.");
|
error_message = std::string("ModError: ") + e.what() +
|
||||||
errorstream << "ModError: " << error_message << std::endl;
|
strgettext("\nCheck debug.txt for details.");
|
||||||
|
errorstream << error_message << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user