54
54
---- ----------------------------------------------------------------------------
55
55
---- ----------------------------------------------------------------------------
56
56
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
- ---- ----------------------------------------------------------------------------
80
57
function ui .update ()
81
- local formspec = " "
58
+ local formspec = {}
82
59
83
60
-- handle errors
84
61
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
+ }
91
73
elseif gamedata ~= nil and gamedata .errormessage ~= nil then
92
- formspec = wordwrap_quickhack (gamedata .errormessage )
74
+ local error_message = core .formspec_escape (gamedata .errormessage )
75
+
93
76
local error_title
94
77
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:" )
96
79
else
97
80
error_title = fgettext (" An error occurred:" )
98
81
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
+ }
103
90
else
104
91
local active_toplevel_ui_elements = 0
105
92
for key ,value in pairs (ui .childlist ) do
106
93
if (value .type == " toplevel" ) then
107
94
local retval = value :get_formspec ()
108
95
109
96
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 )
112
99
end
113
100
end
114
101
end
@@ -120,7 +107,7 @@ function ui.update()
120
107
local retval = value :get_formspec ()
121
108
122
109
if retval ~= nil and retval ~= " " then
123
- formspec = formspec .. retval
110
+ table.insert ( formspec , retval )
124
111
end
125
112
end
126
113
end
@@ -135,10 +122,10 @@ function ui.update()
135
122
core .log (" warning" , " no toplevel ui element " ..
136
123
" active; switching to default" )
137
124
ui .childlist [ui .default ]:show ()
138
- formspec = ui .childlist [ui .default ]:get_formspec ()
125
+ formspec = { ui .childlist [ui .default ]:get_formspec ()}
139
126
end
140
127
end
141
- core .update_formspec (formspec )
128
+ core .update_formspec (table.concat ( formspec ) )
142
129
end
143
130
144
131
---- ----------------------------------------------------------------------------
0 commit comments