Implement switching selected group
parent
47a474f166
commit
5189c88b36
40
gui.lua
40
gui.lua
|
@ -51,7 +51,20 @@ sfinv.register_page("classroom:edu", {
|
|||
end
|
||||
|
||||
fs[#fs + 1] = "]"
|
||||
fs[#fs + 1] = "tabheader[0.3,1.1;group;All,Group 1;1]"
|
||||
fs[#fs + 1] = "tabheader[0.3,1.1;group;All"
|
||||
local selected_group_idx = 1
|
||||
local i = 2
|
||||
for name, group in pairs(classroom.get_all_groups()) do
|
||||
fs[#fs + 1] = ","
|
||||
fs[#fs + 1] = minetest.formspec_escape(name)
|
||||
if context.groupname and name == context.groupname then
|
||||
selected_group_idx = i
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
fs[#fs + 1] = ";"
|
||||
fs[#fs + 1] = tostring(selected_group_idx)
|
||||
fs[#fs + 1] = "]"
|
||||
fs[#fs + 1] = "table[0,0.8;5,8;students;,Name"
|
||||
for _, col in pairs(infos) do
|
||||
fs[#fs + 1] = ",," .. col.title
|
||||
|
@ -190,6 +203,23 @@ sfinv.register_page("classroom:edu", {
|
|||
end
|
||||
end
|
||||
|
||||
if fields.group then
|
||||
if fields.group == "1" then
|
||||
context.groupname = nil
|
||||
else
|
||||
local i = 2
|
||||
for name, _ in pairs(classroom.get_all_groups()) do
|
||||
if i == tonumber(fields.group) then
|
||||
context.groupname = name
|
||||
break
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
sfinv.set_player_inventory_formspec(player)
|
||||
return true
|
||||
end
|
||||
|
||||
if fields.select_all then
|
||||
context.select_toggle = "all"
|
||||
sfinv.set_player_inventory_formspec(player)
|
||||
|
@ -221,6 +251,11 @@ sfinv.register_page("classroom:edu", {
|
|||
return true
|
||||
end
|
||||
|
||||
if fields.edit_group and context.groupname then
|
||||
classroom.show_edit_group(player, context.groupname)
|
||||
return true
|
||||
end
|
||||
|
||||
for _, action in pairs(classroom.get_actions()) do
|
||||
if fields["action_" .. action.name] then
|
||||
local selector
|
||||
|
@ -283,6 +318,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
|
||||
local group = classroom.create_group(fields.name)
|
||||
if group then
|
||||
sfinv.set_player_inventory_formspec(player)
|
||||
classroom.show_edit_group(player, group.name)
|
||||
else
|
||||
classroom.show_new_group(player, fields.name)
|
||||
|
@ -395,6 +431,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
if student then
|
||||
classroom.add_student_to_group(context.groupname, student)
|
||||
classroom.show_edit_group(player, context.groupname)
|
||||
sfinv.set_player_inventory_formspec(player)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@ -405,6 +442,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
if student then
|
||||
classroom.remove_student_from_group(context.groupname, student)
|
||||
classroom.show_edit_group(player, context.groupname)
|
||||
sfinv.set_player_inventory_formspec(player)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue