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.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.setting_get("bind_address") .."]" ..
47 "field[3.05,5.2;1.25,0.5;te_serverport;".. fgettext("Port") .. ";" ..
48 core.setting_get("port") .."]"
51 "field[0.8,5.2;3.5,0.5;te_serverport;".. fgettext("Server Port") .. ";" ..
52 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")))
80 if menu_handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world") then
84 if fields["cb_creative_mode"] then
85 core.setting_set("creative_mode", fields["cb_creative_mode"])
88 if fields["cb_enable_damage"] then
89 core.setting_set("enable_damage", fields["cb_enable_damage"])
92 if fields["cb_server_announce"] then
93 core.setting_set("server_announce", fields["cb_server_announce"])
96 if fields["start_server"] ~= nil or
98 fields["key_enter"] then
99 local selected = core.get_textlist_index("srv_worlds")
100 if selected ~= nil then
101 gamedata.playername = fields["te_playername"]
102 gamedata.password = fields["te_passwd"]
103 gamedata.port = fields["te_serverport"]
104 gamedata.address = ""
105 gamedata.selected_world = menudata.worldlist:get_raw_index(selected)
107 core.setting_set("port",gamedata.port)
108 if fields["te_serveraddr"] ~= nil then
109 core.setting_set("bind_address",fields["te_serveraddr"])
113 local world = menudata.worldlist:get_raw_element(gamedata.selected_world)
114 local game,index = gamemgr.find_by_gameid(world.gameid)
115 core.setting_set("menu_last_game",game.id)
120 if fields["world_create"] ~= nil then
121 print("create world dialog")
122 local create_world_dlg = create_create_world_dlg(true)
123 create_world_dlg:set_parent(this)
124 create_world_dlg:show()
129 if fields["world_delete"] ~= nil then
130 local selected = core.get_textlist_index("srv_worlds")
131 if selected ~= nil and
132 selected <= menudata.worldlist:size() then
133 local world = menudata.worldlist:get_list()[selected]
135 world.name ~= nil and
136 world.name ~= "" then
137 local index = menudata.worldlist:get_raw_index(selected)
138 local delete_world_dlg = create_delete_world_dlg(world.name,index)
139 delete_world_dlg:set_parent(this)
140 delete_world_dlg:show()
148 if fields["world_configure"] ~= nil then
149 local selected = core.get_textlist_index("srv_worlds")
150 if selected ~= nil then
152 create_configure_world_dlg(
153 menudata.worldlist:get_raw_index(selected))
155 if (configdialog ~= nil) then
156 configdialog:set_parent(this)
166 --------------------------------------------------------------------------------
169 caption = fgettext("Server"),
170 cbf_formspec = get_formspec,
171 cbf_button_handler = main_button_handler,