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("Creative mode", "creative") .. ",padding=1;" ..
46 image_column("Damage enabled", "damage") .. ",padding=0.25;" ..
47 image_column("PvP enabled", "pvp") .. ",padding=0.25;" ..
48 "text,padding=1]" -- name
50 retval = retval .. "tablecolumns[text]"
53 "table[-0.05,0;7.55,2.75;favourites;"
55 if #menudata.favorites > 0 then
56 retval = retval .. render_favorite(menudata.favorites[1],render_details)
58 for i=2,#menudata.favorites,1 do
59 retval = retval .. "," .. render_favorite(menudata.favorites[i],render_details)
63 if tabdata.fav_selected ~= nil then
64 retval = retval .. ";" .. tabdata.fav_selected .. "]"
66 retval = retval .. ";0]"
71 "box[-0.3,3.75;12.4,0.1;#FFFFFF]"
75 "checkbox[1.0,3.9;cb_creative;".. fgettext("Creative Mode") .. ";" ..
76 dump(core.setting_getbool("creative_mode")) .. "]"..
77 "checkbox[5.0,3.9;cb_damage;".. fgettext("Enable Damage") .. ";" ..
78 dump(core.setting_getbool("enable_damage")) .. "]" ..
79 "checkbox[8,3.9;cb_fly_mode;".. fgettext("Fly mode") .. ";" ..
80 dump(core.setting_getbool("free_move")) .. "]"
83 "button[2.0,4.5;6,1.5;btn_start_singleplayer;" .. fgettext("Start Singleplayer") .. "]" ..
84 "button[8.25,4.5;2.5,1.5;btn_config_sp_world;" .. fgettext("Config mods") .. "]"
89 --------------------------------------------------------------------------------
91 local function main_button_handler(tabview, fields, name, tabdata)
93 if fields["btn_start_singleplayer"] then
94 gamedata.selected_world = gamedata.worldindex
95 gamedata.singleplayer = true
100 if fields["favourites"] ~= nil then
101 local event = core.explode_textlist_event(fields["favourites"])
103 if event.type == "CHG" then
104 if event.index <= #menudata.favorites then
105 local address = menudata.favorites[event.index].address
106 local port = menudata.favorites[event.index].port
108 if address ~= nil and
110 core.setting_set("address",address)
111 core.setting_set("remote_port",port)
114 tabdata.fav_selected = event.index
120 if fields["cb_public_serverlist"] ~= nil then
121 core.setting_set("public_serverlist", fields["cb_public_serverlist"])
123 if core.setting_getbool("public_serverlist") then
124 asyncOnlineFavourites()
126 menudata.favorites = core.get_favorites("local")
131 if fields["cb_creative"] then
132 core.setting_set("creative_mode", fields["cb_creative"])
136 if fields["cb_damage"] then
137 core.setting_set("enable_damage", fields["cb_damage"])
141 if fields["cb_fly_mode"] then
142 core.setting_set("free_move", fields["cb_fly_mode"])
146 if fields["btn_mp_connect"] ~= nil or
147 fields["key_enter"] ~= nil then
149 gamedata.playername = fields["te_name"]
150 gamedata.password = fields["te_pwd"]
151 gamedata.address = fields["te_address"]
152 gamedata.port = fields["te_port"]
154 local fav_idx = core.get_textlist_index("favourites")
156 if fav_idx ~= nil and fav_idx <= #menudata.favorites and
157 menudata.favorites[fav_idx].address == fields["te_address"] and
158 menudata.favorites[fav_idx].port == fields["te_port"] then
160 gamedata.servername = menudata.favorites[fav_idx].name
161 gamedata.serverdescription = menudata.favorites[fav_idx].description
163 gamedata.servername = ""
164 gamedata.serverdescription = ""
167 gamedata.selected_world = 0
169 core.setting_set("address",fields["te_address"])
170 core.setting_set("remote_port",fields["te_port"])
176 if fields["btn_config_sp_world"] ~= nil then
177 local configdialog = create_configure_world_dlg(1)
179 if (configdialog ~= nil) then
180 configdialog:set_parent(tabview)
188 --------------------------------------------------------------------------------
189 local function on_activate(type,old_tab,new_tab)
190 if type == "LEAVE" then
193 if core.setting_getbool("public_serverlist") then
194 asyncOnlineFavourites()
196 menudata.favorites = core.get_favorites("local")
200 --------------------------------------------------------------------------------
203 caption = fgettext("Main"),
204 cbf_formspec = get_formspec,
205 cbf_button_handler = main_button_handler,
206 on_change = on_activate