2 math.randomseed(os.time())
3 os.setlocale("C", "numeric")
5 local scriptpath = engine.get_scriptdir()
7 mt_color_grey = "#AAAAAA"
8 mt_color_blue = "#0000DD"
9 mt_color_green = "#00DD00"
10 mt_color_dark_green = "#003300"
12 --for all other colors ask sfan5 to complete his worK!
14 dofile(scriptpath .. DIR_DELIM .. "misc_helpers.lua")
15 dofile(scriptpath .. DIR_DELIM .. "filterlist.lua")
16 dofile(scriptpath .. DIR_DELIM .. "modmgr.lua")
17 dofile(scriptpath .. DIR_DELIM .. "modstore.lua")
18 dofile(scriptpath .. DIR_DELIM .. "gamemgr.lua")
19 dofile(scriptpath .. DIR_DELIM .. "mm_textures.lua")
20 dofile(scriptpath .. DIR_DELIM .. "mm_menubar.lua")
26 --------------------------------------------------------------------------------
27 local function filterTP(TPlist)
29 for _,i in ipairs(TPlist) do
31 table.insert(TPlist2, i)
37 --------------------------------------------------------------------------------
38 function menu.render_favorite(spec,render_details)
41 if spec.name ~= nil then
42 text = text .. engine.formspec_escape(spec.name:trim())
44 -- if spec.description ~= nil and
45 -- engine.formspec_escape(spec.description):trim() ~= "" then
46 -- text = text .. " (" .. engine.formspec_escape(spec.description) .. ")"
49 if spec.address ~= nil then
50 text = text .. spec.address:trim()
52 if spec.port ~= nil then
53 text = text .. ":" .. spec.port
58 if not render_details then
63 if spec.password == true then
64 details = details .. "*"
66 details = details .. "_"
70 details = details .. "C"
72 details = details .. "_"
76 details = details .. "D"
78 details = details .. "_"
82 details = details .. "P"
84 details = details .. "_"
86 details = details .. " "
88 local playercount = ""
90 if spec.clients ~= nil and
91 spec.clients_max ~= nil then
92 playercount = string.format("%03d",spec.clients) .. "/" ..
93 string.format("%03d",spec.clients_max) .. " "
96 return playercount .. engine.formspec_escape(details) .. text
99 --------------------------------------------------------------------------------
100 os.tempfolder = function()
101 local filetocheck = os.tmpname()
102 os.remove(filetocheck)
104 local randname = "MTTempModFolder_" .. math.random(0,10000)
105 if DIR_DELIM == "\\" then
106 local tempfolder = os.getenv("TEMP")
107 return tempfolder .. filetocheck
109 local backstring = filetocheck:reverse()
110 return filetocheck:sub(0,filetocheck:len()-backstring:find(DIR_DELIM)+1) ..randname
115 --------------------------------------------------------------------------------
116 function init_globals()
118 gamedata.worldindex = 0
120 worldlist = filterlist.create(
123 function(element,uid)
124 if element.name == uid then
128 end, --unique id compare fct
129 function(element,gameid)
130 if element.gameid == gameid then
137 filterlist.add_sort_mechanism(worldlist,"alphabetic",sort_worlds_alphabetic)
138 filterlist.set_sortmode(worldlist,"alphabetic")
142 --------------------------------------------------------------------------------
143 function update_menu()
145 local formspec = "size[12,5.2]"
148 if gamedata.errormessage ~= nil then
149 formspec = formspec ..
150 "field[1,2;10,2;;ERROR: " ..
151 gamedata.errormessage ..
153 "button[4.5,4.2;3,0.5;btn_error_confirm;Ok]"
155 formspec = formspec .. tabbuilder.gettab()
158 engine.update_formspec(formspec)
161 --------------------------------------------------------------------------------
162 function menu.render_world_list()
165 local current_worldlist = filterlist.get_list(worldlist)
167 for i,v in ipairs(current_worldlist) do
169 retval = retval ..","
172 retval = retval .. v.name ..
173 " \\[" .. v.gameid .. "\\]"
179 --------------------------------------------------------------------------------
180 function menu.render_TP_list(TPlist)
183 --local current_TP = filterlist.get_list(TPlist)
185 for i,v in ipairs(TPlist) do
187 retval = retval ..","
196 --------------------------------------------------------------------------------
199 gamemgr.update_gamelist()
201 menu.last_game = tonumber(engine.setting_get("main_menu_last_game_idx"))
203 if type(menu.last_game) ~= "number" then
207 if engine.setting_getbool("public_serverlist") then
208 menu.favorites = engine.get_favorites("online")
210 menu.favorites = engine.get_favorites("local")
213 menu.defaulttexturedir = engine.get_texturepath() .. DIR_DELIM .. "base" ..
214 DIR_DELIM .. "pack" .. DIR_DELIM
217 --------------------------------------------------------------------------------
218 function menu.lastgame()
219 if menu.last_game > 0 and menu.last_game <= #gamemgr.games then
220 return gamemgr.games[menu.last_game]
223 if #gamemgr.games >= 1 then
225 return gamemgr.games[menu.last_game]
232 --------------------------------------------------------------------------------
233 function menu.update_last_game()
235 local current_world = filterlist.get_raw_element(worldlist,
236 engine.setting_get("mainmenu_last_selected_world")
239 if current_world == nil then
243 for i=1,#gamemgr.games,1 do
244 if gamemgr.games[i].id == current_world.gameid then
246 engine.setting_set("main_menu_last_game_idx",menu.last_game)
252 --------------------------------------------------------------------------------
253 function menu.handle_key_up_down(fields,textlist,settingname)
255 if fields["key_up"] then
256 local oldidx = engine.get_textlist_index(textlist)
259 local newidx = oldidx -1
260 engine.setting_set(settingname,
261 filterlist.get_raw_index(worldlist,newidx))
265 if fields["key_down"] then
266 local oldidx = engine.get_textlist_index(textlist)
268 if oldidx < filterlist.size(worldlist) then
269 local newidx = oldidx + 1
270 engine.setting_set(settingname,
271 filterlist.get_raw_index(worldlist,newidx))
276 --------------------------------------------------------------------------------
277 function tabbuilder.dialog_create_world()
278 local mapgens = {"v6", "v7", "indev", "singlenode", "math"}
280 local current_mg = engine.setting_get("mg_name")
285 for k,v in pairs(mapgens) do
286 if current_mg == v then
290 mglist = mglist .. v .. ","
292 mglist = mglist:sub(1, -2)
295 "label[2,0;World name]"..
296 "label[2,1;Mapgen]"..
297 "field[4.5,0.4;6,0.5;te_world_name;;]" ..
299 "button[5,4.5;2.6,0.5;world_create_confirm;Create]" ..
300 "button[7.5,4.5;2.8,0.5;world_create_cancel;Cancel]" ..
301 "dropdown[4.2,1;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
302 "textlist[4.2,1.9;5.8,2.3;games;" ..
303 gamemgr.gamelist() ..
304 ";" .. menu.last_game .. ";true]"
309 --------------------------------------------------------------------------------
310 function tabbuilder.dialog_delete_world()
311 return "label[2,2;Delete World \"" .. filterlist.get_raw_list(worldlist)[menu.world_to_del].name .. "\"?]"..
312 "button[3.5,4.2;2.6,0.5;world_delete_confirm;Yes]" ..
313 "button[6,4.2;2.8,0.5;world_delete_cancel;No]"
316 --------------------------------------------------------------------------------
317 function tabbuilder.gettab()
320 if tabbuilder.show_buttons then
321 retval = retval .. tabbuilder.tab_header()
324 if tabbuilder.current_tab == "singleplayer" then
325 retval = retval .. tabbuilder.tab_singleplayer()
328 if tabbuilder.current_tab == "multiplayer" then
329 retval = retval .. tabbuilder.tab_multiplayer()
332 if tabbuilder.current_tab == "server" then
333 retval = retval .. tabbuilder.tab_server()
336 if tabbuilder.current_tab == "settings" then
337 retval = retval .. tabbuilder.tab_settings()
340 if tabbuilder.current_tab == "texture_packs" then
341 retval = retval .. tabbuilder.tab_TP()
344 if tabbuilder.current_tab == "credits" then
345 retval = retval .. tabbuilder.tab_credits()
348 if tabbuilder.current_tab == "dialog_create_world" then
349 retval = retval .. tabbuilder.dialog_create_world()
352 if tabbuilder.current_tab == "dialog_delete_world" then
353 retval = retval .. tabbuilder.dialog_delete_world()
356 retval = retval .. modmgr.gettab(tabbuilder.current_tab)
357 retval = retval .. gamemgr.gettab(tabbuilder.current_tab)
358 retval = retval .. modstore.gettab(tabbuilder.current_tab)
363 --------------------------------------------------------------------------------
364 function tabbuilder.handle_create_world_buttons(fields)
366 if fields["world_create_confirm"] or
367 fields["key_enter"] then
369 local worldname = fields["te_world_name"]
370 local gameindex = engine.get_textlist_index("games")
377 if not filterlist.uid_exists_raw(worldlist,worldname) then
378 engine.setting_set("mg_name",fields["dd_mapgen"])
379 message = engine.create_world(worldname,gameindex)
381 message = "A world named \"" .. worldname .. "\" already exists"
384 if message ~= nil then
385 gamedata.errormessage = message
387 menu.last_game = gameindex
388 engine.setting_set("main_menu_last_game_idx",gameindex)
390 filterlist.refresh(worldlist)
391 engine.setting_set("mainmenu_last_selected_world",
392 filterlist.raw_index_by_uid(worldlist,worldname))
395 gamedata.errormessage = "No worldname given or no game selected"
399 if fields["games"] then
400 tabbuilder.skipformupdate = true
405 tabbuilder.is_dialog = false
406 tabbuilder.show_buttons = true
407 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
410 --------------------------------------------------------------------------------
411 function tabbuilder.handle_delete_world_buttons(fields)
413 if fields["world_delete_confirm"] then
414 if menu.world_to_del > 0 and
415 menu.world_to_del <= #filterlist.get_raw_list(worldlist) then
416 engine.delete_world(menu.world_to_del)
417 menu.world_to_del = 0
418 filterlist.refresh(worldlist)
422 tabbuilder.is_dialog = false
423 tabbuilder.show_buttons = true
424 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
427 --------------------------------------------------------------------------------
428 function tabbuilder.handle_multiplayer_buttons(fields)
430 if fields["te_name"] ~= nil then
431 gamedata.playername = fields["te_name"]
432 engine.setting_set("name", fields["te_name"])
435 if fields["favourites"] ~= nil then
436 local event = explode_textlist_event(fields["favourites"])
437 if event.typ == "DCL" then
438 gamedata.address = menu.favorites[event.index].address
439 gamedata.port = menu.favorites[event.index].port
440 gamedata.playername = fields["te_name"]
441 if fields["te_pwd"] ~= nil then
442 gamedata.password = fields["te_pwd"]
444 gamedata.selected_world = 0
446 if menu.favorites ~= nil then
447 gamedata.servername = menu.favorites[event.index].name
448 gamedata.serverdescription = menu.favorites[event.index].description
451 if gamedata.address ~= nil and
452 gamedata.port ~= nil then
458 if event.typ == "CHG" then
459 local address = menu.favorites[event.index].address
460 local port = menu.favorites[event.index].port
462 if address ~= nil and
464 engine.setting_set("address",address)
465 engine.setting_set("port",port)
468 menu.fav_selected = event.index
473 if fields["key_up"] ~= nil or
474 fields["key_down"] ~= nil then
476 local fav_idx = engine.get_textlist_index("favourites")
478 if fields["key_up"] ~= nil and fav_idx > 1 then
480 else if fields["key_down"] and fav_idx < #menu.favorites then
484 local address = menu.favorites[fav_idx].address
485 local port = menu.favorites[fav_idx].port
487 if address ~= nil and
489 engine.setting_set("address",address)
490 engine.setting_set("port",port)
493 menu.fav_selected = fav_idx
497 if fields["cb_public_serverlist"] ~= nil then
498 engine.setting_setbool("public_serverlist",
499 tabbuilder.tobool(fields["cb_public_serverlist"]))
501 if engine.setting_getbool("public_serverlist") then
502 menu.favorites = engine.get_favorites("online")
504 menu.favorites = engine.get_favorites("local")
506 menu.fav_selected = nil
510 if fields["btn_delete_favorite"] ~= nil then
511 local current_favourite = engine.get_textlist_index("favourites")
512 engine.delete_favorite(current_favourite)
513 menu.favorites = engine.get_favorites()
514 menu.fav_selected = nil
516 engine.setting_set("address","")
517 engine.setting_get("port","")
522 if fields["btn_mp_connect"] ~= nil or
523 fields["key_enter"] then
525 gamedata.playername = fields["te_name"]
526 gamedata.password = fields["te_pwd"]
527 gamedata.address = fields["te_address"]
528 gamedata.port = fields["te_port"]
530 local fav_idx = engine.get_textlist_index("favourites")
532 if fav_idx > 0 and fav_idx <= #menu.favorites and
533 menu.favorites[fav_idx].address == fields["te_address"] and
534 menu.favorites[fav_idx].port == fields["te_port"] then
536 gamedata.servername = menu.favorites[fav_idx].name
537 gamedata.serverdescription = menu.favorites[fav_idx].description
539 gamedata.servername = ""
540 gamedata.serverdescription = ""
543 gamedata.selected_world = 0
550 --------------------------------------------------------------------------------
551 function tabbuilder.handle_server_buttons(fields)
553 local world_doubleclick = false
555 if fields["srv_worlds"] ~= nil then
556 local event = explode_textlist_event(fields["srv_worlds"])
558 if event.typ == "DCL" then
559 world_doubleclick = true
561 if event.typ == "CHG" then
562 engine.setting_set("mainmenu_last_selected_world",
563 filterlist.get_raw_index(worldlist,engine.get_textlist_index("srv_worlds")))
567 menu.handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world")
569 if fields["cb_creative_mode"] then
570 engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"]))
573 if fields["cb_enable_damage"] then
574 engine.setting_setbool("enable_damage",tabbuilder.tobool(fields["cb_enable_damage"]))
577 if fields["cb_server_announce"] then
578 engine.setting_setbool("server_announce",tabbuilder.tobool(fields["cb_server_announce"]))
581 if fields["start_server"] ~= nil or
583 fields["key_enter"] then
584 local selected = engine.get_textlist_index("srv_worlds")
586 gamedata.playername = fields["te_playername"]
587 gamedata.password = fields["te_passwd"]
588 gamedata.port = fields["te_serverport"]
589 gamedata.address = ""
590 gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
592 menu.update_last_game(gamedata.selected_world)
597 if fields["world_create"] ~= nil then
598 tabbuilder.current_tab = "dialog_create_world"
599 tabbuilder.is_dialog = true
600 tabbuilder.show_buttons = false
603 if fields["world_delete"] ~= nil then
604 local selected = engine.get_textlist_index("srv_worlds")
606 selected <= filterlist.size(worldlist) then
607 local world = filterlist.get_list(worldlist)[selected]
609 world.name ~= nil and
610 world.name ~= "" then
611 menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
612 tabbuilder.current_tab = "dialog_delete_world"
613 tabbuilder.is_dialog = true
614 tabbuilder.show_buttons = false
616 menu.world_to_del = 0
621 if fields["world_configure"] ~= nil then
622 selected = engine.get_textlist_index("srv_worlds")
624 modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
625 if modmgr.init_worldconfig() then
626 tabbuilder.current_tab = "dialog_configure_world"
627 tabbuilder.is_dialog = true
628 tabbuilder.show_buttons = false
634 --------------------------------------------------------------------------------
635 function tabbuilder.tobool(text)
636 if text == "true" then
643 --------------------------------------------------------------------------------
644 function tabbuilder.handle_settings_buttons(fields)
645 if fields["cb_fancy_trees"] then
646 engine.setting_setbool("new_style_leaves",tabbuilder.tobool(fields["cb_fancy_trees"]))
648 if fields["cb_smooth_lighting"] then
649 engine.setting_setbool("smooth_lighting",tabbuilder.tobool(fields["cb_smooth_lighting"]))
651 if fields["cb_3d_clouds"] then
652 engine.setting_setbool("enable_3d_clouds",tabbuilder.tobool(fields["cb_3d_clouds"]))
654 if fields["cb_opaque_water"] then
655 engine.setting_setbool("opaque_water",tabbuilder.tobool(fields["cb_opaque_water"]))
657 if fields["old_style_modselection"] then
658 engine.setting_setbool("old_style_mod_selection",tabbuilder.tobool(fields["old_style_modselection"]))
661 if fields["cb_mipmapping"] then
662 engine.setting_setbool("mip_map",tabbuilder.tobool(fields["cb_mipmapping"]))
664 if fields["cb_anisotrophic"] then
665 engine.setting_setbool("anisotropic_filter",tabbuilder.tobool(fields["cb_anisotrophic"]))
667 if fields["cb_bilinear"] then
668 engine.setting_setbool("bilinear_filter",tabbuilder.tobool(fields["cb_bilinear"]))
670 if fields["cb_trilinear"] then
671 engine.setting_setbool("trilinear_filter",tabbuilder.tobool(fields["cb_trilinear"]))
674 if fields["cb_shaders"] then
675 engine.setting_setbool("enable_shaders",tabbuilder.tobool(fields["cb_shaders"]))
677 if fields["cb_pre_ivis"] then
678 engine.setting_setbool("preload_item_visuals",tabbuilder.tobool(fields["cb_pre_ivis"]))
680 if fields["cb_particles"] then
681 engine.setting_setbool("enable_particles",tabbuilder.tobool(fields["cb_particles"]))
683 if fields["cb_finite_liquid"] then
684 engine.setting_setbool("liquid_finite",tabbuilder.tobool(fields["cb_finite_liquid"]))
687 if fields["btn_change_keys"] ~= nil then
688 engine.show_keys_menu()
692 --------------------------------------------------------------------------------
693 function tabbuilder.handle_singleplayer_buttons(fields)
695 local world_doubleclick = false
697 if fields["sp_worlds"] ~= nil then
698 local event = explode_textlist_event(fields["sp_worlds"])
700 if event.typ == "DCL" then
701 world_doubleclick = true
704 if event.typ == "CHG" then
705 engine.setting_set("mainmenu_last_selected_world",
706 filterlist.get_raw_index(worldlist,engine.get_textlist_index("sp_worlds")))
710 menu.handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world")
712 if fields["cb_creative_mode"] then
713 engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"]))
716 if fields["cb_enable_damage"] then
717 engine.setting_setbool("enable_damage",tabbuilder.tobool(fields["cb_enable_damage"]))
720 if fields["play"] ~= nil or
722 fields["key_enter"] then
723 local selected = engine.get_textlist_index("sp_worlds")
725 gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
726 gamedata.singleplayer = true
728 menu.update_last_game(gamedata.selected_world)
734 if fields["world_create"] ~= nil then
735 tabbuilder.current_tab = "dialog_create_world"
736 tabbuilder.is_dialog = true
737 tabbuilder.show_buttons = false
740 if fields["world_delete"] ~= nil then
741 local selected = engine.get_textlist_index("sp_worlds")
743 selected <= filterlist.size(worldlist) then
744 local world = filterlist.get_list(worldlist)[selected]
746 world.name ~= nil and
747 world.name ~= "" then
748 menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
749 tabbuilder.current_tab = "dialog_delete_world"
750 tabbuilder.is_dialog = true
751 tabbuilder.show_buttons = false
753 menu.world_to_del = 0
758 if fields["world_configure"] ~= nil then
759 selected = engine.get_textlist_index("sp_worlds")
761 modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
762 if modmgr.init_worldconfig() then
763 tabbuilder.current_tab = "dialog_configure_world"
764 tabbuilder.is_dialog = true
765 tabbuilder.show_buttons = false
771 --------------------------------------------------------------------------------
772 function tabbuilder.handle_TP_buttons(fields)
773 if fields["TPs"] ~= nil then
774 local event = explode_textlist_event(fields["TPs"])
775 if event.typ == "CHG" or event.typ=="DCL" then
776 local index = engine.get_textlist_index("TPs")
777 engine.setting_set("mainmenu_last_selected_TP",
779 local TPlist = filterTP(engine.get_dirlist(engine.get_texturepath(), true))
780 local TPname = TPlist[engine.get_textlist_index("TPs")]
781 local TPpath = engine.get_texturepath()..DIR_DELIM..TPname
782 if TPname == "None" then TPpath = "" end
783 engine.setting_set("texture_path", TPpath)
788 --------------------------------------------------------------------------------
789 function tabbuilder.tab_header()
791 if tabbuilder.last_tab_index == nil then
792 tabbuilder.last_tab_index = 1
797 for i=1,#tabbuilder.current_buttons,1 do
803 toadd = toadd .. tabbuilder.current_buttons[i].caption
805 return "tabheader[-0.3,-0.99;main_tab;" .. toadd ..";" .. tabbuilder.last_tab_index .. ";true;false]"
808 --------------------------------------------------------------------------------
809 function tabbuilder.handle_tab_buttons(fields)
811 if fields["main_tab"] then
812 local index = tonumber(fields["main_tab"])
813 tabbuilder.last_tab_index = index
814 tabbuilder.current_tab = tabbuilder.current_buttons[index].name
816 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
820 if tabbuilder.current_tab ~= tabbuilder.old_tab then
821 if tabbuilder.current_tab ~= "singleplayer" then
822 menu.update_gametype(true)
826 if tabbuilder.current_tab == "singleplayer" then
827 menu.update_gametype()
830 tabbuilder.old_tab = tabbuilder.current_tab
833 --------------------------------------------------------------------------------
834 function tabbuilder.init()
835 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
837 if tabbuilder.current_tab == nil or
838 tabbuilder.current_tab == "" then
839 tabbuilder.current_tab = "singleplayer"
840 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
843 --initialize tab buttons
844 tabbuilder.last_tab = nil
845 tabbuilder.show_buttons = true
847 tabbuilder.current_buttons = {}
848 table.insert(tabbuilder.current_buttons,{name="singleplayer", caption="Singleplayer"})
849 table.insert(tabbuilder.current_buttons,{name="multiplayer", caption="Client"})
850 table.insert(tabbuilder.current_buttons,{name="server", caption="Server"})
851 table.insert(tabbuilder.current_buttons,{name="settings", caption="Settings"})
852 table.insert(tabbuilder.current_buttons,{name="texture_packs", caption="Texture Packs"})
854 if engine.setting_getbool("main_menu_game_mgr") then
855 table.insert(tabbuilder.current_buttons,{name="game_mgr", caption="Games"})
858 if engine.setting_getbool("main_menu_mod_mgr") then
859 table.insert(tabbuilder.current_buttons,{name="mod_mgr", caption="Mods"})
861 table.insert(tabbuilder.current_buttons,{name="credits", caption="Credits"})
864 for i=1,#tabbuilder.current_buttons,1 do
865 if tabbuilder.current_buttons[i].name == tabbuilder.current_tab then
866 tabbuilder.last_tab_index = i
870 if tabbuilder.current_tab ~= "singleplayer" then
871 menu.update_gametype(true)
873 menu.update_gametype()
877 --------------------------------------------------------------------------------
878 function tabbuilder.tab_multiplayer()
881 "vertlabel[0,-0.25;CLIENT]" ..
882 "label[1,-0.25;Favorites:]"..
883 "label[1,4.25;Address/Port]"..
884 "label[9,2.75;Name/Password]" ..
885 "field[1.25,5.25;5.5,0.5;te_address;;" ..engine.setting_get("address") .."]" ..
886 "field[6.75,5.25;2.25,0.5;te_port;;" ..engine.setting_get("port") .."]" ..
887 "checkbox[1,3.6;cb_public_serverlist;Public Serverlist;" ..
888 dump(engine.setting_getbool("public_serverlist")) .. "]"
890 if not engine.setting_getbool("public_serverlist") then
892 "button[6.45,3.95;2.25,0.5;btn_delete_favorite;Delete]"
896 "button[9,4.95;2.5,0.5;btn_mp_connect;Connect]" ..
897 "field[9.3,3.75;2.5,0.5;te_name;;" ..engine.setting_get("name") .."]" ..
898 "pwdfield[9.3,4.5;2.5,0.5;te_pwd;]" ..
899 "textarea[9.3,0.25;2.5,2.75;;"
900 if menu.fav_selected ~= nil and
901 menu.favorites[menu.fav_selected].description ~= nil then
903 engine.formspec_escape(menu.favorites[menu.fav_selected].description,true)
908 "textlist[1,0.35;7.5,3.35;favourites;"
910 local render_details = engine.setting_getbool("public_serverlist")
912 if #menu.favorites > 0 then
913 retval = retval .. menu.render_favorite(menu.favorites[1],render_details)
915 for i=2,#menu.favorites,1 do
916 retval = retval .. "," .. menu.render_favorite(menu.favorites[i],render_details)
920 if menu.fav_selected ~= nil then
921 retval = retval .. ";" .. menu.fav_selected .. "]"
923 retval = retval .. ";0]"
929 --------------------------------------------------------------------------------
930 function tabbuilder.tab_server()
932 local index = filterlist.get_current_index(worldlist,
933 tonumber(engine.setting_get("mainmenu_last_selected_world"))
937 "button[4,4.15;2.6,0.5;world_delete;Delete]" ..
938 "button[6.5,4.15;2.8,0.5;world_create;New]" ..
939 "button[9.2,4.15;2.55,0.5;world_configure;Configure]" ..
940 "button[8.5,4.9;3.25,0.5;start_server;Start Game]" ..
941 "label[4,-0.25;Select World:]"..
942 "vertlabel[0,-0.25;START SERVER]" ..
943 "checkbox[0.5,0.25;cb_creative_mode;Creative Mode;" ..
944 dump(engine.setting_getbool("creative_mode")) .. "]"..
945 "checkbox[0.5,0.7;cb_enable_damage;Enable Damage;" ..
946 dump(engine.setting_getbool("enable_damage")) .. "]"..
947 "checkbox[0.5,1.15;cb_server_announce;Public;" ..
948 dump(engine.setting_getbool("server_announce")) .. "]"..
949 "field[0.8,3.2;3,0.5;te_playername;Name;" ..
950 engine.setting_get("name") .. "]" ..
951 "pwdfield[0.8,4.2;3,0.5;te_passwd;Password]" ..
952 "field[0.8,5.2;3,0.5;te_serverport;Server Port;30000]" ..
953 "textlist[4,0.25;7.5,3.7;srv_worlds;" ..
954 menu.render_world_list() ..
960 --------------------------------------------------------------------------------
961 function tabbuilder.tab_settings()
962 return "vertlabel[0,0;SETTINGS]" ..
963 "checkbox[1,0.75;cb_fancy_trees;Fancy trees;" .. dump(engine.setting_getbool("new_style_leaves")) .. "]"..
964 "checkbox[1,1.25;cb_smooth_lighting;Smooth Lighting;".. dump(engine.setting_getbool("smooth_lighting")) .. "]"..
965 "checkbox[1,1.75;cb_3d_clouds;3D Clouds;" .. dump(engine.setting_getbool("enable_3d_clouds")) .. "]"..
966 "checkbox[1,2.25;cb_opaque_water;Opaque Water;" .. dump(engine.setting_getbool("opaque_water")) .. "]"..
967 "checkbox[1,2.75;old_style_modselection;Old style modmgr;" .. dump(engine.setting_getbool("old_style_mod_selection")) .. "]"..
969 "checkbox[4,0.75;cb_mipmapping;Mip-Mapping;" .. dump(engine.setting_getbool("mip_map")) .. "]"..
970 "checkbox[4,1.25;cb_anisotrophic;Anisotropic Filtering;".. dump(engine.setting_getbool("anisotropic_filter")) .. "]"..
971 "checkbox[4,1.75;cb_bilinear;Bi-Linear Filtering;" .. dump(engine.setting_getbool("bilinear_filter")) .. "]"..
972 "checkbox[4,2.25;cb_trilinear;Tri-Linear Filtering;" .. dump(engine.setting_getbool("trilinear_filter")) .. "]"..
974 "checkbox[7.5,0.75;cb_shaders;Shaders;" .. dump(engine.setting_getbool("enable_shaders")) .. "]"..
975 "checkbox[7.5,1.25;cb_pre_ivis;Preload item visuals;".. dump(engine.setting_getbool("preload_item_visuals")) .. "]"..
976 "checkbox[7.5,1.75;cb_particles;Enable Particles;" .. dump(engine.setting_getbool("enable_particles")) .. "]"..
977 "checkbox[7.5,2.25;cb_finite_liquid;Finite Liquid;" .. dump(engine.setting_getbool("liquid_finite")) .. "]"..
979 "button[1,4.25;2.25,0.5;btn_change_keys;Change keys]"
982 --------------------------------------------------------------------------------
983 function tabbuilder.tab_singleplayer()
985 local index = filterlist.get_current_index(worldlist,
986 tonumber(engine.setting_get("mainmenu_last_selected_world"))
989 return "button[4,4.15;2.6,0.5;world_delete;Delete]" ..
990 "button[6.5,4.15;2.8,0.5;world_create;New]" ..
991 "button[9.2,4.15;2.55,0.5;world_configure;Configure]" ..
992 "button[8.5,4.95;3.25,0.5;play;Play]" ..
993 "label[4,-0.25;Select World:]"..
994 "vertlabel[0,-0.25;SINGLE PLAYER]" ..
995 "checkbox[0.5,0.25;cb_creative_mode;Creative Mode;" ..
996 dump(engine.setting_getbool("creative_mode")) .. "]"..
997 "checkbox[0.5,0.7;cb_enable_damage;Enable Damage;" ..
998 dump(engine.setting_getbool("enable_damage")) .. "]"..
999 "textlist[4,0.25;7.5,3.7;sp_worlds;" ..
1000 menu.render_world_list() ..
1001 ";" .. index .. "]" ..
1005 --------------------------------------------------------------------------------
1006 function tabbuilder.tab_TP()
1007 local TPpath = engine.setting_get("texture_path")
1008 local TPlist = filterTP(engine.get_dirlist(engine.get_texturepath(), true))
1009 local index = tonumber(engine.setting_get("mainmenu_last_selected_TP"))
1010 if index == nil then index = 1 end
1011 if TPpath == "" then
1012 return "label[4,-0.25;Select texture pack:]"..
1013 "vertlabel[0,-0.25;TEXTURE PACKS]" ..
1014 "textlist[4,0.25;7.5,5.0;TPs;" ..
1015 menu.render_TP_list(TPlist) ..
1018 local TPinfofile = TPpath..DIR_DELIM.."info.txt"
1019 local f = io.open(TPinfofile, "r")
1021 menu.TPinfo = "No information available"
1023 menu.TPinfo = f:read("*all")
1026 local TPscreenfile = TPpath..DIR_DELIM.."screenshot.png"
1027 local f = io.open(TPscreenfile, "r")
1031 menu.TPscreen = TPscreenfile
1035 local no_screenshot = engine.get_texturepath()..DIR_DELIM.."base"..DIR_DELIM.."pack"..DIR_DELIM.."no_screenshot.png"
1037 return "label[4,-0.25;Select texture pack:]"..
1038 "vertlabel[0,-0.25;TEXTURE PACKS]" ..
1039 "textlist[4,0.25;7.5,5.0;TPs;" ..
1040 menu.render_TP_list(TPlist) ..
1041 ";" .. index .. "]" ..
1042 "image[0.65,0.25;4.0,3.7;"..(menu.TPscreen or no_screenshot).."]"..
1043 "textarea[1.0,3.25;3.7,1.5;;"..engine.formspec_escape(menu.TPinfo or "")..";]"
1046 --------------------------------------------------------------------------------
1047 function tabbuilder.tab_credits()
1048 return "vertlabel[0,-0.5;CREDITS]" ..
1049 "label[0.5,3;Minetest " .. engine.get_version() .. "]" ..
1050 "label[0.5,3.3;http://minetest.net]" ..
1051 "image[0.5,1;" .. menu.defaulttexturedir .. "logo.png]" ..
1052 "textlist[3.5,-0.25;8.5,5.8;list_credits;" ..
1053 "#FFFF00Core Developers," ..
1054 "Perttu Ahola (celeron55) <celeron55@gmail.com>,"..
1055 "Ryan Kwolek (kwolekr) <kwolekr@minetest.net>,"..
1056 "PilzAdam <pilzadam@minetest.net>," ..
1057 "Ilya Zhuravlev (xyz) <xyz@minetest.net>,"..
1058 "Lisa Milne (darkrose) <lisa@ltmnet.com>,"..
1059 "Maciej Kasatkin (RealBadAngel) <mk@realbadangel.pl>,"..
1060 "proller <proler@gmail.com>,"..
1061 "sfan5 <sfan5@live.de>,"..
1062 "kahrl <kahrl@gmx.net>,"..
1064 "#FFFF00Active Contributors," ..
1066 "Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>,"..
1067 "Jurgen Doser (doserj) <jurgen.doser@gmail.com>,"..
1068 "Jeija <jeija@mesecons.net>,"..
1069 "MirceaKitsune <mirceakitsune@gmail.com>,"..
1071 "dannydark <the_skeleton_of_a_child@yahoo.co.uk>,"..
1072 "0gb.us <0gb.us@0gb.us>,"..
1074 "#FFFF00Previous Contributors," ..
1075 "Guiseppe Bilotta (Oblomov) <guiseppe.bilotta@gmail.com>,"..
1076 "Jonathan Neuschafer <j.neuschaefer@gmx.net>,"..
1077 "Nils Dagsson Moskopp (erlehmann) <nils@dieweltistgarnichtso.net>,"..
1078 "Constantin Wenger (SpeedProg) <constantin.wenger@googlemail.com>,"..
1079 "matttpt <matttpt@gmail.com>,"..
1080 "JacobF <queatz@gmail.com>,"..
1084 --------------------------------------------------------------------------------
1085 function tabbuilder.checkretval(retval)
1087 if retval ~= nil then
1088 if retval.current_tab ~= nil then
1089 tabbuilder.current_tab = retval.current_tab
1092 if retval.is_dialog ~= nil then
1093 tabbuilder.is_dialog = retval.is_dialog
1096 if retval.show_buttons ~= nil then
1097 tabbuilder.show_buttons = retval.show_buttons
1100 if retval.skipformupdate ~= nil then
1101 tabbuilder.skipformupdate = retval.skipformupdate
1106 --------------------------------------------------------------------------------
1107 --------------------------------------------------------------------------------
1108 -- initialize callbacks
1109 --------------------------------------------------------------------------------
1110 --------------------------------------------------------------------------------
1111 engine.button_handler = function(fields)
1112 --print("Buttonhandler: tab: " .. tabbuilder.current_tab .. " fields: " .. dump(fields))
1114 if fields["btn_error_confirm"] then
1115 gamedata.errormessage = nil
1118 local retval = modmgr.handle_buttons(tabbuilder.current_tab,fields)
1119 tabbuilder.checkretval(retval)
1121 retval = gamemgr.handle_buttons(tabbuilder.current_tab,fields)
1122 tabbuilder.checkretval(retval)
1124 retval = modstore.handle_buttons(tabbuilder.current_tab,fields)
1125 tabbuilder.checkretval(retval)
1127 if tabbuilder.current_tab == "dialog_create_world" then
1128 tabbuilder.handle_create_world_buttons(fields)
1131 if tabbuilder.current_tab == "dialog_delete_world" then
1132 tabbuilder.handle_delete_world_buttons(fields)
1135 if tabbuilder.current_tab == "singleplayer" then
1136 tabbuilder.handle_singleplayer_buttons(fields)
1139 if tabbuilder.current_tab == "texture_packs" then
1140 tabbuilder.handle_TP_buttons(fields)
1143 if tabbuilder.current_tab == "multiplayer" then
1144 tabbuilder.handle_multiplayer_buttons(fields)
1147 if tabbuilder.current_tab == "settings" then
1148 tabbuilder.handle_settings_buttons(fields)
1151 if tabbuilder.current_tab == "server" then
1152 tabbuilder.handle_server_buttons(fields)
1156 tabbuilder.handle_tab_buttons(fields)
1159 menubar.handle_buttons(fields)
1161 if not tabbuilder.skipformupdate then
1165 tabbuilder.skipformupdate = false
1169 --------------------------------------------------------------------------------
1170 engine.event_handler = function(event)
1171 if event == "MenuQuit" then
1172 if tabbuilder.is_dialog then
1173 tabbuilder.is_dialog = false
1174 tabbuilder.show_buttons = true
1175 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1176 menu.update_gametype()
1184 --------------------------------------------------------------------------------
1185 function menu.update_gametype(reset)
1188 engine.set_topleft_text("")
1189 filterlist.set_filtercriteria(worldlist,nil)
1191 local game = menu.lastgame()
1192 mm_texture.update(tabbuilder.current_tab,game)
1193 engine.set_topleft_text(game.name)
1194 filterlist.set_filtercriteria(worldlist,game.id)
1198 --------------------------------------------------------------------------------
1199 --------------------------------------------------------------------------------
1201 --------------------------------------------------------------------------------
1202 --------------------------------------------------------------------------------
1210 engine.sound_play("main_menu", true)