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