17
17
18
18
---- ----------------------------------------------------------------------------
19
19
local function get_formspec (tabview , name , tabdata )
20
- local retval = " "
21
-
22
- local render_details = dump (core .setting_getbool (" public_serverlist" ))
23
-
24
- retval = retval ..
25
- " label[8,0.5;" .. fgettext (" Name/Password" ) .. " ]" ..
26
- " field[0.25,3.25;5.5,0.5;te_address;;" ..
27
- core .formspec_escape (core .setting_get (" address" )) .. " ]" ..
28
- " field[5.75,3.25;2.25,0.5;te_port;;" ..
29
- core .formspec_escape (core .setting_get (" remote_port" )) .. " ]" ..
30
- " checkbox[8,-0.25;cb_public_serverlist;" .. fgettext (" Public Serverlist" ) .. " ;" ..
31
- render_details .. " ]"
32
-
33
- retval = retval ..
34
- " button[8,2.5;4,1.5;btn_mp_connect;" .. fgettext (" Connect" ) .. " ]" ..
35
- " field[8.75,1.5;3.5,0.5;te_name;;" ..
36
- core .formspec_escape (core .setting_get (" name" )) .. " ]" ..
37
- " pwdfield[8.75,2.3;3.5,0.5;te_pwd;]"
38
-
39
- if render_details then
40
- retval = retval .. " tablecolumns[" ..
41
- " color,span=3;" ..
42
- " text,align=right;" .. -- clients
43
- " text,align=center,padding=0.25;" .. -- "/"
44
- " text,align=right,padding=0.25;" .. -- clients_max
45
- image_column (fgettext (" Creative mode" ), " creative" ) .. " ,padding=1;" ..
46
- image_column (fgettext (" Damage enabled" ), " damage" ) .. " ,padding=0.25;" ..
47
- image_column (fgettext (" PvP enabled" ), " pvp" ) .. " ,padding=0.25;" ..
48
- " color,span=1;" ..
49
- " text,padding=1]" -- name
50
- else
51
- retval = retval .. " tablecolumns[text]"
20
+ -- Update the cached supported proto info,
21
+ -- it may have changed after a change by the settings menu.
22
+ common_update_cached_supp_proto ()
23
+ local fav_selected = menudata .favorites [tabdata .fav_selected ]
24
+
25
+ local retval =
26
+ " label[9.5,0;" .. fgettext (" Name / Password" ) .. " ]" ..
27
+ " field[0.25,3.35;5.5,0.5;te_address;;" ..
28
+ core .formspec_escape (core .setting_get (" address" )) .. " ]" ..
29
+ " field[5.75,3.35;2.25,0.5;te_port;;" ..
30
+ core .formspec_escape (core .setting_get (" remote_port" )) .. " ]" ..
31
+ " button[10,2.6;2,1.5;btn_mp_connect;" .. fgettext (" Connect" ) .. " ]" ..
32
+ " field[9.8,1;2.6,0.5;te_name;;" ..
33
+ core .formspec_escape (core .setting_get (" name" )) .. " ]" ..
34
+ " pwdfield[9.8,2;2.6,0.5;te_pwd;]"
35
+
36
+
37
+ if tabdata .fav_selected and fav_selected then
38
+ if gamedata .fav then
39
+ retval = retval .. " button[7.7,2.6;2.3,1.5;btn_delete_favorite;" ..
40
+ fgettext (" Del. Favorite" ) .. " ]"
41
+ end
52
42
end
53
- retval = retval ..
54
- " table[-0.05,0;7.55,2.75;favourites;"
55
43
56
- if # menudata .favorites > 0 then
57
- retval = retval .. render_favorite (menudata .favorites [1 ],render_details )
44
+ retval = retval .. " tablecolumns[" ..
45
+ image_column (fgettext (" Favorite" ), " favorite" ) .. " ;" ..
46
+ " color,span=3;" ..
47
+ " text,align=right;" .. -- clients
48
+ " text,align=center,padding=0.25;" .. -- "/"
49
+ " text,align=right,padding=0.25;" .. -- clients_max
50
+ image_column (fgettext (" Creative mode" ), " creative" ) .. " ,padding=1;" ..
51
+ image_column (fgettext (" Damage enabled" ), " damage" ) .. " ,padding=0.25;" ..
52
+ image_column (fgettext (" PvP enabled" ), " pvp" ) .. " ,padding=0.25;" ..
53
+ " color,span=1;" ..
54
+ " text,padding=1]" .. -- name
55
+ " table[-0.05,0;9.2,2.75;favourites;"
58
56
59
- for i = 2 ,# menudata .favorites ,1 do
60
- retval = retval .. " ," .. render_favorite (menudata .favorites [i ],render_details )
57
+ if # menudata .favorites > 0 then
58
+ local favs = core .get_favorites (" local" )
59
+ if # favs > 0 then
60
+ for i = 1 , # favs do
61
+ for j = 1 , # menudata .favorites do
62
+ if menudata .favorites [j ].address == favs [i ].address and
63
+ menudata .favorites [j ].port == favs [i ].port then
64
+ table.insert (menudata .favorites , i ,
65
+ table.remove (menudata .favorites , j ))
66
+ end
67
+ end
68
+ if favs [i ].address ~= menudata .favorites [i ].address then
69
+ table.insert (menudata .favorites , i , favs [i ])
70
+ end
71
+ end
72
+ end
73
+ retval = retval .. render_favorite (menudata .favorites [1 ], (# favs > 0 ))
74
+ for i = 2 , # menudata .favorites do
75
+ retval = retval .. " ," .. render_favorite (menudata .favorites [i ], (i <= # favs ))
61
76
end
62
77
end
63
78
64
- if tabdata .fav_selected ~= nil then
79
+ if tabdata .fav_selected then
65
80
retval = retval .. " ;" .. tabdata .fav_selected .. " ]"
66
81
else
67
82
retval = retval .. " ;0]"
68
83
end
69
84
70
85
-- separator
71
- retval = retval ..
72
- " box[-0.28,3.75;12.4,0.1;#FFFFFF]"
86
+ retval = retval .. " box[-0.28,3.75;12.4,0.1;#FFFFFF]"
73
87
74
88
-- checkboxes
75
89
retval = retval ..
76
90
" checkbox[8.0,3.9;cb_creative;" .. fgettext (" Creative Mode" ) .. " ;" ..
77
- dump (core .setting_getbool (" creative_mode" )) .. " ]" ..
91
+ dump (core .setting_getbool (" creative_mode" )) .. " ]" ..
78
92
" checkbox[8.0,4.4;cb_damage;" .. fgettext (" Enable Damage" ) .. " ;" ..
79
- dump (core .setting_getbool (" enable_damage" )) .. " ]"
93
+ dump (core .setting_getbool (" enable_damage" )) .. " ]"
80
94
-- buttons
81
95
retval = retval ..
82
96
" button[0,3.7;8,1.5;btn_start_singleplayer;" .. fgettext (" Start Singleplayer" ) .. " ]" ..
@@ -87,97 +101,100 @@ end
87
101
88
102
---- ----------------------------------------------------------------------------
89
103
local function main_button_handler (tabview , fields , name , tabdata )
90
-
91
- if fields [" btn_start_singleplayer" ] then
104
+ if fields .btn_start_singleplayer then
92
105
gamedata .selected_world = gamedata .worldindex
93
106
gamedata .singleplayer = true
94
107
core .start ()
95
108
return true
96
109
end
97
110
98
- if fields [" favourites" ] ~= nil then
99
- local event = core .explode_table_event (fields [" favourites" ])
100
-
111
+ if fields .favourites then
112
+ local event = core .explode_table_event (fields .favourites )
101
113
if event .type == " CHG" then
102
114
if event .row <= # menudata .favorites then
103
- local address = menudata .favorites [event .row ].address
104
- local port = menudata .favorites [event .row ].port
105
-
106
- if address ~= nil and
107
- port ~= nil then
108
- core .setting_set (" address" ,address )
109
- core .setting_set (" remote_port" ,port )
115
+ gamedata .fav = false
116
+ local favs = core .get_favorites (" local" )
117
+ local fav = menudata .favorites [event .row ]
118
+ local address = fav .address
119
+ local port = fav .port
120
+ gamedata .serverdescription = fav .description
121
+
122
+ for i = 1 , # favs do
123
+ if fav .address == favs [i ].address and
124
+ fav .port == favs [i ].port then
125
+ gamedata .fav = true
126
+ end
110
127
end
111
128
129
+ if address and port then
130
+ core .setting_set (" address" , address )
131
+ core .setting_set (" remote_port" , port )
132
+ end
112
133
tabdata .fav_selected = event .row
113
134
end
135
+ return true
114
136
end
115
- return true
116
137
end
117
138
118
- if fields [" cb_public_serverlist" ] ~= nil then
119
- core .setting_set (" public_serverlist" , fields [" cb_public_serverlist" ])
139
+ if fields .btn_delete_favorite then
140
+ local current_favourite = core .get_table_index (" favourites" )
141
+ if not current_favourite then return end
120
142
121
- if core .setting_getbool ( " public_serverlist " ) then
122
- asyncOnlineFavourites ()
123
- else
124
- menudata . favorites = core . get_favorites ( " local " )
125
- menudata . favorites_is_public = false
126
- end
143
+ core .delete_favorite ( current_favourite )
144
+ asyncOnlineFavourites ()
145
+ tabdata . fav_selected = nil
146
+
147
+ core . setting_set ( " address " , " " )
148
+ core . setting_set ( " remote_port " , " 30000 " )
127
149
return true
128
150
end
129
151
130
- if fields [ " cb_creative" ] then
131
- core .setting_set (" creative_mode" , fields [ " cb_creative" ] )
152
+ if fields . cb_creative then
153
+ core .setting_set (" creative_mode" , fields . cb_creative )
132
154
return true
133
155
end
134
156
135
- if fields [ " cb_damage" ] then
136
- core .setting_set (" enable_damage" , fields [ " cb_damage" ] )
157
+ if fields . cb_damage then
158
+ core .setting_set (" enable_damage" , fields . cb_damage )
137
159
return true
138
160
end
139
161
140
- if fields [" btn_mp_connect" ] ~= nil or
141
- fields [" key_enter" ] ~= nil then
142
-
143
- gamedata .playername = fields [" te_name" ]
144
- gamedata .password = fields [" te_pwd" ]
145
- gamedata .address = fields [" te_address" ]
146
- gamedata .port = fields [" te_port" ]
147
-
162
+ if fields .btn_mp_connect or fields .key_enter then
163
+ gamedata .playername = fields .te_name
164
+ gamedata .password = fields .te_pwd
165
+ gamedata .address = fields .te_address
166
+ gamedata .port = fields .te_port
148
167
local fav_idx = core .get_textlist_index (" favourites" )
149
168
150
- if fav_idx ~= nil and fav_idx <= # menudata .favorites and
151
- menudata .favorites [fav_idx ].address == fields [ " te_address" ] and
152
- menudata .favorites [fav_idx ].port == fields [ " te_port" ] then
169
+ if fav_idx and fav_idx <= # menudata .favorites and
170
+ menudata .favorites [fav_idx ].address == fields . te_address and
171
+ menudata .favorites [fav_idx ].port == fields . te_port then
153
172
local fav = menudata .favorites [fav_idx ]
154
-
155
173
gamedata .servername = fav .name
156
174
gamedata .serverdescription = fav .description
157
175
158
176
if menudata .favorites_is_public and
159
- not is_server_protocol_compat_or_error (
160
- fav .proto_min , fav .proto_max ) then
177
+ not is_server_protocol_compat_or_error (
178
+ fav .proto_min , fav .proto_max ) then
161
179
return true
162
180
end
163
181
else
164
- gamedata .servername = " "
165
- gamedata .serverdescription = " "
182
+ gamedata .servername = " "
183
+ gamedata .serverdescription = " "
166
184
end
167
185
168
186
gamedata .selected_world = 0
169
187
170
- core .setting_set (" address" ,fields [ " te_address" ] )
171
- core .setting_set (" remote_port" ,fields [ " te_port" ] )
188
+ core .setting_set (" address" , fields . te_address )
189
+ core .setting_set (" remote_port" , fields . te_port )
172
190
173
191
core .start ()
174
192
return true
175
193
end
176
194
177
- if fields [ " btn_config_sp_world" ] ~= nil then
195
+ if fields . btn_config_sp_world then
178
196
local configdialog = create_configure_world_dlg (1 )
179
-
180
- if (configdialog ~= nil ) then
197
+ if configdialog then
181
198
configdialog :set_parent (tabview )
182
199
tabview :hide ()
183
200
configdialog :show ()
188
205
189
206
---- ----------------------------------------------------------------------------
190
207
local function on_activate (type ,old_tab ,new_tab )
191
- if type == " LEAVE" then
192
- return
193
- end
194
- if core .setting_getbool (" public_serverlist" ) then
195
- asyncOnlineFavourites ()
196
- else
197
- menudata .favorites = core .get_favorites (" local" )
198
- menudata .favorites_is_public = false
199
- end
208
+ if type == " LEAVE" then return end
209
+ asyncOnlineFavourites ()
200
210
end
201
211
202
212
---- ----------------------------------------------------------------------------
0 commit comments