z_mirror/BlueprintTools
git clone https://git.raiguard.me/z_mirror/BlueprintTools
00b37f1
trunk
1local gui =require ( "gui" ) 2 3local constants =require ( "constants" ) 4local import_string_gui =require ( "scripts.gui.import-string" ) 5local util =require ( "scripts.util" ) 6 7local library_shortcuts_gui ={} 8 9--- @param player LuaPlayer 10--- @param player_table PlayerTable 11function library_shortcuts_gui . refresh ( player , player_table ) 12local frame =player . gui . relative . bpt_library_shortcuts_frame 13if frame and frame . valid then 14frame . destroy () 15end 16 17if not player_table . settings . show_library_shortcuts then 18return 19end 20 21local buttons ={} 22for _ , prototype_name in pairs ( constants . library_shortcut_prototypes ) do 23local prototype =prototypes . shortcut [ prototype_name ] 24if prototype then 25local tooltip =prototype . localised_name 26if prototype . associated_control_input then 27tooltip ={ "" , tooltip , " (" , { "gui.bpt-shortcut-" .. prototype_name .. "-control" } , ")" } 28end 29table . insert ( buttons , { 30type ="sprite-button" , 31style ="bpt_shortcut_button_" .. prototype_name , 32sprite ="bpt_shortcut_sprite_" .. prototype_name , 33tooltip =tooltip , 34actions ={ 35on_click ={ 36gui ="library_shortcuts" , 37action =prototype . action , 38item_to_spawn =prototype . item_to_spawn and prototype . item_to_spawn . name or nil , 39} , 40} , 41} ) 42end 43end 44 45gui . add ( player . gui . relative , { 46type ="frame" , 47name ="bpt_library_shortcuts_frame" , 48style ="slot_window_frame" , 49{ 50type ="frame" , 51style ="inside_deep_frame" , 52direction ="vertical" , 53children =buttons , 54} , 55--- @type GuiAnchor 56anchor ={ 57gui =defines . relative_gui_type . blueprint_library_gui , 58position =defines . relative_gui_position . right , 59} , 60} ) 61end 62 63--- @param player LuaPlayer 64function library_shortcuts_gui . handle_action ( player , player_table , action ) 65if action . action == "spawn-item" then 66local cursor_stack =player . cursor_stack 67if cursor_stack and cursor_stack . valid and player . clear_cursor () then 68cursor_stack . set_stack ( { type ="item" , name =action . item_to_spawn , count =1 } ) 69-- The event will not fire until the next tick 70player_table . flags . setting_temporary_item =true 71player_table . flags . holding_temporary_item =true 72else 73util . cursor_notification ( player , { "message.bpt-unable-to-clear-cursor" } , "utility/cannot_build" ) 74end 75elseif action . action == "import-string" then 76import_string_gui . build ( player ) 77end 78end 79 80return library_shortcuts_gui