-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu_principal.lua
More file actions
111 lines (86 loc) · 2.46 KB
/
menu_principal.lua
File metadata and controls
111 lines (86 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
--[[
Mod Gestor para Minetest
Gestor v1.0 Copyright (C) 2016 BrunoMine (https://github.com/BrunoMine)
Recebeste uma cópia da GNU Lesser General
Public License junto com esse software,
se não, veja em <http://www.gnu.org/licenses/>.
Menu Principal (Painel do gestor)
]]
-- Tradutor de texto
local S = gestor.S
-- Abas registradas
gestor.abas = {}
-- Registrar aba
local botoes_abas = {
"0,1;3,1", -- 1
"0,2;3,1", -- 2
"0,3;3,1", -- 3
"0,4;3,1", -- 4
"0,5;3,1", -- 5
"0,6;3,1", -- 6
"0,7;3,1", -- 7
"0,8;3,1", -- 8
"0,9;3,1", -- 9
}
gestor.registrar_aba = function(name, def)
gestor.abas[name] = def
gestor.abas[name].formspec_button = "button["..botoes_abas[1]..";"..name..";"..def.titulo.."]"
table.remove(botoes_abas, 1)
end
-- Abrir Menu principal
gestor.menu_principal = function(name)
local player = minetest.get_player_by_name(name)
local formspec = "size[14,11]"
..default.gui_bg
..default.gui_bg_img
.."label[0,0;"..S("Gestor Administrativo do Servidor").."]"
-- Verifica aba em acesso
local aba_atual = player:get_attribute("gestor_aba")
if aba_atual == nil then
aba_atual = "inicio"
player:set_attribute("gestor_aba", aba_atual)
end
-- Botoes de abas
for name_aba,def in pairs(gestor.abas) do
formspec = formspec..def.formspec_button
end
--
-- Gerando Abas
--
if aba_atual ~= "inicio" then
-- Gerar formspec
formspec = formspec .. gestor.abas[aba_atual].get_formspec(name)
else
formspec = formspec.."image[5.5,3;6,6;gestor.png]"
end
-- Exibir tela
minetest.show_formspec(name, "gestor:menu_principal", formspec)
end
-- Receptor de campos
minetest.register_on_player_receive_fields(function(player, formname, fields)
-- Verifica aba em acesso
local aba_atual = player:get_attribute("gestor_aba")
if aba_atual == nil then
aba_atual = "inicio"
player:set_attribute("gestor_aba", aba_atual)
end
-- Menu Principal
if formname == "gestor:menu_principal" then
local name = player:get_player_name()
-- Alternar aba
for name_aba,dados in pairs(gestor.abas) do
if fields[name_aba] then
-- Gerar formspec
player:set_attribute("gestor_aba", name_aba)
gestor.menu_principal(name)
return
end
end
-- Retornos para a aba registrada
if aba_atual ~= "inicio" then
-- Retorno
gestor.abas[aba_atual].on_receive_fields(player, fields)
return
end
end
end)