z_mirror/BlueprintTools
git clone https://git.raiguard.me/z_mirror/BlueprintTools
bf73278
trunk
1local gui =require ( "gui" ) 2local mod_gui =require ( "__core__.lualib.mod-gui" ) 3 4local buttons_gui ={} 5 6local function mod_gui_button ( player_settings , color , action ) 7local internal_name =string . gsub ( string . gsub ( action , "bpt_" , "" ), "_" , "-" ) 8 9local setting =player_settings [ "show_" .. action ] 10if setting then 11return { 12type ="sprite-button" , 13style ="bpt_mod_gui_button_" .. color , 14sprite ="bpt_" .. action .. "_white" , 15tooltip ={ "gui.bpt-" .. internal_name .. "-tooltip" } , 16elem_mods ={ visible =false } , 17actions ={ 18on_click ={ gui ="buttons" , action =action } , 19} , 20ref ={ action } , 21} 22else 23return {} 24end 25end 26 27function buttons_gui . refresh ( player , player_table ) 28local button_flow =mod_gui . get_button_flow ( player ) 29 30local player_settings =player_table . settings 31 32for _ , button in pairs ( player_table . guis . blueprint_buttons or {} ) do 33button . destroy () 34end 35player_table . guis . blueprint_buttons =gui . build ( button_flow , { 36mod_gui_button ( player_settings , "blue" , "swap_wire_colors" ), 37mod_gui_button ( player_settings , "blue" , "set_tiles" ), 38mod_gui_button ( player_settings , "blue" , "configure" ), 39} ) 40 41for _ , button in pairs ( player_table . guis . upgrade_planner_buttons or {} ) do 42button . destroy () 43end 44player_table . guis . upgrade_planner_buttons =gui . build ( button_flow , { 45mod_gui_button ( player_settings , "green" , "configure" ), 46} ) 47 48for _ , button in pairs ( player_table . guis . deconstruction_planner_buttons or {} ) do 49button . destroy () 50end 51player_table . guis . deconstruction_planner_buttons =gui . build ( button_flow , { 52mod_gui_button ( player_settings , "red" , "configure" ), 53} ) 54end 55 56function buttons_gui . show ( player_table , button_type ) 57for _ , button in pairs ( player_table . guis [ button_type .. "_buttons" ]) do 58button . visible =true 59end 60player_table . flags [ button_type .. "_buttons_shown" ] =true 61end 62 63function buttons_gui . hide ( player_table , button_type ) 64for _ , button in pairs ( player_table . guis [ button_type .. "_buttons" ]) do 65button . visible =false 66end 67player_table . flags [ button_type .. "_buttons_shown" ] =false 68end 69 70return buttons_gui