2 --Copyright (C) 2013 sapier
4 --This program is free software; you can redistribute it and/or modify
5 --it under the terms of the GNU Lesser General Public License as published by
6 --the Free Software Foundation; either version 2.1 of the License, or
7 --(at your option) any later version.
9 --This program is distributed in the hope that it will be useful,
10 --but WITHOUT ANY WARRANTY; without even the implied warranty of
11 --MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 --GNU Lesser General Public License for more details.
14 --You should have received a copy of the GNU Lesser General Public License along
15 --with this program; if not, write to the Free Software Foundation, Inc.,
16 --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 --------------------------------------------------------------------------------
19 local function get_formspec(tabview, name, tabdata)
22 local render_details = dump(core.setting_getbool("public_serverlist"))
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") .. ";" ..
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;]"
39 if render_details then
40 retval = retval .. "tablecolumns[" ..
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;" ..
49 "text,padding=1]" -- name
51 retval = retval .. "tablecolumns[text]"
54 "table[-0.05,0;7.55,2.75;favourites;"
56 if #menudata.favorites > 0 then
57 retval = retval .. render_favorite(menudata.favorites[1],render_details)
59 for i=2,#menudata.favorites,1 do
60 retval = retval .. "," .. render_favorite(menudata.favorites[i],render_details)
64 if tabdata.fav_selected ~= nil then
65 retval = retval .. ";" .. tabdata.fav_selected .. "]"
67 retval = retval .. ";0]"
72 "box[-0.28,3.75;12.4,0.1;#FFFFFF]"
76 "checkbox[8.0,3.9;cb_creative;".. fgettext("Creative Mode") .. ";" ..
77 dump(core.setting_getbool("creative_mode")) .. "]"..
78 "checkbox[8.0,4.4;cb_damage;".. fgettext("Enable Damage") .. ";" ..
79 dump(core.setting_getbool("enable_damage")) .. "]"
82 "button[0,3.7;8,1.5;btn_start_singleplayer;" .. fgettext("Start Singleplayer") .. "]" ..
83 "button[0,4.5;8,1.5;btn_config_sp_world;" .. fgettext("Config mods") .. "]"
88 --------------------------------------------------------------------------------
89 local function main_button_handler(tabview, fields, name, tabdata)
91 if fields["btn_start_singleplayer"] then
92 gamedata.selected_world = gamedata.worldindex
93 gamedata.singleplayer = true
98 if fields["favourites"] ~= nil then
99 local event = core.explode_table_event(fields["favourites"])
101 if event.type == "CHG" then
102 if event.row <= #menudata.favorites then
103 local address = menudata.favorites[event.row].address
104 local port = menudata.favorites[event.row].port
106 if address ~= nil and
108 core.setting_set("address",address)
109 core.setting_set("remote_port",port)
112 tabdata.fav_selected = event.row
118 if fields["cb_public_serverlist"] ~= nil then
119 core.setting_set("public_serverlist", fields["cb_public_serverlist"])
121 if core.setting_getbool("public_serverlist") then
122 asyncOnlineFavourites()
124 menudata.favorites = core.get_favorites("local")
125 menudata.favorites_is_public = false
130 if fields["cb_creative"] then
131 core.setting_set("creative_mode", fields["cb_creative"])
135 if fields["cb_damage"] then
136 core.setting_set("enable_damage", fields["cb_damage"])
140 if fields["btn_mp_connect"] ~= nil or
141 fields["key_enter"] ~= nil then
143 gamedata.playername = fields["te_name"]
144 gamedata.password = fields["te_pwd"]
145 gamedata.address = fields["te_address"]
146 gamedata.port = fields["te_port"]
148 local fav_idx = core.get_textlist_index("favourites")
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
153 local fav = menudata.favorites[fav_idx]
155 gamedata.servername = fav.name
156 gamedata.serverdescription = fav.description
158 if menudata.favorites_is_public and
159 not is_server_protocol_compat_or_error(
160 fav.proto_min, fav.proto_max) then
164 gamedata.servername = ""
165 gamedata.serverdescription = ""
168 gamedata.selected_world = 0
170 core.setting_set("address",fields["te_address"])
171 core.setting_set("remote_port",fields["te_port"])
177 if fields["btn_config_sp_world"] ~= nil then
178 local configdialog = create_configure_world_dlg(1)
180 if (configdialog ~= nil) then
181 configdialog:set_parent(tabview)
189 --------------------------------------------------------------------------------
190 local function on_activate(type,old_tab,new_tab)
191 if type == "LEAVE" then
194 if core.setting_getbool("public_serverlist") then
195 asyncOnlineFavourites()
197 menudata.favorites = core.get_favorites("local")
198 menudata.favorites_is_public = false
202 --------------------------------------------------------------------------------
205 caption = fgettext("Main"),
206 cbf_formspec = get_formspec,
207 cbf_button_handler = main_button_handler,
208 on_change = on_activate