z_mirror/BlueprintTools
git clone https://git.raiguard.me/z_mirror/BlueprintTools
00b37f1
trunk
1local gui =require ( "gui" ) 2 3local util =require ( "scripts.util" ) 4 5local import_string_gui ={} 6 7function import_string_gui . build ( player ) 8import_string_gui . destroy ( player ) 9 10local frame =gui . add ( player . gui . screen , { 11type ="frame" , 12name ="bpt_import_string_frame" , 13direction ="vertical" , 14caption ={ "gui-blueprint-library.import-string" } , 15actions ={ 16on_closed ={ gui ="import_string" , action ="close" } , 17} , 18ref ={ "window" } , 19{ 20type ="text-box" , 21name ="textbox" , 22style_mods ={ width =400 , height =250 } , 23elem_mods ={ word_wrap =true } , 24ref ={ "textbox" } , 25} , 26{ 27type ="flow" , 28name ="footer_flow" , 29style ="dialog_buttons_horizontal_flow" , 30ref ={ "footer_flow" } , 31{ 32type ="button" , 33style ="back_button" , 34caption ={ "gui.cancel" } , 35actions ={ 36on_click ={ gui ="import_string" , action ="close" } , 37} , 38} , 39{ type ="empty-widget" , style ="flib_dialog_footer_drag_handle" , ignored_by_interaction =true } , 40{ 41type ="button" , 42style ="confirm_button" , 43caption ={ "gui-blueprint-library.import" } , 44actions ={ 45on_click ={ gui ="import_string" , action ="import" } , 46} , 47} , 48} , 49} ) 50 51frame . force_auto_center () 52frame . footer_flow . drag_target =frame 53frame . textbox . focus () 54player . opened =frame 55end 56 57function import_string_gui . destroy ( player ) 58local frame =player . gui . screen . bpt_string_import_frame 59if frame and frame . valid then 60if player . opened == frame then 61player . opened =nil 62end 63frame . destroy () 64end 65end 66 67function import_string_gui . handle_action ( player , action ) 68local frame =player . gui . screen . bpt_import_string_frame 69if not frame or not frame . valid then 70return 71end 72if action . action == "close" then 73frame . destroy () 74elseif action . action == "import" then 75if player . clear_cursor () then 76local result =player . cursor_stack . import_stack ( frame . textbox . text ) 77if result == 0 then 78local cursor_stack =player . cursor_stack 79if cursor_stack . valid_for_read then 80util . cursor_notification ( player , { "string-import-successful" , cursor_stack . prototype . localised_name } ) 81else 82util . cursor_notification ( player , { "string-import-produced-no-item" } , "utility/cannot_build" ) 83end 84frame . destroy () 85else 86util . cursor_notification ( player , { "failed-to-import-string" , "" } , "utility/cannot_build" ) 87end 88else 89util . cursor_notification ( player , { "message.bpt-unable-to-clear-cursor" } , "utility/cannot_build" ) 90end 91end 92end 93 94return import_string_gui