2 local menupath = engine.get_mainmenu_path()..DIR_DELIM
3 local commonpath = engine.get_builtin_path()..DIR_DELIM.."common"..DIR_DELIM
5 dofile(menupath.."filterlist.lua")
6 dofile(menupath.."modmgr.lua")
7 dofile(menupath.."modstore.lua")
8 dofile(menupath.."gamemgr.lua")
9 dofile(menupath.."textures.lua")
10 dofile(menupath.."menubar.lua")
11 dofile(commonpath.."async_event.lua")
13 mt_color_grey = "#AAAAAA"
14 mt_color_blue = "#0000DD"
15 mt_color_green = "#00DD00"
16 mt_color_dark_green = "#003300"
18 --for all other colors ask sfan5 to complete his worK!
24 --------------------------------------------------------------------------------
25 local function filter_texture_pack_list(list)
27 for _,i in ipairs(list) do
29 table.insert(retval, i)
35 --------------------------------------------------------------------------------
36 function menu.render_favorite(spec,render_details)
39 if spec.name ~= nil then
40 text = text .. engine.formspec_escape(spec.name:trim())
42 -- if spec.description ~= nil and
43 -- engine.formspec_escape(spec.description):trim() ~= "" then
44 -- text = text .. " (" .. engine.formspec_escape(spec.description) .. ")"
47 if spec.address ~= nil then
48 text = text .. spec.address:trim()
50 if spec.port ~= nil then
51 text = text .. ":" .. spec.port
56 if not render_details then
61 if spec.password == true then
62 details = details .. "*"
64 details = details .. "_"
68 details = details .. "C"
70 details = details .. "_"
74 details = details .. "D"
76 details = details .. "_"
80 details = details .. "P"
82 details = details .. "_"
84 details = details .. " "
86 local playercount = ""
88 if spec.clients ~= nil and
89 spec.clients_max ~= nil then
90 playercount = string.format("%03d",spec.clients) .. "/" ..
91 string.format("%03d",spec.clients_max) .. " "
94 return playercount .. engine.formspec_escape(details) .. text
97 --------------------------------------------------------------------------------
98 os.tempfolder = function()
99 local filetocheck = os.tmpname()
100 os.remove(filetocheck)
102 local randname = "MTTempModFolder_" .. math.random(0,10000)
103 if DIR_DELIM == "\\" then
104 local tempfolder = os.getenv("TEMP")
105 return tempfolder .. filetocheck
107 local backstring = filetocheck:reverse()
108 return filetocheck:sub(0,filetocheck:len()-backstring:find(DIR_DELIM)+1) ..randname
113 --------------------------------------------------------------------------------
114 function text2textlist(xpos,ypos,width,height,tl_name,textlen,text,transparency)
115 local textlines = engine.splittext(text,textlen)
117 local retval = "textlist[" .. xpos .. "," .. ypos .. ";"
118 .. width .. "," .. height .. ";"
121 for i=1, #textlines, 1 do
122 textlines[i] = textlines[i]:gsub("\r","")
123 retval = retval .. engine.formspec_escape(textlines[i]) .. ","
126 retval = retval .. ";0;"
129 retval = retval .. "true"
132 retval = retval .. "]"
137 --------------------------------------------------------------------------------
138 function init_globals()
140 gamedata.worldindex = 0
142 worldlist = filterlist.create(
145 function(element,uid)
146 if element.name == uid then
150 end, --unique id compare fct
151 function(element,gameid)
152 if element.gameid == gameid then
159 filterlist.add_sort_mechanism(worldlist,"alphabetic",sort_worlds_alphabetic)
160 filterlist.set_sortmode(worldlist,"alphabetic")
163 --------------------------------------------------------------------------------
164 function update_menu()
169 if gamedata.errormessage ~= nil then
170 formspec = "size[12,5.2,true]" ..
171 "textarea[1,2;10,2;;ERROR: " ..
172 engine.formspec_escape(gamedata.errormessage) ..
174 "button[4.5,4.2;3,0.5;btn_error_confirm;" .. fgettext("Ok") .. "]"
176 formspec = tabbuilder.gettab()
179 engine.update_formspec(formspec)
182 --------------------------------------------------------------------------------
183 function menu.render_world_list()
186 local current_worldlist = filterlist.get_list(worldlist)
188 for i,v in ipairs(current_worldlist) do
190 retval = retval ..","
193 retval = retval .. engine.formspec_escape(v.name) ..
194 " \\[" .. engine.formspec_escape(v.gameid) .. "\\]"
200 --------------------------------------------------------------------------------
201 function menu.render_texture_pack_list(list)
204 for i, v in ipairs(list) do
206 retval = retval ..","
209 retval = retval .. engine.formspec_escape(v)
215 --------------------------------------------------------------------------------
216 function menu.asyncOnlineFavourites()
220 return engine.get_favorites("online")
224 menu.favorites = result
225 engine.event_handler("Refresh")
230 --------------------------------------------------------------------------------
233 gamemgr.update_gamelist()
235 menu.last_game = tonumber(engine.setting_get("main_menu_last_game_idx"))
237 if type(menu.last_game) ~= "number" then
241 if engine.setting_getbool("public_serverlist") then
242 menu.asyncOnlineFavourites()
244 menu.favorites = engine.get_favorites("local")
247 menu.defaulttexturedir = engine.get_texturepath_share() .. DIR_DELIM .. "base" ..
248 DIR_DELIM .. "pack" .. DIR_DELIM
251 --------------------------------------------------------------------------------
252 function menu.lastgame()
253 if menu.last_game > 0 and menu.last_game <= #gamemgr.games then
254 return gamemgr.games[menu.last_game]
257 if #gamemgr.games >= 1 then
259 return gamemgr.games[menu.last_game]
266 --------------------------------------------------------------------------------
267 function menu.update_last_game()
269 local current_world = filterlist.get_raw_element(worldlist,
270 engine.setting_get("mainmenu_last_selected_world")
273 if current_world == nil then
277 local gamespec, i = gamemgr.find_by_gameid(current_world.gameid)
280 engine.setting_set("main_menu_last_game_idx",menu.last_game)
284 --------------------------------------------------------------------------------
285 function menu.handle_key_up_down(fields,textlist,settingname)
287 if fields["key_up"] then
288 local oldidx = engine.get_textlist_index(textlist)
290 if oldidx ~= nil and oldidx > 1 then
291 local newidx = oldidx -1
292 engine.setting_set(settingname,
293 filterlist.get_raw_index(worldlist,newidx))
297 if fields["key_down"] then
298 local oldidx = engine.get_textlist_index(textlist)
300 if oldidx ~= nil and oldidx < filterlist.size(worldlist) then
301 local newidx = oldidx + 1
302 engine.setting_set(settingname,
303 filterlist.get_raw_index(worldlist,newidx))
308 --------------------------------------------------------------------------------
309 function tabbuilder.dialog_create_world()
310 local mapgens = {"v6", "v7", "indev", "singlenode", "math"}
312 local current_seed = engine.setting_get("fixed_map_seed") or ""
313 local current_mg = engine.setting_get("mg_name")
318 for k,v in pairs(mapgens) do
319 if current_mg == v then
323 mglist = mglist .. v .. ","
325 mglist = mglist:sub(1, -2)
328 "label[2,0;" .. fgettext("World name") .. "]"..
329 "field[4.5,0.4;6,0.5;te_world_name;;]" ..
331 "label[2,1;" .. fgettext("Seed") .. "]"..
332 "field[4.5,1.4;6,0.5;te_seed;;".. current_seed .. "]" ..
334 "label[2,2;" .. fgettext("Mapgen") .. "]"..
335 "dropdown[4.2,2;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
337 "label[2,3;" .. fgettext("Game") .. "]"..
338 "textlist[4.2,3;5.8,2.3;games;" .. gamemgr.gamelist() ..
339 ";" .. menu.last_game .. ";true]" ..
341 "button[5,5.5;2.6,0.5;world_create_confirm;" .. fgettext("Create") .. "]" ..
342 "button[7.5,5.5;2.8,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
347 --------------------------------------------------------------------------------
348 function tabbuilder.dialog_delete_world()
349 return "label[2,2;" ..
350 fgettext("Delete World \"$1\"?", filterlist.get_raw_list(worldlist)[menu.world_to_del].name) .. "]"..
351 "button[3.5,4.2;2.6,0.5;world_delete_confirm;" .. fgettext("Yes").. "]" ..
352 "button[6,4.2;2.8,0.5;world_delete_cancel;" .. fgettext("No") .. "]"
355 --------------------------------------------------------------------------------
357 function tabbuilder.gettab()
358 local tsize = tabbuilder.tabsizes[tabbuilder.current_tab] or {width=12, height=5.2}
359 local retval = "size[" .. tsize.width .. "," .. tsize.height .. ",true]"
361 if tabbuilder.show_buttons then
362 retval = retval .. tabbuilder.tab_header()
365 local buildfunc = tabbuilder.tabfuncs[tabbuilder.current_tab]
366 if buildfunc ~= nil then
367 retval = retval .. buildfunc()
370 retval = retval .. modmgr.gettab(tabbuilder.current_tab)
371 retval = retval .. gamemgr.gettab(tabbuilder.current_tab)
372 retval = retval .. modstore.gettab(tabbuilder.current_tab)
377 --------------------------------------------------------------------------------
378 function tabbuilder.handle_create_world_buttons(fields)
380 if fields["world_create_confirm"] or
381 fields["key_enter"] then
383 local worldname = fields["te_world_name"]
384 local gameindex = engine.get_textlist_index("games")
386 if gameindex ~= nil and
391 if not filterlist.uid_exists_raw(worldlist,worldname) then
392 engine.setting_set("mg_name",fields["dd_mapgen"])
393 message = engine.create_world(worldname,gameindex)
395 message = fgettext("A world named \"$1\" already exists", worldname)
398 engine.setting_set("fixed_map_seed", fields["te_seed"])
400 if message ~= nil then
401 gamedata.errormessage = message
403 menu.last_game = gameindex
404 engine.setting_set("main_menu_last_game_idx",gameindex)
406 filterlist.refresh(worldlist)
407 engine.setting_set("mainmenu_last_selected_world",
408 filterlist.raw_index_by_uid(worldlist,worldname))
411 gamedata.errormessage =
412 fgettext("No worldname given or no game selected")
416 if fields["games"] then
417 tabbuilder.skipformupdate = true
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_delete_world_buttons(fields)
430 if fields["world_delete_confirm"] then
431 if menu.world_to_del > 0 and
432 menu.world_to_del <= #filterlist.get_raw_list(worldlist) then
433 engine.delete_world(menu.world_to_del)
434 menu.world_to_del = 0
435 filterlist.refresh(worldlist)
439 tabbuilder.is_dialog = false
440 tabbuilder.show_buttons = true
441 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
444 --------------------------------------------------------------------------------
445 function tabbuilder.handle_multiplayer_buttons(fields)
447 if fields["te_name"] ~= nil then
448 gamedata.playername = fields["te_name"]
449 engine.setting_set("name", fields["te_name"])
452 if fields["favourites"] ~= nil then
453 local event = engine.explode_textlist_event(fields["favourites"])
454 if event.type == "DCL" then
455 if event.index <= #menu.favorites then
456 gamedata.address = menu.favorites[event.index].address
457 gamedata.port = menu.favorites[event.index].port
458 gamedata.playername = fields["te_name"]
459 if fields["te_pwd"] ~= nil then
460 gamedata.password = fields["te_pwd"]
462 gamedata.selected_world = 0
464 if menu.favorites ~= nil then
465 gamedata.servername = menu.favorites[event.index].name
466 gamedata.serverdescription = menu.favorites[event.index].description
469 if gamedata.address ~= nil and
470 gamedata.port ~= nil then
471 engine.setting_set("address",gamedata.address)
472 engine.setting_set("remote_port",gamedata.port)
478 if event.type == "CHG" then
479 if event.index <= #menu.favorites then
480 local address = menu.favorites[event.index].address
481 local port = menu.favorites[event.index].port
483 if address ~= nil and
485 engine.setting_set("address",address)
486 engine.setting_set("remote_port",port)
489 menu.fav_selected = event.index
495 if fields["key_up"] ~= nil or
496 fields["key_down"] ~= nil then
498 local fav_idx = engine.get_textlist_index("favourites")
500 if fav_idx ~= nil then
501 if fields["key_up"] ~= nil and fav_idx > 1 then
503 else if fields["key_down"] and fav_idx < #menu.favorites then
508 local address = menu.favorites[fav_idx].address
509 local port = menu.favorites[fav_idx].port
511 if address ~= nil and
513 engine.setting_set("address",address)
514 engine.setting_set("remote_port",port)
517 menu.fav_selected = fav_idx
521 if fields["cb_public_serverlist"] ~= nil then
522 engine.setting_set("public_serverlist", fields["cb_public_serverlist"])
524 if engine.setting_getbool("public_serverlist") then
525 menu.asyncOnlineFavourites()
527 menu.favorites = engine.get_favorites("local")
529 menu.fav_selected = nil
533 if fields["btn_delete_favorite"] ~= nil then
534 local current_favourite = engine.get_textlist_index("favourites")
535 if current_favourite == nil then return end
536 engine.delete_favorite(current_favourite)
537 menu.favorites = engine.get_favorites()
538 menu.fav_selected = nil
540 engine.setting_set("address","")
541 engine.setting_set("remote_port","30000")
546 if fields["btn_mp_connect"] ~= nil or
547 fields["key_enter"] ~= nil then
549 gamedata.playername = fields["te_name"]
550 gamedata.password = fields["te_pwd"]
551 gamedata.address = fields["te_address"]
552 gamedata.port = fields["te_port"]
554 local fav_idx = engine.get_textlist_index("favourites")
556 if fav_idx ~= nil and fav_idx <= #menu.favorites and
557 menu.favorites[fav_idx].address == fields["te_address"] and
558 menu.favorites[fav_idx].port == fields["te_port"] then
560 gamedata.servername = menu.favorites[fav_idx].name
561 gamedata.serverdescription = menu.favorites[fav_idx].description
563 gamedata.servername = ""
564 gamedata.serverdescription = ""
567 gamedata.selected_world = 0
569 engine.setting_set("address",fields["te_address"])
570 engine.setting_set("remote_port",fields["te_port"])
577 --------------------------------------------------------------------------------
578 function tabbuilder.handle_server_buttons(fields)
580 local world_doubleclick = false
582 if fields["srv_worlds"] ~= nil then
583 local event = engine.explode_textlist_event(fields["srv_worlds"])
585 if event.type == "DCL" then
586 world_doubleclick = true
588 if event.type == "CHG" then
589 engine.setting_set("mainmenu_last_selected_world",
590 filterlist.get_raw_index(worldlist,engine.get_textlist_index("srv_worlds")))
594 menu.handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world")
596 if fields["cb_creative_mode"] then
597 engine.setting_set("creative_mode", fields["cb_creative_mode"])
600 if fields["cb_enable_damage"] then
601 engine.setting_set("enable_damage", fields["cb_enable_damage"])
604 if fields["cb_server_announce"] then
605 engine.setting_set("server_announce", fields["cb_server_announce"])
608 if fields["start_server"] ~= nil or
610 fields["key_enter"] then
611 local selected = engine.get_textlist_index("srv_worlds")
612 if selected ~= nil then
613 gamedata.playername = fields["te_playername"]
614 gamedata.password = fields["te_passwd"]
615 gamedata.port = fields["te_serverport"]
616 gamedata.address = ""
617 gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
619 engine.setting_set("port",gamedata.port)
620 if fields["te_serveraddr"] ~= nil then
621 engine.setting_set("bind_address",fields["te_serveraddr"])
624 menu.update_last_game(gamedata.selected_world)
629 if fields["world_create"] ~= nil then
630 tabbuilder.current_tab = "dialog_create_world"
631 tabbuilder.is_dialog = true
632 tabbuilder.show_buttons = false
635 if fields["world_delete"] ~= nil then
636 local selected = engine.get_textlist_index("srv_worlds")
637 if selected ~= nil and
638 selected <= filterlist.size(worldlist) then
639 local world = filterlist.get_list(worldlist)[selected]
641 world.name ~= nil and
642 world.name ~= "" then
643 menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
644 tabbuilder.current_tab = "dialog_delete_world"
645 tabbuilder.is_dialog = true
646 tabbuilder.show_buttons = false
648 menu.world_to_del = 0
653 if fields["world_configure"] ~= nil then
654 selected = engine.get_textlist_index("srv_worlds")
655 if selected ~= nil then
656 modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
657 if modmgr.init_worldconfig() then
658 tabbuilder.current_tab = "dialog_configure_world"
659 tabbuilder.is_dialog = true
660 tabbuilder.show_buttons = false
666 --------------------------------------------------------------------------------
667 function tabbuilder.handle_settings_buttons(fields)
668 if fields["cb_fancy_trees"] then
669 engine.setting_set("new_style_leaves", fields["cb_fancy_trees"])
671 if fields["cb_smooth_lighting"] then
672 engine.setting_set("smooth_lighting", fields["cb_smooth_lighting"])
674 if fields["cb_3d_clouds"] then
675 engine.setting_set("enable_3d_clouds", fields["cb_3d_clouds"])
677 if fields["cb_opaque_water"] then
678 engine.setting_set("opaque_water", fields["cb_opaque_water"])
681 if fields["cb_mipmapping"] then
682 engine.setting_set("mip_map", fields["cb_mipmapping"])
684 if fields["cb_anisotrophic"] then
685 engine.setting_set("anisotropic_filter", fields["cb_anisotrophic"])
687 if fields["cb_bilinear"] then
688 engine.setting_set("bilinear_filter", fields["cb_bilinear"])
690 if fields["cb_trilinear"] then
691 engine.setting_set("trilinear_filter", fields["cb_trilinear"])
694 if fields["cb_shaders"] then
695 if (engine.setting_get("video_driver") == "direct3d8" or engine.setting_get("video_driver") == "direct3d9") then
696 engine.setting_set("enable_shaders", "false")
697 gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
699 engine.setting_set("enable_shaders", fields["cb_shaders"])
702 if fields["cb_pre_ivis"] then
703 engine.setting_set("preload_item_visuals", fields["cb_pre_ivis"])
705 if fields["cb_particles"] then
706 engine.setting_set("enable_particles", fields["cb_particles"])
708 if fields["cb_bumpmapping"] then
709 engine.setting_set("enable_bumpmapping", fields["cb_bumpmapping"])
711 if fields["cb_parallax"] then
712 engine.setting_set("enable_parallax_occlusion", fields["cb_parallax"])
714 if fields["cb_generate_normalmaps"] then
715 engine.setting_set("generate_normalmaps", fields["cb_generate_normalmaps"])
717 if fields["cb_waving_water"] then
718 engine.setting_set("enable_waving_water", fields["cb_waving_water"])
720 if fields["cb_waving_leaves"] then
721 engine.setting_set("enable_waving_leaves", fields["cb_waving_leaves"])
723 if fields["cb_waving_plants"] then
724 engine.setting_set("enable_waving_plants", fields["cb_waving_plants"])
726 if fields["btn_change_keys"] ~= nil then
727 engine.show_keys_menu()
731 --------------------------------------------------------------------------------
732 function tabbuilder.handle_singleplayer_buttons(fields)
734 local world_doubleclick = false
736 if fields["sp_worlds"] ~= nil then
737 local event = engine.explode_textlist_event(fields["sp_worlds"])
739 if event.type == "DCL" then
740 world_doubleclick = true
743 if event.type == "CHG" then
744 engine.setting_set("mainmenu_last_selected_world",
745 filterlist.get_raw_index(worldlist,engine.get_textlist_index("sp_worlds")))
749 menu.handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world")
751 if fields["cb_creative_mode"] then
752 engine.setting_set("creative_mode", fields["cb_creative_mode"])
755 if fields["cb_enable_damage"] then
756 engine.setting_set("enable_damage", fields["cb_enable_damage"])
759 if fields["play"] ~= nil or
761 fields["key_enter"] then
762 local selected = engine.get_textlist_index("sp_worlds")
763 if selected ~= nil then
764 gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
765 gamedata.singleplayer = true
767 menu.update_last_game(gamedata.selected_world)
773 if fields["world_create"] ~= nil then
774 tabbuilder.current_tab = "dialog_create_world"
775 tabbuilder.is_dialog = true
776 tabbuilder.show_buttons = false
779 if fields["world_delete"] ~= nil then
780 local selected = engine.get_textlist_index("sp_worlds")
781 if selected ~= nil and
782 selected <= filterlist.size(worldlist) then
783 local world = filterlist.get_list(worldlist)[selected]
785 world.name ~= nil and
786 world.name ~= "" then
787 menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
788 tabbuilder.current_tab = "dialog_delete_world"
789 tabbuilder.is_dialog = true
790 tabbuilder.show_buttons = false
792 menu.world_to_del = 0
797 if fields["world_configure"] ~= nil then
798 selected = engine.get_textlist_index("sp_worlds")
799 if selected ~= nil then
800 modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
801 if modmgr.init_worldconfig() then
802 tabbuilder.current_tab = "dialog_configure_world"
803 tabbuilder.is_dialog = true
804 tabbuilder.show_buttons = false
810 --------------------------------------------------------------------------------
811 function tabbuilder.handle_texture_pack_buttons(fields)
812 if fields["TPs"] ~= nil then
813 local event = engine.explode_textlist_event(fields["TPs"])
814 if event.type == "CHG" or event.type == "DCL" then
815 local index = engine.get_textlist_index("TPs")
816 engine.setting_set("mainmenu_last_selected_TP",
818 local list = filter_texture_pack_list(engine.get_dirlist(engine.get_texturepath(), true))
819 local current_index = engine.get_textlist_index("TPs")
820 if current_index ~= nil and #list >= current_index then
821 local new_path = engine.get_texturepath()..DIR_DELIM..list[current_index]
822 if list[current_index] == "None" then new_path = "" end
824 engine.setting_set("texture_path", new_path)
830 --------------------------------------------------------------------------------
831 function tabbuilder.tab_header()
833 if tabbuilder.last_tab_index == nil then
834 tabbuilder.last_tab_index = 1
839 for i=1,#tabbuilder.current_buttons,1 do
845 toadd = toadd .. tabbuilder.current_buttons[i].caption
847 return "tabheader[-0.3,-0.99;main_tab;" .. toadd ..";" .. tabbuilder.last_tab_index .. ";true;false]"
850 --------------------------------------------------------------------------------
851 function tabbuilder.handle_tab_buttons(fields)
853 if fields["main_tab"] then
854 local index = tonumber(fields["main_tab"])
855 tabbuilder.last_tab_index = index
856 tabbuilder.current_tab = tabbuilder.current_buttons[index].name
858 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
862 if tabbuilder.current_tab ~= tabbuilder.old_tab then
863 if tabbuilder.current_tab ~= "singleplayer" and not tabbuilder.is_dialog then
864 menu.update_gametype(true)
868 if tabbuilder.current_tab == "singleplayer" then
869 menu.update_gametype()
872 tabbuilder.old_tab = tabbuilder.current_tab
875 --------------------------------------------------------------------------------
876 function tabbuilder.tab_multiplayer()
879 "vertlabel[0,-0.25;".. fgettext("CLIENT") .. "]" ..
880 "label[1,-0.25;".. fgettext("Favorites:") .. "]"..
881 "label[1,4.25;".. fgettext("Address/Port") .. "]"..
882 "label[9,2.75;".. fgettext("Name/Password") .. "]" ..
883 "field[1.25,5.25;5.5,0.5;te_address;;" ..engine.setting_get("address") .."]" ..
884 "field[6.75,5.25;2.25,0.5;te_port;;" ..engine.setting_get("remote_port") .."]" ..
885 "checkbox[1,3.6;cb_public_serverlist;".. fgettext("Public Serverlist") .. ";" ..
886 dump(engine.setting_getbool("public_serverlist")) .. "]"
888 if not engine.setting_getbool("public_serverlist") then
890 "button[6.45,3.95;2.25,0.5;btn_delete_favorite;".. fgettext("Delete") .. "]"
894 "button[9,4.95;2.5,0.5;btn_mp_connect;".. fgettext("Connect") .. "]" ..
895 "field[9.3,3.75;2.5,0.5;te_name;;" ..engine.setting_get("name") .."]" ..
896 "pwdfield[9.3,4.5;2.5,0.5;te_pwd;]" ..
897 "textarea[9.3,0.25;2.5,2.75;;"
898 if menu.fav_selected ~= nil and
899 menu.favorites[menu.fav_selected].description ~= nil then
901 engine.formspec_escape(menu.favorites[menu.fav_selected].description,true)
906 "textlist[1,0.35;7.5,3.35;favourites;"
908 local render_details = engine.setting_getbool("public_serverlist")
910 if #menu.favorites > 0 then
911 retval = retval .. menu.render_favorite(menu.favorites[1],render_details)
913 for i=2,#menu.favorites,1 do
914 retval = retval .. "," .. menu.render_favorite(menu.favorites[i],render_details)
918 if menu.fav_selected ~= nil then
919 retval = retval .. ";" .. menu.fav_selected .. "]"
921 retval = retval .. ";0]"
927 --------------------------------------------------------------------------------
928 function tabbuilder.tab_server()
930 local index = filterlist.get_current_index(worldlist,
931 tonumber(engine.setting_get("mainmenu_last_selected_world"))
935 "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" ..
936 "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" ..
937 "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" ..
938 "button[8.5,4.9;3.25,0.5;start_server;".. fgettext("Start Game") .. "]" ..
939 "label[4,-0.25;".. fgettext("Select World:") .. "]"..
940 "vertlabel[0,-0.25;".. fgettext("START SERVER") .. "]" ..
941 "checkbox[0.5,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" ..
942 dump(engine.setting_getbool("creative_mode")) .. "]"..
943 "checkbox[0.5,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" ..
944 dump(engine.setting_getbool("enable_damage")) .. "]"..
945 "checkbox[0.5,1.15;cb_server_announce;".. fgettext("Public") .. ";" ..
946 dump(engine.setting_getbool("server_announce")) .. "]"..
947 "field[0.8,3.2;3.5,0.5;te_playername;".. fgettext("Name") .. ";" ..
948 engine.setting_get("name") .. "]" ..
949 "pwdfield[0.8,4.2;3.5,0.5;te_passwd;".. fgettext("Password") .. "]"
951 local bind_addr = engine.setting_get("bind_address")
952 if bind_addr ~= nil and bind_addr ~= "" then
954 "field[0.8,5.2;2.25,0.5;te_serveraddr;".. fgettext("Bind Address") .. ";" ..
955 engine.setting_get("bind_address") .."]" ..
956 "field[3.05,5.2;1.25,0.5;te_serverport;".. fgettext("Port") .. ";" ..
957 engine.setting_get("port") .."]"
960 "field[0.8,5.2;3.5,0.5;te_serverport;".. fgettext("Server Port") .. ";" ..
961 engine.setting_get("port") .."]"
965 "textlist[4,0.25;7.5,3.7;srv_worlds;" ..
966 menu.render_world_list() ..
972 --------------------------------------------------------------------------------
973 function tabbuilder.tab_settings()
975 "vertlabel[0,0;" .. fgettext("SETTINGS") .. "]" ..
976 "checkbox[1,0;cb_fancy_trees;".. fgettext("Fancy Trees") .. ";"
977 .. dump(engine.setting_getbool("new_style_leaves")) .. "]"..
978 "checkbox[1,0.5;cb_smooth_lighting;".. fgettext("Smooth Lighting")
979 .. ";".. dump(engine.setting_getbool("smooth_lighting")) .. "]"..
980 "checkbox[1,1;cb_3d_clouds;".. fgettext("3D Clouds") .. ";"
981 .. dump(engine.setting_getbool("enable_3d_clouds")) .. "]"..
982 "checkbox[1,1.5;cb_opaque_water;".. fgettext("Opaque Water") .. ";"
983 .. dump(engine.setting_getbool("opaque_water")) .. "]"..
984 "checkbox[1,2.0;cb_pre_ivis;".. fgettext("Preload item visuals") .. ";"
985 .. dump(engine.setting_getbool("preload_item_visuals")) .. "]"..
986 "checkbox[1,2.5;cb_particles;".. fgettext("Enable Particles") .. ";"
987 .. dump(engine.setting_getbool("enable_particles")) .. "]"..
988 "checkbox[4.5,0;cb_mipmapping;".. fgettext("Mip-Mapping") .. ";"
989 .. dump(engine.setting_getbool("mip_map")) .. "]"..
990 "checkbox[4.5,0.5;cb_anisotrophic;".. fgettext("Anisotropic Filtering") .. ";"
991 .. dump(engine.setting_getbool("anisotropic_filter")) .. "]"..
992 "checkbox[4.5,1.0;cb_bilinear;".. fgettext("Bi-Linear Filtering") .. ";"
993 .. dump(engine.setting_getbool("bilinear_filter")) .. "]"..
994 "checkbox[4.5,1.5;cb_trilinear;".. fgettext("Tri-Linear Filtering") .. ";"
995 .. dump(engine.setting_getbool("trilinear_filter")) .. "]"..
997 "checkbox[8,0;cb_shaders;".. fgettext("Shaders") .. ";"
998 .. dump(engine.setting_getbool("enable_shaders")) .. "]"..
999 "button[1,4.5;2.25,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"
1001 if engine.setting_getbool("enable_shaders") then
1002 tab_string = tab_string ..
1003 "checkbox[8,0.5;cb_bumpmapping;".. fgettext("Bumpmapping") .. ";"
1004 .. dump(engine.setting_getbool("enable_bumpmapping")) .. "]"..
1005 "checkbox[8,1.0;cb_parallax;".. fgettext("Parallax Occlusion") .. ";"
1006 .. dump(engine.setting_getbool("enable_parallax_occlusion")) .. "]"..
1007 "checkbox[8,1.5;cb_generate_normalmaps;".. fgettext("Generate Normalmaps") .. ";"
1008 .. dump(engine.setting_getbool("generate_normalmaps")) .. "]"..
1009 "checkbox[8,2.0;cb_waving_water;".. fgettext("Waving Water") .. ";"
1010 .. dump(engine.setting_getbool("enable_waving_water")) .. "]"..
1011 "checkbox[8,2.5;cb_waving_leaves;".. fgettext("Waving Leaves") .. ";"
1012 .. dump(engine.setting_getbool("enable_waving_leaves")) .. "]"..
1013 "checkbox[8,3.0;cb_waving_plants;".. fgettext("Waving Plants") .. ";"
1014 .. dump(engine.setting_getbool("enable_waving_plants")) .. "]"
1016 tab_string = tab_string ..
1017 "textlist[8.33,0.7;4,1;;#888888" .. fgettext("Bumpmapping") .. ";0;true]" ..
1018 "textlist[8.33,1.2;4,1;;#888888" .. fgettext("Parallax Occlusion") .. ";0;true]" ..
1019 "textlist[8.33,1.7;4,1;;#888888" .. fgettext("Generate Normalmaps") .. ";0;true]" ..
1020 "textlist[8.33,2.2;4,1;;#888888" .. fgettext("Waving Water") .. ";0;true]" ..
1021 "textlist[8.33,2.7;4,1;;#888888" .. fgettext("Waving Leaves") .. ";0;true]" ..
1022 "textlist[8.33,3.2;4,1;;#888888" .. fgettext("Waving Plants") .. ";0;true]"
1027 --------------------------------------------------------------------------------
1028 function tabbuilder.tab_singleplayer()
1030 local index = filterlist.get_current_index(worldlist,
1031 tonumber(engine.setting_get("mainmenu_last_selected_world"))
1034 return "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" ..
1035 "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" ..
1036 "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" ..
1037 "button[8.5,4.95;3.25,0.5;play;".. fgettext("Play") .. "]" ..
1038 "label[4,-0.25;".. fgettext("Select World:") .. "]"..
1039 "vertlabel[0,-0.25;".. fgettext("SINGLE PLAYER") .. "]" ..
1040 "checkbox[0.5,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" ..
1041 dump(engine.setting_getbool("creative_mode")) .. "]"..
1042 "checkbox[0.5,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" ..
1043 dump(engine.setting_getbool("enable_damage")) .. "]"..
1044 "textlist[4,0.25;7.5,3.7;sp_worlds;" ..
1045 menu.render_world_list() ..
1046 ";" .. index .. "]" ..
1050 --------------------------------------------------------------------------------
1051 function tabbuilder.tab_texture_packs()
1052 local retval = "label[4,-0.25;".. fgettext("Select texture pack:") .. "]"..
1053 "vertlabel[0,-0.25;".. fgettext("TEXTURE PACKS") .. "]" ..
1054 "textlist[4,0.25;7.5,5.0;TPs;"
1056 local current_texture_path = engine.setting_get("texture_path")
1057 local list = filter_texture_pack_list(engine.get_dirlist(engine.get_texturepath(), true))
1058 local index = tonumber(engine.setting_get("mainmenu_last_selected_TP"))
1060 if index == nil then index = 1 end
1062 if current_texture_path == "" then
1064 menu.render_texture_pack_list(list) ..
1069 local infofile = current_texture_path ..DIR_DELIM.."info.txt"
1071 local f = io.open(infofile, "r")
1073 infotext = fgettext("No information available")
1075 infotext = f:read("*all")
1079 local screenfile = current_texture_path..DIR_DELIM.."screenshot.png"
1080 local no_screenshot = nil
1081 if not file_exists(screenfile) then
1083 no_screenshot = menu.defaulttexturedir .. "no_screenshot.png"
1087 menu.render_texture_pack_list(list) ..
1088 ";" .. index .. "]" ..
1089 "image[0.65,0.25;4.0,3.7;"..engine.formspec_escape(screenfile or no_screenshot).."]"..
1090 "textarea[1.0,3.25;3.7,1.5;;"..engine.formspec_escape(infotext or "")..";]"
1093 --------------------------------------------------------------------------------
1094 function tabbuilder.tab_credits()
1095 local logofile = menu.defaulttexturedir .. "logo.png"
1096 return "vertlabel[0,-0.5;CREDITS]" ..
1097 "label[0.5,3;Minetest " .. engine.get_version() .. "]" ..
1098 "label[0.5,3.3;http://minetest.net]" ..
1099 "image[0.5,1;" .. engine.formspec_escape(logofile) .. "]" ..
1100 "textlist[3.5,-0.25;8.5,5.8;list_credits;" ..
1101 "#FFFF00" .. fgettext("Core Developers") .."," ..
1102 "Perttu Ahola (celeron55) <celeron55@gmail.com>,"..
1103 "Ryan Kwolek (kwolekr) <kwolekr@minetest.net>,"..
1104 "PilzAdam <pilzadam@minetest.net>," ..
1105 "Ilya Zhuravlev (xyz) <xyz@minetest.net>,"..
1106 "Lisa Milne (darkrose) <lisa@ltmnet.com>,"..
1107 "Maciej Kasatkin (RealBadAngel) <mk@realbadangel.pl>,"..
1108 "proller <proler@gmail.com>,"..
1109 "sfan5 <sfan5@live.de>,"..
1110 "kahrl <kahrl@gmx.net>,"..
1112 "ShadowNinja <shadowninja@minetest.net>,"..
1113 "Nathanael Courant (Nore/Novatux) <nore@mesecons.net>,"..
1116 "#FFFF00" .. fgettext("Active Contributors") .. "," ..
1117 "Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>,"..
1118 "Jurgen Doser (doserj) <jurgen.doser@gmail.com>,"..
1119 "Jeija <jeija@mesecons.net>,"..
1120 "MirceaKitsune <mirceakitsune@gmail.com>,"..
1121 "dannydark <the_skeleton_of_a_child@yahoo.co.uk>,"..
1122 "0gb.us <0gb.us@0gb.us>,"..
1124 "#FFFF00" .. fgettext("Previous Contributors") .. "," ..
1125 "Guiseppe Bilotta (Oblomov) <guiseppe.bilotta@gmail.com>,"..
1126 "Jonathan Neuschafer <j.neuschaefer@gmx.net>,"..
1127 "Nils Dagsson Moskopp (erlehmann) <nils@dieweltistgarnichtso.net>,"..
1128 "Constantin Wenger (SpeedProg) <constantin.wenger@googlemail.com>,"..
1129 "matttpt <matttpt@gmail.com>,"..
1130 "JacobF <queatz@gmail.com>,"..
1134 --------------------------------------------------------------------------------
1135 function tabbuilder.init()
1136 tabbuilder.tabfuncs = {
1137 singleplayer = tabbuilder.tab_singleplayer,
1138 multiplayer = tabbuilder.tab_multiplayer,
1139 server = tabbuilder.tab_server,
1140 settings = tabbuilder.tab_settings,
1141 texture_packs = tabbuilder.tab_texture_packs,
1142 credits = tabbuilder.tab_credits,
1143 dialog_create_world = tabbuilder.dialog_create_world,
1144 dialog_delete_world = tabbuilder.dialog_delete_world
1147 tabbuilder.tabsizes = {
1148 dialog_create_world = {width=12, height=7},
1149 dialog_delete_world = {width=12, height=5.2}
1152 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1154 if tabbuilder.current_tab == nil or
1155 tabbuilder.current_tab == "" then
1156 tabbuilder.current_tab = "singleplayer"
1157 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
1160 --initialize tab buttons
1161 tabbuilder.last_tab = nil
1162 tabbuilder.show_buttons = true
1164 tabbuilder.current_buttons = {}
1165 table.insert(tabbuilder.current_buttons,{name="singleplayer", caption=fgettext("Singleplayer")})
1166 table.insert(tabbuilder.current_buttons,{name="multiplayer", caption=fgettext("Client")})
1167 table.insert(tabbuilder.current_buttons,{name="server", caption=fgettext("Server")})
1168 table.insert(tabbuilder.current_buttons,{name="settings", caption=fgettext("Settings")})
1169 table.insert(tabbuilder.current_buttons,{name="texture_packs", caption=fgettext("Texture Packs")})
1171 if engine.setting_getbool("main_menu_game_mgr") then
1172 table.insert(tabbuilder.current_buttons,{name="game_mgr", caption=fgettext("Games")})
1175 if engine.setting_getbool("main_menu_mod_mgr") then
1176 table.insert(tabbuilder.current_buttons,{name="mod_mgr", caption=fgettext("Mods")})
1178 table.insert(tabbuilder.current_buttons,{name="credits", caption=fgettext("Credits")})
1181 for i=1,#tabbuilder.current_buttons,1 do
1182 if tabbuilder.current_buttons[i].name == tabbuilder.current_tab then
1183 tabbuilder.last_tab_index = i
1187 if tabbuilder.current_tab ~= "singleplayer" then
1188 menu.update_gametype(true)
1190 menu.update_gametype()
1194 --------------------------------------------------------------------------------
1195 function tabbuilder.checkretval(retval)
1197 if retval ~= nil then
1198 if retval.current_tab ~= nil then
1199 tabbuilder.current_tab = retval.current_tab
1202 if retval.is_dialog ~= nil then
1203 tabbuilder.is_dialog = retval.is_dialog
1206 if retval.show_buttons ~= nil then
1207 tabbuilder.show_buttons = retval.show_buttons
1210 if retval.skipformupdate ~= nil then
1211 tabbuilder.skipformupdate = retval.skipformupdate
1214 if retval.ignore_menu_quit == true then
1215 tabbuilder.ignore_menu_quit = true
1217 tabbuilder.ignore_menu_quit = false
1222 --------------------------------------------------------------------------------
1223 --------------------------------------------------------------------------------
1224 -- initialize callbacks
1225 --------------------------------------------------------------------------------
1226 --------------------------------------------------------------------------------
1227 engine.button_handler = function(fields)
1228 --print("Buttonhandler: tab: " .. tabbuilder.current_tab .. " fields: " .. dump(fields))
1230 if fields["btn_error_confirm"] then
1231 gamedata.errormessage = nil
1234 local retval = modmgr.handle_buttons(tabbuilder.current_tab,fields)
1235 tabbuilder.checkretval(retval)
1237 retval = gamemgr.handle_buttons(tabbuilder.current_tab,fields)
1238 tabbuilder.checkretval(retval)
1240 retval = modstore.handle_buttons(tabbuilder.current_tab,fields)
1241 tabbuilder.checkretval(retval)
1243 if tabbuilder.current_tab == "dialog_create_world" then
1244 tabbuilder.handle_create_world_buttons(fields)
1247 if tabbuilder.current_tab == "dialog_delete_world" then
1248 tabbuilder.handle_delete_world_buttons(fields)
1251 if tabbuilder.current_tab == "singleplayer" then
1252 tabbuilder.handle_singleplayer_buttons(fields)
1255 if tabbuilder.current_tab == "texture_packs" then
1256 tabbuilder.handle_texture_pack_buttons(fields)
1259 if tabbuilder.current_tab == "multiplayer" then
1260 tabbuilder.handle_multiplayer_buttons(fields)
1263 if tabbuilder.current_tab == "settings" then
1264 tabbuilder.handle_settings_buttons(fields)
1267 if tabbuilder.current_tab == "server" then
1268 tabbuilder.handle_server_buttons(fields)
1272 tabbuilder.handle_tab_buttons(fields)
1275 menubar.handle_buttons(fields)
1277 if not tabbuilder.skipformupdate then
1281 tabbuilder.skipformupdate = false
1285 --------------------------------------------------------------------------------
1286 engine.event_handler = function(event)
1287 if event == "MenuQuit" then
1288 if tabbuilder.is_dialog then
1289 if tabbuilder.ignore_menu_quit then
1293 tabbuilder.is_dialog = false
1294 tabbuilder.show_buttons = true
1295 tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1296 menu.update_gametype()
1303 if event == "Refresh" then
1308 --------------------------------------------------------------------------------
1309 function menu.update_gametype(reset)
1310 local game = menu.lastgame()
1312 if reset or game == nil then
1314 engine.set_topleft_text("")
1315 filterlist.set_filtercriteria(worldlist,nil)
1317 mm_texture.update(tabbuilder.current_tab,game)
1318 engine.set_topleft_text(game.name)
1319 filterlist.set_filtercriteria(worldlist,game.id)
1323 --------------------------------------------------------------------------------
1324 --------------------------------------------------------------------------------
1326 --------------------------------------------------------------------------------
1327 --------------------------------------------------------------------------------
1335 engine.sound_play("main_menu", true)