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 menu.favorites ~= nil then
648 gamedata.servername = menu.favorites[event.index].name
649 gamedata.serverdescription = menu.favorites[event.index].description
652 if gamedata.address ~= nil and
653 gamedata.port ~= nil then
659 if event.typ == "CHG" then
660 local address = menu.favorites[event.index].address
661 local port = menu.favorites[event.index].port
663 if address ~= nil and
665 engine.setting_set("address",address)
666 engine.setting_set("port",port)
669 menu.fav_selected = event.index
674 if fields["key_up"] ~= nil or
675 fields["key_down"] ~= nil then
677 local fav_idx = engine.get_textlist_index("favourites")
679 if fields["key_up"] ~= nil and fav_idx > 1 then
681 else if fields["key_down"] and fav_idx < #menu.favorites then
685 local address = menu.favorites[fav_idx].address
686 local port = menu.favorites[fav_idx].port
688 if address ~= nil and
690 engine.setting_set("address",address)
691 engine.setting_set("port",port)
694 menu.fav_selected = fav_idx
698 if fields["cb_public_serverlist"] ~= nil then
699 engine.setting_setbool("public_serverlist",
700 tabbuilder.tobool(fields["cb_public_serverlist"]))
702 if engine.setting_getbool("public_serverlist") then
703 menu.favorites = engine.get_favorites("online")
705 menu.favorites = engine.get_favorites("local")
707 menu.fav_selected = nil
711 if fields["btn_delete_favorite"] ~= nil then
712 local current_favourite = engine.get_textlist_index("favourites")
713 engine.delete_favorite(current_favourite)
714 menu.favorites = engine.get_favorites()
715 menu.fav_selected = nil
717 engine.setting_set("address","")
718 engine.setting_get("port","")
723 if fields["btn_mp_connect"] ~= nil or
724 fields["key_enter"] then
726 gamedata.playername = fields["te_name"]
727 gamedata.password = fields["te_pwd"]
728 gamedata.address = fields["te_address"]
729 gamedata.port = fields["te_port"]
731 local fav_idx = engine.get_textlist_index("favourites")
733 if fav_idx > 0 and fav_idx <= #menu.favorites and
734 menu.favorites[fav_idx].address == fields["te_address"] and
735 menu.favorites[fav_idx].port == fields["te_port"] then
737 gamedata.servername = menu.favorites[fav_idx].name
738 gamedata.serverdescription = menu.favorites[fav_idx].description
740 gamedata.servername = ""
741 gamedata.serverdescription = ""
744 gamedata.selected_world = 0
751 --------------------------------------------------------------------------------
752 function tabbuilder.handle_server_buttons(fields)
754 local world_doubleclick = false
756 if fields["srv_worlds"] ~= nil then
757 local event = explode_textlist_event(fields["srv_worlds"])
759 if event.typ == "DCL" then
760 world_doubleclick = true
762 if event.typ == "CHG" then
763 engine.setting_set("mainmenu_last_selected_world",
764 worldlist.get_engine_index(engine.get_textlist_index("srv_worlds")))
768 menu.handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world")
770 if fields["cb_creative_mode"] then
771 engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"]))
774 if fields["cb_enable_damage"] then
775 engine.setting_setbool("enable_damage",tabbuilder.tobool(fields["cb_enable_damage"]))
778 if fields["cb_server_announce"] then
779 engine.setting_setbool("server_announce",tabbuilder.tobool(fields["cb_server_announce"]))
782 if fields["start_server"] ~= nil or
784 fields["key_enter"] then
785 local selected = engine.get_textlist_index("srv_worlds")
787 gamedata.playername = fields["te_playername"]
788 gamedata.password = fields["te_passwd"]
789 gamedata.port = fields["te_serverport"]
790 gamedata.address = ""
791 gamedata.selected_world = worldlist.get_engine_index(selected)
793 menu.update_last_game(gamedata.selected_world)
798 if fields["world_create"] ~= nil then
799 tabbuilder.current_tab = "dialog_create_world"
800 tabbuilder.is_dialog = true
801 tabbuilder.show_buttons = false
804 if fields["world_delete"] ~= nil then
805 local selected = engine.get_textlist_index("srv_worlds")
807 selected <= worldlist.size() then
808 local world = worldlist.get_list()[selected]
810 world.name ~= nil and
811 world.name ~= "" then
812 menu.world_to_del = worldlist.get_engine_index(selected)
813 tabbuilder.current_tab = "dialog_delete_world"
814 tabbuilder.is_dialog = true
815 tabbuilder.show_buttons = false
817 menu.world_to_del = 0
822 if fields["world_configure"] ~= nil then
823 selected = engine.get_textlist_index("srv_worlds")
825 modmgr.world_config_selected_world = worldlist.get_engine_index(selected)
826 if modmgr.init_worldconfig() then
827 tabbuilder.current_tab = "dialog_configure_world"
828 tabbuilder.is_dialog = true
829 tabbuilder.show_buttons = false
835 --------------------------------------------------------------------------------
836 function tabbuilder.tobool(text)
837 if text == "true" then
844 --------------------------------------------------------------------------------
845 function tabbuilder.handle_settings_buttons(fields)
846 if fields["cb_fancy_trees"] then
847 engine.setting_setbool("new_style_leaves",tabbuilder.tobool(fields["cb_fancy_trees"]))
850 if fields["cb_smooth_lighting"] then
851 engine.setting_setbool("smooth_lighting",tabbuilder.tobool(fields["cb_smooth_lighting"]))
853 if fields["cb_3d_clouds"] then
854 engine.setting_setbool("enable_3d_clouds",tabbuilder.tobool(fields["cb_3d_clouds"]))
856 if fields["cb_opaque_water"] then
857 engine.setting_setbool("opaque_water",tabbuilder.tobool(fields["cb_opaque_water"]))
860 if fields["cb_mipmapping"] then
861 engine.setting_setbool("mip_map",tabbuilder.tobool(fields["cb_mipmapping"]))
863 if fields["cb_anisotrophic"] then
864 engine.setting_setbool("anisotropic_filter",tabbuilder.tobool(fields["cb_anisotrophic"]))
866 if fields["cb_bilinear"] then
867 engine.setting_setbool("bilinear_filter",tabbuilder.tobool(fields["cb_bilinear"]))
869 if fields["cb_trilinear"] then
870 engine.setting_setbool("trilinear_filter",tabbuilder.tobool(fields["cb_trilinear"]))
873 if fields["cb_shaders"] then
874 engine.setting_setbool("enable_shaders",tabbuilder.tobool(fields["cb_shaders"]))
876 if fields["cb_pre_ivis"] then
877 engine.setting_setbool("preload_item_visuals",tabbuilder.tobool(fields["cb_pre_ivis"]))
879 if fields["cb_particles"] then
880 engine.setting_setbool("enable_particles",tabbuilder.tobool(fields["cb_particles"]))
882 if fields["cb_finite_liquid"] then
883 engine.setting_setbool("liquid_finite",tabbuilder.tobool(fields["cb_finite_liquid"]))
886 if fields["btn_change_keys"] ~= nil then
887 engine.show_keys_menu()
891 --------------------------------------------------------------------------------
892 function tabbuilder.handle_singleplayer_buttons(fields)
894 local world_doubleclick = false
896 if fields["sp_worlds"] ~= nil then
897 local event = explode_textlist_event(fields["sp_worlds"])
899 if event.typ == "DCL" then
900 world_doubleclick = true
903 if event.typ == "CHG" then
904 engine.setting_set("mainmenu_last_selected_world",
905 worldlist.get_engine_index(engine.get_textlist_index("sp_worlds")))
909 menu.handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world")
911 if fields["cb_creative_mode"] then
912 engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"]))
915 if fields["cb_enable_damage"] then
916 engine.setting_setbool("enable_damage",tabbuilder.tobool(fields["cb_enable_damage"]))
919 if fields["play"] ~= nil or
921 fields["key_enter"] then
922 local selected = engine.get_textlist_index("sp_worlds")
924 gamedata.selected_world = worldlist.get_engine_index(selected)
925 gamedata.singleplayer = true
927 menu.update_last_game(gamedata.selected_world)
933 if fields["world_create"] ~= nil then
934 tabbuilder.current_tab = "dialog_create_world"
935 tabbuilder.is_dialog = true
936 tabbuilder.show_buttons = false
939 if fields["world_delete"] ~= nil then
940 local selected = engine.get_textlist_index("sp_worlds")
942 selected <= worldlist.size() then
943 local world = worldlist.get_list()[selected]
945 world.name ~= nil and
946 world.name ~= "" then
947 menu.world_to_del = worldlist.get_engine_index(selected)
948 tabbuilder.current_tab = "dialog_delete_world"
949 tabbuilder.is_dialog = true
950 tabbuilder.show_buttons = false
952 menu.world_to_del = 0
957 if fields["world_configure"] ~= nil then
958 selected = engine.get_textlist_index("sp_worlds")
960 modmgr.world_config_selected_world = worldlist.get_engine_index(selected)
961 if modmgr.init_worldconfig() then
962 tabbuilder.current_tab = "dialog_configure_world"
963 tabbuilder.is_dialog = true
964 tabbuilder.show_buttons = false
970 --------------------------------------------------------------------------------
971 function tabbuilder.tab_header()
973 if tabbuilder.last_tab_index == nil then
974 tabbuilder.last_tab_index = 1
979 for i=1,#tabbuilder.current_buttons,1 do
985 toadd = toadd .. tabbuilder.current_buttons[i].caption
987 return "tabheader[-0.3,-0.99;main_tab;" .. toadd ..";" .. tabbuilder.last_tab_index .. ";true;false]"
990 --------------------------------------------------------------------------------
991 function tabbuilder.handle_tab_buttons(fields)
993 if fields["main_tab"] then
994 local index = tonumber(fields["main_tab"])
995 tabbuilder.last_tab_index = index
996 tabbuilder.current_tab = tabbuilder.current_buttons[index].name
998 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
1001 --handle tab changes
1002 if tabbuilder.current_tab ~= tabbuilder.old_tab then
1003 if tabbuilder.current_tab ~= "singleplayer" then
1004 menu.reset_gametype()
1008 if tabbuilder.current_tab == "singleplayer" then
1009 menu.update_gametype()
1012 tabbuilder.old_tab = tabbuilder.current_tab
1015 --------------------------------------------------------------------------------
1016 function tabbuilder.init()
1017 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1019 if tabbuilder.current_tab == nil or
1020 tabbuilder.current_tab == "" then
1021 tabbuilder.current_tab = "singleplayer"
1022 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
1026 --initialize tab buttons
1027 tabbuilder.last_tab = nil
1028 tabbuilder.show_buttons = true
1030 tabbuilder.current_buttons = {}
1031 table.insert(tabbuilder.current_buttons,{name="singleplayer", caption="Singleplayer"})
1032 table.insert(tabbuilder.current_buttons,{name="multiplayer", caption="Client"})
1033 table.insert(tabbuilder.current_buttons,{name="server", caption="Server"})
1034 table.insert(tabbuilder.current_buttons,{name="settings", caption="Settings"})
1036 if engine.setting_getbool("main_menu_game_mgr") then
1037 table.insert(tabbuilder.current_buttons,{name="game_mgr", caption="Games"})
1040 if engine.setting_getbool("main_menu_mod_mgr") then
1041 table.insert(tabbuilder.current_buttons,{name="mod_mgr", caption="Mods"})
1043 table.insert(tabbuilder.current_buttons,{name="credits", caption="Credits"})
1046 for i=1,#tabbuilder.current_buttons,1 do
1047 if tabbuilder.current_buttons[i].name == tabbuilder.current_tab then
1048 tabbuilder.last_tab_index = i
1052 menu.update_gametype()
1055 --------------------------------------------------------------------------------
1056 function tabbuilder.tab_multiplayer()
1059 "vertlabel[0,-0.25;CLIENT]" ..
1060 "label[1,-0.25;Favorites:]"..
1061 "label[1,4.25;Address/Port]"..
1062 "label[9,0;Name/Password]" ..
1063 "field[1.25,5.25;5.5,0.5;te_address;;" ..engine.setting_get("address") .."]" ..
1064 "field[6.75,5.25;2.25,0.5;te_port;;" ..engine.setting_get("port") .."]" ..
1065 "checkbox[1,3.6;cb_public_serverlist;Public Serverlist;" ..
1066 dump(engine.setting_getbool("public_serverlist")) .. "]"
1068 if not engine.setting_getbool("public_serverlist") then
1070 "button[6.45,3.95;2.25,0.5;btn_delete_favorite;Delete]"
1074 "button[9,4.95;2.5,0.5;btn_mp_connect;Connect]" ..
1075 "field[9.25,1;2.5,0.5;te_name;;" ..engine.setting_get("name") .."]" ..
1076 "pwdfield[9.25,1.75;2.5,0.5;te_pwd;]" ..
1077 "textarea[9.25,2.25;2.5,2.75;;"
1078 if menu.fav_selected ~= nil and
1079 menu.favorites[menu.fav_selected].description ~= nil then
1081 fs_escape_string(menu.favorites[menu.fav_selected].description,true)
1086 "textlist[1,0.35;7.5,3.35;favourites;"
1088 local render_details = engine.setting_getbool("public_serverlist")
1090 if #menu.favorites > 0 then
1091 retval = retval .. render_favourite(menu.favorites[1],render_details)
1093 for i=2,#menu.favorites,1 do
1094 retval = retval .. "," .. render_favourite(menu.favorites[i],render_details)
1098 if menu.fav_selected ~= nil then
1099 retval = retval .. ";" .. menu.fav_selected .. "]"
1101 retval = retval .. ";0]"
1107 --------------------------------------------------------------------------------
1108 function tabbuilder.tab_server()
1110 local index = worldlist.get_current_index(
1111 tonumber(engine.setting_get("mainmenu_last_selected_world"))
1115 "button[4,4.15;2.6,0.5;world_delete;Delete]" ..
1116 "button[6.5,4.15;2.8,0.5;world_create;New]" ..
1117 "button[9.2,4.15;2.55,0.5;world_configure;Configure]" ..
1118 "button[8.5,4.9;3.25,0.5;start_server;Start Game]" ..
1119 "label[4,-0.25;Select World:]"..
1120 "vertlabel[0,-0.25;START SERVER]" ..
1121 "checkbox[0.5,0.25;cb_creative_mode;Creative Mode;" ..
1122 dump(engine.setting_getbool("creative_mode")) .. "]"..
1123 "checkbox[0.5,0.7;cb_enable_damage;Enable Damage;" ..
1124 dump(engine.setting_getbool("enable_damage")) .. "]"..
1125 "checkbox[0.5,1.15;cb_server_announce;Public;" ..
1126 dump(engine.setting_getbool("server_announce")) .. "]"..
1127 "field[0.8,3.2;3,0.5;te_playername;Name;" ..
1128 engine.setting_get("name") .. "]" ..
1129 "pwdfield[0.8,4.2;3,0.5;te_passwd;Password]" ..
1130 "field[0.8,5.2;3,0.5;te_serverport;Server Port;30000]" ..
1131 "textlist[4,0.25;7.5,3.7;srv_worlds;" ..
1132 menu.render_world_list() ..
1138 --------------------------------------------------------------------------------
1139 function tabbuilder.tab_settings()
1140 return "vertlabel[0,0;SETTINGS]" ..
1141 "checkbox[1,0.75;cb_fancy_trees;Fancy trees;" .. dump(engine.setting_getbool("new_style_leaves")) .. "]"..
1142 "checkbox[1,1.25;cb_smooth_lighting;Smooth Lighting;".. dump(engine.setting_getbool("smooth_lighting")) .. "]"..
1143 "checkbox[1,1.75;cb_3d_clouds;3D Clouds;" .. dump(engine.setting_getbool("enable_3d_clouds")) .. "]"..
1144 "checkbox[1,2.25;cb_opaque_water;Opaque Water;" .. dump(engine.setting_getbool("opaque_water")) .. "]"..
1146 "checkbox[4,0.75;cb_mipmapping;Mip-Mapping;" .. dump(engine.setting_getbool("mip_map")) .. "]"..
1147 "checkbox[4,1.25;cb_anisotrophic;Anisotropic Filtering;".. dump(engine.setting_getbool("anisotropic_filter")) .. "]"..
1148 "checkbox[4,1.75;cb_bilinear;Bi-Linear Filtering;" .. dump(engine.setting_getbool("bilinear_filter")) .. "]"..
1149 "checkbox[4,2.25;cb_trilinear;Tri-Linear Filtering;" .. dump(engine.setting_getbool("trilinear_filter")) .. "]"..
1151 "checkbox[7.5,0.75;cb_shaders;Shaders;" .. dump(engine.setting_getbool("enable_shaders")) .. "]"..
1152 "checkbox[7.5,1.25;cb_pre_ivis;Preload item visuals;".. dump(engine.setting_getbool("preload_item_visuals")) .. "]"..
1153 "checkbox[7.5,1.75;cb_particles;Enable Particles;" .. dump(engine.setting_getbool("enable_particles")) .. "]"..
1154 "checkbox[7.5,2.25;cb_finite_liquid;Finite Liquid;" .. dump(engine.setting_getbool("liquid_finite")) .. "]"..
1156 "button[1,3.75;2.25,0.5;btn_change_keys;Change keys]"
1159 --------------------------------------------------------------------------------
1160 function tabbuilder.tab_singleplayer()
1162 local index = worldlist.get_current_index(
1163 tonumber(engine.setting_get("mainmenu_last_selected_world"))
1166 return "button[4,4.15;2.6,0.5;world_delete;Delete]" ..
1167 "button[6.5,4.15;2.8,0.5;world_create;New]" ..
1168 "button[9.2,4.15;2.55,0.5;world_configure;Configure]" ..
1169 "button[8.5,4.95;3.25,0.5;play;Play]" ..
1170 "label[4,-0.25;Select World:]"..
1171 "vertlabel[0,-0.25;SINGLE PLAYER]" ..
1172 "checkbox[0.5,0.25;cb_creative_mode;Creative Mode;" ..
1173 dump(engine.setting_getbool("creative_mode")) .. "]"..
1174 "checkbox[0.5,0.7;cb_enable_damage;Enable Damage;" ..
1175 dump(engine.setting_getbool("enable_damage")) .. "]"..
1176 "textlist[4,0.25;7.5,3.7;sp_worlds;" ..
1177 menu.render_world_list() ..
1178 ";" .. index .. "]" ..
1182 --------------------------------------------------------------------------------
1183 function tabbuilder.tab_credits()
1184 return "vertlabel[0,-0.5;CREDITS]" ..
1185 "label[0.5,3;Minetest " .. engine.get_version() .. "]" ..
1186 "label[0.5,3.3;http://minetest.net]" ..
1187 "image[0.5,1;" .. menu.defaulttexturedir .. "logo.png]" ..
1188 "textlist[3.5,-0.25;8.5,5.8;list_credits;" ..
1189 "#FFFF00Core Developers," ..
1190 "Perttu Ahola (celeron55) <celeron55@gmail.com>,"..
1191 "Ryan Kwolek (kwolekr) <kwolekr@minetest.net>,"..
1192 "PilzAdam <pilzadam@minetest.net>," ..
1193 "IIya Zhuravlev (thexyz) <xyz@minetest.net>,"..
1194 "Lisa Milne (darkrose) <lisa@ltmnet.com>,"..
1195 "Maciej Kasatkin (RealBadAngel) <mk@realbadangel.pl>,"..
1196 "proller <proler@gmail.com>,"..
1197 "sfan5 <sfan5@live.de>,"..
1198 "kahrl <kahrl@gmx.net>,"..
1200 "#FFFF00Active Contributors," ..
1202 "Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>,"..
1203 "Jurgen Doser (doserj) <jurgen.doser@gmail.com>,"..
1204 "Jeija <jeija@mesecons.net>,"..
1205 "MirceaKitsune <mirceakitsune@gmail.com>,"..
1207 "dannydark <the_skeleton_of_a_child@yahoo.co.uk>,"..
1208 "0gb.us <0gb.us@0gb.us>,"..
1210 "#FFFF00Previous Contributors," ..
1211 "Guiseppe Bilotta (Oblomov) <guiseppe.bilotta@gmail.com>,"..
1212 "Jonathan Neuschafer <j.neuschaefer@gmx.net>,"..
1213 "Nils Dagsson Moskopp (erlehmann) <nils@dieweltistgarnichtso.net>,"..
1214 "Constantin Wenger (SpeedProg) <constantin.wenger@googlemail.com>,"..
1215 "matttpt <matttpt@gmail.com>,"..
1216 "JacobF <queatz@gmail.com>,"..
1220 --------------------------------------------------------------------------------
1221 function tabbuilder.checkretval(retval)
1223 if retval ~= nil then
1224 if retval.current_tab ~= nil then
1225 tabbuilder.current_tab = retval.current_tab
1228 if retval.is_dialog ~= nil then
1229 tabbuilder.is_dialog = retval.is_dialog
1232 if retval.show_buttons ~= nil then
1233 tabbuilder.show_buttons = retval.show_buttons
1236 if retval.skipformupdate ~= nil then
1237 tabbuilder.skipformupdate = retval.skipformupdate
1242 --------------------------------------------------------------------------------
1243 --------------------------------------------------------------------------------
1244 -- initialize callbacks
1245 --------------------------------------------------------------------------------
1246 --------------------------------------------------------------------------------
1247 engine.button_handler = function(fields)
1248 --print("Buttonhandler: tab: " .. tabbuilder.current_tab .. " fields: " .. dump(fields))
1250 if fields["btn_error_confirm"] then
1251 gamedata.errormessage = nil
1254 local retval = modmgr.handle_buttons(tabbuilder.current_tab,fields)
1255 tabbuilder.checkretval(retval)
1257 retval = gamemgr.handle_buttons(tabbuilder.current_tab,fields)
1258 tabbuilder.checkretval(retval)
1260 retval = modstore.handle_buttons(tabbuilder.current_tab,fields)
1261 tabbuilder.checkretval(retval)
1263 if tabbuilder.current_tab == "dialog_create_world" then
1264 tabbuilder.handle_create_world_buttons(fields)
1267 if tabbuilder.current_tab == "dialog_delete_world" then
1268 tabbuilder.handle_delete_world_buttons(fields)
1271 if tabbuilder.current_tab == "singleplayer" then
1272 tabbuilder.handle_singleplayer_buttons(fields)
1275 if tabbuilder.current_tab == "multiplayer" then
1276 tabbuilder.handle_multiplayer_buttons(fields)
1279 if tabbuilder.current_tab == "settings" then
1280 tabbuilder.handle_settings_buttons(fields)
1283 if tabbuilder.current_tab == "server" then
1284 tabbuilder.handle_server_buttons(fields)
1288 tabbuilder.handle_tab_buttons(fields)
1291 menubar.handle_buttons(fields)
1293 if not tabbuilder.skipformupdate then
1297 tabbuilder.skipformupdate = false
1301 --------------------------------------------------------------------------------
1302 engine.event_handler = function(event)
1303 if event == "MenuQuit" then
1304 if tabbuilder.is_dialog then
1305 tabbuilder.is_dialog = false
1306 tabbuilder.show_buttons = true
1307 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1315 --------------------------------------------------------------------------------
1316 --------------------------------------------------------------------------------
1318 --------------------------------------------------------------------------------
1319 --------------------------------------------------------------------------------