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)
18 if spec.name ~= nil then
19 text = text .. fs_escape_string(spec.name:trim())
21 if spec.description ~= nil then
22 --TODO make sure there's no invalid chat in spec.description
23 text = text .. " (" .. fs_escape_string(spec.description) .. ")"
26 if spec.address ~= nil then
27 text = text .. spec.address:trim()
32 if spec.password == true then
39 details = details .. "C"
41 details = details .. " "
45 details = details .. "D"
47 details = details .. " "
51 details = details .. "P"
53 details = details .. " "
59 --------------------------------------------------------------------------------
60 os.tempfolder = function()
61 local filetocheck = os.tmpname()
62 os.remove(filetocheck)
64 local randname = "MTTempModFolder_" .. math.random(0,10000)
65 if DIR_DELIM == "\\" then
66 local tempfolder = os.getenv("TEMP")
67 return tempfolder .. filetocheck
69 local backstring = filetocheck:reverse()
70 return filetocheck:sub(0,filetocheck:len()-backstring:find(DIR_DELIM)+1) ..randname
75 --------------------------------------------------------------------------------
76 function cleanup_path(temppath)
78 local parts = temppath:split("-")
81 if temppath ~= "" then
82 temppath = temppath .. "_"
84 temppath = temppath .. parts[i]
87 parts = temppath:split(".")
90 if temppath ~= "" then
91 temppath = temppath .. "_"
93 temppath = temppath .. parts[i]
96 parts = temppath:split("'")
99 if temppath ~= "" then
100 temppath = temppath .. ""
102 temppath = temppath .. parts[i]
105 parts = temppath:split(" ")
108 if temppath ~= "" then
111 temppath = temppath .. parts[i]
117 --------------------------------------------------------------------------------
119 function menu.set_texture(identifier,gamedetails)
120 local texture_set = false
121 if menu.texturepack ~= nil and gamedetails ~= nil then
122 local path = menu.basetexturedir ..
123 gamedetails.id .. "_menu_" .. identifier .. ".png"
125 if engine.set_background(identifier,path) then
130 if not texture_set and gamedetails ~= nil then
131 local path = gamedetails.path .. DIR_DELIM .."menu" ..
132 DIR_DELIM .. identifier .. ".png"
133 if engine.set_background(identifier,path) then
138 if not texture_set then
139 local path = menu.basetexturedir .. DIR_DELIM .."menu_" ..
141 if engine.set_background(identifier,path) then
146 if not texture_set then
147 local path = menu.defaulttexturedir .. DIR_DELIM .."menu_" ..
149 engine.set_background(identifier,path)
153 --------------------------------------------------------------------------------
154 function menu.update_gametype()
158 if (menu.game_last_check == nil or
159 menu.game_last_check ~= menu.last_game) and
160 tabbuilder.current_tab == "singleplayer" then
162 local gamedetails = menu.lastgame()
163 engine.set_topleft_text(gamedetails.name)
164 worldlist.set_gamefilter(gamedetails.id)
167 local background_set = false
168 if menu.texturepack ~= nil then
169 local path_background_texture = menu.basetexturedir ..
170 gamedetails.id .. "_menu_background.png"
172 if engine.set_background("background",path_background_texture) then
173 background_set = true
174 engine.set_clouds(false)
178 if not background_set then
179 local path_background_texture = gamedetails.path .. DIR_DELIM .."menu" ..
180 DIR_DELIM .. "background.png"
181 if engine.set_background("background",path_background_texture) then
182 background_set = true
183 engine.set_clouds(false)
187 if not background_set then
188 engine.set_clouds(true)
191 menu.set_texture("overlay",gamedetails)
192 menu.set_texture("header",gamedetails)
193 menu.set_texture("footer",gamedetails)
195 menu.game_last_check = menu.last_game
197 if menu.game_last_check ~= menu.last_game then
198 menu.game_last_check = menu.last_game
199 menu.reset_gametype()
204 --------------------------------------------------------------------------------
205 function menu.reset_gametype()
206 worldlist.set_gamefilter(nil)
207 menu.game_last_check = nil
209 local path_background_texture = menu.basetexturedir .. "menu_background.png"
211 if engine.set_background("background",path_background_texture) then
212 background_set = true
213 engine.set_clouds(false)
215 engine.set_clouds(true)
218 menu.set_texture("overlay",nil)
219 menu.set_texture("header",nil)
220 menu.set_texture("footer",nil)
221 engine.set_topleft_text("")
224 --------------------------------------------------------------------------------
225 function get_last_folder(text,count)
226 local parts = text:split(DIR_DELIM)
234 retval = retval .. parts[#parts - (count-i)] .. DIR_DELIM
240 --------------------------------------------------------------------------------
241 function init_globals()
243 gamedata.worldindex = 0
246 --------------------------------------------------------------------------------
247 function identify_filetype(name)
249 if name:sub(-3):lower() == "zip" then
256 if name:sub(-6):lower() == "tar.gz" or
257 name:sub(-3):lower() == "tgz"then
264 if name:sub(-6):lower() == "tar.bz2" then
271 if name:sub(-2):lower() == "7z" then
284 --------------------------------------------------------------------------------
285 function update_menu()
287 local formspec = "size[12,5.2]"
290 if gamedata.errormessage ~= nil then
291 formspec = formspec ..
292 "field[1,2;10,2;;ERROR: " ..
293 gamedata.errormessage ..
295 "button[4.5,4.2;3,0.5;btn_error_confirm;Ok]"
297 formspec = formspec .. tabbuilder.gettab()
300 engine.update_formspec(formspec)
303 --------------------------------------------------------------------------------
304 function menu.render_world_list()
307 local current_worldlist = worldlist.get_list()
309 for i,v in ipairs(current_worldlist) do
311 retval = retval ..","
314 retval = retval .. v.name ..
315 " \\[" .. v.gameid .. "\\]"
321 --------------------------------------------------------------------------------
324 gamemgr.update_gamelist()
326 menu.last_game = tonumber(engine.setting_get("main_menu_last_game_idx"))
328 if type(menu.last_game) ~= "number" then
332 if engine.setting_getbool("public_serverlist") then
333 menu.favorites = engine.get_favorites("online")
335 menu.favorites = engine.get_favorites("local")
339 menu.defaulttexturedir = engine.get_gamepath() .. DIR_DELIM .. ".." ..
340 DIR_DELIM .. "textures" .. DIR_DELIM .. "base" ..
341 DIR_DELIM .. "pack" .. DIR_DELIM
342 menu.basetexturedir = menu.defaulttexturedir
344 menu.texturepack = engine.setting_get("texture_path")
346 if menu.texturepack ~= nil then
347 menu.basetexturedir = menu.texturepack .. DIR_DELIM
351 --------------------------------------------------------------------------------
352 function menu.lastgame()
353 if menu.last_game > 0 and menu.last_game <= #gamemgr.games then
354 return gamemgr.games[menu.last_game]
357 if #gamemgr.games >= 1 then
359 return gamemgr.games[menu.last_game]
366 --------------------------------------------------------------------------------
367 function menu.update_last_game()
369 local current_world = worldlist.get_raw_world(
370 engine.setting_get("mainmenu_last_selected_world")
373 if current_world == nil then
377 for i=1,#gamemgr.games,1 do
378 if gamemgr.games[i].id == current_world.gameid then
380 engine.setting_set("main_menu_last_game_idx",menu.last_game)
386 --------------------------------------------------------------------------------
387 function menu.handle_key_up_down(fields,textlist,settingname)
389 if fields["key_up"] then
390 local oldidx = engine.get_textlist_index(textlist)
393 local newidx = oldidx -1
394 engine.setting_set(settingname,
395 worldlist.get_engine_index(newidx))
399 if fields["key_down"] then
400 local oldidx = engine.get_textlist_index(textlist)
402 if oldidx < worldlist.size() then
403 local newidx = oldidx + 1
404 engine.setting_set(settingname,
405 worldlist.get_engine_index(newidx))
411 --------------------------------------------------------------------------------
412 function menubar.handle_buttons(fields)
413 for i=1,#menubar.buttons,1 do
414 if fields[menubar.buttons[i].btn_name] ~= nil then
415 menu.last_game = menubar.buttons[i].index
416 engine.setting_set("main_menu_last_game_idx",menu.last_game)
417 menu.update_gametype()
422 --------------------------------------------------------------------------------
423 function menubar.refresh()
424 menubar.formspec = "box[-0.3,5.625;12.4,1.3;000000]" ..
425 "box[-0.3,5.6;12.4,0.05;FFFFFF]"
428 local button_base = -0.25
430 local maxbuttons = #gamemgr.games
432 if maxbuttons > 10 then
436 for i=1,maxbuttons,1 do
438 local btn_name = "menubar_btn_" .. gamemgr.games[i].id
439 local buttonpos = button_base + (i-1) * 1.245
440 if gamemgr.games[i].menuicon_path ~= nil and
441 gamemgr.games[i].menuicon_path ~= "" then
443 menubar.formspec = menubar.formspec ..
444 "image_button[" .. buttonpos .. ",5.7;1.3,1.3;" ..
445 gamemgr.games[i].menuicon_path .. ";" .. btn_name .. ";;true;false]"
448 local part1 = gamemgr.games[i].id:sub(1,5)
449 local part2 = gamemgr.games[i].id:sub(6,10)
450 local part3 = gamemgr.games[i].id:sub(11)
452 local text = part1 .. "\n" .. part2
455 text = text .. "\n" .. part3
457 menubar.formspec = menubar.formspec ..
458 "image_button[" .. buttonpos .. ",5.7;1.3,1.3;;" ..btn_name ..
459 ";" .. text .. ";true;true]"
467 table.insert(menubar.buttons,toadd)
471 --------------------------------------------------------------------------------
472 function tabbuilder.dialog_create_world()
473 local mapgens = {"v6", "v7", "indev", "singlenode", "math"}
475 local current_mg = engine.setting_get("mg_name")
480 for k,v in pairs(mapgens) do
481 if current_mg == v then
485 mglist = mglist .. v .. ","
487 mglist = mglist:sub(1, -2)
490 "label[2,0;World name]"..
491 "label[2,1;Mapgen]"..
492 "field[4.5,0.4;6,0.5;te_world_name;;]" ..
494 "button[5,4.5;2.6,0.5;world_create_confirm;Create]" ..
495 "button[7.5,4.5;2.8,0.5;world_create_cancel;Cancel]" ..
496 "dropdown[4.2,1;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
497 "textlist[4.2,1.9;5.8,2.3;games;" ..
498 gamemgr.gamelist() ..
499 ";" .. menu.last_game .. ";true]"
504 --------------------------------------------------------------------------------
505 function tabbuilder.dialog_delete_world()
506 return "label[2,2;Delete World \"" .. worldlist.get_raw_list()[menu.world_to_del].name .. "\"?]"..
507 "button[3.5,4.2;2.6,0.5;world_delete_confirm;Yes]" ..
508 "button[6,4.2;2.8,0.5;world_delete_cancel;No]"
511 --------------------------------------------------------------------------------
512 function tabbuilder.gettab()
515 if tabbuilder.show_buttons then
516 retval = retval .. tabbuilder.tab_header()
519 if tabbuilder.current_tab == "singleplayer" then
520 retval = retval .. tabbuilder.tab_singleplayer()
523 if tabbuilder.current_tab == "multiplayer" then
524 retval = retval .. tabbuilder.tab_multiplayer()
527 if tabbuilder.current_tab == "server" then
528 retval = retval .. tabbuilder.tab_server()
531 if tabbuilder.current_tab == "settings" then
532 retval = retval .. tabbuilder.tab_settings()
535 if tabbuilder.current_tab == "credits" then
536 retval = retval .. tabbuilder.tab_credits()
539 if tabbuilder.current_tab == "dialog_create_world" then
540 retval = retval .. tabbuilder.dialog_create_world()
543 if tabbuilder.current_tab == "dialog_delete_world" then
544 retval = retval .. tabbuilder.dialog_delete_world()
547 retval = retval .. modmgr.gettab(tabbuilder.current_tab)
548 retval = retval .. gamemgr.gettab(tabbuilder.current_tab)
549 retval = retval .. modstore.gettab(tabbuilder.current_tab)
554 --------------------------------------------------------------------------------
555 function tabbuilder.handle_create_world_buttons(fields)
557 if fields["world_create_confirm"] or
558 fields["key_enter"] then
560 local worldname = fields["te_world_name"]
561 local gameindex = engine.get_textlist_index("games")
568 if not worldlist.exists(worldname) then
569 engine.setting_set("mg_name",fields["dd_mapgen"])
570 message = engine.create_world(worldname,gameindex)
572 message = "A world named \"" .. worldname .. "\" already exists"
575 if message ~= nil then
576 gamedata.errormessage = message
578 menu.last_game = gameindex
579 engine.setting_set("main_menu_last_game_idx",gameindex)
582 engine.setting_set("mainmenu_last_selected_world",
583 worldlist.engine_index_by_name(worldname))
586 gamedata.errormessage = "No worldname given or no game selected"
590 if fields["games"] then
591 tabbuilder.skipformupdate = true
596 tabbuilder.is_dialog = false
597 tabbuilder.show_buttons = true
598 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
601 --------------------------------------------------------------------------------
602 function tabbuilder.handle_delete_world_buttons(fields)
604 if fields["world_delete_confirm"] then
605 if menu.world_to_del > 0 and
606 menu.world_to_del <= #worldlist.get_raw_list() then
607 engine.delete_world(menu.world_to_del)
608 menu.world_to_del = 0
613 tabbuilder.is_dialog = false
614 tabbuilder.show_buttons = true
615 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
618 --------------------------------------------------------------------------------
619 function tabbuilder.handle_multiplayer_buttons(fields)
621 if fields["te_name"] ~= nil then
622 gamedata.playername = fields["te_name"]
623 engine.setting_set("name", fields["te_name"])
626 if fields["favourites"] ~= nil then
627 local event = explode_textlist_event(fields["favourites"])
628 if event.typ == "DCL" then
629 --gamedata.address = menu.favorites[event.index].name
630 if gamedata.address == nil then
631 gamedata.address = menu.favorites[event.index].address
633 gamedata.port = menu.favorites[event.index].port
634 gamedata.playername = fields["te_name"]
635 if fields["te_pwd"] ~= nil then
636 gamedata.password = fields["te_pwd"]
638 gamedata.selected_world = 0
640 if menu.favorites ~= nil then
641 gamedata.servername = menu.favorites[event.index].name
642 gamedata.serverdescription = menu.favorites[event.index].description
645 if menu.favorites ~= nil then
646 gamedata.servername = menu.favorites[event.index].name
647 gamedata.serverdescription = menu.favorites[event.index].description
650 if gamedata.address ~= nil and
651 gamedata.port ~= nil then
657 if event.typ == "CHG" then
658 local address = menu.favorites[event.index].address
659 local port = menu.favorites[event.index].port
661 if address ~= nil and
663 engine.setting_set("address",address)
664 engine.setting_set("port",port)
667 menu.fav_selected = event.index
672 if fields["key_up"] ~= nil or
673 fields["key_down"] ~= nil then
675 local fav_idx = engine.get_textlist_index("favourites")
677 if fields["key_up"] ~= nil and fav_idx > 1 then
679 else if fields["key_down"] and fav_idx < #menu.favorites then
683 local address = menu.favorites[fav_idx].name
684 if address == nil then
685 address = menu.favorites[fav_idx].address
687 local port = menu.favorites[fav_idx].port
689 if address ~= nil and
691 engine.setting_set("address",address)
692 engine.setting_set("port",port)
695 menu.fav_selected = fav_idx
699 if fields["cb_public_serverlist"] ~= nil then
700 engine.setting_setbool("public_serverlist",
701 tabbuilder.tobool(fields["cb_public_serverlist"]))
703 if engine.setting_getbool("public_serverlist") then
704 menu.favorites = engine.get_favorites("online")
706 menu.favorites = engine.get_favorites("local")
708 menu.fav_selected = nil
712 if fields["btn_delete_favorite"] ~= nil then
713 local current_favourite = engine.get_textlist_index("favourites")
714 engine.delete_favorite(current_favourite)
715 menu.favorites = engine.get_favorites()
716 menu.fav_selected = nil
718 engine.setting_set("address","")
719 engine.setting_get("port","")
724 if fields["btn_mp_connect"] ~= nil or
725 fields["key_enter"] then
727 gamedata.playername = fields["te_name"]
728 gamedata.password = fields["te_pwd"]
729 gamedata.address = fields["te_address"]
730 gamedata.port = fields["te_port"]
732 local fav_idx = engine.get_textlist_index("favourites")
734 if fav_idx > 0 and fav_idx <= #menu.favorites and
735 menu.favorites[fav_idx].address == fields["te_address"] and
736 menu.favorites[fav_idx].port == fields["te_port"] then
738 gamedata.servername = menu.favorites[fav_idx].name
739 gamedata.serverdescription = menu.favorites[fav_idx].description
741 gamedata.servername = ""
742 gamedata.serverdescription = ""
745 gamedata.selected_world = 0
752 --------------------------------------------------------------------------------
753 function tabbuilder.handle_server_buttons(fields)
755 local world_doubleclick = false
757 if fields["srv_worlds"] ~= nil then
758 local event = explode_textlist_event(fields["srv_worlds"])
760 if event.typ == "DCL" then
761 world_doubleclick = true
763 if event.typ == "CHG" then
764 engine.setting_set("mainmenu_last_selected_world",
765 worldlist.get_engine_index(engine.get_textlist_index("srv_worlds")))
769 menu.handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world")
771 if fields["cb_creative_mode"] then
772 engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"]))
775 if fields["cb_enable_damage"] then
776 engine.setting_setbool("enable_damage",tabbuilder.tobool(fields["cb_enable_damage"]))
779 if fields["cb_server_announce"] then
780 engine.setting_setbool("server_announce",tabbuilder.tobool(fields["cb_server_announce"]))
783 if fields["start_server"] ~= nil or
785 fields["key_enter"] then
786 local selected = engine.get_textlist_index("srv_worlds")
788 gamedata.playername = fields["te_playername"]
789 gamedata.password = fields["te_passwd"]
790 gamedata.port = fields["te_serverport"]
791 gamedata.address = ""
792 gamedata.selected_world = worldlist.get_engine_index(selected)
794 menu.update_last_game(gamedata.selected_world)
799 if fields["world_create"] ~= nil then
800 tabbuilder.current_tab = "dialog_create_world"
801 tabbuilder.is_dialog = true
802 tabbuilder.show_buttons = false
805 if fields["world_delete"] ~= nil then
806 local selected = engine.get_textlist_index("srv_worlds")
808 selected <= worldlist.size() then
809 local world = worldlist.get_list()[selected]
811 world.name ~= nil and
812 world.name ~= "" then
813 menu.world_to_del = worldlist.get_engine_index(selected)
814 tabbuilder.current_tab = "dialog_delete_world"
815 tabbuilder.is_dialog = true
816 tabbuilder.show_buttons = false
818 menu.world_to_del = 0
823 if fields["world_configure"] ~= nil then
824 selected = engine.get_textlist_index("srv_worlds")
826 modmgr.world_config_selected_world = worldlist.get_engine_index(selected)
827 if modmgr.init_worldconfig() then
828 tabbuilder.current_tab = "dialog_configure_world"
829 tabbuilder.is_dialog = true
830 tabbuilder.show_buttons = false
836 --------------------------------------------------------------------------------
837 function tabbuilder.tobool(text)
838 if text == "true" then
845 --------------------------------------------------------------------------------
846 function tabbuilder.handle_settings_buttons(fields)
847 if fields["cb_fancy_trees"] then
848 engine.setting_setbool("new_style_leaves",tabbuilder.tobool(fields["cb_fancy_trees"]))
851 if fields["cb_smooth_lighting"] then
852 engine.setting_setbool("smooth_lighting",tabbuilder.tobool(fields["cb_smooth_lighting"]))
854 if fields["cb_3d_clouds"] then
855 engine.setting_setbool("enable_3d_clouds",tabbuilder.tobool(fields["cb_3d_clouds"]))
857 if fields["cb_opaque_water"] then
858 engine.setting_setbool("opaque_water",tabbuilder.tobool(fields["cb_opaque_water"]))
861 if fields["cb_mipmapping"] then
862 engine.setting_setbool("mip_map",tabbuilder.tobool(fields["cb_mipmapping"]))
864 if fields["cb_anisotrophic"] then
865 engine.setting_setbool("anisotropic_filter",tabbuilder.tobool(fields["cb_anisotrophic"]))
867 if fields["cb_bilinear"] then
868 engine.setting_setbool("bilinear_filter",tabbuilder.tobool(fields["cb_bilinear"]))
870 if fields["cb_trilinear"] then
871 engine.setting_setbool("trilinear_filter",tabbuilder.tobool(fields["cb_trilinear"]))
874 if fields["cb_shaders"] then
875 engine.setting_setbool("enable_shaders",tabbuilder.tobool(fields["cb_shaders"]))
877 if fields["cb_pre_ivis"] then
878 engine.setting_setbool("preload_item_visuals",tabbuilder.tobool(fields["cb_pre_ivis"]))
880 if fields["cb_particles"] then
881 engine.setting_setbool("enable_particles",tabbuilder.tobool(fields["cb_particles"]))
883 if fields["cb_finite_liquid"] then
884 engine.setting_setbool("liquid_finite",tabbuilder.tobool(fields["cb_finite_liquid"]))
887 if fields["btn_change_keys"] ~= nil then
888 engine.show_keys_menu()
892 --------------------------------------------------------------------------------
893 function tabbuilder.handle_singleplayer_buttons(fields)
895 local world_doubleclick = false
897 if fields["sp_worlds"] ~= nil then
898 local event = explode_textlist_event(fields["sp_worlds"])
900 if event.typ == "DCL" then
901 world_doubleclick = true
904 if event.typ == "CHG" then
905 engine.setting_set("mainmenu_last_selected_world",
906 worldlist.get_engine_index(engine.get_textlist_index("sp_worlds")))
910 menu.handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world")
912 if fields["cb_creative_mode"] then
913 engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"]))
916 if fields["cb_enable_damage"] then
917 engine.setting_setbool("enable_damage",tabbuilder.tobool(fields["cb_enable_damage"]))
920 if fields["play"] ~= nil or
922 fields["key_enter"] then
923 local selected = engine.get_textlist_index("sp_worlds")
925 gamedata.selected_world = worldlist.get_engine_index(selected)
926 gamedata.singleplayer = true
928 menu.update_last_game(gamedata.selected_world)
934 if fields["world_create"] ~= nil then
935 tabbuilder.current_tab = "dialog_create_world"
936 tabbuilder.is_dialog = true
937 tabbuilder.show_buttons = false
940 if fields["world_delete"] ~= nil then
941 local selected = engine.get_textlist_index("sp_worlds")
943 selected <= worldlist.size() then
944 local world = worldlist.get_list()[selected]
946 world.name ~= nil and
947 world.name ~= "" then
948 menu.world_to_del = worldlist.get_engine_index(selected)
949 tabbuilder.current_tab = "dialog_delete_world"
950 tabbuilder.is_dialog = true
951 tabbuilder.show_buttons = false
953 menu.world_to_del = 0
958 if fields["world_configure"] ~= nil then
959 selected = engine.get_textlist_index("sp_worlds")
961 modmgr.world_config_selected_world = worldlist.get_engine_index(selected)
962 if modmgr.init_worldconfig() then
963 tabbuilder.current_tab = "dialog_configure_world"
964 tabbuilder.is_dialog = true
965 tabbuilder.show_buttons = false
971 --------------------------------------------------------------------------------
972 function tabbuilder.tab_header()
974 if tabbuilder.last_tab_index == nil then
975 tabbuilder.last_tab_index = 1
980 for i=1,#tabbuilder.current_buttons,1 do
986 toadd = toadd .. tabbuilder.current_buttons[i].caption
988 return "tabheader[-0.3,-0.99;main_tab;" .. toadd ..";" .. tabbuilder.last_tab_index .. ";true;false]"
991 --------------------------------------------------------------------------------
992 function tabbuilder.handle_tab_buttons(fields)
994 if fields["main_tab"] then
995 local index = tonumber(fields["main_tab"])
996 tabbuilder.last_tab_index = index
997 tabbuilder.current_tab = tabbuilder.current_buttons[index].name
999 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
1002 --handle tab changes
1003 if tabbuilder.current_tab ~= tabbuilder.old_tab then
1004 if tabbuilder.current_tab ~= "singleplayer" then
1005 menu.reset_gametype()
1009 if tabbuilder.current_tab == "singleplayer" then
1010 menu.update_gametype()
1013 tabbuilder.old_tab = tabbuilder.current_tab
1016 --------------------------------------------------------------------------------
1017 function tabbuilder.init()
1018 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1020 if tabbuilder.current_tab == nil or
1021 tabbuilder.current_tab == "" then
1022 tabbuilder.current_tab = "singleplayer"
1023 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
1027 --initialize tab buttons
1028 tabbuilder.last_tab = nil
1029 tabbuilder.show_buttons = true
1031 tabbuilder.current_buttons = {}
1032 table.insert(tabbuilder.current_buttons,{name="singleplayer", caption="Singleplayer"})
1033 table.insert(tabbuilder.current_buttons,{name="multiplayer", caption="Client"})
1034 table.insert(tabbuilder.current_buttons,{name="server", caption="Server"})
1035 table.insert(tabbuilder.current_buttons,{name="settings", caption="Settings"})
1037 if engine.setting_getbool("main_menu_game_mgr") then
1038 table.insert(tabbuilder.current_buttons,{name="game_mgr", caption="Games"})
1041 if engine.setting_getbool("main_menu_mod_mgr") then
1042 table.insert(tabbuilder.current_buttons,{name="mod_mgr", caption="Mods"})
1044 table.insert(tabbuilder.current_buttons,{name="credits", caption="Credits"})
1047 for i=1,#tabbuilder.current_buttons,1 do
1048 if tabbuilder.current_buttons[i].name == tabbuilder.current_tab then
1049 tabbuilder.last_tab_index = i
1053 menu.update_gametype()
1056 --------------------------------------------------------------------------------
1057 function tabbuilder.tab_multiplayer()
1060 "vertlabel[0,-0.25;CLIENT]" ..
1061 "label[1,-0.25;Favorites:]"..
1062 "label[1,4.25;Address/Port]"..
1063 "label[9,0;Name/Password]" ..
1064 "field[1.25,5.25;5.5,0.5;te_address;;" ..engine.setting_get("address") .."]" ..
1065 "field[6.75,5.25;2.25,0.5;te_port;;" ..engine.setting_get("port") .."]" ..
1066 "checkbox[1,3.6;cb_public_serverlist;Public Serverlist;" ..
1067 dump(engine.setting_getbool("public_serverlist")) .. "]"
1069 if not engine.setting_getbool("public_serverlist") then
1071 "button[6.45,3.95;2.25,0.5;btn_delete_favorite;Delete]"
1075 "button[9,4.95;2.5,0.5;btn_mp_connect;Connect]" ..
1076 "field[9.25,1;2.5,0.5;te_name;;" ..engine.setting_get("name") .."]" ..
1077 "pwdfield[9.25,1.75;2.5,0.5;te_pwd;]" ..
1078 "textlist[1,0.35;7.5,3.35;favourites;"
1080 if #menu.favorites > 0 then
1081 retval = retval .. render_favourite(menu.favorites[1])
1083 for i=2,#menu.favorites,1 do
1084 retval = retval .. "," .. render_favourite(menu.favorites[i])
1088 if menu.fav_selected ~= nil then
1089 retval = retval .. ";" .. menu.fav_selected .. "]"
1091 retval = retval .. ";0]"
1097 --------------------------------------------------------------------------------
1098 function tabbuilder.tab_server()
1100 local index = worldlist.get_current_index(
1101 tonumber(engine.setting_get("mainmenu_last_selected_world"))
1105 "button[4,4.15;2.6,0.5;world_delete;Delete]" ..
1106 "button[6.5,4.15;2.8,0.5;world_create;New]" ..
1107 "button[9.2,4.15;2.55,0.5;world_configure;Configure]" ..
1108 "button[8.5,4.9;3.25,0.5;start_server;Start Game]" ..
1109 "label[4,-0.25;Select World:]"..
1110 "vertlabel[0,-0.25;START SERVER]" ..
1111 "checkbox[0.5,0.25;cb_creative_mode;Creative Mode;" ..
1112 dump(engine.setting_getbool("creative_mode")) .. "]"..
1113 "checkbox[0.5,0.7;cb_enable_damage;Enable Damage;" ..
1114 dump(engine.setting_getbool("enable_damage")) .. "]"..
1115 "checkbox[0.5,1.15;cb_server_announce;Public;" ..
1116 dump(engine.setting_getbool("server_announce")) .. "]"..
1117 "field[0.8,3.2;3,0.5;te_playername;Name;" ..
1118 engine.setting_get("name") .. "]" ..
1119 "pwdfield[0.8,4.2;3,0.5;te_passwd;Password]" ..
1120 "field[0.8,5.2;3,0.5;te_serverport;Server Port;30000]" ..
1121 "textlist[4,0.25;7.5,3.7;srv_worlds;" ..
1122 menu.render_world_list() ..
1128 --------------------------------------------------------------------------------
1129 function tabbuilder.tab_settings()
1130 return "vertlabel[0,0;SETTINGS]" ..
1131 "checkbox[1,0.75;cb_fancy_trees;Fancy trees;" .. dump(engine.setting_getbool("new_style_leaves")) .. "]"..
1132 "checkbox[1,1.25;cb_smooth_lighting;Smooth Lighting;".. dump(engine.setting_getbool("smooth_lighting")) .. "]"..
1133 "checkbox[1,1.75;cb_3d_clouds;3D Clouds;" .. dump(engine.setting_getbool("enable_3d_clouds")) .. "]"..
1134 "checkbox[1,2.25;cb_opaque_water;Opaque Water;" .. dump(engine.setting_getbool("opaque_water")) .. "]"..
1136 "checkbox[4,0.75;cb_mipmapping;Mip-Mapping;" .. dump(engine.setting_getbool("mip_map")) .. "]"..
1137 "checkbox[4,1.25;cb_anisotrophic;Anisotropic Filtering;".. dump(engine.setting_getbool("anisotropic_filter")) .. "]"..
1138 "checkbox[4,1.75;cb_bilinear;Bi-Linear Filtering;" .. dump(engine.setting_getbool("bilinear_filter")) .. "]"..
1139 "checkbox[4,2.25;cb_trilinear;Tri-Linear Filtering;" .. dump(engine.setting_getbool("trilinear_filter")) .. "]"..
1141 "checkbox[7.5,0.75;cb_shaders;Shaders;" .. dump(engine.setting_getbool("enable_shaders")) .. "]"..
1142 "checkbox[7.5,1.25;cb_pre_ivis;Preload item visuals;".. dump(engine.setting_getbool("preload_item_visuals")) .. "]"..
1143 "checkbox[7.5,1.75;cb_particles;Enable Particles;" .. dump(engine.setting_getbool("enable_particles")) .. "]"..
1144 "checkbox[7.5,2.25;cb_finite_liquid;Finite Liquid;" .. dump(engine.setting_getbool("liquid_finite")) .. "]"..
1146 "button[1,3.75;2.25,0.5;btn_change_keys;Change keys]"
1149 --------------------------------------------------------------------------------
1150 function tabbuilder.tab_singleplayer()
1152 local index = worldlist.get_current_index(
1153 tonumber(engine.setting_get("mainmenu_last_selected_world"))
1156 return "button[4,4.15;2.6,0.5;world_delete;Delete]" ..
1157 "button[6.5,4.15;2.8,0.5;world_create;New]" ..
1158 "button[9.2,4.15;2.55,0.5;world_configure;Configure]" ..
1159 "button[8.5,4.95;3.25,0.5;play;Play]" ..
1160 "label[4,-0.25;Select World:]"..
1161 "vertlabel[0,-0.25;SINGLE PLAYER]" ..
1162 "checkbox[0.5,0.25;cb_creative_mode;Creative Mode;" ..
1163 dump(engine.setting_getbool("creative_mode")) .. "]"..
1164 "checkbox[0.5,0.7;cb_enable_damage;Enable Damage;" ..
1165 dump(engine.setting_getbool("enable_damage")) .. "]"..
1166 "textlist[4,0.25;7.5,3.7;sp_worlds;" ..
1167 menu.render_world_list() ..
1168 ";" .. index .. "]" ..
1172 --------------------------------------------------------------------------------
1173 function tabbuilder.tab_credits()
1174 return "vertlabel[0,-0.5;CREDITS]" ..
1175 "label[0.5,3;Minetest " .. engine.get_version() .. "]" ..
1176 "label[0.5,3.3;http://minetest.net]" ..
1177 "image[0.5,1;" .. menu.defaulttexturedir .. "logo.png]" ..
1178 "textlist[3.5,-0.25;8.5,5.8;list_credits;" ..
1179 "#FFFF00Core Developers," ..
1180 "Perttu Ahola (celeron55) <celeron55@gmail.com>,"..
1181 "Ryan Kwolek (kwolekr) <kwolekr@minetest.net>,"..
1182 "PilzAdam <pilzadam@minetest.net>," ..
1183 "IIya Zhuravlev (thexyz) <xyz@minetest.net>,"..
1184 "Lisa Milne (darkrose) <lisa@ltmnet.com>,"..
1185 "Maciej Kasatkin (RealBadAngel) <mk@realbadangel.pl>,"..
1186 "proller <proler@gmail.com>,"..
1187 "sfan5 <sfan5@live.de>,"..
1188 "kahrl <kahrl@gmx.net>,"..
1190 "#FFFF00Active Contributors," ..
1192 "Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>,"..
1193 "Jurgen Doser (doserj) <jurgen.doser@gmail.com>,"..
1194 "Jeija <jeija@mesecons.net>,"..
1195 "MirceaKitsune <mirceakitsune@gmail.com>,"..
1197 "dannydark <the_skeleton_of_a_child@yahoo.co.uk>,"..
1198 "0gb.us <0gb.us@0gb.us>,"..
1200 "#FFFF00Previous Contributors," ..
1201 "Guiseppe Bilotta (Oblomov) <guiseppe.bilotta@gmail.com>,"..
1202 "Jonathan Neuschafer <j.neuschaefer@gmx.net>,"..
1203 "Nils Dagsson Moskopp (erlehmann) <nils@dieweltistgarnichtso.net>,"..
1204 "Constantin Wenger (SpeedProg) <constantin.wenger@googlemail.com>,"..
1205 "matttpt <matttpt@gmail.com>,"..
1206 "JacobF <queatz@gmail.com>,"..
1210 --------------------------------------------------------------------------------
1211 function tabbuilder.checkretval(retval)
1213 if retval ~= nil then
1214 if retval.current_tab ~= nil then
1215 tabbuilder.current_tab = retval.current_tab
1218 if retval.is_dialog ~= nil then
1219 tabbuilder.is_dialog = retval.is_dialog
1222 if retval.show_buttons ~= nil then
1223 tabbuilder.show_buttons = retval.show_buttons
1226 if retval.skipformupdate ~= nil then
1227 tabbuilder.skipformupdate = retval.skipformupdate
1232 --------------------------------------------------------------------------------
1233 --------------------------------------------------------------------------------
1234 -- initialize callbacks
1235 --------------------------------------------------------------------------------
1236 --------------------------------------------------------------------------------
1237 engine.button_handler = function(fields)
1238 --print("Buttonhandler: tab: " .. tabbuilder.current_tab .. " fields: " .. dump(fields))
1240 if fields["btn_error_confirm"] then
1241 gamedata.errormessage = nil
1244 local retval = modmgr.handle_buttons(tabbuilder.current_tab,fields)
1245 tabbuilder.checkretval(retval)
1247 retval = gamemgr.handle_buttons(tabbuilder.current_tab,fields)
1248 tabbuilder.checkretval(retval)
1250 retval = modstore.handle_buttons(tabbuilder.current_tab,fields)
1251 tabbuilder.checkretval(retval)
1253 if tabbuilder.current_tab == "dialog_create_world" then
1254 tabbuilder.handle_create_world_buttons(fields)
1257 if tabbuilder.current_tab == "dialog_delete_world" then
1258 tabbuilder.handle_delete_world_buttons(fields)
1261 if tabbuilder.current_tab == "singleplayer" then
1262 tabbuilder.handle_singleplayer_buttons(fields)
1265 if tabbuilder.current_tab == "multiplayer" then
1266 tabbuilder.handle_multiplayer_buttons(fields)
1269 if tabbuilder.current_tab == "settings" then
1270 tabbuilder.handle_settings_buttons(fields)
1273 if tabbuilder.current_tab == "server" then
1274 tabbuilder.handle_server_buttons(fields)
1278 tabbuilder.handle_tab_buttons(fields)
1281 menubar.handle_buttons(fields)
1283 if not tabbuilder.skipformupdate then
1287 tabbuilder.skipformupdate = false
1291 --------------------------------------------------------------------------------
1292 engine.event_handler = function(event)
1293 if event == "MenuQuit" then
1294 if tabbuilder.is_dialog then
1295 tabbuilder.is_dialog = false
1296 tabbuilder.show_buttons = true
1297 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1305 --------------------------------------------------------------------------------
1306 --------------------------------------------------------------------------------
1308 --------------------------------------------------------------------------------
1309 --------------------------------------------------------------------------------