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.9;3.25,0.5;start_server;".. fgettext("Start Game") .. "]" ..
30 "label[4,-0.25;".. fgettext("Select World:") .. "]"..
31 "vertlabel[0,-0.25;".. fgettext("START SERVER") .. "]" ..
32 "checkbox[0.5,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" ..
33 dump(core.setting_getbool("creative_mode")) .. "]"..
34 "checkbox[0.5,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" ..
35 dump(core.setting_getbool("enable_damage")) .. "]"..
36 "checkbox[0.5,1.15;cb_server_announce;".. fgettext("Public") .. ";" ..
37 dump(core.setting_getbool("server_announce")) .. "]"..
38 "field[0.8,3.2;3.5,0.5;te_playername;".. fgettext("Name") .. ";" ..
39 core.formspec_escape(core.setting_get("name")) .. "]" ..
40 "pwdfield[0.8,4.2;3.5,0.5;te_passwd;".. fgettext("Password") .. "]"
42 local bind_addr = core.setting_get("bind_address")
43 if bind_addr ~= nil and bind_addr ~= "" then
45 "field[0.8,5.2;2.25,0.5;te_serveraddr;".. fgettext("Bind Address") .. ";" ..
46 core.formspec_escape(core.setting_get("bind_address")) .."]" ..
47 "field[3.05,5.2;1.25,0.5;te_serverport;".. fgettext("Port") .. ";" ..
48 core.formspec_escape(core.setting_get("port")) .."]"
51 "field[0.8,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"])
71 if event.type == "DCL" then
72 world_doubleclick = true
74 if event.type == "CHG" then
75 core.setting_set("mainmenu_last_selected_world",
76 menudata.worldlist:get_raw_index(core.get_textlist_index("srv_worlds")))
81 if menu_handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world") then
85 if fields["cb_creative_mode"] then
86 core.setting_set("creative_mode", fields["cb_creative_mode"])
90 if fields["cb_enable_damage"] then
91 core.setting_set("enable_damage", fields["cb_enable_damage"])
95 if fields["cb_server_announce"] then
96 core.setting_set("server_announce", fields["cb_server_announce"])
100 if fields["start_server"] ~= nil or
102 fields["key_enter"] then
103 local selected = core.get_textlist_index("srv_worlds")
104 if selected ~= nil then
105 gamedata.playername = fields["te_playername"]
106 gamedata.password = fields["te_passwd"]
107 gamedata.port = fields["te_serverport"]
108 gamedata.address = ""
109 gamedata.selected_world = menudata.worldlist:get_raw_index(selected)
111 core.setting_set("port",gamedata.port)
112 if fields["te_serveraddr"] ~= nil then
113 core.setting_set("bind_address",fields["te_serveraddr"])
117 local world = menudata.worldlist:get_raw_element(gamedata.selected_world)
119 local game,index = gamemgr.find_by_gameid(world.gameid)
120 core.setting_set("menu_last_game",game.id)
126 if fields["world_create"] ~= nil then
127 local create_world_dlg = create_create_world_dlg(true)
128 create_world_dlg:set_parent(this)
129 create_world_dlg:show()
134 if fields["world_delete"] ~= nil then
135 local selected = core.get_textlist_index("srv_worlds")
136 if selected ~= nil and
137 selected <= menudata.worldlist:size() then
138 local world = menudata.worldlist:get_list()[selected]
140 world.name ~= nil and
141 world.name ~= "" then
142 local index = menudata.worldlist:get_raw_index(selected)
143 local delete_world_dlg = create_delete_world_dlg(world.name,index)
144 delete_world_dlg:set_parent(this)
145 delete_world_dlg:show()
153 if fields["world_configure"] ~= nil then
154 local selected = core.get_textlist_index("srv_worlds")
155 if selected ~= nil then
157 create_configure_world_dlg(
158 menudata.worldlist:get_raw_index(selected))
160 if (configdialog ~= nil) then
161 configdialog:set_parent(this)
171 --------------------------------------------------------------------------------
174 caption = fgettext("Server"),
175 cbf_formspec = get_formspec,
176 cbf_button_handler = main_button_handler,