2 --Copyright (C) 2014 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)
21 local index = menudata.worldlist:get_current_index(
22 tonumber(core.setting_get("mainmenu_last_selected_world"))
26 "button[4,4.15;2.6,0.5;world_delete;" .. fgettext("Delete") .. "]" ..
27 "button[6.5,4.15;2.8,0.5;world_create;" .. fgettext("New") .. "]" ..
28 "button[9.2,4.15;2.55,0.5;world_configure;" .. fgettext("Configure") .. "]" ..
29 "button[8.5,4.95;3.25,0.5;start_server;" .. fgettext("Start Game") .. "]" ..
30 "label[4,-0.25;" .. fgettext("Select World:") .. "]" ..
31 "checkbox[0.25,0.25;cb_creative_mode;" .. fgettext("Creative Mode") .. ";" ..
32 dump(core.setting_getbool("creative_mode")) .. "]" ..
33 "checkbox[0.25,0.7;cb_enable_damage;" .. fgettext("Enable Damage") .. ";" ..
34 dump(core.setting_getbool("enable_damage")) .. "]" ..
35 "checkbox[0.25,1.15;cb_server_announce;" .. fgettext("Public") .. ";" ..
36 dump(core.setting_getbool("server_announce")) .. "]" ..
37 "label[0.25,2.2;" .. fgettext("Name/Password") .. "]" ..
38 "field[0.55,3.2;3.5,0.5;te_playername;;" ..
39 core.formspec_escape(core.setting_get("name")) .. "]" ..
40 "pwdfield[0.55,4;3.5,0.5;te_passwd;]"
42 local bind_addr = core.setting_get("bind_address")
43 if bind_addr ~= nil and bind_addr ~= "" then
45 "field[0.55,5.2;2.25,0.5;te_serveraddr;" .. fgettext("Bind Address") .. ";" ..
46 core.formspec_escape(core.setting_get("bind_address")) .. "]" ..
47 "field[2.8,5.2;1.25,0.5;te_serverport;" .. fgettext("Port") .. ";" ..
48 core.formspec_escape(core.setting_get("port")) .. "]"
51 "field[0.55,5.2;3.5,0.5;te_serverport;" .. fgettext("Server Port") .. ";" ..
52 core.formspec_escape(core.setting_get("port")) .. "]"
56 "textlist[4,0.25;7.5,3.7;srv_worlds;" ..
57 menu_render_worldlist() ..
63 --------------------------------------------------------------------------------
64 local function main_button_handler(this, fields, name, tabdata)
66 local world_doubleclick = false
68 if fields["srv_worlds"] ~= nil then
69 local event = core.explode_textlist_event(fields["srv_worlds"])
70 local selected = core.get_textlist_index("srv_worlds")
72 menu_worldmt_legacy(selected)
74 if event.type == "DCL" then
75 world_doubleclick = true
77 if event.type == "CHG" then
78 core.setting_set("mainmenu_last_selected_world",
79 menudata.worldlist:get_raw_index(core.get_textlist_index("srv_worlds")))
84 if menu_handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world") then
88 if fields["cb_creative_mode"] then
89 core.setting_set("creative_mode", fields["cb_creative_mode"])
90 local selected = core.get_textlist_index("srv_worlds")
91 menu_worldmt(selected, "creative_mode", fields["cb_creative_mode"])
96 if fields["cb_enable_damage"] then
97 core.setting_set("enable_damage", fields["cb_enable_damage"])
98 local selected = core.get_textlist_index("srv_worlds")
99 menu_worldmt(selected, "enable_damage", fields["cb_enable_damage"])
104 if fields["cb_server_announce"] then
105 core.setting_set("server_announce", fields["cb_server_announce"])
106 local selected = core.get_textlist_index("srv_worlds")
107 menu_worldmt(selected, "server_announce", fields["cb_server_announce"])
112 if fields["start_server"] ~= nil or
114 fields["key_enter"] then
115 local selected = core.get_textlist_index("srv_worlds")
116 if selected ~= nil then
117 gamedata.playername = fields["te_playername"]
118 gamedata.password = fields["te_passwd"]
119 gamedata.port = fields["te_serverport"]
120 gamedata.address = ""
121 gamedata.selected_world = menudata.worldlist:get_raw_index(selected)
123 core.setting_set("port",gamedata.port)
124 if fields["te_serveraddr"] ~= nil then
125 core.setting_set("bind_address",fields["te_serveraddr"])
129 local world = menudata.worldlist:get_raw_element(gamedata.selected_world)
131 local game, index = gamemgr.find_by_gameid(world.gameid)
132 core.setting_set("menu_last_game", game.id)
140 if fields["world_create"] ~= nil then
141 local create_world_dlg = create_create_world_dlg(true)
142 create_world_dlg:set_parent(this)
143 create_world_dlg:show()
148 if fields["world_delete"] ~= nil then
149 local selected = core.get_textlist_index("srv_worlds")
150 if selected ~= nil and
151 selected <= menudata.worldlist:size() then
152 local world = menudata.worldlist:get_list()[selected]
154 world.name ~= nil and
155 world.name ~= "" then
156 local index = menudata.worldlist:get_raw_index(selected)
157 local delete_world_dlg = create_delete_world_dlg(world.name,index)
158 delete_world_dlg:set_parent(this)
159 delete_world_dlg:show()
167 if fields["world_configure"] ~= nil then
168 local selected = core.get_textlist_index("srv_worlds")
169 if selected ~= nil then
171 create_configure_world_dlg(
172 menudata.worldlist:get_raw_index(selected))
174 if (configdialog ~= nil) then
175 configdialog:set_parent(this)
185 --------------------------------------------------------------------------------
188 caption = fgettext("Server"),
189 cbf_formspec = get_formspec,
190 cbf_button_handler = main_button_handler,