2014-04-18 15:39:15 +02:00
|
|
|
--Minetest
|
|
|
|
--Copyright (C) 2013 sapier
|
|
|
|
--
|
|
|
|
--This program is free software; you can redistribute it and/or modify
|
|
|
|
--it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
--the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
--(at your option) any later version.
|
|
|
|
--
|
|
|
|
--This program is distributed in the hope that it will be useful,
|
|
|
|
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
--GNU Lesser General Public License for more details.
|
|
|
|
--
|
|
|
|
--You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
--with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
local function get_formspec(tabview, name, tabdata)
|
|
|
|
local retval = ""
|
|
|
|
|
|
|
|
local render_details = dump(core.setting_getbool("public_serverlist"))
|
|
|
|
|
|
|
|
retval = retval ..
|
|
|
|
"label[8,0.5;".. fgettext("Name/Password") .. "]" ..
|
2014-12-08 07:47:51 +01:00
|
|
|
"field[0.25,3.25;5.5,0.5;te_address;;" ..
|
|
|
|
core.formspec_escape(core.setting_get("address")) .."]" ..
|
|
|
|
"field[5.75,3.25;2.25,0.5;te_port;;" ..
|
|
|
|
core.formspec_escape(core.setting_get("remote_port")) .."]" ..
|
2014-04-18 15:39:15 +02:00
|
|
|
"checkbox[8,-0.25;cb_public_serverlist;".. fgettext("Public Serverlist") .. ";" ..
|
|
|
|
render_details .. "]"
|
|
|
|
|
|
|
|
retval = retval ..
|
|
|
|
"button[8,2.5;4,1.5;btn_mp_connect;".. fgettext("Connect") .. "]" ..
|
2014-12-08 07:47:51 +01:00
|
|
|
"field[8.75,1.5;3.5,0.5;te_name;;" ..
|
|
|
|
core.formspec_escape(core.setting_get("name")) .."]" ..
|
2014-04-18 15:39:15 +02:00
|
|
|
"pwdfield[8.75,2.3;3.5,0.5;te_pwd;]"
|
2015-01-04 17:37:45 +01:00
|
|
|
|
|
|
|
if render_details then
|
|
|
|
retval = retval .. "tablecolumns[" ..
|
|
|
|
"color,span=3;" ..
|
|
|
|
"text,align=right;" .. -- clients
|
|
|
|
"text,align=center,padding=0.25;" .. -- "/"
|
|
|
|
"text,align=right,padding=0.25;" .. -- clients_max
|
2015-01-21 02:50:33 +01:00
|
|
|
image_column(fgettext("Creative mode"), "creative") .. ",padding=1;" ..
|
|
|
|
image_column(fgettext("Damage enabled"), "damage") .. ",padding=0.25;" ..
|
|
|
|
image_column(fgettext("PvP enabled"), "pvp") .. ",padding=0.25;" ..
|
2015-02-17 01:37:14 +01:00
|
|
|
"color,span=1;" ..
|
2015-01-04 17:37:45 +01:00
|
|
|
"text,padding=1]" -- name
|
|
|
|
else
|
|
|
|
retval = retval .. "tablecolumns[text]"
|
|
|
|
end
|
2014-04-18 15:39:15 +02:00
|
|
|
retval = retval ..
|
2015-01-04 17:37:45 +01:00
|
|
|
"table[-0.05,0;7.55,2.75;favourites;"
|
2014-04-18 15:39:15 +02:00
|
|
|
|
|
|
|
if #menudata.favorites > 0 then
|
|
|
|
retval = retval .. render_favorite(menudata.favorites[1],render_details)
|
|
|
|
|
|
|
|
for i=2,#menudata.favorites,1 do
|
|
|
|
retval = retval .. "," .. render_favorite(menudata.favorites[i],render_details)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if tabdata.fav_selected ~= nil then
|
|
|
|
retval = retval .. ";" .. tabdata.fav_selected .. "]"
|
|
|
|
else
|
|
|
|
retval = retval .. ";0]"
|
|
|
|
end
|
|
|
|
|
|
|
|
-- separator
|
|
|
|
retval = retval ..
|
2015-04-25 05:11:12 +02:00
|
|
|
"box[-0.28,3.75;12.4,0.1;#FFFFFF]"
|
2014-04-18 15:39:15 +02:00
|
|
|
|
|
|
|
-- checkboxes
|
|
|
|
retval = retval ..
|
2015-04-25 05:11:12 +02:00
|
|
|
"checkbox[8.0,3.9;cb_creative;".. fgettext("Creative Mode") .. ";" ..
|
2014-04-18 15:39:15 +02:00
|
|
|
dump(core.setting_getbool("creative_mode")) .. "]"..
|
2015-04-25 05:11:12 +02:00
|
|
|
"checkbox[8.0,4.4;cb_damage;".. fgettext("Enable Damage") .. ";" ..
|
|
|
|
dump(core.setting_getbool("enable_damage")) .. "]"
|
2014-04-18 15:39:15 +02:00
|
|
|
-- buttons
|
|
|
|
retval = retval ..
|
2015-04-25 05:11:12 +02:00
|
|
|
"button[0,3.7;8,1.5;btn_start_singleplayer;" .. fgettext("Start Singleplayer") .. "]" ..
|
|
|
|
"button[0,4.5;8,1.5;btn_config_sp_world;" .. fgettext("Config mods") .. "]"
|
2014-04-18 15:39:15 +02:00
|
|
|
|
|
|
|
return retval
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
local function main_button_handler(tabview, fields, name, tabdata)
|
2014-04-21 14:10:59 +02:00
|
|
|
|
2014-04-18 15:39:15 +02:00
|
|
|
if fields["btn_start_singleplayer"] then
|
|
|
|
gamedata.selected_world = gamedata.worldindex
|
|
|
|
gamedata.singleplayer = true
|
|
|
|
core.start()
|
2014-04-21 14:10:59 +02:00
|
|
|
return true
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if fields["favourites"] ~= nil then
|
2015-03-16 17:32:30 +01:00
|
|
|
local event = core.explode_table_event(fields["favourites"])
|
2014-04-18 15:39:15 +02:00
|
|
|
|
|
|
|
if event.type == "CHG" then
|
2015-03-16 17:32:30 +01:00
|
|
|
if event.row <= #menudata.favorites then
|
|
|
|
local address = menudata.favorites[event.row].address
|
|
|
|
local port = menudata.favorites[event.row].port
|
2014-04-18 15:39:15 +02:00
|
|
|
|
|
|
|
if address ~= nil and
|
|
|
|
port ~= nil then
|
|
|
|
core.setting_set("address",address)
|
|
|
|
core.setting_set("remote_port",port)
|
|
|
|
end
|
|
|
|
|
2015-03-16 17:32:30 +01:00
|
|
|
tabdata.fav_selected = event.row
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
|
|
|
end
|
2014-04-21 14:10:59 +02:00
|
|
|
return true
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if fields["cb_public_serverlist"] ~= nil then
|
|
|
|
core.setting_set("public_serverlist", fields["cb_public_serverlist"])
|
|
|
|
|
|
|
|
if core.setting_getbool("public_serverlist") then
|
|
|
|
asyncOnlineFavourites()
|
|
|
|
else
|
2014-04-21 14:10:59 +02:00
|
|
|
menudata.favorites = core.get_favorites("local")
|
2016-04-15 04:13:53 +02:00
|
|
|
menudata.favorites_is_public = false
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
2014-04-21 14:10:59 +02:00
|
|
|
return true
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if fields["cb_creative"] then
|
|
|
|
core.setting_set("creative_mode", fields["cb_creative"])
|
2014-04-21 14:10:59 +02:00
|
|
|
return true
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if fields["cb_damage"] then
|
|
|
|
core.setting_set("enable_damage", fields["cb_damage"])
|
2014-04-21 14:10:59 +02:00
|
|
|
return true
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if fields["btn_mp_connect"] ~= nil or
|
|
|
|
fields["key_enter"] ~= nil then
|
|
|
|
|
|
|
|
gamedata.playername = fields["te_name"]
|
|
|
|
gamedata.password = fields["te_pwd"]
|
|
|
|
gamedata.address = fields["te_address"]
|
|
|
|
gamedata.port = fields["te_port"]
|
|
|
|
|
|
|
|
local fav_idx = core.get_textlist_index("favourites")
|
|
|
|
|
|
|
|
if fav_idx ~= nil and fav_idx <= #menudata.favorites and
|
|
|
|
menudata.favorites[fav_idx].address == fields["te_address"] and
|
|
|
|
menudata.favorites[fav_idx].port == fields["te_port"] then
|
2016-04-15 04:13:53 +02:00
|
|
|
local fav = menudata.favorites[fav_idx]
|
2014-04-18 15:39:15 +02:00
|
|
|
|
2016-04-15 04:13:53 +02:00
|
|
|
gamedata.servername = fav.name
|
|
|
|
gamedata.serverdescription = fav.description
|
2015-02-17 01:37:14 +01:00
|
|
|
|
2016-04-15 04:13:53 +02:00
|
|
|
if menudata.favorites_is_public and
|
|
|
|
not is_server_protocol_compat_or_error(
|
|
|
|
fav.proto_min, fav.proto_max) then
|
2015-02-17 01:37:14 +01:00
|
|
|
return true
|
|
|
|
end
|
2014-04-18 15:39:15 +02:00
|
|
|
else
|
|
|
|
gamedata.servername = ""
|
|
|
|
gamedata.serverdescription = ""
|
|
|
|
end
|
|
|
|
|
|
|
|
gamedata.selected_world = 0
|
|
|
|
|
|
|
|
core.setting_set("address",fields["te_address"])
|
|
|
|
core.setting_set("remote_port",fields["te_port"])
|
|
|
|
|
|
|
|
core.start()
|
2014-04-21 14:10:59 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["btn_config_sp_world"] ~= nil then
|
|
|
|
local configdialog = create_configure_world_dlg(1)
|
|
|
|
|
|
|
|
if (configdialog ~= nil) then
|
|
|
|
configdialog:set_parent(tabview)
|
|
|
|
tabview:hide()
|
|
|
|
configdialog:show()
|
|
|
|
end
|
|
|
|
return true
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
local function on_activate(type,old_tab,new_tab)
|
|
|
|
if type == "LEAVE" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if core.setting_getbool("public_serverlist") then
|
|
|
|
asyncOnlineFavourites()
|
|
|
|
else
|
|
|
|
menudata.favorites = core.get_favorites("local")
|
2016-04-15 04:13:53 +02:00
|
|
|
menudata.favorites_is_public = false
|
2014-04-18 15:39:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2016-03-31 10:26:39 +02:00
|
|
|
return {
|
2014-04-18 15:39:15 +02:00
|
|
|
name = "main",
|
|
|
|
caption = fgettext("Main"),
|
|
|
|
cbf_formspec = get_formspec,
|
|
|
|
cbf_button_handler = main_button_handler,
|
|
|
|
on_change = on_activate
|
2016-03-31 10:26:39 +02:00
|
|
|
}
|