]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/mainmenu.lua
Shaders rework.
[dragonfireclient.git] / builtin / mainmenu.lua
1 print = engine.debug
2 math.randomseed(os.time())
3 os.setlocale("C", "numeric")
4
5 local errorfct = error
6 error = function(text)
7         print(debug.traceback(""))
8         errorfct(text)
9 end
10
11 local scriptpath = engine.get_scriptdir()
12
13 mt_color_grey  = "#AAAAAA"
14 mt_color_blue  = "#0000DD"
15 mt_color_green = "#00DD00"
16 mt_color_dark_green = "#003300"
17
18 --for all other colors ask sfan5 to complete his worK!
19
20 dofile(scriptpath .. DIR_DELIM .. "misc_helpers.lua")
21 dofile(scriptpath .. DIR_DELIM .. "filterlist.lua")
22 dofile(scriptpath .. DIR_DELIM .. "modmgr.lua")
23 dofile(scriptpath .. DIR_DELIM .. "modstore.lua")
24 dofile(scriptpath .. DIR_DELIM .. "gamemgr.lua")
25 dofile(scriptpath .. DIR_DELIM .. "mm_textures.lua")
26 dofile(scriptpath .. DIR_DELIM .. "mm_menubar.lua")
27 dofile(scriptpath .. DIR_DELIM .. "async_event.lua")
28
29 menu = {}
30 local tabbuilder = {}
31 local worldlist = nil
32
33 --------------------------------------------------------------------------------
34 local function filter_texture_pack_list(list)
35         retval = {"None"}
36         for _,i in ipairs(list) do
37                 if i~="base" then
38                         table.insert(retval, i)
39                 end
40         end
41         return retval
42 end
43
44 --------------------------------------------------------------------------------
45 function menu.render_favorite(spec,render_details)
46         local text = ""
47
48         if spec.name ~= nil then
49                 text = text .. engine.formspec_escape(spec.name:trim())
50
51 --              if spec.description ~= nil and
52 --                      engine.formspec_escape(spec.description):trim() ~= "" then
53 --                      text = text .. " (" .. engine.formspec_escape(spec.description) .. ")"
54 --              end
55         else
56                 if spec.address ~= nil then
57                         text = text .. spec.address:trim()
58
59                         if spec.port ~= nil then
60                                 text = text .. ":" .. spec.port
61                         end
62                 end
63         end
64
65         if not render_details then
66                 return text
67         end
68
69         local details = ""
70         if spec.password == true then
71                 details = details .. "*"
72         else
73                 details = details .. "_"
74         end
75
76         if spec.creative then
77                 details = details .. "C"
78         else
79                 details = details .. "_"
80         end
81
82         if spec.damage then
83                 details = details .. "D"
84         else
85                 details = details .. "_"
86         end
87
88         if spec.pvp then
89                 details = details .. "P"
90         else
91                 details = details .. "_"
92         end
93         details = details .. " "
94
95         local playercount = ""
96
97         if spec.clients ~= nil and
98                 spec.clients_max ~= nil then
99                 playercount = string.format("%03d",spec.clients) .. "/" ..
100                                                 string.format("%03d",spec.clients_max) .. " "
101         end
102
103         return playercount .. engine.formspec_escape(details) ..  text
104 end
105
106 --------------------------------------------------------------------------------
107 os.tempfolder = function()
108         local filetocheck = os.tmpname()
109         os.remove(filetocheck)
110
111         local randname = "MTTempModFolder_" .. math.random(0,10000)
112         if DIR_DELIM == "\\" then
113                 local tempfolder = os.getenv("TEMP")
114                 return tempfolder .. filetocheck
115         else
116                 local backstring = filetocheck:reverse()
117                 return filetocheck:sub(0,filetocheck:len()-backstring:find(DIR_DELIM)+1) ..randname
118         end
119
120 end
121
122 --------------------------------------------------------------------------------
123 function init_globals()
124         --init gamedata
125         gamedata.worldindex = 0
126
127         worldlist = filterlist.create(
128                                         engine.get_worlds,
129                                         compare_worlds,
130                                         function(element,uid)
131                                                 if element.name == uid then
132                                                         return true
133                                                 end
134                                                 return false
135                                         end, --unique id compare fct
136                                         function(element,gameid)
137                                                 if element.gameid == gameid then
138                                                         return true
139                                                 end
140                                                 return false
141                                         end --filter fct
142                                         )
143
144         filterlist.add_sort_mechanism(worldlist,"alphabetic",sort_worlds_alphabetic)
145         filterlist.set_sortmode(worldlist,"alphabetic")
146 end
147
148 --------------------------------------------------------------------------------
149 function update_menu()
150
151         local formspec
152
153         -- handle errors
154         if gamedata.errormessage ~= nil then
155                 formspec = "size[12,5.2]" ..
156                         "field[1,2;10,2;;ERROR: " ..
157                         gamedata.errormessage ..
158                         ";]"..
159                         "button[4.5,4.2;3,0.5;btn_error_confirm;" .. fgettext("Ok") .. "]"
160         else
161                 formspec = tabbuilder.gettab()
162         end
163
164         engine.update_formspec(formspec)
165 end
166
167 --------------------------------------------------------------------------------
168 function menu.render_world_list()
169         local retval = ""
170
171         local current_worldlist = filterlist.get_list(worldlist)
172
173         for i,v in ipairs(current_worldlist) do
174                 if retval ~= "" then
175                         retval = retval ..","
176                 end
177
178                 retval = retval .. engine.formspec_escape(v.name) ..
179                                         " \\[" .. engine.formspec_escape(v.gameid) .. "\\]"
180         end
181
182         return retval
183 end
184
185 --------------------------------------------------------------------------------
186 function menu.render_texture_pack_list(list)
187         local retval = ""
188
189         for i,v in ipairs(list) do
190                 if retval ~= "" then
191                         retval = retval ..","
192                 end
193
194                 retval = retval .. v
195         end
196
197         return retval
198 end
199
200 --------------------------------------------------------------------------------
201 function menu.asyncOnlineFavourites()
202         menu.favorites = {}
203         engine.handle_async(
204                 function(param)
205                         return engine.get_favorites("online")
206                 end,
207                 nil,
208                 function(result)
209                         menu.favorites = result
210                         engine.event_handler("Refresh")
211                 end
212                 )
213 end
214
215 --------------------------------------------------------------------------------
216 function menu.init()
217         --init menu data
218         gamemgr.update_gamelist()
219
220         menu.last_game  = tonumber(engine.setting_get("main_menu_last_game_idx"))
221
222         if type(menu.last_game) ~= "number" then
223                 menu.last_game = 1
224         end
225
226         if engine.setting_getbool("public_serverlist") then
227                 menu.asyncOnlineFavourites()
228         else
229                 menu.favorites = engine.get_favorites("local")
230         end
231
232         menu.defaulttexturedir = engine.get_texturepath() .. DIR_DELIM .. "base" ..
233                                         DIR_DELIM .. "pack" .. DIR_DELIM
234 end
235
236 --------------------------------------------------------------------------------
237 function menu.lastgame()
238         if menu.last_game > 0 and menu.last_game <= #gamemgr.games then
239                 return gamemgr.games[menu.last_game]
240         end
241
242         if #gamemgr.games >= 1 then
243                 menu.last_game = 1
244                 return gamemgr.games[menu.last_game]
245         end
246
247         --error case!!
248         return nil
249 end
250
251 --------------------------------------------------------------------------------
252 function menu.update_last_game()
253
254         local current_world = filterlist.get_raw_element(worldlist,
255                                                         engine.setting_get("mainmenu_last_selected_world")
256                                                         )
257
258         if current_world == nil then
259                 return
260         end
261
262         local gamespec, i = gamemgr.find_by_gameid(current_world.gameid)
263         if i ~= nil then
264                 menu.last_game = i
265                 engine.setting_set("main_menu_last_game_idx",menu.last_game)
266         end
267 end
268
269 --------------------------------------------------------------------------------
270 function menu.handle_key_up_down(fields,textlist,settingname)
271
272         if fields["key_up"] then
273                 local oldidx = engine.get_textlist_index(textlist)
274
275                 if oldidx > 1 then
276                         local newidx = oldidx -1
277                         engine.setting_set(settingname,
278                                 filterlist.get_raw_index(worldlist,newidx))
279                 end
280         end
281
282         if fields["key_down"] then
283                 local oldidx = engine.get_textlist_index(textlist)
284
285                 if oldidx < filterlist.size(worldlist) then
286                         local newidx = oldidx + 1
287                         engine.setting_set(settingname,
288                                 filterlist.get_raw_index(worldlist,newidx))
289                 end
290         end
291 end
292
293 --------------------------------------------------------------------------------
294 function tabbuilder.dialog_create_world()
295         local mapgens = {"v6", "v7", "indev", "singlenode", "math"}
296
297         local current_seed = engine.setting_get("fixed_map_seed") or ""
298         local current_mg   = engine.setting_get("mg_name")
299
300         local mglist = ""
301         local selindex = 1
302         local i = 1
303         for k,v in pairs(mapgens) do
304                 if current_mg == v then
305                         selindex = i
306                 end
307                 i = i + 1
308                 mglist = mglist .. v .. ","
309         end
310         mglist = mglist:sub(1, -2)
311
312         local retval =
313                 "label[2,0;" .. fgettext("World name") .. "]"..
314                 "field[4.5,0.4;6,0.5;te_world_name;;]" ..
315
316                 "label[2,1;" .. fgettext("Seed") .. "]"..
317                 "field[4.5,1.4;6,0.5;te_seed;;".. current_seed .. "]" ..
318
319                 "label[2,2;" .. fgettext("Mapgen") .. "]"..
320                 "dropdown[4.2,2;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
321
322                 "label[2,3;" .. fgettext("Game") .. "]"..
323                 "textlist[4.2,3;5.8,2.3;games;" .. gamemgr.gamelist() ..
324                 ";" .. menu.last_game .. ";true]" ..
325
326                 "button[5,5.5;2.6,0.5;world_create_confirm;" .. fgettext("Create") .. "]" ..
327                 "button[7.5,5.5;2.8,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
328
329         return retval
330 end
331
332 --------------------------------------------------------------------------------
333 function tabbuilder.dialog_delete_world()
334         return  "label[2,2;" ..
335                         fgettext("Delete World \"$1\"?", filterlist.get_raw_list(worldlist)[menu.world_to_del].name) .. "]"..
336                         "button[3.5,4.2;2.6,0.5;world_delete_confirm;" .. fgettext("Yes").. "]" ..
337                         "button[6,4.2;2.8,0.5;world_delete_cancel;" .. fgettext("No") .. "]"
338 end
339
340 --------------------------------------------------------------------------------
341
342 function tabbuilder.gettab()
343         local tsize = tabbuilder.tabsizes[tabbuilder.current_tab] or {width=12, height=5.2}
344         local retval = "size[" .. tsize.width .. "," .. tsize.height .. "]"
345
346         if tabbuilder.show_buttons then
347                 retval = retval .. tabbuilder.tab_header()
348         end
349
350         local buildfunc = tabbuilder.tabfuncs[tabbuilder.current_tab]
351         if buildfunc ~= nil then
352                 retval = retval .. buildfunc()
353         end
354
355         retval = retval .. modmgr.gettab(tabbuilder.current_tab)
356         retval = retval .. gamemgr.gettab(tabbuilder.current_tab)
357         retval = retval .. modstore.gettab(tabbuilder.current_tab)
358
359         return retval
360 end
361
362 --------------------------------------------------------------------------------
363 function tabbuilder.handle_create_world_buttons(fields)
364
365         if fields["world_create_confirm"] or
366                 fields["key_enter"] then
367
368                 local worldname = fields["te_world_name"]
369                 local gameindex = engine.get_textlist_index("games")
370
371                 if gameindex > 0 and
372                         worldname ~= "" then
373
374                         local message = nil
375
376                         if not filterlist.uid_exists_raw(worldlist,worldname) then
377                                 engine.setting_set("mg_name",fields["dd_mapgen"])
378                                 message = engine.create_world(worldname,gameindex)
379                         else
380                                 message = fgettext("A world named \"$1\" already exists", worldname)
381                         end
382
383                         engine.setting_set("fixed_map_seed", fields["te_seed"])
384
385                         if message ~= nil then
386                                 gamedata.errormessage = message
387                         else
388                                 menu.last_game = gameindex
389                                 engine.setting_set("main_menu_last_game_idx",gameindex)
390
391                                 filterlist.refresh(worldlist)
392                                 engine.setting_set("mainmenu_last_selected_world",
393                                                                         filterlist.raw_index_by_uid(worldlist,worldname))
394                         end
395                 else
396                         gamedata.errormessage =
397                                 fgettext("No worldname given or no game selected")
398                 end
399         end
400
401         if fields["games"] then
402                 tabbuilder.skipformupdate = true
403                 return
404         end
405
406         --close dialog
407         tabbuilder.is_dialog = false
408         tabbuilder.show_buttons = true
409         tabbuilder.current_tab = engine.setting_get("main_menu_tab")
410 end
411
412 --------------------------------------------------------------------------------
413 function tabbuilder.handle_delete_world_buttons(fields)
414
415         if fields["world_delete_confirm"] then
416                 if menu.world_to_del > 0 and
417                         menu.world_to_del <= #filterlist.get_raw_list(worldlist) then
418                         engine.delete_world(menu.world_to_del)
419                         menu.world_to_del = 0
420                         filterlist.refresh(worldlist)
421                 end
422         end
423
424         tabbuilder.is_dialog = false
425         tabbuilder.show_buttons = true
426         tabbuilder.current_tab = engine.setting_get("main_menu_tab")
427 end
428
429 --------------------------------------------------------------------------------
430 function tabbuilder.handle_multiplayer_buttons(fields)
431
432         if fields["te_name"] ~= nil then
433                 gamedata.playername = fields["te_name"]
434                 engine.setting_set("name", fields["te_name"])
435         end
436
437         if fields["favourites"] ~= nil then
438                 local event = explode_textlist_event(fields["favourites"])
439                 if event.typ == "DCL" then
440                         if event.index <= #menu.favorites then
441                                 gamedata.address = menu.favorites[event.index].address
442                                 gamedata.port = menu.favorites[event.index].port
443                                 gamedata.playername             = fields["te_name"]
444                                 if fields["te_pwd"] ~= nil then
445                                         gamedata.password               = fields["te_pwd"]
446                                 end
447                                 gamedata.selected_world = 0
448
449                                 if menu.favorites ~= nil then
450                                         gamedata.servername = menu.favorites[event.index].name
451                                         gamedata.serverdescription = menu.favorites[event.index].description
452                                 end
453
454                                 if gamedata.address ~= nil and
455                                         gamedata.port ~= nil then
456                                         engine.setting_set("address",gamedata.address)
457                                         engine.setting_set("remote_port",gamedata.port)
458                                         engine.start()
459                                 end
460                         end
461                 end
462
463                 if event.typ == "CHG" then
464                         if event.index <= #menu.favorites then
465                                 local address = menu.favorites[event.index].address
466                                 local port = menu.favorites[event.index].port
467
468                                 if address ~= nil and
469                                         port ~= nil then
470                                         engine.setting_set("address",address)
471                                         engine.setting_set("remote_port",port)
472                                 end
473
474                                 menu.fav_selected = event.index
475                         end
476                 end
477                 return
478         end
479
480         if fields["key_up"] ~= nil or
481                 fields["key_down"] ~= nil then
482
483                 local fav_idx = engine.get_textlist_index("favourites")
484
485                 if fields["key_up"] ~= nil and fav_idx > 1 then
486                         fav_idx = fav_idx -1
487                 else if fields["key_down"] and fav_idx < #menu.favorites then
488                         fav_idx = fav_idx +1
489                 end end
490
491                 local address = menu.favorites[fav_idx].address
492                 local port = menu.favorites[fav_idx].port
493
494                 if address ~= nil and
495                         port ~= nil then
496                         engine.setting_set("address",address)
497                         engine.setting_set("remote_port",port)
498                 end
499
500                 menu.fav_selected = fav_idx
501                 return
502         end
503
504         if fields["cb_public_serverlist"] ~= nil then
505                 engine.setting_set("public_serverlist", fields["cb_public_serverlist"])
506
507                 if engine.setting_getbool("public_serverlist") then
508                         menu.asyncOnlineFavourites()
509                 else
510                         menu.favorites = engine.get_favorites("local")
511                 end
512                 menu.fav_selected = nil
513                 return
514         end
515
516         if fields["btn_delete_favorite"] ~= nil then
517                 local current_favourite = engine.get_textlist_index("favourites")
518                 engine.delete_favorite(current_favourite)
519                 menu.favorites = engine.get_favorites()
520                 menu.fav_selected = nil
521
522                 engine.setting_set("address","")
523                 engine.setting_set("remote_port","30000")
524
525                 return
526         end
527
528         if fields["btn_mp_connect"] ~= nil or
529                 fields["key_enter"] ~= nil then
530
531                 gamedata.playername             = fields["te_name"]
532                 gamedata.password               = fields["te_pwd"]
533                 gamedata.address                = fields["te_address"]
534                 gamedata.port                   = fields["te_port"]
535
536                 local fav_idx = engine.get_textlist_index("favourites")
537
538                 if fav_idx > 0 and fav_idx <= #menu.favorites and
539                         menu.favorites[fav_idx].address == fields["te_address"] and
540                         menu.favorites[fav_idx].port    == fields["te_port"] then
541
542                         gamedata.servername                     = menu.favorites[fav_idx].name
543                         gamedata.serverdescription      = menu.favorites[fav_idx].description
544                 else
545                         gamedata.servername                     = ""
546                         gamedata.serverdescription      = ""
547                 end
548
549                 gamedata.selected_world = 0
550
551                 engine.setting_set("address",fields["te_address"])
552                 engine.setting_set("remote_port",fields["te_port"])
553
554                 engine.start()
555                 return
556         end
557 end
558
559 --------------------------------------------------------------------------------
560 function tabbuilder.handle_server_buttons(fields)
561
562         local world_doubleclick = false
563
564         if fields["srv_worlds"] ~= nil then
565                 local event = explode_textlist_event(fields["srv_worlds"])
566
567                 if event.typ == "DCL" then
568                         world_doubleclick = true
569                 end
570                 if event.typ == "CHG" then
571                         engine.setting_set("mainmenu_last_selected_world",
572                                 filterlist.get_raw_index(worldlist,engine.get_textlist_index("srv_worlds")))
573                 end
574         end
575
576         menu.handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world")
577
578         if fields["cb_creative_mode"] then
579                 engine.setting_set("creative_mode", fields["cb_creative_mode"])
580         end
581
582         if fields["cb_enable_damage"] then
583                 engine.setting_set("enable_damage", fields["cb_enable_damage"])
584         end
585
586         if fields["cb_server_announce"] then
587                 engine.setting_set("server_announce", fields["cb_server_announce"])
588         end
589
590         if fields["start_server"] ~= nil or
591                 world_doubleclick or
592                 fields["key_enter"] then
593                 local selected = engine.get_textlist_index("srv_worlds")
594                 if selected > 0 then
595                         gamedata.playername             = fields["te_playername"]
596                         gamedata.password               = fields["te_passwd"]
597                         gamedata.port                   = fields["te_serverport"]
598                         gamedata.address                = ""
599                         gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
600
601                         engine.setting_set("port",gamedata.port)
602
603                         menu.update_last_game(gamedata.selected_world)
604                         engine.start()
605                 end
606         end
607
608         if fields["world_create"] ~= nil then
609                 tabbuilder.current_tab = "dialog_create_world"
610                 tabbuilder.is_dialog = true
611                 tabbuilder.show_buttons = false
612         end
613
614         if fields["world_delete"] ~= nil then
615                 local selected = engine.get_textlist_index("srv_worlds")
616                 if selected > 0 and
617                         selected <= filterlist.size(worldlist) then
618                         local world = filterlist.get_list(worldlist)[selected]
619                         if world ~= nil and
620                                 world.name ~= nil and
621                                 world.name ~= "" then
622                                 menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
623                                 tabbuilder.current_tab = "dialog_delete_world"
624                                 tabbuilder.is_dialog = true
625                                 tabbuilder.show_buttons = false
626                         else
627                                 menu.world_to_del = 0
628                         end
629                 end
630         end
631
632         if fields["world_configure"] ~= nil then
633                 selected = engine.get_textlist_index("srv_worlds")
634                 if selected > 0 then
635                         modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
636                         if modmgr.init_worldconfig() then
637                                 tabbuilder.current_tab = "dialog_configure_world"
638                                 tabbuilder.is_dialog = true
639                                 tabbuilder.show_buttons = false
640                         end
641                 end
642         end
643 end
644
645 --------------------------------------------------------------------------------
646 function tabbuilder.handle_settings_buttons(fields)
647         if fields["cb_fancy_trees"] then
648                 engine.setting_set("new_style_leaves", fields["cb_fancy_trees"])
649         end
650         if fields["cb_smooth_lighting"] then
651                 engine.setting_set("smooth_lighting", fields["cb_smooth_lighting"])
652         end
653         if fields["cb_3d_clouds"] then
654                 engine.setting_set("enable_3d_clouds", fields["cb_3d_clouds"])
655         end
656         if fields["cb_opaque_water"] then
657                 engine.setting_set("opaque_water", fields["cb_opaque_water"])
658         end
659
660         if fields["cb_mipmapping"] then
661                 engine.setting_set("mip_map", fields["cb_mipmapping"])
662         end
663         if fields["cb_anisotrophic"] then
664                 engine.setting_set("anisotropic_filter", fields["cb_anisotrophic"])
665         end
666         if fields["cb_bilinear"] then
667                 engine.setting_set("bilinear_filter", fields["cb_bilinear"])
668         end
669         if fields["cb_trilinear"] then
670                 engine.setting_set("trilinear_filter", fields["cb_trilinear"])
671         end
672
673         if fields["cb_shaders"] then
674                 if (engine.setting_get("video_driver") == "direct3d8" or engine.setting_get("video_driver") == "direct3d9") then
675                         engine.setting_set("enable_shaders", "false")
676                         gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
677                 else
678                         engine.setting_set("enable_shaders", fields["cb_shaders"])
679                 end
680         end
681         if fields["cb_pre_ivis"] then
682                 engine.setting_set("preload_item_visuals", fields["cb_pre_ivis"])
683         end
684         if fields["cb_particles"] then
685                 engine.setting_set("enable_particles", fields["cb_particles"])
686         end
687         if fields["cb_finite_liquid"] then
688                 engine.setting_set("liquid_finite", fields["cb_finite_liquid"])
689         end
690         if fields["cb_bumpmapping"] then
691                 engine.setting_set("enable_bumpmapping", fields["cb_bumpmapping"])
692         end
693         if fields["cb_parallax"] then
694                 engine.setting_set("enable_parallax_occlusion", fields["cb_parallax"])
695         end
696         if fields["cb_waving_water"] then
697                 engine.setting_set("enable_waving_water", fields["cb_waving_water"])
698         end
699         if fields["cb_waving_leaves"] then
700                 engine.setting_set("enable_waving_leaves", fields["cb_waving_leaves"])
701         end
702         if fields["cb_waving_plants"] then
703                 engine.setting_set("enable_waving_plants", fields["cb_waving_plants"])
704         end
705         if fields["btn_change_keys"] ~= nil then
706                 engine.show_keys_menu()
707         end
708 end
709
710 --------------------------------------------------------------------------------
711 function tabbuilder.handle_singleplayer_buttons(fields)
712
713         local world_doubleclick = false
714
715         if fields["sp_worlds"] ~= nil then
716                 local event = explode_textlist_event(fields["sp_worlds"])
717
718                 if event.typ == "DCL" then
719                         world_doubleclick = true
720                 end
721
722                 if event.typ == "CHG" then
723                         engine.setting_set("mainmenu_last_selected_world",
724                                 filterlist.get_raw_index(worldlist,engine.get_textlist_index("sp_worlds")))
725                 end
726         end
727
728         menu.handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world")
729
730         if fields["cb_creative_mode"] then
731                 engine.setting_set("creative_mode", fields["cb_creative_mode"])
732         end
733
734         if fields["cb_enable_damage"] then
735                 engine.setting_set("enable_damage", fields["cb_enable_damage"])
736         end
737
738         if fields["play"] ~= nil or
739                 world_doubleclick or
740                 fields["key_enter"] then
741                 local selected = engine.get_textlist_index("sp_worlds")
742                 if selected > 0 then
743                         gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
744                         gamedata.singleplayer   = true
745
746                         menu.update_last_game(gamedata.selected_world)
747
748                         engine.start()
749                 end
750         end
751
752         if fields["world_create"] ~= nil then
753                 tabbuilder.current_tab = "dialog_create_world"
754                 tabbuilder.is_dialog = true
755                 tabbuilder.show_buttons = false
756         end
757
758         if fields["world_delete"] ~= nil then
759                 local selected = engine.get_textlist_index("sp_worlds")
760                 if selected > 0 and
761                         selected <= filterlist.size(worldlist) then
762                         local world = filterlist.get_list(worldlist)[selected]
763                         if world ~= nil and
764                                 world.name ~= nil and
765                                 world.name ~= "" then
766                                 menu.world_to_del = filterlist.get_raw_index(worldlist,selected)
767                                 tabbuilder.current_tab = "dialog_delete_world"
768                                 tabbuilder.is_dialog = true
769                                 tabbuilder.show_buttons = false
770                         else
771                                 menu.world_to_del = 0
772                         end
773                 end
774         end
775
776         if fields["world_configure"] ~= nil then
777                 selected = engine.get_textlist_index("sp_worlds")
778                 if selected > 0 then
779                         modmgr.world_config_selected_world = filterlist.get_raw_index(worldlist,selected)
780                         if modmgr.init_worldconfig() then
781                                 tabbuilder.current_tab = "dialog_configure_world"
782                                 tabbuilder.is_dialog = true
783                                 tabbuilder.show_buttons = false
784                         end
785                 end
786         end
787 end
788
789 --------------------------------------------------------------------------------
790 function tabbuilder.handle_texture_pack_buttons(fields)
791         if fields["TPs"] ~= nil then
792                 local event = explode_textlist_event(fields["TPs"])
793                 if event.typ == "CHG" or event.typ=="DCL" then
794                         local index = engine.get_textlist_index("TPs")
795                         engine.setting_set("mainmenu_last_selected_TP",
796                                 index)
797                         local list = filter_texture_pack_list(engine.get_dirlist(engine.get_texturepath(), true))
798                         local current_index = engine.get_textlist_index("TPs")
799                         if #list >= current_index then
800                                 local new_path = engine.get_texturepath()..DIR_DELIM..list[current_index]
801                                 if list[current_index] == "None" then new_path = "" end
802
803                                 engine.setting_set("texture_path", new_path)
804                         end
805                 end
806         end
807 end
808
809 --------------------------------------------------------------------------------
810 function tabbuilder.tab_header()
811
812         if tabbuilder.last_tab_index == nil then
813                 tabbuilder.last_tab_index = 1
814         end
815
816         local toadd = ""
817
818         for i=1,#tabbuilder.current_buttons,1 do
819
820                 if toadd ~= "" then
821                         toadd = toadd .. ","
822                 end
823
824                 toadd = toadd .. tabbuilder.current_buttons[i].caption
825         end
826         return "tabheader[-0.3,-0.99;main_tab;" .. toadd ..";" .. tabbuilder.last_tab_index .. ";true;false]"
827 end
828
829 --------------------------------------------------------------------------------
830 function tabbuilder.handle_tab_buttons(fields)
831
832         if fields["main_tab"] then
833                 local index = tonumber(fields["main_tab"])
834                 tabbuilder.last_tab_index = index
835                 tabbuilder.current_tab = tabbuilder.current_buttons[index].name
836
837                 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
838         end
839
840         --handle tab changes
841         if tabbuilder.current_tab ~= tabbuilder.old_tab then
842                 if tabbuilder.current_tab ~= "singleplayer" and not tabbuilder.is_dialog then
843                         menu.update_gametype(true)
844                 end
845         end
846
847         if tabbuilder.current_tab == "singleplayer" then
848                 menu.update_gametype()
849         end
850
851         tabbuilder.old_tab = tabbuilder.current_tab
852 end
853
854 --------------------------------------------------------------------------------
855 function tabbuilder.tab_multiplayer()
856
857         local retval =
858                 "vertlabel[0,-0.25;".. fgettext("CLIENT") .. "]" ..
859                 "label[1,-0.25;".. fgettext("Favorites:") .. "]"..
860                 "label[1,4.25;".. fgettext("Address/Port") .. "]"..
861                 "label[9,2.75;".. fgettext("Name/Password") .. "]" ..
862                 "field[1.25,5.25;5.5,0.5;te_address;;" ..engine.setting_get("address") .."]" ..
863                 "field[6.75,5.25;2.25,0.5;te_port;;" ..engine.setting_get("remote_port") .."]" ..
864                 "checkbox[1,3.6;cb_public_serverlist;".. fgettext("Public Serverlist") .. ";" ..
865                 dump(engine.setting_getbool("public_serverlist")) .. "]"
866
867         if not engine.setting_getbool("public_serverlist") then
868                 retval = retval ..
869                 "button[6.45,3.95;2.25,0.5;btn_delete_favorite;".. fgettext("Delete") .. "]"
870         end
871
872         retval = retval ..
873                 "button[9,4.95;2.5,0.5;btn_mp_connect;".. fgettext("Connect") .. "]" ..
874                 "field[9.3,3.75;2.5,0.5;te_name;;" ..engine.setting_get("name") .."]" ..
875                 "pwdfield[9.3,4.5;2.5,0.5;te_pwd;]" ..
876                 "textarea[9.3,0.25;2.5,2.75;;"
877         if menu.fav_selected ~= nil and
878                 menu.favorites[menu.fav_selected].description ~= nil then
879                 retval = retval ..
880                         engine.formspec_escape(menu.favorites[menu.fav_selected].description,true)
881         end
882
883         retval = retval ..
884                 ";]" ..
885                 "textlist[1,0.35;7.5,3.35;favourites;"
886
887         local render_details = engine.setting_getbool("public_serverlist")
888
889         if #menu.favorites > 0 then
890                 retval = retval .. menu.render_favorite(menu.favorites[1],render_details)
891
892                 for i=2,#menu.favorites,1 do
893                         retval = retval .. "," .. menu.render_favorite(menu.favorites[i],render_details)
894                 end
895         end
896
897         if menu.fav_selected ~= nil then
898                 retval = retval .. ";" .. menu.fav_selected .. "]"
899         else
900                 retval = retval .. ";0]"
901         end
902
903         return retval
904 end
905
906 --------------------------------------------------------------------------------
907 function tabbuilder.tab_server()
908
909         local index = filterlist.get_current_index(worldlist,
910                                 tonumber(engine.setting_get("mainmenu_last_selected_world"))
911                                 )
912
913         local retval =
914                 "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" ..
915                 "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" ..
916                 "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" ..
917                 "button[8.5,4.9;3.25,0.5;start_server;".. fgettext("Start Game") .. "]" ..
918                 "label[4,-0.25;".. fgettext("Select World:") .. "]"..
919                 "vertlabel[0,-0.25;".. fgettext("START SERVER") .. "]" ..
920                 "checkbox[0.5,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" ..
921                 dump(engine.setting_getbool("creative_mode")) .. "]"..
922                 "checkbox[0.5,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" ..
923                 dump(engine.setting_getbool("enable_damage")) .. "]"..
924                 "checkbox[0.5,1.15;cb_server_announce;".. fgettext("Public") .. ";" ..
925                 dump(engine.setting_getbool("server_announce")) .. "]"..
926                 "field[0.8,3.2;3,0.5;te_playername;".. fgettext("Name") .. ";" ..
927                 engine.setting_get("name") .. "]" ..
928                 "pwdfield[0.8,4.2;3,0.5;te_passwd;".. fgettext("Password") .. "]" ..
929                 "field[0.8,5.2;3,0.5;te_serverport;".. fgettext("Server Port") .. ";" ..
930                 engine.setting_get("port") .."]" ..
931                 "textlist[4,0.25;7.5,3.7;srv_worlds;" ..
932                 menu.render_world_list() ..
933                 ";" .. index .. "]"
934
935         return retval
936 end
937
938 --------------------------------------------------------------------------------
939 function tabbuilder.tab_settings()
940         tab_string =
941                         "vertlabel[0,0;" .. fgettext("SETTINGS") .. "]" ..
942                         "checkbox[1,0;cb_fancy_trees;".. fgettext("Fancy Trees") .. ";" 
943                                         .. dump(engine.setting_getbool("new_style_leaves")) .. "]"..
944                         "checkbox[1,0.5;cb_smooth_lighting;".. fgettext("Smooth Lighting") 
945                                         .. ";".. dump(engine.setting_getbool("smooth_lighting")) .. "]"..
946                         "checkbox[1,1;cb_3d_clouds;".. fgettext("3D Clouds") .. ";"
947                                         .. dump(engine.setting_getbool("enable_3d_clouds")) .. "]"..
948                         "checkbox[1,1.5;cb_opaque_water;".. fgettext("Opaque Water") .. ";"
949                                         .. dump(engine.setting_getbool("opaque_water")) .. "]"..
950                         "checkbox[1,2.0;cb_pre_ivis;".. fgettext("Preload item visuals") .. ";"
951                                         .. dump(engine.setting_getbool("preload_item_visuals")) .. "]"..
952                         "checkbox[1,2.5;cb_particles;".. fgettext("Enable Particles") .. ";"
953                                         .. dump(engine.setting_getbool("enable_particles"))     .. "]"..
954                         "checkbox[1,3.0;cb_finite_liquid;".. fgettext("Finite Liquid") .. ";"
955                                         .. dump(engine.setting_getbool("liquid_finite")) .. "]"..
956
957                         "checkbox[4.5,0;cb_mipmapping;".. fgettext("Mip-Mapping") .. ";"
958                                         .. dump(engine.setting_getbool("mip_map")) .. "]"..
959                         "checkbox[4.5,0.5;cb_anisotrophic;".. fgettext("Anisotropic Filtering") .. ";"
960                                         .. dump(engine.setting_getbool("anisotropic_filter")) .. "]"..
961                         "checkbox[4.5,1.0;cb_bilinear;".. fgettext("Bi-Linear Filtering") .. ";"
962                                         .. dump(engine.setting_getbool("bilinear_filter")) .. "]"..
963                         "checkbox[4.5,1.5;cb_trilinear;".. fgettext("Tri-Linear Filtering") .. ";"
964                                         .. dump(engine.setting_getbool("trilinear_filter")) .. "]"..
965
966                         "checkbox[8,0;cb_shaders;".. fgettext("Shaders") .. ";"
967                                         .. dump(engine.setting_getbool("enable_shaders")) .. "]"..
968                         "button[1,4.5;2.25,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"
969
970 if engine.setting_getbool("enable_shaders") then
971         tab_string = tab_string ..
972                         "checkbox[8,0.5;cb_bumpmapping;".. fgettext("Bumpmapping") .. ";"
973                                         .. dump(engine.setting_getbool("enable_bumpmapping")) .. "]"..
974                         "checkbox[8,1.0;cb_parallax;".. fgettext("Parallax Occlusion") .. ";"
975                                         .. dump(engine.setting_getbool("enable_parallax_occlusion")) .. "]"..
976                         "checkbox[8,1.5;cb_waving_water;".. fgettext("Waving Water") .. ";"
977                                         .. dump(engine.setting_getbool("enable_waving_water")) .. "]"..
978                         "checkbox[8,2.0;cb_waving_leaves;".. fgettext("Waving Leaves") .. ";"
979                                         .. dump(engine.setting_getbool("enable_waving_leaves")) .. "]"..
980                         "checkbox[8,2.5;cb_waving_plants;".. fgettext("Waving Plants") .. ";"
981                                         .. dump(engine.setting_getbool("enable_waving_plants")) .. "]"
982 else 
983         tab_string = tab_string ..
984                         "textlist[8.33,0.7;4,1;;#888888" .. fgettext("Bumpmapping") .. ";0;true]" ..
985                         "textlist[8.33,1.2;4,1;;#888888" .. fgettext("Parallax Occlusion") .. ";0;true]" ..
986                         "textlist[8.33,1.7;4,1;;#888888" .. fgettext("Waving Water") .. ";0;true]" ..
987                         "textlist[8.33,2.2;4,1;;#888888" .. fgettext("Waving Leaves") .. ";0;true]" ..
988                         "textlist[8.33,2.7;4,1;;#888888" .. fgettext("Waving Plants") .. ";0;true]"
989         end
990 return tab_string
991 end
992
993 --------------------------------------------------------------------------------
994 function tabbuilder.tab_singleplayer()
995
996         local index = filterlist.get_current_index(worldlist,
997                                 tonumber(engine.setting_get("mainmenu_last_selected_world"))
998                                 )
999
1000         return  "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" ..
1001                         "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" ..
1002                         "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" ..
1003                         "button[8.5,4.95;3.25,0.5;play;".. fgettext("Play") .. "]" ..
1004                         "label[4,-0.25;".. fgettext("Select World:") .. "]"..
1005                         "vertlabel[0,-0.25;".. fgettext("SINGLE PLAYER") .. "]" ..
1006                         "checkbox[0.5,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" ..
1007                         dump(engine.setting_getbool("creative_mode")) .. "]"..
1008                         "checkbox[0.5,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" ..
1009                         dump(engine.setting_getbool("enable_damage")) .. "]"..
1010                         "textlist[4,0.25;7.5,3.7;sp_worlds;" ..
1011                         menu.render_world_list() ..
1012                         ";" .. index .. "]" ..
1013                         menubar.formspec
1014 end
1015
1016 --------------------------------------------------------------------------------
1017 function tabbuilder.tab_texture_packs()
1018         local retval = "label[4,-0.25;".. fgettext("Select texture pack:") .. "]"..
1019                         "vertlabel[0,-0.25;".. fgettext("TEXTURE PACKS") .. "]" ..
1020                         "textlist[4,0.25;7.5,5.0;TPs;"
1021
1022         local current_texture_path = engine.setting_get("texture_path")
1023         local list = filter_texture_pack_list(engine.get_dirlist(engine.get_texturepath(), true))
1024         local index = tonumber(engine.setting_get("mainmenu_last_selected_TP"))
1025
1026         if index == nil then index = 1 end
1027
1028         if current_texture_path == "" then
1029                 retval = retval ..
1030                         menu.render_texture_pack_list(list) ..
1031                         ";" .. index .. "]"
1032                 return retval
1033         end
1034
1035         local infofile = current_texture_path ..DIR_DELIM.."info.txt"
1036         local infotext = ""
1037         local f = io.open(infofile, "r")
1038         if f==nil then
1039                 infotext = fgettext("No information available")
1040         else
1041                 infotext = f:read("*all")
1042                 f:close()
1043         end
1044
1045         local screenfile = current_texture_path..DIR_DELIM.."screenshot.png"
1046         local no_screenshot = nil
1047         if not file_exists(screenfile) then
1048                 screenfile = nil
1049                 no_screenshot = engine.get_texturepath()..DIR_DELIM..
1050                                         "base"..DIR_DELIM.."pack"..DIR_DELIM.."no_screenshot.png"
1051         end
1052
1053         return  retval ..
1054                         menu.render_texture_pack_list(list) ..
1055                         ";" .. index .. "]" ..
1056                         "image[0.65,0.25;4.0,3.7;"..engine.formspec_escape(screenfile or no_screenshot).."]"..
1057                         "textarea[1.0,3.25;3.7,1.5;;"..engine.formspec_escape(infotext or "")..";]"
1058 end
1059
1060 --------------------------------------------------------------------------------
1061 function tabbuilder.tab_credits()
1062         local logofile = menu.defaulttexturedir .. "logo.png"
1063         return  "vertlabel[0,-0.5;CREDITS]" ..
1064                         "label[0.5,3;Minetest " .. engine.get_version() .. "]" ..
1065                         "label[0.5,3.3;http://minetest.net]" ..
1066                         "image[0.5,1;" .. engine.formspec_escape(logofile) .. "]" ..
1067                         "textlist[3.5,-0.25;8.5,5.8;list_credits;" ..
1068                         "#FFFF00" .. fgettext("Core Developers") .."," ..
1069                         "Perttu Ahola (celeron55) <celeron55@gmail.com>,"..
1070                         "Ryan Kwolek (kwolekr) <kwolekr@minetest.net>,"..
1071                         "PilzAdam <pilzadam@minetest.net>," ..
1072                         "Ilya Zhuravlev (xyz) <xyz@minetest.net>,"..
1073                         "Lisa Milne (darkrose) <lisa@ltmnet.com>,"..
1074                         "Maciej Kasatkin (RealBadAngel) <mk@realbadangel.pl>,"..
1075                         "proller <proler@gmail.com>,"..
1076                         "sfan5 <sfan5@live.de>,"..
1077                         "kahrl <kahrl@gmx.net>,"..
1078                         "sapier,"..
1079                         "ShadowNinja <shadowninja@minetest.net>,"..
1080                         "Nathanael Courant (Nore/Novatux) <nore@mesecons.net>,"..
1081                         "BlockMen,"..
1082                         ","..
1083                         "#FFFF00" .. fgettext("Active Contributors") .. "," ..
1084                         "Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>,"..
1085                         "Jurgen Doser (doserj) <jurgen.doser@gmail.com>,"..
1086                         "Jeija <jeija@mesecons.net>,"..
1087                         "MirceaKitsune <mirceakitsune@gmail.com>,"..
1088                         "dannydark <the_skeleton_of_a_child@yahoo.co.uk>,"..
1089                         "0gb.us <0gb.us@0gb.us>,"..
1090                         "," ..
1091                         "#FFFF00" .. fgettext("Previous Contributors") .. "," ..
1092                         "Guiseppe Bilotta (Oblomov) <guiseppe.bilotta@gmail.com>,"..
1093                         "Jonathan Neuschafer <j.neuschaefer@gmx.net>,"..
1094                         "Nils Dagsson Moskopp (erlehmann) <nils@dieweltistgarnichtso.net>,"..
1095                         "Constantin Wenger (SpeedProg) <constantin.wenger@googlemail.com>,"..
1096                         "matttpt <matttpt@gmail.com>,"..
1097                         "JacobF <queatz@gmail.com>,"..
1098                         ";0;true]"
1099 end
1100
1101 --------------------------------------------------------------------------------
1102 function tabbuilder.init()
1103         tabbuilder.tabfuncs = {
1104                 singleplayer  = tabbuilder.tab_singleplayer,
1105                 multiplayer   = tabbuilder.tab_multiplayer,
1106                 server        = tabbuilder.tab_server,
1107                 settings      = tabbuilder.tab_settings,
1108                 texture_packs = tabbuilder.tab_texture_packs,
1109                 credits       = tabbuilder.tab_credits,
1110                 dialog_create_world = tabbuilder.dialog_create_world,
1111                 dialog_delete_world = tabbuilder.dialog_delete_world
1112         }
1113
1114         tabbuilder.tabsizes = {
1115                 dialog_create_world = {width=12, height=7},
1116                 dialog_delete_world = {width=12, height=5.2}
1117         }
1118
1119         tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1120
1121         if tabbuilder.current_tab == nil or
1122                 tabbuilder.current_tab == "" then
1123                 tabbuilder.current_tab = "singleplayer"
1124                 engine.setting_set("main_menu_tab",tabbuilder.current_tab)
1125         end
1126
1127         --initialize tab buttons
1128         tabbuilder.last_tab = nil
1129         tabbuilder.show_buttons = true
1130
1131         tabbuilder.current_buttons = {}
1132         table.insert(tabbuilder.current_buttons,{name="singleplayer", caption=fgettext("Singleplayer")})
1133         table.insert(tabbuilder.current_buttons,{name="multiplayer", caption=fgettext("Client")})
1134         table.insert(tabbuilder.current_buttons,{name="server", caption=fgettext("Server")})
1135         table.insert(tabbuilder.current_buttons,{name="settings", caption=fgettext("Settings")})
1136         table.insert(tabbuilder.current_buttons,{name="texture_packs", caption=fgettext("Texture Packs")})
1137
1138         if engine.setting_getbool("main_menu_game_mgr") then
1139                 table.insert(tabbuilder.current_buttons,{name="game_mgr", caption=fgettext("Games")})
1140         end
1141
1142         if engine.setting_getbool("main_menu_mod_mgr") then
1143                 table.insert(tabbuilder.current_buttons,{name="mod_mgr", caption=fgettext("Mods")})
1144         end
1145         table.insert(tabbuilder.current_buttons,{name="credits", caption=fgettext("Credits")})
1146
1147
1148         for i=1,#tabbuilder.current_buttons,1 do
1149                 if tabbuilder.current_buttons[i].name == tabbuilder.current_tab then
1150                         tabbuilder.last_tab_index = i
1151                 end
1152         end
1153
1154         if tabbuilder.current_tab ~= "singleplayer" then
1155                 menu.update_gametype(true)
1156         else
1157                 menu.update_gametype()
1158         end
1159 end
1160
1161 --------------------------------------------------------------------------------
1162 function tabbuilder.checkretval(retval)
1163
1164         if retval ~= nil then
1165                 if retval.current_tab ~= nil then
1166                         tabbuilder.current_tab = retval.current_tab
1167                 end
1168
1169                 if retval.is_dialog ~= nil then
1170                         tabbuilder.is_dialog = retval.is_dialog
1171                 end
1172
1173                 if retval.show_buttons ~= nil then
1174                         tabbuilder.show_buttons = retval.show_buttons
1175                 end
1176
1177                 if retval.skipformupdate ~= nil then
1178                         tabbuilder.skipformupdate = retval.skipformupdate
1179                 end
1180
1181                 if retval.ignore_menu_quit == true then
1182                         tabbuilder.ignore_menu_quit = true
1183                 else
1184                         tabbuilder.ignore_menu_quit = false
1185                 end
1186         end
1187 end
1188
1189 --------------------------------------------------------------------------------
1190 --------------------------------------------------------------------------------
1191 -- initialize callbacks
1192 --------------------------------------------------------------------------------
1193 --------------------------------------------------------------------------------
1194 engine.button_handler = function(fields)
1195         --print("Buttonhandler: tab: " .. tabbuilder.current_tab .. " fields: " .. dump(fields))
1196
1197         if fields["btn_error_confirm"] then
1198                 gamedata.errormessage = nil
1199         end
1200
1201         local retval = modmgr.handle_buttons(tabbuilder.current_tab,fields)
1202         tabbuilder.checkretval(retval)
1203
1204         retval = gamemgr.handle_buttons(tabbuilder.current_tab,fields)
1205         tabbuilder.checkretval(retval)
1206
1207         retval = modstore.handle_buttons(tabbuilder.current_tab,fields)
1208         tabbuilder.checkretval(retval)
1209
1210         if tabbuilder.current_tab == "dialog_create_world" then
1211                 tabbuilder.handle_create_world_buttons(fields)
1212         end
1213
1214         if tabbuilder.current_tab == "dialog_delete_world" then
1215                 tabbuilder.handle_delete_world_buttons(fields)
1216         end
1217
1218         if tabbuilder.current_tab == "singleplayer" then
1219                 tabbuilder.handle_singleplayer_buttons(fields)
1220         end
1221
1222         if tabbuilder.current_tab == "texture_packs" then
1223                 tabbuilder.handle_texture_pack_buttons(fields)
1224         end
1225
1226         if tabbuilder.current_tab == "multiplayer" then
1227                 tabbuilder.handle_multiplayer_buttons(fields)
1228         end
1229
1230         if tabbuilder.current_tab == "settings" then
1231                 tabbuilder.handle_settings_buttons(fields)
1232         end
1233
1234         if tabbuilder.current_tab == "server" then
1235                 tabbuilder.handle_server_buttons(fields)
1236         end
1237
1238         --tab buttons
1239         tabbuilder.handle_tab_buttons(fields)
1240
1241         --menubar buttons
1242         menubar.handle_buttons(fields)
1243
1244         if not tabbuilder.skipformupdate then
1245                 --update menu
1246                 update_menu()
1247         else
1248                 tabbuilder.skipformupdate = false
1249         end
1250 end
1251
1252 --------------------------------------------------------------------------------
1253 engine.event_handler = function(event)
1254         if event == "MenuQuit" then
1255                 if tabbuilder.is_dialog then
1256                         if tabbuilder.ignore_menu_quit then
1257                                 return
1258                         end
1259
1260                         tabbuilder.is_dialog = false
1261                         tabbuilder.show_buttons = true
1262                         tabbuilder.current_tab = engine.setting_get("main_menu_tab")
1263                         menu.update_gametype()
1264                         update_menu()
1265                 else
1266                         engine.close()
1267                 end
1268         end
1269
1270         if event == "Refresh" then
1271                 update_menu()
1272         end
1273 end
1274
1275 --------------------------------------------------------------------------------
1276 function menu.update_gametype(reset)
1277         local game = menu.lastgame()
1278
1279         if reset or game == nil then
1280                 mm_texture.reset()
1281                 engine.set_topleft_text("")
1282                 filterlist.set_filtercriteria(worldlist,nil)
1283         else
1284                 mm_texture.update(tabbuilder.current_tab,game)
1285                 engine.set_topleft_text(game.name)
1286                 filterlist.set_filtercriteria(worldlist,game.id)
1287         end
1288 end
1289
1290 --------------------------------------------------------------------------------
1291 --------------------------------------------------------------------------------
1292 -- menu startup
1293 --------------------------------------------------------------------------------
1294 --------------------------------------------------------------------------------
1295 init_globals()
1296 mm_texture.init()
1297 menu.init()
1298 tabbuilder.init()
1299 menubar.refresh()
1300 modstore.init()
1301
1302 engine.sound_play("main_menu", true)
1303
1304 update_menu()