From 3111155e7d415db6b74c382512c5809956d723c5 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Tue, 25 Jul 2017 23:41:04 +0200 Subject: [PATCH] added prev next buttons to plot info --- inhabitants.lua | 14 +++++++++++++- plotmarker_formspec.lua | 38 ++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/inhabitants.lua b/inhabitants.lua index 6addc5c..cb324ed 100644 --- a/inhabitants.lua +++ b/inhabitants.lua @@ -532,7 +532,17 @@ mg_villages.inhabitants.print_house_info = function( village_to_add_data_bpos, h "field[21,21;0.1,0.1;pos2str;Pos;"..minetest.pos_to_string( handle_schematics.get_pos_in_front_of_house( bpos, 0 )).."]"; end - return 'size[12,4.5]'.. + + -- allow to click through the diffrent plots + -- (a second back button doesn't hurt) + local prev_next_button = "button[8.5,4.7;1,0.5;back_to_plotlist;Back]"; + if( house_nr > 1 ) then + prev_next_button = prev_next_button..'button[9.5,4.7;1,0.5;prev;Prev]'; + end + if( house_nr < #village_to_add_data_bpos ) then + prev_next_button = prev_next_button..'button[10.5,4.7;1,0.5;next;Next]'; + end + return 'size[12,5.0]'.. 'button_exit[4.0,0;2,0.5;quit;Exit]'.. 'button[9.5,0;2,0.5;back_to_plotlist;Back to plotlist]'.. -- the back button needs to know which village we are in @@ -543,6 +553,8 @@ mg_villages.inhabitants.print_house_info = function( village_to_add_data_bpos, h 'label[0.5,0;Location: '..minetest.formspec_escape( minetest.pos_to_string( bpos ))..']'.. -- allow to teleport there (if the player has the teleport priv) link_teleport.. + -- allow to click through the plots + prev_next_button.. 'label[0.5,0.5;'..minetest.formspec_escape(str)..']'.. 'label[0.5,4.1;'..minetest.formspec_escape(add_str)..']'.. 'tablecolumns[' .. diff --git a/plotmarker_formspec.lua b/plotmarker_formspec.lua index c2e19fc..d6f2aa0 100644 --- a/plotmarker_formspec.lua +++ b/plotmarker_formspec.lua @@ -358,7 +358,6 @@ mg_villages.form_input_handler = function( player, formname, fields) return false; end -minetest.chat_send_player("singleplayer","formname: "..tostring(formname).."\nfields: "..minetest.serialize(fields)); -- teleport to a plot or mob if( fields[ 'teleport_to' ] and fields[ 'pos2str' ] @@ -428,24 +427,35 @@ minetest.chat_send_player("singleplayer","formname: "..tostring(formname).."\nfi return true; end - -- provide information about the inhabitants of a particular plot - if( not( fields['back_to_plotlist']) + -- are we supposed to show information about a particular plot? + local plot_selected = nil; + -- show previous plot of that village + if( formname=="mg_villages:formspec_list_inhabitants" and fields["prev"] and fields["plot_nr"]) then + plot_selected = fields.plot_nr - 1; + -- show next plot of that village + elseif( formname=="mg_villages:formspec_list_inhabitants" and fields["next"] and fields["plot_nr"]) then + plot_selected = fields.plot_nr + 1; + -- show informaton about plot selected from list of plots in a village + elseif( not( fields['back_to_plotlist']) and fields['mg_villages:formspec_list_plots'] and fields['mg_villages:formspec_list_plots']~="" and fields['village_id']) then local selection = minetest.explode_table_event( fields['mg_villages:formspec_list_plots'] ); - local pname = player:get_player_name(); - if( 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[ selection.row-1 ]) then + plot_selected = selection.row-1; + end - local village = mg_villages.all_villages[ fields.village_id ]; - local plot_nr = selection.row-1; - minetest.show_formspec( pname, "mg_villages:formspec_list_inhabitants", - mg_villages.inhabitants.print_house_info( village.to_add_data.bpos, plot_nr, fields.village_id, pname )); - return true; - end + -- provide information about the inhabitants of a particular plot + if( plot_selected + and fields.village_id + 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[ plot_selected ]) then + + local village = mg_villages.all_villages[ fields.village_id ]; + minetest.show_formspec( pname, "mg_villages:formspec_list_inhabitants", + mg_villages.inhabitants.print_house_info( village.to_add_data.bpos, plot_selected, fields.village_id, pname )); + return true; end -- back from the list of inhabitants of a plot to the list of plots of a village