1 os.setlocale("C", "numeric")
3 local scriptpath = engine.get_scriptdir()
5 dofile(scriptpath .. DIR_DELIM .. "mainmenu_worldlist.lua")
6 dofile(scriptpath .. DIR_DELIM .. "modmgr.lua")
7 dofile(scriptpath .. DIR_DELIM .. "modstore.lua")
8 dofile(scriptpath .. DIR_DELIM .. "gamemgr.lua")
14 --------------------------------------------------------------------------------
15 function render_favourite(spec,render_details)
18 if spec.name ~= nil then
19 text = text .. fs_escape_string(spec.name:trim())
21 -- if spec.description ~= nil and
22 -- fs_escape_string(spec.description):trim() ~= "" then
23 -- text = text .. " (" .. fs_escape_string(spec.description) .. ")"
26 if spec.address ~= nil then
27 text = text .. spec.address:trim()
31 if not render_details then
36 if spec.password == true then
37 details = details .. "*"
39 details = details .. "_"
43 details = details .. "C"
45 details = details .. "_"
49 details = details .. "D"
51 details = details .. "_"
55 details = details .. "P"
57 details = details .. "_"
59 details = details .. " "
61 return fs_escape_string(details) .. text
64 --------------------------------------------------------------------------------
65 os.tempfolder = function()
66 local filetocheck = os.tmpname()
67 os.remove(filetocheck)
69 local randname = "MTTempModFolder_" .. math.random(0,10000)
70 if DIR_DELIM == "\\" then
71 local tempfolder = os.getenv("TEMP")
72 return tempfolder .. filetocheck
74 local backstring = filetocheck:reverse()
75 return filetocheck:sub(0,filetocheck:len()-backstring:find(DIR_DELIM)+1) ..randname
80 --------------------------------------------------------------------------------
81 function cleanup_path(temppath)
83 local parts = temppath:split("-")
86 if temppath ~= "" then
87 temppath = temppath .. "_"
89 temppath = temppath .. parts[i]
92 parts = temppath:split(".")
95 if temppath ~= "" then
96 temppath = temppath .. "_"
98 temppath = temppath .. parts[i]
101 parts = temppath:split("'")
104 if temppath ~= "" then
105 temppath = temppath .. ""
107 temppath = temppath .. parts[i]
110 parts = temppath:split(" ")
113 if temppath ~= "" then
116 temppath = temppath .. parts[i]
122 --------------------------------------------------------------------------------
124 function menu.set_texture(identifier,gamedetails)
125 local texture_set = false
126 if menu.texturepack ~= nil and gamedetails ~= nil then
127 local path = menu.basetexturedir ..
128 gamedetails.id .. "_menu_" .. identifier .. ".png"
130 if engine.set_background(identifier,path) then
135 if not texture_set and gamedetails ~= nil then
136 local path = gamedetails.path .. DIR_DELIM .."menu" ..
137 DIR_DELIM .. identifier .. ".png"
138 if engine.set_background(identifier,path) then
143 if not texture_set then
144 local path = menu.basetexturedir .. DIR_DELIM .."menu_" ..
146 if engine.set_background(identifier,path) then
151 if not texture_set then
152 local path = menu.defaulttexturedir .. DIR_DELIM .."menu_" ..
154 engine.set_background(identifier,path)
158 --------------------------------------------------------------------------------
159 function menu.update_gametype()
163 if (menu.game_last_check == nil or
164 menu.game_last_check ~= menu.last_game) and
165 tabbuilder.current_tab == "singleplayer" then
167 local gamedetails = menu.lastgame()
168 engine.set_topleft_text(gamedetails.name)
169 worldlist.set_gamefilter(gamedetails.id)
172 local background_set = false
173 if menu.texturepack ~= nil then
174 local path_background_texture = menu.basetexturedir ..
175 gamedetails.id .. "_menu_background.png"
177 if engine.set_background("background",path_background_texture) then
178 background_set = true
179 engine.set_clouds(false)
183 if not background_set then
184 local path_background_texture = gamedetails.path .. DIR_DELIM .."menu" ..
185 DIR_DELIM .. "background.png"
186 if engine.set_background("background",path_background_texture) then
187 background_set = true
188 engine.set_clouds(false)
192 if not background_set then
193 engine.set_clouds(true)
196 menu.set_texture("overlay",gamedetails)
197 menu.set_texture("header",gamedetails)
198 menu.set_texture("footer",gamedetails)
200 menu.game_last_check = menu.last_game
202 if menu.game_last_check ~= menu.last_game then
203 menu.game_last_check = menu.last_game
204 menu.reset_gametype()
209 --------------------------------------------------------------------------------
210 function menu.reset_gametype()
211 worldlist.set_gamefilter(nil)
212 menu.game_last_check = nil
214 local path_background_texture = menu.basetexturedir .. "menu_background.png"
216 if engine.set_background("background",path_background_texture) then
217 background_set = true
218 engine.set_clouds(false)
220 engine.set_clouds(true)
223 menu.set_texture("overlay",nil)
224 menu.set_texture("header",nil)
225 menu.set_texture("footer",nil)
226 engine.set_topleft_text("")
229 --------------------------------------------------------------------------------
230 function get_last_folder(text,count)
231 local parts = text:split(DIR_DELIM)
239 retval = retval .. parts[#parts - (count-i)] .. DIR_DELIM
245 --------------------------------------------------------------------------------
246 function init_globals()
248 gamedata.worldindex = 0
251 --------------------------------------------------------------------------------
252 function identify_filetype(name)
254 if name:sub(-3):lower() == "zip" then
261 if name:sub(-6):lower() == "tar.gz" or
262 name:sub(-3):lower() == "tgz"then
269 if name:sub(-6):lower() == "tar.bz2" then
276 if name:sub(-2):lower() == "7z" then
289 --------------------------------------------------------------------------------
290 function update_menu()
292 local formspec = "size[12,5.2]"
295 if gamedata.errormessage ~= nil then
296 formspec = formspec ..
297 "field[1,2;10,2;;ERROR: " ..
298 gamedata.errormessage ..
300 "button[4.5,4.2;3,0.5;btn_error_confirm;Ok]"
302 formspec = formspec .. tabbuilder.gettab()
305 engine.update_formspec(formspec)
308 --------------------------------------------------------------------------------
309 function menu.render_world_list()
312 local current_worldlist = worldlist.get_list()
314 for i,v in ipairs(current_worldlist) do
316 retval = retval ..","
319 retval = retval .. v.name ..
320 " \\[" .. v.gameid .. "\\]"
326 --------------------------------------------------------------------------------
329 gamemgr.update_gamelist()
331 menu.last_game = tonumber(engine.setting_get("main_menu_last_game_idx"))
333 if type(menu.last_game) ~= "number" then
337 if engine.setting_getbool("public_serverlist") then
338 menu.favorites = engine.get_favorites("online")
340 menu.favorites = engine.get_favorites("local")
344 menu.defaulttexturedir = engine.get_gamepath() .. DIR_DELIM .. ".." ..
345 DIR_DELIM .. "textures" .. DIR_DELIM .. "base" ..
346 DIR_DELIM .. "pack" .. DIR_DELIM
347 menu.basetexturedir = menu.defaulttexturedir
349 menu.texturepack = engine.setting_get("texture_path")
351 if menu.texturepack ~= nil then
352 menu.basetexturedir = menu.texturepack .. DIR_DELIM
356 --------------------------------------------------------------------------------
357 function menu.lastgame()
358 if menu.last_game > 0 and menu.last_game <= #gamemgr.games then
359 return gamemgr.games[menu.last_game]
362 if #gamemgr.games >= 1 then
364 return gamemgr.games[menu.last_game]
371 --------------------------------------------------------------------------------
372 function menu.update_last_game()
374 local current_world = worldlist.get_raw_world(
375 engine.setting_get("mainmenu_last_selected_world")
378 if current_world == nil then
382 for i=1,#gamemgr.games,1 do
383 if gamemgr.games[i].id == current_world.gameid then
385 engine.setting_set("main_menu_last_game_idx",menu.last_game)
391 --------------------------------------------------------------------------------
392 function menu.handle_key_up_down(fields,textlist,settingname)
394 if fields["key_up"] then
395 local oldidx = engine.get_textlist_index(textlist)
398 local newidx = oldidx -1
399 engine.setting_set(settingname,
400 worldlist.get_engine_index(newidx))
404 if fields["key_down"] then
405 local oldidx = engine.get_textlist_index(textlist)
407 if oldidx < worldlist.size() then
408 local newidx = oldidx + 1
409 engine.setting_set(settingname,
410 worldlist.get_engine_index(newidx))
416 --------------------------------------------------------------------------------
417 function menubar.handle_buttons(fields)
418 for i=1,#menubar.buttons,1 do
419 if fields[menubar.buttons[i].btn_name] ~= nil then
420 menu.last_game = menubar.buttons[i].index
421 engine.setting_set("main_menu_last_game_idx",menu.last_game)
422 menu.update_gametype()
427 --------------------------------------------------------------------------------
428 function menubar.refresh()
429 menubar.formspec = "box[-0.3,5.625;12.4,1.3;000000]" ..
430 "box[-0.3,5.6;12.4,0.05;FFFFFF]"
433 local button_base = -0.25
435 local maxbuttons = #gamemgr.games
437 if maxbuttons > 10 then
441 for i=1,maxbuttons,1 do
443 local btn_name = "menubar_btn_" .. gamemgr.games[i].id
444 local buttonpos = button_base + (i-1) * 1.245
445 if gamemgr.games[i].menuicon_path ~= nil and
446 gamemgr.games[i].menuicon_path ~= "" then
448 menubar.formspec = menubar.formspec ..
449 "image_button[" .. buttonpos .. ",5.7;1.3,1.3;" ..
450 gamemgr.games[i].menuicon_path .. ";" .. btn_name .. ";;true;false]"
453 local part1 = gamemgr.games[i].id:sub(1,5)
454 local part2 = gamemgr.games[i].id:sub(6,10)
455 local part3 = gamemgr.games[i].id:sub(11)
457 local text = part1 .. "\n" .. part2
460 text = text .. "\n" .. part3
462 menubar.formspec = menubar.formspec ..
463 "image_button[" .. buttonpos .. ",5.7;1.3,1.3;;" ..btn_name ..
464 ";" .. text .. ";true;true]"
472 table.insert(menubar.buttons,toadd)
476 --------------------------------------------------------------------------------
477 function tabbuilder.dialog_create_world()
478 local mapgens = {"v6", "v7", "indev", "singlenode", "math"}
480 local current_mg = engine.setting_get("mg_name")
485 for k,v in pairs(mapgens) do
486 if current_mg == v then
490 mglist = mglist .. v .. ","
492 mglist = mglist:sub(1, -2)
495 "label[2,0;World name]"..
496 "label[2,1;Mapgen]"..
497 "field[4.5,0.4;6,0.5;te_world_name;;]" ..
499 "button[5,4.5;2.6,0.5;world_create_confirm;Create]" ..
500 "button[7.5,4.5;2.8,0.5;world_create_cancel;Cancel]" ..
501 "dropdown[4.2,1;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
502 "textlist[4.2,1.9;5.8,2.3;games;" ..
503 gamemgr.gamelist() ..
504 ";" .. menu.last_game .. ";true]"
509 --------------------------------------------------------------------------------
510 function tabbuilder.dialog_delete_world()
511 return "label[2,2;Delete World \"" .. worldlist.get_raw_list()[menu.world_to_del].name .. "\"?]"..
512 "button[3.5,4.2;2.6,0.5;world_delete_confirm;Yes]" ..
513 "button[6,4.2;2.8,0.5;world_delete_cancel;No]"
516 --------------------------------------------------------------------------------
517 function tabbuilder.gettab()
520 if tabbuilder.show_buttons then
521 retval = retval .. tabbuilder.tab_header()
524 if tabbuilder.current_tab == "singleplayer" then
525 retval = retval .. tabbuilder.tab_singleplayer()
528 if tabbuilder.current_tab == "multiplayer" then
529 retval = retval .. tabbuilder.tab_multiplayer()
532 if tabbuilder.current_tab == "server" then
533 retval = retval .. tabbuilder.tab_server()
536 if tabbuilder.current_tab == "settings" then
537 retval = retval .. tabbuilder.tab_settings()
540 if tabbuilder.current_tab == "credits" then
541 retval = retval .. tabbuilder.tab_credits()
544 if tabbuilder.current_tab == "dialog_create_world" then
545 retval = retval .. tabbuilder.dialog_create_world()
548 if tabbuilder.current_tab == "dialog_delete_world" then
549 retval = retval .. tabbuilder.dialog_delete_world()
552 retval = retval .. modmgr.gettab(tabbuilder.current_tab)
553 retval = retval .. gamemgr.gettab(tabbuilder.current_tab)
554 retval = retval .. modstore.gettab(tabbuilder.current_tab)
559 --------------------------------------------------------------------------------
560 function tabbuilder.handle_create_world_buttons(fields)
562 if fields["world_create_confirm"] or
563 fields["key_enter"] then
565 local worldname = fields["te_world_name"]
566 local gameindex = engine.get_textlist_index("games")
573 if not worldlist.exists(worldname) then
574 engine.setting_set("mg_name",fields["dd_mapgen"])
575 message = engine.create_world(worldname,gameindex)
577 message = "A world named \"" .. worldname .. "\" already exists"
580 if message ~= nil then
581 gamedata.errormessage = message
583 menu.last_game = gameindex
584 engine.setting_set("main_menu_last_game_idx",gameindex)
587 engine.setting_set("mainmenu_last_selected_world",
588 worldlist.engine_index_by_name(worldname))
591 gamedata.errormessage = "No worldname given or no game selected"
595 if fields["games"] then
596 tabbuilder.skipformupdate = true
601 tabbuilder.is_dialog = false
602 tabbuilder.show_buttons = true
603 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
606 --------------------------------------------------------------------------------
607 function tabbuilder.handle_delete_world_buttons(fields)
609 if fields["world_delete_confirm"] then
610 if menu.world_to_del > 0 and
611 menu.world_to_del <= #worldlist.get_raw_list() then
612 engine.delete_world(menu.world_to_del)
613 menu.world_to_del = 0
618 tabbuilder.is_dialog = false
619 tabbuilder.show_buttons = true
620 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
623 --------------------------------------------------------------------------------
624 function tabbuilder.handle_multiplayer_buttons(fields)
626 if fields["te_name"] ~= nil then
627 gamedata.playername = fields["te_name"]
628 engine.setting_set("name", fields["te_name"])
631 if fields["favourites"] ~= nil then
632 local event = explode_textlist_event(fields["favourites"])
633 if event.typ == "DCL" then
634 gamedata.address = menu.favorites[event.index].address
635 gamedata.port = menu.favorites[event.index].port
636 gamedata.playername = fields["te_name"]
637 if fields["te_pwd"] ~= nil then
638 gamedata.password = fields["te_pwd"]
640 gamedata.selected_world = 0
642 if menu.favorites ~= nil then
643 gamedata.servername = menu.favorites[event.index].name
644 gamedata.serverdescription = menu.favorites[event.index].description
647 if gamedata.address ~= nil and
648 gamedata.port ~= nil then
654 if event.typ == "CHG" then
655 local address = menu.favorites[event.index].address
656 local port = menu.favorites[event.index].port
658 if address ~= nil and
660 engine.setting_set("address",address)
661 engine.setting_set("port",port)
664 menu.fav_selected = event.index
669 if fields["key_up"] ~= nil or
670 fields["key_down"] ~= nil then
672 local fav_idx = engine.get_textlist_index("favourites")
674 if fields["key_up"] ~= nil and fav_idx > 1 then
676 else if fields["key_down"] and fav_idx < #menu.favorites then
680 local address = menu.favorites[fav_idx].address
681 local port = menu.favorites[fav_idx].port
683 if address ~= nil and
685 engine.setting_set("address",address)
686 engine.setting_set("port",port)
689 menu.fav_selected = fav_idx
693 if fields["cb_public_serverlist"] ~= nil then
694 engine.setting_setbool("public_serverlist",
695 tabbuilder.tobool(fields["cb_public_serverlist"]))
697 if engine.setting_getbool("public_serverlist") then
698 menu.favorites = engine.get_favorites("online")
700 menu.favorites = engine.get_favorites("local")
702 menu.fav_selected = nil
706 if fields["btn_delete_favorite"] ~= nil then
707 local current_favourite = engine.get_textlist_index("favourites")
708 engine.delete_favorite(current_favourite)
709 menu.favorites = engine.get_favorites()
710 menu.fav_selected = nil
712 engine.setting_set("address","")
713 engine.setting_get("port","")
718 if fields["btn_mp_connect"] ~= nil or
719 fields["key_enter"] then
721 gamedata.playername = fields["te_name"]
722 gamedata.password = fields["te_pwd"]
723 gamedata.address = fields["te_address"]
724 gamedata.port = fields["te_port"]
726 local fav_idx = engine.get_textlist_index("favourites")
728 if fav_idx > 0 and fav_idx <= #menu.favorites and
729 menu.favorites[fav_idx].address == fields["te_address"] and
730 menu.favorites[fav_idx].port == fields["te_port"] then
732 gamedata.servername = menu.favorites[fav_idx].name
733 gamedata.serverdescription = menu.favorites[fav_idx].description
735 gamedata.servername = ""
736 gamedata.serverdescription = ""
739 gamedata.selected_world = 0
746 --------------------------------------------------------------------------------
747 function tabbuilder.handle_server_buttons(fields)
749 local world_doubleclick = false
751 if fields["srv_worlds"] ~= nil then
752 local event = explode_textlist_event(fields["srv_worlds"])
754 if event.typ == "DCL" then
755 world_doubleclick = true
757 if event.typ == "CHG" then
758 engine.setting_set("mainmenu_last_selected_world",
759 worldlist.get_engine_index(engine.get_textlist_index("srv_worlds")))
763 menu.handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world")
765 if fields["cb_creative_mode"] then
766 engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"]))
769 if fields["cb_enable_damage"] then
770 engine.setting_setbool("enable_damage",tabbuilder.tobool(fields["cb_enable_damage"]))
773 if fields["cb_server_announce"] then
774 engine.setting_setbool("server_announce",tabbuilder.tobool(fields["cb_server_announce"]))
777 if fields["start_server"] ~= nil or
779 fields["key_enter"] then
780 local selected = engine.get_textlist_index("srv_worlds")
782 gamedata.playername = fields["te_playername"]
783 gamedata.password = fields["te_passwd"]
784 gamedata.port = fields["te_serverport"]
785 gamedata.address = ""
786 gamedata.selected_world = worldlist.get_engine_index(selected)
788 menu.update_last_game(gamedata.selected_world)
793 if fields["world_create"] ~= nil then
794 tabbuilder.current_tab = "dialog_create_world"
795 tabbuilder.is_dialog = true
796 tabbuilder.show_buttons = false
799 if fields["world_delete"] ~= nil then
800 local selected = engine.get_textlist_index("srv_worlds")
802 selected <= worldlist.size() then
803 local world = worldlist.get_list()[selected]
805 world.name ~= nil and
806 world.name ~= "" then
807 menu.world_to_del = worldlist.get_engine_index(selected)
808 tabbuilder.current_tab = "dialog_delete_world"
809 tabbuilder.is_dialog = true
810 tabbuilder.show_buttons = false
812 menu.world_to_del = 0
817 if fields["world_configure"] ~= nil then
818 selected = engine.get_textlist_index("srv_worlds")
820 modmgr.world_config_selected_world = worldlist.get_engine_index(selected)
821 if modmgr.init_worldconfig() then
822 tabbuilder.current_tab = "dialog_configure_world"
823 tabbuilder.is_dialog = true
824 tabbuilder.show_buttons = false
830 --------------------------------------------------------------------------------
831 function tabbuilder.tobool(text)
832 if text == "true" then
839 --------------------------------------------------------------------------------
840 function tabbuilder.handle_settings_buttons(fields)
841 if fields["cb_fancy_trees"] then
842 engine.setting_setbool("new_style_leaves",tabbuilder.tobool(fields["cb_fancy_trees"]))
845 if fields["cb_smooth_lighting"] then
846 engine.setting_setbool("smooth_lighting",tabbuilder.tobool(fields["cb_smooth_lighting"]))
848 if fields["cb_3d_clouds"] then
849 engine.setting_setbool("enable_3d_clouds",tabbuilder.tobool(fields["cb_3d_clouds"]))
851 if fields["cb_opaque_water"] then
852 engine.setting_setbool("opaque_water",tabbuilder.tobool(fields["cb_opaque_water"]))
855 if fields["cb_mipmapping"] then
856 engine.setting_setbool("mip_map",tabbuilder.tobool(fields["cb_mipmapping"]))
858 if fields["cb_anisotrophic"] then
859 engine.setting_setbool("anisotropic_filter",tabbuilder.tobool(fields["cb_anisotrophic"]))
861 if fields["cb_bilinear"] then
862 engine.setting_setbool("bilinear_filter",tabbuilder.tobool(fields["cb_bilinear"]))
864 if fields["cb_trilinear"] then
865 engine.setting_setbool("trilinear_filter",tabbuilder.tobool(fields["cb_trilinear"]))
868 if fields["cb_shaders"] then
869 engine.setting_setbool("enable_shaders",tabbuilder.tobool(fields["cb_shaders"]))
871 if fields["cb_pre_ivis"] then
872 engine.setting_setbool("preload_item_visuals",tabbuilder.tobool(fields["cb_pre_ivis"]))
874 if fields["cb_particles"] then
875 engine.setting_setbool("enable_particles",tabbuilder.tobool(fields["cb_particles"]))
877 if fields["cb_finite_liquid"] then
878 engine.setting_setbool("liquid_finite",tabbuilder.tobool(fields["cb_finite_liquid"]))
881 if fields["btn_change_keys"] ~= nil then
882 engine.show_keys_menu()
886 --------------------------------------------------------------------------------
887 function tabbuilder.handle_singleplayer_buttons(fields)
889 local world_doubleclick = false
891 if fields["sp_worlds"] ~= nil then
892 local event = explode_textlist_event(fields["sp_worlds"])
894 if event.typ == "DCL" then
895 world_doubleclick = true
898 if event.typ == "CHG" then
899 engine.setting_set("mainmenu_last_selected_world",
900 worldlist.get_engine_index(engine.get_textlist_index("sp_worlds")))
904 menu.handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world")
906 if fields["cb_creative_mode"] then
907 engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"]))
910 if fields["cb_enable_damage"] then
911 engine.setting_setbool("enable_damage",tabbuilder.tobool(fields["cb_enable_damage"]))
914 if fields["play"] ~= nil or
916 fields["key_enter"] then
917 local selected = engine.get_textlist_index("sp_worlds")
919 gamedata.selected_world = worldlist.get_engine_index(selected)
920 gamedata.singleplayer = true
922 menu.update_last_game(gamedata.selected_world)
928 if fields["world_create"] ~= nil then
929 tabbuilder.current_tab = "dialog_create_world"
930 tabbuilder.is_dialog = true
931 tabbuilder.show_buttons = false
934 if fields["world_delete"] ~= nil then
935 local selected = engine.get_textlist_index("sp_worlds")
937 selected <= worldlist.size() then
938 local world = worldlist.get_list()[selected]
940 world.name ~= nil and
941 world.name ~= "" then
942 menu.world_to_del = worldlist.get_engine_index(selected)
943 tabbuilder.current_tab = "dialog_delete_world"
944 tabbuilder.is_dialog = true
945 tabbuilder.show_buttons = false
947 menu.world_to_del = 0
952 if fields["world_configure"] ~= nil then
953 selected = engine.get_textlist_index("sp_worlds")
955 modmgr.world_config_selected_world = worldlist.get_engine_index(selected)
956 if modmgr.init_worldconfig() then
957 tabbuilder.current_tab = "dialog_configure_world"
958 tabbuilder.is_dialog = true
959 tabbuilder.show_buttons = false
965 --------------------------------------------------------------------------------
966 function tabbuilder.tab_header()
968 if tabbuilder.last_tab_index == nil then
969 tabbuilder.last_tab_index = 1
974 for i=1,#tabbuilder.current_buttons,1 do
980 toadd = toadd .. tabbuilder.current_buttons[i].caption
982 return "tabheader[-0.3,-0.99;main_tab;" .. toadd ..";" .. tabbuilder.last_tab_index .. ";true;false]"
985 --------------------------------------------------------------------------------
986 function tabbuilder.handle_tab_buttons(fields)
988 if fields["main_tab"] then
989 local index = tonumber(fields["main_tab"])
990 tabbuilder.last_tab_index = index
991 tabbuilder.current_tab = tabbuilder.current_buttons[index].name
993 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
997 if tabbuilder.current_tab ~= tabbuilder.old_tab then
998 if tabbuilder.current_tab ~= "singleplayer" then
999 menu.reset_gametype()
1003 if tabbuilder.current_tab == "singleplayer" then
1004 menu.update_gametype()
1007 tabbuilder.old_tab = tabbuilder.current_tab
1010 --------------------------------------------------------------------------------
1011 function tabbuilder.init()
1012 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1014 if tabbuilder.current_tab == nil or
1015 tabbuilder.current_tab == "" then
1016 tabbuilder.current_tab = "singleplayer"
1017 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
1021 --initialize tab buttons
1022 tabbuilder.last_tab = nil
1023 tabbuilder.show_buttons = true
1025 tabbuilder.current_buttons = {}
1026 table.insert(tabbuilder.current_buttons,{name="singleplayer", caption="Singleplayer"})
1027 table.insert(tabbuilder.current_buttons,{name="multiplayer", caption="Client"})
1028 table.insert(tabbuilder.current_buttons,{name="server", caption="Server"})
1029 table.insert(tabbuilder.current_buttons,{name="settings", caption="Settings"})
1031 if engine.setting_getbool("main_menu_game_mgr") then
1032 table.insert(tabbuilder.current_buttons,{name="game_mgr", caption="Games"})
1035 if engine.setting_getbool("main_menu_mod_mgr") then
1036 table.insert(tabbuilder.current_buttons,{name="mod_mgr", caption="Mods"})
1038 table.insert(tabbuilder.current_buttons,{name="credits", caption="Credits"})
1041 for i=1,#tabbuilder.current_buttons,1 do
1042 if tabbuilder.current_buttons[i].name == tabbuilder.current_tab then
1043 tabbuilder.last_tab_index = i
1047 menu.update_gametype()
1050 --------------------------------------------------------------------------------
1051 function tabbuilder.tab_multiplayer()
1054 "vertlabel[0,-0.25;CLIENT]" ..
1055 "label[1,-0.25;Favorites:]"..
1056 "label[1,4.25;Address/Port]"..
1057 "label[9,2.75;Name/Password]" ..
1058 "field[1.25,5.25;5.5,0.5;te_address;;" ..engine.setting_get("address") .."]" ..
1059 "field[6.75,5.25;2.25,0.5;te_port;;" ..engine.setting_get("port") .."]" ..
1060 "checkbox[1,3.6;cb_public_serverlist;Public Serverlist;" ..
1061 dump(engine.setting_getbool("public_serverlist")) .. "]"
1063 if not engine.setting_getbool("public_serverlist") then
1065 "button[6.45,3.95;2.25,0.5;btn_delete_favorite;Delete]"
1069 "button[9,4.95;2.5,0.5;btn_mp_connect;Connect]" ..
1070 "field[9.3,3.75;2.5,0.5;te_name;;" ..engine.setting_get("name") .."]" ..
1071 "pwdfield[9.3,4.5;2.5,0.5;te_pwd;]" ..
1072 "textarea[9.3,0.25;2.5,2.75;;"
1073 if menu.fav_selected ~= nil and
1074 menu.favorites[menu.fav_selected].description ~= nil then
1076 fs_escape_string(menu.favorites[menu.fav_selected].description,true)
1081 "textlist[1,0.35;7.5,3.35;favourites;"
1083 local render_details = engine.setting_getbool("public_serverlist")
1085 if #menu.favorites > 0 then
1086 retval = retval .. render_favourite(menu.favorites[1],render_details)
1088 for i=2,#menu.favorites,1 do
1089 retval = retval .. "," .. render_favourite(menu.favorites[i],render_details)
1093 if menu.fav_selected ~= nil then
1094 retval = retval .. ";" .. menu.fav_selected .. "]"
1096 retval = retval .. ";0]"
1102 --------------------------------------------------------------------------------
1103 function tabbuilder.tab_server()
1105 local index = worldlist.get_current_index(
1106 tonumber(engine.setting_get("mainmenu_last_selected_world"))
1110 "button[4,4.15;2.6,0.5;world_delete;Delete]" ..
1111 "button[6.5,4.15;2.8,0.5;world_create;New]" ..
1112 "button[9.2,4.15;2.55,0.5;world_configure;Configure]" ..
1113 "button[8.5,4.9;3.25,0.5;start_server;Start Game]" ..
1114 "label[4,-0.25;Select World:]"..
1115 "vertlabel[0,-0.25;START SERVER]" ..
1116 "checkbox[0.5,0.25;cb_creative_mode;Creative Mode;" ..
1117 dump(engine.setting_getbool("creative_mode")) .. "]"..
1118 "checkbox[0.5,0.7;cb_enable_damage;Enable Damage;" ..
1119 dump(engine.setting_getbool("enable_damage")) .. "]"..
1120 "checkbox[0.5,1.15;cb_server_announce;Public;" ..
1121 dump(engine.setting_getbool("server_announce")) .. "]"..
1122 "field[0.8,3.2;3,0.5;te_playername;Name;" ..
1123 engine.setting_get("name") .. "]" ..
1124 "pwdfield[0.8,4.2;3,0.5;te_passwd;Password]" ..
1125 "field[0.8,5.2;3,0.5;te_serverport;Server Port;30000]" ..
1126 "textlist[4,0.25;7.5,3.7;srv_worlds;" ..
1127 menu.render_world_list() ..
1133 --------------------------------------------------------------------------------
1134 function tabbuilder.tab_settings()
1135 return "vertlabel[0,0;SETTINGS]" ..
1136 "checkbox[1,0.75;cb_fancy_trees;Fancy trees;" .. dump(engine.setting_getbool("new_style_leaves")) .. "]"..
1137 "checkbox[1,1.25;cb_smooth_lighting;Smooth Lighting;".. dump(engine.setting_getbool("smooth_lighting")) .. "]"..
1138 "checkbox[1,1.75;cb_3d_clouds;3D Clouds;" .. dump(engine.setting_getbool("enable_3d_clouds")) .. "]"..
1139 "checkbox[1,2.25;cb_opaque_water;Opaque Water;" .. dump(engine.setting_getbool("opaque_water")) .. "]"..
1141 "checkbox[4,0.75;cb_mipmapping;Mip-Mapping;" .. dump(engine.setting_getbool("mip_map")) .. "]"..
1142 "checkbox[4,1.25;cb_anisotrophic;Anisotropic Filtering;".. dump(engine.setting_getbool("anisotropic_filter")) .. "]"..
1143 "checkbox[4,1.75;cb_bilinear;Bi-Linear Filtering;" .. dump(engine.setting_getbool("bilinear_filter")) .. "]"..
1144 "checkbox[4,2.25;cb_trilinear;Tri-Linear Filtering;" .. dump(engine.setting_getbool("trilinear_filter")) .. "]"..
1146 "checkbox[7.5,0.75;cb_shaders;Shaders;" .. dump(engine.setting_getbool("enable_shaders")) .. "]"..
1147 "checkbox[7.5,1.25;cb_pre_ivis;Preload item visuals;".. dump(engine.setting_getbool("preload_item_visuals")) .. "]"..
1148 "checkbox[7.5,1.75;cb_particles;Enable Particles;" .. dump(engine.setting_getbool("enable_particles")) .. "]"..
1149 "checkbox[7.5,2.25;cb_finite_liquid;Finite Liquid;" .. dump(engine.setting_getbool("liquid_finite")) .. "]"..
1151 "button[1,3.75;2.25,0.5;btn_change_keys;Change keys]"
1154 --------------------------------------------------------------------------------
1155 function tabbuilder.tab_singleplayer()
1157 local index = worldlist.get_current_index(
1158 tonumber(engine.setting_get("mainmenu_last_selected_world"))
1161 return "button[4,4.15;2.6,0.5;world_delete;Delete]" ..
1162 "button[6.5,4.15;2.8,0.5;world_create;New]" ..
1163 "button[9.2,4.15;2.55,0.5;world_configure;Configure]" ..
1164 "button[8.5,4.95;3.25,0.5;play;Play]" ..
1165 "label[4,-0.25;Select World:]"..
1166 "vertlabel[0,-0.25;SINGLE PLAYER]" ..
1167 "checkbox[0.5,0.25;cb_creative_mode;Creative Mode;" ..
1168 dump(engine.setting_getbool("creative_mode")) .. "]"..
1169 "checkbox[0.5,0.7;cb_enable_damage;Enable Damage;" ..
1170 dump(engine.setting_getbool("enable_damage")) .. "]"..
1171 "textlist[4,0.25;7.5,3.7;sp_worlds;" ..
1172 menu.render_world_list() ..
1173 ";" .. index .. "]" ..
1177 --------------------------------------------------------------------------------
1178 function tabbuilder.tab_credits()
1179 return "vertlabel[0,-0.5;CREDITS]" ..
1180 "label[0.5,3;Minetest " .. engine.get_version() .. "]" ..
1181 "label[0.5,3.3;http://minetest.net]" ..
1182 "image[0.5,1;" .. menu.defaulttexturedir .. "logo.png]" ..
1183 "textlist[3.5,-0.25;8.5,5.8;list_credits;" ..
1184 "#FFFF00Core Developers," ..
1185 "Perttu Ahola (celeron55) <celeron55@gmail.com>,"..
1186 "Ryan Kwolek (kwolekr) <kwolekr@minetest.net>,"..
1187 "PilzAdam <pilzadam@minetest.net>," ..
1188 "IIya Zhuravlev (thexyz) <xyz@minetest.net>,"..
1189 "Lisa Milne (darkrose) <lisa@ltmnet.com>,"..
1190 "Maciej Kasatkin (RealBadAngel) <mk@realbadangel.pl>,"..
1191 "proller <proler@gmail.com>,"..
1192 "sfan5 <sfan5@live.de>,"..
1193 "kahrl <kahrl@gmx.net>,"..
1195 "#FFFF00Active Contributors," ..
1197 "Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>,"..
1198 "Jurgen Doser (doserj) <jurgen.doser@gmail.com>,"..
1199 "Jeija <jeija@mesecons.net>,"..
1200 "MirceaKitsune <mirceakitsune@gmail.com>,"..
1202 "dannydark <the_skeleton_of_a_child@yahoo.co.uk>,"..
1203 "0gb.us <0gb.us@0gb.us>,"..
1205 "#FFFF00Previous Contributors," ..
1206 "Guiseppe Bilotta (Oblomov) <guiseppe.bilotta@gmail.com>,"..
1207 "Jonathan Neuschafer <j.neuschaefer@gmx.net>,"..
1208 "Nils Dagsson Moskopp (erlehmann) <nils@dieweltistgarnichtso.net>,"..
1209 "Constantin Wenger (SpeedProg) <constantin.wenger@googlemail.com>,"..
1210 "matttpt <matttpt@gmail.com>,"..
1211 "JacobF <queatz@gmail.com>,"..
1215 --------------------------------------------------------------------------------
1216 function tabbuilder.checkretval(retval)
1218 if retval ~= nil then
1219 if retval.current_tab ~= nil then
1220 tabbuilder.current_tab = retval.current_tab
1223 if retval.is_dialog ~= nil then
1224 tabbuilder.is_dialog = retval.is_dialog
1227 if retval.show_buttons ~= nil then
1228 tabbuilder.show_buttons = retval.show_buttons
1231 if retval.skipformupdate ~= nil then
1232 tabbuilder.skipformupdate = retval.skipformupdate
1237 --------------------------------------------------------------------------------
1238 --------------------------------------------------------------------------------
1239 -- initialize callbacks
1240 --------------------------------------------------------------------------------
1241 --------------------------------------------------------------------------------
1242 engine.button_handler = function(fields)
1243 --print("Buttonhandler: tab: " .. tabbuilder.current_tab .. " fields: " .. dump(fields))
1245 if fields["btn_error_confirm"] then
1246 gamedata.errormessage = nil
1249 local retval = modmgr.handle_buttons(tabbuilder.current_tab,fields)
1250 tabbuilder.checkretval(retval)
1252 retval = gamemgr.handle_buttons(tabbuilder.current_tab,fields)
1253 tabbuilder.checkretval(retval)
1255 retval = modstore.handle_buttons(tabbuilder.current_tab,fields)
1256 tabbuilder.checkretval(retval)
1258 if tabbuilder.current_tab == "dialog_create_world" then
1259 tabbuilder.handle_create_world_buttons(fields)
1262 if tabbuilder.current_tab == "dialog_delete_world" then
1263 tabbuilder.handle_delete_world_buttons(fields)
1266 if tabbuilder.current_tab == "singleplayer" then
1267 tabbuilder.handle_singleplayer_buttons(fields)
1270 if tabbuilder.current_tab == "multiplayer" then
1271 tabbuilder.handle_multiplayer_buttons(fields)
1274 if tabbuilder.current_tab == "settings" then
1275 tabbuilder.handle_settings_buttons(fields)
1278 if tabbuilder.current_tab == "server" then
1279 tabbuilder.handle_server_buttons(fields)
1283 tabbuilder.handle_tab_buttons(fields)
1286 menubar.handle_buttons(fields)
1288 if not tabbuilder.skipformupdate then
1292 tabbuilder.skipformupdate = false
1296 --------------------------------------------------------------------------------
1297 engine.event_handler = function(event)
1298 if event == "MenuQuit" then
1299 if tabbuilder.is_dialog then
1300 tabbuilder.is_dialog = false
1301 tabbuilder.show_buttons = true
1302 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1310 --------------------------------------------------------------------------------
1311 --------------------------------------------------------------------------------
1313 --------------------------------------------------------------------------------
1314 --------------------------------------------------------------------------------