Skip to content

Commit 3ceef8e

Browse files
committedAug 1, 2019
Mainmenu: Use textarea in error formspecs
1 parent ec3142a commit 3ceef8e

File tree

2 files changed

+31
-43
lines changed

2 files changed

+31
-43
lines changed
 

Diff for: ‎builtin/fstk/ui.lua

+28-41
Original file line numberDiff line numberDiff line change
@@ -54,61 +54,48 @@ end
5454
--------------------------------------------------------------------------------
5555
--------------------------------------------------------------------------------
5656

57-
local function wordwrap_quickhack(str)
58-
local res = ""
59-
local ar = str:split("\n")
60-
for i = 1, #ar do
61-
local text = ar[i]
62-
-- Hack to add word wrapping.
63-
-- TODO: Add engine support for wrapping in formspecs
64-
while #text > 80 do
65-
if res ~= "" then
66-
res = res .. ","
67-
end
68-
res = res .. core.formspec_escape(string.sub(text, 1, 79))
69-
text = string.sub(text, 80, #text)
70-
end
71-
if res ~= "" then
72-
res = res .. ","
73-
end
74-
res = res .. core.formspec_escape(text)
75-
end
76-
return res
77-
end
78-
79-
--------------------------------------------------------------------------------
8057
function ui.update()
81-
local formspec = ""
58+
local formspec = {}
8259

8360
-- handle errors
8461
if gamedata ~= nil and gamedata.reconnect_requested then
85-
formspec = wordwrap_quickhack(gamedata.errormessage or "")
86-
formspec = "size[12,5]" ..
87-
"label[0.5,0;" .. fgettext("The server has requested a reconnect:") ..
88-
"]textlist[0.2,0.8;11.5,3.5;;" .. formspec ..
89-
"]button[6,4.6;3,0.5;btn_reconnect_no;" .. fgettext("Main menu") .. "]" ..
90-
"button[3,4.6;3,0.5;btn_reconnect_yes;" .. fgettext("Reconnect") .. "]"
62+
local error_message = core.formspec_escape(
63+
gamedata.errormessage or "<none available>")
64+
formspec = {
65+
"size[14,8]",
66+
"real_coordinates[true]",
67+
("textarea[0.5,1.2;13,5;;%s;%s]"):format(
68+
fgettext("The server has requested a reconnect:"), error_message),
69+
"box[0.5,1.2;13,5;#000]",
70+
"button[2,6.6;4,1;btn_reconnect_yes;" .. fgettext("Reconnect") .. "]",
71+
"button[8,6.6;4,1;btn_reconnect_no;" .. fgettext("Main menu") .. "]"
72+
}
9173
elseif gamedata ~= nil and gamedata.errormessage ~= nil then
92-
formspec = wordwrap_quickhack(gamedata.errormessage)
74+
local error_message = core.formspec_escape(gamedata.errormessage)
75+
9376
local error_title
9477
if string.find(gamedata.errormessage, "ModError") then
95-
error_title = fgettext("An error occurred in a Lua script, such as a mod:")
78+
error_title = fgettext("An error occurred in a Lua script:")
9679
else
9780
error_title = fgettext("An error occurred:")
9881
end
99-
formspec = "size[12,5]" ..
100-
"label[0.5,0;" .. error_title ..
101-
"]textlist[0.2,0.8;11.5,3.5;;" .. formspec ..
102-
"]button[4.5,4.6;3,0.5;btn_error_confirm;" .. fgettext("Ok") .. "]"
82+
formspec = {
83+
"size[14,8]",
84+
"real_coordinates[true]",
85+
("textarea[0.5,1.2;13,5;;%s;%s]"):format(
86+
error_title, error_message),
87+
"box[0.5,1.2;13,5;#000]",
88+
"button[5,6.6;4,1;btn_error_confirm;" .. fgettext("Ok") .. "]"
89+
}
10390
else
10491
local active_toplevel_ui_elements = 0
10592
for key,value in pairs(ui.childlist) do
10693
if (value.type == "toplevel") then
10794
local retval = value:get_formspec()
10895

10996
if retval ~= nil and retval ~= "" then
110-
active_toplevel_ui_elements = active_toplevel_ui_elements +1
111-
formspec = formspec .. retval
97+
active_toplevel_ui_elements = active_toplevel_ui_elements + 1
98+
table.insert(formspec, retval)
11299
end
113100
end
114101
end
@@ -120,7 +107,7 @@ function ui.update()
120107
local retval = value:get_formspec()
121108

122109
if retval ~= nil and retval ~= "" then
123-
formspec = formspec .. retval
110+
table.insert(formspec, retval)
124111
end
125112
end
126113
end
@@ -135,10 +122,10 @@ function ui.update()
135122
core.log("warning", "no toplevel ui element "..
136123
"active; switching to default")
137124
ui.childlist[ui.default]:show()
138-
formspec = ui.childlist[ui.default]:get_formspec()
125+
formspec = {ui.childlist[ui.default]:get_formspec()}
139126
end
140127
end
141-
core.update_formspec(formspec)
128+
core.update_formspec(table.concat(formspec))
142129
end
143130

144131
--------------------------------------------------------------------------------

Diff for: ‎src/client/game.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -4256,7 +4256,8 @@ void the_game(bool *kill,
42564256
error_message = e.what();
42574257
errorstream << "ServerError: " << error_message << std::endl;
42584258
} catch (ModError &e) {
4259-
error_message = e.what() + strgettext("\nCheck debug.txt for details.");
4260-
errorstream << "ModError: " << error_message << std::endl;
4259+
error_message = std::string("ModError: ") + e.what() +
4260+
strgettext("\nCheck debug.txt for details.");
4261+
errorstream << error_message << std::endl;
42614262
}
42624263
}

0 commit comments

Comments
 (0)