z_mirror/BlueprintTools
git clone https://git.raiguard.me/z_mirror/BlueprintTools
00b37f1
trunk
1local gui =require ( "gui" ) 2 3local set_tiles =require ( "scripts.processors.set-tiles" ) 4 5local set_tiles_gui ={} 6 7function set_tiles_gui . build ( player , player_table ) 8local settings =player_table . set_tiles_settings 9local refs =gui . build ( player . gui . screen , { 10{ 11type ="frame" , 12direction ="vertical" , 13caption ={ "controls.bpt-set-tiles" } , 14ref ={ "window" } , 15actions ={ 16on_closed ={ gui ="set_tiles" , action ="close" } , 17} , 18children ={ 19{ 20type ="frame" , 21style ="inside_shallow_frame_with_padding" , 22children ={ 23{ 24type ="choose-elem-button" , 25style ="slot_button_in_shallow_frame" , 26elem_type ="tile" , 27tile =settings . tile , 28elem_filters ={ { filter ="blueprintable" } } , 29actions ={ 30on_elem_changed ={ gui ="set_tiles" , action ="update_tile" } , 31} , 32ref ={ "tile_button" } , 33} , 34{ 35type ="line" , 36style_mods ={ left_margin =8 , vertically_stretchable =true } , 37direction ="vertical" , 38} , 39{ 40type ="flow" , 41style_mods ={ left_margin =8 } , 42direction ="vertical" , 43children ={ 44{ 45type ="checkbox" , 46caption ={ "gui.bpt-fill-gaps" } , 47tooltip ={ "gui.bpt-fill-gaps-description" } , 48state =settings . fill_gaps , 49ref ={ "fill_gaps_checkbox" } , 50} , 51{ 52type ="flow" , 53style_mods ={ vertical_align ="center" } , 54ref ={ "margin_flow" } , 55children ={ 56{ 57type ="label" , 58style_mods ={ right_margin =8 } , 59caption ={ "gui.bpt-margin" } , 60tooltip ={ "gui.bpt-margin-description" } , 61} , 62{ 63type ="textfield" , 64style_mods ={ width =50 , horizontal_align ="center" } , 65text =tostring ( settings . margin ), 66numeric =true , 67ref ={ "margin_textfield" } , 68} , 69} , 70} , 71} , 72} , 73} , 74} , 75{ 76type ="flow" , 77style ="dialog_buttons_horizontal_flow" , 78children ={ 79{ 80type ="button" , 81style ="back_button" , 82caption ={ "gui.cancel" } , 83actions ={ 84on_click ={ gui ="set_tiles" , action ="close" } , 85} , 86} , 87{ 88type ="empty-widget" , 89style ="flib_dialog_footer_drag_handle" , 90style_mods ={ minimal_width =24 } , 91ref ={ "footer_drag_handle" } , 92} , 93{ 94type ="button" , 95style ="confirm_button" , 96caption ={ "gui.confirm" } , 97ref ={ "confirm_button" } , 98actions ={ 99on_click ={ gui ="set_tiles" , action ="confirm" } , 100} , 101} , 102} , 103} , 104} , 105} , 106} ) 107 108refs . footer_drag_handle . drag_target =refs . window 109refs . window . force_auto_center () 110 111player . opened =refs . window 112 113player_table . guis . set_tiles ={ 114refs =refs , 115} 116end 117 118function set_tiles_gui . destroy ( player_table ) 119local gui_data =player_table . guis . set_tiles 120gui_data . refs . window . destroy () 121player_table . guis . set_tiles =nil 122end 123 124function set_tiles_gui . handle_action ( e , msg ) 125local player =game . get_player ( e . player_index ) 126local player_table =storage . players [ e . player_index ] 127local gui_data =player_table . guis . set_tiles 128local refs =gui_data . refs 129 130if msg . action == "close" then 131set_tiles_gui . destroy ( player_table ) 132elseif msg . action == "confirm" then 133local tile_name =refs . tile_button . elem_value 134if tile_name then 135-- Save settings 136local settings =player_table . set_tiles_settings 137settings . tile =tile_name 138settings . fill_gaps =refs . fill_gaps_checkbox . state 139settings . margin =tonumber ( refs . margin_textfield . text ) or 0 140 141-- Modify the blueprint 142set_tiles ( player , tile_name , settings . fill_gaps , settings . margin ) 143 144-- Destroy the GUI 145set_tiles_gui . destroy ( player_table ) 146end 147elseif msg . action == "update_tile" then 148local tile_name =refs . tile_button . elem_value 149if tile_name then 150refs . confirm_button . enabled =true 151else 152refs . confirm_button . enabled =false 153end 154end 155end 156 157return set_tiles_gui