]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/mm_menubar.lua
Pass pointed_thing to on_punch and minetest.register_on_punchnode callbacks
[dragonfireclient.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
34         menubar.formspec = "box[-0.3,5.625;12.4,1.2;#000000]" ..
35                                            "box[-0.3,5.6;12.4,0.05;#FFFFFF]"
36         menubar.buttons = {}
37
38         local button_base = -0.08
39         
40         local maxbuttons = #gamemgr.games
41         
42         if maxbuttons > 11 then
43                 maxbuttons = 11
44         end
45         
46         for i=1,maxbuttons,1 do
47
48                 local btn_name = "menubar_btn_" .. gamemgr.games[i].id
49                 local buttonpos = button_base + (i-1) * 1.1
50                 if gamemgr.games[i].menuicon_path ~= nil and
51                         gamemgr.games[i].menuicon_path ~= "" then
52
53                         menubar.formspec = menubar.formspec ..
54                                 "image_button[" .. buttonpos ..  ",5.72;1.165,1.175;"  ..
55                                 engine.formspec_escape(gamemgr.games[i].menuicon_path) .. ";" ..
56                                 btn_name .. ";;true;false]"
57                 else
58                 
59                         local part1 = gamemgr.games[i].id:sub(1,5)
60                         local part2 = gamemgr.games[i].id:sub(6,10)
61                         local part3 = gamemgr.games[i].id:sub(11)
62                         
63                         local text = part1 .. "\n" .. part2
64                         if part3 ~= nil and
65                                 part3 ~= "" then
66                                 text = text .. "\n" .. part3
67                         end
68                         menubar.formspec = menubar.formspec ..
69                                 "image_button[" .. buttonpos ..  ",5.72;1.165,1.175;;" ..btn_name ..
70                                 ";" .. text .. ";true;true]"
71                 end
72                 
73                 local toadd = {
74                         btn_name = btn_name,
75                         index = i,
76                 }
77                 
78                 table.insert(menubar.buttons,toadd)
79         end
80 end