prev and next buttons for inhabitant infos

This commit is contained in:
Sokomine 2017-07-25 23:23:41 +02:00
parent 17febf881c
commit d6f3b68af6
2 changed files with 50 additions and 19 deletions

View File

@ -608,12 +608,12 @@ mg_villages.inhabitants.print_mob_info = function( village_to_add_data_bpos, hou
end end
end end
elseif( this_mob_data.generation == 2 ) then elseif( this_mob_data.generation == 2 ) then
if( this_mob_data.gender=="m" ) then if( this_mob_data.gender=="m" and bed_nr == 1) then
generation = generation.. generation = generation..
",Father:,"..mg_villages.inhabitants.mob_get_short_name( bpos.beds[grandfather] ).. ",Father:,"..mg_villages.inhabitants.mob_get_short_name( bpos.beds[grandfather] )..
",Mother:,"..mg_villages.inhabitants.mob_get_short_name( bpos.beds[grandmother] ).. ",Mother:,"..mg_villages.inhabitants.mob_get_short_name( bpos.beds[grandmother] )..
",Father of:,"..list_of_children; ",Father of:,"..list_of_children;
else elseif( bed_nr == 2) then
-- the grandparents belong to the man's side -- the grandparents belong to the man's side
generation = generation.. generation = generation..
",Mother of:,"..list_of_children; ",Mother of:,"..list_of_children;
@ -688,24 +688,38 @@ mg_villages.inhabitants.print_mob_info = function( village_to_add_data_bpos, hou
"field[21,21;0.1,0.1;pos2str;Pos;"..minetest.pos_to_string( "field[21,21;0.1,0.1;pos2str;Pos;"..minetest.pos_to_string(
handle_schematics.get_pos_in_front_of_house( bpos, 0 )).."]"; handle_schematics.get_pos_in_front_of_house( bpos, 0 )).."]";
end end
return 'size[12,6.5]'..
-- allow to click through the inhabitants
-- (a second back button doesn't hurt)
local prev_next_button = "button[8.5,7.2;1,0.5;back_to_houselist;Back]";
if( bed_nr > 1 ) then
prev_next_button = prev_next_button..'button[9.5,7.2;1,0.5;prev;Prev]';
end
if( bed_nr < #bpos.beds ) then
prev_next_button = prev_next_button..'button[10.5,7.2;1,0.5;next;Next]';
end
return 'size[12,7.5]'..
'button_exit[4.0,0;2,0.5;quit;Exit]'.. 'button_exit[4.0,0;2,0.5;quit;Exit]'..
'button[7.5,0;5,0.5;back_to_houselist;Back to all inhabitants of house]'.. 'button[7.5,0;5,0.5;back_to_houselist;Back to all inhabitants of house]'..
-- the back button needs to know which village we are in -- the back button needs to know which village we are in
'field[20,20;0.1,0.1;village_id;VillageID;'..minetest.formspec_escape( village_id ).."]".. 'field[20,20;0.1,0.1;village_id;VillageID;'..minetest.formspec_escape( village_id ).."]"..
-- it also needs to know the plot number we might want to go back to -- it also needs to know the plot number we might want to go back to
'field[22,22;0.1,0.1;plot_nr;HouseNr;'..house_nr..']'.. 'field[22,22;0.1,0.1;plot_nr;HouseNr;'..house_nr..']'..
-- the prev/next buttons need information about the mob nr
'field[23,23;0.1,0.1;bed_nr;BedNr;'..bed_nr..']'..
-- show where the plot is located -- show where the plot is located
'label[0.5,0;Location: '..minetest.formspec_escape( minetest.pos_to_string( bpos ))..']'.. 'label[0.5,0;Location: '..minetest.formspec_escape( minetest.pos_to_string( bpos ))..']'..
-- allow to teleport there (if the player has the teleport priv) -- allow to teleport there (if the player has the teleport priv)
link_teleport.. link_teleport..
-- add prev/next buttons
prev_next_button..
'label[0.5,0.5;'..minetest.formspec_escape("Information about ".. 'label[0.5,0.5;'..minetest.formspec_escape("Information about "..
mg_villages.inhabitants.mob_get_short_name( this_mob_data ).. mg_villages.inhabitants.mob_get_short_name( this_mob_data )..
" ("..( this_mob_data.title or "- no title -").."):")..']'.. " ("..( this_mob_data.title or "- no profession -").."):")..']'..
'tablecolumns[' .. 'tablecolumns[' ..
'text,align=left;'.. 'text,align=left;'..
'text,align=left]'.. -- name and description of inhabitant 'text,align=left]'.. -- name and description of inhabitant
'table[0.1,1.0;11.4,5.0;mg_villages:formspec_list_one_mob;'..text..']'; 'table[0.1,1.0;11.4,6.0;mg_villages:formspec_list_one_mob;'..text..']';
end end

View File

@ -358,6 +358,7 @@ mg_villages.form_input_handler = function( player, formname, fields)
return false; return false;
end end
minetest.chat_send_player("singleplayer","formname: "..tostring(formname).."\nfields: "..minetest.serialize(fields));
-- teleport to a plot or mob -- teleport to a plot or mob
if( fields[ 'teleport_to' ] if( fields[ 'teleport_to' ]
and fields[ 'pos2str' ] and fields[ 'pos2str' ]
@ -390,25 +391,41 @@ mg_villages.form_input_handler = function( player, formname, fields)
return true; return true;
end end
-- provide information about a particular mob -- are we supposed to show information about a particular mob?
if( not( fields['back_to_houselist']) local mob_selected = nil;
-- show previous mob that lives on the plot
if( formname=="mg_villages:formspec_list_one_mob" and fields["prev"] and fields["bed_nr"]) then
mob_selected = tonumber(fields.bed_nr) - 1;
-- show next mob that lives on the mob
elseif( formname=="mg_villages:formspec_list_one_mob" and fields["next"] and fields["bed_nr"]) then
mob_selected = tonumber(fields.bed_nr) + 1;
-- show informaton about mob selected from list of inhabitants
elseif( not( fields['back_to_houselist'])
and fields['mg_villages:formspec_list_inhabitants'] and fields['mg_villages:formspec_list_inhabitants']
and fields['mg_villages:formspec_list_inhabitants']~="" and fields['mg_villages:formspec_list_inhabitants']~=""
and fields['village_id'] and fields['village_id']
and fields['plot_nr']) then and fields['plot_nr']) then
local selection = minetest.explode_table_event( fields['mg_villages:formspec_list_inhabitants'] ); local selection = minetest.explode_table_event( fields['mg_villages:formspec_list_inhabitants'] );
fields.plot_nr = tonumber( fields.plot_nr ); mob_selected = selection.row;
local pname = player:get_player_name(); end
if( mg_villages.all_villages[ fields.village_id ]
and mg_villages.all_villages[ fields.village_id ].to_add_data -- this index has to be a number and not a string
and mg_villages.all_villages[ fields.village_id ].to_add_data.bpos fields.plot_nr = tonumber( fields.plot_nr or "0");
and mg_villages.all_villages[ fields.village_id ].to_add_data.bpos[ fields.plot_nr ] local pname = player:get_player_name();
and mg_villages.all_villages[ fields.village_id ].to_add_data.bpos[ fields.plot_nr ].beds[ selection.row]) then
local village = mg_villages.all_villages[ fields.village_id ]; -- provide information about a particular mob
minetest.show_formspec( pname, "mg_villages:formspec_list_one_mob", if( mob_selected
mg_villages.inhabitants.print_mob_info( village.to_add_data.bpos, fields.plot_nr, fields.village_id, selection.row, pname )); and fields.village_id
return true; and fields.plot_nr
end and mg_villages.all_villages[ fields.village_id ]
and mg_villages.all_villages[ fields.village_id ].to_add_data
and mg_villages.all_villages[ fields.village_id ].to_add_data.bpos
and mg_villages.all_villages[ fields.village_id ].to_add_data.bpos[ fields.plot_nr ]
and mg_villages.all_villages[ fields.village_id ].to_add_data.bpos[ fields.plot_nr ].beds[mob_selected]) then
local village = mg_villages.all_villages[ fields.village_id ];
minetest.show_formspec( pname, "mg_villages:formspec_list_one_mob",
mg_villages.inhabitants.print_mob_info( village.to_add_data.bpos, fields.plot_nr, fields.village_id, mob_selected, pname ));
return true;
end end
-- provide information about the inhabitants of a particular plot -- provide information about the inhabitants of a particular plot