Add missing header/footer for singleplayer tab
[oweals/minetest.git] / builtin / mm_menubar.lua
1 --Minetest
2 --Copyright (C) 2013 sapier
3 --
4 --This program is free software; you can redistribute it and/or modify
5 --it under the terms of the GNU Lesser General Public License as published by
6 --the Free Software Foundation; either version 2.1 of the License, or
7 --(at your option) any later version.
8 --
9 --This program is distributed in the hope that it will be useful,
10 --but WITHOUT ANY WARRANTY; without even the implied warranty of
11 --MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 --GNU Lesser General Public License for more details.
13 --
14 --You should have received a copy of the GNU Lesser General Public License along
15 --with this program; if not, write to the Free Software Foundation, Inc.,
16 --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 menubar = {}
19
20 --------------------------------------------------------------------------------
21 function menubar.handle_buttons(fields)
22         for i=1,#menubar.buttons,1 do
23                 if fields[menubar.buttons[i].btn_name] ~= nil then
24                         menu.last_game = menubar.buttons[i].index
25                         engine.setting_set("main_menu_last_game_idx",menu.last_game)
26                         menu.update_gametype()
27                 end
28         end
29 end
30
31 --------------------------------------------------------------------------------
32 function menubar.refresh()
33         menubar.formspec = "box[-0.3,5.625;12.4,1.3;000000]" ..
34                                            "box[-0.3,5.6;12.4,0.05;FFFFFF]"
35         menubar.buttons = {}
36
37         local button_base = -0.25
38         
39         local maxbuttons = #gamemgr.games
40         
41         if maxbuttons > 10 then
42                 maxbuttons = 10
43         end
44         
45         for i=1,maxbuttons,1 do
46
47                 local btn_name = "menubar_btn_" .. gamemgr.games[i].id
48                 local buttonpos = button_base + (i-1) * 1.245
49                 if gamemgr.games[i].menuicon_path ~= nil and
50                         gamemgr.games[i].menuicon_path ~= "" then
51
52                         menubar.formspec = menubar.formspec ..
53                                 "image_button[" .. buttonpos ..  ",5.7;1.3,1.3;"  ..
54                                 gamemgr.games[i].menuicon_path .. ";" .. btn_name .. ";;true;false]"
55                 else
56                 
57                         local part1 = gamemgr.games[i].id:sub(1,5)
58                         local part2 = gamemgr.games[i].id:sub(6,10)
59                         local part3 = gamemgr.games[i].id:sub(11)
60                         
61                         local text = part1 .. "\n" .. part2
62                         if part3 ~= nil and
63                                 part3 ~= "" then
64                                 text = text .. "\n" .. part3
65                         end
66                         menubar.formspec = menubar.formspec ..
67                                 "image_button[" .. buttonpos ..  ",5.7;1.3,1.3;;" ..btn_name ..
68                                 ";" .. text .. ";true;true]"
69                 end
70                 
71                 local toadd = {
72                         btn_name = btn_name,
73                         index = i,
74                 }
75                 
76                 table.insert(menubar.buttons,toadd)
77         end
78 end